2 // RMAC - Reboot's Macro Assembler for the Atari Jaguar Console System
3 // TOKEN.H - Token Handling
4 // Copyright (C) 199x Landon Dyer, 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
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 256 // 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 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' // ::
48 #define NE 'k' // <> or !=
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 ENDEXPR 'E' // End of expression
59 #define CR_DEFINED 'p' // ^^defined - is symbol defined?
60 #define CR_REFERENCED 'q' // ^^referenced - was symbol referenced?
61 #define CR_STREQ 'v' // ^^streq - compare two strings
62 #define CR_MACDEF 'w' // ^^macdef - is macro defined?
63 #define CR_TIME 'x' // ^^time - DOS format time
64 #define CR_DATE 'y' // ^^date - DOS format date
65 #define CR_ABSCOUNT 'z' // ^^abscount - count the number of bytes defined in curent .abs section
67 // Character Attributes
68 #define ILLEG 0 // Illegal character (unused)
69 #define DIGIT 1 // 0-9
70 #define HDIGIT 2 // A-F, a-f
71 #define STSYM 4 // A-Z, a-z, _~.
72 #define CTSYM 8 // A-Z, a-z, 0-9, _~$?
73 #define SELF 16 // Single-character tokens: ( ) [ ] etc
74 #define WHITE 32 // Whitespace (space, tab, etc.)
75 #define MULTX 64 // Multiple-character tokens
76 #define DOT 128 // [bwlsBWSL] for what follows a `.'
78 // "special" string types
79 #define NORMAL 0 // Standard for PC/ST/whatever
80 #define A8INT 1 // Atari 800 ATASCII translation
81 #define PETSCII 2 // lol
82 #define ORICSCII 3 // lolol
84 // Conditional assembly structures
86 IFENT * if_prev; // Ptr prev .if state block (or NULL)
87 WORD if_state; // 0:enabled, 1:disabled
90 // Pointer to IFILE or IMACRO
97 // Ptr to IFILEs, IMACROs, and so on; back-ptr to previous input objects
99 WORD in_type; // 0=IFILE, 1=IMACRO ...
100 IFENT * in_ifent; // Pointer to .if context on entry
101 INOBJ * in_link; // Pointer to previous INOBJ
102 TOKEN * in_otok; // Old `tok' value
103 TOKEN * in_etok; // Old `etok' value
104 IUNION inobj; // IFILE or IMACRO ...
107 // Information about a file
109 IFILE * if_link; // Pointer to ancient IFILEs
110 char * ifoldfname; // Old file's name
111 int ifoldlineno; // Old line number
112 int ifind; // Position in file buffer
113 int ifcnt; // #chars left in file buffer
114 int ifhandle; // File's descriptor
115 WORD ifno; // File number
116 char ifbuf[LNBUFSIZ]; // Line buffer
119 #define TOKENSTREAM struct _tokenstream
121 TOKEN token[32]; // 32 ought to be enough for anybody (including XiA!)
122 char * string[32]; // same for attached strings
125 // Information about a macro invocation
127 IMACRO * im_link; // Pointer to ancient IMACROs
128 struct LineList * im_nextln; // Next line to include
129 WORD im_nargs; // # of arguments supplied on invocation
130 WORD im_siz; // Size suffix supplied on invocation
131 LONG im_olduniq; // Old value of 'macuniq'
132 SYM * im_macro; // Pointer to macro we're in
133 char im_lnbuf[LNSIZ]; // Line buffer
134 uint32_t argBase; // Base in argPtrs[] for current macro
135 TOKENSTREAM argument[20]; // Assume no more than 20 arguments in an invocation
138 // Information about a .rept invocation
140 LONG * ir_firstln; // Pointer to first line
141 LONG * ir_nextln; // Pointer to next line
142 VALUE ir_count; // Repeat count (decrements)
145 // Exported variables
147 extern int curlineno;
148 extern char * curfname;
153 extern char tolowertab[];
154 extern INOBJ * cur_inobj;
155 extern int mjump_align;
156 extern char * string[];
158 // Exported functions
159 int include(int, char *);
160 void InitTokenizer(void);
161 void SetFilenameForErrorReporting(void);
162 int TokenizeLine(void);
165 INOBJ * a_inobj(int);
166 void DumpTokenBuffer(void);
168 #endif // __TOKEN_H__