-- SPDX-License-Identifier: GPL-2.0-or-later -- Copyright (C) 2026 unkernel contributors module Unkernel ( Options, Kernel, Termination(..), ExecResult , options, withMemory, withDistro, boot, exec, stop, withKernel ) where import Prelude import Control.Promise (Promise, toAffE) import Effect (Effect) import Effect.Aff (Aff, bracket) foreign import data Options :: Type foreign import data Kernel :: Type data Termination = Exited Int | Signaled Int type ExecResult = { stdout :: String, stderr :: String, termination :: Termination } foreign import options :: Options foreign import withMemory :: Int -> Options -> Options foreign import withDistro :: String -> Options -> Options foreign import bootImpl :: Options -> Effect (Promise Kernel) foreign import stopImpl :: Kernel -> Effect (Promise Unit) foreign import execImpl :: (Int -> Termination) -> (Int -> Termination) -> String -> Array String -> Kernel -> Effect (Promise ExecResult) boot :: Options -> Aff Kernel boot opts = bootImpl opts # toAffE stop :: Kernel -> Aff Unit stop vm = stopImpl vm # toAffE exec :: String -> Array String -> Kernel -> Aff ExecResult exec file args vm = execImpl Exited Signaled file args vm # toAffE withKernel :: forall a. (Kernel -> Aff a) -> Options -> Aff a withKernel run opts = bracket (boot opts) stop run