I extended the right-hand side of assignments to accept "None"

without type annotation.

This is meant to enable specify the removal of a map binding.

Note: The index assignments in loops are not concerned.
This commit is contained in:
Christian Rinderknecht 2019-03-20 16:16:30 +01:00
parent 24c0a33c99
commit 495686bbd4
No known key found for this signature in database
GPG Key ID: 9446816CFD267040
4 changed files with 30 additions and 9 deletions

18
AST.ml
View File

@ -390,13 +390,17 @@ and case = {
and assignment = {
lhs : lhs;
assign : assign;
expr : expr
rhs : rhs
}
and lhs =
Path of path
| MapPath of map_lookup reg
and rhs =
Expr of expr
| NoneExpr of c_None
and loop =
While of while_loop reg
| For of for_loop
@ -727,6 +731,10 @@ let lhs_to_region = function
Path path -> path_to_region path
| MapPath {region; _} -> region
let rhs_to_region = function
Expr e -> expr_to_region e
| NoneExpr r -> r
(* Printing the tokens with their source regions *)
let printf = Printf.printf
@ -1028,10 +1036,14 @@ and print_case {value; _} =
print_instruction instr
and print_assignment {value; _} =
let {lhs; assign; expr} = value in
let {lhs; assign; rhs} = value in
print_lhs lhs;
print_token assign ":=";
print_expr expr
print_rhs rhs
and print_rhs = function
Expr e -> print_expr e
| NoneExpr r -> print_token r "None"
and print_lhs = function
Path path -> print_path path

View File

@ -374,13 +374,17 @@ and case = {
and assignment = {
lhs : lhs;
assign : assign;
expr : expr
rhs : rhs;
}
and lhs =
Path of path
| MapPath of map_lookup reg
and rhs =
Expr of expr
| NoneExpr of c_None
and loop =
While of while_loop reg
| For of for_loop
@ -593,6 +597,7 @@ val pattern_to_region : pattern -> Region.t
val local_decl_to_region : local_decl -> Region.t
val path_to_region : path -> Region.t
val lhs_to_region : lhs -> Region.t
val rhs_to_region : rhs -> Region.t
(* Printing *)

View File

@ -543,12 +543,17 @@ case:
}
assignment:
lhs ASS expr {
let region = cover (lhs_to_region $1) (expr_to_region $3)
and value = {lhs = $1; assign = $2; expr = $3}
lhs ASS rhs {
let stop = rhs_to_region $3 in
let region = cover (lhs_to_region $1) stop
and value = {lhs = $1; assign = $2; rhs = $3}
in {region; value}
}
rhs:
expr { Expr $1 }
| C_None { NoneExpr $1 : rhs }
lhs:
path { Path $1 }
| map_lookup { MapPath $1 }
@ -580,7 +585,6 @@ for_loop:
block = $7}
in For (ForInt {region; value})
}
| For var option(arrow_clause) In expr block {
let region = cover $1 $6.region in
let value = {

View File

@ -58,7 +58,7 @@ entrypoint claim (storage store : store; const sender : address)
else
begin
operations := [Transfer (sender, amount)];
store.backers[sender] := (None : option (nat))
store.backers[sender] := None
end
end
end with (store, operations)