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 typedef struct __mapping 87 { 88 unsigned int size, capacity; 89 __fragment **keys; /* array of key arrays */ 90 __fragment **values; /* array of value arrays */ 91 } __mapping; 92 93 #define __MAPPING_SIZE(NUMBER) (2 * NUMBER * sizeof(__fragment *) + 2 * sizeof(unsigned int)) 94 95 /* Special instance position value. The pos member of __obj refers to the 96 special type attribute for classes, indicating which position holds the 97 attribute describing the class type. For instances, it is set to zero. */ 98 99 #define __INSTANCEPOS 0 100 101 /* Special null value. */ 102 103 #define __NULL ((__attr) {0, 0}) 104 105 /* Function pointer type. */ 106 107 typedef __attr (*__func)(); 108 109 /* Convenience macros. */ 110 111 #define __ARGS(...) ((__attr[]) {__VA_ARGS__}) 112 #define __KWARGS(...) ((__param[]) {__VA_ARGS__}) 113 114 #endif /* __TYPES_H__ */