MCPcopy Index your code
hub / github.com/endbasic/endbasic / put_var

Function put_var

core/src/compiler/syms.rs:126–145  ·  view source on GitHub ↗

Defines a new local or global variable (or array) and assigns a register to it. Panics if the symbol already exists.

(
    key: SymbolKey,
    proto: SymbolPrototype,
    table: &mut HashMapWithIds<SymbolKey, SymbolPrototype, u8>,
    make_register: MKR,
    scope: RegisterScope,
)

Source from the content-addressed store, hash-verified

124///
125/// Panics if the symbol already exists.
126fn put_var<MKR>(
127 key: SymbolKey,
128 proto: SymbolPrototype,
129 table: &mut HashMapWithIds<SymbolKey, SymbolPrototype, u8>,
130 make_register: MKR,
131 scope: RegisterScope,
132) -> Result<Register>
133where
134 MKR: FnOnce(u8) -> std::result::Result<Register, bytecode::OutOfRegistersError>,
135{
136 match table.insert(key, proto) {
137 Some((None, reg)) => Ok(make_register(reg).map_err(|_| Error::OutOfRegisters(scope))?),
138
139 Some((Some(_old_proto), _reg)) => {
140 unreachable!("Cannot redefine symbol; caller must check for presence first");
141 }
142
143 None => Err(Error::OutOfRegisters(scope)),
144 }
145}
146
147/// Representation of the symbol table for global symbols.
148///

Callers 2

put_globalMethod · 0.85
put_localMethod · 0.85

Calls 1

insertMethod · 0.45

Tested by

no test coverage detected