diff --git a/runtime/wasm/domain.wat b/runtime/wasm/domain.wat index f5465bdf58..5ae970a00b 100644 --- a/runtime/wasm/domain.wat +++ b/runtime/wasm/domain.wat @@ -16,6 +16,12 @@ ;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. (module + (import "obj" "caml_callback_1" + (func $caml_callback_1 + (param (ref eq)) (param (ref eq)) (result (ref eq)))) + (import "sync" "caml_ml_mutex_unlock" + (func $caml_ml_mutex_unlock (param (ref eq)) (result (ref eq)))) + (type $block (array (mut (ref eq)))) (type $function_1 (func (param (ref eq) (ref eq)) (result (ref eq)))) (type $closure (sub (struct (;(field i32);) (field (ref $function_1))))) @@ -95,6 +101,47 @@ (global $caml_domain_latest_id (export "caml_domain_latest_id") (mut i32) (i32.const 1)) +(@if (>= ocaml_version (5 2 0)) +(@then + (func (export "caml_domain_spawn") + (param $f (ref eq)) (param $term_sync_v (ref eq)) (result (ref eq)) + (local $id i32) (local $old i32) (local $ts (ref $block)) (local $res (ref eq)) + (local.set $id (global.get $caml_domain_latest_id)) + (global.set $caml_domain_latest_id + (i32.add (local.get $id) (i32.const 1))) + (local.set $old (global.get $caml_domain_id)) + (local.set $res + (call $caml_callback_1 (local.get $f) (ref.i31 (i32.const 0)))) + (global.set $caml_domain_id (local.get $old)) + (local.set $ts (ref.cast (ref $block) (local.get $term_sync_v))) + (drop (call $caml_ml_mutex_unlock (array.get $block (local.get $ts) (i32.const 2)))) + ;; TODO: fix exn case + (array.set + $block + (local.get $ts) + (i32.const 1) + (array.new_fixed + $block + 2 + (ref.i31 (i32.const 0)) + (array.new_fixed $block 2 (ref.i31 (i32.const 0)) (local.get $res)))) + (ref.i31 (local.get $id))) +) +(@else + (func (export "caml_domain_spawn") + (param $f (ref eq)) (param $mutex (ref eq)) (result (ref eq)) + (local $id i32) (local $old i32) + (local.set $id (global.get $caml_domain_latest_id)) + (global.set $caml_domain_latest_id + (i32.add (local.get $id) (i32.const 1))) + (local.set $old (global.get $caml_domain_id)) + (drop (call $caml_callback_1 (local.get $f) (ref.i31 (i32.const 0)))) + (global.set $caml_domain_id (local.get $old)) + (drop (call $caml_ml_mutex_unlock (local.get $mutex))) + (ref.i31 (local.get $id))) +)) + + (func (export "caml_ml_domain_id") (export "caml_ml_domain_index") (param (ref eq)) (result (ref eq)) (ref.i31 (global.get $caml_domain_id))) diff --git a/runtime/wasm/dune b/runtime/wasm/dune index 84618077d7..c55cb470cd 100644 --- a/runtime/wasm/dune +++ b/runtime/wasm/dune @@ -3,32 +3,6 @@ (package wasm_of_ocaml-compiler) (files runtime.wasm runtime.js)) -(rule - (target version-dependent.wat) - (deps version-dependent/post-5.2.wat) - (enabled_if - (>= %{ocaml_version} 5.2.0)) - (action - (copy %{deps} %{target}))) - -(rule - (target version-dependent.wat) - (deps version-dependent/post-5.1.wat) - (enabled_if - (and - (>= %{ocaml_version} 5.1.0) - (< %{ocaml_version} 5.2.0))) - (action - (copy %{deps} %{target}))) - -(rule - (target version-dependent.wat) - (deps version-dependent/pre-5.1.wat) - (enabled_if - (< %{ocaml_version} 5.1.0)) - (action - (copy %{deps} %{target}))) - (rule (target runtime.wasm) (deps diff --git a/runtime/wasm/marshal.wat b/runtime/wasm/marshal.wat index 246d41d356..389e97a31e 100644 --- a/runtime/wasm/marshal.wat +++ b/runtime/wasm/marshal.wat @@ -50,8 +50,6 @@ (import "custom" "caml_find_custom_operations" (func $caml_find_custom_operations (param (ref $string)) (result (ref null $custom_operations)))) - (import "version-dependent" "caml_marshal_header_size" - (global $caml_marshal_header_size i32)) (global $input_val_from_string (ref $string) (array.new_fixed $string 21 @@ -723,6 +721,16 @@ (data $marshal_data_size "Marshal.data_size") +(@if (>= ocaml_version (5 1 0)) +(@then + (global $caml_marshal_header_size (export "caml_marshal_header_size") i32 + (i32.const 16)) +) +(@else + (global $caml_marshal_header_size (export "caml_marshal_header_size") i32 + (i32.const 20)) +)) + (func (export "caml_marshal_data_size") (param $buf (ref eq)) (param $ofs (ref eq)) (result (ref eq)) (local $s (ref $intern_state)) diff --git a/runtime/wasm/runtime_events.wat b/runtime/wasm/runtime_events.wat index 9ac0f5f2f9..9c7efa6b01 100644 --- a/runtime/wasm/runtime_events.wat +++ b/runtime/wasm/runtime_events.wat @@ -33,6 +33,18 @@ (local.get $evtag) (local.get $evtype))) +(@if (>= ocaml_version (5 2 0)) +(@then + (func (export "caml_runtime_events_user_write") + (param (ref eq)) (param (ref eq)) (param (ref eq)) (result (ref eq)) + (ref.i31 (i32.const 0))) +) +(@else + (func (export "caml_runtime_events_user_write") + (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))) diff --git a/runtime/wasm/version-dependent/post-5.1.wat b/runtime/wasm/version-dependent/post-5.1.wat deleted file mode 100644 index 258505a5e9..0000000000 --- a/runtime/wasm/version-dependent/post-5.1.wat +++ /dev/null @@ -1,46 +0,0 @@ -;; 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 - (import "obj" "caml_callback_1" - (func $caml_callback_1 - (param (ref eq)) (param (ref eq)) (result (ref eq)))) - (import "sync" "caml_ml_mutex_unlock" - (func $caml_ml_mutex_unlock (param (ref eq)) (result (ref eq)))) - (import "domain" "caml_domain_latest_id" - (global $caml_domain_latest_id (mut i32))) - (import "domain" "caml_domain_id" - (global $caml_domain_id (mut i32))) - - (func (export "caml_runtime_events_user_write") - (param (ref eq)) (param (ref eq)) (result (ref eq)) - (ref.i31 (i32.const 0))) - - (func (export "caml_domain_spawn") - (param $f (ref eq)) (param $mutex (ref eq)) (result (ref eq)) - (local $id i32) (local $old i32) - (local.set $id (global.get $caml_domain_latest_id)) - (global.set $caml_domain_latest_id - (i32.add (local.get $id) (i32.const 1))) - (local.set $old (global.get $caml_domain_id)) - (drop (call $caml_callback_1 (local.get $f) (ref.i31 (i32.const 0)))) - (global.set $caml_domain_id (local.get $old)) - (drop (call $caml_ml_mutex_unlock (local.get $mutex))) - (ref.i31 (local.get $id))) - - (global (export "caml_marshal_header_size") i32 (i32.const 16)) -) diff --git a/runtime/wasm/version-dependent/post-5.2.wat b/runtime/wasm/version-dependent/post-5.2.wat deleted file mode 100644 index b4183d2dcb..0000000000 --- a/runtime/wasm/version-dependent/post-5.2.wat +++ /dev/null @@ -1,59 +0,0 @@ -;; 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)))) - (import "obj" "caml_callback_1" - (func $caml_callback_1 - (param (ref eq)) (param (ref eq)) (result (ref eq)))) - (import "sync" "caml_ml_mutex_unlock" - (func $caml_ml_mutex_unlock (param (ref eq)) (result (ref eq)))) - (import "domain" "caml_domain_latest_id" - (global $caml_domain_latest_id (mut i32))) - (import "domain" "caml_domain_id" - (global $caml_domain_id (mut i32))) - - (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_domain_spawn") - (param $f (ref eq)) (param $term_sync_v (ref eq)) (result (ref eq)) - (local $id i32) (local $old i32) (local $ts (ref $block)) (local $res (ref eq)) - (local.set $id (global.get $caml_domain_latest_id)) - (global.set $caml_domain_latest_id - (i32.add (local.get $id) (i32.const 1))) - (local.set $old (global.get $caml_domain_id)) - (local.set $res - (call $caml_callback_1 (local.get $f) (ref.i31 (i32.const 0)))) - (global.set $caml_domain_id (local.get $old)) - (local.set $ts (ref.cast (ref $block) (local.get $term_sync_v))) - (drop (call $caml_ml_mutex_unlock (array.get $block (local.get $ts) (i32.const 2)))) - ;; TODO: fix exn case - (array.set - $block - (local.get $ts) - (i32.const 1) - (array.new_fixed - $block - 2 - (ref.i31 (i32.const 0)) - (array.new_fixed $block 2 (ref.i31 (i32.const 0)) (local.get $res)))) - (ref.i31 (local.get $id))) - - (global (export "caml_marshal_header_size") i32 (i32.const 16)) -) diff --git a/runtime/wasm/version-dependent/pre-5.1.wat b/runtime/wasm/version-dependent/pre-5.1.wat deleted file mode 100644 index cc23b90ad7..0000000000 --- a/runtime/wasm/version-dependent/pre-5.1.wat +++ /dev/null @@ -1,46 +0,0 @@ -;; 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 - (import "obj" "caml_callback_1" - (func $caml_callback_1 - (param (ref eq)) (param (ref eq)) (result (ref eq)))) - (import "sync" "caml_ml_mutex_unlock" - (func $caml_ml_mutex_unlock (param (ref eq)) (result (ref eq)))) - (import "domain" "caml_domain_latest_id" - (global $caml_domain_latest_id (mut i32))) - (import "domain" "caml_domain_id" - (global $caml_domain_id (mut i32))) - - (func (export "caml_runtime_events_user_write") - (param (ref eq)) (param (ref eq)) (result (ref eq)) - (ref.i31 (i32.const 0))) - - (func (export "caml_domain_spawn") - (param $f (ref eq)) (param $mutex (ref eq)) (result (ref eq)) - (local $id i32) (local $old i32) - (local.set $id (global.get $caml_domain_latest_id)) - (global.set $caml_domain_latest_id - (i32.add (local.get $id) (i32.const 1))) - (local.set $old (global.get $caml_domain_id)) - (drop (call $caml_callback_1 (local.get $f) (ref.i31 (i32.const 0)))) - (global.set $caml_domain_id (local.get $old)) - (drop (call $caml_ml_mutex_unlock (local.get $mutex))) - (ref.i31 (local.get $id))) - - (global (export "caml_marshal_header_size") i32 (i32.const 20)) -)