diff --git a/script/src/lib.rs b/script/src/lib.rs index 5adfd1fc9c..8b2d128039 100644 --- a/script/src/lib.rs +++ b/script/src/lib.rs @@ -9,8 +9,8 @@ mod verify_env; pub use crate::error::{ScriptError, TransactionScriptError}; pub use crate::types::{ - CoreMachine, ScriptGroup, ScriptGroupType, ScriptVersion, TransactionSnapshot, - TransactionState, VerifyResult, VmIsa, VmVersion, + CoreMachine, MachineContext, ResumableMachine, ScriptGroup, ScriptGroupType, ScriptVersion, + TransactionSnapshot, TransactionState, VerifyResult, VmIsa, VmVersion, }; pub use crate::verify::{TransactionScriptsSyscallsGenerator, TransactionScriptsVerifier}; pub use crate::verify_env::TxVerifyEnv; diff --git a/script/src/types.rs b/script/src/types.rs index 055c3c0f7e..1fdab303c1 100644 --- a/script/src/types.rs +++ b/script/src/types.rs @@ -117,7 +117,8 @@ pub(crate) type Machine = TraceMachine; /// a chain of spawned machines. #[derive(Default)] pub struct MachineContext { - pub(crate) suspended_machines: Vec, + /// A stack of ResumableMachines. + pub suspended_machines: Vec, } /// Data structure captured all environment data for a suspended machine @@ -175,8 +176,11 @@ impl TryFrom<&SpawnData> for ResumePoint { } } +/// An enumerated type indicating the type of the Machine. pub enum ResumableMachine { + /// Root machine instance. Initial(Machine), + /// A machine which created by spawn syscall. Spawn(Machine, SpawnData), } @@ -211,10 +215,12 @@ impl ResumableMachine { set_vm_max_cycles(self.machine_mut(), cycles) } + /// Add cycles to current machine. pub fn add_cycles(&mut self, cycles: Cycle) -> Result<(), VMInternalError> { self.machine_mut().machine.add_cycles(cycles) } + /// Run machine. pub fn run(&mut self) -> Result { self.machine_mut().run() }