2 // RMAC - Reboot's Macro Assembler for all Atari computers
3 // TOKEN.H - Token Handling
4 // Copyright (C) 199x Landon Dyer, 2011-2019 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 IMACRO struct _imacro
24 #define IREPT struct _irept
25 #define IFENT struct _ifent
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
34 // (Normally) non-printable tokens
35 #define COLON ':' // : (grumble: GNUmacs hates ':')
36 #define CONST 'a' // CONST <value>
37 #define FCONST 'r' // Floating CONST <value>
38 #define ACONST 'A' // ACONST <value> <attrib>
39 #define STRING 'b' // STRING <address>
40 #define STRINGA8 'S' // Atari 800 internal STRING <address>
41 #define SYMBOL 'c' // SYMBOL <address>
42 #define EOL 'e' // End of line
43 #define TKEOF 'f' // End of file (or macro)
44 #define DEQUALS 'g' // ==
45 #define SET 0x95 // Set
46 #define REG 'R' // Reg
47 #define EQUREG 0x94 // equreg
48 #define CCDEF 0xB7 // ccdef
49 #define DCOLON 'h' // ::
52 #define NE 'k' // <> or !=
55 #define UNMINUS 'n' // Unary '-'
56 #define DOTB 'B' // .b or .B or .s or .S
57 #define DOTW 'W' // .w or .W
58 #define DOTL 'L' // .l or .L
59 #define DOTI 'I' // .l or .L
60 #define DOTX 'X' // .x or .X
61 #define DOTD 'D' // .d or .D
62 #define DOTP 'P' // .p or .P
63 #define DOTQ 'Q' // .q or .Q (essentially an alias for P)
64 #define DOTS 'S' // .s or .S (FPU Single)
65 #define ENDEXPR 'E' // End of expression
66 #define UNLT 0x81 // Unary '<' (low byte)
67 #define UNGT 0x82 // Unary '>' (high byte)
70 #define CR_DEFINED 'p' // ^^defined - is symbol defined?
71 #define CR_REFERENCED 'q' // ^^referenced - was symbol referenced?
72 #define CR_STREQ 'v' // ^^streq - compare two strings
73 #define CR_MACDEF 'w' // ^^macdef - is macro defined?
74 #define CR_TIME 'x' // ^^time - DOS format time
75 #define CR_DATE 'y' // ^^date - DOS format date
76 #define CR_ABSCOUNT 'z' // ^^abscount - count the number of bytes
77 // defined in curent .abs section
79 // Character Attributes
80 #define ILLEG 0 // Illegal character (unused)
81 #define DIGIT 1 // 0-9
82 #define HDIGIT 2 // A-F, a-f
83 #define STSYM 4 // A-Z, a-z, _~.
84 #define CTSYM 8 // A-Z, a-z, 0-9, _~$?
85 #define SELF 16 // Single-character tokens: ( ) [ ] etc
86 #define WHITE 32 // Whitespace (space, tab, etc.)
87 #define MULTX 64 // Multiple-character tokens
88 #define DOT 128 // [bwlsBWSL] for what follows a '.'
90 // Macro to check for specific optimizations or override
91 #define CHECK_OPTS(x) (optim_flags[x] && !optimizeOff)
93 // Conditional assembly structures
95 IFENT * if_prev; // Ptr prev .if state block (or NULL)
96 WORD if_state; // 0:enabled, 1:disabled
99 // Pointer to IFILE or IMACRO or IREPT
106 // Ptr to IFILEs, IMACROs, and so on; back-ptr to previous input objects
108 WORD in_type; // 0=IFILE, 1=IMACRO, 2=IREPT
109 IFENT * in_ifent; // Pointer to .if context on entry
110 INOBJ * in_link; // Pointer to previous INOBJ
111 TOKEN * in_otok; // Old `tok' value
112 TOKEN * in_etok; // Old `etok' value
113 IUNION inobj; // IFILE or IMACRO or IREPT
116 // Information about a file
118 IFILE * if_link; // Pointer to ancient IFILEs
119 char * ifoldfname; // Old file's name
120 int ifoldlineno; // Old line number
121 int ifind; // Position in file buffer
122 int ifcnt; // #chars left in file buffer
123 int ifhandle; // File's descriptor
124 WORD ifno; // File number
125 char ifbuf[LNBUFSIZ]; // Line buffer
128 #define TOKENSTREAM struct _tokenstream
130 TOKEN token[32]; // 32 ought to be enough for anybody (including XiA!)
131 char * string[32]; // same for attached strings
134 // Information about a macro invocation
136 IMACRO * im_link; // Pointer to ancient IMACROs
137 LLIST * im_nextln; // Next line to include
138 WORD im_nargs; // # of arguments supplied on invocation
139 WORD im_siz; // Size suffix supplied on invocation
140 LONG im_olduniq; // Old value of 'macuniq'
141 SYM * im_macro; // Pointer to macro we're in
142 char im_lnbuf[LNSIZ]; // Line buffer
143 TOKENSTREAM argument[20]; // Assume no more than 20 arguments in an invocation
146 // Information about a .rept invocation
148 LLIST * ir_firstln; // Pointer to first line
149 LLIST * ir_nextln; // Pointer to next line
150 uint32_t ir_count; // Repeat count (decrements)
151 uint32_t lineno; // Repeat line number (Convert this to global instead of putting it here?)
154 // Exported variables
156 extern uint16_t curlineno;
157 extern char * curfname;
162 extern char tolowertab[];
163 extern INOBJ * cur_inobj;
164 extern int mjump_align;
165 extern char * string[];
166 extern int optimizeOff;
168 // Exported functions
169 int include(int, char *);
170 void InitTokenizer(void);
171 void SetFilenameForErrorReporting(void);
172 int TokenizeLine(void);
175 INOBJ * a_inobj(int);
176 void DumpToken(TOKEN);
177 void DumpTokenBuffer(void);
179 #endif // __TOKEN_H__