client.nim 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. discard """
  2. cmd: "nim $target --debuginfo --hints:on --define:useNimRtl $options $file"
  3. """
  4. type
  5. TNodeKind = enum nkLit, nkSub, nkAdd, nkDiv, nkMul
  6. TNode = object
  7. case k: TNodeKind
  8. of nkLit: x: int
  9. else: a, b: ref TNode
  10. PNode = ref TNode
  11. when defined(windows):
  12. const dllname = "server.dll"
  13. elif defined(macosx):
  14. const dllname = "libserver.dylib"
  15. else:
  16. const dllname = "libserver.so"
  17. proc newLit(x: int): PNode {.importc: "newLit", dynlib: dllname.}
  18. proc newOp(k: TNodeKind, a, b: PNode): PNode {.
  19. importc: "newOp", dynlib: dllname.}
  20. proc buildTree(x: int): PNode {.importc: "buildTree", dynlib: dllname.}
  21. proc eval(n: PNode): int =
  22. case n.k
  23. of nkLit: result = n.x
  24. of nkSub: result = eval(n.a) - eval(n.b)
  25. of nkAdd: result = eval(n.a) + eval(n.b)
  26. of nkDiv: result = eval(n.a) div eval(n.b)
  27. of nkMul: result = eval(n.a) * eval(n.b)
  28. # Test the GC:
  29. for i in 0..100_000:
  30. discard eval(buildTree(2))
  31. # bug https://forum.nim-lang.org/t/8176; Error: ambiguous identifier: 'nimrtl'
  32. import std/strutils
  33. doAssert join(@[1, 2]) == "12"
  34. doAssert join(@[1.5, 2.5]) == "1.52.5"
  35. doAssert join(@["a", "bc"]) == "abc"