예제 #1
0
        public LiteValue Visit(SyntaxIndexElementsExpressionNode Node, LiteEnv Env)
        {
            var Val = Node.GetElementIdentNode().Accept(this, Env);

            if (Val.Type == LiteValueType.Elements)
            {
                var EleObj = ElementsTable.GetElements((int)Val.Numeric);
                if (EleObj == null)
                {
                    Logger.DError($"bad elements access : {Val}");
                    return(LiteValue.Error);
                }

                var Idx = Node.GetIndexNode().Accept(this, Env);
                if (Idx.Type != LiteValueType.Numeric)
                {
                    Logger.DError($"elements index must be number");
                    return(LiteValue.Error);
                }

                return(EleObj.Get((int)Idx.Numeric));
            }
            else
            {
                Logger.DError($"unknown elements type : {Val}");
            }

            return(LiteValue.Error);
        }
예제 #2
0
        public LiteValue Visit(SyntaxAssignmentExpressionNode Node, LiteEnv Env)
        {
            var LeftNode = Node.GetLeft();

            if (LeftNode.GetType() == SyntaxNodeType.Identifier)
            {
                var Ident = (LeftNode as SyntaxIdentifierNode).GetValue();

                var Val = Node.GetRight().Accept(this, Env);
                Env.Set(Ident, Val);
                return(Val);
            }
            if (LeftNode.GetType() == SyntaxNodeType.DotClassExpression)
            {
                var DotNode    = LeftNode as SyntaxDotClassExpressionNode;
                var Mem        = DotNode.GetCallIdentNode() as SyntaxIdentifierNode;
                var LiteObjVal = DotNode.GetClassIdentNode().Accept(this, Env);
                if (LiteObjVal.Type != LiteValueType.Object)
                {
                    Logger.DError($"bad object access : {LiteObjVal}");
                    return(LiteValue.Error);
                }

                var LiteObj = ObjectTable.GetObject((int)LiteObjVal.Numeric);
                if (LiteObj == null)
                {
                    Logger.DError($"bad object access : {LiteObjVal}");
                    return(LiteValue.Error);
                }

                var ExpVal = Node.GetRight().Accept(this, Env);
                if (ExpVal == LiteValue.Error)
                {
                    return(ExpVal);
                }

                return(LiteObj.Write(Mem.GetValue(), ExpVal));
            }

            if (LeftNode.GetType() == SyntaxNodeType.IndexElementsExpression)
            {
                var IdxNode = LeftNode as SyntaxIndexElementsExpressionNode;
                var Val     = IdxNode.GetElementIdentNode().Accept(this, Env);
                if (Val.Type == LiteValueType.Elements)
                {
                    var EleObj = ElementsTable.GetElements((int)Val.Numeric);
                    if (EleObj == null)
                    {
                        Logger.DError($"bad elements access : {Val}");
                        return(LiteValue.Error);
                    }

                    var Idx = IdxNode.GetIndexNode().Accept(this, Env);
                    if (Idx.Type != LiteValueType.Numeric)
                    {
                        Logger.DError($"elements index must be number");
                        return(LiteValue.Error);
                    }

                    var ExpVal = Node.GetRight().Accept(this, Env);
                    if (ExpVal == LiteValue.Error)
                    {
                        return(ExpVal);
                    }

                    return(EleObj.Set((int)Idx.Numeric, ExpVal));
                }
                else
                {
                    Logger.DError($"unknown elements type : {Val}");
                }
            }

            Logger.DError($"unexpected '=' near {Node.GetLeft()}");
            return(LiteValue.Error);
        }