Extracting native code from C

Henrik Gedenryd h.gedenryd at open.ac.uk
Fri Mar 15 11:18:54 UTC 2002


PhiHo Hoang wrote:

> Hi Henrik,
> 
> A Syntax Error 'BlockNode p.e. variable substitution
> tryToSubstitute:forArguments:'
> 
> System is Squeak3.2gamma latest update: #4743.

Try this:

tryToSubstitute: substitutes forArguments: args
    "try to substitute  args.
    Set up mapping dictionary and expand all the method's affected
variables.
     For expressions that were inserted more than once, check that this is
ok"
 
    | substitutionMap copy assignments assoc |
    "sizes don't match when dummy method returned"
    substitutes size ~= args size | substitutes isEmpty ifTrue: [^self].

    substitutionMap _
        self substitutionMapFrom: args to: substitutes.

    "count number of references to variables"
    statements do: [:statement |
        statement nodesDo: [:node |
            (node isKindOf: VariableNode) ifTrue: [
                substitutionMap at: node ifPresent: [:ass |
                    ass value: ass value + 1]]]].

    "insert temp assignments where arguments cannot be inserted directly"
    copy _ self copy.
    assignments _ OrderedCollection new.
    args do: [:arg |
        assoc _ substitutionMap at: arg.
        (assoc value > 1 and: [assoc key isMultiSubstitutable not]) ifTrue:
[
            assignments add:  (AssignmentNode new variable: arg value: assoc
key).
            copy temporaries: (copy temporaries copyWith: arg).
            substitutionMap removeKey: arg]].

    copy _ copy substituteSimplyFrom: substitutionMap.
    copy statements: assignments, copy statements.
    ^copy

You should have been able to figure that out ;-)

Henrik




More information about the Squeak-dev mailing list