-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathboi.cpp
71 lines (55 loc) · 1.24 KB
/
boi.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include "./vm/VM.hpp"
#include <fstream>
#include <string>
using namespace std;
byte * program;
byte get8bit(char * str) {
int i;
byte newbyte = 0;
for (i = 0; i<8; i++) {
newbyte<<=1;
if (str[i] == 'k') {
newbyte += 1;
} else if (str[i] == 'w') {
} else {
cout << "Unresolved Symbol: " << str[i] << "." << endl;
exit(0);
}
}
return newbyte;
}
void interpret(char * filename) {
char * buffer;
int len;
// load program
ifstream infile;
infile.open(filename);
infile.seekg(0, ios::end);
len = infile.tellg();
infile.seekg(0, ios::beg);
// delete[] buffer;
buffer = new char[len];
infile.read(buffer, len);
infile.close();
if (len % 8 != 0) {
cout << "Invalid code length.\n";
exit(0);
}
int codelen = len / 8;
byte * code = new byte[codelen];
for(int i=0; i<codelen; i++) {
code[i] = get8bit(&buffer[i*8]);
}
delete[] buffer;
program = code;
}
int main(int argc, char ** args) {
if (argc < 2) {
cout << "usage : ./boi filename\n";
exit(0);
}
interpret(args[1]);
VM vm(program);
vm.run();
return 0;
}