summary refs log tree commit diff stats
path: root/tests/dll/server.nim
blob: ae2acc893bd21539109f6b3ad7df1098727f49ef (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
27
28
29
30
31
32
33
34
discard """
  cmd: "nimrod cc --debuginfo --hints:on --define:useNimRtl --app:lib $# $#"
"""

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.} =
  new(result)
  result.x = x
  
proc newOp(k: TNodeKind, a, b: PNode): PNode {.exportc: "newOp", dynlib.} =
  assert a != nil
  assert b != nil
  new(result)
  result.k = k
  result.a = a
  result.b = b
  
proc buildTree(x: int): PNode {.exportc: "buildTree", dynlib.} = 
  result = newOp(nkMul, newOp(nkAdd, newLit(x), newLit(x)), newLit(x))

when false:
  # Test the GC:
  for i in 0..100_000:
    discard buildTree(2)
    
  echo "Done"