diff --git a/runtime/wasm/runtime.js b/runtime/wasm/runtime.js index 317d7b968f..f3d649ccd5 100644 --- a/runtime/wasm/runtime.js +++ b/runtime/wasm/runtime.js @@ -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, { diff --git a/runtime/wasm/sys.wat b/runtime/wasm/sys.wat index b397c89a82..de0f8ca50b 100644 --- a/runtime/wasm/sys.wat +++ b/runtime/wasm/sys.wat @@ -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))) @@ -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)))) diff --git a/runtime/wasm/unix.wat b/runtime/wasm/unix.wat index 797a3b3f3f..4740b129ee 100644 --- a/runtime/wasm/unix.wat +++ b/runtime/wasm/unix.wat @@ -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))) )