Added implementations of framework functions

This commit is contained in:
Dan Hirsch 2013-03-17 20:17:55 -07:00
parent 4c2a536151
commit 17b03dbf4d
3 changed files with 53 additions and 3 deletions

View file

@ -245,4 +245,52 @@ HParseResult *run_trace(HAllocator *mm__, HRVMProg *orig_prog, HRVMTrace *trace,
return NULL;
}
bool h_compile_regex(HRVMProg *prog, const HParser *parser) {
return parser->vtable->compile_to_rvm(prog, parser->env);
}
uint16_t h_rvm_create_action(HRVMProg *prog, HSVMActionFunc action_func, void* env) {
for (uint16_t i = 0; i < prog->action_count; i++) {
if (prog->actions[i].action == action_func && prog->actions[i].env == env)
return i;
}
// Ensure that there's room in the action array...
if (!(prog->action_count & (prog->action_count + 1))) {
// needs to be scaled up.
array_size = (prog->action_count + 1) * 2; // action_count+1 is a
// power of two
prog->actions = prog->allocator->realloc(prog->actions, array_size * sizeof(*prog->actions));
// TODO: Handle the allocation failed case nicely.
}
HAction *action = &prog->actions[prog->action_count];
action->action = action_func;
action->env = env;
return prog->action_count++;
}
uint16_t h_rvm_insert_insn(HRVMProg *prog, HRVMOp op, uint16_t arg) {
// Ensure that there's room in the insn array...
if (!(prog->length & (prog->length + 1))) {
// needs to be scaled up.
array_size = (prog->length + 1) * 2; // action_count+1 is a
// power of two
prog->insns = prog->allocator->realloc(prog->insns, array_size * sizeof(*prog->insns));
// TODO: Handle the allocation failed case nicely.
}
prog->insns[prog->length].op = op;
prog->insns[prog->length].arg = arg;
return prog->length++;
}
uint16_t h_rvm_get_ip(HRVMProg *prog) {
return prog->length;
}
void h_rvm_patch_arg(HRVMProg *prog, uint16_t ip, uint16_t new_val) {
assert(prog->length > ip);
prog->insns[ip].arg = new_val;
}
// TODO: Implement the primitive actions