view runtime/progfoot.inc @ 263:98147071baf6

Add support for llMessage definitions in buildMethodTables
author Michael Pavone <pavone@retrodev.com>
date Mon, 14 Jul 2014 09:30:31 -0700
parents 18598163e3ef
children
line wrap: on
line source


array * alloc_array(uint32_t num_els)
{
	array * arr = GC_MALLOC(sizeof(array));
	arr->header.meta = &array_meta;
	arr->header.parent = NULL;
	arr->storage = arr->size = num_els;
	if (num_els < 4) {
		arr->storage = 4;
	}
	arr->data = GC_MALLOC(sizeof(object *) * arr->storage);
	return arr;
}

object * make_array(uint32_t num_els, ...)
{
	va_list els;
	int i;
	array * arr = alloc_array(num_els);
	va_start(els, num_els);
	for (i = 0; i < num_els; i++)
		arr->data[i] = va_arg(els, object *);
	va_end(els);
	return &(arr->header);
}

object * make_list(uint32_t num_els, ...)
{
	va_list els;
	int i;
	object * cur = mcall(METHOD_ID_EMPTY, 1, module_list);
	va_start(els, num_els);
	for (i = 0; i < num_els; i++)
		cur = mcall(METHOD_ID_CONS, 2, cur, va_arg(els, object *));
	va_end(els);
	return cur;
}

object * make_lambda(void * env, closure_func func)
{
	lambda * ret = GC_MALLOC(sizeof(lambda));
	ret->header.meta = &lambda_meta;
	ret->header.parent = NULL;
	ret->env = env;
	ret->func = func;
	return (object *) ret;
}

int main(int argc, char ** argv)
{
	int i;
	string * arg;
	GC_INIT();
	array * arr = alloc_array(argc);
	for (i = 0; i < argc; ++i) {
		arg = (string *)make_object(&string_meta, NULL, 0);
		arg->data = argv[i];
		arg->bytes = arg->len = strlen(argv[i]);
		arr->data[i] = &(arg->header);
	}
	object * ret = mcall(METHOD_ID_MAIN, 2, mainModule(), &(arr->header));
	if (ret->meta == &obj_int32_meta) {
		obj_int32 * reti32 = (obj_int32 *) ret;
		return reti32->num;
	}
	return 0;
}