summary refs log tree commit diff stats
path: root/compiler
diff options
context:
space:
mode:
Diffstat (limited to 'compiler')
-rw-r--r--compiler/lambdalifting.nim10
-rwxr-xr-xcompiler/sem.nim2
-rwxr-xr-xcompiler/semexprs.nim4
-rwxr-xr-xcompiler/semstmts.nim4
-rwxr-xr-xcompiler/transf.nim1
5 files changed, 16 insertions, 5 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 =