Example #1
0
        public void Visit(Stmt.Function stmt)
        {
            Declare(stmt.name);
            Define(stmt.name);

            ResolveFunction(stmt, FunctionType.Function);
        }
Example #2
0
        private void ResolveFunction(Stmt.Function function, FunctionType type)
        {
            FunctionType enclosingFunction = currentFunction;

            currentFunction = type;

            BeginScope();

            foreach (Token param in function.parameters)
            {
                Declare(param);
                Define(param);
            }

            Resolve(function.body);

            EndScope();

            currentFunction = enclosingFunction;
        }
Example #3
0
        public void Visit(Stmt.Function stmt)
        {
            LoxFunction function = new LoxFunction(stmt, environment, false);

            environment.Define(stmt.name.lexeme, function);
        }
Example #4
0
 public LoxFunction(Stmt.Function declaration, Environment closure, bool isInitializer)
 {
     this.declaration   = declaration;
     this.closure       = closure;
     this.isInitializer = isInitializer;
 }