Documentation
¶
Overview ¶
Package enumrt provides the runtime glue the bytecode generator emits calls into when lowering an `enum` declaration. It installs ONE global helper, `__enum_freeze(table, name) -> table`, that:
- attaches an `__newindex` metamethod which raises "attempt to modify enum '<name>'" when anyone assigns into the table (preserving the "enum values are constants" contract), and
- sets `__metatable = "enum"` so that `setmetatable`/`getmetatable` can't subvert (1) by swapping the metatable out.
The double-underscore name is deliberately ugly — this is a compiler emit target, not a user-facing API. Adding a real user-facing `table.freeze` is a follow-up; the surface we need here is narrower.
Registration mirrors every other native module (a single function pushed onto cmd/natives.go::nativeRegistrars), but enumrt installs the helper directly on Globals rather than under `package.preload` — the bytecode generator emits an unconditional `GetGlobal "__enum_freeze"`, so it must be present before any user code runs, not loaded on first `require`.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RegisterEnumRT ¶
RegisterEnumRT installs __enum_freeze and __enum_adt on the VM's globals. Idempotent — calling it twice replaces the bindings with the same functions, matching how the other registrars behave when the REPL replays them on :reset.
Types ¶
This section is empty.