-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.cpp
124 lines (95 loc) · 2.63 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*
* Copyright (C) 2012-2014 Impossible Language
* by Jacopo Santoni (Jack)
* License: http://www.gnu.org/licenses/gpl.html GPL version 2 or higher
* Created on 12/21/12
*/
#include "parser/compiler.h"
#include "vm/analysis.h"
#include "vm.h"
#include "instruction.h"
#include "semantics.h"
#include "help.h"
#include <string>
#include <iostream>
using namespace std;
void registerFunctions(MicroCode& mc);
int main (int argc, const char * argv[])
{
MicroCode mc;
registerFunctions(mc);
//Help::init();
//Help::printVersion();
//Help::printHelpSummary();
VM vm(mc);
string input;
bool finished = false;
input = "(?0:[1]1:[1][1<>2<>+])2@";
compiler::Compiler compiler;
Code*code = compiler.compile(input);
if (code)
{
vm.execute(code);
vm.printTopStack();
}
//return 0;
while (!finished)
{
cout << "i>";
getline(cin, input);
if (input == "exit")
finished = true;
else if (input == "stack")
{
cout << " " << vm.stackAsString() << " <<" << endl;
}
else if (input == "wipe")
vm.wipe();
else if (input.substr(0,4).compare("help") == 0)
{
if (input == "help")
{
Help::printHelpMain();
}
else
{
string params = input.substr(5);
if (params == "operators")
Help::printOperators();
else if (params == "types")
Help::printTypes();
else if (params == "undocumented")
Help::printUndocumented();
else if (Help::printHelpForOperator(params))
{
}
else if (Help::printHelpForType(params))
{
}
else if (params.length() > 0 && Help::printHelpForSearch(params))
{
}
}
}
else if (input == "info")
{
cout << " arch: " << (sizeof(void*) == 4 ? "x86" : "x86-64") << endl;
cout << " size of value : " << sizeof(Value) << (sizeof(Value) == sizeof(value_data) + sizeof(Type) ? " (packed)" : "") << endl;
cout << " size of instruction : " << sizeof(Instruction) << endl;
cout << " size of opcode : " << sizeof(Opcode) << endl;
cout << " known types : " << TypeTraits::traits().size() << endl;
cout << " known operators : " << Opcode::OPCODES_COUNT << endl;
cout << " implemented operators : " << mc.vocabulary().size() << endl;
}
else
{
compiler::Compiler compiler;
Code *code = compiler.compile(input);
if (code)
{
vm.execute(code);
vm.printTopStack();
}
}
}
}