diff options
author | Tom Willemse | 2021-02-16 23:41:24 -0800 |
---|---|---|
committer | Tom Willemse | 2021-02-16 23:41:24 -0800 |
commit | e283991f902c38af8e6b5c6ae299911d120d8bcf (patch) | |
tree | c58270e72017eb70b677c8b7ffcbf8b8a04cfc80 /src/com/craftinginterpreters/lox/LoxFunction.java | |
parent | 0dbf155da52c5db1cab2688b04c87386a55c5d5b (diff) | |
download | crafting-interpreters-e283991f902c38af8e6b5c6ae299911d120d8bcf.tar.gz crafting-interpreters-e283991f902c38af8e6b5c6ae299911d120d8bcf.zip |
Add local functions and closures
Diffstat (limited to 'src/com/craftinginterpreters/lox/LoxFunction.java')
-rw-r--r-- | src/com/craftinginterpreters/lox/LoxFunction.java | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/src/com/craftinginterpreters/lox/LoxFunction.java b/src/com/craftinginterpreters/lox/LoxFunction.java index 0f7ebd4..fb3e8e3 100644 --- a/src/com/craftinginterpreters/lox/LoxFunction.java +++ b/src/com/craftinginterpreters/lox/LoxFunction.java @@ -4,8 +4,10 @@ import java.util.List; class LoxFunction implements LoxCallable { private final Stmt.Function declaration; + private final Environment closure; - LoxFunction(Stmt.Function declaration) { + LoxFunction(Stmt.Function declaration, Environment closure) { + this.closure = closure; this.declaration = declaration; } @@ -16,7 +18,7 @@ class LoxFunction implements LoxCallable { @Override public Object call(Interpreter interpreter, List<Object> arguments) { - Environment environment = new Environment(interpreter.globals); + Environment environment = new Environment(closure); for (int i = 0; i < declaration.params.size(); i++) { environment.define(declaration.params.get(i).lexeme, arguments.get(i)); |