-- SPDX-FileCopyrightText: 2021 Oxhead Alpha
-- SPDX-License-Identifier: LicenseRef-MIT-OA

-- TODO [#712]: Remove this next major release
{-# OPTIONS_GHC -Wno-deprecations -Wno-redundant-constraints #-}

-- | Parsing of Michelson instructions.

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

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

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

import Morley.Michelson.Let (LetValue(..))
import Morley.Michelson.Macro (ParsedInstr, ParsedOp(..))
import Morley.Michelson.Parser.Annotations
import Morley.Michelson.Parser.Common
import Morley.Michelson.Parser.Lexer
import Morley.Michelson.Parser.Type
import Morley.Michelson.Parser.Types (LetEnv, Parser, Parser', letValues, withLetEnv)
import Morley.Michelson.Parser.Value
import Morley.Michelson.Untyped

-- | Parser for primitive Michelson instruction (no macros and extensions).
primInstr :: Parser' le (Contract' ParsedOp) -> Parser' le ParsedOp -> Parser le ParsedInstr
primInstr :: Parser' le (Contract' ParsedOp)
-> Parser' le ParsedOp -> Parser le ParsedInstr
primInstr Parser' le (Contract' ParsedOp)
contractParser Parser' le ParsedOp
opParser = String
-> ReaderT le (Parsec CustomParserException Text) ParsedInstr
-> ReaderT le (Parsec CustomParserException Text) ParsedInstr
forall e s (m :: * -> *) a.
MonadParsec e s m =>
String -> m a -> m a
label String
"primitive instruction" (ReaderT le (Parsec CustomParserException Text) ParsedInstr
 -> ReaderT le (Parsec CustomParserException Text) ParsedInstr)
-> ReaderT le (Parsec CustomParserException Text) ParsedInstr
-> ReaderT le (Parsec CustomParserException Text) ParsedInstr
forall a b. (a -> b) -> a -> b
$ [ReaderT le (Parsec CustomParserException Text) ParsedInstr]
-> ReaderT le (Parsec CustomParserException Text) ParsedInstr
forall (f :: * -> *) (m :: * -> *) a.
(Foldable f, Alternative m) =>
f (m a) -> m a
choice
  [ ReaderT le (Parsec CustomParserException Text) ParsedInstr
forall le. Parser le ParsedInstr
dropOp, ReaderT le (Parsec CustomParserException Text) ParsedInstr
forall le. Parser le ParsedInstr
swapOp, ReaderT le (Parsec CustomParserException Text) ParsedInstr
forall le. Parser le ParsedInstr
digOp, ReaderT le (Parsec CustomParserException Text) ParsedInstr
forall le. Parser le ParsedInstr
dugOp, Parser' le ParsedOp -> Parser le ParsedInstr
forall le. Parser' le ParsedOp -> Parser le ParsedInstr
pushOp Parser' le ParsedOp
opParser, ReaderT le (Parsec CustomParserException Text) ParsedInstr
forall le. Parser le ParsedInstr
someOp, ReaderT le (Parsec CustomParserException Text) ParsedInstr
forall le. Parser le ParsedInstr
noneOp, ReaderT le (Parsec CustomParserException Text) ParsedInstr
forall le. Parser le ParsedInstr
unitOp
  , Parser' le ParsedOp -> Parser le ParsedInstr
forall le. Parser' le ParsedOp -> Parser le ParsedInstr
ifNoneOp Parser' le ParsedOp
opParser, ReaderT le (Parsec CustomParserException Text) ParsedInstr
forall le. Parser le ParsedInstr
leftOp, ReaderT le (Parsec CustomParserException Text) ParsedInstr
forall le. Parser le ParsedInstr
rightOp, Parser' le ParsedOp -> Parser le ParsedInstr
forall le. Parser' le ParsedOp -> Parser le ParsedInstr
ifLeftOp Parser' le ParsedOp
opParser, ReaderT le (Parsec CustomParserException Text) ParsedInstr
forall le. Parser le ParsedInstr
nilOp
  , ReaderT le (Parsec CustomParserException Text) ParsedInstr
forall le. Parser le ParsedInstr
consOp, Parser' le ParsedOp -> Parser le ParsedInstr
forall le. Parser' le ParsedOp -> Parser le ParsedInstr
ifConsOp Parser' le ParsedOp
opParser, ReaderT le (Parsec CustomParserException Text) ParsedInstr
forall le. Parser le ParsedInstr
sizeOp, ReaderT le (Parsec CustomParserException Text) ParsedInstr
forall le. Parser le ParsedInstr
emptySetOp, ReaderT le (Parsec CustomParserException Text) ParsedInstr
forall le. Parser le ParsedInstr
emptyMapOp, ReaderT le (Parsec CustomParserException Text) ParsedInstr
forall le. Parser le ParsedInstr
emptyBigMapOp, Parser' le ParsedOp -> Parser le ParsedInstr
forall le. Parser' le ParsedOp -> Parser le ParsedInstr
iterOp Parser' le ParsedOp
opParser
  , ReaderT le (Parsec CustomParserException Text) ParsedInstr
forall le. Parser le ParsedInstr
memOp, ReaderT le (Parsec CustomParserException Text) ParsedInstr
forall le. Parser le ParsedInstr
getAndUpdateOp, ReaderT le (Parsec CustomParserException Text) ParsedInstr
forall le. Parser le ParsedInstr
getOp, ReaderT le (Parsec CustomParserException Text) ParsedInstr
forall le. Parser le ParsedInstr
updateOp, Parser' le ParsedOp -> Parser le ParsedInstr
forall le. Parser' le ParsedOp -> Parser le ParsedInstr
loopLOp Parser' le ParsedOp
opParser, Parser' le ParsedOp -> Parser le ParsedInstr
forall le. Parser' le ParsedOp -> Parser le ParsedInstr
loopOp Parser' le ParsedOp
opParser
  , Parser' le ParsedOp -> Parser le ParsedInstr
forall le. Parser' le ParsedOp -> Parser le ParsedInstr
lambdaOp Parser' le ParsedOp
opParser, ReaderT le (Parsec CustomParserException Text) ParsedInstr
forall le. Parser le ParsedInstr
execOp, ReaderT le (Parsec CustomParserException Text) ParsedInstr
forall le. Parser le ParsedInstr
applyOp, Parser' le ParsedOp -> Parser le ParsedInstr
forall le. Parser' le ParsedOp -> Parser le ParsedInstr
dipOp Parser' le ParsedOp
opParser, ReaderT le (Parsec CustomParserException Text) ParsedInstr
forall le. Parser le ParsedInstr
failWithOp, ReaderT le (Parsec CustomParserException Text) ParsedInstr
forall le. Parser le ParsedInstr
castOp, ReaderT le (Parsec CustomParserException Text) ParsedInstr
forall le. Parser le ParsedInstr
renameOp, ReaderT le (Parsec CustomParserException Text) ParsedInstr
forall le. Parser le ParsedInstr
levelOp
  , ReaderT le (Parsec CustomParserException Text) ParsedInstr
forall le. Parser le ParsedInstr
concatOp, ReaderT le (Parsec CustomParserException Text) ParsedInstr
forall le. Parser le ParsedInstr
packOp, ReaderT le (Parsec CustomParserException Text) ParsedInstr
forall le. Parser le ParsedInstr
unpackOp, ReaderT le (Parsec CustomParserException Text) ParsedInstr
forall le. Parser le ParsedInstr
sliceOp, ReaderT le (Parsec CustomParserException Text) ParsedInstr
forall le. Parser le ParsedInstr
isNatOp, ReaderT le (Parsec CustomParserException Text) ParsedInstr
forall le. Parser le ParsedInstr
addressOp, ReaderT le (Parsec CustomParserException Text) ParsedInstr
forall le. Parser le ParsedInstr
selfAddressOp, ReaderT le (Parsec CustomParserException Text) ParsedInstr
forall le. Parser le ParsedInstr
addOp, ReaderT le (Parsec CustomParserException Text) ParsedInstr
forall le. Parser le ParsedInstr
subOp
  , ReaderT le (Parsec CustomParserException Text) ParsedInstr
forall le. Parser le ParsedInstr
subMutezOp, ReaderT le (Parsec CustomParserException Text) ParsedInstr
forall le. Parser le ParsedInstr
mulOp, ReaderT le (Parsec CustomParserException Text) ParsedInstr
forall le. Parser le ParsedInstr
edivOp, ReaderT le (Parsec CustomParserException Text) ParsedInstr
forall le. Parser le ParsedInstr
absOp, ReaderT le (Parsec CustomParserException Text) ParsedInstr
forall le. Parser le ParsedInstr
negOp, ReaderT le (Parsec CustomParserException Text) ParsedInstr
forall le. Parser le ParsedInstr
lslOp, ReaderT le (Parsec CustomParserException Text) ParsedInstr
forall le. Parser le ParsedInstr
lsrOp, ReaderT le (Parsec CustomParserException Text) ParsedInstr
forall le. Parser le ParsedInstr
orOp, ReaderT le (Parsec CustomParserException Text) ParsedInstr
forall le. Parser le ParsedInstr
andOp, ReaderT le (Parsec CustomParserException Text) ParsedInstr
forall le. Parser le ParsedInstr
xorOp, ReaderT le (Parsec CustomParserException Text) ParsedInstr
forall le. Parser le ParsedInstr
notOp
  , ReaderT le (Parsec CustomParserException Text) ParsedInstr
forall le. Parser le ParsedInstr
compareOp, ReaderT le (Parsec CustomParserException Text) ParsedInstr
forall le. Parser le ParsedInstr
eqOp, ReaderT le (Parsec CustomParserException Text) ParsedInstr
forall le. Parser le ParsedInstr
neqOp, ReaderT le (Parsec CustomParserException Text) ParsedInstr
forall le. Parser le ParsedInstr
ltOp, ReaderT le (Parsec CustomParserException Text) ParsedInstr
forall le. Parser le ParsedInstr
leOp, ReaderT le (Parsec CustomParserException Text) ParsedInstr
forall le. Parser le ParsedInstr
gtOp, ReaderT le (Parsec CustomParserException Text) ParsedInstr
forall le. Parser le ParsedInstr
geOp, ReaderT le (Parsec CustomParserException Text) ParsedInstr
forall le. Parser le ParsedInstr
intOp, ReaderT le (Parsec CustomParserException Text) ParsedInstr
forall le. Parser le ParsedInstr
viewOp, ReaderT le (Parsec CustomParserException Text) ParsedInstr
forall le. Parser le ParsedInstr
selfOp, ReaderT le (Parsec CustomParserException Text) ParsedInstr
forall le. Parser le ParsedInstr
contractOp
  , ReaderT le (Parsec CustomParserException Text) ParsedInstr
forall le. Parser le ParsedInstr
transferTokensOp, ReaderT le (Parsec CustomParserException Text) ParsedInstr
forall le. Parser le ParsedInstr
setDelegateOp
  , Parser le (Contract' ParsedOp) -> Parser le ParsedInstr
forall le. Parser le (Contract' ParsedOp) -> Parser le ParsedInstr
createContractOp Parser' le (Contract' ParsedOp)
Parser le (Contract' ParsedOp)
contractParser, ReaderT le (Parsec CustomParserException Text) ParsedInstr
forall le. Parser le ParsedInstr
implicitAccountOp, ReaderT le (Parsec CustomParserException Text) ParsedInstr
forall le. Parser le ParsedInstr
nowOp, ReaderT le (Parsec CustomParserException Text) ParsedInstr
forall le. Parser le ParsedInstr
amountOp
  , ReaderT le (Parsec CustomParserException Text) ParsedInstr
forall le. Parser le ParsedInstr
balanceOp, ReaderT le (Parsec CustomParserException Text) ParsedInstr
forall le. Parser le ParsedInstr
checkSigOp, ReaderT le (Parsec CustomParserException Text) ParsedInstr
forall le. Parser le ParsedInstr
sha256Op, ReaderT le (Parsec CustomParserException Text) ParsedInstr
forall le. Parser le ParsedInstr
sha512Op, ReaderT le (Parsec CustomParserException Text) ParsedInstr
forall le. Parser le ParsedInstr
blake2BOp, ReaderT le (Parsec CustomParserException Text) ParsedInstr
forall le. Parser le ParsedInstr
hashKeyOp, ReaderT le (Parsec CustomParserException Text) ParsedInstr
forall le. Parser le ParsedInstr
pairingCheckOp
  , ReaderT le (Parsec CustomParserException Text) ParsedInstr
forall le. Parser le ParsedInstr
sourceOp, ReaderT le (Parsec CustomParserException Text) ParsedInstr
forall le. Parser le ParsedInstr
senderOp, ReaderT le (Parsec CustomParserException Text) ParsedInstr
forall le. Parser le ParsedInstr
chainIdOp, ReaderT le (Parsec CustomParserException Text) ParsedInstr
forall le. Parser le ParsedInstr
sha3Op, ReaderT le (Parsec CustomParserException Text) ParsedInstr
forall le. Parser le ParsedInstr
keccakOp, ReaderT le (Parsec CustomParserException Text) ParsedInstr
forall le. Parser le ParsedInstr
neverOp
  , ReaderT le (Parsec CustomParserException Text) ParsedInstr
forall le. Parser le ParsedInstr
votingPowerOp, ReaderT le (Parsec CustomParserException Text) ParsedInstr
forall le. Parser le ParsedInstr
totalVotingPowerOp, ReaderT le (Parsec CustomParserException Text) ParsedInstr
-> ReaderT le (Parsec CustomParserException Text) ParsedInstr
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try ReaderT le (Parsec CustomParserException Text) ParsedInstr
forall le. Parser le ParsedInstr
unpairNOp
  , ReaderT le (Parsec CustomParserException Text) ParsedInstr
forall le. Parser le ParsedInstr
unpairOp
  , ReaderT le (Parsec CustomParserException Text) ParsedInstr
forall le. Parser le ParsedInstr
ticketOp, ReaderT le (Parsec CustomParserException Text) ParsedInstr
forall le. Parser le ParsedInstr
readTicketOp, ReaderT le (Parsec CustomParserException Text) ParsedInstr
forall le. Parser le ParsedInstr
splitTicketOp, ReaderT le (Parsec CustomParserException Text) ParsedInstr
forall le. Parser le ParsedInstr
joinTicketsOp
  , ReaderT le (Parsec CustomParserException Text) ParsedInstr
forall le. Parser le ParsedInstr
openChestOp
  , ReaderT le (Parsec CustomParserException Text) ParsedInstr
forall le. Parser le ParsedInstr
saplingEmptyStateOp, ReaderT le (Parsec CustomParserException Text) ParsedInstr
forall le. Parser le ParsedInstr
saplingVerifyUpdateOp
  ]

-- | Parse a sequence of instructions.
ops' :: Parser' le ParsedOp -> Parser le [ParsedOp]
ops' :: Parser' le ParsedOp -> Parser le [ParsedOp]
ops' Parser' le ParsedOp
opParser = (Parser le [ParsedOp] -> Parser le [ParsedOp]
forall le a. Parser le a -> Parser le a
braces (Parser le [ParsedOp] -> Parser le [ParsedOp])
-> Parser le [ParsedOp] -> Parser le [ParsedOp]
forall a b. (a -> b) -> a -> b
$ Parser' le [ParsedOp]
Parser le [ParsedOp]
parseSeq) Parser' le [ParsedOp]
-> Parser' le [ParsedOp] -> Parser' le [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' le ParsedOp -> Parser' le [ParsedOp]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser' le ParsedOp
opParser)
  where
    parseSeq :: Parser' le [ParsedOp]
parseSeq =
      do{ ParsedOp
op <- Parser' le ParsedOp
opParser
        ; let separator :: ReaderT le (Parsec CustomParserException Text) ()
separator = case ParsedOp
op of
                Seq [ParsedOp]
_ SrcPos
_ -> ReaderT le (Parsec CustomParserException Text) (Maybe ())
-> ReaderT le (Parsec CustomParserException Text) ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (ReaderT le (Parsec CustomParserException Text) ()
-> ReaderT le (Parsec CustomParserException Text) (Maybe ())
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional ReaderT le (Parsec CustomParserException Text) ()
forall le. Parser le ()
semicolon)
                ParsedOp
_       -> ReaderT le (Parsec CustomParserException Text) ()
forall le. Parser le ()
semicolon
        ; do{ ()
_ <- ReaderT le (Parsec CustomParserException Text) ()
separator
            ; [ParsedOp]
ops <- Parser' le [ParsedOp]
parseSeq
            ; return (ParsedOp
opParsedOp -> [ParsedOp] -> [ParsedOp]
forall a. a -> [a] -> [a]
:[ParsedOp]
ops)
            }
           Parser' le [ParsedOp]
-> Parser' le [ParsedOp] -> Parser' le [ParsedOp]
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [ParsedOp] -> Parser' le [ParsedOp]
forall (m :: * -> *) a. Monad m => a -> m a
return [ParsedOp
op]
      }
      Parser' le [ParsedOp]
-> Parser' le [ParsedOp] -> Parser' le [ParsedOp]
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [ParsedOp] -> Parser' le [ParsedOp]
forall (m :: * -> *) a. Monad m => a -> m a
return []


-- Control Structures

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

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

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

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

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

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

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

-- Stack Operations

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

dupOp :: Parser le ParsedInstr
dupOp :: Parser' le ParsedInstr
dupOp = do
  Text -> Parser le ()
forall le. Text -> Parser le ()
symbol1' Text
"DUP"
  VarAnn
varAnn <- Parser' le VarAnn
forall tag le. KnownAnnTag tag => Parser le (Annotation tag)
noteDef
  ReaderT le (Parsec CustomParserException Text) Word
-> ReaderT le (Parsec CustomParserException Text) (Maybe Word)
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional (Parser le Word -> Parser le Word
forall le a. Parser le a -> Parser le a
lexeme Parser le Word
forall e s (m :: * -> *) a.
(MonadParsec e s m, Token s ~ Char, Num a) =>
m a
L.decimal) ReaderT le (Parsec CustomParserException Text) (Maybe Word)
-> (Maybe Word -> ParsedInstr) -> Parser' le ParsedInstr
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> ParsedInstr -> (Word -> ParsedInstr) -> Maybe Word -> ParsedInstr
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (VarAnn -> ParsedInstr
forall op. VarAnn -> InstrAbstract op
DUP VarAnn
varAnn) (VarAnn -> Word -> ParsedInstr
forall op. VarAnn -> Word -> InstrAbstract op
DUPN VarAnn
varAnn)

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

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

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

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

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

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

neverOp :: Parser le ParsedInstr
neverOp :: Parser' le ParsedInstr
neverOp = Tokens Text -> ParsedInstr -> Parser le ParsedInstr
forall a le. Tokens Text -> a -> Parser le a
word' Tokens Text
"NEVER" ParsedInstr
forall op. InstrAbstract op
NEVER
-- Generic comparison

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

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

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

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

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

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

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

-- ad-hoc comparison

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

-- Operations on booleans

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

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

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

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

-- Operations on integers and natural numbers

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

saplingEmptyStateOp :: Parser le ParsedInstr
saplingEmptyStateOp :: Parser' le ParsedInstr
saplingEmptyStateOp = Tokens Text
-> (VarAnn -> Natural -> ParsedInstr)
-> Parser le (VarAnn -> Natural -> ParsedInstr)
forall a le. Tokens Text -> a -> Parser le a
word' Tokens Text
"SAPLING_EMPTY_STATE" VarAnn -> Natural -> ParsedInstr
forall op. VarAnn -> Natural -> InstrAbstract op
SAPLING_EMPTY_STATE Parser' le (VarAnn -> Natural -> ParsedInstr)
-> ReaderT le (Parsec CustomParserException Text) VarAnn
-> ReaderT
     le (Parsec CustomParserException Text) (Natural -> ParsedInstr)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ReaderT le (Parsec CustomParserException Text) VarAnn
forall tag le. KnownAnnTag tag => Parser le (Annotation tag)
noteDef ReaderT
  le (Parsec CustomParserException Text) (Natural -> ParsedInstr)
-> ReaderT le (Parsec CustomParserException Text) Natural
-> Parser' le ParsedInstr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser le Natural -> Parser le Natural
forall le a. Parser le a -> Parser le a
lexeme Parser le Natural
forall e s (m :: * -> *) a.
(MonadParsec e s m, Token s ~ Char, Num a) =>
m a
L.decimal

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

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

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

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

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

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

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

-- Bitwise logical operators

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

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

-- Operations on string's

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

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

-- Operations on pairs
pairOp :: Parser le ParsedInstr
pairOp :: Parser' le ParsedInstr
pairOp = do
  Text -> Parser le ()
forall le. Text -> Parser le ()
symbol1' Text
"PAIR"
  (TypeAnn
t, VarAnn
v, (FieldAnn
p, FieldAnn
q)) <- Parser' le (TypeAnn, VarAnn, (FieldAnn, FieldAnn))
forall le. Parser le (TypeAnn, VarAnn, (FieldAnn, FieldAnn))
notesTVF2Def

  -- Make sure this is a `PAIR` instruction,
  -- and not a `PAIR n` instruction.
  ReaderT le (Parsec CustomParserException Text) Word
-> Parser' le ()
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m ()
notFollowedBy ((HasLetEnv le => Parser' le Word)
-> HasLetEnv le => Parser' le Word
forall le a. Parser le a -> Parser le a
lexeme HasLetEnv le => Parser' le Word
forall e s (m :: * -> *) a.
(MonadParsec e s m, Token s ~ Char, Num a) =>
m a
L.decimal :: Parser le Word)

  return $ TypeAnn -> VarAnn -> FieldAnn -> FieldAnn -> ParsedInstr
forall op.
TypeAnn -> VarAnn -> FieldAnn -> FieldAnn -> InstrAbstract op
PAIR TypeAnn
t VarAnn
v FieldAnn
p FieldAnn
q

unpairOp :: Parser le ParsedInstr
unpairOp :: Parser' le ParsedInstr
unpairOp = do
  Text -> Parser le ()
forall le. Text -> Parser le ()
symbol1' Text
"UNPAIR"
  ((VarAnn
vn1, VarAnn
vn2), (FieldAnn
fn1, FieldAnn
fn2)) <- Parser' le ((VarAnn, VarAnn), (FieldAnn, FieldAnn))
forall le. Parser le ((VarAnn, VarAnn), (FieldAnn, FieldAnn))
notesVVFF

  -- Make sure this is an `UNPAIR` instruction,
  -- and not an `UNPAIR n` instruction.
  ReaderT le (Parsec CustomParserException Text) Word
-> Parser' le ()
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m ()
notFollowedBy (Parser le Word -> Parser le Word
forall le a. Parser le a -> Parser le a
lexeme Parser le Word
forall e s (m :: * -> *) a.
(MonadParsec e s m, Token s ~ Char, Num a) =>
m a
L.decimal :: Parser le Word)

  return $ VarAnn -> VarAnn -> FieldAnn -> FieldAnn -> ParsedInstr
forall op.
VarAnn -> VarAnn -> FieldAnn -> FieldAnn -> InstrAbstract op
UNPAIR VarAnn
vn1 VarAnn
vn2 FieldAnn
fn1 FieldAnn
fn2

pairNOp :: Parser le ParsedInstr
pairNOp :: Parser' le ParsedInstr
pairNOp = do
  Text -> Parser le ()
forall le. Text -> Parser le ()
symbol1' Text
"PAIR"
  VarAnn -> Word -> ParsedInstr
forall op. VarAnn -> Word -> InstrAbstract op
PAIRN
    (VarAnn -> Word -> ParsedInstr)
-> ReaderT le (Parsec CustomParserException Text) VarAnn
-> ReaderT
     le (Parsec CustomParserException Text) (Word -> ParsedInstr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ReaderT le (Parsec CustomParserException Text) VarAnn
forall tag le. KnownAnnTag tag => Parser le (Annotation tag)
noteDef
    ReaderT
  le (Parsec CustomParserException Text) (Word -> ParsedInstr)
-> ReaderT le (Parsec CustomParserException Text) Word
-> Parser' le ParsedInstr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser le Word -> Parser le Word
forall le a. Parser le a -> Parser le a
lexeme Parser le Word
forall e s (m :: * -> *) a.
(MonadParsec e s m, Token s ~ Char, Num a) =>
m a
L.decimal

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

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

cdrOp :: Parser le ParsedInstr
cdrOp :: Parser' le ParsedInstr
cdrOp = do Text -> Parser le ()
forall le. Text -> Parser le ()
symbol1' Text
"CDR"; (VarAnn
v, FieldAnn
f) <- Parser' le (VarAnn, FieldAnn)
forall le. Parser le (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 le ParsedInstr
emptySetOp :: Parser' le ParsedInstr
emptySetOp = do Text -> Parser le ()
forall le. Text -> Parser le ()
symbol1' Text
"EMPTY_SET"; (TypeAnn
t, VarAnn
v) <- Parser' le (TypeAnn, VarAnn)
forall le. Parser le (TypeAnn, VarAnn)
notesTV;
                TypeAnn -> VarAnn -> Ty -> ParsedInstr
forall op. TypeAnn -> VarAnn -> Ty -> InstrAbstract op
EMPTY_SET TypeAnn
t VarAnn
v (Ty -> ParsedInstr)
-> ReaderT le (Parsec CustomParserException Text) Ty
-> Parser' le ParsedInstr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ReaderT le (Parsec CustomParserException Text) Ty
forall le. Parser le Ty
type_

emptyMapOp :: Parser le ParsedInstr
emptyMapOp :: Parser' le ParsedInstr
emptyMapOp = do Text -> Parser le ()
forall le. Text -> Parser le ()
symbol1' Text
"EMPTY_MAP"; (TypeAnn
t, VarAnn
v) <- Parser' le (TypeAnn, VarAnn)
forall le. Parser le (TypeAnn, VarAnn)
notesTV; Ty
a <- Parser' le Ty
forall le. Parser le Ty
type_;
                TypeAnn -> VarAnn -> Ty -> Ty -> ParsedInstr
forall op. TypeAnn -> VarAnn -> Ty -> Ty -> InstrAbstract op
EMPTY_MAP TypeAnn
t VarAnn
v Ty
a (Ty -> ParsedInstr) -> Parser' le Ty -> Parser' le ParsedInstr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser' le Ty
forall le. Parser le Ty
type_

emptyBigMapOp :: Parser le ParsedInstr
emptyBigMapOp :: Parser' le ParsedInstr
emptyBigMapOp = do Text -> Parser le ()
forall le. Text -> Parser le ()
symbol1' Text
"EMPTY_BIG_MAP"; (TypeAnn
t, VarAnn
v) <- Parser' le (TypeAnn, VarAnn)
forall le. Parser le (TypeAnn, VarAnn)
notesTV; Ty
a <- Parser' le Ty
forall le. Parser le Ty
type_;
                   TypeAnn -> VarAnn -> Ty -> Ty -> ParsedInstr
forall op. TypeAnn -> VarAnn -> Ty -> Ty -> InstrAbstract op
EMPTY_BIG_MAP TypeAnn
t VarAnn
v Ty
a (Ty -> ParsedInstr) -> Parser' le Ty -> Parser' le ParsedInstr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser' le Ty
forall le. Parser le Ty
type_

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

updateOp :: Parser le ParsedInstr
updateOp :: Parser' le ParsedInstr
updateOp = do
  Text -> Parser le ()
forall le. Text -> Parser le ()
symbol1' Text
"UPDATE"
  VarAnn
varAnn <- Parser' le VarAnn
forall tag le. KnownAnnTag tag => Parser le (Annotation tag)
noteDef
  Maybe Word
ix <- ReaderT le (Parsec CustomParserException Text) Word
-> ReaderT le (Parsec CustomParserException Text) (Maybe Word)
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional (Parser le Word -> Parser le Word
forall le a. Parser le a -> Parser le a
lexeme Parser le Word
forall e s (m :: * -> *) a.
(MonadParsec e s m, Token s ~ Char, Num a) =>
m a
L.decimal)
  pure $ ParsedInstr -> (Word -> ParsedInstr) -> Maybe Word -> ParsedInstr
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (VarAnn -> ParsedInstr
forall op. VarAnn -> InstrAbstract op
UPDATE VarAnn
varAnn) (VarAnn -> Word -> ParsedInstr
forall op. VarAnn -> Word -> InstrAbstract op
UPDATEN VarAnn
varAnn) Maybe Word
ix

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

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

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

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

getOp :: Parser le ParsedInstr
getOp :: Parser' le ParsedInstr
getOp = do
  Text -> Parser le ()
forall le. Text -> Parser le ()
symbol1' Text
"GET"
  VarAnn
varAnn <- Parser' le VarAnn
forall tag le. KnownAnnTag tag => Parser le (Annotation tag)
noteDef
  Maybe Word
ix <- ReaderT le (Parsec CustomParserException Text) Word
-> ReaderT le (Parsec CustomParserException Text) (Maybe Word)
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional (Parser le Word -> Parser le Word
forall le a. Parser le a -> Parser le a
lexeme Parser le Word
forall e s (m :: * -> *) a.
(MonadParsec e s m, Token s ~ Char, Num a) =>
m a
L.decimal)
  pure $ ParsedInstr -> (Word -> ParsedInstr) -> Maybe Word -> ParsedInstr
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (VarAnn -> ParsedInstr
forall op. VarAnn -> InstrAbstract op
GET VarAnn
varAnn) (VarAnn -> Word -> ParsedInstr
forall op. VarAnn -> Word -> InstrAbstract op
GETN VarAnn
varAnn) Maybe Word
ix

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

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

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

-- Operations on options

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

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

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

-- Operations on unions

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

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

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

-- Operations on contracts

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

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

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

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

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

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

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

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

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

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

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

viewOp :: Parser le ParsedInstr
viewOp :: Parser' le ParsedInstr
viewOp =
  -- @VIEW_@ A1 macro should not be parsed by this
  Tokens Text
-> (VarAnn -> ViewName -> Ty -> ParsedInstr)
-> Parser le (VarAnn -> ViewName -> Ty -> ParsedInstr)
forall a le. Tokens Text -> a -> Parser le a
word' Tokens Text
"VIEW" VarAnn -> ViewName -> Ty -> ParsedInstr
forall op. VarAnn -> ViewName -> Ty -> InstrAbstract op
VIEW Parser' le (VarAnn -> ViewName -> Ty -> ParsedInstr)
-> ReaderT le (Parsec CustomParserException Text) VarAnn
-> ReaderT
     le
     (Parsec CustomParserException Text)
     (ViewName -> Ty -> ParsedInstr)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ReaderT le (Parsec CustomParserException Text) VarAnn
forall tag le. KnownAnnTag tag => Parser le (Annotation tag)
noteDef ReaderT
  le
  (Parsec CustomParserException Text)
  (ViewName -> Ty -> ParsedInstr)
-> ReaderT le (Parsec CustomParserException Text) ViewName
-> ReaderT
     le (Parsec CustomParserException Text) (Ty -> ParsedInstr)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ReaderT le (Parsec CustomParserException Text) ViewName
forall le. Parser le ViewName
viewName_ ReaderT le (Parsec CustomParserException Text) (Ty -> ParsedInstr)
-> ReaderT le (Parsec CustomParserException Text) Ty
-> Parser' le ParsedInstr
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ReaderT le (Parsec CustomParserException Text) Ty
forall le. Parser le Ty
type_

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

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

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

-- Special Operations

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

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

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

-- Operations on bytes

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

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

-- Cryptographic Primitives

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

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

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

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

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

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

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

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

-- Type operations

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

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

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

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

-- Ticket Operations

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

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

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

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

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