Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add string encoding suffixes #127

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Allow strings in integer expressions
  • Loading branch information
Artentus committed Oct 26, 2021
commit c9ce7c6e14386721df30f74fd74c42edde64a841
54 changes: 53 additions & 1 deletion src/asm/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -916,6 +916,23 @@ impl State
Ok(())
}
}
else if let expr::Value::String(value_s) = value
{
let mut value_int = value_s.to_bigint();

if value_int.min_size() > size
{
report.error_span(
&format!("argument out of range for type `u{}`", size),
&span);
Err(())
}
else
{
value_int.size = Some(size);
Ok(())
}
}
else
{
report.error_span(
Expand Down Expand Up @@ -944,6 +961,24 @@ impl State
Ok(())
}
}
else if let expr::Value::String(value_s) = value
{
let mut value_int = value_s.to_bigint();

if (value_int.sign() == 0 && size == 0) ||
(value_int.min_size() >= size)
{
report.error_span(
&format!("argument out of range for type `s{}`", size),
&span);
Err(())
}
else
{
value_int.size = Some(size);
Ok(())
}
}
else
{
report.error_span(
Expand All @@ -970,6 +1005,23 @@ impl State
Ok(())
}
}
else if let expr::Value::String(value_s) = value
{
let mut value_int = value_s.to_bigint();

if value_int.min_size() > size
{
report.error_span(
&format!("argument out of range for type `i{}`", size),
&span);
Err(())
}
else
{
value_int.size = Some(size);
Ok(())
}
}
else
{
report.error_span(
Expand Down Expand Up @@ -1232,7 +1284,7 @@ impl State
State::eval_fn_check_arg_number(info, 1)?;
if State::eval_fn_check_unknown_arg(info, 0, self.is_first_pass)
{
return Ok(expr::Value::make_integer(util::BigInt::new_from_str("")));
return Ok(expr::Value::make_integer(util::BigInt::from_bytes_be(&"".bytes().collect::<Vec<u8>>())));
}

let value_string = State::eval_fn_get_string_arg(info, 0)?;
Expand Down