Lichen

templates/progops.h

934:2989aab1b4f7
13 months ago Paul Boddie Renamed the utf8string class to unicode, eliminating the unicode function. This means that the simple case of merely returning an object if it is already a Unicode object no longer occurs when using the unicode callable, but such behaviour might be better supported with more general customised instantiation functionality.
     1 /* Operations depending on program specifics.     2      3 Copyright (C) 2015, 2016, 2017, 2018, 2021 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> /* size_t */    23 #include "types.h"    24 #include "main.h"    25     26 /* Generic instantiation operations, defining common members. */    27     28 __attr __new(const __table *table, __ref cls, size_t size, int immutable);    29 __attr __new_wrapper(__attr context, __attr attr);    30     31 /* Generic internal data allocation. */    32     33 __fragment *__new_fragment(unsigned int n);    34     35 __attr __newdata_list(unsigned int number, __attr args[]);    36 __attr __newdata_tuple(unsigned int number, __attr args[]);    37     38 #define __newliteral___builtins___list_list(NUM, ...) __newdata_list(NUM, __ARGS(__VA_ARGS__))    39 #define __newliteral___builtins___tuple_tuple(NUM, ...) __newdata_tuple(NUM, __ARGS(__VA_ARGS__))    40     41 #ifdef __HAVE___builtins___dict_dict    42 __attr __newdata_dict(unsigned int number, __attr args[]);    43 #define __newliteral___builtins___dict_dict(NUM, ...) __newdata_dict(NUM, __ARGS(__VA_ARGS__))    44 #endif /* __HAVE___builtins___dict_dict */    45     46 /* Helpers for raising errors within common operations. */    47     48 void __raise_eof_error();    49     50 void __raise_io_error(__attr value);    51     52 void __raise_memory_error();    53     54 void __raise_os_error(__attr value, __attr arg);    55     56 void __raise_overflow_error();    57     58 void __raise_unbound_method_error();    59     60 void __raise_value_error(__attr value);    61     62 void __raise_zero_division_error();    63     64 void __raise_type_error();    65     66 /* Helper for raising exception instances. */    67     68 __attr __ensure_instance(__attr arg);    69     70 /* Generic invocation operations. */    71     72 __attr __invoke(__attr callable, int always_callable,    73                    unsigned int nkwargs, __param kwcodes[], __attr kwargs[],    74                    unsigned int nargs, __attr args[]);    75     76 /* Error routines. */    77     78 __attr __unbound_method(__attr __self);    79     80 /* Generic operations depending on specific program details. */    81     82 void __SETDEFAULT(__ref obj, int pos, __attr value);    83     84 __attr __GETDEFAULT(__ref obj, int pos);    85     86 int __BOOL(__attr attr);    87     88 /* Convenience definitions. */    89     90 #define __INSTANCESIZE(CLS) sizeof(__obj_##CLS)    91 #define __INSTANCETABLE(CLS) (__InstanceTable_##CLS)    92 #define __NEWINSTANCE(CLS) __new(&__INSTANCETABLE(CLS), &CLS, __INSTANCESIZE(CLS), 0)    93 #define __NEWINSTANCEIM(CLS) __new(&__INSTANCETABLE(CLS), &CLS, __INSTANCESIZE(CLS), 1)    94 #define __ISINSTANCE(ATTR, TYPE) __BOOL(__fn_native_introspection_isinstance(__NULL, ATTR, TYPE))    95     96 #endif /* __PROGOPS_H__ */