--- gforth/oof.fs 1997/03/13 23:40:33 1.8 +++ gforth/oof.fs 1997/08/03 20:21:35 1.12 @@ -9,7 +9,11 @@ \ \ 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 +\ 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 : @@ -27,7 +31,8 @@ \ from MEMORY : \ allocate free \ from SEARCH : -\ find definitions get-order set-order get-current wordlist set-current search-wordlist +\ find definitions get-order set-order get-current wordlist set-current +\ search-wordlist \ from SEARCH-EXT : \ also Forth previous \ from STRING : @@ -121,18 +126,20 @@ Objects definitions : defer? ( addr -- flag ) >body cell+ @ #defer = ; +false Value oset? + : o+, ( addr offset -- ) postpone Literal postpone ^ postpone + - postpone >o drop ; + oset? IF postpone op! ELSE postpone >o THEN drop ; : o*, ( addr offset -- ) postpone Literal postpone * postpone Literal postpone + - postpone >o ; + oset? IF postpone op! ELSE postpone >o THEN ; : ^+@ ( offset -- addr ) ^ + @ ; : 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 * + ; : 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 @@ -166,16 +173,26 @@ define? faligned 0= [IF] types definitions -: static ( -- ) mallot Create , #static , - DOES> @ o@ + ; -: method ( -- ) mallot Create , #method , - DOES> @ o@ + @ execute ; -: early ( -- ) Create ['] crash , #early , - DOES> @ execute ; -: var ( size -- ) vallot Create , #var , - DOES> @ ^ + ; -: defer ( -- ) valign cell vallot Create , #defer , - DOES> @ ^ + @ execute ; +: static ( -- ) \ oof- oof + \G Create a class-wide cell sized variable + mallot Create , #static , +DOES> @ o@ + ; +: method ( -- ) \ oof- oof + \G Create a method selector + mallot Create , #method , +DOES> @ o@ + @ execute ; +: early ( -- ) \ oof- oof + \G Create a method selector for early binding + Create ['] crash , #early , +DOES> @ execute ; +: var ( size -- ) \ oof- oof + \G Create an instance variable + vallot Create , #var , +DOES> @ ^ + ; +: defer ( -- ) \ oof- oof + \G Create an instance defer + valign cell vallot Create , #defer , +DOES> @ ^ + @ execute ; \ dealing with threads 29oct94py @@ -211,16 +228,18 @@ Objects definitions r> drop-order ; false Value method? -false Value oset? : method, ( object early? -- ) true to method? swap >o >r bl word findo 0< state @ and 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, - 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, - state @ IF postpone o> THEN false to oset? ; + state @ oset? and IF postpone o> THEN false to oset? ; \ new, 29oct94py @@ -301,10 +320,10 @@ Objects definitions \ instance creation 29mar94py : 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 , , 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, ; : array, ( n o -- ) alloc @ >r static new[], r> alloc ! drop @@ -421,19 +440,29 @@ Variable last-interface 0 last-interfac 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, lastob! thread, parent, var, 'link, 0 , cells, interfaces, dup IF dup :method# + @ >r :init + swap r> :init /string move ELSE 2drop THEN ; -: class; ( -- ) decl @ IF how: THEN 0 'link ! - voc# @ drop-order old-current @ set-current ; +: class; ( -- ) \ oof- oof end-class +\G End class declaration or implementation + decl @ IF how: THEN 0 'link ! + voc# @ drop-order old-current @ set-current ; + +: ptr ( -- ) \ oof- oof + \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> ; -: ptr ( -- ) Create immediate lastob @ here lastob ! instptr, ; -: asptr ( addr -- ) cell+ @ Create immediate - lastob @ here lastob ! , , instptr> ; +: Fpostpone postpone postpone ; immediate : : ( -- ) decl @ abort" HOW: missing! " bl word findo 0= abort" not found" @@ -463,74 +492,89 @@ Create object immediate 0 (class \ do static size \ number of variables (bytes) static newlink \ ptr to allocated space static ilist \ interface list - method init - method dispose + method init ( ... -- ) \ object- oof + method dispose ( -- ) \ object- oof - early class - early new immediate - early new[] immediate - early : - early ptr - early asptr - early [] - early :: immediate - early class? - early super immediate - early self - early bind immediate - early is immediate - early bound - early link immediate - early ' immediate - early send immediate - early with immediate - early endwith immediate + early class ( "name" -- ) \ object- oof + early new ( -- o ) \ object- oof + immediate + early new[] ( n -- o ) \ object- oof new-array + immediate + early : ( "name" -- ) \ object- oof define + early ptr ( "name" -- ) \ object- oof + early asptr ( o "name" -- ) \ object- oof + early [] ( n "name" -- ) \ object- oof array + early :: ( "name" -- ) \ object- oof scope + immediate + early class? ( o -- flag ) \ object- oof class-query + early super ( "name" -- ) \ object- oof + immediate + early self ( -- o ) \ object- oof + early bind ( o "name" -- ) \ object- oof + immediate + early bound ( class addr "name" -- ) \ object- oof + 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 -how: 0 parento ! - 0 childo ! - 0 nexto ! - : class ( -- ) Create immediate o@ (class ; - : : ( -- ) Create immediate o@ - decl @ IF instvar, ELSE instance, THEN ; - : ptr ( -- ) Create immediate o@ - decl @ IF instptr, ELSE ptr, THEN ; - : asptr ( addr -- ) - decl @ 0= abort" only in declaration!" - Create immediate o@ , cell+ @ , instptr> ; - : [] ( n -- ) Create immediate o@ - decl @ IF instarray, ELSE array, THEN ; - : new ( -- o ) o@ state @ - IF postpone Literal postpone new, ELSE new, THEN ; - : new[] ( n -- o ) o@ state @ - IF postpone Literal postpone new[], ELSE new[], THEN ; - : dispose ( -- ) ^ size @ dispose, ; - : bind ( addr -- ) (bind ; - : bound ( o1 o2 addr2 -- ) (bound ; - : link ( -- o addr ) (link ; - : class? ( class -- flag ) ^ parent? nip 0<> ; - : :: ( -- ) - state @ IF ^ true method, ELSE inherit THEN ; - : super ( -- ) parento true method, ; - : is ( cfa -- ) (is ; - : self ( -- obj ) ^ ; - : init ( -- ) ; - - : ' ( -- xt ) bl word findo 0= abort" not found!" - state @ IF postpone Literal THEN ; - : send ( xt -- ) execute ; - - : with ( -- ) - state @ oset? 0= and IF postpone >o THEN - o@ add-order voc# ! false to oset? - r> drop state @ - IF o> - ELSE oset? IF ^ THEN o> postpone >o - THEN - r> drop r> drop ; - : endwith postpone o> - voc# @ drop-order ; +how: +0 parento ! +0 childo ! +0 nexto ! + : class ( -- ) Create immediate o@ (class ; + : : ( -- ) Create immediate o@ + decl @ IF instvar, ELSE instance, THEN ; + : ptr ( -- ) Create immediate o@ + decl @ IF instptr, ELSE ptr, THEN ; + : asptr ( addr -- ) + decl @ 0= abort" only in declaration!" + Create immediate o@ , cell+ @ , instptr> ; + : [] ( n -- ) Create immediate o@ + decl @ IF instarray, ELSE array, THEN ; + : new ( -- o ) o@ state @ + IF Fpostpone Literal Fpostpone new, ELSE new, THEN ; + : new[] ( n -- o ) o@ state @ + IF Fpostpone Literal Fpostpone new[], ELSE new[], THEN ; + : dispose ( -- ) ^ size @ dispose, ; + : bind ( addr -- ) (bind ; + : bound ( o1 o2 addr2 -- ) (bound ; + : link ( -- o addr ) (link ; + : class? ( class -- flag ) ^ parent? nip 0<> ; + : :: ( -- ) + state @ IF ^ true method, ELSE inherit THEN ; + : super ( -- ) parento true method, ; + : is ( cfa -- ) (is ; + : self ( -- obj ) ^ ; + : init ( -- ) ; + + : ' ( -- xt ) bl word findo 0= abort" not found!" + state @ IF Fpostpone Literal THEN ; + : send ( xt -- ) execute ; + : postpone ( -- ) o@ add-order Fpostpone Fpostpone drop-order ; + + : with ( -- ) + state @ oset? 0= and IF Fpostpone >o THEN + o@ add-order voc# ! false to oset? ; + : endwith Fpostpone o> voc# @ drop-order ; + + : definitions + o@ add-order 1+ voc# ! also types o@ lastob ! + false to oset? get-current old-current ! + thread @ set-current ; class; \ object \ interface 01sep96py @@ -591,34 +635,3 @@ Forth definitions previous previous -\ The program uses the following words -\ from CORE : -\ decimal : bl word 0= ; cells Constant POSTPONE IF EXIT THEN immediate -\ Create , DOES> @ >r r> swap + and Variable ! allot ELSE +! dup * >body -\ cell+ = Literal drop align here aligned execute ['] 2@ recurse 1+ over -\ LOOP ?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 wordlist get-order set-order definitions get-current set-current search-wordlist -\ from SEARCH-EXT : -\ also Forth previous -\ from STRING : -\ /string compare -\ from TOOLS-EXT : -\ state [IF] [THEN]