feat(runtime): add optional pause and resume lifecycle hooks
Intrepid/Prometeu/Runtime/pipeline/pr-master Build started...
Intrepid/Prometeu/Runtime/pipeline/pr-master Build started...
This commit is contained in:
@@ -101,6 +101,7 @@ fn serialized_single_function_module_with_consts(
|
||||
TestProgram {
|
||||
const_pool,
|
||||
functions: vec![FunctionDecl {
|
||||
lifecycle_role: Default::default(),
|
||||
code_offset: 0,
|
||||
code_len: code.len() as u32,
|
||||
|
||||
|
||||
@@ -105,7 +105,8 @@ impl VirtualMachineRuntime {
|
||||
match step_result {
|
||||
Ok(())
|
||||
| Err(
|
||||
LogicalFrameEndingReason::FrameSync
|
||||
LogicalFrameEndingReason::LifecycleComplete
|
||||
| LogicalFrameEndingReason::FrameSync
|
||||
| LogicalFrameEndingReason::BudgetExhausted
|
||||
| LogicalFrameEndingReason::Halted
|
||||
| LogicalFrameEndingReason::EndOfRom
|
||||
@@ -138,6 +139,55 @@ impl VirtualMachineRuntime {
|
||||
}
|
||||
}
|
||||
|
||||
/// Uses the session's real services, outside logical-frame accounting.
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub(crate) fn tick_lifecycle(
|
||||
&mut self,
|
||||
log_service: &mut LogService,
|
||||
fs: &mut VirtualFS,
|
||||
fs_state: &mut FsState,
|
||||
memcard: &mut MemcardService,
|
||||
open_files: &mut HashMap<u32, String>,
|
||||
next_handle: &mut u32,
|
||||
vm: &mut VirtualMachine,
|
||||
platform: &mut dyn RuntimePlatform,
|
||||
single_step: bool,
|
||||
) -> LogicalFrameEndingReason {
|
||||
if self.paused && !single_step && !self.debug_step_request {
|
||||
return LogicalFrameEndingReason::Breakpoint;
|
||||
}
|
||||
let result = catch_unwind(AssertUnwindSafe(|| {
|
||||
let mut ctx = HostContext::new_platform(Some(platform));
|
||||
let mut host = VmRuntimeHost {
|
||||
runtime: self,
|
||||
log_service,
|
||||
fs,
|
||||
fs_state,
|
||||
memcard,
|
||||
open_files,
|
||||
next_handle,
|
||||
};
|
||||
if single_step {
|
||||
vm.step(&mut host, &mut ctx)
|
||||
.err()
|
||||
.unwrap_or(LogicalFrameEndingReason::BudgetExhausted)
|
||||
} else {
|
||||
vm.run_budget(VirtualMachine::LIFECYCLE_SLICE, &mut host, &mut ctx)
|
||||
.map(|report| report.reason)
|
||||
.unwrap_or_else(LogicalFrameEndingReason::Panic)
|
||||
}
|
||||
}));
|
||||
let reason = result.unwrap_or_else(|payload| {
|
||||
LogicalFrameEndingReason::Panic(Self::host_panic_payload_to_string(payload))
|
||||
});
|
||||
if reason == LogicalFrameEndingReason::Breakpoint || single_step || self.debug_step_request
|
||||
{
|
||||
self.paused = true;
|
||||
self.debug_step_request = false;
|
||||
}
|
||||
reason
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn tick(
|
||||
&mut self,
|
||||
|
||||
Reference in New Issue
Block a user