Hi Subbu,
I do not believe this deserves a paper :P. At most a blogpost. What I can do
quickly here is to draft the “methodology” I followed by instinct, but that can
be reproduced by anyone.
1) generate sources from pharo
2) try to compile (and run)
3) in case of failure, make a diff with the latest version of the same file in
the git repository of opensmalltalk vm
4) spot an interesting difference (most common cases were related to loops and
conditions, missing or extra inlinings) => get ONE method with the problem
4.1) Check 1: verify that the generating that method from squeak does **not**
have the problem
4.2) Check 2: verify that the generating that method from pharo **does have**
the problem
For these checks I used some of the already given VMMaker scripts
5) generate a small artificial but representative case for testing. For example:
methodWithIfNil
self something
ifNil: [ 1 ]
ifNotNil: [ 2 ]
Then I have two level of tests: AST-to-AST transformation, and generation tests.
testIfNilIfNotNilBecomesIfTrueIfFalse
| translation thisAST |
thisAST := (self class >> #methodWithIfNil) ast.
translation := thisAST asTranslationMethodOfClass: TMethod.
self assert: translation statements first selector equals:
#ifTrue:ifFalse:
testSimpleIfNilAssignment
| translation thisAST codeGenerator result |
thisAST := (self class >> #methodWithIfNil) ast.
translation := thisAST asTranslationMethodOfClass: TMethod.
codeGenerator := CCodeGeneratorGlobalStructure new.
codeGenerator generateDeadCode: false.
codeGenerator addMethod: translation.
codeGenerator doInlining: true.
result := String streamContents: [ :stream |
translation parseTree statements first emitCCodeOn: stream
level: 0 generator: codeGenerator.
].
self assert: result equals: 'if ((something()) == null) {
}
else {
}’
6) Fix it
* Most of the “bugs” were related to making the different #asTranslatorNodeIn:
methods in the RB AST compliant to what it was doing in squeak.
* Sometimes I ended up doing parallel stepping in Pharo and Squeak to spot
where the translation diverged
* Something important that I’ve learnt in the process is that Squeak’s AST
contain already some transformations/expansions like
what you see/write: self x ifNil: [ … ]
what you actually have: self x == nil ifTrue: [ … ]
BUT, the most confusing point is that even if the AST internally is structured
as in the version in the right, the printString of the AST in the inspector
showed the left version.
Nothing new under the sun ^^.
Guille
> El 15 may 2019, a las 9:34, ducasse <[email protected]> escribió:
>
> Hi Subbu
>
>>> To do this work
>>> - I had to review the AST-to-AST transformation, checking the output,
>>> comparing it to what squeak does and so on...
>>
>> Guillermo,
>>
>> This is a superb effort! Thanks. Are you planning to write a paper on this
>> part of your work? A blog? It can open new vistas for research students in
>> Pharo.
>
> We will see if we can produce a tutorial in how to extend the VM. Igor did it
> in 2011 and we will redo it. Life is a cycle.
>
> Then we would love to see if we can have a VMMaker repackaged (it should not
> be difficult) with less code so that we can do lectures on the Pharo VM
> and exercises for students with it. It is not really pedagogical to tell them
> to jump over many not used classes.
> And more important since we want to attract smart guys they will not take us
> seriously if we present a system that is monolithic
> - we got several times students asking why VMMaker could not be cut into
> different packages and well they are right.
>
> What I was thinking is that we should have soon a travis to build it
> automatically with Pharo.
> If you are interested to help please join the effort.
> What guille showed us is that it was not difficult to do it in fact.
>
> Stef
>
>>
>> Regards .. Subbu
>>
>
>