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); }
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); }