Skip to content
Snippets Groups Projects
Unverified Commit a106a003 authored by Yorick Peterse's avatar Yorick Peterse
Browse files

Use a function for integer shift errors

This reduces the size of the various shift functions by about 1 KB when
not stripping the binary.
parent 460e66b5
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -44,7 +44,7 @@ macro_rules! shift_integer {
to_shift_big.$op(shift_with as usize)
}
} else {
return Err(shift_error!($to_shift, $shift_with));
return Err(shift_error($to_shift, $shift_with)?);
};
 
$process.allocate(object_value::bigint(bigint), $proto)
Loading
Loading
@@ -114,24 +114,6 @@ macro_rules! invert_shift {
}};
}
 
/// Generates an error message to display in the event of a shift error.
macro_rules! shift_error {
($to_shift:expr, $shift_with:expr) => {{
if $shift_with.is_integer() || $shift_with.is_bigint() {
format!(
"Can't shift integer {} with {} as the operand is too big",
$to_shift.integer_to_string()?,
$shift_with.integer_to_string()?
)
} else {
format!(
"Can't shift integer {} because the operand is not an integer",
$to_shift.integer_to_string()?,
)
}
}};
}
pub fn invert_integer_for_shift(
process: &RcProcess,
integer: ObjectPointer,
Loading
Loading
@@ -179,7 +161,7 @@ pub fn integer_shift_left(
integer_shift_right
)
} else {
Err(shift_error!(to_shift_ptr, shift_with_ptr))
Err(shift_error(to_shift_ptr, shift_with_ptr)?)
}
}
 
Loading
Loading
@@ -211,7 +193,7 @@ pub fn integer_shift_right(
integer_shift_left
)
} else {
Err(shift_error!(to_shift_ptr, shift_with_ptr))
Err(shift_error(to_shift_ptr, shift_with_ptr)?)
}
}
 
Loading
Loading
@@ -241,7 +223,7 @@ pub fn bigint_shift_left(
bigint_shift_right
)
} else {
Err(shift_error!(to_shift_ptr, shift_with_ptr))
Err(shift_error(to_shift_ptr, shift_with_ptr)?)
}
}
 
Loading
Loading
@@ -271,6 +253,27 @@ pub fn bigint_shift_right(
bigint_shift_left
)
} else {
Err(shift_error!(to_shift_ptr, shift_with_ptr))
Err(shift_error(to_shift_ptr, shift_with_ptr)?)
}
}
/// Generates an error message to display in the event of a shift error.
fn shift_error(
to_shift: ObjectPointer,
shift_with: ObjectPointer,
) -> Result<String, String> {
let message = if shift_with.is_integer() || shift_with.is_bigint() {
format!(
"Can't shift integer {} with {} as the operand is too big",
to_shift.integer_to_string()?,
shift_with.integer_to_string()?
)
} else {
format!(
"Can't shift integer {} because the operand is not an integer",
to_shift.integer_to_string()?,
)
};
Ok(message)
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment