1 /* 2 $Id: typeobj.h 2580 2021-04-17 16:09:46Z soci $ 3 4 This program is free software; you can redistribute it and/or modify 5 it under the terms of the GNU General Public License as published by 6 the Free Software Foundation; either version 2 of the License, or 7 (at your option) any later version. 8 9 This program is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 GNU General Public License for more details. 13 14 You should have received a copy of the GNU General Public License along 15 with this program; if not, write to the Free Software Foundation, Inc., 16 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 18 */ 19 #ifndef TYPEOBJ_H 20 #define TYPEOBJ_H 21 #include "obj.h" 22 #include "stdbool.h" 23 24 struct iter_s; 25 26 extern struct Type *const TYPE_OBJ; 27 28 typedef enum Truth_types { 29 TRUTH_BOOL, TRUTH_ALL, TRUTH_ANY 30 } Truth_types; 31 32 typedef enum Type_types { 33 T_NONE, T_BOOL, T_BITS, T_INT, T_FLOAT, T_BYTES, T_STR, T_GAP, T_ADDRESS, 34 T_SYMBOL, T_ANONSYMBOL, T_ERROR, T_OPER, T_COLONLIST, T_TUPLE, T_LIST, 35 T_DICT, T_MACRO, T_SEGMENT, T_UNION, T_STRUCT, T_MFUNC, T_CODE, T_LBL, 36 T_DEFAULT, T_REGISTER, T_FUNCTION, T_ADDRLIST, T_FUNCARGS, T_TYPE, T_LABEL, 37 T_NAMESPACE, T_MEMBLOCKS, T_FOLD, T_SFUNC 38 } Type_types; 39 40 typedef struct Type { 41 Obj v; 42 Type_types type; 43 bool iterable; 44 const char *name; 45 struct Slot **slot; 46 size_t length; 47 Obj *(*convert)(struct oper_s *) MUST_CHECK; 48 Obj *(*convert2)(struct oper_s *) MUST_CHECK; 49 void (*destroy)(Obj *) FAST_CALL; 50 void (*garbage)(Obj *, int) FAST_CALL; 51 bool (*same)(const Obj *, const Obj *) FAST_CALL; 52 Obj *(*truth)(Obj *, Truth_types, linepos_t) MUST_CHECK; 53 Obj *(*hash)(Obj *, int *, linepos_t) MUST_CHECK; 54 Obj *(*repr)(Obj *, linepos_t, size_t) MUST_CHECK; 55 Obj *(*str)(Obj *, linepos_t, size_t) MUST_CHECK; 56 Obj *(*calc1)(struct oper_s *) MUST_CHECK; 57 Obj *(*calc2)(struct oper_s *) MUST_CHECK; 58 Obj *(*rcalc2)(struct oper_s *) MUST_CHECK; 59 Obj *(*slice)(struct oper_s *, argcount_t) MUST_CHECK; 60 struct Error *(*ival)(Obj *, ival_t *, unsigned int, linepos_t) MUST_CHECK; 61 struct Error *(*uval)(Obj *, uval_t *, unsigned int, linepos_t) MUST_CHECK; 62 struct Error *(*uval2)(Obj *, uval_t *, unsigned int, linepos_t) MUST_CHECK; 63 uint32_t (*address)(const Obj *) FAST_CALL; 64 struct Error *(*iaddress)(Obj *, ival_t *, unsigned int, linepos_t) MUST_CHECK; 65 struct Error *(*uaddress)(Obj *, uval_t *, unsigned int, linepos_t) MUST_CHECK; 66 Obj *(*sign)(Obj *, linepos_t) MUST_CHECK; 67 Obj *(*function)(struct oper_s *) MUST_CHECK; 68 Obj *(*len)(struct oper_s *) MUST_CHECK; 69 Obj *(*size)(struct oper_s *) MUST_CHECK; 70 void (*getiter)(struct iter_s *); 71 void (*getriter)(struct iter_s *); 72 } Type; 73 74 #define Type(a) ((Type *)(1 ? (a) : (Obj *)(Type *)(a))) 75 76 extern void typeobj_init(void); 77 extern void typeobj_names(void); 78 extern void new_type(Type *, Type_types, const char *, size_t); 79 80 #endif 81