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