Talk About Network



Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Forth > How does this M...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 12 Topic 3967 of 4050
Post > Topic >>

How does this Mini-OOF thing work, again?

by Bruce McFarling <agila61@[EMAIL PROTECTED] > Mar 24, 2008 at 01:20 PM

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 ;




 12 Posts in Topic:
How does this Mini-OOF thing work, again?
Bruce McFarling <agila  2008-03-24 13:20:36 
Re: How does this Mini-OOF thing work, again?
anton@[EMAIL PROTECTED]   2008-03-24 21:00:03 
Re: How does this Mini-OOF thing work, again?
Bruce McFarling <agila  2008-03-24 14:16:09 
Re: How does this Mini-OOF thing work, again?
Bruce McFarling <agila  2008-03-24 14:17:07 
Re: How does this Mini-OOF thing work, again?
Bruce McFarling <agila  2008-03-24 14:23:58 
Re: How does this Mini-OOF thing work, again?
Bernd Paysan <bernd.pa  2008-03-24 22:40:16 
Re: How does this Mini-OOF thing work, again?
Gerry <gerry@[EMAIL PR  2008-03-24 14:39:35 
Re: How does this Mini-OOF thing work, again?
jacko <jackokring@[EMA  2008-03-24 15:16:15 
Re: How does this Mini-OOF thing work, again?
Bruce McFarling <agila  2008-03-24 15:17:13 
Re: How does this Mini-OOF thing work, again?
Gerry <gerry@[EMAIL PR  2008-03-25 02:36:34 
Re: How does this Mini-OOF thing work, again?
Bruce McFarling <agila  2008-03-25 09:33:52 
Re: How does this Mini-OOF thing work, again?
Bruce McFarling <agila  2008-03-25 11:05:42 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sun May 11 20:14:27 CDT 2008.