IRStackCount.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Thu, 30 Oct 2014 22:27:09 +0000
changeset 44 840c68a91cdd
parent 43 c8afb8e4c3cc
permissions -rw-r--r--
Tests moved to separate subpackage to follow St/X conventions.

"{ Package: 'ctu:ircompiler' }"

Object subclass:#IRStackCount
	instanceVariableNames:'start position length'
	classVariableNames:''
	poolDictionaries:''
	category:'IR Compiler-Bytecode'
!

IRStackCount comment:'This keeps track of the stack count for the BytecodeGenerator.'
!


!IRStackCount class methodsFor:'instance creation'!

new

	^ super new startAt: 0
! !

!IRStackCount class methodsFor:'as yet unclassified'!

startAt: pos

	^ super new startAt: pos
! !

!IRStackCount methodsFor:'affecting'!

pop

	^ self pop: 1
!

pop: n

	(position _ position - n) "< 0 
		ifTrue: [self error: 'Parse stack underflow']"
!

push

	^ self push: 1
!

push: n

	(position _ position + n) > length 
		ifTrue: [length _ position]
! !

!IRStackCount methodsFor:'comparing'!

= other

	^ self class == other class 
	  and: [start = other start
	  and: [position = other position
	  and: [length = other size]]]
!

hash

	^ position hash bitXor: (length hash bitXor: start hash)
! !

!IRStackCount methodsFor:'error handling'!

errorStackOutOfSync: aStackCount 
	self error: 'stack not in sync!!'.
! !

!IRStackCount methodsFor:'initialize'!

startAt: pos

	start _ position _ length _ pos
! !

!IRStackCount methodsFor:'printing'!

printOn: aStream
	
	super printOn: aStream.
	aStream
		nextPutAll: ' start '; print: start;
		nextPutAll: ' stop '; print: position;
		nextPutAll: ' max '; print: length.
! !

!IRStackCount methodsFor:'results'!

length

	^length
!

linkTo: stackOrNil

	stackOrNil ifNil: [^ self class startAt: self position].
	^ self position = stackOrNil start
		ifTrue: [stackOrNil]
		ifFalse: [self errorStackOutOfSync: stackOrNil]
!

position

	^position
!

size

	^length
!

start

	^ start
! !

!IRStackCount class methodsFor:'documentation'!

version_CVS
    ^ '$eader: /cvs/stx/cvut/stx/goodies/newcompiler/IRStackCount.st,v 1.3 2009/10/08 11:59:57 fm Exp$'
!

version_SVN
    ^ '$Id::                                                                                                                        $'
! !