Add catch/throw
[preForth.git] / README.md
1 # Bootstrapping Forth
2
3 ## preForth
4
5 preForth is a minimal non-interactive Forth kernel that can bootstrap itself and can be used as an easy-to-port basis for a full Forth implementation.
6
7 preForth feels like Forth - it's mainly a sublanguage of ANS-Forth - but is significantly reduced in its capabilities.
8
9 ### Features: minimal control structures, no immediate words, strings on stack, few primitives
10
11 just
12
13 - Stack
14 - Returnstack
15 - Only ?exit and recursion as control structures
16 - :-definitions
17 - optional tail call optimization
18 - IO via KEY/EMIT
19 - signed single cell decimal numbers (0-9)+
20 - character constants via 'c'-notation
21 - output single cell decimal numbers
22
23 and
24
25 - no immediate words, i.e.
26 - no control structures IF ELSE THEN BEGIN WHILE REPEAT UNTIL
27 - no defining words
28 - no DOES>
29 - no memory @ ! CMOVE ALLOT ,
30 - no pictured numeric output
31 - no input stream
32 - no state
33 - no base
34 - no dictionary, no EXECUTE, not EVALUATE
35 - no CATCH and THROW
36 - no error handling
37
38 ### Prerequisites:
39
40   Just 13 primitives: emit key dup swap drop 0< ?exit >r r> - nest unnest lit
41
42 ## simpleForth
43
44 simpleForth is an extension to preForth built using preForth. It is still non-interactive but adds 
45
46 - control structures IF ELSE THEN BEGIN WHILE REPEAT UNTIL
47 - definitions with and without headers in generated code
48 - memory: @ ! c@ c! allot c, , 
49 - variable, constants
50 - ['] execute
51 - immediate definitions
52
53 ## Forth
54
55 Forth is a simple interactive Forth system built using simpleForth.
56 Forth is open ended and has a yet incomplete set of features. Work in progress.
57
58
59 # How to use:
60
61 An i386-Backend (32Bit) indirect threaded code implementation based on [FASM](https://flatassembler.net/) is pre-configured.
62 PreForth initially bootstraps on with [gforth](https://www.gnu.org/software/gforth/) or [swiftForth](https://www.forth.com/swiftforth/). 
63 You'll need one of these for the first bootstrap.
64
65     cd preForth
66     make
67
68 This will successively compile preForth, simpleForth, then Forth.
69
70 If successful issue
71
72     $ ./Forth
73
74     Forth 1.2.0
75
76     last * warm cold empty patch minor major banner quit restart REPEAT WHILE AGAIN 
77     UNTIL BEGIN THEN ELSE IF ; : constant variable header cmove compile, , allot here 
78     dp +! clearstack interpret parse-name \ .( ( parse (interpreters ?word (compilers ,word 
79     immediate !flags @flags or and #immediate ] [ interpreters compilers handlers ,'x' ?'x' 
80     ,# ?# scan skip source /string >in query #tib tib accept min words .name l>interp l>name 
81     l>flags type count cell+ cells find-name .s prefix? compare 2dup 2drop rot off on ?dup + 
82     space bl cr . u. negate > 1- nip = 0= pick 1+ < over depth execute c! ! c@ @ ?branch 
83     branch lit exit unnest - r> >r ?exit 0< drop swap dup key emit bye 
84
85 Inspect sources and generated files.
86
87 *Have fun. May the Forth be with you.*
88