5 * Permission is hereby granted, free of charge, to any person obtaining a copy of
6 * this software and associated documentation files (the "Software"), to deal in
7 * the Software without restriction, including without limitation the rights to
8 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
9 * of the Software, and to permit persons to whom the Software is furnished to do
10 * so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in all
13 * copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27 /* The types supported by the language */
34 #define TYPE_FUNCTION 6
35 #define TYPE_POINTER 7
38 * there are 3 accessible memory zones -
40 * array of 32bit ints/floats, mixed, LE,
42 * structure is up to the engine but the fields are a linear array
43 * of mixed ints/floats, there are globals referring to the offsets
44 * of these in the entity struct so there are ADDRESS and STOREP and
45 * LOAD instructions that use globals containing field offsets.
47 * a static array in the progs.dat, with file parsing creating
48 * additional constants, and some engine fields are mapped by
49 * address as well to unique string offsets
54 * These are the external instructions supported by the interperter
55 * this is what things compile to (from the C code). This is not internal
56 * instructions for support like int, and such (which are translated)
60 #define INSTR_MUL_F 1 /* multiplication float */
61 #define INSTR_MUL_V 2 /* multiplication vector */
62 #define INSTR_MUL_FV 3 /* multiplication float->vector */
63 #define INSTR_MUL_VF 4 /* multiplication vector->float */
74 #define INSTR_EQ_FNC 14
79 #define INSTR_NE_FNC 19
86 #define INSTR_LOAD_F 24
87 #define INSTR_LOAD_V 25
88 #define INSTR_LOAD_S 26
89 #define INSTR_LOAD_ENT 27
90 #define INSTR_LOAD_FLD 28
91 #define INSTR_LOAD_FNC 29
92 #define INSTR_STORE_F 31
93 #define INSTR_STORE_V 32
94 #define INSTR_STORE_S 33
95 #define INSTR_STORE_ENT 34
96 #define INSTR_STORE_FLD 35
97 #define INSTR_STORE_FNC 36
99 #define INSTR_ADDRESS 30
100 #define INSTR_RETURN 37
101 #define INSTR_NOT_F 38
102 #define INSTR_NOT_V 39
103 #define INSTR_NOT_S 40
104 #define INSTR_NOT_ENT 41
105 #define INSTR_NOT_FNC 42
107 #define INSTR_IFNOT 44
108 #define INSTR_CALL0 45
109 #define INSTR_CALL1 46
110 #define INSTR_CALL2 47
111 #define INSTR_CALL3 48
112 #define INSTR_CALL4 49
113 #define INSTR_CALL5 50
114 #define INSTR_CALL6 51
115 #define INSTR_CALL7 52
116 #define INSTR_CALL8 53
117 #define INSTR_STATE 54
118 #define INSTR_GOTO 55
121 #define INSTR_BITAND 59
122 #define INSTR_BITOR 60
124 #define mem_a(x) malloc(x)
125 #define mem_d(x) free (x)
128 * This is the smallest lexer I've ever wrote: and I must say, it's quite
129 * more nicer than those large bulky complex parsers that most people write
130 * which has some sort of a complex state.
134 * This is a simple state for lexing, no need to be complex for qc
135 * code. It's trivial stuff.
138 char peek[5]; /* extend for depthier peeks */
143 char lastok[8192]; /* No token shall ever be bigger than this! */
147 * It's important that this table never exceed 32 keywords, the ascii
148 * table starts at 33 (which we need)
153 #define TOKEN_WHILE 3
154 #define TOKEN_BREAK 4
155 #define TOKEN_CONTINUE 5
156 #define TOKEN_RETURN 6
161 * Lexer state constants, these are numbers for where exactly in
162 * the lexing the lexer is at. Or where it decided to stop if a lexer
165 #define LEX_COMMENT 128 /* higher than ascii */
166 #define LEX_CHRLIT 129
167 #define LEX_STRLIT 130
168 #define LEX_IDENT 131
172 #define LEX_WHILE 135
173 #define LEX_INCLUDE 136
174 #define LEX_DEFINE 137
176 int lex_token(struct lex_file *);
177 void lex_reset(struct lex_file *);
178 int lex_debug(struct lex_file *);
179 int lex_close(struct lex_file *);
180 struct lex_file *lex_open (const char *);
183 #define ERROR_LEX (SHRT_MAX+0)
184 #define ERROR_PARSE (SHRT_MAX+1)
185 #define ERROR_INTERNAL (SHRT_MAX+2)
186 #define ERROR_COMPILER (SHRT_MAX+3)
187 int error(int, const char *, ...);
190 int parse(struct lex_file *);