CensoredUsername / unrpyc

A ren'py script decompiler
Other
869 stars 157 forks source link

Paired property lost on renpy.ast.With #21

Closed jackmcbarn closed 9 years ago

jackmcbarn commented 9 years ago

Given this original dump:

            <renpy.ast.If 
                .entries = [(
                    u'hour in [22,23,24,0,1,2,3,4,5,6]',
                    [
                        <renpy.ast.With 
                            .expr = 'None',
                            .next = None,
                            .paired = u'dissolve'
                        >,
                        <renpy.ast.Scene 
                            irrelevant stuff snipped
                        >,
                        <renpy.ast.With 
                            .expr = u'dissolve',
                            .next = None,
                            .paired = None
                        >,
                        <renpy.ast.Python 
                            irrelevant stuff snipped
                        >,
                        <renpy.ast.With 
                            .expr = 'None',
                            .next = None,
                            .paired = u'dissolve2'
                        >,
                        <renpy.ast.Show 
                            irrelevant stuff snipped
                        >,
                        <renpy.ast.With 
                            .expr = u'dissolve2',
                            .next = None,
                            .paired = None
                        >,
                        <renpy.ast.Python 
                            irrelevant stuff snipped
                        >,
                        <renpy.ast.Return 
                            .expression = None,
                            .next = None
                        >
                    ]
                )],
                .next = None
            >,

If the rpyc that gave that dump is decompiled and then recompiled, here's the new dump:

            <renpy.ast.If 
                .entries = [(
                    u'hour in [22,23,24,0,1,2,3,4,5,6]',
                    [
                        <renpy.ast.With 
                            .expr = u'None',
                            .next = None,
                            .paired = None
                        >,
                        <renpy.ast.Scene 
                            irrelevant stuff snipped
                        >,
                        <renpy.ast.With 
                            .expr = u'dissolve',
                            .next = None,
                            .paired = None
                        >,
                        <renpy.ast.Python 
                            irrelevant stuff snipped
                        >,
                        <renpy.ast.With 
                            .expr = u'None',
                            .next = None,
                            .paired = None
                        >,
                        <renpy.ast.Show 
                            irrelevant stuff snipped
                        >,
                        <renpy.ast.With 
                            .expr = u'dissolve2',
                            .next = None,
                            .paired = None
                        >,
                        <renpy.ast.Python 
                            irrelevant stuff snipped
                        >,
                        <renpy.ast.Return 
                            .expression = None,
                            .next = None
                        >
                    ]
                )],
                .next = None
            >,

Every .paired inside a With has been changed to None.

CensoredUsername commented 9 years ago

This is a tricky one.

the with with the paired attribute is only emitted by the ren'py parser on a with statement concatenated to another statement, e.g.: scene bg house with dissolve This is compiled to

    <renpy.ast.With 
        .expr = u'None',
        .next = None,
        .paired = u'dissolve2'
    >,
    <renpy.ast.Show 
        irrelevant stuff snipped
    >,
    <renpy.ast.With 
        .expr = u'dissolve2',
        .next = None,
        .paired = None
    >

since scene bg house with dissolve is equal to

with None
scene bg house
with dissolve

And now the silly thing is, internally the engine does nothing with the paired attribute. Except that it's passed to renpy.config.with_callback, which by default also does nothing with it, but it could've been changed by the user so it might trigger a different result in that case.

It should be relatively easy to fix though.

CensoredUsername commented 9 years ago

It should be fixed now, if it encounters a with-statement-with situation in the ast node list it will reconstruct the postfix with statements properly.

Thanks for the issue reports, I really appreciate it.