vile / scheme / native_scope_arguments_d_vile_native_test.v
39 lines · 36 sloc · 1.48 KB · 76646891b77a3d5c6af4a1e42b122cd61dc1654b
Raw
1module scheme
2
3fn test_native_scope_arguments_lower_parallel_and_nontail_bindings() {
4 mut vm := new_with_options(Options{max_steps: 0, max_frames: 0})!
5 vm.eval('(define(work x)
6 (+ (let ((a(+ x 1))(b(* x 2))) (+ a b x))
7 (let ((v(+ x 3))) (* v 2))))')!
8 vm.with_native_execution(fn (mut vm VM) !Value {
9 assert vm.call(vm.lookup('work')!, [integer(10)])!.whole() == 67
10 assert vm.call(vm.lookup('work')!, [integer(20)])!.whole() == 127
11 hits, deopts := vm.native_execution_stats()
12 assert hits == 2 && deopts == 0
13 return unspecified()
14 })!
15}
16
17fn test_native_scope_arguments_fallback_keeps_initializer_continuations() {
18 mut vm := new_with_options(Options{max_steps: 0, max_frames: 0})!
19 vm.eval('(define saved #f)(define(work x)
20 (let ((a(call/cc(lambda(k)(set! saved k) x)))(b(+ x 2))) (+ a b x)))')!
21 vm.with_native_execution(fn (mut vm VM) !Value {
22 assert vm.call(vm.lookup('work')!, [integer(10)])!.whole() == 32
23 gc_collect()
24 assert vm.call(vm.lookup('saved')!, [integer(20)])!.whole() == 42
25 assert vm.call(vm.lookup('saved')!, [integer(30)])!.whole() == 52
26 return unspecified()
27 })!
28}
29
30fn test_native_map_callbacks_keep_backend_priority_over_cached_vm_entry() {
31 mut vm := new_with_options(Options{max_steps: 0, max_frames: 0})!
32 vm.eval('(define(twice x)(* x 2))')!
33 vm.with_native_execution(fn (mut vm VM) !Value {
34 assert write(vm.eval("(map twice '(1 2 3))")!)! == '(2 4 6)'
35 hits, deopts := vm.native_execution_stats()
36 assert hits == 3 && deopts == 0
37 return unspecified()
38 })!
39}
40