|
|
@ -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]; |
|
|
|