morley-0.5.0: Developer tools for the Michelson Language

Safe HaskellNone
LanguageHaskell2010

Lorentz.Macro

Contents

Description

Common Michelson macros defined using Lorentz syntax.

Synopsis

Compare

ifEq0 :: IfCmp0Constraints a Eq' => (s :-> s') -> (s :-> s') -> (a & s) :-> s' Source #

ifGe0 :: IfCmp0Constraints a Ge => (s :-> s') -> (s :-> s') -> (a & s) :-> s' Source #

ifGt0 :: IfCmp0Constraints a Gt => (s :-> s') -> (s :-> s') -> (a & s) :-> s' Source #

ifLe0 :: IfCmp0Constraints a Le => (s :-> s') -> (s :-> s') -> (a & s) :-> s' Source #

ifLt0 :: IfCmp0Constraints a Lt => (s :-> s') -> (s :-> s') -> (a & s) :-> s' Source #

ifNeq0 :: IfCmp0Constraints a Neq => (s :-> s') -> (s :-> s') -> (a & s) :-> s' Source #

ifEq :: IfCmpXConstraints a Eq' => (s :-> s') -> (s :-> s') -> (a & (a & s)) :-> s' Source #

ifGe :: IfCmpXConstraints a Ge => (s :-> s') -> (s :-> s') -> (a & (a & s)) :-> s' Source #

ifGt :: IfCmpXConstraints a Gt => (s :-> s') -> (s :-> s') -> (a & (a & s)) :-> s' Source #

ifLe :: IfCmpXConstraints a Le => (s :-> s') -> (s :-> s') -> (a & (a & s)) :-> s' Source #

ifLt :: IfCmpXConstraints a Lt => (s :-> s') -> (s :-> s') -> (a & (a & s)) :-> s' Source #

ifNeq :: IfCmpXConstraints a Neq => (s :-> s') -> (s :-> s') -> (a & (a & s)) :-> s' Source #

Fail

fail_ :: a :-> c Source #

Warning: fail_ remains in code

Analog of the FAIL macro in Michelson. Its usage is discouraged because it doesn't carry any information about failure.

Assertion macros

They differ from the same macros in Michelson, because those macros use FAIL macro which is not informative (fails with unit). If you really want Michelson versions (maybe to produce exact copy of an existing contract), you can pass UnspecifiedError, then FAILWITH will be called with unit.

assert :: IsError err => err -> (Bool & s) :-> s Source #

assertEq0 :: (IfCmp0Constraints a Eq', IsError err) => err -> (a & s) :-> s Source #

assertNeq0 :: (IfCmp0Constraints a Neq, IsError err) => err -> (a & s) :-> s Source #

assertLt0 :: (IfCmp0Constraints a Lt, IsError err) => err -> (a & s) :-> s Source #

assertGt0 :: (IfCmp0Constraints a Gt, IsError err) => err -> (a & s) :-> s Source #

assertLe0 :: (IfCmp0Constraints a Le, IsError err) => err -> (a & s) :-> s Source #

assertGe0 :: (IfCmp0Constraints a Ge, IsError err) => err -> (a & s) :-> s Source #

assertEq :: (IfCmpXConstraints a Eq', IsError err) => err -> (a & (a & s)) :-> s Source #

assertNeq :: (IfCmpXConstraints a Neq, IsError err) => err -> (a & (a & s)) :-> s Source #

assertLt :: (IfCmpXConstraints a Lt, IsError err) => err -> (a & (a & s)) :-> s Source #

assertGt :: (IfCmpXConstraints a Gt, IsError err) => err -> (a & (a & s)) :-> s Source #

assertLe :: (IfCmpXConstraints a Le, IsError err) => err -> (a & (a & s)) :-> s Source #

assertGe :: (IfCmpXConstraints a Ge, IsError err) => err -> (a & (a & s)) :-> s Source #

assertNone :: IsError err => err -> (Maybe a & s) :-> s Source #

assertSome :: IsError err => err -> (Maybe a & s) :-> (a & s) Source #

assertLeft :: IsError err => err -> (Either a b & s) :-> (a & s) Source #

assertRight :: IsError err => err -> (Either a b & s) :-> (b & s) Source #

assertUsing :: IsError a => a -> (Bool & s) :-> s Source #

Syntactic Conveniences

dropX :: forall (n :: Nat) a inp out s s'. (ConstraintDIPNLorentz (ToPeano n) inp out s s', s ~ (a ': s')) => inp :-> out Source #

Custom Lorentz macro that drops element with given index (starting from 0) from the stack.

cloneX :: forall (n :: Nat) a s. CloneX (ToPeano n) a s => (a & s) :-> CloneXT (ToPeano n) a s Source #

Duplicate the top of the stack n times.

For example, `cloneX @3` has type `a & s :-> a & a & a & a & s`.

duupX :: forall (n :: Nat) a (s :: [Type]) (s1 :: [Type]) (tail :: [Type]). (ConstraintDuupXLorentz (ToPeano (n - 1)) s a s1 tail, DuupX (ToPeano n) s a s1 tail) => s :-> (a ': s) Source #

DUU+P macro. For example, `duupX @3` is DUUUP, it puts the 3-rd (starting from 1) element to the top of the stack. Note that it is implemented differently for `n ≤ 2` and for `n > 2`. In the latter case it is implemented using dipN, dig and dup. In the former case it uses specialized versions. There is also a minor difference with the implementation of `DUU*P` in Michelson. They implement DUUUUP as `DIP 3 { DUP }; DIG 4`. We implement it as `DIP 3 { DUP }; DIG 3`. These are equivalent. Our version is supposedly cheaper, at least it should be packed more efficiently due to the way numbers are packed.

framedN :: forall n nNat s i i' o o'. (nNat ~ ToPeano n, i' ~ Take nNat i, s ~ Drop nNat i, i ~ (i' ++ s), o ~ (o' ++ s), KnownList i', KnownList o') => (i' :-> o') -> i :-> o Source #

Version of framed which accepts number of elements on input stack which should be preserved.

You can treat this macro as calling a Michelson function with given number of arguments.

caar :: (((a, b1), b2) & s) :-> (a & s) Source #

cadr :: (((a, b1), b2) & s) :-> (b1 & s) Source #

cdar :: ((a1, (a2, b)) & s) :-> (a2 & s) Source #

cddr :: ((a1, (a2, b)) & s) :-> (b & s) Source #

ifRight :: ((b & s) :-> s') -> ((a & s) :-> s') -> (Either a b & s) :-> s' Source #

ifSome :: ((a & s) :-> s') -> (s :-> s') -> (Maybe a & s) :-> s' Source #

mapCar :: ((a & s) :-> (a1 & s)) -> ((a, b) & s) :-> ((a1, b) & s) Source #

mapCdr :: ((b & ((a, b) & s)) :-> (b1 & ((a, b) & s))) -> ((a, b) & s) :-> ((a, b1) & s) Source #

papair :: (a & (b & (c & s))) :-> (((a, b), c) & s) Source #

ppaiir :: (a & (b & (c & s))) :-> ((a, (b, c)) & s) Source #

unpair :: ((a, b) & s) :-> (a & (b & s)) Source #

setCar :: ((a, b1) & (b2 & s)) :-> ((b2, b1) & s) Source #

setCdr :: ((a, b1) & (b2 & s)) :-> ((a, b2) & s) Source #

setInsert :: IsComparable e => (e & (Set e & s)) :-> (Set e & s) Source #

Insert given element into set.

This is a separate function from updateMap because stacks they operate with differ in length.

mapInsert :: (MapInstrs map, IsComparable k) => (k ': (v ': (map k v ': s))) :-> (map k v ': s) Source #

Insert given element into map.

setInsertNew :: (IsComparable e, KnownValue err) => (forall s0. (e ': s0) :-> (err ': s0)) -> (e & (Set e & s)) :-> (Set e & s) Source #

Insert given element into set, ensuring that it does not overwrite any existing entry.

As first argument accepts container name.

mapInsertNew :: (MapInstrs map, IsComparable k, KnownValue e) => (forall s0. (k ': s0) :-> (e ': s0)) -> (k ': (v ': (map k v ': s))) :-> (map k v ': s) Source #

Insert given element into map, ensuring that it does not overwrite any existing entry.

As first argument accepts container name (for error message).

deleteMap :: forall k v s. (MapInstrs map, IsComparable k, KnownValue k, KnownValue v) => (k ': (map k v ': s)) :-> (map k v ': s) Source #

Delete element from the map.

setDelete :: IsComparable e => (e & (Set e & s)) :-> (Set e & s) Source #

Delete given element from the set.

Additional Morley macros

data View (a :: Type) (r :: Type) Source #

view type synonym as described in A1.

Constructors

View 
Instances
Eq a => Eq (View a r) Source # 
Instance details

Defined in Lorentz.Macro

Methods

(==) :: View a r -> View a r -> Bool #

(/=) :: View a r -> View a r -> Bool #

Show a => Show (View a r) Source # 
Instance details

Defined in Lorentz.Macro

Methods

showsPrec :: Int -> View a r -> ShowS #

show :: View a r -> String #

showList :: [View a r] -> ShowS #

Generic (View a r) Source # 
Instance details

Defined in Lorentz.Macro

Associated Types

type Rep (View a r) :: Type -> Type #

Methods

from :: View a r -> Rep (View a r) x #

to :: Rep (View a r) x -> View a r #

Buildable (View () r) Source # 
Instance details

Defined in Lorentz.Macro

Methods

build :: View () r -> Builder #

Buildable a => Buildable (View a r) Source # 
Instance details

Defined in Lorentz.Macro

Methods

build :: View a r -> Builder #

IsoValue a => IsoValue (View a r) Source # 
Instance details

Defined in Lorentz.Macro

Associated Types

type ToT (View a r) :: T Source #

Methods

toVal :: View a r -> Value (ToT (View a r)) Source #

fromVal :: Value (ToT (View a r)) -> View a r Source #

Each ((Typeable :: Type -> Constraint) ': (TypeHasDoc ': ([] :: [Type -> Constraint]))) (a ': (r ': ([] :: [Type]))) => TypeHasDoc (View a r) Source # 
Instance details

Defined in Lorentz.Macro

type Rep (View a r) Source # 
Instance details

Defined in Lorentz.Macro

type Rep (View a r) = D1 (MetaData "View" "Lorentz.Macro" "morley-0.5.0-GrlgowF8t30F9AnUlsv4ov" False) (C1 (MetaCons "View" PrefixI True) (S1 (MetaSel (Just "viewParam") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 a) :*: S1 (MetaSel (Just "viewCallbackTo") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (ContractRef r))))
type ToT (View a r) Source # 
Instance details

Defined in Lorentz.Macro

type ToT (View a r) = GValueType (Rep (View a r))

data Void_ (a :: Type) (b :: Type) Source #

void type synonym as described in A1.

Constructors

Void_ 

Fields

Instances
Generic (Void_ a b) Source # 
Instance details

Defined in Lorentz.Macro

Associated Types

type Rep (Void_ a b) :: Type -> Type #

Methods

from :: Void_ a b -> Rep (Void_ a b) x #

to :: Rep (Void_ a b) x -> Void_ a b #

Buildable a => Buildable (Void_ a b) Source # 
Instance details

Defined in Lorentz.Macro

Methods

build :: Void_ a b -> Builder #

IsoValue a => IsoValue (Void_ a b) Source # 
Instance details

Defined in Lorentz.Macro

Associated Types

type ToT (Void_ a b) :: T Source #

Methods

toVal :: Void_ a b -> Value (ToT (Void_ a b)) Source #

fromVal :: Value (ToT (Void_ a b)) -> Void_ a b Source #

Each ((Typeable :: Type -> Constraint) ': (TypeHasDoc ': ([] :: [Type -> Constraint]))) (a ': (r ': ([] :: [Type]))) => TypeHasDoc (Void_ a r) Source # 
Instance details

Defined in Lorentz.Macro

type Rep (Void_ a b) Source # 
Instance details

Defined in Lorentz.Macro

type Rep (Void_ a b) = D1 (MetaData "Void_" "Lorentz.Macro" "morley-0.5.0-GrlgowF8t30F9AnUlsv4ov" False) (C1 (MetaCons "Void_" PrefixI True) (S1 (MetaSel (Just "voidParam") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 a) :*: S1 (MetaSel (Just "voidResProxy") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (Lambda b b))))
type ToT (Void_ a b) Source # 
Instance details

Defined in Lorentz.Macro

type ToT (Void_ a b) = GValueType (Rep (Void_ a b))

newtype VoidResult r Source #

Newtype over void result type used in tests to distinguish successful void result from other errors.

Usage example: lExpectFailWith (== VoidResult roleMaster)`

This error is special - it can contain arguments of different types depending on entrypoint which raises it.

Constructors

VoidResult 

Fields

Instances
Eq r => Eq (VoidResult r) Source # 
Instance details

Defined in Lorentz.Macro

Methods

(==) :: VoidResult r -> VoidResult r -> Bool #

(/=) :: VoidResult r -> VoidResult r -> Bool #

Generic (VoidResult r) Source # 
Instance details

Defined in Lorentz.Macro

Associated Types

type Rep (VoidResult r) :: Type -> Type #

Methods

from :: VoidResult r -> Rep (VoidResult r) x #

to :: Rep (VoidResult r) x -> VoidResult r #

(CustomErrorNoIsoValue (VoidResult r) :: Constraint) => IsoValue (VoidResult r) Source # 
Instance details

Defined in Lorentz.Macro

Associated Types

type ToT (VoidResult r) :: T Source #

(TypeHasDoc r, IsError (VoidResult r)) => TypeHasDoc (VoidResult r) Source # 
Instance details

Defined in Lorentz.Macro

(Typeable r, NiceConstant r, ErrorHasDoc (VoidResult r)) => IsError (VoidResult r) Source # 
Instance details

Defined in Lorentz.Macro

Methods

errorToVal :: VoidResult r -> (forall (t :: T). ErrorScope t => Value t -> r0) -> r0 Source #

errorFromVal :: (Typeable t, SingI t) => Value t -> Either Text (VoidResult r) Source #

TypeHasDoc r => ErrorHasDoc (VoidResult r :: Type) Source # 
Instance details

Defined in Lorentz.Macro

type Rep (VoidResult r) Source # 
Instance details

Defined in Lorentz.Macro

type Rep (VoidResult r) = D1 (MetaData "VoidResult" "Lorentz.Macro" "morley-0.5.0-GrlgowF8t30F9AnUlsv4ov" True) (C1 (MetaCons "VoidResult" PrefixI True) (S1 (MetaSel (Just "unVoidResult") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 r)))
type ToT (VoidResult r) Source # 
Instance details

Defined in Lorentz.Macro

view_ :: NiceParameter r => (forall s0. ((a, storage) & s0) :-> (r ': s0)) -> (View a r & (storage & s)) :-> ((List Operation, storage) & s) Source #

mkView :: ToContractRef r contract => a -> contract -> View a r Source #

Polymorphic version of View constructor.

void_ :: forall a b s s' anything. (IsError (VoidResult b), KnownValue b) => ((a & s) :-> (b & s')) -> (Void_ a b & s) :-> anything Source #

mkVoid :: forall b a. a -> Void_ a b Source #

Buildable utils for additional Morley macros

buildView :: (a -> Builder) -> View a r -> Builder Source #

Macros for working with contract-like types

pushContractRef :: NiceParameter arg => (forall s0. (Address ': s) :-> s0) -> ContractRef arg -> s :-> (ContractRef arg ': s) Source #

Push a value of contract type.

Doing this via push instruction is not possible, so we need to perform extra actions here.

Aside from contract value itself you will need to specify which error to throw in case this value is not valid.

pickFutureContract :: NiceParameter p => (FutureContract p ': s) :-> (Maybe (ContractRef p) ': s) Source #

Turn FutureContract into actual contract.

This requires contracts lookup and may fail.