module Lorentz.Run
( Contract(..)
, toMichelsonContract
, defaultContract
, CompilationOptions(..)
, defaultCompilationOptions
, intactCompilationOptions
, coBytesTransformerL
, coOptimizerConfL
, coStringTransformerL
, compileLorentz
, compileLorentzWithOptions
, mkContract
, mkContractWith
, ContractData(..)
, ContractView(..)
, defaultContractData
, compileLorentzContract
, mkView
, setViews
, setViewsRec
, noViews
, cdCodeL
, coDisableInitialCastL
, cdCompilationOptionsL
, interpretLorentzInstr
, interpretLorentzLambda
, analyzeLorentz
) where
import Control.Lens.Type as Lens (Lens, Lens')
import Data.Constraint ((\\))
import Data.Default (def)
import Data.Vinyl.Core (Rec(..))
import Data.Vinyl.Functor qualified as Rec
import Data.Vinyl.Recursive qualified as Rec
import Fmt ((+|), (|+))
import Lorentz.Annotation
import Lorentz.Base
import Lorentz.Coercions
import Lorentz.Constraints
import Lorentz.Doc
import Lorentz.Entrypoints
import Lorentz.Entrypoints.Doc
import Lorentz.ViewBase
import Morley.Michelson.Analyzer (AnalyzerRes, analyze)
import Morley.Michelson.Interpret
import Morley.Michelson.Optimizer (OptimizerConf, optimizeWithConf)
import Morley.Michelson.Text (MText)
import Morley.Michelson.TypeCheck (typeCheckingWith, typeVerifyContract, typeVerifyView)
import Morley.Michelson.Typed
(Instr(..), IsoValue, IsoValuesStack(..), ToT, ToTs, convertContract, convertView, starParamNotes)
import Morley.Michelson.Typed qualified as M
import Morley.Michelson.Untyped qualified as U (canonicalEntriesOrder)
import Morley.Util.Lens
import Morley.Util.TypeLits
import Morley.Util.TypeTuple
data CompilationOptions = CompilationOptions
{ CompilationOptions -> Maybe OptimizerConf
coOptimizerConf :: Maybe OptimizerConf
, CompilationOptions -> (Bool, MText -> MText)
coStringTransformer :: (Bool, MText -> MText)
, CompilationOptions -> (Bool, ByteString -> ByteString)
coBytesTransformer :: (Bool, ByteString -> ByteString)
, CompilationOptions -> Bool
coDisableInitialCast :: Bool
}
defaultCompilationOptions :: CompilationOptions
defaultCompilationOptions :: CompilationOptions
defaultCompilationOptions = CompilationOptions :: Maybe OptimizerConf
-> (Bool, MText -> MText)
-> (Bool, ByteString -> ByteString)
-> Bool
-> CompilationOptions
CompilationOptions
{ coOptimizerConf :: Maybe OptimizerConf
coOptimizerConf = OptimizerConf -> Maybe OptimizerConf
forall a. a -> Maybe a
Just OptimizerConf
forall a. Default a => a
def
, coStringTransformer :: (Bool, MText -> MText)
coStringTransformer = (Bool
False, MText -> MText
forall a. a -> a
id)
, coBytesTransformer :: (Bool, ByteString -> ByteString)
coBytesTransformer = (Bool
False, ByteString -> ByteString
forall a. a -> a
id)
, coDisableInitialCast :: Bool
coDisableInitialCast = Bool
False
}
intactCompilationOptions :: CompilationOptions
intactCompilationOptions :: CompilationOptions
intactCompilationOptions = CompilationOptions :: Maybe OptimizerConf
-> (Bool, MText -> MText)
-> (Bool, ByteString -> ByteString)
-> Bool
-> CompilationOptions
CompilationOptions
{ coOptimizerConf :: Maybe OptimizerConf
coOptimizerConf = Maybe OptimizerConf
forall a. Maybe a
Nothing
, coStringTransformer :: (Bool, MText -> MText)
coStringTransformer = (Bool
False, MText -> MText
forall a. a -> a
id)
, coBytesTransformer :: (Bool, ByteString -> ByteString)
coBytesTransformer = (Bool
False, ByteString -> ByteString
forall a. a -> a
id)
, coDisableInitialCast :: Bool
coDisableInitialCast = Bool
False
}
compileLorentz :: (inp :-> out) -> Instr (ToTs inp) (ToTs out)
compileLorentz :: (inp :-> out) -> Instr (ToTs inp) (ToTs out)
compileLorentz = CompilationOptions -> (inp :-> out) -> Instr (ToTs inp) (ToTs out)
forall (inp :: [*]) (out :: [*]).
CompilationOptions -> (inp :-> out) -> Instr (ToTs inp) (ToTs out)
compileLorentzWithOptions CompilationOptions
defaultCompilationOptions
compileLorentzWithOptions :: CompilationOptions -> (inp :-> out) -> Instr (ToTs inp) (ToTs out)
compileLorentzWithOptions :: CompilationOptions -> (inp :-> out) -> Instr (ToTs inp) (ToTs out)
compileLorentzWithOptions CompilationOptions{Bool
Maybe OptimizerConf
(Bool, ByteString -> ByteString)
(Bool, MText -> MText)
coDisableInitialCast :: Bool
coBytesTransformer :: (Bool, ByteString -> ByteString)
coStringTransformer :: (Bool, MText -> MText)
coOptimizerConf :: Maybe OptimizerConf
coDisableInitialCast :: CompilationOptions -> Bool
coBytesTransformer :: CompilationOptions -> (Bool, ByteString -> ByteString)
coStringTransformer :: CompilationOptions -> (Bool, MText -> MText)
coOptimizerConf :: CompilationOptions -> Maybe OptimizerConf
..} =
(Instr (ToTs inp) (ToTs out) -> Instr (ToTs inp) (ToTs out))
-> (OptimizerConf
-> Instr (ToTs inp) (ToTs out) -> Instr (ToTs inp) (ToTs out))
-> Maybe OptimizerConf
-> Instr (ToTs inp) (ToTs out)
-> Instr (ToTs inp) (ToTs out)
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Instr (ToTs inp) (ToTs out) -> Instr (ToTs inp) (ToTs out)
forall a. a -> a
id OptimizerConf
-> Instr (ToTs inp) (ToTs out) -> Instr (ToTs inp) (ToTs out)
forall (inp :: [T]) (out :: [T]).
OptimizerConf -> Instr inp out -> Instr inp out
optimizeWithConf Maybe OptimizerConf
coOptimizerConf
(Instr (ToTs inp) (ToTs out) -> Instr (ToTs inp) (ToTs out))
-> ((inp :-> out) -> Instr (ToTs inp) (ToTs out))
-> (inp :-> out)
-> Instr (ToTs inp) (ToTs out)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (inp :-> out) -> Instr (ToTs inp) (ToTs out)
forall (inp :: [*]) (out :: [*]).
(inp :-> out) -> Instr (ToTs inp) (ToTs out)
iAnyCode
((inp :-> out) -> Instr (ToTs inp) (ToTs out))
-> ((inp :-> out) -> inp :-> out)
-> (inp :-> out)
-> Instr (ToTs inp) (ToTs out)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Bool -> (MText -> MText) -> (inp :-> out) -> inp :-> out)
-> (Bool, MText -> MText) -> (inp :-> out) -> inp :-> out
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry Bool -> (MText -> MText) -> (inp :-> out) -> inp :-> out
forall (inp :: [*]) (out :: [*]).
Bool -> (MText -> MText) -> (inp :-> out) -> inp :-> out
transformStringsLorentz (Bool, MText -> MText)
coStringTransformer
((inp :-> out) -> inp :-> out)
-> ((inp :-> out) -> inp :-> out) -> (inp :-> out) -> inp :-> out
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Bool
-> (ByteString -> ByteString) -> (inp :-> out) -> inp :-> out)
-> (Bool, ByteString -> ByteString) -> (inp :-> out) -> inp :-> out
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry Bool -> (ByteString -> ByteString) -> (inp :-> out) -> inp :-> out
forall (inp :: [*]) (out :: [*]).
Bool -> (ByteString -> ByteString) -> (inp :-> out) -> inp :-> out
transformBytesLorentz (Bool, ByteString -> ByteString)
coBytesTransformer
defaultContract
:: (NiceParameterFull cp, NiceStorageFull st)
=> ContractCode cp st -> Contract cp st ()
defaultContract :: ContractCode cp st -> Contract cp st ()
defaultContract ContractCode cp st
code =
ContractData cp st () -> Contract cp st ()
forall cp st vd. ContractData cp st vd -> Contract cp st vd
compileLorentzContract (ContractData cp st () -> Contract cp st ())
-> ContractData cp st () -> Contract cp st ()
forall a b. (a -> b) -> a -> b
$ ContractCode cp st
-> Rec (ContractView st) (RevealViews ())
-> CompilationOptions
-> ContractData cp st ()
forall cp st vd.
(NiceParameterFull cp, NiceStorageFull st,
NiceViewsDescriptor vd) =>
ContractCode cp st
-> Rec (ContractView st) (RevealViews vd)
-> CompilationOptions
-> ContractData cp st vd
ContractData ContractCode cp st
code Rec (ContractView st) (RevealViews ())
forall a. Monoid a => a
mempty CompilationOptions
defaultCompilationOptions
mkContract
:: (NiceParameterFull cp, NiceStorageFull st)
=> ContractCode cp st -> Contract cp st ()
mkContract :: ContractCode cp st -> Contract cp st ()
mkContract = CompilationOptions -> ContractCode cp st -> Contract cp st ()
forall cp st.
(NiceParameterFull cp, NiceStorageFull st) =>
CompilationOptions -> ContractCode cp st -> Contract cp st ()
mkContractWith CompilationOptions
defaultCompilationOptions
mkContractWith
:: (NiceParameterFull cp, NiceStorageFull st)
=> CompilationOptions -> ContractCode cp st -> Contract cp st ()
mkContractWith :: CompilationOptions -> ContractCode cp st -> Contract cp st ()
mkContractWith CompilationOptions
opts ContractCode cp st
code =
ContractData cp st () -> Contract cp st ()
forall cp st vd. ContractData cp st vd -> Contract cp st vd
compileLorentzContract (ContractData cp st () -> Contract cp st ())
-> ContractData cp st () -> Contract cp st ()
forall a b. (a -> b) -> a -> b
$ ContractCode cp st
-> Rec (ContractView st) (RevealViews ())
-> CompilationOptions
-> ContractData cp st ()
forall cp st vd.
(NiceParameterFull cp, NiceStorageFull st,
NiceViewsDescriptor vd) =>
ContractCode cp st
-> Rec (ContractView st) (RevealViews vd)
-> CompilationOptions
-> ContractData cp st vd
ContractData ContractCode cp st
code Rec (ContractView st) (RevealViews ())
forall a. Monoid a => a
mempty CompilationOptions
opts
data ContractData cp st vd =
(NiceParameterFull cp, NiceStorageFull st, NiceViewsDescriptor vd) =>
ContractData
{ ContractData cp st vd -> ContractCode cp st
cdCode :: ContractCode cp st
, ContractData cp st vd -> Rec (ContractView st) (RevealViews vd)
cdViews :: Rec (ContractView st) (RevealViews vd)
, ContractData cp st vd -> CompilationOptions
cdCompilationOptions :: CompilationOptions
}
data ContractView st (v :: ViewTyInfo) where
ContractView
:: ( KnownSymbol name, NiceViewable arg, NiceViewable ret
, HasAnnotation arg, HasAnnotation ret
)
=> ViewCode arg st ret
-> ContractView st ('ViewTyInfo name arg ret)
mkView
:: forall name arg ret st.
( KnownSymbol name, NiceViewable arg, NiceViewable ret
, HasAnnotation arg, HasAnnotation ret
, TypeHasDoc arg, TypeHasDoc ret
)
=> ViewCode arg st ret
-> ContractView st ('ViewTyInfo name arg ret)
mkView :: ViewCode arg st ret -> ContractView st ('ViewTyInfo name arg ret)
mkView ViewCode arg st ret
code = ViewCode arg st ret -> ContractView st ('ViewTyInfo name arg ret)
forall (name :: Symbol) arg ret st.
(KnownSymbol name, NiceViewable arg, NiceViewable ret,
HasAnnotation arg, HasAnnotation ret) =>
ViewCode arg st ret -> ContractView st ('ViewTyInfo name arg ret)
ContractView (ViewCode arg st ret -> ContractView st ('ViewTyInfo name arg ret))
-> ViewCode arg st ret
-> ContractView st ('ViewTyInfo name arg ret)
forall a b. (a -> b) -> a -> b
$
(SubDoc -> DView) -> ViewCode arg st ret -> ViewCode arg st ret
forall di (inp :: [*]) (out :: [*]).
DocItem di =>
(SubDoc -> di) -> (inp :-> out) -> inp :-> out
docGroup (ViewName -> SubDoc -> DView
DView ((KnownSymbol name, HasCallStack) => ViewName
forall (name :: Symbol).
(KnownSymbol name, HasCallStack) =>
ViewName
demoteViewName @name)) (ViewCode arg st ret -> ViewCode arg st ret)
-> ViewCode arg st ret -> ViewCode arg st ret
forall a b. (a -> b) -> a -> b
$
DViewArg -> '[(arg, st)] :-> '[(arg, st)]
forall di (s :: [*]). DocItem di => di -> s :-> s
doc (Proxy arg -> DViewArg
forall a. (NiceViewable a, TypeHasDoc a) => Proxy a -> DViewArg
DViewArg (Proxy arg
forall k (t :: k). Proxy t
Proxy @arg)) ('[(arg, st)] :-> '[(arg, st)])
-> ('[(arg, st)] :-> '[(arg, st)]) -> '[(arg, st)] :-> '[(arg, st)]
forall (a :: [*]) (b :: [*]) (c :: [*]).
(a :-> b) -> (b :-> c) -> a :-> c
#
DViewRet -> '[(arg, st)] :-> '[(arg, st)]
forall di (s :: [*]). DocItem di => di -> s :-> s
doc (Proxy ret -> DViewRet
forall a. (NiceViewable a, TypeHasDoc a) => Proxy a -> DViewRet
DViewRet (Proxy ret
forall k (t :: k). Proxy t
Proxy @ret)) ('[(arg, st)] :-> '[(arg, st)])
-> ViewCode arg st ret -> ViewCode arg st ret
forall (a :: [*]) (b :: [*]) (c :: [*]).
(a :-> b) -> (b :-> c) -> a :-> c
#
ViewCode arg st ret
code
defaultContractData
:: forall cp st. (NiceParameterFull cp, NiceStorageFull st)
=> ContractCode cp st -> ContractData cp st ()
defaultContractData :: ContractCode cp st -> ContractData cp st ()
defaultContractData ContractCode cp st
code = ContractData :: forall cp st vd.
(NiceParameterFull cp, NiceStorageFull st,
NiceViewsDescriptor vd) =>
ContractCode cp st
-> Rec (ContractView st) (RevealViews vd)
-> CompilationOptions
-> ContractData cp st vd
ContractData
{ cdCode :: ContractCode cp st
cdCode = ContractCode cp st
code
, cdViews :: Rec (ContractView st) (RevealViews ())
cdViews = Rec (ContractView st) (RevealViews ())
forall u (a :: u -> *). Rec a '[]
RNil
, cdCompilationOptions :: CompilationOptions
cdCompilationOptions = CompilationOptions
defaultCompilationOptions
}
compileLorentzContract
:: forall cp st vd. ContractData cp st vd -> Contract cp st vd
compileLorentzContract :: ContractData cp st vd -> Contract cp st vd
compileLorentzContract ContractData{Rec (ContractView st) (RevealViews vd)
ContractCode cp st
CompilationOptions
cdCompilationOptions :: CompilationOptions
cdViews :: Rec (ContractView st) (RevealViews vd)
cdCode :: ContractCode cp st
cdCompilationOptions :: forall cp st vd. ContractData cp st vd -> CompilationOptions
cdViews :: forall cp st vd.
ContractData cp st vd -> Rec (ContractView st) (RevealViews vd)
cdCode :: forall cp st vd. ContractData cp st vd -> ContractCode cp st
..} = Contract :: forall cp st vd.
(NiceParameter cp, NiceStorage st, NiceViewsDescriptor vd) =>
Contract (ToT cp) (ToT st)
-> ContractCode cp st -> Contract cp st vd
Contract{Contract (ToT cp) (ToT st)
ContractCode cp st
cDocumentedCode :: ContractCode cp st
cMichelsonContract :: Contract (ToT cp) (ToT st)
cDocumentedCode :: ContractCode cp st
cMichelsonContract :: Contract (ToT cp) (ToT st)
..}
where
verify :: TypeCheckResult (Contract (ToT cp) (ToT st))
verify = Contract -> TypeCheckResult (Contract (ToT cp) (ToT st))
forall (cp :: T) (st :: T).
(SingI cp, SingI st) =>
Contract -> TypeCheckResult (Contract cp st)
typeVerifyContract @(ToT cp) @(ToT st) (Contract (ToT cp) (ToT st) -> Contract
forall (param :: T) (store :: T). Contract param store -> Contract
convertContract Contract (ToT cp) (ToT st)
cMichelsonContractRaw)
cMichelsonContract :: Contract (ToT cp) (ToT st)
cMichelsonContract
| ParamNotes (ToT cp)
cpNotes ParamNotes (ToT cp) -> ParamNotes (ToT cp) -> Bool
forall a. Eq a => a -> a -> Bool
== ParamNotes (ToT cp)
forall (t :: T). SingI t => ParamNotes t
starParamNotes Bool -> Bool -> Bool
forall a. Boolean a => a -> a -> a
|| CompilationOptions -> Bool
coDisableInitialCast CompilationOptions
cdCompilationOptions
= Contract (ToT cp) (ToT st)
cMichelsonContractRaw
| Right{} <- TypeCheckOptions
-> TypeCheckResult (Contract (ToT cp) (ToT st))
-> Either TCError (Contract (ToT cp) (ToT st))
forall a. TypeCheckOptions -> TypeCheckResult a -> Either TCError a
typeCheckingWith TypeCheckOptions
forall a. Default a => a
def TypeCheckResult (Contract (ToT cp) (ToT st))
verify = Contract (ToT cp) (ToT st)
cMichelsonContractRaw
| Bool
otherwise
= Contract (ToT cp) (ToT st)
cMichelsonContractRaw
{ cCode :: ContractCode' Instr (ToT cp) (ToT st)
M.cCode = CompilationOptions
-> ContractCode cp st
-> Instr (ToTs '[(cp, st)]) (ToTs (ContractOut st))
forall (inp :: [*]) (out :: [*]).
CompilationOptions -> (inp :-> out) -> Instr (ToTs inp) (ToTs out)
compileLorentzWithOptions
CompilationOptions
cdCompilationOptions (Instr (ToTs '[(cp, st)]) (ToTs '[(cp, st)])
-> '[(cp, st)] :-> '[(cp, st)]
forall (inp :: [*]) (out :: [*]).
Instr (ToTs inp) (ToTs out) -> inp :-> out
I Instr (ToTs '[(cp, st)]) (ToTs '[(cp, st)])
forall (a :: T) (s :: [T]). SingI a => Instr (a : s) (a : s)
CAST ('[(cp, st)] :-> '[(cp, st)])
-> ContractCode cp st -> ContractCode cp st
forall (a :: [*]) (b :: [*]) (c :: [*]).
(a :-> b) -> (b :-> c) -> a :-> c
# ContractCode cp st
cdCode :: ContractCode cp st) }
cMichelsonContractRaw :: Contract (ToT cp) (ToT st)
cMichelsonContractRaw = Contract :: forall (instr :: [T] -> [T] -> *) (cp :: T) (st :: T).
(ParameterScope cp, StorageScope st) =>
ContractCode' instr cp st
-> ParamNotes cp
-> Notes st
-> ViewsSet' instr st
-> EntriesOrder
-> Contract' instr cp st
M.Contract
{ cCode :: ContractCode' Instr (ToT cp) (ToT st)
cCode = CompilationOptions
-> ContractCode cp st
-> Instr (ToTs '[(cp, st)]) (ToTs (ContractOut st))
forall (inp :: [*]) (out :: [*]).
CompilationOptions -> (inp :-> out) -> Instr (ToTs inp) (ToTs out)
compileLorentzWithOptions CompilationOptions
cdCompilationOptions ContractCode cp st
cdCode
, cParamNotes :: ParamNotes (ToT cp)
cParamNotes = ParamNotes (ToT cp)
cpNotes
, cStoreNotes :: Notes (ToT st)
cStoreNotes = FollowEntrypointFlag -> Notes (ToT st)
forall a. HasAnnotation a => FollowEntrypointFlag -> Notes (ToT a)
getAnnotation @st FollowEntrypointFlag
NotFollowEntrypoint
, cEntriesOrder :: EntriesOrder
cEntriesOrder = EntriesOrder
U.canonicalEntriesOrder
, cViews :: ViewsSet' Instr (ToT st)
cViews = CompilationOptions
-> Rec (ContractView st) (RevealViews vd)
-> ViewsSet' Instr (ToT st)
forall (vs :: [ViewTyInfo]) st.
(HasCallStack, KnownValue st) =>
CompilationOptions -> Rec (ContractView st) vs -> ViewsSet (ToT st)
compileLorentzViews CompilationOptions
cdCompilationOptions Rec (ContractView st) (RevealViews vd)
cdViews
} (ParameterScope (ToT cp) => Contract (ToT cp) (ToT st))
-> (((SingI (ToT cp), WellTyped (ToT cp),
FailOnOperationFound (ContainsOp (ToT cp)),
FailOnNestedBigMapsFound (ContainsNestedBigMaps (ToT cp))),
KnownValue cp)
:- ParameterScope (ToT cp))
-> Contract (ToT cp) (ToT st)
forall (c :: Constraint) e r. HasDict c e => (c => r) -> e -> r
\\ ((SingI (ToT cp), WellTyped (ToT cp),
FailOnOperationFound (ContainsOp (ToT cp)),
FailOnNestedBigMapsFound (ContainsNestedBigMaps (ToT cp))),
KnownValue cp)
:- ParameterScope (ToT cp)
forall a. NiceParameter a :- ParameterScope (ToT a)
niceParameterEvi @cp
(StorageScope (ToT st) => Contract (ToT cp) (ToT st))
-> (((SingI (ToT st), WellTyped (ToT st),
FailOnOperationFound (ContainsOp (ToT st)),
FailOnNestedBigMapsFound (ContainsNestedBigMaps (ToT st)),
FailOnContractFound (ContainsContract (ToT st))),
KnownValue st)
:- StorageScope (ToT st))
-> Contract (ToT cp) (ToT st)
forall (c :: Constraint) e r. HasDict c e => (c => r) -> e -> r
\\ ((SingI (ToT st), WellTyped (ToT st),
FailOnOperationFound (ContainsOp (ToT st)),
FailOnNestedBigMapsFound (ContainsNestedBigMaps (ToT st)),
FailOnContractFound (ContainsContract (ToT st))),
KnownValue st)
:- StorageScope (ToT st)
forall a. NiceStorage a :- StorageScope (ToT a)
niceStorageEvi @st
cDocumentedCode :: ContractCode cp st
cDocumentedCode =
Proxy cp -> ContractCode cp st -> ContractCode cp st
forall cp (inp :: [*]) (out :: [*]).
(NiceParameterFull cp, HasCallStack) =>
Proxy cp -> (inp :-> out) -> inp :-> out
finalizeParamCallingDoc' (Proxy cp
forall k (t :: k). Proxy t
Proxy @cp) ContractCode cp st
cdCode ContractCode cp st
-> (ContractOut st :-> ContractOut st) -> ContractCode cp st
forall (a :: [*]) (b :: [*]) (c :: [*]).
(a :-> b) -> (b :-> c) -> a :-> c
#
(Element [ContractOut st :-> ContractOut st]
-> (ContractOut st :-> ContractOut st)
-> ContractOut st :-> ContractOut st)
-> (ContractOut st :-> ContractOut st)
-> [ContractOut st :-> ContractOut st]
-> ContractOut st :-> ContractOut st
forall t b. Container t => (Element t -> b -> b) -> b -> t -> b
foldr Element [ContractOut st :-> ContractOut st]
-> (ContractOut st :-> ContractOut st)
-> ContractOut st :-> ContractOut st
forall (a :: [*]) (b :: [*]) (c :: [*]).
(a :-> b) -> (b :-> c) -> a :-> c
(#) (Instr (ToTs (ContractOut st)) (ToTs (ContractOut st))
-> ContractOut st :-> ContractOut st
forall (inp :: [*]) (out :: [*]).
Instr (ToTs inp) (ToTs out) -> inp :-> out
I Instr (ToTs (ContractOut st)) (ToTs (ContractOut st))
forall (inp :: [T]). Instr inp inp
Nop)
( Rec (Const (ContractOut st :-> ContractOut st)) (RevealViews vd)
-> [ContractOut st :-> ContractOut st]
forall u a (rs :: [u]). Rec (Const a) rs -> [a]
Rec.recordToList (Rec (Const (ContractOut st :-> ContractOut st)) (RevealViews vd)
-> [ContractOut st :-> ContractOut st])
-> Rec (Const (ContractOut st :-> ContractOut st)) (RevealViews vd)
-> [ContractOut st :-> ContractOut st]
forall a b. (a -> b) -> a -> b
$
(forall (x :: ViewTyInfo).
ContractView st x -> Const (ContractOut st :-> ContractOut st) x)
-> Rec (ContractView st) (RevealViews vd)
-> Rec (Const (ContractOut st :-> ContractOut st)) (RevealViews vd)
forall u (f :: u -> *) (g :: u -> *) (rs :: [u]).
(forall (x :: u). f x -> g x) -> Rec f rs -> Rec g rs
Rec.rmap (\(ContractView code) -> (ContractOut st :-> ContractOut st)
-> Const (ContractOut st :-> ContractOut st) x
forall k a (b :: k). a -> Const a b
Rec.Const ((ContractOut st :-> ContractOut st)
-> Const (ContractOut st :-> ContractOut st) x)
-> (ContractOut st :-> ContractOut st)
-> Const (ContractOut st :-> ContractOut st) x
forall a b. (a -> b) -> a -> b
$ ('[(arg, st)] :-> '[ret]) -> ContractOut st :-> ContractOut st
forall (s1 :: [*]) (s2 :: [*]) (s1' :: [*]) (s2' :: [*]).
(s1 :-> s2) -> s1' :-> s2'
fakeCoercing '[(arg, st)] :-> '[ret]
code) Rec (ContractView st) (RevealViews vd)
cdViews
)
cpNotes :: ParamNotes (ToT cp)
cpNotes = ParameterDeclaresEntrypoints cp => ParamNotes (ToT cp)
forall cp. ParameterDeclaresEntrypoints cp => ParamNotes (ToT cp)
parameterEntrypointsToNotes @cp
compileLorentzViews
:: forall vs st.
( HasCallStack
, KnownValue st
)
=> CompilationOptions
-> Rec (ContractView st) vs
-> M.ViewsSet (M.ToT st)
compileLorentzViews :: CompilationOptions -> Rec (ContractView st) vs -> ViewsSet (ToT st)
compileLorentzViews CompilationOptions
co Rec (ContractView st) vs
views =
let
viewsList :: [SomeView' Instr (ToT st)]
viewsList =
Rec (Const (SomeView' Instr (ToT st))) vs
-> [SomeView' Instr (ToT st)]
forall u a (rs :: [u]). Rec (Const a) rs -> [a]
Rec.recordToList (Rec (Const (SomeView' Instr (ToT st))) vs
-> [SomeView' Instr (ToT st)])
-> Rec (Const (SomeView' Instr (ToT st))) vs
-> [SomeView' Instr (ToT st)]
forall a b. (a -> b) -> a -> b
$
(forall (x :: ViewTyInfo).
ContractView st x -> Const (SomeView' Instr (ToT st)) x)
-> Rec (ContractView st) vs
-> Rec (Const (SomeView' Instr (ToT st))) vs
forall u (f :: u -> *) (g :: u -> *) (rs :: [u]).
(forall (x :: u). f x -> g x) -> Rec f rs -> Rec g rs
Rec.rmap (\ContractView st x
v -> SomeView' Instr (ToT st) -> Const (SomeView' Instr (ToT st)) x
forall k a (b :: k). a -> Const a b
Rec.Const (SomeView' Instr (ToT st) -> Const (SomeView' Instr (ToT st)) x)
-> SomeView' Instr (ToT st) -> Const (SomeView' Instr (ToT st)) x
forall a b. (a -> b) -> a -> b
$ CompilationOptions -> ContractView st x -> SomeView' Instr (ToT st)
forall st (vt :: ViewTyInfo).
KnownValue st =>
CompilationOptions -> ContractView st vt -> SomeView (ToT st)
compileLorentzView CompilationOptions
co ContractView st x
v) Rec (ContractView st) vs
views
in case [SomeView' Instr (ToT st)]
-> Either ViewsSetError (ViewsSet (ToT st))
forall (instr :: [T] -> [T] -> *) (st :: T).
[SomeView' instr st] -> Either ViewsSetError (ViewsSet' instr st)
M.mkViewsSet [SomeView' Instr (ToT st)]
viewsList of
Right ViewsSet (ToT st)
viewsSet -> ViewsSet (ToT st)
viewsSet
Left e :: ViewsSetError
e@M.DuplicatedViewName{} ->
Text -> ViewsSet (ToT st)
forall a. HasCallStack => Text -> a
error (Text -> ViewsSet (ToT st)) -> Text -> ViewsSet (ToT st)
forall a b. (a -> b) -> a -> b
$ Builder
"An impossble happened: " Builder -> Builder -> Text
forall b. FromBuilder b => Builder -> Builder -> b
+| ViewsSetError
e ViewsSetError -> Builder -> Builder
forall a b. (Buildable a, FromBuilder b) => a -> Builder -> b
|+ Builder
""
compileLorentzView
:: forall st vt.
(KnownValue st)
=> CompilationOptions
-> ContractView st vt
-> M.SomeView (M.ToT st)
compileLorentzView :: CompilationOptions -> ContractView st vt -> SomeView (ToT st)
compileLorentzView CompilationOptions
co (ContractView ViewCode arg st ret
viewCode)
| (_ :: Proxy ('ViewTyInfo name arg ret)) <- Proxy vt
forall k (t :: k). Proxy t
Proxy @vt =
let argNotes :: Notes (ToT arg)
argNotes = FollowEntrypointFlag -> Notes (ToT arg)
forall a. HasAnnotation a => FollowEntrypointFlag -> Notes (ToT a)
getAnnotation @arg FollowEntrypointFlag
NotFollowEntrypoint
retNotes :: Notes (ToT ret)
retNotes = FollowEntrypointFlag -> Notes (ToT ret)
forall a. HasAnnotation a => FollowEntrypointFlag -> Notes (ToT a)
getAnnotation @ret FollowEntrypointFlag
NotFollowEntrypoint
stNotes :: Notes (ToT ret)
stNotes = FollowEntrypointFlag -> Notes (ToT ret)
forall a. HasAnnotation a => FollowEntrypointFlag -> Notes (ToT a)
getAnnotation @ret FollowEntrypointFlag
NotFollowEntrypoint
verify :: TypeCheckResult (View (ToT arg) (ToT ret) (ToT st))
verify = Notes (ToT ret)
-> View -> TypeCheckResult (View (ToT arg) (ToT ret) (ToT st))
forall (arg :: T) (ret :: T) (st :: T).
(SingI arg, SingI ret, WellTyped st) =>
Notes st -> View -> TypeCheckResult (View arg st ret)
typeVerifyView @(ToT arg) @(ToT st) @(ToT ret) Notes (ToT ret)
stNotes (View (ToT arg) (ToT st) (ToT ret) -> View
forall (arg :: T) (store :: T) (ret :: T).
View arg store ret -> View
convertView View (ToT arg) (ToT st) (ToT ret)
viewRaw)
viewRaw, viewWithNecessaryCast :: M.View (ToT arg) (ToT st) (ToT ret)
viewRaw :: View (ToT arg) (ToT st) (ToT ret)
viewRaw = View :: forall (instr :: [T] -> [T] -> *) (arg :: T) (st :: T) (ret :: T).
(ViewableScope arg, SingI st, ViewableScope ret) =>
ViewName
-> Notes arg
-> Notes ret
-> ViewCode' instr arg st ret
-> View' instr arg st ret
M.View
{ vName :: ViewName
M.vName = (KnownSymbol name, HasCallStack) => ViewName
forall (name :: Symbol).
(KnownSymbol name, HasCallStack) =>
ViewName
demoteViewName @name
, vArgument :: Notes (ToT arg)
M.vArgument = Notes (ToT arg)
argNotes
, vReturn :: Notes (ToT ret)
M.vReturn = Notes (ToT ret)
retNotes
, vCode :: ViewCode' Instr (ToT arg) (ToT st) (ToT ret)
M.vCode = CompilationOptions
-> ViewCode arg st ret -> Instr (ToTs '[(arg, st)]) (ToTs '[ret])
forall (inp :: [*]) (out :: [*]).
CompilationOptions -> (inp :-> out) -> Instr (ToTs inp) (ToTs out)
compileLorentzWithOptions CompilationOptions
co ViewCode arg st ret
viewCode
}
(ViewableScope (ToT arg) => View (ToT arg) (ToT st) (ToT ret))
-> (((SingI (ToT arg), FailOnOperationFound (ContainsOp (ToT arg)),
FailOnBigMapFound (ContainsBigMap (ToT arg)),
FailOnTicketFound (ContainsTicket (ToT arg))),
KnownValue arg)
:- ViewableScope (ToT arg))
-> View (ToT arg) (ToT st) (ToT ret)
forall (c :: Constraint) e r. HasDict c e => (c => r) -> e -> r
\\ ((SingI (ToT arg), FailOnOperationFound (ContainsOp (ToT arg)),
FailOnBigMapFound (ContainsBigMap (ToT arg)),
FailOnTicketFound (ContainsTicket (ToT arg))),
KnownValue arg)
:- ViewableScope (ToT arg)
forall a. NiceViewable a :- ViewableScope (ToT a)
niceViewableEvi @arg
(ViewableScope (ToT ret) => View (ToT arg) (ToT st) (ToT ret))
-> (((SingI (ToT ret), FailOnOperationFound (ContainsOp (ToT ret)),
FailOnBigMapFound (ContainsBigMap (ToT ret)),
FailOnTicketFound (ContainsTicket (ToT ret))),
KnownValue ret)
:- ViewableScope (ToT ret))
-> View (ToT arg) (ToT st) (ToT ret)
forall (c :: Constraint) e r. HasDict c e => (c => r) -> e -> r
\\ ((SingI (ToT ret), FailOnOperationFound (ContainsOp (ToT ret)),
FailOnBigMapFound (ContainsBigMap (ToT ret)),
FailOnTicketFound (ContainsTicket (ToT ret))),
KnownValue ret)
:- ViewableScope (ToT ret)
forall a. NiceViewable a :- ViewableScope (ToT a)
niceViewableEvi @ret
viewWithNecessaryCast :: View (ToT arg) (ToT st) (ToT ret)
viewWithNecessaryCast
| Notes (ToT arg)
argNotes Notes (ToT arg) -> Notes (ToT arg) -> Bool
forall a. Eq a => a -> a -> Bool
== Notes (ToT arg)
forall (t :: T). SingI t => Notes t
M.starNotes Bool -> Bool -> Bool
forall a. Boolean a => a -> a -> a
|| CompilationOptions -> Bool
coDisableInitialCast CompilationOptions
co = View (ToT arg) (ToT st) (ToT ret)
viewRaw
| Right{} <- TypeCheckOptions
-> TypeCheckResult (View (ToT arg) (ToT ret) (ToT st))
-> Either TCError (View (ToT arg) (ToT ret) (ToT st))
forall a. TypeCheckOptions -> TypeCheckResult a -> Either TCError a
typeCheckingWith TypeCheckOptions
forall a. Default a => a
def TypeCheckResult (View (ToT arg) (ToT ret) (ToT st))
verify = View (ToT arg) (ToT st) (ToT ret)
viewRaw
| Bool
otherwise = View (ToT arg) (ToT st) (ToT ret)
viewRaw {
vCode :: ViewCode' Instr (ToT arg) (ToT st) (ToT ret)
M.vCode = CompilationOptions
-> ViewCode arg st ret -> Instr (ToTs '[(arg, st)]) (ToTs '[ret])
forall (inp :: [*]) (out :: [*]).
CompilationOptions -> (inp :-> out) -> Instr (ToTs inp) (ToTs out)
compileLorentzWithOptions CompilationOptions
co (Instr (ToTs '[(arg, st)]) (ToTs '[(arg, st)])
-> '[(arg, st)] :-> '[(arg, st)]
forall (inp :: [*]) (out :: [*]).
Instr (ToTs inp) (ToTs out) -> inp :-> out
I Instr (ToTs '[(arg, st)]) (ToTs '[(arg, st)])
forall (a :: T) (s :: [T]). SingI a => Instr (a : s) (a : s)
CAST ('[(arg, st)] :-> '[(arg, st)])
-> ViewCode arg st ret -> ViewCode arg st ret
forall (a :: [*]) (b :: [*]) (c :: [*]).
(a :-> b) -> (b :-> c) -> a :-> c
# ViewCode arg st ret
viewCode :: ViewCode arg st ret) }
in View (ToT arg) (ToT st) (ToT ret) -> SomeView (ToT st)
forall (instr :: [T] -> [T] -> *) (arg :: T) (st :: T) (ret :: T).
View' instr arg st ret -> SomeView' instr st
M.SomeView View (ToT arg) (ToT st) (ToT ret)
viewWithNecessaryCast
setViews
:: forall vd cp st.
( RecFromTuple (Rec (ContractView st) (RevealViews vd))
, NiceViewsDescriptor vd
)
=> IsoRecTuple (Rec (ContractView st) (RevealViews vd))
-> ContractData cp st ()
-> ContractData cp st vd
setViews :: IsoRecTuple (Rec (ContractView st) (RevealViews vd))
-> ContractData cp st () -> ContractData cp st vd
setViews IsoRecTuple (Rec (ContractView st) (RevealViews vd))
views = Rec (ContractView st) (RevealViews vd)
-> ContractData cp st () -> ContractData cp st vd
forall vd cp st.
NiceViewsDescriptor vd =>
Rec (ContractView st) (RevealViews vd)
-> ContractData cp st () -> ContractData cp st vd
setViewsRec (IsoRecTuple (Rec (ContractView st) (RevealViews vd))
-> Rec (ContractView st) (RevealViews vd)
forall r. RecFromTuple r => IsoRecTuple r -> r
recFromTuple IsoRecTuple (Rec (ContractView st) (RevealViews vd))
views)
setViewsRec
:: forall vd cp st.
(NiceViewsDescriptor vd)
=> Rec (ContractView st) (RevealViews vd)
-> ContractData cp st ()
-> ContractData cp st vd
setViewsRec :: Rec (ContractView st) (RevealViews vd)
-> ContractData cp st () -> ContractData cp st vd
setViewsRec Rec (ContractView st) (RevealViews vd)
views ContractData{Rec (ContractView st) (RevealViews ())
ContractCode cp st
CompilationOptions
cdCompilationOptions :: CompilationOptions
cdViews :: Rec (ContractView st) (RevealViews ())
cdCode :: ContractCode cp st
cdCompilationOptions :: forall cp st vd. ContractData cp st vd -> CompilationOptions
cdViews :: forall cp st vd.
ContractData cp st vd -> Rec (ContractView st) (RevealViews vd)
cdCode :: forall cp st vd. ContractData cp st vd -> ContractCode cp st
..} =
ContractData :: forall cp st vd.
(NiceParameterFull cp, NiceStorageFull st,
NiceViewsDescriptor vd) =>
ContractCode cp st
-> Rec (ContractView st) (RevealViews vd)
-> CompilationOptions
-> ContractData cp st vd
ContractData{ cdViews :: Rec (ContractView st) (RevealViews vd)
cdViews = Rec (ContractView st) (RevealViews vd)
views, ContractCode cp st
CompilationOptions
cdCompilationOptions :: CompilationOptions
cdCode :: ContractCode cp st
cdCompilationOptions :: CompilationOptions
cdCode :: ContractCode cp st
.. }
noViews :: contract cp st () -> contract cp st ()
noViews :: contract cp st () -> contract cp st ()
noViews = contract cp st () -> contract cp st ()
forall a. a -> a
id
interpretLorentzInstr
:: (IsoValuesStack inp, IsoValuesStack out)
=> ContractEnv
-> inp :-> out
-> Rec Identity inp
-> Either MichelsonFailureWithStack (Rec Identity out)
interpretLorentzInstr :: ContractEnv
-> (inp :-> out)
-> Rec Identity inp
-> Either MichelsonFailureWithStack (Rec Identity out)
interpretLorentzInstr ContractEnv
env ((inp :-> out) -> Instr (ToTs inp) (ToTs out)
forall (inp :: [*]) (out :: [*]).
(inp :-> out) -> Instr (ToTs inp) (ToTs out)
compileLorentz -> Instr (ToTs inp) (ToTs out)
instr) Rec Identity inp
inp =
Rec Value (ToTs out) -> Rec Identity out
forall (ts :: [*]).
IsoValuesStack ts =>
Rec Value (ToTs ts) -> Rec Identity ts
fromValStack (Rec Value (ToTs out) -> Rec Identity out)
-> Either MichelsonFailureWithStack (Rec Value (ToTs out))
-> Either MichelsonFailureWithStack (Rec Identity out)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ContractEnv
-> Instr (ToTs inp) (ToTs out)
-> Rec Value (ToTs inp)
-> Either MichelsonFailureWithStack (Rec Value (ToTs out))
forall (inp :: [T]) (out :: [T]).
ContractEnv
-> Instr inp out
-> Rec Value inp
-> Either MichelsonFailureWithStack (Rec Value out)
interpretInstr ContractEnv
env Instr (ToTs inp) (ToTs out)
instr (Rec Identity inp -> Rec Value (ToTs inp)
forall (ts :: [*]).
IsoValuesStack ts =>
Rec Identity ts -> Rec Value (ToTs ts)
toValStack Rec Identity inp
inp)
interpretLorentzLambda
:: (IsoValue inp, IsoValue out)
=> ContractEnv
-> Lambda inp out
-> inp
-> Either MichelsonFailureWithStack out
interpretLorentzLambda :: ContractEnv
-> Lambda inp out -> inp -> Either MichelsonFailureWithStack out
interpretLorentzLambda ContractEnv
env Lambda inp out
instr inp
inp = do
Rec Identity '[out]
res <- ContractEnv
-> Lambda inp out
-> Rec Identity '[inp]
-> Either MichelsonFailureWithStack (Rec Identity '[out])
forall (inp :: [*]) (out :: [*]).
(IsoValuesStack inp, IsoValuesStack out) =>
ContractEnv
-> (inp :-> out)
-> Rec Identity inp
-> Either MichelsonFailureWithStack (Rec Identity out)
interpretLorentzInstr ContractEnv
env Lambda inp out
instr (inp -> Identity inp
forall a. a -> Identity a
Identity inp
inp Identity inp -> Rec Identity '[] -> Rec Identity '[inp]
forall u (a :: u -> *) (r :: u) (rs :: [u]).
a r -> Rec a rs -> Rec a (r : rs)
:& Rec Identity '[]
forall u (a :: u -> *). Rec a '[]
RNil)
let Identity out :& Rec Identity rs
RNil = Rec Identity '[out]
res
out -> Either MichelsonFailureWithStack out
forall (m :: * -> *) a. Monad m => a -> m a
return out
out
instance ContainsDoc (ContractData cp st vd) where
buildDocUnfinalized :: ContractData cp st vd -> ContractDoc
buildDocUnfinalized =
Contract cp st vd -> ContractDoc
forall a. ContainsDoc a => a -> ContractDoc
buildDocUnfinalized (Contract cp st vd -> ContractDoc)
-> (ContractData cp st vd -> Contract cp st vd)
-> ContractData cp st vd
-> ContractDoc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ContractData cp st vd -> Contract cp st vd
forall cp st vd. ContractData cp st vd -> Contract cp st vd
compileLorentzContract
instance ContainsUpdateableDoc (ContractData cp st vd) where
modifyDocEntirely :: (SomeDocItem -> SomeDocItem)
-> ContractData cp st vd -> ContractData cp st vd
modifyDocEntirely SomeDocItem -> SomeDocItem
how ContractData cp st vd
c =
ContractData cp st vd
c{ cdCode :: ContractCode cp st
cdCode = (SomeDocItem -> SomeDocItem)
-> ContractCode cp st -> ContractCode cp st
forall a.
ContainsUpdateableDoc a =>
(SomeDocItem -> SomeDocItem) -> a -> a
modifyDocEntirely SomeDocItem -> SomeDocItem
how (ContractData cp st vd -> ContractCode cp st
forall cp st vd. ContractData cp st vd -> ContractCode cp st
cdCode ContractData cp st vd
c) }
analyzeLorentz :: inp :-> out -> AnalyzerRes
analyzeLorentz :: (inp :-> out) -> AnalyzerRes
analyzeLorentz = Instr (ToTs inp) (ToTs out) -> AnalyzerRes
forall (inp :: [T]) (out :: [T]). Instr inp out -> AnalyzerRes
analyze (Instr (ToTs inp) (ToTs out) -> AnalyzerRes)
-> ((inp :-> out) -> Instr (ToTs inp) (ToTs out))
-> (inp :-> out)
-> AnalyzerRes
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (inp :-> out) -> Instr (ToTs inp) (ToTs out)
forall (inp :: [*]) (out :: [*]).
(inp :-> out) -> Instr (ToTs inp) (ToTs out)
compileLorentz
makeLensesWith postfixLFields ''CompilationOptions
cdCodeL ::
forall cp st vd cp1. NiceParameterFull cp1 =>
Lens.Lens (ContractData cp st vd) (ContractData cp1 st vd) (ContractCode cp st) (ContractCode cp1 st)
cdCodeL :: Lens
(ContractData cp st vd)
(ContractData cp1 st vd)
(ContractCode cp st)
(ContractCode cp1 st)
cdCodeL ContractCode cp st -> f (ContractCode cp1 st)
f (ContractData ContractCode cp st
code Rec (ContractView st) (RevealViews vd)
views CompilationOptions
options)
= (ContractCode cp1 st -> ContractData cp1 st vd)
-> f (ContractCode cp1 st) -> f (ContractData cp1 st vd)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\ContractCode cp1 st
code' -> ContractCode cp1 st
-> Rec (ContractView st) (RevealViews vd)
-> CompilationOptions
-> ContractData cp1 st vd
forall cp st vd.
(NiceParameterFull cp, NiceStorageFull st,
NiceViewsDescriptor vd) =>
ContractCode cp st
-> Rec (ContractView st) (RevealViews vd)
-> CompilationOptions
-> ContractData cp st vd
ContractData ContractCode cp1 st
code' Rec (ContractView st) (RevealViews vd)
views CompilationOptions
options) (ContractCode cp st -> f (ContractCode cp1 st)
f ContractCode cp st
code)
cdCompilationOptionsL ::
forall cp st vd.
Lens.Lens' (ContractData cp st vd) CompilationOptions
cdCompilationOptionsL :: (CompilationOptions -> f CompilationOptions)
-> ContractData cp st vd -> f (ContractData cp st vd)
cdCompilationOptionsL CompilationOptions -> f CompilationOptions
f (ContractData ContractCode cp st
code Rec (ContractView st) (RevealViews vd)
views CompilationOptions
options)
= (CompilationOptions -> ContractData cp st vd)
-> f CompilationOptions -> f (ContractData cp st vd)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\CompilationOptions
options' -> ContractCode cp st
-> Rec (ContractView st) (RevealViews vd)
-> CompilationOptions
-> ContractData cp st vd
forall cp st vd.
(NiceParameterFull cp, NiceStorageFull st,
NiceViewsDescriptor vd) =>
ContractCode cp st
-> Rec (ContractView st) (RevealViews vd)
-> CompilationOptions
-> ContractData cp st vd
ContractData ContractCode cp st
code Rec (ContractView st) (RevealViews vd)
views CompilationOptions
options') (CompilationOptions -> f CompilationOptions
f CompilationOptions
options)