Modified operand type.

This commit is contained in:
Ulysse Cura 2026-10-11 01:02:38 +02:00
parent 5ce1fddc8d
commit 1a1744fe80
1 changed files with 33 additions and 31 deletions

View File

@ -28,6 +28,8 @@ enum operations_t {
typedef uint8_t operation_t;
typedef int operand_t;
int main(int argc, char *argv[])
{
int status = EXIT_FAILURE;
@ -135,15 +137,15 @@ int main(int argc, char *argv[])
goto end;
}
if(fwrite(&operation, sizeof(operation), 1, intermediate_representation_file) != 1)
if(fwrite(&operation, sizeof(operation_t), 1, intermediate_representation_file) != 1)
{
fprintf(stderr, "Error writing file: %d\n", errno);
goto end;
}
size_t nb = 2;
operand_t nb = 2;
if(fwrite(&nb, sizeof(nb), 1, intermediate_representation_file) != 1)
if(fwrite(&nb, sizeof(operand_t), 1, intermediate_representation_file) != 1)
{
fprintf(stderr, "Error writing file: %d\n", errno);
goto end;
@ -153,15 +155,15 @@ int main(int argc, char *argv[])
{
operation++;
size_t nb;
operand_t nb;
if(fseek(intermediate_representation_file, -sizeof(nb), SEEK_CUR))
if(fseek(intermediate_representation_file, -sizeof(operand_t), SEEK_CUR))
{
fprintf(stderr, "Error seeking file: %d\n", errno);
goto end;
}
if(fread(&nb, sizeof(nb), 1, intermediate_representation_file) != 1)
if(fread(&nb, sizeof(operand_t), 1, intermediate_representation_file) != 1)
{
fprintf(stderr, "Error reading file: %d\n", errno);
goto end;
@ -169,13 +171,13 @@ int main(int argc, char *argv[])
nb++;
if(fseek(intermediate_representation_file, -sizeof(nb), SEEK_CUR))
if(fseek(intermediate_representation_file, -sizeof(operand_t), SEEK_CUR))
{
fprintf(stderr, "Error seeking file: %d\n", errno);
goto end;
}
if(fwrite(&nb, sizeof(nb), 1, intermediate_representation_file) != 1)
if(fwrite(&nb, sizeof(operand_t), 1, intermediate_representation_file) != 1)
{
fprintf(stderr, "Error writing file: %d\n", errno);
goto end;
@ -183,7 +185,7 @@ int main(int argc, char *argv[])
}
else
{
if(fwrite(&operation, sizeof(operation), 1, intermediate_representation_file) != 1)
if(fwrite(&operation, sizeof(operation_t), 1, intermediate_representation_file) != 1)
{
fprintf(stderr, "Error writing file: %d\n", errno);
goto end;
@ -200,9 +202,9 @@ int main(int argc, char *argv[])
goto end;
}
size_t jump_pos = 0;
operand_t jump_pos = 0;
if(fwrite(&jump_pos, sizeof(jump_pos), 1, intermediate_representation_file) != 1)
if(fwrite(&jump_pos, sizeof(operand_t), 1, intermediate_representation_file) != 1)
{
fprintf(stderr, "Error writing file: %d\n", errno);
goto end;
@ -244,7 +246,7 @@ int main(int argc, char *argv[])
while(true)
{
operation_t operation;
size_t nb_read = fread(&operation, sizeof(operation), 1, intermediate_representation_file);
size_t nb_read = fread(&operation, sizeof(operation_t), 1, intermediate_representation_file);
if(nb_read != 1)
{
@ -273,7 +275,7 @@ int main(int argc, char *argv[])
for(size_t bracket_index = 1; bracket_index;)
{
operation_t operation_search;
nb_read = fread(&operation_search, sizeof(operation_search), 1, intermediate_representation_file);
nb_read = fread(&operation_search, sizeof(operation_t), 1, intermediate_representation_file);
if(nb_read != 1)
{
@ -296,7 +298,7 @@ int main(int argc, char *argv[])
case MEM_ADD_NB:
case MEM_SUB_NB:
case JUMP_IF_NOT_0:
if(fseek(intermediate_representation_file, sizeof(size_t), SEEK_CUR))
if(fseek(intermediate_representation_file, sizeof(operand_t), SEEK_CUR))
{
fprintf(stderr, "Error seeking file: %d\n", errno);
goto end;
@ -325,15 +327,15 @@ int main(int argc, char *argv[])
goto end;
}
if(fseek(intermediate_representation_file, -sizeof(size_t), SEEK_CUR))
if(fseek(intermediate_representation_file, -sizeof(operand_t), SEEK_CUR))
{
fprintf(stderr, "Error seeking file: %d\n", errno);
goto end;
}
size_t bracket_pos_size_t = (size_t)bracket_pos + sizeof(size_t);
operand_t bracket_pos_operand = (operand_t)bracket_pos + sizeof(operand_t);
if(fwrite(&bracket_pos_size_t, sizeof(bracket_pos_size_t), 1, intermediate_representation_file) != 1)
if(fwrite(&bracket_pos_operand, sizeof(operand_t), 1, intermediate_representation_file) != 1)
{
fprintf(stderr, "Error writing file: %d\n", errno);
goto end;
@ -345,8 +347,8 @@ int main(int argc, char *argv[])
goto end;
}
size_t corresponding_bracket_pos_size_t = corresponding_bracket_pos;
if(fwrite(&corresponding_bracket_pos_size_t, sizeof(corresponding_bracket_pos_size_t), 1, intermediate_representation_file) != 1)
operand_t corresponding_bracket_pos_operand = (operand_t)corresponding_bracket_pos;
if(fwrite(&corresponding_bracket_pos_operand, sizeof(operand_t), 1, intermediate_representation_file) != 1)
{
fprintf(stderr, "Error writing file: %d\n", errno);
goto end;
@ -360,7 +362,7 @@ int main(int argc, char *argv[])
case MEM_ADD_NB:
case MEM_SUB_NB:
case JUMP_IF_NOT_0:
fseek(intermediate_representation_file, sizeof(size_t), SEEK_CUR);
fseek(intermediate_representation_file, sizeof(operand_t), SEEK_CUR);
break;
default:
@ -374,13 +376,13 @@ int main(int argc, char *argv[])
uint8_t mem[DATA_SIZE_MAX] = {0};
size_t mem_pointer = 0;
size_t nb_read;
size_t operand;
uint8_t nb_read;
operand_t operand;
while(true)
{
operation_t operation;
nb_read = fread(&operation, sizeof(operation), 1, intermediate_representation_file);
nb_read = fread(&operation, sizeof(operation_t), 1, intermediate_representation_file);
if(nb_read != 1)
{
@ -402,7 +404,7 @@ int main(int argc, char *argv[])
break;
case MEM_POINTER_ADD_NB:
nb_read = fread(&operand, sizeof(operand), 1, intermediate_representation_file);
nb_read = fread(&operand, sizeof(operand_t), 1, intermediate_representation_file);
if(nb_read != 1)
{
fprintf(stderr, "Error reading file: %d\n", ferror(intermediate_representation_file));
@ -416,7 +418,7 @@ int main(int argc, char *argv[])
break;
case MEM_POINTER_SUB_NB:
nb_read = fread(&operand, sizeof(operand), 1, intermediate_representation_file);
nb_read = fread(&operand, sizeof(operand_t), 1, intermediate_representation_file);
if(nb_read != 1)
{
fprintf(stderr, "Error reading file: %d\n", ferror(intermediate_representation_file));
@ -430,7 +432,7 @@ int main(int argc, char *argv[])
break;
case MEM_ADD_NB:
nb_read = fread(&operand, sizeof(operand), 1, intermediate_representation_file);
nb_read = fread(&operand, sizeof(operand_t), 1, intermediate_representation_file);
if(nb_read != 1)
{
fprintf(stderr, "Error reading file: %d\n", ferror(intermediate_representation_file));
@ -444,7 +446,7 @@ int main(int argc, char *argv[])
break;
case MEM_SUB_NB:
nb_read = fread(&operand, sizeof(operand), 1, intermediate_representation_file);
nb_read = fread(&operand, sizeof(operand_t), 1, intermediate_representation_file);
if(nb_read != 1)
{
fprintf(stderr, "Error reading file: %d\n", ferror(intermediate_representation_file));
@ -456,7 +458,7 @@ int main(int argc, char *argv[])
case JUMP_IF_0:
if(mem[mem_pointer] == 0)
{
nb_read = fread(&operand, sizeof(operand), 1, intermediate_representation_file);
nb_read = fread(&operand, sizeof(operand_t), 1, intermediate_representation_file);
if(nb_read != 1)
{
fprintf(stderr, "Error reading file: %d\n", ferror(intermediate_representation_file));
@ -471,7 +473,7 @@ int main(int argc, char *argv[])
}
else
{
if(fseek(intermediate_representation_file, sizeof(size_t), SEEK_CUR))
if(fseek(intermediate_representation_file, sizeof(operand_t), SEEK_CUR))
{
fprintf(stderr, "Error seeking file: %d\n", errno);
goto end;
@ -482,7 +484,7 @@ int main(int argc, char *argv[])
case JUMP_IF_NOT_0:
if(mem[mem_pointer])
{
nb_read = fread(&operand, sizeof(operand), 1, intermediate_representation_file);
nb_read = fread(&operand, sizeof(operand_t), 1, intermediate_representation_file);
if(nb_read != 1)
{
fprintf(stderr, "Error reading file: %d\n", ferror(intermediate_representation_file));
@ -497,7 +499,7 @@ int main(int argc, char *argv[])
}
else
{
if(fseek(intermediate_representation_file, sizeof(size_t), SEEK_CUR))
if(fseek(intermediate_representation_file, sizeof(operand_t), SEEK_CUR))
{
fprintf(stderr, "Error seeking file: %d\n", errno);
goto end;