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,
)
| 124 | /// |
| 125 | /// Panics if the symbol already exists. |
| 126 | fn 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> |
| 133 | where |
| 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 | /// |
no test coverage detected