Skip to content

Commit

Permalink
feat: Add code-function to compare data types when only sizes are known
Browse files Browse the repository at this point in the history
Needed downstream in neptune-core, to compare two elements of type
Option<u128>.
  • Loading branch information
Sword-Smith committed Sep 25, 2024
1 parent c524e21 commit c963bb5
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions tasm-lib/src/data_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,14 +178,14 @@ impl DataType {
crate::io::write_words(self.stack_size())
}

/// Return the code that compares two elements of this type.
/// Return the code that compares two elements of this stack-size.
///
/// ```text
/// BEFORE: _ [self] [other]
/// AFTER: _ (self == other)
/// ```
pub fn compare(&self) -> Vec<LabelledInstruction> {
match self.stack_size() {
pub fn compare_elem_of_stack_size(stack_size: usize) -> Vec<LabelledInstruction> {
match stack_size {
0 => triton_asm!(push 1),
1 => triton_asm!(eq),
n => {
Expand All @@ -204,6 +204,16 @@ impl DataType {
}
}

/// Return the code that compares two elements of this type.
///
/// ```text
/// BEFORE: _ [self] [other]
/// AFTER: _ (self == other)
/// ```
pub fn compare(&self) -> Vec<LabelledInstruction> {
DataType::compare_elem_of_stack_size(self.stack_size())
}

/// Return a string matching how the variant looks in source code
pub fn variant_name(&self) -> String {
// This function is used to autogenerate snippets in the tasm-lang compiler
Expand Down

0 comments on commit c963bb5

Please sign in to comment.