Merge remote-tracking branch 'origin/dev' into rinderknecht-dev

This commit is contained in:
Christian Rinderknecht 2019-12-07 15:13:55 +01:00
commit 9829a35653
4 changed files with 15 additions and 0 deletions

View File

@ -107,6 +107,7 @@ module Simplify = struct
| "map_remove" -> ok C_MAP_REMOVE
| "map_update" -> ok C_MAP_UPDATE
| "map_get" -> ok C_MAP_GET
| "map_mem" -> ok C_MAP_MEM
| "sha_256" -> ok C_SHA256
| "sha_512" -> ok C_SHA512
| "blake2b" -> ok C_BLAKE2b
@ -203,6 +204,7 @@ module Simplify = struct
| "Map.iter" -> ok C_MAP_ITER
| "Map.map" -> ok C_MAP_MAP
| "Map.fold" -> ok C_MAP_FOLD
| "Map.mem" -> ok C_MAP_MEM
| "Map.empty" -> ok C_MAP_EMPTY
| "Map.literal" -> ok C_MAP_LITERAL
| "Map.size" -> ok C_SIZE
@ -913,6 +915,7 @@ module Compiler = struct
| C_MAP_GET_FORCE -> ok @@ simple_binary @@ seq [prim I_GET ; i_assert_some_msg (i_push_string "GET_FORCE")]
| C_MAP_FIND -> ok @@ simple_binary @@ seq [prim I_GET ; i_assert_some_msg (i_push_string "MAP FIND")]
| C_MAP_GET -> ok @@ simple_binary @@ prim I_GET
| C_MAP_MEM -> ok @@ simple_binary @@ prim I_MEM
| C_MAP_FIND_OPT -> ok @@ simple_binary @@ prim I_GET
| C_MAP_ADD -> ok @@ simple_ternary @@ seq [dip (i_some) ; prim I_UPDATE]
| C_MAP_UPDATE -> ok @@ simple_ternary @@ prim I_UPDATE

View File

@ -47,6 +47,8 @@ function get_ (const m : foobar) : option(int) is
skip
end with map_get(42 , m)
function mem (const k: int; const m: foobar) : bool is map_mem(k, m)
function iter_op (const m : foobar) : unit is
block {
function aggregate (const i : int ; const j : int) : unit is block

View File

@ -28,6 +28,8 @@ let gf (m: foobar) : int = Map.find 23 m
let get (m: foobar) : int option = Map.find_opt 42 m
let get_ (m: foobar) : int option = Map.find_opt 42 m
let mem (km: int * foobar) : bool = Map.mem km.0 km.1
let iter_op (m : foobar) : unit =
let assert_eq = fun (i: int) (j: int) -> assert (i=j)
in Map.iter assert_eq m

View File

@ -663,6 +663,14 @@ let map_ type_f path : unit result =
let make_expected = fun _ -> e_some @@ e_int 4 in
expect_eq_n program "get_" make_input make_expected
in
let%bind () =
let input_map = ez [(23, 10) ; (42, 4)] in
expect_eq program "mem" (e_tuple [(e_int 23) ; input_map]) (e_bool true)
in
let%bind () =
let input_map = ez [(23, 10) ; (42, 4)] in
expect_eq program "mem" (e_tuple [(e_int 1000) ; input_map]) (e_bool false)
in
let%bind () = expect_eq_evaluate program "empty_map"
(e_annotation (e_map []) (t_map t_int t_int)) in
let%bind () =