quarkiverse / quarkus-bon-jova-rockstar

An implementation of Rockstar as a JVM language
https://codewithrockstar.com/
3 stars 2 forks source link

If a variable is accessed outside a loop, its value inside the loop is always 0 #113

Closed holly-cummins closed 6 months ago

holly-cummins commented 9 months ago

This is a fairly serious functional issue. This can cause hangs, because if the variable is used for a 'while' check and its value is always 0, the loop becomes infinite.

I think it has something to do with result handles and assignment and writing to a result handle rather than the top-level variable.

I think this is the same issue as #112, but I'm leaving that one open to confirm, and write a test for that specific case.

This reproducer shows the problem (although it's longer than it needs to be):

isInMandelbrotSet wants x, and y (function that decides if a point is in the set and returns a space or a dot)
    maxIterations is 320
    iterationCount is 0
    The hope is 0
    The fear is 4
    let grr be 0
    Let something be 0
    Let anything be 0
    While iterationCount are lower than maxIterations and the hope is lower than the fear
        Let love be something
        Let love be something of it (in other words, something times something, that is, squared)
        Let your head be anything
        Let your head be anything of it (in other words, anything times anything)
        Let the interimsummit be love without your head
        Let the summit be the interimsummit plus x
        A million is insufficient
        Let interimanything be a million times something times anything
        Let anything be interimanything plus y
        Let something be the summit
        Let f be something of something
        Let g be anything of anything
        Let the hope be f + g
        let grrr be the hope
        Build iterationCount up

    The world is only scared
    Cast the world into dot
    Happiness is a fire
    Let your need be the world without happiness
    Say grr
    Cast your need into blank (all of the above lines are very complicated way to generate two characters, done in a loop for extra inefficiency)
    If iterationCount is less than maxIterations
        Let the answer be blank,
    Else let the answer be dot

    Return the answer

calculateRow takes time
    Push row (Initialise the array before using it in a while loop, see https://github.com/quarkiverse/quarkus-bon-jova-rockstar/issues/110)
    index is 0
    Knock index down, down (Decrement down to -2)
    Your dreams is 0.4
    Your spirit is 0.03
    While index is weaker than your dreams
    Let index be index with your spirit
    Let love be index
    Push row with isInMandelbrotSet taking love 'n' time

    Join row
    Return row

rowPos is impossible
Knock rowPos down (a complicated way of declaring -1)
Our souls are incredible
Build our souls up (a complicated way of declaring 1)
While rowPos are weaker than our souls
    The moon is a light
    Let rowPos be rowPos with 0.06666666666666666666666666
    Say calculateRow taking rowPos
holly-cummins commented 6 months ago

This reproducer is invalid, because it uses grr in one place, and grrr in another place. I confirm the behaviour is the same in Satriani. And if I use consistent naming, the variable value does change. So while we do have loop and variable scope issues (see #110), I think this issue can be closed as invalid.