MakoForth is a small Forth dialect which should be moderately familiar to anyone who has been exposed to ANS-Forth. The major notable differences are the use of #
as line comments, loop...(break)...again|until|while
looping constructs and the inclusion of syntax for inline double-quoted string constants. Cells are always 32-bit two's complement signed integers.
a
,b
andn
are signed 32-bit numbers (or any value)str
is the address of a null (0) terminated stringf
is a bit-flag- 0 for false and -1 for trueaddr
generally refers to an address
Words with starred stack effects are immediate and will execute when encountered rather than being compiled.
+
( a b -- n )
adda
tob
-
( a b -- n )
subtractb
froma
*
( a b -- n )
multiplya
byb
/
( a b -- n )
dividea
byb
mod
( a b -- n )
compute the modulus ofa
byb
and
( a b -- n )
bitwise andor
( a b -- n )
bitwise orxor
( a b -- n )
bitwise xornot
( a -- n )
bitwise not<
( a b -- f )
isa
less thanb
?>
( a b -- f )
isa
greater thanb
?!
( n addr -- )
write valuen
to an address in memory@
( addr -- n )
read a value from an address in memorydup
( a -- a a )
duplicate the top stack elementover
( a b -- a b a )
duplicate the second stack elementdrop
( a -- )
discard the top stack elementswap
( a b -- b a )
exchange the top stack elements>r
( n -- )
move the top stack element to the rstackr>
( -- n )
move the top rstack element to the stacki
( -- n )
copy the top rstack element to the stackj
( -- n )
copy the second rstack element to the stackhere
( -- addr )
obtain the address of a var containing the end of the dictionarymode
( -- f )
obtain true if compiling, false if interpreting,
( n -- )
append a value to the dictionary and advancehere
]
( -- )
switch to compiling mode[
( -- )*
switch to interpreting modeimmediate
( -- )
make the last defined word immediateliteral
( n -- )*
compile a constant on the stack into the dictionary definitioncreate
( -- )
read a name from the input stream and make a new dictionary entryexit
( -- )*
compile a return but stay in compiling mode:
( -- )
essentiallycreate ]
- define a procedure;
( -- )*
terminate the current dictionary definitionif
( -- )*
compile anif
(takes an argument from the stack)then
( -- )*
complete anif
statement.else
( -- )*
place betweenif
andthen
optionallyloop
( -- )*
create the head of a loopagain
( -- )*
complete aloop
and branch back unconditionallywhile
( -- )*
complete aloop
and branch back if a stack value is trueuntil
( -- )*
complete aloop
and branch back if a stack value is falsebreak
( -- )*
unconditionally exit the currentloop
'
( -- )*
compile a literal giving the address of a named worddoes>
( -- )
assign the remainder of this definition as behavior for the current word
.
( n -- )
print a signed number followed by a spacespace
( -- )
print a spacecr
( -- )
print a carriage returntype
( str -- )
print a stringtypeln
( str -- )
print a string and a carriage return
forget
( -- )
read a name and forget it and all following wordsfree
( -- )
print remaining free dictionary spacesee
( -- )
read a name and print a dissassembly of that word#
( -- )*
ignore input until a newline- line comment(
( -- )*
ignore input until a)
- block commentstack
( -- )
print the contents of the stackwords
( -- )
print a list of all dictionary entries