SCaml compiler
DaiLambda, Inc.
Jun FURUSE/古瀬淳
, Université de Paris, 2019-11-22Tezos Smart Contracts
What is SCaml
Yet another compiler from OCaml to Michelson.
For Smart contracts
Strict Subset of OCaml
Small (< 3000 loc.).
and Serious
Strict Subset of OCaml
No fancy features for smart contracts
Many OCaml features are disabled:
No recursion
No polymoprhism
No modules
No objects
No mutability
No user defined types
Small
Built over OCaml’s compiler­libs.
Reusing OCaml’s parser and type-checker,
which are well tested for long time.
SCaml code only compiles OCaml’s typed AST to Michelson.
Less than 3000 lines of *.ml, written in 5 days.
and Serious
Serious compiler. Not a toy.
All the Michelson opcodes are supported, except
CREATE_CONTRACT.
Some optimizations in the pure ML level.
Babylon ready (i.e. entry points, closures)
Benefit of being Strict Subset
OCaml programmers can use SCaml without any surprise.
Newbies can learn SCaml via OCaml tutorial.
Many OCaml eco-system tools can be used for free:
Menhir, Tuareg, indender, reformatter
PPX, P4, ReasonML
etc.
Possibilities of being Strict Subset
Contracts can be compiled to native code with a
proper OCaml library:
Fast Monte Carlo simulations of contracts.
Contract, UI and server together in OCaml.
“Ocsigen” for Tezos:
Contracts: to Michelson by SCaml
UI: to JS by JSOO
Server: to native by OCaml
Compilation path
Parsing by OCaml parser
Typing by OCaml type checker
Unifying types for entry points and storage
Translation to an IL, pure monomorhpic core ML
Some inlining and partial evaluation
Compilation to Michelson
SCaml Features
Numeric types: int, nat, tz
Int (­12),   Nat 42,   Tz 1.23
with monomorphic operators: (+), (+^),(+$)
Options, Lists, Sets, Maps:
Some 1,   [ 1; 2; 3 ]
Set [ 1; 2; 3 ],  Map [ (1, "one"), (2, "two") ]
Blockchain related constants with strings:
Key_hash "tz1..."
Pairs, Sums:
int * int,  (int, int) sum
No user defined data types… yet
Aliases are OK: type 'a t = (int * ('a, nat) sum)
Future Work
Pattern match (almost done)
User defined types
Nothing more. We keep things small.
Vague Idea of Collaboration
SCaml + ReFX = SCaml + refinement type
Refinement specification as SCaml annotations.
Compiles down them to annotations in Michelson.
SCam Language
A scam never calls it a scam.
https://gitlab.com/dailambda/scaml

SCaml compiler

  • 1.
    SCaml compiler DaiLambda, Inc. JunFURUSE/古瀬淳 , Université de Paris, 2019-11-22Tezos Smart Contracts
  • 2.
    What is SCaml Yetanother compiler from OCaml to Michelson. For Smart contracts Strict Subset of OCaml Small (< 3000 loc.). and Serious
  • 3.
    Strict Subset ofOCaml No fancy features for smart contracts Many OCaml features are disabled: No recursion No polymoprhism No modules No objects No mutability No user defined types
  • 4.
    Small Built over OCaml’scompiler­libs. Reusing OCaml’s parser and type-checker, which are well tested for long time. SCaml code only compiles OCaml’s typed AST to Michelson. Less than 3000 lines of *.ml, written in 5 days.
  • 5.
    and Serious Serious compiler.Not a toy. All the Michelson opcodes are supported, except CREATE_CONTRACT. Some optimizations in the pure ML level. Babylon ready (i.e. entry points, closures)
  • 6.
    Benefit of beingStrict Subset OCaml programmers can use SCaml without any surprise. Newbies can learn SCaml via OCaml tutorial. Many OCaml eco-system tools can be used for free: Menhir, Tuareg, indender, reformatter PPX, P4, ReasonML etc.
  • 7.
    Possibilities of beingStrict Subset Contracts can be compiled to native code with a proper OCaml library: Fast Monte Carlo simulations of contracts. Contract, UI and server together in OCaml. “Ocsigen” for Tezos: Contracts: to Michelson by SCaml UI: to JS by JSOO Server: to native by OCaml
  • 8.
    Compilation path Parsing byOCaml parser Typing by OCaml type checker Unifying types for entry points and storage Translation to an IL, pure monomorhpic core ML Some inlining and partial evaluation Compilation to Michelson
  • 9.
    SCaml Features Numeric types:int, nat, tz Int (­12),   Nat 42,   Tz 1.23 with monomorphic operators: (+), (+^),(+$) Options, Lists, Sets, Maps: Some 1,   [ 1; 2; 3 ] Set [ 1; 2; 3 ],  Map [ (1, "one"), (2, "two") ] Blockchain related constants with strings: Key_hash "tz1..." Pairs, Sums: int * int,  (int, int) sum No user defined data types… yet Aliases are OK: type 'a t = (int * ('a, nat) sum)
  • 10.
    Future Work Pattern match(almost done) User defined types Nothing more. We keep things small.
  • 11.
    Vague Idea ofCollaboration SCaml + ReFX = SCaml + refinement type Refinement specification as SCaml annotations. Compiles down them to annotations in Michelson.
  • 12.
    SCam Language A scamnever calls it a scam. https://gitlab.com/dailambda/scaml