mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-30 09:54:49 +00:00
[other] newruntime: add a simple closure iterator test
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
discard """
|
||||
cmd: '''nim c --newruntime $file'''
|
||||
output: '''a b
|
||||
0 0 alloc/dealloc pairs: 0'''
|
||||
70
|
||||
2 2 alloc/dealloc pairs: 0'''
|
||||
"""
|
||||
|
||||
import core / allocators
|
||||
@@ -13,10 +14,17 @@ proc main(): owned(proc()) =
|
||||
result = proc() =
|
||||
echo a, " ", b
|
||||
|
||||
|
||||
proc foo(f: (iterator(): int)) =
|
||||
for i in f(): echo i
|
||||
|
||||
proc wrap =
|
||||
let p = main()
|
||||
p()
|
||||
|
||||
let fIt = iterator(): int = yield 70
|
||||
foo fIt
|
||||
|
||||
wrap()
|
||||
let (a, d) = allocCounters()
|
||||
discard cprintf("%ld %ld alloc/dealloc pairs: %ld\n", a, d, system.allocs)
|
||||
|
||||
Reference in New Issue
Block a user