Browse Source

attempt to wrap turing tape, add hello2, file exts

canon
Hazel Levine 2 years ago
parent
commit
a25a9e4952
7 changed files with 22 additions and 9 deletions
  1. +15
    -7
      src/brainfuck.cpp
  2. +4
    -1
      src/brainfuck.hpp
  3. +1
    -1
      test/bottle.b
  4. +0
    -0
      test/cat.b
  5. +0
    -0
      test/fib.b
  6. +0
    -0
      test/hello.b
  7. +2
    -0
      test/hello2.b

+ 15
- 7
src/brainfuck.cpp View File

@ -7,15 +7,15 @@
#include "error.hpp"
void Interpreter::run() {
data_tape = std::vector<char>(30000, 0); // tape size from esolangs
data_tape = std::vector<char>(TAPE_SIZE, 0); // tape size from esolangs
jump = std::stack<int>();
// gamers, let's get this bread
for (std::size_t i = 0; i < prog.size(); i++) {
int j = 0;
j = i;
int j = i;
if ((prog[i] == OpCode::LoopEnd) && (data_tape[ptr] != '\0')) { // we might have to make a jump!
// might have to make a jump
if ((prog[i] == OpCode::LoopEnd) && (data_tape[ptr] != '\0')) {
i = jump.top() - 1; // account for i++?
}
@ -27,13 +27,21 @@ void Interpreter::run() {
}
}
void Interpreter::processIndex(int index) {
void Interpreter::processIndex(int index) {
switch(prog[index]) {
case OpCode::IncPtr:
++ptr;
if (ptr+1 >= TAPE_SIZE) {
ptr = 0;
} else {
++ptr;
}
break;
case OpCode::DecPtr:
if (--ptr < 0) ptr = 0; // no negative indices
if (ptr-1 < 0) {
ptr = TAPE_SIZE-1; // wrap negative indices to end of vector
} else {
--ptr;
}
break;
case OpCode::IncByte:
++data_tape[ptr];


+ 4
- 1
src/brainfuck.hpp View File

@ -18,6 +18,8 @@ enum class OpCode {
LoopEnd // ]
};
const int TAPE_SIZE = 30000;
class Interpreter {
public:
Interpreter(void) {
@ -29,8 +31,9 @@ public:
}
void run();
void processIndex(int);
private:
void processIndex(int);
std::vector<OpCode> prog;
std::stack<int> jump;


test/bottle.bf → test/bottle.b View File

@ -57,4 +57,4 @@ the readability of an IOCCC entry!
++++++++>-]<++++.------------.---.>+++++++[<---------->-]<+.
>++++++++[<+++++++++++>-]<-.>++[<----------->-]<.+++++++++++
..>+++++++++[<---------->-]<-----.---.+++.---.[-]<<<]
@
@

test/cat.bf → test/cat.b View File


test/fib.bf → test/fib.b View File


test/hello.bf → test/hello.b View File


+ 2
- 0
test/hello2.b View File

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

Loading…
Cancel
Save