Mercurial > repos > tabletprog
comparison runtime/object.h @ 35:bf5e88f6419d
Use a function/method call strategy that actually works
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Mon, 09 Jul 2012 21:32:28 -0700 |
parents | a10f1b049193 |
children | e7be612fd3ae |
comparison
equal
deleted
inserted
replaced
34:a10f1b049193 | 35:bf5e88f6419d |
---|---|
1 #ifndef OBJECT_H_ | 1 #ifndef OBJECT_H_ |
2 #define OBJECT_H_ | 2 #define OBJECT_H_ |
3 | 3 |
4 #include <stdint.h> | 4 #include <stdint.h> |
5 #include <stdarg.h> | |
5 | 6 |
6 typedef struct obj_meta obj_meta; | 7 typedef struct obj_meta obj_meta; |
7 | 8 |
8 typedef struct object | 9 typedef struct object |
9 { | 10 { |
10 obj_meta * meta; | 11 obj_meta * meta; |
11 struct object * parent; | 12 struct object * parent; |
12 } object; | 13 } object; |
13 | 14 |
14 typedef object * (*method)(uint32_t method_id, uint32_t num_args, object **); | 15 typedef object * (*method)(uint32_t method_id, uint32_t num_args, object * self, va_list args); |
15 | 16 |
16 typedef object * (*closure_func)(void *, uint32_t, object **); | 17 typedef object * (*closure_func)(void *, uint32_t, ...); |
17 | 18 |
18 typedef struct closure | 19 typedef struct closure |
19 { | 20 { |
20 object header; | 21 object header; |
21 void * env; | 22 void * env; |
28 method meth_lookup[16]; | 29 method meth_lookup[16]; |
29 }; | 30 }; |
30 | 31 |
31 extern obj_meta lambda_meta; | 32 extern obj_meta lambda_meta; |
32 | 33 |
33 #define mcall(method_id, num_args, args) (args[0])->meta->meth_lookup[method_id & 0xF](method_id, num_args, args) | 34 object * mcall(uint32_t method_id, uint32_t num_args, object * self, ...); |
34 #define ccall(clos, num_args, args) (((closure *)clos)->func(((closure *)clos)->env, num_args, args)) | 35 #define ccall(clos, num_args, ...) (((closure *)clos)->func(((closure *)clos)->env, num_args,##__VA_ARGS__)) |
35 | 36 |
36 object * make_object(obj_meta * meta, void * parent, int num_props, ...); | 37 object * make_object(obj_meta * meta, void * parent, int num_props, ...); |
37 object * make_closure(void * env, closure_func func); | 38 object * make_closure(void * env, closure_func func); |
38 | 39 |
39 #endif //OBJECT_H_ | 40 #endif //OBJECT_H_ |