Example #1
0
        public Void Visit_FunctionStmt(FunctionStmt stmt)
        {
            LoxFunction function = new LoxFunction(stmt, _environment);

            _environment.Define((string)stmt.name.value, function);
            return(null);
        }
Example #2
0
 public Void Visit_FunctionStmt(FunctionStmt stmt)
 {
     Declare(stmt.name);
     Define(stmt.name);
     ResolveFunction(stmt, FunctionType.Function);
     return(null);
 }
Example #3
0
        public object VisitFunctionStmt(FunctionStmt stmt)
        {
            var func = new LoxFunction(stmt, _scope, false);

            _scope.Define(stmt.Name.Lexeme, func);

            return(null);
        }
Example #4
0
        public object VisitFunctionStmt(FunctionStmt stmt)
        {
            // Defining the name before resolving the function
            // allows the function to refer to itself.
            Declare(stmt.Name);
            Define(stmt.Name);
            ResolveFunction(stmt, FunctionType.FUNCTION);

            return(null);
        }
Example #5
0
        public string Visit_FunctionStmt(FunctionStmt stmt)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("(FnDecl ");
            sb.Append("'" + (string)stmt.name.value + "'");
            sb.Append(' ');
            foreach (var item in stmt.parameters)
            {
                sb.Append("'" + (string)item.value + "'");
                sb.Append(' ');
            }
            sb.Append(Parenthesize("Body", stmt.body.ToArray()));
            sb.Append(')');
            return(sb.ToString());
        }
Example #6
0
        private void ResolveFunction(FunctionStmt func, FunctionType type)
        {
            var enclosingFuncType = _currentFuncType;

            _currentFuncType = type;

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

            _currentFuncType = enclosingFuncType;
        }
Example #7
0
        void ResolveFunction(FunctionStmt function, FunctionType functionType)
        {
            FunctionType enclosingFunctionType = _currentFunctionType;

            _currentFunctionType = functionType;

            BeginScope();
            foreach (var param in function.parameters)
            {
                Declare(param);
                Define(param);
            }
            Resolve(function.body);
            EndScope();

            _currentFunctionType = enclosingFunctionType;
        }
Example #8
0
 public LoxFunction(FunctionStmt declaration, Environment closure, bool isInitializer = false)
 {
     _declaration   = declaration;
     _closure       = closure;
     _isInitializer = isInitializer;
 }
Example #9
0
 public LoxFunction(FunctionStmt declaration, Scope closure, bool isInitializer)
 {
     _declaration   = declaration;
     _closure       = closure;
     _isInitializer = isInitializer;
 }