-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnrpngen.compact.h
53 lines (47 loc) · 977 Bytes
/
nrpngen.compact.h
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
/* defines nrpngen functions for compact RPN statements */
#pragma once
namespace nrpngen {
enum eatom : char {
INST, REG, VAR, NUM, OP
};
union uatom {
double num;
int ivar;
char reg;
union {
char inst;
char opcode;
};
eoperator op;
};
struct sstatement {
sstatement() {
size = 0;
type = 0;
atom = 0;
}
~sstatement() {
delete [] type;
delete [] atom;
}
int size;
eatom *type;
uatom *atom;
};
void readatom(eatom type, uatom &atom) {
switch (type) {
case INST: cout << "INST: " << (int)atom.inst; break;
case REG: cout << "REG: " << (int)atom.reg; break;
case VAR: cout << "VAR: " << atom.ivar; break;
case NUM: cout << "NUM: " << atom.num; break;
case OP: cout << "OP: "; readop(atom.op); break;
}
cout << endl;
}
void readstatement(sstatement *statement) {
if (!statement) return;
for (int i = 0; i < statement->size; ++i) {
readatom(statement->type[i], statement->atom[i]);
}
}
}