indigo-0.6.0: Convenient imperative eDSL over Lorentz.
Safe HaskellSafe-Inferred
LanguageHaskell2010

Indigo.Compilation.Sequential

Description

Instruction datatype and its compilations.

The idea behind this module is to provide an intermediate representation that can:

  • be generated from the frontend freer monad
  • be compiled to the backend IndigoState
  • be easy to analyze, manipulate and modify

This is meant to be the common ground for modular optimizations on the code before this is handed off to the backend and eventually translated to Michelson.

Synopsis

Documentation

type Block = [Instruction] Source #

Simple synonym for a list of Instruction

data Instruction where Source #

Data type representing an instruction.

Differently from the frontend this is not used to build a Monad of some kind, it is instead based on having as argument the variable to associate with the resulting value (if any).

This is combined in simple lists, named Block, and it is intended to be easily altered, this is because these are used as the intermediate representation between the frontend and the backend, where optimizations can occur.

Constructors

LiftIndigoState :: (forall inp. SomeIndigoState inp) -> Instruction 
Comment :: Text -> Instruction 
AssignVar :: KnownValue x => Var x -> Expr x -> Instruction 
SetVar :: KnownValue x => Var x -> Expr x -> Instruction 
VarModification :: (IsObject x, KnownValue y) => ([y, x] :-> '[x]) -> Var x -> Expr y -> Instruction 
SetField :: (HasField store fname ftype, IsObject store, IsObject ftype) => Var store -> Label fname -> Expr ftype -> Instruction 
LambdaCall1 

Fields

  • :: LambdaKind st arg ret extra

    Kind of lambda (pure, storage modification, fully functional lambda with effects)

  • -> String

    Name of the lambda

  • -> Expr arg

    Expression for the lambda argument

  • -> Var arg

    Variable for the argument value (available to the lambda code block)

  • -> Block

    Code block for the lambda

  • -> ret

    Return value(s) of the lambda

  • -> RetVars ret

    Variable(s) that will be assigned to the resulting value(s)

  • -> Instruction
     
CreateLambda1 

Fields

ExecLambda1 

Fields

Scope 

Fields

  • :: ScopeCodeGen ret
     
  • => Block

    Code block to execute inside the scope

  • -> ret

    Return value(s) of the scoped code block

  • -> RetVars ret

    Variable that will be assigned to the resulting value(s)

  • -> Instruction
     
If 

Fields

  • :: IfConstraint a b
     
  • => Expr Bool

    Expression for the control flow

  • -> Block

    Code block for the positive branch

  • -> a

    Return value(s) of the positive branch

  • -> Block

    Code block for the negative branch

  • -> b

    Return value(s) of the negative branch

  • -> RetVars a

    Variable(s) that will be assigned to the resulting value(s)

  • -> Instruction
     
IfSome 

Fields

IfRight 

Fields

IfCons 

Fields

  • :: (IfConstraint a b, KnownValue x)
     
  • => Expr (List x)

    Expression for the control flow

  • -> Var x

    Variable for the "head" value (available to the next code block)

  • -> Var (List x)

    Variable for the "tail" value (available to the next code block)

  • -> Block

    Code block for the non-empty list branch

  • -> a

    Return value(s) of the non-empty list branch

  • -> Block

    Code block for the empty list branch

  • -> b

    Return value(s) of the empty list branch

  • -> RetVars a

    Variable(s) that will be assigned to the resulting value(s)

  • -> Instruction
     
Case 

Fields

  • :: CaseCommon dt ret clauses
     
  • => Expr dt
     
  • -> clauses
     
  • -> RetVars ret

    Variable(s) that will be assigned to the resulting value(s)

  • -> Instruction
     
EntryCase 

Fields

EntryCaseSimple 

Fields

While 

Fields

WhileLeft 

Fields

ForEach 

Fields

ContractName :: Text -> Block -> Instruction 
DocGroup :: forall di. DocItem di => (SubDoc -> di) -> Block -> Instruction 
ContractGeneral :: Block -> Instruction 
FinalizeParamCallingDoc :: (NiceParameterFull cp, RequireSumType cp) => Var cp -> Block -> Expr cp -> Instruction 
TransferTokens :: (NiceParameter p, HasSideEffects, IsNotInView) => Expr p -> Expr Mutez -> Expr (ContractRef p) -> Instruction 
SetDelegate :: (HasSideEffects, IsNotInView) => Expr (Maybe KeyHash) -> Instruction 
CreateContract 

Fields

SelfCalling 

Fields

ContractCalling 

Fields

Emit :: (HasSideEffects, NicePackedValue a, HasAnnotation a) => FieldAnn -> Expr a -> Instruction 
Fail :: (forall inp. SomeIndigoState inp) -> Instruction 
FailOver :: (forall inp. Expr a -> SomeIndigoState inp) -> Expr a -> Instruction 

data IndigoSeqCaseClause ret (param :: CaseClauseParam) where Source #

Analogous datatype as IndigoCaseClauseL and IndigoMCaseClauseL.

Constructors

OneFieldIndigoSeqCaseClause :: AppendSymbol "c" ctor ~ name => Label name -> CaseBranch x ret -> IndigoSeqCaseClause ret ('CaseClauseParam ctor ('OneField x)) 

data CaseBranch x ret where Source #

Representation of a branch of a generic case-like Instruction.

Constructors

CaseBranch 

Fields

Translations

data InstrCollector Source #

Data type internally used to collect Instructions from IndigoM

indigoMtoSequential :: RefId -> SequentialHooks -> IndigoM a -> (Block, RefId) Source #

Transformation from IndigoM to a Block of Instructions.

Requires the first non-used RefId and returns the next one.

sequentialToLorentz :: MetaData inp -> (Block, RefId) -> inp :-> inp Source #

Translation from a Block and an initial MetaData to Lorentz.

Case machinery

updateClauses :: (Block -> Block) -> Rec (IndigoSeqCaseClause ret) dt -> Rec (IndigoSeqCaseClause ret) dt Source #

Applies the given Block to Block transformation to the inner code block of every case clause.

mapMClauses :: Monad m => (Block -> m ()) -> Rec (IndigoSeqCaseClause ret) dt -> m () Source #

Applies the given monadic function giving it the inner code block of each case clause, in order.