Skip to content

Commit

Permalink
minor bugfixes in map and expand
Browse files Browse the repository at this point in the history
forgot to expand switch { default => {here }
map::inser/set are msising size assigned args
  • Loading branch information
aep committed Sep 26, 2020
1 parent 1e8f203 commit 73b4332
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 9 deletions.
2 changes: 1 addition & 1 deletion modules/json/src/des.zz
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export fn impl()
err::assert(a.args.count == 1);
let arg0 = (ast::Expression*)(a.args.items[0].mem);
err::assert_safe(arg0);
printf("%.*s_from_json", arg0->v.literal.size , arg0->v.literal.mem);
printf("%.*s_from_json", (int)arg0->v.literal.size , arg0->v.literal.mem);
return;
}

Expand Down
19 changes: 14 additions & 5 deletions modules/map/src/lib.zz
Original file line number Diff line number Diff line change
Expand Up @@ -448,20 +448,29 @@ export fn has(Map *self, void *key) bool
}

/// an alias to insert_oo()
export fn insert(Map mut *self, void *key, void *value) bool
export fn insert(Map mut* self, void * k, void * v,
usize kt = static(len(k), 1) * sizeof(*k),
usize vt = static(len(v), 1) * sizeof(*v)
) -> bool
where !constrained(key(*self)) || typeof(*k) == key(*self)
where !constrained(val(*self)) || typeof(*v) == val(*self)
{
return self->insert_oo(key, value);
return self->insert_oo(k, v, kt, vt);
}

/// an alias to insert_bb()
export fn set(Map mut *self, void *key, void *value) bool
export fn set(Map mut* self, void * k, void * v,
usize kt = static(len(k), 1) * sizeof(*k),
usize vt = static(len(v), 1) * sizeof(*v)
) -> bool
where !constrained(key(*self)) || typeof(*k) == key(*self)
where !constrained(val(*self)) || typeof(*v) == val(*self)
{
return self->insert_bb(key, value);
return self->insert_bb(k, v, kt, vt);
}




static u8 siphashk[] = {1,2,3,4,6,7,8,9,0,1,2,3,4,5,6,7};
export fn hash(slice::Slice sl) -> u64
{
Expand Down
7 changes: 6 additions & 1 deletion src/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -750,12 +750,17 @@ impl Stack {
}
ast::Statement::Label { .. } => {}
ast::Statement::Mark { .. } => {}
ast::Statement::Switch { cases, .. } => {
ast::Statement::Switch { cases, default, .. } => {
for (_, block) in cases {
self.push("case".to_string());
self.expand_scope(&mut block.statements)?;
self.pop();
}
if let Some(block) = default {
self.push("case".to_string());
self.expand_scope(&mut block.statements)?;
self.pop();
}
}
ast::Statement::Assign { lhs, rhs, .. } => {
self.expand_expr(lhs)?;
Expand Down
4 changes: 2 additions & 2 deletions src/symbolic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4433,8 +4433,8 @@ impl Symbolic {
Some(v) => v,
None => {
return Err(self.trace(
format!("tail value on non struct"),
vec![(loc.clone(), format!("cannot emit tail binding to ssa"))],
format!("tail value on non struct {}", self.memory[sym].typed),
vec![(loc.clone(), format!("cannot emit tail binding to ssa. this might be a bug in zz"))],
));
}
};
Expand Down

0 comments on commit 73b4332

Please sign in to comment.