diff --git a/compiler/ccgexprs.nim b/compiler/ccgexprs.nim index f6680d252b..7534fc4e5e 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 1c6c90c848..38ecffdf8a 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 caa73da252..3950392082 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) diff --git a/tests/accept/compile/tnestedproc.nim b/tests/accept/compile/tnestedproc.nim new file mode 100644 index 0000000000..49ec6f9a7f --- /dev/null +++ b/tests/accept/compile/tnestedproc.nim @@ -0,0 +1,12 @@ +discard """ + output: "11" +""" + +proc p(x, y: int): int = + result = x + y + +echo p((proc (): int = + var x = 7 + return x)(), + (proc (): int = return 4)()) + diff --git a/tools/trimcc.nim b/tools/trimcc.nim index f742438627..499f04dbd1 100755 --- a/tools/trimcc.nim +++ b/tools/trimcc.nim @@ -19,7 +19,7 @@ proc walker(dir: string) = echo "Required: ", path # copy back: moveFile(path, newName(path)) - of pcDirectory: + of pcDir: walker(path) else: nil