-
Notifications
You must be signed in to change notification settings - Fork 0
/
JMPZ.cpp
76 lines (65 loc) · 1.49 KB
/
JMPZ.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
#include "JMPZ.h"
#include "InvalidArgument.h"
#include <fstream>
JMPZ::JMPZ(){
}
int JMPZ::checkArgs(vector<Var*>const&vec){
JUMP::checkOps(vec);
int temp;
//if(isInteger(vec.at(2)) == 1){
// temp = isInt(vec.at(2)->getInt());
// }
if (dynamic_cast<Int*>(vec.at(2))){
temp = vec.at(2)->getInt();
}else if (dynamic_cast<String*>(vec.at(2))){
Var* temp2 = getEntry(vec.at(2)->getString());
if (dynamic_cast<Int*>(temp2)){
temp = temp2->getInt();
}else{
try{
throw InvalidArgument();
}catch(InvalidArgument &e){
ofstream outputFile;
outputFile.open(".err");
outputFile << "You have entered an invalid argument into the JMP" <<endl;
exit(EXIT_SUCCESS);
}
}
}else{
try{
throw InvalidArgument();
}catch(InvalidArgument &e){
ofstream outputFile;
outputFile.open(".err");
outputFile << "You have entered an invalid argument into the JMP" <<endl;
exit(EXIT_SUCCESS);
}
}
if(temp == 0){
return Label::doGet(vec);
}else{
return -99999;
}
}
Instruction* JMPZ::clone(){
JMPZ *j = new JMPZ();
return j;
}
JMPZ::~JMPZ(){
}
/*
int main(){
//Var *myInt = new Int(10);
vector<Var*>myVec;
//myVec.push_back(myInt);
//cout << checkArgs(myVec) <<endl;
myVec.push_back( new Int(3));
myVec.push_back(new Int(2));
Var *myString = new String("hi");
myVec.push_back(myString);
setEntry("hi", new Double(5.3));
JMPZ *a;
cout << a->checkArgs(myVec) << endl;
cout << a->checkArgs(myVec) << endl;
}
*/