xcomp: add XPACK

This commit is contained in:
Virgil Dupras 2020-04-25 15:43:07 -04:00
parent 389b23fe1a
commit 13771d8c92
5 changed files with 30 additions and 5 deletions

View File

@ -1 +1 @@
263 LOAD 265 LOAD 263 LOAD 265 LOAD 268 LOAD

6
blk/267 Normal file
View File

@ -0,0 +1,6 @@
XPACK - pack source code
The goal of this word is to pack source code in tight places,
such as on the boot section of an EEPROM. It takes a block
number, reads it and packs it to HERE. It normalizes all
whitespaces to a single space and ignore comments.

16
blk/268 Normal file
View File

@ -0,0 +1,16 @@
: XPACK ( blkno -- )
BLK@
BLK( 0x2e RAM+ ! ( boot ptr )
['] (boot<) 0x08 RAM+ ! ( C<* override )
BEGIN
WORD
0x2e RAM+ @ BLK( 1024 + < IF
DUP LIT< ( S= IF
DROP [COMPILE] (
ELSE
SCPY 0x20 H@ 1- C!
THEN 0 ( loop again )
ELSE 1 ( stop looping ) THEN
UNTIL
0 0x08 RAM+ !
;

View File

@ -18,7 +18,8 @@
: BEGIN H@ ; IMMEDIATE : BEGIN H@ ; IMMEDIATE
: AGAIN COMPILE (br) H@ - , ; IMMEDIATE : AGAIN COMPILE (br) H@ - , ; IMMEDIATE
: UNTIL COMPILE (?br) H@ - , ; IMMEDIATE : UNTIL COMPILE (?br) H@ - , ; IMMEDIATE
: ( BEGIN LIT< ) WORD S= UNTIL ; IMMEDIATE : _ BEGIN LIT< ) WORD S= UNTIL ; IMMEDIATE
40 CURRENT @ 4 - C!
( Hello, hello, krkrkrkr... do you hear me? ( Hello, hello, krkrkrkr... do you hear me?
Ah, voice at last! Some lines above need comments Ah, voice at last! Some lines above need comments
BTW: Forth lines limited to 64 cols because of default BTW: Forth lines limited to 64 cols because of default
@ -27,6 +28,8 @@
"_": words starting with "_" are meant to be "private", "_": words starting with "_" are meant to be "private",
that is, only used by their immediate surrondings. that is, only used by their immediate surrondings.
40 is ASCII for '('. We do this to simplify XPACK's task of
not mistakenly consider '(' definition as a comment.
LITS: 34 == litWord LITS: 34 == litWord
LITA: 36 == addrWord LITA: 36 == addrWord
COMPILE: Tough one. Get addr of caller word (example above COMPILE: Tough one. Get addr of caller word (example above

View File

@ -13,7 +13,7 @@ by more than once space or by a newline. Hackish, but works.
int main() int main()
{ {
int spccnt = 2; // if the first char is a (, consider it a comment opener. int spccnt = 1; // if the first char is a (, consider it a comment opener.
int incomment = 0; int incomment = 0;
int c; int c;
c = getchar(); c = getchar();
@ -24,7 +24,7 @@ int main()
// doesn't like when they're not there... // doesn't like when they're not there...
putchar(c); putchar(c);
} }
spccnt += 2; spccnt += 1;
} else if (c == ' ') { } else if (c == ' ') {
spccnt++; spccnt++;
} else { } else {
@ -33,7 +33,7 @@ int main()
incomment = 0; incomment = 0;
} }
} else { } else {
if ((c == '(') && (spccnt > 1)) { if ((c == '(') && spccnt) {
putchar(' '); putchar(' ');
spccnt = 0; spccnt = 0;
int next = getchar(); int next = getchar();