vm factory
This commit is contained in:
parent
3dd26582a2
commit
e3f59d82ef
@ -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;
|
||||
}
|
||||
|
@ -189,7 +189,7 @@ impl From<evmjit::ReturnCode> 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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;
|
||||
|
26
src/evm/vmfactory.rs
Normal file
26
src/evm/vmfactory.rs
Normal file
@ -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<Evm> {
|
||||
Box::new(super::jit::JitEvm)
|
||||
}
|
||||
|
||||
/// Returns native rust evm
|
||||
#[cfg(not(feature = "jit"))]
|
||||
pub fn create() -> Box<Evm> {
|
||||
unimplemented!();
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_create_vm() {
|
||||
let _vm = VmFactory::create();
|
||||
}
|
Loading…
Reference in New Issue
Block a user