From a0a8934a4f089f8a438da280a4c80051ba3607b5 Mon Sep 17 00:00:00 2001 From: Araq Date: Fri, 28 Oct 2011 01:38:41 +0200 Subject: eval context for macros lives as long as the current module is compiled --- tests/accept/run/tidgen.nim | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 tests/accept/run/tidgen.nim (limited to 'tests/accept/run') 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() + -- cgit 1.4.1-2-gfad0