Fixed bug that caused bad code generation for closures with more than one basic blocks.
--- a/IRBuilderTest.st Tue Mar 23 13:38:08 2010 +0000
+++ b/IRBuilderTest.st Wed Mar 24 07:50:55 2010 +0000
@@ -788,7 +788,7 @@
returnTop
];
pushLiteral: 22;
- send:#value;
+ send:#value:;
returnTop;
ir.
"
@@ -800,6 +800,52 @@
self assert:((aCompiledMethod valueWithReceiver:1 arguments:#()) = 22).
"Created: / 11-05-2009 / 23:04:13 / Jan Vrany <vranyj1@fel.cvut.cz>"
+ "Modified: / 23-03-2010 / 21:47:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+testBlock_blockNesting_2
+ |aCompiledMethod irBuilder|
+
+ irBuilder := (IRBuilder new)
+ numRargs:1;
+ addTemps:#( #self );
+ pushBlockUsingBuilder:[:builder |
+ builder
+ numRargs:1;
+ addTemps:#( #barg1 );
+ pushBlockUsingBuilder:[:builder|
+ builder
+ numRargs: 1;
+ addTemps: #( #barg2 );
+ pushTemp: #barg2;
+ returnTop
+ ];
+ pushTemp: #barg1;
+ send: #value:;
+ pushBlockUsingBuilder:[:builder|
+ builder
+ numRargs: 1;
+ addTemps: #( #barg2 );
+ pushLiteral: -1;
+ returnTop
+ ];
+ pushTemp: #barg1;
+ send: #value:;
+ returnTop
+ ];
+ pushLiteral: 22;
+ send:#value:;
+ returnTop;
+ ir.
+ "
+ irBuilder ir
+ "
+
+ aCompiledMethod := irBuilder compiledCode.
+ self assert:(aCompiledMethod isKindOf:CompiledMethod).
+ self assert:((aCompiledMethod valueWithReceiver:1 arguments:#()) = -1).
+
+ "Created: / 23-03-2010 / 21:43:49 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
testBlock_blockTempArg
--- a/IRBytecodeGenerator.st Tue Mar 23 13:38:08 2010 +0000
+++ b/IRBytecodeGenerator.st Wed Mar 24 07:50:55 2010 +0000
@@ -37,17 +37,6 @@
!IRBytecodeGenerator methodsFor:'accessing'!
-getCode
-
- "
- Private entry for IRBytecodeGenerator>>makeBlock:
- "
-
- ^code
-
- "Created: / 30-03-2009 / 19:00:07 / Jan Vrany <vranyj1@fel.cvut.cz>"
-!
-
properties: aDictionary
properties := aDictionary.
@@ -224,7 +213,6 @@
at: index + 1
put: (closureCode at: index + 1) + pos + 4]].
-
code addAll: closureCode.
"Patch number of closure bytecodes"
@@ -232,6 +220,7 @@
"Created: / 30-03-2009 / 18:16:10 / Jan Vrany <vranyj1@fel.cvut.cz>"
"Modified: / 12-05-2009 / 08:58:11 / Jan Vrany <vranyj1@fel.cvut.cz>"
+ "Modified: / 23-03-2010 / 22:34:24 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
popTop
@@ -726,6 +715,38 @@
"Modified: / 13-05-2009 / 10:42:16 / Jan Vrany <vranyj1@fel.cvut.cz>"
!
+getCode
+
+ | stream basicBlockStartOffset |
+ [ orderSeq
+ inject: false
+ into: [:changed :seqId | (self updateJump: seqId) | changed]
+ ] whileTrue.
+
+ stream := (OrderedCollection new: 200) writeStream.
+ basicBlockStartOffset := 0.
+ orderSeq do: [:seqId |
+ (instrMaps at: seqId) do: [:assoc |
+ assoc key "instr" bytecodeIndex: stream position + assoc value.
+ ].
+ "Patch makeBlock offsets"
+ (seqCode at: seqId) withIndexDo:
+ [:instr :index|
+ instr == #makeBlock ifTrue:
+ [(seqCode at: seqId)
+ at: index + 1
+ put: ((seqCode at: seqId) at: index + 1) + basicBlockStartOffset]].
+
+ stream nextPutAll: (seqCode at: seqId).
+ basicBlockStartOffset := basicBlockStartOffset + (seqCode at: seqId) size.
+ ].
+ ^stream contents
+
+ "Created: / 11-06-2008 / 14:00:43 / Jan Vrany <vranyj1@fel.cvut.cz>"
+ "Modified: / 13-05-2009 / 11:15:41 / Jan Vrany <vranyj1@fel.cvut.cz>"
+ "Modified: / 24-03-2010 / 08:42:04 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
literals
^literals asArray
--- a/IRFunction.st Tue Mar 23 13:38:08 2010 +0000
+++ b/IRFunction.st Wed Mar 24 07:50:55 2010 +0000
@@ -59,7 +59,7 @@
[ir tempNames do:
[:temp|
(tempsToAdd includes:temp)
- ifTrue:[tempsToAdd := tempsToAdd remove: temp]].
+ ifTrue:[tempsToAdd remove: temp]].
ir := ir environmentIr].
tempsToAdd isEmpty ifTrue:[^self].
self addTemps: tempsToAdd
--- a/cvut_stx_goodies_newcompiler.st Tue Mar 23 13:38:08 2010 +0000
+++ b/cvut_stx_goodies_newcompiler.st Wed Mar 24 07:50:55 2010 +0000
@@ -128,7 +128,7 @@
"Return a SVN revision number of myself.
This number is updated after a commit"
- ^ "$SVN-Revision:"'27'"$"
+ ^ "$SVN-Revision:"'30'"$"
! !
!cvut_stx_goodies_newcompiler class methodsFor:'documentation'!