"
COPYRIGHT (c) 1989 by Claus Gittinger
All Rights Reserved
This software is furnished under a license and may be used
only in accordance with the terms of that license and with the
inclusion of the above copyright notice. This software may not
be provided or otherwise made available to, or used by, any
other person. No title to or ownership of the software is
hereby transferred.
"
PrimaryNode subclass:#ConstantNode
instanceVariableNames:''
classVariableNames:'trueNode falseNode nilNode const0Node const1Node
float0Node'
poolDictionaries:''
category:'System-Compiler-Support'
!
ConstantNode comment:'
COPYRIGHT (c) 1989 by Claus Gittinger
All Rights Reserved
$Header: /cvs/stx/stx/libcomp/ConstantNode.st,v 1.4 1993-12-11 01:06:58 claus Exp $
'!
!ConstantNode class methodsFor:'queries'!
typeOfConstant:anObject
anObject isNumber ifTrue:[
(anObject isKindOf:SmallInteger) ifTrue:[
^ #Integer
].
(anObject isKindOf:Float) ifTrue:[
^ #Float
].
].
anObject isNil ifTrue:[
^ #Nil
].
(anObject == true) ifTrue:[
^ #True
].
(anObject == false) ifTrue:[
^ #False
].
^ #Literal
! !
!ConstantNode class methodsFor:'instance creation'!
type:t value:val
"some constant nodes are use so often, its worth caching them"
(t == #True) ifTrue:[
trueNode isNil ifTrue:[
trueNode := super type:t value:val
].
^ trueNode
].
(t == #False) ifTrue:[
falseNode isNil ifTrue:[
falseNode := super type:t value:val
].
^ falseNode
].
(t == #Nil) ifTrue:[
nilNode isNil ifTrue:[
nilNode := super type:t value:val
].
^ nilNode
].
(t == #Integer) ifTrue:[
(val == 0) ifTrue:[
const0Node isNil ifTrue:[
const0Node := super type:t value:val
].
^ const0Node
].
(val == 1) ifTrue:[
const1Node isNil ifTrue:[
const1Node := super type:t value:val
].
^ const1Node
]
].
(t == #Float) ifTrue:[
(val = 0.0) ifTrue:[
float0Node isNil ifTrue:[
float0Node := super type:t value:val
].
^ float0Node
]
].
^ (self basicNew) type:t value:val
! !
!ConstantNode methodsFor:'queries'!
isConstant
^ true
! !
!ConstantNode methodsFor:'evaluating'!
evaluate
^ value
!
store:aValue
self error:'store not allowed'.
^ aValue
! !
!ConstantNode methodsFor:'code generation'!
codeOn:aStream inBlock:b
"generated code for the constant"
(type == #Integer) ifTrue:[
(value between: -128 and:127) ifTrue:[
(value == 0) ifTrue:[
aStream nextPut:#push0. ^ self
].
(value == 1) ifTrue:[
aStream nextPut:#push1. ^ self
].
(value == 2) ifTrue:[
aStream nextPut:#push2. ^ self
].
(value == -1) ifTrue:[
aStream nextPut:#pushMinus1. ^ self
].
aStream nextPut:#pushNum.
aStream nextPut:value.
^ self
]
].
(type == #Nil) ifTrue:[
aStream nextPut:#pushNil. ^ self
].
(type == #True) ifTrue:[
aStream nextPut:#pushTrue. ^ self
].
(type == #False) ifTrue:[
aStream nextPut:#pushFalse. ^ self
].
aStream nextPut:#pushLit.
aStream nextPut:value
!
codeStoreOn:aStream
"should never be sent"
^ self error:'assignment to literals not allowed'
! !
!ConstantNode methodsFor:'printing'!
printOn:aStream indent:i
value storeOn:aStream
! !