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