|
51 | 51 | (type $assoc |
52 | 52 | (struct |
53 | 53 | (field (ref $string)) |
54 | | - (field (ref eq)) |
| 54 | + (field (mut (ref eq))) |
55 | 55 | (field (mut (ref null $assoc))))) |
56 | 56 |
|
57 | 57 | (type $assoc_array (array (field (mut (ref null $assoc))))) |
|
62 | 62 | (array.new $assoc_array (ref.null $assoc) (global.get $Named_value_size))) |
63 | 63 |
|
64 | 64 | (func $find_named_value |
65 | | - (param $s (ref eq)) (param $l (ref null $assoc)) (result (ref null eq)) |
| 65 | + (param $s (ref eq)) (param $l (ref null $assoc)) (result (ref null $assoc)) |
66 | 66 | (local $a (ref $assoc)) |
67 | | - (block $tail (result (ref null eq)) |
| 67 | + (block $tail (result (ref null $assoc)) |
68 | 68 | (loop $loop |
69 | 69 | (local.set $a |
70 | 70 | (br_on_cast_fail $tail (ref null eq) (ref $assoc) (local.get $l))) |
|
74 | 74 | (local.get $s) |
75 | 75 | (struct.get $assoc 0 (local.get $a))))) |
76 | 76 | (then |
77 | | - (return (struct.get $assoc 1 (local.get $a))))) |
| 77 | + (return (local.get $a)))) |
78 | 78 | (local.set $l (struct.get $assoc 2 (local.get $a))) |
79 | 79 | (br $loop)))) |
80 | 80 |
|
81 | 81 | (func $caml_named_value (export "caml_named_value") |
82 | 82 | (param $s (ref $string)) (result (ref null eq)) |
83 | | - (return_call $find_named_value |
84 | | - (local.get $s) |
85 | | - (array.get $assoc_array (global.get $named_value_table) |
86 | | - (i32.rem_u |
87 | | - (i31.get_s |
88 | | - (ref.cast (ref i31) |
89 | | - (call $caml_string_hash |
90 | | - (ref.i31 (i32.const 0)) (local.get $s)))) |
91 | | - (global.get $Named_value_size))))) |
| 83 | + (block $not_found |
| 84 | + (return |
| 85 | + (struct.get $assoc 1 |
| 86 | + (br_on_null $not_found |
| 87 | + (call $find_named_value |
| 88 | + (local.get $s) |
| 89 | + (array.get $assoc_array (global.get $named_value_table) |
| 90 | + (i32.rem_u |
| 91 | + (i31.get_s |
| 92 | + (ref.cast (ref i31) |
| 93 | + (call $caml_string_hash |
| 94 | + (ref.i31 (i32.const 0)) (local.get $s)))) |
| 95 | + (global.get $Named_value_size)))))))) |
| 96 | + (return (ref.null eq))) |
92 | 97 |
|
93 | 98 | (func (export "caml_register_named_value") |
94 | 99 | (param (ref eq)) (param (ref eq)) (result (ref eq)) |
|
104 | 109 | (local.set $r |
105 | 110 | (array.get $assoc_array |
106 | 111 | (global.get $named_value_table) (local.get $h))) |
107 | | - (if (ref.is_null (call $find_named_value (local.get 0) (local.get $r))) |
108 | | - (then |
109 | | - (array.set $assoc_array |
110 | | - (global.get $named_value_table) (local.get $h) |
111 | | - (struct.new $assoc |
112 | | - (ref.cast (ref $string) (local.get 0)) |
113 | | - (local.get 1) (local.get $r))))) |
| 112 | + (block $not_found |
| 113 | + (struct.set $assoc 1 |
| 114 | + (br_on_null $not_found |
| 115 | + (call $find_named_value (local.get 0) (local.get $r))) |
| 116 | + (local.get 1)) |
| 117 | + (return (ref.i31 (i32.const 0)))) |
| 118 | + (array.set $assoc_array |
| 119 | + (global.get $named_value_table) (local.get $h) |
| 120 | + (struct.new $assoc |
| 121 | + (ref.cast (ref $string) (local.get 0)) |
| 122 | + (local.get 1) (local.get $r))) |
114 | 123 | (ref.i31 (i32.const 0))) |
115 | 124 |
|
| 125 | + ;; Used only for testing (tests-jsoo/bin), but inconvenient to pull out |
116 | 126 | (func (export "caml_unregister_named_value") |
117 | 127 | (param $name (ref eq)) (result (ref eq)) |
118 | 128 | (local $h i32) |
|
0 commit comments