...
 
Commits (3)
# SCaml, Smart Contract Abstract Machine Language. # SCaml, Smart Contract Abstract Machine Language.
> A scam never calls itself a scam. > Scam never calls itself scam.
Small and Simple Strict Subset of OCaml for Smart contracts. Small and Simple Strict Subset of OCaml for Smart contracts.
...@@ -25,7 +25,7 @@ The following OCaml features are **not** supported: ...@@ -25,7 +25,7 @@ The following OCaml features are **not** supported:
* Product types other than a pair: `t1 * t2`. * Product types other than a pair: `t1 * t2`.
* Modules. * Modules.
* Labeled functions. * Labeled functions.
* Nested patterns. Constants in patterns. "Or" pattern. Pattern guards. Exception patterns. * Exception patterns.
* Multi case in `function` * Multi case in `function`
* Partial applicaiton of primitives defined in `SCaml`. * Partial applicaiton of primitives defined in `SCaml`.
* Reference or mutable record fields. * Reference or mutable record fields.
...@@ -46,16 +46,9 @@ type ('a, 'b) sum = ...@@ -46,16 +46,9 @@ type ('a, 'b) sum =
| Right of 'b | Right of 'b
``` ```
### No real pattern matching (yet) ### Experimental: Pattern match
For simplicity, the pattern match `match .. with ..` of OCaml Full pattern matching for `match` is recently added as an experimental feature. It is not yet fully tested.
is hugely restricted in SCaml.
* Constructors in patterns are restricted to `Left`, `Right`, `::`, `[]`, `Some` and `None.
* Constructors in patterns can take only variables as their arguments. No nested pattern is allowed.
This means that for now SCaml's `match .. with ..` is just a syntactic sugar of
Michelson conditional opcodes `IF_LEFT`, `IF_CONS` and `IF_NONE`.
## Design ## Design
......
...@@ -166,7 +166,7 @@ let pp ppf = ...@@ -166,7 +166,7 @@ let pp ppf =
f "@[<2>(fun (%a) ->@ %a@ : %a)@]" f "@[<2>(fun (%a) ->@ %a@ : %a)@]"
pp_patvar pat pp body M.Type.pp t.typ pp_patvar pat pp body M.Type.pp t.typ
| IfThenElse (t1, t2, t3) -> | IfThenElse (t1, t2, t3) ->
f "(if %a @[then %a@ else %a@])" f "(@[if %a@ then %a@ else %a@])"
pp t1 pp t2 pp t3 pp t1 pp t2 pp t3
| App (t1, ts) -> | App (t1, ts) ->
f "(%a %a)" pp t1 Format.(list " " (fun ppf t -> fprintf ppf "(%a)" pp t)) ts f "(%a %a)" pp t1 Format.(list " " (fun ppf t -> fprintf ppf "(%a)" pp t)) ts
...@@ -200,10 +200,10 @@ let pp ppf = ...@@ -200,10 +200,10 @@ let pp ppf =
(Format.list "@ | " (Format.list "@ | "
(fun ppf (p, guard, e) -> (fun ppf (p, guard, e) ->
match guard with match guard with
| None -> Format.fprintf ppf "%a -> %a" | None -> Format.fprintf ppf "@[<2>%a ->@ %a@]"
pp_pat p pp_pat p
pp e pp e
| Some g -> Format.fprintf ppf "%a when %a -> %a" | Some g -> Format.fprintf ppf "@[<2>%a when %a ->@ %a@]"
pp_pat p pp_pat p
pp g pp g
pp e pp e
......
This diff is collapsed.