public LoxFunction Bind(LoxInstance instance) { var environment = new EnvironmentScope(_closure); environment.Define("this", instance); return(new LoxFunction(_declaration, environment, _isInitializer)); }
public object Call(Interpreter interpreter, List <object> arguments) { var instance = new LoxInstance(this); if (_methods.TryGetValue("init", out var init)) { init.Bind(instance).Call(interpreter, arguments); } return(instance); }
public LoxFunction FindMethod(LoxInstance instance, string name) { if (_methods.TryGetValue(name, out var value)) { return(value.Bind(instance)); } if (_superclass != null) { return(_superclass.FindMethod(instance, name)); } return(null); }