compiler/PPCPluggableNode.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Wed, 15 Apr 2015 11:28:09 +0100
changeset 422 116d2b2af905
parent 421 7e08b31e0dae
child 438 20598d7ce9fa
permissions -rw-r--r--
To fold

"{ Package: 'stx:goodies/petitparser/compiler' }"

"{ NameSpace: Smalltalk }"

PPCNode subclass:#PPCPluggableNode
	instanceVariableNames:'block'
	classVariableNames:''
	poolDictionaries:''
	category:'PetitCompiler-Nodes'
!

!PPCPluggableNode methodsFor:'accessing'!

block
	
	^ block
!

block: anObject
	
	block := anObject
! !

!PPCPluggableNode methodsFor:'as yet unclassified'!

acceptsEpsilon
	^ true
!

acceptsEpsilonOpenSet: set
	^ true
!

asInlined
    "Sadly, on Smalltalk/X blocks cannot be inlined because
     the VM does not provide enough information to map
     it back to source code. Very bad indeed!!"

    ((Smalltalk respondsTo:#isSmalltalkX) and:[ Smalltalk isSmalltalkX ]) ifTrue:[
		^ super asInlined
    ] ifFalse:[
		^ PPCInlinePluggableNode new
			name: name;
			block: block;
			yourself
    ]

!

compileWith: compiler effect: effect id: id
	| blockId |
	blockId := compiler idFor: block prefixed: #block.
	
	compiler startMethod: id.
	compiler addConstant: block as: blockId.
	compiler add: '^ ', blockId, ' value: context.'.
 ^ compiler stopMethod.
!

firstCharSet
	^ PPCharSetPredicate on: [:char | (block asParser parse: char asString) isPetitFailure not ]
!

prefix
	^ #plug
! !

!PPCPluggableNode methodsFor:'comparing'!

= anotherNode
	super = anotherNode ifFalse: [ ^ false ].
	^ block = anotherNode block.
!

hash
	^ super hash bitXor: block hash
! !