Mercurial > repos > tabletprog
comparison runtime/object.h @ 31:668f533e5284
Add initial version of C backend
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Sat, 07 Jul 2012 16:48:36 -0700 |
parents | |
children | a10f1b049193 |
comparison
equal
deleted
inserted
replaced
30:608eb70fe261 | 31:668f533e5284 |
---|---|
1 #ifndef OBJECT_H_ | |
2 #define OBJECT_H_ | |
3 | |
4 #include <stdint.h> | |
5 | |
6 typedef struct obj_meta obj_meta; | |
7 | |
8 typedef struct object | |
9 { | |
10 obj_meta * meta; | |
11 struct object * parent; | |
12 } object; | |
13 | |
14 typedef object * (*method)(uint32_t method_id, uint32_t num_args, object **); | |
15 | |
16 typedef object * (*closure_func)(void *, uint32_t, object **); | |
17 | |
18 typedef struct closure | |
19 { | |
20 object header; | |
21 void * env; | |
22 closure_func func; | |
23 } closure; | |
24 | |
25 struct obj_meta | |
26 { | |
27 uint32_t size; | |
28 method meth_lookup[16]; | |
29 }; | |
30 | |
31 #define mcall(method_id, num_args, args) (args[0])->meta->meth_lookup[method_id & 0xF](method_id, num_args, args) | |
32 #define ccall(clos, num_args, args) (((closure *)clos)->func(((closure *)clos)->env, num_args, args)) | |
33 | |
34 object * make_object(obj_meta * meta, void * parent, int num_props, ...); | |
35 | |
36 #endif //OBJECT_H_ |