1 /* Common operations. 2 3 Copyright (C) 2015, 2016, 2017 Paul Boddie <paul@boddie.org.uk> 4 5 This program is free software; you can redistribute it and/or modify it under 6 the terms of the GNU General Public License as published by the Free Software 7 Foundation; either version 3 of the License, or (at your option) any later 8 version. 9 10 This program is distributed in the hope that it will be useful, but WITHOUT 11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 12 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 13 details. 14 15 You should have received a copy of the GNU General Public License along with 16 this program. If not, see <http://www.gnu.org/licenses/>. 17 */ 18 19 #ifndef __OPS_H__ 20 #define __OPS_H__ 21 22 #include "types.h" 23 #include <string.h> /* for __COPY */ 24 25 /* Direct access and manipulation of static objects. */ 26 27 __attr __load_static_ignore(__ref obj); 28 __attr __load_static_replace(__ref context, __ref obj); 29 __attr __load_static_test(__ref context, __ref obj); 30 31 /* Direct retrieval operations, returning attributes. */ 32 33 __attr __load_via_class(__ref obj, int pos); 34 __attr __load_via_object(__ref obj, int pos); 35 __attr __get_class_and_load(__ref obj, int pos); 36 37 /* Direct storage operations. */ 38 39 int __store_via_object(__ref obj, int pos, __attr value); 40 int __get_class_and_store(__ref obj, int pos, __attr value); 41 42 /* Introspection. */ 43 44 int __is_instance(__ref obj); 45 int __is_type_instance(__ref obj); 46 __ref __get_class(__ref obj); 47 __attr __get_class_attr(__ref obj); 48 49 /* Attribute testing operations. */ 50 51 __ref __test_specific_instance(__ref obj, __ref type); 52 __ref __test_specific_object(__ref obj, __ref type); 53 __ref __test_specific_type(__ref obj, __ref type); 54 __ref __test_common_instance(__ref obj, int pos, int code); 55 __ref __test_common_object(__ref obj, int pos, int code); 56 __ref __test_common_type(__ref obj, int pos, int code); 57 58 /* Attribute testing and retrieval operations. */ 59 60 __attr __check_and_load_via_class(__ref obj, int pos, int code); 61 __attr __check_and_load_via_object(__ref obj, int pos, int code); 62 __attr __check_and_load_via_object_null(__ref obj, int pos, int code); 63 __attr __check_and_load_via_any(__ref obj, int pos, int code); 64 65 /* Attribute testing and storage operations. */ 66 67 int __check_and_store_via_class(__ref obj, int pos, int code, __attr value); 68 int __check_and_store_via_object(__ref obj, int pos, int code, __attr value); 69 int __check_and_store_via_any(__ref obj, int pos, int code, __attr value); 70 71 /* Context-related operations. */ 72 73 __attr __test_context(__ref context, __attr attr); 74 __attr __update_context(__ref context, __attr attr); 75 76 #define __set_context(__ATTR) (__tmp_context = (__ATTR).value) 77 #define __set_accessor(__ATTR) (__tmp_value = (__ATTR).value) 78 #define __set_target_accessor(__ATTR) (__tmp_target_value = (__ATTR).value) 79 80 /* Context testing for invocations. */ 81 82 __attr __unwrap_callable(__attr callable); 83 __attr (*__get_function(__ref context, __attr target))(__attr[]); 84 __attr (*__check_and_get_function(__ref context, __attr target))(__attr[]); 85 86 /* Basic structure tests. */ 87 88 int __WITHIN(__ref obj, int pos); 89 int __HASATTR(__ref obj, int pos, int code); 90 91 /* Parameter position operations. */ 92 93 int __HASPARAM(const __ptable *ptable, int ppos, int pcode); 94 95 /* Conversions. */ 96 97 __attr __CONTEXT_AS_VALUE(__attr attr); 98 99 /* Type testing. */ 100 101 __ref __ISFUNC(__ref obj); 102 int __ISNULL(__attr value); 103 104 /* __TEST(obj, __A) -> test obj for the special type attribute __A */ 105 106 #define __TEST(__OBJ, __TYPE) (__test_common_instance(__OBJ, __pos_##__TYPE, __code_##__TYPE)) 107 108 /* Attribute codes and positions for type objects. */ 109 110 unsigned int __TYPECODE(__ref obj); 111 unsigned int __TYPEPOS(__ref obj); 112 113 /* Attribute codes and positions for attribute names. */ 114 115 #define __ATTRCODE(__ATTRNAME) (__code_##__ATTRNAME) 116 #define __ATTRPOS(__ATTRNAME) (__pos_##__ATTRNAME) 117 118 /* Memory allocation. */ 119 120 void *__ALLOCATE(size_t nmemb, size_t size); 121 void *__REALLOCATE(void *ptr, size_t size); 122 123 /* Copying of structures. */ 124 125 __ref __COPY(__ref obj, int size); 126 127 #endif /* __OPS_H__ */