Exemplo n.º 1
0
        public object VisitFunctionStmt(Stmt.Function stmt)
        {
            var function = new LoxFunction(stmt, environment, false);

            environment.Define(stmt.name.Lexeme, function);
            return(null);
        }
Exemplo n.º 2
0
 public Unit VisitFunction(Stmt.Function stmt)
 {
     Declare(stmt.Name);
     Define(stmt.Name);
     ResolveFunction(stmt, FunctionType.Function);
     return(Unit.Default);
 }
Exemplo n.º 3
0
        object Stmt.IVisitor <object> .VisitFunctionStmt(Stmt.Function stmt)
        {
            LoxFunction function = new LoxFunction(stmt, environment, false);

            environment.Define(stmt.name.lexeme, function);
            return(null);
        }
Exemplo n.º 4
0
        public Void Visit(Stmt.Function stmt)
        {
            var function = new LoxFunction(stmt, environment, false);

            environment.Define(stmt.Name.Lexeme, function);

            return(Void.Instance);
        }
Exemplo n.º 5
0
        object Stmt.IVisitor <object> .VisitFunctionStmt(Stmt.Function stmt)
        {
            Declare(stmt.name);
            Define(stmt.name);

            ResolveFunction(stmt, FunctionType.FUNCTION);
            return(null);
        }
Exemplo n.º 6
0
        public Unit VisitFunction(Stmt.Function stmt)
        {
            // Capture the environment at declaration time.
            string name     = string.Format("<fun {0}>", stmt.Name.Lexeme);
            var    function = new LoxFunction(name, _environment, stmt.Parameters, stmt.Body);

            _environment.Define(stmt.Name.Lexeme, function);
            return(Unit.Default);
        }
Exemplo n.º 7
0
        public Void Visit(Stmt.Function stmt)
        {
            Declare(stmt.Name);
            Define(stmt.Name);

            ResolveFunction(stmt, FunctionType.Function);

            return(Void.Instance);
        }
Exemplo n.º 8
0
        void ResolveFunction(Stmt.Function function, FunctionType type)
        {
            var enclosingFunction = currentFunction;

            currentFunction = type;
            BeginScope();
            function.parameters.ForEach(e =>
            {
                Declare(e);
                Define(e);
            });

            Resolve(function.Body);
            EndScope();
            currentFunction = enclosingFunction;
        }
Exemplo n.º 9
0
        private void ResolveFunction(Stmt.Function function, FunctionType type)
        {
            FunctionType enclosingFunction = currentFunction;

            currentFunction = type;

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

            currentFunction = enclosingFunction;
        }
Exemplo n.º 10
0
        public string VisitFunction(Stmt.Function stmt)
        {
            var builder = new StringBuilder();

            builder.Append("(fun (");
            builder.Append(stmt.Name.Lexeme);
            foreach (var param in stmt.Parameters)
            {
                builder.Append(" ");
                builder.Append(param.Lexeme);
            }

            builder.Append(")");
            foreach (var s in stmt.Body)
            {
                builder.Append(s.Accept(this));
            }
            return(builder.ToString());
        }
Exemplo n.º 11
0
        private void ResolveFunction(Stmt.Function function, FunctionType type)
        {
            var enclosingFunction = currentFunction;

            currentFunction = type;

            BeginScope();

            foreach (var param in function.Parameters)
            {
                Declare(param);
                Define(param);
            }

            Resolve(function.Body);

            EndScope();

            currentFunction = enclosingFunction;
        }
Exemplo n.º 12
0
 public LoxFunction(Stmt.Function declaration, Environment closure, bool isInitializer)
 {
     this.isInitializer = isInitializer;
     this.closure       = closure;
     this.declaration   = declaration;
 }
Exemplo n.º 13
0
 private void ResolveFunction(Stmt.Function stmt, FunctionType type)
 {
     ResolveFunction(type, stmt.Parameters, stmt.Body);
 }
Exemplo n.º 14
0
 public LoxFunction(Stmt.Function declaration, Environment closure, bool isInitializer)
 {
     _declaration   = declaration;
     _closure       = closure;
     _isInitializer = isInitializer;
 }