Skip to content

Commit b64eda4

Browse files
authored
refactor: Add a new trait between AsmMachine and Box<AsmCoreMachine> (#473)
In current design, AsmMachine is a rigid type containing Box<AsmCoreMachine> directly. This is required in a sense that assembly VM needs to know the inner data structures of AsmCoreMachine so as to function. However, It also puts a restriction on AsmMachine: while you can do the following in Rust VM: ``` DefaultMachine<Foo<DefaultCoreMachine<...>> ``` as long as Foo implements SupportMachine via a newtype pattern, this is not possible on AsmMachine. However there are certain cases we need wrappers on `Box<AsmCoreMachine>` to customize behaviors. This commit introduces a a new trait `AsmCoreMachineRevealer` between AsmMachine and AsmCoreMachine, it provides a mean for users of AsmMachine to customize its behavior, while also requires the presence of AsmCoreMachine, so assembly VM can still function. If only Rust has generic specialization, we won't need to go through all those troubles...
1 parent cfb1d01 commit b64eda4

File tree

3 files changed

+186
-139
lines changed

3 files changed

+186
-139
lines changed

definitions/src/asm.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,3 +118,17 @@ impl AsmCoreMachine {
118118
self.max_cycles = cycles;
119119
}
120120
}
121+
122+
impl AsRef<AsmCoreMachine> for AsmCoreMachine {
123+
#[inline(always)]
124+
fn as_ref(&self) -> &AsmCoreMachine {
125+
self
126+
}
127+
}
128+
129+
impl AsMut<AsmCoreMachine> for AsmCoreMachine {
130+
#[inline(always)]
131+
fn as_mut(&mut self) -> &mut AsmCoreMachine {
132+
self
133+
}
134+
}

0 commit comments

Comments
 (0)