Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
vouillon committed Jan 14, 2025
1 parent 52dcd72 commit 28a2bfa
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 17 deletions.
7 changes: 1 addition & 6 deletions runtime/wasm/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -397,12 +397,7 @@
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",
on_windows: () => globalThis?.process?.versions?.node === "win32",
getenv: (n) => (isNode ? process.env[n] : null),
system: (c) => {
var res = require("node:child_process").spawnSync(c, {
Expand Down
21 changes: 10 additions & 11 deletions runtime/wasm/sys.wat
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +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" "on_windows" (func $on_windows (result i32)))
(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,28 +136,27 @@

(func (export "caml_sys_const_ostype_unix")
(param (ref eq)) (result (ref eq))
;; ZZZ
(ref.i31 (i32.const 0)))
(ref.i31 (i32.eqz (call $on_windows))))

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

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

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

(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))
(call $get_os_type)
(if (result (ref eq)) (call $on_windows)
(then
(array.new_data $string $Win32 (i32.const 0) (i32.const 5)))
(else
(array.new_data $string $Unix (i32.const 0) (i32.const 4))))
(ref.i31 (i32.const 32))
(ref.i31 (i32.const 0))))

Expand Down

0 comments on commit 28a2bfa

Please sign in to comment.