view runtime/progfoot.inc @ 63:86ebdfb33711

Add sample for fixed bug
author Mike Pavone <pavone@retrodev.com>
date Sat, 14 Jul 2012 04:46:51 -0700
parents 7b454d100dc8
children abc6f3d644a4
line wrap: on
line source


array * alloc_array(uint32_t num_els)
{
	array * arr = 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 = malloc(sizeof(object *) * arr->storage);
}

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 = 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;
	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->length = 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;
}