A (work in progress) implementation of the forth programming language written
in Rust.
Project goals:
To write a forth implementation that follows the forth standard
(https://forth-standard.org/) and implements the core words.
To practice rust and forth
To have fun
License:
This project is distributed under GPLv3+, read the "COPYING" file
for more details.
Project structure:
src -> Rust source code
fth -> Forth source code
examples -> example forth code
Building:
cargo build
cargo run
Implemented words:
Core:
2dup
2drop
?dup
+!
/
space
cr
c,
,
bl
decimal
0=
0<
1-
1+
.s
bye
dup
drop
.
swap
over
nip
rot
min
max
abs
/mod
*/
*/mod
here
allot
@
!
c@
c!
emit
base
+
-
*
and
or
xor
mod
lshift
rshift
negate
invert
=
<
>
:
cells
r>
>r
r@
fill
u.
u<
move
cell+
depth
quit (partial, displays a ". ok" message)
>in
state
source
immediate
;
if
else
then
begin
until
while
repeat
exit
literal
create
variable
constant
align
aligned
postpone
char+
chars
spaces
(
[
]
char
[char]
2*
2/
2!
2@
word
count
type
."
s"
'
find
execute
>body
[']
2over
2swap
abort
abort"
environment? (partial, not all queries are available)
recurse
evaluate (partial, temporarily overwirtes input buffer instead of replacing it with the given string)
do
loop
unloop
leave
+loop
i
j
does> (experimental)
key (partial, requires the user to hit enter to register the input :\)
accept
s>d
m*
sm/rem
Core extension:
true
false
\
.(
.R
<>
0<>
0>
u>
nip
U.R
tuck
again
hex
2>R
2R>
2R@
unused
roll
buffer:
compile,
Exception:
catch (work in progress)
throw (work in progress)
Floating point:
F*
F+
F-
F/
F0<
F0=
F<
FDROP
FDUP
FOVER
FROT
FSWAP
FDEPTH
FLOOR
FROUND
FNEGATE
F@
F!
>FLOAT
D>F
F>D
FALIGN
FALIGNED
FLITERAL
FCONSTANT
FVARIABLE
FLOAT+
FLOATS
Floating point extension:
F.
FABS
FACOS
FACOSH
FALOG
FASIN
FASINH
FATAN
FATANH
FCOS
FCOSH
FEXP
FLN
FLOG
FSIN
FSINH
FTAN
FTANH
FSQRT
F**
FSINCOS
FEXPM1
FLNP1
FATAN2
F~
Facility extentsion:
BEGIN-STRUCTURE
+field
CFIELD:
FIELD:
FFIELD:
END-STRUCTURE
MS
Double:
2CONSTANT
2VARIABLE
2LITERAL
D=
D0=
D+
D-
D<
D0<
DMIN
DMAX
DNEGATE
DABS
D>S
D.R
D.
D2*
D2/
M+
M*/ (experimental)
Extra:
words
dump-row-size
dump
sizeof-cell
sizeof-char
nl
see
abort-with-message (used for abort")
select-compare (used for min and max)
>=
<=
froll
Core words to implement:
fm/mod
um*
um/mod
#
#>
#s
<#
hold
sign
>number
Floating point words to implement:
REPRESENT
What's next:
Some features I'll might implement in the future
Implement the `Next` opcode using a primitive.
Move the dictionary to the data space.
no_std for the core code. Use traits for a standard target.
Image system:
Save and load the state of the current running program from disk.
Textual image format, for version control!
Debugger
FFI