You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Ondřej Hruška
4efe5ffa86
|
3 years ago | |
---|---|---|
include | 3 years ago | |
src | 3 years ago | |
testfiles | 3 years ago | |
.gitignore | 3 years ago | |
CMakeLists.txt | 3 years ago | |
README.md | 3 years ago | |
build.sh | 3 years ago |
README.md
Forth
This is a new implementation of Forth 2012 in C.
Building & use
Use cmake or build.sh
. It probably needs GCC with --std=gnu99
.
You get a binary with the forth runtime. Run it to get a prompt. Use -h
for help.
Goals
- Comfy to use and extend
- No dynamic allocation where possible
- Compact and embeddable so it can be ported to ARM-CortexM or similar later
- Implement the CORE and CORE-EXT word sets, for a start
- Pass the Forth2012 test suite, at least for the word sets that are implemented
- Maybe eventually have some terminal-based implementation of (a subset of) the Facility word set, like AT-XY and keyboard input
- Try to keep added custom words and quirks at a minimum
- Comment stuff, maybe
Non-Goals
- I don't really care about implementing some of the word sets
- Performance is not so critical for a hobby Forth like this
- Probably won't accept merge requests, this is my Forth
- I also don't care about someone telling me to add a license file
Custom words
.\"
- like."
but allows escaping, this is essentiallyS\" blah" TYPE
, but without allocation (unless compiled)??
- debug dump of the stacksreset
- everything should become like if you restarted the programdebug ( flag -- )
- enable or disable verbose logging
For debug, there is see ( "word" -- )
that lets you inspect and disassemble dictionary entries.
Implementation status
(this section may be outdated)
Implemented and tested:
CORE:
! ' ( * */ */MOD + +! +LOOP , - . ." # #> #S <# >BODY >NUMBER / /mod 0< 0= 1+ 1- 2! 2* 2/ 2@ 2DROP 2DUP 2OVER 2SWAP
: ; < = > >IN >R ?DUP @ ABORT ABORT" ABS ALIGN ALIGNED ALLOT AND BASE BEGIN BL C! C, C@ CELL CELL+ CELLS CHAR CHAR+
CHARS CONSTANT COUNT CR CREATE DECIMAL DEPTH DO DOES> DROP DUP ELSE EMIT ENVIRONMENT? EVALUATE EXECUTE EXIT FILL FM/MOD FIND
HERE HOLD I IF IMMEDIATE INVERT J LEAVE LITERAL LOOP LSHIFT M* MAX MIN MOD MOVE NEGATE OR OVER POSTPONE QUIT R> R@ RECURSE
REPEAT ROT RSHIFT S>D S" SIGN SM/REM SOURCE SPACE SPACES STATE SWAP THEN TYPE U. U< UNTIL UM* UM/MOD UNLOOP VARIABLE WHILE WORD XOR [ ['] [CHAR] ]
CORE-EXT:
.( .R :NONAME 0<> 0> 2>R 2R> 2R@ <> ?DO ACTION-OF AGAIN BUFFER: C" CASE COMPILE, DEFER DEFER! DEFER@ ENDCASE ENDOF ERASE FALSE HEX HOLDS IS MARKER NIP OF PAD PARSE PARSE-NAME PICK REFILL RESTORE-INPUT SAVE-INPUT SOURCE-ID ROLL S\" TO TRUE TUCK U.R U> UNUSED VALUE WITHIN
\
Other sets:
FORGET SEE BYE INCLUDE INCLUDED
Missing:
CORE:
ACCEPT KEY
CORE-EXT:
[COMPILE]
.