public MyVoid VisitFunctionStmt(Stmt.Function stmt)
        {
            declare(stmt.name);
            define(stmt.name);

            resolveFunction(stmt, FunctionType.Function);
            return(null);
        }
Esempio n. 2
0
        public MyVoid VisitFunctionStmt(Stmt.Function stmt)
        {
            // Capture the environment when the function is declared, for closures
            LoxFunction function = new LoxFunction(stmt, environment, isInitializer: false);

            environment.Define(stmt.name.lexeme, function);
            return(null);
        }
        private void resolveFunction(Stmt.Function function, FunctionType functionType)
        {
            FunctionType enclosingFunction = currentFunction;

            currentFunction = functionType;

            beginScope();
            foreach (Token param in function.parameters)
            {
                declare(param);
                define(param);
            }
            resolve(function.body);
            endScope();

            currentFunction = enclosingFunction;
        }
 public LoxFunction(Stmt.Function declaration, VariableEnvironment closure, Boolean isInitializer)
 {
     this.closure       = closure;
     this.declaration   = declaration;
     this.isInitializer = isInitializer;
 }