diff options
Diffstat (limited to 'compiler/plugins')
-rw-r--r-- | compiler/plugins/active.nim | 13 | ||||
-rw-r--r-- | compiler/plugins/locals/locals.nim | 42 |
2 files changed, 55 insertions, 0 deletions
diff --git a/compiler/plugins/active.nim b/compiler/plugins/active.nim new file mode 100644 index 000000000..e9c11c2ea --- /dev/null +++ b/compiler/plugins/active.nim @@ -0,0 +1,13 @@ +# +# +# The Nim Compiler +# (c) Copyright 2015 Andreas Rumpf +# +# See the file "copying.txt", included in this +# distribution, for details about the copyright. +# + +## Include file that imports all plugins that are active. + +import + locals.locals diff --git a/compiler/plugins/locals/locals.nim b/compiler/plugins/locals/locals.nim new file mode 100644 index 000000000..d89149f33 --- /dev/null +++ b/compiler/plugins/locals/locals.nim @@ -0,0 +1,42 @@ +# +# +# The Nim Compiler +# (c) Copyright 2015 Andreas Rumpf +# +# See the file "copying.txt", included in this +# distribution, for details about the copyright. +# + +## The builtin 'system.locals' implemented as a plugin. + +import plugins, ast, astalgo, magicsys, lookups, semdata, lowerings + +proc semLocals(c: PContext, n: PNode): PNode = + var counter = 0 + var tupleType = newTypeS(tyTuple, c) + result = newNodeIT(nkPar, n.info, tupleType) + tupleType.n = newNodeI(nkRecList, n.info) + # for now we skip openarrays ... + for scope in walkScopes(c.currentScope): + if scope == c.topLevelScope: break + for it in items(scope.symbols): + # XXX parameters' owners are wrong for generics; this caused some pain + # for closures too; we should finally fix it. + #if it.owner != c.p.owner: return result + if it.kind in skLocalVars and + it.typ.skipTypes({tyGenericInst, tyVar}).kind notin + {tyVarargs, tyOpenArray, tyTypeDesc, tyStatic, tyExpr, tyStmt, tyEmpty}: + + var field = newSym(skField, it.name, getCurrOwner(), n.info) + field.typ = it.typ.skipTypes({tyGenericInst, tyVar}) + field.position = counter + inc(counter) + + addSon(tupleType.n, newSymNode(field)) + addSonSkipIntLit(tupleType, field.typ) + + var a = newSymNode(it, result.info) + if it.typ.skipTypes({tyGenericInst}).kind == tyVar: a = newDeref(a) + result.add(a) + +registerPlugin("stdlib", "system", "locals", semLocals) |