diff options
author | Andreas Baumann <mail@andreasbaumann.cc> | 2020-01-30 16:51:04 +0100 |
---|---|---|
committer | Andreas Baumann <mail@andreasbaumann.cc> | 2020-01-30 16:51:04 +0100 |
commit | 99ef28b45012765a0bfe078db0568ba48f87969f (patch) | |
tree | e45b56ddef593a8a1b1e2a276088bb78fe1dd81a /ecomp-c | |
parent | 3740165456ced176cde652d27b01ded7484eb954 (diff) | |
download | compilertests-99ef28b45012765a0bfe078db0568ba48f87969f.tar.gz compilertests-99ef28b45012765a0bfe078db0568ba48f87969f.tar.bz2 |
more testing and made it work with tcc-git nostdlib
Diffstat (limited to 'ecomp-c')
-rw-r--r-- | ecomp-c/README | 6 | ||||
-rw-r--r-- | ecomp-c/ec.c | 11 | ||||
-rw-r--r-- | ecomp-c/test1.e | 8 | ||||
-rw-r--r-- | ecomp-c/tests/duplicate_variable.e | 13 | ||||
-rwxr-xr-x | ecomp-c/tests/run_tests.sh | 4 | ||||
-rw-r--r-- | ecomp-c/tests/unknown_type.e | 8 | ||||
-rw-r--r-- | ecomp-c/tests/unknown_type.eerr | 2 | ||||
-rw-r--r-- | ecomp-c/tests/unknown_type.eout | 0 | ||||
-rw-r--r-- | ecomp-c/tests/unknown_variable.e | 5 | ||||
-rw-r--r-- | ecomp-c/tests/unknown_variable.eerr | 2 | ||||
-rw-r--r-- | ecomp-c/tests/unknown_variable.eout | 0 |
11 files changed, 51 insertions, 8 deletions
diff --git a/ecomp-c/README b/ecomp-c/README index 7fe0aa3..dade63c 100644 --- a/ecomp-c/README +++ b/ecomp-c/README @@ -1,12 +1,10 @@ gcc -g -O0 -m32 -march=i386 -ffreestanding -fno-stack-protector -nostdlib -emain -Werror -Wall -pedantic -fno-pic -std=c89 -o ec ec.c clang -g -O0 -m32 -march=i386 -ffreestanding -fno-stack-protector -nostdlib -Wl,-emain -Werror -Wall -pedantic -std=c89 -o ec ec.c pcc -g -O0 -march=i386 -ffreestanding -nostdlib -Wl,-emain -Werror -Wall -std=c89 -o ec ec.c - # -nostdlib segfaults with tcc 0.9.27 -# tcc-git fails with /usr/bin/ld: /tmp/ccKnq97E.o: direct GOT relocation R_386_GOT32X against `printf@@GLIBC_2.0' without base register can not be used when making a shared object -# in tcctest.c (must investigate) -# entry point cannot be changed? -Wl,-emain tcc -g -O0 -m32 -march=i386 -fno-builtin -std=c89 -Werror -Wall -o ec ec.c +# needs git version above 0.9.27 +tcc -g -O0 -m32 -march=i386 -nostdlib -std=c89 -Werror -Wall -o ec ec.c ./ec < test1.e > test1 diff --git a/ecomp-c/ec.c b/ecomp-c/ec.c index 99e2dec..9f1a77e 100644 --- a/ecomp-c/ec.c +++ b/ecomp-c/ec.c @@ -1046,6 +1046,9 @@ static void parseConstDeclaration( void ) Symbol *constant, *type; identifier( ); + if( sym == S_begin || sym == S_var ) { + return; + } constant = insert_symbol( current_scope, ident, SYMBOL_CLASS_CONSTANT ); sym = getSym( ); Expect( S_colon ); @@ -1089,6 +1092,9 @@ static void parseVariableDeclaration( void ) Symbol *variable, *type; identifier( ); + if( sym == S_begin ) { + return; + } variable = insert_symbol( current_scope, ident, SYMBOL_CLASS_VARIABLE ); sym = getSym( ); Expect( S_colon ); @@ -1184,3 +1190,8 @@ int main( void ) return 0; } + +int _start( void ) +{ + return main( ); +} diff --git a/ecomp-c/test1.e b/ecomp-c/test1.e index 66db7f7..315627a 100644 --- a/ecomp-c/test1.e +++ b/ecomp-c/test1.e @@ -5,15 +5,15 @@ module test1; const // integer constant - N : integer = 20; +// N : integer = 20; var // this is an integer - a : integer; +// a : integer; // this is also an integer - b : integer; - c : integer; // c too +// b : integer; +// c : integer; // c too begin a := 1; diff --git a/ecomp-c/tests/duplicate_variable.e b/ecomp-c/tests/duplicate_variable.e new file mode 100644 index 0000000..49a4554 --- /dev/null +++ b/ecomp-c/tests/duplicate_variable.e @@ -0,0 +1,13 @@ +module duplicate_variable; + +var + a : integer = 7; + +var + a : integer; // must croak about redefining a const as a variable + +begin + a := 1; + b := 7; + c := 8; +end diff --git a/ecomp-c/tests/run_tests.sh b/ecomp-c/tests/run_tests.sh index e5ec807..03e828c 100755 --- a/ecomp-c/tests/run_tests.sh +++ b/ecomp-c/tests/run_tests.sh @@ -2,6 +2,8 @@ TESTS=" empty_module +unknown_variable +unknown_type const_assignment_error " @@ -21,6 +23,8 @@ run_test( ) fi } +cd "$(dirname "$0")" + rm -f *.out *.err for test in $TESTS; do diff --git a/ecomp-c/tests/unknown_type.e b/ecomp-c/tests/unknown_type.e new file mode 100644 index 0000000..16b23a3 --- /dev/null +++ b/ecomp-c/tests/unknown_type.e @@ -0,0 +1,8 @@ +module unknown_type; + +var + a : flabla; // must warn here about a unknown type + +begin + a := 1; +end diff --git a/ecomp-c/tests/unknown_type.eerr b/ecomp-c/tests/unknown_type.eerr new file mode 100644 index 0000000..8a1de4c --- /dev/null +++ b/ecomp-c/tests/unknown_type.eerr @@ -0,0 +1,2 @@ +Error line 4, pos 13: Unknown type 'flabla' + diff --git a/ecomp-c/tests/unknown_type.eout b/ecomp-c/tests/unknown_type.eout new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/ecomp-c/tests/unknown_type.eout diff --git a/ecomp-c/tests/unknown_variable.e b/ecomp-c/tests/unknown_variable.e new file mode 100644 index 0000000..5b2f0a3 --- /dev/null +++ b/ecomp-c/tests/unknown_variable.e @@ -0,0 +1,5 @@ +module unknown_variable; + +begin + a := 1; // must warn here about a unknown variable +end diff --git a/ecomp-c/tests/unknown_variable.eerr b/ecomp-c/tests/unknown_variable.eerr new file mode 100644 index 0000000..21add2d --- /dev/null +++ b/ecomp-c/tests/unknown_variable.eerr @@ -0,0 +1,2 @@ +Error line 4, pos 7: Unknown variable 'a' + diff --git a/ecomp-c/tests/unknown_variable.eout b/ecomp-c/tests/unknown_variable.eout new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/ecomp-c/tests/unknown_variable.eout |