nifstreams — the classic NIF streaming surface, used ONLY by this compiler's IC modules: ast2nif, deps, modulegraphs and pipelines import it and must keep compiling unchanged across nimony's own refactorings.
It used to live in dist/nimony/src/lib, which is where the rest of the NIF stack still is. It does not belong there: nimony's own code imports nifpools (via nifprelude) and is under standing orders never to import this file, so nothing over there ever exercised it — which is exactly how it came to hand out TagLit where every caller here tests for ParLe (see next), silently emptying the IC build graph. A compatibility shim with exactly one consumer belongs in the consumer's repo, where its tests run and its contract is somebody's problem.
Everything it adapts (nifpools, nifreader, lineinfos) still comes from dist/nimony; only the adapter moved.
Everything here is an honest adapter, not a fake:
- Floats get a REAL interning pool: pool.floats.getOrIncl returns a FloatId index, floatToken packs it into a genuine FloatLit NifToken (transit-only: it must never enter a TokenBuf, whose float encoding is inline multi-token), and pool.floats[t.floatId] decodes it — lossless.
- Stream/next wrap the textual nifreader; the unified NifKind has real ParLe/ParRi/EofToken members, so structural scanners (deps.nim) see the exact classic kinds. Ident/StringLit/Symbol payloads are interned into the global pool, so pool.strings[t.litId] works as before. Number tokens keep their KIND only (a 4-byte token cannot always carry the value); classic scanners never read those payloads.
Types
IntegersProxy = object
- Source Edit
PackedToken = NifToken
- ast2nif still says PackedToken Source Edit
UIntegersProxy = object
- Source Edit
Procs
proc floatToken(id: FloatId; info: PackedLineInfo): NifToken {.inline, ...raises: [], tags: [], forbids: [].}
- Transit-only token: carries the pool index so the receiver can decode it via pool.floats[t.floatId]. It must never be appended to a TokenBuf (nifcore stores floats inline as a multi-token encoding); the line info is dropped like in the other classic token constructors. Source Edit
proc identToken(id: StrId; info: PackedLineInfo): NifToken {.inline, ...raises: [], tags: [], forbids: [].}
- Source Edit
proc info(c: Cursor): PackedLineInfo {.inline, ...raises: [], tags: [], forbids: [].}
- Classic packed view of a cursor's line info (ast2nif shadows this with its own NifLineInfo template; kept for any other classic reader). Source Edit
proc info(n: NifToken): PackedLineInfo {.inline, ...raises: [], tags: [], forbids: [].}
- Classic tokens carried their line info inline; a bare 4-byte nifcore token cannot, so reading it back yields NoLineInfo (ast2nif's emitInfo(t.info) then emits nothing — matching the writer, which attaches real positions at the builder level instead). Source Edit
proc next(s: var Stream): NifToken {....raises: [], tags: [], forbids: [].}
- One classic packed token per call. Pool-referencing kinds are interned into the global pool/globalTags, so .litId/.tagId accessors and pool.strings[...]/pool.tags[...] lookups behave exactly as classic nifstreams did. Kinds without a pool payload come back kind-only. Source Edit
proc parLeToken(t: TagId): NifToken {.inline, ...raises: [], tags: [], forbids: [].}
- The classic surface's opening-tag token: kind ParLe, tag id in the payload. Transit-only, like floatToken — a ParLe never appears in a binary token stream, so this must not be appended to a TokenBuf. Source Edit
proc tagId(n: NifToken): TagId {.inline, ...raises: [], tags: [], forbids: [].}
- Classic ParLe tokens (see next) keep the tag id in the full 28-bit payload rather than in TagLit's 9-bit field: globalTags already holds 355 tags before the Nim compiler registers its own dialect, so a 512-tag ceiling is not a ceiling this surface can live under. Source Edit
Templates
template `[]`(x: IntegersProxy; id: IntId): int64
- Source Edit
template `[]`(x: UIntegersProxy; id: UIntId): uint64
- Source Edit
template getOrIncl(x: IntegersProxy; v: int64): IntId
- Source Edit
template getOrIncl(x: UIntegersProxy; v: uint64): UIntId
- Source Edit
template integers(p: Pool): IntegersProxy
- Source Edit
template uintegers(p: Pool): UIntegersProxy
- Source Edit