interactive: Don't leak temporaries into environment
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Mars |
Triaged
|
Wishlist
|
Matt Giuca |
Bug Description
The code for interactive is pretty weird at the moment. Currently, for each statement, it:
- Compiles the statement into a sequence of instructions, some assigning temporaries,
- Executes each instruction, one at a time. Assignments to locals go in the "interactive local environment",
- If the statement is an expression, prints out the value of the final temporary.
This has a few problems:
- The temporaries assigned by intermediate instructions (or the final instruction, if an expression statement) remain in the environment after the execution of the statement (this can be seen with :e),
- The code confuses temporaries with "user variables" (the actual variables the user is requesting be assigned).
The new LLVM backend can't keep a persistent "local environment" around, since local variables are actual machine registers. These "user variables" are quite different from both globals and locals, since they can be assigned, but need to persist (and their types can change, for example).
Therefore:
- Add a new kind of variable, a "user" variable (this involves adding a new alternative to ir.varname),
- When generating code in the interactive environment, temporaries should still be local, explicit variables should be user variables,
- The interpret backend should store *three* environments -- global, user and local. user and local should not be threaded through function calls. The local environment should not be part of the executor -- it does not persist across interactive statements.
- Change executor.exec_instr to exec_instrs, which takes a list of instrs, and executes them atomically. Local variables (i.e., temporaries) persist across the instruction sequence, but are destroyed afterwards.
Not important (wishlist, de-milestoning).