add set literals

This commit is contained in:
galfour 2019-09-24 14:00:43 +02:00
parent b6ee28d704
commit f72593ae85
2 changed files with 19 additions and 0 deletions

View File

@ -32,4 +32,22 @@ let peephole_expression : expression -> expression result = fun e ->
in in
return @@ E_map [] return @@ E_map []
) )
| E_constant ("SET_LITERAL" , lst) -> (
let%bind elt =
trace_option (simple_error "map literal expects a single parameter") @@
List.to_singleton lst
in
let%bind lst =
trace (simple_error "map literal expects a list as parameter") @@
get_e_list elt.expression
in
return @@ E_set lst
)
| E_constant ("SET_EMPTY" , lst) -> (
let%bind () =
trace_strong (simple_error "SET_EMPTY expects no parameter") @@
Assert.assert_list_empty lst
in
return @@ E_set []
)
| e -> return e | e -> return e

View File

@ -147,6 +147,7 @@ module Simplify = struct
("Set.mem" , "SET_MEM") ; ("Set.mem" , "SET_MEM") ;
("Set.empty" , "SET_EMPTY") ; ("Set.empty" , "SET_EMPTY") ;
("Set.literal" , "SET_LITERAL") ;
("Set.add" , "SET_ADD") ; ("Set.add" , "SET_ADD") ;
("Set.remove" , "SET_REMOVE") ; ("Set.remove" , "SET_REMOVE") ;
("Set.fold" , "SET_FOLD") ; ("Set.fold" , "SET_FOLD") ;