1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2 ;; UrForth level
1: self
-hosting
32-bit Forth compiler
3 ;; Copyright
(C
) 2020 Ketmar Dark
// Invisible Vector
5 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6 ;; slightly more complicated OO system than mini
-oof
7 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
21 .( Object cls
=) Object
.hex8 cr
23 Object method
: clsinit
( -- )
24 endcr
." clsinit: cls=" self
.hex8 cr
26 endcr
." class init! clsvar=" clsvar
. cr
29 Object method
: init
( -- )
30 ." init " class
-name type
." (" static
-class
-name type
." ) ! self=" self
.hex8
31 ." class=" my
-class
.hex8 cr
33 ." clsvar=" clsvar
. cr
39 Object method
: .xy
( -- ) ." x=" x
. ." y=" y
0 .r
;
41 Object
::invoke Object clsinit
43 Object oop
:new
-allot value obj
46 obj
::invoke Object init
56 class
-method child
-class
-mt
59 method
(unknown
-dispatch
) ( ... addr count
-- )
62 Child method: init ( -- )
63 ." init " class
-name type
." (" static
-class
-name type
." ) ! self=" self
.hex8
64 ." class=" my
-class
.hex8 cr
66 ." child inited; " .xy cr
67 ." :0:x=" self var^ x @
. cr
68 \
." :1:x=" addr
: x @
. cr
69 ." :1:x=" to^ x @
. cr
73 Child method: .xy ( -- ) ." [" inherited .xy ." ]" ;
75 Child method: (unknown-dispatch) ( ... addr count -- )
76 ." UNKNOWN DISPATCH \`" type
." \` in self=0x" self
.hex8 cr
79 Child method: dispatch-test ( -- )
80 ." testing dispatch: self=0x" self
.hex8
." class=0x" my
-class
.hex8 cr
81 \
" child-cv" dispatch
-str
82 " child-mt" dispatch
-str
83 ." dispatch complete: self=0x" self
.hex8 cr
84 ." dispatch class: " self invoke class
-name type cr
85 ." static class: 0x" static
-class
.hex8 cr
88 Child oop:new-allot value childobj
91 childobj ::invoke Object init
93 obj
::invoke Object init
95 : a childobj
::invoke Object init
;
98 Child method: child-class-mt child-cv . cr 69 to child-cv ." Child class method; " child-cv . cr ;
99 Child method: child-mt child-var . cr 666 to child-var ." childcv! " child-cv . child-var . cr ;
101 Child Child:: child-class-mt
102 childobj Child:: child-mt
104 childobj ::invoke Child dispatch-test
106 childobj " child-yy" ::dispatch-str
107 childobj " dispatch-test" ::dispatch-str
108 childobj " child-xx" ::dispatch-str
109 childobj " child-mt" ::dispatch-str
110 childobj ." *** class name: " ::invoke Object class-name type cr
112 childobj ::invoke Child x ." x=" . cr