Lichen

templates/types.h

231:72b93c7c757a
2016-11-24 Paul Boddie Added issubclass and improved isinstance, also introducing various native functions and operations.
     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     36 typedef struct __attr    37 {    38     /* One of... */    39     union    40     {    41         __obj * context;        /* attribute context */    42         unsigned int min;       /* minimum number of parameters */    43         __obj * b;              /* bound callable object */    44     };    45     46     /* One of... */    47     union    48     {    49         __obj * value;          /* attribute value */    50         const __ptable * ptable;/* parameter table */    51         struct __attr (*fn)();  /* callable details */    52     53         int intvalue;           /* integer value */    54         double floatvalue;      /* floating point value */    55         char * strvalue;        /* string value */    56         __fragment * data;      /* sequence data */    57     };    58 } __attr;    59     60 typedef struct __obj    61 {    62     const __table * table;      /* attribute table */    63     unsigned int pos;           /* position of attribute indicating class */    64     __attr attrs[];             /* attributes */    65 } __obj;    66     67 typedef __obj * __ref;    68     69 /* Fragments are simple collections of attributes employed by sequence types. */    70     71 typedef struct __fragment    72 {    73     unsigned int size, capacity;    74     __attr attrs[];    75 } __fragment;    76     77 #define __FRAGMENT_SIZE(NUMBER) (NUMBER * sizeof(__attr) + 2 * sizeof(unsigned int))    78     79 /* Special instance position value. The pos member of __obj refers to the    80    special type attribute for classes, indicating which position holds the    81    attribute describing the class type. For instances, it is set to zero. */    82     83 #define __INSTANCEPOS 0    84     85 /* Special null value. */    86     87 #define __NULL ((__attr) {0, 0})    88     89 /* Function pointer type. */    90     91 typedef __attr (*__func)();    92     93 /* Convenience macros. */    94     95 #define __ARGS(...) ((__attr[]) {__VA_ARGS__})    96 #define __KWARGS(...) ((__param[]) {__VA_ARGS__})    97     98 #endif /* __TYPES_H__ */