Compare commits

..

No commits in common. "e3e5d6a5eb6836e13f95b046a2f57ca5a53042e4" and "5ce1fddc8d7af8b82385aec007056ca0d8a45db7" have entirely different histories.

3 changed files with 79 additions and 33 deletions

17
ghost.bf Normal file
View File

@ -0,0 +1,17 @@
-[
->+++++++++>+++>->>>>->>->>>>->>->>>>->+++
>>->+>++>>+>->++>>+>->++>>+>->++>+++++++++
>+>[>>>]<[>------->-------->->-->>]>>-[<-]<
++[[[>>]+++<[>]++[<]<-]>-<<++]>+>[+>]<<[++++[>++++<-]<<]
<<<[[>->>>++++++++++<<<<+]<[>->>>>+<<<<<+]<]>>[>]>[<+>>+>>+<<<-]
>>>[-[>>+<<-]>>]<[<+>-]<[>++<-]<[<<]<<[>->>[>]+[<]<<-]->>>[>]<+[<-<]>+
>[.>+++++++++[-[>>+<<-]>.>]++++++++++.[-]>]+[<<]<[
,->>>---[<<<--->>>-],<-<<[
<++>>>++<<---[
<++[>-----<-]>>+>-<<[
>--<----[>+<[-]]]]]>[<+>>++++++++++<-]
>[-[>>+<<-]>>]++++[>--------<-]>[-[[<<]<[-]<[-]>>>>[-]]]+[>>]+[[-]<<]<<<<[
[>>[<<->>-]>>+<<<<[+<<]>>>>]>>[<<]<<<<[+>>]>>>>[<<]>>[<<<<<<->>->>>>-]<<<
]-[+<-]-<
]>
]>>-----[>+++<-]>-.----------.++++++.>---.[<<+>-->----]<-.+++++.----.<++.

View File

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

31
utm.bf Normal file
View File

@ -0,0 +1,31 @@
Universal Turing Machine
If you just want a quick and complete test case the input b1b1bbb1c1c11111d
should produce the output 1c11111
+++>++>>>+[>>,[>+++++<[[->]<<]<[>]>]>-[<<+++++>>-[<<---->>-[->]<]]
<[<-<[<]+<+[>]<<+>->>>]<]<[<]>[-[>++++++<-]>[<+>-]+<<<+++>+>
[-
[<<+>->-
[<<[-]>>-
[<<++>+>-
[<<-->->>+++<-
[<<+>+>>--<-
[<<->->-
[<<++++>+>>+<-
[>-<-
[<<->->-
[<<->>-
[<<+++>>>-<-
[<<---->>>++<-
[<<++>>>+<-
[>[-]<-
[<<->>>+++<-
[<<->>>--<-
[<<++++>+>>+<-
[<<[-]>->>++<-
[<<+++++>+>>--<-
[<->>++<
[<<->>-
]]]]]]]]]]]]]]]]]]]]]]<[->>[<<+>>-]<<<[>>>+<<<-]<[>>>+<<<-]]>>]
>[-[---[-<]]>]>[+++[<+++++>--]>]+<++[[>+++++<-]<]>>[-.>]