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 //===================================================================
28 //============================ lex.c ================================
29 //===================================================================
31 FILE *file; /* file handler */
32 char *name; /* name of file */
37 int last; /* last token */
38 int current; /* current token */
40 int length; /* bytes left to parse */
41 int size; /* never changes (size of file) */
42 int line; /* what line are we on? */
46 * It's important that this table never exceed 32 keywords, the ascii
47 * table starts at 33 (and we don't want conflicts)
54 #define TOKEN_CONTINUE 5
55 #define TOKEN_RETURN 6
57 #define TOKEN_FOR 8 // extension
58 #define TOKEN_TYPEDEF 9 // extension
60 // ensure the token types are out of the
61 // bounds of anyothers that may conflict.
62 #define TOKEN_FLOAT 110
63 #define TOKEN_VECTOR 111
64 #define TOKEN_STRING 112
65 #define TOKEN_ENTITY 113
66 #define TOKEN_VOID 114
69 * Lexer state constants, these are numbers for where exactly in
70 * the lexing the lexer is at. Or where it decided to stop if a lexer
71 * error occurs. These numbers must be > where the ascii-table ends
72 * and > the last type token which is TOKEN_VOID
74 #define LEX_COMMENT 1128
75 #define LEX_CHRLIT 1129
76 #define LEX_STRLIT 1130
77 #define LEX_IDENT 1131
79 int lex_token (struct lex_file *);
80 void lex_reset (struct lex_file *);
81 void lex_close (struct lex_file *);
82 struct lex_file *lex_include(struct lex_file *, char *);
83 struct lex_file *lex_open (FILE *);
85 //===================================================================
86 //========================== error.c ================================
87 //===================================================================
88 #define ERROR_LEX (SHRT_MAX+0)
89 #define ERROR_PARSE (SHRT_MAX+1)
90 #define ERROR_INTERNAL (SHRT_MAX+2)
91 #define ERROR_COMPILER (SHRT_MAX+3)
92 #define ERROR_PREPRO (SHRT_MAX+4)
93 int error(int, const char *, ...);
95 //===================================================================
96 //========================== parse.c ================================
97 //===================================================================
98 int parse_gen(struct lex_file *);
100 //===================================================================
101 //========================== typedef.c ==============================
102 //===================================================================
103 typedef struct typedef_node_t {
108 void typedef_clear();
109 typedef_node *typedef_find(const char *);
110 int typedef_add (const char *, const char *);
113 //===================================================================
114 //=========================== util.c ================================
115 //===================================================================
116 void *util_memory_a(unsigned int, unsigned int, const char *);
117 void util_memory_d(void *, unsigned int, const char *);
118 char *util_strdup (const char *);
121 # define mem_a(x) malloc(x)
122 # define mem_d(x) free (x)
124 # define mem_a(x) util_memory_a((x), __LINE__, __FILE__)
125 # define mem_d(x) util_memory_d((x), __LINE__, __FILE__)
128 #define VECTOR_MAKE(T,N) \
129 T* N##_data = NULL; \
130 long N##_elements = 0; \
131 long N##_allocated = 0; \
132 int N##_add(T element) { \
133 if (N##_elements == N##_allocated) { \
134 if (N##_allocated == 0) { \
135 N##_allocated = 12; \
137 N##_allocated *= 2; \
139 void *temp = realloc(N##_data, (N##_allocated * sizeof(T))); \
144 N##_data = (T*)temp; \
146 N##_data[N##_elements] = element; \
147 return N##_elements++; \
150 //===================================================================
151 //=========================== code.c ================================
152 //===================================================================
154 #define TYPE_STRING 1
156 #define TYPE_VECTOR 3
157 #define TYPE_ENTITY 4
159 #define TYPE_FUNCTION 6
160 #define TYPE_POINTER 7
163 * Each paramater incerements by 3 since vector types hold
164 * 3 components (x,y,z).
168 #define OFS_PARM0 (OFS_RETURN+3)
169 #define OFS_PARM1 (OFS_PARM0 +3)
170 #define OFS_PARM2 (OFS_PARM1 +3)
171 #define OFS_PARM3 (OFS_PARM2 +3)
172 #define OFS_PARM4 (OFS_PARM3 +3)
173 #define OFS_PARM5 (OFS_PARM4 +3)
174 #define OFS_PARM6 (OFS_PARM5 +3)
175 #define OFS_PARM7 (OFS_PARM6 +3)
179 * These are the external instructions supported by the interperter
180 * this is what things compile to (from the C code).