diff options
Diffstat (limited to 'src/com/craftinginterpreters/lox/Interpreter.java')
-rw-r--r-- | src/com/craftinginterpreters/lox/Interpreter.java | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/com/craftinginterpreters/lox/Interpreter.java b/src/com/craftinginterpreters/lox/Interpreter.java index 5c1ea50..fd13455 100644 --- a/src/com/craftinginterpreters/lox/Interpreter.java +++ b/src/com/craftinginterpreters/lox/Interpreter.java @@ -177,7 +177,14 @@ class Interpreter implements Expr.Visitor<Object>, Stmt.Visitor<Void> { @Override public Void visitClassStmt(Stmt.Class stmt) { environment.define(stmt.name.lexeme, null); - LoxClass klass = new LoxClass(stmt.name.lexeme); + + Map<String, LoxFunction> methods = new HashMap<>(); + for (Stmt.Function method : stmt.methods) { + LoxFunction function = new LoxFunction(method, environment); + methods.put(method.name.lexeme, function); + } + + LoxClass klass = new LoxClass(stmt.name.lexeme, methods); environment.assign(stmt.name, klass); return null; } |