Skip to content

Commit

Permalink
Marshal header size change in OCaml 5.1
Browse files Browse the repository at this point in the history
  • Loading branch information
vouillon committed Sep 13, 2024
1 parent 6d43b92 commit f41575c
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 4 deletions.
14 changes: 12 additions & 2 deletions runtime/wasm/dune
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,19 @@

(rule
(target version-dependent.wat)
(deps version-dependent/pre-5.2.wat)
(deps version-dependent/post-5.2.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.2.0))
(< %{ocaml_version} 5.1.0))
(action
(copy %{deps} %{target})))

Expand Down
4 changes: 2 additions & 2 deletions runtime/wasm/marshal.wat
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@
(func $caml_find_custom_operations
(param (ref $string)) (result (ref null $custom_operations))))

(global $caml_marshal_header_size (export "caml_marshal_header_size")
(mut i32) (i32.const 20))
(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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,6 @@
(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))
)
2 changes: 2 additions & 0 deletions runtime/wasm/version-dependent/post-5.2.wat
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,6 @@
(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))
)
46 changes: 46 additions & 0 deletions runtime/wasm/version-dependent/pre-5.1.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
;; 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))
)

0 comments on commit f41575c

Please sign in to comment.