commit 718fe39374067606dbf90ad2fad69c516f605bd7
parent ecadd6f6a4f2a201c80e9e5f04bae954309ed5eb
Author: Virgil Dupras <hsoft@hardcoded.net>
Date: Thu, 6 Oct 2022 09:24:38 -0400
cc: fix tokenization bug with /**/ comments
Diffstat:
3 files changed, 13 insertions(+), 11 deletions(-)
diff --git a/fs/app/cos/cvm.c b/fs/app/cos/cvm.c
@@ -27,9 +27,8 @@ struct COSVM {
word PC; /* Program Counter for bytecode interpreter */
/* Array of 0x100 function pointers to IO read and write routines. Leave to
* NULL when IO port is unhandled. */
-// Compiles up to this point!
- IORD iord[0x100];
- IOWR iowr[0x100];
+ IORD iord[$100];
+ IOWR iowr[$100];
/* Used for keeping track of max RS and min SP during the lifetime of the
* program. Useful for debugging. */
word maxRS;
@@ -45,7 +44,7 @@ struct File { // TODO: create system C header
unsigned int pos;
unsigned int size;
void *_seek;
-}
+};
static COSVM vm;
static File *blkfp;
@@ -54,11 +53,13 @@ static File *blkfp;
* processing the cmd, we reset blkop to 0. */
static byte blkop[ #[ BLKOP_CMD_SZ c]# ];
-/* Read single byte from I/O handler, if set. addr is a word only because of */
-/* Forth's cell size, but can't actually address more than a byte-full of ports. */
+/* Read single byte from I/O handler, if set. addr is a word only because of
+ Forth's cell size, but can't actually address more than a byte-full of ports.
+*/
+// Compiles up to this point!
static byte io_read(word addr)
{
- addr &= 0xff;
+ addr &= $ff;
IORD fn = vm.iord[addr];
if (fn != NULL) {
return fn();
@@ -70,13 +71,13 @@ static byte io_read(word addr)
static void io_write(word addr, byte val)
{
- addr &= 0xff;
+ addr &= $ff;
IOWR fn = vm.iowr[addr];
if (fn != NULL) {
fn(val);
} else {
fprintf(
- addr, val, val, "Out of bounds I/O write: %d / %d (0x%x)\n",
+ addr, val, val, "Out of bounds I/O write: %d / %d (%x)\n",
ConsoleOut());
}
}
diff --git a/fs/cc/tok.fs b/fs/cc/tok.fs
@@ -77,8 +77,7 @@ create _ 10 c, ," 09AZaz__$$"
else ( c1 c2 ) StdIn IO :putback 1 ( c1 len ) _writesym then ( tok )
dup case
S" /*" of s= drop begin ( )
- nextt? dup not if ( EOF! ) rdrop exit then ( tok ) S" */" s= until
- nextt? endof
+ stdin '*' = dup if drop stdin '/' = then until nextt? endof
S" //" of s= drop begin ( )
stdin dup not if ( EOF! ) rdrop exit then LF = until
nextt? endof
diff --git a/fs/tests/cc/test.c b/fs/tests/cc/test.c
@@ -262,3 +262,5 @@ int binop2(int n) {
x = x + n - '0';
return x;
}
+/* There used to be a bug where this type of comment with "'" char in it would
+ cause a tokenization error. */