summary refs log tree commit diff stats
path: root/tests/macros
diff options
context:
space:
mode:
authorZahary Karadjov <zahary@gmail.com>2015-07-21 10:21:14 +0300
committerZahary Karadjov <zahary@gmail.com>2015-08-02 23:58:22 +0300
commit02f97489b795cd33d49966e254b46fcc3f8072ba (patch)
treec2be27abe57fe3b0f1118f21065409abc9784629 /tests/macros
parent7af92708af94164cd1373be85a06dd4cc4e4439e (diff)
downloadNim-02f97489b795cd33d49966e254b46fcc3f8072ba.tar.gz
fix #1858 again; restores the support for static macro params
Diffstat (limited to 'tests/macros')
-rw-r--r--tests/macros/tstaticparamsmacro.nim74
1 files changed, 74 insertions, 0 deletions
diff --git a/tests/macros/tstaticparamsmacro.nim b/tests/macros/tstaticparamsmacro.nim
new file mode 100644
index 000000000..1ab638396
--- /dev/null
+++ b/tests/macros/tstaticparamsmacro.nim
@@ -0,0 +1,74 @@
+discard """
+  msg: '''letters
+aa
+bb
+numbers
+11
+22
+AST a 
+[(11, 22), (33, 44)]
+AST b 
+(e: [55, 66], f: [77, 88])
+55
+10
+20Test
+20
+'''
+"""
+
+import macros
+
+type
+  TConfig = tuple
+    letters: seq[string]
+    numbers:seq[int]
+
+const data: Tconfig = (@["aa", "bb"], @[11, 22])
+
+macro mymacro(data: static[TConfig]): stmt =
+  echo "letters"
+  for s in items(data.letters):
+    echo s
+  echo "numbers"
+  for n in items(data.numbers):
+    echo n
+
+mymacro(data)
+
+type
+  Ta = seq[tuple[c:int, d:int]]
+  Tb = tuple[e:seq[int], f:seq[int]]
+
+const
+  a : Ta = @[(11, 22), (33, 44)]
+  b : Tb = (@[55,66], @[77, 88])
+
+macro mA(data: static[Ta]): stmt =
+  echo "AST a \n", repr(data)
+
+macro mB(data: static[Tb]): stmt =
+  echo "AST b \n", repr(data)
+  echo data.e[0]
+
+mA(a)
+mB(b)
+
+type
+  Foo[N: static[int], Z: static[string]] = object
+
+macro staticIntMacro(f: static[int]): stmt = echo f
+staticIntMacro 10
+
+var
+  x: Foo[20, "Test"]
+
+macro genericMacro[N; Z: static[string]](f: Foo[N, Z], ll = 3, zz = 12): stmt =
+  echo N, Z
+
+genericMacro x
+
+template genericTemplate[N, Z](f: Foo[N, Z], ll = 3, zz = 12): int = N
+
+static:
+  echo genericTemplate(x)
+