-
Notifications
You must be signed in to change notification settings - Fork 1
/
Brainfuck.h
60 lines (37 loc) · 1.35 KB
/
Brainfuck.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#ifndef BRAINFUCK_H
#define BRAINFUCK_H
#include <vector>
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
namespace Brainfuck {
void JIT(std::string program, bool optimised = false);
void Compile(std::string program, bool optimised = false);
class Interpreter {
public:
Interpreter(std::istream *inputs = &std::cin);
void Interpret(std::string program);
void Start(const std::string program);
void Step(unsigned num_steps);
void GoUntil(unsigned long target_instr_pointer, bool offset_is_from_end = false);
void Reset();
unsigned GetInstrPointer() const { return instr_pointer; }
unsigned GetDataPointer() const { return data_pointer; }
std::vector<char> GetMemory() const { return memory; }
static const size_t memory_size = 30000;
void PrintFormattedLocation();
bool ProgramIsFinished();
private:
unsigned instr_pointer = 0;
std::string program;
unsigned data_pointer = 0;
std::vector<char> memory = std::vector<char>(memory_size, 0);
std::istream *inputs;
static bool NotBrainfuckCmd(char cmd);
std::string StripUnwantedCharacters(const std::string &program);
void SingleStep();
std::string original_program;
};
}
#endif //BRAINFUCK_H