-
Notifications
You must be signed in to change notification settings - Fork 0
/
mini-oof-BPaysan-by-bob-edwards.txt
114 lines (94 loc) · 1.67 KB
/
mini-oof-BPaysan-by-bob-edwards.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
MINI-OOF by Bernd Paysan 1998 adapted by Bob Edwards 24th July 2021
DEFINED? *MINI-OOF* [IF] forget *MINI-OOF* [THEN]
: *MINI-OOF* ;
\ Words missing from the esp32forth system
: NOOP ;
: /STRING
DUP >R -
SWAP R> +
SWAP
;
\ The object oriented extensions
: METHOD
CREATE
OVER , SWAP
CELL+ SWAP
DOES>
@ OVER @ +
@ EXECUTE
;
: VAR
CREATE
OVER , +
DOES>
@ +
;
: CLASS
DUP
2@ SWAP ;
: END-CLASS
CREATE
HERE >R
, DUP ,
2 CELLS ?DO
['] NOOP ,
1 CELLS +LOOP
CELL+ DUP CELL+ R>
ROT
@
2 CELLS
/STRING
CMOVE
;
: DEFINES
' >BODY @ + !
;
: NEW
HERE OVER @ ALLOT
SWAP OVER !
;
: ::
' >BODY @ + @ ,
;
CREATE OBJECT
1 cells , 2 cells ,
\ Example MINI-OOF code
object class
cell var teeth#
cell var height
method speak
method greet
method walk
method add.
end-class pet
:noname ." pet speaks" drop ; pet defines speak
:noname ." pet greets" drop ; pet defines greet
:noname ." pet walks" drop ; pet defines walk
:noname drop + ." n1 + n2 = " . ; pet defines add.
pet class
method happy
end-class cat
:noname ." cat purrs" drop ; cat defines happy
:noname ." cat says meow" drop ; cat defines speak
:noname ." cat raises tail" drop ; cat defines greet
pet class
end-class dog
:noname ." dog says wuff" drop ; dog defines speak
:noname ." dog wags tail" drop ; dog defines greet
cat new constant tibby
dog new constant fido
20 tibby teeth# !
30 fido teeth# !
50 tibby height !
75 fido height !
tibby teeth# @ . cr
fido height @ . cr
tibby greet
fido speak
tibby speak
34 56 fido add.
tibby walk
\ The above packs quite a lot of punch for very little code space
\ and may make all the difference to an otherwise awkward-to-code job
\ Bernd Paysans Mini-OOF pages
\ An extension to Mini-OOF by Gerry Jackson