Skip to content

Commit

Permalink
feat: more powerful triton_instr! macro
Browse files Browse the repository at this point in the history
Use `from` and `try_from` where applicable.
  • Loading branch information
jan-ferdinand committed Mar 14, 2024
1 parent b1fe8e0 commit 0d1d35e
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions triton-vm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<String>::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::<String>::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::<String>::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::<String>::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::<String>::Swap(argument);
$crate::instruction::LabelledInstruction::Instruction(instruction)
}};
Expand All @@ -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::<String>::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::<String>::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::<String>::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::<String>::WriteIo(argument);
$crate::instruction::LabelledInstruction::Instruction(instruction)
}};
Expand Down

0 comments on commit 0d1d35e

Please sign in to comment.