Skip to content

Allow using a complex type as an array element type - #734

Merged
sbillig merged 1 commit into
argotorg:masterfrom
Y-Nak:complex-array-elem
Jun 16, 2022
Merged

Allow using a complex type as an array element type#734
sbillig merged 1 commit into
argotorg:masterfrom
Y-Nak:complex-array-elem

Conversation

@Y-Nak

@Y-Nak Y-Nak commented Jun 4, 2022

Copy link
Copy Markdown
Member

close #730

  1. Allow using a complex type as an array element type
  2. Fix a bug that incorrect instruction is selected when the operands of a comp instruction are a signed type.

Example:

contract Foo {
    pub fn bar() -> i256 {
        let my_array: Array<Pair, 3> = [Pair::new(-1, 1), Pair::new(10, -10), Pair::new(-100, 100)]

        let sum: i256 = 0
        for pair in my_array {
            sum += pair.l1_norm()
        }

        return sum
    }
}

struct Pair {
    pub x: i256
    pub y: i256

    pub fn new(_ x: i256, _ y: i256) -> Pair {
        return Pair(x, y)
    }

    pub fn l1_norm(self) -> i256 {
        return abs(self.x) + abs(self.y)
    }
}

fn abs(_ val: i256) -> i256 {
    if val < 0 {
        return -val
    } else {
        return val
    }
}

NOTE:
Please start reviewing this after #729 is merged.

  • OPTIONAL: Update Spec if applicable

  • Add entry to the release notes (may forgo for trivial changes)

  • Clean up commit history

@Y-Nak
Y-Nak force-pushed the complex-array-elem branch from 13ac7cc to 3e7870a Compare June 4, 2022 09:47
@Y-Nak Y-Nak mentioned this pull request Jun 6, 2022
7 tasks
@Y-Nak
Y-Nak force-pushed the complex-array-elem branch from 3e7870a to 8d9c383 Compare June 7, 2022 00:23

@sbillig sbillig left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Sorry for the delay.

@sbillig
sbillig merged commit 471714f into argotorg:master Jun 16, 2022
@Y-Nak
Y-Nak deleted the complex-array-elem branch June 17, 2022 02:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow using complex type as array element type

2 participants