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@159 | 34 | typedef struct __fragment __fragment; |
paul@126 | 35 | |
paul@126 | 36 | typedef struct __attr |
paul@126 | 37 | { |
paul@126 | 38 | /* One of... */ |
paul@126 | 39 | union |
paul@126 | 40 | { |
paul@126 | 41 | __obj * context; /* attribute context */ |
paul@126 | 42 | unsigned int min; /* minimum number of parameters */ |
paul@126 | 43 | __obj * b; /* bound callable object */ |
paul@126 | 44 | }; |
paul@126 | 45 | |
paul@126 | 46 | /* One of... */ |
paul@126 | 47 | union |
paul@126 | 48 | { |
paul@126 | 49 | __obj * value; /* attribute value */ |
paul@126 | 50 | const __ptable * ptable;/* parameter table */ |
paul@126 | 51 | struct __attr (*fn)(); /* callable details */ |
paul@136 | 52 | |
paul@159 | 53 | int intvalue; /* integer value */ |
paul@159 | 54 | double floatvalue; /* floating point value */ |
paul@159 | 55 | char * strvalue; /* string value */ |
paul@280 | 56 | __fragment * seqvalue; /* sequence data */ |
paul@126 | 57 | }; |
paul@126 | 58 | } __attr; |
paul@126 | 59 | |
paul@126 | 60 | typedef struct __obj |
paul@126 | 61 | { |
paul@126 | 62 | const __table * table; /* attribute table */ |
paul@126 | 63 | unsigned int pos; /* position of attribute indicating class */ |
paul@126 | 64 | __attr attrs[]; /* attributes */ |
paul@126 | 65 | } __obj; |
paul@126 | 66 | |
paul@126 | 67 | typedef __obj * __ref; |
paul@126 | 68 | |
paul@280 | 69 | /* Fragments are simple collections of attributes employed by sequence types. |
paul@280 | 70 | They provide the basis of lists and tuples. */ |
paul@159 | 71 | |
paul@159 | 72 | typedef struct __fragment |
paul@159 | 73 | { |
paul@206 | 74 | unsigned int size, capacity; |
paul@159 | 75 | __attr attrs[]; |
paul@159 | 76 | } __fragment; |
paul@159 | 77 | |
paul@206 | 78 | #define __FRAGMENT_SIZE(NUMBER) (NUMBER * sizeof(__attr) + 2 * sizeof(unsigned int)) |
paul@206 | 79 | |
paul@126 | 80 | /* Special instance position value. The pos member of __obj refers to the |
paul@143 | 81 | special type attribute for classes, indicating which position holds the |
paul@143 | 82 | attribute describing the class type. For instances, it is set to zero. */ |
paul@126 | 83 | |
paul@126 | 84 | #define __INSTANCEPOS 0 |
paul@126 | 85 | |
paul@143 | 86 | /* Special null value. */ |
paul@143 | 87 | |
paul@143 | 88 | #define __NULL ((__attr) {0, 0}) |
paul@143 | 89 | |
paul@126 | 90 | /* Function pointer type. */ |
paul@126 | 91 | |
paul@126 | 92 | typedef __attr (*__func)(); |
paul@126 | 93 | |
paul@126 | 94 | /* Convenience macros. */ |
paul@126 | 95 | |
paul@126 | 96 | #define __ARGS(...) ((__attr[]) {__VA_ARGS__}) |
paul@126 | 97 | #define __KWARGS(...) ((__param[]) {__VA_ARGS__}) |
paul@126 | 98 | |
paul@126 | 99 | #endif /* __TYPES_H__ */ |