harec

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

commit 11273daeafa6b799e637df3064eb97b5530ddfa6
parent d5aee16e85da40db7f427cb8358697cf9f93236d
Author: Drew DeVault <sir@cmpwn.com>
Date:   Wed, 28 Apr 2021 13:23:23 -0400

gen: fix error with new slice capacity

Signed-off-by: Drew DeVault <sir@cmpwn.com>

Diffstat:
Msrc/gen.c | 4++--
Mtests/19-append.ha | 6++++++
2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/src/gen.c b/src/gen.c @@ -2550,7 +2550,7 @@ gen_expr_slice(struct gen_context *ctx, constl(&temp, 16); pushi(ctx->current, &object, Q_ADD, &object, &temp, NULL); pushi(ctx->current, &src, Q_LOADL, &object, NULL); - pushi(ctx->current, &offset, Q_SUB, &src, &offset, NULL); + pushi(ctx->current, &offset, Q_SUB, &src, &start, NULL); pushi(ctx->current, NULL, Q_STOREL, &offset, &dest, NULL); } else { gen_temp(ctx, &src, &qbe_long, "length.%d"); @@ -2572,7 +2572,7 @@ gen_expr_slice(struct gen_context *ctx, if (otype->array.length != SIZE_UNDEFINED) { constl(&temp, otype->array.length); - pushi(ctx->current, &offset, Q_SUB, &temp, &offset, NULL); + pushi(ctx->current, &offset, Q_SUB, &temp, &start, NULL); pushi(ctx->current, NULL, Q_STOREL, &offset, &dest, NULL); } pushi(ctx->current, NULL, Q_STOREL, &offset, &dest, NULL); diff --git a/tests/19-append.ha b/tests/19-append.ha @@ -49,6 +49,12 @@ fn static_append() void = { static append(x, [3, 4]...); assert(x[0] == 1 && x[1] == 2 && x[2] == 3 && x[3] == 4); assert(buf[0] == 1 && buf[1] == 2 && buf[2] == 3 && buf[3] == 4); + + let buf: [4]int = [1, 2, 0...]; + let x = buf[..2]; + static append(x, 3, 4); + assert(x[0] == 1 && x[1] == 2 && x[2] == 3 && x[3] == 4); + assert(buf[0] == 1 && buf[1] == 2 && buf[2] == 3 && buf[3] == 4); }; export fn main() void = {