IoTokyoCabinetPrefixCursor *IoTokyoCabinetPrefixCursor_rawClone(IoTokyoCabinetPrefixCursor *proto) { IoObject *self = IoObject_rawClonePrimitive(proto); IoObject_tag_(self, IoObject_tag(proto)); IoObject_setDataPointer_(self, tcbdbnew()); return self; }
IoList *IoList_rawClone(IoList *proto) { IoObject *self = IoObject_rawClonePrimitive(proto); IoObject_tag_(self, IoObject_tag(proto)); IoObject_setDataPointer_(self, List_clone(DATA(proto))); return self; }
IoSkipDBM *IoSkipDBM_rawClone(IoSkipDBM *proto) { IoObject *self = IoObject_rawClonePrimitive(proto); IoObject_tag_(self, IoObject_tag(proto)); IoObject_setDataPointer_(self, SkipDBM_new()); return self; }
IoSkipDB *IoSkipDB_rawClone(IoSkipDB *proto) { IoObject *self = IoObject_rawClonePrimitive(proto); IoObject_tag_(self, IoObject_tag(proto)); IoObject_setDataPointer_(self, NULL); return self; }
IoObject *IoObject_rawClonePrimitive(IoObject *proto) { IoObject *self = IoObject_alloc(proto); IoObject_tag_(self, IoObject_tag(proto)); IoObject_setProtoTo_(self, proto); IoObject_setDataPointer_(self, NULL); IoObject_isDirty_(self, 1); return self; }
IoObject *IoObject_addMethod_(IoObject *self, IoSymbol *slotName, IoMethodFunc *fp) { IoTag *t = IoObject_tag(self); IoCFunction *f; f = IoCFunction_newWithFunctionPointer_tag_name_(IOSTATE, (IoUserFunction *)fp, t, CSTRING(slotName)); IoObject_setSlot_to_(self, slotName, f); return f; }
IoObject *IoCFunction_activate(IoCFunction *self, IoObject *target, IoObject *locals, IoMessage *m, IoObject *slotContext) { IoCFunctionData *selfData = DATA(self); IoTag *t = selfData->typeTag; //IoObject_waitOnFutureIfNeeded(target); future forward will already deal with this? IoObject *result; if (t && t != IoObject_tag(target)) // eliminate t check by matching Object tag? { char *a = (char *)IoTag_name(t); char *b = (char *)IoTag_name(IoObject_tag(target)); IoState_error_(IOSTATE, m, "CFunction defined for type %s but called on type %s", a, b); } //IoState_pushRetainPool(state); result = (*(IoUserFunction *)(selfData->func))(target, locals, m); //IoState_popRetainPoolExceptFor_(state, result); return result; }
//inline void IoObject_freeData(IoObject *self) { IoTagFreeFunc *func = IoTag_freeFunc(IoObject_tag(self)); if (func) { (*func)(self); } else if (IoObject_dataPointer(self)) { io_free(IoObject_dataPointer(self)); } IoObject_setDataPointer_(self, NULL); }
IoObject *IoLinker_makeCFunction(IoLinker *self, IoObject *locals, IoMessage *m) { /*doc Linker makeCFunction(aSeq, slotName, object) Creates a CFunction which users the beginning address of the data in aSeq as its function pointer and adds the CFunction to the given object on slot slotName. */ IoSeq *buffer = IoMessage_locals_seqArgAt_(m, locals, 0); IoSeq *slotName = IoMessage_locals_seqArgAt_(m, locals, 1); IoObject *object = IoMessage_locals_valueArgAt_(m, locals, 2); IoCFunction *f; IoUserFunction* fp = (IoUserFunction*)IoSeq_rawBytes(buffer); f = IoCFunction_newWithFunctionPointer_tag_name_(IOSTATE, fp, IoObject_tag(object), CSTRING(slotName)); IoObject_setSlot_to_(f, IOSYMBOL("compiledCode"), buffer); return f; }
IoObject *IoObject_rawClone(IoObject *proto) { IoObject *self = IoObject_alloc(proto); IoObject_tag_(self, IoObject_tag(proto)); /* { IoObject **protos = IoObject_protos(self); protos[0] = proto; } */ IoObject_setProtoTo_(self, proto); //IoObject_protos(self)[0] = proto; //IoObject_setDataPointer_(self, IoObject_dataPointer(proto)); // is this right? IoObject_isDirty_(self, 1); return self; }
//inline void IoObject_freeData(IoObject *self) { IoTagFreeFunc *func = IoTag_freeFunc(IoObject_tag(self)); if (func) { //if(func == free) { //printf("Tag func is free\n"); //if (IoObject_name(self)) printf("free %s\n", IoObject_name(self)); } (*func)(self); } else if (IoObject_dataPointer(self)) { io_free(IoObject_dataPointer(self)); } IoObject_setDataPointer_(self, NULL); }
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; }
printf("white:\n"); IoObjectGroup_show(self->whiteGroup); printf("\n"); */ printf("stacks:\n"); printf("\n"); } IoObject *IoState_replacePerformFunc_with_(IoState *self, IoTagPerformFunc *oldFunc, IoTagPerformFunc *newFunc) { PHASH_FOREACH(self->primitives, k, v, { IoObject *proto = v; IoTag *tag = IoObject_tag(proto); if (tag->performFunc == oldFunc || !tag->performFunc) { tag->performFunc = newFunc; } } ); return NULL; } void IoState_debuggingOn(IoState *self) { IoState_replacePerformFunc_with_(self, (IoTagPerformFunc *)IoObject_perform, (IoTagPerformFunc *)IoObject_performWithDebugger);
IoObject *IoObject_justClone(IoObject *self) { return (IoObject_tag(self)->cloneFunc)(self); }
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; }
IoObject *IoCInvokeStructureInstance_objectFromData_(IoObject *structure, void *data) { IoObject *self = IoCInvokeStructureInstance_new(((IoState *)(IoObject_tag(structure)->state))); // because IOSTATE depends on `self` DATA(self)->instance = data; IoObject_setSlot_to_(self, IOSYMBOL("structure"), structure); return self; }