ScopeManager
Defined in: packages/engine/src/vm/ScopeManager.ts:24
Scoped variable manager for expression evaluation.
Tracks variable definitions across line numbers with write-on-read semantics. When a value is read, the most recent definition at or before the reading line is returned. Invalidation trims downstream definitions when a variable is redefined.
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new ScopeManager(): ScopeManager;Returns
Section titled “Returns”ScopeManager
Methods
Section titled “Methods”clear()
Section titled “clear()”clear(): void;Defined in: packages/engine/src/vm/ScopeManager.ts:74
Remove every tracked variable definition, used when an engine/document is reset.
Returns
Section titled “Returns”void
invalidateDownstream()
Section titled “invalidateDownstream()”invalidateDownstream(variable, definitionLine): void;Defined in: packages/engine/src/vm/ScopeManager.ts:65
Drop every definition of variable that comes strictly after
definitionLine. Call this when a line is re-evaluated with a new
definition, so stale later-line definitions from a previous edit don’t
linger and get returned by read.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
variable | string |
definitionLine | number |
Returns
Section titled “Returns”void
read()
Section titled “read()”read(variable, readLine): Value | undefined;Defined in: packages/engine/src/vm/ScopeManager.ts:50
Look up a variable’s value as seen from readLine: returns the result
of the closest definition at or before readLine, not simply the most
recently-written one, so a read on line 5 of a variable redefined on
lines 2 and 10 sees line 2’s value, not line 10’s. Returns undefined
if the variable has no definition at or before readLine.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
variable | string |
readLine | number |
Returns
Section titled “Returns”Value | undefined
write()
Section titled “write()”write( variable, lineNumber, expr): void;Defined in: packages/engine/src/vm/ScopeManager.ts:34
Record a variable definition at lineNumber. A variable may have
multiple definitions across different lines (e.g. redefined further
down a document), each call adds one, keeping the internal stack
sorted by line so read can binary-scan for “most recent
definition at or before” a given line.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
variable | string |
lineNumber | number |
expr | ExpressionRecord |
Returns
Section titled “Returns”void