]> Shamusworld >> Repos - rmac/blob - token.h
1f57c905589428db0bf95ca7054f6ee0aa36d898
[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 #ifndef __TOKEN_H__
9 #define __TOKEN_H__
10
11 #include "rmac.h"
12 //#include "risca.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           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
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 ENDEXPR         'E'                                 // End of expression 
57
58 // ^^ operators
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
66 // Character Attributes
67 #define ILLEG           0                                   // Illegal character (unused)
68 #define DIGIT           1                                   // 0-9
69 #define HDIGIT          2                                   // A-F, a-f
70 #define STSYM           4                                   // A-Z, a-z, _~.
71 #define CTSYM           8                                   // A-Z, a-z, 0-9, _~$?
72 #define SELF            16                                  // Single-character tokens: ( ) [ ] etc
73 #define WHITE           32                                  // Whitespace (space, tab, etc.)
74 #define MULTX           64                                  // Multiple-character tokens
75 #define DOT             128                                 // [bwlsBWSL] for what follows a `.'
76
77 // Conditional assembly structures
78 IFENT {
79    IFENT *if_prev;                                          // Ptr prev .if state block (or NULL)
80    WORD if_state;                                           // 0:enabled, 1:disabled
81 };
82
83 // Pointer to IFILE or IMACRO
84 IUNION {
85    IFILE *ifile;
86    IMACRO *imacro;
87    IREPT *irept;
88 };
89
90 // Ptr to IFILEs, IMACROs, and so on; back-ptr to previous input objects
91 INOBJ {
92    WORD in_type;                                            // 0=IFILE, 1=IMACRO ...
93    IFENT *in_ifent;                                                 // Pointer to .if context on entry
94    INOBJ *in_link;                                                  // Pointer to previous INOBJ
95    TOKEN *in_otok;                                                  // Old `tok' value
96    TOKEN *in_etok;                                                  // Old `etok' value
97    IUNION inobj;                                                            // IFILE or IMACRO ...
98 };
99
100 // Information about a file
101 IFILE {
102    IFILE *if_link;                                          // Pointer to ancient IFILEs
103    char *ifoldfname;                                        // Old file's name
104    int ifoldlineno;                                         // Old line number
105    int ifind;                                               // Position in file buffer
106    int ifcnt;                                               // #chars left in file buffer 
107    int ifhandle;                                            // File's descriptor
108    WORD ifno;                                               // File number
109    char ifbuf[LNBUFSIZ];                                    // Line buffer
110 };
111
112 // Information about a macro invocation
113 IMACRO {
114    IMACRO *im_link;                                         // Pointer to ancient IMACROs
115    LONG *im_nextln;                                         // Next line to include
116    WORD im_nargs;                                           // # of arguments supplied on invocation
117    WORD im_siz;                                             // Size suffix supplied on invocation
118    LONG im_olduniq;                                         // Old value of 'macuniq'
119    SYM *im_macro;                                           // Pointer to macro we're in
120    char im_lnbuf[LNSIZ];                                    // Line buffer
121 };
122
123 // Information about a .rept invocation
124 IREPT {
125    LONG *ir_firstln;                                        // Pointer to first line
126    LONG *ir_nextln;                                         // Pointer to next line
127    VALUE ir_count;                                          // Repeat count (decrements)
128 };
129
130 // Globals, externals etc
131 extern int lnsave;
132 extern int curlineno;
133 extern char *curfname;
134 extern WORD cfileno;
135 extern TOKEN *tok;
136 extern char lnbuf[];
137 extern char lntag;
138 extern char tolowertab[];
139 extern INOBJ *cur_inobj;
140 extern unsigned orgactive;
141 extern unsigned orgaddr;
142 extern LONG sloc;
143 extern int mjump_align;
144
145 // Prototypes
146 int include(int, char *);
147 void init_token(void);
148 void setfnum(WORD);
149 int tokln(void);
150 int fpop(void);
151 //int d_goto(WORD);
152 int d_goto(void);
153 INOBJ *a_inobj(int);
154
155 #endif // __TOKEN_H__