commit 7163e7b1fd80b1f4a40759c5cd2b51439b5b7d55
parent 561f6b929c31118aa84d27e6c3a406fa89ebb549
Author: Virgil Dupras <hsoft@hardcoded.net>
Date: Wed, 30 Nov 2022 15:41:25 -0500
comp/c: allow static initialization of non-int arrays
This fixes ar/puff which didn't work properly on dynamic blocks.
Diffstat:
3 files changed, 12 insertions(+), 3 deletions(-)
diff --git a/fs/comp/c/pgen.fs b/fs/comp/c/pgen.fs
@@ -416,9 +416,12 @@ create _constarray MAXCONSTARRAYLEN 1+ CELLSZ * allot
dup CType name NEXTWORD ! create then ( ctype )
here over to CType offset ( ctype )
'=' readChar? if ( ctype )
- parseDeclInit vmop loc case
+ parseDeclInit vmop loc case ( ctype )
VM_CONSTANT of = vmop arg , endof
- VM_CONSTARRAY of = vmop arg @+ CELLSZ * move, endof
+ VM_CONSTARRAY of = dup CType type typesize case
+ 1 of = vmop arg @+ >r begin @+ c, next drop endof
+ 2 of = vmop arg @+ >r begin @+ 16b , next drop endof
+ vmop arg @+ CELLSZ * move, endcase endof
_err endcase ops$
else to nexttputback dup CType :size allot then ( ctype )
',' readChar? if
diff --git a/fs/tests/comp/c/cc.fs b/fs/tests/comp/c/cc.fs
@@ -38,6 +38,7 @@ array 52 #eq
global 1234 #eq
globalinc 1236 #eq
globalinc 1238 #eq
+1 globalshort 2 #eq
42 142 sysword 142 #eq
42 142 funcsig 142 #eq
capture helloworld S" Hello World!" #s=
diff --git a/fs/tests/comp/c/test.c b/fs/tests/comp/c/test.c
@@ -147,6 +147,12 @@ int globalinc() {
global1++;
return ++global1;
}
+// allow static init of non-int globals
+static short shortarray[3] = {1, 2, 3};
+short globalshort(int idx) {
+ return shortarray[idx];
+}
+
// "max" is a forth word defined in the system
int sysword(int a, int b) {
return max(a, b);
@@ -446,7 +452,6 @@ SixBytes* ptrari5() {
globstructarray[1].foo = 42;
return globstructarray;
}
-
// unary op, apart from ++ and --, *don't* modify their target.
int unaryop1(int n) {
!n;