1
2 //metadoc Call copyright Steve Dekorte 2002
3 //metadoc Call license BSD revised
4 //metadoc Call category Core
5 /*metadoc Call description
6 Call stores slots related to activation.
7 */
8
9 #include "IoCall.h"
10 #include "IoState.h"
11 #include "IoObject.h"
12
13 static const char *protoId = "Call";
14
15 #define DATA(self) ((IoCallData *)IoObject_dataPointer(self))
16
IoCall_newTag(void * state)17 IoTag *IoCall_newTag(void *state)
18 {
19 IoTag *tag = IoTag_newWithName_(protoId);
20 IoTag_state_(tag, state);
21 IoTag_cloneFunc_(tag, (IoTagCloneFunc *)IoCall_rawClone);
22 IoTag_markFunc_(tag, (IoTagMarkFunc *)IoCall_mark);
23 IoTag_freeFunc_(tag, (IoTagFreeFunc *)IoCall_free);
24 return tag;
25 }
26
IoCall_initSlots(IoCall * self)27 void IoCall_initSlots(IoCall *self)
28 {
29 IoObject *ioNil = IOSTATE->ioNil;
30 DATA(self)->sender = ioNil;
31 DATA(self)->message = ioNil;
32 DATA(self)->slotContext = ioNil;
33 DATA(self)->target = ioNil;
34 DATA(self)->activated = ioNil;
35 DATA(self)->coroutine = ioNil;
36 DATA(self)->stopStatus = MESSAGE_STOP_STATUS_NORMAL;
37 }
38
IoCall_proto(void * vState)39 IoCall *IoCall_proto(void *vState)
40 {
41 IoState *state = (IoState *)vState;
42
43 IoMethodTable methodTable[] = {
44 {"sender", IoCall_sender},
45 {"message", IoCall_message},
46 {"slotContext", IoCall_slotContext},
47 {"target", IoCall_target},
48 {"activated", IoCall_activated},
49 {"coroutine", IoCall_coroutine},
50 {"evalArgAt", IoCall_evalArgAt},
51 {"argAt", IoCall_argAt},
52 {"stopStatus", IoCall_stopStatus},
53 {"setStopStatus", IoCall_setStopStatus},
54 {NULL, NULL},
55 };
56
57 IoObject *self = IoObject_new(state);
58
59 IoObject_setDataPointer_(self, io_calloc(1, sizeof(IoCallData)));
60 IoObject_tag_(self, IoCall_newTag(state));
61 IoCall_initSlots(self);
62
63 IoState_registerProtoWithId_((IoState *)state, self, protoId);
64
65 IoObject_addMethodTable_(self, methodTable);
66 return self;
67 }
68
IoCall_rawClone(IoCall * proto)69 IoCall *IoCall_rawClone(IoCall *proto)
70 {
71 IoObject *self = IoObject_rawClonePrimitive(proto);
72 IoObject_setDataPointer_(self, cpalloc(IoObject_dataPointer(proto), sizeof(IoCallData)));
73 //printf("IoCall_rawClone() %p|%p\n", (void *)self, IoObject_dataPointer(self));
74 IoCall_initSlots(self);
75 return self;
76 }
77
IoCall_new(IoState * state)78 IoCall *IoCall_new(IoState *state)
79 {
80 IoObject *proto = IoState_protoWithId_((IoState *)state, protoId);
81 return IOCLONE(proto);
82 }
83
IoCall_with(void * state,IoObject * sender,IoObject * target,IoObject * message,IoObject * slotContext,IoObject * activated,IoObject * coroutine)84 IoCall *IoCall_with(void *state,
85 IoObject *sender,
86 IoObject *target,
87 IoObject *message,
88 IoObject *slotContext,
89 IoObject *activated,
90 IoObject *coroutine)
91 {
92 IoCall *self = IoCall_new(state);
93
94 DATA(self)->sender = sender;
95 DATA(self)->target = target;
96 DATA(self)->message = message;
97 DATA(self)->slotContext = slotContext;
98 DATA(self)->activated = activated;
99 DATA(self)->coroutine = coroutine;
100 DATA(self)->stopStatus = MESSAGE_STOP_STATUS_NORMAL;
101 return self;
102 }
103
IoCall_mark(IoCall * self)104 void IoCall_mark(IoCall *self)
105 {
106 IoCallData *d = DATA(self);
107
108 IoObject_shouldMark(d->sender);
109 IoObject_shouldMark(d->target);
110 IoObject_shouldMark(d->message);
111 IoObject_shouldMark(d->slotContext);
112 IoObject_shouldMark(d->activated);
113 IoObject_shouldMark(d->coroutine);
114 }
115
IoCall_free(IoCall * self)116 void IoCall_free(IoCall *self)
117 {
118 io_free(IoObject_dataPointer(self));
119 }
120
IO_METHOD(IoCall,sender)121 IO_METHOD(IoCall, sender)
122 {
123 /*doc Call sender
124 Returns the sender value.
125 */
126
127 return DATA(self)->sender;
128 }
129
IO_METHOD(IoCall,message)130 IO_METHOD(IoCall, message)
131 {
132 /*doc Call message
133 Returns the message value.
134 */
135
136 return DATA(self)->message;
137 }
138
IO_METHOD(IoCall,target)139 IO_METHOD(IoCall, target)
140 {
141 /*doc Call target
142 Returns the target value.
143 */
144
145 return DATA(self)->target;
146 }
147
IO_METHOD(IoCall,slotContext)148 IO_METHOD(IoCall, slotContext)
149 {
150 /*doc Call slotContext
151 Returns the slotContext value.
152 */
153
154 return DATA(self)->slotContext;
155 }
156
IO_METHOD(IoCall,activated)157 IO_METHOD(IoCall, activated)
158 {
159 /*doc Call activated
160 Returns the activated value.
161 */
162
163 return DATA(self)->activated;
164 }
165
IO_METHOD(IoCall,coroutine)166 IO_METHOD(IoCall, coroutine)
167 {
168 /*doc Call coroutine
169 Returns the coroutine in which the message was sent.
170 */
171
172 return DATA(self)->coroutine;
173 }
174
IO_METHOD(IoCall,evalArgAt)175 IO_METHOD(IoCall, evalArgAt)
176 {
177 /*doc Call evalArgAt(argNumber)
178 Evaluates the specified argument of the Call's message in the context of its sender.
179 */
180
181 int n = IoMessage_locals_intArgAt_(m, locals, 0);
182 IoCallData *data = DATA(self);
183 return IoMessage_locals_valueArgAt_(data->message, data->sender, n);
184 }
185
IO_METHOD(IoCall,argAt)186 IO_METHOD(IoCall, argAt)
187 {
188 /*doc Call argAt(argNumber)
189 Returns the message's argNumber arg. Shorthand for same as call message argAt(argNumber).
190 */
191
192 return IoMessage_argAt(DATA(self)->message, locals, m);
193 }
194
IoCall_rawStopStatus(IoCall * self)195 int IoCall_rawStopStatus(IoCall *self)
196 {
197 return DATA(self)->stopStatus;
198 }
199
IO_METHOD(IoCall,stopStatus)200 IO_METHOD(IoCall, stopStatus)
201 {
202 /*doc Call stopStatus
203 Returns the stop status on the call. (description of stopStatus will
204 be added once we decide whether or not to keep it)
205 */
206 return IoState_stopStatusObject(IOSTATE, DATA(self)->stopStatus);
207 }
208
IO_METHOD(IoCall,setStopStatus)209 IO_METHOD(IoCall, setStopStatus)
210 {
211 /*doc Call setStopStatus(aStatusObject)
212 Sets the stop status on the call.
213 */
214 IoObject *status = IoMessage_locals_valueArgAt_(m, locals, 0);
215 DATA(self)->stopStatus = IoState_stopStatusNumber(IOSTATE, status);
216 return self;
217 }
218