Skip to content

Commit

Permalink
Fix EMapKeys codegen failure
Browse files Browse the repository at this point in the history
  • Loading branch information
izgzhen committed Oct 21, 2019
1 parent 7fcc941 commit deb807a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
10 changes: 9 additions & 1 deletion cozy/codegen/cxx.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion examples/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions examples/listcomp-flatmap.ds
Original file line number Diff line number Diff line change
Expand Up @@ -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 ]);

0 comments on commit deb807a

Please sign in to comment.