Mini-OOF is (this is mini-oof.fs from gforth 0.6.2):
\ Mini-OOF 12apr98py
: method ( m v "name" -- m' v ) Create over , swap cell+ swap
DOES> ( ... o -- ... ) @[EMAIL PROTECTED]
over @[EMAIL PROTECTED]
+ @[EMAIL PROTECTED]
execute ;
: var ( m v size "name" -- m v' ) Create over , +
DOES> ( o -- addr ) @[EMAIL PROTECTED]
+ ;
: class ( class -- class methods vars ) dup 2@[EMAIL PROTECTED]
;
: end-class ( class methods vars "name" -- )
Create here >r , dup , 2 cells ?DO ['] noop , 1 cells +LOOP
cell+ dup cell+ r> rot @[EMAIL PROTECTED]
2 cells /string move ;
: defines ( xt class "name" -- ) ' >body @[EMAIL PROTECTED]
+ ! ;
: new ( class -- o ) here over @[EMAIL PROTECTED]
allot swap over ! ;
: :: ( class "name" -- ) ' >body @[EMAIL PROTECTED]
+ @[EMAIL PROTECTED]
compile, ;
Create object 1 cells , 2 cells ,
From the example file (moof-exm.fs), I had got the impression that
methods are called with their object on top of stack, but the above
suggests that's not so. That is, moof-exm.fs has code like:
:noname ( addr u o -- ) >r
0 r@[EMAIL PROTECTED]
x ! 0 r@[EMAIL PROTECTED]
y ! r@[EMAIL PROTECTED]
len ! r> text !
; button defines init
where the stack comment makes me think that the phrase:
s" thin foo" foo init
not only uses the object-id of ``foo'' but starts executing the method
with the object-id of ``foo'' on the top of stack.
However when I try:
include mini-oof.fs
object class
method actor ( o -- )
method test$ ( o -- ca u )
end-class test-object
:noname ( o -- ) test$ CR TYPE ; test-object defines actor
:noname ( o -- ca u ) DROP S" Testing." ; test-object defines test$
: Testing ( -- ) test-object actor ;
Testing
I get an invalid memory address in Testing, in actor, when it does a
@[EMAIL PROTECTED]
I called actor as:
( -- ) test-object ( -- o ) actor
and its action is:
DOES> ( ... o -- ... ) @[EMAIL PROTECTED]
over @[EMAIL PROTECTED]
+ @[EMAIL PROTECTED]
execute ;
.... it would seem that when it does the ``OVER'', there's nothing
really on the stack, so its not surprising that it @[EMAIL PROTECTED]
's garbage.
Should that be:
DOES> ( ... o -- ... ) DUP @[EMAIL PROTECTED]
over @[EMAIL PROTECTED]
+ @[EMAIL PROTECTED]
execute ;


|