server.nim 739 B

12345678910111213141516171819202122232425262728
  1. discard """
  2. action: compile
  3. cmd: "nim $target --debuginfo --hints:on --define:useNimRtl --app:lib $options $file"
  4. batchable: false
  5. """
  6. type
  7. TNodeKind = enum nkLit, nkSub, nkAdd, nkDiv, nkMul
  8. TNode = object
  9. case k: TNodeKind
  10. of nkLit: x: int
  11. else: a, b: ref TNode
  12. PNode = ref TNode
  13. proc newLit(x: int): PNode {.exportc: "newLit", dynlib.} =
  14. result = PNode(k: nkLit, x: x)
  15. proc newOp(k: TNodeKind, a, b: PNode): PNode {.exportc: "newOp", dynlib.} =
  16. assert a != nil
  17. assert b != nil
  18. result = PNode(k: nkSub, a: a, b: b)
  19. # now overwrite with the real value:
  20. result.k = k
  21. proc buildTree(x: int): PNode {.exportc: "buildTree", dynlib.} =
  22. result = newOp(nkMul, newOp(nkAdd, newLit(x), newLit(x)), newLit(x))