Compare commits
2 Commits
5ce1fddc8d
...
e3e5d6a5eb
| Author | SHA1 | Date |
|---|---|---|
|
|
e3e5d6a5eb | |
|
|
1a1744fe80 |
17
ghost.bf
17
ghost.bf
|
|
@ -1,17 +0,0 @@
|
||||||
-[
|
|
||||||
->+++++++++>+++>->>>>->>->>>>->>->>>>->+++
|
|
||||||
>>->+>++>>+>->++>>+>->++>>+>->++>+++++++++
|
|
||||||
>+>[>>>]<[>------->-------->->-->>]>>-[<-]<
|
|
||||||
++[[[>>]+++<[>]++[<]<-]>-<<++]>+>[+>]<<[++++[>++++<-]<<]
|
|
||||||
<<<[[>->>>++++++++++<<<<+]<[>->>>>+<<<<<+]<]>>[>]>[<+>>+>>+<<<-]
|
|
||||||
>>>[-[>>+<<-]>>]<[<+>-]<[>++<-]<[<<]<<[>->>[>]+[<]<<-]->>>[>]<+[<-<]>+
|
|
||||||
>[.>+++++++++[-[>>+<<-]>.>]++++++++++.[-]>]+[<<]<[
|
|
||||||
,->>>---[<<<--->>>-],<-<<[
|
|
||||||
<++>>>++<<---[
|
|
||||||
<++[>-----<-]>>+>-<<[
|
|
||||||
>--<----[>+<[-]]]]]>[<+>>++++++++++<-]
|
|
||||||
>[-[>>+<<-]>>]++++[>--------<-]>[-[[<<]<[-]<[-]>>>>[-]]]+[>>]+[[-]<<]<<<<[
|
|
||||||
[>>[<<->>-]>>+<<<<[+<<]>>>>]>>[<<]<<<<[+>>]>>>>[<<]>>[<<<<<<->>->>>>-]<<<
|
|
||||||
]-[+<-]-<
|
|
||||||
]>
|
|
||||||
]>>-----[>+++<-]>-.----------.++++++.>---.[<<+>-->----]<-.+++++.----.<++.
|
|
||||||
64
src/main.c
64
src/main.c
|
|
@ -28,6 +28,8 @@ enum operations_t {
|
||||||
|
|
||||||
typedef uint8_t operation_t;
|
typedef uint8_t operation_t;
|
||||||
|
|
||||||
|
typedef int operand_t;
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int status = EXIT_FAILURE;
|
int status = EXIT_FAILURE;
|
||||||
|
|
@ -135,15 +137,15 @@ int main(int argc, char *argv[])
|
||||||
goto end;
|
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);
|
fprintf(stderr, "Error writing file: %d\n", errno);
|
||||||
goto end;
|
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);
|
fprintf(stderr, "Error writing file: %d\n", errno);
|
||||||
goto end;
|
goto end;
|
||||||
|
|
@ -153,15 +155,15 @@ int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
operation++;
|
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);
|
fprintf(stderr, "Error seeking file: %d\n", errno);
|
||||||
goto end;
|
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);
|
fprintf(stderr, "Error reading file: %d\n", errno);
|
||||||
goto end;
|
goto end;
|
||||||
|
|
@ -169,13 +171,13 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
nb++;
|
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);
|
fprintf(stderr, "Error seeking file: %d\n", errno);
|
||||||
goto end;
|
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);
|
fprintf(stderr, "Error writing file: %d\n", errno);
|
||||||
goto end;
|
goto end;
|
||||||
|
|
@ -183,7 +185,7 @@ int main(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
else
|
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);
|
fprintf(stderr, "Error writing file: %d\n", errno);
|
||||||
goto end;
|
goto end;
|
||||||
|
|
@ -200,9 +202,9 @@ int main(int argc, char *argv[])
|
||||||
goto end;
|
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);
|
fprintf(stderr, "Error writing file: %d\n", errno);
|
||||||
goto end;
|
goto end;
|
||||||
|
|
@ -244,7 +246,7 @@ int main(int argc, char *argv[])
|
||||||
while(true)
|
while(true)
|
||||||
{
|
{
|
||||||
operation_t operation;
|
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)
|
if(nb_read != 1)
|
||||||
{
|
{
|
||||||
|
|
@ -273,7 +275,7 @@ int main(int argc, char *argv[])
|
||||||
for(size_t bracket_index = 1; bracket_index;)
|
for(size_t bracket_index = 1; bracket_index;)
|
||||||
{
|
{
|
||||||
operation_t operation_search;
|
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)
|
if(nb_read != 1)
|
||||||
{
|
{
|
||||||
|
|
@ -296,7 +298,7 @@ int main(int argc, char *argv[])
|
||||||
case MEM_ADD_NB:
|
case MEM_ADD_NB:
|
||||||
case MEM_SUB_NB:
|
case MEM_SUB_NB:
|
||||||
case JUMP_IF_NOT_0:
|
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);
|
fprintf(stderr, "Error seeking file: %d\n", errno);
|
||||||
goto end;
|
goto end;
|
||||||
|
|
@ -325,15 +327,15 @@ int main(int argc, char *argv[])
|
||||||
goto end;
|
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);
|
fprintf(stderr, "Error seeking file: %d\n", errno);
|
||||||
goto end;
|
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);
|
fprintf(stderr, "Error writing file: %d\n", errno);
|
||||||
goto end;
|
goto end;
|
||||||
|
|
@ -345,8 +347,8 @@ int main(int argc, char *argv[])
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t corresponding_bracket_pos_size_t = corresponding_bracket_pos;
|
operand_t corresponding_bracket_pos_operand = (operand_t)corresponding_bracket_pos;
|
||||||
if(fwrite(&corresponding_bracket_pos_size_t, sizeof(corresponding_bracket_pos_size_t), 1, intermediate_representation_file) != 1)
|
if(fwrite(&corresponding_bracket_pos_operand, sizeof(operand_t), 1, intermediate_representation_file) != 1)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Error writing file: %d\n", errno);
|
fprintf(stderr, "Error writing file: %d\n", errno);
|
||||||
goto end;
|
goto end;
|
||||||
|
|
@ -360,7 +362,7 @@ int main(int argc, char *argv[])
|
||||||
case MEM_ADD_NB:
|
case MEM_ADD_NB:
|
||||||
case MEM_SUB_NB:
|
case MEM_SUB_NB:
|
||||||
case JUMP_IF_NOT_0:
|
case JUMP_IF_NOT_0:
|
||||||
fseek(intermediate_representation_file, sizeof(size_t), SEEK_CUR);
|
fseek(intermediate_representation_file, sizeof(operand_t), SEEK_CUR);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
@ -374,13 +376,13 @@ int main(int argc, char *argv[])
|
||||||
uint8_t mem[DATA_SIZE_MAX] = {0};
|
uint8_t mem[DATA_SIZE_MAX] = {0};
|
||||||
size_t mem_pointer = 0;
|
size_t mem_pointer = 0;
|
||||||
|
|
||||||
size_t nb_read;
|
uint8_t nb_read;
|
||||||
size_t operand;
|
operand_t operand;
|
||||||
|
|
||||||
while(true)
|
while(true)
|
||||||
{
|
{
|
||||||
operation_t operation;
|
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)
|
if(nb_read != 1)
|
||||||
{
|
{
|
||||||
|
|
@ -402,7 +404,7 @@ int main(int argc, char *argv[])
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MEM_POINTER_ADD_NB:
|
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)
|
if(nb_read != 1)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Error reading file: %d\n", ferror(intermediate_representation_file));
|
fprintf(stderr, "Error reading file: %d\n", ferror(intermediate_representation_file));
|
||||||
|
|
@ -416,7 +418,7 @@ int main(int argc, char *argv[])
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MEM_POINTER_SUB_NB:
|
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)
|
if(nb_read != 1)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Error reading file: %d\n", ferror(intermediate_representation_file));
|
fprintf(stderr, "Error reading file: %d\n", ferror(intermediate_representation_file));
|
||||||
|
|
@ -430,7 +432,7 @@ int main(int argc, char *argv[])
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MEM_ADD_NB:
|
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)
|
if(nb_read != 1)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Error reading file: %d\n", ferror(intermediate_representation_file));
|
fprintf(stderr, "Error reading file: %d\n", ferror(intermediate_representation_file));
|
||||||
|
|
@ -444,7 +446,7 @@ int main(int argc, char *argv[])
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MEM_SUB_NB:
|
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)
|
if(nb_read != 1)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Error reading file: %d\n", ferror(intermediate_representation_file));
|
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:
|
case JUMP_IF_0:
|
||||||
if(mem[mem_pointer] == 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)
|
if(nb_read != 1)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Error reading file: %d\n", ferror(intermediate_representation_file));
|
fprintf(stderr, "Error reading file: %d\n", ferror(intermediate_representation_file));
|
||||||
|
|
@ -471,7 +473,7 @@ int main(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
else
|
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);
|
fprintf(stderr, "Error seeking file: %d\n", errno);
|
||||||
goto end;
|
goto end;
|
||||||
|
|
@ -482,7 +484,7 @@ int main(int argc, char *argv[])
|
||||||
case JUMP_IF_NOT_0:
|
case JUMP_IF_NOT_0:
|
||||||
if(mem[mem_pointer])
|
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)
|
if(nb_read != 1)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Error reading file: %d\n", ferror(intermediate_representation_file));
|
fprintf(stderr, "Error reading file: %d\n", ferror(intermediate_representation_file));
|
||||||
|
|
@ -497,7 +499,7 @@ int main(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
else
|
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);
|
fprintf(stderr, "Error seeking file: %d\n", errno);
|
||||||
goto end;
|
goto end;
|
||||||
|
|
|
||||||
31
utm.bf
31
utm.bf
|
|
@ -1,31 +0,0 @@
|
||||||
Universal Turing Machine
|
|
||||||
|
|
||||||
If you just want a quick and complete test case the input b1b1bbb1c1c11111d
|
|
||||||
should produce the output 1c11111
|
|
||||||
|
|
||||||
+++>++>>>+[>>,[>+++++<[[->]<<]<[>]>]>-[<<+++++>>-[<<---->>-[->]<]]
|
|
||||||
<[<-<[<]+<+[>]<<+>->>>]<]<[<]>[-[>++++++<-]>[<+>-]+<<<+++>+>
|
|
||||||
[-
|
|
||||||
[<<+>->-
|
|
||||||
[<<[-]>>-
|
|
||||||
[<<++>+>-
|
|
||||||
[<<-->->>+++<-
|
|
||||||
[<<+>+>>--<-
|
|
||||||
[<<->->-
|
|
||||||
[<<++++>+>>+<-
|
|
||||||
[>-<-
|
|
||||||
[<<->->-
|
|
||||||
[<<->>-
|
|
||||||
[<<+++>>>-<-
|
|
||||||
[<<---->>>++<-
|
|
||||||
[<<++>>>+<-
|
|
||||||
[>[-]<-
|
|
||||||
[<<->>>+++<-
|
|
||||||
[<<->>>--<-
|
|
||||||
[<<++++>+>>+<-
|
|
||||||
[<<[-]>->>++<-
|
|
||||||
[<<+++++>+>>--<-
|
|
||||||
[<->>++<
|
|
||||||
[<<->>-
|
|
||||||
]]]]]]]]]]]]]]]]]]]]]]<[->>[<<+>>-]<<<[>>>+<<<-]<[>>>+<<<-]]>>]
|
|
||||||
>[-[---[-<]]>]>[+++[<+++++>--]>]+<++[[>+++++<-]<]>>[-.>]
|
|
||||||
Loading…
Reference in New Issue