Next: , Previous: , Up: Instruction Set   [Contents][Index]


9.3.7.2 Top-Level Environment Instructions

These instructions access values in the top-level environment: bindings that were not lexically apparent at the time that the code in question was compiled.

The location in which a toplevel binding is stored can be looked up once and cached for later. The binding itself may change over time, but its location will stay constant.

Instruction: current-module u24:dst

Store the current module in dst.

Instruction: resolve u24:dst b1:bound? x7:_ u24:sym

Resolve sym in the current module, and place the resulting variable in dst. An error will be signalled if no variable is found. If bound? is true, an error will be signalled if the variable is unbound.

Instruction: define! u12:sym u12:val

Look up a binding for sym in the current module, creating it if necessary. Set its value to val.

Instruction: toplevel-box u24:dst s32:var-offset s32:mod-offset n32:sym-offset b1:bound? x31:_

Load a value. The value will be fetched from memory, var-offset 32-bit words away from the current instruction pointer. var-offset is a signed value. Up to here, toplevel-box is like static-ref.

Then, if the loaded value is a variable, it is placed in dst, and control flow continues.

Otherwise, we have to resolve the variable. In that case we load the module from mod-offset, just as we loaded the variable. Usually the module gets set when the closure is created. sym-offset specifies the name, as an offset to a symbol.

We use the module and the symbol to resolve the variable, placing it in dst, and caching the resolved variable so that we will hit the cache next time. If bound? is true, an error will be signalled if the variable is unbound.

Instruction: module-box u24:dst s32:var-offset n32:mod-offset n32:sym-offset b1:bound? x31:_

Like toplevel-box, except mod-offset points at a module identifier instead of the module itself. A module identifier is a module name, as a list, prefixed by a boolean. If the prefix is true, then the variable is resolved relative to the module’s public interface instead of its private interface.


Next: , Previous: , Up: Instruction Set   [Contents][Index]