|
spudplate
Template scaffolding compiler for spudlang .spud files
|
Variable storage for a running interpreter. More...
#include <interpreter.h>
Public Member Functions | |
| Environment () | |
| Start with one program-level frame already on the stack. | |
| void | push () |
| Push a fresh frame for a nested scope (e.g. | |
| void | pop () |
| Pop the innermost frame, discarding any bindings it held. | |
| void | declare (const std::string &name, Value value) |
Bind name to value in the innermost frame. | |
| void | assign (const std::string &name, Value value) |
| Replace the value of an existing binding, innermost first. | |
| std::optional< Value > | lookup (const std::string &name) const |
Find name in any frame, innermost first. | |
Variable storage for a running interpreter.
Frame stack mirroring the validator's Scope shape (see src/validator.cpp). frames[0] is the program-level scope. Each repeat body pushes a new frame on entry and pops it on exit.
Exposed in the public header solely so tests can observe the final environment after a run; production code should not depend on this type.
|
inline |
Push a fresh frame for a nested scope (e.g.
repeat body).
| void spudplate::Environment::declare | ( | const std::string & | name, |
| Value | value | ||
| ) |
Bind name to value in the innermost frame.
Throws std::logic_error if name is already visible in any frame - the language never silently shadows.
| void spudplate::Environment::assign | ( | const std::string & | name, |
| Value | value | ||
| ) |
Replace the value of an existing binding, innermost first.
Throws std::logic_error if name is not visible - the validator is expected to have rejected such inputs before the interpreter runs.