made tests green again

This commit is contained in:
Araq 2012-08-14 00:09:06 +02:00
commit 991b3096e8
7 changed files with 23 additions and 10 deletions

View file

@ -278,6 +278,13 @@ proc interestingVar(s: PSym): bool {.inline.} =
result = s.kind in {skVar, skLet, skTemp, skForVar, skParam, skResult} and
sfGlobal notin s.flags
proc semCaptureSym*(s, owner: PSym) =
if interestingVar(s) and owner.id != s.owner.id:
if owner.typ != nil:
owner.typ.callConv = ccClosure
# since the analysis is not entirely correct, we don't set 'tfCapturesEnv'
# here
proc gatherVars(o: POuterContext, i: PInnerContext, n: PNode) =
# gather used vars for closure generation
if n == nil: return
@ -363,6 +370,7 @@ proc closureCreationPoint(n: PNode): PNode =
result.add(n)
proc searchForInnerProcs(o: POuterContext, n: PNode) =
if n == nil: return
case n.kind
of nkEmpty..pred(nkSym), succ(nkSym)..nkNilLit:
nil
@ -529,7 +537,7 @@ proc liftLambdas*(fn: PSym, body: PNode): PNode =
if body.kind == nkEmpty or gCmd == cmdCompileToEcmaScript:
# ignore forward declaration:
result = body
elif not containsNode(body, procDefs):
elif not containsNode(body, procDefs) and false:
# fast path: no inner procs, so no closure needed:
result = body
else:

View file

@ -14,7 +14,7 @@ import
wordrecg, ropes, msgs, os, condsyms, idents, renderer, types, platform, math,
magicsys, parser, nversion, nimsets, semfold, importer,
procfind, lookups, rodread, pragmas, passes, semdata, semtypinst, sigmatch,
semthreads, intsets, transf, evals, idgen, aliases, cgmeth
semthreads, intsets, transf, evals, idgen, aliases, cgmeth, lambdalifting
proc semPass*(): TPass
# implementation

View file

@ -107,6 +107,8 @@ proc semSym(c: PContext, n: PNode, s: PSym, flags: TExprFlags): PNode =
incl(c.p.owner.flags, sfSideEffect)
elif s.kind == skParam and s.typ.kind == tyExpr:
return s.typ.n
else:
semCaptureSym(s, c.p.owner)
result = newSymNode(s, n.info)
# We cannot check for access to outer vars for example because it's still
# not sure the symbol really ends up being used:
@ -1524,7 +1526,7 @@ proc semExpr(c: PContext, n: PNode, flags: TExprFlags = {}): PNode =
internalError(n.info, "semExpr() to implement") # XXX: to implement
of nkPar:
case checkPar(n)
of paNone: result = nil
of paNone: result = errorNode(c, n)
of paTuplePositions: result = semTuplePositionsConstr(c, n)
of paTupleFields: result = semTupleFieldsConstr(c, n)
of paSingle: result = semExpr(c, n.sons[0], flags)

View file

@ -876,7 +876,9 @@ proc semMethod(c: PContext, n: PNode): PNode =
# XXX this not really correct way to do it: Perhaps it should be done after
# generic instantiation. Well it's good enough for now:
if not hasObjParam:
if hasObjParam:
methodDef(s, false)
else:
LocalError(n.info, errXNeedsParamObjectType, "method")
proc semConverterDef(c: PContext, n: PNode): PNode =

View file

@ -697,7 +697,6 @@ proc transformBody*(module: PSym, n: PNode, prc: PSym): PNode =
if prc.kind != skMacro:
# XXX no closures yet for macros:
result = liftLambdas(prc, result)
if prc.kind == skMethod: methodDef(prc, false)
incl(result.flags, nfTransf)
proc transformStmt*(module: PSym, n: PNode): PNode =

View file

@ -1,7 +1,12 @@
discard """
line: 6
errormsg: "'ugh' cannot have 'closure' calling convention"
line: 12
errormsg: "type mismatch: got (proc (int){.closure.})"
"""
proc ugh[T](x: T) {.closure.} =
echo "ugha"
proc takeCdecl(p: proc (x: int) {.cdecl.}) = nil
takeCDecl(ugh[int])

View file

@ -6,6 +6,3 @@ discard """
method m(i: int): int =
return 5