Lichen

templates/progops.h

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