5 - Forth Interest Group
5 - Forth Interest Group
5 - Forth Interest Group
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
Dl77 ( magic seed )<br />
swm<br />
3. Page 24, fig-<strong>Forth</strong> to<br />
bot<strong>Forth</strong> definitions,<br />
reads:<br />
: ENDIF ( sys -- )<br />
0 \ LITERAL<br />
\ DO ; IMMEDIATE<br />
but should read:<br />
: ENDIF ( sys -- )<br />
\ THEN ; IMMEDIATE<br />
: FOR (sys -- )<br />
0 \ LITERAL<br />
\ DO ; IMMEDIATE<br />
Also, there is no defmi-<br />
tion for @+. It can be ex-<br />
tracted from the definition<br />
for C@+. In a fig-<strong>Forth</strong> sys-<br />
tem, I believe the equivalent<br />
for RECURSIVE would be to<br />
SMUDGE the latest defmition,<br />
since SMUDGE merely<br />
toggles a bit. In my definition<br />
of : (colon), I preceded<br />
RECURSIVE with a \ since it<br />
is an immediate word in<br />
bot<strong>Forth</strong>.<br />
Since writing this article, I<br />
have another another word,<br />
DICTIONARY, which creates<br />
an instance of a hash table.<br />
This allows multiple hash<br />
tables to be mated. Also,<br />
the hash tables are dynamic.<br />
?hey initially occupy no RAM<br />
but, as entries are added to<br />
them, they grow geometri-<br />
cally to accommodate the<br />
number of entries. EMPTY<br />
empties the table and returns<br />
the used memory.<br />
Another addition I have<br />
fopndvery useful is the word<br />
ADJUNCT. This works just<br />
like QUIKFIND except it re-<br />
turns an entry in a parallel<br />
table where additional infor-<br />
mation may be stored about<br />
the string. Thus, you can<br />
associate a string with a block<br />
of code, another string, or<br />
whatever.<br />
If there is interest, I could<br />
publish the updated version<br />
of QuiWind. Right now, I am<br />
using it to build a translator<br />
which ailows phrase defini-<br />
tions in <strong>Forth</strong>, instead of just<br />
words. Hopefully, more on<br />
that later.<br />
Rob Chapman<br />
January 1992 February<br />
(pmerk Listing Four, continued.)<br />
\ exec-obj<br />
\ This fellow expects an object pointer (in vars segment) atop<br />
\ the object stack and a method X atop the methods stack.<br />
\ Executes an object's method<br />
: exec-obj ( -- )<br />
\ Find the method's executable code<br />
f ind-method-code<br />
domet hod<br />
\ instantiate<br />
\ addrl is current pointer in var seg<br />
\ addr2 is object's token pointer<br />
\ Stores that pointer in the<br />
\ variable segment, then allocates ivars space.<br />
: instantiate ( addrl addr2 -- )<br />
dup \ Make copies of token pointer<br />
dup I \ Store token pointer in var seg<br />
@t \ Fetch ivar space<br />
allot \ Allocate variable storage<br />
6 + @t \ Fetch startup method<br />
dup -1 \ Anything there?<br />
if mpush \ Push method<br />
opush \ Push object<br />
exec-ob j \ Execute stuff<br />
else<br />
2drop \ Drop -1 and object pointer<br />
endif<br />
,<br />
\ **<br />
\ ** Class definition<br />
\ **<br />
\ The contents of a defined class are:<br />
\ Token segment: Vars segment:<br />
\ [ Ivars space I can do a @ and<br />
\ retrieve the offset into token space for the class<br />
\ definition structure.<br />
\<br />
\ Once instantiated, an object looks like this:<br />
\ Token segment: Vars segment:<br />
\ [ (;code) I [ token ptr I