/* * Copyright 2024 Magnus Madsen * * Use of this source code is governed by the Apache 2.0 license * that can be found in the LICENSE.md file. */////// Effect for exiting the JVM, and its functions.///pubmod Sys.Exit {use Sys.Exitimport java.lang.System////// Effect for exiting the JVM.///pubeffExit {////// Immediately exits the JVM with the specified `exitCode`.///defexit(exitCode: Int32): Void }////// Handles the `Exit` effect of the given function `f`.////// In other words, re-interprets the `Exit` effect using the `IO` effect.////// Note: The returned function can still return normally if `exit` is never called by `f`.///pubdefhandle(f: a -> b \ ef): a -> b \ (ef - Exit) + IO = x ->run {f(x) } withhandlerExit {defexit(ec, _k) = unchecked_cast(System.exit(ec) asb) }////// Runs the `Exit` effect of the given function `f`.////// In other words, re-interprets the `Exit` effect using the `IO` effect.////// Note: This function can still return normally if `exit` is never called by `f`.///@DefaultHandlerpubdefrunWithIO(f: Unit -> a \ ef): a \ (ef - Exit) + IO = handle(f)()}