internal LoxFunction bind(LoxInstance instance) { Envir envir = new Envir(Closure); envir.define("this", instance); return(new LoxFunction(Declaration, envir, IsInitializer)); }
public LoxFunction Bind(LoxInstance instance) { Env env = new Env(closure); env.Define("this", instance); return(new LoxFunction(declaration, env, isInitializer)); }
public object Call(Interpreter interpreter, List <object> args) { LoxInstance instance = new LoxInstance(this); LoxFunction initializer = FindMethod("init"); if (initializer != null) { initializer.Bind(instance).Call(interpreter, args); } return(instance); }
public object visitSuperExpr(Expr.Super expr) { int distance = locals[expr]; LoxClass superClass = (LoxClass)env.getAt( distance, "super"); LoxInstance instance = (LoxInstance)env.getAt( distance - 1, "this"); LoxFunction method = superClass.findMethod(expr.Method.Lexeme); if (method == null) { throw new RuntimeError(expr.Method, $"Undefined propert '{expr.Method.Lexeme}'"); } return(method.bind(instance)); }