public object call(Interpreter interpreter, List <object> arguments) { Instance instance = new Instance(this); JingleFunc initializer = findMethod("init"); if (initializer != null) { initializer.bind(instance).call(interpreter, arguments); } return(instance); }
public object get(Token name) { if (fields.ContainsKey(name.lexeme)) { return(fields[name.lexeme]); } JingleFunc method = jnclass.findMethod(name.lexeme); if (method != null) { return(method.bind(this)); } throw new RuntimeError(name, "Undefined property '" + name.lexeme + "'."); }
public object visitSuperExpr(Expr.Super expr) { int distance = locals[expr]; JingleClass superclass = (JingleClass)environment.getAt(distance, "super"); Instance object_ = (Instance)environment.getAt(distance - 1, "this"); JingleFunc method = superclass.findMethod(expr.method.lexeme); if (method == null) { throw new RuntimeError(expr.method, "Undefined property '" + expr.method.lexeme + "'."); } return(method.bind(object_)); }