frame_transpiler icon indicating copy to clipboard operation
frame_transpiler copied to clipboard

Autoincrement/decrement in tests in Python not generating proper code

Open frame-lang opened this issue 2 years ago • 0 comments

Look at code generated for action 'autoid1':


#TestAutoIncDec

    -machine-

    $S0
        |>|
            autoid1()
            autoid2()
            ^
            
    -actions-

    autoid1 {
        var i = 0

        ++i == 2 ? print ("1") :>
        i++ == 2 ? print ("2") :>
        i++ == 2 ? print ("3")
        : print ("none")
        :: ^
    }

    autoid2 {
        var i = 0
        var j = 4

        ++i == j-- ? print ("1") :>
        ++i == j-- ? print ("2") :>
        ++i == j-- ? print ("3")
        : print ("none")
        :: ^
    }

    print [msg] {
        ```
        print (msg)
        ```
    }
##

Generates

class TestAutoIncDec:
    
   ...
      
    
    # ===================== Actions Block =================== #
    
    
    
    def autoid1_do(self):
        i  = 0
        if  i == 2:
            self.print_do("1")
        elif  i == 2:
            self.print_do("2")
        elif  i == 2:
            self.print_do("3")
        else:
            self.print_do("none")
        
        return
        
    
    def autoid2_do(self):
        i  = 0
        j  = 4
        if  i == j:
            self.print_do("1")
        elif  i == j:
            self.print_do("2")
        elif  i == j:
            self.print_do("3")
        else:
            self.print_do("none")
        
        return
        
    
    def print_do(self,msg):
        print (msg)
        
    

However, the autoinc inside the binary tests aren't working correctly. The expected generated code is:

    def autoid1_do(self):
        i = 0
        
        i = i + 1
        b = i == 2
        if b:
            self.print_do("1")
        else:
            b = i == 2
            i = i + 1
            if b:
                self.print_do("2")
            else:
                b = i == 2
                i = i + 1
                if b:
                    self.print_do("3")
                else:
                    self.print_do("none")

    def autoid2_do(self): 
             <todo>

frame-lang avatar Sep 06 '23 04:09 frame-lang