Exemple #1
0
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);
		}
	}
}
Exemple #2
0
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;
}
Exemple #3
0
void IoMessage_opShuffle_(IoMessage *self)
{
	if (IoObject_rawGetSlot_(self, IOSTATE->opShuffleSymbol) && IoMessage_name(self) != IOSTATE->noShufflingSymbol)
	{
		IoMessage_locals_performOn_(IOSTATE->opShuffleMessage, IOSTATE->lobby, self);
	}
}
Exemple #4
0
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;
	}
}
Exemple #5
0
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);
}
Exemple #6
0
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;
	}
}
Exemple #7
0
IoObject *IoCoroutine_rawRunLocals(IoCoroutine *self)
{
	return IoObject_rawGetSlot_(self, IOSYMBOL("runLocals"));
}
Exemple #8
0
IoObject *IoCoroutine_rawRunMessage(IoCoroutine *self)
{
	return IoObject_rawGetSlot_(self, IOSYMBOL("runMessage"));
}
Exemple #9
0
IoObject *IoCoroutine_rawRunTarget(IoCoroutine *self)
{
	return IoObject_rawGetSlot_(self, IOSYMBOL("runTarget"));
}
Exemple #10
0
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;
}