Skip to content

Commit 4a4598e

Browse files
committed
refactor: Add a new trait between AsmMachine and Box<AsmCoreMachine>
In current design, AsmMachine is a right 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 610fb29 commit 4a4598e

File tree

2 files changed

+161
-122
lines changed

2 files changed

+161
-122
lines changed

definitions/src/asm.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,17 @@ pub struct AsmCoreMachine {
6666

6767
pub memory: [u8; RISCV_MAX_MEMORY],
6868
}
69+
70+
impl AsRef<Box<AsmCoreMachine>> for Box<AsmCoreMachine> {
71+
#[inline(always)]
72+
fn as_ref(&self) -> &Box<AsmCoreMachine> {
73+
self
74+
}
75+
}
76+
77+
impl AsMut<Box<AsmCoreMachine>> for Box<AsmCoreMachine> {
78+
#[inline(always)]
79+
fn as_mut(&mut self) -> &mut Box<AsmCoreMachine> {
80+
self
81+
}
82+
}

0 commit comments

Comments
 (0)