Example #1
0
void IoBlock_copy_(IoBlock *self, IoBlock *other)
{
	DATA(self)->message = IOREF(DATA(other)->message);

	{
		List *l1 = DATA(self)->argNames;
		List_removeAll(l1);
		LIST_FOREACH(DATA(other)->argNames, i, v, List_append_(l1, IOREF(v)); );
	}
Example #2
0
File: IoLexer.c Project: Akiyah/io
void IoLexer_clear(IoLexer *self)
{
	LIST_FOREACH(self->tokenStream, i, t, IoToken_free((IoToken *)t) );
	List_removeAll(self->tokenStream);

	Stack_clear(self->posStack);
	Stack_clear(self->tokenStack);

	self->current = self->s;
	self->resultIndex = 0;
	self->maxChar = 0;
	self->errorToken = NULL;
}
Example #3
0
void UDBIndex_findHoles(UDBIndex *self)
{
	PID_TYPE pid = UDBIndex_pidCount(self);
	
	List_removeAll(self->holes);
	
	while (pid --)
	{
		if (!UDBIndex_posForPid_(self, pid)) 
		{
			List_push_(self->holes, (void *)pid);
		}
	}
}
Example #4
0
void IoMessage_copy_(IoMessage *self, IoMessage *other)
{
	IoMessage_rawSetName_(self, DATA(other)->name);

	{
		List *l1 = DATA(self)->args;
		List *l2 = DATA(other)->args;
		size_t i, max = List_size(l2);
		List_removeAll(l1);

		for (i = 0; i < max; i ++)
		{
			List_append_(l1, IOREF(List_rawAt_(l2, i)));
		}
	}

	IoMessage_rawSetNext_(self, DATA(other)->next);
	IoMessage_rawSetCachedResult_(self, DATA(other)->cachedResult);
	IoMessage_rawCopySourceLocation(self, other);
}
Example #5
0
File: IoLexer.c Project: Akiyah/io
void IoLexer_buildLineIndex(IoLexer *self)
{
	char *s = self->s;

	List_removeAll(self->charLineIndex);

	List_append_(self->charLineIndex, s);

	while (*s)
	{
		if (*s == '\n')
		{
			List_append_(self->charLineIndex, s);
		}
		s ++;
	}

	List_append_(self->charLineIndex, s);
	self->lineHint = 0;
}
Example #6
0
IO_METHOD(IoMessage, setArguments)
{
	/*doc Message setArguments(aListOfMessages)
	Sets the arguments of the receiver to deep copies of
	those contained in aListOfMessages.  Returns self.
	*/

	IoList *ioList = IoMessage_locals_listArgAt_(m, locals, 0);
	List *newArgs = IoList_rawList(ioList);

	List_removeAll(DATA(self)->args);

	LIST_FOREACH(newArgs, i, argMessage,

		if (!ISMESSAGE((IoMessage *)argMessage))
		{
			IoState_error_(IOSTATE, m, "arguments_() takes a list containing only Message objects");
		}

		List_append_(DATA(self)->args, IOREF((IoMessage *)argMessage));
	);
Example #7
0
void Level_finish(Level *self)
{
	if (self->message)
	{
		IoMessage_rawSetNext_(self->message, NULL);

		// Remove extra () we added in for operators, but do not need any more
		if ( IoMessage_argCount(self->message) == 1 )
		{
			IoMessage *arg = IoMessage_rawArgAt_(self->message, 0);

			if ( IoSeq_rawSize(IoMessage_name(arg)) == 0 && IoMessage_argCount(arg) == 1 && IoMessage_rawNext(arg) == NULL )
			{
				List_copy_(IoMessage_rawArgList(self->message), IoMessage_rawArgList(arg));
				List_removeAll(IoMessage_rawArgList(arg));
			}
		}
	}

	self->type = UNUSED;
}
Example #8
0
void Levels_reset(Levels *self)
{
	int i;
	self->currentLevel = 1;

	for (i = 0; i < IO_OP_MAX_LEVEL; i ++)
	{
		Level *level = &self->pool[i];
		level->type = UNUSED;
	}

	{
		Level *level = &self->pool[0];
		level->message = NULL;
		level->type = NEW;
		level->precedence = IO_OP_MAX_LEVEL;
	}

	List_removeAll(self->stack);
	List_append_(self->stack, &self->pool[0]);
}
Example #9
0
void Levels_attach(Levels *self, IoMessage *msg, List *expressions)
{
	// TODO clean up this method.

	IoState *state = IoObject_state(msg);
	IoSymbol *messageSymbol = IoMessage_name(msg);
	char *messageName = CSTRING(messageSymbol);
	int precedence = Levels_levelForOp(self, messageName, messageSymbol, msg);

	int msgArgCount = IoMessage_argCount(msg);

	/*
	// o a := b c ; d  becomes  o setSlot("a", b c) ; d
	//
	// a      attaching
	// :=     msg
	// b c    msg->next
	*/
	
	if (Levels_isAssignOperator(self, messageSymbol))
	{
		Level *currentLevel = Levels_currentLevel(self);
		IoMessage *attaching = currentLevel->message;
		IoSymbol *setSlotName;

		if (attaching == NULL) // := b ;
		{
			// Could be handled as, message(:= 42) -> setSlot(nil, 42)

			IoState_error_(state, msg, "compile error: %s requires a symbol to its left.", messageName);
			return;
		}

		if (IoMessage_argCount(attaching) > 0) // a(1,2,3) := b ;
		{
			IoState_error_(state, msg, "compile error: The symbol to the left of %s cannot have arguments.", messageName);
			return;
		}

		if (msgArgCount > 1) // setSlot("a") :=(b, c, d) e ;
		{
			IoState_error_(state, msg, "compile error: Assign operator passed multiple arguments, e.g., a := (b, c).", messageName);
			return;
		}


		{
			// a := b ;
			IoSymbol *slotName = DATA(attaching)->name;
			IoSymbol *quotedSlotName = IoSeq_newSymbolWithFormat_(state, "\"%s\"", CSTRING(slotName));
			IoMessage *slotNameMessage = IoMessage_newWithName_returnsValue_(state, quotedSlotName, slotName);

			IoMessage_rawCopySourceLocation(slotNameMessage, attaching);

			// a := b ;  ->  a("a") := b ;
			IoMessage_addArg_(attaching, slotNameMessage);

			setSlotName = Levels_nameForAssignOperator(self, state, messageSymbol, slotName, msg);
		}

		// a("a") := b ;  ->  setSlot("a") := b ;
		DATA(attaching)->name = IoObject_addingRef_(attaching, setSlotName);

		currentLevel->type = ATTACH;

		if (msgArgCount > 0) // setSlot("a") :=(b c) d e ;
		{
			// b c
			IoMessage *arg = IoMessage_rawArgAt_(msg, 0);

			if (DATA(msg)->next == NULL || IoMessage_rawIsEOL(DATA(msg)->next))
			{
				IoMessage_addArg_(attaching, arg);
			}
			else
			{
				// ()
				IoMessage *foo = IoMessage_newWithName_(state, IoState_symbolWithCString_(state, ""));

				IoMessage_rawCopySourceLocation(foo, attaching);

				// ()  ->  (b c)
				IoMessage_addArg_(foo, arg);

				// (b c)  ->  (b c) d e ;
				IoMessage_rawSetNext_(foo, DATA(msg)->next);

				// setSlot("a") :=(b c) d e ;  ->  setSlot("a", (b c) d e ;) :=(b c) d e ;
				IoMessage_addArg_(attaching, foo);
			}
		}
		else // setSlot("a") := b ;
		{
			// setSlot("a") := or setSlot("a") := ;
			IoMessage *mn = DATA(msg)->next;
			IoSymbol *name = mn ? DATA(mn)->name : NULL;
			IoSymbol *semi = IoObject_state(msg)->semicolonSymbol;

			//if (mn == NULL || IoMessage_rawIsEOL(mn))
			if (mn == NULL || name == semi)
			{
				IoState_error_(state, msg, "compile error: %s must be followed by a value.", messageName);
			}

			// setSlot("a") := b c ;  ->  setSlot("a", b c ;) := b c ;
			IoMessage_addArg_(attaching, DATA(msg)->next);
		}

		// process the value (b c d) later  (setSlot("a", b c d) := b c d ;)
		if (DATA(msg)->next != NULL && !IoMessage_rawIsEOL(DATA(msg)->next))
		{
			List_push_(expressions, DATA(msg)->next);
		}

		{
			IoMessage *last = msg;
			while (DATA(last)->next != NULL && !IoMessage_rawIsEOL(DATA(last)->next))
			{
				last = DATA(last)->next;
			}

			IoMessage_rawSetNext_(attaching, DATA(last)->next);

			// Continue processing in IoMessage_opShuffle loop
			IoMessage_rawSetNext_(msg, DATA(last)->next);

			if (last != msg)
			{
				IoMessage_rawSetNext_(last, NULL);
			}
		}

		// make sure b in 1 := b gets executed
		IoMessage_rawSetCachedResult_(attaching, NULL);
	}
	else if (IoMessage_rawIsEOL(msg))
	{
		Levels_popDownTo(self, IO_OP_MAX_LEVEL-1);
		Level_attachAndReplace(Levels_currentLevel(self), msg);
	}
	else if (precedence != -1) // is an operator
	{
		if (msgArgCount > 0)
		{
			// move arguments off to their own message to make () after operators behave like Cs grouping ()
			IoMessage *brackets = IoMessage_newWithName_(state, IoState_symbolWithCString_(state, ""));

			IoMessage_rawCopySourceLocation(brackets, msg);

			List_copy_(IoMessage_rawArgList(brackets), IoMessage_rawArgList(msg));
			List_removeAll(IoMessage_rawArgList(msg));

			// Insert the brackets message between msg and its next message
			IoMessage_rawSetNext_(brackets, DATA(msg)->next);
			IoMessage_rawSetNext_(msg, brackets);
		}

		Levels_popDownTo(self, precedence);
		Levels_attachToTopAndPush(self, msg, precedence);
	}
	else
	{
		Level_attachAndReplace(Levels_currentLevel(self), msg);
	}
}