Updating built in Io code to use += instead of x = x + y
[io/quag.git] / libs / iovm / source / IoState_inline.h
blob95a2039aac298e509b6f7954d2f7e0fdef7014d0
1 /*#io
2 docCopyright("Steve Dekorte", 2002)
3 docLicense("BSD revised")
4 */
6 #ifdef IOSTATE_C
7 #define IO_IN_C_FILE
8 #endif
9 #include "Common_inline.h"
10 #ifdef IO_DECLARE_INLINES
12 // booleans --------------------------------------------------------
14 #define SIOSYMBOL(stringConstant) IoState_symbolWithCString_(self, stringConstant)
16 #define IOASSERT(value, message) \
17 if (!(value)) { IoState_error_(IOSTATE, m, "Io Assertion '%s'", message); }
19 #define IOCOLLECTOR (IOSTATE->collector)
21 #define IONIL(self) (IOSTATE->ioNil)
22 #define ISNIL(self) (self == IOSTATE->ioNil)
24 // booleans --------------------------------------------------------
26 #define ISBOOL(self) (((self)==IOSTATE->ioFalse) \
27 || ((self)==IOSTATE->ioNil) \
28 || ((self)==IOSTATE->ioTrue))
30 #define IOSUCCESS(self) IOTRUE(self)
31 #define ISSUCCESS(self) ISTRUE(self)
33 #define IOFAILURE(self) IOFALSE(self)
34 #define ISFAILURE(self) ISFALSE(self)
36 inline IoObject *IOBOOL(IoObject *self, int b);
38 #if !defined(IoObjectDataDefined)
39 typedef struct IoObjectData IoObjectData;
40 #endif
42 IOINLINE IoObject *IOTRUE(IoObject *self)
44 return IOSTATE->ioTrue;
47 IOINLINE int ISTRUE(IoObject *self)
49 return self != IOSTATE->ioNil && self != IOSTATE->ioFalse;
52 IOINLINE IoObject *IOFALSE(IoObject *self)
54 return IOSTATE->ioFalse;
57 IOINLINE int ISFALSE(IoObject *self)
59 return self == IOSTATE->ioNil || self == IOSTATE->ioFalse;
62 IOINLINE IoObject *IOBOOL(IoObject *self, int b)
64 return b ? IOTRUE(self) : IOFALSE(self);
67 // collector --------------------------------------------------------
69 IOINLINE IoObject *IoState_retain_(IoState *self, IoObject *v)
71 IoObject_isReferenced_(v, 1);
72 Collector_retain_(self->collector, v);
73 return v;
76 IOINLINE void IoState_stopRetaining_(IoState *self, IoObject *v)
78 Collector_stopRetaining_(self->collector, v);
81 IOINLINE void *IoState_unreferencedStackRetain_(IoState *self, IoObject *v)
83 if (self->currentCoroutine)
85 Collector_value_addingRefTo_(self->collector, self->currentCoroutine, v);
88 Stack_push_(self->currentIoStack, v);
89 return v;
92 IOINLINE void *IoState_stackRetain_(IoState *self, IoObject *v)
94 IoObject_isReferenced_(v, 1);
95 IoState_unreferencedStackRetain_(self, v);
96 return v;
99 IOINLINE void IoState_addValue_(IoState *self, IoObject *v)
101 Collector_addValue_(self->collector, v);
102 IoState_unreferencedStackRetain_(self, v);
105 IOINLINE void IoState_addValueIfNecessary_(IoState *self, IoObject *v)
107 if (v->prev)
109 Collector_addValue_(self->collector, v);
111 IoState_unreferencedStackRetain_(self, v);
114 IOINLINE void IoState_pushCollectorPause(IoState *self)
116 Collector_pushPause(self->collector);
119 IOINLINE void IoState_popCollectorPause(IoState *self)
121 Collector_popPause(self->collector);
124 IOINLINE void IoState_clearRetainStack(IoState *self)
126 Stack_clear(((IoState *)self)->currentIoStack);
129 IOINLINE uintptr_t IoState_pushRetainPool(void *self)
131 uintptr_t m = Stack_pushMarkPoint(((IoState *)self)->currentIoStack);
132 return m;
135 IOINLINE void IoState_clearTopPool(void *self)
137 Stack *stack = ((IoState *)self)->currentIoStack;
138 //Stack_popMark(stack);
139 //Stack_pushMark(stack);
140 Stack_clearTop(stack);
143 IOINLINE void IoState_popRetainPool(void *self)
145 Stack *stack = ((IoState *)self)->currentIoStack;
146 Stack_popMark(stack);
149 IOINLINE void IoState_popRetainPool_(void *self, uintptr_t mark)
151 Stack *stack = ((IoState *)self)->currentIoStack;
152 Stack_popMarkPoint_(stack, mark);
155 IOINLINE void IoState_popRetainPoolExceptFor_(void *state, void *obj)
157 IoState *self = (IoState *)state;
158 #ifdef STACK_POP_CALLBACK
159 IoObject_isReferenced_(((IoObject *)obj), 1);
160 #endif
161 IoState_popRetainPool(self);
162 IoState_stackRetain_(self, (IoObject *)obj);
165 // message args --------------------------------------------------------
167 #define IOMESSAGEDATA(self) ((IoMessageData *)IoObject_dataPointer(self))
169 IOINLINE IoObject *IoMessage_locals_quickValueArgAt_(IoMessage *self, IoObject *locals, int n)
171 IoMessage *m = (IoMessage *)List_at_(IOMESSAGEDATA(self)->args, n);
173 if (m)
175 IoMessageData *md = IOMESSAGEDATA(m);
176 IoObject *v = md->cachedResult;
178 if (v && !md->next)
180 return v;
183 return IoMessage_locals_performOn_(m, locals, locals);
186 return IOSTATE->ioNil;
189 IOINLINE IoObject *IoMessage_locals_valueArgAt_(IoMessage *self, IoObject *locals, int n)
191 return IoMessage_locals_quickValueArgAt_(self, locals, n);
193 List *args = IOMESSAGEDATA(self)->args;
194 IoMessage *m = (IoMessage *)List_at_(args, n);
196 if (m)
198 return IoMessage_locals_performOn_(m, locals, locals);
201 return IOSTATE->ioNil;
205 IOINLINE IoObject *IoMessage_locals_firstStringArg(IoMessage *self, IoObject *locals)
207 // special case this, since it's used for setSlot()
208 List *args = IOMESSAGEDATA(self)->args;
210 if (List_size(args))
212 IoMessage *m = (IoMessage *)List_rawAt_(args, 0);
214 if (m)
216 IoMessageData *md = IOMESSAGEDATA(m);
217 IoObject *v = md->cachedResult;
219 // avoid calling IoMessage_locals, if possible
221 if (v && IoObject_isSymbol(v) && (md->next == NULL))
223 return v;
228 return IoMessage_locals_symbolArgAt_(self, locals, 0);
231 // --------------------------
233 IOINLINE void IoState_break(IoState *self, IoObject *v)
235 self->stopStatus = MESSAGE_STOP_STATUS_BREAK;
236 self->returnValue = v;
239 IOINLINE void IoState_continue(IoState *self)
241 self->stopStatus = MESSAGE_STOP_STATUS_CONTINUE;
244 IOINLINE void IoState_eol(IoState *self)
246 self->stopStatus = MESSAGE_STOP_STATUS_EOL;
249 IOINLINE void IoState_return(IoState *self, IoObject *v)
251 self->stopStatus = MESSAGE_STOP_STATUS_RETURN;
252 self->returnValue = v;
255 IOINLINE void IoState_resetStopStatus(IoState *self)
257 self->stopStatus = MESSAGE_STOP_STATUS_NORMAL;
260 IOINLINE int IoState_handleStatus(IoState *self)
262 switch (self->stopStatus)
264 case MESSAGE_STOP_STATUS_RETURN:
265 return 1;
267 case MESSAGE_STOP_STATUS_BREAK:
268 IoState_resetStopStatus(self);
269 return 1;
271 case MESSAGE_STOP_STATUS_CONTINUE:
272 IoState_resetStopStatus(self);
273 return 0;
275 default:
276 return 0;
280 IOINLINE IoObject* IoState_stopStatusObject(IoState *self, int stopStatus)
282 switch(stopStatus)
284 case MESSAGE_STOP_STATUS_NORMAL:
285 return self->ioNormal;
287 case MESSAGE_STOP_STATUS_BREAK:
288 return self->ioBreak;
290 case MESSAGE_STOP_STATUS_CONTINUE:
291 return self->ioContinue;
293 case MESSAGE_STOP_STATUS_RETURN:
294 return self->ioReturn;
296 case MESSAGE_STOP_STATUS_EOL:
297 return self->ioEol;
299 default:
300 return self->ioNormal;
304 IOINLINE int IoState_stopStatusNumber(IoState *self, IoObject *obj)
306 if (obj == self->ioNormal)
307 return MESSAGE_STOP_STATUS_NORMAL;
309 if (obj == self->ioBreak)
310 return MESSAGE_STOP_STATUS_BREAK;
312 if (obj == self->ioContinue)
313 return MESSAGE_STOP_STATUS_CONTINUE;
315 if (obj == self->ioReturn)
316 return MESSAGE_STOP_STATUS_RETURN;
318 if (obj == self->ioEol)
319 return MESSAGE_STOP_STATUS_EOL;
321 return MESSAGE_STOP_STATUS_NORMAL;
325 #undef IO_IN_C_FILE
326 #endif