Refactor all object-realated manipulation to module object.
[ilari-esolangs.git] / object.h
blob0566efb4b77bb58fbc3fd6524cf3ed025523a6ff
1 #ifndef _object__h__included__
2 #define _object__h__included__
4 #include "class.h"
6 struct context;
7 struct message;
9 /* Object marked for garbage collection. */
10 #define OF_MARKED_FOR_GC 1
11 /* Already execuing message handler. */
12 #define OF_EXECUTING 2
14 /* Object. */
15 struct object;
17 /* Object list. */
18 struct objectlist;
20 /******************************************************************************
22 * DESCRIPTION:
23 * Read object field.
25 * PARAMETERS:
26 * object The object to read.
27 * slot Field slot number.
29 * RETURN VALUE:
30 * Read value, or NULL if slot is invalid.
32 *****************************************************************************/
33 struct object* object_read_field(struct object* object, size_t slot);
35 /******************************************************************************
37 * DESCRIPTION:
38 * Write object field. Writes to nonexistent slots are discarded.
40 * PARAMETERS:
41 * object The object to write.
42 * slot Field slot number.
43 * towrite Refrence to write.
45 *****************************************************************************/
46 void object_write_field(struct object* object, size_t slot,
47 struct object* towrite);
49 /******************************************************************************
51 * DESCRIPTION:
52 * Get class of object.
54 * PARAMETERS:
55 * object The object to interrogate.
57 * RETURN VALUE:
58 * Class of object.
60 *****************************************************************************/
61 struct class* object_class(struct object* object);
63 /******************************************************************************
65 * DESCRIPTION:
66 * Check object EXECUTING flag.
68 * PARAMETERS:
69 * object The object to interrogate.
71 * RETURN VALUE:
72 * 1 if object is executing, 0 otherwise.
74 *****************************************************************************/
75 unsigned object_is_executing(struct object* object);
77 /******************************************************************************
79 * DESCRIPTION:
80 * Set object EXECUTING flag.
82 * PARAMETERS:
83 * object The object to manipulate.
85 *****************************************************************************/
86 void object_set_executing(struct object* object);
88 /******************************************************************************
90 * DESCRIPTION:
91 * Clear object EXECUTING flag.
93 * PARAMETERS:
94 * object The object to manipulate.
96 *****************************************************************************/
97 void object_clear_executing(struct object* object);
100 /******************************************************************************
102 * DESCRIPTION:
103 * Check object MARKED_FOR_GC flag.
105 * PARAMETERS:
106 * object The object to interrogate.
108 * RETURN VALUE:
109 * 1 if object is marked for GC, 0 otherwise.
111 *****************************************************************************/
112 unsigned object_is_gcmark(struct object* object);
114 /******************************************************************************
116 * DESCRIPTION:
117 * Set object MARKED_FOR_GC flag.
119 * PARAMETERS:
120 * object The object to manipulate.
122 *****************************************************************************/
123 void object_set_gcmark(struct object* object);
125 /******************************************************************************
127 * DESCRIPTION:
128 * Clear object MARKED_FOR_GC flag.
130 * PARAMETERS:
131 * object The object to manipulate.
133 *****************************************************************************/
134 void object_clear_gcmark(struct object* object);
136 /******************************************************************************
138 * DESCRIPTION:
139 * Create object of specified class.
141 * PARAMETERS:
142 * class The class of new object.
144 * RETURN VALUE:
145 * The newly created object.
147 *****************************************************************************/
148 struct object* object_create_ordinary(struct class* class);
150 /******************************************************************************
152 * DESCRIPTION:
153 * Create special object.
155 * PARAMETERS:
156 * handler Handler object.
157 * fields Fields for local object. Note that if this
158 * is nonzero, new class is created and
159 * registered.
161 * RETURN VALUE:
162 * The newly created object.
164 *****************************************************************************/
165 struct object* object_create_special(void (*handler)(struct context* ctx,
166 struct message* msg), size_t fields);
168 /******************************************************************************
170 * DESCRIPTION:
171 * Create object list.
173 * RETURN VALUE:
174 * The newly created object list.
176 *****************************************************************************/
177 struct objectlist* objectlist_create();
179 /******************************************************************************
181 * DESCRIPTION:
182 * Destroy object list and all objects in it.
184 * PARAMETERS:
185 * objectlist Object list to destroy.
187 *****************************************************************************/
188 void objectlist_destroy(struct objectlist* objectlist);
190 /******************************************************************************
192 * DESCRIPTION:
193 * Add object to object list.
195 * PARAMETERS:
196 * objectlist Object list to add object to.
197 * object Object to add.
199 *****************************************************************************/
200 void objectlist_add(struct objectlist* objectlist, struct object* object);
202 /******************************************************************************
204 * DESCRIPTION:
205 * Kill all marked objects from list.
207 * PARAMETERS:
208 * objectlist Object list to manipulate.
210 * RETURN VALUE:
211 * 1 if more remain, 0 if all are gone.
213 *****************************************************************************/
214 unsigned objectlist_kill_marked(struct objectlist* objectlist);
216 /******************************************************************************
218 * DESCRIPTION:
219 * Set object MARKED_FOR_GC flag for all objects in list.
221 * PARAMETERS:
222 * objectlist The object list to manipulate.
224 *****************************************************************************/
225 void objectlist_set_gcmark_all(struct objectlist* objectlist);
227 /******************************************************************************
229 * DESCRIPTION:
230 * Execute special action, if any.
232 * PARAMETERS:
233 * object The object.
234 * ctx Context to pass in.
235 * msg Message to pass in.
237 * RETURN VALUE:
238 * 1 if special action was executed, 0 if there is none.
240 *****************************************************************************/
241 unsigned object_exec_special(struct object* object, struct context* ctx,
242 struct message* msg);
245 #endif