Exemple #1
0
        public LiteValue Visit(SyntaxClassNode Node, LiteEnv Env)
        {
            ClassInfo BaseCls = null;

            if (Node.GetBaseClassIdentNode() is SyntaxIdentifierNode BaseIdent)
            {
                var Val = Env.Get(BaseIdent.GetValue());
                if (Val.Type == LiteValueType.Class)
                {
                    BaseCls = ClassTable.GetClass((int)Val.Numeric);
                }

                if (BaseCls == null)
                {
                    Logger.DError($"error base class : {BaseIdent.GetValue()}");
                    return(LiteValue.Error);
                }
            }

            var ClsValue = ClassTable.AddClassEx(new ClassInfo(Node.GetClassName(), Env,
                                                               Node.GetClassBody() as SyntaxClassBodyStatementNode,
                                                               BaseCls));

            Env.SetSelf(Node.GetClassName(), ClsValue);
            return(ClsValue);
        }
Exemple #2
0
        public LiteValue Visit(SyntaxCallFunctionExpressionNode Node, LiteEnv Env)
        {
            var FuncIndex = LiteValue.Nil;
            var FuncName  = Node.GetFuncIdentNode();

            if (FuncName.GetType() == SyntaxNodeType.CallFunctionExpression)
            {
                FuncIndex = Visit(FuncName as SyntaxCallFunctionExpressionNode, Env);
            }
            else if (FuncName.GetType() == SyntaxNodeType.DotClassExpression)
            {
                var DotNode = FuncName as SyntaxDotClassExpressionNode;
                FuncIndex = Visit(DotNode, Env);

                if ((DotNode.GetCallIdentNode() as SyntaxIdentifierNode).GetValue() == "New")
                {
                    return(FuncIndex);
                }
            }
            else if (FuncName.GetType() == SyntaxNodeType.Identifier)
            {
                FuncIndex = Env.Get((FuncName as SyntaxIdentifierNode).GetValue());
            }

            if (FuncIndex == LiteValue.Nil || FuncIndex.Type != LiteValueType.Function)
            {
                Logger.DError($"unknown function : {FuncName}");
                return(LiteValue.Error);
            }

            var Func = FuncTable.GetFunc((int)FuncIndex.Numeric);

            if (Func == null)
            {
                Logger.DError($"=> unknown fn name : {FuncIndex.Numeric}");
                return(LiteValue.Error);
            }
            return(CallFunc(Func, Node.GetArgumentListNode() as SyntaxArgumentListStatementNode, Env));
        }
Exemple #3
0
 public LiteValue Visit(SyntaxIdentifierNode Node, LiteEnv Env)
 {
     return(Env.Get(Node.GetValue()));
 }