module scheme fn test_native_argument_callback_loop_refreshes_same_code_environments() { mut vm := new_with_options(Options{max_steps: 0,max_frames: 0})! vm.eval('(define (make bias)(lambda(x)(+ x bias))) (define a (make 7)) (define b (make 19)) (define (work f n)(do ((i n (- i 1))(sum 0 (+ sum (f 0)))) ((= i 0) sum)))')! vm.with_native_execution(fn (mut vm VM) !Value { work := vm.lookup('work')! for name, expected in {'a':28672,'b':77824} { assert vm.call(work,[vm.lookup(name)!,integer(4096)])!.whole() == expected } scope := unsafe { &NativeScope(vm.native_execution_scope) } assert scope.hits == 2 && scope.deopts == 0 return unspecified() })! } fn test_native_argument_callback_assignment_keeps_dynamic_dispatch() { mut vm := new_with_options(Options{max_steps: 0,max_frames: 0})! vm.eval('(define (a x)(+ x 7)) (define (b x)(+ x 19)) (define (work f g n)(let () (set! f g)) (+ (f n) (g n)))')! vm.with_native_execution(fn (mut vm VM) !Value { assert vm.call(vm.lookup('work')!,[vm.lookup('a')!,vm.lookup('b')!,integer(100)])!.whole() == 238 hits,deopts := vm.native_execution_stats() assert hits == 1 && deopts == 0 return unspecified() })! } fn test_native_argument_callback_internal_entries_recheck_before_effects() { for recursive in ['(work g f (- n 1) v)','(+ 100 (work g f (- n 1) v))'] { mut vm := new_with_options(Options{max_steps: 0,max_frames: 0})! vm.eval('(define (make bias)(lambda(x)(+ x bias))) (define a (make 7)) (define b (make 19)) (define work (letrec ((work (lambda(f g n v)(vector-set! v 0 (+ (vector-ref v 0) 1)) (if (= n 0) (f 1) '+recursive+')))) work))')! vm.with_native_execution(fn [recursive] (mut vm VM) !Value { v := vector([integer(0)]) result := vm.call(vm.lookup('work')!,[vm.lookup('a')!,vm.lookup('b')!,integer(1),v])! assert result.whole() == if recursive.starts_with('(+') { 120 } else { 20 } assert v.vector_pointer().items[0].whole() == 2 _,deopts := vm.native_execution_stats() assert deopts > 0 return unspecified() })! } }