enumrt

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 5, 2026 License: MIT Imports: 2 Imported by: 0

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:

  1. 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
  2. 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

func RegisterEnumRT(v *vm.VM)

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL