harec

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 432d7ce213f2a69447520483adf6c9190a3021d3
parent ce9373218c0d9999fd6bab81d07ac3bcdb816999
Author: Eyal Sawady <ecs@d2evs.net>
Date:   Thu, 25 Feb 2021 17:36:47 -0500

rt::{ensure, unensure}: get length from slice

Diffstat:
Mrt/ensure.ha | 10+++++-----
Msrc/gen.c | 4++--
2 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/rt/ensure.ha b/rt/ensure.ha @@ -4,12 +4,12 @@ export type slice = struct { capacity: size, }; -export fn ensure(s: *slice, membsz: size, length: size) void = { +export fn ensure(s: *slice, membsz: size) void = { let cap = s.capacity; - for (cap < length) { + for (cap < s.length) { assert(cap >= s.capacity, "slice out of memory (overflow)"); if (cap == 0) { - cap = length; + cap = s.length; } else { cap *= 2; }; @@ -20,9 +20,9 @@ export fn ensure(s: *slice, membsz: size, length: size) void = { s.data = data; }; -export fn unensure(s: *slice, membsz: size, length: size) void = { +export fn unensure(s: *slice, membsz: size) void = { let cap = s.capacity; - for (cap > length) { + for (cap > s.length) { cap /= 2; }; cap *= 2; diff --git a/src/gen.c b/src/gen.c @@ -667,7 +667,7 @@ gen_expr_append(struct gen_context *ctx, rtfunc.kind = QV_GLOBAL; rtfunc.name = strdup("rt.ensure"); rtfunc.type = &qbe_long; - pushi(ctx->current, NULL, Q_CALL, &rtfunc, &val, &membsz, &newlen, NULL); + pushi(ctx->current, NULL, Q_CALL, &rtfunc, &val, &membsz, NULL); struct qbe_value ptr = {0}; const struct qbe_type *type = qtype_for_type(ctx, mtype, false); @@ -1712,7 +1712,7 @@ gen_expr_delete(struct gen_context *ctx, rtunensure.kind = QV_GLOBAL; rtunensure.name = strdup("rt.unensure"); rtunensure.type = &qbe_long; - pushi(ctx->current, NULL, Q_CALL, &rtunensure, &object, &membsz, &newlen, NULL); + pushi(ctx->current, NULL, Q_CALL, &rtunensure, &object, &membsz, NULL); } static void