--- a/compiler/PPCCompiler.st Tue May 12 01:24:03 2015 +0100
+++ b/compiler/PPCCompiler.st Thu May 21 14:12:22 2015 +0100
@@ -8,7 +8,7 @@
arguments'
classVariableNames:''
poolDictionaries:''
- category:'PetitCompiler-Core'
+ category:'PetitCompiler-Compiler'
!
@@ -178,9 +178,6 @@
(variable == #whatever) ifFalse: [
"Do not assign, if somebody does not care!!"
self add: variable ,' := ', code.
- ] ifTrue: [
- "In case code hava a side effect"
- self add: code
]
!
@@ -188,10 +185,44 @@
self add: 'self clearError.'.
!
+codeError
+ self add: 'self error: ''message notspecified''.'.
+!
+
codeError: errorMessage
self add: 'self error: ''', errorMessage, '''.'
!
+codeError: errorMessage at: position
+ self add: 'self error: ''', errorMessage, ''' at: ', position asString, '.'
+!
+
+codeEvaluate: selector argument: argument on: variable
+ self assert: variable isNil not.
+
+ "TODO JK: Hack alert, whatever is magic constant!!"
+ (variable == #whatever) ifFalse: [
+ "Do not assign, if somebody does not care!!"
+ self add: variable, ' ', selector,' ', argument.
+ ] ifTrue: [
+ "In case argument has a side effect"
+ self add: argument
+ ]
+!
+
+codeEvaluateAndAssign: argument to: variable
+ self assert: variable isNil not.
+
+ "TODO JK: Hack alert, whatever is magic constant!!"
+ (variable == #whatever) ifFalse: [
+ "Do not assign, if somebody does not care!!"
+ self add: variable ,' := ', argument.
+ ] ifTrue: [
+ "In case an argument has a side effect"
+ self add: argument.
+ ]
+!
+
codeHalt
self add: 'self halt. '
!
@@ -228,7 +259,7 @@
" - returns whatever is in code OR
- assigns whatever is in code into the returnVariable"
currentMethod isInline ifTrue:[
- self codeAssign: code to: currentMethod returnVariable.
+ self codeEvaluateAndAssign: code to: currentMethod returnVariable.
] ifFalse: [
self add: '^ ', code
]
@@ -253,12 +284,26 @@
method isInline ifTrue: [
self callOnLine: method
] ifFalse: [
- self codeAssign: (method call) to: aString.
+ self codeEvaluateAndAssign: (method call) to: aString.
]
"Created: / 23-04-2015 / 18:21:51 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
+codeTokenGuard: node ifFalse: codeBlock
+ | guard id |
+ guard := PPCTokenGuard on: node.
+ (guard makesSense) ifTrue: [
+ id := self idFor: guard firstToken.
+
+ self add: 'self ', id asString, ' ifFalse: ['.
+ self indent.
+ codeBlock value.
+ self dedent.
+ self add: '].'.
+ ]
+!
+
codeTranscriptShow: text
(arguments profile) ifTrue: [
self add: 'Transcript show: ', text storeString, '; cr.'.
@@ -302,7 +347,7 @@
^ ids at: object ifAbsentPut: [
((object isKindOf: PPCNode) and: [object name isNotNil]) ifTrue: [
"Do not use prefix, if there is a name"
- name := self asSelector: object name.
+ name := self asSelector: (object name asString).
id := (name, suffix) asSymbol.
"Make sure, that the generated ID is uniqe!!"
@@ -322,6 +367,14 @@
^ self idFor: object prefixed: object prefix suffixed: suffix effect: #none
! !
+!PPCCompiler methodsFor:'code generation - profiling'!
+
+profileTokenRead: tokenName
+ arguments profile ifTrue: [
+ self add: 'context tokenRead: ', tokenName storeString, '.'
+ ]
+! !
+
!PPCCompiler methodsFor:'code generation - support'!
cache: id as: value
@@ -397,7 +450,7 @@
stopMethod
self cache: currentMethod methodName as: currentMethod.
- arguments profile ifTrue: [ Transcript show: currentMethod code; cr. ].
+ "arguments profile ifTrue: [ Transcript show: currentMethod code; cr. ]."
^ self pop.
"Modified: / 01-05-2015 / 14:18:07 / Jan Vrany <jan.vrany@fit.cvut.cz>"