Skip to content

Commit e83bac7

Browse files
vouillonhhugo
authored andcommitted
Wasm runtime: implement caml_bigstring_memrchr
1 parent e3b6e53 commit e83bac7

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

runtime/wasm/bigstring.wat

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,29 @@
201201
(local.set $len (i32.sub (local.get $len) (i32.const 1)))
202202
(local.set $pos (i32.add (local.get $pos) (i32.const 1)))
203203
(br $loop))))
204-
(ref.i31 (i32.const -1)))
204+
(ref.i31 (i32.const -1)))
205+
206+
(func (export "caml_bigstring_memrchr")
207+
(param $s (ref eq)) (param $vc (ref eq))
208+
(param $vpos (ref eq)) (param $vlen (ref eq)) (result (ref eq))
209+
(local $pos i32) (local $len i32) (local $c i32) (local $cur i32)
210+
(local $d (ref extern))
211+
(local.set $c (i31.get_s (ref.cast (ref i31) (local.get $vc))))
212+
(local.set $pos (i31.get_s (ref.cast (ref i31) (local.get $vpos))))
213+
(local.set $len (i31.get_s (ref.cast (ref i31) (local.get $vlen))))
214+
(local.set $d (call $caml_ba_get_data (local.get $s)))
215+
(local.set $cur
216+
(i32.sub (i32.add (local.get $pos) (local.get $len)) (i32.const 1)))
217+
(loop $loop
218+
(if (i32.ge_s (local.get $cur) (local.get $pos))
219+
(then
220+
(if (i32.eq (local.get $c)
221+
(call $ta_get_ui8 (local.get $d) (local.get $cur)))
222+
(then
223+
(return (ref.i31 (local.get $cur)))))
224+
(local.set $cur (i32.sub (local.get $cur) (i32.const 1)))
225+
(br $loop))))
226+
(ref.i31 (i32.const -1)))
205227

206228
(export "caml_bigstring_blit_string_to_ba"
207229
(func $caml_bigstring_blit_bytes_to_ba))

0 commit comments

Comments
 (0)