2019-06-10 09:58:16 +00:00
|
|
|
type storage = {
|
|
|
|
title : string ;
|
|
|
|
candidates : (string , int) map ;
|
|
|
|
voters : address set ;
|
|
|
|
beginning_time : timestamp ;
|
|
|
|
finish_time : timestamp ;
|
|
|
|
}
|
|
|
|
|
2019-06-10 22:06:00 +00:00
|
|
|
type init_action = {
|
|
|
|
title : string ;
|
|
|
|
beginning_time : timestamp ;
|
|
|
|
finish_time : timestamp ;
|
|
|
|
}
|
2019-06-10 09:58:16 +00:00
|
|
|
|
|
|
|
type action =
|
|
|
|
| Vote of string
|
2019-06-10 22:06:00 +00:00
|
|
|
| Init of init_action
|
2019-06-10 09:58:16 +00:00
|
|
|
|
2020-01-08 20:58:26 +00:00
|
|
|
let init (init_params_s : init_action * storage) =
|
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 candidates = Map.literal [
|
2019-06-10 09:58:16 +00:00
|
|
|
("Yes" , 0) ;
|
|
|
|
("No" , 0)
|
|
|
|
] in
|
|
|
|
(
|
|
|
|
([] : operation list),
|
|
|
|
{
|
2020-01-08 20:58:26 +00:00
|
|
|
title = init_params_s.0.title ;
|
2019-06-10 09:58:16 +00:00
|
|
|
candidates = candidates ;
|
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
|
|
|
voters = (Set.empty : address set) ;
|
2020-01-08 20:58:26 +00:00
|
|
|
beginning_time = init_params_s.0.beginning_time ;
|
|
|
|
finish_time = init_params_s.0.finish_time ;
|
2019-06-10 09:58:16 +00:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2020-01-08 20:58:26 +00:00
|
|
|
let vote (ps : string * storage) =
|
2019-06-10 22:06:00 +00:00
|
|
|
let now = Current.time in
|
2020-01-08 20:58:26 +00:00
|
|
|
(* let _ = assert (now >= ps.1.beginning_time && ps.1.finish_time > now) in *)
|
2020-01-21 02:24:16 -06:00
|
|
|
let addr = Current.sender in
|
2020-01-08 20:58:26 +00:00
|
|
|
(* let _ = assert (not Set.mem addr ps.1.voters) in *)
|
|
|
|
let x = Map.find ps.0 ps.1.candidates in
|
2019-06-10 09:58:16 +00:00
|
|
|
(
|
|
|
|
([] : operation list),
|
|
|
|
{
|
2020-01-08 20:58:26 +00:00
|
|
|
title = ps.1.title ;
|
|
|
|
candidates = Map.update ps.0 (Some (x + 1)) ps.1.candidates ;
|
|
|
|
voters = Set.add addr ps.1.voters ;
|
|
|
|
beginning_time = ps.1.beginning_time ;
|
|
|
|
finish_time = ps.1.finish_time ;
|
2019-06-10 09:58:16 +00:00
|
|
|
}
|
|
|
|
)
|
2019-06-10 22:06:00 +00:00
|
|
|
|
2020-01-08 20:58:26 +00:00
|
|
|
let main (a_s : action * storage) =
|
|
|
|
match a_s.0 with
|
|
|
|
| Vote p -> vote (p, a_s.1)
|
|
|
|
| Init ps -> init (ps, a_s.1)
|
|
|
|
|