-
Notifications
You must be signed in to change notification settings - Fork 2
/
vs.cpp
72 lines (58 loc) · 1.48 KB
/
vs.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
#include "vs.h"
#include "var.h"
#include <iostream>
using namespace std;
ptr vs::StackBegin;
ptr vs::StackPointer;
std::stack<ptr> vs::Scopes;
ptr vs::push_int(int Int){
StackPointer += sizeof(int);
*(int*)vs::StackPointer = Int;
return StackPointer;
}
ptr vs::push_int64(__int64 Int){
StackPointer += sizeof(__int64);
*(__int64*)vs::StackPointer = Int;
return StackPointer;
}
ptr vs::push_char(char Char){
StackPointer += sizeof(char);
*(char*)vs::StackPointer = Char;
return StackPointer;
}
ptr vs::push_float(float Float){
StackPointer += sizeof(float);
*(float*)vs::StackPointer = Float;
return StackPointer;
}
ptr vs::push_mem(ptr Address, int Size){
StackPointer += Size;
memcpy( (void*)(StackPointer), (const void*)(Address), Size );
return StackPointer;
}
ptr vs::push_string(string String){
ptr Temp = StackPointer;
int i;
for(i=0; i<String.size(); ++i){
*(char*)(StackPointer) = String[i];
StackPointer++;
}
*(char*)(StackPointer) = char(0);
//cout << "STRING: " << (char*)Temp << endl;
return Temp;
}
ptr vs::pop(int Bytes){
StackPointer -= Bytes;
return StackPointer;
}
ptr vs::alloc(int Bytes){
StackPointer += Bytes;
return StackPointer;
}
void vs::enter_scope(){
Scopes.push( 0 );
}
void vs::exit_scope(){
StackPointer -= Scopes.top();
Scopes.pop();
}