paul@126 | 1 | /* Runtime types. */ |
paul@126 | 2 | |
paul@126 | 3 | #ifndef __TYPES_H__ |
paul@126 | 4 | #define __TYPES_H__ |
paul@126 | 5 | |
paul@126 | 6 | /* Attribute tables are lists of codes confirming the presence of attributes. */ |
paul@126 | 7 | |
paul@126 | 8 | typedef struct __table |
paul@126 | 9 | { |
paul@126 | 10 | const unsigned int size, attrs[]; |
paul@126 | 11 | } __table; |
paul@126 | 12 | |
paul@126 | 13 | /* Parameter tables are lists of codes confirming the presence of parameters, as |
paul@126 | 14 | well as the positions of those parameters in the list for a given function. |
paul@126 | 15 | */ |
paul@126 | 16 | |
paul@126 | 17 | typedef struct __param |
paul@126 | 18 | { |
paul@126 | 19 | unsigned short code, pos; |
paul@126 | 20 | } __param; |
paul@126 | 21 | |
paul@126 | 22 | typedef struct __ptable |
paul@126 | 23 | { |
paul@126 | 24 | const unsigned int size; |
paul@126 | 25 | const __param params[]; |
paul@126 | 26 | } __ptable; |
paul@126 | 27 | |
paul@126 | 28 | /* Attributes are context and value pairs. |
paul@126 | 29 | Objects are collections of attributes. |
paul@126 | 30 | Object references are references to tables and collections of attributes. |
paul@126 | 31 | Attribute references are references to single attributes. */ |
paul@126 | 32 | |
paul@126 | 33 | typedef struct __obj __obj; |
paul@126 | 34 | |
paul@126 | 35 | typedef struct __attr |
paul@126 | 36 | { |
paul@126 | 37 | /* One of... */ |
paul@126 | 38 | union |
paul@126 | 39 | { |
paul@126 | 40 | __obj * context; /* attribute context */ |
paul@126 | 41 | unsigned int min; /* minimum number of parameters */ |
paul@126 | 42 | __obj * b; /* bound callable object */ |
paul@126 | 43 | }; |
paul@126 | 44 | |
paul@126 | 45 | /* One of... */ |
paul@126 | 46 | union |
paul@126 | 47 | { |
paul@126 | 48 | __obj * value; /* attribute value */ |
paul@126 | 49 | const __ptable * ptable;/* parameter table */ |
paul@126 | 50 | struct __attr (*fn)(); /* callable details */ |
paul@136 | 51 | |
paul@136 | 52 | int intvalue; /* integer value */ |
paul@136 | 53 | double floatvalue; /* floating point value */ |
paul@136 | 54 | char * strvalue; /* string value */ |
paul@126 | 55 | }; |
paul@126 | 56 | } __attr; |
paul@126 | 57 | |
paul@126 | 58 | typedef struct __obj |
paul@126 | 59 | { |
paul@126 | 60 | const __table * table; /* attribute table */ |
paul@126 | 61 | unsigned int pos; /* position of attribute indicating class */ |
paul@126 | 62 | __attr attrs[]; /* attributes */ |
paul@126 | 63 | } __obj; |
paul@126 | 64 | |
paul@126 | 65 | typedef __obj * __ref; |
paul@126 | 66 | |
paul@126 | 67 | /* Special instance position value. The pos member of __obj refers to the |
paul@143 | 68 | special type attribute for classes, indicating which position holds the |
paul@143 | 69 | attribute describing the class type. For instances, it is set to zero. */ |
paul@126 | 70 | |
paul@126 | 71 | #define __INSTANCEPOS 0 |
paul@126 | 72 | |
paul@143 | 73 | /* Special null value. */ |
paul@143 | 74 | |
paul@143 | 75 | #define __NULL ((__attr) {0, 0}) |
paul@143 | 76 | |
paul@126 | 77 | /* Function pointer type. */ |
paul@126 | 78 | |
paul@126 | 79 | typedef __attr (*__func)(); |
paul@126 | 80 | |
paul@126 | 81 | /* Convenience macros. */ |
paul@126 | 82 | |
paul@126 | 83 | #define __ARGS(...) ((__attr[]) {__VA_ARGS__}) |
paul@126 | 84 | #define __KWARGS(...) ((__param[]) {__VA_ARGS__}) |
paul@126 | 85 | |
paul@126 | 86 | #endif /* __TYPES_H__ */ |