diff --git a/.gitignore b/.gitignore index 0715c8b..76bd36e 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ eaxhla eaxcc .gdb_history *.pp +library/tommyds/ diff --git a/Makefile b/Makefile index 034c17b..29e9f47 100644 --- a/Makefile +++ b/Makefile @@ -62,8 +62,8 @@ bootstrap: ./library/bootstrap.sh test: ${OUT} - fcpp -C -LL debug/xop.eax > debug/xop.eax.pp - ${WRAP} ./${OUT} debug/xop.eax.pp + #fcpp -C -LL debug/xop.eax > debug/xop.eax.pp + ${WRAP} ./${OUT} debug/xop.eax clean: -rm ${OUT} ${OBJECT} ${GENOBJECT} ${GENSOURCE} diff --git a/debug/xop.eax b/debug/xop.eax index 7dd17d3..f6e6bf7 100644 --- a/debug/xop.eax +++ b/debug/xop.eax @@ -6,7 +6,7 @@ * It is distributed in the hope that it will be useful or harmful, it really depends... But no warranty what so ever, seriously. See GNU/GPLv3. */ -#include +/* #include */ fast procedure highlight @@ -37,16 +37,16 @@ end procedure unix program xop - s32 file = -1; - s32 size = 0; - s32 offset = 0; + s32 file = -1 + s32 size = 0 + s32 offset = 0 - u8 buffer = NULL; + u8 buffer = 0 begin if /* argc != 2 */ then - fatal_failure(1, "xop: xop input") + fastcall fatal_failure 1 "xop: xop input" end if fastcall file_open [argv + 1] O_RDONLY diff --git a/source/eaxhla.l b/source/eaxhla.l index 7e5d34d..b406c89 100644 --- a/source/eaxhla.l +++ b/source/eaxhla.l @@ -1,15 +1,24 @@ %{ + #include #include "eaxhla.tab.h" + + char * string_literal_buffer; + int string_litral_buffer_size = 0; + int string_litral_buffer_capacity = 128; + + #define YY_USER_INIT \ + string_literal_buffer = malloc(128); %} %option noyywrap -identifier [A-Za-z_][A-z0-9_]* +identifier [A-Za-z_][A-Za-z0-9_]* wsnl [ \t\r\v\f\n] hex [0123456789abcdef] uhex [0123456789ABCDEF] %x IN_COMMENT IN_MULTILINE_COMMENT +%x IN_STRING // XXX: ?! %x IN_DECLARE @@ -49,6 +58,7 @@ unix{wsnl}+ { return UNIX; } \$rip{wsnl}+ { return RIP; } in{wsnl}+ { return TIN; } +\= { return '='; } s8{wsnl}+ { return S8; } s16{wsnl}+ { return S16; } @@ -78,6 +88,25 @@ u64{wsnl}+ { return U64; } return LITERAL; } +\" { BEGIN IN_STRING; } + +{ + /* XXX: escapes */ +\" { + BEGIN INITIAL; + yylval.strval = strdup(string_literal_buffer); + return LITERAL; +} +. { + string_litral_buffer_size += yyleng; + if (string_litral_buffer_size > string_litral_buffer_capacity) { + string_litral_buffer_capacity *= 2; + realloc(string_literal_buffer, string_litral_buffer_capacity); + } + memcpy(string_literal_buffer + string_litral_buffer_size, yytext, yyleng); + } +} + xor{wsnl}+ { return TXOR; } inc{wsnl}+ { return TINC; } @@ -106,6 +135,8 @@ fastcall{wsnl}+ { return FASTCALL; } {identifier}{wsnl}+ { yylval.strval = strdup(yytext); return IDENTIFIER; } +. { yyerror(); } + %% void set_state(int state) { @@ -121,4 +152,6 @@ void yyfree_leftovers(void) { for (size_t i = 0; i < yy_buffer_stack_max; i++) { free(yy_buffer_stack[i]); } + + free(string_literal_buffer); } diff --git a/source/eaxhla.y b/source/eaxhla.y index 994ad8e..f30ca8a 100644 --- a/source/eaxhla.y +++ b/source/eaxhla.y @@ -109,6 +109,7 @@ declaration_section: %empty ; declaration: origin type IDENTIFIER { $2.name = $3; /* add_var($1); */ free($3); } + | origin type IDENTIFIER '=' LITERAL { $2.name = $3; /* add_var($1); */ free($3); } ; origin: %empty