1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/templates/types.h Mon Oct 24 21:18:10 2016 +0200
1.3 @@ -0,0 +1,77 @@
1.4 +/* Runtime types. */
1.5 +
1.6 +#ifndef __TYPES_H__
1.7 +#define __TYPES_H__
1.8 +
1.9 +/* Attribute tables are lists of codes confirming the presence of attributes. */
1.10 +
1.11 +typedef struct __table
1.12 +{
1.13 + const unsigned int size, attrs[];
1.14 +} __table;
1.15 +
1.16 +/* Parameter tables are lists of codes confirming the presence of parameters, as
1.17 + well as the positions of those parameters in the list for a given function.
1.18 +*/
1.19 +
1.20 +typedef struct __param
1.21 +{
1.22 + unsigned short code, pos;
1.23 +} __param;
1.24 +
1.25 +typedef struct __ptable
1.26 +{
1.27 + const unsigned int size;
1.28 + const __param params[];
1.29 +} __ptable;
1.30 +
1.31 +/* Attributes are context and value pairs.
1.32 + Objects are collections of attributes.
1.33 + Object references are references to tables and collections of attributes.
1.34 + Attribute references are references to single attributes. */
1.35 +
1.36 +typedef struct __obj __obj;
1.37 +
1.38 +typedef struct __attr
1.39 +{
1.40 + /* One of... */
1.41 + union
1.42 + {
1.43 + __obj * context; /* attribute context */
1.44 + unsigned int min; /* minimum number of parameters */
1.45 + __obj * b; /* bound callable object */
1.46 + };
1.47 +
1.48 + /* One of... */
1.49 + union
1.50 + {
1.51 + __obj * value; /* attribute value */
1.52 + const __ptable * ptable;/* parameter table */
1.53 + struct __attr (*fn)(); /* callable details */
1.54 + };
1.55 +} __attr;
1.56 +
1.57 +typedef struct __obj
1.58 +{
1.59 + const __table * table; /* attribute table */
1.60 + unsigned int pos; /* position of attribute indicating class */
1.61 + __attr attrs[]; /* attributes */
1.62 +} __obj;
1.63 +
1.64 +typedef __obj * __ref;
1.65 +
1.66 +/* Special instance position value. The pos member of __obj refers to the
1.67 + special type attribute for classes. For instances, it is set to zero. */
1.68 +
1.69 +#define __INSTANCEPOS 0
1.70 +
1.71 +/* Function pointer type. */
1.72 +
1.73 +typedef __attr (*__func)();
1.74 +
1.75 +/* Convenience macros. */
1.76 +
1.77 +#define __ARGS(...) ((__attr[]) {__VA_ARGS__})
1.78 +#define __KWARGS(...) ((__param[]) {__VA_ARGS__})
1.79 +
1.80 +#endif /* __TYPES_H__ */