-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathobj.4th
39 lines (29 loc) · 834 Bytes
/
obj.4th
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
only vocabulary obj
also obj definitions
\ Queste parole Forth sono utili per definire un semplice
\ sistema orientato agli oggetti
32 value obj-stack-max
1 cells array obj-stack obj-stack-max allot
0 value obj-ptr
: obj-check-overflow ( -- )
obj-ptr obj-stack-max >= if abort" Object stack overflow" then ;
: obj-check-underflow ( -- )
obj-ptr 0= if abort" Object stack underflow" then ;
: o@ ( -- obj )
obj-check-underflow
obj-ptr 1- obj-stack @ ;
: >o ( obj -- )
obj-check-overflow
obj-ptr obj-stack !
obj-ptr 1+ to obj-ptr ;
: o> ( -- obj )
obj-check-underflow
obj-ptr 1- obj-stack @
obj-ptr 1- to obj-ptr ;
: (o.)
obj-ptr 0 do
i obj-stack @ . space cr
loop ;
: o. ( -- )
obj-ptr 0 = if ." Object stack empty" else (o.) then ;
: odrop ( -- ) o> drop ;