new-ll: further progress (bootstrapping still fails)

This commit is contained in:
Andreas Rumpf 2015-12-27 00:17:48 +01:00
commit 9309f8101d

View file

@ -169,7 +169,7 @@ proc addHiddenParam(routine: PSym, param: PSym) =
proc getHiddenParam(routine: PSym): PSym = proc getHiddenParam(routine: PSym): PSym =
let params = routine.ast.sons[paramsPos] let params = routine.ast.sons[paramsPos]
let hidden = lastSon(params) let hidden = lastSon(params)
if hidden.kind == nkSym and hidden.sym.kind == skParam: if hidden.kind == nkSym and hidden.sym.kind == skParam and hidden.sym.name.s == paramName:
result = hidden.sym result = hidden.sym
assert sfFromGeneric in result.flags assert sfFromGeneric in result.flags
else: else:
@ -194,7 +194,7 @@ proc illegalCapture(s: PSym): bool {.inline.} =
s.kind == skResult s.kind == skResult
proc isInnerProc(s: PSym): bool = proc isInnerProc(s: PSym): bool =
if s.kind in {skProc, skMethod, skConverter, skIterator}: if s.kind in {skProc, skMethod, skConverter, skIterator} and s.magic == mNone:
result = s.skipGenericOwner.kind in routineKinds result = s.skipGenericOwner.kind in routineKinds
proc createUpField(obj, fieldType: PType): PSym = proc createUpField(obj, fieldType: PType): PSym =
@ -327,7 +327,7 @@ proc detectCapturedVars(n: PNode; owner: PSym; c: var DetectionPass) =
# ow != owner: # ow != owner:
return return
# direct or indirect dependency: # direct or indirect dependency:
if innerProc or interestingVar(s): if (innerProc and s.typ.callConv == ccClosure) or interestingVar(s):
discard """ discard """
proc outer() = proc outer() =
var x: int var x: int
@ -371,8 +371,11 @@ proc detectCapturedVars(n: PNode; owner: PSym; c: var DetectionPass) =
of nkEmpty..pred(nkSym), succ(nkSym)..nkNilLit, nkClosure, of nkEmpty..pred(nkSym), succ(nkSym)..nkNilLit, nkClosure,
nkTemplateDef, nkTypeSection: nkTemplateDef, nkTypeSection:
discard discard
of nkProcDef, nkMethodDef, nkIteratorDef, nkConverterDef, nkMacroDef: of nkProcDef, nkMethodDef, nkConverterDef, nkMacroDef:
discard discard
of nkLambdaKinds, nkIteratorDef:
if n.typ != nil:
detectCapturedVars(n[namePos], owner, c)
else: else:
for i in 0..<n.len: for i in 0..<n.len:
detectCapturedVars(n[i], owner, c) detectCapturedVars(n[i], owner, c)
@ -599,8 +602,11 @@ proc liftCapturedVars(n: PNode; owner: PSym; d: DetectionPass;
of nkEmpty..pred(nkSym), succ(nkSym)..nkNilLit, nkClosure, of nkEmpty..pred(nkSym), succ(nkSym)..nkNilLit, nkClosure,
nkTemplateDef, nkTypeSection: nkTemplateDef, nkTypeSection:
discard discard
of nkProcDef, nkMethodDef, nkIteratorDef, nkConverterDef, nkMacroDef: of nkProcDef, nkMethodDef, nkConverterDef, nkMacroDef:
discard discard
of nkLambdaKinds, nkIteratorDef:
if n.typ != nil:
discard liftCapturedVars(n[namePos], owner, d, c)
else: else:
if owner.isIterator and n.kind == nkYieldStmt: if owner.isIterator and n.kind == nkYieldStmt:
result = transformYield(n, owner, d, c) result = transformYield(n, owner, d, c)
@ -660,8 +666,8 @@ proc liftLambdas*(fn: PSym, body: PNode): PNode =
result = wrapIterBody(newBody, fn) result = wrapIterBody(newBody, fn)
else: else:
result = body result = body
if fn.name.s == "outer": #if fn.name.s == "outer":
echo renderTree(result, {renderIds}) # echo renderTree(result, {renderIds})
proc liftLambdasForTopLevel*(module: PSym, body: PNode): PNode = proc liftLambdasForTopLevel*(module: PSym, body: PNode): PNode =
if body.kind == nkEmpty or gCmd == cmdCompileToJS: if body.kind == nkEmpty or gCmd == cmdCompileToJS: