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