diff --git a/asm-savers.h b/asm-savers.h index b69683a..c807612 100644 --- a/asm-savers.h +++ b/asm-savers.h @@ -1,15 +1,20 @@ #if (!defined(NTSYS__S_ASSEMBLER_H___)) #define NTSYS__S_ASSEMBLER_H___ +#define create_ntsys_asm_parser(cache, str, table) ((ntsys_argument_parser_t){(cache), (str), (table)}) #define create_ntsys_asm_save(ss) ((ntsys_asm_save_t){(ss), (ss)}) #define create_ntsys_asm_cache(ss) ((ntsys_asm_cache_t)&(ss)) #define ntsys_asm_arg_new(str, __cache) ((ntsys_get_arg((__cache))) && ((str) = __cache->string)) +#define ntsys_asm_arg_or_zero_len_str(str, __cache) ((((ntsys_get_arg((__cache))) && ((str) = __cache->string)) == NULL) ? ("") : (str)) + +/* + * #define __SPACE_SHIFT while (is_space(st[pos])) { pos ++; } + * #define __NEXT_ARG {__e_byte_t isStr = 0;while (!is_space(st[save]) || isStr == 1) { if (st[save] == '"' && st[save - 1] != '\\') {isStr = !isStr;}save ++; }}while (is_space(st[save])) { save ++; }{size_t n_p = save;__e_byte_t isStr = 0;while (!is_space(st[n_p]) || isStr == 1) { if (st[n_p] == '"' && st[n_p - 1] != '\\') {isStr = !isStr;}n_p ++; }st[n_p] = '\0';} + * #define get_mem_pos() *mem_pos = ftell(fp) == 0 ? 0 : ftell(fp) - 1; + */ #define __READ_FILE_WITH_EOF_OR_LN ((c = getc(fp)) != EOF && c != '\n' && c != '\r') #define is_space(c) (c >= 0 && c <= 32) -#define __SPACE_SHIFT while (is_space(st[pos])) { pos ++; } -#define __NEXT_ARG {__e_byte_t isStr = 0;while (!is_space(st[save]) || isStr == 1) { if (st[save] == '"' && st[save - 1] != '\\') {isStr = !isStr;}save ++; }}while (is_space(st[save])) { save ++; }{size_t n_p = save;__e_byte_t isStr = 0;while (!is_space(st[n_p]) || isStr == 1) { if (st[n_p] == '"' && st[n_p - 1] != '\\') {isStr = !isStr;}n_p ++; }st[n_p] = '\0';} -#define get_mem_pos() *mem_pos = ftell(fp) == 0 ? 0 : ftell(fp) - 1; char* ntsys_get_str(char* ptr, FILE* fp) { if (ptr != NULL) { @@ -39,6 +44,8 @@ char* ntsys_get_str(char* ptr, FILE* fp) { return ptr; } +#undef __READ_FILE_WITH_EOF_OR_LN + typedef struct { char* string; char* cache; @@ -119,4 +126,17 @@ char* ntsys_get_arg(ntsys_asm_cache_t save) { return str; } +typedef struct { + ntsys_asm_cache_t cache; + char* string; + char** table; +} ntsys_argument_parser_t; + +int ntsys_run_asm_parser(ntsys_argument_parser_t parser) { + ntsys_asm_arg_new(parser.string, parser.cache); + return EXIT_SUCCESS; +} + +#undef is_space + #endif \ No newline at end of file diff --git a/ntsys b/ntsys index fc8c00a..ace9875 100755 Binary files a/ntsys and b/ntsys differ diff --git a/ntsys-assembler.h b/ntsys-assembler.h index f393dcb..033568a 100644 --- a/ntsys-assembler.h +++ b/ntsys-assembler.h @@ -5,13 +5,15 @@ #include "asm-savers.h" +char* ntsys_asm_table[] = { + "print" +}; + int ntsys_asm_from_string(size_t* mempos, char* str, FILE* fp) { ntsys_asm_save_t __save = create_ntsys_asm_save(str); ntsys_asm_cache_t __cache = create_ntsys_asm_cache(__save); - while (ntsys_asm_arg_new(str, __cache)) { - puts(str); - } - return EXIT_SUCCESS; + ntsys_argument_parser_t __parser = create_ntsys_asm_parser(__cache, str, ntsys_asm_table); + return ntsys_run_asm_parser(__parser); } int ntsys_compile_asm(char* filename, char* asm_out) {