Пример #1
0
IoMessage *IoMessage_newWithName_returnsValue_(void *state, IoSymbol *symbol, IoObject *v)
{
	IoMessage *self = IoMessage_new(state);
	IoMessage_rawSetName_(self, symbol);
	IoMessage_rawSetCachedResult_(self, v);
	return self;
}
Пример #2
0
IoMessage *IoMessage_newWithName_label_(void *state, IoSymbol *symbol, IoSymbol *label)
{
	IoMessage *self = IoMessage_new(state);
	IoMessage_rawSetName_(self, symbol);
	IoMessage_rawSetLabel_(self, label);
	return self;
}
Пример #3
0
intptr_t bouncer(IoBlock *self, intptr_t ret, intptr_t a, intptr_t b, intptr_t c, intptr_t d, intptr_t e)
{
	IoObject *lobby = IoState_lobby(IOSTATE);
	IoNumber *n;
	static IoMessage *m = NULL;
	List *argNames = ((IoBlockData*)IoObject_dataPointer(self))->argNames;

	if (m == NULL)
		m = IoMessage_new(IOSTATE);
	if (0 < argNames->size)
		IoMessage_setCachedArg_toInt_(m, 0, (int)a);
	if (1 < argNames->size)
		IoMessage_setCachedArg_toInt_(m, 1, (int)b);
	if (2 < argNames->size)
		IoMessage_setCachedArg_toInt_(m, 2, (int)c);
	if (3 < argNames->size)
		IoMessage_setCachedArg_toInt_(m, 3, (int)d);
	if (4 < argNames->size)
		IoMessage_setCachedArg_toInt_(m, 4, (int)e);

	n = IoBlock_activate(self, lobby, lobby, m, lobby);

	if (ISNUMBER(n))
	{
		return (intptr_t)IoNumber_asInt(n);
	}

	return 0;
}
Пример #4
0
static IoRegexMatch *IoRegexMatches_searchFrom_withOptions_(IoRegexMatches *self, IoMessage *m, int position, int options)
{
	Regex *regex = IoRegex_rawRegex(DATA(self)->regex);
	int *captures = 0;
	int *capture = 0;
	IoList *rangeList = 0;
	int i = 0;

	int captureCount = Regex_search_from_to_withOptions_captureArray_(
		regex,
		CSTRING(DATA(self)->string),
		position,
		DATA(self)->endPosition,
		options,
		DATA(self)->captureArray
	);

	if (Regex_error(regex))
		IoState_error_(IOSTATE, m, Regex_error(regex));

	if (captureCount == 0)
		return IONIL(self);

	/* The search function puts information about captured substrings in captureArray.
	There's a pair of integers for each capture. The first element of the pair is the
	start index of the substring, and the second element is the end index.
	The first pair represents the entire match. */
	captures = (int *)UArray_data(DATA(self)->captureArray);
	DATA(self)->position = captures[1];
	DATA(self)->currentMatchIsEmpty = (captures[0] == captures[1]);

	capture = captures;
	rangeList = IoList_new(IOSTATE);
	for (i = 0; i < captureCount; i++) {
		IoObject *element = 0;
		// unsure about this locals initialization ...
		IoObject *locals = NULL;
		IoMessage *message = IoMessage_new(IOSTATE);

		if (capture[0] == -1 && capture[1] == -1) {
			/* This capture was not matched. */
			element = IONIL(self);
		} else {
			element = IoRange_new(IOSTATE);
			IoMessage_setCachedArg_to_(message, 0, IONUMBER(capture[0]));
			IoMessage_setCachedArg_to_(message, 1, IONUMBER(capture[1]));
			IoRange_setRange(element, locals, message);
			IoRange_setFirst(element, IONUMBER(capture[0]));
			IoRange_setLast(element, IONUMBER(capture[1]));
		}

		IoList_rawAppend_(rangeList, element);
		capture += 2;
	}

	return IoRegexMatch_newWithRegex_subject_captureRanges_(IOSTATE, DATA(self)->regex, DATA(self)->string, rangeList);
}
Пример #5
0
void IoMessage_setCachedArg_to_(IoMessage *self, int n, IoObject *v)
{
	IoMessage *arg;

	while (!(arg = List_at_(DATA(self)->args, n)))
	{
		IoMessage_addArg_(self, IoMessage_new(IOSTATE));
	}

	IoMessage_rawSetCachedResult_(arg, v);
}
Пример #6
0
IoMessage *IoMessage_newParseNextMessageChain(void *state, IoLexer *lexer)
{
		IoCoroutine *current = IoState_currentCoroutine(state);
		Coro *coro = IoCoroutine_cid(current);
		size_t left = Coro_bytesLeftOnStack(coro);

		/*
		if (Coro_stackSpaceAlmostGone(coro))
		{
			// need to make Coroutine support a stack of Coros which it frees when released
			// return IoCoroutine_internallyChain(current, context, IoMessage_...);

			Coro *newCoro = Coro_new();
			ParseContext p = {state, lexer, newCoro, coro, NULL};
			printf("Warning IoMessage_newParseNextMessageChain doing callc with %i bytes left to avoid stack overflow\n", left);

			Coro_startCoro_(coro, newCoro, &p, (CoroStartCallback *)IoMessage_coroNewParseNextMessageChain);
			Coro_free(newCoro);
			return p.result;
		}
		*/

	IoMessage *self = IoMessage_new(state);

	if (IoTokenType_isValidMessageName(IoLexer_topType(lexer)))
	{
		IoMessage_parseName(self, lexer);
	}

	if (IoLexer_topType(lexer) == OPENPAREN_TOKEN)
	{
		IoMessage_parseArgs(self, lexer);
	}

	if (IoTokenType_isValidMessageName(IoLexer_topType(lexer)))
	{
		IoMessage_parseNext(self, lexer);
	}

	while (IoLexer_topType(lexer) == TERMINATOR_TOKEN)
	{
		IoLexer_pop(lexer);

		if (IoTokenType_isValidMessageName(IoLexer_topType(lexer)))
		{
			IoMessage *eol = IoMessage_newWithName_(state, ((IoState*)state)->semicolonSymbol);
			IoMessage_rawSetNext(self, eol);
			IoMessage_parseNext(eol, lexer);
		}
	}

	return self;
}
Пример #7
0
void IoMessage_setCachedArg_toInt_(IoMessage *self, int n, int anInt)
{
	// optimized to avoid creating a number unless necessary

	IoMessage *arg = NULL;

	while (!(arg = List_at_(DATA(self)->args, n)))
	{
		List_append_(DATA(self)->args, IOREF(IoMessage_new(IOSTATE)));
	}

	IoMessage_rawSetCachedResult_(arg, IONUMBER(anInt));
}
Пример #8
0
IoMessage *IoMessage_deepCopyOf_(IoMessage *self)
{
	IoMessage *child = IoMessage_new(IOSTATE);
	int i;

	/*printf("deep copying: %s\n", UArray_asCString(IoMessage_description(self)));*/
	for (i = 0; i < IoMessage_argCount(self); i ++)
	{
		List_append_(DATA(child)->args,
					 IOREF(IoMessage_deepCopyOf_(LIST_AT_(DATA(self)->args, i))));
	}

	IoMessage_rawSetName_(child, DATA(self)->name);
	IoMessage_rawSetCachedResult_(child, (IoObject *)DATA(self)->cachedResult);

	if (DATA(self)->next)
	{
		IoMessage_rawSetNext_(child, IoMessage_deepCopyOf_(DATA(self)->next));
	}
	/*printf("deep copy result: %s\n", UArray_asCString(IoMessage_description(child)));*/
	return child;
}
Пример #9
0
void IoMessage_addCachedArg_(IoMessage *self, IoObject *v)
{
	IoMessage *m = IoMessage_new(IOSTATE);
	IoMessage_rawSetCachedResult_(m, v);
	IoMessage_addArg_(self, m);
}