]> Shamusworld >> Repos - rmac/blob - token.h
Version bump for last commit. :-)
[rmac] / token.h
1 //
2 // RMAC - Renamed Macro Assembler for all Atari computers
3 // TOKEN.H - Token Handling
4 // Copyright (C) 199x Landon Dyer, 2011-2021 Reboot and Friends
5 // RMAC derived from MADMAC v1.07 Written by Landon Dyer, 1986
6 // Source utilised with the kind permission of Landon Dyer
7 //
8
9 #ifndef __TOKEN_H__
10 #define __TOKEN_H__
11
12 #include "rmac.h"
13
14 // Include Files and Macros
15 #define SRC_IFILE       0                       // Input source is IFILE
16 #define SRC_IMACRO      1                       // Input source is IMACRO
17 #define SRC_IREPT       2                       // Input source is IREPT
18
19 // Macros
20 #define INOBJ           struct _inobj
21 #define IUNION          union  _iunion
22 #define IFILE           struct _incldfile
23 #define TOKENSTREAM     struct _tokenstream
24 #define IMACRO          struct _imacro
25 #define IREPT           struct _irept
26 #define IFENT           struct _ifent
27
28 // Tunable definitions
29 #define LNSIZ           1024            // Maximum size of a line of text
30 #define TOKBUFSIZE      4096            // Size of token-line buffer
31 #define QUANTUM         4096L           // # bytes to eat at a time from a file
32 #define LNBUFSIZ        (QUANTUM*2)     // Size of file's buffer
33 #define KWSIZE          10                      // Maximum size of keyword in kwtab.h
34
35 // (Normally) non-printable tokens
36 #define COLON           ':'                     // : (grumble: GNUmacs hates ':')
37 #define CONST           'a'                     // CONST <value>
38 #define FCONST          'r'                     // Floating CONST <value>
39 #define ACONST          'A'                     // ACONST <value> <attrib>
40 #define STRING          'b'                     // STRING <address>
41 #define STRINGA8        'S'                     // Atari 800 internal STRING <address>
42 #define SYMBOL          'c'                     // SYMBOL <address>
43 #define EOL             'e'                     // End of line
44 #define TKEOF           'f'                     // End of file (or macro)
45 #define DEQUALS         'g'                     // ==
46 #define SET             0x95            // Set
47 #define REG             'R'                     // Reg
48 #define EQUREG          'U'                     // equreg (must be synchronised with the equate in kw.tab)
49 #define CCDEF           0xB7            // ccdef
50 #define DCOLON          'h'                     // ::
51 #define GE              'i'                     // >=
52 #define LE              'j'                     // <=
53 #define NE              'k'                     // <> or !=
54 #define SHR             'l'                     // >>
55 #define SHL             'm'                     // <<
56 #define UNMINUS         'n'                     // Unary '-'
57 #define DOTB            'B'                     // .b or .B or .s or .S
58 #define DOTW            'W'                     // .w or .W
59 #define DOTL            'L'                     // .l or .L
60 #define DOTI            'I'                     // .l or .L
61 #define DOTX            'X'                     // .x or .X
62 #define DOTD            'D'                     // .d or .D
63 #define DOTP            'P'                     // .p or .P
64 #define DOTQ            'Q'                     // .q or .Q (essentially an alias for P)
65 #define DOTS            'S'                     // .s or .S (FPU Single)
66 #define ENDEXPR         'E'                     // End of expression
67 #define UNLT            0x81            // Unary '<' (low byte)
68 #define UNGT            0x82            // Unary '>' (high byte)
69
70 // ^^ operators
71 #define CR_DEFINED      'p'                     // ^^defined - is symbol defined?
72 #define CR_REFERENCED   'q'                     // ^^referenced - was symbol referenced?
73 #define CR_STREQ        'v'                     // ^^streq - compare two strings
74 #define CR_MACDEF       'w'                     // ^^macdef - is macro defined?
75 #define CR_TIME         'x'                     // ^^time - DOS format time
76 #define CR_DATE         'y'                     // ^^date - DOS format date
77 #define CR_ABSCOUNT     'z'                     // ^^abscount - count the number of bytes
78                                                                         // defined in current .abs section
79 #define CR_FILESIZE     'F'                     // ^^filesize - return the size in bytes of a file
80
81 // Character Attributes
82 #define ILLEG           0                       // Illegal character (unused)
83 #define DIGIT           1                       // 0-9
84 #define HDIGIT          2                       // A-F, a-f
85 #define STSYM           4                       // A-Z, a-z, _~.
86 #define CTSYM           8                       // A-Z, a-z, 0-9, _~$?
87 #define SELF            16                      // Single-character tokens: ( ) [ ] etc
88 #define WHITE           32                      // Whitespace (space, tab, etc.)
89 #define MULTX           64                      // Multiple-character tokens
90 #define DOT             128                     // [bwlsBWSL] for what follows a '.'
91
92 // Macro to check for specific optimizations or override
93 #define CHECK_OPTS(x)   (optim_flags[x] && !optimizeOff)
94
95 // Conditional assembly structures
96 IFENT {
97         IFENT * if_prev;                // Ptr prev .if state block (or NULL)
98         WORD if_state;                  // 0:enabled, 1:disabled
99 };
100
101 // Pointer to IFILE or IMACRO or IREPT
102 IUNION {
103         IFILE * ifile;
104         IMACRO * imacro;
105         IREPT * irept;
106 };
107
108 // Ptr to IFILEs, IMACROs, and so on; back-ptr to previous input objects
109 INOBJ {
110         WORD in_type;                   // 0=IFILE, 1=IMACRO, 2=IREPT
111         IFENT * in_ifent;               // Pointer to .if context on entry
112         INOBJ * in_link;                // Pointer to previous INOBJ
113         TOKEN * in_otok;                // Old `tok' value
114         TOKEN * in_etok;                // Old `etok' value
115         IUNION inobj;                   // IFILE or IMACRO or IREPT
116 };
117
118 // Information about a file
119 IFILE {
120         IFILE * if_link;                // Pointer to ancient IFILEs
121         char * ifoldfname;              // Old file's name
122         int ifoldlineno;                // Old line number
123         int ifind;                              // Position in file buffer
124         int ifcnt;                              // #chars left in file buffer
125         int ifhandle;                   // File's descriptor
126         WORD ifno;                              // File number
127         char ifbuf[LNBUFSIZ];   // Line buffer
128 };
129
130 // Consts for maximums in TOKENSTREAM
131 #define TS_MAXTOKENS    64      // 32 ought to be enough for anybody (including XiA!)
132 #define TS_MAXSTRINGS   32      // same for attached strings
133 #define TS_MAXARGS              20      // Assume no more than 20 arguments in an invocation
134
135 TOKENSTREAM {
136         TOKEN token[TS_MAXTOKENS];
137         char * string[TS_MAXSTRINGS];
138 };
139
140 // Information about a macro invocation
141 IMACRO {
142         IMACRO * im_link;               // Pointer to ancient IMACROs
143         LLIST * im_nextln;              // Next line to include
144         WORD im_nargs;                  // # of arguments supplied on invocation
145         WORD im_siz;                    // Size suffix supplied on invocation
146         LONG im_olduniq;                // Old value of 'macuniq'
147         SYM * im_macro;                 // Pointer to macro we're in
148         char im_lnbuf[LNSIZ];   // Line buffer
149         TOKENSTREAM argument[TS_MAXARGS];
150 };
151
152 // Information about a .rept invocation
153 IREPT {
154         LLIST * ir_firstln;             // Pointer to first line
155         LLIST * ir_nextln;              // Pointer to next line
156         uint32_t ir_count;              // Repeat count (decrements)
157         uint32_t lineno;                // Repeat line number (Convert this to global instead of putting it here?)
158 };
159
160 // File record, used to maintain a list of every include file ever visited
161 #define FILEREC struct _filerec
162 FILEREC
163 {
164    FILEREC * frec_next;
165    char * frec_name;
166 };
167
168 // Exported variables
169 extern int lnsave;
170 extern uint32_t curlineno;
171 extern char * curfname;
172 extern WORD cfileno;
173 extern TOKEN * tok;
174 extern char lnbuf[];
175 extern char lntag;
176 extern char tolowertab[];
177 extern INOBJ * cur_inobj;
178 extern int mjump_align;
179 extern char * string[];
180 extern int optimizeOff;
181 extern FILEREC * filerec;
182
183 // Exported functions
184 int include(int, char *);
185 void InitTokenizer(void);
186 void SetFilenameForErrorReporting(void);
187 int TokenizeLine(void);
188 int fpop(void);
189 int d_goto(WORD);
190 INOBJ * a_inobj(int);
191 void DumpToken(TOKEN);
192 void DumpTokenBuffer(void);
193
194 #endif // __TOKEN_H__
195