fix bug and add zero instruction

This commit is contained in:
Murphy 2023-04-15 01:04:50 -04:00
parent cb76bcf7d2
commit 1b3c67ba06
5 changed files with 16 additions and 1 deletions

View file

@ -41,6 +41,8 @@ Just like brainfuck, cells wrap from 0 to 255, and vice versa, and also the tape
`%` Clear screen `%` Clear screen
`$` Zero n cells where n is the value of the current cell
`\` Comment out the rest of the line `\` Comment out the rest of the line
## Usage ## Usage
@ -52,6 +54,12 @@ For example:
$ brainfucked helloworld.bfd $ brainfucked helloworld.bfd
``` ```
Brainfucked can also read from standard in, so the following would also work.
```
$ cat helloworld.bfd | brainfucked
```
## License ## License
This project is Licensed under the [WTFPL](http://www.wtfpl.net/) This project is Licensed under the [WTFPL](http://www.wtfpl.net/)

View file

@ -62,8 +62,8 @@ next:
break; break;
} }
case EnterTape: { case EnterTape: {
memcpy(&tape, tape_ptr(tape), sizeof(Tape*));
stack_push(&tape_stack, tape); stack_push(&tape_stack, tape);
memcpy(&tape, tape_ptr(tape), sizeof(Tape*));
break; break;
} }
case LeaveTape: { case LeaveTape: {
@ -82,6 +82,9 @@ next:
case Clear: case Clear:
printf("\033c"); printf("\033c");
break; break;
case Zero:
memset(tape_ptr(tape), 0, tape_get(tape));
break;
case Eof: case Eof:
goto end; goto end;
} }

View file

@ -20,6 +20,7 @@
/// ` Output null terminated string at current cell /// ` Output null terminated string at current cell
/// ~ Input string into current cells with max length in current cell /// ~ Input string into current cells with max length in current cell
/// % Clear screen /// % Clear screen
/// $ Set n cells to 0 where n is the count of the current cell
int main(int argc, char** argv) { int main(int argc, char** argv) {

View file

@ -48,6 +48,8 @@ retest:
return GetString; return GetString;
case '%': case '%':
return Clear; return Clear;
case '$':
return Zero;
case '\n': case '\n':
case '\t': case '\t':
case ' ': case ' ':

View file

@ -19,6 +19,7 @@ typedef enum {
PutString, PutString,
GetString, GetString,
Clear, Clear,
Zero,
Eof Eof
} Symbol; } Symbol;