From 125d76e05922681df0ea8c80582faf55c454a6fa Mon Sep 17 00:00:00 2001 From: crc Date: Tue, 26 Mar 2019 14:26:06 +0000 Subject: [PATCH] new build options for reduced memory footprint FossilOrigin-Name: 3840737baf324f7716e539da1c8711f17fec0fbe4926dafdec0cd544a725c3ec --- RETRO-Book.md | 22 ++++++++++++ book/Advanced-Builds | 22 ++++++++++++ doc/Cross-Reference.md | 68 +++++++++++++----------------------- interfaces/image-functions.h | 52 +++++++++++++++++++++++++++ 4 files changed, 120 insertions(+), 44 deletions(-) diff --git a/RETRO-Book.md b/RETRO-Book.md index 9a242df..d10e3d8 100644 --- a/RETRO-Book.md +++ b/RETRO-Book.md @@ -2351,6 +2351,28 @@ Output is written to stdout; redirect as neeeded. # Advanced Builds +## Reduced Memory + +RETRO can be built for reduced memory targets. This is primarily +intendeded for use with embedded targets, but can be useful on +large machines as well. + +To do this, `make` with `CFLAGS` set to `-DMEM1024K`, `-DMEM512K`, +`-DMEM256K`, `-DMEM192K`, `-DMEM128K`' or `-DMEM96K`. These will +target memory sizes as specified per the following table. + +| | 1024kB | 512kB | 256kB | 192kB | 128kB | 96kB | +| ------------- | --------- | ------- | ------- | ------- | ------- | ------ | +| Total Bytes | 1,048,579 | 524,288 | 262,144 | 196,608 | 131,072 | 98,304 | +| Image | 968,000 | 384,000 | 192,000 | 126,000 | 96,000 | 72,000 | +| Data Stack | 512 | 512 | 512 | 512 | 512 | 512 | +| Address Stack | 1,024 | 1,024 | 1,024 | 1,024 | 1,024 | 1,024 | +| Remaining | 79,040 | 138,752 | 68,608 | 69,072 | 33,536 | 24,768 | + +The remaining memory is available for use by the VM. + +## Custom Image + For users of BSD, Linux, macOS, you can customize the image at build time. diff --git a/book/Advanced-Builds b/book/Advanced-Builds index 28b1869..4ebff01 100644 --- a/book/Advanced-Builds +++ b/book/Advanced-Builds @@ -1,5 +1,27 @@ # Advanced Builds +## Reduced Memory + +RETRO can be built for reduced memory targets. This is primarily +intendeded for use with embedded targets, but can be useful on +large machines as well. + +To do this, `make` with `CFLAGS` set to `-DMEM1024K`, `-DMEM512K`, +`-DMEM256K`, `-DMEM192K`, `-DMEM128K`' or `-DMEM96K`. These will +target memory sizes as specified per the following table. + +| | 1024kB | 512kB | 256kB | 192kB | 128kB | 96kB | +| ------------- | --------- | ------- | ------- | ------- | ------- | ------ | +| Total Bytes | 1,048,579 | 524,288 | 262,144 | 196,608 | 131,072 | 98,304 | +| Image | 968,000 | 384,000 | 192,000 | 126,000 | 96,000 | 72,000 | +| Data Stack | 512 | 512 | 512 | 512 | 512 | 512 | +| Address Stack | 1,024 | 1,024 | 1,024 | 1,024 | 1,024 | 1,024 | +| Remaining | 79,040 | 138,752 | 68,608 | 69,072 | 33,536 | 24,768 | + +The remaining memory is available for use by the VM. + +## Custom Image + For users of BSD, Linux, macOS, you can customize the image at build time. diff --git a/doc/Cross-Reference.md b/doc/Cross-Reference.md index aacfca7..a6d21b7 100644 --- a/doc/Cross-Reference.md +++ b/doc/Cross-Reference.md @@ -1,49 +1,29 @@ -# RETRO Cross Reference +# Forth to RETRO Cross Reference -Definitions ------------ -RETRO :name ; -ANS : name ; +This is a quick overview of some differences between RETRO +and traditional Forth. +| Category | Forth | RETRO | +| ---------------------- | ----------------------- | ----------------------------- | +| Definitions | `: name ;` | `:name ;` | +| Numbers | `100 -12` | `#100 #-12` | +| Characters (interpret) | `CHAR A CHAR D` | `$A $D` | +| Characters (compile) | `[CHAR] A [CHAR] D` | `$A $D` | +| Comments | `( This is a comment )` | `(This_is_a_comment)` | +| Pointers (interpret) | `' Compiler` | `&Compiler` | +| Pointers (compile) | `['] Compiler | `&Compiler` | +| Conditionals #1 | `IF 1 THEN` | `[ #1 ] if` | +| Conditionals #2 | `NOT IF 1 THEN` | `[ #1 ] -if` | +| Conditionals #3 | `IF 1 ELSE 2 THEN` | `[ #1 ] [ #2 ] choose` | +| Counted Loops | `10 0 DO LOOP` | `#10 [ ] times` | +| Counted Loops w/Index | `10 0 DO I LOOP` | `#10 [ I ] times` | +| Unconditional Loops | `BEGIN AGAIN` | `repeat again` | +| Return Stack | `10 >R ... R>` | `#10 push ... pop` | -Numbers -------- -RETRO #100 #-12 -ANS 100 -12 +RETRO conditionals and loops can be used outside of definitions, ANS ones can not. +Some forms are replaced by combinators. -Characters ----------- -RETRO $A $D -ANS CHAR A CHAR D - -RETRO :foo $A ; -ANS : foo [CHAR] A ; - - -Comments --------- -RETRO (This_is_a_comment) -ANS ( This is a comment ) - - -Pointers --------- -RETRO &Compiler -ANS ' Compiler -RETRO :foo &Heap ; -ANS : foo ['] Heap ; - - -Conditionals ------------- -RETRO (flag) [ 'TRUE ] if -ANS ( flag ) IF s" TRUE" THEN - -RETRO (flag) [ 'FALSE ] -if -ANS ( flag ) NOT IF s" FALSE" THEN - -RETRO (flag) [ 'TRUE ] [ 'FALSE ] choose -ANS ( flag ) IF s" TRUE" ELSE s" FALSE" THEN - -RETRO conditionals can be used outside of definitions, ANS ones can not. + FORTH + >R ... R> [ ... ] dip + DUP >R ... R> [ ... ] sip diff --git a/interfaces/image-functions.h b/interfaces/image-functions.h index f03f271..159ec22 100644 --- a/interfaces/image-functions.h +++ b/interfaces/image-functions.h @@ -20,10 +20,62 @@ #define D_OFFSET_NAME 3 #define CELL int32_t + #define IMAGE_SIZE 524288 * 8 #define STACK_DEPTH 4096 #define ADDRESSES STACK_DEPTH * 3 +#ifdef MEM1024K +#undef IMAGE_SIZE +#undef STACK_DEPTH +#undef ADDRESSES +#define IMAGE_SIZE 242000 +#define STACK_DEPTH 128 +#define ADDRESSES 256 +#else +#endif + +#ifdef MEM512K +#undef IMAGE_SIZE +#undef STACK_DEPTH +#undef ADDRESSES +#define IMAGE_SIZE 384000 +#define STACK_DEPTH 128 +#define ADDRESSES 256 +#else +#endif + +#ifdef MEM256K +#undef IMAGE_SIZE +#undef STACK_DEPTH +#undef ADDRESSES +#define IMAGE_SIZE 48000 +#define STACK_DEPTH 128 +#define ADDRESSES 256 +#else +#endif + +#ifdef MEM192K +#undef IMAGE_SIZE +#undef STACK_DEPTH +#undef ADDRESSES +#define IMAGE_SIZE 31500 +#define STACK_DEPTH 128 +#define ADDRESSES 256 +#else +#endif + +#ifdef MEM128K +#undef IMAGE_SIZE +#undef STACK_DEPTH +#undef ADDRESSES +#define IMAGE_SIZE 24000 +#define STACK_DEPTH 128 +#define ADDRESSES 256 +#else +#endif + + extern CELL sp, rp, ip; extern CELL data[STACK_DEPTH]; extern CELL address[ADDRESSES];