IoObject *IoState_on_doCString_withLabel_(IoState *self, IoObject *target, const char *s, const char *label) { IoObject *result; IoState_pushRetainPool(self); { IoMessage *m = IoMessage_newWithName_andCachedArg_(self, SIOSYMBOL("doString"), SIOSYMBOL(s)); if (label) { IoMessage_addCachedArg_(m, SIOSYMBOL(label)); } IoState_zeroSandboxCounts(self); result = IoState_tryToPerform(self, target, target, m); } IoState_popRetainPoolExceptFor_(self, result); return result; }
static int IoSQLite3_resultRow(void *context, int argc, char **argv, char **azColName) { IoSQLite3 *self = context; IoState_pushRetainPool(IOSTATE); { IoMap *map = IoMap_new(IOSTATE); PHash *hash = IoMap_rawHash(map); int i; IoSymbol *key, *value; for(i = 0; i < argc; i ++) { key = IOSYMBOL(azColName[i]); if (argv[i]) { value = IOSYMBOL(argv[i]); } else { value = IOSYMBOL((char *)"NULL"); } PHash_at_put_(hash, key, value); /*printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL"); */ } IoList_rawAppend_(DATA(self)->results, map); } IoState_popRetainPool(IOSTATE); return 0; }
IoObject *IoMemcached_deserialize(IoMemcached *self, char *cvalue, size_t size, uint32_t flags) { IoObject *object; switch(flags) { case _FLAG_NUMBER: object = IONUMBER(atof(cvalue)); break; case _FLAG_NIL: object = IOSTATE->ioNil; break; case _FLAG_BOOLEAN: if(strncmp(cvalue, "1", 1) == 0) object = IOSTATE->ioTrue; else object = IOSTATE->ioFalse; break; case _FLAG_OBJECT: //object = IoState_doCString_(self, cvalue); IoState_pushRetainPool(IOSTATE); IoSeq *serialized = IoSeq_newWithCString_length_(IOSTATE, cvalue, size); object = IoObject_rawDoString_label_(self, serialized, IOSYMBOL("IoMemcached_deserialize")); IoState_popRetainPoolExceptFor_(IOSTATE, object); break; default: object = IoSeq_newWithCString_length_(IOSTATE, cvalue, size); } return object; }
void IoDrawStuffKeyboardFunc(int key) { //printf("IoDrawStuffKeyboardFunc\n"); IoState_pushRetainPool(IoObject_state(proto)); IoMessage_setCachedArg_toInt_(DATA(proto)->keyboardMessage, 0, key); IoDrawStuff_tryCallback(proto, DATA(proto)->keyboardMessage); IoState_popRetainPool(IoObject_state(proto)); }
void IoDrawStuffStepFunc(int pause) { //printf("IoDrawStuffStepFunc\n"); IoState_pushRetainPool(IoObject_state(proto)); IoMessage_setCachedArg_toInt_(DATA(proto)->stepMessage, 0, pause); IoDrawStuff_tryCallback(proto, DATA(proto)->stepMessage); IoState_popRetainPool(IoObject_state(proto)); }
void IoDrawStuffStopFunc(void) { //printf("IoDrawStuffStopFunc\n"); IoState_pushRetainPool(IoObject_state(proto)); IoDrawStuff_tryCallback(proto, DATA(proto)->stopMessage); IoState_popRetainPool(IoObject_state(proto)); }
IO_METHOD(IoNumber, repeat) { /*doc Number repeat(optionalIndex, expression) Evaluates message a number of times that corresponds to the receivers integer value. This is significantly faster than a for() or while() loop. */ IoMessage_assertArgCount_receiver_(m, 1, self); { IoState *state = IOSTATE; IoSymbol *indexSlotName; IoMessage *doMessage; double i, max = CNUMBER(self); IoObject *result = IONIL(self); if(IoMessage_argCount(m) > 1) { indexSlotName = IoMessage_name(IoMessage_rawArgAt_(m, 0)); doMessage = IoMessage_rawArgAt_(m, 1); } else { indexSlotName = 0; doMessage = IoMessage_rawArgAt_(m, 0); } IoState_pushRetainPool(state); for (i = 0; i < max; i ++) { /* if (result != locals && result != self) { IoState_immediatelyFreeIfUnreferenced_(state, result); } */ IoState_clearTopPool(state); if (indexSlotName) { IoObject_setSlot_to_(locals, indexSlotName, IONUMBER(i)); } result = IoMessage_locals_performOn_(doMessage, locals, locals); if (IoState_handleStatus(IOSTATE)) { break; } } IoState_popRetainPoolExceptFor_(IOSTATE, result); return result; } }
IO_METHOD(IoFile, foreachLine) { /*doc File foreachLine(optionalLineNumber, line, message) For each line, set index to the line number of the line and line and execute aMessage. Example usage: <pre> aFile foreachLine(i, v, writeln("Line ", i, ": ", v)) aFile foreach(v, writeln("Line: ", v)) </pre> */ IoObject *result; IoSymbol *indexSlotName, *lineSlotName; IoMessage *doMessage; IoObject *newLine; int i = 0; IoState *state; IoFile_assertOpen(self, locals, m); IoMessage_foreachArgs(m, self, &indexSlotName, &lineSlotName, &doMessage); result = IONIL(self); state = IOSTATE; IoState_pushRetainPool(state); for (;;) { IoState_clearTopPool(state); newLine = IoFile_readLine(self, locals, m); if (ISNIL(newLine)) { break; } if (indexSlotName) { IoObject_setSlot_to_(locals, indexSlotName, IONUMBER(i)); } IoObject_setSlot_to_(locals, lineSlotName, newLine); result = IoMessage_locals_performOn_(doMessage, locals, locals); if (IoState_handleStatus(IOSTATE)) { break; } i ++; } IoState_popRetainPool(state); return result; }
IO_METHOD(IoFile, readLines) { /*doc File readLines Returns list containing all lines in the file. */ IoState *state = IOSTATE; if (!DATA(self)->stream) { IoFile_openForReading(self, locals, m); } IoFile_assertOpen(self, locals, m); { IoList *lines = IoList_new(state); IoObject *newLine; IoState_pushRetainPool(state); for (;;) { IoState_clearTopPool(state); newLine = IoFile_readLine(self, locals, m); if (ISNIL(newLine)) { break; } IoList_rawAppend_(lines, newLine); } IoState_popRetainPool(state); return lines; } }
void IoEvent_handleEvent(int fd, short eventType, void *context) { IoEvent *self = (IoEvent *)context; struct event *ev = IoEvent_rawEvent(self); IoEventManager *em = IoState_protoWithInitFunction_(IOSTATE, IoEventManager_proto); //printf("IoEvent_handleEvent type:%i descriptor:%i\n", eventType, fd); List_remove_(DATA(em)->activeEvents, self); //printf("e: %i\n", List_size(DATA(em)->activeEvents)); if (!ev) { printf("IoEventManager_addEvent: attempt to process an IoEvent with a 0x0 event struct - possible gc error"); exit(1); } event_del(ev); /* if (eventType != && !RawDescriptor_isValid(fd)) { printf("IoEvent_handleEvent: handleEvent type %i on bad file descriptor\n", eventType); } */ IoState_pushRetainPool(IOSTATE); { IoMessage *m = DATA(em)->handleEventMessage; IoMessage_setCachedArg_to_(m, 0, IOBOOL(self, eventType == EV_TIMEOUT)); IoMessage_locals_performOn_(m, self, self); } IoState_popRetainPool(IOSTATE); //printf("IoEvent_handleEvent %p done\n", (void *) context); }
IoObject *IoMessage_locals_performOn_(IoMessage *self, IoObject *locals, IoObject *target) { IoState *state = IOSTATE; IoMessage *m = self; IoObject *result = target; IoObject *cachedTarget = target; //IoObject *semicolonSymbol = state->semicolonSymbol; //IoMessageData *md; IoMessageData *md; if (state->receivedSignal) { IoState_callUserInterruptHandler(IOSTATE); } do { //md = DATA(m); //printf("%s %i\n", CSTRING(IoMessage_name(m)), state->stopStatus); //if(state->showAllMessages) //printf("M:%s:%s:%i\n", CSTRING(IoMessage_name(m)), CSTRING(IoMessage_rawLabel(m)), IoMessage_rawLineNumber(m)); md = DATA(m); if(md->name == state->semicolonSymbol) { target = cachedTarget; } else { result = md->cachedResult; // put it on the stack? /* if(state->debugOn) { char *s = CSTRING(DATA(m)->name); printf("%s\n", s); if (strcmp(s, "clone") == 0) { printf("found '%s'\n", s); } } */ if (!result) { IoState_pushRetainPool(state); #ifdef IOMESSAGE_INLINE_PERFORM if(IoObject_tag(target)->performFunc == NULL) { result = IoObject_perform(target, locals, m); } else { result = IoObject_tag(target)->performFunc(target, locals, m); } #else result = IoObject_tag(target)->performFunc(target, locals, m); #endif IoState_popRetainPoolExceptFor_(state, result); } //IoObject_freeIfUnreferenced(target); target = result; if (state->stopStatus != MESSAGE_STOP_STATUS_NORMAL) { return state->returnValue; /* result = state->returnValue; if (result) { //IoState_stackRetain_(state, result); return result; } printf("IoBlock no result!\n"); return state->ioNil; */ } } } while ((m = md->next)); return result; }
IoObject *IoMessage_locals_performOn_(IoMessage *self, IoObject *locals, IoObject *target) { IoState *state = IOSTATE; IoMessage *m = self; // The message being processed IoObject *result = target; // The value that this function will return IoObject *cachedTarget = target; // The original target IoMessageData *md; // Data for the message being processed int hereStepOut = 0; // Step out from this invocation of IoMessage_locals_performOn_ int hereStepNext = 0; // Step next in this invocation of IoMessage_locals_performOn_ /* if (state->receivedSignal) { IoState_callUserInterruptHandler(IOSTATE); } */ // Catch step next into first line of this block of code, // handle it like a step in on the first message. if (state->stepMode == StepMode_StepNext) { state->stepMode = StepMode_StopOnAnyMessage; } do { md = DATA(m); //printf("%s %i\n", CSTRING(IoMessage_name(m)), state->stopStatus); //if(state->showAllMessages) //printf("M:%s:%s:%i\n", CSTRING(IoMessage_name(m)), CSTRING(IoMessage_rawLabel(m)), IoMessage_rawLineNumber(m)); if (md->breakpoint || state->stepMode == StepMode_StopOnAnyMessage) { StepMode_t mode; if (md->breakpoint) mode = iovm_hit_breakpoint(md->breakpoint, target, locals, m); else mode = iovm_step_stop(target, locals, m); if (mode == StepMode_StepOut) { state->stepMode = StepMode_RunOut; hereStepOut = 1; hereStepNext = 0; } else if (mode == StepMode_StepNext) { state->stepMode = StepMode_RunNext; hereStepNext = 1; hereStepOut = 0; } else { state->stepMode = mode; hereStepNext = 0; hereStepOut = 0; } } // Here we're checking if the current message is an end-of-line or semicolon. if(md->name == state->semicolonSymbol) { // What we are doing here is reseting the environment so that we // process the next line with the same target (such as locals) // as we previously used to process the beginning of the line that is ending. target = cachedTarget; // If we were running over a step next from this level, // convert that to a stop on the very next message. if (hereStepNext && state->stepMode == StepMode_RunNext) { state->stepMode = StepMode_StopOnAnyMessage; } } else { // OK not the end of a line so process a message in the chain. // If there's a cached result in this component, use it. result = md->cachedResult; // put it on the stack? /* if(state->debugOn) { char *s = CSTRING(DATA(m)->name); printf("%s\n", s); if (strcmp(s, "clone") == 0) { printf("found '%s'\n", s); } } */ // Check if there wasn't a cached result if (!result) { // There was not a cached result so perform the message. // Is the stack frame pushed here? IoState_pushRetainPool(state); #ifdef IOMESSAGE_INLINE_PERFORM // Here is where we actually perform the message. // Step-in would have to break in new copy of this function. if(IoObject_tag(target)->performFunc == NULL) { result = IoObject_perform(target, locals, m); } else { result = IoObject_tag(target)->performFunc(target, locals, m); } #else result = IoObject_tag(target)->performFunc(target, locals, m); #endif // Don't collect the result object IoState_popRetainPoolExceptFor_(state, result); } //IoObject_freeIfUnreferenced(target); // Here we are saying use the result from the chain so far as the // target on the next iteration. So for instance if you said // a b c() we're going to use the result of (a b) as target for c(). target = result; // STOP_STATUS_NORMAL means we are going forward as normal, // and not breaking, continuing, returning, etc. // So stopStatus != normal means exit the loop. if (state->stopStatus != MESSAGE_STOP_STATUS_NORMAL) { if (state->stopStatus == MESSAGE_STOP_STATUS_RETURN && hereStepOut && state->stepMode == StepMode_RunOut) state->stepMode = StepMode_StopOnAnyMessage; return state->returnValue; } } } while ((m = md->next)); // Finished with block of lines, exiting the expression // by reaching the ending ")" or last line. if (hereStepOut && state->stepMode == StepMode_RunOut) state->stepMode = StepMode_StopOnAnyMessage; return result; }