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 > Re: OBJECTS.FS ...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 41 of 44 Topic 3974 of 4053
Post > Topic >>

Re: OBJECTS.FS Question

by ragofu64@[EMAIL PROTECTED] May 7, 2008 at 06:20 AM

I finally made it work.  I attach the source code. There is no need to
modify objects.fs although I'd love to see it included in the
"official" release by Anton. Just include this after objects.fs.

Note that if you wish to omit the "persistant" word after each
interface, you need to redefine
end-interface as
: end-interface  end-interface persistant ;

As I said before, this cannot be done generally in classes. If you
always stick to the same class declaration style, then you could
probably do a similar thing either in end-class or end-methods

-Rafael

\
==============================================================================================
\ Persistant classes for objects.fs
\ Rafael Gonzalez Fuentetaja, May, 7th, 2008.
\ Public Domain, no warranty.

: heap>dict				  \ addr1 u1 -- addr2
\ +G Transfer a chunk of memory from the heap to the dictionary
memory,
\ +* releasing the old heap memory.
   over >r
   here dup >r over allot		\ -- addr1 n addr2 ; R: -- addr1 addr2
   swap move
   r> r> free throw
;

: persist-interface-map		  \ old-ifce-map -- new-ifce-map
\ +G Persist a single interface map into the dictionary memory.
   dup
   @[EMAIL PROTECTED]
 interface-map 2@[EMAIL PROTECTED]
 nip		\ get the interface map size
   heap>dict				\ and reallocate
;

: persist-interface-maps		  \ --
\ +G Persist all interface maps for classes that implement interfaces.
\ Loop not executed if no interfaces are implemented.
   current-interface @[EMAIL PROTECTED]
 dup interface-map-offset @[EMAIL PROTECTED]
 swap interface-map
2@[EMAIL PROTECTED]
 drop
   swap bounds ?do
      i @[EMAIL PROTECTED]
 ?dup if persist-interface-map
      i !   \ patch the interfaces list with the new address.
   then
   1 cells +loop
;

: persistant
\ *G Copy the last defined interface map from the heap
\ ** back to the dictionary so that it can be safely saved in turnkey
\ ** applications, freeing the unusued heap memory.
   current-interface @[EMAIL PROTECTED]
 interface-map 2@[EMAIL PROTECTED]
 dup >R
   heap>dict
   R> current-interface @[EMAIL PROTECTED]
 interface-map 2!
   persist-interface-maps
;

object persistant \ make the root class persistant

0 [if] \ example code

interface
   selector sel1
   selector sel2
end-interface i-test1 persistant

interface
   selector sel3
   selector sel4
end-interface i-test2 persistant

object class
   i-test2 implementation

   Cell% inst-var m-count

   selector foo

end-class per1

per1 methods
public

  m:
     m-count off
  ;m  overrides construct

  m:
     ." count is " m-count ? cr
     1 m-count +!
  ;m  overrides print

  m:
     ." I'm foo selector" cr
  ;m overrides foo

  :m bar
     ." I'm bar method"
  ;m

  m:
     ." I'm selector sel4" cr
  ;m overrides sel4

end-methods persistant

per1 dict-new constant p1

p1 print
p1 print

save persis.elf cr
bye


[then]




On 3 mayo, 18:37, Doug Hoffman <no.spam> wrote:
> ragof...@[EMAIL PROTECTED]
 wrote:
> > Further test have shown that this do not work for classes implementing
> > interfaces. I'm working on that to find out why.
>
> That is unfortunate.  Let's hope there is a way to do so.  IMHO
> Objects.fs *require* interfaces so the programmer is not burdened with
> the constraints of which messages can be passed to which objects, i.e.,
> having to design the class hierarchy in a specific way.
>




 44 Posts in Topic:
OBJECTS.FS Question
Doug Hoffman <no.spam&  2008-03-26 21:00:22 
Re: OBJECTS.FS Question
anton@[EMAIL PROTECTED]   2008-03-27 21:36:02 
Re: OBJECTS.FS Question
Bruce McFarling <agila  2008-03-27 18:33:47 
Images and libraries (was: OBJECTS.FS Question)
anton@[EMAIL PROTECTED]   2008-03-28 20:48:24 
Re: Images and libraries
Doug Hoffman <no.spam&  2008-03-29 07:05:58 
Re: Images and libraries
Elizabeth D Rather <er  2008-03-29 06:54:53 
Re: OBJECTS.FS Question
Doug Hoffman <no.spam&  2008-03-27 22:27:11 
Re: OBJECTS.FS Question
Albert van der Horst <  2008-03-28 09:00:39 
Re: Images and libraries (was: OBJECTS.FS Question)
Bruce McFarling <agila  2008-03-28 22:24:06 
Re: Images and libraries (was: OBJECTS.FS Question)
mhx@[EMAIL PROTECTED] (M  2008-03-29 07:01:59 
Re: Images and libraries (was: OBJECTS.FS Question)
Albert van der Horst <  2008-03-29 17:28:00 
Re: Images and libraries
Andrew Haley <andrew29  2008-03-29 10:29:43 
Re: Images and libraries
anton@[EMAIL PROTECTED]   2008-03-30 19:23:04 
Re: Images and libraries (was: OBJECTS.FS Question)
Bruce McFarling <agila  2008-03-29 08:51:33 
Re: Images and libraries (was: OBJECTS.FS Question)
Bruce McFarling <agila  2008-03-29 10:57:17 
Re: Images and libraries (was: OBJECTS.FS Question)
anton@[EMAIL PROTECTED]   2008-03-30 19:40:00 
Re: Images and libraries (was: OBJECTS.FS Question)
Albert van der Horst <  2008-03-31 07:43:03 
Re: Images and libraries (was: OBJECTS.FS Question)
stephenXXX@[EMAIL PROTECT  2008-03-31 13:15:43 
Re: Images and libraries (was: OBJECTS.FS Question)
Bernd Paysan <bernd.pa  2008-03-31 17:33:03 
Re: Images and libraries (was: OBJECTS.FS Question)
Bruce McFarling <agila  2008-03-29 11:07:13 
Re: Images and libraries (was: OBJECTS.FS Question)
anton@[EMAIL PROTECTED]   2008-03-30 19:14:33 
Re: Images and libraries (was: OBJECTS.FS Question)
Bruce McFarling <agila  2008-03-30 14:58:43 
Re: Images and libraries (was: OBJECTS.FS Question)
Jonah Thomas <jethomas  2008-03-31 13:12:13 
Re: Images and libraries (was: OBJECTS.FS Question)
Bernd Paysan <bernd.pa  2008-03-31 21:48:45 
Re: Images and libraries (was: OBJECTS.FS Question)
Bruce McFarling <agila  2008-03-31 11:39:05 
Re: Images and libraries (was: OBJECTS.FS Question)
Bruce McFarling <agila  2008-04-01 08:22:47 
Re: Images and libraries
Bruce McFarling <agila  2008-03-29 08:57:52 
Re: Images and libraries
Doug Hoffman <no.spam&  2008-03-29 18:20:50 
Re: Images and libraries
Bernd Paysan <bernd.pa  2008-03-30 22:10:35 
Re: Images and libraries
Bernd Paysan <bernd.pa  2008-03-30 23:23:34 
Re: Images and libraries (was: OBJECTS.FS Question)
Bruce McFarling <agila  2008-03-30 13:40:29 
Re: Images and libraries
ragofu64@[EMAIL PROTECTED  2008-04-02 17:20:17 
Re: Images and libraries
Doug Hoffman <no.spam&  2008-04-02 20:59:13 
Re: Images and libraries
ragofu64@[EMAIL PROTECTED  2008-04-03 01:19:09 
Re: Images and libraries
Doug Hoffman <no.spam&  2008-04-03 05:58:15 
Re: Images and libraries
ragofu64@[EMAIL PROTECTED  2008-04-03 03:59:41 
Re: OBJECTS.FS Question
ragofu64@[EMAIL PROTECTED  2008-04-29 17:20:20 
Re: OBJECTS.FS Question
Doug Hoffman <no.spam&  2008-04-30 20:22:29 
Re: OBJECTS.FS Question
ragofu64@[EMAIL PROTECTED  2008-05-01 01:06:28 
Re: OBJECTS.FS Question
Doug Hoffman <no.spam&  2008-05-03 12:37:01 
Re: OBJECTS.FS Question
ragofu64@[EMAIL PROTECTED  2008-05-07 06:20:43 
Re: OBJECTS.FS Question
Doug Hoffman <no.spam&  2008-05-07 11:06:44 
Re: OBJECTS.FS Question
ragofu64@[EMAIL PROTECTED  2008-05-07 11:36:26 
Re: OBJECTS.FS Question
ragofu64@[EMAIL PROTECTED  2008-05-10 04:07:39 

Post A Reply:
  Go here to Signup

AddThis Feed Button


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

Contact
tan12V112 Fri May 16 0:45:20 CDT 2008.