comptime VM: Phase 3 — field-level reflection readers
Three more read-only compiler-API readers on the TypeId-handle shape, each backed
by a new TypeTable query that both the legacy handler and the VM call (no drift):
type_nominal_name(t: TypeId) -> StringId (nominalName; loud-bail for unnamed types)
type_field_name(t: TypeId, idx: i64) -> StringId (memberName)
type_field_type(t: TypeId, idx: i64) -> TypeId (memberType)
All loud-bail on out-of-range idx / no-member — no silent default. First multi-arg
compiler fns (callCompilerFn now reads arg 1 = idx); added Vm.argHandle/argTypeId
range-checked arg readers and moved find_type/type_field_count onto them. Names use
the type_* family to avoid colliding with the std metatype builtins (field_name /
type_name in core.sx); the new TypeTable.nominalName is distinct from the existing
typeName(id) display-string renderer.
Example 0629 reflects Pair { lo: Point; hi: Point } — each field name + the nominal
name of a field's type, #run-folded, VM-HANDLED natively. VM unit test added.
Parity 690/690 (gate OFF and -Dcomptime-flat).
This commit is contained in:
@@ -275,13 +275,27 @@ host through it:
|
||||
marker (see CLAUDE.md REJECTED PATTERNS — a dedicated sentinel is the required shape),
|
||||
so the caller checks the handle against 0. This keeps the reader a clean scalar mirror
|
||||
of `intern`/`text_of` and defers `.any`/optional plumbing to when it's actually needed.
|
||||
- **Next (P3.2):** more read-only readers on the same `TypeId`-handle shape (`type_name(t)
|
||||
-> StringId`, `field_name(t, i) -> StringId`, `field_type(t, i) -> TypeId`, kind queries),
|
||||
then `register_struct` (the first MUTATING fn — mints a `TypeId`; resolve the mutable-table
|
||||
/ host-ABI-vs-target-ABI boundary deliberately, per the open questions). Re-expressing
|
||||
`declare`/`define`/`type_info` as sx (the metatype, which runs at LOWERING time) still
|
||||
needs the VM hardened against malformed lowering-time IR first — keep that on the legacy
|
||||
path until then (see the resume note in CHECKPOINT-COMPILER-API.md).
|
||||
- **(P3.2) Field-level reflection readers — `type_nominal_name` + `type_field_name` +
|
||||
`type_field_type` (DONE).** Three more readers on the same `TypeId`-handle shape (each
|
||||
backed by a new `TypeTable` query that BOTH the legacy handler and the VM call, so no
|
||||
drift): `type_nominal_name(t: TypeId) -> StringId` (`nominalName` — a named type's own
|
||||
name; loud-bail for unnamed types), `type_field_name(t: TypeId, idx: i64) -> StringId`
|
||||
(`memberName` — struct/union/tagged-union field, enum variant, named-tuple element), and
|
||||
`type_field_type(t: TypeId, idx: i64) -> TypeId` (`memberType` — struct/tuple/array/vector
|
||||
member type). All loud-bail on out-of-range idx / no-member (no silent default). These are
|
||||
the first MULTI-ARG compiler fns (the VM's `callCompilerFn` now reads arg 1 = idx); added
|
||||
`Vm.argHandle`/`argTypeId` helpers (range-checked u32/TypeId arg reads). Naming uses the
|
||||
`type_*` family so nothing collides with the std metatype builtins (`field_name`/`type_name`
|
||||
exist in `core.sx`). Example `0629` reflects `Pair { lo: Point; hi: Point }` — reads each
|
||||
field name and the nominal name of a field's type, all folded at `#run`, all VM-HANDLED
|
||||
natively. Parity **690/690** (gate ON and OFF); VM unit test added.
|
||||
- **Next (P3.3):** `register_struct` (the first MUTATING fn — mints a `TypeId`; resolve the
|
||||
mutable-table / host-ABI-vs-target-ABI boundary deliberately, per the open questions),
|
||||
plus any remaining read-only readers needed to re-express the metatype (kind query,
|
||||
`field_value_int` for enums). Re-expressing `declare`/`define`/`type_info` as sx (the
|
||||
metatype, which runs at LOWERING time) still needs the VM hardened against malformed
|
||||
lowering-time IR first — keep that on the legacy path until then (see the resume note in
|
||||
CHECKPOINT-COMPILER-API.md).
|
||||
|
||||
### Phase 3 — Compiler-API on flat memory (resume the stream — no weld)
|
||||
With native-byte comptime values, re-home the compiler-API:
|
||||
|
||||
Reference in New Issue
Block a user