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.
* 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 next = -1;
@@ -70,17 +70,15 @@ static int bfi_skip_forward(void)
/* Closing bracket */
case JNB: context--;
if(context == 0)
return next;
return;
break;
/* End of the program or unknown instruction. */
case EOT:
case SOT:
case UKW:
return next;
return;
}
}
return next;
}
/**
@@ -88,7 +86,7 @@ static int bfi_skip_forward(void)
* to be executed.
* 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 prev = -1;
@@ -99,7 +97,7 @@ int bfi_skip_backward(void)
{ /* Opening bracket */
case JZF: context--;
if(context == 0)
return prev;
return;
break;
/* Closing bracket */
case JNB: context++;
@@ -108,11 +106,9 @@ int bfi_skip_backward(void)
case EOT:
case SOT:
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;
case JZF:
if(*bfi_head == 0)
next = bfi_skip_forward();
bfi_skip_forward();
break;
case JNB:
if(*bfi_head != 0)
next = bfi_skip_backward();
bfi_skip_backward();
break;
case UKW:
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);
/* Ensure there is an end of line */
printf("\n");
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");
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. */