anonymous procs implemented; however no closure support yet
This commit is contained in:
parent
00a4e19e8f
commit
f0145ba7c5
5 changed files with 27 additions and 6 deletions
|
|
@ -1716,6 +1716,12 @@ proc expr(p: BProc, e: PNode, d: var TLoc) =
|
||||||
of nkStringToCString: convStrToCStr(p, e, d)
|
of nkStringToCString: convStrToCStr(p, e, d)
|
||||||
of nkCStringToString: convCStrToStr(p, e, d)
|
of nkCStringToString: convCStrToStr(p, e, d)
|
||||||
of nkPassAsOpenArray: passToOpenArray(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")
|
else: InternalError(e.info, "expr(" & $e.kind & "); unknown node kind")
|
||||||
|
|
||||||
proc genNamedConstExpr(p: BProc, n: PNode): PRope =
|
proc genNamedConstExpr(p: BProc, n: PNode): PRope =
|
||||||
|
|
|
||||||
|
|
@ -593,7 +593,8 @@ proc semLambda(c: PContext, n: PNode): PNode =
|
||||||
else:
|
else:
|
||||||
s.typ = newTypeS(tyProc, c)
|
s.typ = newTypeS(tyProc, c)
|
||||||
addSon(s.typ, nil)
|
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:
|
if n.sons[pragmasPos].kind != nkEmpty:
|
||||||
pragma(c, s, n.sons[pragmasPos], lambdaPragmas)
|
pragma(c, s, n.sons[pragmasPos], lambdaPragmas)
|
||||||
s.options = gOptions
|
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
|
var proto = SearchForProc(c, s, c.tab.tos-2) # -2 because we have a scope
|
||||||
# open for parameters
|
# open for parameters
|
||||||
if proto == nil:
|
if proto == nil:
|
||||||
if c.p.owner.kind != skModule:
|
s.typ.callConv = lastOptionEntry(c).defaultCC
|
||||||
s.typ.callConv = ccClosure
|
when false:
|
||||||
else:
|
# do a proper analysis here:
|
||||||
s.typ.callConv = lastOptionEntry(c).defaultCC
|
if c.p.owner.kind != skModule: s.typ.callConv = ccClosure
|
||||||
# add it here, so that recursive procs are possible:
|
# add it here, so that recursive procs are possible:
|
||||||
# -2 because we have a scope open for parameters
|
# -2 because we have a scope open for parameters
|
||||||
if kind in OverloadableSyms:
|
if kind in OverloadableSyms:
|
||||||
|
|
|
||||||
|
|
@ -684,6 +684,8 @@ proc transform(c: PTransf, n: PNode): PTransNode =
|
||||||
of nkBracketExpr:
|
of nkBracketExpr:
|
||||||
result = transformArrayAccess(c, n)
|
result = transformArrayAccess(c, n)
|
||||||
of nkLambda:
|
of nkLambda:
|
||||||
|
n.sons[codePos] = PNode(transform(c, n.sons[codePos]))
|
||||||
|
result = PTransNode(n)
|
||||||
when false: result = transformLambda(c, n)
|
when false: result = transformLambda(c, n)
|
||||||
of nkForStmt:
|
of nkForStmt:
|
||||||
result = transformFor(c, n)
|
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
|
echo "Required: ", path
|
||||||
# copy back:
|
# copy back:
|
||||||
moveFile(path, newName(path))
|
moveFile(path, newName(path))
|
||||||
of pcDirectory:
|
of pcDir:
|
||||||
walker(path)
|
walker(path)
|
||||||
else: nil
|
else: nil
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue