-- SPDX-FileCopyrightText: 2020 Tocqueville Group
--
-- SPDX-License-Identifier: LicenseRef-MIT-TQ

-- | Parsing of Michelson instructions.

module Michelson.Parser.Instr
  ( primInstr
  , ops'
  -- * These are handled separately to have better error messages
  , mapOp
  , pairOp
  , cmpOp
  , dupOp
  ) where

import Prelude hiding (EQ, GT, LT, many, note, some, try)

import Text.Megaparsec (choice, notFollowedBy, sepEndBy, try)
import qualified Text.Megaparsec.Char.Lexer as L

import Michelson.Let (LetValue(..))
import Michelson.Macro (ParsedInstr, ParsedOp(..))
import Michelson.Parser.Annotations
import Michelson.Parser.Lexer
import Michelson.Parser.Type
import Michelson.Parser.Types (Parser, letValues)
import Michelson.Parser.Value
import Michelson.Untyped

-- | Parser for primitive Michelson instruction (no macros and extensions).
primInstr :: Parser (Contract' ParsedOp) -> Parser ParsedOp -> Parser ParsedInstr
primInstr :: Parser (Contract' ParsedOp)
-> Parser ParsedOp -> Parser ParsedInstr
primInstr contractParser :: Parser (Contract' ParsedOp)
contractParser opParser :: Parser ParsedOp
opParser = [Parser ParsedInstr] -> Parser ParsedInstr
forall (f :: * -> *) (m :: * -> *) a.
(Foldable f, Alternative m) =>
f (m a) -> m a
choice
  [ Parser ParsedInstr
dropOp, Parser ParsedInstr
swapOp, Parser ParsedInstr
digOp, Parser ParsedInstr
dugOp, Parser ParsedOp -> Parser ParsedInstr
pushOp Parser ParsedOp
opParser, Parser ParsedInstr
someOp, Parser ParsedInstr
noneOp, Parser ParsedInstr
unitOp
  , Parser ParsedOp -> Parser ParsedInstr
ifNoneOp Parser ParsedOp
opParser, Parser ParsedInstr
carOp, Parser ParsedInstr
cdrOp, Parser ParsedInstr
leftOp, Parser ParsedInstr
rightOp, Parser ParsedOp -> Parser ParsedInstr
ifLeftOp Parser ParsedOp
opParser, Parser ParsedInstr
nilOp
  , Parser ParsedInstr
consOp, Parser ParsedOp -> Parser ParsedInstr
ifConsOp Parser ParsedOp
opParser, Parser ParsedInstr
sizeOp, Parser ParsedInstr
emptySetOp, Parser ParsedInstr
emptyMapOp, Parser ParsedInstr
emptyBigMapOp, Parser ParsedOp -> Parser ParsedInstr
iterOp Parser ParsedOp
opParser
  , Parser ParsedInstr
memOp, Parser ParsedInstr
getOp, Parser ParsedInstr
updateOp, Parser ParsedOp -> Parser ParsedInstr
loopLOp Parser ParsedOp
opParser, Parser ParsedOp -> Parser ParsedInstr
loopOp Parser ParsedOp
opParser
  , Parser ParsedOp -> Parser ParsedInstr
lambdaOp Parser ParsedOp
opParser, Parser ParsedInstr
execOp, Parser ParsedInstr
applyOp, Parser ParsedOp -> Parser ParsedInstr
dipOp Parser ParsedOp
opParser, Parser ParsedInstr
failWithOp, Parser ParsedInstr
castOp, Parser ParsedInstr
renameOp
  , Parser ParsedInstr
concatOp, Parser ParsedInstr
packOp, Parser ParsedInstr
unpackOp, Parser ParsedInstr
sliceOp, Parser ParsedInstr
isNatOp, Parser ParsedInstr
addressOp, Parser ParsedInstr
addOp, Parser ParsedInstr
subOp
  , Parser ParsedInstr
mulOp, Parser ParsedInstr
edivOp, Parser ParsedInstr
absOp, Parser ParsedInstr
negOp, Parser ParsedInstr
lslOp, Parser ParsedInstr
lsrOp, Parser ParsedInstr
orOp, Parser ParsedInstr
andOp, Parser ParsedInstr
xorOp, Parser ParsedInstr
notOp
  , Parser ParsedInstr
compareOp, Parser ParsedInstr
eqOp, Parser ParsedInstr
neqOp, Parser ParsedInstr
ltOp, Parser ParsedInstr
leOp, Parser ParsedInstr
gtOp, Parser ParsedInstr
geOp, Parser ParsedInstr
intOp, Parser ParsedInstr
selfOp, Parser ParsedInstr
contractOp
  , Parser ParsedInstr
transferTokensOp, Parser ParsedInstr
setDelegateOp
  , Parser (Contract' ParsedOp) -> Parser ParsedInstr
createContractOp Parser (Contract' ParsedOp)
contractParser, Parser ParsedInstr
implicitAccountOp, Parser ParsedInstr
nowOp, Parser ParsedInstr
amountOp
  , Parser ParsedInstr
balanceOp, Parser ParsedInstr
checkSigOp, Parser ParsedInstr
sha256Op, Parser ParsedInstr
sha512Op, Parser ParsedInstr
blake2BOp, Parser ParsedInstr
hashKeyOp
  , Parser ParsedInstr
sourceOp, Parser ParsedInstr
senderOp, Parser ParsedInstr
chainIdOp
  ]

-- | Parse a sequence of instructions.
ops' :: Parser ParsedOp -> Parser [ParsedOp]
ops' :: Parser ParsedOp -> Parser [ParsedOp]
ops' opParser :: Parser ParsedOp
opParser = (Parser [ParsedOp] -> Parser [ParsedOp]
forall a. Parser a -> Parser a
braces (Parser [ParsedOp] -> Parser [ParsedOp])
-> Parser [ParsedOp] -> Parser [ParsedOp]
forall a b. (a -> b) -> a -> b
$ Parser ParsedOp
-> ReaderT LetEnv (Parsec CustomParserException Text) (Maybe ())
-> Parser [ParsedOp]
forall (m :: * -> *) a sep. MonadPlus m => m a -> m sep -> m [a]
sepEndBy Parser ParsedOp
opParser (ReaderT LetEnv (Parsec CustomParserException Text) ()
-> ReaderT LetEnv (Parsec CustomParserException Text) (Maybe ())
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional ReaderT LetEnv (Parsec CustomParserException Text) ()
semicolon)) Parser [ParsedOp] -> Parser [ParsedOp] -> Parser [ParsedOp]
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (ParsedOp -> [ParsedOp]
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ParsedOp -> [ParsedOp]) -> Parser ParsedOp -> Parser [ParsedOp]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser ParsedOp
opParser)

-- Control Structures

failWithOp :: Parser ParsedInstr
failWithOp :: Parser ParsedInstr
failWithOp = Tokens Text -> ParsedInstr -> Parser ParsedInstr
forall a. Tokens Text -> a -> Parser a
word' "FAILWITH" ParsedInstr
forall op. InstrAbstract op
FAILWITH

loopOp :: Parser ParsedOp -> Parser ParsedInstr
loopOp :: Parser ParsedOp -> Parser ParsedInstr
loopOp opParser :: Parser ParsedOp
opParser = Tokens Text
-> ([ParsedOp] -> ParsedInstr)
-> Parser ([ParsedOp] -> ParsedInstr)
forall a. Tokens Text -> a -> Parser a
word' "LOOP" [ParsedOp] -> ParsedInstr
forall op. [op] -> InstrAbstract op
LOOP Parser ([ParsedOp] -> ParsedInstr)
-> Parser [ParsedOp] -> Parser ParsedInstr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser ParsedOp -> Parser [ParsedOp]
ops' Parser ParsedOp
opParser

loopLOp :: Parser ParsedOp -> Parser ParsedInstr
loopLOp :: Parser ParsedOp -> Parser ParsedInstr
loopLOp opParser :: Parser ParsedOp
opParser = Tokens Text
-> ([ParsedOp] -> ParsedInstr)
-> Parser ([ParsedOp] -> ParsedInstr)
forall a. Tokens Text -> a -> Parser a
word' "LOOP_LEFT" [ParsedOp] -> ParsedInstr
forall op. [op] -> InstrAbstract op
LOOP_LEFT Parser ([ParsedOp] -> ParsedInstr)
-> Parser [ParsedOp] -> Parser ParsedInstr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser ParsedOp -> Parser [ParsedOp]
ops' Parser ParsedOp
opParser

execOp :: Parser ParsedInstr
execOp :: Parser ParsedInstr
execOp = Tokens Text
-> (VarAnn -> ParsedInstr) -> Parser (VarAnn -> ParsedInstr)
forall a. Tokens Text -> a -> Parser a
word' "EXEC" VarAnn -> ParsedInstr
forall op. VarAnn -> InstrAbstract op
EXEC Parser (VarAnn -> ParsedInstr)
-> ReaderT LetEnv (Parsec CustomParserException Text) VarAnn
-> Parser ParsedInstr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ReaderT LetEnv (Parsec CustomParserException Text) VarAnn
forall tag. KnownAnnTag tag => Parser (Annotation tag)
noteDef

applyOp :: Parser ParsedInstr
applyOp :: Parser ParsedInstr
applyOp = Tokens Text
-> (VarAnn -> ParsedInstr) -> Parser (VarAnn -> ParsedInstr)
forall a. Tokens Text -> a -> Parser a
word' "APPLY" VarAnn -> ParsedInstr
forall op. VarAnn -> InstrAbstract op
APPLY Parser (VarAnn -> ParsedInstr)
-> ReaderT LetEnv (Parsec CustomParserException Text) VarAnn
-> Parser ParsedInstr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ReaderT LetEnv (Parsec CustomParserException Text) VarAnn
forall tag. KnownAnnTag tag => Parser (Annotation tag)
noteDef

-- Parses both `DIP` and `DIP n`.
dipOp :: Parser ParsedOp -> Parser ParsedInstr
dipOp :: Parser ParsedOp -> Parser ParsedInstr
dipOp opParser :: Parser ParsedOp
opParser = Text
-> (Word -> [ParsedOp] -> ParsedInstr)
-> ([ParsedOp] -> ParsedInstr)
-> Parser ([ParsedOp] -> ParsedInstr)
forall instr. Text -> (Word -> instr) -> instr -> Parser instr
parseWithOptionalParameter "DIP" Word -> [ParsedOp] -> ParsedInstr
forall op. Word -> [op] -> InstrAbstract op
DIPN [ParsedOp] -> ParsedInstr
forall op. [op] -> InstrAbstract op
DIP Parser ([ParsedOp] -> ParsedInstr)
-> Parser [ParsedOp] -> Parser ParsedInstr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser ParsedOp -> Parser [ParsedOp]
ops' Parser ParsedOp
opParser

-- Helper for instructions which have optional numeric non-negative parameter.
parseWithOptionalParameter :: Text -> (Word -> instr) -> instr -> Parser instr
parseWithOptionalParameter :: Text -> (Word -> instr) -> instr -> Parser instr
parseWithOptionalParameter instrName :: Text
instrName constructorWithParam :: Word -> instr
constructorWithParam constructorNoParam :: instr
constructorNoParam =
  Text -> ReaderT LetEnv (Parsec CustomParserException Text) ()
symbol' Text
instrName ReaderT LetEnv (Parsec CustomParserException Text) ()
-> Parser instr -> Parser instr
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*>
  (Parser instr -> Parser instr
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try (Word -> instr
constructorWithParam (Word -> instr)
-> ReaderT LetEnv (Parsec CustomParserException Text) Word
-> Parser instr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ReaderT LetEnv (Parsec CustomParserException Text) Word
-> ReaderT LetEnv (Parsec CustomParserException Text) Word
forall a. Parser a -> Parser a
lexeme ReaderT LetEnv (Parsec CustomParserException Text) Word
forall e s (m :: * -> *) a.
(MonadParsec e s m, Token s ~ Char, Num a) =>
m a
L.decimal) Parser instr -> Parser instr -> Parser instr
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> instr -> Parser instr
forall (f :: * -> *) a. Applicative f => a -> f a
pure instr
constructorNoParam)

-- Stack Operations

-- Parses both `DROP` and `DROP n`.
dropOp :: Parser ParsedInstr
dropOp :: Parser ParsedInstr
dropOp = Text -> (Word -> ParsedInstr) -> ParsedInstr -> Parser ParsedInstr
forall instr. Text -> (Word -> instr) -> instr -> Parser instr
parseWithOptionalParameter "DROP" Word -> ParsedInstr
forall op. Word -> InstrAbstract op
DROPN ParsedInstr
forall op. InstrAbstract op
DROP

dupOp :: Parser ParsedInstr
dupOp :: Parser ParsedInstr
dupOp = Tokens Text
-> (VarAnn -> ParsedInstr) -> Parser (VarAnn -> ParsedInstr)
forall a. Tokens Text -> a -> Parser a
word' "DUP" VarAnn -> ParsedInstr
forall op. VarAnn -> InstrAbstract op
DUP Parser (VarAnn -> ParsedInstr)
-> ReaderT LetEnv (Parsec CustomParserException Text) VarAnn
-> Parser ParsedInstr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ReaderT LetEnv (Parsec CustomParserException Text) VarAnn
forall tag. KnownAnnTag tag => Parser (Annotation tag)
noteDef

swapOp :: Parser ParsedInstr
swapOp :: Parser ParsedInstr
swapOp = Tokens Text -> ParsedInstr -> Parser ParsedInstr
forall a. Tokens Text -> a -> Parser a
word' "SWAP" ParsedInstr
forall op. InstrAbstract op
SWAP;

digOp :: Parser ParsedInstr
digOp :: Parser ParsedInstr
digOp = Tokens Text
-> (Word -> ParsedInstr) -> Parser (Word -> ParsedInstr)
forall a. Tokens Text -> a -> Parser a
word' "DIG" Word -> ParsedInstr
forall op. Word -> InstrAbstract op
DIG Parser (Word -> ParsedInstr)
-> ReaderT LetEnv (Parsec CustomParserException Text) Word
-> Parser ParsedInstr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ReaderT LetEnv (Parsec CustomParserException Text) Word
-> ReaderT LetEnv (Parsec CustomParserException Text) Word
forall a. Parser a -> Parser a
lexeme ReaderT LetEnv (Parsec CustomParserException Text) Word
forall e s (m :: * -> *) a.
(MonadParsec e s m, Token s ~ Char, Num a) =>
m a
L.decimal

dugOp :: Parser ParsedInstr
dugOp :: Parser ParsedInstr
dugOp = Tokens Text
-> (Word -> ParsedInstr) -> Parser (Word -> ParsedInstr)
forall a. Tokens Text -> a -> Parser a
word' "DUG" Word -> ParsedInstr
forall op. Word -> InstrAbstract op
DUG Parser (Word -> ParsedInstr)
-> ReaderT LetEnv (Parsec CustomParserException Text) Word
-> Parser ParsedInstr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ReaderT LetEnv (Parsec CustomParserException Text) Word
-> ReaderT LetEnv (Parsec CustomParserException Text) Word
forall a. Parser a -> Parser a
lexeme ReaderT LetEnv (Parsec CustomParserException Text) Word
forall e s (m :: * -> *) a.
(MonadParsec e s m, Token s ~ Char, Num a) =>
m a
L.decimal

pushOp :: Parser ParsedOp -> Parser ParsedInstr
pushOp :: Parser ParsedOp -> Parser ParsedInstr
pushOp opParser :: Parser ParsedOp
opParser = do
  Text -> ReaderT LetEnv (Parsec CustomParserException Text) ()
symbol' "PUSH"
  VarAnn
v <- ReaderT LetEnv (Parsec CustomParserException Text) VarAnn
forall tag. KnownAnnTag tag => Parser (Annotation tag)
noteDef
  (Parser ParsedInstr -> Parser ParsedInstr
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try (Parser ParsedInstr -> Parser ParsedInstr)
-> Parser ParsedInstr -> Parser ParsedInstr
forall a b. (a -> b) -> a -> b
$ VarAnn -> Parser ParsedInstr
pushLet VarAnn
v) Parser ParsedInstr -> Parser ParsedInstr -> Parser ParsedInstr
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (VarAnn -> Parser ParsedInstr
push' VarAnn
v)
  where
    pushLet :: VarAnn -> Parser ParsedInstr
pushLet v :: VarAnn
v = do
      Map Text LetValue
lvs <- (LetEnv -> Map Text LetValue)
-> ReaderT
     LetEnv (Parsec CustomParserException Text) (Map Text LetValue)
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks LetEnv -> Map Text LetValue
letValues
      LetValue
lv <- Map Text LetValue -> Parser LetValue
mkLetVal Map Text LetValue
lvs
      return $ VarAnn -> Type -> Value' ParsedOp -> ParsedInstr
forall op. VarAnn -> Type -> Value' op -> InstrAbstract op
PUSH VarAnn
v (LetValue -> Type
lvSig LetValue
lv) (LetValue -> Value' ParsedOp
lvVal LetValue
lv)
    push' :: VarAnn -> Parser ParsedInstr
push' v :: VarAnn
v = VarAnn -> Type -> Value' ParsedOp -> ParsedInstr
forall op. VarAnn -> Type -> Value' op -> InstrAbstract op
PUSH VarAnn
v (Type -> Value' ParsedOp -> ParsedInstr)
-> ReaderT LetEnv (Parsec CustomParserException Text) Type
-> ReaderT
     LetEnv
     (Parsec CustomParserException Text)
     (Value' ParsedOp -> ParsedInstr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ReaderT LetEnv (Parsec CustomParserException Text) Type
type_ ReaderT
  LetEnv
  (Parsec CustomParserException Text)
  (Value' ParsedOp -> ParsedInstr)
-> ReaderT
     LetEnv (Parsec CustomParserException Text) (Value' ParsedOp)
-> Parser ParsedInstr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser ParsedOp
-> ReaderT
     LetEnv (Parsec CustomParserException Text) (Value' ParsedOp)
value' Parser ParsedOp
opParser

unitOp :: Parser ParsedInstr
unitOp :: Parser ParsedInstr
unitOp = do Text -> ReaderT LetEnv (Parsec CustomParserException Text) ()
symbol' "UNIT"; (t :: TypeAnn
t, v :: VarAnn
v) <- Parser (TypeAnn, VarAnn)
notesTV; return $ TypeAnn -> VarAnn -> ParsedInstr
forall op. TypeAnn -> VarAnn -> InstrAbstract op
UNIT TypeAnn
t VarAnn
v

lambdaOp :: Parser ParsedOp -> Parser ParsedInstr
lambdaOp :: Parser ParsedOp -> Parser ParsedInstr
lambdaOp opParser :: Parser ParsedOp
opParser =
  Tokens Text
-> (VarAnn -> Type -> Type -> [ParsedOp] -> ParsedInstr)
-> Parser (VarAnn -> Type -> Type -> [ParsedOp] -> ParsedInstr)
forall a. Tokens Text -> a -> Parser a
word' "LAMBDA" VarAnn -> Type -> Type -> [ParsedOp] -> ParsedInstr
forall op. VarAnn -> Type -> Type -> [op] -> InstrAbstract op
LAMBDA Parser (VarAnn -> Type -> Type -> [ParsedOp] -> ParsedInstr)
-> ReaderT LetEnv (Parsec CustomParserException Text) VarAnn
-> ReaderT
     LetEnv
     (Parsec CustomParserException Text)
     (Type -> Type -> [ParsedOp] -> ParsedInstr)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ReaderT LetEnv (Parsec CustomParserException Text) VarAnn
forall tag. KnownAnnTag tag => Parser (Annotation tag)
noteDef ReaderT
  LetEnv
  (Parsec CustomParserException Text)
  (Type -> Type -> [ParsedOp] -> ParsedInstr)
-> ReaderT LetEnv (Parsec CustomParserException Text) Type
-> ReaderT
     LetEnv
     (Parsec CustomParserException Text)
     (Type -> [ParsedOp] -> ParsedInstr)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ReaderT LetEnv (Parsec CustomParserException Text) Type
type_ ReaderT
  LetEnv
  (Parsec CustomParserException Text)
  (Type -> [ParsedOp] -> ParsedInstr)
-> ReaderT LetEnv (Parsec CustomParserException Text) Type
-> Parser ([ParsedOp] -> ParsedInstr)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ReaderT LetEnv (Parsec CustomParserException Text) Type
type_ Parser ([ParsedOp] -> ParsedInstr)
-> Parser [ParsedOp] -> Parser ParsedInstr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser ParsedOp -> Parser [ParsedOp]
ops' Parser ParsedOp
opParser

-- Generic comparison

cmpOp :: Parser ParsedInstr
cmpOp :: Parser ParsedInstr
cmpOp = Parser ParsedInstr
eqOp Parser ParsedInstr -> Parser ParsedInstr -> Parser ParsedInstr
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Parser ParsedInstr
neqOp Parser ParsedInstr -> Parser ParsedInstr -> Parser ParsedInstr
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Parser ParsedInstr
ltOp Parser ParsedInstr -> Parser ParsedInstr -> Parser ParsedInstr
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Parser ParsedInstr
gtOp Parser ParsedInstr -> Parser ParsedInstr -> Parser ParsedInstr
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Parser ParsedInstr
leOp Parser ParsedInstr -> Parser ParsedInstr -> Parser ParsedInstr
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Parser ParsedInstr
gtOp Parser ParsedInstr -> Parser ParsedInstr -> Parser ParsedInstr
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Parser ParsedInstr
geOp

eqOp :: Parser ParsedInstr
eqOp :: Parser ParsedInstr
eqOp = Tokens Text
-> (VarAnn -> ParsedInstr) -> Parser (VarAnn -> ParsedInstr)
forall a. Tokens Text -> a -> Parser a
word' "EQ" VarAnn -> ParsedInstr
forall op. VarAnn -> InstrAbstract op
EQ Parser (VarAnn -> ParsedInstr)
-> ReaderT LetEnv (Parsec CustomParserException Text) VarAnn
-> Parser ParsedInstr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ReaderT LetEnv (Parsec CustomParserException Text) VarAnn
forall tag. KnownAnnTag tag => Parser (Annotation tag)
noteDef

neqOp :: Parser ParsedInstr
neqOp :: Parser ParsedInstr
neqOp = Tokens Text
-> (VarAnn -> ParsedInstr) -> Parser (VarAnn -> ParsedInstr)
forall a. Tokens Text -> a -> Parser a
word' "NEQ" VarAnn -> ParsedInstr
forall op. VarAnn -> InstrAbstract op
NEQ Parser (VarAnn -> ParsedInstr)
-> ReaderT LetEnv (Parsec CustomParserException Text) VarAnn
-> Parser ParsedInstr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ReaderT LetEnv (Parsec CustomParserException Text) VarAnn
forall tag. KnownAnnTag tag => Parser (Annotation tag)
noteDef

ltOp :: Parser ParsedInstr
ltOp :: Parser ParsedInstr
ltOp = Tokens Text
-> (VarAnn -> ParsedInstr) -> Parser (VarAnn -> ParsedInstr)
forall a. Tokens Text -> a -> Parser a
word' "LT" VarAnn -> ParsedInstr
forall op. VarAnn -> InstrAbstract op
LT Parser (VarAnn -> ParsedInstr)
-> ReaderT LetEnv (Parsec CustomParserException Text) VarAnn
-> Parser ParsedInstr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ReaderT LetEnv (Parsec CustomParserException Text) VarAnn
forall tag. KnownAnnTag tag => Parser (Annotation tag)
noteDef

gtOp :: Parser ParsedInstr
gtOp :: Parser ParsedInstr
gtOp = Tokens Text
-> (VarAnn -> ParsedInstr) -> Parser (VarAnn -> ParsedInstr)
forall a. Tokens Text -> a -> Parser a
word' "GT" VarAnn -> ParsedInstr
forall op. VarAnn -> InstrAbstract op
GT Parser (VarAnn -> ParsedInstr)
-> ReaderT LetEnv (Parsec CustomParserException Text) VarAnn
-> Parser ParsedInstr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ReaderT LetEnv (Parsec CustomParserException Text) VarAnn
forall tag. KnownAnnTag tag => Parser (Annotation tag)
noteDef

leOp :: Parser ParsedInstr
leOp :: Parser ParsedInstr
leOp = Tokens Text
-> (VarAnn -> ParsedInstr) -> Parser (VarAnn -> ParsedInstr)
forall a. Tokens Text -> a -> Parser a
word' "LE" VarAnn -> ParsedInstr
forall op. VarAnn -> InstrAbstract op
LE Parser (VarAnn -> ParsedInstr)
-> ReaderT LetEnv (Parsec CustomParserException Text) VarAnn
-> Parser ParsedInstr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ReaderT LetEnv (Parsec CustomParserException Text) VarAnn
forall tag. KnownAnnTag tag => Parser (Annotation tag)
noteDef

geOp :: Parser ParsedInstr
geOp :: Parser ParsedInstr
geOp = Tokens Text
-> (VarAnn -> ParsedInstr) -> Parser (VarAnn -> ParsedInstr)
forall a. Tokens Text -> a -> Parser a
word' "GE" VarAnn -> ParsedInstr
forall op. VarAnn -> InstrAbstract op
GE Parser (VarAnn -> ParsedInstr)
-> ReaderT LetEnv (Parsec CustomParserException Text) VarAnn
-> Parser ParsedInstr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ReaderT LetEnv (Parsec CustomParserException Text) VarAnn
forall tag. KnownAnnTag tag => Parser (Annotation tag)
noteDef

-- ad-hoc comparison

compareOp :: Parser ParsedInstr
compareOp :: Parser ParsedInstr
compareOp = Tokens Text
-> (VarAnn -> ParsedInstr) -> Parser (VarAnn -> ParsedInstr)
forall a. Tokens Text -> a -> Parser a
word' "COMPARE" VarAnn -> ParsedInstr
forall op. VarAnn -> InstrAbstract op
COMPARE Parser (VarAnn -> ParsedInstr)
-> ReaderT LetEnv (Parsec CustomParserException Text) VarAnn
-> Parser ParsedInstr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ReaderT LetEnv (Parsec CustomParserException Text) VarAnn
forall tag. KnownAnnTag tag => Parser (Annotation tag)
noteDef

-- Operations on booleans

orOp :: Parser ParsedInstr
orOp :: Parser ParsedInstr
orOp = Tokens Text
-> (VarAnn -> ParsedInstr) -> Parser (VarAnn -> ParsedInstr)
forall a. Tokens Text -> a -> Parser a
word' "OR"  VarAnn -> ParsedInstr
forall op. VarAnn -> InstrAbstract op
OR Parser (VarAnn -> ParsedInstr)
-> ReaderT LetEnv (Parsec CustomParserException Text) VarAnn
-> Parser ParsedInstr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ReaderT LetEnv (Parsec CustomParserException Text) VarAnn
forall tag. KnownAnnTag tag => Parser (Annotation tag)
noteDef

andOp :: Parser ParsedInstr
andOp :: Parser ParsedInstr
andOp = Tokens Text
-> (VarAnn -> ParsedInstr) -> Parser (VarAnn -> ParsedInstr)
forall a. Tokens Text -> a -> Parser a
word' "AND" VarAnn -> ParsedInstr
forall op. VarAnn -> InstrAbstract op
AND Parser (VarAnn -> ParsedInstr)
-> ReaderT LetEnv (Parsec CustomParserException Text) VarAnn
-> Parser ParsedInstr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ReaderT LetEnv (Parsec CustomParserException Text) VarAnn
forall tag. KnownAnnTag tag => Parser (Annotation tag)
noteDef

xorOp :: Parser ParsedInstr
xorOp :: Parser ParsedInstr
xorOp = Tokens Text
-> (VarAnn -> ParsedInstr) -> Parser (VarAnn -> ParsedInstr)
forall a. Tokens Text -> a -> Parser a
word' "XOR" VarAnn -> ParsedInstr
forall op. VarAnn -> InstrAbstract op
XOR Parser (VarAnn -> ParsedInstr)
-> ReaderT LetEnv (Parsec CustomParserException Text) VarAnn
-> Parser ParsedInstr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ReaderT LetEnv (Parsec CustomParserException Text) VarAnn
forall tag. KnownAnnTag tag => Parser (Annotation tag)
noteDef

notOp :: Parser ParsedInstr
notOp :: Parser ParsedInstr
notOp = Tokens Text
-> (VarAnn -> ParsedInstr) -> Parser (VarAnn -> ParsedInstr)
forall a. Tokens Text -> a -> Parser a
word' "NOT" VarAnn -> ParsedInstr
forall op. VarAnn -> InstrAbstract op
NOT Parser (VarAnn -> ParsedInstr)
-> ReaderT LetEnv (Parsec CustomParserException Text) VarAnn
-> Parser ParsedInstr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ReaderT LetEnv (Parsec CustomParserException Text) VarAnn
forall tag. KnownAnnTag tag => Parser (Annotation tag)
noteDef

-- Operations on integers and natural numbers

addOp :: Parser ParsedInstr
addOp :: Parser ParsedInstr
addOp = Tokens Text
-> (VarAnn -> ParsedInstr) -> Parser (VarAnn -> ParsedInstr)
forall a. Tokens Text -> a -> Parser a
word' "ADD" VarAnn -> ParsedInstr
forall op. VarAnn -> InstrAbstract op
ADD Parser (VarAnn -> ParsedInstr)
-> ReaderT LetEnv (Parsec CustomParserException Text) VarAnn
-> Parser ParsedInstr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ReaderT LetEnv (Parsec CustomParserException Text) VarAnn
forall tag. KnownAnnTag tag => Parser (Annotation tag)
noteDef

subOp :: Parser ParsedInstr
subOp :: Parser ParsedInstr
subOp = Tokens Text
-> (VarAnn -> ParsedInstr) -> Parser (VarAnn -> ParsedInstr)
forall a. Tokens Text -> a -> Parser a
word' "SUB" VarAnn -> ParsedInstr
forall op. VarAnn -> InstrAbstract op
SUB Parser (VarAnn -> ParsedInstr)
-> ReaderT LetEnv (Parsec CustomParserException Text) VarAnn
-> Parser ParsedInstr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ReaderT LetEnv (Parsec CustomParserException Text) VarAnn
forall tag. KnownAnnTag tag => Parser (Annotation tag)
noteDef

mulOp :: Parser ParsedInstr
mulOp :: Parser ParsedInstr
mulOp = Tokens Text
-> (VarAnn -> ParsedInstr) -> Parser (VarAnn -> ParsedInstr)
forall a. Tokens Text -> a -> Parser a
word' "MUL" VarAnn -> ParsedInstr
forall op. VarAnn -> InstrAbstract op
MUL Parser (VarAnn -> ParsedInstr)
-> ReaderT LetEnv (Parsec CustomParserException Text) VarAnn
-> Parser ParsedInstr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ReaderT LetEnv (Parsec CustomParserException Text) VarAnn
forall tag. KnownAnnTag tag => Parser (Annotation tag)
noteDef

edivOp :: Parser ParsedInstr
edivOp :: Parser ParsedInstr
edivOp = Tokens Text
-> (VarAnn -> ParsedInstr) -> Parser (VarAnn -> ParsedInstr)
forall a. Tokens Text -> a -> Parser a
word' "EDIV"VarAnn -> ParsedInstr
forall op. VarAnn -> InstrAbstract op
EDIV Parser (VarAnn -> ParsedInstr)
-> ReaderT LetEnv (Parsec CustomParserException Text) VarAnn
-> Parser ParsedInstr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ReaderT LetEnv (Parsec CustomParserException Text) VarAnn
forall tag. KnownAnnTag tag => Parser (Annotation tag)
noteDef

absOp :: Parser ParsedInstr
absOp :: Parser ParsedInstr
absOp = Tokens Text
-> (VarAnn -> ParsedInstr) -> Parser (VarAnn -> ParsedInstr)
forall a. Tokens Text -> a -> Parser a
word' "ABS" VarAnn -> ParsedInstr
forall op. VarAnn -> InstrAbstract op
ABS Parser (VarAnn -> ParsedInstr)
-> ReaderT LetEnv (Parsec CustomParserException Text) VarAnn
-> Parser ParsedInstr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ReaderT LetEnv (Parsec CustomParserException Text) VarAnn
forall tag. KnownAnnTag tag => Parser (Annotation tag)
noteDef

negOp :: Parser ParsedInstr
negOp :: Parser ParsedInstr
negOp = Tokens Text
-> (VarAnn -> ParsedInstr) -> Parser (VarAnn -> ParsedInstr)
forall a. Tokens Text -> a -> Parser a
word' "NEG" VarAnn -> ParsedInstr
forall op. VarAnn -> InstrAbstract op
NEG Parser (VarAnn -> ParsedInstr)
-> ReaderT LetEnv (Parsec CustomParserException Text) VarAnn
-> Parser ParsedInstr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ReaderT LetEnv (Parsec CustomParserException Text) VarAnn
forall tag. KnownAnnTag tag => Parser (Annotation tag)
noteDef

-- Bitwise logical operators

lslOp :: Parser ParsedInstr
lslOp :: Parser ParsedInstr
lslOp = Tokens Text
-> (VarAnn -> ParsedInstr) -> Parser (VarAnn -> ParsedInstr)
forall a. Tokens Text -> a -> Parser a
word' "LSL" VarAnn -> ParsedInstr
forall op. VarAnn -> InstrAbstract op
LSL Parser (VarAnn -> ParsedInstr)
-> ReaderT LetEnv (Parsec CustomParserException Text) VarAnn
-> Parser ParsedInstr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ReaderT LetEnv (Parsec CustomParserException Text) VarAnn
forall tag. KnownAnnTag tag => Parser (Annotation tag)
noteDef

lsrOp :: Parser ParsedInstr
lsrOp :: Parser ParsedInstr
lsrOp = Tokens Text
-> (VarAnn -> ParsedInstr) -> Parser (VarAnn -> ParsedInstr)
forall a. Tokens Text -> a -> Parser a
word' "LSR" VarAnn -> ParsedInstr
forall op. VarAnn -> InstrAbstract op
LSR Parser (VarAnn -> ParsedInstr)
-> ReaderT LetEnv (Parsec CustomParserException Text) VarAnn
-> Parser ParsedInstr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ReaderT LetEnv (Parsec CustomParserException Text) VarAnn
forall tag. KnownAnnTag tag => Parser (Annotation tag)
noteDef

-- Operations on string's

concatOp :: Parser ParsedInstr
concatOp :: Parser ParsedInstr
concatOp = Tokens Text
-> (VarAnn -> ParsedInstr) -> Parser (VarAnn -> ParsedInstr)
forall a. Tokens Text -> a -> Parser a
word' "CONCAT" VarAnn -> ParsedInstr
forall op. VarAnn -> InstrAbstract op
CONCAT Parser (VarAnn -> ParsedInstr)
-> ReaderT LetEnv (Parsec CustomParserException Text) VarAnn
-> Parser ParsedInstr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ReaderT LetEnv (Parsec CustomParserException Text) VarAnn
forall tag. KnownAnnTag tag => Parser (Annotation tag)
noteDef

sliceOp :: Parser ParsedInstr
sliceOp :: Parser ParsedInstr
sliceOp = Tokens Text
-> (VarAnn -> ParsedInstr) -> Parser (VarAnn -> ParsedInstr)
forall a. Tokens Text -> a -> Parser a
word' "SLICE" VarAnn -> ParsedInstr
forall op. VarAnn -> InstrAbstract op
SLICE Parser (VarAnn -> ParsedInstr)
-> ReaderT LetEnv (Parsec CustomParserException Text) VarAnn
-> Parser ParsedInstr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ReaderT LetEnv (Parsec CustomParserException Text) VarAnn
forall tag. KnownAnnTag tag => Parser (Annotation tag)
noteDef

-- Operations on pairs
pairOp :: Parser ParsedInstr
pairOp :: Parser ParsedInstr
pairOp = do Text -> ReaderT LetEnv (Parsec CustomParserException Text) ()
symbol' "PAIR"; (t :: TypeAnn
t, v :: VarAnn
v, (p :: FieldAnn
p, q :: FieldAnn
q)) <- Parser (TypeAnn, VarAnn, (FieldAnn, FieldAnn))
notesTVF2; return $ TypeAnn -> VarAnn -> FieldAnn -> FieldAnn -> ParsedInstr
forall op.
TypeAnn -> VarAnn -> FieldAnn -> FieldAnn -> InstrAbstract op
PAIR TypeAnn
t VarAnn
v FieldAnn
p FieldAnn
q

carOp :: Parser ParsedInstr
carOp :: Parser ParsedInstr
carOp = do Text -> ReaderT LetEnv (Parsec CustomParserException Text) ()
symbol' "CAR"; (v :: VarAnn
v, f :: FieldAnn
f) <- Parser (VarAnn, FieldAnn)
notesVF; return $ VarAnn -> FieldAnn -> ParsedInstr
forall op. VarAnn -> FieldAnn -> InstrAbstract op
CAR VarAnn
v FieldAnn
f

cdrOp :: Parser ParsedInstr
cdrOp :: Parser ParsedInstr
cdrOp = do Text -> ReaderT LetEnv (Parsec CustomParserException Text) ()
symbol' "CDR"; (v :: VarAnn
v, f :: FieldAnn
f) <- Parser (VarAnn, FieldAnn)
notesVF; return $ VarAnn -> FieldAnn -> ParsedInstr
forall op. VarAnn -> FieldAnn -> InstrAbstract op
CDR VarAnn
v FieldAnn
f

-- Operations on collections (sets, maps, lists)

emptySetOp :: Parser ParsedInstr
emptySetOp :: Parser ParsedInstr
emptySetOp = do Text -> ReaderT LetEnv (Parsec CustomParserException Text) ()
symbol' "EMPTY_SET"; (t :: TypeAnn
t, v :: VarAnn
v) <- Parser (TypeAnn, VarAnn)
notesTV;
                TypeAnn -> VarAnn -> Type -> ParsedInstr
forall op. TypeAnn -> VarAnn -> Type -> InstrAbstract op
EMPTY_SET TypeAnn
t VarAnn
v (Type -> ParsedInstr)
-> ReaderT LetEnv (Parsec CustomParserException Text) Type
-> Parser ParsedInstr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ReaderT LetEnv (Parsec CustomParserException Text) Type
typeWithParen

emptyMapOp :: Parser ParsedInstr
emptyMapOp :: Parser ParsedInstr
emptyMapOp = do Text -> ReaderT LetEnv (Parsec CustomParserException Text) ()
symbol' "EMPTY_MAP"; (t :: TypeAnn
t, v :: VarAnn
v) <- Parser (TypeAnn, VarAnn)
notesTV; Type
a <- ReaderT LetEnv (Parsec CustomParserException Text) Type
typeWithParen;
                TypeAnn -> VarAnn -> Type -> Type -> ParsedInstr
forall op. TypeAnn -> VarAnn -> Type -> Type -> InstrAbstract op
EMPTY_MAP TypeAnn
t VarAnn
v Type
a (Type -> ParsedInstr)
-> ReaderT LetEnv (Parsec CustomParserException Text) Type
-> Parser ParsedInstr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ReaderT LetEnv (Parsec CustomParserException Text) Type
type_

emptyBigMapOp :: Parser ParsedInstr
emptyBigMapOp :: Parser ParsedInstr
emptyBigMapOp = do Text -> ReaderT LetEnv (Parsec CustomParserException Text) ()
symbol' "EMPTY_BIG_MAP"; (t :: TypeAnn
t, v :: VarAnn
v) <- Parser (TypeAnn, VarAnn)
notesTV; Type
a <- ReaderT LetEnv (Parsec CustomParserException Text) Type
typeWithParen;
                   TypeAnn -> VarAnn -> Type -> Type -> ParsedInstr
forall op. TypeAnn -> VarAnn -> Type -> Type -> InstrAbstract op
EMPTY_BIG_MAP TypeAnn
t VarAnn
v Type
a (Type -> ParsedInstr)
-> ReaderT LetEnv (Parsec CustomParserException Text) Type
-> Parser ParsedInstr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ReaderT LetEnv (Parsec CustomParserException Text) Type
type_

memOp :: Parser ParsedInstr
memOp :: Parser ParsedInstr
memOp = Tokens Text
-> (VarAnn -> ParsedInstr) -> Parser (VarAnn -> ParsedInstr)
forall a. Tokens Text -> a -> Parser a
word' "MEM" VarAnn -> ParsedInstr
forall op. VarAnn -> InstrAbstract op
MEM Parser (VarAnn -> ParsedInstr)
-> ReaderT LetEnv (Parsec CustomParserException Text) VarAnn
-> Parser ParsedInstr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ReaderT LetEnv (Parsec CustomParserException Text) VarAnn
forall tag. KnownAnnTag tag => Parser (Annotation tag)
noteDef

updateOp :: Parser ParsedInstr
updateOp :: Parser ParsedInstr
updateOp = Tokens Text
-> (VarAnn -> ParsedInstr) -> Parser (VarAnn -> ParsedInstr)
forall a. Tokens Text -> a -> Parser a
word' "UPDATE" VarAnn -> ParsedInstr
forall op. VarAnn -> InstrAbstract op
UPDATE Parser (VarAnn -> ParsedInstr)
-> ReaderT LetEnv (Parsec CustomParserException Text) VarAnn
-> Parser ParsedInstr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ReaderT LetEnv (Parsec CustomParserException Text) VarAnn
forall tag. KnownAnnTag tag => Parser (Annotation tag)
noteDef

iterOp :: Parser ParsedOp -> Parser ParsedInstr
iterOp :: Parser ParsedOp -> Parser ParsedInstr
iterOp opParser :: Parser ParsedOp
opParser = Tokens Text
-> ([ParsedOp] -> ParsedInstr)
-> Parser ([ParsedOp] -> ParsedInstr)
forall a. Tokens Text -> a -> Parser a
word' "ITER" [ParsedOp] -> ParsedInstr
forall op. [op] -> InstrAbstract op
ITER Parser ([ParsedOp] -> ParsedInstr)
-> Parser [ParsedOp] -> Parser ParsedInstr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser ParsedOp -> Parser [ParsedOp]
ops' Parser ParsedOp
opParser

sizeOp :: Parser ParsedInstr
sizeOp :: Parser ParsedInstr
sizeOp = Tokens Text
-> (VarAnn -> ParsedInstr) -> Parser (VarAnn -> ParsedInstr)
forall a. Tokens Text -> a -> Parser a
word' "SIZE" VarAnn -> ParsedInstr
forall op. VarAnn -> InstrAbstract op
SIZE Parser (VarAnn -> ParsedInstr)
-> ReaderT LetEnv (Parsec CustomParserException Text) VarAnn
-> Parser ParsedInstr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ReaderT LetEnv (Parsec CustomParserException Text) VarAnn
forall tag. KnownAnnTag tag => Parser (Annotation tag)
noteDef

mapOp :: Parser ParsedOp -> Parser ParsedInstr
mapOp :: Parser ParsedOp -> Parser ParsedInstr
mapOp opParser :: Parser ParsedOp
opParser = Tokens Text
-> (VarAnn -> [ParsedOp] -> ParsedInstr)
-> Parser (VarAnn -> [ParsedOp] -> ParsedInstr)
forall a. Tokens Text -> a -> Parser a
word' "MAP" VarAnn -> [ParsedOp] -> ParsedInstr
forall op. VarAnn -> [op] -> InstrAbstract op
MAP Parser (VarAnn -> [ParsedOp] -> ParsedInstr)
-> ReaderT LetEnv (Parsec CustomParserException Text) VarAnn
-> Parser ([ParsedOp] -> ParsedInstr)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*>  ReaderT LetEnv (Parsec CustomParserException Text) VarAnn
forall tag. KnownAnnTag tag => Parser (Annotation tag)
noteDef Parser ([ParsedOp] -> ParsedInstr)
-> Parser [ParsedOp] -> Parser ParsedInstr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser ParsedOp -> Parser [ParsedOp]
ops' Parser ParsedOp
opParser

getOp :: Parser ParsedInstr
getOp :: Parser ParsedInstr
getOp = Tokens Text
-> (VarAnn -> ParsedInstr) -> Parser (VarAnn -> ParsedInstr)
forall a. Tokens Text -> a -> Parser a
word' "GET" VarAnn -> ParsedInstr
forall op. VarAnn -> InstrAbstract op
GET Parser (VarAnn -> ParsedInstr)
-> ReaderT LetEnv (Parsec CustomParserException Text) VarAnn
-> Parser ParsedInstr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ReaderT LetEnv (Parsec CustomParserException Text) VarAnn
forall tag. KnownAnnTag tag => Parser (Annotation tag)
noteDef

nilOp :: Parser ParsedInstr
nilOp :: Parser ParsedInstr
nilOp = do Text -> ReaderT LetEnv (Parsec CustomParserException Text) ()
symbol' "NIL"; (t :: TypeAnn
t, v :: VarAnn
v) <- Parser (TypeAnn, VarAnn)
notesTV; TypeAnn -> VarAnn -> Type -> ParsedInstr
forall op. TypeAnn -> VarAnn -> Type -> InstrAbstract op
NIL TypeAnn
t VarAnn
v (Type -> ParsedInstr)
-> ReaderT LetEnv (Parsec CustomParserException Text) Type
-> Parser ParsedInstr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ReaderT LetEnv (Parsec CustomParserException Text) Type
type_

consOp :: Parser ParsedInstr
consOp :: Parser ParsedInstr
consOp = do
  ReaderT LetEnv (Parsec CustomParserException Text) ()
-> ReaderT LetEnv (Parsec CustomParserException Text) ()
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try (ReaderT LetEnv (Parsec CustomParserException Text) ()
 -> ReaderT LetEnv (Parsec CustomParserException Text) ())
-> (ReaderT LetEnv (Parsec CustomParserException Text) ()
    -> ReaderT LetEnv (Parsec CustomParserException Text) ())
-> ReaderT LetEnv (Parsec CustomParserException Text) ()
-> ReaderT LetEnv (Parsec CustomParserException Text) ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ReaderT LetEnv (Parsec CustomParserException Text) ()
-> ReaderT LetEnv (Parsec CustomParserException Text) ()
forall a. Parser a -> Parser a
lexeme (ReaderT LetEnv (Parsec CustomParserException Text) ()
 -> ReaderT LetEnv (Parsec CustomParserException Text) ())
-> ReaderT LetEnv (Parsec CustomParserException Text) ()
-> ReaderT LetEnv (Parsec CustomParserException Text) ()
forall a b. (a -> b) -> a -> b
$ do
    ReaderT LetEnv (Parsec CustomParserException Text) Text
-> ReaderT LetEnv (Parsec CustomParserException Text) ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (ReaderT LetEnv (Parsec CustomParserException Text) Text
 -> ReaderT LetEnv (Parsec CustomParserException Text) ())
-> ReaderT LetEnv (Parsec CustomParserException Text) Text
-> ReaderT LetEnv (Parsec CustomParserException Text) ()
forall a b. (a -> b) -> a -> b
$ Text -> ReaderT LetEnv (Parsec CustomParserException Text) Text
forall e s (f :: * -> *).
(MonadParsec e s f, Tokens s ~ Text) =>
Text -> f Text
string' "CONS"
    ReaderT LetEnv (Parsec CustomParserException Text) Text
-> ReaderT LetEnv (Parsec CustomParserException Text) ()
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m ()
notFollowedBy (Text -> ReaderT LetEnv (Parsec CustomParserException Text) Text
forall e s (f :: * -> *).
(MonadParsec e s f, Tokens s ~ Text) =>
Text -> f Text
string' "T")
  VarAnn -> ParsedInstr
forall op. VarAnn -> InstrAbstract op
CONS (VarAnn -> ParsedInstr)
-> ReaderT LetEnv (Parsec CustomParserException Text) VarAnn
-> Parser ParsedInstr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ReaderT LetEnv (Parsec CustomParserException Text) VarAnn
forall tag. KnownAnnTag tag => Parser (Annotation tag)
noteDef

ifConsOp :: Parser ParsedOp -> Parser ParsedInstr
ifConsOp :: Parser ParsedOp -> Parser ParsedInstr
ifConsOp opParser :: Parser ParsedOp
opParser = Tokens Text
-> ([ParsedOp] -> [ParsedOp] -> ParsedInstr)
-> Parser ([ParsedOp] -> [ParsedOp] -> ParsedInstr)
forall a. Tokens Text -> a -> Parser a
word' "IF_CONS" [ParsedOp] -> [ParsedOp] -> ParsedInstr
forall op. [op] -> [op] -> InstrAbstract op
IF_CONS Parser ([ParsedOp] -> [ParsedOp] -> ParsedInstr)
-> Parser [ParsedOp] -> Parser ([ParsedOp] -> ParsedInstr)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser ParsedOp -> Parser [ParsedOp]
ops' Parser ParsedOp
opParser Parser ([ParsedOp] -> ParsedInstr)
-> Parser [ParsedOp] -> Parser ParsedInstr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser ParsedOp -> Parser [ParsedOp]
ops' Parser ParsedOp
opParser

-- Operations on options

someOp :: Parser ParsedInstr
someOp :: Parser ParsedInstr
someOp = do Text -> ReaderT LetEnv (Parsec CustomParserException Text) ()
symbol' "SOME"; (t :: TypeAnn
t, v :: VarAnn
v) <- Parser (TypeAnn, VarAnn)
notesTV; return $ TypeAnn -> VarAnn -> ParsedInstr
forall op. TypeAnn -> VarAnn -> InstrAbstract op
SOME TypeAnn
t VarAnn
v

noneOp :: Parser ParsedInstr
noneOp :: Parser ParsedInstr
noneOp = do Text -> ReaderT LetEnv (Parsec CustomParserException Text) ()
symbol' "NONE"; (t :: TypeAnn
t, v :: VarAnn
v) <- Parser (TypeAnn, VarAnn)
notesTV; TypeAnn -> VarAnn -> Type -> ParsedInstr
forall op. TypeAnn -> VarAnn -> Type -> InstrAbstract op
NONE TypeAnn
t VarAnn
v (Type -> ParsedInstr)
-> ReaderT LetEnv (Parsec CustomParserException Text) Type
-> Parser ParsedInstr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ReaderT LetEnv (Parsec CustomParserException Text) Type
type_

ifNoneOp :: Parser ParsedOp -> Parser ParsedInstr
ifNoneOp :: Parser ParsedOp -> Parser ParsedInstr
ifNoneOp opParser :: Parser ParsedOp
opParser = Tokens Text
-> ([ParsedOp] -> [ParsedOp] -> ParsedInstr)
-> Parser ([ParsedOp] -> [ParsedOp] -> ParsedInstr)
forall a. Tokens Text -> a -> Parser a
word' "IF_NONE" [ParsedOp] -> [ParsedOp] -> ParsedInstr
forall op. [op] -> [op] -> InstrAbstract op
IF_NONE Parser ([ParsedOp] -> [ParsedOp] -> ParsedInstr)
-> Parser [ParsedOp] -> Parser ([ParsedOp] -> ParsedInstr)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser ParsedOp -> Parser [ParsedOp]
ops' Parser ParsedOp
opParser Parser ([ParsedOp] -> ParsedInstr)
-> Parser [ParsedOp] -> Parser ParsedInstr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser ParsedOp -> Parser [ParsedOp]
ops' Parser ParsedOp
opParser

-- Operations on unions

leftOp :: Parser ParsedInstr
leftOp :: Parser ParsedInstr
leftOp = do Text -> ReaderT LetEnv (Parsec CustomParserException Text) ()
symbol' "LEFT"; (t :: TypeAnn
t, v :: VarAnn
v, (f :: FieldAnn
f, f' :: FieldAnn
f')) <- Parser (TypeAnn, VarAnn, (FieldAnn, FieldAnn))
notesTVF2;
               TypeAnn -> VarAnn -> FieldAnn -> FieldAnn -> Type -> ParsedInstr
forall op.
TypeAnn
-> VarAnn -> FieldAnn -> FieldAnn -> Type -> InstrAbstract op
LEFT TypeAnn
t VarAnn
v FieldAnn
f FieldAnn
f' (Type -> ParsedInstr)
-> ReaderT LetEnv (Parsec CustomParserException Text) Type
-> Parser ParsedInstr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ReaderT LetEnv (Parsec CustomParserException Text) Type
type_

rightOp :: Parser ParsedInstr
rightOp :: Parser ParsedInstr
rightOp = do Text -> ReaderT LetEnv (Parsec CustomParserException Text) ()
symbol' "RIGHT"; (t :: TypeAnn
t, v :: VarAnn
v, (f :: FieldAnn
f, f' :: FieldAnn
f')) <- Parser (TypeAnn, VarAnn, (FieldAnn, FieldAnn))
notesTVF2;
               TypeAnn -> VarAnn -> FieldAnn -> FieldAnn -> Type -> ParsedInstr
forall op.
TypeAnn
-> VarAnn -> FieldAnn -> FieldAnn -> Type -> InstrAbstract op
RIGHT TypeAnn
t VarAnn
v FieldAnn
f FieldAnn
f' (Type -> ParsedInstr)
-> ReaderT LetEnv (Parsec CustomParserException Text) Type
-> Parser ParsedInstr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ReaderT LetEnv (Parsec CustomParserException Text) Type
type_

ifLeftOp :: Parser ParsedOp -> Parser ParsedInstr
ifLeftOp :: Parser ParsedOp -> Parser ParsedInstr
ifLeftOp opParser :: Parser ParsedOp
opParser = Tokens Text
-> ([ParsedOp] -> [ParsedOp] -> ParsedInstr)
-> Parser ([ParsedOp] -> [ParsedOp] -> ParsedInstr)
forall a. Tokens Text -> a -> Parser a
word' "IF_LEFT" [ParsedOp] -> [ParsedOp] -> ParsedInstr
forall op. [op] -> [op] -> InstrAbstract op
IF_LEFT Parser ([ParsedOp] -> [ParsedOp] -> ParsedInstr)
-> Parser [ParsedOp] -> Parser ([ParsedOp] -> ParsedInstr)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser ParsedOp -> Parser [ParsedOp]
ops' Parser ParsedOp
opParser Parser ([ParsedOp] -> ParsedInstr)
-> Parser [ParsedOp] -> Parser ParsedInstr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser ParsedOp -> Parser [ParsedOp]
ops' Parser ParsedOp
opParser

-- Operations on contracts

createContractOp :: Parser (Contract' ParsedOp) -> Parser ParsedInstr
createContractOp :: Parser (Contract' ParsedOp) -> Parser ParsedInstr
createContractOp contractParser :: Parser (Contract' ParsedOp)
contractParser =
  Tokens Text
-> (VarAnn -> VarAnn -> Contract' ParsedOp -> ParsedInstr)
-> Parser (VarAnn -> VarAnn -> Contract' ParsedOp -> ParsedInstr)
forall a. Tokens Text -> a -> Parser a
word' "CREATE_CONTRACT" VarAnn -> VarAnn -> Contract' ParsedOp -> ParsedInstr
forall op. VarAnn -> VarAnn -> Contract' op -> InstrAbstract op
CREATE_CONTRACT
    Parser (VarAnn -> VarAnn -> Contract' ParsedOp -> ParsedInstr)
-> ReaderT LetEnv (Parsec CustomParserException Text) VarAnn
-> ReaderT
     LetEnv
     (Parsec CustomParserException Text)
     (VarAnn -> Contract' ParsedOp -> ParsedInstr)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ReaderT LetEnv (Parsec CustomParserException Text) VarAnn
forall tag. KnownAnnTag tag => Parser (Annotation tag)
noteDef ReaderT
  LetEnv
  (Parsec CustomParserException Text)
  (VarAnn -> Contract' ParsedOp -> ParsedInstr)
-> ReaderT LetEnv (Parsec CustomParserException Text) VarAnn
-> ReaderT
     LetEnv
     (Parsec CustomParserException Text)
     (Contract' ParsedOp -> ParsedInstr)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ReaderT LetEnv (Parsec CustomParserException Text) VarAnn
forall tag. KnownAnnTag tag => Parser (Annotation tag)
noteDef ReaderT
  LetEnv
  (Parsec CustomParserException Text)
  (Contract' ParsedOp -> ParsedInstr)
-> Parser (Contract' ParsedOp) -> Parser ParsedInstr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser (Contract' ParsedOp) -> Parser (Contract' ParsedOp)
forall a. Parser a -> Parser a
braces Parser (Contract' ParsedOp)
contractParser

transferTokensOp :: Parser ParsedInstr
transferTokensOp :: Parser ParsedInstr
transferTokensOp = Tokens Text
-> (VarAnn -> ParsedInstr) -> Parser (VarAnn -> ParsedInstr)
forall a. Tokens Text -> a -> Parser a
word' "TRANSFER_TOKENS" VarAnn -> ParsedInstr
forall op. VarAnn -> InstrAbstract op
TRANSFER_TOKENS Parser (VarAnn -> ParsedInstr)
-> ReaderT LetEnv (Parsec CustomParserException Text) VarAnn
-> Parser ParsedInstr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ReaderT LetEnv (Parsec CustomParserException Text) VarAnn
forall tag. KnownAnnTag tag => Parser (Annotation tag)
noteDef

setDelegateOp :: Parser ParsedInstr
setDelegateOp :: Parser ParsedInstr
setDelegateOp = Tokens Text
-> (VarAnn -> ParsedInstr) -> Parser (VarAnn -> ParsedInstr)
forall a. Tokens Text -> a -> Parser a
word' "SET_DELEGATE" VarAnn -> ParsedInstr
forall op. VarAnn -> InstrAbstract op
SET_DELEGATE Parser (VarAnn -> ParsedInstr)
-> ReaderT LetEnv (Parsec CustomParserException Text) VarAnn
-> Parser ParsedInstr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ReaderT LetEnv (Parsec CustomParserException Text) VarAnn
forall tag. KnownAnnTag tag => Parser (Annotation tag)
noteDef

balanceOp :: Parser ParsedInstr
balanceOp :: Parser ParsedInstr
balanceOp = Tokens Text
-> (VarAnn -> ParsedInstr) -> Parser (VarAnn -> ParsedInstr)
forall a. Tokens Text -> a -> Parser a
word' "BALANCE" VarAnn -> ParsedInstr
forall op. VarAnn -> InstrAbstract op
BALANCE Parser (VarAnn -> ParsedInstr)
-> ReaderT LetEnv (Parsec CustomParserException Text) VarAnn
-> Parser ParsedInstr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ReaderT LetEnv (Parsec CustomParserException Text) VarAnn
forall tag. KnownAnnTag tag => Parser (Annotation tag)
noteDef

contractOp :: Parser ParsedInstr
contractOp :: Parser ParsedInstr
contractOp = Tokens Text
-> (VarAnn -> FieldAnn -> Type -> ParsedInstr)
-> Parser (VarAnn -> FieldAnn -> Type -> ParsedInstr)
forall a. Tokens Text -> a -> Parser a
word' "CONTRACT" VarAnn -> FieldAnn -> Type -> ParsedInstr
forall op. VarAnn -> FieldAnn -> Type -> InstrAbstract op
CONTRACT Parser (VarAnn -> FieldAnn -> Type -> ParsedInstr)
-> ReaderT LetEnv (Parsec CustomParserException Text) VarAnn
-> ReaderT
     LetEnv
     (Parsec CustomParserException Text)
     (FieldAnn -> Type -> ParsedInstr)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ReaderT LetEnv (Parsec CustomParserException Text) VarAnn
forall tag. KnownAnnTag tag => Parser (Annotation tag)
noteDef ReaderT
  LetEnv
  (Parsec CustomParserException Text)
  (FieldAnn -> Type -> ParsedInstr)
-> ReaderT LetEnv (Parsec CustomParserException Text) FieldAnn
-> ReaderT
     LetEnv (Parsec CustomParserException Text) (Type -> ParsedInstr)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ReaderT LetEnv (Parsec CustomParserException Text) FieldAnn
forall tag. KnownAnnTag tag => Parser (Annotation tag)
noteDef ReaderT
  LetEnv (Parsec CustomParserException Text) (Type -> ParsedInstr)
-> ReaderT LetEnv (Parsec CustomParserException Text) Type
-> Parser ParsedInstr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ReaderT LetEnv (Parsec CustomParserException Text) Type
type_

sourceOp :: Parser ParsedInstr
sourceOp :: Parser ParsedInstr
sourceOp = Tokens Text
-> (VarAnn -> ParsedInstr) -> Parser (VarAnn -> ParsedInstr)
forall a. Tokens Text -> a -> Parser a
word' "SOURCE" VarAnn -> ParsedInstr
forall op. VarAnn -> InstrAbstract op
SOURCE Parser (VarAnn -> ParsedInstr)
-> ReaderT LetEnv (Parsec CustomParserException Text) VarAnn
-> Parser ParsedInstr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ReaderT LetEnv (Parsec CustomParserException Text) VarAnn
forall tag. KnownAnnTag tag => Parser (Annotation tag)
noteDef

senderOp :: Parser ParsedInstr
senderOp :: Parser ParsedInstr
senderOp = Tokens Text
-> (VarAnn -> ParsedInstr) -> Parser (VarAnn -> ParsedInstr)
forall a. Tokens Text -> a -> Parser a
word' "SENDER" VarAnn -> ParsedInstr
forall op. VarAnn -> InstrAbstract op
SENDER Parser (VarAnn -> ParsedInstr)
-> ReaderT LetEnv (Parsec CustomParserException Text) VarAnn
-> Parser ParsedInstr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ReaderT LetEnv (Parsec CustomParserException Text) VarAnn
forall tag. KnownAnnTag tag => Parser (Annotation tag)
noteDef

amountOp :: Parser ParsedInstr
amountOp :: Parser ParsedInstr
amountOp = Tokens Text
-> (VarAnn -> ParsedInstr) -> Parser (VarAnn -> ParsedInstr)
forall a. Tokens Text -> a -> Parser a
word' "AMOUNT" VarAnn -> ParsedInstr
forall op. VarAnn -> InstrAbstract op
AMOUNT Parser (VarAnn -> ParsedInstr)
-> ReaderT LetEnv (Parsec CustomParserException Text) VarAnn
-> Parser ParsedInstr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ReaderT LetEnv (Parsec CustomParserException Text) VarAnn
forall tag. KnownAnnTag tag => Parser (Annotation tag)
noteDef

implicitAccountOp :: Parser ParsedInstr
implicitAccountOp :: Parser ParsedInstr
implicitAccountOp = Tokens Text
-> (VarAnn -> ParsedInstr) -> Parser (VarAnn -> ParsedInstr)
forall a. Tokens Text -> a -> Parser a
word' "IMPLICIT_ACCOUNT" VarAnn -> ParsedInstr
forall op. VarAnn -> InstrAbstract op
IMPLICIT_ACCOUNT Parser (VarAnn -> ParsedInstr)
-> ReaderT LetEnv (Parsec CustomParserException Text) VarAnn
-> Parser ParsedInstr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ReaderT LetEnv (Parsec CustomParserException Text) VarAnn
forall tag. KnownAnnTag tag => Parser (Annotation tag)
noteDef

selfOp :: Parser ParsedInstr
selfOp :: Parser ParsedInstr
selfOp = Tokens Text
-> (VarAnn -> FieldAnn -> ParsedInstr)
-> Parser (VarAnn -> FieldAnn -> ParsedInstr)
forall a. Tokens Text -> a -> Parser a
word' "SELF" VarAnn -> FieldAnn -> ParsedInstr
forall op. VarAnn -> FieldAnn -> InstrAbstract op
SELF Parser (VarAnn -> FieldAnn -> ParsedInstr)
-> ReaderT LetEnv (Parsec CustomParserException Text) VarAnn
-> ReaderT
     LetEnv
     (Parsec CustomParserException Text)
     (FieldAnn -> ParsedInstr)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ReaderT LetEnv (Parsec CustomParserException Text) VarAnn
forall tag. KnownAnnTag tag => Parser (Annotation tag)
noteDef ReaderT
  LetEnv
  (Parsec CustomParserException Text)
  (FieldAnn -> ParsedInstr)
-> ReaderT LetEnv (Parsec CustomParserException Text) FieldAnn
-> Parser ParsedInstr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ReaderT LetEnv (Parsec CustomParserException Text) FieldAnn
forall tag. KnownAnnTag tag => Parser (Annotation tag)
noteDef

addressOp :: Parser ParsedInstr
addressOp :: Parser ParsedInstr
addressOp = Tokens Text
-> (VarAnn -> ParsedInstr) -> Parser (VarAnn -> ParsedInstr)
forall a. Tokens Text -> a -> Parser a
word' "ADDRESS" VarAnn -> ParsedInstr
forall op. VarAnn -> InstrAbstract op
ADDRESS Parser (VarAnn -> ParsedInstr)
-> ReaderT LetEnv (Parsec CustomParserException Text) VarAnn
-> Parser ParsedInstr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ReaderT LetEnv (Parsec CustomParserException Text) VarAnn
forall tag. KnownAnnTag tag => Parser (Annotation tag)
noteDef

-- Special Operations

nowOp :: Parser ParsedInstr
nowOp :: Parser ParsedInstr
nowOp = Tokens Text
-> (VarAnn -> ParsedInstr) -> Parser (VarAnn -> ParsedInstr)
forall a. Tokens Text -> a -> Parser a
word' "NOW" VarAnn -> ParsedInstr
forall op. VarAnn -> InstrAbstract op
NOW Parser (VarAnn -> ParsedInstr)
-> ReaderT LetEnv (Parsec CustomParserException Text) VarAnn
-> Parser ParsedInstr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ReaderT LetEnv (Parsec CustomParserException Text) VarAnn
forall tag. KnownAnnTag tag => Parser (Annotation tag)
noteDef

chainIdOp :: Parser ParsedInstr
chainIdOp :: Parser ParsedInstr
chainIdOp = Tokens Text
-> (VarAnn -> ParsedInstr) -> Parser (VarAnn -> ParsedInstr)
forall a. Tokens Text -> a -> Parser a
word' "CHAIN_ID" VarAnn -> ParsedInstr
forall op. VarAnn -> InstrAbstract op
CHAIN_ID Parser (VarAnn -> ParsedInstr)
-> ReaderT LetEnv (Parsec CustomParserException Text) VarAnn
-> Parser ParsedInstr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ReaderT LetEnv (Parsec CustomParserException Text) VarAnn
forall tag. KnownAnnTag tag => Parser (Annotation tag)
noteDef

-- Operations on bytes

packOp :: Parser ParsedInstr
packOp :: Parser ParsedInstr
packOp = Tokens Text
-> (VarAnn -> ParsedInstr) -> Parser (VarAnn -> ParsedInstr)
forall a. Tokens Text -> a -> Parser a
word' "PACK" VarAnn -> ParsedInstr
forall op. VarAnn -> InstrAbstract op
PACK Parser (VarAnn -> ParsedInstr)
-> ReaderT LetEnv (Parsec CustomParserException Text) VarAnn
-> Parser ParsedInstr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ReaderT LetEnv (Parsec CustomParserException Text) VarAnn
forall tag. KnownAnnTag tag => Parser (Annotation tag)
noteDef

unpackOp :: Parser ParsedInstr
unpackOp :: Parser ParsedInstr
unpackOp = do Text -> ReaderT LetEnv (Parsec CustomParserException Text) ()
symbol' "UNPACK"; (t :: TypeAnn
t, v :: VarAnn
v) <- Parser (TypeAnn, VarAnn)
notesTV; TypeAnn -> VarAnn -> Type -> ParsedInstr
forall op. TypeAnn -> VarAnn -> Type -> InstrAbstract op
UNPACK TypeAnn
t VarAnn
v (Type -> ParsedInstr)
-> ReaderT LetEnv (Parsec CustomParserException Text) Type
-> Parser ParsedInstr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ReaderT LetEnv (Parsec CustomParserException Text) Type
type_

-- Cryptographic Primitives

checkSigOp :: Parser ParsedInstr
checkSigOp :: Parser ParsedInstr
checkSigOp = Tokens Text
-> (VarAnn -> ParsedInstr) -> Parser (VarAnn -> ParsedInstr)
forall a. Tokens Text -> a -> Parser a
word' "CHECK_SIGNATURE" VarAnn -> ParsedInstr
forall op. VarAnn -> InstrAbstract op
CHECK_SIGNATURE Parser (VarAnn -> ParsedInstr)
-> ReaderT LetEnv (Parsec CustomParserException Text) VarAnn
-> Parser ParsedInstr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ReaderT LetEnv (Parsec CustomParserException Text) VarAnn
forall tag. KnownAnnTag tag => Parser (Annotation tag)
noteDef

blake2BOp :: Parser ParsedInstr
blake2BOp :: Parser ParsedInstr
blake2BOp = Tokens Text
-> (VarAnn -> ParsedInstr) -> Parser (VarAnn -> ParsedInstr)
forall a. Tokens Text -> a -> Parser a
word' "BLAKE2B" VarAnn -> ParsedInstr
forall op. VarAnn -> InstrAbstract op
BLAKE2B Parser (VarAnn -> ParsedInstr)
-> ReaderT LetEnv (Parsec CustomParserException Text) VarAnn
-> Parser ParsedInstr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ReaderT LetEnv (Parsec CustomParserException Text) VarAnn
forall tag. KnownAnnTag tag => Parser (Annotation tag)
noteDef

sha256Op :: Parser ParsedInstr
sha256Op :: Parser ParsedInstr
sha256Op = Tokens Text
-> (VarAnn -> ParsedInstr) -> Parser (VarAnn -> ParsedInstr)
forall a. Tokens Text -> a -> Parser a
word' "SHA256" VarAnn -> ParsedInstr
forall op. VarAnn -> InstrAbstract op
SHA256 Parser (VarAnn -> ParsedInstr)
-> ReaderT LetEnv (Parsec CustomParserException Text) VarAnn
-> Parser ParsedInstr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ReaderT LetEnv (Parsec CustomParserException Text) VarAnn
forall tag. KnownAnnTag tag => Parser (Annotation tag)
noteDef

sha512Op :: Parser ParsedInstr
sha512Op :: Parser ParsedInstr
sha512Op = Tokens Text
-> (VarAnn -> ParsedInstr) -> Parser (VarAnn -> ParsedInstr)
forall a. Tokens Text -> a -> Parser a
word' "SHA512" VarAnn -> ParsedInstr
forall op. VarAnn -> InstrAbstract op
SHA512 Parser (VarAnn -> ParsedInstr)
-> ReaderT LetEnv (Parsec CustomParserException Text) VarAnn
-> Parser ParsedInstr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ReaderT LetEnv (Parsec CustomParserException Text) VarAnn
forall tag. KnownAnnTag tag => Parser (Annotation tag)
noteDef

hashKeyOp :: Parser ParsedInstr
hashKeyOp :: Parser ParsedInstr
hashKeyOp = Tokens Text
-> (VarAnn -> ParsedInstr) -> Parser (VarAnn -> ParsedInstr)
forall a. Tokens Text -> a -> Parser a
word' "HASH_KEY" VarAnn -> ParsedInstr
forall op. VarAnn -> InstrAbstract op
HASH_KEY Parser (VarAnn -> ParsedInstr)
-> ReaderT LetEnv (Parsec CustomParserException Text) VarAnn
-> Parser ParsedInstr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ReaderT LetEnv (Parsec CustomParserException Text) VarAnn
forall tag. KnownAnnTag tag => Parser (Annotation tag)
noteDef

-- Type operations

castOp :: Parser ParsedInstr
castOp :: Parser ParsedInstr
castOp = Tokens Text
-> (VarAnn -> Type -> ParsedInstr)
-> Parser (VarAnn -> Type -> ParsedInstr)
forall a. Tokens Text -> a -> Parser a
word' "CAST" VarAnn -> Type -> ParsedInstr
forall op. VarAnn -> Type -> InstrAbstract op
CAST Parser (VarAnn -> Type -> ParsedInstr)
-> ReaderT LetEnv (Parsec CustomParserException Text) VarAnn
-> ReaderT
     LetEnv (Parsec CustomParserException Text) (Type -> ParsedInstr)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ReaderT LetEnv (Parsec CustomParserException Text) VarAnn
forall tag. KnownAnnTag tag => Parser (Annotation tag)
noteDef ReaderT
  LetEnv (Parsec CustomParserException Text) (Type -> ParsedInstr)
-> ReaderT LetEnv (Parsec CustomParserException Text) Type
-> Parser ParsedInstr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ReaderT LetEnv (Parsec CustomParserException Text) Type
type_

renameOp :: Parser ParsedInstr
renameOp :: Parser ParsedInstr
renameOp = Tokens Text
-> (VarAnn -> ParsedInstr) -> Parser (VarAnn -> ParsedInstr)
forall a. Tokens Text -> a -> Parser a
word' "RENAME" VarAnn -> ParsedInstr
forall op. VarAnn -> InstrAbstract op
RENAME Parser (VarAnn -> ParsedInstr)
-> ReaderT LetEnv (Parsec CustomParserException Text) VarAnn
-> Parser ParsedInstr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ReaderT LetEnv (Parsec CustomParserException Text) VarAnn
forall tag. KnownAnnTag tag => Parser (Annotation tag)
noteDef

isNatOp :: Parser ParsedInstr
isNatOp :: Parser ParsedInstr
isNatOp = Tokens Text
-> (VarAnn -> ParsedInstr) -> Parser (VarAnn -> ParsedInstr)
forall a. Tokens Text -> a -> Parser a
word' "ISNAT" VarAnn -> ParsedInstr
forall op. VarAnn -> InstrAbstract op
ISNAT Parser (VarAnn -> ParsedInstr)
-> ReaderT LetEnv (Parsec CustomParserException Text) VarAnn
-> Parser ParsedInstr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ReaderT LetEnv (Parsec CustomParserException Text) VarAnn
forall tag. KnownAnnTag tag => Parser (Annotation tag)
noteDef

intOp :: Parser ParsedInstr
intOp :: Parser ParsedInstr
intOp = Tokens Text
-> (VarAnn -> ParsedInstr) -> Parser (VarAnn -> ParsedInstr)
forall a. Tokens Text -> a -> Parser a
word' "INT" VarAnn -> ParsedInstr
forall op. VarAnn -> InstrAbstract op
INT Parser (VarAnn -> ParsedInstr)
-> ReaderT LetEnv (Parsec CustomParserException Text) VarAnn
-> Parser ParsedInstr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ReaderT LetEnv (Parsec CustomParserException Text) VarAnn
forall tag. KnownAnnTag tag => Parser (Annotation tag)
noteDef