mirror of
https://github.com/zap-proto/nim.git
synced 2026-10-30 15:04:34 +00:00
Rename the capnp/ module set to zap/ and the capnpc compiler to zapc; rename all .capnp schemas and fixtures to .zap; update every import, include guard (isInZap), generated-code emission, exception type (ZapFormatError), and the macro-generated zapUnpackStructImpl/ zapPackStructImpl identifiers to the ZAP brand. Zero capnp/Cap'n Proto references remain in source or build files; upstream MIT attribution (Sandstorm, Michał Zieliński) is preserved. Raise the nimble nim floor from the fictional 0.12.0 to the locked, verified 0.15.2 (matches nimenv.cfg/build.sh; code carries fixes through Nim 0.18). Rewrite TODO.md as honest, source-anchored known-limitations (two-word intersegment pointers, nested/named-union codegen, RPC interface inheritance) instead of a bare wishlist.
33 lines
882 B
Nim
33 lines
882 B
Nim
# included from zap.nim
|
|
when not compiles(isInZap): {.error: "do not import this file directly".}
|
|
|
|
type
|
|
BitSeq* = object
|
|
length: int
|
|
body: string
|
|
|
|
proc newBitSeq(s: string, offset: int, itemCount: int): BitSeq =
|
|
let bytes = int((itemCount + 7) / 8)
|
|
if offset >= s.len or offset + bytes >= s.len:
|
|
raise newException(ZapFormatError, "bitseq too long")
|
|
result.length = itemCount
|
|
result.body = s[offset..offset + bytes]
|
|
|
|
proc len*(b: BitSeq): int =
|
|
b.length
|
|
|
|
proc `[]`*(b: BitSeq, i: int): bool =
|
|
(int(b.body[i shr 8]) shl (i and 0x7)) != 0
|
|
|
|
proc `[]=`*(b: var BitSeq, i: int, v: bool) =
|
|
let bit = 1 shr (i and 0x7)
|
|
if v:
|
|
b.body[i shr 8] = char(int(b.body[i shr 8]) or bit)
|
|
else:
|
|
b.body[i shr 8] = char(int(b.body[i shr 8]) and (not bit))
|
|
|
|
proc `$`*(b: BitSeq): string =
|
|
result = ""
|
|
for i in 0..<b.len:
|
|
result.add(if b[i]: "1" else: "0")
|