summary refs log tree commit diff stats
path: root/tests/vm/tcompiletimetable.nim
diff options
context:
space:
mode:
Diffstat (limited to 'tests/vm/tcompiletimetable.nim')
-rw-r--r--tests/vm/tcompiletimetable.nim62
1 files changed, 62 insertions, 0 deletions
diff --git a/tests/vm/tcompiletimetable.nim b/tests/vm/tcompiletimetable.nim
new file mode 100644
index 000000000..1db490f1a
--- /dev/null
+++ b/tests/vm/tcompiletimetable.nim
@@ -0,0 +1,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]