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

Indigo.Backend

Description

Indigo compiler back-end helpers.

For reference, "back-end" refers to the part of the compiler pipeline that comes after the intermediate representation. In our case, intermediate representation is defined in Indigo.Frontend.Internal.Statement.

Essentially these definitions simplify target code generation. This is not intended to be exported from Indigo.

Synopsis

Documentation

Loop

forEach Source #

Arguments

:: (IterOpHs a, KnownValue (IterOpElHs a)) 
=> Expr a

Expression for the container to traverse

-> Var (IterOpElHs a)

Variable for the current item (available to the code block)

-> SomeIndigoState (IterOpElHs a ': inp)

Code block to execute over each element of the container

-> IndigoState inp inp 

For statements to iterate over a container.

while Source #

Arguments

:: Expr Bool

Expression for the control flow

-> SomeIndigoState inp

Block of code to execute, as long as the expression holds True

-> IndigoState inp inp 

While statement.

whileLeft Source #

Arguments

:: forall l r inp. (KnownValue l, KnownValue r) 
=> Expr (Either l r)

Expression for the control flow value

-> Var l

Variable for the Left value (available to the code block)

-> SomeIndigoState (l ': inp)

Code block to execute while the value is Left

-> Var r

Variable that will be assigned to the resulting value

-> IndigoState inp (r ': inp) 

While-left statement. Repeats a block of code as long as the control Either is Left, returns when it is Right.

Contract call

selfCalling Source #

Arguments

:: forall p inp mname. (NiceParameterFull p, KnownValue (GetEntrypointArgCustom p mname), IsoValue (ContractRef (GetEntrypointArgCustom p mname)), IsNotInView) 
=> EntrypointRef mname 
-> Var (ContractRef (GetEntrypointArgCustom p mname))

Variable that will be assigned to the resulting ContractRef

-> IndigoState inp (ContractRef (GetEntrypointArgCustom p mname) ': inp) 

contractCalling Source #

Arguments

:: forall cp vd inp epRef epArg addr. (HasEntrypointArg cp epRef epArg, ToTAddress cp vd addr, ToT addr ~ ToT Address, HasNoOp (ToT epArg), HasNoNestedBigMaps (ToT epArg), KnownValue epArg) 
=> epRef 
-> Expr addr 
-> Var (Maybe (ContractRef epArg))

Variable that will be assigned to the resulting ContractRef

-> IndigoState inp (Maybe (ContractRef epArg) ': inp) 

Documentation

doc :: DocItem di => di -> IndigoState s s Source #

Put a document item.

docGroup :: DocItem di => (SubDoc -> di) -> SomeIndigoState i -> SomeIndigoState i Source #

Group documentation built in the given piece of code into a block dedicated to one thing, e.g. to one entrypoint.

docStorage :: forall storage s. TypeHasDoc storage => IndigoState s s Source #

Deprecated: Use `doc (dStorage @storage)` instead.

Insert documentation of the contract storage type. The type should be passed using type applications.

contractName :: Text -> SomeIndigoState i -> SomeIndigoState i Source #

Deprecated: Use `docGroup name` instead.

Give a name to the given contract. Apply it to the whole contract code.

finalizeParamCallingDoc :: (NiceParameterFull cp, RequireSumType cp, HasCallStack) => Var cp -> SomeIndigoState (cp ': inp) -> Expr cp -> SomeIndigoState inp Source #

Indigo version for the function of the same name from Lorentz.

contractGeneral :: SomeIndigoState i -> SomeIndigoState i Source #

Deprecated: Use `docGroup DGeneralInfoSection` instead.

Attach general info to the given contract.

contractGeneralDefault :: IndigoState s s Source #

Attach default general info to the contract documentation.

Side-effects

createContract Source #

Arguments

:: (HasSideEffects, NiceStorage s, NiceParameterFull p, NiceViewsDescriptor vd, Typeable vd, IsNotInView) 
=> Contract p s vd 
-> Expr (Maybe KeyHash) 
-> Expr Mutez 
-> Expr s 
-> Var Address

Variable that will be assigned to the resulting Address

-> IndigoState inp (Address ': inp) 

Functions, Procedures and Scopes

scope Source #

Arguments

:: forall ret inp. ScopeCodeGen ret 
=> SomeIndigoState inp

Code block to execute inside the scope

-> ret

Return value(s) of the scoped code block

-> RetVars ret

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

-> IndigoState inp (RetOutStack ret ++ inp) 

Takes an arbitrary IndigoM and wraps it into an IndigoFunction producing a local scope for its execution. Once it executed, all non-returned variables are cleaned up so that the stack has only returned variables at the top. This also can be interpreted as if True then f else nop.

Note, that by default we do not define scope inside indigo functions, meaning that once we want to create a new variable or return it from a function we need to do it inside scope $ instr construction, for example:

f :: IndigoFunction s Natural
f = scope $ do
  *[s]*
  res <- newVar (0 :: Natural)
  *[Natural, s]*
  scope $ do
    _n <- newVar (1 :: Integer)
    *[Integer, Natural, s]
    res += 4
  *[Natural, s]*
  return res
  *[s]*

Comments

comment :: CommentType -> IndigoState i i Source #

Add a comment