mirror of
https://github.com/hsoft/collapseos.git
synced 2024-11-23 16:08:06 +11:00
xcomp: add XPACK
This commit is contained in:
parent
389b23fe1a
commit
13771d8c92
6
blk/267
Normal file
6
blk/267
Normal 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
16
blk/268
Normal 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+ !
|
||||
;
|
@ -18,7 +18,8 @@
|
||||
: BEGIN H@ ; IMMEDIATE
|
||||
: AGAIN 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?
|
||||
Ah, voice at last! Some lines above need comments
|
||||
BTW: Forth lines limited to 64 cols because of default
|
||||
@ -27,6 +28,8 @@
|
||||
"_": words starting with "_" are meant to be "private",
|
||||
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
|
||||
LITA: 36 == addrWord
|
||||
COMPILE: Tough one. Get addr of caller word (example above
|
||||
|
@ -13,7 +13,7 @@ by more than once space or by a newline. Hackish, but works.
|
||||
|
||||
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 c;
|
||||
c = getchar();
|
||||
@ -24,7 +24,7 @@ int main()
|
||||
// doesn't like when they're not there...
|
||||
putchar(c);
|
||||
}
|
||||
spccnt += 2;
|
||||
spccnt += 1;
|
||||
} else if (c == ' ') {
|
||||
spccnt++;
|
||||
} else {
|
||||
@ -33,7 +33,7 @@ int main()
|
||||
incomment = 0;
|
||||
}
|
||||
} else {
|
||||
if ((c == '(') && (spccnt > 1)) {
|
||||
if ((c == '(') && spccnt) {
|
||||
putchar(' ');
|
||||
spccnt = 0;
|
||||
int next = getchar();
|
||||
|
Loading…
Reference in New Issue
Block a user