harec

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

commit a3551bd75a0712760a8e2204e4a23dfb9e4b5edc
parent 3db5d7265cfacbd57248655205996619dd1b79b6
Author: Drew DeVault <sir@cmpwn.com>
Date:   Mon, 11 Jan 2021 10:47:33 -0500

gen: implement conversion from array to slice

Diffstat:
Msrc/gen.c | 26++++++++++++++++++++++++--
1 file changed, 24 insertions(+), 2 deletions(-)

diff --git a/src/gen.c b/src/gen.c @@ -694,11 +694,33 @@ gen_expr_cast(struct gen_context *ctx, case TYPE_STORAGE_TAGGED_UNION: case TYPE_STORAGE_ENUM: assert(0); // TODO - // Can be implemented with a copy case TYPE_STORAGE_ARRAY: + if (from->storage == TYPE_STORAGE_ARRAY) { + pushi(ctx->current, &result, Q_COPY, &in, NULL); + break; + } + assert(0); // TODO: Convert slice to array + break; + case TYPE_STORAGE_SLICE: + if (from->storage == TYPE_STORAGE_SLICE) { + pushi(ctx->current, &result, Q_COPY, &in, NULL); + break; + } + // XXX: ARCH + struct qbe_value ptr = {0}, offs = {0}, len = {0}; + gen_temp(ctx, &ptr, &qbe_long, "ptr.%d"); + constl(&offs, 8); + constl(&len, from->array.length); + pushi(ctx->current, &ptr, Q_COPY, out, NULL); + pushi(ctx->current, NULL, Q_STOREL, &in, &ptr, NULL); + pushi(ctx->current, &ptr, Q_ADD, &ptr, &offs, NULL); + pushi(ctx->current, NULL, Q_STOREL, &len, &ptr, NULL); + pushi(ctx->current, &ptr, Q_ADD, &ptr, &offs, NULL); + pushi(ctx->current, NULL, Q_STOREL, &len, &ptr, NULL); + return; + // Can be implemented with a copy case TYPE_STORAGE_NULL: case TYPE_STORAGE_POINTER: - case TYPE_STORAGE_SLICE: pushi(ctx->current, &result, Q_COPY, &in, NULL); break; case TYPE_STORAGE_ALIAS: