File: server.nim

package info (click to toggle)
nim 2.2.4-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,951,164 kB
  • sloc: sh: 24,599; ansic: 1,771; python: 1,493; makefile: 1,013; sql: 298; asm: 141; xml: 13
file content (27 lines) | stat: -rw-r--r-- 739 bytes parent folder | download | duplicates (3)
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
discard """
action: compile
  cmd: "nim $target --debuginfo --hints:on --define:useNimRtl --app:lib $options $file"
batchable: false
"""

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))