Files
nim/examples/calculator_server.nim
zeekay 68037f9ca4 Rebrand Cap'n Proto Nim port to ZAP
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.
2026-06-19 23:42:02 -07:00

30 lines
1.1 KiB
Nim

import reactor, zap, caprpc, calculator_schema
type MyCalculator = ref object of RootObj
proc evaluate(self: MyCalculator, expression: Calculator_Expression): Future[Calculator_Value] =
return now(error(Calculator_Value, "not implemented"))
proc defFunction(self: MyCalculator, paramCount: int32, body: Calculator_Expression): Future[Calculator_Function] =
return now(error(Calculator_Function, "not implemented"))
proc getOperator(self: MyCalculator, op: Calculator_Operator): Future[Calculator_Function] =
return now(error(Calculator_Function, "not implemented"))
proc toCapServer(self: MyCalculator): CapServer =
return toGenericCapServer(self.asCalculator)
proc main() {.async.} =
# let sys = newTwoPartyClient(await connectTcp("127.0.0.1:7890")) # localhost:6789
let server = await createTcpServer(7890)
let myCalculator = new(MyCalculator)
echo "waiting for incoming connections"
asyncFor conn in server.incomingConnections:
echo "connection received"
discard newTwoPartyServer(conn.BytePipe, myCalculator.toCapServer)
when isMainModule:
main().runMain()