Functions 10
This commit is contained in:
parent
7f4946f1e9
commit
e9e3c992cb
4 changed files with 20 additions and 2 deletions
|
|
@ -10,11 +10,15 @@ import jlox.util;
|
|||
|
||||
class LoxFunction : LoxCallable{
|
||||
private Stmt.Function declaration;
|
||||
private Environment closure;
|
||||
mixin defaultCtor;
|
||||
invariant{
|
||||
assert(declaration && closure);
|
||||
}
|
||||
|
||||
int arity() => declaration.params.length.to!int;
|
||||
TValue call(Interpreter interpreter, TValue[] arguments){
|
||||
Environment environment = new Environment(interpreter.globals);
|
||||
Environment environment = new Environment(closure);
|
||||
foreach(i; 0 .. declaration.params.length)
|
||||
environment.define(declaration.params[i].lexeme, arguments[i]);
|
||||
try{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue