Skip to content

Commit

Permalink
Runtime: implement Sys.is_directory
Browse files Browse the repository at this point in the history
  • Loading branch information
vouillon committed Dec 4, 2024
1 parent 1e2c57d commit 913dc6e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
19 changes: 13 additions & 6 deletions runtime/wasm/fs.wat
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
(func $readdir (param anyref) (result (ref extern))))
(import "bindings" "file_exists"
(func $file_exists (param anyref) (result (ref eq))))
(import "bindings" "is_directory"
(func $is_directory (param anyref) (result (ref eq))))
(import "bindings" "rename" (func $rename (param anyref) (param anyref)))
(import "jslib" "wrap" (func $wrap (param anyref) (result (ref eq))))
(import "jslib" "unwrap" (func $unwrap (param (ref eq)) (result anyref)))
Expand Down Expand Up @@ -141,10 +143,15 @@

(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)))
(func (export "caml_sys_is_directory")
(param $name (ref eq)) (result (ref eq))
(try
(do
(return
(call $is_directory
(call $unwrap
(call $caml_jsstring_of_string (local.get $name))))))
(catch $javascript_exception
(call $caml_handle_sys_error (pop externref))
(return (ref.i31 (i32.const 0))))))
)
1 change: 1 addition & 0 deletions runtime/wasm/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,7 @@
unlink: (p) => fs.unlinkSync(p),
readdir: (p) => fs.readdirSync(p),
file_exists: (p) => +fs.existsSync(p),
is_directory: (p) => +fs.lstatSync(p).isDirectory(),
rename: (o, n) => fs.renameSync(o, n),
throw: (e) => {
throw e;
Expand Down

0 comments on commit 913dc6e

Please sign in to comment.