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 $
7 \ $DragonFly: src/sys/boot/ficl/softwords/classes.fr,v 1.2 2003/06/17 04:28:18 dillon Exp $
9 .( loading ficl utility classes ) cr
12 \ REF subclass holds a pointer to an object. It's
13 \ mainly for aggregation to help in making data structures.
19 : get ( inst class -- refinst refclass )
21 : set ( refinst refclass inst class -- )
25 object subclass c-byte
32 object subclass c-2byte
39 object subclass c-4byte
46 object subclass c-cell
55 \ Base class for pointers to scalars (not objects).
56 \ Note: use c-ref to make references to objects. C-ptr
57 \ subclasses refer to untyped quantities of various sizes.
59 \ Derived classes must specify the size of the thing
60 \ they point to, and supply get and set methods.
62 \ All derived classes must define the @size method:
63 \ @size ( inst class -- addr-units )
64 \ Returns the size in address units of the thing the pointer
69 \ get the value of the pointer
70 : get-ptr ( inst class -- addr )
75 \ set the pointer to address supplied
76 : set-ptr ( addr inst class -- )
81 \ force the pointer to be null
83 0 -rot c-ptr => .addr c-cell => set
86 \ return flag indicating null-ness
87 : ?null ( inst class -- flag )
91 \ increment the pointer in place
92 : inc-ptr ( inst class -- )
93 2dup 2dup ( i c i c i c )
94 c-ptr => get-ptr -rot ( i c addr i c )
95 --> @size + -rot ( addr' i c )
99 \ decrement the pointer in place
100 : dec-ptr ( inst class -- )
101 2dup 2dup ( i c i c i c )
102 c-ptr => get-ptr -rot ( i c addr i c )
103 --> @size - -rot ( addr' i c )
107 \ index the pointer in place
108 : index-ptr ( index inst class -- )
109 locals| class inst index |
110 inst class c-ptr => get-ptr ( addr )
111 inst class --> @size index * + ( addr' )
112 inst class c-ptr => set-ptr
118 \ ** C - C E L L P T R
119 \ Models a pointer to cell (a 32 or 64 bit scalar).
120 c-ptr subclass c-cellPtr
121 : @size 2drop 1 cells ;
122 \ fetch and store through the pointer
123 : get ( inst class -- cell )
126 : set ( value inst class -- )
133 \ Models a pointer to an int (a 32 bit scalar).
134 c-ptr subclass c-4bytePtr
136 \ fetch and store through the pointer
137 : get ( inst class -- value )
140 : set ( value inst class -- )
146 \ ** C - 2 B Y T E P T R
147 \ Models a pointer to a 16 bit scalar
148 c-ptr subclass c-2bytePtr
150 \ fetch and store through the pointer
151 : get ( inst class -- value )
154 : set ( value inst class -- )
160 \ ** C - B Y T E P T R
161 \ Models a pointer to an 8 bit scalar
162 c-ptr subclass c-bytePtr
164 \ fetch and store through the pointer
165 : get ( inst class -- value )
168 : set ( value inst class -- )