summary refs log tree commit diff stats
path: root/compiler
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2011-08-01 08:39:27 +0200
committerAraq <rumpf_a@web.de>2011-08-01 08:39:27 +0200
commitf0145ba7c5142b2ea7da8c77522600a251145875 (patch)
tree9450f572e5e1588a3fc330c5d61a715b3458042c /compiler
parent00a4e19e8fe7e0cb02d77523989803591dd6d5cf (diff)
downloadNim-f0145ba7c5142b2ea7da8c77522600a251145875.tar.gz
anonymous procs implemented; however no closure support yet
Diffstat (limited to 'compiler')
-rwxr-xr-xcompiler/ccgexprs.nim6
-rwxr-xr-xcompiler/semstmts.nim11
-rwxr-xr-xcompiler/transf.nim2
3 files changed, 14 insertions, 5 deletions
diff --git a/compiler/ccgexprs.nim b/compiler/ccgexprs.nim
index f6680d252..7534fc4e5 100755
--- a/compiler/ccgexprs.nim
+++ b/compiler/ccgexprs.nim
@@ -1716,6 +1716,12 @@ proc expr(p: BProc, e: PNode, d: var TLoc) =
   of nkStringToCString: convStrToCStr(p, e, d)
   of nkCStringToString: convCStrToStr(p, e, d)
   of nkPassAsOpenArray: passToOpenArray(p, e, d)
+  of nkLambda:
+    var sym = e.sons[namePos].sym
+    genProc(p.module, sym)
+    if sym.loc.r == nil or sym.loc.t == nil:
+      InternalError(e.info, "expr: proc not init " & sym.name.s)
+    putLocIntoDest(p, d, sym.loc)
   else: InternalError(e.info, "expr(" & $e.kind & "); unknown node kind")
 
 proc genNamedConstExpr(p: BProc, n: PNode): PRope =
diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim
index 1c6c90c84..38ecffdf8 100755
--- a/compiler/semstmts.nim
+++ b/compiler/semstmts.nim
@@ -593,7 +593,8 @@ proc semLambda(c: PContext, n: PNode): PNode =
   else:
     s.typ = newTypeS(tyProc, c)
     addSon(s.typ, nil)
-  s.typ.callConv = ccClosure
+  # no! do a proper analysis to determine calling convention
+  when false: s.typ.callConv = ccClosure
   if n.sons[pragmasPos].kind != nkEmpty:
     pragma(c, s, n.sons[pragmasPos], lambdaPragmas)
   s.options = gOptions
@@ -644,10 +645,10 @@ proc semProcAux(c: PContext, n: PNode, kind: TSymKind,
   var proto = SearchForProc(c, s, c.tab.tos-2) # -2 because we have a scope
                                                # open for parameters
   if proto == nil: 
-    if c.p.owner.kind != skModule: 
-      s.typ.callConv = ccClosure
-    else: 
-      s.typ.callConv = lastOptionEntry(c).defaultCC 
+    s.typ.callConv = lastOptionEntry(c).defaultCC 
+    when false:
+      # do a proper analysis here:
+      if c.p.owner.kind != skModule: s.typ.callConv = ccClosure
     # add it here, so that recursive procs are possible:
     # -2 because we have a scope open for parameters
     if kind in OverloadableSyms: 
diff --git a/compiler/transf.nim b/compiler/transf.nim
index caa73da25..395039208 100755
--- a/compiler/transf.nim
+++ b/compiler/transf.nim
@@ -684,6 +684,8 @@ proc transform(c: PTransf, n: PNode): PTransNode =
   of nkBracketExpr: 
     result = transformArrayAccess(c, n)
   of nkLambda: 
+    n.sons[codePos] = PNode(transform(c, n.sons[codePos]))
+    result = PTransNode(n)
     when false: result = transformLambda(c, n)
   of nkForStmt: 
     result = transformFor(c, n)