{-# LANGUAGE PatternSynonyms #-}

module Unison.Runtime
  ( Runtime,
    pattern Runtime,
    terminate,
    evaluate,
    compileTo,
    mainType,
    ioTestTypes,
    Error (..),
  )
where

import Data.Text (Text)
import Unison.Codebase.Runtime qualified as Rt
import Unison.PrettyPrintEnv (PrettyPrintEnv)
import Unison.Reference (Reference)
import Unison.Runtime.Decompile (DecompError, DecompResult)
import Unison.Runtime.Exception (RuntimeExn)
import Unison.Runtime.InternalError (CompileExn)
import Unison.Runtime.Stack (RuntimePanic, Val)
import Unison.Symbol (Symbol)

data Error
  = -- | __TODO__: This constructor should go away, but there are still a few places that have unstructured errors.
    UnstructuredError Text
  | CompileExn CompileExn
  | RuntimeExn (Maybe (PrettyPrintEnv, Reference -> Reference, Val -> DecompResult Symbol)) RuntimeExn
  | RuntimePanic PrettyPrintEnv (Val -> DecompResult Symbol) RuntimePanic

type Runtime = Rt.Runtime Error DecompError

pattern $mRuntime :: forall {r} {e} {e'} {v}.
Runtime e e' v
-> (IO ()
    -> (CodeLookup v IO ()
        -> PrettyPrintEnv
        -> ProfileSpec
        -> Term v
        -> IO (Either e (Response e', Term v)))
    -> (CompileOpts
        -> CodeLookup v IO ()
        -> PrettyPrintEnv
        -> Reference
        -> FilePath
        -> IO (Maybe e))
    -> Type v Ann
    -> NESet (Type v Ann)
    -> r)
-> ((# #) -> r)
-> r
$bRuntime :: forall {e} {e'} {v}.
IO ()
-> (CodeLookup v IO ()
    -> PrettyPrintEnv
    -> ProfileSpec
    -> Term v
    -> IO (Either e (Response e', Term v)))
-> (CompileOpts
    -> CodeLookup v IO ()
    -> PrettyPrintEnv
    -> Reference
    -> FilePath
    -> IO (Maybe e))
-> Type v Ann
-> NESet (Type v Ann)
-> Runtime e e' v
Runtime {forall {e} {e'} {v}. Runtime e e' v -> IO ()
terminate, forall {e} {e'} {v}.
Runtime e e' v
-> CodeLookup v IO ()
-> PrettyPrintEnv
-> ProfileSpec
-> Term v
-> IO (Either e (Response e', Term v))
evaluate, forall {e} {e'} {v}.
Runtime e e' v
-> CompileOpts
-> CodeLookup v IO ()
-> PrettyPrintEnv
-> Reference
-> FilePath
-> IO (Maybe e)
compileTo, forall {e} {e'} {v}. Runtime e e' v -> Type v Ann
mainType, forall {e} {e'} {v}. Runtime e e' v -> NESet (Type v Ann)
ioTestTypes} =
  Rt.Runtime {terminate, evaluate, compileTo, mainType, ioTestTypes}