diff --git a/cozy/codegen/cxx.py b/cozy/codegen/cxx.py index 9f3db8f5..5df0e0d8 100644 --- a/cozy/codegen/cxx.py +++ b/cozy/codegen/cxx.py @@ -10,7 +10,7 @@ Type, INT, BOOL, TNative, TSet, TList, TBag, THandle, TEnum, TTuple, TRecord, TFloat, Exp, EVar, ENum, EFALSE, ETRUE, ZERO, ENull, EEq, ELt, ENot, ECond, EAll, EEnumEntry, ETuple, ETupleGet, EGetField, - Stm, SNoOp, SIf, SDecl, SSeq, seq, SForEach, SAssign) + Stm, SNoOp, SIf, SDecl, SSeq, seq, SForEach, SAssign, SCall) from cozy.target_syntax import TArray, TRef, EEnumToInt, EMapKeys, SReturn from cozy.syntax_tools import pprint, all_types, fresh_var, subst, free_vars, all_exps, break_seq, shallow_copy from cozy.typecheck import is_collection, is_scalar @@ -272,6 +272,14 @@ def visit_EMakeMap2(self, e): self.declare(m, e) return m.id + def visit_EMapKeys(self, e): + key = self.fv(e.type.elem_type) + keys = self.fv(e.type) + self.declare(keys) + add_to_keys = SCall(keys, "add", [key]) + self.visit(SForEach(key, e, add_to_keys)) + return keys.id + def visit_EHasKey(self, e): map = self.visit(e.map) key = self.visit(e.key) diff --git a/examples/Makefile b/examples/Makefile index b4452375..d1509441 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -23,7 +23,7 @@ select.h: select-flatmap.ds cozy -t $(TIMEOUT) --allow-big-sets select-flatmap.ds --c++ select.h -p 8080 --verbose --save select.synthesized listcomp: listcomp.cpp listcomp.h - g++ -std=c++11 -O3 -Werror '$<' -o '$@' + g++ -std=c++11 -O3 -Wno-parentheses-equality -Werror '$<' -o '$@' run-listcomp: listcomp time ./listcomp diff --git a/examples/listcomp-flatmap.ds b/examples/listcomp-flatmap.ds index 5b650a74..560ad750 100644 --- a/examples/listcomp-flatmap.ds +++ b/examples/listcomp-flatmap.ds @@ -22,3 +22,6 @@ ListComp02: op insert_s(s: S) Ss.add(s); + + op delete_r(a: Int) + Rs.remove_all([ r | r <- Rs, r.A == a ]);