Exemplo n.º 1
0
        public LiteValue Visit(SyntaxDotClassExpressionNode Node, LiteEnv Env)
        {
            var Val = Node.GetClassIdentNode().Accept(this, Env);
            var Mem = (Node.GetCallIdentNode() as SyntaxIdentifierNode).GetValue();

            if (Val.Type == LiteValueType.Class)
            {
                if (Mem == "New")
                {
                    var Cls     = ClassTable.GetClass((int)Val.Numeric);
                    var ObjEnv  = Cls.MakeEnv();
                    var LiteObj = new LiteObject(ObjEnv);
                    var Obj     = ObjectTable.AddObjectEx(LiteObj);
                    ObjEnv.SetSelf("this", Obj);
                    LiteObj.InitObject(this, Cls, ObjEnv);
                    return(Obj);
                }
            }
            else if (Val.Type == LiteValueType.Object)
            {
                var LiteObj = ObjectTable.GetObject((int)Val.Numeric);
                if (LiteObj == null)
                {
                    Logger.DError($"bad member access : {Val}");
                    return(LiteValue.Error);
                }

                return(LiteObj.Read(Mem));
            }
            else
            {
                Logger.DError($"unknown class type : {Val}");
            }

            return(LiteValue.Error);
        }
Exemplo n.º 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);
        }
Exemplo n.º 3
0
        public void GetObjectHandlesNull()
        {
            RigidActor actor = ObjectTable.GetObject <RigidActor>(0);

            Assert.IsNull(actor);
        }