AssignmentNode.st
author Claus Gittinger <cg@exept.de>
Thu, 25 Apr 1996 19:09:53 +0200
changeset 263 3b21d0991eff
parent 261 0372e948ca2d
child 375 00e24958b103
permissions -rw-r--r--
documentation
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
52
d80ec10c3321 *** empty log message ***
claus
parents: 32
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
7ad01559b262 Initial revision
claus
parents:
diff changeset
    13
ParseNode subclass:#AssignmentNode
219
6b977f472cda care for block-stores into outer contexts
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
    14
	instanceVariableNames:'variable expression'
6b977f472cda care for block-stores into outer contexts
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
    15
	classVariableNames:''
6b977f472cda care for block-stores into outer contexts
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
    16
	poolDictionaries:''
6b977f472cda care for block-stores into outer contexts
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
    17
	category:'System-Compiler-Support'
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
    18
!
7ad01559b262 Initial revision
claus
parents:
diff changeset
    19
20
f8dd8ba75205 *** empty log message ***
claus
parents: 17
diff changeset
    20
!AssignmentNode class methodsFor:'documentation'!
f8dd8ba75205 *** empty log message ***
claus
parents: 17
diff changeset
    21
f8dd8ba75205 *** empty log message ***
claus
parents: 17
diff changeset
    22
copyright
f8dd8ba75205 *** empty log message ***
claus
parents: 17
diff changeset
    23
"
f8dd8ba75205 *** empty log message ***
claus
parents: 17
diff changeset
    24
 COPYRIGHT (c) 1989 by Claus Gittinger
52
d80ec10c3321 *** empty log message ***
claus
parents: 32
diff changeset
    25
	      All Rights Reserved
20
f8dd8ba75205 *** empty log message ***
claus
parents: 17
diff changeset
    26
f8dd8ba75205 *** empty log message ***
claus
parents: 17
diff changeset
    27
 This software is furnished under a license and may be used
f8dd8ba75205 *** empty log message ***
claus
parents: 17
diff changeset
    28
 only in accordance with the terms of that license and with the
f8dd8ba75205 *** empty log message ***
claus
parents: 17
diff changeset
    29
 inclusion of the above copyright notice.   This software may not
f8dd8ba75205 *** empty log message ***
claus
parents: 17
diff changeset
    30
 be provided or otherwise made available to, or used by, any
f8dd8ba75205 *** empty log message ***
claus
parents: 17
diff changeset
    31
 other person.  No title to or ownership of the software is
f8dd8ba75205 *** empty log message ***
claus
parents: 17
diff changeset
    32
 hereby transferred.
f8dd8ba75205 *** empty log message ***
claus
parents: 17
diff changeset
    33
"
f8dd8ba75205 *** empty log message ***
claus
parents: 17
diff changeset
    34
!
f8dd8ba75205 *** empty log message ***
claus
parents: 17
diff changeset
    35
f8dd8ba75205 *** empty log message ***
claus
parents: 17
diff changeset
    36
documentation
f8dd8ba75205 *** empty log message ***
claus
parents: 17
diff changeset
    37
"
261
0372e948ca2d commentary
Claus Gittinger <cg@exept.de>
parents: 224
diff changeset
    38
    node for parse-trees, representing assignments.
0372e948ca2d commentary
Claus Gittinger <cg@exept.de>
parents: 224
diff changeset
    39
    This is a helper class for the compiler.
263
3b21d0991eff documentation
Claus Gittinger <cg@exept.de>
parents: 261
diff changeset
    40
3b21d0991eff documentation
Claus Gittinger <cg@exept.de>
parents: 261
diff changeset
    41
    [author:]
3b21d0991eff documentation
Claus Gittinger <cg@exept.de>
parents: 261
diff changeset
    42
        Claus Gittinger
3b21d0991eff documentation
Claus Gittinger <cg@exept.de>
parents: 261
diff changeset
    43
20
f8dd8ba75205 *** empty log message ***
claus
parents: 17
diff changeset
    44
"
f8dd8ba75205 *** empty log message ***
claus
parents: 17
diff changeset
    45
! !
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
    46
7ad01559b262 Initial revision
claus
parents:
diff changeset
    47
!AssignmentNode class methodsFor:'instance creation'!
7ad01559b262 Initial revision
claus
parents:
diff changeset
    48
7ad01559b262 Initial revision
claus
parents:
diff changeset
    49
variable:v expression:e
7ad01559b262 Initial revision
claus
parents:
diff changeset
    50
    ^ (self basicNew) variable:v expression:e
7ad01559b262 Initial revision
claus
parents:
diff changeset
    51
! !
7ad01559b262 Initial revision
claus
parents:
diff changeset
    52
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
    53
!AssignmentNode methodsFor:'accessing'!
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
    54
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
    55
expression
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
    56
    ^ expression
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
    57
!
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
    58
7ad01559b262 Initial revision
claus
parents:
diff changeset
    59
variable:v expression:e
7ad01559b262 Initial revision
claus
parents:
diff changeset
    60
    variable := v.
7ad01559b262 Initial revision
claus
parents:
diff changeset
    61
    expression := e
7ad01559b262 Initial revision
claus
parents:
diff changeset
    62
! !
7ad01559b262 Initial revision
claus
parents:
diff changeset
    63
7ad01559b262 Initial revision
claus
parents:
diff changeset
    64
!AssignmentNode methodsFor:'code generation'!
7ad01559b262 Initial revision
claus
parents:
diff changeset
    65
117
claus
parents: 104
diff changeset
    66
checkIncDecOn:aStream
219
6b977f472cda care for block-stores into outer contexts
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
    67
    "check if we can use incMvar / decMvar instruction.
6b977f472cda care for block-stores into outer contexts
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
    68
     If so, code it and return true.
6b977f472cda care for block-stores into outer contexts
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
    69
     Otherwise, return false."
6b977f472cda care for block-stores into outer contexts
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
    70
117
claus
parents: 104
diff changeset
    71
    |sel erec arg code|
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
    72
7ad01559b262 Initial revision
claus
parents:
diff changeset
    73
    (variable type == #MethodVariable) ifTrue:[
219
6b977f472cda care for block-stores into outer contexts
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
    74
        expression isBinaryMessage ifTrue:[
6b977f472cda care for block-stores into outer contexts
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
    75
            sel := expression selector.
6b977f472cda care for block-stores into outer contexts
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
    76
            erec := expression receiver.
6b977f472cda care for block-stores into outer contexts
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
    77
6b977f472cda care for block-stores into outer contexts
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
    78
            ((sel == #+) or:[sel == #-]) ifTrue:[
6b977f472cda care for block-stores into outer contexts
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
    79
                (erec type == #MethodVariable) ifTrue:[
6b977f472cda care for block-stores into outer contexts
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
    80
                    (erec index == variable index) ifTrue:[
6b977f472cda care for block-stores into outer contexts
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
    81
                        arg := expression arg1.
6b977f472cda care for block-stores into outer contexts
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
    82
                        arg isConstant ifTrue:[
6b977f472cda care for block-stores into outer contexts
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
    83
                            (arg value == 1) ifTrue:[
6b977f472cda care for block-stores into outer contexts
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
    84
                                (sel == #+) ifTrue:[
6b977f472cda care for block-stores into outer contexts
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
    85
                                    code := #incMethodVar
6b977f472cda care for block-stores into outer contexts
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
    86
                                ] ifFalse:[
6b977f472cda care for block-stores into outer contexts
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
    87
                                    code := #decMethodVar
6b977f472cda care for block-stores into outer contexts
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
    88
                                ].
6b977f472cda care for block-stores into outer contexts
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
    89
                                aStream nextPut:code; nextPut:(expression lineNumber); nextPut:(variable index).
6b977f472cda care for block-stores into outer contexts
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
    90
                                ^ true
6b977f472cda care for block-stores into outer contexts
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
    91
                            ]
6b977f472cda care for block-stores into outer contexts
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
    92
                        ]
6b977f472cda care for block-stores into outer contexts
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
    93
                    ]
6b977f472cda care for block-stores into outer contexts
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
    94
                ]
6b977f472cda care for block-stores into outer contexts
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
    95
            ]
6b977f472cda care for block-stores into outer contexts
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
    96
        ]
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
    97
    ].
117
claus
parents: 104
diff changeset
    98
    ^ false
219
6b977f472cda care for block-stores into outer contexts
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
    99
6b977f472cda care for block-stores into outer contexts
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   100
    "Modified: 1.3.1996 / 00:08:02 / cg"
117
claus
parents: 104
diff changeset
   101
!
claus
parents: 104
diff changeset
   102
claus
parents: 104
diff changeset
   103
codeForSideEffectOn:aStream inBlock:b for:aCompiler
claus
parents: 104
diff changeset
   104
    (self checkIncDecOn:aStream) ifTrue:[^ self].
219
6b977f472cda care for block-stores into outer contexts
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   105
6b977f472cda care for block-stores into outer contexts
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   106
    self codeNormalOn:aStream valueNeeded:false inBlock:b for:aCompiler
117
claus
parents: 104
diff changeset
   107
claus
parents: 104
diff changeset
   108
    "Modified: 4.9.1995 / 14:38:10 / claus"
219
6b977f472cda care for block-stores into outer contexts
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   109
    "Modified: 1.3.1996 / 00:42:10 / cg"
6b977f472cda care for block-stores into outer contexts
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   110
!
6b977f472cda care for block-stores into outer contexts
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   111
6b977f472cda care for block-stores into outer contexts
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   112
codeNormalOn:aStream valueNeeded:forValue inBlock:b for:aCompiler
6b977f472cda care for block-stores into outer contexts
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   113
    expression codeOn:aStream inBlock:b for:aCompiler.
6b977f472cda care for block-stores into outer contexts
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   114
    expression isBlock ifTrue:[
6b977f472cda care for block-stores into outer contexts
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   115
        variable isLocal ifTrue:[
6b977f472cda care for block-stores into outer contexts
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   116
            aStream nextPut:#blockRef
6b977f472cda care for block-stores into outer contexts
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   117
        ]
6b977f472cda care for block-stores into outer contexts
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   118
    ].
6b977f472cda care for block-stores into outer contexts
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   119
6b977f472cda care for block-stores into outer contexts
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   120
    variable codeStoreOn:aStream inBlock:b valueNeeded:forValue for:aCompiler
6b977f472cda care for block-stores into outer contexts
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   121
6b977f472cda care for block-stores into outer contexts
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   122
    "Modified: 4.9.1995 / 14:38:10 / claus"
6b977f472cda care for block-stores into outer contexts
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   123
    "Modified: 1.3.1996 / 00:10:13 / cg"
6b977f472cda care for block-stores into outer contexts
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   124
    "Created: 1.3.1996 / 00:41:43 / cg"
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   125
!
7ad01559b262 Initial revision
claus
parents:
diff changeset
   126
104
claus
parents: 103
diff changeset
   127
codeOn:aStream inBlock:b for:aCompiler
117
claus
parents: 104
diff changeset
   128
    (self checkIncDecOn:aStream) ifTrue:[
219
6b977f472cda care for block-stores into outer contexts
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   129
        expression receiver codeOn:aStream inBlock:b for:aCompiler.
6b977f472cda care for block-stores into outer contexts
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   130
        ^ self
117
claus
parents: 104
diff changeset
   131
    ].
219
6b977f472cda care for block-stores into outer contexts
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   132
6b977f472cda care for block-stores into outer contexts
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   133
    self codeNormalOn:aStream valueNeeded:true inBlock:b for:aCompiler
6b977f472cda care for block-stores into outer contexts
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   134
6b977f472cda care for block-stores into outer contexts
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   135
    "Modified: 1.3.1996 / 00:42:21 / cg"
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   136
! !
7ad01559b262 Initial revision
claus
parents:
diff changeset
   137
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   138
!AssignmentNode methodsFor:'evaluating'!
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   139
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   140
evaluate
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   141
    |value|
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   142
    value := expression evaluate.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   143
    variable store:value.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   144
    ^ value
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   145
! !
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   146
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   147
!AssignmentNode methodsFor:'printing'!
7ad01559b262 Initial revision
claus
parents:
diff changeset
   148
7ad01559b262 Initial revision
claus
parents:
diff changeset
   149
printOn:aStream indent:i
7ad01559b262 Initial revision
claus
parents:
diff changeset
   150
    variable printOn:aStream.
7ad01559b262 Initial revision
claus
parents:
diff changeset
   151
    aStream nextPutAll:' := '.
7ad01559b262 Initial revision
claus
parents:
diff changeset
   152
    expression printOn:aStream
7ad01559b262 Initial revision
claus
parents:
diff changeset
   153
! !
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   154
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   155
!AssignmentNode methodsFor:'queries'!
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   156
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   157
isAssignment
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   158
    "return true, if this is a node for an assignment"
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   159
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   160
    ^ true
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   161
! !
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   162
148
ef0e604209ec version method at the end
Claus Gittinger <cg@exept.de>
parents: 140
diff changeset
   163
!AssignmentNode class methodsFor:'documentation'!
ef0e604209ec version method at the end
Claus Gittinger <cg@exept.de>
parents: 140
diff changeset
   164
ef0e604209ec version method at the end
Claus Gittinger <cg@exept.de>
parents: 140
diff changeset
   165
version
263
3b21d0991eff documentation
Claus Gittinger <cg@exept.de>
parents: 261
diff changeset
   166
    ^ '$Header: /cvs/stx/stx/libcomp/AssignmentNode.st,v 1.19 1996-04-25 17:08:51 cg Exp $'
148
ef0e604209ec version method at the end
Claus Gittinger <cg@exept.de>
parents: 140
diff changeset
   167
! !