From 13771d8c9225ea0ca1abe8a431946800d8f0db69 Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Sat, 25 Apr 2020 15:43:07 -0400 Subject: [PATCH] xcomp: add XPACK --- blk/262 | 2 +- blk/267 | 6 ++++++ blk/268 | 16 ++++++++++++++++ forth/core.fs | 5 ++++- tools/stripfc.c | 6 +++--- 5 files changed, 30 insertions(+), 5 deletions(-) create mode 100644 blk/267 create mode 100644 blk/268 diff --git a/blk/262 b/blk/262 index 4003147..bb7e6d5 100644 --- a/blk/262 +++ b/blk/262 @@ -1 +1 @@ -263 LOAD 265 LOAD +263 LOAD 265 LOAD 268 LOAD diff --git a/blk/267 b/blk/267 new file mode 100644 index 0000000..74a7e59 --- /dev/null +++ b/blk/267 @@ -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. diff --git a/blk/268 b/blk/268 new file mode 100644 index 0000000..57d20d5 --- /dev/null +++ b/blk/268 @@ -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+ ! +; diff --git a/forth/core.fs b/forth/core.fs index 981338f..fc98f78 100644 --- a/forth/core.fs +++ b/forth/core.fs @@ -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 diff --git a/tools/stripfc.c b/tools/stripfc.c index 01a224c..e994de5 100644 --- a/tools/stripfc.c +++ b/tools/stripfc.c @@ -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();