commit bb7f43d999e6f687c4979e92ed9288101f6983a6
parent a347ffcb11f2194ebd42889f586c0d4d8095ab59
Author: Bor Grošelj Simić <bgs@turminal.net>
Date: Fri, 20 May 2022 08:58:13 +0200
add testmod, a dummy module used in compiler tests
Signed-off-by: Bor Grošelj Simić <bgs@turminal.net>
Diffstat:
6 files changed, 54 insertions(+), 33 deletions(-)
diff --git a/Makefile b/Makefile
@@ -8,6 +8,7 @@ harec: $(harec_objects)
@$(CC) $(LDFLAGS) -o $@ $(harec_objects) $(LIBS)
include rt/Makefile
+include testmod/Makefile
include tests/Makefile
.SUFFIXES: .c .o .ha .s .scd .1 .5
@@ -20,7 +21,7 @@ include tests/Makefile
@printf 'AS\t$@\n'
@$(AS) -o $@ $<
-clean: clean-tests clean-rt
+clean: clean-tests clean-rt clean-testmod
@rm -f harec $(harec_objects)
distclean: clean
diff --git a/config.sh b/config.sh
@@ -225,6 +225,7 @@ EOF
populate "$srcdir/rt"
populate "$srcdir/src"
populate "$srcdir/tests"
+ populate "$srcdir/testmod"
ln -sf "$srcdir"/Makefile ./
echo done
}
diff --git a/testmod/Makefile b/testmod/Makefile
@@ -0,0 +1,16 @@
+testmod_srcs+=\
+ testmod/testmod.ha
+
+testmod.a: harec $(testmod_srcs)
+ @printf 'HAREC\t$@\n'
+ @mkdir -p $(HARECACHE)/testmod
+ @./harec -Ntestmod -t$(HARECACHE)/testmod/testmod.td -o $@.ssa $(testmod_srcs)
+ @$(QBE) -o $@.s $@.ssa
+ @$(AS) -g -o $@.o $@.s
+ @$(AR) -csr $@ $@.o $(testmod_objs)
+ @rm $@.o $@.s $@.ssa
+
+clean-testmod:
+ @rm -f testmod.a
+
+.PHONY: testmod clean-testmod
diff --git a/testmod/testmod.ha b/testmod/testmod.ha
@@ -0,0 +1,2 @@
+export fn testfunc1() void = void;
+export fn testfunc2() void = void;
diff --git a/tests/24-imports.ha b/tests/24-imports.ha
@@ -1,41 +1,42 @@
use rt;
+use testmod;
fn accept() void = {
assert(rt::compile("
- use rt;
- export fn main() void = { &rt::free_; };
+ use testmod;
+ export fn main() void = { &testmod::testfunc1; };
") == 0);
assert(rt::compile("
- use rt;
- use test = rt;
- export fn main() void = static assert(&rt::free_ == &test::free_);
+ use testmod;
+ use alias = testmod;
+ export fn main() void = static assert(&testmod::testfunc1 == &alias::testfunc1);
") == 0);
assert(rt::compile("
- use rt;
- use rt::{free_, malloc};
+ use testmod;
+ use testmod::{testfunc1, testfunc2};
export fn main() void = static assert(
- &rt::free_ == &free_ && &rt::malloc == &malloc
+ &testmod::testfunc1 == &testfunc1 && &testmod::testfunc2 == &testfunc2
);
") == 0);
assert(rt::compile("
- use rt;
- use rt::*;
+ use testmod;
+ use testmod::*;
export fn main() void = static assert(
- &rt::free_ == &free_ && &rt::malloc == &malloc
+ &testmod::testfunc1 == &testfunc1 && &testmod::testfunc2 == &testfunc2
);
") == 0);
assert(rt::compile("
- use rt;
- use rt::{test = free_, malloc};
+ use testmod;
+ use testmod::{alias = testfunc1, testfunc2};
export fn main() void = static assert(
- &rt::free_ == &test && &rt::malloc == &malloc
+ &testmod::testfunc1 == &alias && &testmod::testfunc2 == &testfunc2
);
") == 0);
assert(rt::compile("
- use rt;
- use test = rt::{test = free_, malloc};
+ use testmod;
+ use modalias = testmod::{fnalias = testfunc1, testfunc2};
export fn main() void = static assert(
- &rt::free_ == &test::test && &rt::malloc == &test::malloc
+ &testmod::testfunc1 == &modalias::fnalias && &testmod::testfunc2 == &modalias::testfunc2
);
") == 0);
};
@@ -43,37 +44,37 @@ fn accept() void = {
fn reject() void = {
assert(rt::compile("
use wrong;
- export fn main() void = &rt::free_;
+ export fn main() void = { &testmod::testfunc1 };
") != 0);
assert(rt::compile("
- use rt::{free_};
+ use testmod::{testfunc1};
export fn main() void = static assert(
- &rt::free_ != null
+ &testmod::testfunc1 != null
);
") != 0);
assert(rt::compile("
- use rt::{free_};
+ use testmod::{testfunc1};
export fn main() void = static assert(
- &malloc != null
+ &testfunc2 != null
);
") != 0);
assert(rt::compile("
- use rt;
- use test = rt::*;
+ use testmod;
+ use test = testmod::*;
export fn main() void = void;
") != 0);
assert(rt::compile("
- use rt;
- use rt*;
+ use testmod;
+ use testmod*;
export fn main() void = void;
") != 0);
assert(rt::compile("
- use rt::{test = free_, malloc};
- export fn main() void = static assert(&free_ != null);
+ use testmod::{alias = testfunc1, testfunc2};
+ export fn main() void = static assert(&testfunc1 != null);
") != 0);
assert(rt::compile("
- use test = rt::{test = free_, malloc};
- export fn main() void = static assert(&test != null);
+ use modalias = testmod::{fnalias = testfunc1, testfunc2};
+ export fn main() void = static assert(&fnalias != null);
") != 0);
};
diff --git a/tests/configure b/tests/configure
@@ -48,12 +48,12 @@ tests() {
35-floats
do
cat <<EOF
-tests/$t: libhart.a tests/$t.ha
+tests/$t: libhart.a testmod.a tests/$t.ha
@printf 'HAREC\t%s\t$@\n' "tests/$t"
@HARECACHE=\$(HARECACHE) ./harec -o tests/$t.ssa tests/$t.ha
@\$(QBE) -o tests/$t.s tests/$t.ssa
@\$(AS) -g -o tests/$t.o tests/$t.s
- @\$(LD) --gc-sections -T $rtscript -o tests/$t $rtstart tests/$t.o libhart.a
+ @\$(LD) --gc-sections -T $rtscript -o tests/$t $rtstart tests/$t.o libhart.a testmod.a
@rm tests/$t.s tests/$t.ssa tests/$t.o
check: tests/$t