Skip to main content

nomiscript/runtime/symbol/
rebind.rs

1//! What a unit that rebinds a special keeps so a host can tell, after a trap,
2//! which value the global holds outside every binding (plan 0014 PERSIST P11).
3
4use super::homes::locked;
5use super::table::SymbolTable;
6
7/// Exported i32 `depth` counts the dynamic bindings of a special in force;
8/// entering the outermost one stores the special's value in `outer` and its
9/// bound flag in `outer_bound`.
10#[derive(Clone, Copy, Debug, PartialEq, Eq)]
11pub struct Rebind {
12    pub depth: u32,
13    pub outer: u32,
14    pub outer_bound: u32,
15}
16
17impl SymbolTable {
18    /// The rebind globals of the special held in global `global`.
19    pub(crate) fn rebind_of(&self, global: u32) -> Option<Rebind> {
20        locked(&self.homes).rebinds.get(&global).copied()
21    }
22
23    pub(crate) fn note_rebind(&self, global: u32, rebind: Rebind) {
24        locked(&self.homes).rebinds.insert(global, rebind);
25    }
26}