2020-03-07 12:13:15 -05:00
|
|
|
Stack notation: "<stack before> -- <stack after>". Rightmost is top of stack
|
|
|
|
(TOS). For example, in "a b -- c d", b is TOS before, d is TOS
|
|
|
|
after. "R:" means that the Return Stack is modified.
|
|
|
|
|
2020-03-07 22:18:14 -05:00
|
|
|
DOES>: Used inside a colon definition that itself uses CREATE, DOES> transforms
|
|
|
|
that newly created word into a "does cell", that is, a regular cell (
|
|
|
|
when called, puts the cell's addr on PS), but right after that, it
|
|
|
|
executes words that appear after the DOES>.
|
|
|
|
|
|
|
|
"does cells" always allocate 4 bytes (2 for the cell, 2 for the DOES>
|
|
|
|
link) and there is no need for ALLOT in colon definition.
|
|
|
|
|
|
|
|
At compile time, colon definition stops processing words when reaching
|
|
|
|
the DOES>.
|
|
|
|
|
|
|
|
Example: ": CONSTANT CREATE HERE @ ! DOES> @ ;"
|
|
|
|
|
2020-03-07 21:12:30 -05:00
|
|
|
*** Native Words ***
|
|
|
|
|
2020-03-09 08:49:51 -04:00
|
|
|
: x ... -- Define a new word
|
|
|
|
; R:I -- Exit a colon definition
|
2020-03-07 17:09:45 -05:00
|
|
|
. n -- Print n in its decimal form
|
|
|
|
@ a -- n Set n to value at address a
|
|
|
|
! n a -- Store n in address a
|
2020-03-07 19:42:07 -05:00
|
|
|
+ a b -- c a + b -> c
|
|
|
|
- a b -- c a - b -> c
|
|
|
|
* a b -- c a * b -> c
|
|
|
|
/ a b -- c a / b -> c
|
2020-03-07 22:23:08 -05:00
|
|
|
CREATE x -- Create cell named x. Doesn't allocate a PF.
|
2020-03-07 22:18:14 -05:00
|
|
|
DOES> -- See description at top of file
|
2020-03-07 21:12:30 -05:00
|
|
|
DUP a -- a a
|
2020-03-09 14:19:51 -04:00
|
|
|
ELSE -- Branch to THEN
|
2020-03-07 12:13:15 -05:00
|
|
|
EMIT c -- Spit char c to stdout
|
|
|
|
EXECUTE a -- Execute word at addr a
|
2020-03-07 17:09:45 -05:00
|
|
|
HERE -- a Push HERE's address
|
2020-03-09 14:19:51 -04:00
|
|
|
IF n -- Branch to ELSE or THEN if n is zero
|
2020-03-07 17:09:45 -05:00
|
|
|
QUIT R:drop -- Return to interpreter promp immediately
|
2020-03-07 12:13:15 -05:00
|
|
|
KEY -- c Get char c from stdin
|
|
|
|
INTERPRET -- Get a line from stdin, compile it in tmp memory,
|
|
|
|
then execute the compiled contents.
|
2020-03-07 21:12:30 -05:00
|
|
|
OVER a b -- a b a
|
|
|
|
SWAP a b -- b a
|
2020-03-09 14:19:51 -04:00
|
|
|
THEN -- Does nothing. Serves as a branching merker for IF
|
|
|
|
and ELSE.
|
2020-03-07 21:12:30 -05:00
|
|
|
|
|
|
|
*** Core-but-Forth Words ***
|
|
|
|
|
|
|
|
? a -- Print value of addr a
|
|
|
|
+! n a -- Increase value of addr a by n
|
|
|
|
ALLOT n -- Move HERE by n bytes
|
2020-03-07 22:18:14 -05:00
|
|
|
CONSTANT x n -- Creates cell x that when called pushes its value
|
2020-03-07 22:23:08 -05:00
|
|
|
VARIABLE c -- Creates cell x with 2 bytes allocation.
|