|
| 1 | +(* TEST |
| 2 | + flags = "-extension layouts_beta"; |
| 3 | + { |
| 4 | + reference = "${test_source_directory}/uniform_or_mixed.native.reference"; |
| 5 | + compiler_reference2 = "${test_source_directory}/uniform_or_mixed.compiler.reference"; |
| 6 | + native; |
| 7 | + }{ |
| 8 | + reference = "${test_source_directory}/uniform_or_mixed.bytecode.reference"; |
| 9 | + compiler_reference2 = "${test_source_directory}/uniform_or_mixed.compiler.reference"; |
| 10 | + bytecode; |
| 11 | + } |
| 12 | +*) |
| 13 | + |
| 14 | +(* Bytecode and native code have slightly different outputs for the scannable prefix |
| 15 | + of mixed records. The fields of mixed records must be scanned in bytecode. |
| 16 | + (They are "faux mixed blocks".) |
| 17 | +*) |
| 18 | + |
| 19 | +type t_uniform1 = { x : int } |
| 20 | +type t_uniform2 = floatarray |
| 21 | +type t_uniform3 = int -> int |
| 22 | + |
| 23 | +type t_mixed0 = { x : int64# } |
| 24 | +type t_mixed1 = { x : string; y : int64# } |
| 25 | +type t_mixed2 = { x : string; y : string; z : int64# } |
| 26 | + |
| 27 | +let run (type a) test_name (obj : a) = |
| 28 | + let obj = Obj.repr obj in |
| 29 | + let uniform_or_mixed = Obj.Uniform_or_mixed.of_block obj in |
| 30 | + match Obj.Uniform_or_mixed.repr uniform_or_mixed with |
| 31 | + | Uniform -> |
| 32 | + assert (Obj.Uniform_or_mixed.is_uniform uniform_or_mixed); |
| 33 | + assert (not (Obj.Uniform_or_mixed.is_mixed uniform_or_mixed)); |
| 34 | + Printf.printf "%s: uniform\n" test_name |
| 35 | + | Mixed { scannable_prefix_len } -> |
| 36 | + assert (Obj.Uniform_or_mixed.is_mixed uniform_or_mixed); |
| 37 | + assert (not (Obj.Uniform_or_mixed.is_uniform uniform_or_mixed)); |
| 38 | + assert |
| 39 | + (Obj.Uniform_or_mixed.mixed_scannable_prefix_len_exn uniform_or_mixed = |
| 40 | + scannable_prefix_len); |
| 41 | + Printf.printf "%s: mixed (scannable_prefix_len = %d)\n" |
| 42 | + test_name scannable_prefix_len; |
| 43 | +;; |
| 44 | + |
| 45 | +let () = run "t_uniform1" ({ x = 3 } : t_uniform1) |
| 46 | +let () = run "t_uniform2.0" (Float.Array.create 0 : t_uniform2) |
| 47 | +let () = run "t_uniform2.1" (Float.Array.create 1 : t_uniform2) |
| 48 | +let () = run "t_uniform3" ((fun x -> x) : t_uniform3) |
| 49 | + |
| 50 | +let () = run "t_mixed0" ({ x = #4L } : t_mixed0) |
| 51 | +let () = run "t_mixed1" ({ x = ""; y = #5L } : t_mixed1) |
| 52 | +let () = run "t_mixed2" ({ x = ""; y = ""; z = #5L }: t_mixed2) |
| 53 | + |
0 commit comments