paul@353 | 1 | /* Operations depending on program specifics. |
paul@353 | 2 | |
paul@971 | 3 | Copyright (C) 2015-2019, 2021, 2023 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@353 | 18 | |
paul@353 | 19 | #ifndef __PROGOPS_H__ |
paul@353 | 20 | #define __PROGOPS_H__ |
paul@126 | 21 | |
paul@569 | 22 | #include <stdlib.h> /* size_t */ |
paul@126 | 23 | #include "types.h" |
paul@674 | 24 | #include "main.h" |
paul@126 | 25 | |
paul@353 | 26 | /* Generic instantiation operations, defining common members. */ |
paul@126 | 27 | |
paul@756 | 28 | __attr __new(const __table *table, __ref cls, size_t size, int immutable); |
paul@757 | 29 | __attr __new_wrapper(__attr context, __attr attr); |
paul@159 | 30 | |
paul@353 | 31 | /* Generic internal data allocation. */ |
paul@353 | 32 | |
paul@941 | 33 | __fragment *__new_fragment(__int n); |
paul@283 | 34 | |
paul@941 | 35 | __attr __newdata_list(__int number, __attr args[]); |
paul@941 | 36 | __attr __newdata_tuple(__int number, __attr args[]); |
paul@786 | 37 | |
paul@786 | 38 | #define __newliteral___builtins___list_list(NUM, ...) __newdata_list(NUM, __ARGS(__VA_ARGS__)) |
paul@786 | 39 | #define __newliteral___builtins___tuple_tuple(NUM, ...) __newdata_tuple(NUM, __ARGS(__VA_ARGS__)) |
paul@283 | 40 | |
paul@850 | 41 | /* Potentially superfluous operations. */ |
paul@850 | 42 | |
paul@327 | 43 | #ifdef __HAVE___builtins___dict_dict |
paul@941 | 44 | __attr __newdata_dict(__int number, __attr args[]); |
paul@786 | 45 | #define __newliteral___builtins___dict_dict(NUM, ...) __newdata_dict(NUM, __ARGS(__VA_ARGS__)) |
paul@850 | 46 | #endif |
paul@159 | 47 | |
paul@353 | 48 | /* Helpers for raising errors within common operations. */ |
paul@317 | 49 | |
paul@336 | 50 | void __raise_eof_error(); |
paul@879 | 51 | void __raise_floating_point_error(); |
paul@331 | 52 | void __raise_io_error(__attr value); |
paul@306 | 53 | void __raise_memory_error(); |
paul@379 | 54 | void __raise_os_error(__attr value, __attr arg); |
paul@306 | 55 | void __raise_overflow_error(); |
paul@852 | 56 | void __raise_unbound_method_error(); |
paul@850 | 57 | void __raise_underflow_error(); |
paul@928 | 58 | void __raise_value_error(__attr value); |
paul@306 | 59 | void __raise_zero_division_error(); |
paul@305 | 60 | void __raise_type_error(); |
paul@353 | 61 | |
paul@353 | 62 | /* Helper for raising exception instances. */ |
paul@353 | 63 | |
paul@317 | 64 | __attr __ensure_instance(__attr arg); |
paul@317 | 65 | |
paul@317 | 66 | /* Generic invocation operations. */ |
paul@305 | 67 | |
paul@156 | 68 | __attr __invoke(__attr callable, int always_callable, |
paul@664 | 69 | unsigned int nkwargs, __param kwcodes[], __attr kwargs[], |
paul@664 | 70 | unsigned int nargs, __attr args[]); |
paul@126 | 71 | |
paul@126 | 72 | /* Error routines. */ |
paul@126 | 73 | |
paul@971 | 74 | __attr __unbound_method(__attr __result, __attr __self); |
paul@126 | 75 | |
paul@126 | 76 | /* Generic operations depending on specific program details. */ |
paul@126 | 77 | |
paul@126 | 78 | void __SETDEFAULT(__ref obj, int pos, __attr value); |
paul@126 | 79 | __attr __GETDEFAULT(__ref obj, int pos); |
paul@144 | 80 | int __BOOL(__attr attr); |
paul@353 | 81 | |
paul@462 | 82 | /* Convenience definitions. */ |
paul@462 | 83 | |
paul@850 | 84 | #define __OBJTYPE(CLS) __obj_##CLS |
paul@850 | 85 | #define __INSTANCESIZE(CLS) sizeof(__OBJTYPE(CLS)) |
paul@778 | 86 | #define __INSTANCETABLE(CLS) (__InstanceTable_##CLS) |
paul@778 | 87 | #define __NEWINSTANCE(CLS) __new(&__INSTANCETABLE(CLS), &CLS, __INSTANCESIZE(CLS), 0) |
paul@778 | 88 | #define __NEWINSTANCEIM(CLS) __new(&__INSTANCETABLE(CLS), &CLS, __INSTANCESIZE(CLS), 1) |
paul@971 | 89 | #define __ISINSTANCE(ATTR, TYPE) __BOOL(__fn_native_introspection_isinstance(__NULL, __NULL, ATTR, TYPE)) |
paul@462 | 90 | |
paul@850 | 91 | /* Operations for accessing trailing data. */ |
paul@850 | 92 | |
paul@850 | 93 | #define __get_trailing_data(ATTR, TYPE) (((__OBJTYPE(TYPE) *) ((ATTR).value))->trailing) |
paul@1010 | 94 | #define __set_trailing_data(ATTR, TYPE, VALUE) ((__OBJTYPE(TYPE) *) ((ATTR).value))->trailing = VALUE |
paul@850 | 95 | |
paul@353 | 96 | #endif /* __PROGOPS_H__ */ |