module Indigo.Compilation
( compileIndigo
, IndigoWithParams
, IndigoContract
, compileIndigoContract
, Ops
, HasSideEffects
, operationsVar
, HasStorage
, storageVar
) where
import qualified Data.Map as M
import Data.Reflection (give)
import qualified Data.Set as S
import Data.Singletons (SingI(..))
import Data.Typeable ((:~:)(..), eqT)
import Data.Vinyl.Core (RMap(..))
import qualified Indigo.Backend as B
import Indigo.Compilation.Lambda
import Indigo.Compilation.Params
import Indigo.Frontend.Program (IndigoM(..), Program(..))
import Indigo.Frontend.Statement
import Indigo.Internal hiding (SetField, return, (>>), (>>=))
import qualified Indigo.Internal as I
import Indigo.Lorentz
import Indigo.Prelude
import qualified Lorentz.Instr as L
import qualified Lorentz.Macro as L
import Util.Peano
compileIndigoM
:: forall inp a .
(forall x anyInp . StatementF IndigoM x -> SomeIndigoState anyInp x)
-> IndigoM a
-> SomeIndigoState inp a
compileIndigoM :: (forall x (anyInp :: [*]).
StatementF IndigoM x -> SomeIndigoState anyInp x)
-> IndigoM a -> SomeIndigoState inp a
compileIndigoM _ (IndigoM (Done a :: a
a)) = a -> SomeIndigoState inp a
forall a (inp :: [*]). a -> SomeIndigoState inp a
returnSIS a
a
compileIndigoM interp :: forall x (anyInp :: [*]).
StatementF IndigoM x -> SomeIndigoState anyInp x
interp (IndigoM (Instr i :: StatementF IndigoM a
i)) = StatementF IndigoM a -> SomeIndigoState inp a
forall x (anyInp :: [*]).
StatementF IndigoM x -> SomeIndigoState anyInp x
interp StatementF IndigoM a
i
compileIndigoM interp :: forall x (anyInp :: [*]).
StatementF IndigoM x -> SomeIndigoState anyInp x
interp (IndigoM (Bind instr :: Program (StatementF IndigoM) a
instr cont :: a -> Program (StatementF IndigoM) a
cont)) =
(forall x (anyInp :: [*]).
StatementF IndigoM x -> SomeIndigoState anyInp x)
-> IndigoM a -> SomeIndigoState inp a
forall (inp :: [*]) a.
(forall x (anyInp :: [*]).
StatementF IndigoM x -> SomeIndigoState anyInp x)
-> IndigoM a -> SomeIndigoState inp a
compileIndigoM forall x (anyInp :: [*]).
StatementF IndigoM x -> SomeIndigoState anyInp x
interp (Program (StatementF IndigoM) a -> IndigoM a
forall a. Program (StatementF IndigoM) a -> IndigoM a
IndigoM Program (StatementF IndigoM) a
instr) SomeIndigoState inp a
-> (forall (someOut :: [*]). a -> SomeIndigoState someOut a)
-> SomeIndigoState inp a
forall (inp :: [*]) a b.
SomeIndigoState inp a
-> (forall (someOut :: [*]). a -> SomeIndigoState someOut b)
-> SomeIndigoState inp b
`bindSIS` ((forall x (anyInp :: [*]).
StatementF IndigoM x -> SomeIndigoState anyInp x)
-> IndigoM a -> SomeIndigoState someOut a
forall (inp :: [*]) a.
(forall x (anyInp :: [*]).
StatementF IndigoM x -> SomeIndigoState anyInp x)
-> IndigoM a -> SomeIndigoState inp a
compileIndigoM forall x (anyInp :: [*]).
StatementF IndigoM x -> SomeIndigoState anyInp x
interp (IndigoM a -> SomeIndigoState someOut a)
-> (a -> IndigoM a) -> a -> SomeIndigoState someOut a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Program (StatementF IndigoM) a -> IndigoM a
forall a. Program (StatementF IndigoM) a -> IndigoM a
IndigoM (Program (StatementF IndigoM) a -> IndigoM a)
-> (a -> Program (StatementF IndigoM) a) -> a -> IndigoM a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Program (StatementF IndigoM) a
cont)
simpleCompileIndigoM :: forall inp a . IndigoM a -> SomeIndigoState inp a
simpleCompileIndigoM :: IndigoM a -> SomeIndigoState inp a
simpleCompileIndigoM indigoM :: IndigoM a
indigoM =
let lambdas :: [Lambda1Def]
lambdas = Set Lambda1Def -> [Lambda1Def]
forall a. Set a -> [a]
S.toList (IndigoM a -> Set Lambda1Def
forall a. IndigoM a -> Set Lambda1Def
collectLambdas IndigoM a
indigoM) in
[Lambda1Def]
-> (forall (someInp :: [*]).
Lambda1Def -> SomeIndigoState someInp CompiledLambda)
-> SomeIndigoState inp [CompiledLambda]
forall r v (someInp1 :: [*]).
[r]
-> (forall (someInp :: [*]). r -> SomeIndigoState someInp v)
-> SomeIndigoState someInp1 [v]
forMSIS [Lambda1Def]
lambdas forall (someInp :: [*]).
Lambda1Def -> SomeIndigoState someInp CompiledLambda
defineLambda
SomeIndigoState inp [CompiledLambda]
-> (forall (someOut :: [*]).
[CompiledLambda] -> SomeIndigoState someOut a)
-> SomeIndigoState inp a
forall (inp :: [*]) a b.
SomeIndigoState inp a
-> (forall (someOut :: [*]). a -> SomeIndigoState someOut b)
-> SomeIndigoState inp b
`bindSIS`
(\defined :: [CompiledLambda]
defined ->
let definedLambdas :: Map String CompiledLambda
definedLambdas = [(String, CompiledLambda)] -> Map String CompiledLambda
forall k a. Ord k => [(k, a)] -> Map k a
M.fromList ([(String, CompiledLambda)] -> Map String CompiledLambda)
-> [(String, CompiledLambda)] -> Map String CompiledLambda
forall a b. (a -> b) -> a -> b
$ (CompiledLambda -> (String, CompiledLambda))
-> [CompiledLambda] -> [(String, CompiledLambda)]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
map (\l :: CompiledLambda
l -> (CompiledLambda -> String
_clName CompiledLambda
l, CompiledLambda
l)) [CompiledLambda]
defined
in Map String CompiledLambda -> IndigoM a -> SomeIndigoState someOut a
forall a (inp :: [*]).
Map String CompiledLambda -> IndigoM a -> SomeIndigoState inp a
compileBody Map String CompiledLambda
definedLambdas IndigoM a
indigoM
)
where
compileBody :: Map String CompiledLambda -> IndigoM a -> SomeIndigoState inp a
compileBody definedLambdas :: Map String CompiledLambda
definedLambdas = (forall x (anyInp :: [*]).
StatementF IndigoM x -> SomeIndigoState anyInp x)
-> IndigoM a -> SomeIndigoState inp a
forall (inp :: [*]) a.
(forall x (anyInp :: [*]).
StatementF IndigoM x -> SomeIndigoState anyInp x)
-> IndigoM a -> SomeIndigoState inp a
compileIndigoM (Map String CompiledLambda
-> Reader (Map String CompiledLambda) (SomeIndigoState anyInp x)
-> SomeIndigoState anyInp x
forall r a. r -> Reader r a -> a
usingReader Map String CompiledLambda
definedLambdas (Reader (Map String CompiledLambda) (SomeIndigoState anyInp x)
-> SomeIndigoState anyInp x)
-> (StatementF IndigoM x
-> Reader (Map String CompiledLambda) (SomeIndigoState anyInp x))
-> StatementF IndigoM x
-> SomeIndigoState anyInp x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. StatementF IndigoM x
-> Reader (Map String CompiledLambda) (SomeIndigoState anyInp x)
forall x (anyInp :: [*]).
StatementF IndigoM x
-> Reader (Map String CompiledLambda) (SomeIndigoState anyInp x)
compileSt)
compileSt :: StatementF IndigoM x -> Reader (Map String CompiledLambda) (SomeIndigoState anyInp x)
compileSt :: StatementF IndigoM x
-> Reader (Map String CompiledLambda) (SomeIndigoState anyInp x)
compileSt (LiftIndigoState cd :: forall (inp :: [*]). SomeIndigoState inp x
cd) = SomeIndigoState anyInp x
-> Reader (Map String CompiledLambda) (SomeIndigoState anyInp x)
forall (f :: * -> *) a. Applicative f => a -> f a
pure SomeIndigoState anyInp x
forall (inp :: [*]). SomeIndigoState inp x
cd
compileSt (NewVar ex :: Expr x
ex) = SomeIndigoState anyInp (Var x)
-> Reader (Map String CompiledLambda) (SomeIndigoState anyInp x)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (SomeIndigoState anyInp (Var x)
-> Reader (Map String CompiledLambda) (SomeIndigoState anyInp x))
-> SomeIndigoState anyInp (Var x)
-> Reader (Map String CompiledLambda) (SomeIndigoState anyInp x)
forall a b. (a -> b) -> a -> b
$ IndigoState anyInp (x & anyInp) (Var x)
-> SomeIndigoState anyInp (Var x)
forall (inp :: [*]) (out :: [*]) a.
IndigoState inp out a -> SomeIndigoState inp a
toSIS (Expr x -> IndigoState anyInp (x & anyInp) (Var x)
forall x (inp :: [*]).
KnownValue x =>
Expr x -> IndigoState inp (x & inp) (Var x)
B.newVar Expr x
ex)
compileSt (SetVar v :: Var x
v ex :: Expr x
ex) = SomeIndigoState anyInp ()
-> Reader (Map String CompiledLambda) (SomeIndigoState anyInp x)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (SomeIndigoState anyInp ()
-> Reader (Map String CompiledLambda) (SomeIndigoState anyInp x))
-> SomeIndigoState anyInp ()
-> Reader (Map String CompiledLambda) (SomeIndigoState anyInp x)
forall a b. (a -> b) -> a -> b
$ IndigoState anyInp anyInp () -> SomeIndigoState anyInp ()
forall (inp :: [*]) (out :: [*]) a.
IndigoState inp out a -> SomeIndigoState inp a
toSIS (Var x -> Expr x -> IndigoState anyInp anyInp ()
forall a (inp :: [*]). Var a -> Expr a -> IndigoState inp inp ()
B.setVar Var x
v Expr x
ex)
compileSt (SetField v :: Var dt
v fName :: Label fname
fName ex :: Expr ftype
ex) = SomeIndigoState anyInp ()
-> Reader (Map String CompiledLambda) (SomeIndigoState anyInp x)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (SomeIndigoState anyInp ()
-> Reader (Map String CompiledLambda) (SomeIndigoState anyInp x))
-> SomeIndigoState anyInp ()
-> Reader (Map String CompiledLambda) (SomeIndigoState anyInp x)
forall a b. (a -> b) -> a -> b
$ IndigoState anyInp anyInp () -> SomeIndigoState anyInp ()
forall (inp :: [*]) (out :: [*]) a.
IndigoState inp out a -> SomeIndigoState inp a
toSIS (Var dt -> Label fname -> Expr ftype -> IndigoState anyInp anyInp ()
forall dt (fname :: Symbol) ftype (inp :: [*]).
(IsObject dt, IsObject ftype, HasField dt fname ftype) =>
Var dt -> Label fname -> Expr ftype -> IndigoState inp inp ()
B.setField Var dt
v Label fname
fName Expr ftype
ex)
compileSt (VarModification act :: '[y, x] :-> '[x]
act var :: Var x
var ex :: Expr y
ex) = SomeIndigoState anyInp ()
-> Reader (Map String CompiledLambda) (SomeIndigoState anyInp x)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (SomeIndigoState anyInp ()
-> Reader (Map String CompiledLambda) (SomeIndigoState anyInp x))
-> SomeIndigoState anyInp ()
-> Reader (Map String CompiledLambda) (SomeIndigoState anyInp x)
forall a b. (a -> b) -> a -> b
$ IndigoState anyInp anyInp () -> SomeIndigoState anyInp ()
forall (inp :: [*]) (out :: [*]) a.
IndigoState inp out a -> SomeIndigoState inp a
toSIS (('[y, x] :-> '[x])
-> Var x -> Expr y -> IndigoState anyInp anyInp ()
forall x y (inp :: [*]).
(IsObject x, KnownValue y) =>
('[y, x] :-> '[x]) -> Var x -> Expr y -> IndigoState inp inp ()
B.updateVar '[y, x] :-> '[x]
act Var x
var Expr y
ex)
compileSt (LambdaPure1Call lName :: String
lName (Var arg -> IndigoM res
body :: (Var arg -> IndigoM res)) argm :: Expr arg
argm) =
(forall (inpt :: [*]). LambdaExecutor '[] arg res inpt)
-> String
-> (Var arg -> IndigoM res)
-> Expr arg
-> Reader
(Map String CompiledLambda) (SomeIndigoState anyInp (RetVars res))
forall (extra :: [*]) res arg (someOut :: [*]).
(Typeable extra, KnownValue arg, Typeable res, ScopeCodeGen res) =>
(forall (inpt :: [*]). LambdaExecutor extra arg res inpt)
-> String
-> (Var arg -> IndigoM res)
-> Expr arg
-> Reader
(Map String CompiledLambda) (SomeIndigoState someOut (RetVars res))
execGenericLambda @'[] @res (forall arg (inp :: [*]).
ExecuteLambdaPure1C arg res =>
LambdaExecutor '[] arg res inp
forall res arg (inp :: [*]).
ExecuteLambdaPure1C arg res =>
LambdaExecutor '[] arg res inp
B.executeLambdaPure1 @res) String
lName Var arg -> IndigoM res
body Expr arg
argm
compileSt (Lambda1Call (Proxy st
_ :: Proxy st) lName :: String
lName (Var arg -> IndigoM res
body :: (Var arg -> IndigoM res)) argm :: Expr arg
argm) =
(forall (inpt :: [*]). LambdaExecutor '[st] arg res inpt)
-> String
-> (Var arg -> IndigoM res)
-> Expr arg
-> Reader
(Map String CompiledLambda) (SomeIndigoState anyInp (RetVars res))
forall (extra :: [*]) res arg (someOut :: [*]).
(Typeable extra, KnownValue arg, Typeable res, ScopeCodeGen res) =>
(forall (inpt :: [*]). LambdaExecutor extra arg res inpt)
-> String
-> (Var arg -> IndigoM res)
-> Expr arg
-> Reader
(Map String CompiledLambda) (SomeIndigoState someOut (RetVars res))
execGenericLambda @'[st] @res (forall arg (inp :: [*]).
ExecuteLambda1C st arg res =>
LambdaExecutor '[st] arg res inp
forall st res arg (inp :: [*]).
ExecuteLambda1C st arg res =>
LambdaExecutor '[st] arg res inp
B.executeLambda1 @st @res) String
lName Var arg -> IndigoM res
body Expr arg
argm
compileSt (LambdaEff1Call (Proxy st
_ :: Proxy st) lName :: String
lName (Var arg -> IndigoM res
body :: (Var arg -> IndigoM res)) argm :: Expr arg
argm) =
(forall (inpt :: [*]). LambdaExecutor '[st, Ops] arg res inpt)
-> String
-> (Var arg -> IndigoM res)
-> Expr arg
-> Reader
(Map String CompiledLambda) (SomeIndigoState anyInp (RetVars res))
forall (extra :: [*]) res arg (someOut :: [*]).
(Typeable extra, KnownValue arg, Typeable res, ScopeCodeGen res) =>
(forall (inpt :: [*]). LambdaExecutor extra arg res inpt)
-> String
-> (Var arg -> IndigoM res)
-> Expr arg
-> Reader
(Map String CompiledLambda) (SomeIndigoState someOut (RetVars res))
execGenericLambda @'[st, Ops] @res (forall arg (inp :: [*]).
ExecuteLambdaEff1C st arg res =>
LambdaExecutor '[st, Ops] arg res inp
forall st res arg (inp :: [*]).
ExecuteLambdaEff1C st arg res =>
LambdaExecutor '[st, Ops] arg res inp
B.executeLambdaEff1 @st @res) String
lName Var arg -> IndigoM res
body Expr arg
argm
compileSt (Scope cd :: IndigoM a
cd) = do
Map String CompiledLambda
definedLambdas <- ReaderT
(Map String CompiledLambda) Identity (Map String CompiledLambda)
forall r (m :: * -> *). MonadReader r m => m r
ask
SomeIndigoState anyInp x
-> Reader (Map String CompiledLambda) (SomeIndigoState anyInp x)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (SomeIndigoState anyInp x
-> Reader (Map String CompiledLambda) (SomeIndigoState anyInp x))
-> SomeIndigoState anyInp x
-> Reader (Map String CompiledLambda) (SomeIndigoState anyInp x)
forall a b. (a -> b) -> a -> b
$ SomeIndigoState anyInp a
-> (forall (out :: [*]).
IndigoState anyInp out a -> SomeIndigoState anyInp x)
-> SomeIndigoState anyInp x
forall (inp :: [*]) a b.
SomeIndigoState inp a
-> (forall (out :: [*]).
IndigoState inp out a -> SomeIndigoState inp b)
-> SomeIndigoState inp b
withSIS (Map String CompiledLambda -> IndigoM a -> SomeIndigoState anyInp a
forall a (inp :: [*]).
Map String CompiledLambda -> IndigoM a -> SomeIndigoState inp a
compileBody Map String CompiledLambda
definedLambdas IndigoM a
cd) (IndigoState
anyInp (RetOutStack' (ClassifyReturnValue a) a ++ anyInp) x
-> SomeIndigoState anyInp x
forall (inp :: [*]) (out :: [*]) a.
IndigoState inp out a -> SomeIndigoState inp a
toSIS (IndigoState
anyInp (RetOutStack' (ClassifyReturnValue a) a ++ anyInp) x
-> SomeIndigoState anyInp x)
-> (IndigoState anyInp out a
-> IndigoState
anyInp (RetOutStack' (ClassifyReturnValue a) a ++ anyInp) x)
-> IndigoState anyInp out a
-> SomeIndigoState anyInp x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IndigoState anyInp out a
-> IndigoState
anyInp (RetOutStack' (ClassifyReturnValue a) a ++ anyInp) x
forall a (inp :: [*]) (out :: [*]).
ScopeCodeGen a =>
IndigoState inp out a
-> IndigoState inp (RetOutStack a ++ inp) (RetVars a)
B.scope)
compileSt (If ex :: Expr Bool
ex tb :: IndigoM a
tb fb :: IndigoM b
fb) = do
Map String CompiledLambda
definedLambdas <- ReaderT
(Map String CompiledLambda) Identity (Map String CompiledLambda)
forall r (m :: * -> *). MonadReader r m => m r
ask
SomeIndigoState anyInp x
-> Reader (Map String CompiledLambda) (SomeIndigoState anyInp x)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (SomeIndigoState anyInp x
-> Reader (Map String CompiledLambda) (SomeIndigoState anyInp x))
-> SomeIndigoState anyInp x
-> Reader (Map String CompiledLambda) (SomeIndigoState anyInp x)
forall a b. (a -> b) -> a -> b
$ SomeIndigoState anyInp a
-> (forall (out :: [*]).
IndigoState anyInp out a -> SomeIndigoState anyInp x)
-> SomeIndigoState anyInp x
forall (inp :: [*]) a b.
SomeIndigoState inp a
-> (forall (out :: [*]).
IndigoState inp out a -> SomeIndigoState inp b)
-> SomeIndigoState inp b
withSIS (Map String CompiledLambda -> IndigoM a -> SomeIndigoState anyInp a
forall a (inp :: [*]).
Map String CompiledLambda -> IndigoM a -> SomeIndigoState inp a
compileBody Map String CompiledLambda
definedLambdas IndigoM a
tb) ((forall (out :: [*]).
IndigoState anyInp out a -> SomeIndigoState anyInp x)
-> SomeIndigoState anyInp x)
-> (forall (out :: [*]).
IndigoState anyInp out a -> SomeIndigoState anyInp x)
-> SomeIndigoState anyInp x
forall a b. (a -> b) -> a -> b
$ \tb' :: IndigoState anyInp out a
tb' ->
SomeIndigoState anyInp b
-> (forall (out :: [*]).
IndigoState anyInp out b -> SomeIndigoState anyInp x)
-> SomeIndigoState anyInp x
forall (inp :: [*]) a b.
SomeIndigoState inp a
-> (forall (out :: [*]).
IndigoState inp out a -> SomeIndigoState inp b)
-> SomeIndigoState inp b
withSIS (Map String CompiledLambda -> IndigoM b -> SomeIndigoState anyInp b
forall a (inp :: [*]).
Map String CompiledLambda -> IndigoM a -> SomeIndigoState inp a
compileBody Map String CompiledLambda
definedLambdas IndigoM b
fb) ((forall (out :: [*]).
IndigoState anyInp out b -> SomeIndigoState anyInp x)
-> SomeIndigoState anyInp x)
-> (forall (out :: [*]).
IndigoState anyInp out b -> SomeIndigoState anyInp x)
-> SomeIndigoState anyInp x
forall a b. (a -> b) -> a -> b
$ \fb' :: IndigoState anyInp out b
fb' ->
IndigoState
anyInp (RetOutStack' (ClassifyReturnValue b) b ++ anyInp) x
-> SomeIndigoState anyInp x
forall (inp :: [*]) (out :: [*]) a.
IndigoState inp out a -> SomeIndigoState inp a
toSIS (Expr Bool
-> IndigoState anyInp out a
-> IndigoState anyInp out b
-> IndigoState anyInp (RetOutStack a ++ anyInp) (RetVars a)
forall (inp :: [*]) (xs :: [*]) (ys :: [*]) a b.
IfConstraint a b =>
Expr Bool
-> IndigoState inp xs a
-> IndigoState inp ys b
-> IndigoState inp (RetOutStack a ++ inp) (RetVars a)
B.if_ Expr Bool
ex IndigoState anyInp out a
tb' IndigoState anyInp out b
fb')
compileSt (IfSome ex :: Expr (Maybe x)
ex tb :: Var x -> IndigoM a
tb fb :: IndigoM b
fb) = do
Map String CompiledLambda
definedLambdas <- ReaderT
(Map String CompiledLambda) Identity (Map String CompiledLambda)
forall r (m :: * -> *). MonadReader r m => m r
ask
SomeIndigoState anyInp x
-> Reader (Map String CompiledLambda) (SomeIndigoState anyInp x)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (SomeIndigoState anyInp x
-> Reader (Map String CompiledLambda) (SomeIndigoState anyInp x))
-> SomeIndigoState anyInp x
-> Reader (Map String CompiledLambda) (SomeIndigoState anyInp x)
forall a b. (a -> b) -> a -> b
$ (Var x -> SomeIndigoState (x & anyInp) a)
-> (forall (out :: [*]).
(Var x -> IndigoState (x & anyInp) out a)
-> SomeIndigoState anyInp x)
-> SomeIndigoState anyInp x
forall x (inp :: [*]) a b.
KnownValue x =>
(Var x -> SomeIndigoState (x & inp) a)
-> (forall (out :: [*]).
(Var x -> IndigoState (x & inp) out a) -> SomeIndigoState inp b)
-> SomeIndigoState inp b
withSIS1 (Map String CompiledLambda
-> IndigoM a -> SomeIndigoState (x & anyInp) a
forall a (inp :: [*]).
Map String CompiledLambda -> IndigoM a -> SomeIndigoState inp a
compileBody Map String CompiledLambda
definedLambdas (IndigoM a -> SomeIndigoState (x & anyInp) a)
-> (Var x -> IndigoM a) -> Var x -> SomeIndigoState (x & anyInp) a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Var x -> IndigoM a
tb) ((forall (out :: [*]).
(Var x -> IndigoState (x & anyInp) out a)
-> SomeIndigoState anyInp x)
-> SomeIndigoState anyInp x)
-> (forall (out :: [*]).
(Var x -> IndigoState (x & anyInp) out a)
-> SomeIndigoState anyInp x)
-> SomeIndigoState anyInp x
forall a b. (a -> b) -> a -> b
$ \tb' :: Var x -> IndigoState (x & anyInp) out a
tb' ->
SomeIndigoState anyInp b
-> (forall (out :: [*]).
IndigoState anyInp out b -> SomeIndigoState anyInp x)
-> SomeIndigoState anyInp x
forall (inp :: [*]) a b.
SomeIndigoState inp a
-> (forall (out :: [*]).
IndigoState inp out a -> SomeIndigoState inp b)
-> SomeIndigoState inp b
withSIS (Map String CompiledLambda -> IndigoM b -> SomeIndigoState anyInp b
forall a (inp :: [*]).
Map String CompiledLambda -> IndigoM a -> SomeIndigoState inp a
compileBody Map String CompiledLambda
definedLambdas IndigoM b
fb) ((forall (out :: [*]).
IndigoState anyInp out b -> SomeIndigoState anyInp x)
-> SomeIndigoState anyInp x)
-> (forall (out :: [*]).
IndigoState anyInp out b -> SomeIndigoState anyInp x)
-> SomeIndigoState anyInp x
forall a b. (a -> b) -> a -> b
$ \fb' :: IndigoState anyInp out b
fb' ->
IndigoState
anyInp (RetOutStack' (ClassifyReturnValue b) b ++ anyInp) x
-> SomeIndigoState anyInp x
forall (inp :: [*]) (out :: [*]) a.
IndigoState inp out a -> SomeIndigoState inp a
toSIS (Expr (Maybe x)
-> (Var x -> IndigoState (x & anyInp) out a)
-> IndigoState anyInp out b
-> IndigoState anyInp (RetOutStack a ++ anyInp) (RetVars a)
forall (inp :: [*]) (xs :: [*]) (ys :: [*]) x a b.
(IfConstraint a b, KnownValue x) =>
Expr (Maybe x)
-> (Var x -> IndigoState (x & inp) xs a)
-> IndigoState inp ys b
-> IndigoState inp (RetOutStack a ++ inp) (RetVars a)
B.ifSome Expr (Maybe x)
ex Var x -> IndigoState (x & anyInp) out a
tb' IndigoState anyInp out b
fb')
compileSt (IfRight ex :: Expr (Either y x)
ex rb :: Var x -> IndigoM a
rb lb :: Var y -> IndigoM b
lb) = do
Map String CompiledLambda
definedLambdas <- ReaderT
(Map String CompiledLambda) Identity (Map String CompiledLambda)
forall r (m :: * -> *). MonadReader r m => m r
ask
SomeIndigoState anyInp x
-> Reader (Map String CompiledLambda) (SomeIndigoState anyInp x)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (SomeIndigoState anyInp x
-> Reader (Map String CompiledLambda) (SomeIndigoState anyInp x))
-> SomeIndigoState anyInp x
-> Reader (Map String CompiledLambda) (SomeIndigoState anyInp x)
forall a b. (a -> b) -> a -> b
$ (Var x -> SomeIndigoState (x & anyInp) a)
-> (forall (out :: [*]).
(Var x -> IndigoState (x & anyInp) out a)
-> SomeIndigoState anyInp x)
-> SomeIndigoState anyInp x
forall x (inp :: [*]) a b.
KnownValue x =>
(Var x -> SomeIndigoState (x & inp) a)
-> (forall (out :: [*]).
(Var x -> IndigoState (x & inp) out a) -> SomeIndigoState inp b)
-> SomeIndigoState inp b
withSIS1 (Map String CompiledLambda
-> IndigoM a -> SomeIndigoState (x & anyInp) a
forall a (inp :: [*]).
Map String CompiledLambda -> IndigoM a -> SomeIndigoState inp a
compileBody Map String CompiledLambda
definedLambdas (IndigoM a -> SomeIndigoState (x & anyInp) a)
-> (Var x -> IndigoM a) -> Var x -> SomeIndigoState (x & anyInp) a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Var x -> IndigoM a
rb) ((forall (out :: [*]).
(Var x -> IndigoState (x & anyInp) out a)
-> SomeIndigoState anyInp x)
-> SomeIndigoState anyInp x)
-> (forall (out :: [*]).
(Var x -> IndigoState (x & anyInp) out a)
-> SomeIndigoState anyInp x)
-> SomeIndigoState anyInp x
forall a b. (a -> b) -> a -> b
$ \rb' :: Var x -> IndigoState (x & anyInp) out a
rb' ->
(Var y -> SomeIndigoState (y & anyInp) b)
-> (forall (out :: [*]).
(Var y -> IndigoState (y & anyInp) out b)
-> SomeIndigoState anyInp x)
-> SomeIndigoState anyInp x
forall x (inp :: [*]) a b.
KnownValue x =>
(Var x -> SomeIndigoState (x & inp) a)
-> (forall (out :: [*]).
(Var x -> IndigoState (x & inp) out a) -> SomeIndigoState inp b)
-> SomeIndigoState inp b
withSIS1 (Map String CompiledLambda
-> IndigoM b -> SomeIndigoState (y & anyInp) b
forall a (inp :: [*]).
Map String CompiledLambda -> IndigoM a -> SomeIndigoState inp a
compileBody Map String CompiledLambda
definedLambdas (IndigoM b -> SomeIndigoState (y & anyInp) b)
-> (Var y -> IndigoM b) -> Var y -> SomeIndigoState (y & anyInp) b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Var y -> IndigoM b
lb) ((forall (out :: [*]).
(Var y -> IndigoState (y & anyInp) out b)
-> SomeIndigoState anyInp x)
-> SomeIndigoState anyInp x)
-> (forall (out :: [*]).
(Var y -> IndigoState (y & anyInp) out b)
-> SomeIndigoState anyInp x)
-> SomeIndigoState anyInp x
forall a b. (a -> b) -> a -> b
$ \lb' :: Var y -> IndigoState (y & anyInp) out b
lb' ->
IndigoState
anyInp (RetOutStack' (ClassifyReturnValue b) b ++ anyInp) x
-> SomeIndigoState anyInp x
forall (inp :: [*]) (out :: [*]) a.
IndigoState inp out a -> SomeIndigoState inp a
toSIS (Expr (Either y x)
-> (Var x -> IndigoState (x & anyInp) out a)
-> (Var y -> IndigoState (y & anyInp) out b)
-> IndigoState anyInp (RetOutStack a ++ anyInp) (RetVars a)
forall (inp :: [*]) (xs :: [*]) (ys :: [*]) x y a b.
(IfConstraint a b, KnownValue x, KnownValue y) =>
Expr (Either y x)
-> (Var x -> IndigoState (x & inp) xs a)
-> (Var y -> IndigoState (y & inp) ys b)
-> IndigoState inp (RetOutStack a ++ inp) (RetVars a)
B.ifRight Expr (Either y x)
ex Var x -> IndigoState (x & anyInp) out a
rb' Var y -> IndigoState (y & anyInp) out b
lb')
compileSt (IfCons ex :: Expr (List x)
ex tb :: Var x -> Var (List x) -> IndigoM a
tb fb :: IndigoM b
fb) = do
Map String CompiledLambda
definedLambdas <- ReaderT
(Map String CompiledLambda) Identity (Map String CompiledLambda)
forall r (m :: * -> *). MonadReader r m => m r
ask
SomeIndigoState anyInp x
-> Reader (Map String CompiledLambda) (SomeIndigoState anyInp x)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (SomeIndigoState anyInp x
-> Reader (Map String CompiledLambda) (SomeIndigoState anyInp x))
-> SomeIndigoState anyInp x
-> Reader (Map String CompiledLambda) (SomeIndigoState anyInp x)
forall a b. (a -> b) -> a -> b
$ (Var x
-> Var (List x) -> SomeIndigoState (x & (List x & anyInp)) a)
-> (forall (out :: [*]).
(Var x
-> Var (List x) -> IndigoState (x & (List x & anyInp)) out a)
-> SomeIndigoState anyInp x)
-> SomeIndigoState anyInp x
forall x y (inp :: [*]) a b.
(KnownValue x, KnownValue y) =>
(Var x -> Var y -> SomeIndigoState (x & (y & inp)) a)
-> (forall (out :: [*]).
(Var x -> Var y -> IndigoState (x & (y & inp)) out a)
-> SomeIndigoState inp b)
-> SomeIndigoState inp b
withSIS2 (\x :: Var x
x y :: Var (List x)
y -> Map String CompiledLambda
-> IndigoM a -> SomeIndigoState (x & (List x & anyInp)) a
forall a (inp :: [*]).
Map String CompiledLambda -> IndigoM a -> SomeIndigoState inp a
compileBody Map String CompiledLambda
definedLambdas (IndigoM a -> SomeIndigoState (x & (List x & anyInp)) a)
-> IndigoM a -> SomeIndigoState (x & (List x & anyInp)) a
forall a b. (a -> b) -> a -> b
$ Var x -> Var (List x) -> IndigoM a
tb Var x
x Var (List x)
y) ((forall (out :: [*]).
(Var x
-> Var (List x) -> IndigoState (x & (List x & anyInp)) out a)
-> SomeIndigoState anyInp x)
-> SomeIndigoState anyInp x)
-> (forall (out :: [*]).
(Var x
-> Var (List x) -> IndigoState (x & (List x & anyInp)) out a)
-> SomeIndigoState anyInp x)
-> SomeIndigoState anyInp x
forall a b. (a -> b) -> a -> b
$ \tb' :: Var x -> Var (List x) -> IndigoState (x & (List x & anyInp)) out a
tb' ->
SomeIndigoState anyInp b
-> (forall (out :: [*]).
IndigoState anyInp out b -> SomeIndigoState anyInp x)
-> SomeIndigoState anyInp x
forall (inp :: [*]) a b.
SomeIndigoState inp a
-> (forall (out :: [*]).
IndigoState inp out a -> SomeIndigoState inp b)
-> SomeIndigoState inp b
withSIS (Map String CompiledLambda -> IndigoM b -> SomeIndigoState anyInp b
forall a (inp :: [*]).
Map String CompiledLambda -> IndigoM a -> SomeIndigoState inp a
compileBody Map String CompiledLambda
definedLambdas IndigoM b
fb) ((forall (out :: [*]).
IndigoState anyInp out b -> SomeIndigoState anyInp x)
-> SomeIndigoState anyInp x)
-> (forall (out :: [*]).
IndigoState anyInp out b -> SomeIndigoState anyInp x)
-> SomeIndigoState anyInp x
forall a b. (a -> b) -> a -> b
$ \fb' :: IndigoState anyInp out b
fb' ->
IndigoState
anyInp (RetOutStack' (ClassifyReturnValue b) b ++ anyInp) x
-> SomeIndigoState anyInp x
forall (inp :: [*]) (out :: [*]) a.
IndigoState inp out a -> SomeIndigoState inp a
toSIS (Expr (List x)
-> (Var x
-> Var (List x) -> IndigoState (x & (List x & anyInp)) out a)
-> IndigoState anyInp out b
-> IndigoState anyInp (RetOutStack a ++ anyInp) (RetVars a)
forall (inp :: [*]) (xs :: [*]) (ys :: [*]) x a b.
(IfConstraint a b, KnownValue x) =>
Expr (List x)
-> (Var x -> Var (List x) -> IndigoState (x & (List x & inp)) xs a)
-> IndigoState inp ys b
-> IndigoState inp (RetOutStack a ++ inp) (RetVars a)
B.ifCons Expr (List x)
ex Var x -> Var (List x) -> IndigoState (x & (List x & anyInp)) out a
tb' IndigoState anyInp out b
fb')
compileSt (Case grd :: Expr dt
grd clauses :: clauses
clauses) = do
Map String CompiledLambda
definedLambdas <- ReaderT
(Map String CompiledLambda) Identity (Map String CompiledLambda)
forall r (m :: * -> *). MonadReader r m => m r
ask
SomeIndigoState anyInp x
-> Reader (Map String CompiledLambda) (SomeIndigoState anyInp x)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (SomeIndigoState anyInp x
-> Reader (Map String CompiledLambda) (SomeIndigoState anyInp x))
-> SomeIndigoState anyInp x
-> Reader (Map String CompiledLambda) (SomeIndigoState anyInp x)
forall a b. (a -> b) -> a -> b
$ IndigoState
anyInp (RetOutStack' (ClassifyReturnValue ret) ret ++ anyInp) x
-> SomeIndigoState anyInp x
forall (inp :: [*]) (out :: [*]) a.
IndigoState inp out a -> SomeIndigoState inp a
toSIS (IndigoState
anyInp (RetOutStack' (ClassifyReturnValue ret) ret ++ anyInp) x
-> SomeIndigoState anyInp x)
-> IndigoState
anyInp (RetOutStack' (ClassifyReturnValue ret) ret ++ anyInp) x
-> SomeIndigoState anyInp x
forall a b. (a -> b) -> a -> b
$ Expr dt
-> Rec (IndigoCaseClauseL ret) (GCaseClauses (Rep dt))
-> IndigoState
anyInp
(RetOutStack' (ClassifyReturnValue ret) ret ++ anyInp)
(RetVars ret)
forall dt (inp :: [*]) ret clauses.
CaseCommon dt ret clauses =>
Expr dt
-> clauses
-> IndigoState inp (RetOutStack ret ++ inp) (RetVars ret)
B.caseRec Expr dt
grd (Map String CompiledLambda
-> Rec (IndigoMCaseClauseL IndigoM ret) (GCaseClauses (Rep dt))
-> Rec (IndigoCaseClauseL ret) (GCaseClauses (Rep dt))
forall ret (cs :: [CaseClauseParam]).
RMap cs =>
Map String CompiledLambda
-> Rec (IndigoMCaseClauseL IndigoM ret) cs
-> Rec (IndigoCaseClauseL ret) cs
rmapClauses Map String CompiledLambda
definedLambdas clauses
Rec (IndigoMCaseClauseL IndigoM ret) (GCaseClauses (Rep dt))
clauses)
compileSt (EntryCase proxy :: Proxy entrypointKind
proxy grd :: Expr dt
grd clauses :: clauses
clauses) = do
Map String CompiledLambda
definedLambdas <- ReaderT
(Map String CompiledLambda) Identity (Map String CompiledLambda)
forall r (m :: * -> *). MonadReader r m => m r
ask
SomeIndigoState anyInp x
-> Reader (Map String CompiledLambda) (SomeIndigoState anyInp x)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (SomeIndigoState anyInp x
-> Reader (Map String CompiledLambda) (SomeIndigoState anyInp x))
-> SomeIndigoState anyInp x
-> Reader (Map String CompiledLambda) (SomeIndigoState anyInp x)
forall a b. (a -> b) -> a -> b
$ IndigoState
anyInp (RetOutStack' (ClassifyReturnValue ret) ret ++ anyInp) x
-> SomeIndigoState anyInp x
forall (inp :: [*]) (out :: [*]) a.
IndigoState inp out a -> SomeIndigoState inp a
toSIS (IndigoState
anyInp (RetOutStack' (ClassifyReturnValue ret) ret ++ anyInp) x
-> SomeIndigoState anyInp x)
-> IndigoState
anyInp (RetOutStack' (ClassifyReturnValue ret) ret ++ anyInp) x
-> SomeIndigoState anyInp x
forall a b. (a -> b) -> a -> b
$ Proxy entrypointKind
-> Expr dt
-> Rec (IndigoCaseClauseL ret) (GCaseClauses (Rep dt))
-> IndigoState
anyInp
(RetOutStack' (ClassifyReturnValue ret) ret ++ anyInp)
(RetVars ret)
forall dt entrypointKind (inp :: [*]) ret clauses.
(CaseCommon dt ret clauses,
DocumentEntrypoints entrypointKind dt) =>
Proxy entrypointKind
-> Expr dt
-> clauses
-> IndigoState inp (RetOutStack ret ++ inp) (RetVars ret)
B.entryCaseRec Proxy entrypointKind
proxy Expr dt
grd (Map String CompiledLambda
-> Rec (IndigoMCaseClauseL IndigoM ret) (GCaseClauses (Rep dt))
-> Rec (IndigoCaseClauseL ret) (GCaseClauses (Rep dt))
forall ret (cs :: [CaseClauseParam]).
RMap cs =>
Map String CompiledLambda
-> Rec (IndigoMCaseClauseL IndigoM ret) cs
-> Rec (IndigoCaseClauseL ret) cs
rmapClauses Map String CompiledLambda
definedLambdas clauses
Rec (IndigoMCaseClauseL IndigoM ret) (GCaseClauses (Rep dt))
clauses)
compileSt (EntryCaseSimple grd :: Expr cp
grd clauses :: clauses
clauses) = do
Map String CompiledLambda
definedLambdas <- ReaderT
(Map String CompiledLambda) Identity (Map String CompiledLambda)
forall r (m :: * -> *). MonadReader r m => m r
ask
SomeIndigoState anyInp x
-> Reader (Map String CompiledLambda) (SomeIndigoState anyInp x)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (SomeIndigoState anyInp x
-> Reader (Map String CompiledLambda) (SomeIndigoState anyInp x))
-> SomeIndigoState anyInp x
-> Reader (Map String CompiledLambda) (SomeIndigoState anyInp x)
forall a b. (a -> b) -> a -> b
$ IndigoState
anyInp (RetOutStack' (ClassifyReturnValue ret) ret ++ anyInp) x
-> SomeIndigoState anyInp x
forall (inp :: [*]) (out :: [*]) a.
IndigoState inp out a -> SomeIndigoState inp a
toSIS (IndigoState
anyInp (RetOutStack' (ClassifyReturnValue ret) ret ++ anyInp) x
-> SomeIndigoState anyInp x)
-> IndigoState
anyInp (RetOutStack' (ClassifyReturnValue ret) ret ++ anyInp) x
-> SomeIndigoState anyInp x
forall a b. (a -> b) -> a -> b
$ Expr cp
-> Rec (IndigoCaseClauseL ret) (GCaseClauses (Rep cp))
-> IndigoState
anyInp
(RetOutStack' (ClassifyReturnValue ret) ret ++ anyInp)
(RetVars ret)
forall cp (inp :: [*]) ret clauses.
(CaseCommon cp ret clauses,
DocumentEntrypoints PlainEntrypointsKind cp, NiceParameterFull cp,
RequireFlatParamEps cp) =>
Expr cp
-> clauses
-> IndigoState inp (RetOutStack ret ++ inp) (RetVars ret)
B.entryCaseSimpleRec Expr cp
grd (Map String CompiledLambda
-> Rec (IndigoMCaseClauseL IndigoM ret) (GCaseClauses (Rep cp))
-> Rec (IndigoCaseClauseL ret) (GCaseClauses (Rep cp))
forall ret (cs :: [CaseClauseParam]).
RMap cs =>
Map String CompiledLambda
-> Rec (IndigoMCaseClauseL IndigoM ret) cs
-> Rec (IndigoCaseClauseL ret) cs
rmapClauses Map String CompiledLambda
definedLambdas clauses
Rec (IndigoMCaseClauseL IndigoM ret) (GCaseClauses (Rep cp))
clauses)
compileSt (While ex :: Expr Bool
ex body :: IndigoM ()
body) = do
Map String CompiledLambda
definedLambdas <- ReaderT
(Map String CompiledLambda) Identity (Map String CompiledLambda)
forall r (m :: * -> *). MonadReader r m => m r
ask
SomeIndigoState anyInp x
-> Reader (Map String CompiledLambda) (SomeIndigoState anyInp x)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (SomeIndigoState anyInp x
-> Reader (Map String CompiledLambda) (SomeIndigoState anyInp x))
-> SomeIndigoState anyInp x
-> Reader (Map String CompiledLambda) (SomeIndigoState anyInp x)
forall a b. (a -> b) -> a -> b
$ SomeIndigoState anyInp ()
-> (forall (out :: [*]).
IndigoState anyInp out () -> SomeIndigoState anyInp x)
-> SomeIndigoState anyInp x
forall (inp :: [*]) a b.
SomeIndigoState inp a
-> (forall (out :: [*]).
IndigoState inp out a -> SomeIndigoState inp b)
-> SomeIndigoState inp b
withSIS (Map String CompiledLambda
-> IndigoM () -> SomeIndigoState anyInp ()
forall a (inp :: [*]).
Map String CompiledLambda -> IndigoM a -> SomeIndigoState inp a
compileBody Map String CompiledLambda
definedLambdas IndigoM ()
body) ((forall (out :: [*]).
IndigoState anyInp out () -> SomeIndigoState anyInp x)
-> SomeIndigoState anyInp x)
-> (forall (out :: [*]).
IndigoState anyInp out () -> SomeIndigoState anyInp x)
-> SomeIndigoState anyInp x
forall a b. (a -> b) -> a -> b
$ \bd :: IndigoState anyInp out ()
bd -> IndigoState anyInp anyInp () -> SomeIndigoState anyInp ()
forall (inp :: [*]) (out :: [*]) a.
IndigoState inp out a -> SomeIndigoState inp a
toSIS (Expr Bool
-> IndigoState anyInp out () -> IndigoState anyInp anyInp ()
forall (inp :: [*]) (xs :: [*]).
Expr Bool -> IndigoState inp xs () -> IndigoState inp inp ()
B.while Expr Bool
ex IndigoState anyInp out ()
bd)
compileSt (WhileLeft ex :: Expr (Either y x)
ex lb :: Var y -> IndigoM ()
lb) = do
Map String CompiledLambda
definedLambdas <- ReaderT
(Map String CompiledLambda) Identity (Map String CompiledLambda)
forall r (m :: * -> *). MonadReader r m => m r
ask
SomeIndigoState anyInp x
-> Reader (Map String CompiledLambda) (SomeIndigoState anyInp x)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (SomeIndigoState anyInp x
-> Reader (Map String CompiledLambda) (SomeIndigoState anyInp x))
-> SomeIndigoState anyInp x
-> Reader (Map String CompiledLambda) (SomeIndigoState anyInp x)
forall a b. (a -> b) -> a -> b
$
(Var y -> SomeIndigoState (y & anyInp) ())
-> (forall (out :: [*]).
(Var y -> IndigoState (y & anyInp) out ())
-> SomeIndigoState anyInp x)
-> SomeIndigoState anyInp x
forall x (inp :: [*]) a b.
KnownValue x =>
(Var x -> SomeIndigoState (x & inp) a)
-> (forall (out :: [*]).
(Var x -> IndigoState (x & inp) out a) -> SomeIndigoState inp b)
-> SomeIndigoState inp b
withSIS1 (Map String CompiledLambda
-> IndigoM () -> SomeIndigoState (y & anyInp) ()
forall a (inp :: [*]).
Map String CompiledLambda -> IndigoM a -> SomeIndigoState inp a
compileBody Map String CompiledLambda
definedLambdas (IndigoM () -> SomeIndigoState (y & anyInp) ())
-> (Var y -> IndigoM ())
-> Var y
-> SomeIndigoState (y & anyInp) ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Var y -> IndigoM ()
lb) ((forall (out :: [*]).
(Var y -> IndigoState (y & anyInp) out ())
-> SomeIndigoState anyInp x)
-> SomeIndigoState anyInp x)
-> (forall (out :: [*]).
(Var y -> IndigoState (y & anyInp) out ())
-> SomeIndigoState anyInp x)
-> SomeIndigoState anyInp x
forall a b. (a -> b) -> a -> b
$ \lb' :: Var y -> IndigoState (y & anyInp) out ()
lb' -> do
IndigoState anyInp (x & anyInp) (Var x)
-> SomeIndigoState anyInp (Var x)
forall (inp :: [*]) (out :: [*]) a.
IndigoState inp out a -> SomeIndigoState inp a
toSIS (Expr (Either y x)
-> (Var y -> IndigoState (y & anyInp) out ())
-> IndigoState anyInp (x & anyInp) (Var x)
forall l r (inp :: [*]) (xs :: [*]).
(KnownValue l, KnownValue r) =>
Expr (Either l r)
-> (Var l -> IndigoState (l & inp) xs ())
-> IndigoState inp (r & inp) (Var r)
B.whileLeft Expr (Either y x)
ex Var y -> IndigoState (y & anyInp) out ()
lb')
compileSt (ForEach e :: Expr a
e body :: Var (IterOpElHs a) -> IndigoM ()
body) = do
Map String CompiledLambda
definedLambdas <- ReaderT
(Map String CompiledLambda) Identity (Map String CompiledLambda)
forall r (m :: * -> *). MonadReader r m => m r
ask
SomeIndigoState anyInp x
-> Reader (Map String CompiledLambda) (SomeIndigoState anyInp x)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (SomeIndigoState anyInp x
-> Reader (Map String CompiledLambda) (SomeIndigoState anyInp x))
-> SomeIndigoState anyInp x
-> Reader (Map String CompiledLambda) (SomeIndigoState anyInp x)
forall a b. (a -> b) -> a -> b
$ (Var (IterOpElHs a) -> SomeIndigoState (IterOpElHs a & anyInp) ())
-> (forall (out :: [*]).
(Var (IterOpElHs a) -> IndigoState (IterOpElHs a & anyInp) out ())
-> SomeIndigoState anyInp x)
-> SomeIndigoState anyInp x
forall x (inp :: [*]) a b.
KnownValue x =>
(Var x -> SomeIndigoState (x & inp) a)
-> (forall (out :: [*]).
(Var x -> IndigoState (x & inp) out a) -> SomeIndigoState inp b)
-> SomeIndigoState inp b
withSIS1 (Map String CompiledLambda
-> IndigoM () -> SomeIndigoState (IterOpElHs a & anyInp) ()
forall a (inp :: [*]).
Map String CompiledLambda -> IndigoM a -> SomeIndigoState inp a
compileBody Map String CompiledLambda
definedLambdas (IndigoM () -> SomeIndigoState (IterOpElHs a & anyInp) ())
-> (Var (IterOpElHs a) -> IndigoM ())
-> Var (IterOpElHs a)
-> SomeIndigoState (IterOpElHs a & anyInp) ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Var (IterOpElHs a) -> IndigoM ()
body) ((forall (out :: [*]).
(Var (IterOpElHs a) -> IndigoState (IterOpElHs a & anyInp) out ())
-> SomeIndigoState anyInp x)
-> SomeIndigoState anyInp x)
-> (forall (out :: [*]).
(Var (IterOpElHs a) -> IndigoState (IterOpElHs a & anyInp) out ())
-> SomeIndigoState anyInp x)
-> SomeIndigoState anyInp x
forall a b. (a -> b) -> a -> b
$ \bd :: Var (IterOpElHs a) -> IndigoState (IterOpElHs a & anyInp) out ()
bd -> IndigoState anyInp anyInp () -> SomeIndigoState anyInp ()
forall (inp :: [*]) (out :: [*]) a.
IndigoState inp out a -> SomeIndigoState inp a
toSIS (Expr a
-> (Var (IterOpElHs a)
-> IndigoState (IterOpElHs a & anyInp) out ())
-> IndigoState anyInp anyInp ()
forall a (inp :: [*]) (xs :: [*]).
(IterOpHs a, KnownValue (IterOpElHs a)) =>
Expr a
-> (Var (IterOpElHs a) -> IndigoState (IterOpElHs a & inp) xs ())
-> IndigoState inp inp ()
B.forEach Expr a
e Var (IterOpElHs a) -> IndigoState (IterOpElHs a & anyInp) out ()
bd)
compileSt (ContractName cName :: Text
cName contr :: IndigoM ()
contr) = do
Map String CompiledLambda
definedLambdas <- ReaderT
(Map String CompiledLambda) Identity (Map String CompiledLambda)
forall r (m :: * -> *). MonadReader r m => m r
ask
SomeIndigoState anyInp x
-> Reader (Map String CompiledLambda) (SomeIndigoState anyInp x)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (SomeIndigoState anyInp x
-> Reader (Map String CompiledLambda) (SomeIndigoState anyInp x))
-> SomeIndigoState anyInp x
-> Reader (Map String CompiledLambda) (SomeIndigoState anyInp x)
forall a b. (a -> b) -> a -> b
$ SomeIndigoState anyInp ()
-> (forall (out :: [*]).
IndigoState anyInp out () -> SomeIndigoState anyInp x)
-> SomeIndigoState anyInp x
forall (inp :: [*]) a b.
SomeIndigoState inp a
-> (forall (out :: [*]).
IndigoState inp out a -> SomeIndigoState inp b)
-> SomeIndigoState inp b
withSIS (Map String CompiledLambda
-> IndigoM () -> SomeIndigoState anyInp ()
forall a (inp :: [*]).
Map String CompiledLambda -> IndigoM a -> SomeIndigoState inp a
compileBody Map String CompiledLambda
definedLambdas IndigoM ()
contr) ((forall (out :: [*]).
IndigoState anyInp out () -> SomeIndigoState anyInp x)
-> SomeIndigoState anyInp x)
-> (forall (out :: [*]).
IndigoState anyInp out () -> SomeIndigoState anyInp x)
-> SomeIndigoState anyInp x
forall a b. (a -> b) -> a -> b
$ IndigoState anyInp out () -> SomeIndigoState anyInp ()
forall (inp :: [*]) (out :: [*]) a.
IndigoState inp out a -> SomeIndigoState inp a
toSIS (IndigoState anyInp out () -> SomeIndigoState anyInp ())
-> (IndigoState anyInp out () -> IndigoState anyInp out ())
-> IndigoState anyInp out ()
-> SomeIndigoState anyInp ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> IndigoState anyInp out () -> IndigoState anyInp out ()
forall (i :: [*]) (o :: [*]).
Text -> IndigoState i o () -> IndigoState i o ()
B.contractName Text
cName
compileSt (DocGroup gr :: DocGrouping
gr ii :: IndigoM ()
ii) = do
Map String CompiledLambda
definedLambdas <- ReaderT
(Map String CompiledLambda) Identity (Map String CompiledLambda)
forall r (m :: * -> *). MonadReader r m => m r
ask
SomeIndigoState anyInp x
-> Reader (Map String CompiledLambda) (SomeIndigoState anyInp x)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (SomeIndigoState anyInp x
-> Reader (Map String CompiledLambda) (SomeIndigoState anyInp x))
-> SomeIndigoState anyInp x
-> Reader (Map String CompiledLambda) (SomeIndigoState anyInp x)
forall a b. (a -> b) -> a -> b
$ SomeIndigoState anyInp ()
-> (forall (out :: [*]).
IndigoState anyInp out () -> SomeIndigoState anyInp x)
-> SomeIndigoState anyInp x
forall (inp :: [*]) a b.
SomeIndigoState inp a
-> (forall (out :: [*]).
IndigoState inp out a -> SomeIndigoState inp b)
-> SomeIndigoState inp b
withSIS (Map String CompiledLambda
-> IndigoM () -> SomeIndigoState anyInp ()
forall a (inp :: [*]).
Map String CompiledLambda -> IndigoM a -> SomeIndigoState inp a
compileBody Map String CompiledLambda
definedLambdas IndigoM ()
ii) ((forall (out :: [*]).
IndigoState anyInp out () -> SomeIndigoState anyInp x)
-> SomeIndigoState anyInp x)
-> (forall (out :: [*]).
IndigoState anyInp out () -> SomeIndigoState anyInp x)
-> SomeIndigoState anyInp x
forall a b. (a -> b) -> a -> b
$ IndigoState anyInp out () -> SomeIndigoState anyInp ()
forall (inp :: [*]) (out :: [*]) a.
IndigoState inp out a -> SomeIndigoState inp a
toSIS (IndigoState anyInp out () -> SomeIndigoState anyInp ())
-> (IndigoState anyInp out () -> IndigoState anyInp out ())
-> IndigoState anyInp out ()
-> SomeIndigoState anyInp ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DocGrouping
-> IndigoState anyInp out () -> IndigoState anyInp out ()
forall (i :: [*]) (o :: [*]).
DocGrouping -> IndigoState i o () -> IndigoState i o ()
B.docGroup DocGrouping
gr
compileSt (ContractGeneral contr :: IndigoM ()
contr) = do
Map String CompiledLambda
definedLambdas <- ReaderT
(Map String CompiledLambda) Identity (Map String CompiledLambda)
forall r (m :: * -> *). MonadReader r m => m r
ask
SomeIndigoState anyInp x
-> Reader (Map String CompiledLambda) (SomeIndigoState anyInp x)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (SomeIndigoState anyInp x
-> Reader (Map String CompiledLambda) (SomeIndigoState anyInp x))
-> SomeIndigoState anyInp x
-> Reader (Map String CompiledLambda) (SomeIndigoState anyInp x)
forall a b. (a -> b) -> a -> b
$ SomeIndigoState anyInp ()
-> (forall (out :: [*]).
IndigoState anyInp out () -> SomeIndigoState anyInp x)
-> SomeIndigoState anyInp x
forall (inp :: [*]) a b.
SomeIndigoState inp a
-> (forall (out :: [*]).
IndigoState inp out a -> SomeIndigoState inp b)
-> SomeIndigoState inp b
withSIS (Map String CompiledLambda
-> IndigoM () -> SomeIndigoState anyInp ()
forall a (inp :: [*]).
Map String CompiledLambda -> IndigoM a -> SomeIndigoState inp a
compileBody Map String CompiledLambda
definedLambdas IndigoM ()
contr) (IndigoState anyInp out () -> SomeIndigoState anyInp ()
forall (inp :: [*]) (out :: [*]) a.
IndigoState inp out a -> SomeIndigoState inp a
toSIS (IndigoState anyInp out () -> SomeIndigoState anyInp ())
-> (IndigoState anyInp out () -> IndigoState anyInp out ())
-> IndigoState anyInp out ()
-> SomeIndigoState anyInp ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IndigoState anyInp out () -> IndigoState anyInp out ()
forall (i :: [*]) (o :: [*]).
IndigoState i o () -> IndigoState i o ()
B.contractGeneral)
compileSt (FinalizeParamCallingDoc entrypoint :: Var cp -> IndigoM x
entrypoint param :: Expr cp
param) = do
Map String CompiledLambda
definedLambdas <- ReaderT
(Map String CompiledLambda) Identity (Map String CompiledLambda)
forall r (m :: * -> *). MonadReader r m => m r
ask
SomeIndigoState anyInp x
-> Reader (Map String CompiledLambda) (SomeIndigoState anyInp x)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (SomeIndigoState anyInp x
-> Reader (Map String CompiledLambda) (SomeIndigoState anyInp x))
-> SomeIndigoState anyInp x
-> Reader (Map String CompiledLambda) (SomeIndigoState anyInp x)
forall a b. (a -> b) -> a -> b
$ (Var cp -> SomeIndigoState (cp & anyInp) x)
-> (forall (out :: [*]).
(Var cp -> IndigoState (cp & anyInp) out x)
-> SomeIndigoState anyInp x)
-> SomeIndigoState anyInp x
forall x (inp :: [*]) a b.
KnownValue x =>
(Var x -> SomeIndigoState (x & inp) a)
-> (forall (out :: [*]).
(Var x -> IndigoState (x & inp) out a) -> SomeIndigoState inp b)
-> SomeIndigoState inp b
withSIS1 (Map String CompiledLambda
-> IndigoM x -> SomeIndigoState (cp & anyInp) x
forall a (inp :: [*]).
Map String CompiledLambda -> IndigoM a -> SomeIndigoState inp a
compileBody Map String CompiledLambda
definedLambdas (IndigoM x -> SomeIndigoState (cp & anyInp) x)
-> (Var cp -> IndigoM x)
-> Var cp
-> SomeIndigoState (cp & anyInp) x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Var cp -> IndigoM x
entrypoint)
(\bd :: Var cp -> IndigoState (cp & anyInp) out x
bd -> IndigoState anyInp out x -> SomeIndigoState anyInp x
forall (inp :: [*]) (out :: [*]) a.
IndigoState inp out a -> SomeIndigoState inp a
toSIS (IndigoState anyInp out x -> SomeIndigoState anyInp x)
-> IndigoState anyInp out x -> SomeIndigoState anyInp x
forall a b. (a -> b) -> a -> b
$ (Var cp -> IndigoState (cp & anyInp) out x)
-> Expr cp -> IndigoState anyInp out x
forall cp (inp :: [*]) (out :: [*]) x.
(NiceParameterFull cp, RequireSumType cp, HasCallStack) =>
(Var cp -> IndigoState (cp & inp) out x)
-> Expr cp -> IndigoState inp out x
B.finalizeParamCallingDoc Var cp -> IndigoState (cp & anyInp) out x
bd Expr cp
param)
compileSt (TransferTokens expar :: Expr p
expar exm :: Expr Mutez
exm exc :: Expr (ContractRef p)
exc) = SomeIndigoState anyInp ()
-> Reader (Map String CompiledLambda) (SomeIndigoState anyInp x)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (SomeIndigoState anyInp ()
-> Reader (Map String CompiledLambda) (SomeIndigoState anyInp x))
-> SomeIndigoState anyInp ()
-> Reader (Map String CompiledLambda) (SomeIndigoState anyInp x)
forall a b. (a -> b) -> a -> b
$ IndigoState anyInp anyInp () -> SomeIndigoState anyInp ()
forall (inp :: [*]) (out :: [*]) a.
IndigoState inp out a -> SomeIndigoState inp a
toSIS (Expr p
-> Expr Mutez
-> Expr (ContractRef p)
-> IndigoState anyInp anyInp ()
forall p (inp :: [*]).
(NiceParameter p, HasSideEffects) =>
Expr p
-> Expr Mutez -> Expr (ContractRef p) -> IndigoState inp inp ()
B.transferTokens Expr p
expar Expr Mutez
exm Expr (ContractRef p)
exc)
compileSt (SetDelegate kh :: Expr (Maybe KeyHash)
kh) = SomeIndigoState anyInp ()
-> Reader (Map String CompiledLambda) (SomeIndigoState anyInp x)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (SomeIndigoState anyInp ()
-> Reader (Map String CompiledLambda) (SomeIndigoState anyInp x))
-> SomeIndigoState anyInp ()
-> Reader (Map String CompiledLambda) (SomeIndigoState anyInp x)
forall a b. (a -> b) -> a -> b
$ IndigoState anyInp anyInp () -> SomeIndigoState anyInp ()
forall (inp :: [*]) (out :: [*]) a.
IndigoState inp out a -> SomeIndigoState inp a
toSIS (Expr (Maybe KeyHash) -> IndigoState anyInp anyInp ()
forall (inp :: [*]).
HasSideEffects =>
Expr (Maybe KeyHash) -> IndigoState inp inp ()
B.setDelegate Expr (Maybe KeyHash)
kh)
compileSt (CreateContract lCtr :: Contract param st
lCtr ek :: Expr (Maybe KeyHash)
ek em :: Expr Mutez
em es :: Expr st
es) = SomeIndigoState anyInp (Var Address)
-> Reader (Map String CompiledLambda) (SomeIndigoState anyInp x)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (SomeIndigoState anyInp (Var Address)
-> Reader (Map String CompiledLambda) (SomeIndigoState anyInp x))
-> SomeIndigoState anyInp (Var Address)
-> Reader (Map String CompiledLambda) (SomeIndigoState anyInp x)
forall a b. (a -> b) -> a -> b
$ IndigoState anyInp (Address & anyInp) (Var Address)
-> SomeIndigoState anyInp (Var Address)
forall (inp :: [*]) (out :: [*]) a.
IndigoState inp out a -> SomeIndigoState inp a
toSIS (IndigoState anyInp (Address & anyInp) (Var Address)
-> SomeIndigoState anyInp (Var Address))
-> IndigoState anyInp (Address & anyInp) (Var Address)
-> SomeIndigoState anyInp (Var Address)
forall a b. (a -> b) -> a -> b
$
IndigoState anyInp anyInp (MetaData anyInp)
forall (inp :: [*]). IndigoState inp inp (MetaData inp)
I.iget IndigoState anyInp anyInp (MetaData anyInp)
-> (MetaData anyInp
-> IndigoState anyInp (Address & anyInp) (Var Address))
-> IndigoState anyInp (Address & anyInp) (Var Address)
forall (inp :: [*]) (out :: [*]) (out1 :: [*]) a b.
IndigoState inp out a
-> (a -> IndigoState out out1 b) -> IndigoState inp out1 b
I.>>= \(MetaData s :: StackVars anyInp
s _) ->
Expr (Maybe KeyHash)
-> Expr Mutez
-> Expr st
-> ((Maybe KeyHash & (Mutez & (st & anyInp)))
:-> (Address & anyInp))
-> IndigoState anyInp (Address & anyInp) ()
forall res n m l (inp :: [*]).
KnownValue res =>
Expr n
-> Expr m
-> Expr l
-> ((n & (m & (l & inp))) :-> (res & inp))
-> IndigoState inp (res & inp) ()
ternaryOp Expr (Maybe KeyHash)
ek Expr Mutez
em Expr st
es (Contract param st
-> (Maybe KeyHash & (Mutez & (st & anyInp)))
:-> (Operation & (Address & anyInp))
forall p g (s :: [*]).
(NiceStorage g, NiceParameterFull p) =>
Contract p g
-> (Maybe KeyHash & (Mutez & (g & s)))
:-> (Operation & (Address & s))
L.createContract Contract param st
lCtr
# varActionOperation (NoRef :& s))
IndigoState anyInp (Address & anyInp) ()
-> IndigoState (Address & anyInp) (Address & anyInp) (Var Address)
-> IndigoState anyInp (Address & anyInp) (Var Address)
forall (inp :: [*]) (out :: [*]) a (out1 :: [*]) b.
IndigoState inp out a
-> IndigoState out out1 b -> IndigoState inp out1 b
I.>> IndigoState (Address & anyInp) (Address & anyInp) (Var Address)
forall x (inp :: [*]).
KnownValue x =>
IndigoState (x & inp) (x & inp) (Var x)
makeTopVar
compileSt (ContractCalling (Proxy cp
_ :: Proxy cp) ref :: epRef
ref addr :: Expr addr
addr) = SomeIndigoState anyInp (Var (Maybe (ContractRef epArg)))
-> Reader (Map String CompiledLambda) (SomeIndigoState anyInp x)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (SomeIndigoState anyInp (Var (Maybe (ContractRef epArg)))
-> Reader (Map String CompiledLambda) (SomeIndigoState anyInp x))
-> SomeIndigoState anyInp (Var (Maybe (ContractRef epArg)))
-> Reader (Map String CompiledLambda) (SomeIndigoState anyInp x)
forall a b. (a -> b) -> a -> b
$ IndigoState
anyInp
(Maybe (ContractRef epArg) & anyInp)
(Var (Maybe (ContractRef epArg)))
-> SomeIndigoState anyInp (Var (Maybe (ContractRef epArg)))
forall (inp :: [*]) (out :: [*]) a.
IndigoState inp out a -> SomeIndigoState inp a
toSIS (IndigoState
anyInp
(Maybe (ContractRef epArg) & anyInp)
(Var (Maybe (ContractRef epArg)))
-> SomeIndigoState anyInp (Var (Maybe (ContractRef epArg))))
-> IndigoState
anyInp
(Maybe (ContractRef epArg) & anyInp)
(Var (Maybe (ContractRef epArg)))
-> SomeIndigoState anyInp (Var (Maybe (ContractRef epArg)))
forall a b. (a -> b) -> a -> b
$ epRef
-> Expr addr
-> IndigoState
anyInp
(Maybe (ContractRef epArg) & anyInp)
(Var (Maybe (ContractRef epArg)))
forall cp (inp :: [*]) epRef epArg addr.
(HasEntrypointArg cp epRef epArg, ToTAddress cp addr,
ToT addr ~ ToT Address, KnownValue epArg) =>
epRef
-> Expr addr
-> IndigoState
inp
(Maybe (ContractRef epArg) & inp)
(Var (Maybe (ContractRef epArg)))
B.contractCalling @cp epRef
ref Expr addr
addr
compileSt (FailWith ex :: Expr a
ex) = SomeIndigoState anyInp x
-> Reader (Map String CompiledLambda) (SomeIndigoState anyInp x)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (SomeIndigoState anyInp x
-> Reader (Map String CompiledLambda) (SomeIndigoState anyInp x))
-> SomeIndigoState anyInp x
-> Reader (Map String CompiledLambda) (SomeIndigoState anyInp x)
forall a b. (a -> b) -> a -> b
$ IndigoState anyInp Any x -> SomeIndigoState anyInp x
forall (inp :: [*]) (out :: [*]) a.
IndigoState inp out a -> SomeIndigoState inp a
toSIS (IndigoState anyInp Any x -> SomeIndigoState anyInp x)
-> IndigoState anyInp Any x -> SomeIndigoState anyInp x
forall a b. (a -> b) -> a -> b
$ Expr a -> IndigoState anyInp Any x
forall a (s :: [*]) (t :: [*]) r.
KnownValue a =>
Expr a -> IndigoState s t r
B.failWith Expr a
ex
compileSt (Assert err :: x
err expr :: Expr Bool
expr) = SomeIndigoState anyInp ()
-> Reader (Map String CompiledLambda) (SomeIndigoState anyInp x)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (SomeIndigoState anyInp ()
-> Reader (Map String CompiledLambda) (SomeIndigoState anyInp x))
-> SomeIndigoState anyInp ()
-> Reader (Map String CompiledLambda) (SomeIndigoState anyInp x)
forall a b. (a -> b) -> a -> b
$ IndigoState anyInp anyInp () -> SomeIndigoState anyInp ()
forall (inp :: [*]) (out :: [*]) a.
IndigoState inp out a -> SomeIndigoState inp a
toSIS (IndigoState anyInp anyInp () -> SomeIndigoState anyInp ())
-> IndigoState anyInp anyInp () -> SomeIndigoState anyInp ()
forall a b. (a -> b) -> a -> b
$ x -> Expr Bool -> IndigoState anyInp anyInp ()
forall (s :: [*]) x.
IsError x =>
x -> Expr Bool -> IndigoState s s ()
B.assert x
err Expr Bool
expr
compileSt (FailCustom l :: Label tag
l expr :: Expr err
expr) = SomeIndigoState anyInp x
-> Reader (Map String CompiledLambda) (SomeIndigoState anyInp x)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (SomeIndigoState anyInp x
-> Reader (Map String CompiledLambda) (SomeIndigoState anyInp x))
-> SomeIndigoState anyInp x
-> Reader (Map String CompiledLambda) (SomeIndigoState anyInp x)
forall a b. (a -> b) -> a -> b
$ IndigoState anyInp Any x -> SomeIndigoState anyInp x
forall (inp :: [*]) (out :: [*]) a.
IndigoState inp out a -> SomeIndigoState inp a
toSIS (IndigoState anyInp Any x -> SomeIndigoState anyInp x)
-> IndigoState anyInp Any x -> SomeIndigoState anyInp x
forall a b. (a -> b) -> a -> b
$ Label tag -> Expr err -> IndigoState anyInp Any x
forall (tag :: Symbol) err (s :: [*]) (t :: [*]) r.
(err ~ ErrorArg tag, CustomErrorHasDoc tag, NiceConstant err) =>
Label tag -> Expr err -> IndigoState s t r
B.failCustom Label tag
l Expr err
expr
rmapClauses:: forall ret cs . RMap cs
=> Map String CompiledLambda
-> Rec (IndigoMCaseClauseL IndigoM ret) cs
-> Rec (B.IndigoCaseClauseL ret) cs
rmapClauses :: Map String CompiledLambda
-> Rec (IndigoMCaseClauseL IndigoM ret) cs
-> Rec (IndigoCaseClauseL ret) cs
rmapClauses definedLambdas :: Map String CompiledLambda
definedLambdas = (forall (x :: CaseClauseParam).
IndigoMCaseClauseL IndigoM ret x -> IndigoCaseClauseL ret x)
-> Rec (IndigoMCaseClauseL IndigoM ret) cs
-> Rec (IndigoCaseClauseL ret) cs
forall u (rs :: [u]) (f :: u -> *) (g :: u -> *).
RMap rs =>
(forall (x :: u). f x -> g x) -> Rec f rs -> Rec g rs
rmap (\(OneFieldIndigoMCaseClauseL cName clause) ->
Label name
cName Label name
-> (IndigoObjectF (NamedFieldVar x) x -> IndigoAnyOut x ret)
-> IndigoCaseClauseL ret x
forall (name :: Symbol) body clause.
CaseArrow name body clause =>
Label name -> body -> clause
/-> (\v :: IndigoObjectF (NamedFieldVar x) x
v -> (forall (inp :: [*]). SomeIndigoState (x : inp) retBr)
-> IndigoAnyOut x ret
forall x ret retBranch.
(ScopeCodeGen retBranch,
RetOutStack ret ~ RetOutStack retBranch) =>
(forall (inp :: [*]). SomeIndigoState (x : inp) retBranch)
-> IndigoAnyOut x ret
B.IndigoAnyOut ((forall (inp :: [*]). SomeIndigoState (x : inp) retBr)
-> IndigoAnyOut x ret)
-> (forall (inp :: [*]). SomeIndigoState (x : inp) retBr)
-> IndigoAnyOut x ret
forall a b. (a -> b) -> a -> b
$ Map String CompiledLambda
-> IndigoM retBr -> SomeIndigoState (x : inp) retBr
forall a (inp :: [*]).
Map String CompiledLambda -> IndigoM a -> SomeIndigoState inp a
compileBody Map String CompiledLambda
definedLambdas (IndigoM retBr -> SomeIndigoState (x : inp) retBr)
-> IndigoM retBr -> SomeIndigoState (x : inp) retBr
forall a b. (a -> b) -> a -> b
$ IndigoObjectF (NamedFieldVar x) x -> IndigoM retBr
clause IndigoObjectF (NamedFieldVar x) x
v))
forMSIS :: [r] -> (forall someInp . r -> SomeIndigoState someInp v) -> SomeIndigoState someInp1 [v]
forMSIS :: [r]
-> (forall (someInp :: [*]). r -> SomeIndigoState someInp v)
-> SomeIndigoState someInp1 [v]
forMSIS [] _ = [v] -> SomeIndigoState someInp1 [v]
forall a (inp :: [*]). a -> SomeIndigoState inp a
returnSIS []
forMSIS (x :: r
x : xs :: [r]
xs) f :: forall (someInp :: [*]). r -> SomeIndigoState someInp v
f = r -> SomeIndigoState someInp1 v
forall (someInp :: [*]). r -> SomeIndigoState someInp v
f r
x SomeIndigoState someInp1 v
-> (forall (someOut :: [*]). v -> SomeIndigoState someOut [v])
-> SomeIndigoState someInp1 [v]
forall (inp :: [*]) a b.
SomeIndigoState inp a
-> (forall (someOut :: [*]). a -> SomeIndigoState someOut b)
-> SomeIndigoState inp b
`bindSIS` (\what :: v
what -> (v
what v -> [v] -> [v]
forall a. a -> [a] -> [a]
:) ([v] -> [v])
-> SomeIndigoState someOut [v] -> SomeIndigoState someOut [v]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [r]
-> (forall (someInp :: [*]). r -> SomeIndigoState someInp v)
-> SomeIndigoState someOut [v]
forall r v (someInp1 :: [*]).
[r]
-> (forall (someInp :: [*]). r -> SomeIndigoState someInp v)
-> SomeIndigoState someInp1 [v]
forMSIS [r]
xs forall (someInp :: [*]). r -> SomeIndigoState someInp v
f)
defineLambda :: Lambda1Def -> SomeIndigoState someOut CompiledLambda
defineLambda :: Lambda1Def -> SomeIndigoState someOut CompiledLambda
defineLambda (LambdaPure1Def (Proxy (_stUnit, arg, res)
_ :: Proxy (_s, arg, res)) lName :: String
lName fun :: Var arg -> IndigoM res
fun) =
(Var arg, MetaData (arg & '[]))
-> (forall (inpt :: [*]) (out :: [*]).
LambdaCreator '[] arg res inpt out)
-> String
-> (Var arg -> IndigoM res)
-> SomeIndigoState someOut CompiledLambda
forall (extra :: [*]) res arg (someOut :: [*]).
(Typeable arg, Typeable res, Typeable extra) =>
(Var arg, MetaData (arg & extra))
-> (forall (inpt :: [*]) (out :: [*]).
LambdaCreator extra arg res inpt out)
-> String
-> (Var arg -> IndigoM res)
-> SomeIndigoState someOut CompiledLambda
defineGenericLambda @'[] (Var arg, MetaData (arg & '[]))
forall arg. KnownValue arg => (Var arg, MetaData '[arg])
B.initMetaDataPure forall (inpt :: [*]) (out :: [*]).
LambdaCreator '[] arg res inpt out
forall res arg (inp :: [*]) (out :: [*]).
CreateLambdaPure1C arg res =>
LambdaCreator '[] arg res inp out
B.createLambdaPure1 String
lName Var arg -> IndigoM res
fun
defineLambda (Lambda1Def (Proxy (st, arg, res)
_ :: Proxy (st, arg, res)) lName :: String
lName fun :: Var arg -> IndigoM res
fun) =
(Var arg, MetaData (arg & '[st]))
-> (forall (inpt :: [*]) (out :: [*]).
LambdaCreator '[st] arg res inpt out)
-> String
-> (Var arg -> IndigoM res)
-> SomeIndigoState someOut CompiledLambda
forall (extra :: [*]) res arg (someOut :: [*]).
(Typeable arg, Typeable res, Typeable extra) =>
(Var arg, MetaData (arg & extra))
-> (forall (inpt :: [*]) (out :: [*]).
LambdaCreator extra arg res inpt out)
-> String
-> (Var arg -> IndigoM res)
-> SomeIndigoState someOut CompiledLambda
defineGenericLambda @'[st] (Var arg, MetaData (arg & '[st]))
forall arg st.
(KnownValue arg, KnownValue st) =>
(Var arg, MetaData '[arg, st])
B.initMetaData forall (inpt :: [*]) (out :: [*]).
LambdaCreator '[st] arg res inpt out
forall st res arg (inp :: [*]) (out :: [*]).
CreateLambda1C st arg res =>
LambdaCreator '[st] arg res inp out
B.createLambda1 String
lName Var arg -> IndigoM res
fun
defineLambda (LambdaEff1Def (Proxy (st, arg, res)
_ :: Proxy (st, arg, res)) lName :: String
lName fun :: Var arg -> IndigoM res
fun) =
(Var arg, MetaData (arg & '[st, Ops]))
-> (forall (inpt :: [*]) (out :: [*]).
LambdaCreator '[st, Ops] arg res inpt out)
-> String
-> (Var arg -> IndigoM res)
-> SomeIndigoState someOut CompiledLambda
forall (extra :: [*]) res arg (someOut :: [*]).
(Typeable arg, Typeable res, Typeable extra) =>
(Var arg, MetaData (arg & extra))
-> (forall (inpt :: [*]) (out :: [*]).
LambdaCreator extra arg res inpt out)
-> String
-> (Var arg -> IndigoM res)
-> SomeIndigoState someOut CompiledLambda
defineGenericLambda @'[st, Ops] (Var arg, MetaData (arg & '[st, Ops]))
forall arg st.
(KnownValue arg, KnownValue st) =>
(Var arg, MetaData '[arg, st, Ops])
B.initMetaDataEff forall (inpt :: [*]) (out :: [*]).
LambdaCreator '[st, Ops] arg res inpt out
forall st res arg (inp :: [*]) (out :: [*]).
CreateLambdaEff1C st arg res =>
LambdaCreator '[st, Ops] arg res inp out
B.createLambdaEff1 String
lName Var arg -> IndigoM res
fun
defineGenericLambda
:: forall extra res arg someOut .
(Typeable arg, Typeable res, Typeable extra)
=> (Var arg, MetaData (arg & extra))
-> (forall inpt out . B.LambdaCreator extra arg res inpt out)
-> String
-> (Var arg -> IndigoM res)
-> SomeIndigoState someOut CompiledLambda
defineGenericLambda :: (Var arg, MetaData (arg & extra))
-> (forall (inpt :: [*]) (out :: [*]).
LambdaCreator extra arg res inpt out)
-> String
-> (Var arg -> IndigoM res)
-> SomeIndigoState someOut CompiledLambda
defineGenericLambda (varArg :: Var arg
varArg, initMd :: MetaData (arg & extra)
initMd) lambdaCreator :: forall (inpt :: [*]) (out :: [*]).
LambdaCreator extra arg res inpt out
lambdaCreator lName :: String
lName fun :: Var arg -> IndigoM res
fun = do
SomeIndigoState (arg & extra) res
-> MetaData (arg & extra)
-> (forall (out :: [*]).
GenCode (arg & extra) out res
-> SomeIndigoState
someOut
(Var
((arg & extra)
:-> (RetOutStack' (ClassifyReturnValue res) res ++ extra))))
-> SomeIndigoState
someOut
(Var
((arg & extra)
:-> (RetOutStack' (ClassifyReturnValue res) res ++ extra)))
forall (inp :: [*]) a r.
SomeIndigoState inp a
-> MetaData inp
-> (forall (out :: [*]). GenCode inp out a -> r)
-> r
runSIS
(IndigoM res -> SomeIndigoState (arg & extra) res
forall (inp :: [*]) a. IndigoM a -> SomeIndigoState inp a
simpleCompileIndigoM (IndigoM res -> SomeIndigoState (arg & extra) res)
-> IndigoM res -> SomeIndigoState (arg & extra) res
forall a b. (a -> b) -> a -> b
$ Var arg -> IndigoM res
fun Var arg
varArg) MetaData (arg & extra)
initMd
(\gc :: GenCode (arg & extra) out res
gc -> IndigoState
someOut
(((arg & extra)
:-> (RetOutStack' (ClassifyReturnValue res) res ++ extra))
& someOut)
(Var
((arg & extra)
:-> (RetOutStack' (ClassifyReturnValue res) res ++ extra)))
-> SomeIndigoState
someOut
(Var
((arg & extra)
:-> (RetOutStack' (ClassifyReturnValue res) res ++ extra)))
forall (inp :: [*]) (out :: [*]) a.
IndigoState inp out a -> SomeIndigoState inp a
toSIS (IndigoState
someOut
(((arg & extra)
:-> (RetOutStack' (ClassifyReturnValue res) res ++ extra))
& someOut)
(Var
((arg & extra)
:-> (RetOutStack' (ClassifyReturnValue res) res ++ extra)))
-> SomeIndigoState
someOut
(Var
((arg & extra)
:-> (RetOutStack' (ClassifyReturnValue res) res ++ extra))))
-> IndigoState
someOut
(((arg & extra)
:-> (RetOutStack' (ClassifyReturnValue res) res ++ extra))
& someOut)
(Var
((arg & extra)
:-> (RetOutStack' (ClassifyReturnValue res) res ++ extra)))
-> SomeIndigoState
someOut
(Var
((arg & extra)
:-> (RetOutStack' (ClassifyReturnValue res) res ++ extra)))
forall a b. (a -> b) -> a -> b
$ LambdaCreator extra arg res someOut out
forall (inpt :: [*]) (out :: [*]).
LambdaCreator extra arg res inpt out
lambdaCreator (\_v :: Var arg
_v -> (MetaData (arg & extra) -> GenCode (arg & extra) out res)
-> IndigoState (arg & extra) out res
forall (inp :: [*]) (out :: [*]) a.
(MetaData inp -> GenCode inp out a) -> IndigoState inp out a
IndigoState ((MetaData (arg & extra) -> GenCode (arg & extra) out res)
-> IndigoState (arg & extra) out res)
-> (MetaData (arg & extra) -> GenCode (arg & extra) out res)
-> IndigoState (arg & extra) out res
forall a b. (a -> b) -> a -> b
$ \_md :: MetaData (arg & extra)
_md -> GenCode (arg & extra) out res
gc))
SomeIndigoState
someOut
(Var
((arg & extra)
:-> (RetOutStack' (ClassifyReturnValue res) res ++ extra)))
-> (forall (someOut :: [*]).
Var
((arg & extra)
:-> (RetOutStack' (ClassifyReturnValue res) res ++ extra))
-> SomeIndigoState someOut CompiledLambda)
-> SomeIndigoState someOut CompiledLambda
forall (inp :: [*]) a b.
SomeIndigoState inp a
-> (forall (someOut :: [*]). a -> SomeIndigoState someOut b)
-> SomeIndigoState inp b
`bindSIS`
(CompiledLambda -> SomeIndigoState someOut CompiledLambda
forall a (inp :: [*]). a -> SomeIndigoState inp a
returnSIS (CompiledLambda -> SomeIndigoState someOut CompiledLambda)
-> (Var
((arg & extra)
:-> (RetOutStack' (ClassifyReturnValue res) res ++ extra))
-> CompiledLambda)
-> Var
((arg & extra)
:-> (RetOutStack' (ClassifyReturnValue res) res ++ extra))
-> SomeIndigoState someOut CompiledLambda
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Proxy res
-> String
-> Var
((arg & extra)
:-> (RetOutStack' (ClassifyReturnValue res) res ++ extra))
-> CompiledLambda
forall arg res (extra :: [*]).
(Typeable arg, Typeable res, Typeable extra) =>
Proxy res
-> String -> Var (Lambda1Generic extra arg res) -> CompiledLambda
CompiledLambda (Proxy res
forall k (t :: k). Proxy t
Proxy @res) String
lName)
execGenericLambda
:: forall extra res arg someOut .
(Typeable extra, KnownValue arg, Typeable res, B.ScopeCodeGen res)
=> (forall inpt . B.LambdaExecutor extra arg res inpt)
-> String
-> (Var arg -> IndigoM res)
-> Expr arg
-> Reader (Map String CompiledLambda) (SomeIndigoState someOut (B.RetVars res))
execGenericLambda :: (forall (inpt :: [*]). LambdaExecutor extra arg res inpt)
-> String
-> (Var arg -> IndigoM res)
-> Expr arg
-> Reader
(Map String CompiledLambda) (SomeIndigoState someOut (RetVars res))
execGenericLambda executor :: forall (inpt :: [*]). LambdaExecutor extra arg res inpt
executor lName :: String
lName (Var arg -> IndigoM res
body :: (Var arg -> IndigoM res)) (Expr arg
argm :: Expr arg) = do
Map String CompiledLambda
compiled <- ReaderT
(Map String CompiledLambda) Identity (Map String CompiledLambda)
forall r (m :: * -> *). MonadReader r m => m r
ask
let maybeToRight' :: Maybe r -> l -> Either l r
maybeToRight' = (l -> Maybe r -> Either l r) -> Maybe r -> l -> Either l r
forall a b c. (a -> b -> c) -> b -> a -> c
flip l -> Maybe r -> Either l r
forall l r. l -> Maybe r -> Either l r
maybeToRight
SomeIndigoState someOut (RetVars res)
-> Reader
(Map String CompiledLambda) (SomeIndigoState someOut (RetVars res))
forall (f :: * -> *) a. Applicative f => a -> f a
pure (SomeIndigoState someOut (RetVars res)
-> Reader
(Map String CompiledLambda)
(SomeIndigoState someOut (RetVars res)))
-> SomeIndigoState someOut (RetVars res)
-> Reader
(Map String CompiledLambda) (SomeIndigoState someOut (RetVars res))
forall a b. (a -> b) -> a -> b
$ (String -> SomeIndigoState someOut (RetVars res))
-> (SomeIndigoState someOut (RetVars res)
-> SomeIndigoState someOut (RetVars res))
-> Either String (SomeIndigoState someOut (RetVars res))
-> SomeIndigoState someOut (RetVars res)
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (Text -> SomeIndigoState someOut (RetVars res)
forall a. HasCallStack => Text -> a
error (Text -> SomeIndigoState someOut (RetVars res))
-> (String -> Text)
-> String
-> SomeIndigoState someOut (RetVars res)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
forall a. IsString a => String -> a
fromString) SomeIndigoState someOut (RetVars res)
-> SomeIndigoState someOut (RetVars res)
forall a. a -> a
id (Either String (SomeIndigoState someOut (RetVars res))
-> SomeIndigoState someOut (RetVars res))
-> Either String (SomeIndigoState someOut (RetVars res))
-> SomeIndigoState someOut (RetVars res)
forall a b. (a -> b) -> a -> b
$ do
case String -> Map String CompiledLambda -> Maybe CompiledLambda
forall k a. Ord k => k -> Map k a -> Maybe a
M.lookup String
lName Map String CompiledLambda
compiled of
Nothing -> SomeIndigoState someOut (RetVars res)
-> Either String (SomeIndigoState someOut (RetVars res))
forall a b. b -> Either a b
Right (SomeIndigoState someOut (RetVars res)
-> Either String (SomeIndigoState someOut (RetVars res)))
-> SomeIndigoState someOut (RetVars res)
-> Either String (SomeIndigoState someOut (RetVars res))
forall a b. (a -> b) -> a -> b
$
(Var arg -> SomeIndigoState (arg & someOut) res)
-> (forall (out :: [*]).
(Var arg -> IndigoState (arg & someOut) out res)
-> SomeIndigoState someOut (RetVars res))
-> SomeIndigoState someOut (RetVars res)
forall x (inp :: [*]) a b.
KnownValue x =>
(Var x -> SomeIndigoState (x & inp) a)
-> (forall (out :: [*]).
(Var x -> IndigoState (x & inp) out a) -> SomeIndigoState inp b)
-> SomeIndigoState inp b
withSIS1 (Map String CompiledLambda
-> IndigoM res -> SomeIndigoState (arg & someOut) res
forall a (inp :: [*]).
Map String CompiledLambda -> IndigoM a -> SomeIndigoState inp a
compileBody Map String CompiledLambda
compiled (IndigoM res -> SomeIndigoState (arg & someOut) res)
-> (Var arg -> IndigoM res)
-> Var arg
-> SomeIndigoState (arg & someOut) res
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Var arg -> IndigoM res
body)
(\bd :: Var arg -> IndigoState (arg & someOut) out res
bd -> IndigoState
someOut
(RetOutStack' (ClassifyReturnValue res) res ++ (arg & someOut))
(RetVars res)
-> SomeIndigoState someOut (RetVars res)
forall (inp :: [*]) (out :: [*]) a.
IndigoState inp out a -> SomeIndigoState inp a
toSIS (IndigoState
someOut
(RetOutStack' (ClassifyReturnValue res) res ++ (arg & someOut))
(RetVars res)
-> SomeIndigoState someOut (RetVars res))
-> IndigoState
someOut
(RetOutStack' (ClassifyReturnValue res) res ++ (arg & someOut))
(RetVars res)
-> SomeIndigoState someOut (RetVars res)
forall a b. (a -> b) -> a -> b
$ Expr arg -> IndigoState someOut (arg & someOut) (Var arg)
forall x (inp :: [*]).
KnownValue x =>
Expr x -> IndigoState inp (x & inp) (Var x)
B.newVar Expr arg
argm IndigoState someOut (arg & someOut) (Var arg)
-> (Var arg
-> IndigoState
(arg & someOut)
(RetOutStack' (ClassifyReturnValue res) res ++ (arg & someOut))
(RetVars res))
-> IndigoState
someOut
(RetOutStack' (ClassifyReturnValue res) res ++ (arg & someOut))
(RetVars res)
forall (inp :: [*]) (out :: [*]) (out1 :: [*]) a b.
IndigoState inp out a
-> (a -> IndigoState out out1 b) -> IndigoState inp out1 b
I.>>= (forall (inp :: [*]) (out :: [*]).
ScopeCodeGen res =>
IndigoState inp out res
-> IndigoState
inp
(RetOutStack' (ClassifyReturnValue res) res ++ inp)
(RetVars res)
forall a (inp :: [*]) (out :: [*]).
ScopeCodeGen a =>
IndigoState inp out a
-> IndigoState inp (RetOutStack a ++ inp) (RetVars a)
B.scope @res (IndigoState (arg & someOut) out res
-> IndigoState
(arg & someOut)
(RetOutStack' (ClassifyReturnValue res) res ++ (arg & someOut))
(RetVars res))
-> (Var arg -> IndigoState (arg & someOut) out res)
-> Var arg
-> IndigoState
(arg & someOut)
(RetOutStack' (ClassifyReturnValue res) res ++ (arg & someOut))
(RetVars res)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Var arg -> IndigoState (arg & someOut) out res
bd))
Just compLam :: CompiledLambda
compLam -> case CompiledLambda
compLam of
CompiledLambda (Proxy res
_ :: Proxy res1) _ (varF :: Var (B.Lambda1Generic extra1 arg1 res1)) -> do
res :~: res
Refl <- Maybe (res :~: res) -> String -> Either String (res :~: res)
forall r l. Maybe r -> l -> Either l r
maybeToRight' ((Typeable res, Typeable res) => Maybe (res :~: res)
forall k (a :: k) (b :: k).
(Typeable a, Typeable b) =>
Maybe (a :~: b)
eqT @res @res1) ("unexpected result type of " String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
lName String -> String -> String
forall a. [a] -> [a] -> [a]
++ " lambda didn't match")
arg :~: arg
Refl <- Maybe (arg :~: arg) -> String -> Either String (arg :~: arg)
forall r l. Maybe r -> l -> Either l r
maybeToRight' ((Typeable arg, Typeable arg) => Maybe (arg :~: arg)
forall k (a :: k) (b :: k).
(Typeable a, Typeable b) =>
Maybe (a :~: b)
eqT @arg @arg1) ("unexpected argument type of " String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
lName String -> String -> String
forall a. [a] -> [a] -> [a]
++ " lambda didn't match")
extra :~: extra
Refl <- Maybe (extra :~: extra)
-> String -> Either String (extra :~: extra)
forall r l. Maybe r -> l -> Either l r
maybeToRight' ((Typeable extra, Typeable extra) => Maybe (extra :~: extra)
forall k (a :: k) (b :: k).
(Typeable a, Typeable b) =>
Maybe (a :~: b)
eqT @extra @extra1) ("unexpected storage type of " String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
lName String -> String -> String
forall a. [a] -> [a] -> [a]
++ " lambda didn't match")
SomeIndigoState someOut (RetVars res)
-> Either String (SomeIndigoState someOut (RetVars res))
forall (f :: * -> *) a. Applicative f => a -> f a
pure (SomeIndigoState someOut (RetVars res)
-> Either String (SomeIndigoState someOut (RetVars res)))
-> SomeIndigoState someOut (RetVars res)
-> Either String (SomeIndigoState someOut (RetVars res))
forall a b. (a -> b) -> a -> b
$ IndigoState
someOut
(RetOutStack' (ClassifyReturnValue res) res ++ someOut)
(RetVars res)
-> SomeIndigoState someOut (RetVars res)
forall (inp :: [*]) (out :: [*]) a.
IndigoState inp out a -> SomeIndigoState inp a
toSIS (LambdaExecutor extra arg res someOut
forall (inpt :: [*]). LambdaExecutor extra arg res inpt
executor IndigoObjectF
(NamedFieldVar
((arg : extra)
:-> (RetOutStack' (ClassifyReturnValue res) res ++ extra)))
((arg : extra)
:-> (RetOutStack' (ClassifyReturnValue res) res ++ extra))
Var (Lambda1Generic extra arg res)
varF Expr arg
argm)
compileIndigo
:: forall n inp a.
( SingI (ToPeano n), Default (MetaData inp)
, AreIndigoParams (ToPeano n) inp, KnownValue a
)
=> IndigoWithParams (ToPeano n) inp a
-> inp :-> inp
compileIndigo :: IndigoWithParams (ToPeano n) inp a -> inp :-> inp
compileIndigo paramCode :: IndigoWithParams (ToPeano n) inp a
paramCode =
SomeIndigoState inp a
-> MetaData inp
-> (forall (out :: [*]). GenCode inp out a -> inp :-> inp)
-> inp :-> inp
forall (inp :: [*]) a r.
SomeIndigoState inp a
-> MetaData inp
-> (forall (out :: [*]). GenCode inp out a -> r)
-> r
runSIS (IndigoM a -> SomeIndigoState inp a
forall (inp :: [*]) a. IndigoM a -> SomeIndigoState inp a
simpleCompileIndigoM IndigoM a
code) MetaData inp
md forall (out :: [*]). GenCode inp out a -> inp :-> inp
forall (inp :: [*]) (out :: [*]) a.
GenCode inp out a -> inp :-> inp
cleanGenCode
where
(code :: IndigoM a
code, md :: MetaData inp
md) = IndigoWithParams (ToPeano n) inp a
-> MetaData inp -> Sing (ToPeano n) -> (IndigoM a, MetaData inp)
forall (inp :: [*]) (n :: Nat) a.
(AreIndigoParams n inp, KnownValue a) =>
IndigoWithParams n inp a
-> MetaData inp -> Sing n -> (IndigoM a, MetaData inp)
fromIndigoWithParams @inp @_ @a IndigoWithParams (ToPeano n) inp a
paramCode MetaData inp
forall a. Default a => a
def (SingI (ToPeano n) => Sing (ToPeano n)
forall k (a :: k). SingI a => Sing a
sing @(ToPeano n))
type IndigoContract param st =
(HasStorage st, HasSideEffects) => Var param -> IndigoM ()
compileIndigoContract
:: forall param st .
( KnownValue param
, IsObject st
)
=> IndigoContract param st
-> ContractCode param st
compileIndigoContract :: IndigoContract param st -> ContractCode param st
compileIndigoContract code :: IndigoContract param st
code =
let (varOps :: Var Ops
varOps, opsMd :: MetaData '[Ops]
opsMd) = MetaData '[] -> (Var Ops, MetaData '[Ops])
forall x (stk :: [*]).
KnownValue x =>
MetaData stk -> (Var x, MetaData (x & stk))
pushRefMd MetaData '[]
emptyMetadata
mdSt :: MetaData (st & '[Ops])
mdSt = MetaData '[Ops] -> MetaData (st & '[Ops])
forall a (inp :: [*]).
KnownValue a =>
MetaData inp -> MetaData (a & inp)
pushNoRefMd MetaData '[Ops]
opsMd in
SomeIndigoState (st & '[Ops]) (Var st)
-> MetaData (st & '[Ops])
-> (forall (out :: [*]).
GenCode (st & '[Ops]) out (Var st) -> ContractCode param st)
-> ContractCode param st
forall (inp :: [*]) a r.
SomeIndigoState inp a
-> MetaData inp
-> (forall (out :: [*]). GenCode inp out a -> r)
-> r
runSIS (forall (inp :: [*]).
IsObject st =>
SomeIndigoState (st & inp) (Var st)
forall a (inp :: [*]).
IsObject a =>
SomeIndigoState (a & inp) (Var a)
deepDecomposeCompose @st) MetaData (st & '[Ops])
mdSt ((forall (out :: [*]).
GenCode (st & '[Ops]) out (Var st) -> ContractCode param st)
-> ContractCode param st)
-> (forall (out :: [*]).
GenCode (st & '[Ops]) out (Var st) -> ContractCode param st)
-> ContractCode param st
forall a b. (a -> b) -> a -> b
$ \(GenCode varSt :: Var st
varSt decomposedMd :: MetaData out
decomposedMd decomposeSt :: (st & '[Ops]) :-> out
decomposeSt composeSt :: out :-> (st & '[Ops])
composeSt) ->
let (varParam :: Var param
varParam, initMd :: MetaData (param & out)
initMd) = MetaData out -> (Var param, MetaData (param & out))
forall x (stk :: [*]).
KnownValue x =>
MetaData stk -> (Var x, MetaData (x & stk))
pushRefMd MetaData out
decomposedMd
everythingGiven :: IndigoM ()
everythingGiven = (Var Ops
-> (HasSideEffects => Var param -> IndigoM ())
-> Var param
-> IndigoM ()
forall a r. a -> (Given a => r) -> r
give @(Var Ops) Var Ops
varOps ((HasSideEffects => Var param -> IndigoM ())
-> Var param -> IndigoM ())
-> (HasSideEffects => Var param -> IndigoM ())
-> Var param
-> IndigoM ()
forall a b. (a -> b) -> a -> b
$ Var st
-> (Given (Var st) => Var param -> IndigoM ())
-> Var param
-> IndigoM ()
forall a r. a -> (Given a => r) -> r
give @(Var st) Var st
varSt IndigoContract param st
Given (Var st) => Var param -> IndigoM ()
code) Var param
varParam
indigoCode :: (param & out) :-> (param & out)
indigoCode = SomeIndigoState (param & out) ()
-> MetaData (param & out)
-> (forall (out :: [*]).
GenCode (param & out) out () -> (param & out) :-> (param & out))
-> (param & out) :-> (param & out)
forall (inp :: [*]) a r.
SomeIndigoState inp a
-> MetaData inp
-> (forall (out :: [*]). GenCode inp out a -> r)
-> r
runSIS (IndigoM () -> SomeIndigoState (param & out) ()
forall (inp :: [*]) a. IndigoM a -> SomeIndigoState inp a
simpleCompileIndigoM IndigoM ()
everythingGiven) MetaData (param & out)
initMd forall (out :: [*]).
GenCode (param & out) out () -> (param & out) :-> (param & out)
forall (inp :: [*]) (out :: [*]) a.
GenCode inp out a -> inp :-> inp
cleanGenCode in
((param, st) & '[]) :-> (Ops & ((param, st) & '[]))
forall p (s :: [*]). KnownValue p => s :-> (List p & s)
L.nil (((param, st) & '[]) :-> (Ops & ((param, st) & '[])))
-> ((Ops & ((param, st) & '[])) :-> ((param, st) & '[Ops]))
-> ((param, st) & '[]) :-> ((param, st) & '[Ops])
forall (a :: [*]) (b :: [*]) (c :: [*]).
(a :-> b) -> (b :-> c) -> a :-> c
# (Ops & ((param, st) & '[])) :-> ((param, st) & '[Ops])
forall a b (s :: [*]). (a & (b & s)) :-> (b & (a & s))
L.swap (((param, st) & '[]) :-> ((param, st) & '[Ops]))
-> (((param, st) & '[Ops]) :-> (param & (st & '[Ops])))
-> ((param, st) & '[]) :-> (param & (st & '[Ops]))
forall (a :: [*]) (b :: [*]) (c :: [*]).
(a :-> b) -> (b :-> c) -> a :-> c
# ((param, st) & '[Ops]) :-> (param & (st & '[Ops]))
forall a b (s :: [*]). ((a, b) & s) :-> (a & (b & s))
L.unpair (((param, st) & '[]) :-> (param & (st & '[Ops])))
-> ((param & (st & '[Ops])) :-> (param & out))
-> ((param, st) & '[]) :-> (param & out)
forall (a :: [*]) (b :: [*]) (c :: [*]).
(a :-> b) -> (b :-> c) -> a :-> c
#
((st & '[Ops]) :-> out)
-> (param & (st & '[Ops])) :-> (param & out)
forall a (s :: [*]) (s' :: [*]).
HasCallStack =>
(s :-> s') -> (a & s) :-> (a & s')
L.dip (st & '[Ops]) :-> out
decomposeSt (((param, st) & '[]) :-> (param & out))
-> ((param & out) :-> (param & out))
-> ((param, st) & '[]) :-> (param & out)
forall (a :: [*]) (b :: [*]) (c :: [*]).
(a :-> b) -> (b :-> c) -> a :-> c
#
(param & out) :-> (param & out)
indigoCode (((param, st) & '[]) :-> (param & out))
-> ((param & out) :-> out) -> ((param, st) & '[]) :-> out
forall (a :: [*]) (b :: [*]) (c :: [*]).
(a :-> b) -> (b :-> c) -> a :-> c
#
(param & out) :-> out
forall a (s :: [*]). (a & s) :-> s
L.drop (((param, st) & '[]) :-> out)
-> (out :-> (st & '[Ops])) -> ((param, st) & '[]) :-> (st & '[Ops])
forall (a :: [*]) (b :: [*]) (c :: [*]).
(a :-> b) -> (b :-> c) -> a :-> c
#
out :-> (st & '[Ops])
composeSt (((param, st) & '[]) :-> (st & '[Ops]))
-> ((st & '[Ops]) :-> (Ops & (st & '[])))
-> ((param, st) & '[]) :-> (Ops & (st & '[]))
forall (a :: [*]) (b :: [*]) (c :: [*]).
(a :-> b) -> (b :-> c) -> a :-> c
#
(st & '[Ops]) :-> (Ops & (st & '[]))
forall a b (s :: [*]). (a & (b & s)) :-> (b & (a & s))
L.swap (((param, st) & '[]) :-> (Ops & (st & '[])))
-> ((Ops & (st & '[])) :-> ((Ops, st) & '[]))
-> ContractCode param st
forall (a :: [*]) (b :: [*]) (c :: [*]).
(a :-> b) -> (b :-> c) -> a :-> c
# (Ops & (st & '[])) :-> ((Ops, st) & '[])
forall a b (s :: [*]). (a & (b & s)) :-> ((a, b) & s)
L.pair