Skip to content

Commit

Permalink
rename vec::push_b to vec::put
Browse files Browse the repository at this point in the history
put:   To place something somewhere.
push:  To press upon or against (a thing) with force in order to move it away.
  • Loading branch information
aep committed Sep 25, 2020
1 parent d3edd93 commit 8e9b913
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 19 deletions.
8 changes: 4 additions & 4 deletions modules/ast/src/parser.zz
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ pub fn parse_typed(ast::Ast mut* self, ast::Typed mut *typed, err::Err mut *e, j
static_attest(safe(m));
m->make_expression(&self->pl);
static_attest(vec::integrity(&typed->params));
typed->params.push_b(m);
typed->params.put(m);
parse_expression(self, m, e, dec);
} else {
dec->skip(e);
Expand Down Expand Up @@ -214,7 +214,7 @@ pub fn decode_struct(ast::Ast mut*self,err::Err mut *e, json::Decoder mut*dec)
static_attest(safe(m));
m->make_field(&self->pl);
static_attest(vec::integrity(&self->local.v.dstruct.fields));
self->local.v.dstruct.fields.push_b(m);
self->local.v.dstruct.fields.put(m);

while dec->next(e) {
if dec->item == json::Item::Map && dec->key.eq_cstr("typed") {
Expand Down Expand Up @@ -256,7 +256,7 @@ pub fn decode_enum(ast::Ast mut*self,err::Err mut *e, json::Decoder mut*dec)
static_attest(safe(m));
static_attest(vec::integrity(&self->local.v.denum.items));
m->name = dec->val;
if !self->local.v.denum.items.push_b(m) {
if !self->local.v.denum.items.put(m) {
e->fail(err::OutOfTail,"oom");
return;
}
Expand Down Expand Up @@ -310,7 +310,7 @@ pub fn decode_ast(ast::Ast mut*self,err::Err mut *e, json::Decoder mut*dec)
}
static_attest(safe(m));
m->make_expression(&self->pl);
if !self->args.push_b(m) {
if !self->args.put(m) {
e->fail(err::OutOfTail,"oom");
return;
}
Expand Down
2 changes: 1 addition & 1 deletion modules/json/src/des.zz
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export fn impl()
);
printf(" if v == 0 { e->fail(err::OutOfTail, \"oom\"); return; }\n");
printf(" static_attest(safe(v));\n");
printf(" if !vec::push_b((::vec::Vec mut*)self, v) { e->fail(err::OutOfTail, \"oom\"); return; }\n");
printf(" if !vec::put((::vec::Vec mut*)self, v) { e->fail(err::OutOfTail, \"oom\"); return; }\n");


if vec_item.eq_cstr("::slice::slice::Slice") {
Expand Down
3 changes: 3 additions & 0 deletions modules/slice/src/slice.zz
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ export fn eq(Slice *self, Slice other) -> bool
if self->size != other.size {
return false;
}
if self->mem == 0 || other.mem == 0 {
return false;
}
return (c_string::memcmp(self->mem, other.mem, self->size) == 0);
}

Expand Down
18 changes: 5 additions & 13 deletions modules/vec/src/lib.zz
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,7 @@ export fn make(Vec mut new* self, usize lt = static(len(self->pool.pmem)))
{
mem::zero(self);
self->pool.make(sizeof(slice::Slice), lt);
self->capacity = lt/unsafe<usize>(sizeof(slice::Slice) + sizeof(bool))/10;
if self->capacity == 0 {
self->capacity = 1;
}

self->capacity = 1;
u8 mut* themem = self->pool.malloc(unsafe<usize>(sizeof(slice::Slice) + sizeof(bool)) * self->capacity);
err::assert_safe(themem);
self->items = (slice::slice::Slice mut*)themem;
Expand All @@ -59,11 +55,7 @@ export fn make_with_pool(Vec mut new* self, pool::Pool mut * pool, usize lt = st
mem::zero(self);
self->pool.make(sizeof(slice::Slice), lt);
self->pool.extra = pool;
self->capacity = lt/unsafe<usize>(sizeof(slice::Slice) + sizeof(bool))/10;
if self->capacity == 0 {
self->capacity = 1;
}

self->capacity = 1;
u8 mut * themem = self->pool.malloc(unsafe<usize>(sizeof(slice::Slice) + sizeof(bool)) * self->capacity);
err::assert_safe(themem);
self->items = (slice::slice::Slice mut*)themem;
Expand Down Expand Up @@ -145,7 +137,7 @@ export fn push(Vec mut* self, void * val, usize vt = static(len(val), 1) * sizeo
/// append borrowed value
/// the borrowed references must be valid for the lifetime of the vec
/// returns false if there is no memory left in the pool to grow the vec
export fn push_b(Vec mut* self, void * val, usize vt = static(len(val), 1) * sizeof(*val)) bool
export fn put(Vec mut* self, void * val, usize vt = static(len(val), 1) * sizeof(*val)) bool
where integrity(self)
model integrity(self)
{
Expand Down Expand Up @@ -202,7 +194,7 @@ export fn delete(Vec mut* self) bool {
/// an Iterator over a Vec
export struct Iter {
usize mut at;
Vec mut * mut v;
Vec * mut v;

slice::Slice mut val;
}
Expand All @@ -212,7 +204,7 @@ export struct Iter {
/// for let mut i = l.iter(); i.next(); {
/// log::info(">%.*s<", i.val.size, i.val.mem);
/// }
export fn iter(Vec mut* self) Iter
export fn iter(Vec * self) Iter
{
return Iter {
v: self,
Expand Down
2 changes: 1 addition & 1 deletion modules/vec/src/main.zz
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export fn main() int {


err::assert(l.push("hello"));
err::assert(l.push_b("bob"));
err::assert(l.put("bob"));



Expand Down

0 comments on commit 8e9b913

Please sign in to comment.