diff options
author | Araq <rumpf_a@web.de> | 2012-08-14 00:09:06 +0200 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2012-08-14 00:09:06 +0200 |
commit | 991b3096e8fb99d3a1cc06668b724e440c380272 (patch) | |
tree | 1098d8797aabcfe4d555fa3754c76f88af2fda45 | |
parent | adb73ec9ed87a5c5fe1ced35f3440b85bac49d8a (diff) | |
download | Nim-991b3096e8fb99d3a1cc06668b724e440c380272.tar.gz |
made tests green again
-rw-r--r-- | compiler/lambdalifting.nim | 10 | ||||
-rwxr-xr-x | compiler/sem.nim | 2 | ||||
-rwxr-xr-x | compiler/semexprs.nim | 4 | ||||
-rwxr-xr-x | compiler/semstmts.nim | 4 | ||||
-rwxr-xr-x | compiler/transf.nim | 1 | ||||
-rw-r--r-- | tests/reject/tinvalidclosure.nim | 9 | ||||
-rwxr-xr-x | tests/reject/tmethod.nim | 3 |
7 files changed, 23 insertions, 10 deletions
diff --git a/compiler/lambdalifting.nim b/compiler/lambdalifting.nim index 341f95798..a42c83af9 100644 --- a/compiler/lambdalifting.nim +++ b/compiler/lambdalifting.nim @@ -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: diff --git a/compiler/sem.nim b/compiler/sem.nim index feb8acdf7..7f461a11c 100755 --- a/compiler/sem.nim +++ b/compiler/sem.nim @@ -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 diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim index 96a195485..a77a34d52 100755 --- a/compiler/semexprs.nim +++ b/compiler/semexprs.nim @@ -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) diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim index ace73422d..5e2be5e9f 100755 --- a/compiler/semstmts.nim +++ b/compiler/semstmts.nim @@ -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 = diff --git a/compiler/transf.nim b/compiler/transf.nim index c6c7739d6..21f58dc4a 100755 --- a/compiler/transf.nim +++ b/compiler/transf.nim @@ -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 = diff --git a/tests/reject/tinvalidclosure.nim b/tests/reject/tinvalidclosure.nim index f5ac3a5f0..c06270bfa 100644 --- a/tests/reject/tinvalidclosure.nim +++ b/tests/reject/tinvalidclosure.nim @@ -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]) diff --git a/tests/reject/tmethod.nim b/tests/reject/tmethod.nim index 999016072..0cfe24c70 100755 --- a/tests/reject/tmethod.nim +++ b/tests/reject/tmethod.nim @@ -6,6 +6,3 @@ discard """ method m(i: int): int = return 5 - - - |