From 3f792a9a2bdd00f2c219bfdd391721215901f095 Mon Sep 17 00:00:00 2001 From: Wen Yuxiang Date: Fri, 22 Nov 2024 14:37:51 +0800 Subject: [PATCH] add @sys.exit --- sys/internal/ffi/ffi.mbti | 2 ++ sys/internal/ffi/sys_js.mbt | 5 +++++ sys/internal/ffi/sys_native.mbt | 2 ++ sys/internal/ffi/sys_wasm.mbt | 2 ++ sys/sys.mbt | 4 ++++ sys/sys.mbti | 2 ++ 6 files changed, 17 insertions(+) diff --git a/sys/internal/ffi/ffi.mbti b/sys/internal/ffi/ffi.mbti index 12b3107..f594b17 100644 --- a/sys/internal/ffi/ffi.mbti +++ b/sys/internal/ffi/ffi.mbti @@ -1,6 +1,8 @@ package moonbitlang/x/sys/internal/ffi // Values +fn exit(Int) -> Unit + fn get_cli_args() -> Array[String] fn get_env_var() -> Map[String, String] diff --git a/sys/internal/ffi/sys_js.mbt b/sys/internal/ffi/sys_js.mbt index e931ca1..04a9da7 100644 --- a/sys/internal/ffi/sys_js.mbt +++ b/sys/internal/ffi/sys_js.mbt @@ -40,3 +40,8 @@ extern "js" fn get_env_var_internal() -> Array[String] = #| } #| return result; #| } + +pub extern "js" fn exit(code : Int) -> Unit = + #| function(code) { + #| process.exit(code); + #| } diff --git a/sys/internal/ffi/sys_native.mbt b/sys/internal/ffi/sys_native.mbt index 7c46531..89cde9f 100644 --- a/sys/internal/ffi/sys_native.mbt +++ b/sys/internal/ffi/sys_native.mbt @@ -21,3 +21,5 @@ pub fn get_env_var() -> Map[String, String] { // not implement yet panic() } + +pub extern "native" fn exit(code : Int) -> Unit = "exit" diff --git a/sys/internal/ffi/sys_wasm.mbt b/sys/internal/ffi/sys_wasm.mbt index 2e34f36..9ad5de7 100644 --- a/sys/internal/ffi/sys_wasm.mbt +++ b/sys/internal/ffi/sys_wasm.mbt @@ -32,3 +32,5 @@ pub fn get_env_var() -> Map[String, String] { } fn get_env_var_ffi() -> XExternStringArray = "__moonbit_fs_unstable" "env_get_vars" + +pub fn exit(code : Int) = "__moonbit_sys_unstable" "exit" diff --git a/sys/sys.mbt b/sys/sys.mbt index c8d825c..53ba847 100644 --- a/sys/sys.mbt +++ b/sys/sys.mbt @@ -19,3 +19,7 @@ pub fn get_cli_args() -> Array[String] { pub fn get_env_var() -> Map[String, String] { @ffi.get_env_var() } + +pub fn exit(code : Int) -> Unit { + @ffi.exit(code) +} diff --git a/sys/sys.mbti b/sys/sys.mbti index 848b103..e1e053c 100644 --- a/sys/sys.mbti +++ b/sys/sys.mbti @@ -1,6 +1,8 @@ package moonbitlang/x/sys // Values +fn exit(Int) -> Unit + fn get_cli_args() -> Array[String] fn get_env_var() -> Map[String, String]