From 6bf9b4b35debd1112091cee5fa562fef95b52786 Mon Sep 17 00:00:00 2001 From: Olivier Nicole Date: Thu, 18 Jul 2024 18:05:21 +0200 Subject: [PATCH 1/3] Add missing primitives --- runtime/wasm/bigarray.wat | 27 ++++++++++++++++++++++++++- runtime/wasm/domain.wat | 9 +++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/runtime/wasm/bigarray.wat b/runtime/wasm/bigarray.wat index 0baf91f92..57920939d 100644 --- a/runtime/wasm/bigarray.wat +++ b/runtime/wasm/bigarray.wat @@ -2097,7 +2097,9 @@ (ref.i31 (i32.wrap_i64 (i64.shr_u (local.get $d) (i64.const 56))))) (ref.i31 (i32.const 0))) - (func (export "caml_string_of_array") (param (ref eq)) (result (ref eq)) + (export "caml_bytes_of_array" (func $caml_string_of_array)) + (func $caml_string_of_array (export "caml_string_of_array") + (param (ref eq)) (result (ref eq)) ;; used to convert a typed array to a string (local $a (ref extern)) (local $len i32) (local $i i32) (local $s (ref $string)) @@ -2114,6 +2116,29 @@ (br $loop)))) (local.get $s)) + (export "caml_uint8_array_of_bytes" (func $caml_uint8_array_of_string)) + (func $caml_uint8_array_of_string (export "caml_uint8_array_of_string") + (param (ref eq)) (result (ref eq)) + ;; Convert a string to a typed array + (local $ta (ref extern)) (local $len i32) (local $i i32) + (local $s (ref $string)) + (local.set $s (ref.cast (ref $string) (local.get 0))) + (local.set $len (array.len (local.get $s))) + (local.set $ta + (call $ta_create + (i32.const 3) ;; Uint8Array + (local.get $len))) + (loop $loop + (if (i32.lt_u (local.get $i) (local.get $len)) + (then + (call $ta_set_ui8 + (local.get $ta) + (local.get $i) + (ref.i31 (array.get $string (local.get $s) (local.get $i)))) + (local.set $i (i32.add (local.get $i) (i32.const 1))) + (br $loop)))) + (call $wrap (extern.internalize (local.get $ta)))) + (func (export "caml_ba_get_kind") (param (ref eq)) (result i32) (struct.get $bigarray $ba_kind (ref.cast (ref $bigarray) (local.get 0)))) diff --git a/runtime/wasm/domain.wat b/runtime/wasm/domain.wat index 169f9d9ab..2ba72bcf9 100644 --- a/runtime/wasm/domain.wat +++ b/runtime/wasm/domain.wat @@ -69,6 +69,15 @@ (global.set $caml_domain_dls (local.get $a)) (ref.i31 (i32.const 0))) + (func (export "caml_domain_dls_compare_and_set") (param $old (ref eq)) (param $new (ref eq)) (result (ref eq)) + (if (result (ref eq)) + (ref.eq (global.get $caml_domain_dls) (local.get $old)) + (then + (global.set $caml_domain_dls (local.get $new)) + (ref.i31 (i32.const 1))) + (else + (ref.i31 (i32.const 0))))) + (func (export "caml_domain_dls_get") (param (ref eq)) (result (ref eq)) (global.get $caml_domain_dls)) From a87c5aeaa876206635b752577287c60c761e4981 Mon Sep 17 00:00:00 2001 From: Olivier Nicole Date: Tue, 23 Jul 2024 18:40:15 +0200 Subject: [PATCH 2/3] Add missing runtime_events primitives --- runtime/wasm/runtime_events.wat | 69 +++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 runtime/wasm/runtime_events.wat diff --git a/runtime/wasm/runtime_events.wat b/runtime/wasm/runtime_events.wat new file mode 100644 index 000000000..ff77e5570 --- /dev/null +++ b/runtime/wasm/runtime_events.wat @@ -0,0 +1,69 @@ +;; Wasm_of_ocaml runtime support +;; http://www.ocsigen.org/js_of_ocaml/ +;; +;; This program is free software; you can redistribute it and/or modify +;; it under the terms of the GNU Lesser General Public License as published by +;; the Free Software Foundation, with linking exception; +;; either version 2.1 of the License, or (at your option) any later version. +;; +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU Lesser General Public License for more details. +;; +;; You should have received a copy of the GNU Lesser General Public License +;; along with this program; if not, write to the Free Software +;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +(module + + (type $block (array (mut (ref eq)))) + + (global $caml_custom_event_index (mut i32) (i32.const 0)) + + (func (export "caml_runtime_events_user_register") + (param $evname (ref eq)) (param $evtag (ref eq)) (param $evtype (ref eq)) + (result (ref eq)) + (global.set $caml_custom_event_index + (i32.add (global.get $caml_custom_event_index) (i32.const 1))) + (array.new_fixed $block 5 + (ref.i31 (i32.const 0)) + (ref.i31 (global.get $caml_custom_event_index)) + (local.get $evname) + (local.get $evtag) + (local.get $evtype))) + + (func (export "caml_runtime_events_user_write") + (param (ref eq)) (param (ref eq)) (param (ref eq)) (result (ref eq)) + (ref.i31 (i32.const 0))) + + (func (export "caml_runtime_events_user_resolve") + (param (ref eq)) (param (ref eq)) (param (ref eq)) (result (ref eq)) + (ref.i31 (i32.const 0))) + + (func (export "caml_runtime_events_start") (param (ref eq)) (result (ref eq)) + (ref.i31 (i32.const 0))) + + (func (export "caml_runtime_events_pause") (param (ref eq)) (result (ref eq)) + (ref.i31 (i32.const 0))) + + (func (export "caml_runtime_events_resume") (param (ref eq)) (result (ref eq)) + (ref.i31 (i32.const 0))) + + (func (export "caml_ml_runtime_events_are_active") + (param (ref eq)) (result (ref eq)) + (ref.i31 (i32.const 0))) + + ;; TODO: use Javascript function + ;;(func (export "caml_runtime_events_create_cursor") + ;; (param (ref eq)) (result (ref eq)) + ;; (ref.i31 (i32.const 0))) + + (func (export "caml_runtime_events_free_cursor") + (param (ref eq)) (result (ref eq)) + (ref.i31 (i32.const 0))) + + (func (export "caml_runtime_events_read_poll") + (param (ref eq)) (param (ref eq)) (param (ref eq)) (result (ref eq)) + (ref.i31 (i32.const 0))) +) From 3eac4d4f6bd155c53a26e43905b7c71b749dcb1f Mon Sep 17 00:00:00 2001 From: Olivier Nicole Date: Thu, 1 Aug 2024 16:25:22 +0200 Subject: [PATCH 3/3] False-returning stub for caml_zstd_initialize This stops a few tests from failing with Wasm --- runtime/wasm/zstd.wat | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 runtime/wasm/zstd.wat diff --git a/runtime/wasm/zstd.wat b/runtime/wasm/zstd.wat new file mode 100644 index 000000000..09aa888ba --- /dev/null +++ b/runtime/wasm/zstd.wat @@ -0,0 +1,22 @@ +;; Wasm_of_ocaml runtime support +;; http://www.ocsigen.org/js_of_ocaml/ +;; +;; This program is free software; you can redistribute it and/or modify +;; it under the terms of the GNU Lesser General Public License as published by +;; the Free Software Foundation, with linking exception; +;; either version 2.1 of the License, or (at your option) any later version. +;; +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU Lesser General Public License for more details. +;; +;; You should have received a copy of the GNU Lesser General Public License +;; along with this program; if not, write to the Free Software +;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +(module + + (func (export "caml_zstd_initialize") (param (ref eq)) (result (ref eq)) + (ref.i31 (i32.const 0))) +)