private object NewDo(NewAst ast) { var className = Resolve(ast); var classType = (className as ClassSymbol).Src as ClassAst; var space = new MemorySpace(); var oldSpace = MemorySpaces.Current; MemorySpaces.Current = space; foreach (var symbol in classType.Body.ScopedStatements) { Exec(symbol); } if (classType.Constructor != null) { var funcInvoke = new FuncInvoke(classType.Constructor.Token, ast.Args); funcInvoke.CurrentScope = classType.Body.CurrentScope; Exec(funcInvoke); } MemorySpaces.Current = oldSpace; return space; }
public void Visit(NewAst ast) { Exec(ast); }
public void Visit(NewAst ast) { ast.Args.ForEach(arg => arg.Visit(this)); if (ResolvingTypes) { if (ast.Name.Token.TokenType == TokenType.Word && !ast.IsArray) { var className = Resolve(ast.Name) as ClassSymbol; if (className == null) { className = ast.Global.Resolve(ast.Name) as ClassSymbol; if (className == null) { throw new InvalidSyntax(String.Format("Class {0} is undefined", ast.Name.Token.TokenValue)); } } ValidateClassConstructorArgs(ast, className); ast.AstSymbolType = className.Type; } else if (ast.IsArray) { } else { throw new InvalidSyntax("Cannot new type of " + ast.Name); } } SetScope(ast); }
private void ValidateClassConstructorArgs(NewAst ast, ClassSymbol classSource) { if (!ResolvingTypes) { return; } if (classSource == null) { throw new ArgumentException("classSource"); } var constructor = GetConstructorForClass(classSource.Src as ClassAst); if (constructor != null) { if (CollectionUtil.IsNullOrEmpty(ast.Args) && !CollectionUtil.IsNullOrEmpty(constructor.Arguments)) { throw new InvalidSyntax("Not enough arguments for constructor arguments"); } if (ast.Args.Count != constructor.Arguments.Count) { throw new InvalidSyntax("Not enough arguments for constructor arguments"); } (classSource.Src as ClassAst).Constructor = constructor; } }
public void Visit(NewAst ast) { throw new NotImplementedException(); }