Exemplo n.º 1
0
IO_METHOD(IoSeq, inclusiveSlice)
{
	/*doc Sequence inclusiveSlice(inclusiveStartIndex, inclusiveEndIndex)
	Returns a new string containing the subset of the
	receiver from the inclusiveStartIndex to the inclusiveEndIndex. The inclusiveEndIndex argument
	is optional. If not given, it is assumed to be the end of the string. 
	*/

	long fromIndex = IoMessage_locals_longArgAt_(m, locals, 0);
	long last = UArray_size(DATA(self));
	UArray *ba;

	if (IoMessage_argCount(m) > 1)
	{
		last = IoMessage_locals_longArgAt_(m, locals, 1);
	}

	if (last == -1)
	{
		last = UArray_size(DATA(self));
	}
	else
	{
		last = last + 1;
	}
	
	ba = UArray_slice(DATA(self), fromIndex, last);

	if (ISSYMBOL(self))
	{
		return IoState_symbolWithUArray_copy_(IOSTATE, ba, 0);
	}

	return IoSeq_newWithUArray_copy_(IOSTATE, ba, 0);
}
Exemplo n.º 2
0
IO_METHOD(IoSeq, replaceFirstSeq)
{
	/*doc Sequence replaceFirstSeq(aSequence, anotherSequence, optionalStartIndex)
	Returns a new Sequence with the first occurance of aSequence
	replaced with anotherSequence in the receiver. If optionalStartIndex is
	provided, the search for aSequence begins at that index. Returns self.
	*/

	IoSeq *subSeq   = IoMessage_locals_seqArgAt_(m, locals, 0);
	IoSeq *otherSeq = IoMessage_locals_seqArgAt_(m, locals, 1);
	size_t startIndex = 0;

	if (IoMessage_argCount(m) > 2)
	{
		startIndex = IoMessage_locals_longArgAt_(m, locals, 2);
	}

	IO_ASSERT_NOT_SYMBOL(self);

	{
		UArray *a = DATA(self);
		UArray *b = DATA(subSeq);
		UArray *c = DATA(otherSeq);
		long i = UArray_find_from_(a, b, startIndex);
		if(i != -1)
		{
			UArray_removeRange(a, i, UArray_size(b));
			UArray_at_putAll_(a, i, c);
		}
	}
	return self;
}
Exemplo n.º 3
0
IO_METHOD(IoSeq, removeSlice)
{
	/*doc Sequence removeSlice(startIndex, endIndex)
	Removes the items from startIndex to endIndex.
	Returns self.
	*/

	long start = IoMessage_locals_longArgAt_(m, locals, 0);
	long end   = IoMessage_locals_longArgAt_(m, locals, 1);

	IO_ASSERT_NOT_SYMBOL(self);

	start = UArray_wrapPos_(DATA(self), start);
	end   = UArray_wrapPos_(DATA(self), end);

	UArray_removeRange(DATA(self), start, end - start + 1);
	return self;
}
Exemplo n.º 4
0
Arquivo: IoRandom.c Projeto: Akiyah/io
IoObject *IoRandom_setSeed(IoObject *self, IoObject *locals, IoMessage *m)
{
	/*doc Random setSeed(aNumber)
	Sets the random number generator seed to the unsign int version of aNumber.
	*/

	unsigned long v = IoMessage_locals_longArgAt_(m, locals, 0);
	RandomGen_setSeed(DATA(self), v);
	return self;
}
Exemplo n.º 5
0
Arquivo: IoNumber.c Projeto: Akiyah/io
IO_METHOD(IoNumber, bitShiftRight)
{
	/*doc Number >>(aNumber)
	Shifts the bits of the receiver right by the number of places specified by aNumber.
	*/

	long other = IoMessage_locals_longArgAt_(m, locals, 0);
	long r =  (double)((long)DATA(self) >> (long)other);
	return IONUMBER(r);
}
Exemplo n.º 6
0
IoObject *IoAudioMixer_removeSound_onSample_ofSound_(IoAudioMixer *self, IoObject *locals, IoMessage *m)
{
	IoSound *ioSound        = IoMessage_locals_soundArgAt_(m, locals, 0);
	long sample             = IoMessage_locals_longArgAt_(m, locals, 1);
	IoSound *ioTriggerSound = IoMessage_locals_soundArgAt_(m, locals, 2);
	AudioEvent *event       = 
		AudioEvent_newWithSound_onSample_of_type_(ioSound, sample, ioTriggerSound, AUDIOEVENT_REMOVE);
	IoAudioMixer_addEvent_(self, event);
	return self;
}
Exemplo n.º 7
0
Arquivo: IoFile.c Projeto: achoy/io
IO_METHOD(IoFile, truncateToSize)
{
	/*doc File truncateToSize(numberOfBytes)
	Truncates the file's size to the numberOfBytes. Returns self.
	*/

	long newSize = IoMessage_locals_longArgAt_(m, locals, 0);
	truncate(UTF8CSTRING(DATA(self)->path), newSize);
	return self;
}
Exemplo n.º 8
0
Arquivo: IoNumber.c Projeto: Akiyah/io
IO_METHOD(IoNumber, bitwiseAnd)
{
	/*doc Number &(aNumber)
	Returns a new number with the bitwise AND of the receiver and aNumber.
	*/

	/*doc Number bitwiseAnd(aNumber)
	Returns a new number with the bitwise AND of the receiver and aNumber.
	*/

	long other = IoMessage_locals_longArgAt_(m, locals, 0);
	return IONUMBER(((long)DATA(self) & other));
}
Exemplo n.º 9
0
Arquivo: IoFile.c Projeto: achoy/io
IO_METHOD(IoFile, readToBufferLength)
{
	/*doc File readToBufferLength(aBuffer, aNumber)
	Reads at most aNumber number of items and appends them to aBuffer.
	Returns number of items read.
	*/

	IoSeq *buffer = IoMessage_locals_mutableSeqArgAt_(m, locals, 0);
	size_t length = IoMessage_locals_longArgAt_(m, locals, 1);
	UArray *ba = IoSeq_rawUArray(buffer);
	size_t itemsRead = UArray_readNumberOfItems_fromCStream_(ba, length, DATA(self)->stream);
	return IONUMBER(itemsRead);
}
Exemplo n.º 10
0
Arquivo: IoNumber.c Projeto: Akiyah/io
IO_METHOD(IoNumber, bitwiseXor)
{
	/*doc Number bitwiseXor(aNumber)
	Returns a new number with the bitwise XOR of the receiver and aNumber.
	*/

	/*doc Number ^(aNumber)
	Returns the bitwise xor with the receiver (both numbers are converted to longs for the operation).
	*/

	long other = IoMessage_locals_longArgAt_(m, locals, 0);
	long r = (double)((long)DATA(self) ^ other);
	return IONUMBER(r);
}
Exemplo n.º 11
0
IO_METHOD(IoSeq, atPut)
{
	/*doc Sequence atPut(aNumberIndex, aNumber)
	Sets the value at the index specified by aNumberIndex to aNumber. Returns self. 
	*/

	size_t i = IoMessage_locals_longArgAt_(m, locals, 0);
	UArray *a = DATA(self);

	IO_ASSERT_NOT_SYMBOL(self);

	if (UArray_isFloatType(a))
	{
		double v = IoMessage_locals_doubleArgAt_(m, locals, 1);
		UArray_at_putDouble_(a, i, v);
	}
	else
	{
		long v = IoMessage_locals_longArgAt_(m, locals, 1);
		UArray_at_putLong_(a, i, v);
	}

	return self;
}
Exemplo n.º 12
0
IO_METHOD(IoSeq, removeAt)
{
	/*doc Sequence removeAt(index)
	Removes the item at index. Returns self.
	*/

	long i = IoMessage_locals_longArgAt_(m, locals, 0);

	IO_ASSERT_NOT_SYMBOL(self);

	i = UArray_wrapPos_(DATA(self), i);

	UArray_removeRange(DATA(self), i, 1);
	return self;
}
Exemplo n.º 13
0
Arquivo: IoNumber.c Projeto: Akiyah/io
IO_METHOD(IoNumber, bitwiseOr)
{
	/*doc Number |(aNumber)
	Returns a new number with the bitwise OR of the receiver and aNumber.
	*/

	/*doc Number bitwiseOr(aNumber)
	Returns a new number with the bitwise AND of the receiver and aNumber.
	*/

	long other = IoMessage_locals_longArgAt_(m, locals, 0);
	long n = DATA(self);
	long r = n | other;
	return IONUMBER(r);
}
Exemplo n.º 14
0
Arquivo: IoFile.c Projeto: achoy/io
IO_METHOD(IoFile, position_)
{
	/*doc File setPosition(aNumber)
	Sets the file position pointer to the byte specified by aNumber. Returns self.
	*/

	long pos = IoMessage_locals_longArgAt_(m, locals, 0);
	IoFile_assertOpen(self, locals, m);

	if (fseek(DATA(self)->stream, pos, 0) != 0)
	{
		IoState_error_(IOSTATE, m, "unable to set position %i file path '%s'",
						(int)pos, UTF8CSTRING(DATA(self)->path));
	}

	return self;
}
Exemplo n.º 15
0
IO_METHOD(IoSeq, findSeqs)
{
	/*doc Sequence findSeqs(listOfSequences, optionalStartIndex)
	Returns an object with two slots - an \"index\" slot which contains 
	the first occurrence of any of the sequences in listOfSequences found 
	in the receiver after the startIndex, and a \"match\" slot, which 
	contains a reference to the matching sequence from listOfSequences. 
	If no startIndex is specified, the search starts at index 0. 
	nil is returned if no occurences are found. 
	*/

	IoList *others = IoMessage_locals_listArgAt_(m, locals, 0);
	List *delims = IoList_rawList(others);
	long f = 0;
	long firstIndex = -1;
	size_t match = 0;

	if (IoMessage_argCount(m) > 1)
	{
		f = IoMessage_locals_longArgAt_(m, locals, 1);
	}

	{
		size_t index;

		LIST_FOREACH(delims, i, s,
			if (!ISSEQ((IoSeq *)s))
			{
				IoState_error_(IOSTATE, m, "requires Sequences as arguments, not %ss", IoObject_name((IoSeq *)s));
			}

			index = UArray_find_from_(DATA(self), DATA(((IoSeq *)s)), f);

			if(index != -1 && (firstIndex == -1 || index < firstIndex)) 
			{ 
				firstIndex = (long)index; 
				match = i; 
			}
		);
	}