Skip to content

For Loop to Repeat Statement #44

Open

Description

@ControlCplusControlV
No description provided.

Activity

  1. ControlCplusControlV commented on Dec 17, 2022

    @ControlCplusControlV
    OwnerAuthor

    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
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions