summary refs log tree commit diff stats
path: root/tests/dll/server.nim
blob: 2b7791d4b44dbdbe4e731584f261c218146d0965 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
discard """
action: compile
  cmd: "nim $target --debuginfo --hints:on --define:useNimRtl --app:lib $options $file"
"""

type
  TNodeKind = enum nkLit, nkSub, nkAdd, nkDiv, nkMul
  TNode = object
    case k: TNodeKind
    of nkLit: x: int
    else: a, b: ref TNode

  PNode = ref TNode

proc newLit(x: int): PNode {.exportc: "newLit", dynlib.} =
  result = PNode(k: nkLit, x: x)

proc newOp(k: TNodeKind, a, b: PNode): PNode {.exportc: "newOp", dynlib.} =
  assert a != nil
  assert b != nil
  result = PNode(k: nkSub, a: a, b: b)
  # now overwrite with the real value:
  result.k = k

proc buildTree(x: int): PNode {.exportc: "buildTree", dynlib.} =
  result = newOp(nkMul, newOp(nkAdd, newLit(x), newLit(x)), newLit(x))