view runtime/object.c @ 44:9dd370530f69

Fix escape codes in string literals. Don't print out the return value of main method. Fixup fib example to use print: method. Cleanup error handling in compiler slightly
author Mike Pavone <pavone@retrodev.com>
date Thu, 12 Jul 2012 22:49:08 -0700
parents bf5e88f6419d
children 2a9c6eed0c70
line wrap: on
line source

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

object * make_object(obj_meta * meta, void * parent, int num_props, ...)
{
	va_list args;
	object * newobj = 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 * make_closure(void * env, closure_func func)
{
	closure * ret = malloc(sizeof(closure));
	ret->header.meta = &lambda_meta;
	ret->header.parent = NULL;
	ret->env = env;
	ret->func = func;
	return (object *) ret;
}

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