harec

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

commit 2e57947c398da8594ef65becb074aa62854ed6e5
parent adcd7db262ffb1deed24044d882cbbb8028f62b0
Author: Drew DeVault <sir@cmpwn.com>
Date:   Fri, 22 Jan 2021 11:04:37 -0500

tests: use rt via hare modules

Diffstat:
Mconfig.sh | 1+
Mrt/Makefile | 3++-
Msrc/check.c | 7++-----
Msrc/gen.c | 6++++--
Msrc/typedef.c | 58+++++++++++++++++++++++++++++++++++++++++++++++++++++-----
Mtests/03-pointers.ha | 2+-
Mtests/05-implicit-casts.ha | 2+-
Mtests/06-structs.ha | 2+-
Mtests/08-slices.ha | 2+-
Mtests/09-funcs.ha | 2+-
Mtests/10-binarithms.ha | 1-
Mtests/11-globals.ha | 2+-
Mtests/12-loops.ha | 2+-
Mtests/13-tagged.ha | 2+-
14 files changed, 70 insertions(+), 22 deletions(-)

diff --git a/config.sh b/config.sh @@ -167,6 +167,7 @@ run_configure() { CFLAGS+=-DVARLIBDIR='"\$(VARLIBDIR)"' CFLAGS+=-DSYSCONFDIR='"\$(SYSCONFDIR)"' LDFLAGS=${LDFLAGS} + HARECACHE=./mod all: ${all} EOF diff --git a/rt/Makefile b/rt/Makefile @@ -5,7 +5,8 @@ libhart_srcs+=\ libhart.a: harec $(libhart_srcs) $(libhart_objs) $(rtstart) @printf 'HAREC\t$@\n' - @./harec -N rt -o $@.ssa $(libhart_srcs) + @mkdir -p $(HARECACHE)/rt + @./harec -Nrt -t$(HARECACHE)/rt/rt.td -o $@.ssa $(libhart_srcs) @qbe -o $@.s $@.ssa @$(AS) -o $@.o $@.s @$(AR) -csr $@ $@.o $(libhart_objs) diff --git a/src/check.c b/src/check.c @@ -1224,11 +1224,9 @@ check_function(struct context *ctx, decl->func.flags = afndecl->flags; if (afndecl->symbol) { - decl->ident.name = strdup(afndecl->symbol); decl->symbol = strdup(afndecl->symbol); - } else { - mkident(ctx, &decl->ident, &afndecl->ident); } + mkident(ctx, &decl->ident, &afndecl->ident); decl->func.scope = scope_push(&ctx->scope, TR_CHECK); struct ast_function_parameters *params = afndecl->prototype.params; @@ -1548,8 +1546,6 @@ load_import(struct ast_imports *import, case AST_IMPORT_MEMBERS: assert(0); // TODO } - - scope_free(mod); } struct scope * @@ -1583,6 +1579,7 @@ check(struct type_store *ts, const struct ast_unit *aunit, struct unit *unit) load_import(imports, ts, ctx.scope); } + ctx.store->check_context = &ctx; scan_declarations(&ctx, &su->decls); *next = xcalloc(1, sizeof(struct scopes)); diff --git a/src/gen.c b/src/gen.c @@ -1069,7 +1069,9 @@ gen_string(struct gen_context *ctx, def->name = temp.name; def->kind = Q_DATA; def->data.items.type = QD_STRING; - def->data.items.str = strdup(expr->constant.string.value); + def->data.items.str = xcalloc(1, expr->constant.string.len); + memcpy(def->data.items.str, expr->constant.string.value, + expr->constant.string.len); def->data.items.sz = expr->constant.string.len; qbe_append_def(ctx->out, def); @@ -1665,7 +1667,7 @@ gen_function_decl(struct gen_context *ctx, const struct declaration *decl) struct qbe_def *qdef = xcalloc(1, sizeof(struct qbe_def)); qdef->kind = Q_FUNC; qdef->exported = decl->exported; - qdef->name = ident_to_sym(&decl->ident); + qdef->name = decl->symbol ? strdup(decl->symbol) : ident_to_sym(&decl->ident); qdef->func.returns = qtype_for_type(ctx, fntype->func.result, false); ctx->current = &qdef->func; diff --git a/src/typedef.c b/src/typedef.c @@ -6,6 +6,41 @@ #include "identifier.h" #include "typedef.h" +static const char * +storage_to_suffix(enum type_storage storage) +{ + switch (storage) { + case TYPE_STORAGE_F32: + return "f32"; + case TYPE_STORAGE_F64: + return "f64"; + case TYPE_STORAGE_I16: + return "i16"; + case TYPE_STORAGE_I32: + return "i32"; + case TYPE_STORAGE_I64: + return "i64"; + case TYPE_STORAGE_I8: + return "i8"; + case TYPE_STORAGE_INT: + return "i"; + case TYPE_STORAGE_SIZE: + return "z"; + case TYPE_STORAGE_U16: + return "u16"; + case TYPE_STORAGE_U32: + return "u32"; + case TYPE_STORAGE_U64: + return "u64"; + case TYPE_STORAGE_U8: + return "u8"; + case TYPE_STORAGE_UINT: + return "u"; + default: + assert(0); + } +} + static void emit_const(const struct expression *expr, FILE *out) { @@ -17,14 +52,16 @@ emit_const(const struct expression *expr, FILE *out) break; case TYPE_STORAGE_F32: case TYPE_STORAGE_F64: - fprintf(out, "%lf", val->fval); + fprintf(out, "%lf%s", val->fval, + storage_to_suffix(expr->result->storage)); break; case TYPE_STORAGE_I16: case TYPE_STORAGE_I32: case TYPE_STORAGE_I64: case TYPE_STORAGE_I8: case TYPE_STORAGE_INT: - fprintf(out, "%ld", val->ival); + fprintf(out, "%ld%s", val->ival, + storage_to_suffix(expr->result->storage)); break; case TYPE_STORAGE_NULL: fprintf(out, "null"); @@ -35,7 +72,8 @@ emit_const(const struct expression *expr, FILE *out) case TYPE_STORAGE_U64: case TYPE_STORAGE_U8: case TYPE_STORAGE_UINT: - fprintf(out, "%lu", val->uval); + fprintf(out, "%lu%s", val->uval, + storage_to_suffix(expr->result->storage)); break; case TYPE_STORAGE_VOID: fprintf(out, "void"); @@ -95,10 +133,20 @@ emit_type(const struct type *type, FILE *out) ? "nullable " : ""); emit_type(type->pointer.referent, out); break; - case TYPE_STORAGE_ALIAS: case TYPE_STORAGE_ARRAY: - case TYPE_STORAGE_FUNCTION: + if (type->array.length == SIZE_UNDEFINED) { + fprintf(out, "[*]"); + } else { + fprintf(out, "[%zd]", type->array.length); + } + emit_type(type->array.members, out); + break; case TYPE_STORAGE_SLICE: + fprintf(out, "[]"); + emit_type(type->array.members, out); + break; + case TYPE_STORAGE_ALIAS: + case TYPE_STORAGE_FUNCTION: case TYPE_STORAGE_STRUCT: case TYPE_STORAGE_TAGGED_UNION: case TYPE_STORAGE_UNION: diff --git a/tests/03-pointers.ha b/tests/03-pointers.ha @@ -1,4 +1,4 @@ -fn rt::compile(src: str) int; +use rt; fn basics() void = { let x = 42; diff --git a/tests/05-implicit-casts.ha b/tests/05-implicit-casts.ha @@ -1,4 +1,4 @@ -fn rt::compile(src: str) int; +use rt; fn rules() void = { // Fixed precision ints diff --git a/tests/06-structs.ha b/tests/06-structs.ha @@ -1,4 +1,4 @@ -fn rt::compile(src: str) int; +use rt; fn padding() void = { assert(size(struct { x: i32, y: i32 }) == 8z); diff --git a/tests/08-slices.ha b/tests/08-slices.ha @@ -1,4 +1,4 @@ -fn rt::compile(src: str) int; +use rt; fn from_array() void = { let src = [1, 2, 3]; diff --git a/tests/09-funcs.ha b/tests/09-funcs.ha @@ -1,4 +1,4 @@ -@noreturn fn rt::exit(status: int) void; +use rt; fn addone(x: *int) void = { *x += 1; diff --git a/tests/10-binarithms.ha b/tests/10-binarithms.ha @@ -1,4 +1,3 @@ - fn error() bool = { abort(); return false; diff --git a/tests/11-globals.ha b/tests/11-globals.ha @@ -1,4 +1,4 @@ -fn rt::compile(src: str) int; +use rt; let x: int = 42; diff --git a/tests/12-loops.ha b/tests/12-loops.ha @@ -1,4 +1,4 @@ -fn rt::compile(src: str) int; +use rt; fn scope() void = { let x = 0; diff --git a/tests/13-tagged.ha b/tests/13-tagged.ha @@ -1,4 +1,4 @@ -fn rt::compile(src: str) int; +use rt; fn measurements() void = { const x: (u8 | u16 | u32 | u64) = 1337u16; // With padding