Ejemplo n.º 1
0
        public Void Visit_FunctionStmt(FunctionStmt stmt)
        {
            LoxFunction function = new LoxFunction(stmt, _environment);

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

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

            return(null);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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());
        }
Ejemplo n.º 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;
        }
Ejemplo n.º 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;
        }
Ejemplo n.º 8
0
 public LoxFunction(FunctionStmt declaration, Environment closure, bool isInitializer = false)
 {
     _declaration   = declaration;
     _closure       = closure;
     _isInitializer = isInitializer;
 }
Ejemplo n.º 9
0
 public LoxFunction(FunctionStmt declaration, Scope closure, bool isInitializer)
 {
     _declaration   = declaration;
     _closure       = closure;
     _isInitializer = isInitializer;
 }