Skip to content

Commit

Permalink
Merge pull request #73 from izgzhen/separate
Browse files Browse the repository at this point in the history
support code-gen for TTuple construction
  • Loading branch information
Calvin-L authored Oct 25, 2018
2 parents 1869354 + 0019675 commit 266151a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
8 changes: 8 additions & 0 deletions cozy/codegen/cxx.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,14 @@ def construct_concrete(self, t : Type, e : Exp, out : Exp):
return SEscape("{indent}{lhs} = {rhs};\n", ["lhs", "rhs"], [out, e])
elif is_scalar(t):
return SEscape("{indent}{lhs} = {rhs};\n", ["lhs", "rhs"], [out, e])
elif isinstance(t, TTuple):
x = self.fv(t, "x")
indices = range(len(t.ts))
return SSeq(
SEscape("{indent}{rv} = {rhs};\n", ["rv", "rhs"], [x, e]),
SEscape("{indent}{lhs} = {rv};\n", ["lhs", "rv"],
[out, ETuple([ETupleGet(x, i).with_type(t.ts[i]) for i in indices]).with_type(t)]),
)
else:
h = extension_handler(type(t))
if h is not None:
Expand Down
2 changes: 1 addition & 1 deletion cozy/synthesis/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ def possibly_useful_nonrecursive(solver, e : Exp, context : Context, pool = RUNT
if not allow_int_arithmetic_state.value and not at_runtime and isinstance(e, EBinOp) and e.type == INT:
return No("integer arithmetic in state position")
if is_collection(e.type) and not is_scalar(e.type.elem_type):
return No("collection of nonscalar")
return No("collection of nonscalar: e {}\n elem_type: {}\n".format(e, e.type.elem_type))
if isinstance(e.type, TMap) and not is_scalar(e.type.k):
return No("bad key type {}".format(pprint(e.type.k)))
if isinstance(e.type, TMap) and isinstance(e.type.v, TMap):
Expand Down
12 changes: 12 additions & 0 deletions examples/nonscalar-tuple.ds
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Example:
type Member = {
id : Int,
name: String
}
handletype Clz = {
id : Int,
members : Bag<Member>
}
state classes : Bag<Clz>
query selectClzMembers()
[ (c, [ m.id | m <- c.val.members, m.id > 10 ]) | c <- classes ]

0 comments on commit 266151a

Please sign in to comment.