From 45762bced35335cdb4d51f65cef6d405b88b252a Mon Sep 17 00:00:00 2001 From: Kyle Gunger Date: Thu, 28 Mar 2024 15:08:07 -0400 Subject: Makefile for tests --- compiler.c | 16 ++++++---------- tests/Makefile | 28 ++++++++++++++++++++++++++++ tests/test_struct_2.tnsl | 13 +++++++++++++ 3 files changed, 47 insertions(+), 10 deletions(-) create mode 100644 tests/Makefile create mode 100644 tests/test_struct_2.tnsl diff --git a/compiler.c b/compiler.c index 2729484..cd11b0d 100644 --- a/compiler.c +++ b/compiler.c @@ -1215,7 +1215,10 @@ char *_var_get_store(CompData *out, Variable *store) { vect_push_string(&out->text, "; litl set\n"); if (store->type != NULL) return _op_get_register(6, _var_size(store)); - return _op_get_register(6, 8); + return _op_get_register(6, 8); + var_end(store); + *store = var_init("#store", typ_get_inbuilt("int")); + store->location = 6; } else if (store->location < 0) { return _gen_address(PREFIXES[_var_size(store) - 1], "rbp", "", 0, store->offset, false); } else { @@ -4819,6 +4822,7 @@ Variable _eval_literal(Scope *s, CompData *data, Vector *tokens, size_t literal) out.location = LOC_LITL; } else { out.location = LOC_LITL; + out.type = typ_get_inbuilt("int"); if (t->data[0] == '\'') out.offset = tnsl_unquote_char(t->data + 1); else @@ -5017,16 +5021,8 @@ Variable _eval(Scope *s, CompData *data, Vector *tokens, size_t start, size_t en if (out.name == NULL) { return rhs; } - - if (out.location == LOC_LITL) { - if (rhs.location != LOC_LITL) { - Variable tmp = rhs; - out = rhs; - rhs = tmp; - } - } - if (op != 10 && out.location != LOC_LITL) { + if (op != 10 && !scope_is_tmp(&out)) { Variable tmp = scope_mk_tmp(s, data, &out); var_end(&out); out = tmp; diff --git a/tests/Makefile b/tests/Makefile new file mode 100644 index 0000000..d1a2c46 --- /dev/null +++ b/tests/Makefile @@ -0,0 +1,28 @@ +empty := + +out_dir := out +obj_dir := $(out_dir)/artifacts + +src_files := $(wildcard *.tnsl) +obj_files := $(src_files:.tnsl=.o) +out_files := $(src_files:.tnsl=.out) + +all: outdir $(out_files) +.PHONY: all test + +%.asm: %.tnsl + ../ctc $< $(obj_dir)/$@ + +%.o: %.asm + nasm -f elf64 -o $(obj_dir)/$@ $(obj_dir)/$< + +%.out: %.o + gcc -o $(out_dir)/$@ $(obj_dir)/$< + +outdir: + mkdir -p $(out_dir) + mkdir -p $(obj_dir) + +clean: + rm -rf out/* + diff --git a/tests/test_struct_2.tnsl b/tests/test_struct_2.tnsl new file mode 100644 index 0000000..2577959 --- /dev/null +++ b/tests/test_struct_2.tnsl @@ -0,0 +1,13 @@ +struct Rec { + ~Rec r, + int i +} + +/; main [int] + + Rec a, b + a.i = 1 + a.r = ~b + a.r`.i = 69 + return b.i +;/ -- cgit v1.2.3