Nimony

The road to Nim 3

nifcore

nimony/src/lib/nifcore.nim

nifcore — in-memory NIF representation, builder, and cursor.

Design summary ==============

A NIF token is a distinct uint32 (4 bytes) with the kind in the low 4 bits and a 28-bit kind-specific payload above.

There is no separate ParLe / ParRi kind — a node is just a TagLit that carries (tag, jump), where jump counts the body tokens that follow. The matching close is implicit; iterators stop after consuming jump body tokens.

  TagLit payload (28 bits):
    [3..0]   kind = TagLit
    [12..4]  tag  (9 bits, 0..511)
    [31..13] jump (19 bits, 0..524287 body tokens)

Atom kinds (StrLit, IntLit, FloatLit, …) put a 28-bit pool id (or a small inline value, e.g. CharLit) in the payload.

ExtendedSuffix is the universal extension knob — one kind handles both literal overflow and jump overflow uniformly:

Atoms with wide payload: [P] StrLit(low28) [P+1] ExtendedSuffix(high28) ⇒ 56-bit combined id

TagLits with overflowing jump: [P] TagLit(tag, jumplow19) [P+1] ExtendedSuffix(jumphigh28) ⇒ 47-bit combined jump [P+2 .. P+1+combined_jump] body

Putting the extension after the kinded token means a cursor always lands on the kinded token; kind(c) is one load + one mask (no branch). The suffix is only consulted by the helpers that actually need extended bits (combinedPayload, cursorJump, tokenWidth).

Pool ownership is per-TokenBuf by default; pass sharedPool to createTokenBuf to thread the same intern tables through many trees.