ConstNode.st
author Stefan Vogel <sv@exept.de>
Fri, 06 Mar 1998 16:38:37 +0100
changeset 657 0ecf1ff6f6bf
parent 612 2748896a66c8
child 710 fc74f135494d
permissions -rw-r--r--
Fix #makeMethod:
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
     1
"
4
f6fd83437415 *** empty log message ***
claus
parents: 3
diff changeset
     2
 COPYRIGHT (c) 1989 by Claus Gittinger
47
f861ad42703e *** empty log message ***
claus
parents: 33
diff changeset
     3
	      All Rights Reserved
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
     4
7ad01559b262 Initial revision
claus
parents:
diff changeset
     5
 This software is furnished under a license and may be used
7ad01559b262 Initial revision
claus
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
7ad01559b262 Initial revision
claus
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
7ad01559b262 Initial revision
claus
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
7ad01559b262 Initial revision
claus
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
7ad01559b262 Initial revision
claus
parents:
diff changeset
    10
 hereby transferred.
7ad01559b262 Initial revision
claus
parents:
diff changeset
    11
"
7ad01559b262 Initial revision
claus
parents:
diff changeset
    12
612
2748896a66c8 comments
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
    13
'From Smalltalk/X, Version:3.1.10 on 20-sep-1997 at 11:49:43 pm'                !
2748896a66c8 comments
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
    14
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
    15
PrimaryNode subclass:#ConstantNode
242
3cca9ffd2620 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
    16
	instanceVariableNames:''
3cca9ffd2620 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
    17
	classVariableNames:'TrueNode FalseNode NilNode Const0Node Const1Node Float0Node'
3cca9ffd2620 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
    18
	poolDictionaries:''
3cca9ffd2620 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
    19
	category:'System-Compiler-Support'
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
    20
!
7ad01559b262 Initial revision
claus
parents:
diff changeset
    21
20
f8dd8ba75205 *** empty log message ***
claus
parents: 13
diff changeset
    22
!ConstantNode class methodsFor:'documentation'!
f8dd8ba75205 *** empty log message ***
claus
parents: 13
diff changeset
    23
f8dd8ba75205 *** empty log message ***
claus
parents: 13
diff changeset
    24
copyright
f8dd8ba75205 *** empty log message ***
claus
parents: 13
diff changeset
    25
"
f8dd8ba75205 *** empty log message ***
claus
parents: 13
diff changeset
    26
 COPYRIGHT (c) 1989 by Claus Gittinger
47
f861ad42703e *** empty log message ***
claus
parents: 33
diff changeset
    27
	      All Rights Reserved
20
f8dd8ba75205 *** empty log message ***
claus
parents: 13
diff changeset
    28
f8dd8ba75205 *** empty log message ***
claus
parents: 13
diff changeset
    29
 This software is furnished under a license and may be used
f8dd8ba75205 *** empty log message ***
claus
parents: 13
diff changeset
    30
 only in accordance with the terms of that license and with the
f8dd8ba75205 *** empty log message ***
claus
parents: 13
diff changeset
    31
 inclusion of the above copyright notice.   This software may not
f8dd8ba75205 *** empty log message ***
claus
parents: 13
diff changeset
    32
 be provided or otherwise made available to, or used by, any
f8dd8ba75205 *** empty log message ***
claus
parents: 13
diff changeset
    33
 other person.  No title to or ownership of the software is
f8dd8ba75205 *** empty log message ***
claus
parents: 13
diff changeset
    34
 hereby transferred.
f8dd8ba75205 *** empty log message ***
claus
parents: 13
diff changeset
    35
"
f8dd8ba75205 *** empty log message ***
claus
parents: 13
diff changeset
    36
!
f8dd8ba75205 *** empty log message ***
claus
parents: 13
diff changeset
    37
f8dd8ba75205 *** empty log message ***
claus
parents: 13
diff changeset
    38
documentation
f8dd8ba75205 *** empty log message ***
claus
parents: 13
diff changeset
    39
"
f8dd8ba75205 *** empty log message ***
claus
parents: 13
diff changeset
    40
    node for parse-trees, representing literal constants
261
0372e948ca2d commentary
Claus Gittinger <cg@exept.de>
parents: 242
diff changeset
    41
    This is a helper class for the compiler.
263
3b21d0991eff documentation
Claus Gittinger <cg@exept.de>
parents: 261
diff changeset
    42
3b21d0991eff documentation
Claus Gittinger <cg@exept.de>
parents: 261
diff changeset
    43
    [author:]
3b21d0991eff documentation
Claus Gittinger <cg@exept.de>
parents: 261
diff changeset
    44
        Claus Gittinger
20
f8dd8ba75205 *** empty log message ***
claus
parents: 13
diff changeset
    45
"
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
    46
! !
7ad01559b262 Initial revision
claus
parents:
diff changeset
    47
7ad01559b262 Initial revision
claus
parents:
diff changeset
    48
!ConstantNode class methodsFor:'instance creation'!
7ad01559b262 Initial revision
claus
parents:
diff changeset
    49
7ad01559b262 Initial revision
claus
parents:
diff changeset
    50
type:t value:val
13
30e69e21d1d1 *** empty log message ***
claus
parents: 10
diff changeset
    51
    "some constant nodes are used so often, its worth caching them"
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
    52
    (t == #True) ifTrue:[
47
f861ad42703e *** empty log message ***
claus
parents: 33
diff changeset
    53
	TrueNode isNil ifTrue:[
f861ad42703e *** empty log message ***
claus
parents: 33
diff changeset
    54
	    TrueNode := (self basicNew) type:t value:val
f861ad42703e *** empty log message ***
claus
parents: 33
diff changeset
    55
	].
f861ad42703e *** empty log message ***
claus
parents: 33
diff changeset
    56
	^ TrueNode
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
    57
    ].
7ad01559b262 Initial revision
claus
parents:
diff changeset
    58
    (t == #False) ifTrue:[
47
f861ad42703e *** empty log message ***
claus
parents: 33
diff changeset
    59
	FalseNode isNil ifTrue:[
f861ad42703e *** empty log message ***
claus
parents: 33
diff changeset
    60
	    FalseNode := (self basicNew) type:t value:val
f861ad42703e *** empty log message ***
claus
parents: 33
diff changeset
    61
	].
f861ad42703e *** empty log message ***
claus
parents: 33
diff changeset
    62
	^ FalseNode
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
    63
    ].
7ad01559b262 Initial revision
claus
parents:
diff changeset
    64
    (t == #Nil) ifTrue:[
47
f861ad42703e *** empty log message ***
claus
parents: 33
diff changeset
    65
	NilNode isNil ifTrue:[
f861ad42703e *** empty log message ***
claus
parents: 33
diff changeset
    66
	    NilNode := (self basicNew) type:t value:val
f861ad42703e *** empty log message ***
claus
parents: 33
diff changeset
    67
	].
f861ad42703e *** empty log message ***
claus
parents: 33
diff changeset
    68
	^ NilNode
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
    69
    ].
7ad01559b262 Initial revision
claus
parents:
diff changeset
    70
    (t == #Integer) ifTrue:[
47
f861ad42703e *** empty log message ***
claus
parents: 33
diff changeset
    71
	(val == 0) ifTrue:[
f861ad42703e *** empty log message ***
claus
parents: 33
diff changeset
    72
	    Const0Node isNil ifTrue:[
f861ad42703e *** empty log message ***
claus
parents: 33
diff changeset
    73
		Const0Node := (self basicNew) type:t value:val
f861ad42703e *** empty log message ***
claus
parents: 33
diff changeset
    74
	    ].
f861ad42703e *** empty log message ***
claus
parents: 33
diff changeset
    75
	    ^ Const0Node
f861ad42703e *** empty log message ***
claus
parents: 33
diff changeset
    76
	].
f861ad42703e *** empty log message ***
claus
parents: 33
diff changeset
    77
	(val == 1) ifTrue:[
f861ad42703e *** empty log message ***
claus
parents: 33
diff changeset
    78
	    Const1Node isNil ifTrue:[
f861ad42703e *** empty log message ***
claus
parents: 33
diff changeset
    79
		Const1Node := (self basicNew) type:t value:val
f861ad42703e *** empty log message ***
claus
parents: 33
diff changeset
    80
	    ].
f861ad42703e *** empty log message ***
claus
parents: 33
diff changeset
    81
	    ^ Const1Node
f861ad42703e *** empty log message ***
claus
parents: 33
diff changeset
    82
	]
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
    83
    ].
7ad01559b262 Initial revision
claus
parents:
diff changeset
    84
    (t == #Float) ifTrue:[
47
f861ad42703e *** empty log message ***
claus
parents: 33
diff changeset
    85
	(val = 0.0) ifTrue:[
f861ad42703e *** empty log message ***
claus
parents: 33
diff changeset
    86
	    Float0Node isNil ifTrue:[
f861ad42703e *** empty log message ***
claus
parents: 33
diff changeset
    87
		Float0Node := (self basicNew) type:t value:val
f861ad42703e *** empty log message ***
claus
parents: 33
diff changeset
    88
	    ].
f861ad42703e *** empty log message ***
claus
parents: 33
diff changeset
    89
	    ^ Float0Node
f861ad42703e *** empty log message ***
claus
parents: 33
diff changeset
    90
	]
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
    91
    ].
7ad01559b262 Initial revision
claus
parents:
diff changeset
    92
    ^ (self basicNew) type:t value:val
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
    93
!
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
    94
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
    95
value:val
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
    96
    ^ self type:(self typeOfConstant:val) value:val 
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
    97
! !
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
    98
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
    99
!ConstantNode class methodsFor:'queries'!
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   100
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   101
typeOfConstant:anObject
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   102
    "return the constantNode type for an object"
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   103
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   104
    "the most common case first ..."
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   105
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   106
    (anObject isMemberOf:SmallInteger) ifTrue:[
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   107
	^ #Integer
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   108
    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   109
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   110
    anObject isNil ifTrue:[
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   111
	^ #Nil
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   112
    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   113
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   114
    anObject isNumber ifTrue:[
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   115
	"the most common case first ..."
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   116
	(anObject isMemberOf:Float) ifTrue:[
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   117
	    ^ #Float
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   118
	].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   119
	anObject isInteger ifTrue:[
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   120
	    ^ #Integer
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   121
	].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   122
    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   123
    (anObject == true) ifTrue:[
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   124
	^ #True
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   125
    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   126
    (anObject == false) ifTrue:[
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   127
	^ #False
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   128
    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   129
    ^ #Literal
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   130
! !
7ad01559b262 Initial revision
claus
parents:
diff changeset
   131
13
30e69e21d1d1 *** empty log message ***
claus
parents: 10
diff changeset
   132
!ConstantNode methodsFor:'accessing'!
30e69e21d1d1 *** empty log message ***
claus
parents: 10
diff changeset
   133
30e69e21d1d1 *** empty log message ***
claus
parents: 10
diff changeset
   134
type:t value:val
30e69e21d1d1 *** empty log message ***
claus
parents: 10
diff changeset
   135
    type := t.
30e69e21d1d1 *** empty log message ***
claus
parents: 10
diff changeset
   136
    value := val
30e69e21d1d1 *** empty log message ***
claus
parents: 10
diff changeset
   137
! !
30e69e21d1d1 *** empty log message ***
claus
parents: 10
diff changeset
   138
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   139
!ConstantNode methodsFor:'code generation'!
7ad01559b262 Initial revision
claus
parents:
diff changeset
   140
104
claus
parents: 103
diff changeset
   141
codeOn:aStream inBlock:b for:aCompiler
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   142
    "generated code for the constant"
7ad01559b262 Initial revision
claus
parents:
diff changeset
   143
104
claus
parents: 103
diff changeset
   144
    |code index|
96
claus
parents: 62
diff changeset
   145
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   146
    (type == #Integer) ifTrue:[
47
f861ad42703e *** empty log message ***
claus
parents: 33
diff changeset
   147
	(value between: -128 and:127) ifTrue:[
f861ad42703e *** empty log message ***
claus
parents: 33
diff changeset
   148
	    (value == 0) ifTrue:[
96
claus
parents: 62
diff changeset
   149
		code := #push0
47
f861ad42703e *** empty log message ***
claus
parents: 33
diff changeset
   150
	    ].
f861ad42703e *** empty log message ***
claus
parents: 33
diff changeset
   151
	    (value == 1) ifTrue:[
96
claus
parents: 62
diff changeset
   152
		code := #push1.
47
f861ad42703e *** empty log message ***
claus
parents: 33
diff changeset
   153
	    ].
f861ad42703e *** empty log message ***
claus
parents: 33
diff changeset
   154
	    (value == 2) ifTrue:[
96
claus
parents: 62
diff changeset
   155
		code := #push2.
47
f861ad42703e *** empty log message ***
claus
parents: 33
diff changeset
   156
	    ].
f861ad42703e *** empty log message ***
claus
parents: 33
diff changeset
   157
	    (value == -1) ifTrue:[
96
claus
parents: 62
diff changeset
   158
		code := #pushMinus1.
47
f861ad42703e *** empty log message ***
claus
parents: 33
diff changeset
   159
	    ].
96
claus
parents: 62
diff changeset
   160
	    code notNil ifTrue:[
claus
parents: 62
diff changeset
   161
		aStream nextPut:code. ^ self
claus
parents: 62
diff changeset
   162
	    ].
claus
parents: 62
diff changeset
   163
claus
parents: 62
diff changeset
   164
	    aStream nextPut:#pushNum; nextPut:value.
47
f861ad42703e *** empty log message ***
claus
parents: 33
diff changeset
   165
	    ^ self
f861ad42703e *** empty log message ***
claus
parents: 33
diff changeset
   166
	].
f861ad42703e *** empty log message ***
claus
parents: 33
diff changeset
   167
	(value between:16r-8000 and:16r7FFF) ifTrue:[
96
claus
parents: 62
diff changeset
   168
	    aStream nextPut:#pushNum16; nextPut:value; nextPut:0. 
47
f861ad42703e *** empty log message ***
claus
parents: 33
diff changeset
   169
	    ^ self
f861ad42703e *** empty log message ***
claus
parents: 33
diff changeset
   170
	]
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   171
    ].
7ad01559b262 Initial revision
claus
parents:
diff changeset
   172
    (type == #Nil) ifTrue:[
96
claus
parents: 62
diff changeset
   173
	code := #pushNil.
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   174
    ].
7ad01559b262 Initial revision
claus
parents:
diff changeset
   175
    (type == #True) ifTrue:[
96
claus
parents: 62
diff changeset
   176
	code := #pushTrue.
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   177
    ].
7ad01559b262 Initial revision
claus
parents:
diff changeset
   178
    (type == #False) ifTrue:[
96
claus
parents: 62
diff changeset
   179
	code := #pushFalse.
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   180
    ].
96
claus
parents: 62
diff changeset
   181
    code notNil ifTrue:[
claus
parents: 62
diff changeset
   182
	aStream nextPut:code. ^ self
claus
parents: 62
diff changeset
   183
    ].
106
claus
parents: 104
diff changeset
   184
claus
parents: 104
diff changeset
   185
    "/ kludge for backward compatibility
claus
parents: 104
diff changeset
   186
    aCompiler isNil ifTrue:[
claus
parents: 104
diff changeset
   187
	aStream nextPut:#pushLit; nextPut:value.
claus
parents: 104
diff changeset
   188
	^ self.
claus
parents: 104
diff changeset
   189
    ].
claus
parents: 104
diff changeset
   190
104
claus
parents: 103
diff changeset
   191
    index := aCompiler addLiteral:value.
claus
parents: 103
diff changeset
   192
    index <= 8 ifTrue:[
claus
parents: 103
diff changeset
   193
	aStream nextPut:(#(pushLit1 pushLit2 pushLit3 pushLit4
claus
parents: 103
diff changeset
   194
			   pushLit5 pushLit6 pushLit7 pushLit8) at:index).
claus
parents: 103
diff changeset
   195
    ] ifFalse:[
106
claus
parents: 104
diff changeset
   196
	index < 256 ifTrue:[
claus
parents: 104
diff changeset
   197
	    aStream nextPut:#pushLitS; nextPut:index
claus
parents: 104
diff changeset
   198
	] ifFalse:[
claus
parents: 104
diff changeset
   199
	    aStream nextPut:#pushLitL; nextPut:index; nextPut:0
claus
parents: 104
diff changeset
   200
	].
104
claus
parents: 103
diff changeset
   201
    ].
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   202
!
7ad01559b262 Initial revision
claus
parents:
diff changeset
   203
104
claus
parents: 103
diff changeset
   204
codeStoreOn:aStream inBlock:codeBlock valueNeeded:valueNeeded for:aCompiler
13
30e69e21d1d1 *** empty log message ***
claus
parents: 10
diff changeset
   205
    "not sent - parser checks for this"
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   206
7ad01559b262 Initial revision
claus
parents:
diff changeset
   207
    ^ self error:'assignment to literals not allowed'
7ad01559b262 Initial revision
claus
parents:
diff changeset
   208
! !
7ad01559b262 Initial revision
claus
parents:
diff changeset
   209
539
69a1cd05c7d6 added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
   210
!ConstantNode methodsFor:'enumeration'!
69a1cd05c7d6 added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
   211
69a1cd05c7d6 added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
   212
nodeDo:anEnumerator
69a1cd05c7d6 added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
   213
    "helper for parse tree walking"
69a1cd05c7d6 added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
   214
69a1cd05c7d6 added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
   215
    ^ anEnumerator doLiteral:self value:value
69a1cd05c7d6 added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
   216
69a1cd05c7d6 added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
   217
    "Modified: 19.6.1997 / 16:40:59 / cg"
69a1cd05c7d6 added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
   218
! !
69a1cd05c7d6 added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
   219
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   220
!ConstantNode methodsFor:'evaluating'!
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   221
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   222
evaluate
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   223
    ^ value
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   224
!
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   225
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   226
store:aValue
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   227
    "not reached - parser checks for this"
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   228
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   229
    self error:'store not allowed'.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   230
    ^ aValue
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   231
! !
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   232
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   233
!ConstantNode methodsFor:'printing'!
7ad01559b262 Initial revision
claus
parents:
diff changeset
   234
13
30e69e21d1d1 *** empty log message ***
claus
parents: 10
diff changeset
   235
displayString
612
2748896a66c8 comments
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
   236
    "return a printed representation of the receiver for displaying"
2748896a66c8 comments
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
   237
13
30e69e21d1d1 *** empty log message ***
claus
parents: 10
diff changeset
   238
    ^ value displayString
612
2748896a66c8 comments
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
   239
2748896a66c8 comments
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
   240
    "Modified: 20.9.1997 / 11:39:07 / cg"
13
30e69e21d1d1 *** empty log message ***
claus
parents: 10
diff changeset
   241
!
30e69e21d1d1 *** empty log message ***
claus
parents: 10
diff changeset
   242
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   243
printOn:aStream indent:i
7ad01559b262 Initial revision
claus
parents:
diff changeset
   244
    value storeOn:aStream
7ad01559b262 Initial revision
claus
parents:
diff changeset
   245
! !
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   246
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   247
!ConstantNode methodsFor:'queries'!
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   248
242
3cca9ffd2620 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   249
canReuseAsArg:anotherNode
3cca9ffd2620 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   250
    |otherValue|
3cca9ffd2620 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   251
3cca9ffd2620 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   252
    anotherNode isConstant ifTrue:[
3cca9ffd2620 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   253
        anotherNode type ~~ type ifTrue:[^ false].
3cca9ffd2620 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   254
3cca9ffd2620 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   255
        otherValue := anotherNode evaluate.
3cca9ffd2620 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   256
        (value isMemberOf:SmallInteger) ifTrue:[
3cca9ffd2620 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   257
            (value == 0) ifTrue:[^ false].
3cca9ffd2620 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   258
            (value == 1) ifTrue:[^ false].
3cca9ffd2620 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   259
            (value == 2) ifTrue:[^ false].
3cca9ffd2620 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   260
            (value == -1) ifTrue:[^ false].
3cca9ffd2620 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   261
            ^ otherValue == value
3cca9ffd2620 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   262
        ].
3cca9ffd2620 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   263
        (value isMemberOf:Float) ifTrue:[
3cca9ffd2620 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   264
            ^ (otherValue isMemberOf:Float)
3cca9ffd2620 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   265
              and:[otherValue = value]
3cca9ffd2620 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   266
        ].
3cca9ffd2620 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   267
        (value isMemberOf:Symbol) ifTrue:[
3cca9ffd2620 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   268
            ^ otherValue == value
3cca9ffd2620 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   269
        ].
3cca9ffd2620 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   270
        (value isMemberOf:String) ifTrue:[
3cca9ffd2620 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   271
            ^ (otherValue isMemberOf:String)
3cca9ffd2620 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   272
              and:[otherValue = value]
3cca9ffd2620 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   273
        ].
3cca9ffd2620 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   274
    ].
3cca9ffd2620 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   275
    ^ false
3cca9ffd2620 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   276
3cca9ffd2620 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   277
    "Created: 14.4.1996 / 00:43:14 / cg"
3cca9ffd2620 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   278
    "Modified: 14.4.1996 / 01:00:29 / cg"
3cca9ffd2620 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   279
!
3cca9ffd2620 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   280
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   281
isConstant
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   282
    ^ true
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   283
! !
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   284
148
ef0e604209ec version method at the end
Claus Gittinger <cg@exept.de>
parents: 140
diff changeset
   285
!ConstantNode class methodsFor:'documentation'!
ef0e604209ec version method at the end
Claus Gittinger <cg@exept.de>
parents: 140
diff changeset
   286
ef0e604209ec version method at the end
Claus Gittinger <cg@exept.de>
parents: 140
diff changeset
   287
version
612
2748896a66c8 comments
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
   288
    ^ '$Header: /cvs/stx/stx/libcomp/Attic/ConstNode.st,v 1.24 1997-09-20 21:03:30 cg Exp $'
148
ef0e604209ec version method at the end
Claus Gittinger <cg@exept.de>
parents: 140
diff changeset
   289
! !