|
|
@@ -52,12 +52,44 @@ Interpreter output is unbuffered and only has EMIT. This |
|
|
|
word can also be overriden, mostly as a companion to the |
|
|
|
raison d'etre of your KEY override. |
|
|
|
|
|
|
|
# Aliases and Switches |
|
|
|
|
|
|
|
A common pattern in Forth is to add an indirection layer with |
|
|
|
a pointer word. For example, if you have a word "FOO" for |
|
|
|
which you would like to add an indirection layer, you would |
|
|
|
rename "FOO" to "_FOO", add a variable "FOO*" pointing to |
|
|
|
"_FOO" and re-defining "FOO" as ": FOO FOO* @ EXECUTE". |
|
|
|
|
|
|
|
This is all well and good, but it is resource intensive and |
|
|
|
verbose, which make us want to avoid this pattern for words |
|
|
|
that are often used. |
|
|
|
|
|
|
|
For this purpose, Collapse OS has two special word types: |
|
|
|
alias and switches. |
|
|
|
|
|
|
|
An alias is a variable that contains a pointer to another word. |
|
|
|
When invoked, we invoke the specified pointer with minimal over- |
|
|
|
head. Using our FOO example above, we would create an alias |
|
|
|
with "' _FOO :* FOO". Invoking FOO will then invoke "_FOO". You |
|
|
|
can change the alias' pointer with "*!" like this: |
|
|
|
"' BAR ' FOO *!". FOO now invokes BAR. |
|
|
|
|
|
|
|
A switch is like an alias, but with a second level of indi- |
|
|
|
rection. The variable points to a cell pointing to our word. |
|
|
|
It works like an alias, except you have to use ":**" and "**!". |
|
|
|
Switches are used by core code which point to hardcoded |
|
|
|
addresses in RAM (because the core code is designed to run from |
|
|
|
ROM, we can't have regular variables). You are unlikely to |
|
|
|
need switches in regular code. |
|
|
|
|
|
|
|
# Addressed devices |
|
|
|
|
|
|
|
A@ and A! are the indirect versions of C@ and C!. Their target |
|
|
|
word is controlled through A@* and A!* and by default point to |
|
|
|
C@ and C*. There is also a AMOVE word that is the same as MOVE |
|
|
|
but using A@ and A!. |
|
|
|
A@ and A! are the indirect versions of C@ and C!. They are |
|
|
|
aliases and initially point to C@ and C!. There is also a AMOVE |
|
|
|
word that is the same as MOVE but using A@ and A!. |
|
|
|
|
|
|
|
Addressed device words can be useful to "pipe" processing to |
|
|
|
places outside of regular memory. |
|
|
|
|
|
|
|
# Disk blocks |
|
|
|
|
|
|
|