Merge branch 'feature/clean-big-map' into 'dev'
Feature/clean big map See merge request ligolang/ligo!145
This commit is contained in:
commit
5a5c3a8dd4
@ -497,6 +497,7 @@ and closing =
|
|||||||
and map_expr =
|
and map_expr =
|
||||||
MapLookUp of map_lookup reg
|
MapLookUp of map_lookup reg
|
||||||
| MapInj of binding reg injection reg
|
| MapInj of binding reg injection reg
|
||||||
|
| BigMapInj of binding reg injection reg
|
||||||
|
|
||||||
and map_lookup = {
|
and map_lookup = {
|
||||||
path : path;
|
path : path;
|
||||||
@ -654,6 +655,7 @@ and tuple_expr_to_region {region; _} = region
|
|||||||
and map_expr_to_region = function
|
and map_expr_to_region = function
|
||||||
MapLookUp {region; _}
|
MapLookUp {region; _}
|
||||||
| MapInj {region; _} -> region
|
| MapInj {region; _} -> region
|
||||||
|
| BigMapInj {region; _} -> region
|
||||||
|
|
||||||
and set_expr_to_region = function
|
and set_expr_to_region = function
|
||||||
SetInj {region; _}
|
SetInj {region; _}
|
||||||
|
@ -488,6 +488,7 @@ and closing =
|
|||||||
and map_expr =
|
and map_expr =
|
||||||
MapLookUp of map_lookup reg
|
MapLookUp of map_lookup reg
|
||||||
| MapInj of binding reg injection reg
|
| MapInj of binding reg injection reg
|
||||||
|
| BigMapInj of binding reg injection reg
|
||||||
|
|
||||||
and map_lookup = {
|
and map_lookup = {
|
||||||
path : path;
|
path : path;
|
||||||
|
@ -899,6 +899,7 @@ set_expr:
|
|||||||
map_expr:
|
map_expr:
|
||||||
map_lookup { MapLookUp $1 }
|
map_lookup { MapLookUp $1 }
|
||||||
| injection(Map,binding) { MapInj $1 }
|
| injection(Map,binding) { MapInj $1 }
|
||||||
|
| injection(BigMap,binding) { BigMapInj $1 }
|
||||||
|
|
||||||
map_lookup:
|
map_lookup:
|
||||||
path brackets(expr) {
|
path brackets(expr) {
|
||||||
|
@ -431,6 +431,7 @@ and print_case_clause_expr buffer {value; _} =
|
|||||||
and print_map_expr buffer = function
|
and print_map_expr buffer = function
|
||||||
MapLookUp {value; _} -> print_map_lookup buffer value
|
MapLookUp {value; _} -> print_map_lookup buffer value
|
||||||
| MapInj inj -> print_injection buffer "map" print_binding inj
|
| MapInj inj -> print_injection buffer "map" print_binding inj
|
||||||
|
| BigMapInj inj -> print_injection buffer "big_map" print_binding inj
|
||||||
|
|
||||||
and print_set_expr buffer = function
|
and print_set_expr buffer = function
|
||||||
SetInj inj -> print_injection buffer "set" print_expr inj
|
SetInj inj -> print_injection buffer "set" print_expr inj
|
||||||
@ -1461,7 +1462,7 @@ and pp_map_expr buffer ~pad = function
|
|||||||
MapLookUp {value; _} ->
|
MapLookUp {value; _} ->
|
||||||
pp_node buffer ~pad "MapLookUp";
|
pp_node buffer ~pad "MapLookUp";
|
||||||
pp_map_lookup buffer ~pad value
|
pp_map_lookup buffer ~pad value
|
||||||
| MapInj {value; _} ->
|
| MapInj {value; _} | BigMapInj {value; _} ->
|
||||||
pp_node buffer ~pad "MapInj";
|
pp_node buffer ~pad "MapInj";
|
||||||
pp_injection pp_binding buffer ~pad value
|
pp_injection pp_binding buffer ~pad value
|
||||||
|
|
||||||
|
@ -389,7 +389,7 @@ let rec simpl_expression (t:Raw.expr) : expr result =
|
|||||||
let%bind cases = simpl_cases lst in
|
let%bind cases = simpl_cases lst in
|
||||||
return @@ e_matching ~loc e cases
|
return @@ e_matching ~loc e cases
|
||||||
)
|
)
|
||||||
| EMap (MapInj mi) -> (
|
| EMap (MapInj mi) -> (
|
||||||
let (mi , loc) = r_split mi in
|
let (mi , loc) = r_split mi in
|
||||||
let%bind lst =
|
let%bind lst =
|
||||||
let lst = List.map get_value @@ pseq_to_list mi.elements in
|
let lst = List.map get_value @@ pseq_to_list mi.elements in
|
||||||
@ -401,6 +401,18 @@ let rec simpl_expression (t:Raw.expr) : expr result =
|
|||||||
bind_map_list aux lst in
|
bind_map_list aux lst in
|
||||||
return @@ e_map ~loc lst
|
return @@ e_map ~loc lst
|
||||||
)
|
)
|
||||||
|
| EMap (BigMapInj mi) -> (
|
||||||
|
let (mi , loc) = r_split mi in
|
||||||
|
let%bind lst =
|
||||||
|
let lst = List.map get_value @@ pseq_to_list mi.elements in
|
||||||
|
let aux : Raw.binding -> (expression * expression) result =
|
||||||
|
fun b ->
|
||||||
|
let%bind src = simpl_expression b.source in
|
||||||
|
let%bind dst = simpl_expression b.image in
|
||||||
|
ok (src, dst) in
|
||||||
|
bind_map_list aux lst in
|
||||||
|
return @@ e_big_map ~loc lst
|
||||||
|
)
|
||||||
| EMap (MapLookUp lu) -> (
|
| EMap (MapLookUp lu) -> (
|
||||||
let (lu , loc) = r_split lu in
|
let (lu , loc) = r_split lu in
|
||||||
let%bind path = match lu.path with
|
let%bind path = match lu.path with
|
||||||
|
@ -4,6 +4,27 @@ open Trace
|
|||||||
let peephole_expression : expression -> expression result = fun e ->
|
let peephole_expression : expression -> expression result = fun e ->
|
||||||
let return expression = ok { e with expression } in
|
let return expression = ok { e with expression } in
|
||||||
match e.expression with
|
match e.expression with
|
||||||
|
| E_constant ("BIG_MAP_LITERAL" , lst) -> (
|
||||||
|
let%bind elt =
|
||||||
|
trace_option (simple_error "big_map literal expects a single parameter") @@
|
||||||
|
List.to_singleton lst
|
||||||
|
in
|
||||||
|
let%bind lst =
|
||||||
|
trace (simple_error "big_map literal expects a list as parameter") @@
|
||||||
|
get_e_list elt.expression
|
||||||
|
in
|
||||||
|
let aux = fun (e : expression) ->
|
||||||
|
trace (simple_error "big_map literal expects a list of pairs as parameter") @@
|
||||||
|
let%bind tpl = get_e_tuple e.expression in
|
||||||
|
let%bind (a , b) =
|
||||||
|
trace_option (simple_error "of pairs") @@
|
||||||
|
List.to_pair tpl
|
||||||
|
in
|
||||||
|
ok (a , b)
|
||||||
|
in
|
||||||
|
let%bind pairs = bind_map_list aux lst in
|
||||||
|
return @@ E_big_map pairs
|
||||||
|
)
|
||||||
| E_constant ("MAP_LITERAL" , lst) -> (
|
| E_constant ("MAP_LITERAL" , lst) -> (
|
||||||
let%bind elt =
|
let%bind elt =
|
||||||
trace_option (simple_error "map literal expects a single parameter") @@
|
trace_option (simple_error "map literal expects a single parameter") @@
|
||||||
@ -25,6 +46,13 @@ let peephole_expression : expression -> expression result = fun e ->
|
|||||||
let%bind pairs = bind_map_list aux lst in
|
let%bind pairs = bind_map_list aux lst in
|
||||||
return @@ E_map pairs
|
return @@ E_map pairs
|
||||||
)
|
)
|
||||||
|
| E_constant ("BIG_MAP_EMPTY" , lst) -> (
|
||||||
|
let%bind () =
|
||||||
|
trace_strong (simple_error "BIG_MAP_EMPTY expects no parameter") @@
|
||||||
|
Assert.assert_list_empty lst
|
||||||
|
in
|
||||||
|
return @@ E_big_map []
|
||||||
|
)
|
||||||
| E_constant ("MAP_EMPTY" , lst) -> (
|
| E_constant ("MAP_EMPTY" , lst) -> (
|
||||||
let%bind () =
|
let%bind () =
|
||||||
trace_strong (simple_error "MAP_EMPTY expects no parameter") @@
|
trace_strong (simple_error "MAP_EMPTY expects no parameter") @@
|
||||||
|
@ -85,6 +85,7 @@ module Simplify = struct
|
|||||||
("list_iter" , "LIST_ITER") ;
|
("list_iter" , "LIST_ITER") ;
|
||||||
("list_fold" , "LIST_FOLD") ;
|
("list_fold" , "LIST_FOLD") ;
|
||||||
("list_map" , "LIST_MAP") ;
|
("list_map" , "LIST_MAP") ;
|
||||||
|
(*ici*)
|
||||||
("map_iter" , "MAP_ITER") ;
|
("map_iter" , "MAP_ITER") ;
|
||||||
("map_map" , "MAP_MAP") ;
|
("map_map" , "MAP_MAP") ;
|
||||||
("map_fold" , "MAP_FOLD") ;
|
("map_fold" , "MAP_FOLD") ;
|
||||||
@ -168,6 +169,14 @@ module Simplify = struct
|
|||||||
("Map.literal" , "MAP_LITERAL" ) ;
|
("Map.literal" , "MAP_LITERAL" ) ;
|
||||||
("Map.size" , "SIZE" ) ;
|
("Map.size" , "SIZE" ) ;
|
||||||
|
|
||||||
|
("Big_map.find_opt" , "MAP_FIND_OPT") ;
|
||||||
|
("Big_map.find" , "MAP_FIND") ;
|
||||||
|
("Big_map.update" , "MAP_UPDATE") ;
|
||||||
|
("Big_map.add" , "MAP_ADD") ;
|
||||||
|
("Big_map.remove" , "MAP_REMOVE") ;
|
||||||
|
("Big_map.literal" , "BIG_MAP_LITERAL" ) ;
|
||||||
|
("Big_map.empty" , "BIG_MAP_EMPTY" ) ;
|
||||||
|
|
||||||
("String.length", "SIZE") ;
|
("String.length", "SIZE") ;
|
||||||
("String.size", "SIZE") ;
|
("String.size", "SIZE") ;
|
||||||
("String.slice", "SLICE") ;
|
("String.slice", "SLICE") ;
|
||||||
|
@ -1,30 +1,36 @@
|
|||||||
type storage_ is big_map(int, int) * unit
|
type storage_ is big_map(int, int) * unit
|
||||||
|
type foo is big_map(int, int)
|
||||||
|
|
||||||
function main(const p : unit; const s : storage_) : list(operation) * storage_ is
|
function main(const p : unit; const s : storage_) : list(operation) * storage_ is
|
||||||
var r : big_map(int, int) := s.0 ;
|
|
||||||
var toto : option (int) := Some(0);
|
var toto : option (int) := Some(0);
|
||||||
block {
|
block {
|
||||||
toto := r[23];
|
toto := s.0[23];
|
||||||
r[2] := 444;
|
s.0[2] := 444;
|
||||||
s.0 := r;
|
|
||||||
}
|
}
|
||||||
with ((nil: list(operation)), s)
|
with ((nil: list(operation)), s)
|
||||||
|
|
||||||
function set_ (var n : int ; var m : storage_) : storage_ is block {
|
function set_ (var n : int ; var m : foo) : foo is block {
|
||||||
var tmp : big_map(int,int) := m.0 ;
|
m[23] := n ;
|
||||||
tmp[23] := n ;
|
|
||||||
m.0 := tmp ;
|
|
||||||
} with m
|
} with m
|
||||||
|
|
||||||
function rm (var m : storage_) : storage_ is block {
|
function rm (var m : foo) : foo is block {
|
||||||
var tmp : big_map(int,int) := m.0 ;
|
remove 42 from map m;
|
||||||
remove 42 from map tmp;
|
|
||||||
m.0 := tmp;
|
|
||||||
} with m
|
} with m
|
||||||
|
|
||||||
function gf (const m : storage_) : int is begin skip end with get_force(23, m.0)
|
function gf (const m : foo) : int is begin skip end with get_force(23, m)
|
||||||
|
|
||||||
function get (const m : storage_) : option(int) is
|
function get (const m : foo) : option(int) is begin skip end with m[42]
|
||||||
begin
|
|
||||||
skip
|
const empty_big_map : big_map(int,int) = big_map end
|
||||||
end with m.0[42]
|
|
||||||
|
const big_map1 : big_map(int,int) = big_map
|
||||||
|
23 -> 0 ;
|
||||||
|
42 -> 0 ;
|
||||||
|
end
|
||||||
|
|
||||||
|
function mutimaps (const m : foo ; const n : foo) : foo is block
|
||||||
|
{
|
||||||
|
var bar : foo := m ;
|
||||||
|
bar[42] := 0 ;
|
||||||
|
n[42] := get_force(42, bar) ;
|
||||||
|
} with n
|
@ -1,12 +1,21 @@
|
|||||||
type storage_ = ((int, int) big_map * unit)
|
type foo = (int, int) big_map
|
||||||
|
|
||||||
let set_ (n : int) (m : storage_) : storage_ =
|
let set_ (n : int) (m : foo) : foo = Big_map.update 23 (Some(n)) m
|
||||||
(Map.update 23 (Some(n)) m.(0), ())
|
|
||||||
|
|
||||||
let rm (m : storage_) : storage_ =
|
let rm (m : foo) : foo = Big_map.remove 42 m
|
||||||
(Map.remove 42 m.(0), ())
|
|
||||||
|
|
||||||
let gf (m : storage_) : int = Map.find 23 m.(0)
|
let gf (m : foo) : int = Big_map.find 23 m
|
||||||
|
|
||||||
let get (m: storage_): int option =
|
let get (m: foo): int option = Big_map.find_opt 42 m
|
||||||
Map.find_opt 42 m.(0)
|
|
||||||
|
let empty_map : foo = Big_map.empty
|
||||||
|
|
||||||
|
let map1 : foo = Big_map.literal
|
||||||
|
[ (23 , 0) ; (42, 0) ]
|
||||||
|
|
||||||
|
let map1 : foo = Big_map.literal
|
||||||
|
[ (23 , 0) ; (42, 0) ]
|
||||||
|
|
||||||
|
let mutimaps (m : foo) (n : foo) : foo =
|
||||||
|
let bar : foo = Big_map.update 42 (Some(0)) m in
|
||||||
|
Big_map.update 42 (get(bar)) n
|
@ -520,7 +520,7 @@ let big_map_ type_f path : unit result =
|
|||||||
let ez lst =
|
let ez lst =
|
||||||
let open Ast_simplified.Combinators in
|
let open Ast_simplified.Combinators in
|
||||||
let lst' = List.map (fun (x, y) -> e_int x, e_int y) lst in
|
let lst' = List.map (fun (x, y) -> e_int x, e_int y) lst in
|
||||||
e_pair (e_typed_big_map lst' t_int t_int) (e_unit ())
|
(e_typed_big_map lst' t_int t_int)
|
||||||
in
|
in
|
||||||
let%bind () =
|
let%bind () =
|
||||||
let make_input = fun n -> ez [(23, n) ; (42, 4)] in
|
let make_input = fun n -> ez [(23, n) ; (42, 4)] in
|
||||||
|
Loading…
Reference in New Issue
Block a user