From 1621968fc82f17708c1d5b6f5bd65ba2244269a3 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Mon, 17 Jun 2024 17:31:50 -0400 Subject: Fix issue with bitfields --- Makefile | 2 +- compile.c | 2 +- structs.c | 5 ++++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index c9e182ef..413dc1d7 100644 --- a/Makefile +++ b/Makefile @@ -47,7 +47,7 @@ tags: $(CC) $(CFLAGS) -c $< -o $@ %.tm.testresult: %.tm tomo - VERBOSE=0 COLOR=1 CC=tcc ./tomo $< 2>&1 | tee $@ + VERBOSE=0 COLOR=1 CC=tcc ./tomo $< 2>$@ >$@ test: $(TESTS) @echo -e '\x1b[32;7m ALL TESTS PASSED! \x1b[m' diff --git a/compile.c b/compile.c index 1a7f4002..59eb4595 100644 --- a/compile.c +++ b/compile.c @@ -850,7 +850,7 @@ CORD expr_as_text(env_t *env, CORD expr, type_t *t, CORD color) { switch (t->tag) { case MemoryType: return CORD_asprintf("Memory$as_text(stack(%r), %r, &$Memory)", expr, color); - case BoolType: return CORD_asprintf("Bool$as_text(stack(%r), %r, &$Bool)", expr, color); + case BoolType: return CORD_asprintf("Bool$as_text((Bool_t[1]){%r}, %r, &$Bool)", expr, color); case CStringType: return CORD_asprintf("CString$as_text(stack(%r), %r, &$CString)", expr, color); case IntType: { CORD name = type_to_cord(t); diff --git a/structs.c b/structs.c index 5c00055f..51f69287 100644 --- a/structs.c +++ b/structs.c @@ -102,7 +102,10 @@ static CORD compile_hash_method(env_t *env, ast_t *ast) "uint32_t field_hashes[] = {"); for (arg_ast_t *field = def->fields; field; field = field->next) { type_t *field_type = get_arg_ast_type(env, field); - hash_func = CORD_all(hash_func, "\ngeneric_hash(&obj->", field->name, ", ", compile_type_info(env, field_type), "),"); + if (field_type->tag == BoolType) // Bools can be bit fields, so you can't use *obj->field there: + hash_func = CORD_all(hash_func, "\n(uint32_t)(obj->", field->name, "),"); + else + hash_func = CORD_all(hash_func, "\ngeneric_hash(&obj->", field->name, ", ", compile_type_info(env, field_type), "),"); } hash_func = CORD_all(hash_func, "};\n" "uint32_t hash;\n" -- cgit v1.2.3