summary refs log tree commit diff stats
path: root/tests/accept
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2011-10-28 01:38:41 +0200
committerAraq <rumpf_a@web.de>2011-10-28 01:38:41 +0200
commita0a8934a4f089f8a438da280a4c80051ba3607b5 (patch)
tree7869a80b499d8740d84549ca178d60a7470ba5c2 /tests/accept
parentfe9bb1869d8418e6929e0d3a284b698c690af06e (diff)
downloadNim-a0a8934a4f089f8a438da280a4c80051ba3607b5.tar.gz
eval context for macros lives as long as the current module is compiled
Diffstat (limited to 'tests/accept')
-rw-r--r--tests/accept/run/tidgen.nim19
1 files changed, 19 insertions, 0 deletions
diff --git a/tests/accept/run/tidgen.nim b/tests/accept/run/tidgen.nim
new file mode 100644
index 000000000..68fffbabb
--- /dev/null
+++ b/tests/accept/run/tidgen.nim
@@ -0,0 +1,19 @@
+discard """
+  output: "3 4"
+"""
+
+import macros
+
+# Test compile-time state in same module
+
+var gid = 3
+
+macro genId(invokation: expr): expr =
+  result = newIntLitNode(gid)
+  inc gid
+
+proc Id1(): int = return genId()
+proc Id2(): int = return genId()
+
+echo Id1(), " ", Id2()
+