summary refs log tree commit diff stats
path: root/compiler/plugins/itersgen.nim
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/plugins/itersgen.nim')
-rw-r--r--compiler/plugins/itersgen.nim35
1 files changed, 15 insertions, 20 deletions
diff --git a/compiler/plugins/itersgen.nim b/compiler/plugins/itersgen.nim
index f44735b77..e2c97bdc5 100644
--- a/compiler/plugins/itersgen.nim
+++ b/compiler/plugins/itersgen.nim
@@ -9,43 +9,38 @@
 
 ## Plugin to transform an inline iterator into a data structure.
 
-import compiler/pluginsupport, compiler/ast, compiler/astalgo,
-  compiler/magicsys, compiler/lookups, compiler/semdata,
-  compiler/lambdalifting, compiler/rodread, compiler/msgs
+import ".." / [ast, modulegraphs, lookups, semdata, lambdalifting, msgs]
 
-
-proc iterToProcImpl(c: PContext, n: PNode): PNode =
+proc iterToProcImpl*(c: PContext, n: PNode): PNode =
   result = newNodeI(nkStmtList, n.info)
   let iter = n[1]
   if iter.kind != nkSym or iter.sym.kind != skIterator:
-    localError(iter.info, "first argument needs to be an iterator")
+    localError(c.config, iter.info, "first argument needs to be an iterator")
     return
   if n[2].typ.isNil:
-    localError(n[2].info, "second argument needs to be a type")
+    localError(c.config, n[2].info, "second argument needs to be a type")
     return
   if n[3].kind != nkIdent:
-    localError(n[3].info, "third argument needs to be an identifier")
+    localError(c.config, n[3].info, "third argument needs to be an identifier")
     return
 
   let t = n[2].typ.skipTypes({tyTypeDesc, tyGenericInst})
-  if t.kind notin {tyRef, tyPtr} or t.lastSon.kind != tyObject:
-    localError(n[2].info,
+  if t.kind notin {tyRef, tyPtr} or t.elementType.kind != tyObject:
+    localError(c.config, n[2].info,
         "type must be a non-generic ref|ptr to object with state field")
     return
-  let body = liftIterToProc(iter.sym, iter.sym.getBody, t)
+  let body = liftIterToProc(c.graph, iter.sym, getBody(c.graph, iter.sym), t, c.idgen)
 
-  let prc = newSym(skProc, n[3].ident, iter.sym.owner, iter.sym.info)
-  prc.typ = copyType(iter.sym.typ, prc, false)
+  let prc = newSym(skProc, n[3].ident, c.idgen, iter.sym.owner, iter.sym.info)
+  prc.typ = copyType(iter.sym.typ, c.idgen, prc)
   excl prc.typ.flags, tfCapturesEnv
   prc.typ.n.add newSymNode(getEnvParam(iter.sym))
   prc.typ.rawAddSon t
   let orig = iter.sym.ast
   prc.ast = newProcNode(nkProcDef, n.info,
-                        name = newSymNode(prc),
-                        params = orig[paramsPos],
-                        pragmas = orig[pragmasPos],
-                        body = body)
-  prc.ast.add iter.sym.ast.sons[resultPos]
-  addInterfaceDecl(c, prc)
+              body = body, params = orig[paramsPos], name = newSymNode(prc),
+              pattern = c.graph.emptyNode, genericParams = c.graph.emptyNode,
+              pragmas = orig[pragmasPos], exceptions = c.graph.emptyNode)
 
-registerPlugin("stdlib", "system", "iterToProc", iterToProcImpl)
+  prc.ast.add iter.sym.ast[resultPos]
+  addInterfaceDecl(c, prc)