Esempio n. 1
0
SlimList* SlimList_GetTailAt(SlimList* self, int index)
{
    SlimList * tail = SlimList_Create();
    int length = SlimList_GetLength(self);
    for(; index < length; index++) {
        SlimList_AddString(tail, SlimList_GetStringAt(self, index));
    }
    return tail;
}
Esempio n. 2
0
int SlimList_SerializedLength(SlimList* self)
{
    int length = LIST_OVERHEAD;
    int i;
    for(i = 0; i < SlimList_GetLength(self); i++)
    {
        length += strlen(nodeStringAt(self, i)) + ELEMENT_OVERHEAD;
    }
    return length;
}
Esempio n. 3
0
char* Call(ListExecutor* self, SlimList* instruction) {
	if (SlimList_GetLength(instruction) < 4)
		return MalformedInstruction(self, instruction);
	char* instanceName = SlimList_GetStringAt(instruction, 2);
	char* methodName = SlimList_GetStringAt(instruction, 3);
	SlimList* args = SlimList_GetTailAt(instruction, 4);
		
	char* result = buyString(StatementExecutor_Call(self->executor, instanceName, methodName, args));
	SlimList_Destroy(args);
	return result;
}
Esempio n. 4
0
void* ExceptionsExample_Create(void* errorHandler, SlimList* args)
{
	if (SlimList_GetLength(args) < 1) {
		SLIM_CONSTRUCTOR_ERROR(errorHandler, "One arg required");
		return NULL;
	}

	ExceptionsExample* self = malloc(sizeof(ExceptionsExample));
	memset(self, 0, sizeof(ExceptionsExample));
	return self;
}
Esempio n. 5
0
char* CallAndAssign(ListExecutor* self, SlimList* instruction) {
	if (SlimList_GetLength(instruction) < 5)
		return MalformedInstruction(self, instruction);
	char* symbolName = SlimList_GetStringAt(instruction, 2);
	char* instanceName = SlimList_GetStringAt(instruction, 3);
	char* methodName = SlimList_GetStringAt(instruction, 4);
	SlimList* args = SlimList_GetTailAt(instruction, 5);
		
	char* result = CSlim_BuyString(StatementExecutor_Call(self->executor, instanceName, methodName, args));
	StatementExecutor_SetSymbol(self->executor, symbolName, result);
	SlimList_Destroy(args);
	return result;
}
Esempio n. 6
0
SlimList* ListExecutor_Execute(ListExecutor* self, SlimList* instructions)
{
	SlimList* results = SlimList_Create();
	int numberOfInstructions = SlimList_GetLength(instructions);
	int n;
	for (n=0; n<numberOfInstructions; n++) {
		SlimList* instruction = SlimList_GetListAt(instructions, n);
		char* id = SlimList_GetStringAt(instruction, 0);
		char* result = Dispatch(self, instruction);
		AddResult(results, id, result);		
		if (result)
			free(result);
	}
	
	return results;	
}
Esempio n. 7
0
char* SlimList_Serialize(SlimList* self)
{
    char* buf = malloc(SlimList_SerializedLength(self)+1);
    char* write_ptr = buf;
    int listLength = SlimList_GetLength(self);
    int i;

    write_ptr += sprintf(write_ptr, "[%06d:", listLength);

    for(i = 0; i < listLength; i++)
    {
        char * nodeString = nodeStringAt(self, i);
        write_ptr += sprintf(write_ptr, "%06ld:%s:", strlen(nodeString), nodeString);
    }
    strcpy(write_ptr, "]");
    return buf;
}
Esempio n. 8
0
void replaceSymbols(SymbolTable* symbolTable, SlimList* list) {
	int i;
	for (i=0; i<SlimList_GetLength(list); i++) {
		char* string = SlimList_GetStringAt(list, i);
		SlimList* embeddedList = SlimList_Deserialize(string);
		if (embeddedList == NULL) {
			char* replacedString = replaceString(symbolTable, string);
			SlimList_ReplaceAt(list, i, replacedString);
			free(replacedString);
		} else {
			replaceSymbols(symbolTable, embeddedList);
			char* serializedReplacedList = SlimList_Serialize(embeddedList);
			SlimList_ReplaceAt(list, i, serializedReplacedList);
			SlimList_Destroy(embeddedList);
			free(serializedReplacedList);
		}
	}
}
Esempio n. 9
0
char* StatementExecutor_Call(StatementExecutor* executor, const char* instanceName, const char* methodName, SlimList* args){
	InstanceNode* instanceNode = GetInstanceNode(executor, instanceName);
	if (instanceNode)
	{
		MethodNode* node;
		for (node = instanceNode->fixture->methods; node; node = node->next) {
			if (strcmp(methodName, node->name) == 0) {
				replaceSymbols(executor->symbolTable, args);
				char* retval =  node->method(instanceNode->instance, args);
				return retval;
			}
		}
		char * formatString = "__EXCEPTION__:message:<<NO_METHOD_IN_CLASS %.32s[%d] %.32s.>>";
		snprintf(executor->message, 120, formatString, methodName, SlimList_GetLength(args), instanceNode->fixture->name);
		return executor->message;
	}
	char * formatString = "__EXCEPTION__:message:<<NO_INSTANCE %.32s.>>";
	snprintf(executor->message, 120, formatString, instanceName);
	return executor->message;
}
Esempio n. 10
0
char* SlimList_ToString(SlimList* self) {
    static char string[128];
    char buf[128];
    buf[0] = '\0';
    strncat(buf, "[", 128);
    int length = SlimList_GetLength(self);
    int i;
    for (i = 0; i<length; i++) {
        SlimList* sublist = SlimList_GetListAt(self, i);
        if (sublist != NULL) {
            strncat(buf, SlimList_ToString(sublist), 128);
        } else {
            strncat(buf, "\"", 128);
            strncat(buf, SlimList_GetStringAt(self, i), 128);
            strncat(buf, "\"", 128);
        }
        if (i != (length-1)) {
            strncat(buf, ", ", 128);
        }
    }
    strncat(buf, "]", 128);
    strncpy(string, buf, 128);
    return string;
}