meta.mx raw
1 package iskra
2
3 // NodeKind classifies code constructs as a bitfield.
4 type NodeKind uint16
5
6 const (
7 KindUnknown NodeKind = 0
8 KindPkg NodeKind = 1 << 0
9 KindImport NodeKind = 1 << 1
10 KindConst NodeKind = 1 << 2
11 KindVar NodeKind = 1 << 3
12 KindType NodeKind = 1 << 4
13 KindFunc NodeKind = 1 << 5
14 KindMethod NodeKind = 1 << 6
15 KindField NodeKind = 1 << 7
16 KindStmt NodeKind = 1 << 8
17 KindExpr NodeKind = 1 << 9
18 KindControl NodeKind = 1 << 10
19 KindLiteral NodeKind = 1 << 11
20 )
21
22 func (k NodeKind) Has(tag NodeKind) bool { return k&tag != 0 }
23 func (k NodeKind) IsKnown() bool { return k != KindUnknown }
24
25 // MetaEntry is per-record semantic metadata, indexed by record index in Tree.RecMeta.
26 // AdjCount/AdjOffset removed: cross-stage adjacency is key-implicit (same hash,
27 // different stage prefix); cross-branch adjacency is in Record.Link[2].
28 //
29 // Extra layout:
30 // [0:4] TritPath (uint32)
31 // [4] low nibble: Rotation
32 // [5:8] signature hash (24-bit, fast rejection)
33 // [8:12] ContentOffset into Tree.TokenPool
34 // [12:16] ContentLen (token count)
35 type MetaEntry struct {
36 Count uint32
37 Kind NodeKind
38 StageTag uint8
39 _pad [9]byte
40 Extra [16]byte
41 }
42
43 func (m *MetaEntry) ContentOffset() uint32 {
44 return uint32(m.Extra[8]) |
45 uint32(m.Extra[9])<<8 |
46 uint32(m.Extra[10])<<16 |
47 uint32(m.Extra[11])<<24
48 }
49
50 func (m *MetaEntry) ContentLen() uint32 {
51 return uint32(m.Extra[12]) |
52 uint32(m.Extra[13])<<8 |
53 uint32(m.Extra[14])<<16 |
54 uint32(m.Extra[15])<<24
55 }
56
57 func (m *MetaEntry) SetContentRef(offset, length uint32) {
58 m.Extra[8] = byte(offset)
59 m.Extra[9] = byte(offset >> 8)
60 m.Extra[10] = byte(offset >> 16)
61 m.Extra[11] = byte(offset >> 24)
62 m.Extra[12] = byte(length)
63 m.Extra[13] = byte(length >> 8)
64 m.Extra[14] = byte(length >> 16)
65 m.Extra[15] = byte(length >> 24)
66 }
67
68 func (m *MetaEntry) SigHash() uint32 {
69 return uint32(m.Extra[5]) |
70 uint32(m.Extra[6])<<8 |
71 uint32(m.Extra[7])<<16
72 }
73
74 func (m *MetaEntry) SetSigHash(h uint32) {
75 m.Extra[5] = byte(h)
76 m.Extra[6] = byte(h >> 8)
77 m.Extra[7] = byte(h >> 16)
78 }
79