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.
if r> compl \ Lengths match ... try comparison<br />
else<br />
endif<br />
4drop r>drop 1 \ Show mismatch<br />
\ Advance to next item past the current counted string.<br />
\ seg:addr points to counted string. Takes into account<br />
\ trailing integer.<br />
: nextstr ( seg addr -- seg addr' )<br />
countl + 2+<br />
\ Search one of the temporary segments.<br />
\ seg1:addrl points to string to search for<br />
\ seg2 is temporary segment to search<br />
\ max is maximum current offset in segment.<br />
\ n is returned associated integer; -1 means<br />
\ the string was not located.<br />
: search-tseg ( segl addrl seg2 max -- n )<br />
dup \ Anything to look for?<br />
if<br />
> r \ Save max<br />
0 \ Start search at zero<br />
begin<br />
2over 2over \ Dup seg/address<br />
ccompl \ Look for match<br />
0 =<br />
if 2swap r> 3drop \ Clear stack<br />
count1 + @1 \ Fetch value<br />
exit<br />
endif<br />
nextstr \ Advance to next string<br />
dup r@ >= \ Topped out?<br />
until<br />
r>drop \ Clear return stack<br />
endif<br />
4drop \ Clear stack<br />
- 1 \ Show error<br />
\ **<br />
\ ** Instance variable segment handling<br />
\ **<br />
\ The ivar segment is a temporary region where the system<br />
\ keeps a list of the current class definition's instance<br />
\ variables. Each entry is composed of a length byte, the<br />
\ name, and a 2-byte value that indicates that instance<br />
\ variable's offset into an instance of the class<br />
\ Allocate space for the IVAR segment. Place the segment<br />
\ in global variable ivar-seg<br />
: alloc-ivar-seg ( -- )<br />
IVAR-SEG-SIZE alloc<br />
error \ Fetch error<br />
if abort" Ivar allocation error"<br />
endif<br />
ivar-seg ! \ Save pointer<br />
\ Clear the ivar segment<br />
: clear-ivar-seg ( -- )<br />
0 ivar-next !<br />
I<br />
<strong>Forth</strong> Dimensions 11<br />
(Zisting continues<br />
lethod by mimicking the<br />
m-time action of the colon<br />
rord. You pass (domethd)<br />
the starting address of<br />
le method code and it<br />
andles the rest.<br />
PCYerk does not create<br />
andard <strong>Forth</strong> headers (5 la<br />
reate) for instance varibles<br />
and methods. In the<br />
ase of instance variables,<br />
ou want their names to disppear<br />
after the class definion.<br />
For method names, you<br />
on't want their names taklg<br />
up header space, since<br />
ley are instantly resolved to<br />
wo-byte selector ID numers.<br />
PCYerk allocates two<br />
nemory blocks (using the<br />
JD<strong>Forth</strong>wordalloc, which<br />
brovides access to the DOS<br />
unction for allocating a<br />
nemory segment): one to<br />
!old instance variable names,<br />
he other to hold method<br />
lames. Each name stored in<br />
me of these blocks is associ-<br />
~ted with an integer.<br />
In the case of instance<br />
rariables, the associated ineger<br />
carries that instance<br />
rariable's offset into the<br />
~bject's local data space. At<br />
:ompile time, whenthe sysem<br />
encounters an instance<br />
rariable, it looks up the<br />
rariable's offset and com-<br />
3iles that as a literal, folowed<br />
by the word ( iva r ) .<br />
4t run time, ( ivar ) takes the<br />
~ffset from the stack and<br />
resolves that offset to an adkss.<br />
In the case of methods,<br />
he associated integer is the<br />
selector ID number. When<br />
you define a new method's<br />
name, the system increments<br />
an internal counter and the<br />
incremented value becomes<br />
that method's ID number.<br />
This ensures a unique ID<br />
number for each method.<br />
(Yerkused a hashing method<br />
to generate such ID numbers.<br />
I chose a separate route,<br />
since the code for handling<br />
instance variable names and<br />
method names was so similar.)<br />
But wait. If the system<br />
puts method names and in-<br />
January 1992 February