Skip to content

Commit

Permalink
add @sys.exit (#74)
Browse files Browse the repository at this point in the history
  • Loading branch information
hackwaly authored Nov 25, 2024
1 parent 56986f4 commit 182f984
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions sys/internal/ffi/ffi.mbti
Original file line number Diff line number Diff line change
@@ -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]
Expand Down
5 changes: 5 additions & 0 deletions sys/internal/ffi/sys_js.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -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);
#| }
2 changes: 2 additions & 0 deletions sys/internal/ffi/sys_native.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
2 changes: 2 additions & 0 deletions sys/internal/ffi/sys_wasm.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
4 changes: 4 additions & 0 deletions sys/sys.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
2 changes: 2 additions & 0 deletions sys/sys.mbti
Original file line number Diff line number Diff line change
@@ -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]
Expand Down

0 comments on commit 182f984

Please sign in to comment.