Author Topic: Decompiler Changes  (Read 3273 times)

0 Members and 1 Guest are viewing this topic.

Offline OmerMor

Decompiler Changes
« on: December 17, 2015, 03:36:33 AM »
troflip,
I compiled the latest SciCompanion version, and tried the decompiler with the christmas demo.
I noticed it decompiled many scripts a bit differently.
I have a question about one of these changes.

In room 950, method passChecks, the previous decompiler gave this code:
Code: [Select]
    (method (passedChecks param1)
        (var temp0)

        (if (<= param1 4)
            verbChecks1
        )(else
            verbChecks2
        )
        (if ((not ((not (& (= temp0 (& (>> verbChecks2 (* 4 (% (- param1 1) 4))) $000f)) $0008) or (self:isNotHidden())) and (not (& temp0 $0004) or (self:farCheck()))) or not (not (& temp0 $0002) or (self:nearCheck()))) or not (& temp0 $0001))
        )(else
            (self:facingMe())
        )
    )

The new decompiler, gave this:
Code: [Select]
(method (passedChecks param1)
(var temp0)
(if ((((not (& (= temp0 (& (>>
(if (<= param1 4)
verbChecks1
)(else
verbChecks2
)
 (* 4 (% (- param1 1) 4))) $000f)) $0008) or (self:isNotHidden())) and (not (& temp0 $0004) or (self:farCheck()))) and (not (& temp0 $0002) or (self:nearCheck()))) and not not (& temp0 $0001))

(self:facingMe())
)
)

Being a non-expert in SCI, I wonder what does the statement 'verbChecks1' means?
I noticed in the disassembly it calls ptoa (push to accumulator). Doesn't that have side effects? If so, then the new decompiled version behaves differently?



Offline troflip

Re: Decompiler Changes
« Reply #1 on: December 17, 2015, 04:13:26 AM »
Yes, it behaves differently. The old version looks incorrect, so it looks like my change may have fixed a bug.

verbChecks1 is a property. So the value of the expression:

Code: [Select]
        (if (<= param1 4)
            verbChecks1
        )(else
            verbChecks2
        )

will be verbChecks1 or verbChecks2 depending on the value of param1. So that statement does nothing by itself, because nothing is checking the value of the expression (Companion used to spit out warnings in these cases, but I stopped doing that). It does modify the accumulator though (as you noted), so if that were all the code in the function, that result is what the function would return.

The first code snippet you posted is incorrect, because the expression in the second if statement is simply "verbChecks2", whereas it should be the entire first if statement there.

The formatting is better if you switch the language to Sierra Script:

Code: [Select]
(method (passedChecks param1 &tmp temp0)
(if
(and
(or
(not
(&
(= temp0
(&
(>>
(if (<= param1 4) verbChecks1 else verbChecks2)
(* 4 (mod (- param1 1) 4))
)
$000f
)
)
$0008
)
)
(self isNotHidden:)
)
(or (not (& temp0 $0004)) (self farCheck:))
(or (not (& temp0 $0002)) (self nearCheck:))
(not (not (& temp0 $0001)))
)
(self facingMe:)
)
)


Note that the function either returns the result of (self facingMe:), or 0 (what will be left in the accumulator in the branch not taken case).
« Last Edit: December 17, 2015, 04:15:11 AM by troflip »
Check out my website: http://icefallgames.com
Groundhog Day Competition

Offline OmerMor

Re: Decompiler Changes
« Reply #2 on: December 17, 2015, 05:42:59 AM »
Thanks for the explanation - and for fixing the decompiler!


SMF 2.0.19 | SMF © 2021, Simple Machines
Simple Audio Video Embedder

Page created in 0.023 seconds with 23 queries.