From 0d1d35ec2b10d4924c8a4304be3024aec8e624ca Mon Sep 17 00:00:00 2001 From: Jan Ferdinand Sauer Date: Mon, 11 Mar 2024 14:35:48 +0100 Subject: [PATCH] feat: more powerful `triton_instr!` macro Use `from` and `try_from` where applicable. --- triton-vm/src/lib.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/triton-vm/src/lib.rs b/triton-vm/src/lib.rs index 6b49950a..7a8c5bc7 100644 --- a/triton-vm/src/lib.rs +++ b/triton-vm/src/lib.rs @@ -417,28 +417,28 @@ macro_rules! triton_asm { #[macro_export] macro_rules! triton_instr { (pop $arg:literal) => {{ - let argument: $crate::op_stack::NumberOfWords = u32::try_into($arg).unwrap(); + let argument = $crate::op_stack::NumberOfWords::try_from($arg).unwrap(); let instruction = $crate::instruction::AnInstruction::::Pop(argument); $crate::instruction::LabelledInstruction::Instruction(instruction) }}; (push $arg:expr) => {{ - let argument = $crate::prelude::BFieldElement::new($arg); + let argument = $crate::prelude::BFieldElement::from($arg); let instruction = $crate::instruction::AnInstruction::::Push(argument); $crate::instruction::LabelledInstruction::Instruction(instruction) }}; (divine $arg:literal) => {{ - let argument: $crate::op_stack::NumberOfWords = u32::try_into($arg).unwrap(); + let argument = $crate::op_stack::NumberOfWords::try_from($arg).unwrap(); let instruction = $crate::instruction::AnInstruction::::Divine(argument); $crate::instruction::LabelledInstruction::Instruction(instruction) }}; (dup $arg:literal) => {{ - let argument: $crate::op_stack::OpStackElement = u32::try_into($arg).unwrap(); + let argument = $crate::op_stack::OpStackElement::try_from($arg).unwrap(); let instruction = $crate::instruction::AnInstruction::::Dup(argument); $crate::instruction::LabelledInstruction::Instruction(instruction) }}; (swap $arg:literal) => {{ assert_ne!(0_u32, $arg, "`swap 0` is illegal."); - let argument: $crate::op_stack::OpStackElement = u32::try_into($arg).unwrap(); + let argument = $crate::op_stack::OpStackElement::try_from($arg).unwrap(); let instruction = $crate::instruction::AnInstruction::::Swap(argument); $crate::instruction::LabelledInstruction::Instruction(instruction) }}; @@ -448,22 +448,22 @@ macro_rules! triton_instr { $crate::instruction::LabelledInstruction::Instruction(instruction) }}; (read_mem $arg:literal) => {{ - let argument: $crate::op_stack::NumberOfWords = u32::try_into($arg).unwrap(); + let argument = $crate::op_stack::NumberOfWords::try_from($arg).unwrap(); let instruction = $crate::instruction::AnInstruction::::ReadMem(argument); $crate::instruction::LabelledInstruction::Instruction(instruction) }}; (write_mem $arg:literal) => {{ - let argument: $crate::op_stack::NumberOfWords = u32::try_into($arg).unwrap(); + let argument = $crate::op_stack::NumberOfWords::try_from($arg).unwrap(); let instruction = $crate::instruction::AnInstruction::::WriteMem(argument); $crate::instruction::LabelledInstruction::Instruction(instruction) }}; (read_io $arg:literal) => {{ - let argument: $crate::op_stack::NumberOfWords = u32::try_into($arg).unwrap(); + let argument = $crate::op_stack::NumberOfWords::try_from($arg).unwrap(); let instruction = $crate::instruction::AnInstruction::::ReadIo(argument); $crate::instruction::LabelledInstruction::Instruction(instruction) }}; (write_io $arg:literal) => {{ - let argument: $crate::op_stack::NumberOfWords = u32::try_into($arg).unwrap(); + let argument = $crate::op_stack::NumberOfWords::try_from($arg).unwrap(); let instruction = $crate::instruction::AnInstruction::::WriteIo(argument); $crate::instruction::LabelledInstruction::Instruction(instruction) }};