16.10.2013 Views

5 - Forth Interest Group

5 - Forth Interest Group

5 - Forth Interest Group

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

I r> 3 + methname-next +! \ Advance next<br />

\ ***************<br />

\ ** METHODS **<br />

\ ***************<br />

\ Methods are kept on singly-linked list. That list is anchored<br />

\ in the class definition structure defined below. Each entry<br />

\ on a method list looks like this:<br />

\ Token segment<br />

\ [ link to next 1<br />

\ [ Method id # I<br />

\ [ ... tokens 1<br />

~<br />

\ Attach a new method to tail. addr on top of stack is assumed<br />

\ to be pointer into token segment<br />

: new-method-tail ( addr -- )<br />

\ See if we are first method added. If so, attach to parent.<br />

curr-meth-tail<br />

if dup<br />

@ ?dup 0-<br />

\ Copy ourselves<br />

curr-class-off<br />

!t<br />

over swap !t<br />

@ 2+<br />

\ Fix link<br />

endif<br />

curr-meth-tail !<br />

\ We are new tail<br />

!<br />

\ (>super)<br />

\ This routine looks 'up the chain' to an object's super object<br />

\ Used when searching for methods to execute.<br />

\ addrl is the current object's address in the token seg.<br />

\ addr2 is the super object's address or 0 if none found<br />

: (>super) ( addrl -- addr2 )<br />

4 + @t \ Fetch the super object address<br />

\ (domethod)<br />

\ Following code word vectors execution to a method.<br />

\ Assumes that the value on top of the stack is offset<br />

\ into token space for the method.<br />

code (domethod) ( off -- )<br />

bp dec \ Make room on return stack<br />

bp dec<br />

si 0 [bp] mov \ Push IP<br />

bx si mov \ Get method address in IP<br />

bx POP \ Pop stack<br />

next \ Take off!<br />

end-code<br />

\ domethod<br />

\ Calls (domethod) and clears the object stack.<br />

\ Off is the address of the method code.<br />

: domethod ( off -- )<br />

(domethod)<br />

odrop<br />

\ (methid->addr)<br />

\ Given a method id, this finds that method's address in the<br />

\ token segment. addrl is the address of the object (in the<br />

\ token segment) whose method<br />

\ list we'll search. addr2 is the method address, or 0 if the<br />

\ method wasn't found.<br />

Girting continues.<br />

<strong>Forth</strong> Dimensions 13<br />

Ceaers, fm page 5.1<br />

zrs to at least give it a spin.<br />

Iobbyists will buy it. Small<br />

,ompanies will try it. The<br />

vord gets around.<br />

At this time, the low-cost<br />

,ersions of <strong>Forth</strong> are not at<br />

.I1 well marketed-if you<br />

:ould say they're marketed<br />

~t all. I have not used F-PC<br />

ret, but I assume it fmes the<br />

~wful programming envionment<br />

of F83. How can we<br />

xpect people accustomed<br />

o the pleasant Microsoft<br />

&id

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!