Small fixes

This commit is contained in:
2024-09-12 16:48:58 +02:00
parent 178a437f86
commit 2f12edb163
2 changed files with 24 additions and 26 deletions

22
interpreter.c Executable file → Normal file
View File

@@ -56,7 +56,7 @@ static int bfi_execution_error(char* reason, int code)
* to be executed. * to be executed.
* Hypotheses: bfi_token_start points just after the opening bracket. * Hypotheses: bfi_token_start points just after the opening bracket.
*/ */
static int bfi_skip_forward(void) static void bfi_skip_forward(void)
{ {
int context = 0; int context = 0;
int next = -1; int next = -1;
@@ -70,17 +70,15 @@ static int bfi_skip_forward(void)
/* Closing bracket */ /* Closing bracket */
case JNB: context--; case JNB: context--;
if(context == 0) if(context == 0)
return next; return;
break; break;
/* End of the program or unknown instruction. */ /* End of the program or unknown instruction. */
case EOT: case EOT:
case SOT: case SOT:
case UKW: case UKW:
return next; return;
} }
} }
return next;
} }
/** /**
@@ -88,7 +86,7 @@ static int bfi_skip_forward(void)
* to be executed. * to be executed.
* Hypotheses: bfi_token_start points just before the closing bracket. * Hypotheses: bfi_token_start points just before the closing bracket.
*/ */
int bfi_skip_backward(void) static void bfi_skip_backward(void)
{ {
int context = 0; int context = 0;
int prev = -1; int prev = -1;
@@ -99,7 +97,7 @@ int bfi_skip_backward(void)
{ /* Opening bracket */ { /* Opening bracket */
case JZF: context--; case JZF: context--;
if(context == 0) if(context == 0)
return prev; return;
break; break;
/* Closing bracket */ /* Closing bracket */
case JNB: context++; case JNB: context++;
@@ -108,11 +106,9 @@ int bfi_skip_backward(void)
case EOT: case EOT:
case SOT: case SOT:
case UKW: case UKW:
return prev; return;
} }
} }
return prev;
} }
/** /**
@@ -201,11 +197,11 @@ int bfi_execute(char* program, size_t length, enum bfi_dialects dialect, char pr
break; break;
case JZF: case JZF:
if(*bfi_head == 0) if(*bfi_head == 0)
next = bfi_skip_forward(); bfi_skip_forward();
break; break;
case JNB: case JNB:
if(*bfi_head != 0) if(*bfi_head != 0)
next = bfi_skip_backward(); bfi_skip_backward();
break; break;
case UKW: case UKW:
default: default:
@@ -214,8 +210,10 @@ int bfi_execute(char* program, size_t length, enum bfi_dialects dialect, char pr
} }
bfi_execution_error("End of Program", *bfi_head); bfi_execution_error("End of Program", *bfi_head);
/* Ensure there is an end of line */ /* Ensure there is an end of line */
printf("\n"); printf("\n");
return (int)*bfi_head; return (int)*bfi_head;
} }

2
main.c Executable file → Normal file
View File

@@ -171,7 +171,7 @@ int main(int argc, const char *argv[])
{ {
perror("init"); perror("init");
printf(COLOR_ERR "Error during the loading of '%s'." COLOR_RST "\n", options.filename); printf(COLOR_ERR "Error during the loading of '%s'." COLOR_RST "\n", options.filename);
return 1; return err;
} }
/* Print the program as loaded into memory. */ /* Print the program as loaded into memory. */