Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
g-r-a-n-t committed Jul 27, 2021
1 parent 608cbc4 commit 6edbd31
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 14 deletions.
6 changes: 3 additions & 3 deletions crates/yulgen/src/mappers/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ use crate::mappers::{assignments, declarations, expressions};
use crate::names;
use crate::operations::data as data_operations;
use crate::operations::revert as revert_operations;
use crate::types::{AbiType, EvmSized, to_abi_types};
use crate::types::{AbiType, EvmSized};
use crate::Context;
use fe_analyzer::context::ExpressionAttributes;
use fe_analyzer::namespace::types::{FixedSize, Type};
use fe_analyzer::namespace::types::Type;
use fe_parser::ast as fe;
use fe_parser::node::Node;
use yultsur::*;
Expand Down Expand Up @@ -135,7 +135,7 @@ fn revert(context: &mut Context, stmt: &Node<fe::FuncStmt>) -> yul::Statement {
revert_operations::revert(
&_struct.name,
&AbiType::from(_struct),
expressions::expr(context, error_expr)
expressions::expr(context, error_expr),
)
} else {
panic!("trying to revert with non-struct expression")
Expand Down
2 changes: 1 addition & 1 deletion crates/yulgen/src/operations/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pub mod abi;
pub mod contracts;
pub mod data;
pub mod revert;
pub mod structs;
pub mod revert;
10 changes: 7 additions & 3 deletions crates/yulgen/src/operations/revert.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::types::AbiType;
use crate::names;
use crate::types::AbiType;
use yultsur::*;

// this is more of an assert operation
Expand All @@ -8,10 +8,14 @@ pub fn error_revert(typ: &AbiType, msg: yul::Expression) -> yul::Statement {
}

pub fn panic_revert(val: usize) -> yul::Statement {
revert("Panic", &AbiType::Uint { size: 32 }, literal_expression! { (val) })
revert(
"Panic",
&AbiType::Uint { size: 32 },
literal_expression! { (val) },
)
}

pub fn revert(name: &str, typ: &AbiType, val: yul::Expression) -> yul::Statement {
let func_name = names::revert(name, typ);
statement! { [func_name]([val]) }
}
}
10 changes: 7 additions & 3 deletions crates/yulgen/src/runtime/functions/abi.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
use crate::constants::PANIC_INVALID_ABI_DATA;
use crate::names::abi as abi_names;
use crate::operations::abi as abi_operations;
use crate::operations::revert as revert_operations;
use crate::operations::abi::EncodingSize;
use crate::operations::revert as revert_operations;
use crate::types::{AbiDecodeLocation, AbiType};
use crate::utils::ceil_32;
use yultsur::*;

/// Return all abi runtime functions
pub fn all() -> Vec<yul::Statement> {
vec![unpack(), is_left_padded(), is_right_padded(), encode(vec![AbiType::Uint { size: 32 }])]
vec![
unpack(),
is_left_padded(),
is_right_padded(),
encode(vec![AbiType::Uint { size: 32 }]),
]
}

/// Creates a batch of encoding function for the given type arrays.
Expand Down Expand Up @@ -43,7 +48,6 @@ pub fn batch_decode(data_batch: Vec<(Vec<AbiType>, AbiDecodeLocation)>) -> Vec<y
let component_functions: Vec<_> = component_batch
.into_iter()
.map(|(typ, location)| {
let typ: AbiType = typ.into();
let top_function = decode_component(&typ, location);

let inner_functions = match &typ {
Expand Down
6 changes: 2 additions & 4 deletions crates/yulgen/src/runtime/functions/revert.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use crate::names;
use crate::names::abi as abi_names;
use crate::operations::abi as abi_operations;
use crate::types::{to_abi_selector_names, AbiType, to_abi_types};
use fe_analyzer::namespace::types::Struct;
use crate::types::{to_abi_selector_names, AbiType};
use yultsur::*;

/// Generate a YUL function to revert with the `Error` signature and the
Expand All @@ -26,7 +24,7 @@ pub fn revert(name: &str, typ: &AbiType) -> yul::Statement {
let selector = {
let selector_params = match typ.clone() {
AbiType::Tuple { components } => components,
typ => vec![typ]
typ => vec![typ],
};
let selector = fe_abi::utils::func_selector(name, &to_abi_selector_names(&selector_params));
literal_expression! { (selector) }
Expand Down

0 comments on commit 6edbd31

Please sign in to comment.