Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
hhugo committed Jan 14, 2025
1 parent 82c1939 commit a9c4b0e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
6 changes: 6 additions & 0 deletions runtime/wasm/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,12 @@
channel_list,
exit: (n) => isNode && process.exit(n),
argv: () => (isNode ? process.argv.slice(1) : ["a.out"]),
ostype: () =>
globalThis.process &&
globalThis.process.platform &&
globalThis.process.platform === "win32"
? "Win32"
: "Unix",
getenv: (n) => (isNode ? process.env[n] : null),
system: (c) => {
var res = require("node:child_process").spawnSync(c, {
Expand Down
10 changes: 6 additions & 4 deletions runtime/wasm/sys.wat
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
(func $caml_raise_sys_error (param (ref eq))))
(import "fail" "caml_raise_not_found" (func $caml_raise_not_found))
(import "bindings" "argv" (func $argv (result (ref extern))))
(import "bindings" "ostype" (func $ostype (result anyref)))
(import "bindings" "system" (func $system (param anyref) (result (ref eq))))
(import "bindings" "getenv" (func $getenv (param anyref) (result anyref)))
(import "bindings" "time" (func $time (result f64)))
Expand Down Expand Up @@ -136,26 +137,27 @@
(func (export "caml_sys_const_ostype_unix")
(param (ref eq)) (result (ref eq))
;; ZZZ
(ref.i31 (i32.const 1)))
(ref.i31 (i32.const 0)))

(func (export "caml_sys_const_ostype_win32")
(param (ref eq)) (result (ref eq))
;; ZZZ
(ref.i31 (i32.const 0)))
(ref.i31 (i32.const 1)))

(func (export "caml_sys_const_ostype_cygwin")
(param (ref eq)) (result (ref eq))
;; ZZZ
(ref.i31 (i32.const 0)))

(data $Unix "Unix")
(func $get_os_type (result (ref eq))
(return_call $caml_string_of_jsstring (call $wrap (call $ostype))))

(func (export "caml_sys_get_config")
(param (ref eq)) (result (ref eq))
;; ZZZ
;; (call $log_js (string.const "caml_sys_get_config"))
(array.new_fixed $block 4 (ref.i31 (i32.const 0))
(array.new_data $string $Unix (i32.const 0) (i32.const 4))
(call $get_os_type)
(ref.i31 (i32.const 32))
(ref.i31 (i32.const 0))))

Expand Down
7 changes: 7 additions & 0 deletions runtime/wasm/unix.wat
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,11 @@
(func $unix_inet_addr_of_string (export "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")
(param (ref eq)) (result (ref eq))
(local.get 0))
(func $unix_cleanup (export "caml_unix_cleanup")
(param (ref eq)) (result (ref eq))
(ref.i31 (i32.const 0)))
)

0 comments on commit a9c4b0e

Please sign in to comment.