This commit is contained in:
Tomusdrw
2016-02-03 15:57:17 +01:00
parent 2b4653ee35
commit 8a2db83803
3 changed files with 32 additions and 22 deletions

View File

@@ -1,26 +1,35 @@
//! Evm factory.
//!
//! TODO: consider spliting it into two separate files.
#[cfg(test)]
use std::fmt;
use evm::Evm;
#[derive(Clone)]
/// Type of EVM to use.
pub enum VMType {
#[allow(dead_code)] // crated only by jit
/// JIT EVM
#[cfg(feature="jit")]
Jit,
/// RUST EVM
Interpreter
}
#[cfg(test)]
impl fmt::Display for VMType {
#[cfg(feature="jit")]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", match *self {
VMType::Jit => "JIT",
VMType::Interpreter => "INT"
})
}
#[cfg(not(feature="jit"))]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", match *self {
VMType::Interpreter => "INT"
})
}
}
#[cfg(test)]
@@ -46,10 +55,12 @@ pub struct Factory {
impl Factory {
/// Create fresh instance of VM
#[cfg(test)]
#[cfg(feature="jit")]
pub fn create(&self) -> Box<Evm> {
match self.evm {
VMType::Jit => {
Factory::jit()
Box::new(super::jit::JitEvm)
},
VMType::Interpreter => {
Box::new(super::interpreter::Interpreter)
@@ -57,6 +68,16 @@ impl Factory {
}
}
/// Create fresh instance of VM
#[cfg(not(feature="jit"))]
pub fn create(&self) -> Box<Evm> {
match self.evm {
VMType::Interpreter => {
Box::new(super::interpreter::Interpreter)
}
}
}
/// Create new instance of specific `VMType` factory
#[cfg(test)]
pub fn new(evm: VMType) -> Factory {
@@ -64,16 +85,6 @@ impl Factory {
evm: evm
}
}
#[cfg(feature = "jit")]
fn jit() -> Box<Evm> {
Box::new(super::jit::JitEvm)
}
#[cfg(not(feature = "jit"))]
fn jit() -> Box<Evm> {
unimplemented!()
}
}
impl Default for Factory {
/// Returns jitvm factory