Skip to content

Commit

Permalink
Wasm runtime: clean-up
Browse files Browse the repository at this point in the history
  • Loading branch information
vouillon committed Feb 4, 2025
1 parent 603e9b0 commit 01bf135
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 22 deletions.
17 changes: 9 additions & 8 deletions runtime/wasm/fs.wat
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
(import "bindings" "mkdir" (func $mkdir (param anyref) (param i32)))
(import "bindings" "rmdir" (func $rmdir (param anyref)))
(import "bindings" "unlink" (func $unlink (param anyref)))
(import "bindings" "readdir"
(func $readdir (param anyref) (result (ref extern))))
(import "bindings" "read_dir"
(func $read_dir (param anyref) (result (ref extern))))
(import "bindings" "file_exists"
(func $file_exists (param anyref) (result (ref eq))))
(import "bindings" "is_directory"
Expand All @@ -48,7 +48,12 @@

(func (export "caml_sys_getcwd")
(param (ref eq)) (result (ref eq))
(return_call $caml_string_of_jsstring (call $wrap (call $getcwd))))
(try (result (ref eq))
(do
(call $caml_string_of_jsstring (call $wrap (call $getcwd))))
(catch $javascript_exception
(call $caml_handle_sys_error (pop externref))
(ref.i31 (i32.const 0)))))

(func (export "caml_sys_chdir")
(param $name (ref eq)) (result (ref eq))
Expand Down Expand Up @@ -77,7 +82,7 @@
(do
(return
(call $caml_js_to_string_array
(call $readdir
(call $read_dir
(call $unwrap
(call $caml_jsstring_of_string (local.get $name)))))))
(catch $javascript_exception
Expand Down Expand Up @@ -138,8 +143,6 @@
(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))
(call $caml_raise_no_such_file (local.get 0))
Expand All @@ -148,8 +151,6 @@
(func (export "caml_fs_init") (result (ref eq))
(ref.i31 (i32.const 0)))

(data $caml_sys_is_directory "caml_sys_is_directory")

(func (export "caml_sys_is_directory")
(param $name (ref eq)) (result (ref eq))
(try
Expand Down
2 changes: 1 addition & 1 deletion runtime/wasm/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@
mkdir: (p, m) => fs.mkdirSync(p, m),
rmdir: (p) => fs.rmdirSync(p),
unlink: (p) => fs.unlinkSync(p),
readdir: (p) => fs.readdirSync(p),
read_dir: (p) => fs.readdirSync(p),
stat: (p, l) => alloc_stat(fs.statSync(p), l),
lstat: (p, l) => alloc_stat(fs.lstatSync(p), l),
fstat: (fd, l) => alloc_stat(fs.fstatSync(fd), l),
Expand Down
26 changes: 13 additions & 13 deletions runtime/wasm/unix.wat
Original file line number Diff line number Diff line change
Expand Up @@ -219,23 +219,22 @@
(ref.i31 (local.get $yday))
(ref.i31 (local.get $isdst))))

(export "caml_unix_gmtime" (func $unix_gmtime))
(func $unix_gmtime (export "unix_gmtime") (param (ref eq)) (result (ref eq))
(func $unix_gmtime (export "unix_gmtime") (export "caml_unix_gmtime")
(param (ref eq)) (result (ref eq))
(call $gmtime
(struct.get $float 0 (ref.cast (ref $float) (local.get 0)))))

(export "caml_unix_localtime" (func $unix_localtime))
(func $unix_localtime (export "unix_localtime")
(func $unix_localtime (export "unix_localtime") (export "caml_unix_localtime")
(param (ref eq)) (result (ref eq))
(call $localtime
(struct.get $float 0 (ref.cast (ref $float) (local.get 0)))))

(export "caml_unix_time" (func $unix_time))
(func $unix_time (export "unix_time") (param (ref eq)) (result (ref eq))
(func $unix_time (export "unix_time") (export "caml_unix_time")
(param (ref eq)) (result (ref eq))
(struct.new $float (f64.floor (call $gettimeofday))))

(export "caml_unix_mktime" (func $unix_mktime))
(func $unix_mktime (export "unix_mktime") (param (ref eq)) (result (ref eq))
(func $unix_mktime (export "unix_mktime") (export "caml_unix_mktime")
(param (ref eq)) (result (ref eq))
(local $tm (ref $block)) (local $t f64)
(local.set $tm (ref.cast (ref $block) (local.get 0)))
(local.set $t
Expand Down Expand Up @@ -789,15 +788,16 @@
(export "unix_isatty" (func $isatty))
(export "caml_unix_isatty" (func $isatty))

(export "caml_unix_inet_addr_of_string" (func $unix_inet_addr_of_string))
(func $unix_inet_addr_of_string (export "unix_inet_addr_of_string")
(func (export "unix_inet_addr_of_string")
(export "caml_unix_inet_addr_of_string")
(param (ref eq)) (result (ref eq))
(ref.i31 (i32.const 0)))
(export "caml_unix_filedescr_of_fd" (func $unix_filedescr_of_fd))
(func $unix_filedescr_of_fd (export "unix_filedescr_of_fd")

(func (export "win_handle_fd") (export "caml_unix_filedescr_of_fd")
(param (ref eq)) (result (ref eq))
(local.get 0))
(func $unix_cleanup (export "caml_unix_cleanup")

(func (export "win_cleanup") (export "caml_unix_cleanup")
(param (ref eq)) (result (ref eq))
(ref.i31 (i32.const 0)))
)

0 comments on commit 01bf135

Please sign in to comment.