view runtime/object.c @ 242:0e7982adc76b

Make the successful return value from a match expression be truthy and the failure value false. This avoids an extra method call when checking the result and avoids allocating a new object when a match fails.
author Mike Pavone <pavone@retrodev.com>
date Sun, 05 Jan 2014 20:56:25 -0800
parents abc6f3d644a4
children 75dc7161c1ca
line wrap: on
line source

#include "object.h"
#include <stdarg.h>
#include <stdlib.h>
#include <stddef.h>
#include <gc/gc.h>

object * make_object(obj_meta * meta, void * parent, int num_props, ...)
{
	va_list args;
	object * newobj = GC_MALLOC(meta->size);
	newobj->meta = meta;
	newobj->parent = parent;
	
	va_start(args, num_props);
	object ** curprop = ((object **)(newobj + 1));
	for (; num_props > 0; num_props--)
	{
		*curprop = va_arg(args, object *);
		curprop++;
	}
	va_end(args);
	return newobj;
}

object * mcall(uint32_t method_id, uint32_t num_args, object * self, ...)
{
	va_list args;
	va_start(args, self);
	object * ret = self->meta->meth_lookup[method_id & 0xF](method_id, num_args, self, args);
	va_end(args);
	return ret;
}