Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
vouillon committed Dec 4, 2024
1 parent 1e2c57d commit f86895e
Show file tree
Hide file tree
Showing 6 changed files with 3 additions and 227 deletions.
23 changes: 0 additions & 23 deletions runtime/wasm/dynlink.wat
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,4 @@
;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

(module
(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_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_str
(array.new_data $string $caml_dynlink_lookup_symbol
(i32.const 0) (i32.const 26)))
(ref.i31 (i32.const 0)))
)
6 changes: 2 additions & 4 deletions runtime/wasm/fs.wat
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,6 @@

(func (export "caml_read_file_content")
(param (ref eq)) (result (ref eq))
;; ZZZ
(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 All @@ -141,10 +137,12 @@

(data $caml_sys_is_directory "caml_sys_is_directory")

(;
(func (export "caml_sys_is_directory") (param (ref eq)) (result (ref eq))
;; ZZZ
(call $log_str
(array.new_data $string $caml_sys_is_directory
(i32.const 0) (i32.const 21)))
(ref.i31 (i32.const 0)))
;)
)
9 changes: 0 additions & 9 deletions runtime/wasm/int64.wat
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

(module
(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 @@ -212,14 +211,6 @@

(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_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))
(local $s (ref $string))
(local $negative i32) (local $i i32) (local $n i64)
Expand Down
11 changes: 0 additions & 11 deletions runtime/wasm/io.wat
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

(module
(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 @@ -828,16 +827,6 @@
(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_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))
;; ZZZ check for overflow
(ref.i31
Expand Down
179 changes: 0 additions & 179 deletions runtime/wasm/nat.wat
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

(module
(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 @@ -383,182 +382,4 @@
(local.set $ofs1 (i32.add (local.get $ofs1) (i32.const 1)))
(if (local.get $len1) (then (br $loop))))
(ref.i31 (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)) (param $vlen3 (ref eq))
(result (ref eq))
;; ZZZ
(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_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_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_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_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_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_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_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_str
(array.new_data $string $complement_nat (i32.const 0) (i32.const 14)))
(unreachable))

(func (export "land_digit_nat")
(param $nat1 (ref eq)) (param $vofs1 (ref eq))
(param $nat2 (ref eq)) (param $vofs2 (ref eq))
(result (ref eq))
(local $ofs1 i32) (local $data1 (ref $data))
(local $ofs2 i32) (local $data2 (ref $data))
(local.set $data1
(struct.get $nat $data (ref.cast (ref $nat) (local.get $nat1))))
(local.set $ofs1 (i31.get_s (ref.cast (ref i31) (local.get $vofs1))))
(local.set $data2
(struct.get $nat $data (ref.cast (ref $nat) (local.get $nat2))))
(local.set $ofs2 (i31.get_s (ref.cast (ref i31) (local.get $vofs2))))
(array.set $data (local.get $data1) (local.get $ofs1)
(i32.and (array.get $data (local.get $data1) (local.get $ofs1))
(array.get $data (local.get $data2) (local.get $ofs2))))
(ref.i31 (i32.const 0)))

(func (export "lxor_digit_nat")
(param $nat1 (ref eq)) (param $vofs1 (ref eq))
(param $nat2 (ref eq)) (param $vofs2 (ref eq))
(result (ref eq))
(local $ofs1 i32) (local $data1 (ref $data))
(local $ofs2 i32) (local $data2 (ref $data))
(local.set $data1
(struct.get $nat $data (ref.cast (ref $nat) (local.get $nat1))))
(local.set $ofs1 (i31.get_s (ref.cast (ref i31) (local.get $vofs1))))
(local.set $data2
(struct.get $nat $data (ref.cast (ref $nat) (local.get $nat2))))
(local.set $ofs2 (i31.get_s (ref.cast (ref i31) (local.get $vofs2))))
(array.set $data (local.get $data1) (local.get $ofs1)
(i32.xor (array.get $data (local.get $data1) (local.get $ofs1))
(array.get $data (local.get $data2) (local.get $ofs2))))
(ref.i31 (i32.const 0)))

(func (export "lor_digit_nat")
(param $nat1 (ref eq)) (param $vofs1 (ref eq))
(param $nat2 (ref eq)) (param $vofs2 (ref eq))
(result (ref eq))
(local $ofs1 i32) (local $data1 (ref $data))
(local $ofs2 i32) (local $data2 (ref $data))
(local.set $data1
(struct.get $nat $data (ref.cast (ref $nat) (local.get $nat1))))
(local.set $ofs1 (i31.get_s (ref.cast (ref i31) (local.get $vofs1))))
(local.set $data2
(struct.get $nat $data (ref.cast (ref $nat) (local.get $nat2))))
(local.set $ofs2 (i31.get_s (ref.cast (ref i31) (local.get $vofs2))))
(array.set $data (local.get $data1) (local.get $ofs1)
(i32.or (array.get $data (local.get $data1) (local.get $ofs1))
(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_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_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_str
(array.new_data $string $serialize_nat (i32.const 0) (i32.const 15)))
(unreachable))
)
2 changes: 1 addition & 1 deletion runtime/wasm/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@
},
map_set: (m, x, v) => m.set(x, v),
map_delete: (m, x) => m.delete(x),
log: (x) => console.log("ZZZZZ", x),
log: (x) => console.log(x),
};
const string_ops = {
test: (v) => +(typeof v === "string"),
Expand Down

0 comments on commit f86895e

Please sign in to comment.