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

View File

@ -11,7 +11,6 @@ pub struct StateDiff (BTreeMap<Address, AccountDiff>);
impl StateDiff {
#[cfg(test)]
/// Calculate and return diff between `pre` state and `post` state.
#[allow(dead_code)] // Used only in test code for now.
pub fn diff_pod(pre: &PodState, post: &PodState) -> StateDiff {
StateDiff(pre.get().keys().merge(post.get().keys()).filter_map(|acc| AccountDiff::diff_pod(pre.get().get(acc), post.get().get(acc)).map(|d|(acc.clone(), d))).collect())
}

View File

@ -46,10 +46,10 @@ impl Drop for RandomTempPath {
}
}
#[allow(dead_code)]
#[cfg(test)]
pub struct GuardedTempResult<T> {
result: T,
temp: RandomTempPath
_temp: RandomTempPath
}
impl<T> GuardedTempResult<T> {
@ -149,7 +149,7 @@ pub fn generate_dummy_client(block_number: u32) -> GuardedTempResult<Arc<Client>
client.import_verified_blocks(&IoChannel::disconnected());
GuardedTempResult::<Arc<Client>> {
temp: dir,
_temp: dir,
result: client
}
}
@ -167,7 +167,7 @@ pub fn get_test_client_with_blocks(blocks: Vec<Bytes>) -> GuardedTempResult<Arc<
client.import_verified_blocks(&IoChannel::disconnected());
GuardedTempResult::<Arc<Client>> {
temp: dir,
_temp: dir,
result: client
}
}
@ -180,7 +180,7 @@ pub fn generate_dummy_blockchain(block_number: u32) -> GuardedTempResult<BlockCh
}
GuardedTempResult::<BlockChain> {
temp: temp,
_temp: temp,
result: bc
}
}
@ -193,7 +193,7 @@ pub fn generate_dummy_blockchain_with_extra(block_number: u32) -> GuardedTempRes
}
GuardedTempResult::<BlockChain> {
temp: temp,
_temp: temp,
result: bc
}
}
@ -203,7 +203,7 @@ pub fn generate_dummy_empty_blockchain() -> GuardedTempResult<BlockChain> {
let bc = BlockChain::new(&create_unverifiable_block(0, H256::zero()), temp.as_path());
GuardedTempResult::<BlockChain> {
temp: temp,
_temp: temp,
result: bc
}
}
@ -213,7 +213,7 @@ pub fn get_temp_journal_db() -> GuardedTempResult<JournalDB> {
let db = DB::open_default(temp.as_str()).unwrap();
let journal_db = JournalDB::new(db);
GuardedTempResult {
temp: temp,
_temp: temp,
result: journal_db
}
}
@ -222,7 +222,7 @@ pub fn get_temp_state() -> GuardedTempResult<State> {
let temp = RandomTempPath::new();
let journal_db = get_temp_journal_db_in(temp.as_path());
GuardedTempResult {
temp: temp,
_temp: temp,
result: State::new(journal_db, U256::from(0u8))
}
}