Introduced PPCMappedActionNode for PPMappedActionParser.
It's compilation is not yet ideal, bot works for now.
"{ Package: 'stx:goodies/petitparser/compiler' }"
"{ NameSpace: Smalltalk }"
Object subclass:#PPCMethod
instanceVariableNames:'buffer id variableForReturn category'
classVariableNames:''
poolDictionaries:''
category:'PetitCompiler-Compiler-Codegen'
!
!PPCMethod class methodsFor:'as yet unclassified'!
new
"return an initialized instance"
^ self basicNew initialize.
! !
!PPCMethod methodsFor:'accessing'!
body
^ buffer contents
!
bridge
^ PPCBridge on: self methodName.
!
category
^ category isNil
ifTrue: [ category := 'generated' ]
ifFalse: [ category ]
!
category: value
category := value
!
code
^ String streamContents: [ :s |
s nextPutAll: self methodName; cr.
buffer codeOn: s.
]
"Modified: / 01-06-2015 / 21:24:47 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
id: value
id := value
!
indentationLevel
^ buffer indentationLevel
"Created: / 01-06-2015 / 21:38:31 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
indentationLevel: anInteger
buffer indentationLevel: anInteger
"Created: / 01-06-2015 / 21:38:58 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
methodName
^ id
! !
!PPCMethod methodsFor:'as yet unclassified'!
add: string
buffer add: string
"Modified: / 01-06-2015 / 21:09:06 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
addOnLine: string
buffer addOnLine: string
"Modified: / 01-06-2015 / 21:09:20 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
call
^ 'self ', self methodName, '.'.
!
profilingBegin
self profile ifTrue: [
^ ' context methodInvoked: #', id, '.'
].
^ ''
!
profilingEnd
self profile ifTrue: [
^ ' context methodFinished: #', id, '.'
].
^ ''
! !
!PPCMethod methodsFor:'code generation'!
code: aStringOrBlockOrRBParseNode
buffer code: aStringOrBlockOrRBParseNode.
"Created: / 01-06-2015 / 22:31:16 / Jan Vrany <jan.vrany@fit.cvut.cz>"
"Modified (format): / 01-06-2015 / 23:50:26 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
codeBlock: contents
| outerBlock innerBlock |
outerBlock := buffer.
innerBlock := PPCCodeBlock new.
innerBlock indentationLevel: outerBlock indentationLevel + 1.
[
buffer addOnLine:'['; nl; codeIndent.
buffer := innerBlock.
self code: contents.
] ensure:[
buffer := outerBlock.
buffer
code: (String streamContents:[:s | innerBlock codeOn: s]);
nl;
codeIndent.
buffer addOnLine:']'.
]
"Created: / 01-06-2015 / 22:33:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
"Modified: / 03-06-2015 / 06:11:32 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!PPCMethod methodsFor:'code generation - indenting'!
dedent
buffer dedent
"Created: / 01-06-2015 / 21:32:28 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
indent
buffer indent
"Created: / 01-06-2015 / 21:32:22 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
nl
buffer nl
"Created: / 01-06-2015 / 21:52:31 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!PPCMethod methodsFor:'code generation - variables'!
allocateReturnVariable
^ variableForReturn isNil ifTrue:[
variableForReturn := self allocateTemporaryVariableNamed: 'retval'
] ifFalse:[
variableForReturn
].
"Created: / 23-04-2015 / 18:03:40 / Jan Vrany <jan.vrany@fit.cvut.cz>"
"Modified (format): / 01-06-2015 / 21:01:29 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
allocateTemporaryVariableNamed:preferredName
"Allocate a new variable with (preferably) given name.
Returns a real variable name that should be used."
^ buffer allocateTemporaryVariableNamed: preferredName
"Created: / 23-04-2015 / 17:37:55 / Jan Vrany <jan.vrany@fit.cvut.cz>"
"Modified: / 01-06-2015 / 21:04:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
returnVariable
^ variableForReturn
"Created: / 23-04-2015 / 20:50:50 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
returnVariable: aString
^ variableForReturn := aString
"Created: / 23-04-2015 / 18:23:47 / Jan Vrany <jan.vrany@fit.cvut.cz>"
"Modified: / 23-04-2015 / 21:08:54 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!PPCMethod methodsFor:'initialization'!
initialize
buffer := PPCCodeBlock new.
"Modified: / 01-06-2015 / 21:33:36 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!PPCMethod methodsFor:'printing'!
printOn:aStream
"append a printed representation if the receiver to the argument, aStream"
super printOn:aStream.
aStream nextPutAll:' id: '.
id printOn:aStream.
"Modified: / 23-04-2015 / 12:32:30 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!PPCMethod methodsFor:'testing'!
isInline
^ false
!
isMethod
^ true
! !
!PPCMethod class methodsFor:'documentation'!
version_HG
^ '$Changeset: <not expanded> $'
! !