comparison runtime/object.c @ 34:a10f1b049193

Working closures, but need to rethink method call strategy
author Mike Pavone <pavone@retrodev.com>
date Mon, 09 Jul 2012 08:57:50 -0700
parents 668f533e5284
children bf5e88f6419d
comparison
equal deleted inserted replaced
33:96e21f525b78 34:a10f1b049193
1 #include "object.h" 1 #include "object.h"
2 #include <stdarg.h> 2 #include <stdarg.h>
3 #include <stdlib.h> 3 #include <stdlib.h>
4 #include <stddef.h>
4 5
5 object * make_object(obj_meta * meta, void * parent, int num_props, ...) 6 object * make_object(obj_meta * meta, void * parent, int num_props, ...)
6 { 7 {
7 va_list args; 8 va_list args;
8 object * newobj = malloc(meta->size); 9 object * newobj = malloc(meta->size);
12 va_start(args, num_props); 13 va_start(args, num_props);
13 object ** curprop = ((object **)(newobj + 1)); 14 object ** curprop = ((object **)(newobj + 1));
14 for (; num_props > 0; num_props--) 15 for (; num_props > 0; num_props--)
15 { 16 {
16 *curprop = va_arg(args, object *); 17 *curprop = va_arg(args, object *);
18 curprop++;
17 } 19 }
18 va_end(args); 20 va_end(args);
19 return newobj; 21 return newobj;
20 } 22 }
21 23
24 object * make_closure(void * env, closure_func func)
25 {
26 closure * ret = malloc(sizeof(closure));
27 ret->header.meta = &lambda_meta;
28 ret->header.parent = NULL;
29 ret->env = env;
30 ret->func = func;
31 return (object *) ret;
32 }