-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
84 lines (60 loc) · 1.54 KB
/
main.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
72
73
74
75
76
77
78
79
80
81
82
83
#include <iostream>
#include <vector>
#include "uswua-core/opcode.hpp"
#include "uswua-core/error.hpp"
#include "uswua-core/vm.hpp"
#include "uswua-utils/b2i.hpp"
#include "uswua-utils/b2i.hpp"
#include "uswua-utils/parser.hpp"
#include "uswua-utils/html_logger.hpp"
#include "tests/tests_all.cpp"
using namespace std;
int main() {
// TESTS_RUN_ALL();
auto code = R"(
#STARTPTR 0
.foo 0x0A
PUSH 0x00 ; r = 0
STORE r ;
PUSH 0x01 ; i = 1
STORE i ;
#pstart F
PROC F ; def f():
LOAD r ;
LOAD i ;
ADD ;
STORE r ; r = r + i
LOAD i ;
PUSH 0x01 ;
ADD ;
STORE i ; i = i + 1
LOAD i ;
DLOAD .foo ;
GTE ;
JIF _CASE_FALSE ; if 10 >= i:
_CASE_TRUE:
CALL 4 ; f()
_CASE_FALSE:
RET ; else: return
#pend F
CALL F ; f()
LOAD r
LOAD i
)";
try {
Parser p = Parser(code);
Instructions instructions = p.parse();
Stack stack;
Heap heap;
Vm vm = Vm(instructions, stack, heap, p.data, p.vm_options);
vm.execute();
// cout << vm.stackDump() << endl;
// cout << "-----" << endl;
// cout << vm.heapDump() << endl;
HTMLLogger logger(vm.logs);
cout << logger.html() << endl;
} catch (BytecodeError error) {
cout << error.what() << " at " << error.where() << endl;
}
return 0;
}