IoObject *IoCFFIPointer_castTo(IoCFFIPointer *self, IoObject *locals, IoMessage *m) { IoObject *toType = IoMessage_locals_valueArgAt_(m, locals, 0); IoObject *o = IoState_on_doCString_withLabel_(IOSTATE, toType, "?typeString", "IoCFFIPointer_castTo"); if(!ISNIL(o)) { char *typeStr = CSTRING(o); switch(typeStr[0]) { case '^': toType = IOCLONE(toType); *(DATA(toType)->valuePointer) = *((void **)IoCFFIDataType_ValuePointerFromObject_(toType, self)); return toType; case '*': toType = IOCLONE(toType); IoCFFIDataType_rawSetValue(toType, self); return toType; default: IoState_error_(IOSTATE, m, "Wrong type to cast to."); break; } } else { // Mm... well, if the type to cast to does not have a typeString slot, // it should be an Io Object, so the address stored here is a pointer to an // Io Object. Simply cast the pointer and return it... dangerous but... IoObject *obj = (IoObject *)*(DATA(self)->valuePointer); if(ISOBJECT(obj)) return (IoObject *)*(DATA(self)->valuePointer); } return IONIL(self); }
IoCFFIArray *IoCFFIArray_with(IoCFFIArray *self, IoObject *locals, IoMessage *m) { IoCFFIDataType *type; int size, i; ffi_type *item_type; IoCFFIArray *o = IOCLONE(self); IoState_on_doCString_withLabel_(IoObject_state(o), o, "init", "IoCFFIArray_with"); type = IOCLONE(IoMessage_locals_valueArgAt_(m, locals, 0)); IoObject_setSlot_to_(o, IOSYMBOL("arrayType"), type); size = IoMessage_locals_intArgAt_(m, locals, 1); DATA(o)->arraySize = size; item_type = IoCFFIDataType_ffiType(type); DATA(o)->itemSize = item_type->size; // Fake libffi to think we are a Struct DATA(o)->ffiType.size = 0; DATA(o)->ffiType.alignment = 0; DATA(o)->ffiType.type = FFI_TYPE_STRUCT; DATA(o)->ffiType.elements = io_calloc(size + 1, sizeof(ffi_type *)); DATA(o)->needToFreeFFIType = 1; for ( i = 0 ; i < size ; i++ ) { DATA(o)->ffiType.elements[i] = item_type; } DATA(o)->ffiType.elements[size] = NULL; ffi_cif cif; ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 0, &(DATA(o)->ffiType), NULL); return o; }
IoBox *IoBox_rawClone(IoBox *proto) { IoBox *self = IoObject_rawClonePrimitive(proto); IoObject_setDataPointer_(self, calloc(1, sizeof(IoBoxData))); DATA(self)->origin = IOCLONE(DATA(proto)->origin); DATA(self)->size = IOCLONE(DATA(proto)->size); return self; }
IoAudioDevice *IoAudioDevice_rawClone(IoAudioDevice *proto) { IoObject *self = IoObject_rawClonePrimitive(proto); IoObject_setDataPointer_(self, calloc(1, sizeof(IoAudioDeviceData))); DATA(self)->writeBuffer = IOCLONE(DATA(proto)->writeBuffer); DATA(self)->readBuffer = IOCLONE(DATA(proto)->readBuffer); DATA(self)->audioDevice = AudioDevice_new(); return self; }
IoGLScissor *IoGLScissor_rawClone(IoGLScissor *proto) { IoObject *self = IoObject_rawClonePrimitive(proto); IoObject_setDataPointer_(self, cpalloc(IoObject_dataPointer(proto), sizeof(IoGLScissorData))); DATA(self)->rect = IOCLONE(DATA(proto)->rect); DATA(self)->tmpRect = IOCLONE(DATA(proto)->tmpRect); return self; }
IoAVCodec *IoAVCodec_rawClone(IoAVCodec *proto) { IoObject *self = IoObject_rawClonePrimitive(proto); IoObject_setDataPointer_(self, calloc(1, sizeof(IoAVCodecData))); DATA(self)->inputBuffer = IOCLONE(DATA(proto)->inputBuffer); DATA(self)->outputBuffer = IOCLONE(DATA(proto)->outputBuffer); return self; }
IoMP3Decoder *IoMP3Decoder_rawClone(IoMP3Decoder *proto) { IoObject *self = IoObject_rawClonePrimitive(proto); IoObject_setDataPointer_(self, calloc(1, sizeof(IoMP3DecoderData))); DATA(self)->willProcessMessage = DATA(proto)->willProcessMessage; DATA(self)->didProcessMessage = DATA(proto)->didProcessMessage; DATA(self)->inputBuffer = IOCLONE(DATA(proto)->inputBuffer); DATA(self)->outputBuffer = IOCLONE(DATA(proto)->outputBuffer); DATA(self)->tmpInputBa = UArray_new(); IoState_addValue_(IOSTATE, self); return self; }
IoCairoSurface *IoCairoSurface_newWithRawSurface_(void *state, IoMessage *m, cairo_surface_t *surface) { IoObject *self = 0; IoStateProtoFunc *initFunc = 0; checkStatus_(state, m, cairo_surface_status(surface)); switch(cairo_surface_get_type(surface)) { case CAIRO_SURFACE_TYPE_IMAGE: initFunc = IoCairoImageSurface_proto; break; case CAIRO_SURFACE_TYPE_PS: initFunc = IoCairoPSSurface_proto; break; case CAIRO_SURFACE_TYPE_PDF: initFunc = IoCairoPDFSurface_proto; break; case CAIRO_SURFACE_TYPE_SVG: initFunc = IoCairoSVGSurface_proto; break; default: IoState_error_(state, 0, "Unsupported surface type"); } self = IOCLONE(IoState_protoWithId_(state, protoId)); IoObject_setDataPointer_(self, surface); return self; }
IoODEBody *IoODEBody_newBodyProtoWithWorld(void *state, IoODEWorld *world) { IoODEBody *proto = IoState_protoWithInitFunction_(state, IoODEBody_proto); IoODEBody *self = IOCLONE(proto); WORLD = world; return self; }
IoCFFIArray *IoCFFIArray_atPut(IoCFFIArray *self, IoObject *locals, IoMessage *m) { int pos; IoObject *value, *arrayType, *d; char *ptr; pos = CNUMBER(IoMessage_locals_numberArgAt_(m, locals, 0)); value = IoMessage_locals_valueArgAt_(m, locals, 1); if ( pos >= DATA(self)->arraySize ) { IoState_error_(IOSTATE, m, "index out of bounds"); return IONIL(self); } arrayType = IoObject_getSlot_(self, IOSYMBOL("arrayType")); ptr = ((char *)DATA(self)->buffer) + (DATA(self)->itemSize * pos); d = IOCLONE(arrayType); IoCFFIDataType_rawSetValue(d, value); memcpy(ptr, (void *)IoCFFIDataType_ValuePointerFromObject_(self, d), DATA(self)->itemSize); if ( DATA(self)->keepValuesRefs ) { DATA(self)->keepValuesRefs[pos] = IOREF(d); } return self; }
// _new creates a new object from this prototype IoObject *IoSVN_new(void *state) { printf("IoSVN_new\n"); IoObject *proto = IoState_protoWithInitFunction_(state, IoSVN_proto); return IOCLONE(proto); }
IoCoroutine *IoCoroutine_new(void *state) { IoObject *proto = IoState_protoWithInitFunction_((IoState *)state, IoCoroutine_proto); IoObject *self = IOCLONE(proto); //printf("IoCoroutine_new %p\n", (void *)self); return self; }
IoNumber *IoNumber_newWithDouble_(void *state, double n) { IoNumber *proto = IoState_protoWithInitFunction_((IoState *)state, IoNumber_proto); IoNumber *self = IOCLONE(proto); // since Numbers have no refs, we can avoid IOCLONE DATA(self) = n; return self; }
IoCairoFontOptions *IoCairoFontOptions_newWithRawFontOptions_(void *state, IoMessage *m, cairo_font_options_t *options) { IoCairoFontOptions *self = IOCLONE(IoState_protoWithId_(state, proto)); IoObject_setDataPointer_(self, options); CHECK_STATUS(self); return self; }
IoODEJoint *IoODEJoint_newProtoCommon(void *state, IoStateProtoFunc *func, IoODEJointGroup *jointGroup) { IoODEJoint *proto = IoState_protoWithInitFunction_(state, func); IoODEJoint *self = IOCLONE(proto); JOINTGROUP = jointGroup; return self; }
void IoState_setupSingletons(IoState *self) { IoObject *core = self->core; // nil self->ioNil = IOCLONE(self->objectProto); IoObject_setSlot_to_(core, SIOSYMBOL("nil"), self->ioNil); //IoObject_setSlot_to_(core, self->noShufflingSymbol, self->ioNil); IoObject_setSlot_to_(core, SIOSYMBOL("Message"), IoMessage_proto(self)); IoObject_setSlot_to_(core, SIOSYMBOL("Call"), IoCall_proto(self)); self->nilMessage = IoMessage_newWithName_(self, SIOSYMBOL("nil")); IoMessage_cachedResult_(self->nilMessage, self->ioNil); IoState_retain_(self, self->nilMessage); // true self->ioTrue = IoObject_new(self); IoObject_setSlot_to_(core, SIOSYMBOL("true"), self->ioTrue); IoObject_setSlot_to_(self->ioTrue, SIOSYMBOL("type"), SIOSYMBOL("true")); IoState_retain_(self, self->ioTrue); // false self->ioFalse = IoObject_new(self); IoObject_setSlot_to_(core, SIOSYMBOL("false"), self->ioFalse); IoObject_setSlot_to_(self->ioFalse, SIOSYMBOL("type"), SIOSYMBOL("false")); IoState_retain_(self, self->ioFalse); // Flow control: Normal self->ioNormal = IoObject_new(self); IoObject_setSlot_to_(core, SIOSYMBOL("Normal"), self->ioNormal); IoObject_setSlot_to_(self->ioNormal, SIOSYMBOL("type"), SIOSYMBOL("Normal")); IoState_retain_(self, self->ioNormal); // Flow control: Break self->ioBreak = IoObject_new(self); IoObject_setSlot_to_(core, SIOSYMBOL("Break"), self->ioBreak); IoObject_setSlot_to_(self->ioBreak, SIOSYMBOL("type"), SIOSYMBOL("Break")); IoState_retain_(self, self->ioBreak); // Flow control: Continue self->ioContinue = IoObject_new(self); IoObject_setSlot_to_(core, SIOSYMBOL("Continue"), self->ioContinue); IoObject_setSlot_to_(self->ioContinue, SIOSYMBOL("type"), SIOSYMBOL("Continue")); IoState_retain_(self, self->ioContinue); // Flow control: Return self->ioReturn = IoObject_new(self); IoObject_setSlot_to_(core, SIOSYMBOL("Return"), self->ioReturn); IoObject_setSlot_to_(self->ioReturn, SIOSYMBOL("type"), SIOSYMBOL("Return")); IoState_retain_(self, self->ioReturn); // Flow control: Eol self->ioEol = IoObject_new(self); IoObject_setSlot_to_(core, SIOSYMBOL("Eol"), self->ioEol); IoObject_setSlot_to_(self->ioEol, SIOSYMBOL("type"), SIOSYMBOL("Eol")); IoState_retain_(self, self->ioEol); }
IoODEPlane *IoODEPlane_new(void *state, dGeomID geomId) { IoODEPlane *proto = IoState_protoWithInitFunction_(state, IoODEPlane_proto); IoODEPlane *self = IOCLONE(proto); GEOMID = geomId; dGeomSetData(GEOMID, self); return self; }
IoCairoContext *IoCairoContext_newWithSurface_(void *state, IoCairoImageSurface *surface) { IoCairoContext *self = IOCLONE(IoState_protoWithInitFunction_(state, IoCairoContext_proto)); cairo_t *rawContext = cairo_create(IoCairoSurface_rawSurface(surface)); checkStatus_(state, 0, cairo_status(rawContext)); IoObject_setDataPointer_(self, rawContext); return self; }
IoImage *IoImage_rawClone(IoImage *proto) { IoObject *self = IoObject_rawClonePrimitive(proto); IoObject_setDataPointer_(self, cpalloc(IoObject_dataPointer(proto), sizeof(IoImageData))); DATA(self)->buffer = IOCLONE(DATA(proto)->buffer); DATA(self)->image = Image_copyWithUArray_(DATA(proto)->image, IoSeq_rawUArray(DATA(self)->buffer)); return self; }
IoRegexMatch *IoRegexMatch_newWithRegex_subject_captureRanges_(void *state, IoRegex *regex, IoSymbol *subject, IoList *captureRanges) { IoRegexMatch *self = IOCLONE(IoState_protoWithId_(state, protoId)); DATA(self)->regex = IOREF(regex); DATA(self)->subject = IOREF(subject); DATA(self)->ranges = captureRanges; return self; }
IoODEBox *IoODEBox_new(void *state, dGeomID geomId) { IoODEBox *proto = IoState_protoWithId_(state, protoId); IoODEBox *self = IOCLONE(proto); GEOMID = geomId; dGeomSetData(GEOMID, self); return self; }
IoCertificate *IoCertificate_newWithX509_shouldFree(void *state, X509 *x509, int shouldFree) { IoObject *proto = IoState_protoWithInitFunction_((IoState *)state, IoCertificate_proto); IoCertificate *self = IOCLONE(proto); Certificate *certData = calloc(1, sizeof(Certificate)); certData->shouldFree = shouldFree; certData->x509 = x509; IoObject_setDataPointer_(self, certData); return self; }
IO_METHOD(IoDate, add) { /*doc Date +(aDuration) Return a new Date with the receiver's value plus an amount of time specified by aDuration object to the receiver. */ IoDate *newDate = IOCLONE(self); return IoDate_addInPlace(newDate, locals, m); }
IoCairoPathElement *IoCairoPathElement_newWithPath_dataOffset_(void *state, IoObject *path, int offset) { IoCairoPathElement *self = IOCLONE(IoState_protoWithInitFunction_(state, IoCairoPathElement_proto)); cairo_path_t *rawPath = ((IoCairoPathData *)IoObject_dataPointer(path))->path; IoObject_setDataPointer_(self, malloc(sizeof(IoCairoPathElementData))); DATA(self)->path = path; PATH_DATA(self) = rawPath->data + offset; return self; }
static IoRegex *IoRegex_cloneWithOptions_(IoRegex *self, int options) { IoRegex *clone = 0; if (options == DATA(self)->options) return self; clone = IOCLONE(self); DATA(clone)->options = options; return clone; }
IoCFunction *IoCFunction_newWithFunctionPointer_tag_name_(void *state, IoUserFunction *func, IoTag *typeTag, const char *funcName) { IoCFunction *proto = IoState_protoWithInitFunction_((IoState *)state, IoCFunction_proto); IoCFunction *self = IOCLONE(proto); DATA(self)->typeTag = typeTag; DATA(self)->func = func; DATA(self)->uniqueName = IoState_symbolWithCString_((IoState *)state, funcName); return self; }
void IoCoroutine_raiseError(IoCoroutine *self, IoSymbol *description, IoMessage *m) { IoObject *e = IoObject_rawGetSlot_(self, IOSYMBOL("Exception")); if (e) { e = IOCLONE(e); IoObject_setSlot_to_(e, IOSYMBOL("error"), description); if (m) IoObject_setSlot_to_(e, IOSYMBOL("caughtMessage"), m); IoObject_setSlot_to_(e, IOSYMBOL("coroutine"), self); IoCoroutine_rawSetException_(self, e); } IoCoroutine_rawReturnToParent(self); }
IoCFFIArray *IoCFFIArray_atPut(IoCFFIArray *self, IoObject *locals, IoMessage *m) { int pos; IoObject *value, *d; char *ptr; //TODO check limits and types pos = CNUMBER(IoMessage_locals_numberArgAt_(m, locals, 0)); value = IoMessage_locals_valueArgAt_(m, locals, 1); ptr = ((char *)DATA(self)->buffer) + (DATA(self)->itemSize * pos); d = IOCLONE(IoObject_getSlot_(self, IOSYMBOL("arrayType"))); IoCFFIDataType_rawSetValue(d, value); memcpy(ptr, (void *)IoCFFIDataType_ValuePointerFromObject_(NULL, d), DATA(self)->itemSize); return self; }
IoObject *IoCFFIPointer_atPut(IoCFFIPointer *self, IoObject *locals, IoMessage *m) { int pos; IoObject *value, *pointedToType, *d; char *ptr; //TODO comprobar overrun y coincidencia de tipos pos = CNUMBER(IoMessage_locals_numberArgAt_(m, locals, 0)); value = IoMessage_locals_valueArgAt_(m, locals, 1); pointedToType = IoObject_getSlot_(self, IOSYMBOL("pointedToType")); ptr = ((char *)*(DATA(self)->valuePointer)) + (IoCFFIDataType_ffiType(pointedToType)->size * pos); d = IOCLONE(pointedToType); IoCFFIDataType_rawSetValue(d, value); memcpy(ptr, (void *)IoCFFIDataType_ValuePointerFromObject_(NULL, d), IoCFFIDataType_ffiType(pointedToType)->size); return self; }
IO_METHOD(IoDate, subtract) { /*doc Date -(aDurationOrDate) Return a new Date with the receiver's value minus an amount of time specified by aDuration to the receiver. Returns self. */ IoObject *v = IoMessage_locals_valueArgAt_(m, locals, 0); if (ISDATE(v)) { double d = Date_secondsSince_(DATA(self), DATA(v)); return IoDuration_newWithSeconds_(IOSTATE, d); } else if (ISDURATION(v)) { IoDate *newDate = IOCLONE(self); Date_subtractDuration_(DATA(newDate), IoDuration_duration(v)); return newDate; } IOASSERT(1, "Date or Duration argument required"); return IONIL(self); }