From 182f984b3006374ccf621a2ae5df25805d8ef310 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=96=87=E5=AE=87=E7=A5=A5?= Date: Mon, 25 Nov 2024 09:59:31 +0800 Subject: [PATCH] add @sys.exit (#74) --- 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]