///|
#cfg(any(target="native", target="llvm"))
extern "c" fn cli_native_exit(code : Int) -> Unit = "exit"

///|
#cfg(any(target="native", target="llvm"))
fn cli_process_exit(code : Int) -> Unit {
  cli_native_exit(code)
}

///|
#cfg(target="wasm")
fn cli_wasm_exit(code : Int) -> Unit = "wasi_snapshot_preview1" "proc_exit"

///|
#cfg(target="wasm")
fn cli_process_exit(code : Int) -> Unit {
  cli_wasm_exit(code)
}

///|
#cfg(target="wasm-gc")
fn cli_wasm_gc_exit(code : Int) -> Unit = "__moonbit_sys_unstable" "exit"

///|
#cfg(target="wasm-gc")
fn cli_process_exit(code : Int) -> Unit {
  cli_wasm_gc_exit(code)
}

///|
#cfg(target="js")
extern "js" fn cli_js_exit(code : Int) -> Bool =
  #| function(code) {
  #|   if (typeof process !== "undefined" && typeof process.exit === "function") {
  #|     process.exit(code)
  #|     return true
  #|   }
  #|   return false
  #| }

///|
#cfg(target="js")
fn cli_process_exit(code : Int) -> Unit {
  if !cli_js_exit(code) {
    panic()
  }
}