This commit is contained in:
Brad Nelson
2020-12-30 12:51:05 -08:00
parent bc9ac61d5d
commit f382cff852
9 changed files with 66 additions and 19 deletions

2
.gitignore vendored
View File

@ -1 +1 @@
forth
ueforth/out

View File

@ -1,6 +0,0 @@
forth: forth.c
CFLAGS=-O2 -Wall -Werror
clean:
rm -f forth

33
README.md Normal file
View File

@ -0,0 +1,33 @@
# The many faces of EForth
EForth is delightfully minimalist approach to Forth originated by Bill Muench and Dr. C. H. Ting.
In its original form metacompilation is avoided.
## Directories
* reference/ - EForth Reference Material
* circleforth/ - A minimalist Forth modeled after toy Lisps.
* ueforth/ - micro EForth - EForth refactored to allow source boostraping.
## EForth Quirks
EForth uses `FOR..NEXT` in favor of `DO..LOOP`:
[FOR/NEXT](https://github.com/TG9541/stm8ef/wiki/eForth-FOR-..-NEXT).
This construct has the odd property that it iterates one "extra" time for zero.
```
: FOO 10 FOR R@ . NEXT ; FOO
10 9 8 7 6 5 4 3 2 1 0 ok
```
To permit a more ordinary loop the `AFT` word is used in the sequence `FOR..AFT..THEN..NEXT`.
```
: FOO 10 FOR ( 1st time only ) AFT R@ . THEN NEXT ; FOO
9 8 7 6 5 4 3 2 1 0 ok
```
The even more enigmatic `FOR..WHILE..NEXT..ELSE..THEN` is used in place of `DO..LEAVE..LOOP`.
It allows a while condition to early out of a counted loop.

6
circleforth/README.md Normal file
View File

@ -0,0 +1,6 @@
# Circleforth
Created as an example of a minimalist Forth in the style of typical "toy" Lisp implementations.
Similar to classic "Eval-Apply" style Lisps, the core problem of reimplementing the core interpreter
is approached on top of an existing Forth. Primitives are reused, and crucially parsing is reused.

View File

@ -1,3 +1,5 @@
( EForth High Level Definitions )
( Variables and User Variables )
: doVAR ( -- a ) R> ;

12
ueforth/Makefile Normal file
View File

@ -0,0 +1,12 @@
all: out/ueforth
out:
mkdir -p out
out/ueforth: ueforth.c | out
$(CC) $(CFLAGS) $< -o $@
CFLAGS=-O2 -Wall -Werror
clean:
rm -rf out/

View File

@ -198,18 +198,6 @@ static const char boot[] =
" : throw handler @ rp! r> handler ! r> swap >r sp! drop r> ; "
" ' throw 'throw ! "
// Examine Dictionary
" : >name ( xt -- a n ) 3 cells - dup @ swap over aligned - swap ; "
" : >link ( xt -- a ) 2 cells - @ ; "
" : >body ( xt -- a ) cell+ ; "
" : see. ( xt -- ) >name type space ; "
" : see-one ( xt -- xt+1 ) "
" dup @ dup ['] DOLIT = if drop cell+ dup @ . else see. then cell+ ; "
" : exit= ( xt -- ) ['] exit = ; "
" : see-loop >body begin see-one dup @ exit= until ; "
" : see cr ['] : see. ' dup see. see-loop drop ['] ; see. cr ; "
" : words last @ begin dup see. >link dup 0= until drop cr ; "
// Numeric Output
" variable hld "
" : pad ( -- a ) here 80 + ; "
@ -234,6 +222,18 @@ static const char boot[] =
" : $@ r@ dup cell+ swap @ r> dup @ aligned + cell+ >r ; "
" : s\" [char] \" parse postpone $@ dup , 0 do dup c@ c, 1+ loop drop align ; immediate "
// Examine Dictionary
" : >name ( xt -- a n ) 3 cells - dup @ swap over aligned - swap ; "
" : >link ( xt -- a ) 2 cells - @ ; "
" : >body ( xt -- a ) cell+ ; "
" : see. ( xt -- ) >name type space ; "
" : see-one ( xt -- xt+1 ) "
" dup @ dup ['] DOLIT = if drop cell+ dup @ . else see. then cell+ ; "
" : exit= ( xt -- ) ['] exit = ; "
" : see-loop >body begin see-one dup @ exit= until ; "
" : see cr ['] : see. ' dup see. see-loop drop ['] ; see. cr ; "
" : words last @ begin dup see. >link dup 0= until drop cr ; "
// ( Input )
" : accept ( a n -- n ) 0 swap begin 2dup < while "
" key dup nl = if 2drop nip exit then "