prog_header code_header;
void code_write() {
+ #if 0
/* Add test program */
code_strings_add('\0');
code_functions_add((prog_section_function){0, 0, 0, 0, .name=0, 0, 0, {0}}); /* NULL */
code_functions_add((prog_section_function){1, 0, 0, 0, .name=1, 0, 0, {0}}); /* m_init */
- code_functions_add((prog_section_function){-2, 0, 0, 0, .name=8, 0, 0, {0}}); /* print */
+ code_functions_add((prog_section_function){-4, 0, 0, 0, .name=8, 0, 0, {0}}); /* print */
code_functions_add((prog_section_function){0, 0, 0, 0, .name=14+13, 0,0, {0}}); /* m_keydown */
code_functions_add((prog_section_function){0, 0, 0, 0, .name=14+13+10, 0,0, {0}});
code_functions_add((prog_section_function){0, 0, 0, 0, .name=14+13+10+7, 0,0, {0}});
code_header.globals = (prog_section){code_header.functions.offset + sizeof(prog_section_function) *code_functions_elements, code_globals_elements };
code_header.strings = (prog_section){code_header.globals.offset + sizeof(int) *code_globals_elements, code_strings_elements };
code_header.entfield = 0; /* TODO: */
-
+ #endif
+
+ /* write out everything one SHOT! */
FILE *fp = fopen("program.dat", "wb");
fwrite(&code_header, 1, sizeof(prog_header), fp);
fwrite(code_statements_data, 1, sizeof(prog_section_statement)*code_statements_elements, fp);
if (typedef_find(file->lastok))
TEST_TYPE(typedef_find(file->lastok)->name);
+ #undef TEST_TYPE
return LEX_IDENT;
}
return ch;
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
-#include <stdlib.h>
-#include <string.h>
-#include <limits.h>
-#include "gmqcc.h"
+# include <stdlib.h>
+ #include <string.h>
+# include <limits.h>
+ # include "gmqcc.h"
int main(int argc, char **argv) {
argc--;
#include <limits.h>
#include <stdlib.h>
#include <string.h>
+#include <ctype.h>
#include "gmqcc.h"
/*
case TOKEN_CONTINUE:
PARSE_TREE_ADD(PARSE_TYPE_CONTINUE);
break;
-
+
+ /*
+ * DO loops work like so:
+ * __do_loop_beg:
+ * IFNOT __do_loop_beg#
+ * GOTO __do_loop_end
+ * INSTR1
+ * INSTR2
+ * ......
+ * GOTO __do_loop_beg
+ */
+
case TOKEN_DO: PARSE_PERFORM(PARSE_TYPE_DO, {});
case TOKEN_WHILE: PARSE_PERFORM(PARSE_TYPE_WHILE, {});
case TOKEN_BREAK: PARSE_PERFORM(PARSE_TYPE_BREAK, {});
* which are higer than the ascii table.)
*/
case '#':
+ token = lex_token(file); /* skip '#' */
+ while (isspace(token)) {
+ if (token == '\n') {
+ return error(ERROR_PARSE, "Expected valid preprocessor directive after `#` %s\n");
+ }
+ token = lex_token(file); /* try again */
+ }
/*
- * Skip the preprocessor for now: We'll implement our own
- * eventually. For now we need to make sure directives are
- * not accidently tokenized.
+ * If we make it here we found a directive, the supported
+ * directives so far are #include.
*/
- token = lex_token(file);
- token = lex_token(file);
-
+ if (strncmp(file->lastok, "include", sizeof("include")) == 0) {
+ //lex_include("file");
+ /*
+ * We need to compose a name till we find either a
+ * '"',> or a <, (for includes), if we hit a '\n' then
+ * clearly the person miswrote the include.
+ */
+ while (*file->lastok != '"' && token != '\n')
+ token = lex_token(file);
+
+ if (token == '\n')
+ return error(ERROR_PARSE, "Invalid use of include preprocessor directive: wanted #include \"file.h\"\n");
+
+
+ //lex_token(file);
+ //lex_token(file);
+ printf("include: %s\n", file->lastok);
+ }
+
/* skip all tokens to end of directive */
while (token != '\n')
token = lex_token(file);
--- /dev/null
+/*
+ * all of these includes should work. No matter what the spacing
+ * is, we rely on it.
+ */
+#include "include.h"
+#include "include.h"
+ #include "include.h"
+ #include "include.h"
+ #include "include.h"
+# include "include.h"
+ # include "include.h"
+#include "include.h"
+# include "include.h"
strncmp(from, "void", sizeof("void")) == 0) {
typedef_table[hash] = mem_a(sizeof(typedef_node));
- typedef_table[hash]->name = strdup(from);
+ typedef_table[hash]->name = util_strdup(from);
return -100;
} else {
/* search the typedefs for it (typedef-a-typedef?) */