Trying to build a forth runtime in C
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 f23c8260c9
bigger stack
3 years ago
include bigger stack 3 years ago
src fix postpone 3 years ago
testfiles bigger stack 3 years ago
.gitignore new words 3 years ago
CMakeLists.txt many fixes using prelimtest 3 years ago
README.md many fixes and add some missing words 3 years ago
build.sh move to folders, more cleaning and fixes 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 essentially S\" blah" TYPE, but without allocation (unless compiled)
  • ?? - debug dump of the stacks
  • reset - everything should become like if you restarted the program
  • debug ( 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 (some may be wrong, like FM/MOD):

CORE:
! ' ( * */ */MOD + +! +LOOP , - . ." / /mod 0< 0= 1+ 1- 2! 2* 2/ 2@ 2DROP 2DUP 2OVER 2SWAP
: ; < = > >IN >R ?DUP @ 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 DROP DUP ELSE EMIT ENVIRONMENT? EXECUTE EXIT FM/MOD FIND
HERE I IF IMMEDIATE INVERT J LEAVE LITERAL LOOP LSHIFT M* MAX MIN MOD NEGATE OR OVER POSTPONE QUIT R> R@ RECURSE
REPEAT ROT RSHIFT S>D S" SM/REM SOURCE SPACE STATE SWAP THEN TYPE U< UNTIL UM* UM/MOD UNLOOP VARIABLE WHILE WORD XOR [ ['] [CHAR] ] 

CORE-EXT:
.( 0<> 0> 2>R 2R> 2R@ <> ?DO AGAIN FALSE HEX NIP PAD PICK ROLL S\" TO TRUE TUCK U.R U> UNUSED VALUE
\

Other sets:
FORGET SEE BYE

Missing:

basically, CASE-OF, pictured numbers, keyboard input, some weirder metaprogramming things, manipulating the input buffer.

CORE:
# #> #S <# >BODY >NUMBER ABORT" ACCEPT DOES> EVALUATE FILL HOLD KEY MOVE SIGN SPACES U.

CORE-EXT:
.R :NONAME ACTION-OF BUFFER: C" CASE COMPILE, DEFER DEFER! DEFER@ ENDCASE ENDOF ERASE HOLDS IS
MARKER OF PARSE PARSE-NAME REFILL RESTORE-INPUT SAVE-INPUT SOURCE-ID WITHIN [COMPILE]

.