Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

For Loop to Repeat Statement #44

Open
Tracked by #43
ControlCplusControlV opened this issue Dec 17, 2022 · 1 comment
Open
Tracked by #43

For Loop to Repeat Statement #44

ControlCplusControlV opened this issue Dec 17, 2022 · 1 comment

Comments

@ControlCplusControlV
Copy link
Owner

No description provided.

@ControlCplusControlV
Copy link
Owner Author

For Loop to Repeat Statement

Given a loop statement like

    for { let i:u32 := 0 } lt(i, 10) { i := add(i, 1)}
    {
        c := add(a,b)
        a := b
        b := c
    }

Should be transpiled down to a statement which utilizes the Miden Assembly instruction

repeat.{}

Rather than the current while based implementation of for loops

Testcases

  1. Input Yul
    for { let i:u32 := 0 } lt(i, 10) { i := add(i, 1)}
    {
        c := add(a,b)
        a := b
        b := c
    }
  1. Assembly Output
use.std::math::u256
 
 
begin
    # Assigning to a #
        # u32 literal 10 #
        push.10

    # Assigning to b #
        # u32 literal 5 #
        push.5

    # Assigning to c #
        # u32 literal 0 #
        push.0

    repeat.10
        # -- interior block -- #
            # Assigning to c #
                # add() #
                # pushing a to the top #
                    dup.3
                # pushing b to the top #
                    dup.3
                add
            # Assigning to a #
                # pushing b to the top #
                    dup.3
            # Assigning to b #
                # pushing c to the top #
                    dup.1

    end

end
  1. Input Yul
{
    let a:u32 := 10
    let b:u32 := 5
    let c:u32 := 0

for { let i:u32 := 10 } gt(i, 0) { i := sub(i, 5)}
    {
        let c := add(a,b)
        let a := b
        let b := c
    }
}
  1. Assembly Output

use.std::math::u256
 
begin
    # Assigning to a #
        # u32 literal 10 #
        push.10

    # Assigning to b #
        # u32 literal 5 #
        push.5

    # Assigning to c #
        # u32 literal 0 #
        push.0

repeat.2
    # -- interior block -- #
        # Assigning to c #
            # add() #
            # pushing a to the top #
                dup.3
            # pushing b to the top #
                dup.3
            add
        # Assigning to a #
            # pushing b to the top #
                dup.3
        # Assigning to b #
            # pushing c to the top #
                dup.1

    end
end
  1. Input Yul
{
    let a:u32 := 10
    let b:u32 := 5
    let c:u32 := 0

for { let i:u32 := 10 } lt(i, 0) { i := sub(i, 5)}
    {
        let c := add(a,b)
        let a := b
        let b := c
    }
}
  1. Assembly Output
//Dead Code, No Assembly Generated

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant