public object VisitFunctionStmt(Stmt.Function stmt) { var function = new LoxFunction(stmt, _environment, false); _environment.Define(stmt.Name.Lexeme, function); return(null); }
public string VisitFunctionStmt(Stmt.Function stmt) { var builder = new StringBuilder(); builder.Append("(fun " + stmt.Name.Lexeme + "("); foreach (var param in stmt.Parameters) { if (param != stmt.Parameters[0]) { builder.Append(" "); } builder.Append(param.Lexeme); } builder.Append(") "); foreach (var body in stmt.Body) { builder.Append(body.Accept(this)); } builder.Append(")"); return(builder.ToString()); }
public object VisitFunctionStmt(Stmt.Function stmt) { Declare(stmt.Name); Define(stmt.Name); ResolveFunction(stmt, FunctionType.FUNCTION); return(null); }
private void ResolveFunction(Stmt.Function function, FunctionType type) { var enclosingFunction = _currentFunction; _currentFunction = type; BeginScope(); foreach (var param in function.Parameters) { Declare(param); Define(param); } Resolve(function.Body); EndScope(); _currentFunction = enclosingFunction; }
public LoxFunction(Stmt.Function declaration, EnvironmentScope closure, bool isInitializer) { _declaration = declaration; _closure = closure; _isInitializer = isInitializer; }