M fs/comp/c/egen.fs => fs/comp/c/egen.fs +4 -2
@@ 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# <>) ;
M fs/tests/comp/c/cc.fs => fs/tests/comp/c/cc.fs +1 -0
@@ 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
M fs/tests/comp/c/lib.fs => fs/tests/comp/c/lib.fs +1 -1
@@ 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
M fs/tests/comp/c/test.c => fs/tests/comp/c/test.c +6 -2
@@ 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;