Lichen

templates/ops.h

286:ea96958037c6
2016-11-30 Paul Boddie Implemented the zip function.
     1 /* Common operations. */     2      3 #ifndef __OPS_H__     4 #define __OPS_H__     5      6 #include "types.h"     7 #include <string.h> /* for __COPY */     8      9 /* Direct access and manipulation of static objects. */    10     11 __attr __load_static(__ref parent, __ref obj);    12     13 /* Direct retrieval operations, returning attributes. */    14     15 __attr __load_via_class(__ref obj, int pos);    16 __attr __load_via_object(__ref obj, int pos);    17 __attr __get_class_and_load(__ref obj, int pos);    18     19 /* Direct storage operations. */    20     21 int __store_via_object(__ref obj, int pos, __attr value);    22 int __get_class_and_store(__ref obj, int pos, __attr value);    23     24 /* Introspection. */    25     26 int __is_instance(__ref obj);    27 int __is_type_instance(__ref obj);    28 __ref __get_class(__ref obj);    29 __attr __get_class_attr(__ref obj);    30     31 /* Attribute testing operations. */    32     33 __ref __test_specific_instance(__ref obj, __ref type);    34 __ref __test_specific_object(__ref obj, __ref type);    35 __ref __test_specific_type(__ref obj, __ref type);    36 __ref __test_common_instance(__ref obj, int pos, int code);    37 __ref __test_common_object(__ref obj, int pos, int code);    38 __ref __test_common_type(__ref obj, int pos, int code);    39     40 /* Attribute testing and retrieval operations. */    41     42 __attr __check_and_load_via_class(__ref obj, int pos, int code);    43 __attr __check_and_load_via_object(__ref obj, int pos, int code);    44 __attr __check_and_load_via_any(__ref obj, int pos, int code);    45     46 /* Attribute testing and storage operations. */    47     48 int __check_and_store_via_class(__ref obj, int pos, int code, __attr value);    49 int __check_and_store_via_object(__ref obj, int pos, int code, __attr value);    50 int __check_and_store_via_any(__ref obj, int pos, int code, __attr value);    51     52 /* Context-related operations. */    53     54 __attr __test_context(__ref context, __attr attr);    55 __attr __replace_context(__ref context, __attr attr);    56 __attr __update_context(__ref context, __attr attr);    57     58 #define __set_context(__ATTR) (__tmp_context = (__ATTR).value)    59 #define __set_accessor(__ATTR) (__tmp_value = (__ATTR).value)    60     61 /* Basic structure tests. */    62     63 int __WITHIN(__ref obj, int pos);    64 int __HASATTR(__ref obj, int pos, int code);    65     66 /* Parameter position operations. */    67     68 int __HASPARAM(const __ptable *ptable, int ppos, int pcode);    69     70 /* Conversions. */    71     72 __attr __CONTEXT_AS_VALUE(__attr attr);    73     74 /* Type testing. */    75     76 __ref __ISFUNC(__ref obj);    77 int __ISNULL(__attr value);    78     79 /* __TEST(obj, __A) -> test obj for the special type attribute __A */    80     81 #define __TEST(__OBJ, __TYPE) (__test_common_instance(__OBJ, __pos_##__TYPE, __code_##__TYPE))    82     83 /* Attribute codes and positions for type objects. */    84     85 unsigned int __TYPECODE(__ref obj);    86 unsigned int __TYPEPOS(__ref obj);    87     88 /* Attribute codes and positions for attribute names. */    89     90 #define __ATTRCODE(__ATTRNAME) (__code_##__ATTRNAME)    91 #define __ATTRPOS(__ATTRNAME) (__pos_##__ATTRNAME)    92     93 /* Memory allocation. */    94     95 void *__ALLOCATE(size_t nmemb, size_t size);    96 void *__REALLOCATE(void *ptr, size_t size);    97     98 /* Copying of structures. */    99    100 __ref __COPY(__ref obj, int size);   101    102 #endif /* __OPS_H__ */