[gforth] / gforth / oof.fs  

gforth: gforth/oof.fs


1 : pazsan 1.1 \ oof.fs Object Oriented FORTH
2 :     \ This file is (c) 1996 by Bernd Paysan
3 :     \ e-mail: paysan@informatik.tu-muenchen.de
4 :     \
5 :     \ Please copy and share this program, modify it for your system
6 :     \ and improve it as you like. But don't remove this notice.
7 :     \
8 :     \ Thank you.
9 :     \
10 : pazsan 1.8 \ The program uses the following words
11 :     \ from CORE :
12 : pazsan 1.9 \ decimal : bl word 0= ; = cells Constant Variable ! Create , allot @ IF
13 :     \ POSTPONE >r ELSE +! dup + THEN immediate r> * >body cell+ Literal drop
14 :     \ align here aligned DOES> execute ['] 2@ recurse swap 1+ over LOOP and
15 :     \ EXIT ?dup 0< rot r@ - i negate +LOOP 2drop BEGIN WHILE 2dup REPEAT 1-
16 :     \ rshift > / ' move UNTIL or count
17 : pazsan 1.8 \ from CORE-EXT :
18 :     \ nip tuck true ?DO compile, false Value erase pick :noname 0<>
19 :     \ from BLOCK-EXT :
20 :     \ \
21 :     \ from EXCEPTION :
22 :     \ throw
23 :     \ from EXCEPTION-EXT :
24 :     \ abort"
25 :     \ from FILE :
26 :     \ ( S"
27 :     \ from FLOAT :
28 :     \ faligned
29 :     \ from LOCAL :
30 :     \ TO
31 :     \ from MEMORY :
32 :     \ allocate free
33 :     \ from SEARCH :
34 : pazsan 1.9 \ find definitions get-order set-order get-current wordlist set-current
35 :     \ search-wordlist
36 : pazsan 1.8 \ from SEARCH-EXT :
37 :     \ also Forth previous
38 :     \ from STRING :
39 :     \ /string compare
40 :     \ from TOOLS-EXT :
41 :     \ [IF] [THEN] [ELSE] state
42 : pazsan 1.1
43 :     \ Loadscreen 27dec95py
44 :    
45 :     decimal
46 :    
47 :     : define? ( -- flag )
48 :     bl word find nip 0= ;
49 :    
50 : pazsan 1.7 define? cell [IF]
51 :     1 cells Constant cell
52 :     [THEN]
53 : pazsan 1.1
54 :     define? ?EXIT [IF]
55 :     : ?EXIT postpone IF postpone EXIT postpone THEN ; immediate
56 :     [THEN]
57 :    
58 :     define? Vocabulary [IF]
59 :     : Vocabulary wordlist create ,
60 :     DOES> @ >r get-order nip r> swap set-order ;
61 :     [THEN]
62 :    
63 : pazsan 1.7 define? faligned [IF] false [ELSE] 1 faligned 8 = [THEN]
64 :     [IF]
65 :     : 8aligned ( n1 -- n2 ) faligned ;
66 :     [ELSE]
67 :     : 8aligned ( n1 -- n2 ) 7 + -8 and ;
68 :     [THEN]
69 :    
70 : pazsan 1.1 Vocabulary Objects also Objects also definitions
71 :    
72 :     Vocabulary types types also
73 :    
74 :     0 cells Constant :wordlist
75 :     1 cells Constant :parent
76 :     2 cells Constant :child
77 :     3 cells Constant :next
78 :     4 cells Constant :method#
79 :     5 cells Constant :var#
80 :     6 cells Constant :newlink
81 :     7 cells Constant :iface
82 :     8 cells Constant :init
83 :    
84 :     0 cells Constant :inext
85 :     1 cells Constant :ilist
86 :     2 cells Constant :ilen
87 :     3 cells Constant :inum
88 :    
89 :     Variable op
90 :     : op! ( o -- ) op ! ;
91 :    
92 :     Forth definitions
93 :    
94 :     Create ostack 0 , 16 cells allot
95 :    
96 :     : ^ ( -- o ) op @ ;
97 :     : o@ ( -- o ) op @ @ ;
98 :     : >o ( o -- )
99 :     state @
100 :     IF postpone ^ postpone >r postpone op!
101 :     ELSE 1 ostack +! ^ ostack dup @ cells + ! op!
102 :     THEN ; immediate
103 :     : o> ( -- )
104 :     state @
105 :     IF postpone r> postpone op!
106 :     ELSE ostack dup @ cells + @ op! -1 ostack +!
107 :     THEN ; immediate
108 :     : o[] ( n -- ) o@ :var# + @ * ^ + op! ;
109 :    
110 :     Objects definitions
111 :    
112 :     \ Coding 27dec95py
113 :    
114 :     0 Constant #static
115 :     1 Constant #method
116 :     2 Constant #early
117 :     3 Constant #var
118 :     4 Constant #defer
119 :    
120 :     : exec? ( addr -- flag )
121 :     >body cell+ @ #method = ;
122 :     : static? ( addr -- flag )
123 :     >body cell+ @ #static = ;
124 :     : early? ( addr -- flag )
125 :     >body cell+ @ #early = ;
126 :     : defer? ( addr -- flag )
127 :     >body cell+ @ #defer = ;
128 :    
129 : pazsan 1.10 false Value oset?
130 :    
131 : pazsan 1.1 : o+, ( addr offset -- )
132 :     postpone Literal postpone ^ postpone +
133 : pazsan 1.10 oset? IF postpone op! ELSE postpone >o THEN drop ;
134 : pazsan 1.1 : o*, ( addr offset -- )
135 :     postpone Literal postpone * postpone Literal postpone +
136 : pazsan 1.10 oset? IF postpone op! ELSE postpone >o THEN ;
137 : pazsan 1.1 : ^+@ ( offset -- addr ) ^ + @ ;
138 :     : o+@, ( addr offset -- )
139 : pazsan 1.10 postpone Literal postpone ^+@ oset? IF postpone op! ELSE postpone >o THEN drop ;
140 : pazsan 1.1 : ^*@ ( offset -- addr ) ^ + @ tuck @ :var# + @ 8aligned * + ;
141 :     : o+@*, ( addr offset -- )
142 : pazsan 1.10 postpone Literal postpone ^*@ oset? IF postpone op! ELSE postpone >o THEN drop ;
143 : pazsan 1.1
144 :     \ variables / memory allocation 30oct94py
145 :    
146 :     Variable lastob
147 :     Variable lastparent 0 lastparent !
148 :     Variable vars
149 :     Variable methods
150 :     Variable decl 0 decl !
151 :     Variable 'link
152 :    
153 :     : crash true abort" unbound method" ;
154 :    
155 :     : link, ( addr -- ) align here 'link ! , 0 , 0 , ;
156 :    
157 :     0 link,
158 :    
159 :     \ type declaration 30oct94py
160 :    
161 :     : vallot ( size -- offset ) vars @ >r dup vars +!
162 :     'link @ 0=
163 :     IF lastparent @ dup IF :newlink + @ THEN link,
164 :     THEN
165 :     'link @ 2 cells + +! r> ;
166 :    
167 :     : valign ( -- ) vars @ aligned vars ! ;
168 :     define? faligned 0= [IF]
169 :     : vfalign ( -- ) vars @ faligned vars ! ;
170 :     [THEN]
171 :    
172 :     : mallot ( -- offset ) methods @ cell methods +! ;
173 :    
174 :     types definitions
175 :    
176 :     : static ( -- ) mallot Create , #static ,
177 :     DOES> @ o@ + ;
178 :     : method ( -- ) mallot Create , #method ,
179 :     DOES> @ o@ + @ execute ;
180 :     : early ( -- ) Create ['] crash , #early ,
181 :     DOES> @ execute ;
182 :     : var ( size -- ) vallot Create , #var ,
183 :     DOES> @ ^ + ;
184 :     : defer ( -- ) valign cell vallot Create , #defer ,
185 :     DOES> @ ^ + @ execute ;
186 :    
187 :     \ dealing with threads 29oct94py
188 :    
189 :     Objects definitions
190 :    
191 :     : object-order ( wid0 .. widm m addr -- wid0 .. widn n )
192 :     dup IF 2@ >r recurse r> swap 1+ ELSE drop THEN ;
193 :    
194 :     : interface-order ( wid0 .. widm m addr -- wid0 .. widn n )
195 :     dup IF 2@ >r recurse r> :ilist + @ swap 1+
196 :     ELSE drop THEN ;
197 :    
198 : pazsan 1.7 : add-order ( addr -- n ) dup 0= ?EXIT >r
199 :     get-order r> swap >r 0 swap
200 :     dup >r object-order r> :iface + @ interface-order
201 : pazsan 1.1 r> over >r + set-order r> ;
202 :    
203 :     : drop-order ( n -- ) 0 ?DO previous LOOP ;
204 :    
205 :     \ object compiling/executing 20feb95py
206 :    
207 :     : o, ( xt early? -- )
208 :     over exec? over and IF
209 :     drop >body @ o@ + @ compile, EXIT THEN
210 :     over static? over and IF
211 :     drop >body @ o@ + @ postpone Literal EXIT THEN
212 :     drop dup early? IF >body @ THEN compile, ;
213 :    
214 :     : findo ( string -- cfa n )
215 : pazsan 1.7 o@ add-order >r
216 :     find
217 : pazsan 1.1 ?dup 0= IF drop set-order true abort" method not found!" THEN
218 : pazsan 1.7 r> drop-order ;
219 : pazsan 1.1
220 :     false Value method?
221 : pazsan 1.7
222 : pazsan 1.1 : method, ( object early? -- ) true to method?
223 :     swap >o >r bl word findo 0< state @ and
224 :     IF r> o, ELSE r> drop execute THEN o> false to method? ;
225 :    
226 : pazsan 1.10 : cmethod, ( object early? -- )
227 :     state @ >r state on method, r> state ! ;
228 :    
229 : pazsan 1.7 : early, ( object -- ) true to oset? true method,
230 : pazsan 1.10 state @ oset? and IF postpone o> THEN false to oset? ;
231 : pazsan 1.7 : late, ( object -- ) true to oset? false method,
232 : pazsan 1.10 state @ oset? and IF postpone o> THEN false to oset? ;
233 : pazsan 1.1
234 :     \ new, 29oct94py
235 :    
236 :     previous Objects definitions
237 :    
238 :     Variable alloc
239 :     0 Value ohere
240 :    
241 :     : oallot ( n -- ) ohere + to ohere ;
242 :    
243 :     : ((new, ( link -- )
244 :     dup @ ?dup IF recurse THEN cell+ 2@ swap ohere + >r
245 :     ?dup IF ohere >r dup >r :newlink + @ recurse r> r> ! THEN
246 :     r> to ohere ;
247 :    
248 :     : (new ( object -- )
249 :     ohere >r dup >r :newlink + @ ((new, r> r> ! ;
250 :    
251 :     : init-instance ( pos link -- pos )
252 :     dup >r @ ?dup IF recurse THEN r> cell+ 2@
253 :     IF drop dup >r ^ +
254 :     >o o@ :init + @ execute 0 o@ :newlink + @ recurse o>
255 :     r> THEN + ;
256 :    
257 :     : init-object ( object -- size )
258 :     >o o@ :init + @ execute 0 o@ :newlink + @ init-instance o> ;
259 :    
260 :     : (new, ( object -- ) ohere dup >r over :var# + @ erase (new
261 :     r> init-object drop ;
262 :    
263 :     : size@ ( objc -- size ) :var# + @ 8aligned ;
264 :     : (new[], ( n o -- addr ) ohere >r
265 :     dup size@ rot over * oallot r@ ohere dup >r 2 pick -
266 :     ?DO I to ohere >r dup >r (new, r> r> dup negate +LOOP
267 :     2drop r> to ohere r> ;
268 :    
269 :     \ new, 29oct94py
270 :    
271 :     Create chunks here 16 cells dup allot erase
272 :    
273 :     : DelFix ( addr root -- ) dup @ 2 pick ! ! ;
274 :    
275 :     : NewFix ( root size # -- addr )
276 :     BEGIN 2 pick @ ?dup 0=
277 :     WHILE 2dup * allocate throw over 0
278 :     ?DO dup 4 pick DelFix 2 pick +
279 :     LOOP
280 :     drop
281 :     REPEAT
282 :     >r drop r@ @ rot ! r@ swap erase r> ;
283 :    
284 :     : >chunk ( n -- root n' )
285 : pazsan 1.4 1- -8 and dup 3 rshift cells chunks + swap 8 + ;
286 : pazsan 1.1
287 :     : Dalloc ( size -- addr )
288 :     dup 128 > IF allocate throw EXIT THEN
289 :     >chunk 2048 over / NewFix ;
290 :    
291 :     : Salloc ( size -- addr ) align here swap allot ;
292 :    
293 :     : dispose, ( addr size -- )
294 :     dup 128 > IF drop free throw EXIT THEN
295 :     >chunk drop DelFix ;
296 :    
297 :     : new, ( o -- addr ) dup :var# + @
298 :     alloc @ execute dup >r to ohere (new, r> ;
299 :    
300 :     : new[], ( n o -- addr ) dup :var# + @ 8aligned
301 :     2 pick * alloc @ execute to ohere (new[], ;
302 :    
303 :     Forth definitions
304 :    
305 :     : dynamic ['] Dalloc alloc ! ; dynamic
306 :     : static ['] Salloc alloc ! ;
307 :    
308 :     Objects definitions
309 :    
310 :     \ instance creation 29mar94py
311 :    
312 :     : instance, ( o -- ) alloc @ >r static new, r> alloc ! drop
313 : pazsan 1.10 DOES> state @ IF dup postpone Literal oset? IF postpone op! ELSE postpone >o THEN THEN early, ;
314 : pazsan 1.1 : ptr, ( o -- ) 0 , ,
315 :     DOES> state @
316 : pazsan 1.10 IF dup postpone Literal postpone @ oset? IF postpone op! ELSE postpone >o THEN cell+
317 : pazsan 1.1 ELSE @ THEN late, ;
318 :    
319 :     : array, ( n o -- ) alloc @ >r static new[], r> alloc ! drop
320 :     DOES> ( n -- ) dup dup @ size@
321 :     state @ IF o*, ELSE nip rot * + THEN early, ;
322 :    
323 :     \ class creation 29mar94py
324 :    
325 :     Variable voc#
326 :     Variable classlist
327 :     Variable old-current
328 :     Variable ob-interface
329 :    
330 :     : voc! ( addr -- ) get-current old-current !
331 :     add-order 2 + voc# !
332 :     get-order wordlist tuck classlist ! 1+ set-order
333 :     also types classlist @ set-current ;
334 :    
335 :     : (class ( parent -- )
336 :     here lastob ! true decl ! 0 ob-interface !
337 :     0 , dup voc! dup lastparent !
338 :     dup 0= IF 0 ELSE :method# + 2@ THEN methods ! vars !
339 :     DOES> false method, ;
340 :    
341 :     : (is ( addr -- ) bl word findo drop
342 :     dup defer? abort" not deferred!"
343 :     >body @ state @
344 :     IF postpone ^ postpone Literal postpone + postpone !
345 :     ELSE ^ + ! THEN ;
346 :    
347 :     : inherit ( -- ) bl word findo drop
348 :     dup exec? IF >body @ dup o@ + @ swap lastob @ + ! EXIT THEN
349 :     abort" Not a polymorph method!" ;
350 :    
351 :     \ instance variables inside objects 27dec93py
352 :    
353 :     : instvar, ( addr -- ) dup , here 0 , 0 vallot swap !
354 :     'link @ 2 cells + @ IF 'link @ link, THEN
355 :     'link @ >r dup r@ cell+ ! :var# + @ dup vars +! r> 2 cells + !
356 :     DOES> dup 2@ swap state @ IF o+, ELSE ^ + nip nip THEN
357 :     early, ;
358 :    
359 :     : instptr> ( -- ) DOES> dup 2@ swap
360 :     state @ IF o+@, ELSE ^ + @ nip nip THEN late, ;
361 :    
362 :     : instptr, ( addr -- ) , here 0 , cell vallot swap !
363 :     instptr> ;
364 :    
365 :     : (o* ( i addr -- addr' ) dup @ :var# + @ 8aligned rot * + ;
366 :    
367 :     : instarray, ( addr -- ) , here 0 , cell vallot swap !
368 :     DOES> dup 2@ swap
369 :     state @ IF o+@*, ELSE ^ + @ nip nip (o* THEN
370 :     late, ;
371 :    
372 :     \ bind instance pointers 27mar94py
373 :    
374 :     : ((link ( addr -- o addr' ) 2@ swap ^ + ;
375 :    
376 :     : (link ( -- o addr ) bl word findo drop >body state @
377 :     IF postpone Literal postpone ((link EXIT THEN ((link ;
378 :    
379 :     : parent? ( class o -- class class' ) @
380 :     BEGIN 2dup = ?EXIT dup WHILE :parent + @ REPEAT ;
381 :    
382 :     : (bound ( obj1 obj2 adr2 -- ) >r over parent?
383 :     nip 0= abort" not the same class !" r> ! ;
384 :    
385 :     : (bind ( addr -- ) \ <name>
386 :     (link state @ IF postpone (bound EXIT THEN (bound ;
387 :    
388 :     : (sbound ( o addr -- ) dup cell+ @ swap (bound ;
389 :    
390 :     Forth definitions
391 :    
392 :     : bind ( o -- ) ' state @
393 :     IF postpone Literal postpone >body postpone (sbound EXIT THEN
394 :     >body (sbound ; immediate
395 :    
396 :     Objects definitions
397 :    
398 :     \ method implementation 29oct94py
399 :    
400 :     Variable m-name
401 :     Variable last-interface 0 last-interface !
402 :    
403 :     : interface, ( -- ) last-interface @
404 :     BEGIN dup WHILE dup , @ REPEAT drop ;
405 :    
406 :     : inter, ( iface -- )
407 :     align here over :inum + @ lastob @ + !
408 :     here over :ilen + @ dup allot move ;
409 :    
410 :     : interfaces, ( -- ) ob-interface @ lastob @ :iface + !
411 :     ob-interface @
412 :     BEGIN dup WHILE 2@ inter, REPEAT drop ;
413 :    
414 :     : lastob! ( -- ) lastob @ dup
415 :     BEGIN nip dup @ here cell+ 2 pick ! dup 0= UNTIL drop
416 : pazsan 1.7 dup , op! o@ lastob ! ;
417 : pazsan 1.1
418 :     : thread, ( -- ) classlist @ , ;
419 :     : var, ( -- ) methods @ , vars @ , ;
420 :     : parent, ( -- o parent )
421 :     o@ lastparent @ 2dup dup , 0 ,
422 :     dup IF :child + dup @ , ! ELSE , drop THEN ;
423 :     : 'link, ( -- )
424 :     'link @ ?dup 0=
425 :     IF lastparent @ dup IF :newlink + @ THEN THEN , ;
426 :     : cells, ( -- )
427 :     methods @ :init ?DO ['] crash , cell +LOOP ;
428 :    
429 :     \ method implementation 20feb95py
430 :    
431 :     types definitions
432 :    
433 :     : how: ( -- ) decl @ 0= abort" not twice!" 0 decl !
434 :     align interface,
435 :     lastob! thread, parent, var, 'link, 0 , cells, interfaces,
436 :     dup
437 :     IF dup :method# + @ >r :init + swap r> :init /string move
438 :     ELSE 2drop THEN ;
439 :    
440 :     : class; ( -- ) decl @ IF how: THEN 0 'link !
441 :     voc# @ drop-order old-current @ set-current ;
442 :    
443 :     : ptr ( -- ) Create immediate lastob @ here lastob ! instptr, ;
444 :     : asptr ( addr -- ) cell+ @ Create immediate
445 :     lastob @ here lastob ! , , instptr> ;
446 :    
447 : pazsan 1.10 : Fpostpone postpone postpone ; immediate
448 :    
449 : pazsan 1.1 : : ( <methodname> -- ) decl @ abort" HOW: missing! "
450 :     bl word findo 0= abort" not found"
451 :     dup exec? over early? or over >body cell+ @ 0< or
452 :     0= abort" not a method"
453 :     m-name ! :noname ;
454 :    
455 :     Forth
456 :    
457 :     : ; ( xt colon-sys -- ) postpone ;
458 :     m-name @ dup >body swap exec?
459 :     IF @ o@ +
460 :     ELSE dup cell+ @ 0< IF 2@ swap o@ + @ + THEN
461 :     THEN ! ; immediate
462 :    
463 :     Forth definitions
464 :    
465 :     \ object 23mar95py
466 :    
467 :     Create object immediate 0 (class \ do not create as subclass
468 :     cell var oblink \ create offset for backlink
469 :     static thread \ method/variable wordlist
470 :     static parento \ pointer to parent
471 :     static childo \ ptr to first child
472 :     static nexto \ ptr to next child of parent
473 :     static method# \ number of methods (bytes)
474 :     static size \ number of variables (bytes)
475 :     static newlink \ ptr to allocated space
476 :     static ilist \ interface list
477 :     method init
478 :     method dispose
479 :    
480 :     early class
481 :     early new immediate
482 :     early new[] immediate
483 :     early :
484 :     early ptr
485 :     early asptr
486 :     early []
487 :     early :: immediate
488 :     early class?
489 :     early super immediate
490 :     early self
491 :     early bind immediate
492 :     early is immediate
493 :     early bound
494 :     early link immediate
495 :     early ' immediate
496 :     early send immediate
497 : pazsan 1.7 early with immediate
498 :     early endwith immediate
499 : pazsan 1.10 early postpone immediate
500 : pazsan 1.1
501 :     \ base object class implementation part 23mar95py
502 :    
503 : pazsan 1.7 how: 0 parento !
504 :     0 childo !
505 :     0 nexto !
506 :     : class ( -- ) Create immediate o@ (class ;
507 :     : : ( -- ) Create immediate o@
508 :     decl @ IF instvar, ELSE instance, THEN ;
509 :     : ptr ( -- ) Create immediate o@
510 :     decl @ IF instptr, ELSE ptr, THEN ;
511 :     : asptr ( addr -- )
512 :     decl @ 0= abort" only in declaration!"
513 :     Create immediate o@ , cell+ @ , instptr> ;
514 :     : [] ( n -- ) Create immediate o@
515 :     decl @ IF instarray, ELSE array, THEN ;
516 :     : new ( -- o ) o@ state @
517 : pazsan 1.10 IF Fpostpone Literal Fpostpone new, ELSE new, THEN ;
518 : pazsan 1.7 : new[] ( n -- o ) o@ state @
519 : pazsan 1.10 IF Fpostpone Literal Fpostpone new[], ELSE new[], THEN ;
520 : pazsan 1.7 : dispose ( -- ) ^ size @ dispose, ;
521 :     : bind ( addr -- ) (bind ;
522 :     : bound ( o1 o2 addr2 -- ) (bound ;
523 :     : link ( -- o addr ) (link ;
524 :     : class? ( class -- flag ) ^ parent? nip 0<> ;
525 :     : :: ( -- )
526 :     state @ IF ^ true method, ELSE inherit THEN ;
527 :     : super ( -- ) parento true method, ;
528 :     : is ( cfa -- ) (is ;
529 :     : self ( -- obj ) ^ ;
530 :     : init ( -- ) ;
531 :    
532 :     : ' ( -- xt ) bl word findo 0= abort" not found!"
533 : pazsan 1.10 state @ IF Fpostpone Literal THEN ;
534 : pazsan 1.7 : send ( xt -- ) execute ;
535 : pazsan 1.10 : postpone ( -- ) o@ add-order Fpostpone Fpostpone drop-order ;
536 : pazsan 1.7
537 :     : with ( -- )
538 : pazsan 1.10 state @ oset? 0= and IF Fpostpone >o THEN
539 :     o@ add-order voc# ! false to oset? ;
540 :     : endwith Fpostpone o>
541 : pazsan 1.7 voc# @ drop-order ;
542 : pazsan 1.1 class; \ object
543 :    
544 :     \ interface 01sep96py
545 :    
546 :     Objects definitions
547 :    
548 :     : implement ( interface -- )
549 :     align here over , ob-interface @ , ob-interface !
550 : pazsan 1.2 :ilist + @ >r get-order r> swap 1+ set-order 1 voc# +! ;
551 : pazsan 1.1
552 :     : inter-method, ( interface -- )
553 :     :ilist + @ bl word count 2dup s" '" compare
554 :     0= dup >r IF 2drop bl word count THEN
555 :     rot search-wordlist
556 :     dup 0= abort" Not an interface method!"
557 :     r> IF drop state @ IF postpone Literal THEN EXIT THEN
558 :     0< state @ and IF compile, ELSE execute THEN ;
559 :    
560 :     Variable inter-list
561 :     Variable lastif
562 :     Variable inter#
563 :    
564 :     Vocabulary interfaces interfaces definitions
565 :    
566 :     : method ( -- ) mallot Create , inter# @ ,
567 :     DOES> 2@ swap o@ + @ + @ execute ;
568 :    
569 :     : how: ( -- ) align
570 :     here lastif @ ! 0 decl !
571 : pazsan 1.4 here last-interface @ , last-interface !
572 :     inter-list @ , methods @ , inter# @ ,
573 : pazsan 1.1 methods @ :inum cell+ ?DO ['] crash , LOOP ;
574 :    
575 :     : interface; ( -- ) old-current @ set-current
576 :     previous previous ;
577 :    
578 :     : : ( <methodname> -- ) decl @ abort" HOW: missing! "
579 :     bl word count lastif @ @ :ilist + @
580 :     search-wordlist 0= abort" not found"
581 :     dup >body cell+ @ 0< 0= abort" not a method"
582 :     m-name ! :noname ;
583 :    
584 :     Forth
585 :    
586 :     : ; ( xt colon-sys -- ) postpone ;
587 :     m-name @ >body @ lastif @ @ + ! ; immediate
588 :    
589 :     Forth definitions
590 :    
591 :     : interface ( -- )
592 :     Create here lastif ! 0 , get-current old-current !
593 :     last-interface @ dup IF :inum @ THEN 1 cells - inter# !
594 :     get-order wordlist
595 :     dup inter-list ! dup set-current swap 1+ set-order
596 :     true decl !
597 :     0 vars ! :inum cell+ methods ! also interfaces
598 :     DOES> @ decl @ IF implement ELSE inter-method, THEN ;
599 :    
600 :     previous previous
601 : pazsan 1.7

CVS Admin

Powered by ViewCVS 1.0-dev
(Powered by ViewCVS)

ViewCVS and CVS Help