diff options
author | Jo-Philipp Wich <jo@mein.io> | 2021-07-05 20:22:39 +0200 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2021-07-11 15:49:14 +0200 |
commit | 2f77657ae97f84edcd665c4cfe00ef91b9cde1bc (patch) | |
tree | bc786e60d2a743310f037a8bff595c9252011887 /vm.c | |
parent | 111645aa965717adb40604e53d0bab07e25c1b27 (diff) |
vm: extend API to allow returning result value from VM execution
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'vm.c')
-rw-r--r-- | vm.c | 16 |
1 files changed, 11 insertions, 5 deletions
@@ -2024,7 +2024,7 @@ uc_vm_output_exception(uc_vm *vm) } static uc_vm_status_t -uc_vm_execute_chunk(uc_vm *vm) +uc_vm_execute_chunk(uc_vm *vm, uc_value_t **retvalp) { uc_callframe *frame = uc_vm_current_frame(vm); uc_chunk *chunk = uc_vm_frame_chunk(frame); @@ -2227,7 +2227,10 @@ uc_vm_execute_chunk(uc_vm *vm) retval = uc_vm_callframe_pop(vm); if (vm->callframes.count == 0) { - ucv_put(retval); + if (retvalp) + *retvalp = retval; + else + ucv_put(retval); return STATUS_OK; } @@ -2280,7 +2283,7 @@ uc_vm_execute_chunk(uc_vm *vm) } uc_vm_status_t -uc_vm_execute(uc_vm *vm, uc_function_t *fn) +uc_vm_execute(uc_vm *vm, uc_function_t *fn, uc_value_t **retval) { uc_closure_t *closure = (uc_closure_t *)ucv_closure_new(vm, fn, false); uc_callframe *frame; @@ -2308,7 +2311,10 @@ uc_vm_execute(uc_vm *vm, uc_function_t *fn) //uc_vm_stack_push(vm, closure->header.jso); uc_vm_stack_push(vm, NULL); - return uc_vm_execute_chunk(vm); + if (retval) + *retval = NULL; + + return uc_vm_execute_chunk(vm, retval); } uc_exception_type_t @@ -2319,7 +2325,7 @@ uc_vm_call(uc_vm *vm, bool mcall, size_t nargs) if (uc_vm_call_function(vm, ctx, fno, mcall, nargs & 0xffff)) { if (ucv_type(fno) != UC_CFUNCTION) - uc_vm_execute_chunk(vm); + uc_vm_execute_chunk(vm, NULL); } return vm->exception.type; |