Labels positioner

This commit is contained in:
german 2026-03-05 18:07:12 +04:00
parent a5f7f103c0
commit 34d8d0a6d8
3 changed files with 23 additions and 8 deletions

View File

@ -3,7 +3,7 @@
#define ntsys_exit_if_error(parser) if (!ntsys_asm_arg_new((parser)->string, (parser)->cache)) #define ntsys_exit_if_error(parser) if (!ntsys_asm_arg_new((parser)->string, (parser)->cache))
#define ntsys_run_asm_parser(ss) __ntsys_arg_function_loader(&(ss)) #define ntsys_run_asm_parser(ss) __ntsys_arg_function_loader(&(ss))
#define create_ntsys_asm_parser(cache, fp, str, table, table_size, labels) ((ntsys_argument_parser_t){(cache), (fp), (str), (table), (table_size), (labels)}) #define create_ntsys_asm_parser(cache, fp, str, table, table_size, labels) ((ntsys_argument_parser_t){(cache), (fp), (str), (table), (table_size), (labels), NULL, 0, 0})
#define create_ntsys_asm_save(ss) ((ntsys_asm_save_t){(ss), (ss)}) #define create_ntsys_asm_save(ss) ((ntsys_asm_save_t){(ss), (ss)})
#define create_ntsys_asm_cache(ss) ((ntsys_asm_cache_t)&(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_new(str, __cache) ((ntsys_get_arg((__cache))) && ((str) = __cache->string))
@ -136,6 +136,9 @@ typedef struct {
char** table; char** table;
size_t table_length; size_t table_length;
char** labels; char** labels;
word_t* labels_positions;
size_t labels_count;
byte_t is_rewrite;
} ntsys_argument_parser_t; } ntsys_argument_parser_t;
static void __input_datatype(ntsys_argument_parser_t* parser, byte_t* mode) { static void __input_datatype(ntsys_argument_parser_t* parser, byte_t* mode) {
@ -173,7 +176,19 @@ static void __input_datatype(ntsys_argument_parser_t* parser, byte_t* mode) {
} }
static void __write_label(ntsys_argument_parser_t* parser) { static void __write_label(ntsys_argument_parser_t* parser) {
if (parser->is_rewrite == 0) {
putc('E', parser->fp);
putc('F', parser->fp);
return;
}
size_t i = 0;
while (i < parser->labels_count) {
if (strcmp(parser->string, parser->labels[i]) == 0) {
fwrite(&(parser->labels_positions[i]), 1, sizeof(word_t), parser->fp);
return;
}
i ++;
}
} }
static void __input_data(ntsys_argument_parser_t* parser, byte_t* mode) { static void __input_data(ntsys_argument_parser_t* parser, byte_t* mode) {
@ -226,12 +241,12 @@ static void __input_data(ntsys_argument_parser_t* parser, byte_t* mode) {
} }
static int __arg_writer(char* str, ntsys_argument_parser_t* parser, byte_t mode) { static int __arg_writer(char* str, ntsys_argument_parser_t* parser, byte_t* mode) {
if (str[0] == ':') { if (str[0] == ':') {
if (str[1] == 'T') { if (str[1] == 'T') {
__input_datatype(parser, &mode); __input_datatype(parser, mode);
} else if (str[1] == 'D') { } else if (str[1] == 'D') {
__input_data(parser, &mode); __input_data(parser, mode);
} }
} else { } else {
byte_t x = strtol(str, NULL, 16); byte_t x = strtol(str, NULL, 16);
@ -242,8 +257,9 @@ static int __arg_writer(char* str, ntsys_argument_parser_t* parser, byte_t mode)
static int select_argument(ntsys_argument_parser_t* parser) { static int select_argument(ntsys_argument_parser_t* parser) {
size_t i = 0; size_t i = 0;
byte_t internal = 0x00;
char* str = parser->string; char* str = parser->string;
if (str[strlen(str) - 1] == ':') { if (str[strlen(str) - 1] == ':' && !parser->is_rewrite) {
/* TODO: Добавить метки */ /* TODO: Добавить метки */
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
@ -259,12 +275,11 @@ static int select_argument(ntsys_argument_parser_t* parser) {
buf[t] = '\0'; buf[t] = '\0';
if (strcmp(str, buf) == 0) { if (strcmp(str, buf) == 0) {
char* se = &table[i][t + 1]; char* se = &table[i][t + 1];
byte_t internal = 0x00;
while (strlen(se) > 1) { while (strlen(se) > 1) {
char is[3]; char is[3];
strncpy(is, se, 2); strncpy(is, se, 2);
is[2] = '\0'; is[2] = '\0';
if (__arg_writer(is, parser, internal) == EXIT_FAILURE) { if (__arg_writer(is, parser, &internal) == EXIT_FAILURE) {
ntsys_error("Internal program error!"); ntsys_error("Internal program error!");
return EXIT_FAILURE; return EXIT_FAILURE;
} }

BIN
ntsys

Binary file not shown.

BIN
out.exe

Binary file not shown.