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

            environment.Define(stmt.name.Lexeme, function);
            return(null);
        }
Beispiel #2
0
 public Unit VisitFunction(Stmt.Function stmt)
 {
     Declare(stmt.Name);
     Define(stmt.Name);
     ResolveFunction(stmt, FunctionType.Function);
     return(Unit.Default);
 }
Beispiel #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);
        }
Beispiel #4
0
        public Void Visit(Stmt.Function stmt)
        {
            var function = new LoxFunction(stmt, environment, false);

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

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

            ResolveFunction(stmt, FunctionType.FUNCTION);
            return(null);
        }
Beispiel #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);
        }
Beispiel #7
0
        public Void Visit(Stmt.Function stmt)
        {
            Declare(stmt.Name);
            Define(stmt.Name);

            ResolveFunction(stmt, FunctionType.Function);

            return(Void.Instance);
        }
Beispiel #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;
        }
Beispiel #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;
        }
Beispiel #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());
        }
Beispiel #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;
        }
Beispiel #12
0
 public LoxFunction(Stmt.Function declaration, Environment closure, bool isInitializer)
 {
     this.isInitializer = isInitializer;
     this.closure       = closure;
     this.declaration   = declaration;
 }
Beispiel #13
0
 private void ResolveFunction(Stmt.Function stmt, FunctionType type)
 {
     ResolveFunction(type, stmt.Parameters, stmt.Body);
 }
Beispiel #14
0
 public LoxFunction(Stmt.Function declaration, Environment closure, bool isInitializer)
 {
     _declaration   = declaration;
     _closure       = closure;
     _isInitializer = isInitializer;
 }