Skip to main content

Module scope

Module scope 

Source
Expand description

Helpers for the scope family of commands (scope variables, scope commands, …).

§How “what’s in scope” is collected

Permanent (global) bindings live on EngineState overlays. Nested parse scopes throw away their name maps on exit_scope, so two additional mechanisms recover locals:

  1. Variables — each Variable may store its name. ScopeData::collect_vars builds a name→id map from permanent overlays, then overwrites with stack-resident VarIds (outer→inner so the live binding wins). Non-const entries without a stack value are skipped (supports unlet). Permanent names without Variable.name still appear via overlays.

  2. Commands / aliases / externs / modules — parse snapshots ScopeBindings onto Block. At runtime:

    • Whole blocks (closures, custom commands) push bindings on Stack::active_scope_bindings in eval_ir_block.
    • Keyword bodies inlined into parent IR record ScopeRegions; scope includes regions that contain the current instruction index.

    ScopeData::populate_decls / ScopeData::populate_modules merge permanent overlays, then active whole-block bindings, then matching IR regions.

scope engine-stats intentionally reports only engine-wide counts and ignores locals.

Structs§

ScopeData
Collects name→id maps for the scope subcommands.

Functions§

find_builtin_decl
Find the first declaration with CommandType::Builtin whose name matches name, scanning from the most-recently registered declaration backwards.