public MyVoid VisitVarStmt(Stmt.Var stmt) { object value = null; if (stmt.initializer != null) { value = Evaluate(stmt.initializer); } environment.Define(stmt.name.lexeme, value); return(null); }
public LoxFunction Bind(LoxInstance instance) { VariableEnvironment environment = new VariableEnvironment(closure); environment.Define("this", instance); return(new LoxFunction(declaration, environment, isInitializer)); }
public object Call(Interpreter interpreter, List <object> arguments) { VariableEnvironment environment = new VariableEnvironment(closure); for (int i = 0; i < declaration.parameters.Count; i++) { environment.Define(declaration.parameters[i].lexeme, arguments[i]); } try { interpreter.ExecuteBlock(declaration.body, environment); } catch (Return returnValue) { // Allow an empty return ("return;") in a constructor. When this happens, return "this". if (isInitializer) { return(closure.GetAt(0, "this")); } return(returnValue.value); } return(null); }
public Interpreter() { this.globals = new VariableEnvironment(); this.environment = globals; //Define built-in function to get the time in milliseconds globals.Define("clock", new ClockFn()); }