add common crate

Signed-off-by: xermicus <cyrill@parity.io>
This commit is contained in:
xermicus
2024-03-22 16:19:18 +01:00
parent 50f2dd9b74
commit c52a8d0f20
65 changed files with 839 additions and 271 deletions
@@ -125,13 +125,12 @@ impl Literal {
.as_basic_value_enum();
let constant = match inner {
IntegerLiteral::Decimal { ref inner } => num::BigUint::from_str_radix(
inner.as_str(),
era_compiler_common::BASE_DECIMAL,
),
IntegerLiteral::Decimal { ref inner } => {
num::BigUint::from_str_radix(inner.as_str(), revive_common::BASE_DECIMAL)
}
IntegerLiteral::Hexadecimal { ref inner } => num::BigUint::from_str_radix(
&inner["0x".len()..],
era_compiler_common::BASE_HEXADECIMAL,
revive_common::BASE_HEXADECIMAL,
),
}
.expect("Always valid");
@@ -148,7 +147,7 @@ impl Literal {
string.clone()
} else {
let mut hex_string =
String::with_capacity(era_compiler_common::BYTE_LENGTH_FIELD * 2);
String::with_capacity(revive_common::BYTE_LENGTH_FIELD * 2);
let mut index = 0;
loop {
if index >= string.len() {
@@ -165,7 +164,7 @@ impl Literal {
let codepoint_str = &string[index + 1..index + 5];
let codepoint = u32::from_str_radix(
codepoint_str,
era_compiler_common::BASE_HEXADECIMAL,
revive_common::BASE_HEXADECIMAL,
)
.map_err(|error| {
anyhow::anyhow!(
@@ -209,16 +208,16 @@ impl Literal {
hex_string
};
if hex_string.len() > era_compiler_common::BYTE_LENGTH_FIELD * 2 {
if hex_string.len() > revive_common::BYTE_LENGTH_FIELD * 2 {
return Ok(era_compiler_llvm_context::EraVMArgument::new_with_original(
r#type.const_zero().as_basic_value_enum(),
string,
));
}
if hex_string.len() < era_compiler_common::BYTE_LENGTH_FIELD * 2 {
if hex_string.len() < revive_common::BYTE_LENGTH_FIELD * 2 {
hex_string.push_str(
"0".repeat((era_compiler_common::BYTE_LENGTH_FIELD * 2) - hex_string.len())
"0".repeat((revive_common::BYTE_LENGTH_FIELD * 2) - hex_string.len())
.as_str(),
);
}