From f72593ae852a5006f23b22f83df8bee84312ad09 Mon Sep 17 00:00:00 2001 From: galfour Date: Tue, 24 Sep 2019 14:00:43 +0200 Subject: [PATCH] add set literals --- src/passes/3-self_ast_simplified/literals.ml | 18 ++++++++++++++++++ src/passes/operators/operators.ml | 1 + 2 files changed, 19 insertions(+) diff --git a/src/passes/3-self_ast_simplified/literals.ml b/src/passes/3-self_ast_simplified/literals.ml index 4584f1eb5..5d7be25b6 100644 --- a/src/passes/3-self_ast_simplified/literals.ml +++ b/src/passes/3-self_ast_simplified/literals.ml @@ -32,4 +32,22 @@ let peephole_expression : expression -> expression result = fun e -> in 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 diff --git a/src/passes/operators/operators.ml b/src/passes/operators/operators.ml index 00d580a87..335cd53d0 100644 --- a/src/passes/operators/operators.ml +++ b/src/passes/operators/operators.ml @@ -147,6 +147,7 @@ module Simplify = struct ("Set.mem" , "SET_MEM") ; ("Set.empty" , "SET_EMPTY") ; + ("Set.literal" , "SET_LITERAL") ; ("Set.add" , "SET_ADD") ; ("Set.remove" , "SET_REMOVE") ; ("Set.fold" , "SET_FOLD") ;