public object VisitFunctionStatement(Statement.Function stmt) { var name = stmt.Identifier; var parameters = stmt.Parameters.Count; var returnValues = stmt.ReturnValue == null ? 0 : 1; current = new WASMFunction(parameters, returnValues, name); functions.Declare(name); // TODO too many nested envs? environment.EnterInner(); passByVar.Add(name, new List <bool>()); // TODO pass by foreach (var param in stmt.Parameters) { environment.Declare(param.Identifier); current.Locals++; passByVar[name].Add(param.IsRef); } stmt.Body.Accept(this); wasm.addFunction(current); environment.ExitInner(); return(null); }
public object VisitFunctionStatement(Statement.Function statement) { Declare(statement.name); Define(statement.name); ResolveFunction(statement); return(null); }
public object VisitFunctionStatement(Statement.Function statement) { Function function = new Function(statement, environment); environment.Define(statement.name.lexeme, function); return(null); }
public object VisitFunctionStatement(Statement.Function stmt) { // todo params? foreach (var param in stmt.Parameters) { param.Accept(this); } return(stmt.Body.Accept(this)); }
private void ResolveFunction(Statement.Function function) { BeginScope(); foreach (Token parameter in function.parameters) { Define(parameter); Define(parameter); } Resolve(function.body); EndScope(); }
Expr IStatementVisitor <Expr> .Visit(Statement.Function statement) { // Rewrite AST to its desugared state // function a:b (params) body end -> function a.b (self, params) body end if (statement.Name.Table != null) { statement.Body.Parameters.Insert(0, "self"); statement.Name.Identifiers.Add(statement.Name.Table); statement.Name.Table = null; } var bodyExpr = Visit(statement.Name.Identifiers.Last(), statement.Body); return(AssignToIdentifierList(statement.Name.Identifiers, bodyExpr)); }
public Function(Statement.Function declaration, Environment closure) { this.declaration = declaration; this.closure = closure; }