Branch: slice/S.8a. Commit only there; never to trunk.
Read first:
docs/phases/S-small-targets.md, slice S.8: what the tree is for, and the RAM estimate this arena has to meet.src/glint/shell/matcher.cr: the style for code that runs both in the image and on Linux: integers, pointers andStaticArraylocals, noArray,Stringbuilding, classes ornewof a reference type.docs/phases/P-parser.md, P.4b: aStaticArrayconstant is filled by a start-up initialiser that firmware never runs. The arena must be a value the caller owns (a local or a field), never a constant.
Claim. S.8's program tree lives in a fixed arena of small nodes that needs no heap, so its RAM cost is a number known at compile time.
Passage. S.8's own finding: "Glint's heap (3.4) takes whole 4 KiB pages,
a quarter of the Zepto's RAM each. The tree needs a fixed arena that is
emptied after each line or after emit, with a stated node limit."
Make: src/glint/shell/tree.cr, module Glint::Shell::Tree.
Node, astructof exactly 12 bytes:kind : UInt8, one spare byte, three child indicesa,b,c : UInt16, andvalue : Int32.NONE = 0xFFFF_u16means no child.- The kinds this first set needs, as
UInt8constants with a comment each saying which fields they use:INT(value),LOCAL(value = slot 0–7),ASSIGN(value = slot, a = expression),ADD,SUB,LT(a, b),IF(a = condition, b = then, c = else orNONE),WHILE(a = condition, b = body),SEQ(a, b: evaluate a, then b, the result is b's). Arena(N), astructholdingStaticArray(Node, N)and a count.add(kind, a, b, c, value) : UInt16returns the new index, orNONEwhen full, writing nothing. It also returnsNONE, writing nothing, when a child index is notNONEand not an index already added, so a tree can only point backwards and can't loop.[](index),size,capacityandclear. Nothing else.- Constructors for each kind (
int(value),add(a, b),if_(c, t, e)and so on), each a one-line call toadd, so specs and S.8c read as the tree they build.
spec/shell/tree_spec.cr checks:
sizeof(Glint::Shell::Tree::Node) == 12, and anArena(256)is at most 3,080 bytes (256 × 12 plus the count, padded): 3 KiB of the 16.- Building the tree for
x = 0; while x < 10; x = x + 3; end; xgives the indices and fields the spec spells out. - A full arena returns
NONEand its size doesn't change; a forward or out-of-range child returnsNONE;clearempties it and the nextaddreturns 0.
Constraints. No Array, Hash, String building, Pointer.malloc,
classes, exceptions or constants of StaticArray. Nothing in the image
requires it yet, so image sizes are unchanged. crystal tool format --check
passes. Report the line counts.