summary refs log tree commit diff stats
path: root/compiler/macrocacheimpl.nim
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/macrocacheimpl.nim')
-rw-r--r--compiler/macrocacheimpl.nim84
1 files changed, 57 insertions, 27 deletions
diff --git a/compiler/macrocacheimpl.nim b/compiler/macrocacheimpl.nim
index 5c27f9265..d23040763 100644
--- a/compiler/macrocacheimpl.nim
+++ b/compiler/macrocacheimpl.nim
@@ -11,39 +11,69 @@
 
 import lineinfos, ast, modulegraphs, vmdef, magicsys
 
-proc genCall3(g: ModuleGraph; m: TMagic; s: string; a, b, c: PNode): PNode =
-  newTree(nkStaticStmt, newTree(nkCall, createMagic(g, s, m).newSymNode, a, b, c))
+proc recordInc*(c: PCtx; info: TLineInfo; key: string; by: BiggestInt) =
+  var recorded = newNodeI(nkCommentStmt, info)
+  recorded.add newStrNode("inc", info)
+  recorded.add newStrNode(key, info)
+  recorded.add newIntNode(nkIntLit, by)
+  c.graph.recordStmt(c.graph, c.module, recorded)
 
-proc genCall2(g: ModuleGraph; m: TMagic; s: string; a, b: PNode): PNode =
-  newTree(nkStaticStmt, newTree(nkCall, createMagic(g, s, m).newSymNode, a, b))
+proc recordPut*(c: PCtx; info: TLineInfo; key: string; k: string; val: PNode) =
+  var recorded = newNodeI(nkCommentStmt, info)
+  recorded.add newStrNode("put", info)
+  recorded.add newStrNode(key, info)
+  recorded.add newStrNode(k, info)
+  recorded.add copyTree(val)
+  c.graph.recordStmt(c.graph, c.module, recorded)
 
-template nodeFrom(s: string): PNode =
-  var res = newStrNode(s, info)
-  res.typ = getSysType(g, info, tyString)
-  res
+proc recordAdd*(c: PCtx; info: TLineInfo; key: string; val: PNode) =
+  var recorded = newNodeI(nkCommentStmt, info)
+  recorded.add newStrNode("add", info)
+  recorded.add newStrNode(key, info)
+  recorded.add copyTree(val)
+  c.graph.recordStmt(c.graph, c.module, recorded)
 
-template nodeFrom(i: BiggestInt): PNode =
-  var res = newIntNode(i, info)
-  res.typ = getSysType(g, info, tyInt)
-  res
+proc recordIncl*(c: PCtx; info: TLineInfo; key: string; val: PNode) =
+  var recorded = newNodeI(nkCommentStmt, info)
+  recorded.add newStrNode("incl", info)
+  recorded.add newStrNode(key, info)
+  recorded.add copyTree(val)
+  c.graph.recordStmt(c.graph, c.module, recorded)
 
-template nodeFrom(n: PNode): PNode = copyTree(n)
+when false:
+  proc genCall3(g: ModuleGraph; m: TMagic; s: string; a, b, c: PNode): PNode =
+    newTree(nkStaticStmt, newTree(nkCall, createMagic(g, s, m).newSymNode, a, b, c))
 
-template record(call) =
-  g.recordStmt(g, c.module, call)
+  proc genCall2(g: ModuleGraph; m: TMagic; s: string; a, b: PNode): PNode =
+    newTree(nkStaticStmt, newTree(nkCall, createMagic(g, s, m).newSymNode, a, b))
 
-proc recordInc*(c: PCtx; info: TLineInfo; key: string; by: BiggestInt) =
-  let g = c.graph
-  record genCall2(mNccInc, "inc", nodeFrom key, nodeFrom by)
+  template nodeFrom(s: string): PNode =
+    var res = newStrNode(s, info)
+    res.typ = getSysType(g, info, tyString)
+    res
 
-proc recordPut*(c: PCtx; info: TLineInfo; key: string; k: string; val: PNode) =
-  let g = c.graph
-  record genCall3(mNctPut, "[]=", nodeFrom key, nodeFrom k, nodeFrom val)
+  template nodeFrom(i: BiggestInt): PNode =
+    var res = newIntNode(i, info)
+    res.typ = getSysType(g, info, tyInt)
+    res
 
-proc recordAdd*(c: PCtx; info: TLineInfo; key: string; val: PNode) =
-  let g = c.graph
-  record genCall2(mNcsAdd, "add", nodeFrom key, nodeFrom val)
+  template nodeFrom(n: PNode): PNode = copyTree(n)
 
-proc recordIncl*(c: PCtx; info: TLineInfo; key: string; val: PNode) =
-  let g = c.graph
-  record genCall2(mNcsIncl, "incl", nodeFrom key, nodeFrom val)
+  template record(call) =
+    g.recordStmt(g, c.module, call)
+
+  proc recordInc*(c: PCtx; info: TLineInfo; key: string; by: BiggestInt) =
+    let g = c.graph
+    record genCall2(mNccInc, "inc", nodeFrom key, nodeFrom by)
+
+  proc recordPut*(c: PCtx; info: TLineInfo; key: string; k: string; val: PNode) =
+    let g = c.graph
+    record genCall3(mNctPut, "[]=", nodeFrom key, nodeFrom k, nodeFrom val)
+
+  proc recordAdd*(c: PCtx; info: TLineInfo; key: string; val: PNode) =
+    let g = c.graph
+    record genCall2(mNcsAdd, "add", nodeFrom key, nodeFrom val)
+
+  proc recordIncl*(c: PCtx; info: TLineInfo; key: string; val: PNode) =
+    let g = c.graph
+    record genCall2(mNcsIncl, "incl", nodeFrom key, nodeFrom val)