harec

[hare] Hare compiler, written in C11 for POSIX OSs
Log | Files | Refs | README | LICENSE

commit b502ce457e5db45dd9ec1386ff118a474e9cef2f
parent 2c11aaca24c7072a24e55815756333f23827d001
Author: Ember Sawady <ecs@d2evs.net>
Date:   Fri,  2 Dec 2022 00:07:20 +0000

Change bool storage to u8

Signed-off-by: Ember Sawady <ecs@d2evs.net>

Diffstat:
Msrc/check.c | 7++++++-
Msrc/gen.c | 9+++++----
Msrc/qinstr.c | 4++--
Msrc/qtype.c | 2+-
Msrc/types.c | 16++++------------
5 files changed, 18 insertions(+), 20 deletions(-)

diff --git a/src/check.c b/src/check.c @@ -2345,8 +2345,13 @@ check_expr_propagate(struct context *ctx, case_err->value->assert.message->constant.string.len = n; } else { if (!type_is_assignable(ctx->fntype->func.result, return_type)) { + char *res = gen_typename(ctx->fntype->func.result); + char *ret = gen_typename(return_type); error(ctx, aexpr->loc, expr, - "Error type is not assignable to function result type"); + "Error type %s is not assignable to function result type %s", + ret, res); + free(res); + free(ret); return; } diff --git a/src/gen.c b/src/gen.c @@ -3510,16 +3510,17 @@ gen_data_item(struct gen_context *ctx, struct expression *expr, item->value = constw((uint8_t)constant->uval); item->value.type = &qbe_byte; break; + case STORAGE_BOOL: + item->type = QD_VALUE; + item->value = constw(constant->bval ? 1 : 0); + item->value.type = &qbe_byte; + break; case STORAGE_I16: case STORAGE_U16: item->type = QD_VALUE; item->value = constw((uint16_t)constant->uval); item->value.type = &qbe_half; break; - case STORAGE_BOOL: - item->type = QD_VALUE; - item->value = constw(constant->bval ? 1 : 0); - break; case STORAGE_I32: case STORAGE_U32: case STORAGE_INT: diff --git a/src/qinstr.c b/src/qinstr.c @@ -29,6 +29,7 @@ store_for_type(struct gen_context *ctx, const struct type *type) case STORAGE_CHAR: case STORAGE_I8: case STORAGE_U8: + case STORAGE_BOOL: return Q_STOREB; case STORAGE_I16: case STORAGE_U16: @@ -39,7 +40,6 @@ store_for_type(struct gen_context *ctx, const struct type *type) case STORAGE_UINT: case STORAGE_RCONST: case STORAGE_RUNE: - case STORAGE_BOOL: return Q_STOREW; case STORAGE_I64: case STORAGE_U64: @@ -94,6 +94,7 @@ load_for_type(struct gen_context *ctx, const struct type *type) return Q_LOADSB; case STORAGE_CHAR: case STORAGE_U8: + case STORAGE_BOOL: return Q_LOADUB; case STORAGE_I16: return Q_LOADSH; @@ -103,7 +104,6 @@ load_for_type(struct gen_context *ctx, const struct type *type) case STORAGE_UINT: case STORAGE_RCONST: case STORAGE_RUNE: - case STORAGE_BOOL: return Q_LOADUW; case STORAGE_I32: case STORAGE_INT: diff --git a/src/qtype.c b/src/qtype.c @@ -199,6 +199,7 @@ qtype_lookup(struct gen_context *ctx, case STORAGE_U8: case STORAGE_I8: case STORAGE_CHAR: + case STORAGE_BOOL: return xtype ? &qbe_byte : &qbe_word; case STORAGE_I16: case STORAGE_U16: @@ -208,7 +209,6 @@ qtype_lookup(struct gen_context *ctx, case STORAGE_INT: case STORAGE_UINT: case STORAGE_RUNE: - case STORAGE_BOOL: return &qbe_word; case STORAGE_U64: case STORAGE_I64: diff --git a/src/types.c b/src/types.c @@ -982,8 +982,6 @@ void builtin_types_init(const char *target) { if (strcmp(target, "aarch64") == 0) { - builtin_type_bool.size = 4; - builtin_type_bool.align = 4; builtin_type_int.size = 4; builtin_type_int.align = 4; builtin_type_uint.size = 4; @@ -994,8 +992,6 @@ builtin_types_init(const char *target) builtin_type_null.align = 8; builtin_type_size.size = 8; builtin_type_size.align = 8; - builtin_type_const_bool.size = 4; - builtin_type_const_bool.align = 4; builtin_type_const_int.size = 4; builtin_type_const_int.align = 4; builtin_type_const_uint.size = 4; @@ -1013,8 +1009,6 @@ builtin_types_init(const char *target) builtin_type_valist.size = 32; builtin_type_valist.align = 8; } else if (strcmp(target, "riscv64") == 0) { - builtin_type_bool.size = 4; - builtin_type_bool.align = 4; builtin_type_int.size = 4; builtin_type_int.align = 4; builtin_type_uint.size = 4; @@ -1025,8 +1019,6 @@ builtin_types_init(const char *target) builtin_type_null.align = 8; builtin_type_size.size = 8; builtin_type_size.align = 8; - builtin_type_const_bool.size = 4; - builtin_type_const_bool.align = 4; builtin_type_const_int.size = 4; builtin_type_const_int.align = 4; builtin_type_const_uint.size = 4; @@ -1044,8 +1036,6 @@ builtin_types_init(const char *target) builtin_type_valist.size = 8; builtin_type_valist.align = 8; } else if (strcmp(target, "x86_64") == 0) { - builtin_type_bool.size = 4; - builtin_type_bool.align = 4; builtin_type_int.size = 4; builtin_type_int.align = 4; builtin_type_uint.size = 4; @@ -1056,8 +1046,6 @@ builtin_types_init(const char *target) builtin_type_null.align = 8; builtin_type_size.size = 8; builtin_type_size.align = 8; - builtin_type_const_bool.size = 4; - builtin_type_const_bool.align = 4; builtin_type_const_int.size = 4; builtin_type_const_int.align = 4; builtin_type_const_uint.size = 4; @@ -1106,6 +1094,8 @@ builtin_types_init(const char *target) // Built-in type singletons struct type builtin_type_bool = { .storage = STORAGE_BOOL, + .size = 1, + .align = 1, }, builtin_type_char = { .storage = STORAGE_CHAR, @@ -1190,6 +1180,8 @@ builtin_type_void = { builtin_type_const_bool = { .storage = STORAGE_BOOL, .flags = TYPE_CONST, + .size = 1, + .align = 1, }, builtin_type_const_char = { .storage = STORAGE_CHAR,