1 /*
2 $Id: codeobj.h 2475 2021-03-07 01:34:55Z 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 CODEOBJ_H
20 #define CODEOBJ_H
21 #include "obj.h"
22 #include "values.h"
23
24 extern struct Type *const CODE_OBJ;
25
26 typedef enum Code_types {
27 D_DINT = -4,
28 D_LINT = -3,
29 D_SINT = -2,
30 D_CHAR = -1,
31 D_NONE = 0,
32 D_BYTE = 1,
33 D_WORD = 2,
34 D_LONG = 3,
35 D_DWORD = 4
36 } Code_types;
37
38 typedef struct Code {
39 Obj v;
40 address_t size;
41 address_t addr;
42 ival_t offs;
43 uint8_t pass;
44 uint8_t apass;
45 signed char dtype;
46 Obj *typ;
47 struct Memblocks *memblocks;
48 address_t memaddr;
49 size_t membp;
50 struct Namespace *names;
51 uval_t requires;
52 uval_t conflicts;
53 } Code;
54
55 #define Code(a) ((Code *)(1 ? (a) : (Obj *)(Code *)(a)))
56
57 extern void codeobj_init(void);
58 extern void codeobj_names(void);
59
new_code(void)60 static inline MUST_CHECK Code *new_code(void) {
61 return Code(val_alloc(CODE_OBJ));
62 }
63
64 struct Error;
65
66 extern MUST_CHECK Obj *get_code_value(const Code *, linepos_t);
67 extern MUST_CHECK struct Error *code_uaddress(Obj *, uval_t *, uval_t *, linepos_t);
68 extern MUST_CHECK Obj *int_from_code(const Code *, linepos_t);
69 extern MUST_CHECK Obj *float_from_code(const Code *, linepos_t);
70 extern MUST_CHECK Obj *bits_from_code(const Code *, linepos_t);
71 extern MUST_CHECK Obj *bytes_from_code(const Code *, linepos_t);
72 extern MUST_CHECK Obj *tuple_from_code(const Code *, const struct Type *);
73 #endif
74