1 \ ** ficl/softwords/classes.fr
2 \ ** F I C L 2 . 0 C L A S S E S
6 \ $FreeBSD: src/sys/boot/ficl/softwords/classes.fr,v 1.1.6.1 2000/07/06 23:51:46 obrien Exp $
8 .( loading ficl utility classes ) cr
11 \ REF subclass holds a pointer to an object. It's
12 \ mainly for aggregation to help in making data structures.
18 : get ( inst class -- refinst refclass )
20 : set ( refinst refclass inst class -- )
24 object subclass c-byte
31 object subclass c-2byte
38 object subclass c-4byte
45 object subclass c-cell
54 \ Base class for pointers to scalars (not objects).
55 \ Note: use c-ref to make references to objects. C-ptr
56 \ subclasses refer to untyped quantities of various sizes.
58 \ Derived classes must specify the size of the thing
59 \ they point to, and supply get and set methods.
61 \ All derived classes must define the @size method:
62 \ @size ( inst class -- addr-units )
63 \ Returns the size in address units of the thing the pointer
68 \ get the value of the pointer
69 : get-ptr ( inst class -- addr )
74 \ set the pointer to address supplied
75 : set-ptr ( addr inst class -- )
80 \ force the pointer to be null
82 0 -rot c-ptr => .addr c-cell => set
85 \ return flag indicating null-ness
86 : ?null ( inst class -- flag )
90 \ increment the pointer in place
91 : inc-ptr ( inst class -- )
92 2dup 2dup ( i c i c i c )
93 c-ptr => get-ptr -rot ( i c addr i c )
94 --> @size + -rot ( addr' i c )
98 \ decrement the pointer in place
99 : dec-ptr ( inst class -- )
100 2dup 2dup ( i c i c i c )
101 c-ptr => get-ptr -rot ( i c addr i c )
102 --> @size - -rot ( addr' i c )
106 \ index the pointer in place
107 : index-ptr ( index inst class -- )
108 locals| class inst index |
109 inst class c-ptr => get-ptr ( addr )
110 inst class --> @size index * + ( addr' )
111 inst class c-ptr => set-ptr
117 \ ** C - C E L L P T R
118 \ Models a pointer to cell (a 32 or 64 bit scalar).
119 c-ptr subclass c-cellPtr
120 : @size 2drop 1 cells ;
121 \ fetch and store through the pointer
122 : get ( inst class -- cell )
125 : set ( value inst class -- )
132 \ Models a pointer to an int (a 32 bit scalar).
133 c-ptr subclass c-4bytePtr
135 \ fetch and store through the pointer
136 : get ( inst class -- value )
139 : set ( value inst class -- )
145 \ ** C - 2 B Y T E P T R
146 \ Models a pointer to a 16 bit scalar
147 c-ptr subclass c-2bytePtr
149 \ fetch and store through the pointer
150 : get ( inst class -- value )
153 : set ( value inst class -- )
159 \ ** C - B Y T E P T R
160 \ Models a pointer to an 8 bit scalar
161 c-ptr subclass c-bytePtr
163 \ fetch and store through the pointer
164 : get ( inst class -- value )
167 : set ( value inst class -- )