nifstreams

Search:
Group by:
Source   Edit  

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

FloatId = distinct uint32
1-based index into the global float pool Source   Edit  
FloatPool = object
Source   Edit  
IntegersProxy = object
Source   Edit  
IntId = distinct int64
value carriers (nifcore stores inline) Source   Edit  
PackedToken = NifToken
ast2nif still says PackedToken Source   Edit  
Stream = object
  r*: Reader
Source   Edit  
UIntegersProxy = object
Source   Edit  
UIntId = distinct uint64
Source   Edit  

Vars

lineMan: LineInfoManager
The classic packed line-info side channel (pool.man). Frontend code no longer uses it — it lives here purely for ast2nif's writer, which packs TLineInfo into PackedLineInfo and unpacks on emit. Source   Edit  

Procs

func `==`(a, b: FloatId): bool {.borrow, ...raises: [], tags: [], forbids: [].}
Source   Edit  
func `==`(a, b: IntId): bool {.borrow, ...raises: [], tags: [], forbids: [].}
Source   Edit  
func `==`(a, b: UIntId): bool {.borrow, ...raises: [], tags: [], forbids: [].}
Source   Edit  
proc `[]`(fp: FloatPool; id: FloatId): float64 {.inline, ...raises: [], tags: [],
    forbids: [].}
Source   Edit  
proc addIntLit(dest: var TokenBuf; id: IntId; info: PackedLineInfo) {.
    ...raises: [], tags: [], forbids: [].}
Source   Edit  
proc charToken(ch: char; info: PackedLineInfo): NifToken {.inline, ...raises: [],
    tags: [], forbids: [].}
Source   Edit  
proc close(s: var Stream) {....raises: [Exception], tags: [RootEffect], forbids: [].}
Source   Edit  
proc dotToken(info: PackedLineInfo): NifToken {.inline, ...raises: [], tags: [],
    forbids: [].}
Source   Edit  
proc firstSon(n: Cursor): Cursor {.inline, ...raises: [], tags: [], forbids: [].}
Source   Edit  
proc floatId(n: NifToken): FloatId {.inline, ...raises: [], tags: [], forbids: [].}
Source   Edit  
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 getOrIncl(fp: var FloatPool; v: float64): FloatId {....raises: [], tags: [],
    forbids: [].}
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 intId(c: Cursor): IntId {.inline, ...raises: [], tags: [], forbids: [].}
Source   Edit  
proc intId(n: NifToken): IntId {.inline, ...raises: [], tags: [], forbids: [].}
Source   Edit  
proc litId(c: Cursor): StrId {.inline, ...raises: [], tags: [], forbids: [].}
Source   Edit  
proc litId(n: NifToken): StrId {.inline, ...raises: [], tags: [], forbids: [].}
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 open(filename: string): Stream {....raises: [ValueError], tags: [RootEffect],
                                      forbids: [].}
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 strToken(s: StrId; info: PackedLineInfo): NifToken {.inline, ...raises: [],
    tags: [], forbids: [].}
Source   Edit  
proc symId(n: NifToken): SymId {.inline, ...raises: [], tags: [], forbids: [].}
Source   Edit  
proc symToken(id: SymId; info: PackedLineInfo): NifToken {.inline, ...raises: [],
    tags: [], forbids: [].}
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  
proc uintId(c: Cursor): UIntId {.inline, ...raises: [], tags: [], forbids: [].}
Source   Edit  
proc uintId(n: NifToken): UIntId {.inline, ...raises: [], tags: [], forbids: [].}
Source   Edit  

Templates

template `[]`(x: IntegersProxy; id: IntId): int64
Source   Edit  
template `[]`(x: UIntegersProxy; id: UIntId): uint64
Source   Edit  
template files(p: Pool): untyped
Source   Edit  
template floats(p: Pool): var FloatPool
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 man(p: Pool): untyped
Source   Edit  
template tags(p: Pool): untyped
Source   Edit  
template uintegers(p: Pool): UIntegersProxy
Source   Edit