paul@353 | 1 | /* Common operations. |
paul@353 | 2 | |
paul@523 | 3 | Copyright (C) 2015, 2016, 2017 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 __OPS_H__ |
paul@126 | 20 | #define __OPS_H__ |
paul@126 | 21 | |
paul@126 | 22 | #include "types.h" |
paul@148 | 23 | #include <string.h> /* for __COPY */ |
paul@126 | 24 | |
paul@126 | 25 | /* Direct access and manipulation of static objects. */ |
paul@126 | 26 | |
paul@200 | 27 | __attr __load_static(__ref parent, __ref obj); |
paul@126 | 28 | |
paul@126 | 29 | /* Direct retrieval operations, returning attributes. */ |
paul@126 | 30 | |
paul@126 | 31 | __attr __load_via_class(__ref obj, int pos); |
paul@126 | 32 | __attr __load_via_object(__ref obj, int pos); |
paul@153 | 33 | __attr __get_class_and_load(__ref obj, int pos); |
paul@126 | 34 | |
paul@126 | 35 | /* Direct storage operations. */ |
paul@126 | 36 | |
paul@126 | 37 | int __store_via_object(__ref obj, int pos, __attr value); |
paul@252 | 38 | int __get_class_and_store(__ref obj, int pos, __attr value); |
paul@126 | 39 | |
paul@126 | 40 | /* Introspection. */ |
paul@126 | 41 | |
paul@126 | 42 | int __is_instance(__ref obj); |
paul@274 | 43 | int __is_type_instance(__ref obj); |
paul@126 | 44 | __ref __get_class(__ref obj); |
paul@231 | 45 | __attr __get_class_attr(__ref obj); |
paul@126 | 46 | |
paul@126 | 47 | /* Attribute testing operations. */ |
paul@126 | 48 | |
paul@237 | 49 | __ref __test_specific_instance(__ref obj, __ref type); |
paul@237 | 50 | __ref __test_specific_object(__ref obj, __ref type); |
paul@237 | 51 | __ref __test_specific_type(__ref obj, __ref type); |
paul@144 | 52 | __ref __test_common_instance(__ref obj, int pos, int code); |
paul@144 | 53 | __ref __test_common_object(__ref obj, int pos, int code); |
paul@144 | 54 | __ref __test_common_type(__ref obj, int pos, int code); |
paul@126 | 55 | |
paul@126 | 56 | /* Attribute testing and retrieval operations. */ |
paul@126 | 57 | |
paul@126 | 58 | __attr __check_and_load_via_class(__ref obj, int pos, int code); |
paul@126 | 59 | __attr __check_and_load_via_object(__ref obj, int pos, int code); |
paul@487 | 60 | __attr __check_and_load_via_object_null(__ref obj, int pos, int code); |
paul@126 | 61 | __attr __check_and_load_via_any(__ref obj, int pos, int code); |
paul@126 | 62 | |
paul@126 | 63 | /* Attribute testing and storage operations. */ |
paul@126 | 64 | |
paul@252 | 65 | int __check_and_store_via_class(__ref obj, int pos, int code, __attr value); |
paul@126 | 66 | int __check_and_store_via_object(__ref obj, int pos, int code, __attr value); |
paul@126 | 67 | int __check_and_store_via_any(__ref obj, int pos, int code, __attr value); |
paul@126 | 68 | |
paul@126 | 69 | /* Context-related operations. */ |
paul@126 | 70 | |
paul@126 | 71 | __attr __test_context(__ref context, __attr attr); |
paul@126 | 72 | __attr __update_context(__ref context, __attr attr); |
paul@126 | 73 | |
paul@126 | 74 | #define __set_context(__ATTR) (__tmp_context = (__ATTR).value) |
paul@126 | 75 | #define __set_accessor(__ATTR) (__tmp_value = (__ATTR).value) |
paul@368 | 76 | #define __set_target_accessor(__ATTR) (__tmp_target_value = (__ATTR).value) |
paul@126 | 77 | |
paul@523 | 78 | /* Context testing for invocations. */ |
paul@523 | 79 | |
paul@523 | 80 | __attr (*__get_function(__attr attr))(__attr[]); |
paul@523 | 81 | __attr (*__check_and_get_function(__attr attr))(__attr[]); |
paul@523 | 82 | |
paul@126 | 83 | /* Basic structure tests. */ |
paul@126 | 84 | |
paul@126 | 85 | int __WITHIN(__ref obj, int pos); |
paul@126 | 86 | int __HASATTR(__ref obj, int pos, int code); |
paul@126 | 87 | |
paul@126 | 88 | /* Parameter position operations. */ |
paul@126 | 89 | |
paul@126 | 90 | int __HASPARAM(const __ptable *ptable, int ppos, int pcode); |
paul@126 | 91 | |
paul@126 | 92 | /* Conversions. */ |
paul@126 | 93 | |
paul@126 | 94 | __attr __CONTEXT_AS_VALUE(__attr attr); |
paul@126 | 95 | |
paul@126 | 96 | /* Type testing. */ |
paul@126 | 97 | |
paul@144 | 98 | __ref __ISFUNC(__ref obj); |
paul@126 | 99 | int __ISNULL(__attr value); |
paul@126 | 100 | |
paul@126 | 101 | /* __TEST(obj, __A) -> test obj for the special type attribute __A */ |
paul@126 | 102 | |
paul@126 | 103 | #define __TEST(__OBJ, __TYPE) (__test_common_instance(__OBJ, __pos_##__TYPE, __code_##__TYPE)) |
paul@126 | 104 | |
paul@126 | 105 | /* Attribute codes and positions for type objects. */ |
paul@126 | 106 | |
paul@126 | 107 | unsigned int __TYPECODE(__ref obj); |
paul@126 | 108 | unsigned int __TYPEPOS(__ref obj); |
paul@126 | 109 | |
paul@126 | 110 | /* Attribute codes and positions for attribute names. */ |
paul@126 | 111 | |
paul@126 | 112 | #define __ATTRCODE(__ATTRNAME) (__code_##__ATTRNAME) |
paul@126 | 113 | #define __ATTRPOS(__ATTRNAME) (__pos_##__ATTRNAME) |
paul@126 | 114 | |
paul@260 | 115 | /* Memory allocation. */ |
paul@260 | 116 | |
paul@260 | 117 | void *__ALLOCATE(size_t nmemb, size_t size); |
paul@260 | 118 | void *__REALLOCATE(void *ptr, size_t size); |
paul@260 | 119 | |
paul@148 | 120 | /* Copying of structures. */ |
paul@148 | 121 | |
paul@151 | 122 | __ref __COPY(__ref obj, int size); |
paul@148 | 123 | |
paul@126 | 124 | #endif /* __OPS_H__ */ |