, , :
typedef void (*code_ptr)();
unsigned long instruction_pointer = entry_point;
std::map<unsigned long, code_ptr> code_map;
void execute_block() {
code_ptr f;
std::map<unsigned long, void *>::iterator it = code_map.find(instruction_pointer);
if(it != code_map.end()) {
f = it->second
} else {
f = generate_code_block();
code_map[instruction_pointer] = f;
}
f();
instruction_pointer = update_instruction_pointer();
}
void execute() {
while(true) {
execute_block();
}
}
, . , , " " ( , ), , , . , , , .
:)
, , , "", .
EDIT: , , " "
2: , . , ( , , , ), "" , . . , f() "update_instruction_pointer", , , , "" ret jmp , ( ), . , VM, "execute_block".