Lichen

templates/ops.h

543:b7334adb7dec
2017-02-04 Paul Boddie Handle situations where a global accidentally refers to a built-in module.
     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(__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_object_null(__ref obj, int pos, int code);    61 __attr __check_and_load_via_any(__ref obj, int pos, int code);    62     63 /* Attribute testing and storage operations. */    64     65 int __check_and_store_via_class(__ref obj, int pos, int code, __attr value);    66 int __check_and_store_via_object(__ref obj, int pos, int code, __attr value);    67 int __check_and_store_via_any(__ref obj, int pos, int code, __attr value);    68     69 /* Context-related operations. */    70     71 __attr __test_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 /* Context testing for invocations. */    79     80 __attr (*__get_function(__attr attr))(__attr[]);    81 __attr (*__check_and_get_function(__attr attr))(__attr[]);    82     83 /* Basic structure tests. */    84     85 int __WITHIN(__ref obj, int pos);    86 int __HASATTR(__ref obj, int pos, int code);    87     88 /* Parameter position operations. */    89     90 int __HASPARAM(const __ptable *ptable, int ppos, int pcode);    91     92 /* Conversions. */    93     94 __attr __CONTEXT_AS_VALUE(__attr attr);    95     96 /* Type testing. */    97     98 __ref __ISFUNC(__ref obj);    99 int __ISNULL(__attr value);   100    101 /* __TEST(obj, __A) -> test obj for the special type attribute __A */   102    103 #define __TEST(__OBJ, __TYPE) (__test_common_instance(__OBJ, __pos_##__TYPE, __code_##__TYPE))   104    105 /* Attribute codes and positions for type objects. */   106    107 unsigned int __TYPECODE(__ref obj);   108 unsigned int __TYPEPOS(__ref obj);   109    110 /* Attribute codes and positions for attribute names. */   111    112 #define __ATTRCODE(__ATTRNAME) (__code_##__ATTRNAME)   113 #define __ATTRPOS(__ATTRNAME) (__pos_##__ATTRNAME)   114    115 /* Memory allocation. */   116    117 void *__ALLOCATE(size_t nmemb, size_t size);   118 void *__REALLOCATE(void *ptr, size_t size);   119    120 /* Copying of structures. */   121    122 __ref __COPY(__ref obj, int size);   123    124 #endif /* __OPS_H__ */