public override object Call(AstInterpreter interpreter, IEnumerable <object> arguments) { var environment = new Environment(closure); foreach (var parameter in declaration.Parameters.Enumerate()) { environment.Define(parameter.Value, arguments.ElementAt(parameter.Index)); } try { interpreter.ExecuteBlock(declaration.Body, environment); } catch (LoxReturn returnValue) { return(isInitializer ? InstanceReference : returnValue.Value); } if (isInitializer) { return(InstanceReference); } return(null); }
public override object Call(AstInterpreter interpreter, IEnumerable <object> arguments) { var instance = new LoxInstance(this); Constructor?.Bind(instance).Call(interpreter, arguments); return(instance); }
public virtual object Call(AstInterpreter interpreter, IEnumerable <object> arguments) { throw new NotImplementedException(); }