| 1 | module scheme |
| 2 | |
| 3 | import math |
| 4 | |
| 5 | fn test_native_floating_vile_syntax_matches_scheme_and_preserves_results() { |
| 6 | mut vm := new_with_options(Options{max_steps: 0, max_frames: 0})! |
| 7 | vm.eval_alt('work := fn(x) { (x + 0.25) * 2.0 }')! |
| 8 | vm.eval('(define(scheme-work x)(* (+ x 0.25) 2.0))')! |
| 9 | args := [integer(5), real(-1.5), real(-0.0), real(math.f64_from_bits(1))] |
| 10 | mut expected := []Value{} |
| 11 | for arg in args { expected << vm.call(vm.lookup('scheme-work')!, [arg])! } |
| 12 | vm.with_native_execution(fn [args, expected] (mut vm VM) !Value { |
| 13 | for name in ['work', 'scheme-work'] { |
| 14 | for i, arg in args { |
| 15 | actual := vm.call(vm.lookup(name)!, [arg])! |
| 16 | assert actual.tag == .real |
| 17 | assert math.f64_bits(actual.floating()) == math.f64_bits(expected[i].floating()) |
| 18 | } |
| 19 | } |
| 20 | hits, deopts := vm.native_execution_stats() |
| 21 | assert hits == u64(2 * args.len) && deopts == 0 |
| 22 | return unspecified() |
| 23 | })! |
| 24 | } |
| 25 | |