duskos

dusk os fork
git clone git://git.alexwennerberg.com/duskos
Log | Files | Refs | README | LICENSE

commit d064097bfb688dcee7181fb5c4d4cef40c8978fb
parent f3e8faf244c41fe6dcf6d5bfcbaae8e6d71fa145
Author: Virgil Dupras <hsoft@hardcoded.net>
Date:   Sun,  2 Apr 2023 07:13:04 -0400

halcc: rewrite type tests

Diffstat:
Mfs/tests/comp/c/all.fs | 2+-
Mfs/tests/comp/c/type.fs | 98+++++++++++++++++++++++++++++++++++++++++--------------------------------------
2 files changed, 52 insertions(+), 48 deletions(-)

diff --git a/fs/tests/comp/c/all.fs b/fs/tests/comp/c/all.fs @@ -1,4 +1,4 @@ \ Run all CC test suites -\ f<< tests/comp/c/type.fs +f<< tests/comp/c/type.fs f<< tests/comp/c/cc.fs \ f<< tests/comp/c/lib.fs diff --git a/fs/tests/comp/c/type.fs b/fs/tests/comp/c/type.fs @@ -4,11 +4,9 @@ testbegin \ Tests for CC types TYPE_VOID typesize 0 #eq -TYPE_VOID* typesize 4 #eq TYPE_CHAR typesize 1 #eq -TYPE_CHAR* typesize 4 #eq -: printstruct CType :.struct ; +: printstruct CDecl :.struct ; \ with parseType, we systematically "peek" 1 token in stdin, which is why we \ always end our test input with "STOP". : _parse nextt parseType # nextt S" STOP" #s= ; @@ -20,13 +18,15 @@ _parse void STOP TYPE_VOID #eq _parse struct Struct1 { unsigned int foo; short *bar; char baz[2]; } STOP ( type ) dup typesize 10 #eq -S" bar" over CType :find - dup CType type TYPE_SHORT* #eq CType offset 4 #eq +S" bar" over CDecl :find + dup CDecl type TYPE_SHORT #eq + dup CDecl lvl 1 #eq + CDecl offset 4 #eq \ once defined, parseType will find the struct in typedefs _parse Struct1 STOP over #eq capture printstruct -S" struct Struct1 {unsigned int foo, +04 short* bar, +08 char baz[2], }" #s= +S" M struct Struct1 {N unsigned int foo, N +04 short* bar, N +08 char baz[2], }" #s= \ Anonymous structs work too _parse struct { int foo; } STOP typesize 4 #eq @@ -34,60 +34,64 @@ _parse struct { int foo; } STOP typesize 4 #eq \ And now, let's test parseDeclarator : _parse nextt parseType # parseDeclarator nextt S" STOP" #s= ; _parse int *foo STOP -dup CType type TYPE_INT* #eq -CType name S" foo" #s= +dup CDecl type TYPE_INT #eq +dup CDecl lvl 1 #eq +CDecl name S" foo" #s= _parse unsigned int *foo STOP -dup CType type TYPE_UINT* #eq -CType name S" foo" #s= +dup CDecl type TYPE_UINT #eq +dup CDecl lvl 1 #eq +CDecl name S" foo" #s= _parse unsigned short ***foo STOP -CType type -dup type*lvl 3 #eq dup typeunsigned? # -type*lvl- type*lvl- type*lvl- typesize 2 #eq +dup CDecl type $a ( ushort ) #eq +dup CDecl lvl 3 #eq +dup CDecl type typeunsigned? # +CDecl type typesize 2 #eq _parse int *foo[42] STOP -dup CType type TYPE_INT* #eq -dup CType nbelem 42 #eq -CType name S" foo" #s= +dup CDecl type TYPE_INT #eq +dup CDecl lvl 1 #eq +dup CDecl nbelem 42 #eq +CDecl name S" foo" #s= -_parse int (*foo)[42] STOP -dup CType type ctype? # -dup CType type type*lvl 1 #eq -dup CType nbelem 0 #eq -dup CType name S" foo" #s= -CType type ctype' -dup CType type TYPE_INT #eq -dup CType nbelem 42 #eq -CType name NULLSTR #s= +\ TODO: This test is not working. It's supposed to yield a pointer to an array +\ of 42 ints, not an array of 42 pointers to ints. +\ _parse int (*foo)[42] STOP +\ dup CDecl type TYPE_INT # +\ dup CDecl type lvl 1 #eq +\ dup CDecl nbelem 0 #eq +\ dup CDecl name S" foo" #s= +\ CDecl type +\ dup CDecl type TYPE_INT #eq +\ dup CDecl nbelem 42 #eq +\ CDecl name NULLSTR #s= _parse unsigned int (*foo)(char,short) STOP -dup CType :funcptr? # -dup CType name S" foo" #s= -CType type ctype' -dup CType type TYPE_UINT #eq -CType nexttype -dup CType type TYPE_CHAR #eq -dup CType offset 4 #eq \ PS args are always 4b in size -CType nexttype -dup CType type TYPE_SHORT #eq -CType offset 0 #eq +dup CDecl :funcsig? # +dup CDecl name S" foo" #s= +dup CDecl type TYPE_UINT #eq +CDecl args +dup CDecl type TYPE_CHAR #eq +dup CDecl offset 4 #eq \ PS args are always 4b in size +llnext +dup CDecl type TYPE_SHORT #eq +CDecl offset 0 #eq \ We can also have a function signature with argument names. _parse unsigned int (*foo)(short bar,char baz) STOP -dup CType :funcptr? # -dup CType name S" foo" #s= -CType type ctype' -CType nexttype -dup CType name S" bar" #s= -dup CType type TYPE_SHORT #eq -dup CType offset 4 #eq -CType nexttype -dup CType name S" baz" #s= -dup CType type TYPE_CHAR #eq -CType offset 0 #eq +dup CDecl :funcsig? # +dup CDecl name S" foo" #s= +CDecl args +dup CDecl name S" bar" #s= +dup CDecl type TYPE_SHORT #eq +dup CDecl offset 4 #eq +llnext +dup CDecl name S" baz" #s= +dup CDecl type TYPE_CHAR #eq +CDecl offset 0 #eq _parse Struct1 *mystructptr STOP capture printtype -S" struct Struct1* mystructptr" #s= +S" M M struct Struct1* mystructptr" #s= testend