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