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