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@577 | 27 | __attr __load_static_ignore(__ref obj); |
paul@577 | 28 | __attr __load_static_replace(__ref context, __ref obj); |
paul@577 | 29 | __attr __load_static_test(__ref context, __ref obj); |
paul@126 | 30 | |
paul@126 | 31 | /* Direct retrieval operations, returning attributes. */ |
paul@126 | 32 | |
paul@624 | 33 | __attr __load_via_class__(__ref obj, int pos); |
paul@624 | 34 | __attr __load_via_object__(__ref obj, int pos); |
paul@624 | 35 | __attr __get_class_and_load__(__ref obj, int pos); |
paul@624 | 36 | |
paul@624 | 37 | #define __load_via_class(OBJ, ATTRNAME) (__load_via_class__(OBJ, __ATTRPOS(ATTRNAME))) |
paul@624 | 38 | #define __load_via_object(OBJ, ATTRNAME) (__load_via_object__(OBJ, __ATTRPOS(ATTRNAME))) |
paul@624 | 39 | #define __get_class_and_load(OBJ, ATTRNAME) (__get_class_and_load__(OBJ, __ATTRPOS(ATTRNAME))) |
paul@126 | 40 | |
paul@126 | 41 | /* Direct storage operations. */ |
paul@126 | 42 | |
paul@624 | 43 | int __store_via_object__(__ref obj, int pos, __attr value); |
paul@624 | 44 | int __get_class_and_store__(__ref obj, int pos, __attr value); |
paul@624 | 45 | |
paul@624 | 46 | #define __store_via_object(OBJ, ATTRNAME, VALUE) (__store_via_object__(OBJ, __ATTRPOS(ATTRNAME), VALUE)) |
paul@624 | 47 | #define __get_class_and_store(OBJ, ATTRNAME, VALUE) (__get_class_and_store__(OBJ, __ATTRPOS(ATTRNAME), VALUE)) |
paul@126 | 48 | |
paul@126 | 49 | /* Introspection. */ |
paul@126 | 50 | |
paul@126 | 51 | int __is_instance(__ref obj); |
paul@655 | 52 | int __is_subclass(__ref obj, __attr cls); |
paul@655 | 53 | int __is_instance_subclass(__ref obj, __attr cls); |
paul@274 | 54 | int __is_type_instance(__ref obj); |
paul@126 | 55 | __ref __get_class(__ref obj); |
paul@231 | 56 | __attr __get_class_attr(__ref obj); |
paul@126 | 57 | |
paul@126 | 58 | /* Attribute testing operations. */ |
paul@126 | 59 | |
paul@237 | 60 | __ref __test_specific_instance(__ref obj, __ref type); |
paul@237 | 61 | __ref __test_specific_object(__ref obj, __ref type); |
paul@237 | 62 | __ref __test_specific_type(__ref obj, __ref type); |
paul@624 | 63 | |
paul@624 | 64 | __ref __test_common_instance__(__ref obj, int pos, int code); |
paul@624 | 65 | __ref __test_common_object__(__ref obj, int pos, int code); |
paul@624 | 66 | __ref __test_common_type__(__ref obj, int pos, int code); |
paul@624 | 67 | |
paul@624 | 68 | #define __test_common_instance(OBJ, TYPENAME) (__test_common_instance__(OBJ, __ATTRPOS(TYPENAME), __ATTRCODE(TYPENAME))) |
paul@624 | 69 | #define __test_common_object(OBJ, TYPENAME) (__test_common_object__(OBJ, __ATTRPOS(TYPENAME), __ATTRCODE(TYPENAME))) |
paul@624 | 70 | #define __test_common_type(OBJ, TYPENAME) (__test_common_type__(OBJ, __ATTRPOS(TYPENAME), __ATTRCODE(TYPENAME))) |
paul@126 | 71 | |
paul@126 | 72 | /* Attribute testing and retrieval operations. */ |
paul@126 | 73 | |
paul@487 | 74 | __attr __check_and_load_via_object_null(__ref obj, int pos, int code); |
paul@624 | 75 | |
paul@624 | 76 | __attr __check_and_load_via_class__(__ref obj, int pos, int code); |
paul@624 | 77 | __attr __check_and_load_via_object__(__ref obj, int pos, int code); |
paul@624 | 78 | __attr __check_and_load_via_any__(__ref obj, int pos, int code); |
paul@624 | 79 | |
paul@624 | 80 | #define __check_and_load_via_class(OBJ, ATTRNAME) (__check_and_load_via_class__(OBJ, __ATTRPOS(ATTRNAME), __ATTRCODE(ATTRNAME))) |
paul@624 | 81 | #define __check_and_load_via_object(OBJ, ATTRNAME) (__check_and_load_via_object__(OBJ, __ATTRPOS(ATTRNAME), __ATTRCODE(ATTRNAME))) |
paul@624 | 82 | #define __check_and_load_via_any(OBJ, ATTRNAME) (__check_and_load_via_any__(OBJ, __ATTRPOS(ATTRNAME), __ATTRCODE(ATTRNAME))) |
paul@126 | 83 | |
paul@126 | 84 | /* Attribute testing and storage operations. */ |
paul@126 | 85 | |
paul@624 | 86 | int __check_and_store_via_class__(__ref obj, int pos, int code, __attr value); |
paul@624 | 87 | int __check_and_store_via_object__(__ref obj, int pos, int code, __attr value); |
paul@624 | 88 | int __check_and_store_via_any__(__ref obj, int pos, int code, __attr value); |
paul@624 | 89 | |
paul@624 | 90 | #define __check_and_store_via_class(OBJ, ATTRNAME, VALUE) (__check_and_store_via_class__(OBJ, __ATTRPOS(ATTRNAME), __ATTRCODE(ATTRNAME), VALUE)) |
paul@624 | 91 | #define __check_and_store_via_object(OBJ, ATTRNAME, VALUE) (__check_and_store_via_object__(OBJ, __ATTRPOS(ATTRNAME), __ATTRCODE(ATTRNAME), VALUE)) |
paul@624 | 92 | #define __check_and_store_via_any(OBJ, ATTRNAME, VALUE) (__check_and_store_via_any__(OBJ, __ATTRPOS(ATTRNAME), __ATTRCODE(ATTRNAME), VALUE)) |
paul@126 | 93 | |
paul@126 | 94 | /* Context-related operations. */ |
paul@126 | 95 | |
paul@594 | 96 | int __test_context_update(__ref context, __attr attr); |
paul@126 | 97 | __attr __test_context(__ref context, __attr attr); |
paul@126 | 98 | __attr __update_context(__ref context, __attr attr); |
paul@602 | 99 | __attr __test_context_revert(int target, __ref context, __attr attr, __ref contexts[]); |
paul@602 | 100 | __attr __test_context_static(int target, __ref context, __ref value, __ref contexts[]); |
paul@595 | 101 | |
paul@591 | 102 | #define __get_context(__TARGET) (__tmp_contexts[__TARGET]) |
paul@591 | 103 | #define __set_context(__TARGET, __ATTR) (__tmp_contexts[__TARGET] = (__ATTR).value) |
paul@592 | 104 | #define __set_private_context(__ATTR) (__tmp_private_context = (__ATTR).value) |
paul@126 | 105 | #define __set_accessor(__ATTR) (__tmp_value = (__ATTR).value) |
paul@368 | 106 | #define __set_target_accessor(__ATTR) (__tmp_target_value = (__ATTR).value) |
paul@126 | 107 | |
paul@523 | 108 | /* Context testing for invocations. */ |
paul@523 | 109 | |
paul@577 | 110 | __attr __unwrap_callable(__attr callable); |
paul@746 | 111 | __attr (*__get_function_unchecked(__attr target))(__attr[]); |
paul@577 | 112 | __attr (*__get_function(__ref context, __attr target))(__attr[]); |
paul@577 | 113 | __attr (*__check_and_get_function(__ref context, __attr target))(__attr[]); |
paul@523 | 114 | |
paul@126 | 115 | /* Parameter position operations. */ |
paul@126 | 116 | |
paul@126 | 117 | int __HASPARAM(const __ptable *ptable, int ppos, int pcode); |
paul@126 | 118 | |
paul@126 | 119 | /* Conversions. */ |
paul@126 | 120 | |
paul@126 | 121 | __attr __CONTEXT_AS_VALUE(__attr attr); |
paul@126 | 122 | |
paul@126 | 123 | /* Type testing. */ |
paul@126 | 124 | |
paul@144 | 125 | __ref __ISFUNC(__ref obj); |
paul@126 | 126 | int __ISNULL(__attr value); |
paul@126 | 127 | |
paul@126 | 128 | /* Attribute codes and positions for type objects. */ |
paul@126 | 129 | |
paul@126 | 130 | unsigned int __TYPECODE(__ref obj); |
paul@126 | 131 | unsigned int __TYPEPOS(__ref obj); |
paul@126 | 132 | |
paul@260 | 133 | /* Memory allocation. */ |
paul@260 | 134 | |
paul@260 | 135 | void *__ALLOCATE(size_t nmemb, size_t size); |
paul@260 | 136 | void *__REALLOCATE(void *ptr, size_t size); |
paul@260 | 137 | |
paul@148 | 138 | /* Copying of structures. */ |
paul@148 | 139 | |
paul@151 | 140 | __ref __COPY(__ref obj, int size); |
paul@148 | 141 | |
paul@126 | 142 | #endif /* __OPS_H__ */ |