Added qualified names to patches ("patch x.y.z with ...").
Fixed grammar for map patches (should start with "patch", not "map").
This commit is contained in:
parent
60c23850bd
commit
563bc59285
38
AST.ml
38
AST.ml
@ -331,9 +331,9 @@ and single_instr =
|
|||||||
|
|
||||||
and map_patch = {
|
and map_patch = {
|
||||||
kwd_patch : kwd_patch;
|
kwd_patch : kwd_patch;
|
||||||
map_name : variable;
|
path : path;
|
||||||
kwd_with : kwd_with;
|
kwd_with : kwd_with;
|
||||||
delta : map_injection reg
|
map_inj : map_injection reg
|
||||||
}
|
}
|
||||||
|
|
||||||
and map_injection = {
|
and map_injection = {
|
||||||
@ -350,10 +350,10 @@ and binding = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
and record_patch = {
|
and record_patch = {
|
||||||
kwd_patch : kwd_patch;
|
kwd_patch : kwd_patch;
|
||||||
record_name : variable;
|
path : path;
|
||||||
kwd_with : kwd_with;
|
kwd_with : kwd_with;
|
||||||
delta : record_injection reg
|
record_inj : record_injection reg
|
||||||
}
|
}
|
||||||
|
|
||||||
and fail_instr = {
|
and fail_instr = {
|
||||||
@ -625,11 +625,11 @@ and logic_expr_to_region = function
|
|||||||
| CompExpr e -> comp_expr_to_region e
|
| CompExpr e -> comp_expr_to_region e
|
||||||
|
|
||||||
and bool_expr_to_region = function
|
and bool_expr_to_region = function
|
||||||
Or {region; _}
|
Or {region; _}
|
||||||
| And {region; _}
|
| And {region; _}
|
||||||
| Not {region; _}
|
| Not {region; _}
|
||||||
| False region
|
| False region
|
||||||
| True region -> region
|
| True region -> region
|
||||||
|
|
||||||
and comp_expr_to_region = function
|
and comp_expr_to_region = function
|
||||||
Lt {region; _}
|
Lt {region; _}
|
||||||
@ -670,6 +670,10 @@ and record_expr_to_region = function
|
|||||||
RecordInj {region; _}
|
RecordInj {region; _}
|
||||||
| RecordProj {region; _} -> region
|
| RecordProj {region; _} -> region
|
||||||
|
|
||||||
|
let path_to_region = function
|
||||||
|
Name var -> var.region
|
||||||
|
| RecordPath {region; _} -> region
|
||||||
|
|
||||||
let instr_to_region = function
|
let instr_to_region = function
|
||||||
Single Cond {region; _}
|
Single Cond {region; _}
|
||||||
| Single Case {region; _}
|
| Single Case {region; _}
|
||||||
@ -1182,18 +1186,18 @@ and print_field_path sequence =
|
|||||||
print_nsepseq "." print_var sequence
|
print_nsepseq "." print_var sequence
|
||||||
|
|
||||||
and print_record_patch node =
|
and print_record_patch node =
|
||||||
let {kwd_patch; record_name; kwd_with; delta} = node in
|
let {kwd_patch; path; kwd_with; record_inj} = node in
|
||||||
print_token kwd_patch "patch";
|
print_token kwd_patch "patch";
|
||||||
print_var record_name;
|
print_path path;
|
||||||
print_token kwd_with "with";
|
print_token kwd_with "with";
|
||||||
print_record_injection delta
|
print_record_injection record_inj
|
||||||
|
|
||||||
and print_map_patch node =
|
and print_map_patch node =
|
||||||
let {kwd_patch; map_name; kwd_with; delta} = node in
|
let {kwd_patch; path; kwd_with; map_inj} = node in
|
||||||
print_token kwd_patch "patch";
|
print_token kwd_patch "patch";
|
||||||
print_var map_name;
|
print_path path;
|
||||||
print_token kwd_with "with";
|
print_token kwd_with "with";
|
||||||
print_map_injection delta
|
print_map_injection map_inj
|
||||||
|
|
||||||
and print_map_injection {value; _} =
|
and print_map_injection {value; _} =
|
||||||
let {opening; bindings; terminator; close} = value in
|
let {opening; bindings; terminator; close} = value in
|
||||||
|
25
AST.mli
25
AST.mli
@ -315,9 +315,9 @@ and single_instr =
|
|||||||
|
|
||||||
and map_patch = {
|
and map_patch = {
|
||||||
kwd_patch : kwd_patch;
|
kwd_patch : kwd_patch;
|
||||||
map_name : variable;
|
path : path;
|
||||||
kwd_with : kwd_with;
|
kwd_with : kwd_with;
|
||||||
delta : map_injection reg
|
map_inj : map_injection reg
|
||||||
}
|
}
|
||||||
|
|
||||||
and map_injection = {
|
and map_injection = {
|
||||||
@ -334,10 +334,10 @@ and binding = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
and record_patch = {
|
and record_patch = {
|
||||||
kwd_patch : kwd_patch;
|
kwd_patch : kwd_patch;
|
||||||
record_name : variable;
|
path : path;
|
||||||
kwd_with : kwd_with;
|
kwd_with : kwd_with;
|
||||||
delta : record_injection reg
|
record_inj : record_injection reg
|
||||||
}
|
}
|
||||||
|
|
||||||
and fail_instr = {
|
and fail_instr = {
|
||||||
@ -575,15 +575,12 @@ and list_pattern =
|
|||||||
|
|
||||||
(* Projecting regions *)
|
(* Projecting regions *)
|
||||||
|
|
||||||
val type_expr_to_region : type_expr -> Region.t
|
val type_expr_to_region : type_expr -> Region.t
|
||||||
|
val expr_to_region : expr -> Region.t
|
||||||
val expr_to_region : expr -> Region.t
|
val instr_to_region : instruction -> Region.t
|
||||||
|
val pattern_to_region : pattern -> Region.t
|
||||||
val instr_to_region : instruction -> Region.t
|
|
||||||
|
|
||||||
val pattern_to_region : pattern -> Region.t
|
|
||||||
|
|
||||||
val local_decl_to_region : local_decl -> Region.t
|
val local_decl_to_region : local_decl -> Region.t
|
||||||
|
val path_to_region : path -> Region.t
|
||||||
|
|
||||||
(* Printing *)
|
(* Printing *)
|
||||||
|
|
||||||
|
38
Parser.mly
38
Parser.mly
@ -126,7 +126,6 @@ sepseq(X,Sep):
|
|||||||
%inline fun_name : Ident { $1 }
|
%inline fun_name : Ident { $1 }
|
||||||
%inline field_name : Ident { $1 }
|
%inline field_name : Ident { $1 }
|
||||||
%inline record_name : Ident { $1 }
|
%inline record_name : Ident { $1 }
|
||||||
%inline map_name : Ident { $1 }
|
|
||||||
|
|
||||||
(* Main *)
|
(* Main *)
|
||||||
|
|
||||||
@ -446,13 +445,13 @@ single_instr:
|
|||||||
| map_patch { MapPatch $1 }
|
| map_patch { MapPatch $1 }
|
||||||
|
|
||||||
map_patch:
|
map_patch:
|
||||||
Map map_name With map_injection {
|
Patch path With map_injection {
|
||||||
let region = cover $1 $4.region in
|
let region = cover $1 $4.region in
|
||||||
let value = {
|
let value = {
|
||||||
kwd_patch = $1;
|
kwd_patch = $1;
|
||||||
map_name = $2;
|
path = $2;
|
||||||
kwd_with = $3;
|
kwd_with = $3;
|
||||||
delta = $4}
|
map_inj = $4}
|
||||||
in {region; value}
|
in {region; value}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -481,13 +480,13 @@ binding:
|
|||||||
}
|
}
|
||||||
|
|
||||||
record_patch:
|
record_patch:
|
||||||
Patch record_name With record_injection {
|
Patch path With record_injection {
|
||||||
let region = cover $1 $4.region in
|
let region = cover $1 $4.region in
|
||||||
let value = {
|
let value = {
|
||||||
kwd_patch = $1;
|
kwd_patch = $1;
|
||||||
record_name = $2;
|
path = $2;
|
||||||
kwd_with = $3;
|
kwd_with = $3;
|
||||||
delta = $4}
|
record_inj = $4}
|
||||||
in {region; value}
|
in {region; value}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -769,21 +768,18 @@ core_expr:
|
|||||||
map_expr:
|
map_expr:
|
||||||
map_selection { MapLookUp $1 }
|
map_selection { MapLookUp $1 }
|
||||||
|
|
||||||
|
path:
|
||||||
|
var { Name $1 }
|
||||||
|
| record_projection { RecordPath $1 }
|
||||||
|
|
||||||
map_selection:
|
map_selection:
|
||||||
map_name brackets(expr) {
|
path brackets(expr) {
|
||||||
let region = cover $1.region $2.region in
|
let region = cover (path_to_region $1) $2.region in
|
||||||
let value = {
|
let value = {
|
||||||
path = Name $1;
|
path = $1;
|
||||||
index = $2}
|
index = $2}
|
||||||
in {region; value}
|
in {region; value}
|
||||||
}
|
}
|
||||||
| record_projection brackets(expr) {
|
|
||||||
let region = cover $1.region $2.region in
|
|
||||||
let value = {
|
|
||||||
path = RecordPath $1;
|
|
||||||
index = $2}
|
|
||||||
in {region; value}
|
|
||||||
}
|
|
||||||
|
|
||||||
record_expr:
|
record_expr:
|
||||||
record_injection { RecordInj $1 }
|
record_injection { RecordInj $1 }
|
||||||
|
@ -16,12 +16,9 @@ entrypoint contribute (storage store : store;
|
|||||||
fail "Deadline passed"
|
fail "Deadline passed"
|
||||||
else
|
else
|
||||||
case store.backers[sender] of
|
case store.backers[sender] of
|
||||||
None ->
|
None -> //store.backers[sender] := amount
|
||||||
patch store with
|
patch store.backers with map sender -> amount end
|
||||||
record
|
| _ -> skip
|
||||||
backers = add_binding ((sender, amount), store.backers)
|
|
||||||
end
|
|
||||||
| _ -> skip
|
|
||||||
end
|
end
|
||||||
end with (store, operations)
|
end with (store, operations)
|
||||||
|
|
||||||
@ -33,8 +30,10 @@ entrypoint withdraw (storage store : store; const sender : address)
|
|||||||
if now >= store.deadline then
|
if now >= store.deadline then
|
||||||
if balance >= store.goal then
|
if balance >= store.goal then
|
||||||
begin
|
begin
|
||||||
patch store with record funded = True end;
|
patch store with record funded = True end;
|
||||||
operations := [Transfer (owner, balance)]
|
// patch store.funded with True end;
|
||||||
|
// store.funded := True;
|
||||||
|
operations := [Transfer (owner, balance)]
|
||||||
end
|
end
|
||||||
else fail "Below target"
|
else fail "Below target"
|
||||||
else fail "Too soon"
|
else fail "Too soon"
|
||||||
@ -57,12 +56,8 @@ entrypoint claim (storage store : store; const sender : address)
|
|||||||
fail "Cannot refund"
|
fail "Cannot refund"
|
||||||
else
|
else
|
||||||
begin
|
begin
|
||||||
amount := store.backers[sender];
|
operations := [Transfer (sender, amount)];
|
||||||
patch store with
|
// patch store.backers without key sender;
|
||||||
record
|
|
||||||
backers = remove_entry (sender, store.backers)
|
|
||||||
end;
|
|
||||||
operations := [Transfer (sender, amount)]
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end with (store, operations)
|
end with (store, operations)
|
||||||
|
Loading…
Reference in New Issue
Block a user