Skip to content

Liorst4/liorforth

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 -> 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
	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+
	Floating point extension:
		 F.
	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)
		>=
		<=

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 `Return` opcode using a primitive.
       Merge the `BranchOnFalse` and `Branch` opcodes.
       Implement the `Branch` opcode using a primitive.

       Move the dictionary to the data space.
       no_std for the core code. Use traits for a standard target.

       Floating point word set
       Exception word set

       Image system:
       	     Save and load the state of the current running program from disk.
	     Textual image format, for version control!

       Debugger
       FFI