Tiny translator from Michelson to OCaml
- OCaml (>=4.11.0)
- menhir
- ocamlfind
% dune build
will build ocaml_of_michelson in src.
ocaml_of_michelson [-spec spec_file] [-o output_file] [michelson_file]
It reads a Michelson script from michelson_file (or stdin if not specified).
The output is written to output_file (or stdout if -o is omitted); debug messages are also written to stderr.
The option -spec (default ./inst.mli) specifies an OCaml interface file that describes the OCaml types of Michelson instructions. The output file should typecheck with it.
% dune test
All .tz files are translated into .ml, which is typedchecked with ocamlopt.
The interface file test/inst.mli lists the types of instructions.
-
The generated program is not supposed to run 💦. (This is a FEATURE!)
-
Input checking is loose. It assumes the code section is well typed.
-
The produced ocaml code should typecheck but we make loose assumptions about the types of instructions (e.g.,
stringandaddressare identified,comparecan be applied to any type, and so on). So, a potential bug of the translator may be overlooked. -
Some overloaded instructions (at least
MAP) can't be handled properly even with loose checking. -
GET nandUPDATE nassumesnis less than 7. (Seetest/inst.mlito see why.) -
Macros are not supported yet.
-
Some forms for compound literals are not supported:
{1; "foo"; True}for tuples.{}for the empty map (it is always a list).- lambdas.