2 \ ** ficl/softwords/classes.fr
3 \ ** F I C L 2 . 0 C L A S S E S
10 \ REF subclass holds a pointer to an object. It's
11 \ mainly for aggregation to help in making data structures.
17 : get ( inst class -- refinst refclass )
19 : set ( refinst refclass inst class -- )
23 object subclass c-byte
30 object subclass c-2byte
37 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 2:this -- }
108 this --> get-ptr ( addr )
109 this --> @size index * + ( addr' )
116 \ ** C - C E L L P T R
117 \ Models a pointer to cell (a 32 or 64 bit scalar).
118 c-ptr subclass c-cellPtr
119 : @size 2drop 1 cells ;
120 \ fetch and store through the pointer
121 : get ( inst class -- cell )
124 : set ( value inst class -- )
130 \ ** C - 4 B Y T E P T R
131 \ Models a pointer to a quadbyte scalar
132 c-ptr subclass c-4bytePtr
134 \ fetch and store through the pointer
135 : get ( inst class -- value )
138 : set ( value inst class -- )
143 \ ** C - 2 B Y T E P T R
144 \ Models a pointer to a 16 bit scalar
145 c-ptr subclass c-2bytePtr
147 \ fetch and store through the pointer
148 : get ( inst class -- value )
151 : set ( value inst class -- )
157 \ ** C - B Y T E P T R
158 \ Models a pointer to an 8 bit scalar
159 c-ptr subclass c-bytePtr
161 \ fetch and store through the pointer
162 : get ( inst class -- value )
165 : set ( value inst class -- )