fixes anon procs created by macros
This commit is contained in:
parent
76cf4f4c1b
commit
2ad9a16e0a
2 changed files with 35 additions and 2 deletions
|
|
@ -1558,7 +1558,9 @@ proc semProcAux(c: PContext, n: PNode, kind: TSymKind,
|
||||||
popOwner(c)
|
popOwner(c)
|
||||||
if n.sons[patternPos].kind != nkEmpty:
|
if n.sons[patternPos].kind != nkEmpty:
|
||||||
c.patterns.add(s)
|
c.patterns.add(s)
|
||||||
if isAnon: result.typ = s.typ
|
if isAnon:
|
||||||
|
n.kind = nkLambda
|
||||||
|
result.typ = s.typ
|
||||||
if isTopLevel(c) and s.kind != skIterator and
|
if isTopLevel(c) and s.kind != skIterator and
|
||||||
s.typ.callConv == ccClosure:
|
s.typ.callConv == ccClosure:
|
||||||
localError(s.info, "'.closure' calling convention for top level routines is invalid")
|
localError(s.info, "'.closure' calling convention for top level routines is invalid")
|
||||||
|
|
|
||||||
|
|
@ -6,10 +6,14 @@ discard """
|
||||||
3
|
3
|
||||||
noReturn
|
noReturn
|
||||||
6
|
6
|
||||||
|
calling mystuff
|
||||||
|
yes
|
||||||
|
calling mystuff
|
||||||
|
yes
|
||||||
'''
|
'''
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import future
|
import future, macros
|
||||||
|
|
||||||
proc twoParams(x: (int, int) -> int): int =
|
proc twoParams(x: (int, int) -> int): int =
|
||||||
result = x(5, 5)
|
result = x(5, 5)
|
||||||
|
|
@ -41,3 +45,30 @@ proc pass2(f: (int, int) -> int): (int) -> int =
|
||||||
((x: int) -> int) => f(2, x)
|
((x: int) -> int) => f(2, x)
|
||||||
|
|
||||||
echo pass2((x, y) => x + y)(4)
|
echo pass2((x, y) => x + y)(4)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
proc register(name: string; x: proc()) =
|
||||||
|
echo "calling ", name
|
||||||
|
x()
|
||||||
|
|
||||||
|
register("mystuff", proc () =
|
||||||
|
echo "yes"
|
||||||
|
)
|
||||||
|
|
||||||
|
proc helper(x: NimNode): NimNode =
|
||||||
|
if x.kind == nnkProcDef:
|
||||||
|
result = copyNimTree(x)
|
||||||
|
result[0] = newEmptyNode()
|
||||||
|
result = newCall("register", newLit($x[0]), result)
|
||||||
|
else:
|
||||||
|
result = copyNimNode(x)
|
||||||
|
for i in 0..<x.len:
|
||||||
|
result.add helper(x[i])
|
||||||
|
|
||||||
|
macro m(x: untyped): untyped =
|
||||||
|
result = helper(x)
|
||||||
|
|
||||||
|
m:
|
||||||
|
proc mystuff() =
|
||||||
|
echo "yes"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue