Skip to content

Michelson embedding with support of types and annotations

E. Rivas requested to merge er433/michelson/types into dev

type:internal

For LIGO developers

Many constants are handled as "specials": they need types/strings in their Michelson generation, and thus cannot be represented using [%Michelson ...].

This MR adds support to [%Michelson ...] for handling types and strings. Here's an example from the stdlib:

  [@inline] [@thunk] let self (type a) (s : string) : a contract =
    let _ : a option = [%external ("CHECK_SELF", s)] in
    [%Michelson (({| { DROP ; SELF (annot $0) } |} : unit -> a contract), (s : string))] ()

Now the Michelson embedding can access the parameter s by using (annot $0). In this case, (annot $0) will be replaced by an string literal as annotation.

Notice we also add a call to a C_CHECK_SELF, which keeps the checking which before was based on C_SELF (there are three "check" primitives: C_CHECK_SELF, C_CHECK_EMIT_EVENT and C_CHECK_ENTRYPOINT). C_CHECK_SELF will be replaced by None after check (and thus later removed).

Another example is get_contract_opt, which needs the type:

  [@inline] [@thunk] let get_contract_opt (type p) (a : address) : (p contract) option =
    [%Michelson (({| { CONTRACT (type $0) } |} : address -> (p contract) option), (() : p))] a

Again, now the Michelson embedding can access the type (p) of the expression (() : p). Notice this is not well-typed, but it really doesn't matter.

Changelog details:

Edited by E. Rivas

Merge request reports