Blocks seems to work. No support for nested block. No support for
compiling cheap blocks.
--- a/IRBuilderTest.st Mon Mar 30 17:49:01 2009 +0000
+++ b/IRBuilderTest.st Wed Apr 01 21:13:00 2009 +0000
@@ -766,6 +766,64 @@
"Created: / 30-03-2009 / 14:26:18 / Jan Vrany <vranyj1@fel.cvut.cz>"
"Modified: / 30-03-2009 / 19:16:25 / Jan Vrany <vranyj1@fel.cvut.cz>"
+!
+
+testBlock_blockTempVar
+ |aCompiledMethod irBuilder|
+
+ irBuilder := (IRBuilder new)
+ numRargs:1;
+ addTemps:#( #self );
+ pushBlockUsingBuilder:[:builder |
+ builder
+ numRargs:0;
+ addTemps:#( #bvar1 );
+ pushLiteral: 22;
+ storeTemp:#bvar1;
+ pushTemp: #bvar1;
+ returnTop
+ ];
+ send:#value;
+ returnTop;
+ ir.
+ "
+ irBuilder ir
+ "
+
+ aCompiledMethod := irBuilder compiledCode.
+ self assert:(aCompiledMethod isKindOf:CompiledMethod).
+ self assert:((aCompiledMethod valueWithReceiver:1 arguments:#()) = 22).
+
+ "Created: / 30-03-2009 / 23:03:48 / Jan Vrany <vranyj1@fel.cvut.cz>"
+!
+
+testBlock_methodTempVar
+ |aCompiledMethod irBuilder|
+
+ irBuilder := (IRBuilder new)
+ numRargs:1;
+ addTemps:#( #self #a);
+ pushLiteral: 22;
+ storeTemp: #a;
+ pushBlockUsingBuilder:[:builder |
+ builder
+ numRargs:0;
+ pushTemp: #a;
+ returnTop
+ ];
+ send:#value;
+ returnTop;
+ ir.
+ "
+ irBuilder ir
+ "
+
+ aCompiledMethod := irBuilder compiledCode.
+ self assert:(aCompiledMethod isKindOf:CompiledMethod).
+ self assert:((aCompiledMethod valueWithReceiver:1 arguments:#()) = 22).
+
+ "Created: / 30-03-2009 / 23:05:00 / Jan Vrany <vranyj1@fel.cvut.cz>"
+ "Modified: / 01-04-2009 / 19:43:52 / Jan Vrany <vranyj1@fel.cvut.cz>"
! !
!IRBuilderTest class methodsFor:'documentation'!
--- a/IRBytecodeGenerator.st Mon Mar 30 17:49:01 2009 +0000
+++ b/IRBytecodeGenerator.st Wed Apr 01 21:13:00 2009 +0000
@@ -39,6 +39,17 @@
properties := aDictionary.
"Created: / 17-09-2008 / 12:17:49 / Jan Vrany <vranyj1@fel.cvut.cz>"
+!
+
+setLiterals: aCollection
+
+ "
+ Private entry for IRBytecodeGenerator>>makeBlock:
+ "
+
+ ^literals := aCollection
+
+ "Created: / 30-03-2009 / 23:09:16 / Jan Vrany <vranyj1@fel.cvut.cz>"
! !
!IRBytecodeGenerator methodsFor:'accessing default'!
@@ -171,26 +182,30 @@
makeBlock: irClosure
- | closureCode |
+ | pos translator closureCode |
stack push.
+ pos := code size.
+
self
nextPut: #makeBlock;
nextPut: nil "Number of block bytecodes. Patched later";
nextPut: irClosure numVars;
nextPut: irClosure numArgs.
- closureCode := (IRTranslator new)
+ translator := IRTranslator new.
+ translator getGenerator setLiterals: literals.
+ closureCode := translator
interpret: irClosure;
getCode.
+ code addAll: closureCode.
"Patch number of closure bytecodes"
- code at: code size - 2 put: (closureCode size + 5).
- code addAll: closureCode.
+ code at: pos + 2 put: code size + 1.
"Created: / 30-03-2009 / 18:16:10 / Jan Vrany <vranyj1@fel.cvut.cz>"
- "Modified: / 30-03-2009 / 19:39:50 / Jan Vrany <vranyj1@fel.cvut.cz>"
+ "Modified: / 01-04-2009 / 19:43:22 / Jan Vrany <vranyj1@fel.cvut.cz>"
!
popTop
--- a/IRClosure.st Mon Mar 30 17:49:01 2009 +0000
+++ b/IRClosure.st Wed Apr 01 21:13:00 2009 +0000
@@ -43,7 +43,11 @@
tempVarKindForLevel:level
"Superclass IRFunction says that I am responsible to implement this method"
- self shouldImplement
+ ^level isZero
+ ifTrue: [#BVar]
+ ifFalse:[#OBVar]
+
+ "Modified: / 30-03-2009 / 23:05:37 / Jan Vrany <vranyj1@fel.cvut.cz>"
! !
!IRClosure methodsFor:'testing'!
--- a/IRTranslator.st Mon Mar 30 17:49:01 2009 +0000
+++ b/IRTranslator.st Wed Apr 01 21:13:00 2009 +0000
@@ -26,6 +26,13 @@
^gen getCode
"Created: / 30-03-2009 / 19:08:21 / Jan Vrany <vranyj1@fel.cvut.cz>"
+!
+
+getGenerator
+
+ ^gen
+
+ "Created: / 30-03-2009 / 23:08:34 / Jan Vrany <vranyj1@fel.cvut.cz>"
! !
!IRTranslator methodsFor:'initialize'!
@@ -35,17 +42,6 @@
gen := IRBytecodeGenerator new
"Modified: / 17-09-2008 / 12:19:10 / Jan Vrany <vranyj1@fel.cvut.cz>"
-!
-
-setGenerator: aByteCodeGenerator
-
- "
- Private method for IRByteCodeGenerator>>makeBlock:
- "
-
- gen := aByteCodeGenerator
-
- "Created: / 30-03-2009 / 18:23:32 / Jan Vrany <vranyj1@fel.cvut.cz>"
! !
!IRTranslator methodsFor:'instructions'!