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 typedef struct __mapping __mapping; 36 37 typedef struct __attr 38 { 39 /* One of... */ 40 union 41 { 42 __obj * context; /* attribute context */ 43 unsigned int min; /* minimum number of parameters */ 44 __obj * b; /* bound callable object */ 45 }; 46 47 /* One of... */ 48 union 49 { 50 __obj * value; /* attribute value */ 51 const __ptable * ptable;/* parameter table */ 52 struct __attr (*fn)(); /* callable details */ 53 54 int intvalue; /* integer value */ 55 double floatvalue; /* floating point value */ 56 char * strvalue; /* string value */ 57 __fragment * seqvalue; /* sequence data */ 58 __mapping * mapvalue; /* mapping data */ 59 }; 60 } __attr; 61 62 typedef struct __obj 63 { 64 const __table * table; /* attribute table */ 65 unsigned int pos; /* position of attribute indicating class */ 66 __attr attrs[]; /* attributes */ 67 } __obj; 68 69 typedef __obj * __ref; 70 71 /* Fragments are simple collections of attributes employed by sequence types. 72 They provide the basis of lists and tuples. */ 73 74 typedef struct __fragment 75 { 76 unsigned int size, capacity; 77 __attr attrs[]; 78 } __fragment; 79 80 #define __FRAGMENT_SIZE(NUMBER) (NUMBER * sizeof(__attr) + 2 * sizeof(unsigned int)) 81 82 /* Mappings are simple collections of fragment references used to hold the 83 "buckets" used in hash tables. Here, separate lists of keys and values hold 84 attributes referring to the actual keys and corresponding values. */ 85 86 #define __MAPPING_BUCKETS 10 87 88 typedef struct __mapping 89 { 90 __fragment *keys[__MAPPING_BUCKETS]; 91 __fragment *values[__MAPPING_BUCKETS]; 92 } __mapping; 93 94 #define __MAPPING_SIZE(NUMBER) (2 * NUMBER * sizeof(__fragment *) + sizeof(unsigned int)) 95 96 /* Special instance position value. The pos member of __obj refers to the 97 special type attribute for classes, indicating which position holds the 98 attribute describing the class type. For instances, it is set to zero. */ 99 100 #define __INSTANCEPOS 0 101 102 /* Special null value. */ 103 104 #define __NULL ((__attr) {0, 0}) 105 106 /* Function pointer type. */ 107 108 typedef __attr (*__func)(); 109 110 /* Convenience macros. */ 111 112 #define __ARGS(...) ((__attr[]) {__VA_ARGS__}) 113 #define __KWARGS(...) ((__param[]) {__VA_ARGS__}) 114 115 #endif /* __TYPES_H__ */