Skip to content

Commit

Permalink
Merge pull request ocaml-wasm#59 from OlivierNicole/add-primitives
Browse files Browse the repository at this point in the history
Add missing primitives
  • Loading branch information
vouillon committed Aug 30, 2024
2 parents 5417acb + 3eac4d4 commit fb964b6
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 1 deletion.
27 changes: 26 additions & 1 deletion runtime/wasm/bigarray.wat
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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))))

Expand Down
9 changes: 9 additions & 0 deletions runtime/wasm/domain.wat
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
69 changes: 69 additions & 0 deletions runtime/wasm/runtime_events.wat
Original file line number Diff line number Diff line change
@@ -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)))
)
22 changes: 22 additions & 0 deletions runtime/wasm/zstd.wat
Original file line number Diff line number Diff line change
@@ -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)))
)

0 comments on commit fb964b6

Please sign in to comment.