Compiler options
scamlc
Compilation modes
The compiler scamlc
has 3 complation modes.
Compilation mode (default)
In its default compilation mode, scamlc xxx.ml
compiles SCaml source xxx.ml
to Michelson xxx.tz
.
$ scamlc xxx.ml # Successful compilation produces xxx.tz
Not only the final output .tz
, scamlc
generates the following file:
.cmi
- Compiled module interface of the module. It contains the type signature of the compiled module. Compatible with OCaml's
.cmi
file.
Conversion mode: --scaml-convert
When you deploy and execute a Tezos smart contract, you have to give its initial storage and
the parameter as Michelson values respectively to tezos-client
command.
The conversion mode, scamlc --scaml-convert
, compiles SCaml constant expressions to Michelson values
for these initial storages and execution parameters.
In this mode, the compiler takes a .ml
file and print Michelson representations of
ML constants and types to stdout. The conversion targets must be defined as toplevel
declarations. For example:
(* hoo.ml *)
open SCaml
type t =
{ name : string
; age : nat
; salary : tz
}
and u =
| Foo of int * tz * string
| Bar
| Boo of t list
| Far
let v = Boo [ { name= "jon"; age= Nat 18; salary= Tz 10000.0 }
; { name= "dow"; age= Nat 50; salary= Tz 1.0 }
]
then,
$ scamlc --scaml-convert hoo.ml
type t: pair string (pair nat mutez)
type u: or int (or (pair int (pair mutez string)) (list (pair string (pair nat mutez))))
v: Right (Right { Pair "jon" (Pair 18 10000000000) ; Pair "dow" (Pair 50 1000000) })
Note that the values in .ml
must be constants. Constructors and types can refer to types
defined in other modules, as far as they are already compiled to .cmi
files.
Revert mode: --scaml-revert file
SCaml specific compiler switch --scaml-revert file
, where file
is a file name
which contains Michelson constant expression.
With this option, scamlc
command takes a .ml
of one type definition, then translate
the Michelson constant expression in file
as an SCaml value of the type in .ml
,
then print out the SCaml expression to stdout. For example, suppose we have hoo.ml
of the example of --scaml-convert
. Create hoo_type.ml
with a type alias definition
of Hoo.t
:
(* hoo_u.ml *)
type u = Hoo.u (* Refers the type defined in hoo.ml in the example of --scaml-convert *)
Prepare a file with the Michelson constant obtained in the example of the conversion:
/* value.tz */
Right (Right { Pair "jon" (Pair 18 10000000000) ; Pair "dow" (Pair 50 1000000) })
$ scamlc --scaml-revert value.tz hoo_u.ml
Boo
[{ name = "jon"; age = (Nat 18); salary = (Tz 10000.000000) };
{ name = "dow"; age = (Nat 50); salary = (Tz 1.000000) }]
Note that the values must be constants. Constructors and types can refer to types
defined in other modules, as far as they are already compiled to .cmi
files.
Version
-v
- Shows the versions of SCaml, the version of Tezos protocol it uses, and the version of OCaml compiler used:
Debugging options
--scaml-debug
- Prints out various debugging messages of compilation.
--scaml-dump-iml0
- The initial representation of the compiled contract in SCaml's intermediate language IML
before any optimization is dumped to a file with extension
.iml0
. --scaml-dump-iml
- The final representation of the comipled contract in SCaml's intermediate language IML
after all the optimizations is dumped to a file with extension
.iml
.
Test purpose
--scaml-noscamlib
- Exclude the installation directory of
SCaml
library module from the compiler's load path. Useful when testing a customSCaml
module.