[gforth] / gforth / oof.fs  

gforth: gforth/oof.fs

Diff for /gforth/oof.fs between version 1.5 and 1.12

version 1.5, Sat Jan 25 20:53:02 1997 UTC version 1.12, Sun Aug 3 20:21:35 1997 UTC
Line 7 
Line 7 
 \  \
 \               Thank you.  \               Thank you.
 \  \
   \ The program uses the following words
   \ from CORE :
   \ decimal : bl word 0= ; = cells Constant Variable ! Create , allot @ IF
   \ POSTPONE >r ELSE +! dup + THEN immediate r> * >body cell+ Literal drop
   \ align here aligned DOES> execute ['] 2@ recurse swap 1+ over LOOP and
   \ EXIT ?dup 0< rot r@ - i negate +LOOP 2drop BEGIN WHILE 2dup REPEAT 1-
   \ rshift > / ' move UNTIL or count
   \ from CORE-EXT :
   \ nip tuck true ?DO compile, false Value erase pick :noname 0<>
   \ from BLOCK-EXT :
   \ \
   \ from EXCEPTION :
   \ throw
   \ from EXCEPTION-EXT :
   \ abort"
   \ from FILE :
   \ ( S"
   \ from FLOAT :
   \ faligned
   \ from LOCAL :
   \ TO
   \ from MEMORY :
   \ allocate free
   \ from SEARCH :
   \ find definitions get-order set-order get-current wordlist set-current
   \ search-wordlist
   \ from SEARCH-EXT :
   \ also Forth previous
   \ from STRING :
   \ /string compare
   \ from TOOLS-EXT :
   \ [IF] [THEN] [ELSE] state
   
 \ Loadscreen                                           27dec95py  \ Loadscreen                                           27dec95py
   
Line 15 
Line 47 
 : define?  ( -- flag )  : define?  ( -- flag )
   bl word find  nip 0= ;    bl word find  nip 0= ;
   
 define? cell  [IF]  1 cells Constant cell  [THEN]  define? cell  [IF]
   1 cells Constant cell
   [THEN]
   
 define? ?EXIT [IF]  define? ?EXIT [IF]
 : ?EXIT  postpone IF  postpone EXIT postpone THEN ; immediate  : ?EXIT  postpone IF  postpone EXIT postpone THEN ; immediate
Line 26 
Line 60 
 DOES> @ >r get-order nip r> swap set-order ;  DOES> @ >r get-order nip r> swap set-order ;
 [THEN]  [THEN]
   
   define? faligned [IF] false [ELSE] 1 faligned 8 = [THEN]
   [IF]
   : 8aligned ( n1 -- n2 )  faligned ;
   [ELSE]
   : 8aligned ( n1 -- n2 )  7 + -8 and ;
   [THEN]
   
 Vocabulary Objects  also Objects also definitions  Vocabulary Objects  also Objects also definitions
   
 Vocabulary types  types also  Vocabulary types  types also
Line 85 
Line 126 
 : defer?   ( addr -- flag )  : defer?   ( addr -- flag )
   >body cell+ @ #defer  = ;    >body cell+ @ #defer  = ;
   
 define? faligned [IF] false [ELSE] 1 faligned 8 = [THEN]  false Value oset?
 [IF]   : 8aligned ( n1 -- n2 )  faligned ;  
 [ELSE] : 8aligned ( n1 -- n2 )  7 + -8 and ;  
 [THEN]  
   
 : o+,   ( addr offset -- )  : o+,   ( addr offset -- )
   postpone Literal postpone ^ postpone +    postpone Literal postpone ^ postpone +
   postpone >o drop ;    oset? IF  postpone op!  ELSE  postpone >o  THEN  drop ;
 : o*,   ( addr offset -- )  : o*,   ( addr offset -- )
   postpone Literal postpone * postpone Literal postpone +    postpone Literal postpone * postpone Literal postpone +
   postpone >o ;    oset? IF  postpone op!  ELSE  postpone >o  THEN ;
 : ^+@  ( offset -- addr )  ^ + @ ;  : ^+@  ( offset -- addr )  ^ + @ ;
 : o+@,  ( addr offset -- )  : o+@,  ( addr offset -- )
     postpone Literal postpone ^+@  postpone >o drop ;      postpone Literal postpone ^+@  oset? IF  postpone op!  ELSE  postpone >o  THEN drop ;
 : ^*@  ( offset -- addr )  ^ + @ tuck @ :var# + @ 8aligned * + ;  : ^*@  ( offset -- addr )  ^ + @ tuck @ :var# + @ 8aligned * + ;
 : o+@*, ( addr offset -- )  : o+@*, ( addr offset -- )
   postpone Literal postpone ^*@  postpone >o drop ;    postpone Literal postpone ^*@  oset? IF  postpone op!  ELSE  postpone >o  THEN drop ;
   
 \ variables / memory allocation                        30oct94py  \ variables / memory allocation                        30oct94py
   
Line 135 
Line 173 
   
 types definitions  types definitions
   
 : static   ( -- )  mallot Create , #static ,  : static   ( -- ) \ oof- oof
       \G Create a class-wide cell sized variable
       mallot Create , #static ,
   DOES> @ o@ + ;    DOES> @ o@ + ;
 : method   ( -- )  mallot Create , #method ,  : method   ( -- ) \ oof- oof
       \G Create a method selector
       mallot Create , #method ,
   DOES> @ o@ + @ execute ;    DOES> @ o@ + @ execute ;
 : early    ( -- )  Create ['] crash , #early ,  : early    ( -- ) \ oof- oof
       \G Create a method selector for early binding
       Create ['] crash , #early ,
   DOES> @ execute ;    DOES> @ execute ;
 : var ( size -- )  vallot Create , #var ,  : var ( size -- ) \ oof- oof
       \G Create an instance variable
       vallot Create , #var ,
   DOES> @ ^ + ;    DOES> @ ^ + ;
 : defer    ( -- )  valign cell vallot Create , #defer ,  : defer    ( -- ) \ oof- oof
       \G Create an instance defer
       valign cell vallot Create , #defer ,
   DOES> @ ^ + @ execute ;    DOES> @ ^ + @ execute ;
   
 \ dealing with threads                                 29oct94py  \ dealing with threads                                 29oct94py
Line 180 
Line 228 
     r> drop-order ;      r> drop-order ;
   
 false Value method?  false Value method?
 false Value oset?  
   
 : method,  ( object early? -- )  true to method?  : method,  ( object early? -- )  true to method?
     swap >o >r bl word  findo  0< state @ and      swap >o >r bl word  findo  0< state @ and
     IF  r> o,  ELSE  r> drop execute  THEN  o> false to method?  ;      IF  r> o,  ELSE  r> drop execute  THEN  o> false to method?  ;
   
   : cmethod,  ( object early? -- )
       state @ >r state on  method, r> state ! ;
   
 : early, ( object -- )  true to oset?  true  method,  : early, ( object -- )  true to oset?  true  method,
   state @ IF  postpone o>  THEN  false to oset? ;    state @ oset? and IF  postpone o>  THEN  false to oset? ;
 : late,  ( object -- )  true to oset?  false method,  : late,  ( object -- )  true to oset?  false method,
   state @ IF  postpone o>  THEN  false to oset? ;    state @ oset? and IF  postpone o>  THEN  false to oset? ;
   
 \ new,                                                 29oct94py  \ new,                                                 29oct94py
   
Line 270 
Line 320 
 \ instance creation                                    29mar94py  \ instance creation                                    29mar94py
   
 : instance, ( o -- )  alloc @ >r static new, r> alloc ! drop  : instance, ( o -- )  alloc @ >r static new, r> alloc ! drop
   DOES> state @ IF  dup postpone Literal postpone >o  THEN early, ;    DOES> state @ IF  dup postpone Literal oset? IF  postpone op!  ELSE  postpone >o  THEN  THEN early, ;
 : ptr,      ( o -- )  0 , ,  : ptr,      ( o -- )  0 , ,
   DOES>  state @    DOES>  state @
     IF    dup postpone Literal postpone @ postpone >o cell+      IF    dup postpone Literal postpone @ oset? IF  postpone op!  ELSE  postpone >o  THEN cell+
     ELSE  @  THEN late, ;      ELSE  @  THEN late, ;
   
 : array,  ( n o -- )  alloc @ >r static new[], r> alloc ! drop  : array,  ( n o -- )  alloc @ >r static new[], r> alloc ! drop
Line 390 
Line 440 
   
 types definitions  types definitions
   
 : how:  ( -- )  decl @ 0= abort" not twice!" 0 decl !  : how:  ( -- ) \ oof- oof how-to
   \G End declaration, start implementation
       decl @ 0= abort" not twice!" 0 decl !
     align  interface,      align  interface,
     lastob! thread, parent, var, 'link, 0 , cells, interfaces,      lastob! thread, parent, var, 'link, 0 , cells, interfaces,
     dup      dup
     IF    dup :method# + @ >r :init + swap r> :init /string move      IF    dup :method# + @ >r :init + swap r> :init /string move
     ELSE  2drop  THEN ;      ELSE  2drop  THEN ;
   
 : class; ( -- ) decl @ IF  how:  THEN  0 'link !  : class; ( -- ) \ oof- oof end-class
   \G End class declaration or implementation
       decl @ IF  how:  THEN  0 'link !
   voc# @ drop-order old-current @ set-current ;    voc# @ drop-order old-current @ set-current ;
   
 : ptr ( -- ) Create immediate lastob @ here lastob ! instptr, ;  : ptr ( -- ) \ oof- oof
 : asptr ( addr -- )  cell+ @ Create immediate      \G Create an instance pointer
       Create immediate lastob @ here lastob ! instptr, ;
   : asptr ( class -- ) \ oof- oof
       \G Create an alias to an instance pointer, casted to another class
       cell+ @ Create immediate
   lastob @ here lastob ! , ,  instptr> ;    lastob @ here lastob ! , ,  instptr> ;
   
   : Fpostpone  postpone postpone ; immediate
   
 : : ( <methodname> -- )  decl @ abort" HOW: missing! "  : : ( <methodname> -- )  decl @ abort" HOW: missing! "
     bl word findo 0= abort" not found"      bl word findo 0= abort" not found"
     dup exec? over early? or over >body cell+ @ 0< or      dup exec? over early? or over >body cell+ @ 0< or
Line 432 
Line 492 
          static    size         \ number of variables (bytes)           static    size         \ number of variables (bytes)
          static    newlink      \ ptr to allocated space           static    newlink      \ ptr to allocated space
          static    ilist        \ interface list           static    ilist        \ interface list
          method    init           method    init ( ... -- ) \ object- oof
          method    dispose           method    dispose ( -- ) \ object- oof
   
          early     class           early     class ( "name" -- ) \ object- oof
          early     new         immediate           early     new ( -- o ) \ object- oof
          early     new[]       immediate                                  immediate
          early     :           early     new[] ( n -- o ) \ object- oof new-array
          early     ptr                                  immediate
          early     asptr           early     : ( "name" -- ) \ object- oof define
          early     []           early     ptr ( "name" -- ) \ object- oof
          early     ::          immediate           early     asptr ( o "name" -- ) \ object- oof
          early     class?           early     [] ( n "name" -- ) \ object- oof array
          early     super       immediate           early     ::  ( "name" -- ) \ object- oof scope
          early     self                                  immediate
          early     bind        immediate           early     class? ( o -- flag ) \ object- oof class-query
          early     is          immediate           early     super  ( "name" -- ) \ object- oof
          early     bound                                  immediate
          early     link        immediate           early     self ( -- o ) \ object- oof
          early     '           immediate           early     bind ( o "name" -- ) \ object- oof
          early     send        immediate                                  immediate
          early     with        immediate           early     bound ( class addr "name" -- ) \ object- oof
          early     endwith     immediate           early     link ( "name" -- class addr ) \ object- oof
                                   immediate
            early     is  ( xt "name" -- ) \ object- oof
                                   immediate
            early     send ( xt -- ) \ object- oof
                                   immediate
            early     with ( o -- ) \ object- oof
                                   immediate
            early     endwith ( -- ) \ object- oof
                                   immediate
            early     ' ( "name" -- xt ) \ object- oof tick
                                   immediate
            early     postpone ( "name" -- ) \ object- oof
                                   immediate
            early     definitions ( -- ) \ object- oof
   
 \ base object class implementation part                23mar95py  \ base object class implementation part                23mar95py
   
 how:    0 parento !  how:
   0 parento !
         0 childo !          0 childo !
         0 nexto !          0 nexto !
         : class   ( -- )       Create immediate o@ (class ;          : class   ( -- )       Create immediate o@ (class ;
Line 471 
Line 546 
         : []      ( n -- )     Create immediate o@          : []      ( n -- )     Create immediate o@
           decl @ IF  instarray,  ELSE  array,     THEN ;            decl @ IF  instarray,  ELSE  array,     THEN ;
         : new     ( -- o )     o@ state @          : new     ( -- o )     o@ state @
           IF  postpone Literal postpone new,  ELSE  new,  THEN ;          IF  Fpostpone Literal Fpostpone new,  ELSE  new,  THEN ;
         : new[]   ( n -- o )   o@ state @          : new[]   ( n -- o )   o@ state @
           IF postpone Literal postpone new[], ELSE new[], THEN ;          IF Fpostpone Literal Fpostpone new[], ELSE new[], THEN ;
         : dispose ( -- )       ^ size @ dispose, ;          : dispose ( -- )       ^ size @ dispose, ;
         : bind    ( addr -- )  (bind ;          : bind    ( addr -- )  (bind ;
         : bound   ( o1 o2 addr2  -- ) (bound ;          : bound   ( o1 o2 addr2  -- ) (bound ;
Line 487 
Line 562 
         : init    ( -- )       ;          : init    ( -- )       ;
   
         : '       ( -- xt )  bl word findo 0= abort" not found!"          : '       ( -- xt )  bl word findo 0= abort" not found!"
           state @ IF  postpone Literal  THEN ;          state @ IF  Fpostpone Literal  THEN ;
         : send    ( xt -- )  execute ;          : send    ( xt -- )  execute ;
       : postpone ( -- )  o@ add-order Fpostpone Fpostpone drop-order ;
   
         : with ( -- )          : with ( -- )
           state @ oset? 0= and IF  postpone >o  THEN          state @ oset? 0= and IF  Fpostpone >o  THEN
           o@ add-order voc# ! false to oset?          o@ add-order voc# ! false to oset? ;
           rdrop state @      : endwith  Fpostpone o> voc# @ drop-order ;
           IF    o>  
           ELSE  oset? IF  ^ THEN  o> postpone >o      : definitions
           THEN          o@ add-order 1+ voc# ! also types o@ lastob !
           rdrop rdrop ;          false to oset?   get-current old-current !
         : endwith  postpone o>          thread @ set-current ;
           voc# @ drop-order ;  
 class; \ object  class; \ object
   
 \ interface                                            01sep96py  \ interface                                            01sep96py
Line 559 
Line 634 
     DOES>  @ decl @  IF  implement  ELSE  inter-method,  THEN ;      DOES>  @ decl @  IF  implement  ELSE  inter-method,  THEN ;
   
 previous previous  previous previous
   


Generate output suitable for use with a patch program
Legend:
Removed from v.1.5  
changed lines
  Added in v.1.12

CVS Admin

Powered by ViewCVS 1.0-dev
(Powered by ViewCVS)

ViewCVS and CVS Help