rewrite rule help

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

rewrite rule help

Eliot Miranda-2
Hi All,

    can anyone tell me why the following rules

rules
replace: '``@statements. interpreterProxy pop: ``@const. interpreterProxy pushInteger: ``@integer'
with: '``@statements. interpreterProxy methodReturnInteger: ``@integer';
replace: '``@statements. interpreterProxy pop: ``@const. ^interpreterProxy pushInteger: ``@integer'
with: '``@statements. ^interpreterProxy methodReturnInteger: ``@integer'.

    or
rules
replace: 'interpreterProxy pop: ``@const. interpreterProxy pushInteger: ``@integer'
with: 'interpreterProxy methodReturnInteger: ``@integer';
replace: 'interpreterProxy pop: ``@const. ^interpreterProxy pushInteger: ``@integer'
with: '^interpreterProxy methodReturnInteger: ``@integer'.

do edit this

primitiveRendererVersion
<export: true>
interpreterProxy methodArgumentCount = 0
ifFalse:[^interpreterProxy primitiveFail].
interpreterProxy pop: 1.
^interpreterProxy pushInteger: 1.

to

primitiveRendererVersion
<export: true>
interpreterProxy methodArgumentCount = 0
ifFalse: [ ^ interpreterProxy primitiveFail ].
^ interpreterProxy methodReturnInteger: 1

but not this?

primitiveTextureDepth
| handle result renderer |
<export: true>
interpreterProxy methodArgumentCount = 2
ifFalse:[^interpreterProxy primitiveFail].
handle := interpreterProxy stackIntegerValue: 0.
renderer := interpreterProxy stackIntegerValue: 1.
interpreterProxy failed ifTrue:[^nil].
result := self cCode:'b3dxActualTextureDepth(renderer, handle)' inSmalltalk:[-1].
result < 0 ifTrue:[^interpreterProxy primitiveFail].
interpreterProxy pop: 3.
^interpreterProxy pushInteger: result.

_,,,^..^,,,_
best, Eliot


Reply | Threaded
Open this post in threaded view
|

Re: [Pharo-dev] rewrite rule help

John Brant-2
On Jun 1, 2018, at 8:25 PM, Eliot Miranda <[hidden email]> wrote:

>
> Hi All,
>
>     can anyone tell me why the following rules
>
> rules
> replace: '``@statements. interpreterProxy pop: ``@const. interpreterProxy pushInteger: ``@integer'
> with: '``@statements. interpreterProxy methodReturnInteger: ``@integer';
> replace: '``@statements. interpreterProxy pop: ``@const. ^interpreterProxy pushInteger: ``@integer'
> with: '``@statements. ^interpreterProxy methodReturnInteger: ``@integer'.
>

You need a “.” in your ``@statements (i.e., ``@.statements). The ``@ prefix matches any node, but ``@. will match a list of statements (0 or more). Currently, you are only matching sequence nodes with exactly 3 statements. You also need to add some temps in case the sequence node has temps:

        | `@temps |
        ``@.statements.
         interpreterProxy pop: ``@const.
        ^interpreterProxy pushInteger: ``@integer
->
        | `@temps |
        ``@.statements.
        ^interpreterProxy methodReturnInteger: ``@integer


John Brant

Reply | Threaded
Open this post in threaded view
|

Re: [Pharo-dev] rewrite rule help

Eliot Miranda-2
John, thanks!!

> On Jun 1, 2018, at 7:01 PM, John Brant <[hidden email]> wrote:
>
>> On Jun 1, 2018, at 8:25 PM, Eliot Miranda <[hidden email]> wrote:
>>
>> Hi All,
>>
>>    can anyone tell me why the following rules
>>
>>    rules
>>        replace: '``@statements. interpreterProxy pop: ``@const. interpreterProxy pushInteger: ``@integer'
>>            with: '``@statements. interpreterProxy methodReturnInteger: ``@integer';
>>        replace: '``@statements. interpreterProxy pop: ``@const. ^interpreterProxy pushInteger: ``@integer'
>>            with: '``@statements. ^interpreterProxy methodReturnInteger: ``@integer'.
>>
>
> You need a “.” in your ``@statements (i.e., ``@.statements). The ``@ prefix matches any node, but ``@. will match a list of statements (0 or more). Currently, you are only matching sequence nodes with exactly 3 statements. You also need to add some temps in case the sequence node has temps:
>
>    | `@temps |
>    ``@.statements.
>     interpreterProxy pop: ``@const.
>    ^interpreterProxy pushInteger: ``@integer
> ->
>    | `@temps |
>    ``@.statements.
>    ^interpreterProxy methodReturnInteger: ``@integer
>
>
> John Brant
>