-
Notifications
You must be signed in to change notification settings - Fork 0
/
bf_switch.cpp
54 lines (39 loc) · 1.07 KB
/
bf_switch.cpp
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
#include "bf_instruction.hpp"
namespace bf {
void execute(std::vector<Instruction>& _instructions)
{
std::vector<char> characters(30000);
char* ptr = characters.data();
const int sz = _instructions.size();
const auto instructions = _instructions.data();
for(int i=0; i<sz; i++){
const auto& instr = instructions[i];
switch(instr.action){
case TRUEJUMP:
if(*ptr){
i += instr.val;
}
break;
case FALSEJUMP:
if(!(*ptr)){
i += instr.val;
}
break;
case MOVE:
ptr += instr.val;
break;
case INCR:
*ptr += instr.val;
break;
case PRINT:
std::cout << (*ptr);
break;
case READ:
std::cin.get(*ptr);
break;
case TERMINATE:
break;
}
}
}
}