1 /* Runtime types. 2 3 Copyright (C) 2015, 2016 Paul Boddie <paul@boddie.org.uk> 4 5 This program is free software; you can redistribute it and/or modify it under 6 the terms of the GNU General Public License as published by the Free Software 7 Foundation; either version 3 of the License, or (at your option) any later 8 version. 9 10 This program is distributed in the hope that it will be useful, but WITHOUT 11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 12 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 13 details. 14 15 You should have received a copy of the GNU General Public License along with 16 this program. If not, see <http://www.gnu.org/licenses/>. 17 */ 18 19 #ifndef __TYPES_H__ 20 #define __TYPES_H__ 21 22 /* Attribute tables are lists of codes confirming the presence of attributes. */ 23 24 typedef struct __table 25 { 26 const unsigned int size, attrs[]; 27 } __table; 28 29 /* Parameter tables are lists of codes confirming the presence of parameters, as 30 well as the positions of those parameters in the list for a given function. 31 */ 32 33 typedef struct __param 34 { 35 unsigned short code, pos; 36 } __param; 37 38 typedef struct __ptable 39 { 40 const unsigned int size; 41 const __param params[]; 42 } __ptable; 43 44 /* Attributes are context and value pairs. 45 Objects are collections of attributes. 46 Object references are references to tables and collections of attributes. 47 Attribute references are references to single attributes. */ 48 49 typedef struct __obj __obj; 50 typedef struct __fragment __fragment; 51 52 typedef struct __attr 53 { 54 /* One of... */ 55 union 56 { 57 __obj * context; /* attribute context */ 58 unsigned int min; /* minimum number of parameters */ 59 __obj * b; /* bound callable object */ 60 }; 61 62 /* One of... */ 63 union 64 { 65 __obj * value; /* attribute value */ 66 const __ptable * ptable;/* parameter table */ 67 struct __attr (*fn)(); /* callable details */ 68 69 int intvalue; /* integer value */ 70 double floatvalue; /* floating point value */ 71 char * strvalue; /* string value */ 72 __fragment * seqvalue; /* sequence data */ 73 void * datavalue; /* object-specific data */ 74 }; 75 } __attr; 76 77 typedef struct __obj 78 { 79 const __table * table; /* attribute table */ 80 unsigned int pos; /* position of attribute indicating class */ 81 __attr attrs[]; /* attributes */ 82 } __obj; 83 84 typedef __obj * __ref; 85 86 /* Fragments are simple collections of attributes employed by sequence types. 87 They provide the basis of lists and tuples. */ 88 89 typedef struct __fragment 90 { 91 unsigned int size, capacity; 92 __attr attrs[]; 93 } __fragment; 94 95 #define __FRAGMENT_SIZE(NUMBER) (NUMBER * sizeof(__attr) + 2 * sizeof(unsigned int)) 96 97 /* Special instance position value. The pos member of __obj refers to the 98 special type attribute for classes, indicating which position holds the 99 attribute describing the class type. For instances, it is set to zero. */ 100 101 #define __INSTANCEPOS 0 102 103 /* Special null value. */ 104 105 #define __NULL ((__attr) {0, 0}) 106 107 /* Function pointer type. */ 108 109 typedef __attr (*__func)(); 110 111 /* Convenience macros. */ 112 113 #define __ARGS(...) ((__attr[]) {__VA_ARGS__}) 114 #define __KWARGS(...) ((__param[]) {__VA_ARGS__}) 115 116 #endif /* __TYPES_H__ */