refactoring: fewer global variables

This commit is contained in:
Andreas Rumpf 2018-05-27 19:19:12 +02:00
commit a325692fb2
6 changed files with 36 additions and 43 deletions

View file

@ -10,4 +10,15 @@
## Include file that imports all plugins that are active.
import
locals / locals, itersgen
compiler / [pluginsupport, idents, ast], locals, itersgen
const
plugins: array[2, Plugin] = [
("stdlib", "system", "iterToProc", iterToProcImpl),
("stdlib", "system", "locals", semLocals)
]
proc getPlugin*(ic: IdentCache; fn: PSym): Transformation =
for p in plugins:
if pluginMatches(ic, p, fn): return p.t
return nil

View file

@ -9,11 +9,11 @@
## Plugin to transform an inline iterator into a data structure.
import ".." / [pluginsupport, ast, astalgo,
import ".." / [ast, astalgo,
magicsys, lookups, semdata,
lambdalifting, rodread, 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:
@ -46,5 +46,3 @@ proc iterToProcImpl(c: PContext, n: PNode): PNode =
prc.ast.add iter.sym.ast.sons[resultPos]
addInterfaceDecl(c, prc)
registerPlugin("stdlib", "system", "iterToProc", iterToProcImpl)

View file

@ -9,10 +9,10 @@
## The builtin 'system.locals' implemented as a plugin.
import "../../" / [pluginsupport, ast, astalgo,
import ".." / [pluginsupport, ast, astalgo,
magicsys, lookups, semdata, lowerings]
proc semLocals(c: PContext, n: PNode): PNode =
proc semLocals*(c: PContext, n: PNode): PNode =
var counter = 0
var tupleType = newTypeS(tyTuple, c)
result = newNodeIT(nkPar, n.info, tupleType)
@ -39,5 +39,3 @@ proc semLocals(c: PContext, n: PNode): PNode =
var a = newSymNode(it, result.info)
if it.typ.skipTypes({tyGenericInst}).kind == tyVar: a = newDeref(a)
result.add(a)
registerPlugin("stdlib", "system", "locals", semLocals)