comparison runtime/object.h @ 7:d61550e2c001

Added current work on new runtime
author Mike Pavone <pavone@retrodev.com>
date Wed, 13 May 2009 00:47:40 -0400
parents
children 8d74ef7fa357
comparison
equal deleted inserted replaced
6:f67d9be38ddf 7:d61550e2c001
1 #ifndef _OBJECT_H_
2 #define _OBJECT_H_
3
4 #include "plat_types.h"
5 #include "thread.h"
6
7 typedef enum {
8 NORMAL_RETURN=0,
9 EXCEPTION_RETURN,
10 TAIL_RETURN,
11 NO_CONVERSION,
12 STACK_UNWIND
13 } returntype;
14
15
16 typedef returntype (*rhope_func)(struct calldata *);
17 typedef void (*special_func) (struct object *);
18
19 typedef struct{
20 rhope_func *method_lookup;
21 rhope_func *getter_lookup;
22 rhope_func *setter_lookup;
23 rhope_func *convert_to;
24 rhope_func *convert_from;
25 special_func init;
26 special_func copy;
27 special_func cleanup;
28 struct object *name;
29 uint32_t first_methodid;
30 uint32_t last_methodid;
31 uint32_t first_getfieldid;
32 uint32_t last_getfieldid;
33 uint32_t first_setfieldid;
34 uint32_t last_setfieldid;
35 uint32_t first_convertto;
36 uint32_t last_convertto;
37 uint32_t first_convertfrom;
38 uint32_t last_convertfrom;
39 uint32_t size;
40 uint32_t boxed_size;
41 } blueprint;
42
43 typedef struct object {
44 rh_atomic32(refcount);
45 blueprint *bprint;
46 } object;
47
48 typedef struct {
49 object base;
50 uint32_t size;
51 } multisize;
52
53
54 typedef struct calldata {
55 rhope_func tail_func;
56 uint32_t num_params;
57 uint32_t original_methodid;
58 object *params[32];
59 } calldata;
60
61 #define OBegin typedef struct { object header;
62 #define Object(name) } _t_ ## name;
63
64 #define MOBegin typedef struct { multisize header;
65
66 #define get_blueprint(object) (object)->bprint
67
68 #define add_ref(object) rh_atomic_add(&(object->header), refcount, 1)
69
70 returntype call_method(uint32_t methodid, calldata * params);
71 returntype set_field(uint32_t setfieldid, calldata * params);
72 returntype get_field(uint32_t getfieldid, calldata * params);
73 object * alloc_object(blueprint * bp);
74 void * alloc_variable(uint32_t size);
75 object * new_object(uint32_t type);
76 multisize * new_multisize(uint32_t type, uint32_t size);
77 void release_ref(object * obj);
78 blueprint * register_type_byid(uint32_t type, uint32_t size, special_func init, special_func copy, special_func cleanup);
79 blueprint * new_blueprint(uint32_t type, uint32_t size, special_func init, special_func copy, special_func cleanup);
80 void add_method(blueprint * bp, uint32_t methodid, rhope_func impl);
81 returntype convert_to(uint32_t convertto, calldata * params);
82 returntype convert_from(uint32_t convertfrom, calldata * params);
83 object * copy_object(object * tocopy);
84 returntype coerce_value(uint32_t type, calldata * params);
85
86 #define INITIAL_TYPE_STORAGE 32
87 #define INITIAL_METHOD_LOOKUP 8
88 #define BELOW_INITIAL_METHOD 3
89
90 #endif //_OBJECT_H_