diff options
| -rw-r--r-- | README.md | 5 | ||||
| -rw-r--r-- | skullfuck.c | 10 |
2 files changed, 9 insertions, 6 deletions
@@ -1,14 +1,17 @@ Skullfuck ========= -Skullfuck is a dead simple compiler for Brainfuck, contained in a single C source file. It outputs binaries targeting x86_64 and i686 Linux. +Skullfuck is a dead simple optimizing compiler for Brainfuck, contained in a single C source file. It outputs binaries targeting x86_64 and i686 Linux. It depends on GNU Binutils, or any compatible implementation of `as` and `ld`. An explanation of the history and design behind the language is available at [the Esolang wiki.](https://esolangs.org/wiki/Brainfuck) +Skullfuck is free software, licensed under the [GNU General Public License.](http://gnu.org/licenses/gpl.html) + TODO ---- * *BSD targeted binaries. * Automate test compilation/running. * Static analysis to warn when undefined behavior has been detected. +* Optimize mutally cancelling operations. diff --git a/skullfuck.c b/skullfuck.c index a8de668..1c41dc9 100644 --- a/skullfuck.c +++ b/skullfuck.c @@ -37,7 +37,7 @@ #define DEC_DATA "\tdecb (%rsi)\n" #define SUB_DATA "\tsubb $0x%x, (%%rsi)\n" #define ZERO_DATA "\tmovb $0x00, (%rsi)\n" -#define PRINT_DATA "\tmovq $0x01, %rax\n" \ +#define WRITE_DATA "\tmovq $0x01, %rax\n" \ "\tmovq $0x01, %rdi\n" \ "\tsyscall\n" #define READ_DATA "\tmovq $0x00, %rax\n" \ @@ -71,7 +71,7 @@ #define DEC_DATA "\tdecb (%ecx)\n" #define SUB_DATA "\tsubb $0x%x, (%%ecx)\n" #define ZERO_DATA "\tmovb $0x00, (%ecx)\n" -#define PRINT_DATA "\tmovl $0x04, %eax\n" \ +#define WRITE_DATA "\tmovl $0x04, %eax\n" \ "\tmovl $0x01, %ebx\n" \ "\tint $0x80\n" #define READ_DATA "\tmovl $0x03, %eax\n" \ @@ -98,7 +98,7 @@ #define MAX_CELLS 30000 #define MAX_LOOP_DEPTH 64 -#define SKULLFUCK_VERSION "0.2.0" +#define SKULLFUCK_VERSION "0.3.0" #define EXIT_SUCCESS 0 #define EXIT_FAILURE 1 @@ -161,7 +161,7 @@ static int optimize_loops(char **in) { the collection of adjacent `op` characters, and returns the number of operations counted. */ static int reduce(char **in, char op) { - int i; + int i; for (i = 0; (*in)[i] == op; i++); *in += i - 1; return i; @@ -210,7 +210,7 @@ static void write_instructions(FILE *out, char *in) { } break; case '.': - fputs(PRINT_DATA, out); + fputs(WRITE_DATA, out); break; case ',': fputs(READ_DATA, out); |