{-# LANGUAGE LambdaCase #-}

module PlutusCore.Executable.Types where

import PlutusCore qualified as PLC
import PlutusIR qualified as PIR
import UntypedPlutusCore qualified as UPLC

import Data.Text qualified as T

-- These types are for ASTs with Names.  This is the internal format for all
-- ASTs: conversions (eg between Names and de Bruijn indices) are carried out
-- when ASTs are read and written.

-- | PIR program type.
type PirProg =
    PIR.Program PLC.TyName PLC.Name PLC.DefaultUni PLC.DefaultFun

-- | PIR term type.
type PirTerm =
    PIR.Term PLC.TyName PLC.Name PLC.DefaultUni PLC.DefaultFun

-- | PLC program type.
type PlcProg =
    PLC.Program PLC.TyName PLC.Name PLC.DefaultUni PLC.DefaultFun

-- | PLC term type.
type PlcTerm =
    PLC.Term PLC.TyName PLC.Name PLC.DefaultUni PLC.DefaultFun

-- | UPLC program type.
type UplcProg =
    UPLC.Program PLC.Name PLC.DefaultUni PLC.DefaultFun

-- | UPLC term type.
type UplcTerm =
    UPLC.Term UPLC.Name PLC.DefaultUni PLC.DefaultFun


---------------- Types for commands and arguments ----------------

data AstNameType
    = Named
    | DeBruijn
    | NamedDeBruijn
    deriving stock Int -> AstNameType -> ShowS
[AstNameType] -> ShowS
AstNameType -> String
(Int -> AstNameType -> ShowS)
-> (AstNameType -> String)
-> ([AstNameType] -> ShowS)
-> Show AstNameType
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> AstNameType -> ShowS
showsPrec :: Int -> AstNameType -> ShowS
$cshow :: AstNameType -> String
show :: AstNameType -> String
$cshowList :: [AstNameType] -> ShowS
showList :: [AstNameType] -> ShowS
Show

data Input = FileInput FilePath | StdInput
instance Show Input where
    show :: Input -> String
show (FileInput String
path) = ShowS
forall a. Show a => a -> String
show String
path
    show Input
StdInput         = String
"<stdin>"

data Output = FileOutput FilePath | StdOutput | NoOutput
data TimingMode = NoTiming | Timing Integer deriving stock (TimingMode -> TimingMode -> Bool
(TimingMode -> TimingMode -> Bool)
-> (TimingMode -> TimingMode -> Bool) -> Eq TimingMode
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: TimingMode -> TimingMode -> Bool
== :: TimingMode -> TimingMode -> Bool
$c/= :: TimingMode -> TimingMode -> Bool
/= :: TimingMode -> TimingMode -> Bool
Eq) -- Report program execution time?
data CekModel = Default | Unit -- Which cost model should we use for CEK machine steps?
data PrintMode = Classic | Simple | Readable | ReadableSimple deriving stock (Int -> PrintMode -> ShowS
[PrintMode] -> ShowS
PrintMode -> String
(Int -> PrintMode -> ShowS)
-> (PrintMode -> String)
-> ([PrintMode] -> ShowS)
-> Show PrintMode
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PrintMode -> ShowS
showsPrec :: Int -> PrintMode -> ShowS
$cshow :: PrintMode -> String
show :: PrintMode -> String
$cshowList :: [PrintMode] -> ShowS
showList :: [PrintMode] -> ShowS
Show, ReadPrec [PrintMode]
ReadPrec PrintMode
Int -> ReadS PrintMode
ReadS [PrintMode]
(Int -> ReadS PrintMode)
-> ReadS [PrintMode]
-> ReadPrec PrintMode
-> ReadPrec [PrintMode]
-> Read PrintMode
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS PrintMode
readsPrec :: Int -> ReadS PrintMode
$creadList :: ReadS [PrintMode]
readList :: ReadS [PrintMode]
$creadPrec :: ReadPrec PrintMode
readPrec :: ReadPrec PrintMode
$creadListPrec :: ReadPrec [PrintMode]
readListPrec :: ReadPrec [PrintMode]
Read)
data NameFormat = IdNames | DeBruijnNames -- Format for textual output of names
data TraceMode = None | Logs | LogsWithTimestamps | LogsWithBudgets deriving stock (Int -> TraceMode -> ShowS
[TraceMode] -> ShowS
TraceMode -> String
(Int -> TraceMode -> ShowS)
-> (TraceMode -> String)
-> ([TraceMode] -> ShowS)
-> Show TraceMode
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> TraceMode -> ShowS
showsPrec :: Int -> TraceMode -> ShowS
$cshow :: TraceMode -> String
show :: TraceMode -> String
$cshowList :: [TraceMode] -> ShowS
showList :: [TraceMode] -> ShowS
Show, ReadPrec [TraceMode]
ReadPrec TraceMode
Int -> ReadS TraceMode
ReadS [TraceMode]
(Int -> ReadS TraceMode)
-> ReadS [TraceMode]
-> ReadPrec TraceMode
-> ReadPrec [TraceMode]
-> Read TraceMode
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS TraceMode
readsPrec :: Int -> ReadS TraceMode
$creadList :: ReadS [TraceMode]
readList :: ReadS [TraceMode]
$creadPrec :: ReadPrec TraceMode
readPrec :: ReadPrec TraceMode
$creadListPrec :: ReadPrec [TraceMode]
readListPrec :: ReadPrec [TraceMode]
Read)
type ExampleName = T.Text
data ExampleMode = ExampleSingle ExampleName | ExampleAvailable

type Files = [FilePath]

-- | Input/output format for programs
data Format
    = Textual
    | Flat AstNameType

instance Show Format where
    show :: Format -> String
show Format
Textual              = String
"textual"
    show (Flat AstNameType
Named)         = String
"flat-named"
    show (Flat AstNameType
DeBruijn)      = String
"flat-deBruijn"
    show (Flat AstNameType
NamedDeBruijn) = String
"flat-namedDeBruijn"

type Certifier = Maybe String

data ConvertOptions = ConvertOptions Input Format Output Format PrintMode
data OptimiseOptions = OptimiseOptions Input Format Output Format PrintMode Certifier
data PrintOptions = PrintOptions Input Output PrintMode
newtype ExampleOptions = ExampleOptions ExampleMode
data ApplyOptions = ApplyOptions Files Format Output Format PrintMode


-- | Specialised types for PIR, which doesn't support deBruijn names in ASTs
-- | A specialised format type for PIR. We don't support deBruijn or named deBruijn for PIR.

data PirFormat = TextualPir | FlatNamed
instance Show PirFormat
    where show :: PirFormat -> String
show = \case { PirFormat
TextualPir  -> String
"textual"; PirFormat
FlatNamed -> String
"flat-named" }

-- | Convert the PIR format type to the general format type.
pirFormatToFormat :: PirFormat -> Format
pirFormatToFormat :: PirFormat -> Format
pirFormatToFormat PirFormat
TextualPir = Format
Textual
pirFormatToFormat PirFormat
FlatNamed  = AstNameType -> Format
Flat AstNameType
Named

-- | Output types for some pir commands
data Language = PLC | UPLC