mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-28 18:24:01 +00:00
rewrote lambdalifting; fixes deeply nested closures
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
discard """
|
||||
file: "tclosure.nim"
|
||||
output: "2 4 6 8 10"
|
||||
disabled: true
|
||||
output: "1 3 6 11 20"
|
||||
"""
|
||||
# Test the closure implementation
|
||||
|
||||
@@ -30,7 +29,8 @@ proc testA() =
|
||||
testA()
|
||||
|
||||
myData.each do (x: int):
|
||||
write(stout, x)
|
||||
write(stdout, x)
|
||||
write(stdout, " ")
|
||||
|
||||
#OUT 2 4 6 8 10
|
||||
|
||||
@@ -42,6 +42,6 @@ type
|
||||
proc getInterf(): ITest =
|
||||
var shared: int
|
||||
|
||||
return (setter: proc (x) = shared = x,
|
||||
return (setter: proc (x: int) = shared = x,
|
||||
getter: proc (): int = return shared)
|
||||
|
||||
|
||||
36
tests/closure/tnestedclosure.nim
Normal file
36
tests/closure/tnestedclosure.nim
Normal file
@@ -0,0 +1,36 @@
|
||||
discard """
|
||||
output: '''foo88
|
||||
23 24foo 88
|
||||
foo88
|
||||
23 24foo 88'''
|
||||
"""
|
||||
|
||||
# test nested closure
|
||||
proc main(param: int) =
|
||||
var foo = 23
|
||||
proc outer(outerParam: string) =
|
||||
var outerVar = 88
|
||||
echo outerParam, outerVar
|
||||
proc inner() =
|
||||
block Test:
|
||||
echo foo, " ", param, outerParam, " ", outerVar
|
||||
inner()
|
||||
outer("foo")
|
||||
|
||||
# test simple closure within dummy 'main':
|
||||
proc dummy =
|
||||
proc main2(param: int) =
|
||||
var foo = 23
|
||||
proc outer(outerParam: string) =
|
||||
var outerVar = 88
|
||||
echo outerParam, outerVar
|
||||
proc inner() =
|
||||
block Test:
|
||||
echo foo, " ", param, outerParam, " ", outerVar
|
||||
inner()
|
||||
outer("foo")
|
||||
main2(24)
|
||||
|
||||
dummy()
|
||||
|
||||
main(24)
|
||||
Reference in New Issue
Block a user