~sircmpwn/harec unlisted

11273daeafa6b799e637df3064eb97b5530ddfa6 — Drew DeVault a month ago d5aee16
gen: fix error with new slice capacity

Signed-off-by: Drew DeVault <sir@cmpwn.com>
2 files changed, 8 insertions(+), 2 deletions(-)

M src/gen.c
M tests/19-append.ha
M src/gen.c => src/gen.c +2 -2
@@ 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);

M tests/19-append.ha => tests/19-append.ha +6 -0
@@ 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 = {