Skip to content

Commit

Permalink
Runtime: no longer use string.const
Browse files Browse the repository at this point in the history
  • Loading branch information
vouillon committed Oct 2, 2023
1 parent bb007b3 commit 66f151e
Show file tree
Hide file tree
Showing 11 changed files with 85 additions and 29 deletions.
1 change: 0 additions & 1 deletion runtime/wasm/bigarray.wat
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
(module
(import "bindings" "log" (func $log_js (param anyref)))
(import "bindings" "ta_create"
(func $ta_create (param i32) (param i32) (result (ref extern))))
(import "bindings" "ta_normalize"
Expand Down
1 change: 0 additions & 1 deletion runtime/wasm/bigstring.wat
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
(module
(import "bindings" "log" (func $log_js (param anyref)))
(import "jslib" "wrap" (func $wrap (param anyref) (result (ref eq))))
(import "jslib" "unwrap" (func $unwrap (param (ref eq)) (result anyref)))
(import "jslib" "caml_js_get"
Expand Down
16 changes: 13 additions & 3 deletions runtime/wasm/dynlink.wat
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
(module
(import "bindings" "log" (func $log_js (param anyref)))
(import "jslib" "log_str" (func $log_str (param (ref $string))))

(type $string (array (mut i8)))

(data $caml_dynlink_close_lib "caml_dynlink_close_lib")

(func (export "caml_dynlink_close_lib")
(param (ref eq)) (result (ref eq))
;; ZZZ
(call $log_js (string.const "caml_dynlink_close_lib"))
(call $log_str
(array.new_data $string $caml_dynlink_close_lib
(i32.const 0) (i32.const 22)))
(ref.i31 (i32.const 0)))

(data $caml_dynlink_lookup_symbol "caml_dynlink_lookup_symbol")

(func (export "caml_dynlink_lookup_symbol")
(param (ref eq)) (param (ref eq)) (result (ref eq))
;; ZZZ
(call $log_js (string.const "caml_dynlink_lookup_symbol"))
(call $log_str
(array.new_data $string $caml_dynlink_lookup_symbol
(i32.const 0) (i32.const 26)))
(ref.i31 (i32.const 0)))
)
8 changes: 6 additions & 2 deletions runtime/wasm/fs.wat
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(module
(import "bindings" "log" (func $log_js (param anyref)))
(import "jslib" "log_str" (func $log_str (param (ref $string))))
(import "bindings" "getcwd" (func $getcwd (result anyref)))
(import "bindings" "chdir" (func $chdir (param anyref)))
(import "bindings" "mkdir" (func $mkdir (param anyref) (param i32)))
Expand Down Expand Up @@ -108,10 +108,14 @@
(local.get $msg) (local.get $len) (i32.const 0) (i32.const 27))
(call $caml_raise_sys_error (local.get $msg)))

(data $caml_read_file_content "caml_read_file_content")

(func (export "caml_read_file_content")
(param (ref eq)) (result (ref eq))
;; ZZZ
(call $log_js (string.const "caml_read_file_content"))
(call $log_str
(array.new_data $string $caml_read_file_content
(i32.const 0) (i32.const 22)))
(call $caml_raise_no_such_file (local.get 0))
(ref.i31 (i32.const 0)))

Expand Down
2 changes: 0 additions & 2 deletions runtime/wasm/gc.wat
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
(module
(import "bindings" "log" (func $log_js (param anyref)))

(type $float (struct (field f64)))
(type $block (array (mut (ref eq))))

Expand Down
8 changes: 6 additions & 2 deletions runtime/wasm/int64.wat
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(module
(import "bindings" "log" (func $log_js (param anyref)))
(import "jslib" "log_str" (func $log_str (param (ref $string))))
(import "ints" "parse_sign_and_base"
(func $parse_sign_and_base
(param (ref $string)) (result i32 i32 i32 i32)))
Expand Down Expand Up @@ -172,10 +172,14 @@
(then (local.set $res (i64.sub (i64.const 0) (local.get $res)))))
(return_call $caml_copy_int64 (local.get $res)))

(data $caml_int64_create_lo_mi_hi "caml_int64_create_lo_mi_hi")

(func (export "caml_int64_create_lo_mi_hi")
(param (ref eq) (ref eq) (ref eq)) (result (ref eq))
;; ZZZ does not really make sense
(call $log_js (string.const "caml_int64_create_lo_mi_hi"))
(call $log_str
(array.new_data $string $caml_int64_create_lo_mi_hi
(i32.const 0) (i32.const 26)))
(ref.i31 (i32.const 0)))

(func $format_int64_default (param $d i64) (result (ref eq))
Expand Down
8 changes: 6 additions & 2 deletions runtime/wasm/io.wat
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(module
(import "bindings" "log" (func $log_js (param anyref)))
(import "jslib" "log_str" (func $log_str (param (ref $string))))
(import "fail" "caml_raise_end_of_file" (func $caml_raise_end_of_file))
(import "jslib" "wrap" (func $wrap (param anyref) (result (ref eq))))
(import "jslib" "unwrap" (func $unwrap (param (ref eq)) (result anyref)))
Expand Down Expand Up @@ -801,10 +801,14 @@
(then (call $caml_flush (local.get $ch))))))
(ref.i31 (i32.const 0)))

(data $caml_ml_set_channel_refill "caml_ml_set_channel_refill")

(func (export "caml_ml_set_channel_refill")
(param (ref eq) (ref eq)) (result (ref eq))
;; ZZZ
(call $log_js (string.const "caml_ml_set_channel_refill"))
(call $log_str
(array.new_data $string $caml_ml_set_channel_refill
(i32.const 0) (i32.const 26)))
(ref.i31 (i32.const 0)))

(func (export "caml_ml_channel_size") (param (ref eq)) (result (ref eq))
Expand Down
5 changes: 5 additions & 0 deletions runtime/wasm/jslib.wat
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
(module
(import "bindings" "log" (func $log_js (param anyref)))
(import "bindings" "identity" (func $to_float (param anyref) (result f64)))
(import "bindings" "identity" (func $from_float (param f64) (result anyref)))
(import "bindings" "identity" (func $to_bool (param anyref) (result i32)))
Expand Down Expand Up @@ -639,4 +640,8 @@
(return
(array.get $block (local.get $exn) (i32.const 2)))))))
(call $wrap (ref.null any)))

(func (export "log_str") (param $s (ref $string))
(call $log_js
(call $unwrap (call $caml_jsstring_of_string (local.get $s)))))
)
2 changes: 0 additions & 2 deletions runtime/wasm/jsstring.wat
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
(module
(import "bindings" "log" (func $log_js (param anyref)))

(import "bindings" "read_string"
(func $read_string (param i32) (result anyref)))
(import "bindings" "read_string_stream"
Expand Down
62 changes: 49 additions & 13 deletions runtime/wasm/nat.wat
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(module
(import "bindings" "log" (func $log_js (param anyref)))
(import "jslib" "log_str" (func $log_str (param (ref $string))))
(import "custom" "caml_register_custom_operations"
(func $caml_register_custom_operations
(param $ops (ref $custom_operations))))
Expand Down Expand Up @@ -362,78 +362,105 @@
(if (local.get $len1) (then (br $loop))))
(i31.new (i32.const 1)))

(data $mult_nat "mult_nat")

(func (export "mult_nat")
(param $nat1 (ref eq)) (param $vofs1 (ref eq)) (param $vlen1 (ref eq))
(param $nat2 (ref eq)) (param $vofs2 (ref eq)) (param $vlen2 (ref eq))
(param $nat3 (ref eq)) (param $vofs3 (ref eq)) (result (ref eq))
;; ZZZ
(call $log_js (string.const "mult_nat"))
(call $log_str
(array.new_data $string $mult_nat (i32.const 0) (i32.const 8)))
(unreachable))

(data $square_nat "square_nat")

(func (export "square_nat")
(param $nat1 (ref eq)) (param $vofs1 (ref eq)) (param $vlen1 (ref eq))
(param $nat2 (ref eq)) (param $vofs2 (ref eq)) (param $vlen2 (ref eq))
(result (ref eq))
;; ZZZ
(call $log_js (string.const "square_nat"))
(call $log_str
(array.new_data $string $square_nat (i32.const 0) (i32.const 10)))
(unreachable))

(data $shift_left_nat "shift_left_nat")

(func (export "shift_left_nat")
(param $nat1 (ref eq)) (param $vofs1 (ref eq)) (param $vlen1 (ref eq))
(param $nat2 (ref eq)) (param $vofs2 (ref eq)) (param $vnbits (ref eq))
(result (ref eq))
;; ZZZ
(call $log_js (string.const "shift_left_nat"))
(call $log_str
(array.new_data $string $shift_left_nat (i32.const 0) (i32.const 14)))
(unreachable))

(data $shift_right_nat "shift_right_nat")

(func (export "shift_right_nat")
(param $nat1 (ref eq)) (param $vofs1 (ref eq)) (param $vlen1 (ref eq))
(param $nat2 (ref eq)) (param $vofs2 (ref eq)) (param $vnbits (ref eq))
(result (ref eq))
;; ZZZ
(call $log_js (string.const "shift_right_nat"))
(call $log_str
(array.new_data $string $shift_right_nat (i32.const 0) (i32.const 15)))
(unreachable))

(data $div_digit_nat "div_digit_nat")

(func (export "div_digit_nat")
(param $natq (ref eq)) (param $ofsq (ref eq))
(param $natr (ref eq)) (param $ofsr (ref eq))
(param $nat1 (ref eq)) (param $ofs1 (ref eq)) (param $len (ref eq))
(param $nat2 (ref eq)) (param $ofs2 (ref eq)) (result (ref eq))
;; ZZZ
(call $log_js (string.const "div_digit_nat"))
(call $log_str
(array.new_data $string $div_digit_nat (i32.const 0) (i32.const 13)))
(unreachable))

(data $div_nat "div_nat")

(func (export "div_nat")
(param $nat1 (ref eq)) (param $vofs1 (ref eq)) (param $vlen1 (ref eq))
(param $nat2 (ref eq)) (param $vofs2 (ref eq)) (param $vlen2 (ref eq))
(result (ref eq))
;; ZZZ
(call $log_js (string.const "div_nat"))
(call $log_str
(array.new_data $string $div_nat (i32.const 0) (i32.const 7)))
(unreachable))

(data $add_nat "add_nat")

(func (export "add_nat")
(param $nat1 (ref eq)) (param $vofs1 (ref eq)) (param $vlen1 (ref eq))
(param $nat2 (ref eq)) (param $vofs2 (ref eq)) (param $vlen2 (ref eq))
(param $carry_in (ref eq))
(result (ref eq))
;; ZZZ
(call $log_js (string.const "add_nat"))
(call $log_str
(array.new_data $string $add_nat (i32.const 0) (i32.const 7)))
(unreachable))

(data $sub_nat "sub_nat")

(func (export "sub_nat")
(param $nat1 (ref eq)) (param $vofs1 (ref eq)) (param $vlen1 (ref eq))
(param $nat2 (ref eq)) (param $vofs2 (ref eq)) (param $vlen2 (ref eq))
(param $carry_in (ref eq))
(result (ref eq))
;; ZZZ
(call $log_js (string.const "sub_nat"))
(call $log_str
(array.new_data $string $sub_nat (i32.const 0) (i32.const 7)))
(unreachable))

(data $complement_nat "complement_nat")

(func (export "complement_nat")
(param $nat (ref eq)) (param $vofs (ref eq)) (param $vlen (ref eq))
(result (ref eq))
;; ZZZ
(call $log_js (string.const "complement_nat"))
(call $log_str
(array.new_data $string $complement_nat (i32.const 0) (i32.const 14)))
(unreachable))

(func (export "land_digit_nat")
Expand Down Expand Up @@ -487,19 +514,28 @@
(array.get $data (local.get $data2) (local.get $ofs2))))
(ref.i31 (i32.const 0)))

(data $hash_nat "hash_nat")

(func $hash_nat (param (ref eq)) (result i32)
;; ZZZ
(call $log_js (string.const "hash_nat"))
(call $log_str
(array.new_data $string $hash_nat (i32.const 0) (i32.const 8)))
(unreachable))

(data $serialize_nat "serialize_nat")

(func $serialize_nat
(param (ref eq)) (param (ref eq)) (result i32) (result i32)
;; ZZZ
(call $log_js (string.const "serialize_nat"))
(call $log_str
(array.new_data $string $serialize_nat (i32.const 0) (i32.const 13)))
(unreachable))

(data $deserialize_nat "deserialize_nat")

(func $deserialize_nat (param (ref eq)) (result (ref eq)) (result i32)
;; ZZZ
(call $log_js (string.const "deserialize_nat"))
(call $log_str
(array.new_data $string $serialize_nat (i32.const 0) (i32.const 15)))
(unreachable))
)
1 change: 0 additions & 1 deletion runtime/wasm/sys.wat
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
(module
(import "bindings" "log" (func $log_js (param anyref)))
(import "bindings" "ta_length"
(func $ta_length (param (ref extern)) (result i32)))
(import "bindings" "ta_get_i32"
Expand Down

0 comments on commit 66f151e

Please sign in to comment.