module scheme import arena fn numeric_budget_observation(mut vm VM, source string, budget int) !Value { options := vm.options vm.options = Options{ ...options, max_steps: budget } return vm.eval(source) } // Bounded VMs retain the complete primitive dispatcher. Compare its exact // budget/error behavior with the ordinary integer path, including promotion // and calls that must fall back rather than charging their invocation twice. fn test_integer_dispatch_keeps_the_complete_dispatchers_budget_boundaries() { mut plain := new() mut bounded := new_bounded(Options{}, arena.ChunkLimits{ max_live_bytes: 16 * 1024 * 1024 })! defer { bounded.close() or { panic(err) } } for source in [ '(+ 40 2)', '(list (+ 40 2) (- 44 2))', '(let ((f +)) (f 40 2))', '(+ 9223372036854775807 1)', '(/ 1 0)', ] { for budget in 0 .. 40 { mut plain_error := ?IError(none) want := numeric_budget_observation(mut plain, source, budget) or { plain_error = err unspecified() } mut bounded_error := ?IError(none) got := bounded.run(fn [source, budget] (mut vm VM) !Value { return numeric_budget_observation(mut vm, source, budget) }) or { bounded_error = err unspecified() } if expected := plain_error { actual := bounded_error or { panic('bounded dispatcher accepted a denied call') } assert expected.msg() == actual.msg() } else { assert bounded_error == none assert write(want)! == write(got)! } } } }