mirror of
https://github.com/nim-lang/Nim.git
synced 2026-06-03 10:24:44 +00:00
anonymous procs implemented; however no closure support yet
This commit is contained in:
@@ -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 =
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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)
|
||||
|
||||
12
tests/accept/compile/tnestedproc.nim
Normal file
12
tests/accept/compile/tnestedproc.nim
Normal file
@@ -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)())
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user