summary refs log tree commit diff stats
path: root/tests/vm/tcompiletimetable.nim
blob: 1db490f1ab762a442f40bd07d40dd739d4642328 (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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
discard """
  nimout: '''
2
3
4:2
Got Hi
Got Hey
'''
  output:'''
a
b
c
'''
"""

# bug #404

import macros, tables, strtabs

var ZOOT{.compileTime.} = initTable[int, int](2)
var iii {.compiletime.} = 1

macro zoo: untyped =
  ZOOT[iii] = iii*2
  inc iii
  echo iii

zoo
zoo


macro tupleUnpack: untyped =
  var (y,z) = (4, 2)
  echo y, ":", z

tupleUnpack

# bug #903

var x {.compileTime.}: StringTableRef

macro addStuff(stuff, body: untyped): untyped =
  result = newNimNode(nnkStmtList)

  if x.isNil:
    x = newStringTable(modeStyleInsensitive)
  x[$stuff] = ""

macro dump(): untyped =
  result = newNimNode(nnkStmtList)
  for y in x.keys: echo "Got ", y

addStuff("Hey"): echo "Hey"
addStuff("Hi"): echo "Hi"
dump()

# ensure .compileTime vars can be used at runtime:
import macros

var xzzzz {.compileTime.}: array[3, string] = ["a", "b", "c"]

for i in 0..high(xzzzz): echo xzzzz[i]