void IoCoroutine_rawPrintBackTrace(IoCoroutine *self) { IoObject *e = IoCoroutine_rawException(self); IoMessage *caughtMessage = IoObject_rawGetSlot_(e, IOSYMBOL("caughtMessage")); if (IoObject_rawGetSlot_(e, IOSYMBOL("showStack"))) // sanity check { IoState_on_doCString_withLabel_(IOSTATE, e, "showStack", "[Coroutine]"); } else { IoSymbol *error = IoObject_rawGetSlot_(e, IOSYMBOL("error")); if (error) { fputs(CSTRING(error), stderr); fputs("\n", stderr); } else { fputs("error: [missing error slot in Exception object]\n", stderr); } if (caughtMessage) { UArray *ba = IoMessage_asMinimalStackEntryDescription(caughtMessage); fputs(UArray_asCString(ba), stderr); fputs("\n", stderr); UArray_free(ba); } } }
Levels *Levels_new(IoMessage *msg) { Levels *self = io_calloc(1, sizeof(Levels)); IoState *state = IoObject_state(msg); IoSymbol *operatorTableSymbol = IoState_symbolWithCString_(state, "OperatorTable"); // Be ultra flexable, and try to use the first message's operator table. IoObject *opTable = IoObject_rawGetSlot_(msg, operatorTableSymbol); // Otherwise, use Core OperatorTable, and if that doesn't exist, create it. if (opTable == NULL) { // There is a chance the message didn't have it, but the core did---due // to the Core not being part of the message's protos. Use Core // Message's OperatorTable opTable = IoObject_rawGetSlot_(state->core, operatorTableSymbol); // If Core doesn't have an OperatorTable, then create it. if (opTable == NULL) { opTable = IoObject_new(state); IoObject_setSlot_to_(state->core, operatorTableSymbol, opTable); IoObject_setSlot_to_(opTable, IoState_symbolWithCString_(state, "precedenceLevelCount"), IoState_numberWithDouble_(state, IO_OP_MAX_LEVEL)); } } self->operatorTable = getOpTable(opTable, "operators", IoState_createOperatorTable); self->assignOperatorTable = getOpTable(opTable, "assignOperators", IoState_createAssignOperatorTable); self->stack = List_new(); Levels_reset(self); return self; }
void IoMessage_opShuffle_(IoMessage *self) { if (IoObject_rawGetSlot_(self, IOSTATE->opShuffleSymbol) && IoMessage_name(self) != IOSTATE->noShufflingSymbol) { IoMessage_locals_performOn_(IOSTATE->opShuffleMessage, IOSTATE->lobby, self); } }
IoSocket *IoSocket_rawSetupEvent_(IoSocket *self, IoObject *locals, IoMessage *m, char *eventSlotName) { IoObject *event = IoObject_rawGetSlot_(self, IOSYMBOL(eventSlotName)); if(!event || ISNIL(event)) { IoState_error_(IOSTATE, m, "Expected %s slot to be set!", eventSlotName); return IONIL(self); } else { IoObject_setSlot_to_(event, IOSYMBOL("descriptorId"), IoSocket_descriptorId(self, locals, m)); 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); }
IoMap *getOpTable(IoObject *self, const char *slotName, IoMap *create(IoState *state)) { IoSymbol *symbol = IoState_symbolWithCString_(IOSTATE, slotName); IoObject *operators = IoObject_rawGetSlot_(self, symbol); if (operators && ISMAP(operators)) { return operators; } else { // Not strictly correct as if the message has it's own empty // OperatorTable slot, we'll create one for it instead of using // Core Message OperatorTable operators. Oh well. IoMap *result = create(IOSTATE); IoObject_setSlot_to_(self, symbol, result); return result; } }
IoObject *IoCoroutine_rawRunLocals(IoCoroutine *self) { return IoObject_rawGetSlot_(self, IOSYMBOL("runLocals")); }
IoObject *IoCoroutine_rawRunMessage(IoCoroutine *self) { return IoObject_rawGetSlot_(self, IOSYMBOL("runMessage")); }
IoObject *IoCoroutine_rawRunTarget(IoCoroutine *self) { return IoObject_rawGetSlot_(self, IOSYMBOL("runTarget")); }
IoAudioMixer *IoAudioMixer_proto(void *state) { IoObject *self = IoObject_new(state); IoObject_tag_(self, IoAudioMixer_newTag(state)); self->data = calloc(1, sizeof(IoAudioMixerData)); DATA(self)->sounds = List_new(); DATA(self)->soundsToRemove = List_new(); DATA(self)->events = List_new(); DATA(self)->activeEvents = List_new(); DATA(self)->samplesPerBuffer = FRAMES_PER_BUFFER; DATA(self)->volume = 1.0; DATA(self)->ioBuffer = IoSeq_new(IOSTATE); DATA(self)->buffer = IoSeq_rawUArray(DATA(self)->ioBuffer); DATA(self)->mixBuffer = UArray_new(); DATA(self)->writeMessage = IoMessage_newWithName_label_(IOSTATE, IOSYMBOL("write"), IOSYMBOL("AudioMixer")); IoMessage_setCachedArg_to_(DATA(self)->writeMessage, 0, DATA(self)->ioBuffer); DATA(self)->nonBlockingWriteMessage = IoMessage_newWithName_label_(IOSTATE, IOSYMBOL("nonBlockingWrite"), IOSYMBOL("AudioMixer")); IoMessage_setCachedArg_to_(DATA(self)->nonBlockingWriteMessage, 0, DATA(self)->ioBuffer); DATA(self)->soundTouch = SoundTouch_init(); SoundTouch_setSampleRate(DATA(self)->soundTouch, 44100); SoundTouch_setChannels(DATA(self)->soundTouch, 2); DATA(self)->tempo = 1.0; IoState_registerProtoWithId_(state, self, protoId); { IoMethodTable methodTable[] = { {"start", IoAudioMixer_start}, {"stop", IoAudioMixer_stop}, {"sounds", IoAudioMixer_sounds}, {"addSound", IoAudioMixer_addSound_}, {"addSoundOnSampleOfSound", IoAudioMixer_addSound_onSample_ofSound_}, {"removeSound", IoAudioMixer_removeSound_}, {"removeAllSounds", IoAudioMixer_removeAllSounds}, {"removeSoundOnSampleOfSound", IoAudioMixer_removeSound_onSample_ofSound_}, {"setSamplesPerBuffer", IoAudioMixer_setSamplesPerBuffer}, {"setVolume", IoAudioMixer_setVolume}, {"setTempo", IoAudioMixer_setTempo}, {"setSampleRate", IoAudioMixer_setSampleRate}, {"setPitchSemiTones", IoAudioMixer_setPitchSemiTones}, {"setAudioDevice", IoAudioMixer_setAudioDevice}, {NULL, NULL}, }; IoObject_addMethodTable_(self, methodTable); } DATA(self)->ioAudioDevice = IoObject_rawGetSlot_(self, IOSYMBOL("AudioDevice")); { IoMessage *m = 0x0; IOASSERT(DATA(self)->ioAudioDevice, "unable to find AudioDevice"); } return self; }