| 1 | module scheme |
| 2 | |
| 3 | import arena |
| 4 | |
| 5 | fn test_break_iteration_count_does_not_add_allocation_or_exit_markers() { |
| 6 | mut region := arena.new() |
| 7 | region.push() |
| 8 | defer { |
| 9 | region.pop() |
| 10 | region.free() |
| 11 | } |
| 12 | mut vm := new_with_options(Options{ max_steps: 0, max_frames: 4 }) or { panic(err.msg()) } |
| 13 | vm.eval('(define (run n) |
| 14 | (do ((i 0 (+ i 1))) ((> i n) missing) (if (= i n) (break))) 42)') or { panic(err.msg()) } |
| 15 | run := vm.lookup('run') or { panic(err.msg()) } |
| 16 | mut arguments := [integer(1)] |
| 17 | vm.call(run, arguments) or { panic(err.msg()) } |
| 18 | mut fixed := 0 |
| 19 | for n in [1, 101, 10001] { |
| 20 | container_store_validated(mut arguments, 0, integer(n)) |
| 21 | before := region.used() |
| 22 | assert vm.call(run, arguments) or { panic(err.msg()) }.as_integer() or { panic(err.msg()) } == 42 |
| 23 | allocated := region.used() - before |
| 24 | if fixed == 0 { fixed = allocated } |
| 25 | assert allocated == fixed, '${n} iterations: ${allocated} bytes, expected fixed ${fixed}' |
| 26 | } |
| 27 | } |
| 28 | |