2019-05-20 21:42:11 +02:00
|
|
|
[@@@warning "-45"]
|
|
|
|
|
2019-05-14 15:57:25 +02:00
|
|
|
open Trace
|
2020-03-12 23:20:39 +01:00
|
|
|
open Ast_imperative
|
2019-05-14 15:57:25 +02:00
|
|
|
|
2019-12-12 14:35:07 +01:00
|
|
|
module Raw = Parser.Cameligo.AST
|
2019-05-14 15:57:25 +02:00
|
|
|
module SMap = Map.String
|
2019-05-20 21:42:11 +02:00
|
|
|
module Option = Simple_utils.Option
|
Refactoring of Ligodity (CameLIGO) and making an AST pretty-printer
- AST.ml/AST.mli:
- The AST now distinguishes the constructors `None` and `Some` as being
predefined, as in PascaLIGO. See type `AST.constr_pattern`.
- I removed the nodes specific to Liquidity,
e.g. `let%entry`, and, in particular, the natural literals
ending with `p`. Now it should be `n`, as in `10n`.
- I renamed the node `TAlias` to `TVar`.
- I have applied the rule of expanding type expressions after `of` when
those were not records.
- The type of the argument to a data constructor is now
`type_expr`, instead of `cartesian`.
- I added the patterns for bytes (`PBytes`) and natural literals (`PNat`).
- I renamed the node `Sugar` into
`PListComp` (meaning "pattern of list comprehension").
- Record types in CameLIGO now must have at least one field declaration.
- Replaced the type `closing` and `opening` with one type `compound`,
which captures only the right combinations of opening and closing.
- Components of tuples in a selection must not be written
between parentheses. For example, `a.b.(1).(0)` is now
`a.b.1.0`, as in PascaLIGO.
- LexToken.mli/LexToken.mll
- I renamed the string literal `Str` into `String`.
- I added the tokens `C_None` and `C_Some` (to distinguish the
constructors `None` and `Some`. See AST.ml)
- Fixed the function `mk_sym` so it does not fail with `failwith`, but
with `Error Invalid_symbol`.
- Lexer.mll (shared)
- I removed the character `%` from the identifiers (used to
support Liquidity, like `entry%point` and `match%nat`).
- I adde to the hint on broken strings: "or insert a backslash"
(from a Gitlab issue).
- ParToken.mly
- I added the tokens `C_None` and `C_Some` (to distinguish the
constructors `None` and `Some`. See AST.ml and LexToken.mll)
- Parser.mly
- Fixed the order of declarations in the AST (it was reversed).
- I removed syntax support for Liquidity.
- I added user-defined constructor applications to irrefutable
patterns (the ones afer a `let`), even though only the type
checker can decide that they are truly irrefutable because they
are the only constructors of their types.
- I added natural numbers and bytes to patterns.
- Access of tuple components do not require parentheses now, like
`a.b.1.0`.
- I refactored the semantic actions.
- I added the empty sequence `begin end`.
- ParserLog.ml/ParserLog.mli
- I added a pretty-printer for the AST (with source locations).
- ParserMain.ml
- The CLI for the pretty-printer is now `--verbose=ast`.
- The old CLI `--verbose=ast` is now `--verbose=ast-tokens`.
- ligodity.ml (simplifier)
- I removed the constructions of sets, lists and maps with
`Set [...]`, `List [...]` and `Map [...]`, as there are already
better ways (that is, more like the OCaml's way), like
`Set.literal [...]` and `Map.literal [...]`. (The case for lists
was entirely redundant with the rest of the language as it is.)
- Everywhere there is now a non-empty list of elements, I made a
change. In particular, I removed a corner case ("let without
binding"), thanks to more precise OCaml types for non-empty
lists.
- I ported all the changes to the AST above.
- region.ml (vendors)
- I changed the method `compact` so the end-line is not repeated
if it is the same as the start line: this is even more compact. I
use this in the new pretty-printer for the AST (see above)
- I updated all the CameLIGO contracts.
2019-11-04 23:51:47 +01:00
|
|
|
(* TODO: move 1-parser/shared/Utils.ml{i} to Simple_utils/ *)
|
2019-05-14 15:57:25 +02:00
|
|
|
|
|
|
|
open Combinators
|
|
|
|
|
|
|
|
let nseq_to_list (hd, tl) = hd :: tl
|
|
|
|
let npseq_to_list (hd, tl) = hd :: (List.map snd tl)
|
|
|
|
let npseq_to_nelist (hd, tl) = hd, (List.map snd tl)
|
|
|
|
let pseq_to_list = function
|
|
|
|
| None -> []
|
|
|
|
| Some lst -> npseq_to_list lst
|
|
|
|
let get_value : 'a Raw.reg -> 'a = fun x -> x.value
|
|
|
|
|
2019-06-03 10:33:13 +00:00
|
|
|
module Errors = struct
|
|
|
|
let wrong_pattern expected_name actual =
|
|
|
|
let title () = "wrong pattern" in
|
2019-12-24 14:54:22 -08:00
|
|
|
let message () =
|
2019-12-29 01:24:22 +00:00
|
|
|
match actual with
|
|
|
|
| Raw.PVar v -> v.value
|
|
|
|
| Raw.PTuple _ -> "tuple"
|
|
|
|
| Raw.PRecord _ -> "record"
|
|
|
|
| Raw.PList _ -> "list"
|
|
|
|
| Raw.PBytes _ -> "bytes"
|
|
|
|
| _ -> "other"
|
2019-12-24 14:54:22 -08:00
|
|
|
in
|
2019-06-03 10:33:13 +00:00
|
|
|
let data = [
|
2019-06-03 17:43:25 +02:00
|
|
|
("expected", fun () -> expected_name);
|
2020-01-24 14:03:25 +01:00
|
|
|
("location",
|
|
|
|
fun () -> Format.asprintf "%a" Location.pp_lift @@
|
|
|
|
Raw.pattern_to_region actual)]
|
|
|
|
in error ~data title message
|
2019-06-03 10:33:13 +00:00
|
|
|
|
2020-05-15 17:46:56 +02:00
|
|
|
let unsupported_let_in_function (region : Region.t) (patterns : Raw.pattern list) =
|
2020-01-24 14:03:25 +01:00
|
|
|
let title () = "" in
|
|
|
|
let message () = "\nDefining functions with \"let ... in\" \
|
|
|
|
is not supported yet.\n" in
|
2019-12-24 15:35:05 -08:00
|
|
|
let patterns_loc =
|
|
|
|
List.fold_left (fun a p -> Region.cover a (Raw.pattern_to_region p))
|
2020-05-15 17:46:56 +02:00
|
|
|
region patterns in
|
2019-12-24 15:35:05 -08:00
|
|
|
let data = [
|
2020-01-24 14:03:25 +01:00
|
|
|
("location",
|
|
|
|
fun () -> Format.asprintf "%a" Location.pp_lift @@ patterns_loc)]
|
|
|
|
in error ~data title message
|
2019-12-24 15:35:05 -08:00
|
|
|
|
2019-06-03 17:43:25 +02:00
|
|
|
let unknown_predefined_type name =
|
2020-01-24 14:03:25 +01:00
|
|
|
let title () = "Type constants" in
|
2019-06-03 17:43:25 +02:00
|
|
|
let message () =
|
2020-01-24 14:03:25 +01:00
|
|
|
Format.asprintf "Unknown predefined type \"%s\".\n"
|
|
|
|
name.Region.value in
|
2019-06-03 17:43:25 +02:00
|
|
|
let data = [
|
2019-12-30 15:24:42 -06:00
|
|
|
("location",
|
2020-01-24 14:03:25 +01:00
|
|
|
fun () -> Format.asprintf "%a" Location.pp_lift @@ name.Region.region)]
|
|
|
|
in error ~data title message
|
2019-06-03 17:43:25 +02:00
|
|
|
|
2019-06-03 19:23:40 +02:00
|
|
|
let untyped_fun_param var =
|
2020-01-24 14:03:25 +01:00
|
|
|
let title () = "" in
|
2019-06-03 19:23:40 +02:00
|
|
|
let message () =
|
2020-01-24 14:03:25 +01:00
|
|
|
Format.asprintf "\nUntyped function parameters \
|
|
|
|
are not supported yet.\n" in
|
2019-06-03 19:23:40 +02:00
|
|
|
let param_loc = var.Region.region in
|
|
|
|
let data = [
|
2019-12-30 15:24:42 -06:00
|
|
|
("location",
|
2020-01-24 14:03:25 +01:00
|
|
|
fun () -> Format.asprintf "%a" Location.pp_lift @@ param_loc)]
|
|
|
|
in error ~data title message
|
2019-06-03 19:23:40 +02:00
|
|
|
|
2020-03-06 23:44:28 +01:00
|
|
|
let untyped_recursive_function var =
|
|
|
|
let title () = "" in
|
|
|
|
let message () =
|
2020-03-11 11:18:39 +01:00
|
|
|
Format.asprintf "\nUntyped recursive functions \
|
2020-03-06 23:44:28 +01:00
|
|
|
are not supported yet.\n" in
|
|
|
|
let param_loc = var.Region.region in
|
|
|
|
let data = [
|
|
|
|
("location",
|
|
|
|
fun () -> Format.asprintf "%a" Location.pp_lift @@ param_loc)]
|
|
|
|
in error ~data title message
|
|
|
|
|
2019-06-03 19:23:40 +02:00
|
|
|
let unsupported_tuple_pattern p =
|
2020-01-24 14:03:25 +01:00
|
|
|
let title () = "" in
|
2019-06-03 19:23:40 +02:00
|
|
|
let message () =
|
2020-01-24 14:03:25 +01:00
|
|
|
Format.asprintf "\nTuple patterns are not supported yet.\n" in
|
2019-06-04 16:12:17 +02:00
|
|
|
let pattern_loc = Raw.pattern_to_region p in
|
2019-06-03 19:23:40 +02:00
|
|
|
let data = [
|
2019-12-30 15:24:42 -06:00
|
|
|
("location",
|
2019-06-03 19:23:40 +02:00
|
|
|
fun () -> Format.asprintf "%a" Location.pp_lift @@ pattern_loc)
|
|
|
|
] in
|
|
|
|
error ~data title message
|
|
|
|
|
|
|
|
let unsupported_cst_constr p =
|
2020-01-24 14:03:25 +01:00
|
|
|
let title () = "" in
|
2019-06-03 19:23:40 +02:00
|
|
|
let message () =
|
2020-01-24 14:03:25 +01:00
|
|
|
Format.asprintf "\nConstant constructors are not supported yet.\n" in
|
2019-06-04 16:12:17 +02:00
|
|
|
let pattern_loc = Raw.pattern_to_region p in
|
2019-06-03 19:23:40 +02:00
|
|
|
let data = [
|
2019-12-30 15:24:42 -06:00
|
|
|
("location",
|
2020-01-24 14:03:25 +01:00
|
|
|
fun () -> Format.asprintf "%a" Location.pp_lift @@ pattern_loc)]
|
|
|
|
in error ~data title message
|
|
|
|
|
2019-06-04 13:45:21 +02:00
|
|
|
let unsupported_non_var_pattern p =
|
2020-01-24 14:03:25 +01:00
|
|
|
let title () = "" in
|
2019-06-04 13:45:21 +02:00
|
|
|
let message () =
|
2020-01-24 14:03:25 +01:00
|
|
|
Format.asprintf "\nNon-variable patterns in constructors \
|
|
|
|
are not supported yet.\n" in
|
2019-06-04 16:12:17 +02:00
|
|
|
let pattern_loc = Raw.pattern_to_region p in
|
2019-06-04 13:45:21 +02:00
|
|
|
let data = [
|
2019-12-30 15:24:42 -06:00
|
|
|
("location",
|
2019-06-04 13:45:21 +02:00
|
|
|
fun () -> Format.asprintf "%a" Location.pp_lift @@ pattern_loc)
|
|
|
|
] in
|
|
|
|
error ~data title message
|
|
|
|
|
2020-03-12 23:20:39 +01:00
|
|
|
let abstracting_expr t =
|
|
|
|
let title () = "abstracting expression" in
|
2019-06-04 13:45:21 +02:00
|
|
|
let message () = "" in
|
|
|
|
let data = [
|
Refactoring of comments (for [dune build @doc]).
Refactoring of parsing command-line arguments
* The type [options] is now abstract and implemented as an
object type to avoid struggling with scoping and type
inference when record types share some common field names.
Refactoring of ParserLog for PascaLIGO and CameLIGO
* The immediate motivation behind that refactoring was to
remove the use of a couple of global references. A
consequence is that we have a nicer and more compact code, by
threading a state. The files [pascaligo/Tests/pp.ligo] and
[ligodity/Tests/pp.mligo].
* Another consequence is that the choice of making strings from
AST nodes depends on the CLI (offsets? mode?). After this
refactoring, that choice is hardcoded in the simplifiers in a
few places (TODO), waiting for a general solution that would
have all CL options flow through the compiler.
* I removed the use of vendors [x_option.ml], [x_map.ml] and
[x_list.ml] when handling optional values. (Less dependencies
this way.)
Refactoring of the ASTs
* I removed the node [local_decl], which was set to [[]]
already in a previous commit (which removed local
declarations as being redundant, as statements could already
be instructions or declarations).
* I changed [StrLit] to [String] in the AST of CameLIGO and
ReasonLIGO.
* I also changed the type [fun_expr] so now either a block is
present, and therefore followed by the [with] keyword, or it
is not. (Before, the presence of a block was not enforced in
the type with the presence of the keyword.)
Notes
* [LexerMain.ml] and [ParserMain.ml] for CameLIGO and PascaLIGO
are almost identical and differ in the same way (language
name and file extension), which suggests that they should be
in the [shared] folder and instanciated as a functor in the
future (TODO).
* I removed the blank characters at the end of many lines in
the parser of ReasonLIGO.
2019-12-13 12:21:52 +01:00
|
|
|
("expression" ,
|
|
|
|
(** TODO: The labelled arguments should be flowing from the CLI. *)
|
2020-04-12 15:26:47 +02:00
|
|
|
thunk @@ Parser_cameligo.ParserLog.expr_to_string
|
2020-01-24 14:03:25 +01:00
|
|
|
~offsets:true ~mode:`Point t)]
|
|
|
|
in error ~data title message
|
2019-06-04 13:45:21 +02:00
|
|
|
|
|
|
|
let only_constructors p =
|
2020-01-24 14:03:25 +01:00
|
|
|
let title () = "" in
|
2019-06-04 13:45:21 +02:00
|
|
|
let message () =
|
2020-01-24 14:03:25 +01:00
|
|
|
Format.asprintf "\nCurrently, only constructors are \
|
|
|
|
supported in patterns.\n" in
|
2019-06-04 16:12:17 +02:00
|
|
|
let pattern_loc = Raw.pattern_to_region p in
|
2019-06-04 13:45:21 +02:00
|
|
|
let data = [
|
2019-12-30 15:24:42 -06:00
|
|
|
("location",
|
2019-06-04 13:45:21 +02:00
|
|
|
fun () -> Format.asprintf "%a" Location.pp_lift @@ pattern_loc)
|
|
|
|
] in
|
|
|
|
error ~data title message
|
|
|
|
|
|
|
|
let unsupported_sugared_lists region =
|
2020-01-24 14:03:25 +01:00
|
|
|
let title () = "" in
|
2019-06-04 13:45:21 +02:00
|
|
|
let message () =
|
2020-01-24 14:03:25 +01:00
|
|
|
Format.asprintf "\nCurrently, only empty lists and \
|
|
|
|
constructors (::) \
|
|
|
|
are supported in patterns.\n" in
|
2019-06-04 13:45:21 +02:00
|
|
|
let data = [
|
2019-12-30 15:24:42 -06:00
|
|
|
("location",
|
2020-01-24 14:03:25 +01:00
|
|
|
fun () -> Format.asprintf "%a" Location.pp_lift @@ region)]
|
|
|
|
in error ~data title message
|
2019-12-24 15:35:05 -08:00
|
|
|
|
|
|
|
let corner_case description =
|
2020-01-24 14:03:25 +01:00
|
|
|
let title () = "Corner case" in
|
2019-12-24 15:35:05 -08:00
|
|
|
let message () = description in
|
|
|
|
error title message
|
|
|
|
|
2020-04-20 17:39:36 +02:00
|
|
|
let unknown_built_in name =
|
|
|
|
let title () = "\n Unknown built-in function" in
|
|
|
|
let message () = "" in
|
|
|
|
let data = [
|
|
|
|
("built-in", fun () -> name);
|
|
|
|
] in
|
|
|
|
error ~data title message
|
|
|
|
|
2019-06-03 10:33:13 +00:00
|
|
|
end
|
2019-06-03 17:43:25 +02:00
|
|
|
|
2019-06-03 10:33:13 +00:00
|
|
|
open Errors
|
2019-06-03 12:23:46 +00:00
|
|
|
|
2020-03-16 14:53:56 +01:00
|
|
|
open Operators.Concrete_to_imperative.Cameligo
|
2019-05-14 15:57:25 +02:00
|
|
|
|
2019-05-28 16:34:53 +00:00
|
|
|
let r_split = Location.r_split
|
|
|
|
|
2020-04-16 22:48:34 +02:00
|
|
|
let get_t_string_singleton_opt = function
|
2020-05-20 16:36:44 +00:00
|
|
|
| Raw.TString s -> Some s.value
|
2020-04-16 22:48:34 +02:00
|
|
|
| _ -> None
|
|
|
|
|
2019-06-01 11:29:31 +00:00
|
|
|
let rec pattern_to_var : Raw.pattern -> _ = fun p ->
|
|
|
|
match p with
|
|
|
|
| Raw.PPar p -> pattern_to_var p.value.inside
|
|
|
|
| Raw.PVar v -> ok v
|
2019-06-10 22:06:00 +00:00
|
|
|
| Raw.PWild r -> ok @@ ({ region = r ; value = "_" } : Raw.variable)
|
2019-12-29 01:24:22 +00:00
|
|
|
| _ -> fail @@ wrong_pattern "single var" p
|
2019-06-01 11:29:31 +00:00
|
|
|
|
2020-02-27 01:36:56 +01:00
|
|
|
let rec tuple_pattern_to_vars : Raw.pattern -> _ = fun pattern ->
|
|
|
|
match pattern with
|
|
|
|
| Raw.PPar pp -> tuple_pattern_to_vars pp.value.inside
|
|
|
|
| Raw.PTuple pt -> bind_map_list pattern_to_var (npseq_to_list pt.value)
|
|
|
|
| Raw.PVar _ | Raw.PWild _-> bind_list [pattern_to_var pattern]
|
|
|
|
| other -> (fail @@ wrong_pattern "parenthetical, tuple, or variable" other)
|
|
|
|
|
|
|
|
|
2019-06-01 11:29:31 +00:00
|
|
|
let rec pattern_to_typed_var : Raw.pattern -> _ = fun p ->
|
|
|
|
match p with
|
|
|
|
| Raw.PPar p -> pattern_to_typed_var p.value.inside
|
|
|
|
| Raw.PTyped tp -> (
|
|
|
|
let tp = tp.value in
|
|
|
|
let%bind v = pattern_to_var tp.pattern in
|
|
|
|
ok (v , Some tp.type_expr)
|
|
|
|
)
|
|
|
|
| Raw.PVar v -> ok (v , None)
|
2019-06-10 22:06:00 +00:00
|
|
|
| Raw.PWild r -> ok (({ region = r ; value = "_" } : Raw.variable) , None)
|
2019-12-29 01:24:22 +00:00
|
|
|
| _ -> fail @@ wrong_pattern "single typed variable" p
|
2019-06-01 11:29:31 +00:00
|
|
|
|
2020-03-07 02:39:39 +01:00
|
|
|
let rec expr_to_typed_expr : Raw.expr -> _ = function
|
|
|
|
EPar e -> expr_to_typed_expr e.value.inside
|
|
|
|
| EAnnot {value={inside=e,_,t; _}; _} -> ok (e, Some t)
|
|
|
|
| e -> ok (e , None)
|
|
|
|
|
2019-12-29 01:24:22 +00:00
|
|
|
let rec tuple_pattern_to_typed_vars : Raw.pattern -> _ = fun pattern ->
|
|
|
|
match pattern with
|
|
|
|
| Raw.PPar pp -> tuple_pattern_to_typed_vars pp.value.inside
|
|
|
|
| Raw.PTuple pt -> bind_map_list pattern_to_typed_var (npseq_to_list pt.value)
|
|
|
|
| Raw.PVar _ -> bind_list [pattern_to_typed_var pattern]
|
|
|
|
| other -> (fail @@ wrong_pattern "parenthetical, tuple, or variable" other)
|
2019-06-01 11:29:31 +00:00
|
|
|
|
2020-02-27 01:36:56 +01:00
|
|
|
let rec typed_pattern_to_typed_vars : Raw.pattern -> _ = fun pattern ->
|
|
|
|
match pattern with
|
|
|
|
| Raw.PPar pp -> typed_pattern_to_typed_vars pp.value.inside
|
|
|
|
| Raw.PTyped pt ->
|
|
|
|
let (p,t) = pt.value.pattern,pt.value.type_expr in
|
2020-04-12 15:26:47 +02:00
|
|
|
let%bind p = tuple_pattern_to_vars p in
|
2020-03-16 14:53:56 +01:00
|
|
|
let%bind t = compile_type_expression t in
|
2020-05-19 18:53:20 +02:00
|
|
|
let l = Location.lift pt.region in
|
|
|
|
ok @@ (p,t,l)
|
2020-02-27 01:36:56 +01:00
|
|
|
| other -> (fail @@ wrong_pattern "parenthetical or type annotation" other)
|
|
|
|
|
|
|
|
and unpar_pattern : Raw.pattern -> Raw.pattern = function
|
2020-01-21 21:23:31 +01:00
|
|
|
| PPar p -> unpar_pattern p.value.inside
|
|
|
|
| _ as p -> p
|
|
|
|
|
2020-03-16 14:53:56 +01:00
|
|
|
and compile_type_expression : Raw.type_expr -> type_expression result = fun te ->
|
2020-03-12 23:20:39 +01:00
|
|
|
trace (simple_info "abstracting this type expression...") @@
|
2019-06-03 12:23:46 +00:00
|
|
|
match te with
|
2020-03-16 14:53:56 +01:00
|
|
|
TPar x -> compile_type_expression x.value.inside
|
Refactoring of Ligodity (CameLIGO) and making an AST pretty-printer
- AST.ml/AST.mli:
- The AST now distinguishes the constructors `None` and `Some` as being
predefined, as in PascaLIGO. See type `AST.constr_pattern`.
- I removed the nodes specific to Liquidity,
e.g. `let%entry`, and, in particular, the natural literals
ending with `p`. Now it should be `n`, as in `10n`.
- I renamed the node `TAlias` to `TVar`.
- I have applied the rule of expanding type expressions after `of` when
those were not records.
- The type of the argument to a data constructor is now
`type_expr`, instead of `cartesian`.
- I added the patterns for bytes (`PBytes`) and natural literals (`PNat`).
- I renamed the node `Sugar` into
`PListComp` (meaning "pattern of list comprehension").
- Record types in CameLIGO now must have at least one field declaration.
- Replaced the type `closing` and `opening` with one type `compound`,
which captures only the right combinations of opening and closing.
- Components of tuples in a selection must not be written
between parentheses. For example, `a.b.(1).(0)` is now
`a.b.1.0`, as in PascaLIGO.
- LexToken.mli/LexToken.mll
- I renamed the string literal `Str` into `String`.
- I added the tokens `C_None` and `C_Some` (to distinguish the
constructors `None` and `Some`. See AST.ml)
- Fixed the function `mk_sym` so it does not fail with `failwith`, but
with `Error Invalid_symbol`.
- Lexer.mll (shared)
- I removed the character `%` from the identifiers (used to
support Liquidity, like `entry%point` and `match%nat`).
- I adde to the hint on broken strings: "or insert a backslash"
(from a Gitlab issue).
- ParToken.mly
- I added the tokens `C_None` and `C_Some` (to distinguish the
constructors `None` and `Some`. See AST.ml and LexToken.mll)
- Parser.mly
- Fixed the order of declarations in the AST (it was reversed).
- I removed syntax support for Liquidity.
- I added user-defined constructor applications to irrefutable
patterns (the ones afer a `let`), even though only the type
checker can decide that they are truly irrefutable because they
are the only constructors of their types.
- I added natural numbers and bytes to patterns.
- Access of tuple components do not require parentheses now, like
`a.b.1.0`.
- I refactored the semantic actions.
- I added the empty sequence `begin end`.
- ParserLog.ml/ParserLog.mli
- I added a pretty-printer for the AST (with source locations).
- ParserMain.ml
- The CLI for the pretty-printer is now `--verbose=ast`.
- The old CLI `--verbose=ast` is now `--verbose=ast-tokens`.
- ligodity.ml (simplifier)
- I removed the constructions of sets, lists and maps with
`Set [...]`, `List [...]` and `Map [...]`, as there are already
better ways (that is, more like the OCaml's way), like
`Set.literal [...]` and `Map.literal [...]`. (The case for lists
was entirely redundant with the rest of the language as it is.)
- Everywhere there is now a non-empty list of elements, I made a
change. In particular, I removed a corner case ("let without
binding"), thanks to more precise OCaml types for non-empty
lists.
- I ported all the changes to the AST above.
- region.ml (vendors)
- I changed the method `compact` so the end-line is not repeated
if it is the same as the start line: this is even more compact. I
use this in the new pretty-printer for the AST (see above)
- I updated all the CameLIGO contracts.
2019-11-04 23:51:47 +01:00
|
|
|
| TVar v -> (
|
2020-04-09 18:19:22 +02:00
|
|
|
let (v, loc) = r_split v in
|
|
|
|
match type_constants v with
|
2020-04-20 17:39:36 +02:00
|
|
|
| Some s -> ok @@ make_t ~loc @@ T_constant s
|
|
|
|
| None -> ok @@ make_t ~loc @@ T_variable (Var.of_name v)
|
2019-05-14 15:57:25 +02:00
|
|
|
)
|
|
|
|
| TFun x -> (
|
2020-04-09 18:19:22 +02:00
|
|
|
let (x,loc) = r_split x in
|
2019-12-04 18:30:52 +01:00
|
|
|
let%bind (type1 , type2) =
|
2020-04-09 18:19:22 +02:00
|
|
|
let (a , _ , b) = x in
|
2020-03-16 14:53:56 +01:00
|
|
|
let%bind a = compile_type_expression a in
|
|
|
|
let%bind b = compile_type_expression b in
|
2019-06-03 12:23:46 +00:00
|
|
|
ok (a , b)
|
|
|
|
in
|
2020-04-09 18:19:22 +02:00
|
|
|
ok @@ make_t ~loc @@ T_arrow {type1;type2}
|
2019-05-14 15:57:25 +02:00
|
|
|
)
|
2019-06-04 08:21:13 +00:00
|
|
|
| TApp x -> (
|
2020-04-09 18:19:22 +02:00
|
|
|
let (x,loc) = r_split x in
|
|
|
|
let (name, tuple) = x in
|
2020-04-16 22:48:34 +02:00
|
|
|
( match name.value with
|
2020-05-20 16:36:44 +00:00
|
|
|
| "michelson_or" ->
|
2020-04-16 22:48:34 +02:00
|
|
|
let lst = npseq_to_list tuple.value.inside in
|
|
|
|
(match lst with
|
|
|
|
| [a ; b ; c ; d ] -> (
|
|
|
|
let%bind b' =
|
|
|
|
trace_option (simple_error "second argument of michelson_or must be a string singleton") @@
|
|
|
|
get_t_string_singleton_opt b in
|
|
|
|
let%bind d' =
|
|
|
|
trace_option (simple_error "fourth argument of michelson_or must be a string singleton") @@
|
|
|
|
get_t_string_singleton_opt d in
|
|
|
|
let%bind a' = compile_type_expression a in
|
|
|
|
let%bind c' = compile_type_expression c in
|
|
|
|
ok @@ t_michelson_or ~loc a' b' c' d'
|
|
|
|
)
|
|
|
|
| _ -> simple_fail "michelson_or does not have the right number of argument")
|
2020-04-18 00:13:50 +02:00
|
|
|
| "michelson_pair" ->
|
|
|
|
let lst = npseq_to_list tuple.value.inside in
|
|
|
|
(match lst with
|
|
|
|
| [a ; b ; c ; d ] -> (
|
|
|
|
let%bind b' =
|
|
|
|
trace_option (simple_error "second argument of michelson_pair must be a string singleton") @@
|
|
|
|
get_t_string_singleton_opt b in
|
|
|
|
let%bind d' =
|
|
|
|
trace_option (simple_error "fourth argument of michelson_pair must be a string singleton") @@
|
|
|
|
get_t_string_singleton_opt d in
|
|
|
|
let%bind a' = compile_type_expression a in
|
|
|
|
let%bind c' = compile_type_expression c in
|
|
|
|
ok @@ t_michelson_pair ~loc a' b' c' d'
|
|
|
|
)
|
|
|
|
| _ -> simple_fail "michelson_pair does not have the right number of argument")
|
2020-04-16 22:48:34 +02:00
|
|
|
| _ ->
|
|
|
|
let lst = npseq_to_list tuple.value.inside in
|
|
|
|
let%bind lst' = bind_map_list compile_type_expression lst in
|
|
|
|
let%bind cst =
|
2020-04-20 17:39:36 +02:00
|
|
|
trace_option (unknown_predefined_type name) @@
|
2020-04-16 22:48:34 +02:00
|
|
|
type_operators name.value in
|
|
|
|
t_operator ~loc cst lst' )
|
2019-06-04 08:21:13 +00:00
|
|
|
)
|
|
|
|
| TProd p -> (
|
2020-03-16 14:53:56 +01:00
|
|
|
let%bind tpl = compile_list_type_expression @@ npseq_to_list p.value in
|
2019-05-14 15:57:25 +02:00
|
|
|
ok tpl
|
2019-06-04 08:21:13 +00:00
|
|
|
)
|
2019-05-14 15:57:25 +02:00
|
|
|
| TRecord r ->
|
2020-04-09 18:19:22 +02:00
|
|
|
let (r, loc) = r_split r in
|
2020-03-16 14:53:56 +01:00
|
|
|
let aux = fun (x, y) -> let%bind y = compile_type_expression y in ok (x, y) in
|
2020-04-22 19:44:21 +02:00
|
|
|
let order = fun i (x,y) -> ((x,i),y) in
|
2019-06-04 13:45:21 +02:00
|
|
|
let apply (x:Raw.field_decl Raw.reg) =
|
|
|
|
(x.value.field_name.value, x.value.field_type) in
|
2019-06-03 12:23:46 +00:00
|
|
|
let%bind lst =
|
|
|
|
bind_list
|
2019-05-14 15:57:25 +02:00
|
|
|
@@ List.map aux
|
2020-04-22 19:44:21 +02:00
|
|
|
@@ List.mapi order
|
2019-06-04 13:45:21 +02:00
|
|
|
@@ List.map apply
|
2020-04-09 18:19:22 +02:00
|
|
|
@@ npseq_to_list r.ne_elements in
|
2020-04-28 16:58:47 +02:00
|
|
|
let m = List.fold_left (fun m ((x,i), y) -> LMap.add (Label x) {field_type=y;field_decl_pos=i} m) LMap.empty lst in
|
2020-04-09 18:19:22 +02:00
|
|
|
ok @@ make_t ~loc @@ T_record m
|
2019-05-14 15:57:25 +02:00
|
|
|
| TSum s ->
|
2020-04-09 18:19:22 +02:00
|
|
|
let (s,loc) = r_split s in
|
2020-04-29 23:17:29 +02:00
|
|
|
let aux i (v:Raw.variant Raw.reg) =
|
2019-05-14 15:57:25 +02:00
|
|
|
let args =
|
Refactoring of Ligodity (CameLIGO) and making an AST pretty-printer
- AST.ml/AST.mli:
- The AST now distinguishes the constructors `None` and `Some` as being
predefined, as in PascaLIGO. See type `AST.constr_pattern`.
- I removed the nodes specific to Liquidity,
e.g. `let%entry`, and, in particular, the natural literals
ending with `p`. Now it should be `n`, as in `10n`.
- I renamed the node `TAlias` to `TVar`.
- I have applied the rule of expanding type expressions after `of` when
those were not records.
- The type of the argument to a data constructor is now
`type_expr`, instead of `cartesian`.
- I added the patterns for bytes (`PBytes`) and natural literals (`PNat`).
- I renamed the node `Sugar` into
`PListComp` (meaning "pattern of list comprehension").
- Record types in CameLIGO now must have at least one field declaration.
- Replaced the type `closing` and `opening` with one type `compound`,
which captures only the right combinations of opening and closing.
- Components of tuples in a selection must not be written
between parentheses. For example, `a.b.(1).(0)` is now
`a.b.1.0`, as in PascaLIGO.
- LexToken.mli/LexToken.mll
- I renamed the string literal `Str` into `String`.
- I added the tokens `C_None` and `C_Some` (to distinguish the
constructors `None` and `Some`. See AST.ml)
- Fixed the function `mk_sym` so it does not fail with `failwith`, but
with `Error Invalid_symbol`.
- Lexer.mll (shared)
- I removed the character `%` from the identifiers (used to
support Liquidity, like `entry%point` and `match%nat`).
- I adde to the hint on broken strings: "or insert a backslash"
(from a Gitlab issue).
- ParToken.mly
- I added the tokens `C_None` and `C_Some` (to distinguish the
constructors `None` and `Some`. See AST.ml and LexToken.mll)
- Parser.mly
- Fixed the order of declarations in the AST (it was reversed).
- I removed syntax support for Liquidity.
- I added user-defined constructor applications to irrefutable
patterns (the ones afer a `let`), even though only the type
checker can decide that they are truly irrefutable because they
are the only constructors of their types.
- I added natural numbers and bytes to patterns.
- Access of tuple components do not require parentheses now, like
`a.b.1.0`.
- I refactored the semantic actions.
- I added the empty sequence `begin end`.
- ParserLog.ml/ParserLog.mli
- I added a pretty-printer for the AST (with source locations).
- ParserMain.ml
- The CLI for the pretty-printer is now `--verbose=ast`.
- The old CLI `--verbose=ast` is now `--verbose=ast-tokens`.
- ligodity.ml (simplifier)
- I removed the constructions of sets, lists and maps with
`Set [...]`, `List [...]` and `Map [...]`, as there are already
better ways (that is, more like the OCaml's way), like
`Set.literal [...]` and `Map.literal [...]`. (The case for lists
was entirely redundant with the rest of the language as it is.)
- Everywhere there is now a non-empty list of elements, I made a
change. In particular, I removed a corner case ("let without
binding"), thanks to more precise OCaml types for non-empty
lists.
- I ported all the changes to the AST above.
- region.ml (vendors)
- I changed the method `compact` so the end-line is not repeated
if it is the same as the start line: this is even more compact. I
use this in the new pretty-printer for the AST (see above)
- I updated all the CameLIGO contracts.
2019-11-04 23:51:47 +01:00
|
|
|
match v.value.arg with
|
2019-05-14 15:57:25 +02:00
|
|
|
None -> []
|
Refactoring of Ligodity (CameLIGO) and making an AST pretty-printer
- AST.ml/AST.mli:
- The AST now distinguishes the constructors `None` and `Some` as being
predefined, as in PascaLIGO. See type `AST.constr_pattern`.
- I removed the nodes specific to Liquidity,
e.g. `let%entry`, and, in particular, the natural literals
ending with `p`. Now it should be `n`, as in `10n`.
- I renamed the node `TAlias` to `TVar`.
- I have applied the rule of expanding type expressions after `of` when
those were not records.
- The type of the argument to a data constructor is now
`type_expr`, instead of `cartesian`.
- I added the patterns for bytes (`PBytes`) and natural literals (`PNat`).
- I renamed the node `Sugar` into
`PListComp` (meaning "pattern of list comprehension").
- Record types in CameLIGO now must have at least one field declaration.
- Replaced the type `closing` and `opening` with one type `compound`,
which captures only the right combinations of opening and closing.
- Components of tuples in a selection must not be written
between parentheses. For example, `a.b.(1).(0)` is now
`a.b.1.0`, as in PascaLIGO.
- LexToken.mli/LexToken.mll
- I renamed the string literal `Str` into `String`.
- I added the tokens `C_None` and `C_Some` (to distinguish the
constructors `None` and `Some`. See AST.ml)
- Fixed the function `mk_sym` so it does not fail with `failwith`, but
with `Error Invalid_symbol`.
- Lexer.mll (shared)
- I removed the character `%` from the identifiers (used to
support Liquidity, like `entry%point` and `match%nat`).
- I adde to the hint on broken strings: "or insert a backslash"
(from a Gitlab issue).
- ParToken.mly
- I added the tokens `C_None` and `C_Some` (to distinguish the
constructors `None` and `Some`. See AST.ml and LexToken.mll)
- Parser.mly
- Fixed the order of declarations in the AST (it was reversed).
- I removed syntax support for Liquidity.
- I added user-defined constructor applications to irrefutable
patterns (the ones afer a `let`), even though only the type
checker can decide that they are truly irrefutable because they
are the only constructors of their types.
- I added natural numbers and bytes to patterns.
- Access of tuple components do not require parentheses now, like
`a.b.1.0`.
- I refactored the semantic actions.
- I added the empty sequence `begin end`.
- ParserLog.ml/ParserLog.mli
- I added a pretty-printer for the AST (with source locations).
- ParserMain.ml
- The CLI for the pretty-printer is now `--verbose=ast`.
- The old CLI `--verbose=ast` is now `--verbose=ast-tokens`.
- ligodity.ml (simplifier)
- I removed the constructions of sets, lists and maps with
`Set [...]`, `List [...]` and `Map [...]`, as there are already
better ways (that is, more like the OCaml's way), like
`Set.literal [...]` and `Map.literal [...]`. (The case for lists
was entirely redundant with the rest of the language as it is.)
- Everywhere there is now a non-empty list of elements, I made a
change. In particular, I removed a corner case ("let without
binding"), thanks to more precise OCaml types for non-empty
lists.
- I ported all the changes to the AST above.
- region.ml (vendors)
- I changed the method `compact` so the end-line is not repeated
if it is the same as the start line: this is even more compact. I
use this in the new pretty-printer for the AST (see above)
- I updated all the CameLIGO contracts.
2019-11-04 23:51:47 +01:00
|
|
|
| Some (_, TProd product) -> npseq_to_list product.value
|
|
|
|
| Some (_, t_expr) -> [t_expr] in
|
2020-03-16 14:53:56 +01:00
|
|
|
let%bind te = compile_list_type_expression @@ args in
|
2020-04-29 23:17:29 +02:00
|
|
|
ok ((v.value.constr.value,i), te) in
|
2019-05-14 15:57:25 +02:00
|
|
|
let%bind lst = bind_list
|
2020-04-29 23:17:29 +02:00
|
|
|
@@ List.mapi aux
|
2020-04-09 18:19:22 +02:00
|
|
|
@@ npseq_to_list s in
|
2020-04-29 23:17:29 +02:00
|
|
|
let m = List.fold_left (fun m ((x,i), y) -> CMap.add (Constructor x) {ctor_type=y;ctor_decl_pos=i} m) CMap.empty lst in
|
2020-04-09 18:19:22 +02:00
|
|
|
ok @@ make_t ~loc @@ T_sum m
|
2020-05-20 16:36:44 +00:00
|
|
|
| TString _s -> simple_fail "we don't support singleton string type"
|
2019-05-14 15:57:25 +02:00
|
|
|
|
2020-03-16 14:53:56 +01:00
|
|
|
and compile_list_type_expression (lst:Raw.type_expr list) : type_expression result =
|
2019-05-14 15:57:25 +02:00
|
|
|
match lst with
|
2020-04-09 18:19:22 +02:00
|
|
|
| [] -> ok @@ t_unit ()
|
2020-03-16 14:53:56 +01:00
|
|
|
| [hd] -> compile_type_expression hd
|
2019-05-14 15:57:25 +02:00
|
|
|
| lst ->
|
2020-03-16 14:53:56 +01:00
|
|
|
let%bind lst = bind_map_list compile_type_expression lst in
|
2019-12-04 18:30:52 +01:00
|
|
|
ok @@ t_tuple lst
|
2019-05-14 15:57:25 +02:00
|
|
|
|
2020-03-16 14:53:56 +01:00
|
|
|
let rec compile_expression :
|
2019-05-28 16:34:53 +00:00
|
|
|
Raw.expr -> expr result = fun t ->
|
|
|
|
let return x = ok x in
|
2020-03-16 14:53:56 +01:00
|
|
|
let compile_projection = fun (p:Raw.projection Region.reg) ->
|
2019-05-28 16:34:53 +00:00
|
|
|
let (p , loc) = r_split p in
|
2019-05-14 15:57:25 +02:00
|
|
|
let var =
|
2019-12-04 11:40:58 +00:00
|
|
|
let name = Var.of_name p.struct_name.value in
|
2019-05-23 07:49:06 +00:00
|
|
|
e_variable name in
|
2019-05-14 15:57:25 +02:00
|
|
|
let path = p.field_path in
|
|
|
|
let path' =
|
|
|
|
let aux (s:Raw.selection) =
|
|
|
|
match s with
|
2019-12-04 18:30:52 +01:00
|
|
|
FieldName property -> property.value
|
|
|
|
| Component index -> Z.to_string (snd index.value)
|
2019-05-14 15:57:25 +02:00
|
|
|
in
|
|
|
|
List.map aux @@ npseq_to_list path in
|
2020-04-03 17:39:48 +02:00
|
|
|
return @@ List.fold_left (e_record_accessor ~loc ) var path'
|
2019-05-14 15:57:25 +02:00
|
|
|
in
|
2020-03-16 14:53:56 +01:00
|
|
|
let compile_path : Raw.path -> string * label list = fun p ->
|
2020-01-09 18:23:37 +01:00
|
|
|
match p with
|
|
|
|
| Raw.Name v -> (v.value , [])
|
|
|
|
| Raw.Path p -> (
|
|
|
|
let p' = p.value in
|
|
|
|
let var = p'.struct_name.value in
|
|
|
|
let path = p'.field_path in
|
|
|
|
let path' =
|
|
|
|
let aux (s:Raw.selection) =
|
|
|
|
match s with
|
2019-12-04 18:30:52 +01:00
|
|
|
| FieldName property -> Label property.value
|
|
|
|
| Component index -> Label (Z.to_string (snd index.value))
|
2020-01-09 18:23:37 +01:00
|
|
|
in
|
|
|
|
List.map aux @@ npseq_to_list path in
|
|
|
|
(var , path')
|
|
|
|
)
|
|
|
|
in
|
2020-03-16 14:53:56 +01:00
|
|
|
let compile_update = fun (u:Raw.update Region.reg) ->
|
2020-01-09 18:23:37 +01:00
|
|
|
let (u, loc) = r_split u in
|
2020-03-16 14:53:56 +01:00
|
|
|
let (name, path) = compile_path u.record in
|
2020-01-24 14:03:25 +01:00
|
|
|
let record = match path with
|
2020-01-09 18:23:37 +01:00
|
|
|
| [] -> e_variable (Var.of_name name)
|
2019-12-04 18:30:52 +01:00
|
|
|
| _ ->
|
2020-04-03 17:39:48 +02:00
|
|
|
let aux expr (Label l) = e_record_accessor expr l in
|
2020-04-12 15:26:47 +02:00
|
|
|
List.fold_left aux (e_variable (Var.of_name name)) path in
|
2020-01-09 18:23:37 +01:00
|
|
|
let updates = u.updates.value.ne_elements in
|
|
|
|
let%bind updates' =
|
2020-01-28 14:12:46 +00:00
|
|
|
let aux (f:Raw.field_path_assign Raw.reg) =
|
2020-01-09 18:23:37 +01:00
|
|
|
let (f,_) = r_split f in
|
2020-03-16 14:53:56 +01:00
|
|
|
let%bind expr = compile_expression f.field_expr in
|
2020-01-28 14:12:46 +00:00
|
|
|
ok ( List.map (fun (x: _ Raw.reg) -> x.value) (npseq_to_list f.field_path), expr)
|
2020-01-09 18:23:37 +01:00
|
|
|
in
|
2020-01-24 14:03:25 +01:00
|
|
|
bind_map_list aux @@ npseq_to_list updates
|
2020-01-09 18:23:37 +01:00
|
|
|
in
|
2020-04-12 15:26:47 +02:00
|
|
|
let aux ur (path, expr) =
|
2020-01-28 14:12:46 +00:00
|
|
|
let rec aux record = function
|
|
|
|
| [] -> failwith "error in parsing"
|
2020-04-03 17:39:48 +02:00
|
|
|
| hd :: [] -> ok @@ e_record_update ~loc record hd expr
|
2020-04-12 15:26:47 +02:00
|
|
|
| hd :: tl ->
|
2020-04-03 17:39:48 +02:00
|
|
|
let%bind expr = (aux (e_record_accessor ~loc record hd) tl) in
|
2020-04-12 15:26:47 +02:00
|
|
|
ok @@ e_record_update ~loc record hd expr
|
2020-01-28 14:12:46 +00:00
|
|
|
in
|
|
|
|
aux ur path in
|
|
|
|
bind_fold_list aux record updates'
|
2020-01-09 18:23:37 +01:00
|
|
|
in
|
2019-05-20 21:42:11 +02:00
|
|
|
|
2020-03-12 23:20:39 +01:00
|
|
|
trace (abstracting_expr t) @@
|
2019-05-14 15:57:25 +02:00
|
|
|
match t with
|
Refactoring of Ligodity (CameLIGO) and making an AST pretty-printer
- AST.ml/AST.mli:
- The AST now distinguishes the constructors `None` and `Some` as being
predefined, as in PascaLIGO. See type `AST.constr_pattern`.
- I removed the nodes specific to Liquidity,
e.g. `let%entry`, and, in particular, the natural literals
ending with `p`. Now it should be `n`, as in `10n`.
- I renamed the node `TAlias` to `TVar`.
- I have applied the rule of expanding type expressions after `of` when
those were not records.
- The type of the argument to a data constructor is now
`type_expr`, instead of `cartesian`.
- I added the patterns for bytes (`PBytes`) and natural literals (`PNat`).
- I renamed the node `Sugar` into
`PListComp` (meaning "pattern of list comprehension").
- Record types in CameLIGO now must have at least one field declaration.
- Replaced the type `closing` and `opening` with one type `compound`,
which captures only the right combinations of opening and closing.
- Components of tuples in a selection must not be written
between parentheses. For example, `a.b.(1).(0)` is now
`a.b.1.0`, as in PascaLIGO.
- LexToken.mli/LexToken.mll
- I renamed the string literal `Str` into `String`.
- I added the tokens `C_None` and `C_Some` (to distinguish the
constructors `None` and `Some`. See AST.ml)
- Fixed the function `mk_sym` so it does not fail with `failwith`, but
with `Error Invalid_symbol`.
- Lexer.mll (shared)
- I removed the character `%` from the identifiers (used to
support Liquidity, like `entry%point` and `match%nat`).
- I adde to the hint on broken strings: "or insert a backslash"
(from a Gitlab issue).
- ParToken.mly
- I added the tokens `C_None` and `C_Some` (to distinguish the
constructors `None` and `Some`. See AST.ml and LexToken.mll)
- Parser.mly
- Fixed the order of declarations in the AST (it was reversed).
- I removed syntax support for Liquidity.
- I added user-defined constructor applications to irrefutable
patterns (the ones afer a `let`), even though only the type
checker can decide that they are truly irrefutable because they
are the only constructors of their types.
- I added natural numbers and bytes to patterns.
- Access of tuple components do not require parentheses now, like
`a.b.1.0`.
- I refactored the semantic actions.
- I added the empty sequence `begin end`.
- ParserLog.ml/ParserLog.mli
- I added a pretty-printer for the AST (with source locations).
- ParserMain.ml
- The CLI for the pretty-printer is now `--verbose=ast`.
- The old CLI `--verbose=ast` is now `--verbose=ast-tokens`.
- ligodity.ml (simplifier)
- I removed the constructions of sets, lists and maps with
`Set [...]`, `List [...]` and `Map [...]`, as there are already
better ways (that is, more like the OCaml's way), like
`Set.literal [...]` and `Map.literal [...]`. (The case for lists
was entirely redundant with the rest of the language as it is.)
- Everywhere there is now a non-empty list of elements, I made a
change. In particular, I removed a corner case ("let without
binding"), thanks to more precise OCaml types for non-empty
lists.
- I ported all the changes to the AST above.
- region.ml (vendors)
- I changed the method `compact` so the end-line is not repeated
if it is the same as the start line: this is even more compact. I
use this in the new pretty-printer for the AST (see above)
- I updated all the CameLIGO contracts.
2019-11-04 23:51:47 +01:00
|
|
|
Raw.ELetIn e ->
|
2020-03-09 00:13:07 +01:00
|
|
|
let Raw.{kwd_rec; binding; body; attributes; _} = e.value in
|
2020-05-15 17:46:56 +02:00
|
|
|
let region = e.region in
|
|
|
|
let loc = Location.lift region in
|
2020-01-16 19:36:04 +00:00
|
|
|
let inline = List.exists (fun (a: Raw.attribute) -> a.value = "inline") attributes in
|
Refactoring of Ligodity (CameLIGO) and making an AST pretty-printer
- AST.ml/AST.mli:
- The AST now distinguishes the constructors `None` and `Some` as being
predefined, as in PascaLIGO. See type `AST.constr_pattern`.
- I removed the nodes specific to Liquidity,
e.g. `let%entry`, and, in particular, the natural literals
ending with `p`. Now it should be `n`, as in `10n`.
- I renamed the node `TAlias` to `TVar`.
- I have applied the rule of expanding type expressions after `of` when
those were not records.
- The type of the argument to a data constructor is now
`type_expr`, instead of `cartesian`.
- I added the patterns for bytes (`PBytes`) and natural literals (`PNat`).
- I renamed the node `Sugar` into
`PListComp` (meaning "pattern of list comprehension").
- Record types in CameLIGO now must have at least one field declaration.
- Replaced the type `closing` and `opening` with one type `compound`,
which captures only the right combinations of opening and closing.
- Components of tuples in a selection must not be written
between parentheses. For example, `a.b.(1).(0)` is now
`a.b.1.0`, as in PascaLIGO.
- LexToken.mli/LexToken.mll
- I renamed the string literal `Str` into `String`.
- I added the tokens `C_None` and `C_Some` (to distinguish the
constructors `None` and `Some`. See AST.ml)
- Fixed the function `mk_sym` so it does not fail with `failwith`, but
with `Error Invalid_symbol`.
- Lexer.mll (shared)
- I removed the character `%` from the identifiers (used to
support Liquidity, like `entry%point` and `match%nat`).
- I adde to the hint on broken strings: "or insert a backslash"
(from a Gitlab issue).
- ParToken.mly
- I added the tokens `C_None` and `C_Some` (to distinguish the
constructors `None` and `Some`. See AST.ml and LexToken.mll)
- Parser.mly
- Fixed the order of declarations in the AST (it was reversed).
- I removed syntax support for Liquidity.
- I added user-defined constructor applications to irrefutable
patterns (the ones afer a `let`), even though only the type
checker can decide that they are truly irrefutable because they
are the only constructors of their types.
- I added natural numbers and bytes to patterns.
- Access of tuple components do not require parentheses now, like
`a.b.1.0`.
- I refactored the semantic actions.
- I added the empty sequence `begin end`.
- ParserLog.ml/ParserLog.mli
- I added a pretty-printer for the AST (with source locations).
- ParserMain.ml
- The CLI for the pretty-printer is now `--verbose=ast`.
- The old CLI `--verbose=ast` is now `--verbose=ast-tokens`.
- ligodity.ml (simplifier)
- I removed the constructions of sets, lists and maps with
`Set [...]`, `List [...]` and `Map [...]`, as there are already
better ways (that is, more like the OCaml's way), like
`Set.literal [...]` and `Map.literal [...]`. (The case for lists
was entirely redundant with the rest of the language as it is.)
- Everywhere there is now a non-empty list of elements, I made a
change. In particular, I removed a corner case ("let without
binding"), thanks to more precise OCaml types for non-empty
lists.
- I ported all the changes to the AST above.
- region.ml (vendors)
- I changed the method `compact` so the end-line is not repeated
if it is the same as the start line: this is even more compact. I
use this in the new pretty-printer for the AST (see above)
- I updated all the CameLIGO contracts.
2019-11-04 23:51:47 +01:00
|
|
|
let Raw.{binders; lhs_type; let_rhs; _} = binding in
|
2019-12-29 01:24:22 +00:00
|
|
|
begin match binders with
|
|
|
|
| (p, []) ->
|
|
|
|
let%bind variables = tuple_pattern_to_typed_vars p in
|
2019-05-28 16:34:53 +00:00
|
|
|
let%bind ty_opt =
|
2020-05-15 17:46:56 +02:00
|
|
|
bind_map_option (fun (re,te) -> let%bind te = compile_type_expression te in ok(Location.lift re,te)) lhs_type in
|
2020-03-16 14:53:56 +01:00
|
|
|
let%bind rhs = compile_expression let_rhs in
|
2019-12-26 21:06:24 -08:00
|
|
|
let rhs_b = Var.fresh ~name: "rhs" () in
|
|
|
|
let rhs',rhs_b_expr =
|
2019-05-28 16:34:53 +00:00
|
|
|
match ty_opt with
|
2020-05-15 17:46:56 +02:00
|
|
|
None -> rhs, e_variable ~loc rhs_b
|
|
|
|
| Some (lt,ty) -> (e_annotation ~loc:lt rhs ty), e_annotation ~loc:lt (e_variable ~loc rhs_b) ty in
|
2020-03-16 14:53:56 +01:00
|
|
|
let%bind body = compile_expression body in
|
2019-12-24 14:54:22 -08:00
|
|
|
let prepare_variable (ty_var: Raw.variable * Raw.type_expr option) =
|
|
|
|
let variable, ty_opt = ty_var in
|
|
|
|
let var_expr = Var.of_name variable.value in
|
|
|
|
let%bind ty_expr_opt =
|
|
|
|
match ty_opt with
|
2020-03-16 14:53:56 +01:00
|
|
|
| Some ty -> bind_map_option compile_type_expression (Some ty)
|
2019-12-24 14:54:22 -08:00
|
|
|
| None -> ok None
|
|
|
|
in ok (var_expr, ty_expr_opt)
|
|
|
|
in
|
|
|
|
let%bind prep_vars = bind_list (List.map prepare_variable variables) in
|
2019-12-24 15:35:05 -08:00
|
|
|
let%bind () =
|
|
|
|
if (List.length prep_vars) = 0
|
|
|
|
then fail @@ corner_case "let ... in without variables passed parsing stage"
|
|
|
|
else ok ()
|
|
|
|
in
|
2019-12-26 21:06:24 -08:00
|
|
|
let rhs_b_expr = (* We only want to evaluate the rhs first if multi-bind *)
|
|
|
|
if List.length prep_vars = 1
|
|
|
|
then rhs' else rhs_b_expr
|
|
|
|
in
|
2019-12-24 15:35:05 -08:00
|
|
|
let rec chain_let_in variables body : expression =
|
2019-12-24 14:54:22 -08:00
|
|
|
match variables with
|
|
|
|
| hd :: [] ->
|
|
|
|
if (List.length prep_vars = 1)
|
2020-05-15 17:46:56 +02:00
|
|
|
then e_let_in ~loc hd inline rhs_b_expr body
|
|
|
|
else e_let_in ~loc hd inline (e_record_accessor ~loc rhs_b_expr (string_of_int ((List.length prep_vars) - 1))) body
|
2019-12-24 14:54:22 -08:00
|
|
|
| hd :: tl ->
|
2020-05-15 17:46:56 +02:00
|
|
|
e_let_in ~loc hd
|
2020-01-16 19:36:04 +00:00
|
|
|
inline
|
2020-05-15 17:46:56 +02:00
|
|
|
(e_record_accessor ~loc rhs_b_expr (string_of_int ((List.length prep_vars) - (List.length tl) - 1)))
|
2019-12-24 14:54:22 -08:00
|
|
|
(chain_let_in tl body)
|
2019-12-24 15:35:05 -08:00
|
|
|
| [] -> body (* Precluded by corner case assertion above *)
|
2019-12-26 21:06:24 -08:00
|
|
|
in
|
2020-04-12 15:26:47 +02:00
|
|
|
let%bind ty_opt = match ty_opt with
|
|
|
|
| None -> (match let_rhs with
|
|
|
|
| EFun {value={binders;lhs_type}} ->
|
2020-03-09 00:13:07 +01:00
|
|
|
let f_args = nseq_to_list (binders) in
|
2020-03-16 14:53:56 +01:00
|
|
|
let%bind lhs_type' = bind_map_option (fun x -> compile_type_expression (snd x)) lhs_type in
|
2020-03-09 00:13:07 +01:00
|
|
|
let%bind ty = bind_map_list typed_pattern_to_typed_vars f_args in
|
2020-05-19 18:53:20 +02:00
|
|
|
let aux acc (_,ty,loc) = Option.map (t_function ~loc ty) acc in
|
2020-03-09 00:13:07 +01:00
|
|
|
ok @@ (List.fold_right' aux lhs_type' ty)
|
|
|
|
| _ -> ok None
|
|
|
|
)
|
2020-05-15 17:46:56 +02:00
|
|
|
| Some (_,t) -> ok @@ Some t
|
2020-03-09 00:13:07 +01:00
|
|
|
in
|
|
|
|
let%bind ret_expr = if List.length prep_vars = 1
|
|
|
|
then ok (chain_let_in prep_vars body)
|
|
|
|
(* Bind the right hand side so we only evaluate it once *)
|
2020-03-23 16:00:50 +01:00
|
|
|
else ok (e_let_in (rhs_b, ty_opt) inline rhs' (chain_let_in prep_vars body))
|
2020-03-09 00:13:07 +01:00
|
|
|
in
|
2020-04-12 15:26:47 +02:00
|
|
|
let%bind ret_expr = match kwd_rec with
|
2020-03-09 00:13:07 +01:00
|
|
|
| None -> ok @@ ret_expr
|
2020-04-12 15:26:47 +02:00
|
|
|
| Some _ ->
|
|
|
|
match ret_expr.expression_content with
|
2020-03-09 00:13:07 +01:00
|
|
|
| E_let_in li -> (
|
2020-04-12 15:26:47 +02:00
|
|
|
let%bind lambda =
|
2020-03-09 00:13:07 +01:00
|
|
|
let rec aux rhs = match rhs.expression_content with
|
|
|
|
| E_lambda l -> ok @@ l
|
|
|
|
| E_ascription a -> aux a.anno_expr
|
|
|
|
| _ -> fail @@ corner_case "recursive only supported for lambda"
|
|
|
|
in
|
|
|
|
aux rhs'
|
|
|
|
in
|
|
|
|
let fun_name = fst @@ List.hd prep_vars in
|
2020-04-12 15:26:47 +02:00
|
|
|
let%bind fun_type = match ty_opt with
|
2020-03-09 00:13:07 +01:00
|
|
|
| Some t -> ok @@ t
|
2020-04-12 15:26:47 +02:00
|
|
|
| None -> match rhs'.expression_content with
|
2020-03-09 00:13:07 +01:00
|
|
|
| E_ascription a -> ok a.type_annotation
|
|
|
|
| _ -> fail @@ untyped_recursive_function e
|
|
|
|
in
|
|
|
|
let expression_content = E_recursive {fun_name;fun_type;lambda} in
|
|
|
|
let expression_content = E_let_in {li with rhs = {li.rhs with expression_content}} in
|
|
|
|
ok @@ {ret_expr with expression_content}
|
|
|
|
)
|
|
|
|
| _ -> fail @@ corner_case "impossible"
|
|
|
|
in
|
|
|
|
ok ret_expr
|
2019-12-29 01:24:22 +00:00
|
|
|
|
|
|
|
(* let f p1 ps... = rhs in body *)
|
|
|
|
| (f, p1 :: ps) ->
|
2020-05-15 17:46:56 +02:00
|
|
|
fail @@ unsupported_let_in_function e.region (f :: p1 :: ps)
|
2019-12-29 01:24:22 +00:00
|
|
|
end
|
Refactoring of Ligodity (CameLIGO) and making an AST pretty-printer
- AST.ml/AST.mli:
- The AST now distinguishes the constructors `None` and `Some` as being
predefined, as in PascaLIGO. See type `AST.constr_pattern`.
- I removed the nodes specific to Liquidity,
e.g. `let%entry`, and, in particular, the natural literals
ending with `p`. Now it should be `n`, as in `10n`.
- I renamed the node `TAlias` to `TVar`.
- I have applied the rule of expanding type expressions after `of` when
those were not records.
- The type of the argument to a data constructor is now
`type_expr`, instead of `cartesian`.
- I added the patterns for bytes (`PBytes`) and natural literals (`PNat`).
- I renamed the node `Sugar` into
`PListComp` (meaning "pattern of list comprehension").
- Record types in CameLIGO now must have at least one field declaration.
- Replaced the type `closing` and `opening` with one type `compound`,
which captures only the right combinations of opening and closing.
- Components of tuples in a selection must not be written
between parentheses. For example, `a.b.(1).(0)` is now
`a.b.1.0`, as in PascaLIGO.
- LexToken.mli/LexToken.mll
- I renamed the string literal `Str` into `String`.
- I added the tokens `C_None` and `C_Some` (to distinguish the
constructors `None` and `Some`. See AST.ml)
- Fixed the function `mk_sym` so it does not fail with `failwith`, but
with `Error Invalid_symbol`.
- Lexer.mll (shared)
- I removed the character `%` from the identifiers (used to
support Liquidity, like `entry%point` and `match%nat`).
- I adde to the hint on broken strings: "or insert a backslash"
(from a Gitlab issue).
- ParToken.mly
- I added the tokens `C_None` and `C_Some` (to distinguish the
constructors `None` and `Some`. See AST.ml and LexToken.mll)
- Parser.mly
- Fixed the order of declarations in the AST (it was reversed).
- I removed syntax support for Liquidity.
- I added user-defined constructor applications to irrefutable
patterns (the ones afer a `let`), even though only the type
checker can decide that they are truly irrefutable because they
are the only constructors of their types.
- I added natural numbers and bytes to patterns.
- Access of tuple components do not require parentheses now, like
`a.b.1.0`.
- I refactored the semantic actions.
- I added the empty sequence `begin end`.
- ParserLog.ml/ParserLog.mli
- I added a pretty-printer for the AST (with source locations).
- ParserMain.ml
- The CLI for the pretty-printer is now `--verbose=ast`.
- The old CLI `--verbose=ast` is now `--verbose=ast-tokens`.
- ligodity.ml (simplifier)
- I removed the constructions of sets, lists and maps with
`Set [...]`, `List [...]` and `Map [...]`, as there are already
better ways (that is, more like the OCaml's way), like
`Set.literal [...]` and `Map.literal [...]`. (The case for lists
was entirely redundant with the rest of the language as it is.)
- Everywhere there is now a non-empty list of elements, I made a
change. In particular, I removed a corner case ("let without
binding"), thanks to more precise OCaml types for non-empty
lists.
- I ported all the changes to the AST above.
- region.ml (vendors)
- I changed the method `compact` so the end-line is not repeated
if it is the same as the start line: this is even more compact. I
use this in the new pretty-printer for the AST (see above)
- I updated all the CameLIGO contracts.
2019-11-04 23:51:47 +01:00
|
|
|
| Raw.EAnnot a ->
|
2019-12-15 17:46:08 +01:00
|
|
|
let Raw.{inside=expr, _, type_expr; _}, loc = r_split a in
|
2020-03-16 14:53:56 +01:00
|
|
|
let%bind expr' = compile_expression expr in
|
|
|
|
let%bind type_expr' = compile_type_expression type_expr in
|
2019-05-28 16:34:53 +00:00
|
|
|
return @@ e_annotation ~loc expr' type_expr'
|
Refactoring of Ligodity (CameLIGO) and making an AST pretty-printer
- AST.ml/AST.mli:
- The AST now distinguishes the constructors `None` and `Some` as being
predefined, as in PascaLIGO. See type `AST.constr_pattern`.
- I removed the nodes specific to Liquidity,
e.g. `let%entry`, and, in particular, the natural literals
ending with `p`. Now it should be `n`, as in `10n`.
- I renamed the node `TAlias` to `TVar`.
- I have applied the rule of expanding type expressions after `of` when
those were not records.
- The type of the argument to a data constructor is now
`type_expr`, instead of `cartesian`.
- I added the patterns for bytes (`PBytes`) and natural literals (`PNat`).
- I renamed the node `Sugar` into
`PListComp` (meaning "pattern of list comprehension").
- Record types in CameLIGO now must have at least one field declaration.
- Replaced the type `closing` and `opening` with one type `compound`,
which captures only the right combinations of opening and closing.
- Components of tuples in a selection must not be written
between parentheses. For example, `a.b.(1).(0)` is now
`a.b.1.0`, as in PascaLIGO.
- LexToken.mli/LexToken.mll
- I renamed the string literal `Str` into `String`.
- I added the tokens `C_None` and `C_Some` (to distinguish the
constructors `None` and `Some`. See AST.ml)
- Fixed the function `mk_sym` so it does not fail with `failwith`, but
with `Error Invalid_symbol`.
- Lexer.mll (shared)
- I removed the character `%` from the identifiers (used to
support Liquidity, like `entry%point` and `match%nat`).
- I adde to the hint on broken strings: "or insert a backslash"
(from a Gitlab issue).
- ParToken.mly
- I added the tokens `C_None` and `C_Some` (to distinguish the
constructors `None` and `Some`. See AST.ml and LexToken.mll)
- Parser.mly
- Fixed the order of declarations in the AST (it was reversed).
- I removed syntax support for Liquidity.
- I added user-defined constructor applications to irrefutable
patterns (the ones afer a `let`), even though only the type
checker can decide that they are truly irrefutable because they
are the only constructors of their types.
- I added natural numbers and bytes to patterns.
- Access of tuple components do not require parentheses now, like
`a.b.1.0`.
- I refactored the semantic actions.
- I added the empty sequence `begin end`.
- ParserLog.ml/ParserLog.mli
- I added a pretty-printer for the AST (with source locations).
- ParserMain.ml
- The CLI for the pretty-printer is now `--verbose=ast`.
- The old CLI `--verbose=ast` is now `--verbose=ast-tokens`.
- ligodity.ml (simplifier)
- I removed the constructions of sets, lists and maps with
`Set [...]`, `List [...]` and `Map [...]`, as there are already
better ways (that is, more like the OCaml's way), like
`Set.literal [...]` and `Map.literal [...]`. (The case for lists
was entirely redundant with the rest of the language as it is.)
- Everywhere there is now a non-empty list of elements, I made a
change. In particular, I removed a corner case ("let without
binding"), thanks to more precise OCaml types for non-empty
lists.
- I ported all the changes to the AST above.
- region.ml (vendors)
- I changed the method `compact` so the end-line is not repeated
if it is the same as the start line: this is even more compact. I
use this in the new pretty-printer for the AST (see above)
- I updated all the CameLIGO contracts.
2019-11-04 23:51:47 +01:00
|
|
|
| EVar c ->
|
2020-01-02 19:30:19 +01:00
|
|
|
let (c',loc) = r_split c in
|
2019-12-04 11:40:58 +00:00
|
|
|
(match constants c' with
|
2020-04-20 17:39:36 +02:00
|
|
|
| None -> return @@ e_variable ~loc (Var.of_name c.value)
|
|
|
|
| Some s -> return @@ e_constant s [])
|
2019-05-15 15:04:03 +02:00
|
|
|
| ECall x -> (
|
2019-05-28 16:34:53 +00:00
|
|
|
let ((e1 , e2) , loc) = r_split x in
|
2020-03-16 14:53:56 +01:00
|
|
|
let%bind args = bind_map_list compile_expression (nseq_to_list e2) in
|
2020-01-08 20:58:26 +00:00
|
|
|
let rec chain_application (f: expression) (args: expression list) =
|
|
|
|
match args with
|
|
|
|
| hd :: tl -> chain_application (e_application ~loc f hd) tl
|
|
|
|
| [] -> f
|
|
|
|
in
|
2019-05-15 15:04:03 +02:00
|
|
|
match e1 with
|
2019-05-28 16:34:53 +00:00
|
|
|
| EVar f -> (
|
|
|
|
let (f , f_loc) = r_split f in
|
2019-12-04 11:40:58 +00:00
|
|
|
match constants f with
|
2020-04-20 17:39:36 +02:00
|
|
|
| None -> return @@ chain_application (e_variable ~loc:f_loc (Var.of_name f)) args
|
|
|
|
| Some s -> return @@ e_constant ~loc s args
|
2020-01-08 20:58:26 +00:00
|
|
|
)
|
Refactoring of Ligodity (CameLIGO) and making an AST pretty-printer
- AST.ml/AST.mli:
- The AST now distinguishes the constructors `None` and `Some` as being
predefined, as in PascaLIGO. See type `AST.constr_pattern`.
- I removed the nodes specific to Liquidity,
e.g. `let%entry`, and, in particular, the natural literals
ending with `p`. Now it should be `n`, as in `10n`.
- I renamed the node `TAlias` to `TVar`.
- I have applied the rule of expanding type expressions after `of` when
those were not records.
- The type of the argument to a data constructor is now
`type_expr`, instead of `cartesian`.
- I added the patterns for bytes (`PBytes`) and natural literals (`PNat`).
- I renamed the node `Sugar` into
`PListComp` (meaning "pattern of list comprehension").
- Record types in CameLIGO now must have at least one field declaration.
- Replaced the type `closing` and `opening` with one type `compound`,
which captures only the right combinations of opening and closing.
- Components of tuples in a selection must not be written
between parentheses. For example, `a.b.(1).(0)` is now
`a.b.1.0`, as in PascaLIGO.
- LexToken.mli/LexToken.mll
- I renamed the string literal `Str` into `String`.
- I added the tokens `C_None` and `C_Some` (to distinguish the
constructors `None` and `Some`. See AST.ml)
- Fixed the function `mk_sym` so it does not fail with `failwith`, but
with `Error Invalid_symbol`.
- Lexer.mll (shared)
- I removed the character `%` from the identifiers (used to
support Liquidity, like `entry%point` and `match%nat`).
- I adde to the hint on broken strings: "or insert a backslash"
(from a Gitlab issue).
- ParToken.mly
- I added the tokens `C_None` and `C_Some` (to distinguish the
constructors `None` and `Some`. See AST.ml and LexToken.mll)
- Parser.mly
- Fixed the order of declarations in the AST (it was reversed).
- I removed syntax support for Liquidity.
- I added user-defined constructor applications to irrefutable
patterns (the ones afer a `let`), even though only the type
checker can decide that they are truly irrefutable because they
are the only constructors of their types.
- I added natural numbers and bytes to patterns.
- Access of tuple components do not require parentheses now, like
`a.b.1.0`.
- I refactored the semantic actions.
- I added the empty sequence `begin end`.
- ParserLog.ml/ParserLog.mli
- I added a pretty-printer for the AST (with source locations).
- ParserMain.ml
- The CLI for the pretty-printer is now `--verbose=ast`.
- The old CLI `--verbose=ast` is now `--verbose=ast-tokens`.
- ligodity.ml (simplifier)
- I removed the constructions of sets, lists and maps with
`Set [...]`, `List [...]` and `Map [...]`, as there are already
better ways (that is, more like the OCaml's way), like
`Set.literal [...]` and `Map.literal [...]`. (The case for lists
was entirely redundant with the rest of the language as it is.)
- Everywhere there is now a non-empty list of elements, I made a
change. In particular, I removed a corner case ("let without
binding"), thanks to more precise OCaml types for non-empty
lists.
- I ported all the changes to the AST above.
- region.ml (vendors)
- I changed the method `compact` so the end-line is not repeated
if it is the same as the start line: this is even more compact. I
use this in the new pretty-printer for the AST (see above)
- I updated all the CameLIGO contracts.
2019-11-04 23:51:47 +01:00
|
|
|
| e1 ->
|
2020-03-16 14:53:56 +01:00
|
|
|
let%bind e1' = compile_expression e1 in
|
2020-01-08 20:58:26 +00:00
|
|
|
return @@ chain_application e1' args
|
|
|
|
)
|
2020-03-16 14:53:56 +01:00
|
|
|
| EPar x -> compile_expression x.value.inside
|
Refactoring of Ligodity (CameLIGO) and making an AST pretty-printer
- AST.ml/AST.mli:
- The AST now distinguishes the constructors `None` and `Some` as being
predefined, as in PascaLIGO. See type `AST.constr_pattern`.
- I removed the nodes specific to Liquidity,
e.g. `let%entry`, and, in particular, the natural literals
ending with `p`. Now it should be `n`, as in `10n`.
- I renamed the node `TAlias` to `TVar`.
- I have applied the rule of expanding type expressions after `of` when
those were not records.
- The type of the argument to a data constructor is now
`type_expr`, instead of `cartesian`.
- I added the patterns for bytes (`PBytes`) and natural literals (`PNat`).
- I renamed the node `Sugar` into
`PListComp` (meaning "pattern of list comprehension").
- Record types in CameLIGO now must have at least one field declaration.
- Replaced the type `closing` and `opening` with one type `compound`,
which captures only the right combinations of opening and closing.
- Components of tuples in a selection must not be written
between parentheses. For example, `a.b.(1).(0)` is now
`a.b.1.0`, as in PascaLIGO.
- LexToken.mli/LexToken.mll
- I renamed the string literal `Str` into `String`.
- I added the tokens `C_None` and `C_Some` (to distinguish the
constructors `None` and `Some`. See AST.ml)
- Fixed the function `mk_sym` so it does not fail with `failwith`, but
with `Error Invalid_symbol`.
- Lexer.mll (shared)
- I removed the character `%` from the identifiers (used to
support Liquidity, like `entry%point` and `match%nat`).
- I adde to the hint on broken strings: "or insert a backslash"
(from a Gitlab issue).
- ParToken.mly
- I added the tokens `C_None` and `C_Some` (to distinguish the
constructors `None` and `Some`. See AST.ml and LexToken.mll)
- Parser.mly
- Fixed the order of declarations in the AST (it was reversed).
- I removed syntax support for Liquidity.
- I added user-defined constructor applications to irrefutable
patterns (the ones afer a `let`), even though only the type
checker can decide that they are truly irrefutable because they
are the only constructors of their types.
- I added natural numbers and bytes to patterns.
- Access of tuple components do not require parentheses now, like
`a.b.1.0`.
- I refactored the semantic actions.
- I added the empty sequence `begin end`.
- ParserLog.ml/ParserLog.mli
- I added a pretty-printer for the AST (with source locations).
- ParserMain.ml
- The CLI for the pretty-printer is now `--verbose=ast`.
- The old CLI `--verbose=ast` is now `--verbose=ast-tokens`.
- ligodity.ml (simplifier)
- I removed the constructions of sets, lists and maps with
`Set [...]`, `List [...]` and `Map [...]`, as there are already
better ways (that is, more like the OCaml's way), like
`Set.literal [...]` and `Map.literal [...]`. (The case for lists
was entirely redundant with the rest of the language as it is.)
- Everywhere there is now a non-empty list of elements, I made a
change. In particular, I removed a corner case ("let without
binding"), thanks to more precise OCaml types for non-empty
lists.
- I ported all the changes to the AST above.
- region.ml (vendors)
- I changed the method `compact` so the end-line is not repeated
if it is the same as the start line: this is even more compact. I
use this in the new pretty-printer for the AST (see above)
- I updated all the CameLIGO contracts.
2019-11-04 23:51:47 +01:00
|
|
|
| EUnit reg ->
|
2019-05-28 16:34:53 +00:00
|
|
|
let (_ , loc) = r_split reg in
|
|
|
|
return @@ e_literal ~loc Literal_unit
|
Refactoring of Ligodity (CameLIGO) and making an AST pretty-printer
- AST.ml/AST.mli:
- The AST now distinguishes the constructors `None` and `Some` as being
predefined, as in PascaLIGO. See type `AST.constr_pattern`.
- I removed the nodes specific to Liquidity,
e.g. `let%entry`, and, in particular, the natural literals
ending with `p`. Now it should be `n`, as in `10n`.
- I renamed the node `TAlias` to `TVar`.
- I have applied the rule of expanding type expressions after `of` when
those were not records.
- The type of the argument to a data constructor is now
`type_expr`, instead of `cartesian`.
- I added the patterns for bytes (`PBytes`) and natural literals (`PNat`).
- I renamed the node `Sugar` into
`PListComp` (meaning "pattern of list comprehension").
- Record types in CameLIGO now must have at least one field declaration.
- Replaced the type `closing` and `opening` with one type `compound`,
which captures only the right combinations of opening and closing.
- Components of tuples in a selection must not be written
between parentheses. For example, `a.b.(1).(0)` is now
`a.b.1.0`, as in PascaLIGO.
- LexToken.mli/LexToken.mll
- I renamed the string literal `Str` into `String`.
- I added the tokens `C_None` and `C_Some` (to distinguish the
constructors `None` and `Some`. See AST.ml)
- Fixed the function `mk_sym` so it does not fail with `failwith`, but
with `Error Invalid_symbol`.
- Lexer.mll (shared)
- I removed the character `%` from the identifiers (used to
support Liquidity, like `entry%point` and `match%nat`).
- I adde to the hint on broken strings: "or insert a backslash"
(from a Gitlab issue).
- ParToken.mly
- I added the tokens `C_None` and `C_Some` (to distinguish the
constructors `None` and `Some`. See AST.ml and LexToken.mll)
- Parser.mly
- Fixed the order of declarations in the AST (it was reversed).
- I removed syntax support for Liquidity.
- I added user-defined constructor applications to irrefutable
patterns (the ones afer a `let`), even though only the type
checker can decide that they are truly irrefutable because they
are the only constructors of their types.
- I added natural numbers and bytes to patterns.
- Access of tuple components do not require parentheses now, like
`a.b.1.0`.
- I refactored the semantic actions.
- I added the empty sequence `begin end`.
- ParserLog.ml/ParserLog.mli
- I added a pretty-printer for the AST (with source locations).
- ParserMain.ml
- The CLI for the pretty-printer is now `--verbose=ast`.
- The old CLI `--verbose=ast` is now `--verbose=ast-tokens`.
- ligodity.ml (simplifier)
- I removed the constructions of sets, lists and maps with
`Set [...]`, `List [...]` and `Map [...]`, as there are already
better ways (that is, more like the OCaml's way), like
`Set.literal [...]` and `Map.literal [...]`. (The case for lists
was entirely redundant with the rest of the language as it is.)
- Everywhere there is now a non-empty list of elements, I made a
change. In particular, I removed a corner case ("let without
binding"), thanks to more precise OCaml types for non-empty
lists.
- I ported all the changes to the AST above.
- region.ml (vendors)
- I changed the method `compact` so the end-line is not repeated
if it is the same as the start line: this is even more compact. I
use this in the new pretty-printer for the AST (see above)
- I updated all the CameLIGO contracts.
2019-11-04 23:51:47 +01:00
|
|
|
| EBytes x ->
|
2019-05-28 16:34:53 +00:00
|
|
|
let (x , loc) = r_split x in
|
2020-01-09 16:50:27 -06:00
|
|
|
return @@ e_literal ~loc (Literal_bytes (Hex.to_bytes @@ snd x))
|
2020-03-16 14:53:56 +01:00
|
|
|
| ETuple tpl -> compile_tuple_expression @@ (npseq_to_list tpl.value)
|
Refactoring of Ligodity (CameLIGO) and making an AST pretty-printer
- AST.ml/AST.mli:
- The AST now distinguishes the constructors `None` and `Some` as being
predefined, as in PascaLIGO. See type `AST.constr_pattern`.
- I removed the nodes specific to Liquidity,
e.g. `let%entry`, and, in particular, the natural literals
ending with `p`. Now it should be `n`, as in `10n`.
- I renamed the node `TAlias` to `TVar`.
- I have applied the rule of expanding type expressions after `of` when
those were not records.
- The type of the argument to a data constructor is now
`type_expr`, instead of `cartesian`.
- I added the patterns for bytes (`PBytes`) and natural literals (`PNat`).
- I renamed the node `Sugar` into
`PListComp` (meaning "pattern of list comprehension").
- Record types in CameLIGO now must have at least one field declaration.
- Replaced the type `closing` and `opening` with one type `compound`,
which captures only the right combinations of opening and closing.
- Components of tuples in a selection must not be written
between parentheses. For example, `a.b.(1).(0)` is now
`a.b.1.0`, as in PascaLIGO.
- LexToken.mli/LexToken.mll
- I renamed the string literal `Str` into `String`.
- I added the tokens `C_None` and `C_Some` (to distinguish the
constructors `None` and `Some`. See AST.ml)
- Fixed the function `mk_sym` so it does not fail with `failwith`, but
with `Error Invalid_symbol`.
- Lexer.mll (shared)
- I removed the character `%` from the identifiers (used to
support Liquidity, like `entry%point` and `match%nat`).
- I adde to the hint on broken strings: "or insert a backslash"
(from a Gitlab issue).
- ParToken.mly
- I added the tokens `C_None` and `C_Some` (to distinguish the
constructors `None` and `Some`. See AST.ml and LexToken.mll)
- Parser.mly
- Fixed the order of declarations in the AST (it was reversed).
- I removed syntax support for Liquidity.
- I added user-defined constructor applications to irrefutable
patterns (the ones afer a `let`), even though only the type
checker can decide that they are truly irrefutable because they
are the only constructors of their types.
- I added natural numbers and bytes to patterns.
- Access of tuple components do not require parentheses now, like
`a.b.1.0`.
- I refactored the semantic actions.
- I added the empty sequence `begin end`.
- ParserLog.ml/ParserLog.mli
- I added a pretty-printer for the AST (with source locations).
- ParserMain.ml
- The CLI for the pretty-printer is now `--verbose=ast`.
- The old CLI `--verbose=ast` is now `--verbose=ast-tokens`.
- ligodity.ml (simplifier)
- I removed the constructions of sets, lists and maps with
`Set [...]`, `List [...]` and `Map [...]`, as there are already
better ways (that is, more like the OCaml's way), like
`Set.literal [...]` and `Map.literal [...]`. (The case for lists
was entirely redundant with the rest of the language as it is.)
- Everywhere there is now a non-empty list of elements, I made a
change. In particular, I removed a corner case ("let without
binding"), thanks to more precise OCaml types for non-empty
lists.
- I ported all the changes to the AST above.
- region.ml (vendors)
- I changed the method `compact` so the end-line is not repeated
if it is the same as the start line: this is even more compact. I
use this in the new pretty-printer for the AST (see above)
- I updated all the CameLIGO contracts.
2019-11-04 23:51:47 +01:00
|
|
|
| ERecord r ->
|
2019-05-28 16:34:53 +00:00
|
|
|
let (r , loc) = r_split r in
|
2019-05-14 15:57:25 +02:00
|
|
|
let%bind fields = bind_list
|
2020-03-16 14:53:56 +01:00
|
|
|
@@ List.map (fun ((k : _ Raw.reg), v) -> let%bind v = compile_expression v in ok (k.value, v))
|
2019-05-14 15:57:25 +02:00
|
|
|
@@ List.map (fun (x:Raw.field_assign Raw.reg) -> (x.value.field_name, x.value.field_expr))
|
Refactoring of Ligodity (CameLIGO) and making an AST pretty-printer
- AST.ml/AST.mli:
- The AST now distinguishes the constructors `None` and `Some` as being
predefined, as in PascaLIGO. See type `AST.constr_pattern`.
- I removed the nodes specific to Liquidity,
e.g. `let%entry`, and, in particular, the natural literals
ending with `p`. Now it should be `n`, as in `10n`.
- I renamed the node `TAlias` to `TVar`.
- I have applied the rule of expanding type expressions after `of` when
those were not records.
- The type of the argument to a data constructor is now
`type_expr`, instead of `cartesian`.
- I added the patterns for bytes (`PBytes`) and natural literals (`PNat`).
- I renamed the node `Sugar` into
`PListComp` (meaning "pattern of list comprehension").
- Record types in CameLIGO now must have at least one field declaration.
- Replaced the type `closing` and `opening` with one type `compound`,
which captures only the right combinations of opening and closing.
- Components of tuples in a selection must not be written
between parentheses. For example, `a.b.(1).(0)` is now
`a.b.1.0`, as in PascaLIGO.
- LexToken.mli/LexToken.mll
- I renamed the string literal `Str` into `String`.
- I added the tokens `C_None` and `C_Some` (to distinguish the
constructors `None` and `Some`. See AST.ml)
- Fixed the function `mk_sym` so it does not fail with `failwith`, but
with `Error Invalid_symbol`.
- Lexer.mll (shared)
- I removed the character `%` from the identifiers (used to
support Liquidity, like `entry%point` and `match%nat`).
- I adde to the hint on broken strings: "or insert a backslash"
(from a Gitlab issue).
- ParToken.mly
- I added the tokens `C_None` and `C_Some` (to distinguish the
constructors `None` and `Some`. See AST.ml and LexToken.mll)
- Parser.mly
- Fixed the order of declarations in the AST (it was reversed).
- I removed syntax support for Liquidity.
- I added user-defined constructor applications to irrefutable
patterns (the ones afer a `let`), even though only the type
checker can decide that they are truly irrefutable because they
are the only constructors of their types.
- I added natural numbers and bytes to patterns.
- Access of tuple components do not require parentheses now, like
`a.b.1.0`.
- I refactored the semantic actions.
- I added the empty sequence `begin end`.
- ParserLog.ml/ParserLog.mli
- I added a pretty-printer for the AST (with source locations).
- ParserMain.ml
- The CLI for the pretty-printer is now `--verbose=ast`.
- The old CLI `--verbose=ast` is now `--verbose=ast-tokens`.
- ligodity.ml (simplifier)
- I removed the constructions of sets, lists and maps with
`Set [...]`, `List [...]` and `Map [...]`, as there are already
better ways (that is, more like the OCaml's way), like
`Set.literal [...]` and `Map.literal [...]`. (The case for lists
was entirely redundant with the rest of the language as it is.)
- Everywhere there is now a non-empty list of elements, I made a
change. In particular, I removed a corner case ("let without
binding"), thanks to more precise OCaml types for non-empty
lists.
- I ported all the changes to the AST above.
- region.ml (vendors)
- I changed the method `compact` so the end-line is not repeated
if it is the same as the start line: this is even more compact. I
use this in the new pretty-printer for the AST (see above)
- I updated all the CameLIGO contracts.
2019-11-04 23:51:47 +01:00
|
|
|
@@ npseq_to_list r.ne_elements in
|
2019-12-04 18:30:52 +01:00
|
|
|
return @@ e_record_ez ~loc fields
|
2020-03-16 14:53:56 +01:00
|
|
|
| EProj p -> compile_projection p
|
|
|
|
| EUpdate u -> compile_update u
|
Refactoring of Ligodity (CameLIGO) and making an AST pretty-printer
- AST.ml/AST.mli:
- The AST now distinguishes the constructors `None` and `Some` as being
predefined, as in PascaLIGO. See type `AST.constr_pattern`.
- I removed the nodes specific to Liquidity,
e.g. `let%entry`, and, in particular, the natural literals
ending with `p`. Now it should be `n`, as in `10n`.
- I renamed the node `TAlias` to `TVar`.
- I have applied the rule of expanding type expressions after `of` when
those were not records.
- The type of the argument to a data constructor is now
`type_expr`, instead of `cartesian`.
- I added the patterns for bytes (`PBytes`) and natural literals (`PNat`).
- I renamed the node `Sugar` into
`PListComp` (meaning "pattern of list comprehension").
- Record types in CameLIGO now must have at least one field declaration.
- Replaced the type `closing` and `opening` with one type `compound`,
which captures only the right combinations of opening and closing.
- Components of tuples in a selection must not be written
between parentheses. For example, `a.b.(1).(0)` is now
`a.b.1.0`, as in PascaLIGO.
- LexToken.mli/LexToken.mll
- I renamed the string literal `Str` into `String`.
- I added the tokens `C_None` and `C_Some` (to distinguish the
constructors `None` and `Some`. See AST.ml)
- Fixed the function `mk_sym` so it does not fail with `failwith`, but
with `Error Invalid_symbol`.
- Lexer.mll (shared)
- I removed the character `%` from the identifiers (used to
support Liquidity, like `entry%point` and `match%nat`).
- I adde to the hint on broken strings: "or insert a backslash"
(from a Gitlab issue).
- ParToken.mly
- I added the tokens `C_None` and `C_Some` (to distinguish the
constructors `None` and `Some`. See AST.ml and LexToken.mll)
- Parser.mly
- Fixed the order of declarations in the AST (it was reversed).
- I removed syntax support for Liquidity.
- I added user-defined constructor applications to irrefutable
patterns (the ones afer a `let`), even though only the type
checker can decide that they are truly irrefutable because they
are the only constructors of their types.
- I added natural numbers and bytes to patterns.
- Access of tuple components do not require parentheses now, like
`a.b.1.0`.
- I refactored the semantic actions.
- I added the empty sequence `begin end`.
- ParserLog.ml/ParserLog.mli
- I added a pretty-printer for the AST (with source locations).
- ParserMain.ml
- The CLI for the pretty-printer is now `--verbose=ast`.
- The old CLI `--verbose=ast` is now `--verbose=ast-tokens`.
- ligodity.ml (simplifier)
- I removed the constructions of sets, lists and maps with
`Set [...]`, `List [...]` and `Map [...]`, as there are already
better ways (that is, more like the OCaml's way), like
`Set.literal [...]` and `Map.literal [...]`. (The case for lists
was entirely redundant with the rest of the language as it is.)
- Everywhere there is now a non-empty list of elements, I made a
change. In particular, I removed a corner case ("let without
binding"), thanks to more precise OCaml types for non-empty
lists.
- I ported all the changes to the AST above.
- region.ml (vendors)
- I changed the method `compact` so the end-line is not repeated
if it is the same as the start line: this is even more compact. I
use this in the new pretty-printer for the AST (see above)
- I updated all the CameLIGO contracts.
2019-11-04 23:51:47 +01:00
|
|
|
| EConstr (ESomeApp a) ->
|
|
|
|
let (_, args), loc = r_split a in
|
2020-03-16 14:53:56 +01:00
|
|
|
let%bind arg = compile_expression args in
|
2019-12-04 11:40:58 +00:00
|
|
|
return @@ e_constant ~loc C_SOME [arg]
|
Refactoring of Ligodity (CameLIGO) and making an AST pretty-printer
- AST.ml/AST.mli:
- The AST now distinguishes the constructors `None` and `Some` as being
predefined, as in PascaLIGO. See type `AST.constr_pattern`.
- I removed the nodes specific to Liquidity,
e.g. `let%entry`, and, in particular, the natural literals
ending with `p`. Now it should be `n`, as in `10n`.
- I renamed the node `TAlias` to `TVar`.
- I have applied the rule of expanding type expressions after `of` when
those were not records.
- The type of the argument to a data constructor is now
`type_expr`, instead of `cartesian`.
- I added the patterns for bytes (`PBytes`) and natural literals (`PNat`).
- I renamed the node `Sugar` into
`PListComp` (meaning "pattern of list comprehension").
- Record types in CameLIGO now must have at least one field declaration.
- Replaced the type `closing` and `opening` with one type `compound`,
which captures only the right combinations of opening and closing.
- Components of tuples in a selection must not be written
between parentheses. For example, `a.b.(1).(0)` is now
`a.b.1.0`, as in PascaLIGO.
- LexToken.mli/LexToken.mll
- I renamed the string literal `Str` into `String`.
- I added the tokens `C_None` and `C_Some` (to distinguish the
constructors `None` and `Some`. See AST.ml)
- Fixed the function `mk_sym` so it does not fail with `failwith`, but
with `Error Invalid_symbol`.
- Lexer.mll (shared)
- I removed the character `%` from the identifiers (used to
support Liquidity, like `entry%point` and `match%nat`).
- I adde to the hint on broken strings: "or insert a backslash"
(from a Gitlab issue).
- ParToken.mly
- I added the tokens `C_None` and `C_Some` (to distinguish the
constructors `None` and `Some`. See AST.ml and LexToken.mll)
- Parser.mly
- Fixed the order of declarations in the AST (it was reversed).
- I removed syntax support for Liquidity.
- I added user-defined constructor applications to irrefutable
patterns (the ones afer a `let`), even though only the type
checker can decide that they are truly irrefutable because they
are the only constructors of their types.
- I added natural numbers and bytes to patterns.
- Access of tuple components do not require parentheses now, like
`a.b.1.0`.
- I refactored the semantic actions.
- I added the empty sequence `begin end`.
- ParserLog.ml/ParserLog.mli
- I added a pretty-printer for the AST (with source locations).
- ParserMain.ml
- The CLI for the pretty-printer is now `--verbose=ast`.
- The old CLI `--verbose=ast` is now `--verbose=ast-tokens`.
- ligodity.ml (simplifier)
- I removed the constructions of sets, lists and maps with
`Set [...]`, `List [...]` and `Map [...]`, as there are already
better ways (that is, more like the OCaml's way), like
`Set.literal [...]` and `Map.literal [...]`. (The case for lists
was entirely redundant with the rest of the language as it is.)
- Everywhere there is now a non-empty list of elements, I made a
change. In particular, I removed a corner case ("let without
binding"), thanks to more precise OCaml types for non-empty
lists.
- I ported all the changes to the AST above.
- region.ml (vendors)
- I changed the method `compact` so the end-line is not repeated
if it is the same as the start line: this is even more compact. I
use this in the new pretty-printer for the AST (see above)
- I updated all the CameLIGO contracts.
2019-11-04 23:51:47 +01:00
|
|
|
| EConstr (ENone reg) ->
|
|
|
|
let loc = Location.lift reg in
|
|
|
|
return @@ e_none ~loc ()
|
|
|
|
| EConstr (EConstrApp c) ->
|
|
|
|
let (c_name, args), loc = r_split c in
|
|
|
|
let c_name, _c_loc = r_split c_name in
|
2019-05-14 15:57:25 +02:00
|
|
|
let args =
|
|
|
|
match args with
|
Refactoring of Ligodity (CameLIGO) and making an AST pretty-printer
- AST.ml/AST.mli:
- The AST now distinguishes the constructors `None` and `Some` as being
predefined, as in PascaLIGO. See type `AST.constr_pattern`.
- I removed the nodes specific to Liquidity,
e.g. `let%entry`, and, in particular, the natural literals
ending with `p`. Now it should be `n`, as in `10n`.
- I renamed the node `TAlias` to `TVar`.
- I have applied the rule of expanding type expressions after `of` when
those were not records.
- The type of the argument to a data constructor is now
`type_expr`, instead of `cartesian`.
- I added the patterns for bytes (`PBytes`) and natural literals (`PNat`).
- I renamed the node `Sugar` into
`PListComp` (meaning "pattern of list comprehension").
- Record types in CameLIGO now must have at least one field declaration.
- Replaced the type `closing` and `opening` with one type `compound`,
which captures only the right combinations of opening and closing.
- Components of tuples in a selection must not be written
between parentheses. For example, `a.b.(1).(0)` is now
`a.b.1.0`, as in PascaLIGO.
- LexToken.mli/LexToken.mll
- I renamed the string literal `Str` into `String`.
- I added the tokens `C_None` and `C_Some` (to distinguish the
constructors `None` and `Some`. See AST.ml)
- Fixed the function `mk_sym` so it does not fail with `failwith`, but
with `Error Invalid_symbol`.
- Lexer.mll (shared)
- I removed the character `%` from the identifiers (used to
support Liquidity, like `entry%point` and `match%nat`).
- I adde to the hint on broken strings: "or insert a backslash"
(from a Gitlab issue).
- ParToken.mly
- I added the tokens `C_None` and `C_Some` (to distinguish the
constructors `None` and `Some`. See AST.ml and LexToken.mll)
- Parser.mly
- Fixed the order of declarations in the AST (it was reversed).
- I removed syntax support for Liquidity.
- I added user-defined constructor applications to irrefutable
patterns (the ones afer a `let`), even though only the type
checker can decide that they are truly irrefutable because they
are the only constructors of their types.
- I added natural numbers and bytes to patterns.
- Access of tuple components do not require parentheses now, like
`a.b.1.0`.
- I refactored the semantic actions.
- I added the empty sequence `begin end`.
- ParserLog.ml/ParserLog.mli
- I added a pretty-printer for the AST (with source locations).
- ParserMain.ml
- The CLI for the pretty-printer is now `--verbose=ast`.
- The old CLI `--verbose=ast` is now `--verbose=ast-tokens`.
- ligodity.ml (simplifier)
- I removed the constructions of sets, lists and maps with
`Set [...]`, `List [...]` and `Map [...]`, as there are already
better ways (that is, more like the OCaml's way), like
`Set.literal [...]` and `Map.literal [...]`. (The case for lists
was entirely redundant with the rest of the language as it is.)
- Everywhere there is now a non-empty list of elements, I made a
change. In particular, I removed a corner case ("let without
binding"), thanks to more precise OCaml types for non-empty
lists.
- I ported all the changes to the AST above.
- region.ml (vendors)
- I changed the method `compact` so the end-line is not repeated
if it is the same as the start line: this is even more compact. I
use this in the new pretty-printer for the AST (see above)
- I updated all the CameLIGO contracts.
2019-11-04 23:51:47 +01:00
|
|
|
None -> []
|
2019-05-14 15:57:25 +02:00
|
|
|
| Some arg -> [arg] in
|
2020-03-16 14:53:56 +01:00
|
|
|
let%bind arg = compile_tuple_expression @@ args
|
Refactoring of Ligodity (CameLIGO) and making an AST pretty-printer
- AST.ml/AST.mli:
- The AST now distinguishes the constructors `None` and `Some` as being
predefined, as in PascaLIGO. See type `AST.constr_pattern`.
- I removed the nodes specific to Liquidity,
e.g. `let%entry`, and, in particular, the natural literals
ending with `p`. Now it should be `n`, as in `10n`.
- I renamed the node `TAlias` to `TVar`.
- I have applied the rule of expanding type expressions after `of` when
those were not records.
- The type of the argument to a data constructor is now
`type_expr`, instead of `cartesian`.
- I added the patterns for bytes (`PBytes`) and natural literals (`PNat`).
- I renamed the node `Sugar` into
`PListComp` (meaning "pattern of list comprehension").
- Record types in CameLIGO now must have at least one field declaration.
- Replaced the type `closing` and `opening` with one type `compound`,
which captures only the right combinations of opening and closing.
- Components of tuples in a selection must not be written
between parentheses. For example, `a.b.(1).(0)` is now
`a.b.1.0`, as in PascaLIGO.
- LexToken.mli/LexToken.mll
- I renamed the string literal `Str` into `String`.
- I added the tokens `C_None` and `C_Some` (to distinguish the
constructors `None` and `Some`. See AST.ml)
- Fixed the function `mk_sym` so it does not fail with `failwith`, but
with `Error Invalid_symbol`.
- Lexer.mll (shared)
- I removed the character `%` from the identifiers (used to
support Liquidity, like `entry%point` and `match%nat`).
- I adde to the hint on broken strings: "or insert a backslash"
(from a Gitlab issue).
- ParToken.mly
- I added the tokens `C_None` and `C_Some` (to distinguish the
constructors `None` and `Some`. See AST.ml and LexToken.mll)
- Parser.mly
- Fixed the order of declarations in the AST (it was reversed).
- I removed syntax support for Liquidity.
- I added user-defined constructor applications to irrefutable
patterns (the ones afer a `let`), even though only the type
checker can decide that they are truly irrefutable because they
are the only constructors of their types.
- I added natural numbers and bytes to patterns.
- Access of tuple components do not require parentheses now, like
`a.b.1.0`.
- I refactored the semantic actions.
- I added the empty sequence `begin end`.
- ParserLog.ml/ParserLog.mli
- I added a pretty-printer for the AST (with source locations).
- ParserMain.ml
- The CLI for the pretty-printer is now `--verbose=ast`.
- The old CLI `--verbose=ast` is now `--verbose=ast-tokens`.
- ligodity.ml (simplifier)
- I removed the constructions of sets, lists and maps with
`Set [...]`, `List [...]` and `Map [...]`, as there are already
better ways (that is, more like the OCaml's way), like
`Set.literal [...]` and `Map.literal [...]`. (The case for lists
was entirely redundant with the rest of the language as it is.)
- Everywhere there is now a non-empty list of elements, I made a
change. In particular, I removed a corner case ("let without
binding"), thanks to more precise OCaml types for non-empty
lists.
- I ported all the changes to the AST above.
- region.ml (vendors)
- I changed the method `compact` so the end-line is not repeated
if it is the same as the start line: this is even more compact. I
use this in the new pretty-printer for the AST (see above)
- I updated all the CameLIGO contracts.
2019-11-04 23:51:47 +01:00
|
|
|
in return @@ e_constructor ~loc c_name arg
|
2019-05-14 15:57:25 +02:00
|
|
|
| EArith (Add c) ->
|
2020-03-16 14:53:56 +01:00
|
|
|
compile_binop "ADD" c
|
2019-05-14 15:57:25 +02:00
|
|
|
| EArith (Sub c) ->
|
2020-03-16 14:53:56 +01:00
|
|
|
compile_binop "SUB" c
|
2019-05-14 15:57:25 +02:00
|
|
|
| EArith (Mult c) ->
|
2020-03-16 14:53:56 +01:00
|
|
|
compile_binop "TIMES" c
|
2019-05-14 15:57:25 +02:00
|
|
|
| EArith (Div c) ->
|
2020-03-16 14:53:56 +01:00
|
|
|
compile_binop "DIV" c
|
2019-05-14 15:57:25 +02:00
|
|
|
| EArith (Mod c) ->
|
2020-03-16 14:53:56 +01:00
|
|
|
compile_binop "MOD" c
|
2019-05-28 16:34:53 +00:00
|
|
|
| EArith (Int n) -> (
|
|
|
|
let (n , loc) = r_split n in
|
2020-04-27 16:15:26 +02:00
|
|
|
let n = snd @@ n in
|
2019-05-28 16:34:53 +00:00
|
|
|
return @@ e_literal ~loc (Literal_int n)
|
|
|
|
)
|
|
|
|
| EArith (Nat n) -> (
|
|
|
|
let (n , loc) = r_split n in
|
2020-04-27 16:15:26 +02:00
|
|
|
let n = snd @@ n in
|
2019-05-28 16:34:53 +00:00
|
|
|
return @@ e_literal ~loc (Literal_nat n)
|
|
|
|
)
|
2019-10-27 11:50:24 -05:00
|
|
|
| EArith (Mutez n) -> (
|
2019-05-28 16:34:53 +00:00
|
|
|
let (n , loc) = r_split n in
|
2020-04-27 16:15:26 +02:00
|
|
|
let n = snd @@ n in
|
2019-09-24 14:29:18 +02:00
|
|
|
return @@ e_literal ~loc (Literal_mutez n)
|
2019-05-28 16:34:53 +00:00
|
|
|
)
|
2020-03-16 14:53:56 +01:00
|
|
|
| EArith (Neg e) -> compile_unop "NEG" e
|
Refactoring of comments (for [dune build @doc]).
Refactoring of parsing command-line arguments
* The type [options] is now abstract and implemented as an
object type to avoid struggling with scoping and type
inference when record types share some common field names.
Refactoring of ParserLog for PascaLIGO and CameLIGO
* The immediate motivation behind that refactoring was to
remove the use of a couple of global references. A
consequence is that we have a nicer and more compact code, by
threading a state. The files [pascaligo/Tests/pp.ligo] and
[ligodity/Tests/pp.mligo].
* Another consequence is that the choice of making strings from
AST nodes depends on the CLI (offsets? mode?). After this
refactoring, that choice is hardcoded in the simplifiers in a
few places (TODO), waiting for a general solution that would
have all CL options flow through the compiler.
* I removed the use of vendors [x_option.ml], [x_map.ml] and
[x_list.ml] when handling optional values. (Less dependencies
this way.)
Refactoring of the ASTs
* I removed the node [local_decl], which was set to [[]]
already in a previous commit (which removed local
declarations as being redundant, as statements could already
be instructions or declarations).
* I changed [StrLit] to [String] in the AST of CameLIGO and
ReasonLIGO.
* I also changed the type [fun_expr] so now either a block is
present, and therefore followed by the [with] keyword, or it
is not. (Before, the presence of a block was not enforced in
the type with the presence of the keyword.)
Notes
* [LexerMain.ml] and [ParserMain.ml] for CameLIGO and PascaLIGO
are almost identical and differ in the same way (language
name and file extension), which suggests that they should be
in the [shared] folder and instanciated as a functor in the
future (TODO).
* I removed the blank characters at the end of many lines in
the parser of ReasonLIGO.
2019-12-13 12:21:52 +01:00
|
|
|
| EString (String s) -> (
|
2019-05-28 16:34:53 +00:00
|
|
|
let (s , loc) = r_split s in
|
2020-04-27 11:31:16 +02:00
|
|
|
return @@ e_literal ~loc (Literal_string (Standard s))
|
|
|
|
)
|
|
|
|
| EString (Verbatim v) -> (
|
|
|
|
let (v , loc) = r_split v in
|
|
|
|
return @@ e_literal ~loc (Literal_string (Verbatim v))
|
2019-05-28 16:34:53 +00:00
|
|
|
)
|
2019-10-21 15:46:26 -07:00
|
|
|
| EString (Cat c) ->
|
|
|
|
let (c, loc) = r_split c in
|
2020-03-16 14:53:56 +01:00
|
|
|
let%bind string_left = compile_expression c.arg1 in
|
|
|
|
let%bind string_right = compile_expression c.arg2 in
|
2019-10-21 15:46:26 -07:00
|
|
|
return @@ e_string_cat ~loc string_left string_right
|
2020-03-16 14:53:56 +01:00
|
|
|
| ELogic l -> compile_logic_expression l
|
|
|
|
| EList l -> compile_list_expression l
|
2019-05-31 22:03:06 +00:00
|
|
|
| ECase c -> (
|
2019-05-28 16:34:53 +00:00
|
|
|
let (c , loc) = r_split c in
|
2020-03-16 14:53:56 +01:00
|
|
|
let%bind e = compile_expression c.expr in
|
2019-05-14 15:57:25 +02:00
|
|
|
let%bind lst =
|
|
|
|
let aux (x : Raw.expr Raw.case_clause) =
|
2020-03-16 14:53:56 +01:00
|
|
|
let%bind expr = compile_expression x.rhs in
|
2019-05-14 15:57:25 +02:00
|
|
|
ok (x.pattern, expr) in
|
|
|
|
bind_list
|
|
|
|
@@ List.map aux
|
|
|
|
@@ List.map get_value
|
2019-05-28 16:34:53 +00:00
|
|
|
@@ npseq_to_list c.cases.value in
|
2019-05-31 22:03:06 +00:00
|
|
|
let default_action () =
|
2020-03-16 14:53:56 +01:00
|
|
|
let%bind cases = compile_cases lst in
|
2019-06-01 11:29:31 +00:00
|
|
|
return @@ e_matching ~loc e cases in
|
2019-12-12 14:35:07 +01:00
|
|
|
(* Hack to take care of patterns introduced by `parser/cameligo/Parser.mly` in "norm_fun_expr". TODO: Still needed? *)
|
2019-05-31 22:03:06 +00:00
|
|
|
match lst with
|
|
|
|
| [ (pattern , rhs) ] -> (
|
|
|
|
match pattern with
|
|
|
|
| Raw.PPar p -> (
|
|
|
|
let p' = p.value.inside in
|
|
|
|
match p' with
|
|
|
|
| Raw.PTyped x -> (
|
|
|
|
let x' = x.value in
|
|
|
|
match x'.pattern with
|
|
|
|
| Raw.PVar y ->
|
2019-12-04 11:40:58 +00:00
|
|
|
let var_name = Var.of_name y.value in
|
2020-03-16 14:53:56 +01:00
|
|
|
let%bind type_expr = compile_type_expression x'.type_expr in
|
2020-03-23 16:00:50 +01:00
|
|
|
return @@ e_let_in (var_name , Some type_expr) false e rhs
|
2019-05-31 22:03:06 +00:00
|
|
|
| _ -> default_action ()
|
|
|
|
)
|
|
|
|
| _ -> default_action ()
|
|
|
|
)
|
|
|
|
| _ -> default_action ()
|
|
|
|
)
|
|
|
|
| _ -> default_action ()
|
|
|
|
)
|
2020-03-16 14:53:56 +01:00
|
|
|
| EFun lamb -> compile_fun lamb
|
2019-05-28 16:34:53 +00:00
|
|
|
| ESeq s -> (
|
|
|
|
let (s , loc) = r_split s in
|
|
|
|
let items : Raw.expr list = pseq_to_list s.elements in
|
2020-04-08 18:00:03 +02:00
|
|
|
(match List.rev items with
|
2019-06-01 11:29:31 +00:00
|
|
|
[] -> return @@ e_skip ~loc ()
|
2019-05-28 17:00:43 +02:00
|
|
|
| expr::more ->
|
2020-03-16 14:53:56 +01:00
|
|
|
let expr' = compile_expression expr in
|
2020-04-08 18:00:03 +02:00
|
|
|
let apply e1 e2 =
|
|
|
|
let%bind a = compile_expression e2 in
|
|
|
|
let%bind e1' = e1 in
|
|
|
|
return @@ e_sequence a e1'
|
|
|
|
in List.fold_left apply expr' more)
|
2019-05-28 16:34:53 +00:00
|
|
|
)
|
|
|
|
| ECond c -> (
|
|
|
|
let (c , loc) = r_split c in
|
2020-03-16 14:53:56 +01:00
|
|
|
let%bind expr = compile_expression c.test in
|
|
|
|
let%bind match_true = compile_expression c.ifso in
|
|
|
|
let%bind match_false = compile_expression c.ifnot in
|
2020-04-23 17:53:10 +02:00
|
|
|
return @@ e_cond ~loc expr match_true match_false
|
2019-05-28 16:34:53 +00:00
|
|
|
)
|
2019-05-31 22:03:06 +00:00
|
|
|
|
2020-03-16 14:53:56 +01:00
|
|
|
and compile_fun lamb' : expr result =
|
2019-06-01 08:37:43 +00:00
|
|
|
let return x = ok x in
|
2019-06-01 11:29:31 +00:00
|
|
|
let (lamb , loc) = r_split lamb' in
|
2020-01-08 20:58:26 +00:00
|
|
|
let%bind params' =
|
|
|
|
let params = nseq_to_list lamb.binders in
|
|
|
|
let params = (* Handle case where we have tuple destructure in params *)
|
|
|
|
(* So basically the transformation we're doing is:
|
|
|
|
|
|
|
|
let sum (result, i: int * int) : int = result + i
|
|
|
|
|
|
|
|
TO:
|
|
|
|
|
|
|
|
let sum (#P: int * int) : int =
|
|
|
|
let result, i = #P in result + i
|
|
|
|
|
|
|
|
In this first section we replace `result, i` with `#P`. *)
|
2019-12-29 01:24:22 +00:00
|
|
|
match lamb.binders with
|
|
|
|
(* TODO: currently works only if there is one param *)
|
|
|
|
| (Raw.PPar pp, []) ->
|
|
|
|
let pt = pp.value.inside in
|
|
|
|
(match pt with
|
|
|
|
| Raw.PTyped pt ->
|
|
|
|
begin
|
2020-01-21 21:23:31 +01:00
|
|
|
let pt_pattern = unpar_pattern pt.value.pattern in
|
|
|
|
match pt_pattern with
|
2020-01-08 20:58:26 +00:00
|
|
|
| Raw.PVar _ -> params
|
2020-05-15 17:46:56 +02:00
|
|
|
| Raw.PTuple t ->
|
2019-12-29 01:24:22 +00:00
|
|
|
[Raw.PTyped
|
2020-05-15 17:46:56 +02:00
|
|
|
{region=t.region;
|
2019-12-29 01:24:22 +00:00
|
|
|
value=
|
|
|
|
{ pt.value with pattern=
|
2020-05-15 17:46:56 +02:00
|
|
|
Raw.PVar {region=pt.region;
|
2019-12-29 01:24:22 +00:00
|
|
|
value="#P"}}}]
|
2020-01-08 20:58:26 +00:00
|
|
|
| _ -> params
|
2019-12-29 01:24:22 +00:00
|
|
|
end
|
2020-01-08 20:58:26 +00:00
|
|
|
| _ -> params)
|
|
|
|
| _ -> params
|
2019-12-29 01:24:22 +00:00
|
|
|
in
|
2020-01-08 20:58:26 +00:00
|
|
|
let%bind p_params = bind_map_list pattern_to_typed_var params in
|
2019-06-01 11:29:31 +00:00
|
|
|
let aux ((var : Raw.variable) , ty_opt) =
|
|
|
|
match var.value , ty_opt with
|
|
|
|
| "storage" , None ->
|
2019-12-04 11:40:58 +00:00
|
|
|
ok (var , t_variable "storage")
|
2019-06-01 11:29:31 +00:00
|
|
|
| _ , None ->
|
2019-06-03 19:23:40 +02:00
|
|
|
fail @@ untyped_fun_param var
|
2019-06-01 11:29:31 +00:00
|
|
|
| _ , Some ty -> (
|
2020-03-16 14:53:56 +01:00
|
|
|
let%bind ty' = compile_type_expression ty in
|
2019-06-01 11:29:31 +00:00
|
|
|
ok (var , ty')
|
|
|
|
)
|
2019-06-01 08:37:43 +00:00
|
|
|
in
|
2020-01-08 20:58:26 +00:00
|
|
|
bind_map_list aux p_params
|
2019-06-01 08:37:43 +00:00
|
|
|
in
|
2020-01-08 20:58:26 +00:00
|
|
|
let%bind body =
|
|
|
|
if (List.length params' > 1) then ok lamb.body
|
|
|
|
else
|
|
|
|
let original_params = nseq_to_list lamb.binders in
|
|
|
|
let%bind destruct =
|
|
|
|
match original_params with
|
|
|
|
| hd :: _ -> ok @@ hd
|
|
|
|
| [] -> fail @@ corner_case "Somehow have no parameters in function during tuple param destructure"
|
|
|
|
in
|
|
|
|
match destruct with (* Handle tuple parameter destructuring *)
|
|
|
|
(* In this section we create a let ... in that binds the original parameters *)
|
|
|
|
| Raw.PPar pp ->
|
2020-01-21 21:23:31 +01:00
|
|
|
(match unpar_pattern pp.value.inside with
|
2020-01-08 20:58:26 +00:00
|
|
|
| Raw.PTyped pt ->
|
|
|
|
let vars = pt.value in
|
2020-01-21 21:23:31 +01:00
|
|
|
(match unpar_pattern vars.pattern with
|
2020-01-08 20:58:26 +00:00
|
|
|
| PTuple vars ->
|
|
|
|
let let_in_binding: Raw.let_binding =
|
|
|
|
{binders = (PTuple vars, []) ;
|
|
|
|
lhs_type=None;
|
|
|
|
eq=Region.ghost;
|
2020-05-15 17:46:56 +02:00
|
|
|
let_rhs=(Raw.EVar {region=pt.region; value="#P"});
|
2020-01-08 20:58:26 +00:00
|
|
|
}
|
|
|
|
in
|
|
|
|
let let_in: Raw.let_in =
|
|
|
|
{kwd_let= Region.ghost;
|
2020-02-20 22:31:47 +01:00
|
|
|
kwd_rec= None;
|
2020-01-08 20:58:26 +00:00
|
|
|
binding= let_in_binding;
|
|
|
|
kwd_in= Region.ghost;
|
|
|
|
body= lamb.body;
|
2020-01-16 19:36:04 +00:00
|
|
|
attributes = []
|
2020-01-08 20:58:26 +00:00
|
|
|
}
|
|
|
|
in
|
|
|
|
ok (Raw.ELetIn
|
|
|
|
{
|
2020-05-15 17:46:56 +02:00
|
|
|
region=pt.region;
|
2020-01-08 20:58:26 +00:00
|
|
|
value=let_in
|
|
|
|
})
|
|
|
|
| Raw.PVar _ -> ok lamb.body
|
|
|
|
| _ -> ok lamb.body)
|
|
|
|
| _ -> ok lamb.body)
|
|
|
|
| _ -> ok lamb.body
|
|
|
|
in
|
2020-03-07 02:39:39 +01:00
|
|
|
let%bind (body , body_type) = expr_to_typed_expr body in
|
2020-01-08 20:58:26 +00:00
|
|
|
let%bind output_type =
|
2020-03-16 14:53:56 +01:00
|
|
|
bind_map_option compile_type_expression body_type in
|
|
|
|
let%bind body = compile_expression body in
|
2020-01-08 20:58:26 +00:00
|
|
|
let rec layer_arguments (arguments: (Raw.variable * type_expression) list) =
|
|
|
|
match arguments with
|
|
|
|
| hd :: tl ->
|
2019-06-06 21:06:33 +00:00
|
|
|
let (binder , input_type) =
|
2020-01-08 20:58:26 +00:00
|
|
|
(Var.of_name (fst hd).value , snd hd) in
|
|
|
|
e_lambda ~loc (binder) (Some input_type) output_type (layer_arguments tl)
|
|
|
|
| [] -> body
|
|
|
|
in
|
2020-03-09 00:13:07 +01:00
|
|
|
let ret_lamb = layer_arguments params' in
|
|
|
|
return @@ ret_lamb
|
2019-06-01 08:37:43 +00:00
|
|
|
|
2019-05-31 22:03:06 +00:00
|
|
|
|
2020-03-16 14:53:56 +01:00
|
|
|
and compile_logic_expression ?te_annot (t:Raw.logic_expr) : expr result =
|
2019-05-23 07:49:06 +00:00
|
|
|
let return x = ok @@ make_option_typed x te_annot in
|
2019-05-14 15:57:25 +02:00
|
|
|
match t with
|
2019-05-28 16:34:53 +00:00
|
|
|
| BoolExpr (False reg) -> (
|
|
|
|
let loc = Location.lift reg in
|
2020-04-22 17:56:27 +02:00
|
|
|
return @@ e_bool ~loc false
|
2019-05-28 16:34:53 +00:00
|
|
|
)
|
|
|
|
| BoolExpr (True reg) -> (
|
|
|
|
let loc = Location.lift reg in
|
2020-04-22 17:56:27 +02:00
|
|
|
return @@ e_bool ~loc true
|
2019-05-28 16:34:53 +00:00
|
|
|
)
|
2019-05-14 15:57:25 +02:00
|
|
|
| BoolExpr (Or b) ->
|
2020-03-16 14:53:56 +01:00
|
|
|
compile_binop "OR" b
|
2019-05-14 15:57:25 +02:00
|
|
|
| BoolExpr (And b) ->
|
2020-03-16 14:53:56 +01:00
|
|
|
compile_binop "AND" b
|
2019-05-14 15:57:25 +02:00
|
|
|
| BoolExpr (Not b) ->
|
2020-03-16 14:53:56 +01:00
|
|
|
compile_unop "NOT" b
|
2019-05-14 15:57:25 +02:00
|
|
|
| CompExpr (Lt c) ->
|
2020-03-16 14:53:56 +01:00
|
|
|
compile_binop "LT" c
|
2019-05-14 15:57:25 +02:00
|
|
|
| CompExpr (Gt c) ->
|
2020-03-16 14:53:56 +01:00
|
|
|
compile_binop "GT" c
|
2019-05-14 15:57:25 +02:00
|
|
|
| CompExpr (Leq c) ->
|
2020-03-16 14:53:56 +01:00
|
|
|
compile_binop "LE" c
|
2019-05-14 15:57:25 +02:00
|
|
|
| CompExpr (Geq c) ->
|
2020-03-16 14:53:56 +01:00
|
|
|
compile_binop "GE" c
|
2019-05-14 15:57:25 +02:00
|
|
|
| CompExpr (Equal c) ->
|
2020-03-16 14:53:56 +01:00
|
|
|
compile_binop "EQ" c
|
2019-05-14 15:57:25 +02:00
|
|
|
| CompExpr (Neq c) ->
|
2020-03-16 14:53:56 +01:00
|
|
|
compile_binop "NEQ" c
|
2019-05-14 15:57:25 +02:00
|
|
|
|
2020-03-16 14:53:56 +01:00
|
|
|
and compile_list_expression (t:Raw.list_expr) : expression result =
|
2019-05-28 16:34:53 +00:00
|
|
|
let return x = ok @@ x in
|
2019-05-14 15:57:25 +02:00
|
|
|
match t with
|
2020-03-16 14:53:56 +01:00
|
|
|
ECons c -> compile_binop "CONS" c
|
Refactoring of Ligodity (CameLIGO) and making an AST pretty-printer
- AST.ml/AST.mli:
- The AST now distinguishes the constructors `None` and `Some` as being
predefined, as in PascaLIGO. See type `AST.constr_pattern`.
- I removed the nodes specific to Liquidity,
e.g. `let%entry`, and, in particular, the natural literals
ending with `p`. Now it should be `n`, as in `10n`.
- I renamed the node `TAlias` to `TVar`.
- I have applied the rule of expanding type expressions after `of` when
those were not records.
- The type of the argument to a data constructor is now
`type_expr`, instead of `cartesian`.
- I added the patterns for bytes (`PBytes`) and natural literals (`PNat`).
- I renamed the node `Sugar` into
`PListComp` (meaning "pattern of list comprehension").
- Record types in CameLIGO now must have at least one field declaration.
- Replaced the type `closing` and `opening` with one type `compound`,
which captures only the right combinations of opening and closing.
- Components of tuples in a selection must not be written
between parentheses. For example, `a.b.(1).(0)` is now
`a.b.1.0`, as in PascaLIGO.
- LexToken.mli/LexToken.mll
- I renamed the string literal `Str` into `String`.
- I added the tokens `C_None` and `C_Some` (to distinguish the
constructors `None` and `Some`. See AST.ml)
- Fixed the function `mk_sym` so it does not fail with `failwith`, but
with `Error Invalid_symbol`.
- Lexer.mll (shared)
- I removed the character `%` from the identifiers (used to
support Liquidity, like `entry%point` and `match%nat`).
- I adde to the hint on broken strings: "or insert a backslash"
(from a Gitlab issue).
- ParToken.mly
- I added the tokens `C_None` and `C_Some` (to distinguish the
constructors `None` and `Some`. See AST.ml and LexToken.mll)
- Parser.mly
- Fixed the order of declarations in the AST (it was reversed).
- I removed syntax support for Liquidity.
- I added user-defined constructor applications to irrefutable
patterns (the ones afer a `let`), even though only the type
checker can decide that they are truly irrefutable because they
are the only constructors of their types.
- I added natural numbers and bytes to patterns.
- Access of tuple components do not require parentheses now, like
`a.b.1.0`.
- I refactored the semantic actions.
- I added the empty sequence `begin end`.
- ParserLog.ml/ParserLog.mli
- I added a pretty-printer for the AST (with source locations).
- ParserMain.ml
- The CLI for the pretty-printer is now `--verbose=ast`.
- The old CLI `--verbose=ast` is now `--verbose=ast-tokens`.
- ligodity.ml (simplifier)
- I removed the constructions of sets, lists and maps with
`Set [...]`, `List [...]` and `Map [...]`, as there are already
better ways (that is, more like the OCaml's way), like
`Set.literal [...]` and `Map.literal [...]`. (The case for lists
was entirely redundant with the rest of the language as it is.)
- Everywhere there is now a non-empty list of elements, I made a
change. In particular, I removed a corner case ("let without
binding"), thanks to more precise OCaml types for non-empty
lists.
- I ported all the changes to the AST above.
- region.ml (vendors)
- I changed the method `compact` so the end-line is not repeated
if it is the same as the start line: this is even more compact. I
use this in the new pretty-printer for the AST (see above)
- I updated all the CameLIGO contracts.
2019-11-04 23:51:47 +01:00
|
|
|
| EListComp lst -> (
|
2019-05-28 16:34:53 +00:00
|
|
|
let (lst , loc) = r_split lst in
|
2019-05-14 15:57:25 +02:00
|
|
|
let%bind lst' =
|
2020-03-16 14:53:56 +01:00
|
|
|
bind_map_list compile_expression @@
|
2019-05-28 16:34:53 +00:00
|
|
|
pseq_to_list lst.elements in
|
|
|
|
return @@ e_list ~loc lst'
|
|
|
|
)
|
2019-05-14 15:57:25 +02:00
|
|
|
|
2020-03-16 14:53:56 +01:00
|
|
|
and compile_binop (name:string) (t:_ Raw.bin_op Region.reg) : expression result =
|
2019-05-28 16:34:53 +00:00
|
|
|
let return x = ok @@ x in
|
|
|
|
let (args , loc) = r_split t in
|
2020-03-16 14:53:56 +01:00
|
|
|
let%bind a = compile_expression args.arg1 in
|
|
|
|
let%bind b = compile_expression args.arg2 in
|
2020-04-20 17:39:36 +02:00
|
|
|
let%bind name = trace_option (unknown_built_in name) @@ constants name in
|
2019-05-28 16:34:53 +00:00
|
|
|
return @@ e_constant ~loc name [ a ; b ]
|
2019-05-14 15:57:25 +02:00
|
|
|
|
2020-03-16 14:53:56 +01:00
|
|
|
and compile_unop (name:string) (t:_ Raw.un_op Region.reg) : expression result =
|
2019-05-28 16:34:53 +00:00
|
|
|
let return x = ok @@ x in
|
|
|
|
let (t , loc) = r_split t in
|
2020-03-16 14:53:56 +01:00
|
|
|
let%bind a = compile_expression t.arg in
|
2020-04-20 17:39:36 +02:00
|
|
|
let%bind name = trace_option (unknown_built_in name) @@ constants name in
|
2019-05-28 16:34:53 +00:00
|
|
|
return @@ e_constant ~loc name [ a ]
|
2019-05-14 15:57:25 +02:00
|
|
|
|
2020-03-16 14:53:56 +01:00
|
|
|
and compile_tuple_expression ?loc (lst:Raw.expr list) : expression result =
|
2019-05-28 16:34:53 +00:00
|
|
|
let return x = ok @@ x in
|
2019-05-14 15:57:25 +02:00
|
|
|
match lst with
|
2019-05-28 16:34:53 +00:00
|
|
|
| [] -> return @@ e_literal ?loc Literal_unit
|
2020-03-16 14:53:56 +01:00
|
|
|
| [hd] -> compile_expression hd
|
2019-05-14 15:57:25 +02:00
|
|
|
| lst ->
|
2020-03-16 14:53:56 +01:00
|
|
|
let%bind lst = bind_list @@ List.map compile_expression lst in
|
2019-05-28 16:34:53 +00:00
|
|
|
return @@ e_tuple ?loc lst
|
2019-05-14 15:57:25 +02:00
|
|
|
|
2020-03-16 14:53:56 +01:00
|
|
|
and compile_declaration : Raw.declaration -> declaration Location.wrap list result =
|
2019-06-03 19:23:40 +02:00
|
|
|
fun t ->
|
2019-05-14 15:57:25 +02:00
|
|
|
let open! Raw in
|
2019-06-03 19:23:40 +02:00
|
|
|
let loc : 'a . 'a Raw.reg -> _ -> _ =
|
|
|
|
fun x v -> Location.wrap ~loc:(File x.region) v in
|
2019-05-14 15:57:25 +02:00
|
|
|
match t with
|
|
|
|
| TypeDecl x ->
|
|
|
|
let {name;type_expr} : Raw.type_decl = x.value in
|
2020-03-16 14:53:56 +01:00
|
|
|
let%bind type_expression = compile_type_expression type_expr in
|
2019-12-04 11:40:58 +00:00
|
|
|
ok @@ [loc x @@ Declaration_type (Var.of_name name.value , type_expression)]
|
2019-05-23 07:49:06 +00:00
|
|
|
| Let x -> (
|
2020-05-15 17:46:56 +02:00
|
|
|
let (region, recursive, let_binding, attributes), _ = r_split x in
|
2020-01-16 19:36:04 +00:00
|
|
|
let inline = List.exists (fun (a: Raw.attribute) -> a.value = "inline") attributes in
|
|
|
|
let binding = let_binding in
|
Refactoring of Ligodity (CameLIGO) and making an AST pretty-printer
- AST.ml/AST.mli:
- The AST now distinguishes the constructors `None` and `Some` as being
predefined, as in PascaLIGO. See type `AST.constr_pattern`.
- I removed the nodes specific to Liquidity,
e.g. `let%entry`, and, in particular, the natural literals
ending with `p`. Now it should be `n`, as in `10n`.
- I renamed the node `TAlias` to `TVar`.
- I have applied the rule of expanding type expressions after `of` when
those were not records.
- The type of the argument to a data constructor is now
`type_expr`, instead of `cartesian`.
- I added the patterns for bytes (`PBytes`) and natural literals (`PNat`).
- I renamed the node `Sugar` into
`PListComp` (meaning "pattern of list comprehension").
- Record types in CameLIGO now must have at least one field declaration.
- Replaced the type `closing` and `opening` with one type `compound`,
which captures only the right combinations of opening and closing.
- Components of tuples in a selection must not be written
between parentheses. For example, `a.b.(1).(0)` is now
`a.b.1.0`, as in PascaLIGO.
- LexToken.mli/LexToken.mll
- I renamed the string literal `Str` into `String`.
- I added the tokens `C_None` and `C_Some` (to distinguish the
constructors `None` and `Some`. See AST.ml)
- Fixed the function `mk_sym` so it does not fail with `failwith`, but
with `Error Invalid_symbol`.
- Lexer.mll (shared)
- I removed the character `%` from the identifiers (used to
support Liquidity, like `entry%point` and `match%nat`).
- I adde to the hint on broken strings: "or insert a backslash"
(from a Gitlab issue).
- ParToken.mly
- I added the tokens `C_None` and `C_Some` (to distinguish the
constructors `None` and `Some`. See AST.ml and LexToken.mll)
- Parser.mly
- Fixed the order of declarations in the AST (it was reversed).
- I removed syntax support for Liquidity.
- I added user-defined constructor applications to irrefutable
patterns (the ones afer a `let`), even though only the type
checker can decide that they are truly irrefutable because they
are the only constructors of their types.
- I added natural numbers and bytes to patterns.
- Access of tuple components do not require parentheses now, like
`a.b.1.0`.
- I refactored the semantic actions.
- I added the empty sequence `begin end`.
- ParserLog.ml/ParserLog.mli
- I added a pretty-printer for the AST (with source locations).
- ParserMain.ml
- The CLI for the pretty-printer is now `--verbose=ast`.
- The old CLI `--verbose=ast` is now `--verbose=ast-tokens`.
- ligodity.ml (simplifier)
- I removed the constructions of sets, lists and maps with
`Set [...]`, `List [...]` and `Map [...]`, as there are already
better ways (that is, more like the OCaml's way), like
`Set.literal [...]` and `Map.literal [...]`. (The case for lists
was entirely redundant with the rest of the language as it is.)
- Everywhere there is now a non-empty list of elements, I made a
change. In particular, I removed a corner case ("let without
binding"), thanks to more precise OCaml types for non-empty
lists.
- I ported all the changes to the AST above.
- region.ml (vendors)
- I changed the method `compact` so the end-line is not repeated
if it is the same as the start line: this is even more compact. I
use this in the new pretty-printer for the AST (see above)
- I updated all the CameLIGO contracts.
2019-11-04 23:51:47 +01:00
|
|
|
let {binders; lhs_type; let_rhs} = binding in
|
2020-03-06 23:44:28 +01:00
|
|
|
let (hd, _) = binders in
|
2019-11-19 21:13:52 +00:00
|
|
|
match hd with
|
|
|
|
| PTuple pt ->
|
2020-03-12 23:20:39 +01:00
|
|
|
let process_variable (var_pair: pattern * Raw.expr) =
|
2019-11-19 21:13:52 +00:00
|
|
|
(let (par_var, rhs_expr) = var_pair in
|
|
|
|
let%bind (v, v_type) = pattern_to_typed_var par_var in
|
|
|
|
let%bind v_type_expression =
|
|
|
|
match v_type with
|
2020-03-16 14:53:56 +01:00
|
|
|
| Some v_type -> ok (to_option (compile_type_expression v_type))
|
2019-12-17 21:04:53 +00:00
|
|
|
| None -> ok None
|
2020-01-24 14:03:25 +01:00
|
|
|
in
|
2020-03-16 14:53:56 +01:00
|
|
|
let%bind compile_rhs_expr = compile_expression rhs_expr in
|
|
|
|
ok @@ loc x @@ Declaration_constant (Var.of_name v.value, v_type_expression, inline, compile_rhs_expr) )
|
2019-11-19 21:13:52 +00:00
|
|
|
in let%bind variables = ok @@ npseq_to_list pt.value
|
|
|
|
in let%bind expr_bind_lst =
|
|
|
|
match let_rhs with
|
|
|
|
| ETuple et -> ok @@ npseq_to_list et.value
|
|
|
|
| EVar v -> (* Handle variable bound to tuple *)
|
|
|
|
let name = v.value in
|
|
|
|
let rec gen_access_tuple ?(i: int = 0)
|
|
|
|
?(accesses: Raw.expr list = []) (name: string)
|
|
|
|
: Raw.expr list =
|
|
|
|
let build_access_expr : Raw.expr = EProj
|
|
|
|
{region = v.region;
|
|
|
|
value =
|
|
|
|
{ struct_name = v;
|
|
|
|
selector = Region.ghost ;
|
|
|
|
field_path =
|
|
|
|
(
|
|
|
|
(Component
|
2020-05-15 17:46:56 +02:00
|
|
|
{region = v.region;
|
2019-11-19 21:13:52 +00:00
|
|
|
value = name, Z.of_int i;} : Raw.selection)
|
|
|
|
, []);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
in
|
|
|
|
if i = (List.length variables) then accesses
|
|
|
|
else
|
|
|
|
let accesses =
|
2019-12-03 10:49:58 -08:00
|
|
|
build_access_expr :: accesses
|
2019-11-19 21:13:52 +00:00
|
|
|
in
|
|
|
|
gen_access_tuple name ~i: (i + 1) ~accesses
|
|
|
|
in ok (gen_access_tuple name)
|
|
|
|
(* TODO: Improve this error message *)
|
2020-03-12 23:20:39 +01:00
|
|
|
| other -> fail @@ abstracting_expr other
|
2019-11-19 21:13:52 +00:00
|
|
|
in let%bind decls =
|
2019-12-03 10:49:58 -08:00
|
|
|
(* TODO: Rewrite the gen_access_tuple so there's no List.rev *)
|
|
|
|
bind_map_list process_variable (List.combine variables (List.rev expr_bind_lst))
|
2019-11-19 21:13:52 +00:00
|
|
|
in ok @@ decls
|
|
|
|
| PPar {region = _ ; value = { lpar = _ ; inside = pt; rpar = _; } } ->
|
|
|
|
(* Extract parenthetical multi-bind *)
|
2020-03-09 22:53:15 +01:00
|
|
|
let (wild, recursive, _, attributes) = fst @@ r_split x in
|
2020-03-16 14:53:56 +01:00
|
|
|
compile_declaration
|
2019-11-19 21:13:52 +00:00
|
|
|
(Let {
|
|
|
|
region = x.region;
|
2020-03-09 22:53:15 +01:00
|
|
|
value = (wild, recursive, {binders = (pt, []);
|
2019-11-19 21:13:52 +00:00
|
|
|
lhs_type = lhs_type;
|
|
|
|
eq = Region.ghost ;
|
2020-01-16 19:36:04 +00:00
|
|
|
let_rhs = let_rhs}, attributes)}
|
2019-11-19 21:13:52 +00:00
|
|
|
: Raw.declaration)
|
|
|
|
| _ ->
|
Refactoring of Ligodity (CameLIGO) and making an AST pretty-printer
- AST.ml/AST.mli:
- The AST now distinguishes the constructors `None` and `Some` as being
predefined, as in PascaLIGO. See type `AST.constr_pattern`.
- I removed the nodes specific to Liquidity,
e.g. `let%entry`, and, in particular, the natural literals
ending with `p`. Now it should be `n`, as in `10n`.
- I renamed the node `TAlias` to `TVar`.
- I have applied the rule of expanding type expressions after `of` when
those were not records.
- The type of the argument to a data constructor is now
`type_expr`, instead of `cartesian`.
- I added the patterns for bytes (`PBytes`) and natural literals (`PNat`).
- I renamed the node `Sugar` into
`PListComp` (meaning "pattern of list comprehension").
- Record types in CameLIGO now must have at least one field declaration.
- Replaced the type `closing` and `opening` with one type `compound`,
which captures only the right combinations of opening and closing.
- Components of tuples in a selection must not be written
between parentheses. For example, `a.b.(1).(0)` is now
`a.b.1.0`, as in PascaLIGO.
- LexToken.mli/LexToken.mll
- I renamed the string literal `Str` into `String`.
- I added the tokens `C_None` and `C_Some` (to distinguish the
constructors `None` and `Some`. See AST.ml)
- Fixed the function `mk_sym` so it does not fail with `failwith`, but
with `Error Invalid_symbol`.
- Lexer.mll (shared)
- I removed the character `%` from the identifiers (used to
support Liquidity, like `entry%point` and `match%nat`).
- I adde to the hint on broken strings: "or insert a backslash"
(from a Gitlab issue).
- ParToken.mly
- I added the tokens `C_None` and `C_Some` (to distinguish the
constructors `None` and `Some`. See AST.ml and LexToken.mll)
- Parser.mly
- Fixed the order of declarations in the AST (it was reversed).
- I removed syntax support for Liquidity.
- I added user-defined constructor applications to irrefutable
patterns (the ones afer a `let`), even though only the type
checker can decide that they are truly irrefutable because they
are the only constructors of their types.
- I added natural numbers and bytes to patterns.
- Access of tuple components do not require parentheses now, like
`a.b.1.0`.
- I refactored the semantic actions.
- I added the empty sequence `begin end`.
- ParserLog.ml/ParserLog.mli
- I added a pretty-printer for the AST (with source locations).
- ParserMain.ml
- The CLI for the pretty-printer is now `--verbose=ast`.
- The old CLI `--verbose=ast` is now `--verbose=ast-tokens`.
- ligodity.ml (simplifier)
- I removed the constructions of sets, lists and maps with
`Set [...]`, `List [...]` and `Map [...]`, as there are already
better ways (that is, more like the OCaml's way), like
`Set.literal [...]` and `Map.literal [...]`. (The case for lists
was entirely redundant with the rest of the language as it is.)
- Everywhere there is now a non-empty list of elements, I made a
change. In particular, I removed a corner case ("let without
binding"), thanks to more precise OCaml types for non-empty
lists.
- I ported all the changes to the AST above.
- region.ml (vendors)
- I changed the method `compact` so the end-line is not repeated
if it is the same as the start line: this is even more compact. I
use this in the new pretty-printer for the AST (see above)
- I updated all the CameLIGO contracts.
2019-11-04 23:51:47 +01:00
|
|
|
let%bind (var, args) =
|
|
|
|
let%bind (hd, tl) =
|
|
|
|
let hd, tl = binders in ok (hd, tl) in
|
2019-06-01 11:29:31 +00:00
|
|
|
let%bind var = pattern_to_var hd in
|
|
|
|
ok (var , tl)
|
2019-12-04 11:40:58 +00:00
|
|
|
in
|
2020-03-16 14:53:56 +01:00
|
|
|
let%bind lhs_type' = bind_map_option (fun x -> compile_type_expression (snd x)) lhs_type in
|
2020-03-07 02:39:39 +01:00
|
|
|
let%bind let_rhs,lhs_type = match args with
|
|
|
|
| [] -> ok (let_rhs, lhs_type')
|
2019-12-04 11:40:58 +00:00
|
|
|
| param1::others ->
|
|
|
|
let fun_ = {
|
|
|
|
kwd_fun = Region.ghost;
|
|
|
|
binders = param1, others;
|
|
|
|
lhs_type;
|
|
|
|
arrow = Region.ghost;
|
2020-01-16 19:36:04 +00:00
|
|
|
body = let_rhs
|
|
|
|
} in
|
2020-03-07 02:39:39 +01:00
|
|
|
let f_args = nseq_to_list (param1,others) in
|
|
|
|
let%bind ty = bind_map_list typed_pattern_to_typed_vars f_args in
|
2020-05-19 18:53:20 +02:00
|
|
|
let aux acc (_,ty,loc) = Option.map (t_function ~loc ty) acc in
|
2020-05-15 17:46:56 +02:00
|
|
|
ok (Raw.EFun {region; value=fun_},List.fold_right' aux lhs_type' ty)
|
2020-03-07 02:00:29 +01:00
|
|
|
in
|
2020-03-16 14:53:56 +01:00
|
|
|
let%bind rhs' = compile_expression let_rhs in
|
2020-04-12 15:26:47 +02:00
|
|
|
let%bind lhs_type = match lhs_type with
|
|
|
|
| None -> (match let_rhs with
|
|
|
|
| EFun {value={binders;lhs_type}} ->
|
2020-03-07 02:00:29 +01:00
|
|
|
let f_args = nseq_to_list (binders) in
|
2020-03-16 14:53:56 +01:00
|
|
|
let%bind lhs_type' = bind_map_option (fun x -> compile_type_expression (snd x)) lhs_type in
|
2020-03-03 16:17:07 +01:00
|
|
|
let%bind ty = bind_map_list typed_pattern_to_typed_vars f_args in
|
2020-05-19 18:53:20 +02:00
|
|
|
let aux acc (_,ty,loc) = Option.map (t_function ~loc ty) acc in
|
2020-03-07 02:39:39 +01:00
|
|
|
ok @@ (List.fold_right' aux lhs_type' ty)
|
|
|
|
| _ -> ok None
|
|
|
|
)
|
|
|
|
| Some t -> ok @@ Some t
|
2020-02-27 12:38:00 +01:00
|
|
|
in
|
2020-03-06 23:44:28 +01:00
|
|
|
let binder = Var.of_name var.value in
|
2020-04-12 15:26:47 +02:00
|
|
|
let%bind rhs' = match recursive with
|
|
|
|
None -> ok @@ rhs'
|
|
|
|
| Some _ -> match rhs'.expression_content with
|
2020-03-06 23:44:28 +01:00
|
|
|
E_lambda lambda ->
|
2020-04-12 15:26:47 +02:00
|
|
|
(match lhs_type with
|
|
|
|
None -> fail @@ untyped_recursive_function var
|
|
|
|
| Some (lhs_type) ->
|
2020-03-06 23:44:28 +01:00
|
|
|
let expression_content = E_recursive {fun_name=binder;fun_type=lhs_type;lambda} in
|
|
|
|
ok @@ {rhs' with expression_content})
|
|
|
|
| _ -> ok @@ rhs'
|
|
|
|
in
|
2020-03-03 16:17:07 +01:00
|
|
|
ok @@ [loc x @@ (Declaration_constant (Var.of_name var.value , lhs_type , inline, rhs'))]
|
2019-12-04 11:40:58 +00:00
|
|
|
)
|
2019-05-15 15:04:03 +02:00
|
|
|
|
2020-03-16 14:53:56 +01:00
|
|
|
and compile_cases : type a . (Raw.pattern * a) list -> (a, unit) matching_content result =
|
2019-06-04 13:45:21 +02:00
|
|
|
fun t ->
|
2019-05-14 15:57:25 +02:00
|
|
|
let open Raw in
|
2019-06-04 13:45:21 +02:00
|
|
|
let rec get_var (t:Raw.pattern) =
|
|
|
|
match t with
|
2019-05-14 15:57:25 +02:00
|
|
|
| PVar v -> ok v.value
|
2019-06-04 13:45:21 +02:00
|
|
|
| PPar p -> get_var p.value.inside
|
Refactoring of Ligodity (CameLIGO) and making an AST pretty-printer
- AST.ml/AST.mli:
- The AST now distinguishes the constructors `None` and `Some` as being
predefined, as in PascaLIGO. See type `AST.constr_pattern`.
- I removed the nodes specific to Liquidity,
e.g. `let%entry`, and, in particular, the natural literals
ending with `p`. Now it should be `n`, as in `10n`.
- I renamed the node `TAlias` to `TVar`.
- I have applied the rule of expanding type expressions after `of` when
those were not records.
- The type of the argument to a data constructor is now
`type_expr`, instead of `cartesian`.
- I added the patterns for bytes (`PBytes`) and natural literals (`PNat`).
- I renamed the node `Sugar` into
`PListComp` (meaning "pattern of list comprehension").
- Record types in CameLIGO now must have at least one field declaration.
- Replaced the type `closing` and `opening` with one type `compound`,
which captures only the right combinations of opening and closing.
- Components of tuples in a selection must not be written
between parentheses. For example, `a.b.(1).(0)` is now
`a.b.1.0`, as in PascaLIGO.
- LexToken.mli/LexToken.mll
- I renamed the string literal `Str` into `String`.
- I added the tokens `C_None` and `C_Some` (to distinguish the
constructors `None` and `Some`. See AST.ml)
- Fixed the function `mk_sym` so it does not fail with `failwith`, but
with `Error Invalid_symbol`.
- Lexer.mll (shared)
- I removed the character `%` from the identifiers (used to
support Liquidity, like `entry%point` and `match%nat`).
- I adde to the hint on broken strings: "or insert a backslash"
(from a Gitlab issue).
- ParToken.mly
- I added the tokens `C_None` and `C_Some` (to distinguish the
constructors `None` and `Some`. See AST.ml and LexToken.mll)
- Parser.mly
- Fixed the order of declarations in the AST (it was reversed).
- I removed syntax support for Liquidity.
- I added user-defined constructor applications to irrefutable
patterns (the ones afer a `let`), even though only the type
checker can decide that they are truly irrefutable because they
are the only constructors of their types.
- I added natural numbers and bytes to patterns.
- Access of tuple components do not require parentheses now, like
`a.b.1.0`.
- I refactored the semantic actions.
- I added the empty sequence `begin end`.
- ParserLog.ml/ParserLog.mli
- I added a pretty-printer for the AST (with source locations).
- ParserMain.ml
- The CLI for the pretty-printer is now `--verbose=ast`.
- The old CLI `--verbose=ast` is now `--verbose=ast-tokens`.
- ligodity.ml (simplifier)
- I removed the constructions of sets, lists and maps with
`Set [...]`, `List [...]` and `Map [...]`, as there are already
better ways (that is, more like the OCaml's way), like
`Set.literal [...]` and `Map.literal [...]`. (The case for lists
was entirely redundant with the rest of the language as it is.)
- Everywhere there is now a non-empty list of elements, I made a
change. In particular, I removed a corner case ("let without
binding"), thanks to more precise OCaml types for non-empty
lists.
- I ported all the changes to the AST above.
- region.ml (vendors)
- I changed the method `compact` so the end-line is not repeated
if it is the same as the start line: this is even more compact. I
use this in the new pretty-printer for the AST (see above)
- I updated all the CameLIGO contracts.
2019-11-04 23:51:47 +01:00
|
|
|
| _ -> fail @@ unsupported_non_var_pattern t in
|
2019-06-04 13:45:21 +02:00
|
|
|
let rec get_tuple (t:Raw.pattern) =
|
|
|
|
match t with
|
2019-05-23 07:49:06 +00:00
|
|
|
| PTuple v -> npseq_to_list v.value
|
2019-06-03 19:23:40 +02:00
|
|
|
| PPar p -> get_tuple p.value.inside
|
Refactoring of Ligodity (CameLIGO) and making an AST pretty-printer
- AST.ml/AST.mli:
- The AST now distinguishes the constructors `None` and `Some` as being
predefined, as in PascaLIGO. See type `AST.constr_pattern`.
- I removed the nodes specific to Liquidity,
e.g. `let%entry`, and, in particular, the natural literals
ending with `p`. Now it should be `n`, as in `10n`.
- I renamed the node `TAlias` to `TVar`.
- I have applied the rule of expanding type expressions after `of` when
those were not records.
- The type of the argument to a data constructor is now
`type_expr`, instead of `cartesian`.
- I added the patterns for bytes (`PBytes`) and natural literals (`PNat`).
- I renamed the node `Sugar` into
`PListComp` (meaning "pattern of list comprehension").
- Record types in CameLIGO now must have at least one field declaration.
- Replaced the type `closing` and `opening` with one type `compound`,
which captures only the right combinations of opening and closing.
- Components of tuples in a selection must not be written
between parentheses. For example, `a.b.(1).(0)` is now
`a.b.1.0`, as in PascaLIGO.
- LexToken.mli/LexToken.mll
- I renamed the string literal `Str` into `String`.
- I added the tokens `C_None` and `C_Some` (to distinguish the
constructors `None` and `Some`. See AST.ml)
- Fixed the function `mk_sym` so it does not fail with `failwith`, but
with `Error Invalid_symbol`.
- Lexer.mll (shared)
- I removed the character `%` from the identifiers (used to
support Liquidity, like `entry%point` and `match%nat`).
- I adde to the hint on broken strings: "or insert a backslash"
(from a Gitlab issue).
- ParToken.mly
- I added the tokens `C_None` and `C_Some` (to distinguish the
constructors `None` and `Some`. See AST.ml and LexToken.mll)
- Parser.mly
- Fixed the order of declarations in the AST (it was reversed).
- I removed syntax support for Liquidity.
- I added user-defined constructor applications to irrefutable
patterns (the ones afer a `let`), even though only the type
checker can decide that they are truly irrefutable because they
are the only constructors of their types.
- I added natural numbers and bytes to patterns.
- Access of tuple components do not require parentheses now, like
`a.b.1.0`.
- I refactored the semantic actions.
- I added the empty sequence `begin end`.
- ParserLog.ml/ParserLog.mli
- I added a pretty-printer for the AST (with source locations).
- ParserMain.ml
- The CLI for the pretty-printer is now `--verbose=ast`.
- The old CLI `--verbose=ast` is now `--verbose=ast-tokens`.
- ligodity.ml (simplifier)
- I removed the constructions of sets, lists and maps with
`Set [...]`, `List [...]` and `Map [...]`, as there are already
better ways (that is, more like the OCaml's way), like
`Set.literal [...]` and `Map.literal [...]`. (The case for lists
was entirely redundant with the rest of the language as it is.)
- Everywhere there is now a non-empty list of elements, I made a
change. In particular, I removed a corner case ("let without
binding"), thanks to more precise OCaml types for non-empty
lists.
- I ported all the changes to the AST above.
- region.ml (vendors)
- I changed the method `compact` so the end-line is not repeated
if it is the same as the start line: this is even more compact. I
use this in the new pretty-printer for the AST (see above)
- I updated all the CameLIGO contracts.
2019-11-04 23:51:47 +01:00
|
|
|
| x -> [ x ] in
|
2019-05-14 15:57:25 +02:00
|
|
|
let get_single (t:Raw.pattern) =
|
|
|
|
let t' = get_tuple t in
|
|
|
|
let%bind () =
|
2019-06-03 19:23:40 +02:00
|
|
|
trace_strong (unsupported_tuple_pattern t) @@
|
2019-05-14 15:57:25 +02:00
|
|
|
Assert.assert_list_size t' 1 in
|
Refactoring of Ligodity (CameLIGO) and making an AST pretty-printer
- AST.ml/AST.mli:
- The AST now distinguishes the constructors `None` and `Some` as being
predefined, as in PascaLIGO. See type `AST.constr_pattern`.
- I removed the nodes specific to Liquidity,
e.g. `let%entry`, and, in particular, the natural literals
ending with `p`. Now it should be `n`, as in `10n`.
- I renamed the node `TAlias` to `TVar`.
- I have applied the rule of expanding type expressions after `of` when
those were not records.
- The type of the argument to a data constructor is now
`type_expr`, instead of `cartesian`.
- I added the patterns for bytes (`PBytes`) and natural literals (`PNat`).
- I renamed the node `Sugar` into
`PListComp` (meaning "pattern of list comprehension").
- Record types in CameLIGO now must have at least one field declaration.
- Replaced the type `closing` and `opening` with one type `compound`,
which captures only the right combinations of opening and closing.
- Components of tuples in a selection must not be written
between parentheses. For example, `a.b.(1).(0)` is now
`a.b.1.0`, as in PascaLIGO.
- LexToken.mli/LexToken.mll
- I renamed the string literal `Str` into `String`.
- I added the tokens `C_None` and `C_Some` (to distinguish the
constructors `None` and `Some`. See AST.ml)
- Fixed the function `mk_sym` so it does not fail with `failwith`, but
with `Error Invalid_symbol`.
- Lexer.mll (shared)
- I removed the character `%` from the identifiers (used to
support Liquidity, like `entry%point` and `match%nat`).
- I adde to the hint on broken strings: "or insert a backslash"
(from a Gitlab issue).
- ParToken.mly
- I added the tokens `C_None` and `C_Some` (to distinguish the
constructors `None` and `Some`. See AST.ml and LexToken.mll)
- Parser.mly
- Fixed the order of declarations in the AST (it was reversed).
- I removed syntax support for Liquidity.
- I added user-defined constructor applications to irrefutable
patterns (the ones afer a `let`), even though only the type
checker can decide that they are truly irrefutable because they
are the only constructors of their types.
- I added natural numbers and bytes to patterns.
- Access of tuple components do not require parentheses now, like
`a.b.1.0`.
- I refactored the semantic actions.
- I added the empty sequence `begin end`.
- ParserLog.ml/ParserLog.mli
- I added a pretty-printer for the AST (with source locations).
- ParserMain.ml
- The CLI for the pretty-printer is now `--verbose=ast`.
- The old CLI `--verbose=ast` is now `--verbose=ast-tokens`.
- ligodity.ml (simplifier)
- I removed the constructions of sets, lists and maps with
`Set [...]`, `List [...]` and `Map [...]`, as there are already
better ways (that is, more like the OCaml's way), like
`Set.literal [...]` and `Map.literal [...]`. (The case for lists
was entirely redundant with the rest of the language as it is.)
- Everywhere there is now a non-empty list of elements, I made a
change. In particular, I removed a corner case ("let without
binding"), thanks to more precise OCaml types for non-empty
lists.
- I ported all the changes to the AST above.
- region.ml (vendors)
- I changed the method `compact` so the end-line is not repeated
if it is the same as the start line: this is even more compact. I
use this in the new pretty-printer for the AST (see above)
- I updated all the CameLIGO contracts.
2019-11-04 23:51:47 +01:00
|
|
|
ok (List.hd t') in
|
2019-06-04 13:45:21 +02:00
|
|
|
let rec get_constr (t:Raw.pattern) =
|
|
|
|
match t with
|
Refactoring of Ligodity (CameLIGO) and making an AST pretty-printer
- AST.ml/AST.mli:
- The AST now distinguishes the constructors `None` and `Some` as being
predefined, as in PascaLIGO. See type `AST.constr_pattern`.
- I removed the nodes specific to Liquidity,
e.g. `let%entry`, and, in particular, the natural literals
ending with `p`. Now it should be `n`, as in `10n`.
- I renamed the node `TAlias` to `TVar`.
- I have applied the rule of expanding type expressions after `of` when
those were not records.
- The type of the argument to a data constructor is now
`type_expr`, instead of `cartesian`.
- I added the patterns for bytes (`PBytes`) and natural literals (`PNat`).
- I renamed the node `Sugar` into
`PListComp` (meaning "pattern of list comprehension").
- Record types in CameLIGO now must have at least one field declaration.
- Replaced the type `closing` and `opening` with one type `compound`,
which captures only the right combinations of opening and closing.
- Components of tuples in a selection must not be written
between parentheses. For example, `a.b.(1).(0)` is now
`a.b.1.0`, as in PascaLIGO.
- LexToken.mli/LexToken.mll
- I renamed the string literal `Str` into `String`.
- I added the tokens `C_None` and `C_Some` (to distinguish the
constructors `None` and `Some`. See AST.ml)
- Fixed the function `mk_sym` so it does not fail with `failwith`, but
with `Error Invalid_symbol`.
- Lexer.mll (shared)
- I removed the character `%` from the identifiers (used to
support Liquidity, like `entry%point` and `match%nat`).
- I adde to the hint on broken strings: "or insert a backslash"
(from a Gitlab issue).
- ParToken.mly
- I added the tokens `C_None` and `C_Some` (to distinguish the
constructors `None` and `Some`. See AST.ml and LexToken.mll)
- Parser.mly
- Fixed the order of declarations in the AST (it was reversed).
- I removed syntax support for Liquidity.
- I added user-defined constructor applications to irrefutable
patterns (the ones afer a `let`), even though only the type
checker can decide that they are truly irrefutable because they
are the only constructors of their types.
- I added natural numbers and bytes to patterns.
- Access of tuple components do not require parentheses now, like
`a.b.1.0`.
- I refactored the semantic actions.
- I added the empty sequence `begin end`.
- ParserLog.ml/ParserLog.mli
- I added a pretty-printer for the AST (with source locations).
- ParserMain.ml
- The CLI for the pretty-printer is now `--verbose=ast`.
- The old CLI `--verbose=ast` is now `--verbose=ast-tokens`.
- ligodity.ml (simplifier)
- I removed the constructions of sets, lists and maps with
`Set [...]`, `List [...]` and `Map [...]`, as there are already
better ways (that is, more like the OCaml's way), like
`Set.literal [...]` and `Map.literal [...]`. (The case for lists
was entirely redundant with the rest of the language as it is.)
- Everywhere there is now a non-empty list of elements, I made a
change. In particular, I removed a corner case ("let without
binding"), thanks to more precise OCaml types for non-empty
lists.
- I ported all the changes to the AST above.
- region.ml (vendors)
- I changed the method `compact` so the end-line is not repeated
if it is the same as the start line: this is even more compact. I
use this in the new pretty-printer for the AST (see above)
- I updated all the CameLIGO contracts.
2019-11-04 23:51:47 +01:00
|
|
|
PPar p -> get_constr p.value.inside
|
|
|
|
| PConstr v ->
|
|
|
|
let const, pat_opt =
|
|
|
|
match v with
|
2020-05-15 17:46:56 +02:00
|
|
|
PConstrApp {value; region} ->
|
2020-01-03 13:01:13 +00:00
|
|
|
(match value with
|
2020-01-24 14:03:25 +01:00
|
|
|
| constr, None ->
|
2020-05-15 17:46:56 +02:00
|
|
|
constr, Some (PVar {value = "unit"; region})
|
2020-01-03 13:01:13 +00:00
|
|
|
| _ -> value)
|
Refactoring of Ligodity (CameLIGO) and making an AST pretty-printer
- AST.ml/AST.mli:
- The AST now distinguishes the constructors `None` and `Some` as being
predefined, as in PascaLIGO. See type `AST.constr_pattern`.
- I removed the nodes specific to Liquidity,
e.g. `let%entry`, and, in particular, the natural literals
ending with `p`. Now it should be `n`, as in `10n`.
- I renamed the node `TAlias` to `TVar`.
- I have applied the rule of expanding type expressions after `of` when
those were not records.
- The type of the argument to a data constructor is now
`type_expr`, instead of `cartesian`.
- I added the patterns for bytes (`PBytes`) and natural literals (`PNat`).
- I renamed the node `Sugar` into
`PListComp` (meaning "pattern of list comprehension").
- Record types in CameLIGO now must have at least one field declaration.
- Replaced the type `closing` and `opening` with one type `compound`,
which captures only the right combinations of opening and closing.
- Components of tuples in a selection must not be written
between parentheses. For example, `a.b.(1).(0)` is now
`a.b.1.0`, as in PascaLIGO.
- LexToken.mli/LexToken.mll
- I renamed the string literal `Str` into `String`.
- I added the tokens `C_None` and `C_Some` (to distinguish the
constructors `None` and `Some`. See AST.ml)
- Fixed the function `mk_sym` so it does not fail with `failwith`, but
with `Error Invalid_symbol`.
- Lexer.mll (shared)
- I removed the character `%` from the identifiers (used to
support Liquidity, like `entry%point` and `match%nat`).
- I adde to the hint on broken strings: "or insert a backslash"
(from a Gitlab issue).
- ParToken.mly
- I added the tokens `C_None` and `C_Some` (to distinguish the
constructors `None` and `Some`. See AST.ml and LexToken.mll)
- Parser.mly
- Fixed the order of declarations in the AST (it was reversed).
- I removed syntax support for Liquidity.
- I added user-defined constructor applications to irrefutable
patterns (the ones afer a `let`), even though only the type
checker can decide that they are truly irrefutable because they
are the only constructors of their types.
- I added natural numbers and bytes to patterns.
- Access of tuple components do not require parentheses now, like
`a.b.1.0`.
- I refactored the semantic actions.
- I added the empty sequence `begin end`.
- ParserLog.ml/ParserLog.mli
- I added a pretty-printer for the AST (with source locations).
- ParserMain.ml
- The CLI for the pretty-printer is now `--verbose=ast`.
- The old CLI `--verbose=ast` is now `--verbose=ast-tokens`.
- ligodity.ml (simplifier)
- I removed the constructions of sets, lists and maps with
`Set [...]`, `List [...]` and `Map [...]`, as there are already
better ways (that is, more like the OCaml's way), like
`Set.literal [...]` and `Map.literal [...]`. (The case for lists
was entirely redundant with the rest of the language as it is.)
- Everywhere there is now a non-empty list of elements, I made a
change. In particular, I removed a corner case ("let without
binding"), thanks to more precise OCaml types for non-empty
lists.
- I ported all the changes to the AST above.
- region.ml (vendors)
- I changed the method `compact` so the end-line is not repeated
if it is the same as the start line: this is even more compact. I
use this in the new pretty-printer for the AST (see above)
- I updated all the CameLIGO contracts.
2019-11-04 23:51:47 +01:00
|
|
|
| PSomeApp {value=region,pat; _} ->
|
|
|
|
{value="Some"; region}, Some pat
|
|
|
|
| PNone region ->
|
|
|
|
{value="None"; region}, None in
|
2019-05-23 07:49:06 +00:00
|
|
|
let%bind pat =
|
Refactoring of Ligodity (CameLIGO) and making an AST pretty-printer
- AST.ml/AST.mli:
- The AST now distinguishes the constructors `None` and `Some` as being
predefined, as in PascaLIGO. See type `AST.constr_pattern`.
- I removed the nodes specific to Liquidity,
e.g. `let%entry`, and, in particular, the natural literals
ending with `p`. Now it should be `n`, as in `10n`.
- I renamed the node `TAlias` to `TVar`.
- I have applied the rule of expanding type expressions after `of` when
those were not records.
- The type of the argument to a data constructor is now
`type_expr`, instead of `cartesian`.
- I added the patterns for bytes (`PBytes`) and natural literals (`PNat`).
- I renamed the node `Sugar` into
`PListComp` (meaning "pattern of list comprehension").
- Record types in CameLIGO now must have at least one field declaration.
- Replaced the type `closing` and `opening` with one type `compound`,
which captures only the right combinations of opening and closing.
- Components of tuples in a selection must not be written
between parentheses. For example, `a.b.(1).(0)` is now
`a.b.1.0`, as in PascaLIGO.
- LexToken.mli/LexToken.mll
- I renamed the string literal `Str` into `String`.
- I added the tokens `C_None` and `C_Some` (to distinguish the
constructors `None` and `Some`. See AST.ml)
- Fixed the function `mk_sym` so it does not fail with `failwith`, but
with `Error Invalid_symbol`.
- Lexer.mll (shared)
- I removed the character `%` from the identifiers (used to
support Liquidity, like `entry%point` and `match%nat`).
- I adde to the hint on broken strings: "or insert a backslash"
(from a Gitlab issue).
- ParToken.mly
- I added the tokens `C_None` and `C_Some` (to distinguish the
constructors `None` and `Some`. See AST.ml and LexToken.mll)
- Parser.mly
- Fixed the order of declarations in the AST (it was reversed).
- I removed syntax support for Liquidity.
- I added user-defined constructor applications to irrefutable
patterns (the ones afer a `let`), even though only the type
checker can decide that they are truly irrefutable because they
are the only constructors of their types.
- I added natural numbers and bytes to patterns.
- Access of tuple components do not require parentheses now, like
`a.b.1.0`.
- I refactored the semantic actions.
- I added the empty sequence `begin end`.
- ParserLog.ml/ParserLog.mli
- I added a pretty-printer for the AST (with source locations).
- ParserMain.ml
- The CLI for the pretty-printer is now `--verbose=ast`.
- The old CLI `--verbose=ast` is now `--verbose=ast-tokens`.
- ligodity.ml (simplifier)
- I removed the constructions of sets, lists and maps with
`Set [...]`, `List [...]` and `Map [...]`, as there are already
better ways (that is, more like the OCaml's way), like
`Set.literal [...]` and `Map.literal [...]`. (The case for lists
was entirely redundant with the rest of the language as it is.)
- Everywhere there is now a non-empty list of elements, I made a
change. In particular, I removed a corner case ("let without
binding"), thanks to more precise OCaml types for non-empty
lists.
- I ported all the changes to the AST above.
- region.ml (vendors)
- I changed the method `compact` so the end-line is not repeated
if it is the same as the start line: this is even more compact. I
use this in the new pretty-printer for the AST (see above)
- I updated all the CameLIGO contracts.
2019-11-04 23:51:47 +01:00
|
|
|
trace_option (unsupported_cst_constr t) @@ pat_opt in
|
2019-05-23 07:49:06 +00:00
|
|
|
let%bind single_pat = get_single pat in
|
|
|
|
let%bind var = get_var single_pat in
|
Refactoring of Ligodity (CameLIGO) and making an AST pretty-printer
- AST.ml/AST.mli:
- The AST now distinguishes the constructors `None` and `Some` as being
predefined, as in PascaLIGO. See type `AST.constr_pattern`.
- I removed the nodes specific to Liquidity,
e.g. `let%entry`, and, in particular, the natural literals
ending with `p`. Now it should be `n`, as in `10n`.
- I renamed the node `TAlias` to `TVar`.
- I have applied the rule of expanding type expressions after `of` when
those were not records.
- The type of the argument to a data constructor is now
`type_expr`, instead of `cartesian`.
- I added the patterns for bytes (`PBytes`) and natural literals (`PNat`).
- I renamed the node `Sugar` into
`PListComp` (meaning "pattern of list comprehension").
- Record types in CameLIGO now must have at least one field declaration.
- Replaced the type `closing` and `opening` with one type `compound`,
which captures only the right combinations of opening and closing.
- Components of tuples in a selection must not be written
between parentheses. For example, `a.b.(1).(0)` is now
`a.b.1.0`, as in PascaLIGO.
- LexToken.mli/LexToken.mll
- I renamed the string literal `Str` into `String`.
- I added the tokens `C_None` and `C_Some` (to distinguish the
constructors `None` and `Some`. See AST.ml)
- Fixed the function `mk_sym` so it does not fail with `failwith`, but
with `Error Invalid_symbol`.
- Lexer.mll (shared)
- I removed the character `%` from the identifiers (used to
support Liquidity, like `entry%point` and `match%nat`).
- I adde to the hint on broken strings: "or insert a backslash"
(from a Gitlab issue).
- ParToken.mly
- I added the tokens `C_None` and `C_Some` (to distinguish the
constructors `None` and `Some`. See AST.ml and LexToken.mll)
- Parser.mly
- Fixed the order of declarations in the AST (it was reversed).
- I removed syntax support for Liquidity.
- I added user-defined constructor applications to irrefutable
patterns (the ones afer a `let`), even though only the type
checker can decide that they are truly irrefutable because they
are the only constructors of their types.
- I added natural numbers and bytes to patterns.
- Access of tuple components do not require parentheses now, like
`a.b.1.0`.
- I refactored the semantic actions.
- I added the empty sequence `begin end`.
- ParserLog.ml/ParserLog.mli
- I added a pretty-printer for the AST (with source locations).
- ParserMain.ml
- The CLI for the pretty-printer is now `--verbose=ast`.
- The old CLI `--verbose=ast` is now `--verbose=ast-tokens`.
- ligodity.ml (simplifier)
- I removed the constructions of sets, lists and maps with
`Set [...]`, `List [...]` and `Map [...]`, as there are already
better ways (that is, more like the OCaml's way), like
`Set.literal [...]` and `Map.literal [...]`. (The case for lists
was entirely redundant with the rest of the language as it is.)
- Everywhere there is now a non-empty list of elements, I made a
change. In particular, I removed a corner case ("let without
binding"), thanks to more precise OCaml types for non-empty
lists.
- I ported all the changes to the AST above.
- region.ml (vendors)
- I changed the method `compact` so the end-line is not repeated
if it is the same as the start line: this is even more compact. I
use this in the new pretty-printer for the AST (see above)
- I updated all the CameLIGO contracts.
2019-11-04 23:51:47 +01:00
|
|
|
ok (const.value, var)
|
|
|
|
| _ -> fail @@ only_constructors t in
|
2019-09-20 20:38:04 +02:00
|
|
|
let rec get_constr_opt (t:Raw.pattern) =
|
|
|
|
match t with
|
Refactoring of Ligodity (CameLIGO) and making an AST pretty-printer
- AST.ml/AST.mli:
- The AST now distinguishes the constructors `None` and `Some` as being
predefined, as in PascaLIGO. See type `AST.constr_pattern`.
- I removed the nodes specific to Liquidity,
e.g. `let%entry`, and, in particular, the natural literals
ending with `p`. Now it should be `n`, as in `10n`.
- I renamed the node `TAlias` to `TVar`.
- I have applied the rule of expanding type expressions after `of` when
those were not records.
- The type of the argument to a data constructor is now
`type_expr`, instead of `cartesian`.
- I added the patterns for bytes (`PBytes`) and natural literals (`PNat`).
- I renamed the node `Sugar` into
`PListComp` (meaning "pattern of list comprehension").
- Record types in CameLIGO now must have at least one field declaration.
- Replaced the type `closing` and `opening` with one type `compound`,
which captures only the right combinations of opening and closing.
- Components of tuples in a selection must not be written
between parentheses. For example, `a.b.(1).(0)` is now
`a.b.1.0`, as in PascaLIGO.
- LexToken.mli/LexToken.mll
- I renamed the string literal `Str` into `String`.
- I added the tokens `C_None` and `C_Some` (to distinguish the
constructors `None` and `Some`. See AST.ml)
- Fixed the function `mk_sym` so it does not fail with `failwith`, but
with `Error Invalid_symbol`.
- Lexer.mll (shared)
- I removed the character `%` from the identifiers (used to
support Liquidity, like `entry%point` and `match%nat`).
- I adde to the hint on broken strings: "or insert a backslash"
(from a Gitlab issue).
- ParToken.mly
- I added the tokens `C_None` and `C_Some` (to distinguish the
constructors `None` and `Some`. See AST.ml and LexToken.mll)
- Parser.mly
- Fixed the order of declarations in the AST (it was reversed).
- I removed syntax support for Liquidity.
- I added user-defined constructor applications to irrefutable
patterns (the ones afer a `let`), even though only the type
checker can decide that they are truly irrefutable because they
are the only constructors of their types.
- I added natural numbers and bytes to patterns.
- Access of tuple components do not require parentheses now, like
`a.b.1.0`.
- I refactored the semantic actions.
- I added the empty sequence `begin end`.
- ParserLog.ml/ParserLog.mli
- I added a pretty-printer for the AST (with source locations).
- ParserMain.ml
- The CLI for the pretty-printer is now `--verbose=ast`.
- The old CLI `--verbose=ast` is now `--verbose=ast-tokens`.
- ligodity.ml (simplifier)
- I removed the constructions of sets, lists and maps with
`Set [...]`, `List [...]` and `Map [...]`, as there are already
better ways (that is, more like the OCaml's way), like
`Set.literal [...]` and `Map.literal [...]`. (The case for lists
was entirely redundant with the rest of the language as it is.)
- Everywhere there is now a non-empty list of elements, I made a
change. In particular, I removed a corner case ("let without
binding"), thanks to more precise OCaml types for non-empty
lists.
- I ported all the changes to the AST above.
- region.ml (vendors)
- I changed the method `compact` so the end-line is not repeated
if it is the same as the start line: this is even more compact. I
use this in the new pretty-printer for the AST (see above)
- I updated all the CameLIGO contracts.
2019-11-04 23:51:47 +01:00
|
|
|
PPar p -> get_constr_opt p.value.inside
|
|
|
|
| PConstr v ->
|
|
|
|
let const, pat_opt =
|
|
|
|
match v with
|
|
|
|
PConstrApp {value; _} -> value
|
|
|
|
| PSomeApp {value=region,pat; _} ->
|
|
|
|
{value="Some"; region}, Some pat
|
|
|
|
| PNone region ->
|
|
|
|
{value="None"; region}, None in
|
2019-09-20 20:38:04 +02:00
|
|
|
let%bind var_opt =
|
|
|
|
match pat_opt with
|
|
|
|
| None -> ok None
|
Refactoring of Ligodity (CameLIGO) and making an AST pretty-printer
- AST.ml/AST.mli:
- The AST now distinguishes the constructors `None` and `Some` as being
predefined, as in PascaLIGO. See type `AST.constr_pattern`.
- I removed the nodes specific to Liquidity,
e.g. `let%entry`, and, in particular, the natural literals
ending with `p`. Now it should be `n`, as in `10n`.
- I renamed the node `TAlias` to `TVar`.
- I have applied the rule of expanding type expressions after `of` when
those were not records.
- The type of the argument to a data constructor is now
`type_expr`, instead of `cartesian`.
- I added the patterns for bytes (`PBytes`) and natural literals (`PNat`).
- I renamed the node `Sugar` into
`PListComp` (meaning "pattern of list comprehension").
- Record types in CameLIGO now must have at least one field declaration.
- Replaced the type `closing` and `opening` with one type `compound`,
which captures only the right combinations of opening and closing.
- Components of tuples in a selection must not be written
between parentheses. For example, `a.b.(1).(0)` is now
`a.b.1.0`, as in PascaLIGO.
- LexToken.mli/LexToken.mll
- I renamed the string literal `Str` into `String`.
- I added the tokens `C_None` and `C_Some` (to distinguish the
constructors `None` and `Some`. See AST.ml)
- Fixed the function `mk_sym` so it does not fail with `failwith`, but
with `Error Invalid_symbol`.
- Lexer.mll (shared)
- I removed the character `%` from the identifiers (used to
support Liquidity, like `entry%point` and `match%nat`).
- I adde to the hint on broken strings: "or insert a backslash"
(from a Gitlab issue).
- ParToken.mly
- I added the tokens `C_None` and `C_Some` (to distinguish the
constructors `None` and `Some`. See AST.ml and LexToken.mll)
- Parser.mly
- Fixed the order of declarations in the AST (it was reversed).
- I removed syntax support for Liquidity.
- I added user-defined constructor applications to irrefutable
patterns (the ones afer a `let`), even though only the type
checker can decide that they are truly irrefutable because they
are the only constructors of their types.
- I added natural numbers and bytes to patterns.
- Access of tuple components do not require parentheses now, like
`a.b.1.0`.
- I refactored the semantic actions.
- I added the empty sequence `begin end`.
- ParserLog.ml/ParserLog.mli
- I added a pretty-printer for the AST (with source locations).
- ParserMain.ml
- The CLI for the pretty-printer is now `--verbose=ast`.
- The old CLI `--verbose=ast` is now `--verbose=ast-tokens`.
- ligodity.ml (simplifier)
- I removed the constructions of sets, lists and maps with
`Set [...]`, `List [...]` and `Map [...]`, as there are already
better ways (that is, more like the OCaml's way), like
`Set.literal [...]` and `Map.literal [...]`. (The case for lists
was entirely redundant with the rest of the language as it is.)
- Everywhere there is now a non-empty list of elements, I made a
change. In particular, I removed a corner case ("let without
binding"), thanks to more precise OCaml types for non-empty
lists.
- I ported all the changes to the AST above.
- region.ml (vendors)
- I changed the method `compact` so the end-line is not repeated
if it is the same as the start line: this is even more compact. I
use this in the new pretty-printer for the AST (see above)
- I updated all the CameLIGO contracts.
2019-11-04 23:51:47 +01:00
|
|
|
| Some pat ->
|
2019-09-20 20:38:04 +02:00
|
|
|
let%bind single_pat = get_single pat in
|
|
|
|
let%bind var = get_var single_pat in
|
|
|
|
ok (Some var)
|
Refactoring of Ligodity (CameLIGO) and making an AST pretty-printer
- AST.ml/AST.mli:
- The AST now distinguishes the constructors `None` and `Some` as being
predefined, as in PascaLIGO. See type `AST.constr_pattern`.
- I removed the nodes specific to Liquidity,
e.g. `let%entry`, and, in particular, the natural literals
ending with `p`. Now it should be `n`, as in `10n`.
- I renamed the node `TAlias` to `TVar`.
- I have applied the rule of expanding type expressions after `of` when
those were not records.
- The type of the argument to a data constructor is now
`type_expr`, instead of `cartesian`.
- I added the patterns for bytes (`PBytes`) and natural literals (`PNat`).
- I renamed the node `Sugar` into
`PListComp` (meaning "pattern of list comprehension").
- Record types in CameLIGO now must have at least one field declaration.
- Replaced the type `closing` and `opening` with one type `compound`,
which captures only the right combinations of opening and closing.
- Components of tuples in a selection must not be written
between parentheses. For example, `a.b.(1).(0)` is now
`a.b.1.0`, as in PascaLIGO.
- LexToken.mli/LexToken.mll
- I renamed the string literal `Str` into `String`.
- I added the tokens `C_None` and `C_Some` (to distinguish the
constructors `None` and `Some`. See AST.ml)
- Fixed the function `mk_sym` so it does not fail with `failwith`, but
with `Error Invalid_symbol`.
- Lexer.mll (shared)
- I removed the character `%` from the identifiers (used to
support Liquidity, like `entry%point` and `match%nat`).
- I adde to the hint on broken strings: "or insert a backslash"
(from a Gitlab issue).
- ParToken.mly
- I added the tokens `C_None` and `C_Some` (to distinguish the
constructors `None` and `Some`. See AST.ml and LexToken.mll)
- Parser.mly
- Fixed the order of declarations in the AST (it was reversed).
- I removed syntax support for Liquidity.
- I added user-defined constructor applications to irrefutable
patterns (the ones afer a `let`), even though only the type
checker can decide that they are truly irrefutable because they
are the only constructors of their types.
- I added natural numbers and bytes to patterns.
- Access of tuple components do not require parentheses now, like
`a.b.1.0`.
- I refactored the semantic actions.
- I added the empty sequence `begin end`.
- ParserLog.ml/ParserLog.mli
- I added a pretty-printer for the AST (with source locations).
- ParserMain.ml
- The CLI for the pretty-printer is now `--verbose=ast`.
- The old CLI `--verbose=ast` is now `--verbose=ast-tokens`.
- ligodity.ml (simplifier)
- I removed the constructions of sets, lists and maps with
`Set [...]`, `List [...]` and `Map [...]`, as there are already
better ways (that is, more like the OCaml's way), like
`Set.literal [...]` and `Map.literal [...]`. (The case for lists
was entirely redundant with the rest of the language as it is.)
- Everywhere there is now a non-empty list of elements, I made a
change. In particular, I removed a corner case ("let without
binding"), thanks to more precise OCaml types for non-empty
lists.
- I ported all the changes to the AST above.
- region.ml (vendors)
- I changed the method `compact` so the end-line is not repeated
if it is the same as the start line: this is even more compact. I
use this in the new pretty-printer for the AST (see above)
- I updated all the CameLIGO contracts.
2019-11-04 23:51:47 +01:00
|
|
|
in ok (const.value , var_opt)
|
|
|
|
| _ -> fail @@ only_constructors t in
|
2019-05-14 15:57:25 +02:00
|
|
|
let%bind patterns =
|
|
|
|
let aux (x , y) =
|
|
|
|
let xs = get_tuple x in
|
2019-06-04 13:45:21 +02:00
|
|
|
trace_strong (unsupported_tuple_pattern x) @@
|
2019-05-14 15:57:25 +02:00
|
|
|
Assert.assert_list_size xs 1 >>? fun () ->
|
|
|
|
ok (List.hd xs , y)
|
|
|
|
in
|
|
|
|
bind_map_list aux t in
|
|
|
|
match patterns with
|
Refactoring of Ligodity (CameLIGO) and making an AST pretty-printer
- AST.ml/AST.mli:
- The AST now distinguishes the constructors `None` and `Some` as being
predefined, as in PascaLIGO. See type `AST.constr_pattern`.
- I removed the nodes specific to Liquidity,
e.g. `let%entry`, and, in particular, the natural literals
ending with `p`. Now it should be `n`, as in `10n`.
- I renamed the node `TAlias` to `TVar`.
- I have applied the rule of expanding type expressions after `of` when
those were not records.
- The type of the argument to a data constructor is now
`type_expr`, instead of `cartesian`.
- I added the patterns for bytes (`PBytes`) and natural literals (`PNat`).
- I renamed the node `Sugar` into
`PListComp` (meaning "pattern of list comprehension").
- Record types in CameLIGO now must have at least one field declaration.
- Replaced the type `closing` and `opening` with one type `compound`,
which captures only the right combinations of opening and closing.
- Components of tuples in a selection must not be written
between parentheses. For example, `a.b.(1).(0)` is now
`a.b.1.0`, as in PascaLIGO.
- LexToken.mli/LexToken.mll
- I renamed the string literal `Str` into `String`.
- I added the tokens `C_None` and `C_Some` (to distinguish the
constructors `None` and `Some`. See AST.ml)
- Fixed the function `mk_sym` so it does not fail with `failwith`, but
with `Error Invalid_symbol`.
- Lexer.mll (shared)
- I removed the character `%` from the identifiers (used to
support Liquidity, like `entry%point` and `match%nat`).
- I adde to the hint on broken strings: "or insert a backslash"
(from a Gitlab issue).
- ParToken.mly
- I added the tokens `C_None` and `C_Some` (to distinguish the
constructors `None` and `Some`. See AST.ml and LexToken.mll)
- Parser.mly
- Fixed the order of declarations in the AST (it was reversed).
- I removed syntax support for Liquidity.
- I added user-defined constructor applications to irrefutable
patterns (the ones afer a `let`), even though only the type
checker can decide that they are truly irrefutable because they
are the only constructors of their types.
- I added natural numbers and bytes to patterns.
- Access of tuple components do not require parentheses now, like
`a.b.1.0`.
- I refactored the semantic actions.
- I added the empty sequence `begin end`.
- ParserLog.ml/ParserLog.mli
- I added a pretty-printer for the AST (with source locations).
- ParserMain.ml
- The CLI for the pretty-printer is now `--verbose=ast`.
- The old CLI `--verbose=ast` is now `--verbose=ast-tokens`.
- ligodity.ml (simplifier)
- I removed the constructions of sets, lists and maps with
`Set [...]`, `List [...]` and `Map [...]`, as there are already
better ways (that is, more like the OCaml's way), like
`Set.literal [...]` and `Map.literal [...]`. (The case for lists
was entirely redundant with the rest of the language as it is.)
- Everywhere there is now a non-empty list of elements, I made a
change. In particular, I removed a corner case ("let without
binding"), thanks to more precise OCaml types for non-empty
lists.
- I ported all the changes to the AST above.
- region.ml (vendors)
- I changed the method `compact` so the end-line is not repeated
if it is the same as the start line: this is even more compact. I
use this in the new pretty-printer for the AST (see above)
- I updated all the CameLIGO contracts.
2019-11-04 23:51:47 +01:00
|
|
|
| [(PFalse _, f) ; (PTrue _, t)]
|
|
|
|
| [(PTrue _, t) ; (PFalse _, f)] ->
|
2020-04-23 17:28:05 +02:00
|
|
|
ok @@ Match_variant ([((Constructor "true", Var.of_name "_"), t); ((Constructor "false", Var.of_name "_"), f)], ())
|
Refactoring of Ligodity (CameLIGO) and making an AST pretty-printer
- AST.ml/AST.mli:
- The AST now distinguishes the constructors `None` and `Some` as being
predefined, as in PascaLIGO. See type `AST.constr_pattern`.
- I removed the nodes specific to Liquidity,
e.g. `let%entry`, and, in particular, the natural literals
ending with `p`. Now it should be `n`, as in `10n`.
- I renamed the node `TAlias` to `TVar`.
- I have applied the rule of expanding type expressions after `of` when
those were not records.
- The type of the argument to a data constructor is now
`type_expr`, instead of `cartesian`.
- I added the patterns for bytes (`PBytes`) and natural literals (`PNat`).
- I renamed the node `Sugar` into
`PListComp` (meaning "pattern of list comprehension").
- Record types in CameLIGO now must have at least one field declaration.
- Replaced the type `closing` and `opening` with one type `compound`,
which captures only the right combinations of opening and closing.
- Components of tuples in a selection must not be written
between parentheses. For example, `a.b.(1).(0)` is now
`a.b.1.0`, as in PascaLIGO.
- LexToken.mli/LexToken.mll
- I renamed the string literal `Str` into `String`.
- I added the tokens `C_None` and `C_Some` (to distinguish the
constructors `None` and `Some`. See AST.ml)
- Fixed the function `mk_sym` so it does not fail with `failwith`, but
with `Error Invalid_symbol`.
- Lexer.mll (shared)
- I removed the character `%` from the identifiers (used to
support Liquidity, like `entry%point` and `match%nat`).
- I adde to the hint on broken strings: "or insert a backslash"
(from a Gitlab issue).
- ParToken.mly
- I added the tokens `C_None` and `C_Some` (to distinguish the
constructors `None` and `Some`. See AST.ml and LexToken.mll)
- Parser.mly
- Fixed the order of declarations in the AST (it was reversed).
- I removed syntax support for Liquidity.
- I added user-defined constructor applications to irrefutable
patterns (the ones afer a `let`), even though only the type
checker can decide that they are truly irrefutable because they
are the only constructors of their types.
- I added natural numbers and bytes to patterns.
- Access of tuple components do not require parentheses now, like
`a.b.1.0`.
- I refactored the semantic actions.
- I added the empty sequence `begin end`.
- ParserLog.ml/ParserLog.mli
- I added a pretty-printer for the AST (with source locations).
- ParserMain.ml
- The CLI for the pretty-printer is now `--verbose=ast`.
- The old CLI `--verbose=ast` is now `--verbose=ast-tokens`.
- ligodity.ml (simplifier)
- I removed the constructions of sets, lists and maps with
`Set [...]`, `List [...]` and `Map [...]`, as there are already
better ways (that is, more like the OCaml's way), like
`Set.literal [...]` and `Map.literal [...]`. (The case for lists
was entirely redundant with the rest of the language as it is.)
- Everywhere there is now a non-empty list of elements, I made a
change. In particular, I removed a corner case ("let without
binding"), thanks to more precise OCaml types for non-empty
lists.
- I ported all the changes to the AST above.
- region.ml (vendors)
- I changed the method `compact` so the end-line is not repeated
if it is the same as the start line: this is even more compact. I
use this in the new pretty-printer for the AST (see above)
- I updated all the CameLIGO contracts.
2019-11-04 23:51:47 +01:00
|
|
|
| [(PList (PCons c), cons); (PList (PListComp sugar_nil), nil)]
|
|
|
|
| [(PList (PListComp sugar_nil), nil); (PList (PCons c), cons)] ->
|
2019-05-23 07:49:06 +00:00
|
|
|
let%bind () =
|
2019-06-04 13:45:21 +02:00
|
|
|
trace_strong (unsupported_sugared_lists sugar_nil.region)
|
2019-05-23 07:49:06 +00:00
|
|
|
@@ Assert.assert_list_empty
|
|
|
|
@@ pseq_to_list
|
|
|
|
@@ sugar_nil.value.elements in
|
2019-05-14 15:57:25 +02:00
|
|
|
let%bind (a, b) =
|
Refactoring of Ligodity (CameLIGO) and making an AST pretty-printer
- AST.ml/AST.mli:
- The AST now distinguishes the constructors `None` and `Some` as being
predefined, as in PascaLIGO. See type `AST.constr_pattern`.
- I removed the nodes specific to Liquidity,
e.g. `let%entry`, and, in particular, the natural literals
ending with `p`. Now it should be `n`, as in `10n`.
- I renamed the node `TAlias` to `TVar`.
- I have applied the rule of expanding type expressions after `of` when
those were not records.
- The type of the argument to a data constructor is now
`type_expr`, instead of `cartesian`.
- I added the patterns for bytes (`PBytes`) and natural literals (`PNat`).
- I renamed the node `Sugar` into
`PListComp` (meaning "pattern of list comprehension").
- Record types in CameLIGO now must have at least one field declaration.
- Replaced the type `closing` and `opening` with one type `compound`,
which captures only the right combinations of opening and closing.
- Components of tuples in a selection must not be written
between parentheses. For example, `a.b.(1).(0)` is now
`a.b.1.0`, as in PascaLIGO.
- LexToken.mli/LexToken.mll
- I renamed the string literal `Str` into `String`.
- I added the tokens `C_None` and `C_Some` (to distinguish the
constructors `None` and `Some`. See AST.ml)
- Fixed the function `mk_sym` so it does not fail with `failwith`, but
with `Error Invalid_symbol`.
- Lexer.mll (shared)
- I removed the character `%` from the identifiers (used to
support Liquidity, like `entry%point` and `match%nat`).
- I adde to the hint on broken strings: "or insert a backslash"
(from a Gitlab issue).
- ParToken.mly
- I added the tokens `C_None` and `C_Some` (to distinguish the
constructors `None` and `Some`. See AST.ml and LexToken.mll)
- Parser.mly
- Fixed the order of declarations in the AST (it was reversed).
- I removed syntax support for Liquidity.
- I added user-defined constructor applications to irrefutable
patterns (the ones afer a `let`), even though only the type
checker can decide that they are truly irrefutable because they
are the only constructors of their types.
- I added natural numbers and bytes to patterns.
- Access of tuple components do not require parentheses now, like
`a.b.1.0`.
- I refactored the semantic actions.
- I added the empty sequence `begin end`.
- ParserLog.ml/ParserLog.mli
- I added a pretty-printer for the AST (with source locations).
- ParserMain.ml
- The CLI for the pretty-printer is now `--verbose=ast`.
- The old CLI `--verbose=ast` is now `--verbose=ast-tokens`.
- ligodity.ml (simplifier)
- I removed the constructions of sets, lists and maps with
`Set [...]`, `List [...]` and `Map [...]`, as there are already
better ways (that is, more like the OCaml's way), like
`Set.literal [...]` and `Map.literal [...]`. (The case for lists
was entirely redundant with the rest of the language as it is.)
- Everywhere there is now a non-empty list of elements, I made a
change. In particular, I removed a corner case ("let without
binding"), thanks to more precise OCaml types for non-empty
lists.
- I ported all the changes to the AST above.
- region.ml (vendors)
- I changed the method `compact` so the end-line is not repeated
if it is the same as the start line: this is even more compact. I
use this in the new pretty-printer for the AST (see above)
- I updated all the CameLIGO contracts.
2019-11-04 23:51:47 +01:00
|
|
|
let a, _, b = c.value in
|
2019-05-23 07:49:06 +00:00
|
|
|
let%bind a = get_var a in
|
|
|
|
let%bind b = get_var b in
|
Refactoring of Ligodity (CameLIGO) and making an AST pretty-printer
- AST.ml/AST.mli:
- The AST now distinguishes the constructors `None` and `Some` as being
predefined, as in PascaLIGO. See type `AST.constr_pattern`.
- I removed the nodes specific to Liquidity,
e.g. `let%entry`, and, in particular, the natural literals
ending with `p`. Now it should be `n`, as in `10n`.
- I renamed the node `TAlias` to `TVar`.
- I have applied the rule of expanding type expressions after `of` when
those were not records.
- The type of the argument to a data constructor is now
`type_expr`, instead of `cartesian`.
- I added the patterns for bytes (`PBytes`) and natural literals (`PNat`).
- I renamed the node `Sugar` into
`PListComp` (meaning "pattern of list comprehension").
- Record types in CameLIGO now must have at least one field declaration.
- Replaced the type `closing` and `opening` with one type `compound`,
which captures only the right combinations of opening and closing.
- Components of tuples in a selection must not be written
between parentheses. For example, `a.b.(1).(0)` is now
`a.b.1.0`, as in PascaLIGO.
- LexToken.mli/LexToken.mll
- I renamed the string literal `Str` into `String`.
- I added the tokens `C_None` and `C_Some` (to distinguish the
constructors `None` and `Some`. See AST.ml)
- Fixed the function `mk_sym` so it does not fail with `failwith`, but
with `Error Invalid_symbol`.
- Lexer.mll (shared)
- I removed the character `%` from the identifiers (used to
support Liquidity, like `entry%point` and `match%nat`).
- I adde to the hint on broken strings: "or insert a backslash"
(from a Gitlab issue).
- ParToken.mly
- I added the tokens `C_None` and `C_Some` (to distinguish the
constructors `None` and `Some`. See AST.ml and LexToken.mll)
- Parser.mly
- Fixed the order of declarations in the AST (it was reversed).
- I removed syntax support for Liquidity.
- I added user-defined constructor applications to irrefutable
patterns (the ones afer a `let`), even though only the type
checker can decide that they are truly irrefutable because they
are the only constructors of their types.
- I added natural numbers and bytes to patterns.
- Access of tuple components do not require parentheses now, like
`a.b.1.0`.
- I refactored the semantic actions.
- I added the empty sequence `begin end`.
- ParserLog.ml/ParserLog.mli
- I added a pretty-printer for the AST (with source locations).
- ParserMain.ml
- The CLI for the pretty-printer is now `--verbose=ast`.
- The old CLI `--verbose=ast` is now `--verbose=ast-tokens`.
- ligodity.ml (simplifier)
- I removed the constructions of sets, lists and maps with
`Set [...]`, `List [...]` and `Map [...]`, as there are already
better ways (that is, more like the OCaml's way), like
`Set.literal [...]` and `Map.literal [...]`. (The case for lists
was entirely redundant with the rest of the language as it is.)
- Everywhere there is now a non-empty list of elements, I made a
change. In particular, I removed a corner case ("let without
binding"), thanks to more precise OCaml types for non-empty
lists.
- I ported all the changes to the AST above.
- region.ml (vendors)
- I changed the method `compact` so the end-line is not repeated
if it is the same as the start line: this is even more compact. I
use this in the new pretty-printer for the AST (see above)
- I updated all the CameLIGO contracts.
2019-11-04 23:51:47 +01:00
|
|
|
ok (a, b) in
|
2019-12-04 11:40:58 +00:00
|
|
|
ok @@ Match_list {match_cons=(Var.of_name a, Var.of_name b, cons, ()); match_nil=nil}
|
Refactoring of Ligodity (CameLIGO) and making an AST pretty-printer
- AST.ml/AST.mli:
- The AST now distinguishes the constructors `None` and `Some` as being
predefined, as in PascaLIGO. See type `AST.constr_pattern`.
- I removed the nodes specific to Liquidity,
e.g. `let%entry`, and, in particular, the natural literals
ending with `p`. Now it should be `n`, as in `10n`.
- I renamed the node `TAlias` to `TVar`.
- I have applied the rule of expanding type expressions after `of` when
those were not records.
- The type of the argument to a data constructor is now
`type_expr`, instead of `cartesian`.
- I added the patterns for bytes (`PBytes`) and natural literals (`PNat`).
- I renamed the node `Sugar` into
`PListComp` (meaning "pattern of list comprehension").
- Record types in CameLIGO now must have at least one field declaration.
- Replaced the type `closing` and `opening` with one type `compound`,
which captures only the right combinations of opening and closing.
- Components of tuples in a selection must not be written
between parentheses. For example, `a.b.(1).(0)` is now
`a.b.1.0`, as in PascaLIGO.
- LexToken.mli/LexToken.mll
- I renamed the string literal `Str` into `String`.
- I added the tokens `C_None` and `C_Some` (to distinguish the
constructors `None` and `Some`. See AST.ml)
- Fixed the function `mk_sym` so it does not fail with `failwith`, but
with `Error Invalid_symbol`.
- Lexer.mll (shared)
- I removed the character `%` from the identifiers (used to
support Liquidity, like `entry%point` and `match%nat`).
- I adde to the hint on broken strings: "or insert a backslash"
(from a Gitlab issue).
- ParToken.mly
- I added the tokens `C_None` and `C_Some` (to distinguish the
constructors `None` and `Some`. See AST.ml and LexToken.mll)
- Parser.mly
- Fixed the order of declarations in the AST (it was reversed).
- I removed syntax support for Liquidity.
- I added user-defined constructor applications to irrefutable
patterns (the ones afer a `let`), even though only the type
checker can decide that they are truly irrefutable because they
are the only constructors of their types.
- I added natural numbers and bytes to patterns.
- Access of tuple components do not require parentheses now, like
`a.b.1.0`.
- I refactored the semantic actions.
- I added the empty sequence `begin end`.
- ParserLog.ml/ParserLog.mli
- I added a pretty-printer for the AST (with source locations).
- ParserMain.ml
- The CLI for the pretty-printer is now `--verbose=ast`.
- The old CLI `--verbose=ast` is now `--verbose=ast-tokens`.
- ligodity.ml (simplifier)
- I removed the constructions of sets, lists and maps with
`Set [...]`, `List [...]` and `Map [...]`, as there are already
better ways (that is, more like the OCaml's way), like
`Set.literal [...]` and `Map.literal [...]`. (The case for lists
was entirely redundant with the rest of the language as it is.)
- Everywhere there is now a non-empty list of elements, I made a
change. In particular, I removed a corner case ("let without
binding"), thanks to more precise OCaml types for non-empty
lists.
- I ported all the changes to the AST above.
- region.ml (vendors)
- I changed the method `compact` so the end-line is not repeated
if it is the same as the start line: this is even more compact. I
use this in the new pretty-printer for the AST (see above)
- I updated all the CameLIGO contracts.
2019-11-04 23:51:47 +01:00
|
|
|
| lst ->
|
2019-09-20 20:38:04 +02:00
|
|
|
let error x =
|
|
|
|
let title () = "Pattern" in
|
Refactoring of comments (for [dune build @doc]).
Refactoring of parsing command-line arguments
* The type [options] is now abstract and implemented as an
object type to avoid struggling with scoping and type
inference when record types share some common field names.
Refactoring of ParserLog for PascaLIGO and CameLIGO
* The immediate motivation behind that refactoring was to
remove the use of a couple of global references. A
consequence is that we have a nicer and more compact code, by
threading a state. The files [pascaligo/Tests/pp.ligo] and
[ligodity/Tests/pp.mligo].
* Another consequence is that the choice of making strings from
AST nodes depends on the CLI (offsets? mode?). After this
refactoring, that choice is hardcoded in the simplifiers in a
few places (TODO), waiting for a general solution that would
have all CL options flow through the compiler.
* I removed the use of vendors [x_option.ml], [x_map.ml] and
[x_list.ml] when handling optional values. (Less dependencies
this way.)
Refactoring of the ASTs
* I removed the node [local_decl], which was set to [[]]
already in a previous commit (which removed local
declarations as being redundant, as statements could already
be instructions or declarations).
* I changed [StrLit] to [String] in the AST of CameLIGO and
ReasonLIGO.
* I also changed the type [fun_expr] so now either a block is
present, and therefore followed by the [with] keyword, or it
is not. (Before, the presence of a block was not enforced in
the type with the presence of the keyword.)
Notes
* [LexerMain.ml] and [ParserMain.ml] for CameLIGO and PascaLIGO
are almost identical and differ in the same way (language
name and file extension), which suggests that they should be
in the [shared] folder and instanciated as a functor in the
future (TODO).
* I removed the blank characters at the end of many lines in
the parser of ReasonLIGO.
2019-12-13 12:21:52 +01:00
|
|
|
(** TODO: The labelled arguments should be flowing from the CLI. *)
|
2019-09-20 20:38:04 +02:00
|
|
|
let content () =
|
2019-10-09 16:07:13 +02:00
|
|
|
Printf.sprintf "Pattern : %s"
|
2020-04-12 15:26:47 +02:00
|
|
|
(Parser_cameligo.ParserLog.pattern_to_string
|
Refactoring of comments (for [dune build @doc]).
Refactoring of parsing command-line arguments
* The type [options] is now abstract and implemented as an
object type to avoid struggling with scoping and type
inference when record types share some common field names.
Refactoring of ParserLog for PascaLIGO and CameLIGO
* The immediate motivation behind that refactoring was to
remove the use of a couple of global references. A
consequence is that we have a nicer and more compact code, by
threading a state. The files [pascaligo/Tests/pp.ligo] and
[ligodity/Tests/pp.mligo].
* Another consequence is that the choice of making strings from
AST nodes depends on the CLI (offsets? mode?). After this
refactoring, that choice is hardcoded in the simplifiers in a
few places (TODO), waiting for a general solution that would
have all CL options flow through the compiler.
* I removed the use of vendors [x_option.ml], [x_map.ml] and
[x_list.ml] when handling optional values. (Less dependencies
this way.)
Refactoring of the ASTs
* I removed the node [local_decl], which was set to [[]]
already in a previous commit (which removed local
declarations as being redundant, as statements could already
be instructions or declarations).
* I changed [StrLit] to [String] in the AST of CameLIGO and
ReasonLIGO.
* I also changed the type [fun_expr] so now either a block is
present, and therefore followed by the [with] keyword, or it
is not. (Before, the presence of a block was not enforced in
the type with the presence of the keyword.)
Notes
* [LexerMain.ml] and [ParserMain.ml] for CameLIGO and PascaLIGO
are almost identical and differ in the same way (language
name and file extension), which suggests that they should be
in the [shared] folder and instanciated as a functor in the
future (TODO).
* I removed the blank characters at the end of many lines in
the parser of ReasonLIGO.
2019-12-13 12:21:52 +01:00
|
|
|
~offsets:true ~mode:`Point x) in
|
2019-09-20 20:38:04 +02:00
|
|
|
error title content
|
|
|
|
in
|
|
|
|
let as_variant () =
|
|
|
|
trace (simple_info "currently, only booleans, lists, options, and constructors \
|
|
|
|
are supported in patterns") @@
|
|
|
|
let%bind constrs =
|
Refactoring of Ligodity (CameLIGO) and making an AST pretty-printer
- AST.ml/AST.mli:
- The AST now distinguishes the constructors `None` and `Some` as being
predefined, as in PascaLIGO. See type `AST.constr_pattern`.
- I removed the nodes specific to Liquidity,
e.g. `let%entry`, and, in particular, the natural literals
ending with `p`. Now it should be `n`, as in `10n`.
- I renamed the node `TAlias` to `TVar`.
- I have applied the rule of expanding type expressions after `of` when
those were not records.
- The type of the argument to a data constructor is now
`type_expr`, instead of `cartesian`.
- I added the patterns for bytes (`PBytes`) and natural literals (`PNat`).
- I renamed the node `Sugar` into
`PListComp` (meaning "pattern of list comprehension").
- Record types in CameLIGO now must have at least one field declaration.
- Replaced the type `closing` and `opening` with one type `compound`,
which captures only the right combinations of opening and closing.
- Components of tuples in a selection must not be written
between parentheses. For example, `a.b.(1).(0)` is now
`a.b.1.0`, as in PascaLIGO.
- LexToken.mli/LexToken.mll
- I renamed the string literal `Str` into `String`.
- I added the tokens `C_None` and `C_Some` (to distinguish the
constructors `None` and `Some`. See AST.ml)
- Fixed the function `mk_sym` so it does not fail with `failwith`, but
with `Error Invalid_symbol`.
- Lexer.mll (shared)
- I removed the character `%` from the identifiers (used to
support Liquidity, like `entry%point` and `match%nat`).
- I adde to the hint on broken strings: "or insert a backslash"
(from a Gitlab issue).
- ParToken.mly
- I added the tokens `C_None` and `C_Some` (to distinguish the
constructors `None` and `Some`. See AST.ml and LexToken.mll)
- Parser.mly
- Fixed the order of declarations in the AST (it was reversed).
- I removed syntax support for Liquidity.
- I added user-defined constructor applications to irrefutable
patterns (the ones afer a `let`), even though only the type
checker can decide that they are truly irrefutable because they
are the only constructors of their types.
- I added natural numbers and bytes to patterns.
- Access of tuple components do not require parentheses now, like
`a.b.1.0`.
- I refactored the semantic actions.
- I added the empty sequence `begin end`.
- ParserLog.ml/ParserLog.mli
- I added a pretty-printer for the AST (with source locations).
- ParserMain.ml
- The CLI for the pretty-printer is now `--verbose=ast`.
- The old CLI `--verbose=ast` is now `--verbose=ast-tokens`.
- ligodity.ml (simplifier)
- I removed the constructions of sets, lists and maps with
`Set [...]`, `List [...]` and `Map [...]`, as there are already
better ways (that is, more like the OCaml's way), like
`Set.literal [...]` and `Map.literal [...]`. (The case for lists
was entirely redundant with the rest of the language as it is.)
- Everywhere there is now a non-empty list of elements, I made a
change. In particular, I removed a corner case ("let without
binding"), thanks to more precise OCaml types for non-empty
lists.
- I ported all the changes to the AST above.
- region.ml (vendors)
- I changed the method `compact` so the end-line is not repeated
if it is the same as the start line: this is even more compact. I
use this in the new pretty-printer for the AST (see above)
- I updated all the CameLIGO contracts.
2019-11-04 23:51:47 +01:00
|
|
|
let aux (x, y) =
|
|
|
|
let%bind x' = trace (error x) @@ get_constr x
|
|
|
|
in ok (x', y)
|
|
|
|
in bind_map_list aux lst
|
2019-12-04 11:40:58 +00:00
|
|
|
in ok @@ ez_match_variant constrs in
|
2019-09-20 20:38:04 +02:00
|
|
|
let as_option () =
|
Refactoring of Ligodity (CameLIGO) and making an AST pretty-printer
- AST.ml/AST.mli:
- The AST now distinguishes the constructors `None` and `Some` as being
predefined, as in PascaLIGO. See type `AST.constr_pattern`.
- I removed the nodes specific to Liquidity,
e.g. `let%entry`, and, in particular, the natural literals
ending with `p`. Now it should be `n`, as in `10n`.
- I renamed the node `TAlias` to `TVar`.
- I have applied the rule of expanding type expressions after `of` when
those were not records.
- The type of the argument to a data constructor is now
`type_expr`, instead of `cartesian`.
- I added the patterns for bytes (`PBytes`) and natural literals (`PNat`).
- I renamed the node `Sugar` into
`PListComp` (meaning "pattern of list comprehension").
- Record types in CameLIGO now must have at least one field declaration.
- Replaced the type `closing` and `opening` with one type `compound`,
which captures only the right combinations of opening and closing.
- Components of tuples in a selection must not be written
between parentheses. For example, `a.b.(1).(0)` is now
`a.b.1.0`, as in PascaLIGO.
- LexToken.mli/LexToken.mll
- I renamed the string literal `Str` into `String`.
- I added the tokens `C_None` and `C_Some` (to distinguish the
constructors `None` and `Some`. See AST.ml)
- Fixed the function `mk_sym` so it does not fail with `failwith`, but
with `Error Invalid_symbol`.
- Lexer.mll (shared)
- I removed the character `%` from the identifiers (used to
support Liquidity, like `entry%point` and `match%nat`).
- I adde to the hint on broken strings: "or insert a backslash"
(from a Gitlab issue).
- ParToken.mly
- I added the tokens `C_None` and `C_Some` (to distinguish the
constructors `None` and `Some`. See AST.ml and LexToken.mll)
- Parser.mly
- Fixed the order of declarations in the AST (it was reversed).
- I removed syntax support for Liquidity.
- I added user-defined constructor applications to irrefutable
patterns (the ones afer a `let`), even though only the type
checker can decide that they are truly irrefutable because they
are the only constructors of their types.
- I added natural numbers and bytes to patterns.
- Access of tuple components do not require parentheses now, like
`a.b.1.0`.
- I refactored the semantic actions.
- I added the empty sequence `begin end`.
- ParserLog.ml/ParserLog.mli
- I added a pretty-printer for the AST (with source locations).
- ParserMain.ml
- The CLI for the pretty-printer is now `--verbose=ast`.
- The old CLI `--verbose=ast` is now `--verbose=ast-tokens`.
- ligodity.ml (simplifier)
- I removed the constructions of sets, lists and maps with
`Set [...]`, `List [...]` and `Map [...]`, as there are already
better ways (that is, more like the OCaml's way), like
`Set.literal [...]` and `Map.literal [...]`. (The case for lists
was entirely redundant with the rest of the language as it is.)
- Everywhere there is now a non-empty list of elements, I made a
change. In particular, I removed a corner case ("let without
binding"), thanks to more precise OCaml types for non-empty
lists.
- I ported all the changes to the AST above.
- region.ml (vendors)
- I changed the method `compact` so the end-line is not repeated
if it is the same as the start line: this is even more compact. I
use this in the new pretty-printer for the AST (see above)
- I updated all the CameLIGO contracts.
2019-11-04 23:51:47 +01:00
|
|
|
let aux (x, y) =
|
|
|
|
let%bind x' = trace (error x) @@ get_constr_opt x
|
|
|
|
in ok (x', y) in
|
2019-09-20 20:38:04 +02:00
|
|
|
let%bind constrs = bind_map_list aux lst in
|
|
|
|
match constrs with
|
Refactoring of Ligodity (CameLIGO) and making an AST pretty-printer
- AST.ml/AST.mli:
- The AST now distinguishes the constructors `None` and `Some` as being
predefined, as in PascaLIGO. See type `AST.constr_pattern`.
- I removed the nodes specific to Liquidity,
e.g. `let%entry`, and, in particular, the natural literals
ending with `p`. Now it should be `n`, as in `10n`.
- I renamed the node `TAlias` to `TVar`.
- I have applied the rule of expanding type expressions after `of` when
those were not records.
- The type of the argument to a data constructor is now
`type_expr`, instead of `cartesian`.
- I added the patterns for bytes (`PBytes`) and natural literals (`PNat`).
- I renamed the node `Sugar` into
`PListComp` (meaning "pattern of list comprehension").
- Record types in CameLIGO now must have at least one field declaration.
- Replaced the type `closing` and `opening` with one type `compound`,
which captures only the right combinations of opening and closing.
- Components of tuples in a selection must not be written
between parentheses. For example, `a.b.(1).(0)` is now
`a.b.1.0`, as in PascaLIGO.
- LexToken.mli/LexToken.mll
- I renamed the string literal `Str` into `String`.
- I added the tokens `C_None` and `C_Some` (to distinguish the
constructors `None` and `Some`. See AST.ml)
- Fixed the function `mk_sym` so it does not fail with `failwith`, but
with `Error Invalid_symbol`.
- Lexer.mll (shared)
- I removed the character `%` from the identifiers (used to
support Liquidity, like `entry%point` and `match%nat`).
- I adde to the hint on broken strings: "or insert a backslash"
(from a Gitlab issue).
- ParToken.mly
- I added the tokens `C_None` and `C_Some` (to distinguish the
constructors `None` and `Some`. See AST.ml and LexToken.mll)
- Parser.mly
- Fixed the order of declarations in the AST (it was reversed).
- I removed syntax support for Liquidity.
- I added user-defined constructor applications to irrefutable
patterns (the ones afer a `let`), even though only the type
checker can decide that they are truly irrefutable because they
are the only constructors of their types.
- I added natural numbers and bytes to patterns.
- Access of tuple components do not require parentheses now, like
`a.b.1.0`.
- I refactored the semantic actions.
- I added the empty sequence `begin end`.
- ParserLog.ml/ParserLog.mli
- I added a pretty-printer for the AST (with source locations).
- ParserMain.ml
- The CLI for the pretty-printer is now `--verbose=ast`.
- The old CLI `--verbose=ast` is now `--verbose=ast-tokens`.
- ligodity.ml (simplifier)
- I removed the constructions of sets, lists and maps with
`Set [...]`, `List [...]` and `Map [...]`, as there are already
better ways (that is, more like the OCaml's way), like
`Set.literal [...]` and `Map.literal [...]`. (The case for lists
was entirely redundant with the rest of the language as it is.)
- Everywhere there is now a non-empty list of elements, I made a
change. In particular, I removed a corner case ("let without
binding"), thanks to more precise OCaml types for non-empty
lists.
- I ported all the changes to the AST above.
- region.ml (vendors)
- I changed the method `compact` so the end-line is not repeated
if it is the same as the start line: this is even more compact. I
use this in the new pretty-printer for the AST (see above)
- I updated all the CameLIGO contracts.
2019-11-04 23:51:47 +01:00
|
|
|
| [ (("Some", Some some_var), some_expr);
|
|
|
|
(("None" , None) , none_expr) ]
|
|
|
|
| [ (("None", None), none_expr);
|
|
|
|
(("Some", Some some_var), some_expr) ] ->
|
|
|
|
ok @@ Match_option {
|
2019-12-04 11:40:58 +00:00
|
|
|
match_some = (Var.of_name some_var, some_expr, ());
|
Refactoring of Ligodity (CameLIGO) and making an AST pretty-printer
- AST.ml/AST.mli:
- The AST now distinguishes the constructors `None` and `Some` as being
predefined, as in PascaLIGO. See type `AST.constr_pattern`.
- I removed the nodes specific to Liquidity,
e.g. `let%entry`, and, in particular, the natural literals
ending with `p`. Now it should be `n`, as in `10n`.
- I renamed the node `TAlias` to `TVar`.
- I have applied the rule of expanding type expressions after `of` when
those were not records.
- The type of the argument to a data constructor is now
`type_expr`, instead of `cartesian`.
- I added the patterns for bytes (`PBytes`) and natural literals (`PNat`).
- I renamed the node `Sugar` into
`PListComp` (meaning "pattern of list comprehension").
- Record types in CameLIGO now must have at least one field declaration.
- Replaced the type `closing` and `opening` with one type `compound`,
which captures only the right combinations of opening and closing.
- Components of tuples in a selection must not be written
between parentheses. For example, `a.b.(1).(0)` is now
`a.b.1.0`, as in PascaLIGO.
- LexToken.mli/LexToken.mll
- I renamed the string literal `Str` into `String`.
- I added the tokens `C_None` and `C_Some` (to distinguish the
constructors `None` and `Some`. See AST.ml)
- Fixed the function `mk_sym` so it does not fail with `failwith`, but
with `Error Invalid_symbol`.
- Lexer.mll (shared)
- I removed the character `%` from the identifiers (used to
support Liquidity, like `entry%point` and `match%nat`).
- I adde to the hint on broken strings: "or insert a backslash"
(from a Gitlab issue).
- ParToken.mly
- I added the tokens `C_None` and `C_Some` (to distinguish the
constructors `None` and `Some`. See AST.ml and LexToken.mll)
- Parser.mly
- Fixed the order of declarations in the AST (it was reversed).
- I removed syntax support for Liquidity.
- I added user-defined constructor applications to irrefutable
patterns (the ones afer a `let`), even though only the type
checker can decide that they are truly irrefutable because they
are the only constructors of their types.
- I added natural numbers and bytes to patterns.
- Access of tuple components do not require parentheses now, like
`a.b.1.0`.
- I refactored the semantic actions.
- I added the empty sequence `begin end`.
- ParserLog.ml/ParserLog.mli
- I added a pretty-printer for the AST (with source locations).
- ParserMain.ml
- The CLI for the pretty-printer is now `--verbose=ast`.
- The old CLI `--verbose=ast` is now `--verbose=ast-tokens`.
- ligodity.ml (simplifier)
- I removed the constructions of sets, lists and maps with
`Set [...]`, `List [...]` and `Map [...]`, as there are already
better ways (that is, more like the OCaml's way), like
`Set.literal [...]` and `Map.literal [...]`. (The case for lists
was entirely redundant with the rest of the language as it is.)
- Everywhere there is now a non-empty list of elements, I made a
change. In particular, I removed a corner case ("let without
binding"), thanks to more precise OCaml types for non-empty
lists.
- I ported all the changes to the AST above.
- region.ml (vendors)
- I changed the method `compact` so the end-line is not repeated
if it is the same as the start line: this is even more compact. I
use this in the new pretty-printer for the AST (see above)
- I updated all the CameLIGO contracts.
2019-11-04 23:51:47 +01:00
|
|
|
match_none = none_expr }
|
2019-09-20 20:38:04 +02:00
|
|
|
| _ -> simple_fail "bad option pattern"
|
Refactoring of Ligodity (CameLIGO) and making an AST pretty-printer
- AST.ml/AST.mli:
- The AST now distinguishes the constructors `None` and `Some` as being
predefined, as in PascaLIGO. See type `AST.constr_pattern`.
- I removed the nodes specific to Liquidity,
e.g. `let%entry`, and, in particular, the natural literals
ending with `p`. Now it should be `n`, as in `10n`.
- I renamed the node `TAlias` to `TVar`.
- I have applied the rule of expanding type expressions after `of` when
those were not records.
- The type of the argument to a data constructor is now
`type_expr`, instead of `cartesian`.
- I added the patterns for bytes (`PBytes`) and natural literals (`PNat`).
- I renamed the node `Sugar` into
`PListComp` (meaning "pattern of list comprehension").
- Record types in CameLIGO now must have at least one field declaration.
- Replaced the type `closing` and `opening` with one type `compound`,
which captures only the right combinations of opening and closing.
- Components of tuples in a selection must not be written
between parentheses. For example, `a.b.(1).(0)` is now
`a.b.1.0`, as in PascaLIGO.
- LexToken.mli/LexToken.mll
- I renamed the string literal `Str` into `String`.
- I added the tokens `C_None` and `C_Some` (to distinguish the
constructors `None` and `Some`. See AST.ml)
- Fixed the function `mk_sym` so it does not fail with `failwith`, but
with `Error Invalid_symbol`.
- Lexer.mll (shared)
- I removed the character `%` from the identifiers (used to
support Liquidity, like `entry%point` and `match%nat`).
- I adde to the hint on broken strings: "or insert a backslash"
(from a Gitlab issue).
- ParToken.mly
- I added the tokens `C_None` and `C_Some` (to distinguish the
constructors `None` and `Some`. See AST.ml and LexToken.mll)
- Parser.mly
- Fixed the order of declarations in the AST (it was reversed).
- I removed syntax support for Liquidity.
- I added user-defined constructor applications to irrefutable
patterns (the ones afer a `let`), even though only the type
checker can decide that they are truly irrefutable because they
are the only constructors of their types.
- I added natural numbers and bytes to patterns.
- Access of tuple components do not require parentheses now, like
`a.b.1.0`.
- I refactored the semantic actions.
- I added the empty sequence `begin end`.
- ParserLog.ml/ParserLog.mli
- I added a pretty-printer for the AST (with source locations).
- ParserMain.ml
- The CLI for the pretty-printer is now `--verbose=ast`.
- The old CLI `--verbose=ast` is now `--verbose=ast-tokens`.
- ligodity.ml (simplifier)
- I removed the constructions of sets, lists and maps with
`Set [...]`, `List [...]` and `Map [...]`, as there are already
better ways (that is, more like the OCaml's way), like
`Set.literal [...]` and `Map.literal [...]`. (The case for lists
was entirely redundant with the rest of the language as it is.)
- Everywhere there is now a non-empty list of elements, I made a
change. In particular, I removed a corner case ("let without
binding"), thanks to more precise OCaml types for non-empty
lists.
- I ported all the changes to the AST above.
- region.ml (vendors)
- I changed the method `compact` so the end-line is not repeated
if it is the same as the start line: this is even more compact. I
use this in the new pretty-printer for the AST (see above)
- I updated all the CameLIGO contracts.
2019-11-04 23:51:47 +01:00
|
|
|
in bind_or (as_option () , as_variant ())
|
2019-05-14 15:57:25 +02:00
|
|
|
|
2020-03-16 14:53:56 +01:00
|
|
|
let compile_program : Raw.ast -> program result = fun t ->
|
|
|
|
let%bind decls = bind_map_list compile_declaration @@ nseq_to_list t.decl in
|
2019-11-19 21:13:52 +00:00
|
|
|
ok @@ List.concat @@ decls
|