diff --git a/src/evm/evm.rs b/src/evm/evm.rs index b25eabc15..41ce32b9e 100644 --- a/src/evm/evm.rs +++ b/src/evm/evm.rs @@ -12,5 +12,5 @@ pub enum ReturnCode { } pub trait Evm { - fn exec(data: RuntimeData, env: &mut Env) -> ReturnCode; + fn exec(&self, data: RuntimeData, env: &mut Env) -> ReturnCode; } diff --git a/src/evm/jit.rs b/src/evm/jit.rs index 3af980207..bb9527b95 100644 --- a/src/evm/jit.rs +++ b/src/evm/jit.rs @@ -189,7 +189,7 @@ impl From for evm::ReturnCode { pub struct JitEvm; impl evm::Evm for JitEvm { - fn exec(data: evm::RuntimeData, env: &mut evm::Env) -> evm::ReturnCode { + fn exec(&self, data: evm::RuntimeData, env: &mut evm::Env) -> evm::ReturnCode { // Dirty hack. This is unsafe, but we interact with ffi, so it's justified. let env_adapter: EnvAdapter<'static> = unsafe { ::std::mem::transmute(EnvAdapter::new(env)) }; let mut env_handle = evmjit::EnvHandle::new(env_adapter); @@ -205,6 +205,7 @@ mod tests { use util::uint::*; use evm::*; use evm::jit::{FromJit, IntoJit}; + use super::*; #[test] fn test_to_and_from_u256() { @@ -254,7 +255,8 @@ mod tests { data.origin = Address::from_str("cd1722f3947def4cf144679da39c4c32bdc35681").unwrap(); data.call_value = U256::from_str("0de0b6b3a7640000").unwrap(); let mut env = Env::new(); - assert_eq!(JitEvm::exec(data, &mut env), ReturnCode::Stop); + let evm = JitEvm; + assert_eq!(evm.exec(data, &mut env), ReturnCode::Stop); } } diff --git a/src/evm/mod.rs b/src/evm/mod.rs index 095c47dd6..304a4cc78 100644 --- a/src/evm/mod.rs +++ b/src/evm/mod.rs @@ -3,12 +3,10 @@ pub mod env; pub mod runtime_data; pub mod evm; +pub mod vmfactory; #[cfg(feature = "jit" )] -pub mod jit; +mod jit; pub use self::evm::{Evm, ReturnCode}; pub use self::env::Env; pub use self::runtime_data::RuntimeData; - -#[cfg(feature = "jit" )] -pub use self::jit::JitEvm; diff --git a/src/evm/vmfactory.rs b/src/evm/vmfactory.rs new file mode 100644 index 000000000..404a95f46 --- /dev/null +++ b/src/evm/vmfactory.rs @@ -0,0 +1,26 @@ +//! Vm factory. + +use evm::Evm; + +/// Vm factory. Creates appropriate Evm. +/// TODO: SmartVm +pub struct VmFactory; + +impl VmFactory { + /// Returns jit vm + #[cfg(feature = "jit")] + pub fn create() -> Box { + Box::new(super::jit::JitEvm) + } + + /// Returns native rust evm + #[cfg(not(feature = "jit"))] + pub fn create() -> Box { + unimplemented!(); + } +} + +#[test] +fn test_create_vm() { + let _vm = VmFactory::create(); +}