Example #1
0
        private object EvaluateFunctionStatement(FunctionStatement expr)
        {
            var function = new LoxFunction(expr, _environment, false);

            _environment.Define(expr.Name.Lexeme, function);
            return(null);
        }
Example #2
0
        private void ResolveFunction(FunctionStatement expr, FunctionType type)
        {
            var enclosingFunction = _currentFunction;

            _currentFunction = type;

            BeginScope();
            foreach (var param in expr.Parameters)
            {
                Declare(param);
                Define(param);
            }
            Resolve(expr.Body);
            EndScope();

            _currentFunction = enclosingFunction;
        }
Example #3
0
 public LoxFunction(FunctionStatement declaration, Environment closure, bool isInitializer)
 {
     _declaration   = declaration;
     _closure       = closure;
     _isInitializer = isInitializer;
 }
Example #4
0
 private void ResolveFunctionStatement(FunctionStatement expr)
 {
     Declare(expr.Name);
     Define(expr.Name);
     ResolveFunction(expr, FunctionType.Function);
 }