Mercurial > repos > tabletprog
annotate 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 |
rev | line source |
---|---|
31
668f533e5284
Add initial version of C backend
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1 #include "object.h" |
668f533e5284
Add initial version of C backend
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2 #include <stdarg.h> |
668f533e5284
Add initial version of C backend
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
3 #include <stdlib.h> |
34
a10f1b049193
Working closures, but need to rethink method call strategy
Mike Pavone <pavone@retrodev.com>
parents:
31
diff
changeset
|
4 #include <stddef.h> |
31
668f533e5284
Add initial version of C backend
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
5 |
668f533e5284
Add initial version of C backend
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
6 object * make_object(obj_meta * meta, void * parent, int num_props, ...) |
668f533e5284
Add initial version of C backend
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
7 { |
668f533e5284
Add initial version of C backend
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
8 va_list args; |
668f533e5284
Add initial version of C backend
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
9 object * newobj = malloc(meta->size); |
668f533e5284
Add initial version of C backend
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
10 newobj->meta = meta; |
668f533e5284
Add initial version of C backend
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
11 newobj->parent = parent; |
668f533e5284
Add initial version of C backend
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
12 |
668f533e5284
Add initial version of C backend
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
13 va_start(args, num_props); |
668f533e5284
Add initial version of C backend
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
14 object ** curprop = ((object **)(newobj + 1)); |
668f533e5284
Add initial version of C backend
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
15 for (; num_props > 0; num_props--) |
668f533e5284
Add initial version of C backend
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
16 { |
668f533e5284
Add initial version of C backend
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
17 *curprop = va_arg(args, object *); |
34
a10f1b049193
Working closures, but need to rethink method call strategy
Mike Pavone <pavone@retrodev.com>
parents:
31
diff
changeset
|
18 curprop++; |
31
668f533e5284
Add initial version of C backend
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
19 } |
668f533e5284
Add initial version of C backend
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
20 va_end(args); |
668f533e5284
Add initial version of C backend
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
21 return newobj; |
668f533e5284
Add initial version of C backend
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
22 } |
668f533e5284
Add initial version of C backend
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
23 |
34
a10f1b049193
Working closures, but need to rethink method call strategy
Mike Pavone <pavone@retrodev.com>
parents:
31
diff
changeset
|
24 object * make_closure(void * env, closure_func func) |
a10f1b049193
Working closures, but need to rethink method call strategy
Mike Pavone <pavone@retrodev.com>
parents:
31
diff
changeset
|
25 { |
a10f1b049193
Working closures, but need to rethink method call strategy
Mike Pavone <pavone@retrodev.com>
parents:
31
diff
changeset
|
26 closure * ret = malloc(sizeof(closure)); |
a10f1b049193
Working closures, but need to rethink method call strategy
Mike Pavone <pavone@retrodev.com>
parents:
31
diff
changeset
|
27 ret->header.meta = &lambda_meta; |
a10f1b049193
Working closures, but need to rethink method call strategy
Mike Pavone <pavone@retrodev.com>
parents:
31
diff
changeset
|
28 ret->header.parent = NULL; |
a10f1b049193
Working closures, but need to rethink method call strategy
Mike Pavone <pavone@retrodev.com>
parents:
31
diff
changeset
|
29 ret->env = env; |
a10f1b049193
Working closures, but need to rethink method call strategy
Mike Pavone <pavone@retrodev.com>
parents:
31
diff
changeset
|
30 ret->func = func; |
a10f1b049193
Working closures, but need to rethink method call strategy
Mike Pavone <pavone@retrodev.com>
parents:
31
diff
changeset
|
31 return (object *) ret; |
a10f1b049193
Working closures, but need to rethink method call strategy
Mike Pavone <pavone@retrodev.com>
parents:
31
diff
changeset
|
32 } |