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

eq and neq parsers, u32 error message #528

Merged
merged 1 commit into from
Nov 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions assembly/src/parsers/ast/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -438,8 +438,8 @@ fn parse_op_token(op: &Token) -> Result<Node, AssemblyError> {
"u32checked_rotl" => u32_ops::parse_u32_rotl(op, true),
"u32unchecked_rotl" => u32_ops::parse_u32_rotl(op, false),

"u32checked_eq" => simple_instruction(op, U32CheckedEq),
"u32checked_neq" => simple_instruction(op, U32CheckedNeq),
"u32checked_eq" => u32_ops::parse_u32checked_eq(op),
"u32checked_neq" => u32_ops::parse_u32checked_neq(op),

"u32checked_lt" => simple_instruction(op, U32CheckedLt),
"u32unchecked_lt" => simple_instruction(op, U32UncheckedLt),
Expand Down
34 changes: 34 additions & 0 deletions assembly/src/parsers/ast/u32_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -389,3 +389,37 @@ pub fn parse_u32_rotl(op: &Token, checked: bool) -> Result<Node, AssemblyError>
_ => Err(AssemblyError::extra_param(op)),
}
}

/// Returns `U32CheckedEq` instruction node if no immediate value is provided or
/// `U32CheckedEqImm` instruction node otherwise.
///
/// # Errors
/// Returns an error if the instruction token contains wrong number of parameters, or if the
/// provided parameter is not a u32 value.
pub fn parse_u32checked_eq(op: &Token) -> Result<Node, AssemblyError> {
match op.num_parts() {
1 => Ok(Instruction(U32CheckedEq)),
2 => {
let value = parse_param::<u32>(op, 1)?;
Ok(Instruction(U32CheckedEqImm(value)))
}
_ => Err(AssemblyError::extra_param(op)),
}
}

/// Returns `U32CheckedNeq` instruction node if no immediate value is provided or
/// `U32CheckedNeqImm` instruction node otherwise.
///
/// # Errors
/// Returns an error if the instruction token contains wrong number of parameters, or if the
/// provided parameter is not a u32 value.
pub fn parse_u32checked_neq(op: &Token) -> Result<Node, AssemblyError> {
match op.num_parts() {
1 => Ok(Instruction(U32CheckedNeq)),
2 => {
let value = parse_param::<u32>(op, 1)?;
Ok(Instruction(U32CheckedNeqImm(value)))
}
_ => Err(AssemblyError::extra_param(op)),
}
}
6 changes: 3 additions & 3 deletions miden/tests/integration/operations/u32_ops/arithmetic_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -792,7 +792,7 @@ fn u32checked_div_b_fail() {

// should fail during compilation if b = 0.
let test = build_op_test!(build_asm_op(0).as_str());
test.expect_error(TestError::AssemblyError("parameter"));
test.expect_error(TestError::AssemblyError("division by zero"));
}

#[test]
Expand Down Expand Up @@ -885,7 +885,7 @@ fn u32checked_mod_b_fail() {

// should fail during compilation if b = 0.
let test = build_op_test!(build_asm_op(0).as_str());
test.expect_error(TestError::AssemblyError("parameter"));
test.expect_error(TestError::AssemblyError("division by zero"));
}

#[test]
Expand Down Expand Up @@ -980,7 +980,7 @@ fn u32checked_divmod_b_fail() {

// should fail during compilation if b = 0.
let test = build_op_test!(build_asm_op(0).as_str());
test.expect_error(TestError::AssemblyError("parameter"));
test.expect_error(TestError::AssemblyError("division by zero"));
}

#[test]
Expand Down