-
Notifications
You must be signed in to change notification settings - Fork 0
/
bc.cpp
50 lines (48 loc) · 1.24 KB
/
bc.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
#include "bc.h"
#include "object.h"
void BCVerifier::verify(BC* bc, unsigned size) {
unsigned i = 0; for(; i < size;) {
BC pc = bc[i++];
assert((B)pc < (B)BC::num_of);
switch(BC_immediate[(B)pc]) {
case ImmediateType::None:
break;
case ImmediateType::Symbol: {
Value* v = *((Value**)&bc[i]);
Symbol* s = dynamic_cast<Symbol*>(v);
assert(s);
assert(Symbols::name(s));
i += sizeof(Value*);
break;
}
case ImmediateType::CodeVector:
case ImmediateType::Code: {
Value* v = *((Value**)&bc[i]);
assert(dynamic_cast<Code*>(v));
i += sizeof(Value*);
if (BC_immediate[(B)pc] == ImmediateType::CodeVector)
goto vector;
break;
}
case ImmediateType::Vector: {
vector:
Value* v = *((Value**)&bc[i]);
assert(dynamic_cast<Vector*>(v));
i += sizeof(Value*);
break;
}
case ImmediateType::Value: {
Value* v = *((Value**)&bc[i]);
assert(dynamic_cast<Value*>(v));
assert(*(int*)v);
i += sizeof(Value*);
break;
}
case ImmediateType::Unsigned: {
i += sizeof(unsigned);
break;
}
}
}
assert(i == size);
}