-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.cpp
More file actions
69 lines (54 loc) · 1.75 KB
/
main.cpp
File metadata and controls
69 lines (54 loc) · 1.75 KB
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
#include <cstdlib>
#include <iostream>
#include <vector>
#include <bitset>
#include <cstdlib>
#include <time.h>
#include "parser.h"
#include "lex.h"
#include "vm.h"
#include "var.h"
#include "vs.h"
#define SPP_STACK_SIZE 100000000
using namespace std;
int main(int argc, char** argv)
{
cout << "ÄãºÃ£¬ÕâÊÇS++" << endl;
vs::StackBegin = (ptr)( malloc(SPP_STACK_SIZE) );
vs::StackPointer = vs::StackBegin;
ptr This = 0x0;
vm VM;
VM.Vars["_sp"] = var( (ptr)(&vs::StackPointer), T_PTR, sizeof(ptr), T_INT, 1 );
VM.Vars["_ds"] = var( (ptr)(&vs::StackBegin), T_PTR, sizeof(ptr), T_INT, 1);
VM.Vars["argc"] = var( (ptr)(&argc), T_INT, sizeof(int) );
VM.Vars["argv"] = var( (ptr)(&argv), T_PTR, sizeof(char), T_CHAR, 2);
VM.Vars["cout"] = var( (ptr)(&cout), T_OBJECT, sizeof(cout) );
VM.Vars["cin"] = var( (ptr)(&cin), T_OBJECT, sizeof(cin), 0, 0, 0 );
while(1){
cout << "\n@" << vs::StackPointer-vs::StackBegin << "> ";
string Line;
getline(cin,Line);
try{
vector<token> Tokens = Lex(Line);
if( !Tokens.size() ) continue;
tree Tree;
VM.PreParse( Tokens );
VM.LoadTree( Tokens, Tree );
VM.PreEval( Tree, VM.Vars, This );
Tree.Show();
int Start=clock();
var* Temp = VM.Eval( Tree, VM.Vars, vs::StackBegin );
This = vs::StackPointer - vs::StackBegin;
cout << "T: " << clock() - Start << endl;
cout << "(" << Temp->Type << " @ " << Temp->Address << ") >> " << *Temp << endl;
}
catch(string){}
}
return EXIT_SUCCESS;
}
void Error( string X )
{
cout << "ERROR: " << X << endl;
cin.get();
throw string("");
}