]> Shamusworld >> Repos - rmac/blob - token.h
Fix for USP token, submitted by ggn.
[rmac] / token.h
1 //
2 // RMAC - Reboot's Macro Assembler for the Atari Jaguar Console System
3 // TOKEN.H - Token Handling
4 // Copyright (C) 199x Landon Dyer, 2011 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 //#include "risca.h"
14
15 // Include Files and Macros
16 #define SRC_IFILE       0                                   // Input source is IFILE
17 #define SRC_IMACRO      1                                   // Input source is IMACRO
18 #define SRC_IREPT       2                                   // Input source is IREPT
19
20 // Macros
21 #define INOBJ           struct _inobj
22 #define IUNION          union _iunion
23 #define IFILE           struct _incldfile
24 #define IMACRO          struct _imacro
25 #define IREPT           struct _irept
26 #define IFENT           struct _ifent
27
28 // Tunable definitions
29 #define LNSIZ           256                                 // Maximum size of a line of text
30 #define TOKBUFSIZE      400                                 // 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
34
35 // (Normally) non-printable tokens
36 #define COLON           ':'                                 // : (grumble: GNUmacs hates ':')
37 #define CONST           'a'                                 // CONST <value>
38 #define ACONST          'A'                                 // ACONST <value> <attrib>
39 #define STRING          'b'                                 // 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             149                                 // Set
45 #define REG             'R'                                 // Reg
46 #define DCOLON          'h'                                 // ::
47 #define GE              'i'                                 // >= 
48 #define LE              'j'                                 // <= 
49 #define NE              'k'                                 // <> or != 
50 #define SHR             'l'                                 // >> 
51 #define SHL             'm'                                 // << 
52 #define UNMINUS         'n'                                 // Unary '-' 
53 #define DOTB            'B'                                 // .b or .B or .s or .S 
54 #define DOTW            'W'                                 // .w or .W 
55 #define DOTL            'L'                                 // .l or .L 
56 #define DOTI            'I'                                 // .l or .L 
57 #define ENDEXPR         'E'                                 // End of expression 
58
59 // ^^ operators
60 #define CR_DEFINED      'p'                                 // ^^defined - is symbol defined?
61 #define CR_REFERENCED   'q'                                 // ^^referenced - was symbol referenced?
62 #define CR_STREQ        'v'                                 // ^^streq - compare two strings
63 #define CR_MACDEF       'w'                                 // ^^macdef - is macro defined?
64 #define CR_TIME         'x'                                 // ^^time - DOS format time
65 #define CR_DATE         'y'                                 // ^^date - DOS format date
66
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 `.'
77
78 // Conditional assembly structures
79 IFENT {
80    IFENT *if_prev;                                          // Ptr prev .if state block (or NULL)
81    WORD if_state;                                           // 0:enabled, 1:disabled
82 };
83
84 // Pointer to IFILE or IMACRO
85 IUNION {
86    IFILE *ifile;
87    IMACRO *imacro;
88    IREPT *irept;
89 };
90
91 // Ptr to IFILEs, IMACROs, and so on; back-ptr to previous input objects
92 INOBJ {
93    WORD in_type;                                            // 0=IFILE, 1=IMACRO ...
94    IFENT *in_ifent;                                                 // Pointer to .if context on entry
95    INOBJ *in_link;                                                  // Pointer to previous INOBJ
96    TOKEN *in_otok;                                                  // Old `tok' value
97    TOKEN *in_etok;                                                  // Old `etok' value
98    IUNION inobj;                                                            // IFILE or IMACRO ...
99 };
100
101 // Information about a file
102 IFILE {
103    IFILE *if_link;                                          // Pointer to ancient IFILEs
104    char *ifoldfname;                                        // Old file's name
105    int ifoldlineno;                                         // Old line number
106    int ifind;                                               // Position in file buffer
107    int ifcnt;                                               // #chars left in file buffer 
108    int ifhandle;                                            // File's descriptor
109    WORD ifno;                                               // File number
110    char ifbuf[LNBUFSIZ];                                    // Line buffer
111 };
112
113 // Information about a macro invocation
114 IMACRO {
115    IMACRO *im_link;                                         // Pointer to ancient IMACROs
116    LONG *im_nextln;                                         // Next line to include
117    WORD im_nargs;                                           // # of arguments supplied on invocation
118    WORD im_siz;                                             // Size suffix supplied on invocation
119    LONG im_olduniq;                                         // Old value of 'macuniq'
120    SYM *im_macro;                                           // Pointer to macro we're in
121    char im_lnbuf[LNSIZ];                                    // Line buffer
122 };
123
124 // Information about a .rept invocation
125 IREPT {
126    LONG *ir_firstln;                                        // Pointer to first line
127    LONG *ir_nextln;                                         // Pointer to next line
128    VALUE ir_count;                                          // Repeat count (decrements)
129 };
130
131 // Globals, externals etc
132 extern int lnsave;
133 extern int curlineno;
134 extern char *curfname;
135 extern WORD cfileno;
136 extern TOKEN *tok;
137 extern char lnbuf[];
138 extern char lntag;
139 extern char tolowertab[];
140 extern INOBJ *cur_inobj;
141 extern unsigned orgactive;
142 extern unsigned orgaddr;
143 extern LONG sloc;
144 extern int mjump_align;
145
146 // Prototypes
147 int include(int, char *);
148 void init_token(void);
149 void setfnum(WORD);
150 int tokln(void);
151 int fpop(void);
152 //int d_goto(WORD);
153 int d_goto(void);
154 INOBJ *a_inobj(int);
155
156 #endif // __TOKEN_H__