diff --git a/runtime/wasm/ints.wat b/runtime/wasm/ints.wat index f5c3fb8241..65f8a205b8 100644 --- a/runtime/wasm/ints.wat +++ b/runtime/wasm/ints.wat @@ -193,7 +193,7 @@ (then (local.set $res (i32.sub (i32.const 0) (local.get $res))))) (local.get $res)) - (#string $INT_ERRMSG "int.of_string") + (#string $INT_ERRMSG "int_of_string") (func (export "caml_int_of_string") (param $v (ref eq)) (result (ref eq)) diff --git a/runtime/wasm/jslib.wat b/runtime/wasm/jslib.wat index 03567900f4..625e13f31e 100644 --- a/runtime/wasm/jslib.wat +++ b/runtime/wasm/jslib.wat @@ -96,6 +96,10 @@ (func $jsbytes_of_bytes (param (ref $bytes)) (result anyref))) (import "jsstring" "bytes_of_jsbytes" (func $bytes_of_jsbytes (param anyref) (result (ref $bytes)))) + (import "jsstring" "jsstring_of_subbytes" + (func $jsstring_of_subbytes (param (ref $bytes) i32 i32) (result anyref))) + (import "jsstring" "jsstring_of_substring" + (func $jsstring_of_substring (param (ref eq) i32 i32) (result (ref eq)))) (import "int32" "caml_copy_int32" (func $caml_copy_int32 (param i32) (result (ref eq)))) (import "int32" "Int32_val" @@ -476,6 +480,24 @@ (return (struct.new $js (call $jsstring_of_bytes (local.get $s))))) )) +(#if use-js-string +(#then + (func (export "caml_jsstring_of_substring") + (param $s (ref eq)) (param $i i32) (param $l i32) (result (ref eq)) + (return_call $jsstring_of_substring + (local.get $s) (local.get $i) (local.get $l))) +) +(#else + (func (export "caml_jsstring_of_substring") + (param $vs (ref eq)) (param $i i32) (param $l i32) (result (ref eq)) + (local $s (ref $bytes)) + (local.set $s (ref.cast (ref $bytes) (local.get $vs))) + (return + (struct.new $js + (call $jsstring_of_subbytes + (local.get $s) (local.get $i) (local.get $l))))) +)) + (#if use-js-string (#then (func (export "caml_jsbytes_of_string") diff --git a/runtime/wasm/jsstring.wat b/runtime/wasm/jsstring.wat index 6195e144b4..e81108b2e0 100644 --- a/runtime/wasm/jsstring.wat +++ b/runtime/wasm/jsstring.wat @@ -24,6 +24,8 @@ (func $hash_string (param i32) (param anyref) (result i32))) (import "wasm:js-string" "length" (func $string_length (param externref) (result i32))) + (import "wasm:js-string" "substring" + (func $string_sub (param externref i32 i32) (result (ref extern)))) (import "wasm:js-string" "fromCharCodeArray" (func $fromCharCodeArray (param (ref null $wstring)) (param i32) (param i32) @@ -172,7 +174,7 @@ (br $loop)))) (i32.const 1)) - (func (export "jsstring_of_string") + (func $jsstring_of_string (export "jsstring_of_string") (param $s (ref eq)) (result (ref eq)) (if (result (ref eq)) (call $string_is_ascii (local.get $s)) (then @@ -184,6 +186,18 @@ (struct.get $string 0 (ref.cast (ref $string) (local.get $s))))))))) + (func (export "jsstring_of_substring") + (param $s (ref eq)) (param $i i32) (param $l i32) (result (ref eq)) + (return_call $jsstring_of_string + (struct.new $string + (any.convert_extern + (call $string_sub + (extern.convert_any + (struct.get $string 0 + (ref.cast (ref $string) (local.get $s)))) + (local.get $i) + (i32.add (local.get $i) (local.get $l))))))) + (func (export "string_of_jsstring") (param $s (ref eq)) (result (ref eq)) (if (result (ref eq)) (call $string_is_ascii (local.get $s))