Debian Codegraph @

src/alu.h

raw symbols SCIP
1 // ACME - a crossassembler for producing 6502/65c02/65816/65ce02 code.
2 // Copyright (C) 1998-2024 Marco Baye
3 // Have a look at "acme.c" for further info
4 //
5 // ALU stuff (the expression parser)
6 #ifndef alu_H
7 #define alu_H
8
9
10 #include "config.h"
11
12
13 struct op;
14 struct dynabuf;
15 struct type {
16 const char *name;
17 boolean (*is_defined)(const struct object *self);
18 boolean (*differs)(const struct object *self, const struct object *other);
19 boolean (*assign)(struct object *self, const struct object *new_value, boolean accept_change);
20 void (*monadic_op)(struct object *self, const struct op *op);
21 void (*dyadic_op)(struct object *self, const struct op *op, struct object *other);
22 void (*fix_result)(struct object *self);
23 void (*print)(const struct object *self, struct dynabuf *db);
24 int (*length)(const struct object *self); // returns -1 if not iterable
25 void (*at)(const struct object *self, struct object *target, int index);
26 };
27 extern struct type type_number;
28 extern struct type type_list;
29 extern struct type type_string;
30
31 struct expression {
32 struct object result;
33 boolean is_empty; // nothing parsed (first character was a delimiter)
34 int open_parentheses; // number of parentheses still open
35 boolean is_parenthesized; // whole expression was in parentheses (indicating indirect addressing)
36 // TODO - how to return reserved cpu constant (register names)?
37 };
38
39
40 // constants
41
42 // flag bits in number struct:
43 #define NO_FORCE_BIT 0 // (just to make source more readable)
44 #define NUMBER_FORCES_8 (1u << 0) // value usage forces 8-bit usage
45 #define NUMBER_FORCES_16 (1u << 1) // value usage forces 16-bit usage
46 #define NUMBER_FORCES_24 (1u << 2) // value usage forces 24-bit usage
47 #define NUMBER_FORCEBITS (NUMBER_FORCES_8 | NUMBER_FORCES_16 | NUMBER_FORCES_24)
48 #define NUMBER_FITS_BYTE (1u << 3) // value is guaranteed to fit in one byte
49 #define NUMBER_EVER_UNDEFINED (1u << 4) // value once was related to
50 // undefined expression. Needed for producing the same addresses in all
51 // passes; because in the first pass there will almost for sure be
52 // labels that are undefined, we can't simply get the addressing mode
53 // from looking at the parameter's value. FIXME - rename to TAINTED :)
54
55
56 // prototypes
57
58 // make new string object
59 // (exported because symbol.c calls this for strings given on command line)
60 extern void string_prepare_string(struct object *self, int len);
61
62 /*
63 // FIXME - replace all the functions below with a single one using a "flags" arg!
64 // its return value would then be "error"/"ok".
65 // input flags:
66 #define ACCEPT_UNDEFINED (1u << 0) // if not given, undefined throws serious error
67 #define ACCEPT_INT (1u << 1)
68 #define ACCEPT_FLOAT (1u << 2) // if not given, floats are converted to integer
69 #define ACCEPT_OPENPARENTHESIS (1u << 3) // if not given, throws syntax error
70 #define ACCEPT_STRING (1u << 4) // if not given, convert 1-char strings to int?
71 #define ACCEPT_LIST (1u << 5)
72 // do I need ACCEPT_NONADDR and/or ACCEPT_ADDRESS?
73 */
74
75 // stores int value (0 if result was undefined)
76 extern void ALU_any_int(intval_t *target);
77
78 // stores int value and flags (floats are transformed to int)
79 // if result was undefined, serious error is thrown
80 extern void ALU_defined_int(struct number *intresult);
81
82 // stores int value and flags, allowing for "paren" '(' too many (x-indirect addr).
83 extern void ALU_addrmode_int(struct expression *expression, int paren);
84
85 // stores resulting object
86 extern void ALU_any_result(struct object *result);
87
88
89 #endif