duskos

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

commit 502776783e8ef7de7f7c233d9b5a653433641f17
parent 3556a8d786a9e2c5ff23e0fe36023b096c313794
Author: Virgil Dupras <hsoft@hardcoded.net>
Date:   Sun,  2 Apr 2023 11:28:13 -0400

halcc: fix bug with pointer subtractions

All stdlib tests pass!

Diffstat:
Mfs/comp/c/egen.fs | 6++++--
Mfs/tests/comp/c/cc.fs | 1+
Mfs/tests/comp/c/lib.fs | 2+-
Mfs/tests/comp/c/test.c | 8++++++--
4 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/fs/comp/c/egen.fs b/fs/comp/c/egen.fs @@ -70,9 +70,11 @@ UOPSCNT wordtbl uoptbl ( res -- res ) : _/, _prep /, ; : _%, _prep %, ; : _<<, _prep <<, ; : _>>, _prep >>, ; +: _ptr-, ( left right -- res ) + _prep -, CELLSZ over Result :/n dup Result :toint ; : _-, ( left right -- res ) - over Result :*arisz >r _arimul - _prep -, r> ?dup if over Result :/n then dup Result :toint ; + over Result :*arisz over Result :*arisz tuck = swap CELLSZ = and if + _ptr-, else _arimul _prep -, then ; : _prep ( left right -- res halop ) Result :?freeCurrentW Result :?>W$ dup Result :hal# <>) ; diff --git a/fs/tests/comp/c/cc.fs b/fs/tests/comp/c/cc.fs @@ -118,6 +118,7 @@ to' myval unaryop2 to' myval #eq myval 42 #eq ptrari5 6 + @ 42 #eq 123 456 ptrari6 123 456 + #eq +$1234 2 ptrari7 $1238 #eq funcall1 138 #eq 42 funcall2 85 #eq 41 switch1 41 #eq diff --git a/fs/tests/comp/c/lib.fs b/fs/tests/comp/c/lib.fs @@ -62,6 +62,6 @@ foo # create myarray 3 , 7 , 8 , 5 , 2 , 1 , 9 , 5 , 4 , myarray 9 qsort create expected 1 , 2 , 3 , 4 , 5 , 5 , 7 , 8 , 9 , -\ myarray expected 9 CELLSZ * []= # +myarray expected 9 CELLSZ * []= # testend diff --git a/fs/tests/comp/c/test.c b/fs/tests/comp/c/test.c @@ -167,7 +167,7 @@ static char *msgs[1] = {"Hello World!"}; void helloworld() { stype(msgs[0]); } -void nullstr() { +char* nullstr() { return "Null terminated"0; } int forsum(int n) { @@ -498,12 +498,16 @@ SixBytes* ptrari5() { globstructarray[1].foo = 42; return globstructarray; } -// Assignment of a derfeferenced pointer into another dereferenced pointer +// Assignment of a dereferenced pointer into another dereferenced pointer int ptrari6(int a, int b) { int *pa = &a, *pb = &b; *pa += *pb; return *pa; } +// The "div by CELLSZ" logic used to trigger on the "-1" part. +int* ptrari7(int *a, uint offset) { + return a+offset-1; +} // unary op, apart from ++ and --, *don't* modify their target. int unaryop1(int n) { !n;