1 /* Operations depending on program specifics. 2 3 Copyright (C) 2015, 2016 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 __PROGOPS_H__ 20 #define __PROGOPS_H__ 21 22 #include <stdlib.h> 23 #include "types.h" 24 25 /* Generic instantiation operations, defining common members. */ 26 27 __attr __new(const __table *table, __ref cls, size_t size); 28 29 /* Generic internal data allocation. */ 30 31 __fragment *__new_fragment(unsigned int n); 32 33 void __newdata_sequence(__attr args[], unsigned int number); 34 35 #ifdef __HAVE___builtins___dict_dict 36 void __newdata_mapping(__attr args[], unsigned int number); 37 #endif /* __HAVE___builtins___dict_dict */ 38 39 /* Helpers for raising errors within common operations. */ 40 41 void __raise_eof_error(); 42 43 void __raise_io_error(__attr value); 44 45 void __raise_memory_error(); 46 47 void __raise_os_error(__attr value, __attr arg); 48 49 void __raise_overflow_error(); 50 51 void __raise_zero_division_error(); 52 53 void __raise_type_error(); 54 55 /* Helper for raising exception instances. */ 56 57 __attr __ensure_instance(__attr arg); 58 59 /* Generic invocation operations. */ 60 61 __attr __invoke(__attr callable, int always_callable, 62 unsigned int nkwargs, __param kwcodes[], __attr kwargs[], 63 unsigned int nargs, __attr args[]); 64 65 /* Error routines. */ 66 67 __attr __unbound_method(__attr args[]); 68 69 /* Generic operations depending on specific program details. */ 70 71 void __SETDEFAULT(__ref obj, int pos, __attr value); 72 73 __attr __GETDEFAULT(__ref obj, int pos); 74 75 int __BOOL(__attr attr); 76 77 /* Convenience definitions. */ 78 79 #define __ISINSTANCE(__ATTR, __TYPE) __BOOL(__fn_native_introspection_isinstance((__attr[]) {{0, 0}, __ATTR, __TYPE})) 80 81 #endif /* __PROGOPS_H__ */