comptime VM: Phase 3 — type_kind + type_field_value readers (read side complete)

The last two read-only readers the metatype's type_info(T) needs, each backed by
a TypeTable query both the legacy handler and the VM call (no drift):

  type_kind(t: TypeId) -> i64            (kindCode; stable discriminant, total — never bails)
  type_field_value(t: TypeId, idx) -> i64 (memberValue; enum explicit value or ordinal)

kindCode codes (compiler-owned, stable): 0 other / 1 struct / 2 enum /
3 tagged_union / 4 tuple / 5 union / 6 array / 7 vector / 8 error_set.

With these, the READ side is complete: find_type + type_kind + type_field_count +
type_field_{name,type} + type_nominal_name + type_field_value cover everything
reflectTypeInfo reads — a comptime sx fn can fully reflect a struct/enum/tuple
into data with no #builtin.

Example 0630 reflects Color / WindowFlags(flags) / Point. VM unit test added.

Revised forward direction: the write side will be ONE register_type(info) fn that
branches on the kind in the compiler (subsuming define's per-kind dispatch), not a
per-kind register_struct.

Parity 691/691 (gate OFF and -Dcomptime-flat).
This commit is contained in:
agra
2026-06-18 09:47:23 +03:00
parent d23e208430
commit 27bc301651
10 changed files with 252 additions and 29 deletions

View File

@@ -1067,6 +1067,19 @@ pub const Vm = struct {
return self.failMsg("comptime type_field_type: out-of-range idx or member has no type");
return @as(Reg, mty.index());
}
if (std.mem.eql(u8, name, "type_kind")) {
if (args.len != 1) return self.failMsg("comptime type_kind: expected one TypeId arg");
const tid = try self.argTypeId(args, frame, 0);
return @as(Reg, @bitCast(table.kindCode(tid))); // total — never bails
}
if (std.mem.eql(u8, name, "type_field_value")) {
if (args.len != 2) return self.failMsg("comptime type_field_value: expected (TypeId, idx)");
const tid = try self.argTypeId(args, frame, 0);
const idx: i64 = @bitCast(frame.get(args[1].index()));
const v = table.memberValue(tid, idx) orelse
return self.failMsg("comptime type_field_value: non-enum or out-of-range idx");
return @as(Reg, @bitCast(v));
}
return null; // not a known compiler function → caller bails to legacy
}