Lichen

templates/ops.h

606:e6d60706c5a0
2017-02-20 Paul Boddie Merged changes from the default branch. method-wrapper-for-context
     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 int __test_context_update(__ref context, __attr attr);    74 __attr __test_context(__ref context, __attr attr);    75 __attr __update_context(__ref context, __attr attr);    76 __attr __test_context_revert(int target, __ref context, __attr attr, __ref contexts[]);    77 __attr __test_context_static(int target, __ref context, __ref value, __ref contexts[]);    78     79 #define __get_context(__TARGET) (__tmp_contexts[__TARGET])    80 #define __set_context(__TARGET, __ATTR) (__tmp_contexts[__TARGET] = (__ATTR).value)    81 #define __set_private_context(__ATTR) (__tmp_private_context = (__ATTR).value)    82 #define __set_accessor(__ATTR) (__tmp_value = (__ATTR).value)    83 #define __set_target_accessor(__ATTR) (__tmp_target_value = (__ATTR).value)    84     85 /* Context testing for invocations. */    86     87 __attr __unwrap_callable(__attr callable);    88 __attr (*__get_function(__ref context, __attr target))(__attr[]);    89 __attr (*__check_and_get_function(__ref context, __attr target))(__attr[]);    90     91 /* Basic structure tests. */    92     93 int __WITHIN(__ref obj, int pos);    94 int __HASATTR(__ref obj, int pos, int code);    95     96 /* Parameter position operations. */    97     98 int __HASPARAM(const __ptable *ptable, int ppos, int pcode);    99    100 /* Conversions. */   101    102 __attr __CONTEXT_AS_VALUE(__attr attr);   103    104 /* Type testing. */   105    106 __ref __ISFUNC(__ref obj);   107 int __ISNULL(__attr value);   108    109 /* __TEST(obj, __A) -> test obj for the special type attribute __A */   110    111 #define __TEST(__OBJ, __TYPE) (__test_common_instance(__OBJ, __pos_##__TYPE, __code_##__TYPE))   112    113 /* Attribute codes and positions for type objects. */   114    115 unsigned int __TYPECODE(__ref obj);   116 unsigned int __TYPEPOS(__ref obj);   117    118 /* Attribute codes and positions for attribute names. */   119    120 #define __ATTRCODE(__ATTRNAME) (__code_##__ATTRNAME)   121 #define __ATTRPOS(__ATTRNAME) (__pos_##__ATTRNAME)   122    123 /* Memory allocation. */   124    125 void *__ALLOCATE(size_t nmemb, size_t size);   126 void *__REALLOCATE(void *ptr, size_t size);   127    128 /* Copying of structures. */   129    130 __ref __COPY(__ref obj, int size);   131    132 #endif /* __OPS_H__ */