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