removed redundant VMType enum with one variant (#11266)

This commit is contained in:
Marek Kotewicz
2019-11-20 11:11:36 +08:00
committed by GitHub
parent 82c3265858
commit e0091c672a
18 changed files with 29 additions and 117 deletions

View File

@@ -21,12 +21,10 @@ use vm::{Exec, Schedule};
use ethereum_types::U256;
use super::vm::ActionParams;
use super::interpreter::SharedCache;
use super::vmtype::VMType;
/// Evm factory. Creates appropriate Evm.
#[derive(Clone)]
pub struct Factory {
evm: VMType,
evm_cache: Arc<SharedCache>,
}
@@ -34,20 +32,17 @@ impl Factory {
/// Create fresh instance of VM
/// Might choose implementation depending on supplied gas.
pub fn create(&self, params: ActionParams, schedule: &Schedule, depth: usize) -> Box<dyn Exec> {
match self.evm {
VMType::Interpreter => if Self::can_fit_in_usize(&params.gas) {
Box::new(super::interpreter::Interpreter::<usize>::new(params, self.evm_cache.clone(), schedule, depth))
} else {
Box::new(super::interpreter::Interpreter::<U256>::new(params, self.evm_cache.clone(), schedule, depth))
}
if Self::can_fit_in_usize(&params.gas) {
Box::new(super::interpreter::Interpreter::<usize>::new(params, self.evm_cache.clone(), schedule, depth))
} else {
Box::new(super::interpreter::Interpreter::<U256>::new(params, self.evm_cache.clone(), schedule, depth))
}
}
/// Create new instance of specific `VMType` factory, with a size in bytes
/// Create new instance of a factory, with a size in bytes
/// for caching jump destinations.
pub fn new(evm: VMType, cache_size: usize) -> Self {
pub fn new(cache_size: usize) -> Self {
Factory {
evm,
evm_cache: Arc::new(SharedCache::new(cache_size)),
}
}
@@ -61,7 +56,6 @@ impl Default for Factory {
/// Returns native rust evm factory
fn default() -> Factory {
Factory {
evm: VMType::Interpreter,
evm_cache: Arc::new(SharedCache::default()),
}
}
@@ -85,7 +79,7 @@ macro_rules! evm_test(
($name_test: ident: $name_int: ident) => {
#[test]
fn $name_int() {
$name_test(Factory::new(VMType::Interpreter, 1024 * 32));
$name_test(Factory::new(1024 * 32));
}
}
);
@@ -98,7 +92,7 @@ macro_rules! evm_test_ignore(
#[ignore]
#[cfg(feature = "ignored-tests")]
fn $name_int() {
$name_test(Factory::new(VMType::Interpreter, 1024 * 32));
$name_test(Factory::new(1024 * 32));
}
}
);

View File

@@ -1213,14 +1213,13 @@ fn address_to_u256(value: Address) -> U256 {
mod tests {
use std::sync::Arc;
use rustc_hex::FromHex;
use vmtype::VMType;
use factory::Factory;
use vm::{self, Exec, ActionParams, ActionValue};
use vm::tests::{FakeExt, test_finalize};
use ethereum_types::Address;
fn interpreter(params: ActionParams, ext: &dyn vm::Ext) -> Box<dyn Exec> {
Factory::new(VMType::Interpreter, 1).create(params, ext.schedule(), ext.depth())
Factory::new(1).create(params, ext.schedule(), ext.depth())
}
#[test]

View File

@@ -41,7 +41,6 @@ pub mod interpreter;
#[macro_use]
pub mod factory;
mod vmtype;
mod instructions;
#[cfg(test)]
@@ -54,5 +53,4 @@ pub use vm::{
};
pub use self::evm::{Finalize, FinalizationResult, CostType};
pub use self::instructions::{InstructionInfo, Instruction};
pub use self::vmtype::VMType;
pub use self::factory::Factory;

View File

@@ -23,7 +23,6 @@ use ethereum_types::{U256, H256, Address};
use vm::{self, ActionParams, ActionValue, Ext};
use vm::tests::{FakeExt, FakeCall, FakeCallType, test_finalize};
use factory::Factory;
use vmtype::VMType;
use hex_literal::hex;
evm_test!{test_add: test_add_int}
@@ -705,7 +704,7 @@ fn test_signextend(factory: super::Factory) {
#[test] // JIT just returns out of gas
fn test_badinstruction_int() {
let factory = super::Factory::new(VMType::Interpreter, 1024 * 32);
let factory = super::Factory::new(1024 * 32);
let code = hex!("af").to_vec();
let mut params = ActionParams::default();

View File

@@ -1,45 +0,0 @@
// Copyright 2015-2019 Parity Technologies (UK) Ltd.
// This file is part of Parity Ethereum.
// Parity Ethereum is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Parity Ethereum is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Parity Ethereum. If not, see <http://www.gnu.org/licenses/>.
use std::fmt;
/// Type of EVM to use.
#[derive(Debug, PartialEq, Clone)]
pub enum VMType {
/// RUST EVM
Interpreter
}
impl fmt::Display for VMType {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", match *self {
VMType::Interpreter => "INT"
})
}
}
impl Default for VMType {
fn default() -> Self {
VMType::Interpreter
}
}
impl VMType {
/// Return all possible VMs (Interpreter)
pub fn all() -> Vec<VMType> {
vec![VMType::Interpreter]
}
}