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.
28 lines
791 B
Nim
28 lines
791 B
Nim
import zap, zap/gensupport
|
|
|
|
type
|
|
Pair* = ref object
|
|
first*: AnyPointer
|
|
second*: AnyPointer
|
|
|
|
makeStructCoders(Pair, [],
|
|
[
|
|
(first, 0, PointerFlag.none, true),
|
|
(second, 1, PointerFlag.none, true)
|
|
], [])
|
|
|
|
proc packPointerHook*[A, B](p: Packer, offset: int, value: (A, B)) =
|
|
packPointer(p, offset, Pair(first: value[0].toAnyPointer, second: value[1].toAnyPointer))
|
|
|
|
proc unpackPointerHook*[A, B](self: Unpacker, offset: int, typ: typedesc[(A, B)]): (A, B) =
|
|
let p = unpackPointer(self, offset, Pair)
|
|
(p.first.castAs(A), p.second.castAs(B))
|
|
|
|
proc getPointerField*[A, B](value: (A, B), index: int): AnyPointer =
|
|
if index == 0:
|
|
return value[0].toAnyPointer
|
|
elif index == 1:
|
|
return value[1].toAnyPointer
|
|
else:
|
|
raise newException(ValueError, "bad index")
|