vile / scheme / native_import_cleanup_d_vile_native_test.v
18 lines · 17 sloc · 726 bytes · 76646891b77a3d5c6af4a1e42b122cd61dc1654b
Raw
1module scheme
2
3fn test_native_calls_retain_imported_names_and_providers_after_import_cleanup() {
4 mut vm := new_with_options(Options{ max_steps: 0, max_frames: 0 })!
5 vm.eval('(define-library (native imported)
6 (export work) (import (scheme base))
7 (begin (define (work x) (+ x 1))))')!
8 vm.with_native_execution(fn (mut vm VM) !Value {
9 vm.eval('(import (rename (prefix (native imported) imported:) (imported:work imported-work)))')!
10 callback := vm.lookup('imported-work')!
11 assert vm.call(callback, [integer(40)])!.whole() == 41
12 gc_collect()
13 assert vm.call(callback, [integer(41)])!.whole() == 42
14 scope := unsafe { &NativeScope(vm.native_execution_scope) }
15 assert scope.hits >= 2
16 return unspecified()
17 })!
18}
19