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
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
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
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 7 // Maximum size of keyword in kwtab.h
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 0x94 // equreg
49 #define CCDEF 0xB7 // ccdef
50 #define DCOLON 'h' // ::
53 #define NE 'k' // <> or !=
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)
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
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 '.'
92 // Macro to check for specific optimizations or override
93 #define CHECK_OPTS(x) (optim_flags[x] && !optimizeOff)
95 // Conditional assembly structures
97 IFENT * if_prev; // Ptr prev .if state block (or NULL)
98 WORD if_state; // 0:enabled, 1:disabled
101 // Pointer to IFILE or IMACRO or IREPT
108 // Ptr to IFILEs, IMACROs, and so on; back-ptr to previous input objects
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
118 // Information about a file
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
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
136 TOKEN token[TS_MAXTOKENS];
137 char * string[TS_MAXSTRINGS];
140 // Information about a macro invocation
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];
152 // Information about a .rept invocation
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?)
160 // Exported variables
162 extern uint32_t curlineno;
163 extern char * curfname;
168 extern char tolowertab[];
169 extern INOBJ * cur_inobj;
170 extern int mjump_align;
171 extern char * string[];
172 extern int optimizeOff;
174 // Exported functions
175 int include(int, char *);
176 void InitTokenizer(void);
177 void SetFilenameForErrorReporting(void);
178 int TokenizeLine(void);
181 INOBJ * a_inobj(int);
182 void DumpToken(TOKEN);
183 void DumpTokenBuffer(void);
185 #endif // __TOKEN_H__