summary refs log tree commit diff stats
path: root/tests/dll/client.nim
blob: 62697569f0811391a2f5f3c14c03b7c27e69a5f4 (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
35
36
37
38
39
40
41
42
43
discard """
  cmd: "nim $target --debuginfo --hints:on --define:useNimRtl $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


when defined(windows):
  const dllname = "server.dll"
elif defined(macosx):
  const dllname = "libserver.dylib"
else:
  const dllname = "libserver.so"

proc newLit(x: int): PNode {.importc: "newLit", dynlib: dllname.}
proc newOp(k: TNodeKind, a, b: PNode): PNode {.
  importc: "newOp", dynlib: dllname.}
proc buildTree(x: int): PNode {.importc: "buildTree", dynlib: dllname.}

proc eval(n: PNode): int =
  case n.k
  of nkLit: result = n.x
  of nkSub: result = eval(n.a) - eval(n.b)
  of nkAdd: result = eval(n.a) + eval(n.b)
  of nkDiv: result = eval(n.a) div eval(n.b)
  of nkMul: result = eval(n.a) * eval(n.b)

# Test the GC:
for i in 0..100_000:
  discard eval(buildTree(2))

# bug https://forum.nim-lang.org/t/8176; Error: ambiguous identifier: 'nimrtl'
import std/strutils
doAssert join(@[1, 2]) == "12"
doAssert join(@[1.5, 2.5]) == "1.52.5"
doAssert join(@["a", "bc"]) == "abc"