paul@353 | 1 | /* Operations depending on program specifics. |
paul@353 | 2 | |
paul@569 | 3 | Copyright (C) 2015, 2016, 2017 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@126 | 24 | |
paul@353 | 25 | /* Generic instantiation operations, defining common members. */ |
paul@126 | 26 | |
paul@162 | 27 | __attr __new(const __table *table, __ref cls, size_t size); |
paul@577 | 28 | __attr __new_wrapper(__ref context, __attr attr); |
paul@159 | 29 | |
paul@353 | 30 | /* Generic internal data allocation. */ |
paul@353 | 31 | |
paul@283 | 32 | __fragment *__new_fragment(unsigned int n); |
paul@283 | 33 | |
paul@283 | 34 | void __newdata_sequence(__attr args[], unsigned int number); |
paul@283 | 35 | |
paul@327 | 36 | #ifdef __HAVE___builtins___dict_dict |
paul@283 | 37 | void __newdata_mapping(__attr args[], unsigned int number); |
paul@327 | 38 | #endif /* __HAVE___builtins___dict_dict */ |
paul@159 | 39 | |
paul@353 | 40 | /* Helpers for raising errors within common operations. */ |
paul@317 | 41 | |
paul@336 | 42 | void __raise_eof_error(); |
paul@336 | 43 | |
paul@331 | 44 | void __raise_io_error(__attr value); |
paul@327 | 45 | |
paul@306 | 46 | void __raise_memory_error(); |
paul@379 | 47 | |
paul@379 | 48 | void __raise_os_error(__attr value, __attr arg); |
paul@379 | 49 | |
paul@306 | 50 | void __raise_overflow_error(); |
paul@379 | 51 | |
paul@306 | 52 | void __raise_zero_division_error(); |
paul@379 | 53 | |
paul@305 | 54 | void __raise_type_error(); |
paul@353 | 55 | |
paul@353 | 56 | /* Helper for raising exception instances. */ |
paul@353 | 57 | |
paul@317 | 58 | __attr __ensure_instance(__attr arg); |
paul@317 | 59 | |
paul@317 | 60 | /* Generic invocation operations. */ |
paul@305 | 61 | |
paul@156 | 62 | __attr __invoke(__attr callable, int always_callable, |
paul@156 | 63 | unsigned int nkwargs, __param kwcodes[], __attr kwargs[], |
paul@156 | 64 | unsigned int nargs, __attr args[]); |
paul@126 | 65 | |
paul@126 | 66 | /* Error routines. */ |
paul@126 | 67 | |
paul@126 | 68 | __attr __unbound_method(__attr args[]); |
paul@126 | 69 | |
paul@126 | 70 | /* Generic operations depending on specific program details. */ |
paul@126 | 71 | |
paul@126 | 72 | void __SETDEFAULT(__ref obj, int pos, __attr value); |
paul@159 | 73 | |
paul@126 | 74 | __attr __GETDEFAULT(__ref obj, int pos); |
paul@159 | 75 | |
paul@144 | 76 | int __BOOL(__attr attr); |
paul@353 | 77 | |
paul@462 | 78 | /* Convenience definitions. */ |
paul@462 | 79 | |
paul@571 | 80 | #define __NEWINSTANCE(__CLS) __new(&__InstanceTable_##__CLS, &__CLS, sizeof(__obj_##__CLS)) |
paul@477 | 81 | #define __ISINSTANCE(__ATTR, __TYPE) __BOOL(__fn_native_introspection_isinstance((__attr[]) {__NULL, __ATTR, __TYPE})) |
paul@462 | 82 | |
paul@353 | 83 | #endif /* __PROGOPS_H__ */ |