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