--- a/IRTranslator.st Wed Feb 25 16:49:21 2009 +0000
+++ b/IRTranslator.st Mon Mar 30 14:47:18 2009 +0000
@@ -1,7 +1,7 @@
"{ Package: 'stx:goodies/newcompiler' }"
IRInterpreter subclass:#IRTranslator
- instanceVariableNames:'pending gen currentInstr trailerBytes'
+ instanceVariableNames:'pending gen currentInstr'
classVariableNames:''
poolDictionaries:''
category:'NewCompiler-IR'
@@ -26,13 +26,6 @@
gen := IRBytecodeGenerator new
"Modified: / 17-09-2008 / 12:19:10 / Jan Vrany <vranyj1@fel.cvut.cz>"
-!
-
-trailer: bytes
-
- trailerBytes := bytes
-
- "Modified: / 17-09-2008 / 12:20:00 / Jan Vrany <vranyj1@fel.cvut.cz>"
! !
!IRTranslator methodsFor:'instructions'!
@@ -97,21 +90,31 @@
pushBlock: irMethod
+ self shouldImplement
+
+ "
| meth block |
meth := irMethod compiledMethodWith: trailerBytes.
meth isBlockMethod: true.
block := meth createBlock: nil.
self addPending: (Message selector: #pushLiteral: argument: block)
+ "
- "Modified: / 17-09-2008 / 12:19:36 / Jan Vrany <vranyj1@fel.cvut.cz>"
+ "Modified: / 28-03-2009 / 20:34:11 / Jan Vrany <vranyj1@fel.cvut.cz>"
!
pushBlockMethod: irMethod
- | meth |
- meth _ irMethod compiledMethodWith: trailerBytes.
- meth isBlockMethod: true.
- self addPending: (Message selector: #pushLiteral: argument: meth)
+ self shouldImplement
+
+ "
+ | meth |
+ meth _ irMethod compiledMethodWith: trailerBytes.
+ meth isBlockMethod: true.
+ self addPending: (Message selector: #pushLiteral: argument: meth)
+ "
+
+ "Modified: / 28-03-2009 / 20:34:25 / Jan Vrany <vranyj1@fel.cvut.cz>"
!
pushDup
@@ -137,23 +140,31 @@
self addPending: (Message selector: #pushLiteralVariable: argument: object)
!
-pushTemp: index
+pushTemp: index kind: kind level: level
- index = 0 ifTrue: [^ self addPending: (Message selector: #pushReceiver)].
+ index = 0 ifTrue: [^ self addPending: (Message selector: #pushReceiver)].
- (self pendingMatches: {
- [:m | m selector == #storePopTemp: and: [m argument = index]]}
- ) ifTrue: [^ self pendingSelector: #storeTemp:].
+ (self pendingMatches: (Array with:
+ [:m | m selector == #storePopTemp: and: [m argument = index]])
+ ) ifTrue: [^ self pendingSelector: #storeTemp:].
+
+ self doPending.
- self doPending.
+ index = -2 ifTrue: [^ gen pushThisContext].
+ index = -1 ifTrue: [
+ self halt:'Not supported'
+ "
+ ^ gen pushThisContext;
+ pushLiteral: MethodContext myEnvFieldIndex;
+ send: #privGetInstVar:"].
- index = -2 ifTrue: [^ gen pushThisContext].
- index = -1 ifTrue: [
- ^ gen pushThisContext;
- pushLiteral: MethodContext myEnvFieldIndex;
- send: #privGetInstVar:].
+ "Bad bad bad!! Type switch"
+ kind == #MArg ifTrue:[^gen pushMethodArg: index].
+ kind == #MVar ifTrue:[^gen pushMethodVar: index].
- gen pushTemp: index.
+ self halt:'Should never be reached'.
+
+ "Created: / 30-03-2009 / 14:06:28 / Jan Vrany <vranyj1@fel.cvut.cz>"
!
remoteReturn
@@ -234,15 +245,20 @@
self addPending: (Message selector: #storeIntoLiteralVariable: argument: assoc)
!
-storeTemp: index
+storeTemp: index kind: kind level: level
- index = -1 "thisEnv" ifTrue: [
- self doPending.
- ^ gen pushThisContext;
- pushLiteral: MethodContext myEnvFieldIndex;
- send: #privStoreIn:instVar:].
+ index = -1 "thisEnv" ifTrue: [
+ self halt:'Not supported'
+ "
+ self doPending.
+ ^ gen pushThisContext;
+ pushLiteral: MethodContext myEnvFieldIndex;
+ send: #privStoreIn:instVar:"].
- self addPending: (Message selector: #storeTemp: argument: index)
+ kind == #MArg ifTrue:[^self error:'Cannot store to method argument!!'].
+ kind == #MVar ifTrue:[^self addPending: (Message selector: #storeMethodVar: argument: index)].
+
+ "Created: / 30-03-2009 / 14:07:04 / Jan Vrany <vranyj1@fel.cvut.cz>"
! !
!IRTranslator methodsFor:'interpret'!
@@ -279,15 +295,17 @@
!
doPending
- "execute pending instructions"
+ "execute pending instructions"
- | assoc |
- [pending isEmpty] whileFalse: [
- assoc _ pending removeFirst.
- gen mapBytesTo: assoc key "instr".
- assoc value "message" sendTo: gen.
- ].
- gen mapBytesTo: currentInstr.
+ | assoc |
+ [pending isEmpty] whileFalse: [
+ assoc := pending removeFirst.
+ gen mapBytesTo: assoc key "instr".
+ assoc value "message" sendTo: gen.
+ ].
+ gen mapBytesTo: currentInstr.
+
+ "Modified: / 28-03-2009 / 20:33:26 / Jan Vrany <vranyj1@fel.cvut.cz>"
!
pendingMatches: blocks
@@ -328,20 +346,18 @@
"Created: / 03-11-2008 / 09:23:01 / Jan Vrany <vranyj1@fel.cvut.cz>"
!
-compiledMethod
+compiledCodeUsing:aCompiledMethodClass
+ ^ gen compiledCodeUsing:aCompiledMethodClass
- ^ gen compiledMethod
+ "Modified: / 17-09-2008 / 12:18:43 / Jan Vrany <vranyj1@fel.cvut.cz>"
+!
+
+compiledMethod
+ ^ gen compiledCode
"Modified: / 03-11-2008 / 09:22:36 / Jan Vrany <vranyj1@fel.cvut.cz>"
!
-compiledMethodUsing: aCompiledMethodClass
-
- ^ gen compiledMethodUsing: aCompiledMethodClass
-
- "Modified: / 17-09-2008 / 12:18:43 / Jan Vrany <vranyj1@fel.cvut.cz>"
-!
-
literals
^gen literals