1
0
mirror of https://github.com/hsoft/collapseos.git synced 2024-11-08 14:18:06 +11:00
collapseos/dictionary.txt

173 lines
8.3 KiB
Plaintext
Raw Normal View History

2020-04-06 06:11:17 +10:00
Be sure to read "usage.txt" for a guide to Collapse OS' Forth.
*** Glossary ***
2020-03-08 04:13:15 +11: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. "I:" prefix means "IMMEDIATE", that is, that
this stack transformation is made at compile time.
2020-03-08 04:13:15 +11:00
Word references (wordref): When we say we have a "word reference", it's a
pointer to a words *code link*. For example, the label "PLUS:" in this unit is a
word reference. Why not refer to the beginning of the word struct? Because we
actually seldom refer to the name and prev link, except during compilation, so
defining "word reference" this way makes the code easier to understand.
Atom: A word of the type compiledWord contains, in its PF, a list of what we
call "atoms". Those atoms are most of the time word references, but they can
also be references to NUMBER and LIT.
2020-03-08 14:18:14 +11:00
Words between "()" are "support words" that aren't really meant to be used
directly, but as part of another word.
"*I*" in description indicates an IMMEDIATE word.
2020-03-10 13:13:11 +11:00
*** Defining words ***
(find) a -- a f Read at a and find it in dict. If found, f=1 and
2020-03-18 07:02:01 +11:00
a = wordref. If not found, f=0 and a = string addr.
: x ... -- Define a new word
; R:I -- Exit a colon definition
, n -- Write n in HERE and advance it.
2020-03-18 07:02:01 +11:00
' x -- a Push addr of word x to a. If not found, aborts
['] x -- *I* Like "'", but spits the addr as a number
literal. If not found, aborts.
( -- *I* Comment. Ignore rest of line until ")" is read.
2020-03-10 13:13:11 +11:00
ALLOT n -- Move HERE by n bytes
C, b -- Write byte b in HERE and advance it.
2020-03-08 14:23:08 +11:00
CREATE x -- Create cell named x. Doesn't allocate a PF.
2020-03-22 07:17:51 +11:00
[COMPILE] x -- Compile word x and write it to HERE. IMMEDIATE
words are *not* executed.
2020-03-17 12:31:43 +11:00
COMPILE x -- Meta compiles. Kind of blows the mind. See below.
2020-03-10 13:13:11 +11:00
CONSTANT x n -- Creates cell x that when called pushes its value
2020-04-09 22:26:27 +10:00
DELW a -- Delete wordref at a. If it shadows another
definition, that definition is unshadowed.
2020-03-08 14:18:14 +11:00
DOES> -- See description at top of file
2020-03-18 08:29:03 +11:00
IMMED? a -- f Checks whether wordref at a is immediate.
2020-03-10 13:13:11 +11:00
IMMEDIATE -- Flag the latest defined word as immediate.
LITN n -- Write number n as a literal.
2020-03-10 13:13:11 +11:00
VARIABLE c -- Creates cell x with 2 bytes allocation.
*** Flow ***
Note about flow words: flow words can only be used in definitions. In the
INTERPRET loop, they don't have the desired effect because each word from the
input stream is executed immediately. In this context, branching doesn't work.
(br) -- Branches by the number specified in the 2 following
bytes. Can be negative.
(?br) f -- Branch if f is false.
2020-03-28 06:25:20 +11:00
[ -- Begin interetative mode. In a definition, words
between here and "]" will be executed instead of
compiled.
] -- End interpretative mode.
2020-03-18 06:30:57 +11:00
ABORT -- Resets PS and RS and returns to interpreter
ABORT" x" -- *I* Compiles a ." followed by a ABORT.
AGAIN I:a -- *I* Jump backwards to preceeding BEGIN.
BEGIN -- I:a *I* Marker for backward branching with AGAIN.
ELSE I:a -- *I* Compiles a (fbr) and set branching cell at a.
EXECUTE a -- Execute wordref at addr a
IF -- I:a *I* Compiles a (fbr?) and pushes its cell's addr
2020-03-08 04:13:15 +11:00
INTERPRET -- Get a line from stdin, compile it in tmp memory,
then execute the compiled contents.
QUIT R:drop -- Return to interpreter prompt immediately
RECURSE R:I -- R:I-2 Run the current word again.
THEN I:a -- *I* Set branching cell at a.
2020-03-19 07:39:22 +11:00
UNTIL f -- *I* Jump backwards to BEGIN if f is *false*.
*** Parameter Stack ***
DROP a --
2020-03-10 13:13:11 +11:00
DUP a -- a a
OVER a b -- a b a
2020-03-22 12:23:13 +11:00
ROT a b c -- b c a
2020-03-10 13:13:11 +11:00
SWAP a b -- b a
2020-03-31 04:54:46 +11:00
2DROP a a --
2DUP a b -- a b a b
2OVER a b c d -- a b c d a b
2SWAP a b c d -- c d a b
*** Return Stack ***
>R n -- R:n Pops PS and push to RS
R> R:n -- n Pops RS and push to PS
I -- n Copy RS TOS to PS
I' -- n Copy RS second item to PS
J -- n Copy RS third item to PS
2020-03-10 13:13:11 +11:00
*** Memory ***
@ a -- n Set n to value at address a
! n a -- Store n in address a
? a -- Print value of addr a
+! n a -- Increase value of addr a by n
2020-03-12 13:11:54 +11:00
C@ a -- c Set c to byte at address a
C! c a -- Store byte c in address a
CURRENT -- a Set a to wordref of last added entry.
2020-03-10 13:13:11 +11:00
HERE -- a Push HERE's address
H@ -- a HERE @
2020-04-06 11:01:19 +10:00
MOVE a1 a2 u -- Copy u bytes from a1 to a2, starting with a1, going
up.
2020-03-10 13:13:11 +11:00
2020-03-22 05:47:38 +11:00
*** Arithmetic / Bits ***
2020-03-10 13:13:11 +11:00
+ a b -- c a + b -> c
- a b -- c a - b -> c
-^ a b -- c b - a -> c
2020-03-10 13:13:11 +11:00
* a b -- c a * b -> c
/ a b -- c a / b -> c
2020-03-17 13:36:29 +11:00
MOD a b -- c a % b -> c
/MOD a b -- r q r:remainder q:quotient
2020-03-22 05:47:38 +11:00
AND a b -- c a & b -> c
OR a b -- c a | b -> c
XOR a b -- c a ^ b -> c
2020-03-10 13:13:11 +11:00
*** Logic ***
= n1 n2 -- f Push true if n1 == n2
< n1 n2 -- f Push true if n1 < n2
> n1 n2 -- f Push true if n1 > n2
CMP n1 n2 -- n Compare n1 and n2 and set n to -1, 0, or 1.
n=0: a1=a2. n=1: a1>a2. n=-1: a1<a2.
NOT f -- f Push the logical opposite of f
*** Strings ***
2020-03-22 08:21:01 +11:00
LIT -- Write a LIT entry. You're expected to write actual
string to HERE right afterwards.
2020-03-22 07:27:21 +11:00
LIT< x -- Read following word and write to HERE as a string
literal.
2020-03-22 07:31:53 +11:00
LITS a -- Write word at addr a as a atring literal.
SCMP a1 a2 -- n Compare strings a1 and a2. See CMP
2020-03-22 08:21:01 +11:00
SCPY a -- Copy string at addr a into HERE.
2020-03-19 12:52:55 +11:00
SLEN a -- n Push length of str at a.
2020-03-10 13:13:11 +11:00
*** I/O ***
2020-03-18 08:46:58 +11:00
(parse) a -- n Parses string at a as a number and push the result
in n as well as whether parsing was a success in f
(false = failure, true = success)
(parse.) a -- n f Sub-parsing words. They all have the same signature.
Parses string at a as a number and push the result
in n as well as whether parsing was a success in f
(0 = failure, 1 = success)
(parse*) -- a Variable holding the current pointer for system
number parsing. By default, (parse).
2020-03-18 06:22:13 +11:00
(print) a -- Print string at addr a.
2020-03-10 13:13:11 +11:00
. n -- Print n in its decimal form
.x n -- Print n's LSB in hex form. Always 2 characters.
.X n -- Print n in hex form. Always 4 characters. Numbers
are never considered negative. "-1 .X" --> ffff
2020-03-18 06:22:13 +11:00
." xxx" -- *I* Compiles string literal xxx followed by a call
to (print)
C< -- c Read one char from buffered input.
2020-04-06 03:53:03 +10:00
DUMP n a -- Prints n bytes at addr a in a hexdump format.
Prints in chunks of 8 bytes. Doesn't do partial
lines. Output is designed to fit in 32 columns.
EMIT c -- Spit char c to output stream
IN> -- a Address of variable containing current pos in input
buffer.
KEY -- c Get char c from direct input
2020-03-11 04:00:57 +11:00
PC! c a -- Spit c to port a
PC@ a -- c Fetch c from port a
WORD -- a Read one word from buffered input and push its addr
2020-03-10 13:13:11 +11:00
There are also ascii const emitters:
BS
CR
LF
SPC