view runtime/progfoot.inc @ 161:fc8eecad71e6

Fix variable name collision in integer objects
author Mike Pavone <pavone@retrodev.com>
date Sat, 10 Aug 2013 18:26:33 -0700
parents 25bc8a5ab41e
children 18598163e3ef
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_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;
}