summary refs log tree commit diff stats
path: root/tests/macros/tmemit.nim
diff options
context:
space:
mode:
Diffstat (limited to 'tests/macros/tmemit.nim')
-rw-r--r--tests/macros/tmemit.nim38
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/macros/tmemit.nim b/tests/macros/tmemit.nim
new file mode 100644
index 000000000..6c9f9f935
--- /dev/null
+++ b/tests/macros/tmemit.nim
@@ -0,0 +1,38 @@
+discard """
+  output: '''
+c_func
+12
+'''
+"""
+
+import macros, strutils
+
+# bug #1025
+
+macro foo(icname): untyped =
+  let ic = newStrLitNode($icname)
+  result = quote do:
+    proc x* =
+      proc private {.exportc: `ic`.} = discard
+      echo `ic`
+      private()
+
+foo(c_func)
+x()
+
+
+template volatileLoad[T](x: ptr T): T =
+  var res: T
+  {.emit: [res, " = (*(", type(x[]), " volatile*)", x, ");"].}
+  res
+
+template volatileStore[T](x: ptr T; y: T) =
+  {.emit: ["*((", type(x[]), " volatile*)(", x, ")) = ", y, ";"].}
+
+proc main =
+  var st: int
+  var foo: ptr int = addr st
+  volatileStore(foo, 12)
+  echo volatileLoad(foo)
+
+main()