MessageNode.st
author Claus Gittinger <cg@exept.de>
Mon, 26 Aug 2013 15:44:37 +0200
changeset 3290 ed93979b62ac
parent 3278 73ef6a07d279
child 3310 f22eebdb8868
permissions -rw-r--r--
class: MessageNode class definition added: #selectorPartPositions #selectorPartPositions: changed: #receiver:selector:args:lineno:
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
1727
58820b0c1e7a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1724
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
"
1045
ee448a958d19 migration support
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
    12
"{ Package: 'stx:libcomp' }"
ee448a958d19 migration support
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
    13
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
    14
ParseNode subclass:#MessageNode
2496
4d67e1d9423b Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2489
diff changeset
    15
	instanceVariableNames:'receiver selector argArray lineNr selectorPosition lines
3290
ed93979b62ac class: MessageNode
Claus Gittinger <cg@exept.de>
parents: 3278
diff changeset
    16
		endLineNr endCharPosition selectorPartPositions'
1791
cd786d318d6f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1727
diff changeset
    17
	classVariableNames:''
cd786d318d6f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1727
diff changeset
    18
	poolDictionaries:''
cd786d318d6f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1727
diff changeset
    19
	category:'System-Compiler-Support'
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
    20
!
7ad01559b262 Initial revision
claus
parents:
diff changeset
    21
370
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
    22
!MessageNode class methodsFor:'documentation'!
20
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
    23
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
    24
copyright
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
    25
"
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
    26
 COPYRIGHT (c) 1989 by Claus Gittinger
1727
58820b0c1e7a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1724
diff changeset
    27
              All Rights Reserved
20
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
    28
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
    29
 This software is furnished under a license and may be used
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
    30
 only in accordance with the terms of that license and with the
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
    31
 inclusion of the above copyright notice.   This software may not
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
    32
 be provided or otherwise made available to, or used by, any
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
    33
 other person.  No title to or ownership of the software is
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
    34
 hereby transferred.
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
    35
"
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
    36
!
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
    37
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
    38
documentation
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
    39
"
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
    40
    node for parse-trees, representing message sends
261
0372e948ca2d commentary
Claus Gittinger <cg@exept.de>
parents: 253
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:]
1727
58820b0c1e7a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1724
diff changeset
    44
        Claus Gittinger
20
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
    45
"
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
    46
! !
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
    47
370
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
    48
!MessageNode class methodsFor:'instance creation'!
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
    49
7ad01559b262 Initial revision
claus
parents:
diff changeset
    50
receiver:recNode selector:selectorString 
7ad01559b262 Initial revision
claus
parents:
diff changeset
    51
    ^ (self basicNew) receiver:recNode selector:selectorString args:nil lineno:0
7ad01559b262 Initial revision
claus
parents:
diff changeset
    52
!
7ad01559b262 Initial revision
claus
parents:
diff changeset
    53
1266
35e2c67fbdd9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
    54
receiver:recNode selector:selectorString arg1:arg1Node arg2:arg2Node
35e2c67fbdd9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
    55
    ^ self receiver:recNode selector:selectorString arg1:arg1Node arg2:arg2Node fold:nil
35e2c67fbdd9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
    56
!
35e2c67fbdd9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1248
diff changeset
    57
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
    58
receiver:recNode selector:selectorString arg1:argNode1 arg2:argNode2 fold:folding
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
    59
    |result recVal argVal selector|
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
    60
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
    61
    "
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
    62
     This is just a demonstration - of how complex constants can be folded.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
    63
     This was inspired by some discussion in c.l.s about enhancing the language - I prefer
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
    64
     enhancing the compiler ....
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
    65
     The following optimization will convert '#(...) with:#(...) collect:[...]' into an array constant,
212
ff39051e219f more constant folding options
Claus Gittinger <cg@exept.de>
parents: 204
diff changeset
    66
     allowing constant arrays of complex objects.
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
    67
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
    68
     Notice: this method is normally disabled - its just a demo after all.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
    69
    "
212
ff39051e219f more constant folding options
Claus Gittinger <cg@exept.de>
parents: 204
diff changeset
    70
    folding notNil ifTrue:[
1397
969f505b6111 #errorSignal -> #description
Stefan Vogel <sv@exept.de>
parents: 1389
diff changeset
    71
        "/
969f505b6111 #errorSignal -> #description
Stefan Vogel <sv@exept.de>
parents: 1389
diff changeset
    72
        "/ do constant folding ...
969f505b6111 #errorSignal -> #description
Stefan Vogel <sv@exept.de>
parents: 1389
diff changeset
    73
        "/
969f505b6111 #errorSignal -> #description
Stefan Vogel <sv@exept.de>
parents: 1389
diff changeset
    74
        (recNode isConstant and:[argNode1 isConstant]) ifTrue:[
969f505b6111 #errorSignal -> #description
Stefan Vogel <sv@exept.de>
parents: 1389
diff changeset
    75
            "check if we can do it ..."
969f505b6111 #errorSignal -> #description
Stefan Vogel <sv@exept.de>
parents: 1389
diff changeset
    76
            selector := selectorString asSymbolIfInterned.
969f505b6111 #errorSignal -> #description
Stefan Vogel <sv@exept.de>
parents: 1389
diff changeset
    77
            selector notNil ifTrue:[
969f505b6111 #errorSignal -> #description
Stefan Vogel <sv@exept.de>
parents: 1389
diff changeset
    78
                recVal := recNode evaluate.
969f505b6111 #errorSignal -> #description
Stefan Vogel <sv@exept.de>
parents: 1389
diff changeset
    79
                (recVal respondsTo:selector) ifTrue:[
969f505b6111 #errorSignal -> #description
Stefan Vogel <sv@exept.de>
parents: 1389
diff changeset
    80
                    "
969f505b6111 #errorSignal -> #description
Stefan Vogel <sv@exept.de>
parents: 1389
diff changeset
    81
                     we could do much more here - but then, we need a dependency from
969f505b6111 #errorSignal -> #description
Stefan Vogel <sv@exept.de>
parents: 1389
diff changeset
    82
                     the folded selectors method to the method we generate code for ...
969f505b6111 #errorSignal -> #description
Stefan Vogel <sv@exept.de>
parents: 1389
diff changeset
    83
                     limit optimizations to those that will never change
969f505b6111 #errorSignal -> #description
Stefan Vogel <sv@exept.de>
parents: 1389
diff changeset
    84
                     (or - if you change them - you will crash so bad ...)
969f505b6111 #errorSignal -> #description
Stefan Vogel <sv@exept.de>
parents: 1389
diff changeset
    85
                    "
969f505b6111 #errorSignal -> #description
Stefan Vogel <sv@exept.de>
parents: 1389
diff changeset
    86
                    argVal := argNode1 evaluate.
969f505b6111 #errorSignal -> #description
Stefan Vogel <sv@exept.de>
parents: 1389
diff changeset
    87
                    ((recVal isMemberOf:Array) and:[argVal isMemberOf:Array]) ifTrue:[
969f505b6111 #errorSignal -> #description
Stefan Vogel <sv@exept.de>
parents: 1389
diff changeset
    88
                        folding == #full ifTrue:[
969f505b6111 #errorSignal -> #description
Stefan Vogel <sv@exept.de>
parents: 1389
diff changeset
    89
                            (selector == #with:collect:) ifTrue:[
969f505b6111 #errorSignal -> #description
Stefan Vogel <sv@exept.de>
parents: 1389
diff changeset
    90
                                (argNode2 isBlock) ifTrue:[
969f505b6111 #errorSignal -> #description
Stefan Vogel <sv@exept.de>
parents: 1389
diff changeset
    91
                                    SignalSet anySignal handle:[:ex |
1533
bff4a03d6d48 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1529
diff changeset
    92
                                        ^ ParseErrorNode errorString:'error in constant expression (' , ex description , ')'
1397
969f505b6111 #errorSignal -> #description
Stefan Vogel <sv@exept.de>
parents: 1389
diff changeset
    93
                                    ] do:[
969f505b6111 #errorSignal -> #description
Stefan Vogel <sv@exept.de>
parents: 1389
diff changeset
    94
                                        result := recVal perform:selector with:argVal with:(argNode2 evaluate).
969f505b6111 #errorSignal -> #description
Stefan Vogel <sv@exept.de>
parents: 1389
diff changeset
    95
                                    ].
969f505b6111 #errorSignal -> #description
Stefan Vogel <sv@exept.de>
parents: 1389
diff changeset
    96
                                    ^ ConstantNode type:(ConstantNode typeOfConstant:result) value:result
969f505b6111 #errorSignal -> #description
Stefan Vogel <sv@exept.de>
parents: 1389
diff changeset
    97
                                ]
969f505b6111 #errorSignal -> #description
Stefan Vogel <sv@exept.de>
parents: 1389
diff changeset
    98
                            ]
969f505b6111 #errorSignal -> #description
Stefan Vogel <sv@exept.de>
parents: 1389
diff changeset
    99
                        ]
969f505b6111 #errorSignal -> #description
Stefan Vogel <sv@exept.de>
parents: 1389
diff changeset
   100
                    ]
969f505b6111 #errorSignal -> #description
Stefan Vogel <sv@exept.de>
parents: 1389
diff changeset
   101
                ]
969f505b6111 #errorSignal -> #description
Stefan Vogel <sv@exept.de>
parents: 1389
diff changeset
   102
            ]
969f505b6111 #errorSignal -> #description
Stefan Vogel <sv@exept.de>
parents: 1389
diff changeset
   103
        ]
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   104
    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   105
    ^ (self basicNew) receiver:recNode selector:selectorString args:(Array with:argNode1 with:argNode2) lineno:0
570
e55ab798d077 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 567
diff changeset
   106
e55ab798d077 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 567
diff changeset
   107
    "Modified: 28.6.1997 / 15:16:01 / cg"
140
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
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   110
receiver:recNode selector:selectorString arg:argNode
212
ff39051e219f more constant folding options
Claus Gittinger <cg@exept.de>
parents: 204
diff changeset
   111
    ^ self receiver:recNode selector:selectorString arg:argNode fold:nil
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   112
!
7ad01559b262 Initial revision
claus
parents:
diff changeset
   113
7ad01559b262 Initial revision
claus
parents:
diff changeset
   114
receiver:recNode selector:selectorString arg:argNode fold:folding
212
ff39051e219f more constant folding options
Claus Gittinger <cg@exept.de>
parents: 204
diff changeset
   115
    |result recVal argVal selector globalName canFold|
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   116
20
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
   117
   "
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
   118
     The constant folding code can usually not optimize much
639
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
   119
     - this may change when some kind of constant/macro declaration is added to smalltalk,
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
   120
     so that constant classVars can be inlined.
20
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
   121
    "
212
ff39051e219f more constant folding options
Claus Gittinger <cg@exept.de>
parents: 204
diff changeset
   122
    folding notNil ifTrue:[
992
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
   123
        selector := selectorString asSymbolIfInterned.
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
   124
        selector notNil ifTrue:[
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
   125
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
   126
            "/
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
   127
            "/ do constant folding ...
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
   128
            "/
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
   129
            canFold := false.
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
   130
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
   131
            (recNode isGlobal and:[argNode isConstant]) ifTrue:[
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
   132
                globalName := recNode name.
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
   133
                recVal := recNode evaluate.
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
   134
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
   135
                (globalName = 'SmallInteger') ifTrue:[
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
   136
                    ( #( bitMaskFor: ) includes:selector)
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
   137
                    ifTrue:[
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
   138
                        canFold := true
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
   139
                    ]
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
   140
                ].
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
   141
            ].
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
   142
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
   143
            (recNode isConstant and:[argNode isConstant]) ifTrue:[
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
   144
                "check if we can do it ..."
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
   145
                recVal := recNode evaluate.
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
   146
                "
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
   147
                 we could do much more here - but then, we need a dependency from
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
   148
                 the folded selectors method to the method we generate code for ...
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
   149
                 limit optimizations to those that will never change
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
   150
                 (or - if you change them - you will crash so bad ...)
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
   151
                "
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
   152
                argVal := argNode evaluate.
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
   153
                (recVal respondsToArithmetic and:[argVal respondsToArithmetic]) ifTrue:[
2197
c92fee01c220 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2102
diff changeset
   154
                    ( #( + - * / // \\ min: max: quo: raisedTo:) includes:selector) ifTrue:[
992
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
   155
                        (#( / // \\ ) includes:selector) ifTrue:[
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
   156
                            argVal = 0 ifTrue:[
1533
bff4a03d6d48 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1529
diff changeset
   157
                                ^ ParseErrorNode errorString:'division by zero in constant expression'
992
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
   158
                            ].
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
   159
                        ].
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
   160
                        canFold := true
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
   161
                    ].
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
   162
                    ( #( @ ) includes:selector) ifTrue:[
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
   163
                        canFold := (folding == #full)
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
   164
                    ]
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
   165
                ].
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
   166
                (recVal isInteger and:[argVal isInteger]) ifTrue:[
1017
c923ff9f397e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 993
diff changeset
   167
                    ( #( bitShift: bitOr: bitAnd: ) includes:selector) ifTrue:[
992
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
   168
                        canFold := true
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
   169
                    ]
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
   170
                ].
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
   171
                (recVal isMemberOf:String) ifTrue:[
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
   172
                    (argVal isInteger and:[selector == #at:]) ifTrue:[
993
902eec8d132b oops - folding argument is not always a symbol.
Claus Gittinger <cg@exept.de>
parents: 992
diff changeset
   173
                        canFold := folding isSymbol
902eec8d132b oops - folding argument is not always a symbol.
Claus Gittinger <cg@exept.de>
parents: 992
diff changeset
   174
                                   and:[(folding >= #level2) or:[folding == #full]].
992
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
   175
                    ].
1093
41e224d479b5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1080
diff changeset
   176
                    selector == #',' ifTrue:[
41e224d479b5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1080
diff changeset
   177
                        (argVal isMemberOf:String) ifTrue:[
41e224d479b5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1080
diff changeset
   178
                            canFold := folding isSymbol
41e224d479b5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1080
diff changeset
   179
                                       and:[(folding >= #level2) or:[folding == #full]].
41e224d479b5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1080
diff changeset
   180
                        ].
41e224d479b5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1080
diff changeset
   181
                        (argVal isMemberOf:Character) ifTrue:[
41e224d479b5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1080
diff changeset
   182
                            canFold := folding isSymbol
41e224d479b5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1080
diff changeset
   183
                                       and:[(folding >= #level2) or:[folding == #full]].
41e224d479b5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1080
diff changeset
   184
                        ].
992
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
   185
                    ]
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
   186
                ].
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
   187
            ].
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
   188
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
   189
            canFold ifTrue:[
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
   190
                (recVal respondsTo:selector) ifTrue:[
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
   191
                    SignalSet anySignal handle:[:ex |
1533
bff4a03d6d48 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1529
diff changeset
   192
                        ^ ParseErrorNode errorString:'error in constant expression (' , ex description , ')'
992
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
   193
                    ] do:[
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
   194
                        result := recVal perform:selector with:argVal.
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
   195
                    ].
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
   196
                    ^ ConstantNode type:(ConstantNode typeOfConstant:result) value:result
2617
160ca364f3d3 More fixes for start/end position
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2610
diff changeset
   197
                                   from: recNode startPosition to: argNode endPosition
992
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
   198
                ]
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
   199
            ]
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
   200
        ].
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
   201
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
   202
        "/
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
   203
        "/ #perform with a constant selector
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
   204
        "/
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
   205
        (selector == #perform: 
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
   206
        and:[argNode isConstant]) ifTrue:[
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
   207
            argVal := argNode evaluate.
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
   208
            argVal isSymbol ifTrue:[
2620
25babff22da4 start/end position fixes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2617
diff changeset
   209
                ^ (UnaryNode receiver:recNode selector:argVal fold:folding)
25babff22da4 start/end position fixes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2617
diff changeset
   210
                    startPosition: recNode startPosition endPosition: argNode endPosition.
25babff22da4 start/end position fixes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2617
diff changeset
   211
992
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
   212
            ]
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
   213
        ].
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   214
    ].
212
ff39051e219f more constant folding options
Claus Gittinger <cg@exept.de>
parents: 204
diff changeset
   215
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   216
    ^ (self basicNew) receiver:recNode selector:selectorString args:(Array with:argNode) lineno:0
576
5cb4af0eea67 also inline and:/or: ...
Claus Gittinger <cg@exept.de>
parents: 574
diff changeset
   217
2617
160ca364f3d3 More fixes for start/end position
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2610
diff changeset
   218
    "Modified: / 16-11-1999 / 21:50:33 / cg"
2620
25babff22da4 start/end position fixes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2617
diff changeset
   219
    "Modified: / 01-08-2011 / 12:31:59 / Jan Vrany <jan.vrany@fit.cvut.cz>"
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   220
!
7ad01559b262 Initial revision
claus
parents:
diff changeset
   221
7ad01559b262 Initial revision
claus
parents:
diff changeset
   222
receiver:recNode selector:selectorString args:anArray
212
ff39051e219f more constant folding options
Claus Gittinger <cg@exept.de>
parents: 204
diff changeset
   223
    ^ self receiver:recNode selector:selectorString args:anArray fold:nil
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   224
!
7ad01559b262 Initial revision
claus
parents:
diff changeset
   225
7ad01559b262 Initial revision
claus
parents:
diff changeset
   226
receiver:recNode selector:selectorString args:argArray fold:folding
639
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
   227
    |numArgs arg1 arg1Val|
117
claus
parents: 111
diff changeset
   228
212
ff39051e219f more constant folding options
Claus Gittinger <cg@exept.de>
parents: 204
diff changeset
   229
    folding notNil ifTrue:[
715
408ac886ffc1 allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents: 676
diff changeset
   230
        numArgs := argArray size.
408ac886ffc1 allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents: 676
diff changeset
   231
        numArgs > 0 ifTrue:[
408ac886ffc1 allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents: 676
diff changeset
   232
            arg1 := (argArray at:1).
408ac886ffc1 allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents: 676
diff changeset
   233
            (numArgs == 1) ifTrue:[
408ac886ffc1 allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents: 676
diff changeset
   234
                ^ self receiver:recNode selector:selectorString arg:arg1 fold:folding 
408ac886ffc1 allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents: 676
diff changeset
   235
            ].
20
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
   236
715
408ac886ffc1 allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents: 676
diff changeset
   237
            "/
408ac886ffc1 allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents: 676
diff changeset
   238
            "/ #perform:... with a constant selector
408ac886ffc1 allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents: 676
diff changeset
   239
            "/
408ac886ffc1 allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents: 676
diff changeset
   240
            numArgs <= 6 ifTrue:[
408ac886ffc1 allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents: 676
diff changeset
   241
                (#(nil
408ac886ffc1 allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents: 676
diff changeset
   242
                   #'perform:with:'
408ac886ffc1 allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents: 676
diff changeset
   243
                   #'perform:with:with:'
408ac886ffc1 allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents: 676
diff changeset
   244
                   #'perform:with:with:with:'
408ac886ffc1 allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents: 676
diff changeset
   245
                   #'perform:with:with:with:with:'
408ac886ffc1 allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents: 676
diff changeset
   246
                   #'perform:with:with:with:with:with:'
408ac886ffc1 allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents: 676
diff changeset
   247
                   #'perform:with:with:with:with:with:with:'
408ac886ffc1 allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents: 676
diff changeset
   248
                ) at:numArgs) = selectorString 
408ac886ffc1 allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents: 676
diff changeset
   249
                ifTrue:[
408ac886ffc1 allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents: 676
diff changeset
   250
                    arg1 isConstant ifTrue:[    
408ac886ffc1 allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents: 676
diff changeset
   251
                        arg1Val := arg1 evaluate.
408ac886ffc1 allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents: 676
diff changeset
   252
                        arg1Val isSymbol ifTrue:[
408ac886ffc1 allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents: 676
diff changeset
   253
                            ^ MessageNode 
408ac886ffc1 allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents: 676
diff changeset
   254
                                    receiver:recNode 
408ac886ffc1 allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents: 676
diff changeset
   255
                                    selector:arg1Val
408ac886ffc1 allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents: 676
diff changeset
   256
                                    args:(argArray copyFrom:2)
408ac886ffc1 allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents: 676
diff changeset
   257
                                    fold:folding
408ac886ffc1 allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents: 676
diff changeset
   258
                        ]
408ac886ffc1 allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents: 676
diff changeset
   259
                    ]
408ac886ffc1 allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents: 676
diff changeset
   260
                ]
408ac886ffc1 allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents: 676
diff changeset
   261
            ].
408ac886ffc1 allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents: 676
diff changeset
   262
        ].
639
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
   263
715
408ac886ffc1 allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents: 676
diff changeset
   264
        (numArgs == 2) ifTrue:[
408ac886ffc1 allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents: 676
diff changeset
   265
            ^ self receiver:recNode selector:selectorString arg1:arg1 arg2:(argArray at:2) fold:folding 
408ac886ffc1 allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents: 676
diff changeset
   266
        ].
408ac886ffc1 allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents: 676
diff changeset
   267
        numArgs > Method maxNumberOfArguments ifTrue:[
1533
bff4a03d6d48 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1529
diff changeset
   268
            ^ ParseErrorNode errorString:'too many arguments for current VM implementation'.
715
408ac886ffc1 allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents: 676
diff changeset
   269
        ].
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   270
    ].
117
claus
parents: 111
diff changeset
   271
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   272
    ^ (self basicNew) receiver:recNode selector:selectorString args:argArray lineno:0
117
claus
parents: 111
diff changeset
   273
639
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
   274
    "Modified: / 3.9.1995 / 16:41:39 / claus"
715
408ac886ffc1 allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents: 676
diff changeset
   275
    "Modified: / 15.5.1998 / 15:32:05 / cg"
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   276
! !
7ad01559b262 Initial revision
claus
parents:
diff changeset
   277
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   278
!MessageNode methodsFor:'accessing'!
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   279
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   280
arg1
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   281
    ^ argArray at:1
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   282
!
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   283
1639
65686abde429 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1629
diff changeset
   284
arg2
65686abde429 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1629
diff changeset
   285
    ^ argArray at:2
65686abde429 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1629
diff changeset
   286
!
65686abde429 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1629
diff changeset
   287
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   288
args
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   289
    ^ argArray
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   290
!
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   291
543
de47f8969fd9 more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
   292
arguments
de47f8969fd9 more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
   293
    ^ argArray ? #()
de47f8969fd9 more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
   294
de47f8969fd9 more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
   295
    "Created: 19.6.1997 / 17:31:14 / cg"
de47f8969fd9 more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
   296
    "Modified: 19.6.1997 / 17:32:25 / cg"
de47f8969fd9 more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
   297
!
de47f8969fd9 more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
   298
2496
4d67e1d9423b Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2489
diff changeset
   299
endCharPosition
4d67e1d9423b Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2489
diff changeset
   300
    ^ endCharPosition
4d67e1d9423b Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2489
diff changeset
   301
!
4d67e1d9423b Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2489
diff changeset
   302
4d67e1d9423b Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2489
diff changeset
   303
endCharPosition:something
4d67e1d9423b Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2489
diff changeset
   304
    endCharPosition := something.
4d67e1d9423b Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2489
diff changeset
   305
!
4d67e1d9423b Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2489
diff changeset
   306
4d67e1d9423b Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2489
diff changeset
   307
endLineNr
4d67e1d9423b Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2489
diff changeset
   308
    ^ endLineNr
4d67e1d9423b Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2489
diff changeset
   309
!
4d67e1d9423b Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2489
diff changeset
   310
4d67e1d9423b Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2489
diff changeset
   311
endLineNr:something
4d67e1d9423b Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2489
diff changeset
   312
    endLineNr := something.
4d67e1d9423b Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2489
diff changeset
   313
!
4d67e1d9423b Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2489
diff changeset
   314
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   315
lineNumber
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   316
     ^ lineNr
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   317
!
7ad01559b262 Initial revision
claus
parents:
diff changeset
   318
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   319
lineNumber:num
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   320
     lineNr := num
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   321
!
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   322
2496
4d67e1d9423b Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2489
diff changeset
   323
lines
4d67e1d9423b Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2489
diff changeset
   324
    ^ lines
4d67e1d9423b Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2489
diff changeset
   325
!
4d67e1d9423b Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2489
diff changeset
   326
4d67e1d9423b Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2489
diff changeset
   327
lines:something
4d67e1d9423b Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2489
diff changeset
   328
    lines := something.
4d67e1d9423b Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2489
diff changeset
   329
!
4d67e1d9423b Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2489
diff changeset
   330
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   331
receiver
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   332
    ^ receiver
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   333
!
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   334
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   335
receiver:r selector:s args:a lineno:l
2601
0bee48798eac - added acceptVisior:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2562
diff changeset
   336
3290
ed93979b62ac class: MessageNode
Claus Gittinger <cg@exept.de>
parents: 3278
diff changeset
   337
    receiver notNil ifTrue:[ receiver parent: nil].
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   338
    receiver := r.
3290
ed93979b62ac class: MessageNode
Claus Gittinger <cg@exept.de>
parents: 3278
diff changeset
   339
    receiver notNil ifTrue:[
ed93979b62ac class: MessageNode
Claus Gittinger <cg@exept.de>
parents: 3278
diff changeset
   340
        receiver parent notNil ifTrue:[self breakPoint:#cg].
ed93979b62ac class: MessageNode
Claus Gittinger <cg@exept.de>
parents: 3278
diff changeset
   341
        receiver parent: self
ed93979b62ac class: MessageNode
Claus Gittinger <cg@exept.de>
parents: 3278
diff changeset
   342
    ].
1500
3c4cb012b24b Lazy conversion of selector strings to symbols.
Stefan Vogel <sv@exept.de>
parents: 1480
diff changeset
   343
2610
398820190422 More fixes to keep node position in the source. Not yet fully implemented
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2601
diff changeset
   344
    startPosition := receiver startPosition.
398820190422 More fixes to keep node position in the source. Not yet fully implemented
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2601
diff changeset
   345
1500
3c4cb012b24b Lazy conversion of selector strings to symbols.
Stefan Vogel <sv@exept.de>
parents: 1480
diff changeset
   346
"/ create the symbol only, if the symbol is already known in the system.
3c4cb012b24b Lazy conversion of selector strings to symbols.
Stefan Vogel <sv@exept.de>
parents: 1480
diff changeset
   347
"/ otherwise a lot of partial symbols will be created by the SyntaxHighlighter
3c4cb012b24b Lazy conversion of selector strings to symbols.
Stefan Vogel <sv@exept.de>
parents: 1480
diff changeset
   348
"/ during typing
3c4cb012b24b Lazy conversion of selector strings to symbols.
Stefan Vogel <sv@exept.de>
parents: 1480
diff changeset
   349
"/    selector := s asSymbol.
3c4cb012b24b Lazy conversion of selector strings to symbols.
Stefan Vogel <sv@exept.de>
parents: 1480
diff changeset
   350
3c4cb012b24b Lazy conversion of selector strings to symbols.
Stefan Vogel <sv@exept.de>
parents: 1480
diff changeset
   351
    selector := s asSymbolIfInterned ? s.
3c4cb012b24b Lazy conversion of selector strings to symbols.
Stefan Vogel <sv@exept.de>
parents: 1480
diff changeset
   352
2601
0bee48798eac - added acceptVisior:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2562
diff changeset
   353
    argArray isNil ifFalse:[argArray do:[:each|each parent: nil]].
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   354
    argArray := a.
2865
cc62390767a2 changed: #receiver:selector:args:lineno:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2849
diff changeset
   355
    "JV@2012-04-20: I hate this #Error being returned. We should not
cc62390767a2 changed: #receiver:selector:args:lineno:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2849
diff changeset
   356
     be lazy to create a new class - ErrorNode. Results in a mess!!"
cc62390767a2 changed: #receiver:selector:args:lineno:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2849
diff changeset
   357
    argArray ~~ #Error ifTrue:[
cc62390767a2 changed: #receiver:selector:args:lineno:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2849
diff changeset
   358
        argArray isNil ifFalse:[argArray do:[:each|each parent: self]].
2869
819a9e78f728 changed: #receiver:selector:args:lineno:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2865
diff changeset
   359
        argArray notEmptyOrNil ifTrue:[
819a9e78f728 changed: #receiver:selector:args:lineno:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2865
diff changeset
   360
            endPosition := argArray last endPosition
819a9e78f728 changed: #receiver:selector:args:lineno:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2865
diff changeset
   361
        ]
2610
398820190422 More fixes to keep node position in the source. Not yet fully implemented
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2601
diff changeset
   362
    ].
398820190422 More fixes to keep node position in the source. Not yet fully implemented
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2601
diff changeset
   363
574
993d1182782b fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents: 570
diff changeset
   364
    lineNr := l.
993d1182782b fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents: 570
diff changeset
   365
    self checkInlinability.
993d1182782b fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents: 570
diff changeset
   366
2601
0bee48798eac - added acceptVisior:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2562
diff changeset
   367
    "Modified: / 02-07-1997 / 17:01:24 / cg"
2869
819a9e78f728 changed: #receiver:selector:args:lineno:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2865
diff changeset
   368
    "Modified: / 08-05-2012 / 17:07:27 / Jan Vrany <jan.vrany@fit.cvut.cz>"
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   369
!
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   370
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   371
selector
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   372
    ^ selector
595
a90e8d8bf417 remember position of selector
Claus Gittinger <cg@exept.de>
parents: 578
diff changeset
   373
!
a90e8d8bf417 remember position of selector
Claus Gittinger <cg@exept.de>
parents: 578
diff changeset
   374
1384
0db9682870d9 evaluate -> evaluateIn:
Claus Gittinger <cg@exept.de>
parents: 1382
diff changeset
   375
selector:s
1500
3c4cb012b24b Lazy conversion of selector strings to symbols.
Stefan Vogel <sv@exept.de>
parents: 1480
diff changeset
   376
"/ create the symbol only, if the symbol is already known in the system.
3c4cb012b24b Lazy conversion of selector strings to symbols.
Stefan Vogel <sv@exept.de>
parents: 1480
diff changeset
   377
"/ otherwise a lot of partial symbols will be created by the SyntaxHighlighter
3c4cb012b24b Lazy conversion of selector strings to symbols.
Stefan Vogel <sv@exept.de>
parents: 1480
diff changeset
   378
"/ during typing
3c4cb012b24b Lazy conversion of selector strings to symbols.
Stefan Vogel <sv@exept.de>
parents: 1480
diff changeset
   379
"/    selector := s asSymbol.
3c4cb012b24b Lazy conversion of selector strings to symbols.
Stefan Vogel <sv@exept.de>
parents: 1480
diff changeset
   380
3c4cb012b24b Lazy conversion of selector strings to symbols.
Stefan Vogel <sv@exept.de>
parents: 1480
diff changeset
   381
    selector := s asSymbolIfInterned ? s.
3c4cb012b24b Lazy conversion of selector strings to symbols.
Stefan Vogel <sv@exept.de>
parents: 1480
diff changeset
   382
"/    selector := s asSymbol.
1384
0db9682870d9 evaluate -> evaluateIn:
Claus Gittinger <cg@exept.de>
parents: 1382
diff changeset
   383
!
0db9682870d9 evaluate -> evaluateIn:
Claus Gittinger <cg@exept.de>
parents: 1382
diff changeset
   384
3290
ed93979b62ac class: MessageNode
Claus Gittinger <cg@exept.de>
parents: 3278
diff changeset
   385
selectorPartPositions
ed93979b62ac class: MessageNode
Claus Gittinger <cg@exept.de>
parents: 3278
diff changeset
   386
    ^ selectorPartPositions
ed93979b62ac class: MessageNode
Claus Gittinger <cg@exept.de>
parents: 3278
diff changeset
   387
!
ed93979b62ac class: MessageNode
Claus Gittinger <cg@exept.de>
parents: 3278
diff changeset
   388
ed93979b62ac class: MessageNode
Claus Gittinger <cg@exept.de>
parents: 3278
diff changeset
   389
selectorPartPositions:something
ed93979b62ac class: MessageNode
Claus Gittinger <cg@exept.de>
parents: 3278
diff changeset
   390
    selectorPartPositions := something.
ed93979b62ac class: MessageNode
Claus Gittinger <cg@exept.de>
parents: 3278
diff changeset
   391
!
ed93979b62ac class: MessageNode
Claus Gittinger <cg@exept.de>
parents: 3278
diff changeset
   392
595
a90e8d8bf417 remember position of selector
Claus Gittinger <cg@exept.de>
parents: 578
diff changeset
   393
selectorPosition
a90e8d8bf417 remember position of selector
Claus Gittinger <cg@exept.de>
parents: 578
diff changeset
   394
    "return the value of the instance variable 'selectorPosition' (automatically generated)"
a90e8d8bf417 remember position of selector
Claus Gittinger <cg@exept.de>
parents: 578
diff changeset
   395
a90e8d8bf417 remember position of selector
Claus Gittinger <cg@exept.de>
parents: 578
diff changeset
   396
    ^ selectorPosition
a90e8d8bf417 remember position of selector
Claus Gittinger <cg@exept.de>
parents: 578
diff changeset
   397
a90e8d8bf417 remember position of selector
Claus Gittinger <cg@exept.de>
parents: 578
diff changeset
   398
    "Created: 5.8.1997 / 02:49:27 / cg"
a90e8d8bf417 remember position of selector
Claus Gittinger <cg@exept.de>
parents: 578
diff changeset
   399
!
a90e8d8bf417 remember position of selector
Claus Gittinger <cg@exept.de>
parents: 578
diff changeset
   400
a90e8d8bf417 remember position of selector
Claus Gittinger <cg@exept.de>
parents: 578
diff changeset
   401
selectorPosition:something
a90e8d8bf417 remember position of selector
Claus Gittinger <cg@exept.de>
parents: 578
diff changeset
   402
    "set the value of the instance variable 'selectorPosition' (automatically generated)"
a90e8d8bf417 remember position of selector
Claus Gittinger <cg@exept.de>
parents: 578
diff changeset
   403
a90e8d8bf417 remember position of selector
Claus Gittinger <cg@exept.de>
parents: 578
diff changeset
   404
    selectorPosition := something.
a90e8d8bf417 remember position of selector
Claus Gittinger <cg@exept.de>
parents: 578
diff changeset
   405
a90e8d8bf417 remember position of selector
Claus Gittinger <cg@exept.de>
parents: 578
diff changeset
   406
    "Created: 5.8.1997 / 02:49:27 / cg"
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   407
! !
7ad01559b262 Initial revision
claus
parents:
diff changeset
   408
7ad01559b262 Initial revision
claus
parents:
diff changeset
   409
!MessageNode methodsFor:'checks'!
7ad01559b262 Initial revision
claus
parents:
diff changeset
   410
1626
6addd73f7d47 precedence check for if-condition
Claus Gittinger <cg@exept.de>
parents: 1588
diff changeset
   411
checkCondition
2489
da5775ff9f1f comment
Michael Beyl <mb@exept.de>
parents: 2429
diff changeset
   412
    "check ifTrue/ifFalse for plausibility"
da5775ff9f1f comment
Michael Beyl <mb@exept.de>
parents: 2429
diff changeset
   413
2102
0d60bf6818d7 obfuscated code detection
Claus Gittinger <cg@exept.de>
parents: 2096
diff changeset
   414
    |args lastArg receiverSelector or1 or2|
1626
6addd73f7d47 precedence check for if-condition
Claus Gittinger <cg@exept.de>
parents: 1588
diff changeset
   415
6addd73f7d47 precedence check for if-condition
Claus Gittinger <cg@exept.de>
parents: 1588
diff changeset
   416
    receiver isBlock ifTrue:[
6addd73f7d47 precedence check for if-condition
Claus Gittinger <cg@exept.de>
parents: 1588
diff changeset
   417
        (Block canUnderstand:selector) ifFalse:[
6addd73f7d47 precedence check for if-condition
Claus Gittinger <cg@exept.de>
parents: 1588
diff changeset
   418
            ^ 'blocks usually do not respond to ' , selector , ' messages'
6addd73f7d47 precedence check for if-condition
Claus Gittinger <cg@exept.de>
parents: 1588
diff changeset
   419
        ].
6addd73f7d47 precedence check for if-condition
Claus Gittinger <cg@exept.de>
parents: 1588
diff changeset
   420
    ].
6addd73f7d47 precedence check for if-condition
Claus Gittinger <cg@exept.de>
parents: 1588
diff changeset
   421
6addd73f7d47 precedence check for if-condition
Claus Gittinger <cg@exept.de>
parents: 1588
diff changeset
   422
    "/ (rr keyw:ra = a) ifTrue:[ ...]
6addd73f7d47 precedence check for if-condition
Claus Gittinger <cg@exept.de>
parents: 1588
diff changeset
   423
6addd73f7d47 precedence check for if-condition
Claus Gittinger <cg@exept.de>
parents: 1588
diff changeset
   424
    receiver isMessage ifTrue:[
6addd73f7d47 precedence check for if-condition
Claus Gittinger <cg@exept.de>
parents: 1588
diff changeset
   425
        (receiver numArgs > 0) ifTrue:[
2102
0d60bf6818d7 obfuscated code detection
Claus Gittinger <cg@exept.de>
parents: 2096
diff changeset
   426
            receiverSelector := receiver selector asSymbol.
0d60bf6818d7 obfuscated code detection
Claus Gittinger <cg@exept.de>
parents: 2096
diff changeset
   427
            (receiverSelector isKeyword) ifTrue:[
1626
6addd73f7d47 precedence check for if-condition
Claus Gittinger <cg@exept.de>
parents: 1588
diff changeset
   428
                (args := receiver arguments) notEmptyOrNil ifTrue:[
6addd73f7d47 precedence check for if-condition
Claus Gittinger <cg@exept.de>
parents: 1588
diff changeset
   429
                    (lastArg := args last) isMessage ifTrue:[
1989
e6a763ac2587 oops - parenthesized was written with typo
Claus Gittinger <cg@exept.de>
parents: 1809
diff changeset
   430
                        lastArg parenthesized ifFalse:[
1626
6addd73f7d47 precedence check for if-condition
Claus Gittinger <cg@exept.de>
parents: 1588
diff changeset
   431
                            (#( #'=' #'~=' #'==' #'~~' '>' '<' '>=' '<=') 
1629
8f69fe5b0fea *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1628
diff changeset
   432
                            includes:(lastArg selector asSymbol)) ifTrue:[
1628
9641d61e717f precedence check for if-condition
Claus Gittinger <cg@exept.de>
parents: 1627
diff changeset
   433
                                ^ 'possible precedence error in condition (missing parenthesis ?)'
1626
6addd73f7d47 precedence check for if-condition
Claus Gittinger <cg@exept.de>
parents: 1588
diff changeset
   434
                            ]
6addd73f7d47 precedence check for if-condition
Claus Gittinger <cg@exept.de>
parents: 1588
diff changeset
   435
                        ]
2102
0d60bf6818d7 obfuscated code detection
Claus Gittinger <cg@exept.de>
parents: 2096
diff changeset
   436
                    ].
0d60bf6818d7 obfuscated code detection
Claus Gittinger <cg@exept.de>
parents: 2096
diff changeset
   437
                ].
0d60bf6818d7 obfuscated code detection
Claus Gittinger <cg@exept.de>
parents: 2096
diff changeset
   438
0d60bf6818d7 obfuscated code detection
Claus Gittinger <cg@exept.de>
parents: 2096
diff changeset
   439
                (selector == #ifFalse: or:[ selector == #ifFalse:ifTrue: ]) ifTrue:[
0d60bf6818d7 obfuscated code detection
Claus Gittinger <cg@exept.de>
parents: 2096
diff changeset
   440
                    receiverSelector == #or: ifTrue:[
0d60bf6818d7 obfuscated code detection
Claus Gittinger <cg@exept.de>
parents: 2096
diff changeset
   441
                        or1 := receiver receiver.    
0d60bf6818d7 obfuscated code detection
Claus Gittinger <cg@exept.de>
parents: 2096
diff changeset
   442
                        or2 := receiver arg1.
0d60bf6818d7 obfuscated code detection
Claus Gittinger <cg@exept.de>
parents: 2096
diff changeset
   443
                        (or1 isMessage and:[or1 selector = '~~']) ifTrue:[
0d60bf6818d7 obfuscated code detection
Claus Gittinger <cg@exept.de>
parents: 2096
diff changeset
   444
                            (or2 isBlock 
0d60bf6818d7 obfuscated code detection
Claus Gittinger <cg@exept.de>
parents: 2096
diff changeset
   445
                            and:[ or2 isSingleExpressionBlock
0d60bf6818d7 obfuscated code detection
Claus Gittinger <cg@exept.de>
parents: 2096
diff changeset
   446
                            and:[ or2 statements expression isMessage 
0d60bf6818d7 obfuscated code detection
Claus Gittinger <cg@exept.de>
parents: 2096
diff changeset
   447
                            and:[ or2 statements expression selector = '~~']]]) ifTrue:[
0d60bf6818d7 obfuscated code detection
Claus Gittinger <cg@exept.de>
parents: 2096
diff changeset
   448
                                ^ 'please use "((...==...) and:[...==...]) ifTrue:" here\\(are you obfuscating by purpose ?)'
0d60bf6818d7 obfuscated code detection
Claus Gittinger <cg@exept.de>
parents: 2096
diff changeset
   449
                            ].
0d60bf6818d7 obfuscated code detection
Claus Gittinger <cg@exept.de>
parents: 2096
diff changeset
   450
                        ].
0d60bf6818d7 obfuscated code detection
Claus Gittinger <cg@exept.de>
parents: 2096
diff changeset
   451
                    ].
0d60bf6818d7 obfuscated code detection
Claus Gittinger <cg@exept.de>
parents: 2096
diff changeset
   452
                ].
1626
6addd73f7d47 precedence check for if-condition
Claus Gittinger <cg@exept.de>
parents: 1588
diff changeset
   453
            ]
6addd73f7d47 precedence check for if-condition
Claus Gittinger <cg@exept.de>
parents: 1588
diff changeset
   454
        ].
6addd73f7d47 precedence check for if-condition
Claus Gittinger <cg@exept.de>
parents: 1588
diff changeset
   455
    ].
6addd73f7d47 precedence check for if-condition
Claus Gittinger <cg@exept.de>
parents: 1588
diff changeset
   456
6addd73f7d47 precedence check for if-condition
Claus Gittinger <cg@exept.de>
parents: 1588
diff changeset
   457
    ^ nil
6addd73f7d47 precedence check for if-condition
Claus Gittinger <cg@exept.de>
parents: 1588
diff changeset
   458
!
6addd73f7d47 precedence check for if-condition
Claus Gittinger <cg@exept.de>
parents: 1588
diff changeset
   459
2208
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   460
checkGlobalFromNameSpaceConflictFor:aNode
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   461
    "check if aNode is a local-nameSpace's variable,
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   462
     which hides a global from Smalltalk with the same name.
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   463
     This is especially bad for Error handle: do:... "
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   464
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   465
    |fullName shortName|
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   466
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   467
    aNode isGlobalVariable ifTrue:[
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   468
        fullName := aNode name.
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   469
        shortName := Class nameWithoutPrefix:fullName.
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   470
        shortName ~= fullName ifTrue:[
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   471
            (Smalltalk includesKey:shortName) ifTrue:[
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   472
                ^ 'Possible name conflict (local ',shortName,' vs. Smalltalk::',shortName,')'
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   473
            ].
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   474
        ].
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   475
    ].
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   476
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   477
    ^ nil.
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   478
!
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   479
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   480
checkIdentityCompare
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   481
    |rec arg1 arg1Value operand|
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   482
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   483
    "
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   484
     check #== applied to Floats, Strings or Fractions
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   485
    "
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   486
    ((selector == #==) or:[selector == #~~]) ifTrue:[
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   487
        (argArray size > 0) ifTrue:[
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   488
            arg1 := argArray at:1
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   489
        ].
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   490
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   491
        "
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   492
         it once took me almost an hour, to find a '==' which
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   493
         should have been an '=' (you cannot compare floats with ==)
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   494
         (well, I looked at the '==' at least 50 times -
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   495
          - but didn't think about it ...).
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   496
         that's reason enough to add this check here.
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   497
         I will add more as heuristic knowledge increases ...
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   498
         (send me comments on common programming errors...)
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   499
        "
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   500
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   501
        receiver isConstant ifTrue:[
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   502
            rec := receiver evaluate.
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   503
            ((rec isMemberOf:String) or:[
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   504
             (rec isMemberOf:Float) or:[
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   505
             (rec isMemberOf:Fraction)]]) ifTrue:[
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   506
                operand := rec
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   507
            ].
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   508
        ].
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   509
        arg1 isConstant ifTrue:[
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   510
            arg1Value := arg1 evaluate.
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   511
            ((arg1Value isMemberOf:String) or:[
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   512
             (arg1Value isMemberOf:Float) or:[
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   513
             (arg1Value isMemberOf:Fraction)]]) ifTrue:[
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   514
                operand := arg1Value
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   515
            ].
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   516
        ].
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   517
        operand notNil ifTrue:[
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   518
            (selector == #==) ifTrue:[
2849
fa7f159cbbb0 changed: #checkIdentityCompare
Claus Gittinger <cg@exept.de>
parents: 2620
diff changeset
   519
                ^ 'identity compare is unsafe here (will usually return false here. Consider changing to "=")'
2208
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   520
            ].
2849
fa7f159cbbb0 changed: #checkIdentityCompare
Claus Gittinger <cg@exept.de>
parents: 2620
diff changeset
   521
            ^ 'identity compare is unsafe here (will usually return true here. Consider changing to "~=")'
2208
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   522
        ]
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   523
    ].
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   524
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   525
    ^ nil
2849
fa7f159cbbb0 changed: #checkIdentityCompare
Claus Gittinger <cg@exept.de>
parents: 2620
diff changeset
   526
fa7f159cbbb0 changed: #checkIdentityCompare
Claus Gittinger <cg@exept.de>
parents: 2620
diff changeset
   527
    "Modified: / 08-03-2012 / 01:07:33 / cg"
2208
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   528
!
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   529
574
993d1182782b fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents: 570
diff changeset
   530
checkInlinability
993d1182782b fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents: 570
diff changeset
   531
    "early check for possible inlinability"
993d1182782b fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents: 570
diff changeset
   532
993d1182782b fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents: 570
diff changeset
   533
    |numArgs arg1 arg2 arg3|
993d1182782b fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents: 570
diff changeset
   534
993d1182782b fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents: 570
diff changeset
   535
    (numArgs := argArray size) >= 1 ifTrue:[
676
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   536
        arg1 := argArray at:1.
574
993d1182782b fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents: 570
diff changeset
   537
    ].
993d1182782b fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents: 570
diff changeset
   538
    numArgs == 0 ifTrue:[
676
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   539
        (selector == #whileTrue 
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   540
        or:[selector == #whileFalse]) ifTrue:[
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   541
            receiver isBlock ifTrue:[
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   542
                receiver possiblyInlined:true
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   543
            ].
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   544
        ].
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   545
        (selector == #value) ifTrue:[
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   546
            receiver isBlock ifTrue:[
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   547
                receiver possiblyInlined:true
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   548
            ].
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   549
        ].
1425
4f698bf5ff76 inline [...] loop
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
   550
        ((selector == #repeat) or:[selector == #loop]) ifTrue:[
676
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   551
            receiver isBlock ifTrue:[
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   552
                receiver possiblyInlined:true
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   553
            ].
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   554
        ].
574
993d1182782b fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents: 570
diff changeset
   555
    ].
993d1182782b fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents: 570
diff changeset
   556
993d1182782b fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents: 570
diff changeset
   557
    numArgs == 1 ifTrue:[
676
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   558
        (selector == #or: 
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   559
        or:[selector == #and:]) ifTrue:[
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   560
            arg1 isBlock ifTrue:[
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   561
                arg1 possiblyInlined:true
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   562
            ].
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   563
        ].
576
5cb4af0eea67 also inline and:/or: ...
Claus Gittinger <cg@exept.de>
parents: 574
diff changeset
   564
676
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   565
        (selector == #ifTrue: 
898
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
   566
        or:[selector == #ifFalse:
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
   567
        or:[selector == #ifNil:
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
   568
        or:[selector == #ifNotNil:]]]) ifTrue:[
676
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   569
            arg1 isBlock ifTrue:[
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   570
                arg1 possiblyInlined:true
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   571
            ].
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   572
        ].
574
993d1182782b fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents: 570
diff changeset
   573
676
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   574
        (selector == #whileTrue: 
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   575
        or:[selector == #whileFalse:]) ifTrue:[
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   576
            arg1 isBlock ifTrue:[
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   577
                arg1 possiblyInlined:true
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   578
            ].
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   579
            receiver isBlock ifTrue:[
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   580
                receiver possiblyInlined:true
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   581
            ].
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   582
        ].
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   583
        selector == #timesRepeat: ifTrue:[
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   584
            arg1 isBlock ifTrue:[
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   585
                arg1 possiblyInlined:true withSelector:selector.
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   586
            ]
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   587
        ].
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   588
        ^ self
574
993d1182782b fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents: 570
diff changeset
   589
    ].
993d1182782b fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents: 570
diff changeset
   590
    numArgs >= 2 ifTrue:[
676
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   591
        arg2 := argArray at:2.
574
993d1182782b fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents: 570
diff changeset
   592
    ].    
993d1182782b fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents: 570
diff changeset
   593
    numArgs == 2 ifTrue:[
676
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   594
        (selector == #ifTrue:ifFalse:
898
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
   595
        or:[selector == #ifFalse:ifTrue:
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
   596
        or:[selector == #ifNil:ifNotNil:
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
   597
        or:[selector == #ifNotNil:ifNil:]]]) ifTrue:[
676
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   598
            (arg1 isBlock 
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   599
            and:[arg2 isBlock]) ifTrue:[
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   600
                arg1 possiblyInlined:true.
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   601
                arg2 possiblyInlined:true.
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   602
            ].
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   603
        ].
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   604
        selector == #to:do: ifTrue:[
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   605
            arg2 isBlock ifTrue:[
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   606
                arg2 possiblyInlined:true withSelector:selector.
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   607
            ].
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   608
        ].
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   609
        ^ self
574
993d1182782b fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents: 570
diff changeset
   610
    ].
993d1182782b fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents: 570
diff changeset
   611
    numArgs >= 3 ifTrue:[
676
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   612
        arg3 := argArray at:3.
574
993d1182782b fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents: 570
diff changeset
   613
    ].    
993d1182782b fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents: 570
diff changeset
   614
    numArgs == 3 ifTrue:[
676
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   615
        selector == #to:by:do: ifTrue:[
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   616
            arg3 isBlock ifTrue:[
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   617
                arg3 possiblyInlined:true withSelector:selector.
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   618
            ].
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   619
        ].
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   620
        ^ self
574
993d1182782b fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents: 570
diff changeset
   621
    ].
993d1182782b fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents: 570
diff changeset
   622
    ^ self
993d1182782b fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents: 570
diff changeset
   623
676
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   624
    "Created: / 2.7.1997 / 17:01:10 / cg"
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   625
    "Modified: / 2.4.1998 / 19:08:54 / cg"
574
993d1182782b fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents: 570
diff changeset
   626
!
993d1182782b fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents: 570
diff changeset
   627
2096
b993f62fab49 alreadyWarned selectors
Claus Gittinger <cg@exept.de>
parents: 2028
diff changeset
   628
plausibilityCheckIn:aParser
2208
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   629
    |arg1 msg|
902
4ceee83e5e07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 899
diff changeset
   630
4ceee83e5e07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 899
diff changeset
   631
    (argArray size > 0) ifTrue:[
4ceee83e5e07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 899
diff changeset
   632
        arg1 := argArray at:1
4ceee83e5e07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 899
diff changeset
   633
    ].
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   634
3
b63b8a6b71fb *** empty log message ***
claus
parents: 0
diff changeset
   635
    "
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   636
     check #== applied to Floats, Strings or Fractions
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   637
    "
7ad01559b262 Initial revision
claus
parents:
diff changeset
   638
    ((selector == #==) or:[selector == #~~]) ifTrue:[
2208
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   639
        (msg := self checkIdentityCompare) notNil ifTrue:[^ msg].
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   640
    ].
3
b63b8a6b71fb *** empty log message ***
claus
parents: 0
diff changeset
   641
b63b8a6b71fb *** empty log message ***
claus
parents: 0
diff changeset
   642
    "
19
84a1ddf215a5 *** empty log message ***
claus
parents: 15
diff changeset
   643
     [...] ifTrue:...
3
b63b8a6b71fb *** empty log message ***
claus
parents: 0
diff changeset
   644
     an error often occuring when you are a beginner ...
b63b8a6b71fb *** empty log message ***
claus
parents: 0
diff changeset
   645
    "
b63b8a6b71fb *** empty log message ***
claus
parents: 0
diff changeset
   646
    ((selector == #ifTrue:) or:[selector == #ifFalse:]) ifTrue:[
1626
6addd73f7d47 precedence check for if-condition
Claus Gittinger <cg@exept.de>
parents: 1588
diff changeset
   647
        (msg := self checkCondition) notNil ifTrue:[^ msg].
3
b63b8a6b71fb *** empty log message ***
claus
parents: 0
diff changeset
   648
    ].
19
84a1ddf215a5 *** empty log message ***
claus
parents: 15
diff changeset
   649
    ((selector == #ifTrue:ifFalse:) or:[selector == #ifFalse:ifTrue:]) ifTrue:[
1626
6addd73f7d47 precedence check for if-condition
Claus Gittinger <cg@exept.de>
parents: 1588
diff changeset
   650
        (msg := self checkCondition) notNil ifTrue:[^ msg].
3
b63b8a6b71fb *** empty log message ***
claus
parents: 0
diff changeset
   651
    ].
19
84a1ddf215a5 *** empty log message ***
claus
parents: 15
diff changeset
   652
84a1ddf215a5 *** empty log message ***
claus
parents: 15
diff changeset
   653
    "
84a1ddf215a5 *** empty log message ***
claus
parents: 15
diff changeset
   654
     (...) whileTrue:[
84a1ddf215a5 *** empty log message ***
claus
parents: 15
diff changeset
   655
    "
3
b63b8a6b71fb *** empty log message ***
claus
parents: 0
diff changeset
   656
    ((selector == #whileTrue:) or:[selector == #whileFalse:]) ifTrue:[
2028
a9b5ec797153 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1994
diff changeset
   657
        (receiver isBlock not and:[ receiver parenthesized ]) ifTrue:[
a9b5ec797153 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1994
diff changeset
   658
            "/ only warn, if code was originally parenthized
a9b5ec797153 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1994
diff changeset
   659
            ^ 'will fail at runtime, if receiver of ' , selector , ' does not evaluate to a block or respond reasonable to #value'
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   660
        ].
902
4ceee83e5e07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 899
diff changeset
   661
        arg1 isBlock ifFalse:[
1059
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
   662
            ^ 'will fail at runtime, if argument to ' , selector , ' does not evaluate to a block or respond reasonable to #value'
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   663
        ].
3
b63b8a6b71fb *** empty log message ***
claus
parents: 0
diff changeset
   664
    ].
902
4ceee83e5e07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 899
diff changeset
   665
2028
a9b5ec797153 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1994
diff changeset
   666
    "
a9b5ec797153 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1994
diff changeset
   667
     [...] ensure:[...]
a9b5ec797153 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1994
diff changeset
   668
    "
a9b5ec797153 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1994
diff changeset
   669
    ((selector == #ensure:) or:[(selector == #ifCurtailed:)]) ifTrue:[
a9b5ec797153 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1994
diff changeset
   670
        (receiver isBlock not and:[ receiver parenthesized ]) ifTrue:[
a9b5ec797153 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1994
diff changeset
   671
            "/ only warn, if code was originally parenthized
a9b5ec797153 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1994
diff changeset
   672
            ^ 'will fail at runtime, if receiver of ' , selector , ' does not evaluate to a block or respond reasonable to #value'
a9b5ec797153 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1994
diff changeset
   673
        ].
a9b5ec797153 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1994
diff changeset
   674
        (arg1 isBlock not and:[ arg1 parenthesized ]) ifTrue:[
a9b5ec797153 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1994
diff changeset
   675
            ^ 'will fail at runtime, if receiver of ' , selector , ' does not evaluate to a block or respond reasonable to #value'
a9b5ec797153 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1994
diff changeset
   676
        ].
a9b5ec797153 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1994
diff changeset
   677
        (arg1 isBlock and:[arg1 isEmptyBlock]) ifTrue:[
a9b5ec797153 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1994
diff changeset
   678
            ^ 'useless ensure (empty block)'
a9b5ec797153 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1994
diff changeset
   679
        ].
a9b5ec797153 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1994
diff changeset
   680
    ].
a9b5ec797153 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1994
diff changeset
   681
905
9d5500bffa74 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 902
diff changeset
   682
    argArray size > 0 ifTrue:[
9d5500bffa74 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 902
diff changeset
   683
        "/ check for a beginners error (using super as arg)
9d5500bffa74 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 902
diff changeset
   684
        "/ as in (something ? super) foo
9d5500bffa74 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 902
diff changeset
   685
9d5500bffa74 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 902
diff changeset
   686
        argArray do:[:arg | arg isSuper ifTrue:[
1192
b13a83abf72f warning message
Claus Gittinger <cg@exept.de>
parents: 1154
diff changeset
   687
                                ^ 'super special semantic only with receiver of message sends'
905
9d5500bffa74 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 902
diff changeset
   688
                            ]
9d5500bffa74 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 902
diff changeset
   689
                    ].
9d5500bffa74 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 902
diff changeset
   690
    ].
1154
8c8787349aaf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1134
diff changeset
   691
2208
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   692
    (selector = #'handle:do:' 
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   693
    or:[ selector = #'handle:from:do:'
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   694
    or:[ selector = #'ignoreIn:'
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   695
    or:[ selector = #'catch:' ]]]) ifTrue:[
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   696
        (msg := self checkGlobalFromNameSpaceConflictFor:receiver) notNil ifTrue:[^ msg].
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   697
    ].
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   698
    (selector = #'on:do:'
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   699
    or:[ selector = #'on:do:ensure:'
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   700
    or:[ selector = #'on:do:on:do:' ]]) ifTrue:[
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   701
        (msg := self checkGlobalFromNameSpaceConflictFor:arg1) notNil ifTrue:[^ msg].
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   702
    ].
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   703
1154
8c8787349aaf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1134
diff changeset
   704
"/    receiver isBlock ifTrue:[
8c8787349aaf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1134
diff changeset
   705
"/        ([] respondsTo:selector) ifFalse:[
8c8787349aaf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1134
diff changeset
   706
"/            ^ 'blocks do not respond to ' , selector , '; Missing ''.'' between statements ?'
8c8787349aaf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1134
diff changeset
   707
"/        ].
8c8787349aaf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1134
diff changeset
   708
"/    ].
8c8787349aaf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1134
diff changeset
   709
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   710
    ^ nil
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   711
2028
a9b5ec797153 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1994
diff changeset
   712
    "Modified: / 28-03-2007 / 14:14:28 / cg"
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   713
! !
7ad01559b262 Initial revision
claus
parents:
diff changeset
   714
7ad01559b262 Initial revision
claus
parents:
diff changeset
   715
!MessageNode methodsFor:'code generation'!
7ad01559b262 Initial revision
claus
parents:
diff changeset
   716
1691
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   717
codeOn:aStream inBlock:b for:aCompiler
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   718
    self codeOn:aStream inBlock:b valueNeeded:true for:aCompiler
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   719
!
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   720
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   721
codeOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler
2345
d3c1bbb5cddc comment/format in: #codeOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2344
diff changeset
   722
    "most work is in checking for inlinable code here."
d3c1bbb5cddc comment/format in: #codeOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2344
diff changeset
   723
1691
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   724
    |recType nargs isBuiltIn litIndex cls clsLitIndex code isSpecial
1809
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
   725
     specialCode stackTop arg1 arg2 arg3 isSuper realReceiver 
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
   726
     noSendDrop alreadyDropped
1994
4094e1eb3399 preps for selectorNamespaces.
Claus Gittinger <cg@exept.de>
parents: 1989
diff changeset
   727
     useSelfSend usedSelector|
4094e1eb3399 preps for selectorNamespaces.
Claus Gittinger <cg@exept.de>
parents: 1989
diff changeset
   728
1691
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   729
    selector := selector asSymbol.
1994
4094e1eb3399 preps for selectorNamespaces.
Claus Gittinger <cg@exept.de>
parents: 1989
diff changeset
   730
    usedSelector := aCompiler nameSpaceSelectorFor:selector.
4094e1eb3399 preps for selectorNamespaces.
Claus Gittinger <cg@exept.de>
parents: 1989
diff changeset
   731
4094e1eb3399 preps for selectorNamespaces.
Claus Gittinger <cg@exept.de>
parents: 1989
diff changeset
   732
    "/ must be added for browsers-search to work on optimized nodes
4094e1eb3399 preps for selectorNamespaces.
Claus Gittinger <cg@exept.de>
parents: 1989
diff changeset
   733
    usedSelector ~~ selector ifTrue:[ aCompiler addLiteral:selector ].
4094e1eb3399 preps for selectorNamespaces.
Claus Gittinger <cg@exept.de>
parents: 1989
diff changeset
   734
    litIndex := aCompiler addLiteral:usedSelector.
1691
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   735
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   736
    noSendDrop := aCompiler class newCodeSet == true.
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   737
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   738
    realReceiver := self realReceiver.
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   739
    isSuper := realReceiver isSuper.
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   740
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   741
    argArray isNil ifTrue:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   742
        nargs := 0
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   743
    ] ifFalse:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   744
        nargs := argArray size.
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   745
        nargs > 0 ifTrue:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   746
            arg1 := argArray at:1.
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   747
            nargs > 1 ifTrue:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   748
                arg2 := argArray at:2.
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   749
                nargs > 2 ifTrue:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   750
                    arg3 := argArray at:3.
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   751
                ]
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   752
            ]    
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   753
        ].
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   754
    ].
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   755
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   756
    recType := receiver type.
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   757
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   758
    (nargs == 0) ifTrue:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   759
        (recType == #ThisContext) ifTrue:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   760
            valueNeeded ifFalse:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   761
                "for now, only do it in methods"
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   762
                b isNil ifTrue:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   763
                    (selector == #restart) ifTrue:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   764
                        aStream nextPut:#jump; nextPut:1.      "jump to start"
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   765
                        ^ self
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   766
                    ].
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   767
                ].
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   768
                (selector == #return) ifTrue:[  "^ nil"
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   769
                    aStream nextPut:#retNil.
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   770
                    ^ self
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   771
                ].
2562
be17095cbb21 comment/format in: #codeOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2542
diff changeset
   772
            ].
be17095cbb21 comment/format in: #codeOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2542
diff changeset
   773
            "/ aCompiler rememberContextReturnablePragma
1691
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   774
        ].
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   775
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   776
        (receiver isBlock 
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   777
        and:[receiver numArgs == 0
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   778
        and:[receiver isInlinable]]) ifTrue:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   779
            selector == #value ifTrue:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   780
                receiver codeInlineOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler.
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   781
                ^ self
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   782
            ].
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   783
            ((selector == #whileTrue) or:[selector == #whileFalse]) ifTrue:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   784
                ^ self codeWhileOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler.
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   785
            ].
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   786
            ((selector == #repeat) or:[selector == #loop]) ifTrue:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   787
                valueNeeded ifFalse:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   788
                    ^ self codeRepeatOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler.
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   789
                ]
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   790
            ].
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   791
        ].
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   792
    ].
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   793
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   794
    (nargs == 1) ifTrue:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   795
        (recType == #ThisContext) ifTrue:[
2343
e3c3dad6a800 changed: #codeOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   796
            (selector == #return:) ifTrue:[
e3c3dad6a800 changed: #codeOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   797
                arg1 codeOn:aStream inBlock:b for:aCompiler.  "^ value"
e3c3dad6a800 changed: #codeOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   798
                aStream nextPut:#retTop.
e3c3dad6a800 changed: #codeOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   799
                valueNeeded ifTrue:[
e3c3dad6a800 changed: #codeOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   800
                    "/ although we know, that it is useless, we generate a push-nil
2344
4cfbc5060382 comment/format in: #codeOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2343
diff changeset
   801
                    "/ to make any stack-checkers happy (caller will generate a pop).
2343
e3c3dad6a800 changed: #codeOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   802
                    aStream nextPut:#pushNil.
1691
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   803
                ].
2343
e3c3dad6a800 changed: #codeOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   804
                ^ self.
1691
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   805
             ].
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   806
        ].
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   807
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   808
        ((selector == #ifNil:) or:[selector == #ifNotNil:]) ifTrue:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   809
            receiver isBlock ifFalse:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   810
                (arg1 isBlock not
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   811
                or:[arg1 numArgs == 0]) ifTrue:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   812
                    ^ self codeIfNilOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler.
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   813
                ].
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   814
                (arg1 isConstant or:[arg1 isVariable]) ifTrue:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   815
                    ^ self codeIfNilOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler.
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   816
                ].
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   817
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   818
            ].
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   819
        ].
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   820
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   821
        (arg1 isBlock 
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   822
        and:[arg1 isInlinable
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   823
        and:[arg1 numArgs == 0]]) ifTrue:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   824
            ((selector == #ifTrue:) or:[selector == #ifFalse:]) ifTrue:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   825
                receiver isBlock ifFalse:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   826
                    ^ self codeIfOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler.
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   827
                ].
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   828
            ].
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   829
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   830
            (selector == #or:) ifTrue:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   831
                ^ self codeOrOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler.
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   832
            ].
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   833
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   834
            (selector == #and:) ifTrue:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   835
                ^ self codeAndOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler.
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   836
            ].
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   837
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   838
            (selector == #timesRepeat:) ifTrue:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   839
                "/ now, always inline #timesRepeat:;
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   840
                "/ the receiver must understand #> and #-
3164
f11d0862c65e Emit #lineno16 byte codes only, if line number really changes
Stefan Vogel <sv@exept.de>
parents: 3108
diff changeset
   841
1691
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   842
               ^ self codeTimesRepeatOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler.
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   843
            ].
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   844
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   845
            ((selector == #whileTrue:) or:[selector == #whileFalse:]) ifTrue:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   846
                (receiver isBlock 
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   847
                and:[receiver isInlinable
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   848
                and:[receiver numArgs == 0]]) ifTrue:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   849
                    ^ self codeWhileOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler.
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   850
                ]
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   851
            ]
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   852
        ].
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   853
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   854
        ((selector == #ifTrue:) or:[selector == #ifFalse:]) ifTrue:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   855
            (arg1 isConstant or:[arg1 isVariable]) ifTrue:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   856
                ^ self codeIfOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler.
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   857
            ].
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   858
        ].
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   859
1994
4094e1eb3399 preps for selectorNamespaces.
Claus Gittinger <cg@exept.de>
parents: 1989
diff changeset
   860
        usedSelector == #? ifTrue:[
1691
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   861
            "/ only do short-circuit optimization, if arg is not a message;
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   862
            "/ (could have side-effects)
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   863
            "/
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   864
            arg1 isMessage ifFalse:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   865
                ^ self codeQuestOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler.
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   866
            ]
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   867
        ].
2870
75f1f73b3bf9 added: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2869
diff changeset
   868
        (selector == #caseOf:) ifTrue:[
75f1f73b3bf9 added: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2869
diff changeset
   869
            (self codeCaseOfOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler) ifTrue:[
75f1f73b3bf9 added: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2869
diff changeset
   870
                ^ self
75f1f73b3bf9 added: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2869
diff changeset
   871
            ].
75f1f73b3bf9 added: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2869
diff changeset
   872
        ].
1691
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   873
    ].
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   874
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   875
    (nargs == 2) ifTrue:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   876
        receiver isBlock ifFalse:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   877
            (arg1 isBlock 
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   878
            and:[arg1 isInlinable
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   879
            and:[arg1 numArgs == 0
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   880
            and:[arg2 isBlock 
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   881
            and:[arg2 isInlinable
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   882
            and:[arg2 numArgs == 0]]]]]) ifTrue:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   883
                ((selector == #ifTrue:ifFalse:) or:[selector == #ifFalse:ifTrue:]) ifTrue:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   884
                    ^ self codeIfElseOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler.
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   885
                ].
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   886
                ((selector == #ifNil:ifNotNil:) or:[selector == #ifNotNil:ifNil:]) ifTrue:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   887
                    ^ self codeIfNilNotNilOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler.
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   888
                ]
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   889
            ].
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   890
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   891
            ((arg1 isConstant or:[arg1 isVariable])
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   892
            and:[arg2 isConstant or:[arg2 isVariable]]) ifTrue:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   893
                ((selector == #ifTrue:ifFalse:) or:[selector == #ifFalse:ifTrue:]) ifTrue:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   894
                    ^ self codeIfElseOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler.
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   895
                ].
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   896
                ((selector == #ifNil:ifNotNil:) or:[selector == #ifNotNil:ifNil:]) ifTrue:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   897
                    ^ self codeIfNilNotNilOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler.
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   898
                ]
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   899
            ].
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   900
        ].
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   901
        selector == #to:do: ifTrue:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   902
            (arg2 isBlock 
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   903
            and:[arg2 isInlinable 
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   904
            and:[arg2 numArgs == 1]]) ifTrue:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   905
                ^ self codeToDoOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   906
            ]
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   907
        ].
2870
75f1f73b3bf9 added: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2869
diff changeset
   908
        (selector == #'caseOf:otherwise:') ifTrue:[
75f1f73b3bf9 added: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2869
diff changeset
   909
            (self codeCaseOfOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler) ifTrue:[
75f1f73b3bf9 added: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2869
diff changeset
   910
                ^ self
75f1f73b3bf9 added: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2869
diff changeset
   911
            ].
75f1f73b3bf9 added: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2869
diff changeset
   912
        ].
1691
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   913
    ].
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   914
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   915
    (nargs == 3) ifTrue:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   916
        selector == #to:by:do: ifTrue:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   917
            "/ step must be a constant (need to know how to compare)
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   918
            (arg2 isConstant 
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   919
            and:[arg2 type == #Integer
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   920
            and:[arg3 isBlock 
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   921
            and:[arg3 isInlinable 
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   922
            and:[arg3 numArgs == 1]]]]) ifTrue:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   923
                ^ self codeToByDoOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   924
            ]
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   925
        ].
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   926
    ].
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   927
1809
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
   928
    isBuiltIn := isSpecial := false.
1691
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   929
    isSuper ifFalse:[
1994
4094e1eb3399 preps for selectorNamespaces.
Claus Gittinger <cg@exept.de>
parents: 1989
diff changeset
   930
        isBuiltIn := aCompiler isBuiltInSelector:usedSelector forReceiver:receiver.
1691
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   931
        isBuiltIn ifFalse:[
1994
4094e1eb3399 preps for selectorNamespaces.
Claus Gittinger <cg@exept.de>
parents: 1989
diff changeset
   932
            specialCode := aCompiler specialSendCodeFor:usedSelector.
1691
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   933
            isSpecial := specialCode notNil.
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   934
        ].
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   935
    ].
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   936
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   937
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   938
    "can we use a send-bytecode ?"
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   939
    (isBuiltIn or:[isSpecial]) ifTrue:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   940
        receiver codeOn:aStream inBlock:b for:aCompiler.
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   941
        (nargs > 0) ifTrue:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   942
            arg1 codeOn:aStream inBlock:b for:aCompiler.
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   943
            (nargs > 1) ifTrue:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   944
                arg2 codeOn:aStream inBlock:b for:aCompiler
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   945
            ]
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   946
        ].
3108
805f9d928eda Emit LINE16 bytecode insn just before a SEND bytecode is emmited when
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3017
diff changeset
   947
        lineNr >= 255 ifTrue:[
3164
f11d0862c65e Emit #lineno16 byte codes only, if line number really changes
Stefan Vogel <sv@exept.de>
parents: 3108
diff changeset
   948
            self codeLineNumber: lineNr on: aStream for:aCompiler.  
3108
805f9d928eda Emit LINE16 bytecode insn just before a SEND bytecode is emmited when
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3017
diff changeset
   949
        ].
1994
4094e1eb3399 preps for selectorNamespaces.
Claus Gittinger <cg@exept.de>
parents: 1989
diff changeset
   950
        aStream nextPut:usedSelector.
4094e1eb3399 preps for selectorNamespaces.
Claus Gittinger <cg@exept.de>
parents: 1989
diff changeset
   951
        (aCompiler hasLineNumber:usedSelector) ifTrue:[
1691
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   952
            aStream nextPut:lineNr.
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   953
        ].
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   954
        isSpecial ifTrue:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   955
            aStream nextPut:specialCode
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   956
        ].
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   957
        valueNeeded ifFalse:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   958
            aStream nextPut:#drop
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   959
        ].
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   960
        ^ self
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   961
    ].
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   962
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   963
    ((nargs == 0) and:[selector == #yourself]) ifTrue:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   964
        "yourself is often added to get the receiver -
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   965
         we get it without the yourself-message"
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   966
2429
89d05ce26891 changed: #codeOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2399
diff changeset
   967
        (valueNeeded or:[receiver isMessage]) ifTrue:[
1691
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   968
            receiver codeOn:aStream inBlock:b for:aCompiler
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   969
        ].
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   970
        ^ self
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   971
    ].
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   972
2345
d3c1bbb5cddc comment/format in: #codeOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2344
diff changeset
   973
    "not inlinable - generate a send"
1691
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   974
1809
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
   975
    stackTop := nil.
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
   976
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
   977
    useSelfSend := isSuper not and:[ recType == #Self and:[ litIndex <= 16rFFFF ] ].
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
   978
    useSelfSend ifFalse:[
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
   979
        receiver codeOn:aStream inBlock:b for:aCompiler.
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
   980
        receiver isConstant ifTrue:[ 
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
   981
            stackTop := receiver
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
   982
        ].
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
   983
    ].
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
   984
    argArray notNil ifTrue:[
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
   985
        argArray do:[:arg |
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
   986
            (stackTop notNil and:[arg canReuseAsArg:stackTop]) ifTrue:[
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
   987
                aStream nextPut:#dup.
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
   988
                "/ 'reuse:' print. stackTop print. ' in ' print. aCompiler selector printNL.
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
   989
            ] ifFalse:[
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
   990
                arg codeOn:aStream inBlock:b for:aCompiler.
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
   991
                stackTop := arg.
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
   992
            ]
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
   993
        ]
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
   994
    ].
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
   995
1691
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   996
    isSuper ifTrue:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   997
        cls := aCompiler targetClass.
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   998
        realReceiver isHere ifTrue:[
1809
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
   999
            "/ same code as supersend, but targetClass starts search
1691
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1000
        ] ifFalse:[
1809
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  1001
            "/ targetClasses superclass starts search
1691
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1002
            cls := cls superclass.
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1003
        ].
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1004
        clsLitIndex := aCompiler addLiteral:cls.
3164
f11d0862c65e Emit #lineno16 byte codes only, if line number really changes
Stefan Vogel <sv@exept.de>
parents: 3108
diff changeset
  1005
        self emitSuperSendLiteralIndex:litIndex classLiteralIndex:clsLitIndex numArgs:nargs line:lineNr on:aStream for:aCompiler.
1809
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  1006
        valueNeeded ifFalse:[
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  1007
            aStream nextPut:#drop
1691
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1008
        ].
1809
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  1009
        ^ self.
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  1010
    ].
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  1011
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  1012
    valueNeeded ifTrue:[ noSendDrop := true ].
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  1013
    alreadyDropped := false.
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  1014
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  1015
    (litIndex <= 255) ifTrue:[
1691
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1016
        (nargs <= 3) ifTrue:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1017
            |codes|
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1018
1809
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  1019
            noSendDrop ifTrue:[
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  1020
                useSelfSend ifTrue:[
1691
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1021
                    codes := #(sendSelf0 sendSelf1 sendSelf2 sendSelf3)
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1022
                ] ifFalse:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1023
                    codes := #(send0 send1 send2 send3)
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1024
                ]
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1025
            ] ifFalse:[
1809
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  1026
                useSelfSend ifTrue:[
1691
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1027
                    codes := #(sendSelfDrop0 sendSelfDrop1 sendSelfDrop2 sendSelfDrop3)
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1028
                ] ifFalse:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1029
                    codes := #(sendDrop0 sendDrop1 sendDrop2 sendDrop3)
1809
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  1030
                ].
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  1031
                alreadyDropped := true.
1691
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1032
            ].
3108
805f9d928eda Emit LINE16 bytecode insn just before a SEND bytecode is emmited when
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3017
diff changeset
  1033
            lineNr >= 255 ifTrue:[
805f9d928eda Emit LINE16 bytecode insn just before a SEND bytecode is emmited when
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3017
diff changeset
  1034
                self codeLineNumber: lineNr on: aStream for: aCompiler.
805f9d928eda Emit LINE16 bytecode insn just before a SEND bytecode is emmited when
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3017
diff changeset
  1035
            ].
1691
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1036
            aStream nextPut:(codes at:(nargs + 1)); nextPut:lineNr; nextPut:litIndex.
1809
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  1037
            valueNeeded ifFalse:[
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  1038
                alreadyDropped ifFalse:[
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  1039
                    aStream nextPut:#drop
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  1040
                ].
1691
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1041
            ].
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1042
            ^ self
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1043
        ].
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1044
1809
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  1045
        useSelfSend ifTrue:[
1691
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1046
            code := #sendSelf
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1047
        ] ifFalse:[
1809
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  1048
            noSendDrop ifTrue:[
1691
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1049
                code := #send
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1050
            ] ifFalse:[
1809
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  1051
                code := #sendDrop.
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  1052
                alreadyDropped := true.
1691
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1053
            ]
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1054
        ].
3108
805f9d928eda Emit LINE16 bytecode insn just before a SEND bytecode is emmited when
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3017
diff changeset
  1055
805f9d928eda Emit LINE16 bytecode insn just before a SEND bytecode is emmited when
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3017
diff changeset
  1056
        lineNr >= 255 ifTrue:[
805f9d928eda Emit LINE16 bytecode insn just before a SEND bytecode is emmited when
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3017
diff changeset
  1057
            self codeLineNumber: lineNr on: aStream for: aCompiler.
805f9d928eda Emit LINE16 bytecode insn just before a SEND bytecode is emmited when
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3017
diff changeset
  1058
        ].           
1691
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1059
        aStream nextPut:code; nextPut:lineNr; nextPut:litIndex; nextPut:nargs.
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1060
        valueNeeded ifFalse:[
1809
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  1061
            alreadyDropped ifFalse:[
1691
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1062
                aStream nextPut:#drop
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1063
            ].
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1064
        ].
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1065
        ^ self
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1066
    ].
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1067
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1068
    "needs 16bit literal index"
1809
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  1069
    (litIndex <= 16rFFFF) ifTrue:[
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  1070
        useSelfSend ifTrue:[
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  1071
            aStream nextPut:#sendSelfL; nextPut:lineNr; nextPut:litIndex; nextPut:0; nextPut:nargs.
1801
9fd56369b7f1 more long ops
Claus Gittinger <cg@exept.de>
parents: 1791
diff changeset
  1072
        ] ifFalse:[
3164
f11d0862c65e Emit #lineno16 byte codes only, if line number really changes
Stefan Vogel <sv@exept.de>
parents: 3108
diff changeset
  1073
            self emitSendLiteralIndex:litIndex numArgs:nargs line:lineNr on:aStream for:aCompiler.
1801
9fd56369b7f1 more long ops
Claus Gittinger <cg@exept.de>
parents: 1791
diff changeset
  1074
        ].
9fd56369b7f1 more long ops
Claus Gittinger <cg@exept.de>
parents: 1791
diff changeset
  1075
    ] ifFalse:[
9fd56369b7f1 more long ops
Claus Gittinger <cg@exept.de>
parents: 1791
diff changeset
  1076
        "needs 32bit literal index"
3164
f11d0862c65e Emit #lineno16 byte codes only, if line number really changes
Stefan Vogel <sv@exept.de>
parents: 3108
diff changeset
  1077
        self emitSendLiteralIndex:litIndex numArgs:nargs line:lineNr on:aStream for:aCompiler.
1691
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1078
    ].
1801
9fd56369b7f1 more long ops
Claus Gittinger <cg@exept.de>
parents: 1791
diff changeset
  1079
1691
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1080
    valueNeeded ifFalse:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1081
        aStream nextPut:#drop
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1082
    ].
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1083
1994
4094e1eb3399 preps for selectorNamespaces.
Claus Gittinger <cg@exept.de>
parents: 1989
diff changeset
  1084
    "Modified: / 03-09-1995 / 12:55:42 / claus"
2870
75f1f73b3bf9 added: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2869
diff changeset
  1085
    "Modified: / 25-05-2012 / 11:29:47 / cg"
3108
805f9d928eda Emit LINE16 bytecode insn just before a SEND bytecode is emmited when
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3017
diff changeset
  1086
    "Modified: / 12-04-2013 / 22:42:49 / Jan Vrany <jan.vrany@fit.cvut.cz>"
1691
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1087
! !
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1088
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1089
!MessageNode methodsFor:'enumerating'!
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1090
3278
73ef6a07d279 class: ParseNode
Claus Gittinger <cg@exept.de>
parents: 3274
diff changeset
  1091
messageSelectorsDo:aBlock
73ef6a07d279 class: ParseNode
Claus Gittinger <cg@exept.de>
parents: 3274
diff changeset
  1092
    "evaluate aBlock for each message-selector here and in subnodes"
73ef6a07d279 class: ParseNode
Claus Gittinger <cg@exept.de>
parents: 3274
diff changeset
  1093
73ef6a07d279 class: ParseNode
Claus Gittinger <cg@exept.de>
parents: 3274
diff changeset
  1094
    aBlock value:selector.
73ef6a07d279 class: ParseNode
Claus Gittinger <cg@exept.de>
parents: 3274
diff changeset
  1095
    receiver messageSelectorsDo:aBlock.
3274
18fa73f6a23b renamed messagesDo: to messageNodes: do
Claus Gittinger <cg@exept.de>
parents: 3266
diff changeset
  1096
    argArray notNil ifTrue:[
3278
73ef6a07d279 class: ParseNode
Claus Gittinger <cg@exept.de>
parents: 3274
diff changeset
  1097
        argArray do:[:arg | arg messageSelectorsDo:aBlock].
3274
18fa73f6a23b renamed messagesDo: to messageNodes: do
Claus Gittinger <cg@exept.de>
parents: 3266
diff changeset
  1098
    ]
18fa73f6a23b renamed messagesDo: to messageNodes: do
Claus Gittinger <cg@exept.de>
parents: 3266
diff changeset
  1099
!
18fa73f6a23b renamed messagesDo: to messageNodes: do
Claus Gittinger <cg@exept.de>
parents: 3266
diff changeset
  1100
1691
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1101
messagesDo:aBlock
3274
18fa73f6a23b renamed messagesDo: to messageNodes: do
Claus Gittinger <cg@exept.de>
parents: 3266
diff changeset
  1102
    "evaluate aBlock for each message-selector here and in subnodes"
18fa73f6a23b renamed messagesDo: to messageNodes: do
Claus Gittinger <cg@exept.de>
parents: 3266
diff changeset
  1103
1691
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1104
    aBlock value:self.
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1105
    receiver messagesDo:aBlock.
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1106
    argArray notNil ifTrue:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1107
        argArray do:[:arg | arg messagesDo:aBlock].
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1108
    ]
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1109
!
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1110
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1111
nodeDo:anEnumerator
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1112
    "helper for parse tree walking"
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1113
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1114
    |args|
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1115
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1116
    args := argArray ? #().
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1117
    ^ anEnumerator doMessage:self receiver:receiver selector:selector arguments:args
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1118
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1119
    "Created: 19.6.1997 / 16:46:39 / cg"
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1120
    "Modified: 19.6.1997 / 17:08:28 / cg"
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1121
! !
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1122
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1123
!MessageNode methodsFor:'evaluation'!
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1124
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1125
evaluateForCascadeIn:anEnvironment
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1126
    ^ self evaluateIn:anEnvironment forCascade:true
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1127
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1128
    "Modified: / 20-04-2005 / 12:12:01 / cg"
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1129
!
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1130
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1131
evaluateIn:anEnvironment
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1132
    ^ self evaluateIn:anEnvironment forCascade:false
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1133
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1134
    "Modified: / 20-04-2005 / 12:11:55 / cg"
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1135
!
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1136
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1137
evaluateIn:anEnvironment forCascade:forCascade
2329
50473c5384bb changed: #evaluateIn:forCascade:
Claus Gittinger <cg@exept.de>
parents: 2321
diff changeset
  1138
    |retVal defClass r a1 a2 a3 nargs argValueArray class sel|
1691
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1139
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1140
    sel := self evaluationSelector.
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1141
    receiver isSuper ifTrue:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1142
        r := receiver value.
2329
50473c5384bb changed: #evaluateIn:forCascade:
Claus Gittinger <cg@exept.de>
parents: 2321
diff changeset
  1143
50473c5384bb changed: #evaluateIn:forCascade:
Claus Gittinger <cg@exept.de>
parents: 2321
diff changeset
  1144
        defClass := receiver definingClass.
1691
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1145
        receiver isHere ifTrue:[
2329
50473c5384bb changed: #evaluateIn:forCascade:
Claus Gittinger <cg@exept.de>
parents: 2321
diff changeset
  1146
            class := defClass.
1691
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1147
        ] ifFalse:[
2329
50473c5384bb changed: #evaluateIn:forCascade:
Claus Gittinger <cg@exept.de>
parents: 2321
diff changeset
  1148
            class := defClass superclass.
1691
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1149
        ].
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1150
        argArray notNil ifTrue:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1151
            argValueArray := argArray collect:[:arg | arg evaluateIn:anEnvironment].
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1152
        ] ifFalse:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1153
            argValueArray := #()
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1154
        ].
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1155
        retVal := r perform:sel inClass:class withArguments:argValueArray.
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1156
    ] ifFalse:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1157
        r := receiver evaluateIn:anEnvironment.
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1158
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1159
        argArray isNil ifTrue:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1160
            retVal := r perform:sel
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1161
        ] ifFalse:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1162
            nargs := argArray size.
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1163
            (nargs == 0) ifTrue:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1164
                retVal := r perform:sel
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1165
            ] ifFalse:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1166
                a1 := (argArray at:1) evaluateIn:anEnvironment.
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1167
                (nargs == 1) ifTrue:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1168
                    retVal := r perform:sel with:a1
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1169
                ] ifFalse:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1170
                    a2 := (argArray at:2) evaluateIn:anEnvironment.
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1171
                    (nargs == 2) ifTrue:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1172
                        retVal := r perform:sel with:a1 with:a2
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1173
                    ] ifFalse:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1174
                        a3 := (argArray at:3) evaluateIn:anEnvironment.
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1175
                        (nargs == 3) ifTrue:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1176
                            retVal := r perform:sel with:a1 with:a2 with:a3
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1177
                        ] ifFalse:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1178
                            argValueArray := Array new:nargs.
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1179
                            argValueArray at:1 put:a1.
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1180
                            argValueArray at:2 put:a2.
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1181
                            argValueArray at:3 put:a3.
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1182
                            4 to:nargs do:[:idx | argValueArray at:idx put:((argArray at:idx) evaluateIn:anEnvironment)].
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1183
                            retVal := r perform:sel withArguments:argValueArray.
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1184
                        ].
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1185
                    ].
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1186
                ].
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1187
            ].
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1188
        ].
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1189
    ].
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1190
    ^ forCascade ifTrue:[r] ifFalse:[retVal]
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1191
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1192
    "Created: / 20-04-2005 / 12:11:39 / cg"
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1193
!
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1194
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1195
evaluationSelector
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1196
    ^ selector asSymbol
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1197
! !
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1198
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1199
!MessageNode methodsFor:'optimized code generation'!
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1200
338
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1201
codeAndIfElseOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1202
    "generate code for (x and:[y]) ifxxx:[ ... ] ifyyy:[ ... ]"
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1203
2941
346983db9f8f changed:
Claus Gittinger <cg@exept.de>
parents: 2925
diff changeset
  1204
    |theByteCode optByteCode receiver1 receiver2 theArg theArg2 pos1 pos2 pos3 code here jmp
346983db9f8f changed:
Claus Gittinger <cg@exept.de>
parents: 2925
diff changeset
  1205
     block1 block2 andBlock optByteCode2|
338
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1206
1464
fa19f86d1ef4 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1463
diff changeset
  1207
    aCompiler addLiteral:#and:.
fa19f86d1ef4 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1463
diff changeset
  1208
338
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1209
    theByteCode := #falseJump.
2941
346983db9f8f changed:
Claus Gittinger <cg@exept.de>
parents: 2925
diff changeset
  1210
    receiver1 := receiver receiver.
346983db9f8f changed:
Claus Gittinger <cg@exept.de>
parents: 2925
diff changeset
  1211
    theArg := nil.
346983db9f8f changed:
Claus Gittinger <cg@exept.de>
parents: 2925
diff changeset
  1212
346983db9f8f changed:
Claus Gittinger <cg@exept.de>
parents: 2925
diff changeset
  1213
    optByteCode := self optimizedConditionFor:receiver1 with:theByteCode for:aCompiler.
338
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1214
    optByteCode notNil ifTrue:[
1058
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  1215
        ((optByteCode == #eqJump) or:[optByteCode == #notEqJump]) ifTrue:[
2941
346983db9f8f changed:
Claus Gittinger <cg@exept.de>
parents: 2925
diff changeset
  1216
            theArg := receiver1 arg1
1058
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  1217
        ].
2941
346983db9f8f changed:
Claus Gittinger <cg@exept.de>
parents: 2925
diff changeset
  1218
        receiver1 := receiver1 receiver.
1058
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  1219
        theByteCode := optByteCode
338
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1220
    ].
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1221
    "/ code the left-of the and-part
2941
346983db9f8f changed:
Claus Gittinger <cg@exept.de>
parents: 2925
diff changeset
  1222
    receiver1 codeOn:aStream inBlock:b for:aCompiler.
338
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1223
    theArg notNil ifTrue:[
1058
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  1224
        theArg codeOn:aStream inBlock:b for:aCompiler
338
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1225
    ].
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1226
    aStream nextPut:theByteCode.
3266
96ed152db6df class: MessageNode
Stefan Vogel <sv@exept.de>
parents: 3164
diff changeset
  1227
    pos1 := aStream position + 1.   "/ remember branch target of left-fail branch
338
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1228
    aStream nextPut:0.
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1229
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1230
    "/ code the right of the and-part
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1231
    (selector == #ifTrue:ifFalse:) ifTrue:[
1058
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  1232
        jmp := #falseJump
338
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1233
    ] ifFalse:[
1058
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  1234
        jmp := #trueJump
338
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1235
    ].
2941
346983db9f8f changed:
Claus Gittinger <cg@exept.de>
parents: 2925
diff changeset
  1236
346983db9f8f changed:
Claus Gittinger <cg@exept.de>
parents: 2925
diff changeset
  1237
    andBlock := receiver arg1.
346983db9f8f changed:
Claus Gittinger <cg@exept.de>
parents: 2925
diff changeset
  1238
    theArg2 := nil.
346983db9f8f changed:
Claus Gittinger <cg@exept.de>
parents: 2925
diff changeset
  1239
346983db9f8f changed:
Claus Gittinger <cg@exept.de>
parents: 2925
diff changeset
  1240
    "/ code the left-of the and-part
346983db9f8f changed:
Claus Gittinger <cg@exept.de>
parents: 2925
diff changeset
  1241
    (andBlock statements isNil or:[andBlock statements nextStatement isNil]) ifTrue:[
346983db9f8f changed:
Claus Gittinger <cg@exept.de>
parents: 2925
diff changeset
  1242
        "/ simple - one statement
346983db9f8f changed:
Claus Gittinger <cg@exept.de>
parents: 2925
diff changeset
  1243
        receiver2 := andBlock statements expression.
346983db9f8f changed:
Claus Gittinger <cg@exept.de>
parents: 2925
diff changeset
  1244
        optByteCode2 := self optimizedConditionFor:receiver2 with:jmp for:aCompiler.
346983db9f8f changed:
Claus Gittinger <cg@exept.de>
parents: 2925
diff changeset
  1245
    ].
346983db9f8f changed:
Claus Gittinger <cg@exept.de>
parents: 2925
diff changeset
  1246
    optByteCode2 notNil ifTrue:[
346983db9f8f changed:
Claus Gittinger <cg@exept.de>
parents: 2925
diff changeset
  1247
        ((optByteCode2 == #eqJump) or:[optByteCode2 == #notEqJump]) ifTrue:[
346983db9f8f changed:
Claus Gittinger <cg@exept.de>
parents: 2925
diff changeset
  1248
            theArg2 := receiver2 arg1
346983db9f8f changed:
Claus Gittinger <cg@exept.de>
parents: 2925
diff changeset
  1249
        ].
346983db9f8f changed:
Claus Gittinger <cg@exept.de>
parents: 2925
diff changeset
  1250
        receiver2 := receiver2 receiver.
346983db9f8f changed:
Claus Gittinger <cg@exept.de>
parents: 2925
diff changeset
  1251
        receiver2 codeOn:aStream inBlock:b for:aCompiler.
346983db9f8f changed:
Claus Gittinger <cg@exept.de>
parents: 2925
diff changeset
  1252
        theArg2 notNil ifTrue:[
346983db9f8f changed:
Claus Gittinger <cg@exept.de>
parents: 2925
diff changeset
  1253
            theArg2 codeOn:aStream inBlock:b for:aCompiler
346983db9f8f changed:
Claus Gittinger <cg@exept.de>
parents: 2925
diff changeset
  1254
        ].
346983db9f8f changed:
Claus Gittinger <cg@exept.de>
parents: 2925
diff changeset
  1255
        jmp := optByteCode2
346983db9f8f changed:
Claus Gittinger <cg@exept.de>
parents: 2925
diff changeset
  1256
    ] ifFalse:[
346983db9f8f changed:
Claus Gittinger <cg@exept.de>
parents: 2925
diff changeset
  1257
        andBlock codeInlineOn:aStream inBlock:b for:aCompiler.
346983db9f8f changed:
Claus Gittinger <cg@exept.de>
parents: 2925
diff changeset
  1258
    ].
346983db9f8f changed:
Claus Gittinger <cg@exept.de>
parents: 2925
diff changeset
  1259
338
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1260
    aStream nextPut:jmp.
3266
96ed152db6df class: MessageNode
Stefan Vogel <sv@exept.de>
parents: 3164
diff changeset
  1261
    pos2 := aStream position + 1.   "/ remember branch target of right-fail branch 
338
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1262
    aStream nextPut:0.
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1263
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1264
    code := aStream contents.
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1265
    (selector == #ifFalse:ifTrue:) ifTrue:[
3266
96ed152db6df class: MessageNode
Stefan Vogel <sv@exept.de>
parents: 3164
diff changeset
  1266
        code at:pos1 put:(aStream position + 1)
338
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1267
    ].
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1268
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1269
    "/ code the if-block
1059
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1270
    block1 := argArray at: 1.
1435
be9680c6145c factored out some common code (block-code and value-sending)
Claus Gittinger <cg@exept.de>
parents: 1425
diff changeset
  1271
    self codeBlockEvaluation:block1 on:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler.
338
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1272
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1273
    aStream nextPut:#jump.
3266
96ed152db6df class: MessageNode
Stefan Vogel <sv@exept.de>
parents: 3164
diff changeset
  1274
    pos3 := aStream position + 1.
338
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1275
    aStream nextPut:0.
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1276
3266
96ed152db6df class: MessageNode
Stefan Vogel <sv@exept.de>
parents: 3164
diff changeset
  1277
    here := aStream position + 1.
338
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1278
    (selector == #ifTrue:ifFalse:) ifTrue:[
1058
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  1279
        code at:pos1 put:here
338
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1280
    ].
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1281
    code at:pos2 put:here.
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1282
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1283
    "/ code the else-block
1059
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1284
    block2 := argArray at: 2.
1435
be9680c6145c factored out some common code (block-code and value-sending)
Claus Gittinger <cg@exept.de>
parents: 1425
diff changeset
  1285
    self codeBlockEvaluation:block2 on:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler.
338
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1286
3266
96ed152db6df class: MessageNode
Stefan Vogel <sv@exept.de>
parents: 3164
diff changeset
  1287
    code at:pos3 put:(aStream position + 1)
338
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1288
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1289
    "Created: 6.9.1996 / 12:56:23 / cg"
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1290
!
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1291
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1292
codeAndIfOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1293
    "generate code for (x and:[y]) ifxxx:[ ... ]"
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1294
812
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1295
    |theByteCode optByteCode andBlock theArg pos1 pos2 pos3 code here jmp
1059
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1296
     receiver1 receiver2 optByteCode2 theArg2 block|
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1297
1464
fa19f86d1ef4 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1463
diff changeset
  1298
    aCompiler addLiteral:#and:.
fa19f86d1ef4 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1463
diff changeset
  1299
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1300
    theByteCode := #falseJump.
812
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1301
    receiver1 := receiver receiver.
2941
346983db9f8f changed:
Claus Gittinger <cg@exept.de>
parents: 2925
diff changeset
  1302
    theArg := nil.
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1303
1463
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  1304
    optByteCode := self optimizedConditionFor:receiver1 with:theByteCode for:aCompiler.
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1305
    optByteCode notNil ifTrue:[
812
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1306
        ((optByteCode == #eqJump) or:[optByteCode == #notEqJump]) ifTrue:[
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1307
            theArg := receiver1 arg1
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1308
        ].
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1309
        receiver1 := receiver1 receiver.
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1310
        theByteCode := optByteCode
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1311
    ].
2941
346983db9f8f changed:
Claus Gittinger <cg@exept.de>
parents: 2925
diff changeset
  1312
    "/ code the left-of the and-part
812
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1313
    receiver1 codeOn:aStream inBlock:b for:aCompiler.
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1314
    theArg notNil ifTrue:[
812
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1315
        theArg codeOn:aStream inBlock:b for:aCompiler
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1316
    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1317
    aStream nextPut:theByteCode.
3266
96ed152db6df class: MessageNode
Stefan Vogel <sv@exept.de>
parents: 3164
diff changeset
  1318
    pos1 := aStream position + 1.
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1319
    aStream nextPut:0.
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1320
812
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1321
    andBlock := receiver arg1. "/ the and:-block
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1322
    (selector == #ifTrue:) ifTrue:[
812
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1323
        jmp := #falseJump
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1324
    ] ifFalse:[
812
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1325
        jmp := #trueJump
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1326
    ].
2941
346983db9f8f changed:
Claus Gittinger <cg@exept.de>
parents: 2925
diff changeset
  1327
    optByteCode2 := nil.
346983db9f8f changed:
Claus Gittinger <cg@exept.de>
parents: 2925
diff changeset
  1328
346983db9f8f changed:
Claus Gittinger <cg@exept.de>
parents: 2925
diff changeset
  1329
    (andBlock statements isNil or:[andBlock statements nextStatement isNil]) ifTrue:[
812
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1330
        "/ simple - one statement
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1331
        receiver2 := andBlock statements expression.
1463
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  1332
        optByteCode2 := self optimizedConditionFor:receiver2 with:jmp for:aCompiler.
812
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1333
    ].
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1334
    optByteCode2 notNil ifTrue:[
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1335
        ((optByteCode2 == #eqJump) or:[optByteCode2 == #notEqJump]) ifTrue:[
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1336
            theArg2 := receiver2 arg1
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1337
        ].
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1338
        receiver2 := receiver2 receiver.
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1339
        receiver2 codeOn:aStream inBlock:b for:aCompiler.
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1340
        theArg2 notNil ifTrue:[
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1341
            theArg2 codeOn:aStream inBlock:b for:aCompiler
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1342
        ].
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1343
        jmp := optByteCode2.
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1344
    ] ifFalse:[
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1345
        andBlock codeInlineOn:aStream inBlock:b for:aCompiler.
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1346
    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1347
    aStream nextPut:jmp.
3266
96ed152db6df class: MessageNode
Stefan Vogel <sv@exept.de>
parents: 3164
diff changeset
  1348
    pos2 := aStream position + 1.
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1349
    aStream nextPut:0.
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1350
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1351
    code := aStream contents.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1352
    (selector == #ifFalse:) ifTrue:[
3266
96ed152db6df class: MessageNode
Stefan Vogel <sv@exept.de>
parents: 3164
diff changeset
  1353
        code at:pos1 put:(aStream position + 1)
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1354
    ].
1059
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1355
    block := argArray at: 1.
1435
be9680c6145c factored out some common code (block-code and value-sending)
Claus Gittinger <cg@exept.de>
parents: 1425
diff changeset
  1356
    self codeBlockEvaluation:block on:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler.
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1357
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1358
    valueNeeded ifTrue:[
812
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1359
        aStream nextPut:#jump.
3266
96ed152db6df class: MessageNode
Stefan Vogel <sv@exept.de>
parents: 3164
diff changeset
  1360
        pos3 := aStream position + 1.
812
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1361
        aStream nextPut:0.
3266
96ed152db6df class: MessageNode
Stefan Vogel <sv@exept.de>
parents: 3164
diff changeset
  1362
        here := aStream position + 1.
812
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1363
        (selector == #ifTrue:) ifTrue:[
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1364
            code at:pos1 put:here
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1365
        ].
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1366
        code at:pos2 put:here.
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1367
        aStream nextPut:#pushNil.
3266
96ed152db6df class: MessageNode
Stefan Vogel <sv@exept.de>
parents: 3164
diff changeset
  1368
        code at:pos3 put:(aStream position + 1)
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1369
    ] ifFalse:[
3266
96ed152db6df class: MessageNode
Stefan Vogel <sv@exept.de>
parents: 3164
diff changeset
  1370
        here := aStream position + 1.
812
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1371
        (selector == #ifTrue:) ifTrue:[
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1372
            code at:pos1 put:here
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1373
        ].
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1374
        code at:pos2 put:here
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1375
    ]
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1376
!
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1377
289
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  1378
codeAndOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  1379
    "generate code for (x and:[y])"
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1380
289
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  1381
    |pos1 rightExpr|
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  1382
1464
fa19f86d1ef4 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1463
diff changeset
  1383
    aCompiler addLiteral:#and:.
fa19f86d1ef4 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1463
diff changeset
  1384
289
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  1385
    receiver codeOn:aStream inBlock:b for:aCompiler.
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  1386
    valueNeeded ifTrue:[
1371
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  1387
        aStream nextPut:#dup.
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1388
    ].
289
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  1389
    aStream nextPut:#falseJump.
3266
96ed152db6df class: MessageNode
Stefan Vogel <sv@exept.de>
parents: 3164
diff changeset
  1390
    pos1 := aStream position + 1.
289
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  1391
    aStream nextPut:0.
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  1392
    valueNeeded ifTrue:[
1371
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  1393
        aStream nextPut:#drop.
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1394
    ].
289
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  1395
    rightExpr := argArray at:1.
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  1396
    rightExpr codeInlineOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler.
163
9a7dfd547e69 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
  1397
3266
96ed152db6df class: MessageNode
Stefan Vogel <sv@exept.de>
parents: 3164
diff changeset
  1398
    (aStream contents) at:pos1 put:(aStream position + 1)
289
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  1399
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  1400
    "Created: 17.6.1996 / 15:46:42 / cg"
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  1401
    "Modified: 17.6.1996 / 15:47:44 / cg"
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1402
!
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1403
1435
be9680c6145c factored out some common code (block-code and value-sending)
Claus Gittinger <cg@exept.de>
parents: 1425
diff changeset
  1404
codeBlockEvaluation:aBlock on:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler
be9680c6145c factored out some common code (block-code and value-sending)
Claus Gittinger <cg@exept.de>
parents: 1425
diff changeset
  1405
    "gen code to evaluate a block"
be9680c6145c factored out some common code (block-code and value-sending)
Claus Gittinger <cg@exept.de>
parents: 1425
diff changeset
  1406
be9680c6145c factored out some common code (block-code and value-sending)
Claus Gittinger <cg@exept.de>
parents: 1425
diff changeset
  1407
    (aBlock isBlock and:[aBlock isInlinable]) ifTrue:[
be9680c6145c factored out some common code (block-code and value-sending)
Claus Gittinger <cg@exept.de>
parents: 1425
diff changeset
  1408
        aBlock codeInlineOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler.
be9680c6145c factored out some common code (block-code and value-sending)
Claus Gittinger <cg@exept.de>
parents: 1425
diff changeset
  1409
    ] ifFalse:[
be9680c6145c factored out some common code (block-code and value-sending)
Claus Gittinger <cg@exept.de>
parents: 1425
diff changeset
  1410
        aBlock codeOn:aStream inBlock:b for:aCompiler.
be9680c6145c factored out some common code (block-code and value-sending)
Claus Gittinger <cg@exept.de>
parents: 1425
diff changeset
  1411
        aBlock isConstant ifFalse:[
be9680c6145c factored out some common code (block-code and value-sending)
Claus Gittinger <cg@exept.de>
parents: 1425
diff changeset
  1412
            self codeValueSendOn:aStream for:aCompiler.
be9680c6145c factored out some common code (block-code and value-sending)
Claus Gittinger <cg@exept.de>
parents: 1425
diff changeset
  1413
        ].
be9680c6145c factored out some common code (block-code and value-sending)
Claus Gittinger <cg@exept.de>
parents: 1425
diff changeset
  1414
        valueNeeded ifFalse:[
be9680c6145c factored out some common code (block-code and value-sending)
Claus Gittinger <cg@exept.de>
parents: 1425
diff changeset
  1415
            aStream nextPut:#drop
be9680c6145c factored out some common code (block-code and value-sending)
Claus Gittinger <cg@exept.de>
parents: 1425
diff changeset
  1416
        ].
be9680c6145c factored out some common code (block-code and value-sending)
Claus Gittinger <cg@exept.de>
parents: 1425
diff changeset
  1417
    ].
be9680c6145c factored out some common code (block-code and value-sending)
Claus Gittinger <cg@exept.de>
parents: 1425
diff changeset
  1418
!
be9680c6145c factored out some common code (block-code and value-sending)
Claus Gittinger <cg@exept.de>
parents: 1425
diff changeset
  1419
2870
75f1f73b3bf9 added: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2869
diff changeset
  1420
codeCaseOfOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler
75f1f73b3bf9 added: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2869
diff changeset
  1421
    "expr
75f1f73b3bf9 added: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2869
diff changeset
  1422
        caseOf: {
75f1f73b3bf9 added: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2869
diff changeset
  1423
            [val1] -> [ caseStats1 ].
75f1f73b3bf9 added: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2869
diff changeset
  1424
            [val2] -> [ caseStats2 ].
75f1f73b3bf9 added: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2869
diff changeset
  1425
            ...
75f1f73b3bf9 added: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2869
diff changeset
  1426
            [valN] -> [ caseStatsN ].
75f1f73b3bf9 added: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2869
diff changeset
  1427
        }
75f1f73b3bf9 added: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2869
diff changeset
  1428
        otherwise: [
75f1f73b3bf9 added: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2869
diff changeset
  1429
            otherStats
75f1f73b3bf9 added: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2869
diff changeset
  1430
        ].
75f1f73b3bf9 added: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2869
diff changeset
  1431
     also handles caseOf, without otherwise: arg.
75f1f73b3bf9 added: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2869
diff changeset
  1432
     Compiled as a nested if-statement.
75f1f73b3bf9 added: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2869
diff changeset
  1433
    "
75f1f73b3bf9 added: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2869
diff changeset
  1434
2893
0fe6659c742e changed: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2870
diff changeset
  1435
    |caseArg otherwiseArg checkAndCollectCases checkAndCollectCases2 caseValueExpressions caseBlocks elseBlock ifMessage|
2870
75f1f73b3bf9 added: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2869
diff changeset
  1436
75f1f73b3bf9 added: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2869
diff changeset
  1437
    checkAndCollectCases := 
75f1f73b3bf9 added: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2869
diff changeset
  1438
        [:expr :atEnd |
75f1f73b3bf9 added: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2869
diff changeset
  1439
            |numCasesAllocated caseNr caseValueExpression caseBlock|
75f1f73b3bf9 added: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2869
diff changeset
  1440
75f1f73b3bf9 added: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2869
diff changeset
  1441
            expr receiver isMessage ifFalse:[ ^ false].
75f1f73b3bf9 added: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2869
diff changeset
  1442
            expr selector = #'at:put:' ifFalse:[ ^ false].
75f1f73b3bf9 added: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2869
diff changeset
  1443
            "check if at: arg is an integer (the case-nr)"
75f1f73b3bf9 added: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2869
diff changeset
  1444
            expr arg1 isConstant ifFalse:[ ^ false].
75f1f73b3bf9 added: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2869
diff changeset
  1445
            (caseNr := expr arg1 value) isInteger ifFalse:[ ^ false].
75f1f73b3bf9 added: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2869
diff changeset
  1446
            "check if put: arg is []->[] (the case-spec)"
75f1f73b3bf9 added: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2869
diff changeset
  1447
            expr arg2 isMessage ifFalse:[ ^ false].
75f1f73b3bf9 added: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2869
diff changeset
  1448
            expr arg2 selector == #'->' ifFalse:[ ^ false].
75f1f73b3bf9 added: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2869
diff changeset
  1449
            expr arg2 receiver isBlock ifFalse:[ ^ false].
75f1f73b3bf9 added: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2869
diff changeset
  1450
            (caseBlock := expr arg2 arg1) isBlock ifFalse:[ ^ false].
75f1f73b3bf9 added: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2869
diff changeset
  1451
            "the case-value-block must consist of a single expression"
75f1f73b3bf9 added: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2869
diff changeset
  1452
            expr arg2 receiver isSingleExpressionBlock ifFalse:[ ^ false].
75f1f73b3bf9 added: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2869
diff changeset
  1453
            (caseValueExpression := expr arg2 receiver simpleSendBlockExpression) notNil ifFalse:[ ^ false].
75f1f73b3bf9 added: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2869
diff changeset
  1454
            caseValueExpressions isEmptyOrNil ifTrue:[
75f1f73b3bf9 added: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2869
diff changeset
  1455
                caseValueExpressions := OrderedCollection withSize:caseNr.
75f1f73b3bf9 added: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2869
diff changeset
  1456
                caseBlocks := OrderedCollection withSize:caseNr.
75f1f73b3bf9 added: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2869
diff changeset
  1457
            ].
75f1f73b3bf9 added: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2869
diff changeset
  1458
            caseValueExpressions at:caseNr put:caseValueExpression.
75f1f73b3bf9 added: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2869
diff changeset
  1459
            caseBlocks at:caseNr put:caseBlock.
75f1f73b3bf9 added: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2869
diff changeset
  1460
75f1f73b3bf9 added: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2869
diff changeset
  1461
            atEnd ifFalse: [
75f1f73b3bf9 added: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2869
diff changeset
  1462
                expr receiver isCascade ifTrue:[
75f1f73b3bf9 added: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2869
diff changeset
  1463
                    "at the left, there must be another cascade"
75f1f73b3bf9 added: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2869
diff changeset
  1464
                    checkAndCollectCases value:expr receiver value:false.
75f1f73b3bf9 added: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2869
diff changeset
  1465
                ] ifFalse:[
75f1f73b3bf9 added: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2869
diff changeset
  1466
                    "at the left, there must be an (Array new:N) at:1 put:([]->[]) expression"
75f1f73b3bf9 added: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2869
diff changeset
  1467
                    checkAndCollectCases value:expr receiver value:true.
75f1f73b3bf9 added: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2869
diff changeset
  1468
                    expr receiver selector = #'at:put:' ifFalse:[ ^ false].
75f1f73b3bf9 added: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2869
diff changeset
  1469
                    expr receiver receiver isMessage ifFalse:[ ^ false].
75f1f73b3bf9 added: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2869
diff changeset
  1470
                    expr receiver receiver selector = #'new:' ifFalse:[ ^ false].
75f1f73b3bf9 added: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2869
diff changeset
  1471
                    expr receiver receiver receiver isGlobal ifFalse:[ ^ false].
75f1f73b3bf9 added: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2869
diff changeset
  1472
                    expr receiver receiver receiver name = 'Array' ifFalse:[^ false].
75f1f73b3bf9 added: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2869
diff changeset
  1473
                    expr receiver receiver arg1 isConstant ifFalse:[^ false].
75f1f73b3bf9 added: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2869
diff changeset
  1474
                    (numCasesAllocated := expr receiver receiver arg1 value) isInteger ifFalse:[^ false].
75f1f73b3bf9 added: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2869
diff changeset
  1475
                    numCasesAllocated = caseBlocks size ifFalse:[^ false].
75f1f73b3bf9 added: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2869
diff changeset
  1476
                ].
75f1f73b3bf9 added: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2869
diff changeset
  1477
            ].
75f1f73b3bf9 added: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2869
diff changeset
  1478
        ].
75f1f73b3bf9 added: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2869
diff changeset
  1479
2893
0fe6659c742e changed: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2870
diff changeset
  1480
    checkAndCollectCases2 :=    "/ for with:with: cases
0fe6659c742e changed: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2870
diff changeset
  1481
        [:expr |
0fe6659c742e changed: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2870
diff changeset
  1482
            |caseNr caseValueExpression caseBlock|
0fe6659c742e changed: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2870
diff changeset
  1483
0fe6659c742e changed: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2870
diff changeset
  1484
            expr args do:[:eachCaseArg |
0fe6659c742e changed: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2870
diff changeset
  1485
                "check if put: eachCaseArg is []->[] (the case-spec)"
0fe6659c742e changed: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2870
diff changeset
  1486
                eachCaseArg isMessage ifFalse:[ ^ false].
0fe6659c742e changed: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2870
diff changeset
  1487
                eachCaseArg selector == #'->' ifFalse:[ ^ false].
0fe6659c742e changed: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2870
diff changeset
  1488
                eachCaseArg receiver isBlock ifFalse:[ ^ false].
0fe6659c742e changed: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2870
diff changeset
  1489
                (caseBlock := eachCaseArg arg1) isBlock ifFalse:[ ^ false].
0fe6659c742e changed: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2870
diff changeset
  1490
                "the case-value-block must consist of a single expression"
0fe6659c742e changed: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2870
diff changeset
  1491
                eachCaseArg receiver isSingleExpressionBlock ifFalse:[ ^ false].
0fe6659c742e changed: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2870
diff changeset
  1492
                (caseValueExpression := eachCaseArg receiver simpleSendBlockExpression) notNil ifFalse:[ ^ false].
0fe6659c742e changed: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2870
diff changeset
  1493
                caseValueExpressions isEmptyOrNil ifTrue:[
0fe6659c742e changed: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2870
diff changeset
  1494
                    caseValueExpressions := OrderedCollection new.
0fe6659c742e changed: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2870
diff changeset
  1495
                    caseBlocks := OrderedCollection new.
0fe6659c742e changed: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2870
diff changeset
  1496
                ].
0fe6659c742e changed: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2870
diff changeset
  1497
                caseValueExpressions add:caseValueExpression.
0fe6659c742e changed: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2870
diff changeset
  1498
                caseBlocks add:caseBlock.
0fe6659c742e changed: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2870
diff changeset
  1499
            ].
0fe6659c742e changed: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2870
diff changeset
  1500
        ].
0fe6659c742e changed: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2870
diff changeset
  1501
2870
75f1f73b3bf9 added: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2869
diff changeset
  1502
    receiver isMessage ifTrue:[ ^ false].   "for now: I cannot introduce temporaries"
75f1f73b3bf9 added: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2869
diff changeset
  1503
75f1f73b3bf9 added: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2869
diff changeset
  1504
    caseArg := argArray at:1.
75f1f73b3bf9 added: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2869
diff changeset
  1505
    "caseArg has already been transformed from a {...}- to
2893
0fe6659c742e changed: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2870
diff changeset
  1506
     an Array-creating cascade expression or an Array-with:... expression"
2870
75f1f73b3bf9 added: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2869
diff changeset
  1507
    caseArg isCascade ifTrue:[
75f1f73b3bf9 added: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2869
diff changeset
  1508
        caseArg receiver isMessage ifFalse:[^ false].
75f1f73b3bf9 added: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2869
diff changeset
  1509
        checkAndCollectCases value:(caseArg receiver) value:false.
75f1f73b3bf9 added: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2869
diff changeset
  1510
    ] ifFalse:[
2893
0fe6659c742e changed: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2870
diff changeset
  1511
        (caseArg isMessage
0fe6659c742e changed: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2870
diff changeset
  1512
            and:[ (caseArg receiver isGlobalNamed:'Array')
0fe6659c742e changed: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2870
diff changeset
  1513
            and:[ 
0fe6659c742e changed: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2870
diff changeset
  1514
                #( 'with:'
0fe6659c742e changed: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2870
diff changeset
  1515
                   'with:with:' 
0fe6659c742e changed: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2870
diff changeset
  1516
                   'with:with:with:' 
0fe6659c742e changed: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2870
diff changeset
  1517
                   'with:with:with:with:' 
0fe6659c742e changed: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2870
diff changeset
  1518
                   'with:with:with:with:with:' 
0fe6659c742e changed: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2870
diff changeset
  1519
                   'with:with:with:with:with:with:' 
0fe6659c742e changed: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2870
diff changeset
  1520
                   'with:with:with:with:with:with:with:' 
0fe6659c742e changed: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2870
diff changeset
  1521
                   'with:with:with:with:with:with:with:with:' 
0fe6659c742e changed: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2870
diff changeset
  1522
                    ) includes:caseArg selector ]
0fe6659c742e changed: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2870
diff changeset
  1523
        ]) ifTrue:[
0fe6659c742e changed: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2870
diff changeset
  1524
            checkAndCollectCases2 value:caseArg.
0fe6659c742e changed: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2870
diff changeset
  1525
        ] ifFalse:[
0fe6659c742e changed: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2870
diff changeset
  1526
            "whenever an explicit Array-expression is used here, add support below"
0fe6659c742e changed: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2870
diff changeset
  1527
            ^ false
0fe6659c742e changed: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2870
diff changeset
  1528
        ].
2870
75f1f73b3bf9 added: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2869
diff changeset
  1529
    ].
75f1f73b3bf9 added: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2869
diff changeset
  1530
    argArray size > 1 ifTrue:[
75f1f73b3bf9 added: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2869
diff changeset
  1531
        otherwiseArg := argArray at:2.
75f1f73b3bf9 added: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2869
diff changeset
  1532
        otherwiseArg isBlock ifFalse:[^ false]
75f1f73b3bf9 added: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2869
diff changeset
  1533
    ].
75f1f73b3bf9 added: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2869
diff changeset
  1534
    "compile as a nested if"
75f1f73b3bf9 added: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2869
diff changeset
  1535
75f1f73b3bf9 added: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2869
diff changeset
  1536
    elseBlock := otherwiseArg.
75f1f73b3bf9 added: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2869
diff changeset
  1537
    caseValueExpressions with:caseBlocks reverseDo:[:eachCaseValueExpression :eachCaseBlock |
75f1f73b3bf9 added: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2869
diff changeset
  1538
        |cond|
75f1f73b3bf9 added: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2869
diff changeset
  1539
75f1f73b3bf9 added: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2869
diff changeset
  1540
        cond := MessageNode receiver:receiver selector:#'=' arg:eachCaseValueExpression.
75f1f73b3bf9 added: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2869
diff changeset
  1541
        ifMessage := MessageNode
75f1f73b3bf9 added: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2869
diff changeset
  1542
                        receiver:cond
75f1f73b3bf9 added: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2869
diff changeset
  1543
                        selector:#'ifTrue:ifFalse:'
75f1f73b3bf9 added: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2869
diff changeset
  1544
                        arg1:eachCaseBlock
75f1f73b3bf9 added: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2869
diff changeset
  1545
                        arg2:elseBlock.
75f1f73b3bf9 added: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2869
diff changeset
  1546
        elseBlock := BlockNode withExpression:ifMessage in:b.
75f1f73b3bf9 added: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2869
diff changeset
  1547
    ].
75f1f73b3bf9 added: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2869
diff changeset
  1548
    ifMessage codeOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler.
75f1f73b3bf9 added: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2869
diff changeset
  1549
    ^ true
75f1f73b3bf9 added: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2869
diff changeset
  1550
75f1f73b3bf9 added: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2869
diff changeset
  1551
    "Created: / 25-05-2012 / 11:28:27 / cg"
75f1f73b3bf9 added: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2869
diff changeset
  1552
!
75f1f73b3bf9 added: #codeCaseOfOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2869
diff changeset
  1553
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1554
codeForCascadeOn:aStream inBlock:b for:aCompiler
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1555
    "like codeOn, but always leave the receiver instead of the result"
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1556
1809
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  1557
    |nargs isBuiltIn code litIndex cls clsLitIndex isSuper realReceiver noSendDrop|
1048
6eaeba225e67 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1046
diff changeset
  1558
1500
3c4cb012b24b Lazy conversion of selector strings to symbols.
Stefan Vogel <sv@exept.de>
parents: 1480
diff changeset
  1559
    selector := selector asSymbol.
1048
6eaeba225e67 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1046
diff changeset
  1560
    noSendDrop := aCompiler class newCodeSet == true.
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1561
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1562
    realReceiver := self realReceiver.
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1563
    isSuper := realReceiver isSuper.
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1564
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1565
    argArray isNil ifTrue:[
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1566
        nargs := 0
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1567
    ] ifFalse:[
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1568
        nargs := argArray size
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1569
    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1570
1809
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  1571
    isBuiltIn := isSuper not and:[ aCompiler isBuiltInSelector:selector forReceiver:receiver ].
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  1572
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  1573
    litIndex := aCompiler addLiteral:selector.
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1574
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1575
    receiver codeOn:aStream inBlock:b for:aCompiler.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1576
    aStream nextPut:#dup.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1577
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1578
    "can we use a send-bytecode ?"
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1579
    isBuiltIn ifTrue:[
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1580
        (nargs > 0) ifTrue:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1581
            (argArray at:1) codeOn:aStream inBlock:b for:aCompiler.
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1582
            (nargs > 1) ifTrue:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1583
                (argArray at:2) codeOn:aStream inBlock:b for:aCompiler
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1584
            ]
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1585
        ].
3108
805f9d928eda Emit LINE16 bytecode insn just before a SEND bytecode is emmited when
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3017
diff changeset
  1586
        lineNr >= 255 ifTrue:[
3164
f11d0862c65e Emit #lineno16 byte codes only, if line number really changes
Stefan Vogel <sv@exept.de>
parents: 3108
diff changeset
  1587
            self codeLineNumber: lineNr on: aStream for:aCompiler.  
3108
805f9d928eda Emit LINE16 bytecode insn just before a SEND bytecode is emmited when
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3017
diff changeset
  1588
        ].
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1589
        aStream nextPut:selector.
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1590
        (aCompiler hasLineNumber:selector) ifTrue:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1591
            aStream nextPut:lineNr.
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1592
        ].
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1593
        aStream nextPut:#drop.
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1594
        ^ self
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1595
    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1596
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1597
    "no - generate a send"
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1598
    argArray notNil ifTrue:[
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1599
        argArray do:[:arg |
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1600
            arg codeOn:aStream inBlock:b for:aCompiler
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1601
        ]
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1602
    ].
189
673580572edd fixed cascades involving super sends (i.e. super foo; bar)
Claus Gittinger <cg@exept.de>
parents: 186
diff changeset
  1603
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1604
    isSuper ifTrue:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1605
        cls := aCompiler targetClass.
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1606
        realReceiver isHere ifTrue:[
1809
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  1607
            "/ same code as supersend, but targetClass starts search
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1608
        ] ifFalse:[
1809
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  1609
            "/ targetClasses superclass starts search
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1610
            cls := cls superclass.
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1611
        ].
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1612
        clsLitIndex := aCompiler addLiteral:cls.
3164
f11d0862c65e Emit #lineno16 byte codes only, if line number really changes
Stefan Vogel <sv@exept.de>
parents: 3108
diff changeset
  1613
        self emitSuperSendLiteralIndex:litIndex classLiteralIndex:clsLitIndex numArgs:nargs line:lineNr on:aStream for:aCompiler.
1809
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  1614
        aStream nextPut:#drop.
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1615
        ^ self
189
673580572edd fixed cascades involving super sends (i.e. super foo; bar)
Claus Gittinger <cg@exept.de>
parents: 186
diff changeset
  1616
    ].
673580572edd fixed cascades involving super sends (i.e. super foo; bar)
Claus Gittinger <cg@exept.de>
parents: 186
diff changeset
  1617
1809
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  1618
    noSendDrop ifFalse:[
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  1619
        litIndex <= 255 ifTrue:[
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  1620
            (nargs <= 3) ifTrue:[
1046
8e5818442eb9 newCode (for rel5)
Claus Gittinger <cg@exept.de>
parents: 1045
diff changeset
  1621
                code := #(sendDrop0 sendDrop1 sendDrop2 sendDrop3) at:(nargs+1).
3108
805f9d928eda Emit LINE16 bytecode insn just before a SEND bytecode is emmited when
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3017
diff changeset
  1622
                lineNr >= 255 ifTrue:[
3164
f11d0862c65e Emit #lineno16 byte codes only, if line number really changes
Stefan Vogel <sv@exept.de>
parents: 3108
diff changeset
  1623
                    self codeLineNumber: lineNr on: aStream for:aCompiler.  
3108
805f9d928eda Emit LINE16 bytecode insn just before a SEND bytecode is emmited when
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3017
diff changeset
  1624
                ].
1046
8e5818442eb9 newCode (for rel5)
Claus Gittinger <cg@exept.de>
parents: 1045
diff changeset
  1625
                aStream nextPut:code; nextPut:lineNr; nextPut:litIndex.
1809
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  1626
                ^ self
1046
8e5818442eb9 newCode (for rel5)
Claus Gittinger <cg@exept.de>
parents: 1045
diff changeset
  1627
            ].
3108
805f9d928eda Emit LINE16 bytecode insn just before a SEND bytecode is emmited when
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3017
diff changeset
  1628
            lineNr >= 255 ifTrue:[
3164
f11d0862c65e Emit #lineno16 byte codes only, if line number really changes
Stefan Vogel <sv@exept.de>
parents: 3108
diff changeset
  1629
                self codeLineNumber: lineNr on: aStream for:aCompiler.  
3108
805f9d928eda Emit LINE16 bytecode insn just before a SEND bytecode is emmited when
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3017
diff changeset
  1630
            ].
1809
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  1631
            aStream nextPut:#sendDrop; nextPut:lineNr; nextPut:litIndex; nextPut:nargs.
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1632
            ^ self
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1633
        ].
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1634
    ].
1809
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  1635
3164
f11d0862c65e Emit #lineno16 byte codes only, if line number really changes
Stefan Vogel <sv@exept.de>
parents: 3108
diff changeset
  1636
    self emitSendLiteralIndex:litIndex numArgs:nargs line:lineNr on:aStream for:aCompiler.
1809
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  1637
    aStream nextPut:#drop.
189
673580572edd fixed cascades involving super sends (i.e. super foo; bar)
Claus Gittinger <cg@exept.de>
parents: 186
diff changeset
  1638
3108
805f9d928eda Emit LINE16 bytecode insn just before a SEND bytecode is emmited when
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3017
diff changeset
  1639
    "Modified: / 04-07-1999 / 19:06:53 / cg"
805f9d928eda Emit LINE16 bytecode insn just before a SEND bytecode is emmited when
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3017
diff changeset
  1640
    "Modified: / 13-04-2013 / 10:49:55 / Jan Vrany <jan.vrany@fit.cvut.cz>"
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1641
!
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1642
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1643
codeForSideEffectOn:aStream inBlock:b for:aCompiler
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1644
    self codeOn:aStream inBlock:b valueNeeded:false for:aCompiler
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1645
!
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1646
843
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1647
codeForSimpleReturnOn:aStream inBlock:b lineNumber:lineNrOrNil for:aCompiler
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1648
    |arg1 rightExpr pos1|
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1649
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1650
    (selector == #and:
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1651
    or:[selector == #or:]) ifTrue:[
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1652
        arg1 := argArray at:1.
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1653
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1654
        "/ for now:
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1655
        "/ only do it for non-blocks, since
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1656
        "/ the JIT compiler is smart enough to
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1657
        "/ specially optimize the resulting code
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1658
        "/ (and not smart enough to optimized the
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1659
        "/  other - actually more efficient - code)
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1660
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1661
        (arg1 isBlock not 
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1662
"/        or:[arg1 isInlinable]
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1663
        ) ifTrue:[
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1664
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1665
            "/ encode #and: as:
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1666
            "/
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1667
            "/      eLeft
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1668
            "/      jmp_false       LBL
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1669
            "/      eRight
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1670
            "/      retTop
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1671
            "/  LBL:
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1672
            "/      retFalse
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1673
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1674
            "/ encode #or: as:
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1675
            "/
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1676
            "/      eLeft
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1677
            "/      jmp_true       LBL
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1678
            "/      eRight
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1679
            "/      retTop
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1680
            "/  LBL:
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1681
            "/      retTrue
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1682
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1683
            receiver codeOn:aStream inBlock:b for:aCompiler.
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1684
            selector == #and: ifTrue:[
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1685
                aStream nextPut:#falseJump.
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1686
            ] ifFalse:[
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1687
                aStream nextPut:#trueJump.
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1688
            ].
3266
96ed152db6df class: MessageNode
Stefan Vogel <sv@exept.de>
parents: 3164
diff changeset
  1689
            pos1 := aStream position + 1.
843
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1690
            aStream nextPut:0.
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1691
        
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1692
            rightExpr := argArray at:1.
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1693
            rightExpr isBlock ifTrue:[
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1694
                rightExpr codeInlineOn:aStream inBlock:b valueNeeded:true for:aCompiler.
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1695
            ] ifFalse:[
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1696
                rightExpr codeOn:aStream inBlock:b for:aCompiler.
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1697
            ].
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1698
            aStream nextPut:#retTop.
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1699
        
3266
96ed152db6df class: MessageNode
Stefan Vogel <sv@exept.de>
parents: 3164
diff changeset
  1700
            (aStream contents) at:pos1 put:(aStream position + 1).
843
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1701
            selector == #and: ifTrue:[
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1702
                aStream nextPut:#retFalse.
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1703
            ] ifFalse:[
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1704
                aStream nextPut:#retTrue
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1705
            ].
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1706
            ^ self.
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1707
        ].
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1708
    ].
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1709
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1710
    super
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1711
        codeForSimpleReturnOn:aStream 
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1712
        inBlock:b 
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1713
        lineNumber:lineNrOrNil 
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1714
        for:aCompiler
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1715
!
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1716
104
claus
parents: 103
diff changeset
  1717
codeIfElseOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1718
    "generate code for x ifxxx:[ ... ] yyy:[ ...]"
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1719
334
cd7491b7ad33 dont code a jump after if-part if it ends in a return.
Claus Gittinger <cg@exept.de>
parents: 309
diff changeset
  1720
    |pos pos2 theReceiver theArg theByteCode optByteCode subsel code needLineNr
1059
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1721
     needJump block1 block2|
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1722
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1723
    theReceiver := receiver.
76
55d64cb1ffea *** empty log message ***
claus
parents: 75
diff changeset
  1724
992
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1725
    theReceiver isConstant ifTrue:[
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1726
        (self tryFoldedIfOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler) ifTrue:[
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1727
            ^ self
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1728
        ].
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1729
    ].
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1730
76
55d64cb1ffea *** empty log message ***
claus
parents: 75
diff changeset
  1731
    (theReceiver isMessage) ifTrue:[
992
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1732
        subsel := theReceiver selector.
2399
57ba9eb8c502 changed: #codeIfElseOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2384
diff changeset
  1733
        ((subsel == #and:) and:[theReceiver arg1 isBlock and:[theReceiver arg1 isInlinable]]) ifTrue:[
992
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1734
            self codeAndIfElseOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler.
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1735
            ^ self
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1736
        ].
2399
57ba9eb8c502 changed: #codeIfElseOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2384
diff changeset
  1737
        ((subsel == #or:) and:[theReceiver arg1 isBlock and:[theReceiver arg1 isInlinable]]) ifTrue:[
992
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1738
            self codeOrIfElseOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler.
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1739
            ^ self
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1740
        ]
76
55d64cb1ffea *** empty log message ***
claus
parents: 75
diff changeset
  1741
    ].
2399
57ba9eb8c502 changed: #codeIfElseOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2384
diff changeset
  1742
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1743
    (selector == #ifTrue:ifFalse:) ifTrue:[
992
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1744
        theByteCode := #falseJump
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1745
    ] ifFalse:[
1059
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1746
        theByteCode := #trueJump
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1747
    ].
1463
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  1748
    optByteCode := self optimizedConditionFor:theReceiver with:theByteCode for:aCompiler.
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1749
    optByteCode notNil ifTrue:[
992
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1750
        ((optByteCode == #eqJump) or:[optByteCode == #notEqJump]) ifTrue:[
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1751
            theArg := theReceiver arg1
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1752
        ].
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1753
        theReceiver := theReceiver receiver.
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1754
        theByteCode := optByteCode
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1755
    ].
1059
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1756
    theReceiver codeOn:aStream inBlock:b for:aCompiler.
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1757
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1758
    needLineNr := true.
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1759
    theArg isNil ifTrue:[
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1760
        theReceiver isMessage ifTrue:[
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1761
            (aCompiler hasLineNumber:(theReceiver selector)) ifTrue:[
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1762
                theReceiver lineNumber == lineNr ifTrue:[
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1763
                    needLineNr := false
992
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1764
                ]
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1765
            ]
1059
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1766
        ]
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1767
    ] ifFalse:[
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1768
        theArg codeOn:aStream inBlock:b for:aCompiler
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1769
    ].
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1770
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1771
    needLineNr ifTrue:[
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1772
        (lineNr between:1 and:255) ifTrue:[
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1773
            aStream nextPut:#lineno; nextPut:lineNr.
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1774
        ]
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1775
    ].
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1776
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1777
    aStream nextPut:theByteCode.
3266
96ed152db6df class: MessageNode
Stefan Vogel <sv@exept.de>
parents: 3164
diff changeset
  1778
    pos := aStream position + 1.
1059
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1779
    aStream nextPut:0.
1435
be9680c6145c factored out some common code (block-code and value-sending)
Claus Gittinger <cg@exept.de>
parents: 1425
diff changeset
  1780
    block1 := argArray at:1.
be9680c6145c factored out some common code (block-code and value-sending)
Claus Gittinger <cg@exept.de>
parents: 1425
diff changeset
  1781
    self codeBlockEvaluation:block1 on:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler.
be9680c6145c factored out some common code (block-code and value-sending)
Claus Gittinger <cg@exept.de>
parents: 1425
diff changeset
  1782
1059
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1783
    needJump := true.
1435
be9680c6145c factored out some common code (block-code and value-sending)
Claus Gittinger <cg@exept.de>
parents: 1425
diff changeset
  1784
    (block1 isBlock and:[block1 endsWithReturn]) ifTrue:[
be9680c6145c factored out some common code (block-code and value-sending)
Claus Gittinger <cg@exept.de>
parents: 1425
diff changeset
  1785
        needJump := false
1059
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1786
    ].
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1787
    needJump ifTrue:[
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1788
        aStream nextPut:#jump.
3266
96ed152db6df class: MessageNode
Stefan Vogel <sv@exept.de>
parents: 3164
diff changeset
  1789
        pos2 := aStream position + 1.
1059
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1790
        aStream nextPut:0.
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1791
    ].
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1792
    code := aStream contents.
3266
96ed152db6df class: MessageNode
Stefan Vogel <sv@exept.de>
parents: 3164
diff changeset
  1793
    code at:pos put:(aStream position + 1).
1059
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1794
    block2 := (argArray at:2).
1435
be9680c6145c factored out some common code (block-code and value-sending)
Claus Gittinger <cg@exept.de>
parents: 1425
diff changeset
  1795
    self codeBlockEvaluation:block2 on:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler.
1059
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1796
    needJump ifTrue:[
3266
96ed152db6df class: MessageNode
Stefan Vogel <sv@exept.de>
parents: 3164
diff changeset
  1797
        code at:pos2 put:(aStream position + 1)
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1798
    ]
166
9f6c57a3bce1 no line number bytecode in if-else if not needed
Claus Gittinger <cg@exept.de>
parents: 163
diff changeset
  1799
2399
57ba9eb8c502 changed: #codeIfElseOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2384
diff changeset
  1800
    "
57ba9eb8c502 changed: #codeIfElseOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2384
diff changeset
  1801
     |a|
57ba9eb8c502 changed: #codeIfElseOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2384
diff changeset
  1802
     (a size = 0 and:a isNil) ifTrue: [self halt.] ifFalse:[]
57ba9eb8c502 changed: #codeIfElseOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2384
diff changeset
  1803
    "
57ba9eb8c502 changed: #codeIfElseOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2384
diff changeset
  1804
57ba9eb8c502 changed: #codeIfElseOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2384
diff changeset
  1805
    "Modified: / 21-05-2010 / 15:39:15 / cg"
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1806
!
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1807
898
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1808
codeIfNilNotNilOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler
1034
d4f1640f1aad better code for #ifNil:ifNotNil:, if args are non-block consts
Claus Gittinger <cg@exept.de>
parents: 1017
diff changeset
  1809
    "generate code for x ifNil:[ ... ] ifNotNil:[...]
d4f1640f1aad better code for #ifNil:ifNotNil:, if args are non-block consts
Claus Gittinger <cg@exept.de>
parents: 1017
diff changeset
  1810
     or: x ifNil:const1 ifNotNil:const2"
898
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1811
1371
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  1812
    |pos pos2 theReceiver theArg theByteCode code
1059
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1813
     needLineNr block1 block2|
898
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1814
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1815
    theReceiver := receiver.
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1816
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1817
    (selector == #ifNil:ifNotNil:) ifTrue:[
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1818
        theByteCode := #notNilJump
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1819
    ] ifFalse:[
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1820
        theByteCode := #nilJump
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1821
    ].
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1822
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1823
    theReceiver codeOn:aStream inBlock:b for:aCompiler.
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1824
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1825
    needLineNr := true.
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1826
    theArg isNil ifTrue:[
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1827
        theReceiver isMessage ifTrue:[
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1828
            (aCompiler hasLineNumber:(theReceiver selector)) ifTrue:[
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1829
                theReceiver lineNumber == lineNr ifTrue:[
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1830
                    needLineNr := false
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1831
                ]
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1832
            ]
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1833
        ]
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1834
    ].
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1835
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1836
    needLineNr ifTrue:[
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1837
        (lineNr between:1 and:255) ifTrue:[
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1838
            aStream nextPut:#lineno; nextPut:lineNr.
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1839
        ]
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1840
    ].
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1841
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1842
    aStream nextPut:theByteCode.
3266
96ed152db6df class: MessageNode
Stefan Vogel <sv@exept.de>
parents: 3164
diff changeset
  1843
    pos := aStream position + 1.
898
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1844
    aStream nextPut:0.
1059
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1845
    block1 := argArray at: 1.
1435
be9680c6145c factored out some common code (block-code and value-sending)
Claus Gittinger <cg@exept.de>
parents: 1425
diff changeset
  1846
    self codeBlockEvaluation:block1 on:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler.
898
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1847
    aStream nextPut:#jump.
3266
96ed152db6df class: MessageNode
Stefan Vogel <sv@exept.de>
parents: 3164
diff changeset
  1848
    pos2 := aStream position + 1.
898
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1849
    aStream nextPut:0.
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1850
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1851
    code := aStream contents.
3266
96ed152db6df class: MessageNode
Stefan Vogel <sv@exept.de>
parents: 3164
diff changeset
  1852
    code at:pos put:(aStream position + 1).
1059
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1853
    block2 := argArray at: 2.
1435
be9680c6145c factored out some common code (block-code and value-sending)
Claus Gittinger <cg@exept.de>
parents: 1425
diff changeset
  1854
    self codeBlockEvaluation:block2 on:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler.
898
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1855
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1856
    code := aStream contents.
3266
96ed152db6df class: MessageNode
Stefan Vogel <sv@exept.de>
parents: 3164
diff changeset
  1857
    code at:pos2 put:(aStream position + 1)
898
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1858
1034
d4f1640f1aad better code for #ifNil:ifNotNil:, if args are non-block consts
Claus Gittinger <cg@exept.de>
parents: 1017
diff changeset
  1859
    "Modified: / 11.2.2000 / 12:50:36 / cg"
898
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1860
!
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1861
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1862
codeIfNilOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1863
    "generate code for x ifNil:[ ... ]"
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1864
1435
be9680c6145c factored out some common code (block-code and value-sending)
Claus Gittinger <cg@exept.de>
parents: 1425
diff changeset
  1865
    |pos theReceiver theByteCode code needLineNr|
898
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1866
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1867
    theReceiver := receiver.
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1868
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1869
    (selector == #ifNil:) ifTrue:[
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1870
        theByteCode := #notNilJump
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1871
    ] ifFalse:[
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1872
        theByteCode := #nilJump
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1873
    ].
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1874
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1875
    theReceiver codeOn:aStream inBlock:b for:aCompiler.
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1876
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1877
    needLineNr := true.
899
fb678b9e18a7 also inline ifNot:/ifNotNil: for non-block arg.
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  1878
fb678b9e18a7 also inline ifNot:/ifNotNil: for non-block arg.
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  1879
    theReceiver isMessage ifTrue:[
fb678b9e18a7 also inline ifNot:/ifNotNil: for non-block arg.
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  1880
        (aCompiler hasLineNumber:(theReceiver selector)) ifTrue:[
fb678b9e18a7 also inline ifNot:/ifNotNil: for non-block arg.
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  1881
            theReceiver lineNumber == lineNr ifTrue:[
fb678b9e18a7 also inline ifNot:/ifNotNil: for non-block arg.
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  1882
                needLineNr := false
898
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1883
            ]
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1884
        ]
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1885
    ].
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1886
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1887
    needLineNr ifTrue:[
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1888
        (lineNr between:1 and:255) ifTrue:[
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1889
            aStream nextPut:#lineno; nextPut:lineNr.
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1890
        ]
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1891
    ].
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1892
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1893
    valueNeeded ifTrue:[
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1894
        aStream nextPut:#dup.
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1895
    ].
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1896
    aStream nextPut:theByteCode.
3266
96ed152db6df class: MessageNode
Stefan Vogel <sv@exept.de>
parents: 3164
diff changeset
  1897
    pos := aStream position + 1.
898
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1898
    aStream nextPut:0.
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1899
    valueNeeded ifTrue:[
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1900
        aStream nextPut:#drop.
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1901
    ].
899
fb678b9e18a7 also inline ifNot:/ifNotNil: for non-block arg.
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  1902
1435
be9680c6145c factored out some common code (block-code and value-sending)
Claus Gittinger <cg@exept.de>
parents: 1425
diff changeset
  1903
    self codeBlockEvaluation:(argArray at: 1) on:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler.
898
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1904
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1905
    code := aStream contents.
3266
96ed152db6df class: MessageNode
Stefan Vogel <sv@exept.de>
parents: 3164
diff changeset
  1906
    code at:pos put:(aStream position + 1)
898
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1907
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1908
    "Modified: / 28.10.1997 / 18:33:42 / cg"
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1909
!
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1910
104
claus
parents: 103
diff changeset
  1911
codeIfOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1912
    "generate code for x ifxxx:[ ... ]"
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1913
103
claus
parents: 102
diff changeset
  1914
    |pos pos2 theReceiver theArg theByteCode optByteCode subsel code
1059
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1915
     needLineNr block|
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1916
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1917
    theReceiver := receiver.
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1918
992
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1919
    theReceiver isConstant ifTrue:[
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1920
        (self tryFoldedIfOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler) ifTrue:[
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1921
            ^ self
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1922
        ].
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1923
    ].
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1924
76
55d64cb1ffea *** empty log message ***
claus
parents: 75
diff changeset
  1925
    (theReceiver isMessage) ifTrue:[
992
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1926
        subsel := theReceiver selector.
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1927
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1928
        (subsel == #and:) ifTrue:[
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1929
            theReceiver arg1 isBlock ifTrue:[
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1930
                self codeAndIfOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler.
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1931
                ^ self
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1932
            ]
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1933
        ].
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1934
        (subsel == #or:) ifTrue:[
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1935
            theReceiver arg1 isBlock ifTrue:[
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1936
                self codeOrIfOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler.
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1937
                ^ self
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1938
            ]
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1939
        ].
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1940
    ].
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1941
    (selector == #ifTrue:) ifTrue:[
992
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1942
        theByteCode := #falseJump
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1943
    ] ifFalse:[
992
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1944
        theByteCode := #trueJump
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1945
    ].
1463
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  1946
    optByteCode := self optimizedConditionFor:theReceiver with:theByteCode for:aCompiler.
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1947
    optByteCode notNil ifTrue:[
992
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1948
        ((optByteCode == #eqJump) or:[optByteCode == #notEqJump]) ifTrue:[
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1949
            theArg := theReceiver arg1
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1950
        ].
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1951
        theReceiver := theReceiver receiver.
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1952
        theByteCode := optByteCode
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1953
    ].
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1954
104
claus
parents: 103
diff changeset
  1955
    theReceiver codeOn:aStream inBlock:b for:aCompiler.
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1956
    theArg notNil ifTrue:[
992
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1957
        theArg codeOn:aStream inBlock:b for:aCompiler
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1958
    ].
53
c5dd7abf8431 *** empty log message ***
claus
parents: 52
diff changeset
  1959
103
claus
parents: 102
diff changeset
  1960
    needLineNr := true.
claus
parents: 102
diff changeset
  1961
    theArg isNil ifTrue:[
992
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1962
        theReceiver isMessage ifTrue:[
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1963
            (aCompiler hasLineNumber:(theReceiver selector)) ifTrue:[
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1964
                theReceiver lineNumber == lineNr ifTrue:[
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1965
                    needLineNr := false
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1966
                ]
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1967
            ]
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1968
        ]
103
claus
parents: 102
diff changeset
  1969
    ].
claus
parents: 102
diff changeset
  1970
claus
parents: 102
diff changeset
  1971
    needLineNr ifTrue:[
992
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1972
        (lineNr between:1 and:255) ifTrue:[
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1973
            aStream nextPut:#lineno; nextPut:lineNr.
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1974
        ]
53
c5dd7abf8431 *** empty log message ***
claus
parents: 52
diff changeset
  1975
    ].
c5dd7abf8431 *** empty log message ***
claus
parents: 52
diff changeset
  1976
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1977
    aStream nextPut:theByteCode.
3266
96ed152db6df class: MessageNode
Stefan Vogel <sv@exept.de>
parents: 3164
diff changeset
  1978
    pos := aStream position + 1.
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1979
    aStream nextPut:0.
1059
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1980
    block := (argArray at:1).
1435
be9680c6145c factored out some common code (block-code and value-sending)
Claus Gittinger <cg@exept.de>
parents: 1425
diff changeset
  1981
be9680c6145c factored out some common code (block-code and value-sending)
Claus Gittinger <cg@exept.de>
parents: 1425
diff changeset
  1982
    self codeBlockEvaluation:block on:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler.
76
55d64cb1ffea *** empty log message ***
claus
parents: 75
diff changeset
  1983
55d64cb1ffea *** empty log message ***
claus
parents: 75
diff changeset
  1984
    code := aStream contents.
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1985
    valueNeeded ifTrue:[
992
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1986
        aStream nextPut:#jump.
3266
96ed152db6df class: MessageNode
Stefan Vogel <sv@exept.de>
parents: 3164
diff changeset
  1987
        pos2 := aStream position + 1.
992
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1988
        aStream nextPut:0.
3266
96ed152db6df class: MessageNode
Stefan Vogel <sv@exept.de>
parents: 3164
diff changeset
  1989
        code at:pos put:(aStream position + 1).
992
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1990
        aStream nextPut:#pushNil.
3266
96ed152db6df class: MessageNode
Stefan Vogel <sv@exept.de>
parents: 3164
diff changeset
  1991
        code at:pos2 put:(aStream position + 1)
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1992
    ] ifFalse:[
3266
96ed152db6df class: MessageNode
Stefan Vogel <sv@exept.de>
parents: 3164
diff changeset
  1993
        code at:pos put:(aStream position + 1)
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1994
    ]
308
fe3b95e6d9c0 oops - dont try to inline: (expr or:expr2) ifXXX
Claus Gittinger <cg@exept.de>
parents: 289
diff changeset
  1995
627
b29a02258247 comments
Claus Gittinger <cg@exept.de>
parents: 624
diff changeset
  1996
    "Modified: / 28.10.1997 / 18:33:42 / cg"
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1997
!
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1998
338
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1999
codeOrIfElseOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  2000
    "generate code for (x or:[y]) ifxxx:[ ... ] ifyyy:[ ... ]"
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  2001
1057
97ef980e2a46 better code for
Claus Gittinger <cg@exept.de>
parents: 1048
diff changeset
  2002
    |theByteCode optByteCode theReceiver theArg pos1 pos2 pos3 code here jmp
1059
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  2003
     block1 block2 optJmp blockExpr|
338
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  2004
1464
fa19f86d1ef4 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1463
diff changeset
  2005
    aCompiler addLiteral:#or:.
fa19f86d1ef4 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1463
diff changeset
  2006
338
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  2007
    theByteCode := #trueJump.
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  2008
    theReceiver := receiver receiver.
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  2009
1463
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  2010
    optByteCode := self optimizedConditionFor:theReceiver with:theByteCode for:aCompiler.
338
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  2011
    optByteCode notNil ifTrue:[
1057
97ef980e2a46 better code for
Claus Gittinger <cg@exept.de>
parents: 1048
diff changeset
  2012
        ((optByteCode == #eqJump) or:[optByteCode == #notEqJump]) ifTrue:[
97ef980e2a46 better code for
Claus Gittinger <cg@exept.de>
parents: 1048
diff changeset
  2013
            theArg := theReceiver arg1
97ef980e2a46 better code for
Claus Gittinger <cg@exept.de>
parents: 1048
diff changeset
  2014
        ].
97ef980e2a46 better code for
Claus Gittinger <cg@exept.de>
parents: 1048
diff changeset
  2015
        theReceiver := theReceiver receiver.
97ef980e2a46 better code for
Claus Gittinger <cg@exept.de>
parents: 1048
diff changeset
  2016
        theByteCode := optByteCode
338
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  2017
    ].
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  2018
    "/ code the left-of the or-part
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  2019
    theReceiver codeOn:aStream inBlock:b for:aCompiler.
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  2020
    theArg notNil ifTrue:[
1057
97ef980e2a46 better code for
Claus Gittinger <cg@exept.de>
parents: 1048
diff changeset
  2021
        theArg codeOn:aStream inBlock:b for:aCompiler
338
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  2022
    ].
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  2023
    aStream nextPut:theByteCode.
3266
96ed152db6df class: MessageNode
Stefan Vogel <sv@exept.de>
parents: 3164
diff changeset
  2024
    pos1 := aStream position + 1.   "/ remember branch target of left-ok branch
338
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  2025
    aStream nextPut:0.
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  2026
1057
97ef980e2a46 better code for
Claus Gittinger <cg@exept.de>
parents: 1048
diff changeset
  2027
    "/ code the right of the or-part
338
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  2028
    (selector == #ifTrue:ifFalse:) ifTrue:[
1057
97ef980e2a46 better code for
Claus Gittinger <cg@exept.de>
parents: 1048
diff changeset
  2029
        jmp := #falseJump
338
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  2030
    ] ifFalse:[
1057
97ef980e2a46 better code for
Claus Gittinger <cg@exept.de>
parents: 1048
diff changeset
  2031
        jmp := #trueJump
97ef980e2a46 better code for
Claus Gittinger <cg@exept.de>
parents: 1048
diff changeset
  2032
    ].
97ef980e2a46 better code for
Claus Gittinger <cg@exept.de>
parents: 1048
diff changeset
  2033
    theReceiver := receiver arg1.
97ef980e2a46 better code for
Claus Gittinger <cg@exept.de>
parents: 1048
diff changeset
  2034
    theArg := nil.
97ef980e2a46 better code for
Claus Gittinger <cg@exept.de>
parents: 1048
diff changeset
  2035
    optJmp := nil.
97ef980e2a46 better code for
Claus Gittinger <cg@exept.de>
parents: 1048
diff changeset
  2036
97ef980e2a46 better code for
Claus Gittinger <cg@exept.de>
parents: 1048
diff changeset
  2037
    (theReceiver isBlock
97ef980e2a46 better code for
Claus Gittinger <cg@exept.de>
parents: 1048
diff changeset
  2038
    and:[theReceiver statements notNil
97ef980e2a46 better code for
Claus Gittinger <cg@exept.de>
parents: 1048
diff changeset
  2039
    and:[theReceiver statements nextStatement isNil]]) ifTrue:[
97ef980e2a46 better code for
Claus Gittinger <cg@exept.de>
parents: 1048
diff changeset
  2040
        blockExpr := theReceiver statements expression.
1463
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  2041
        optJmp := self optimizedConditionFor:blockExpr with:jmp for:aCompiler.
1057
97ef980e2a46 better code for
Claus Gittinger <cg@exept.de>
parents: 1048
diff changeset
  2042
        optJmp notNil ifTrue:[
97ef980e2a46 better code for
Claus Gittinger <cg@exept.de>
parents: 1048
diff changeset
  2043
            ((optJmp == #eqJump) or:[optJmp == #notEqJump]) ifTrue:[
97ef980e2a46 better code for
Claus Gittinger <cg@exept.de>
parents: 1048
diff changeset
  2044
                theArg := blockExpr arg1
97ef980e2a46 better code for
Claus Gittinger <cg@exept.de>
parents: 1048
diff changeset
  2045
            ].
97ef980e2a46 better code for
Claus Gittinger <cg@exept.de>
parents: 1048
diff changeset
  2046
            theReceiver := blockExpr receiver.
97ef980e2a46 better code for
Claus Gittinger <cg@exept.de>
parents: 1048
diff changeset
  2047
            jmp := optJmp
97ef980e2a46 better code for
Claus Gittinger <cg@exept.de>
parents: 1048
diff changeset
  2048
        ].
97ef980e2a46 better code for
Claus Gittinger <cg@exept.de>
parents: 1048
diff changeset
  2049
    ].
97ef980e2a46 better code for
Claus Gittinger <cg@exept.de>
parents: 1048
diff changeset
  2050
97ef980e2a46 better code for
Claus Gittinger <cg@exept.de>
parents: 1048
diff changeset
  2051
    optJmp notNil ifTrue:[
97ef980e2a46 better code for
Claus Gittinger <cg@exept.de>
parents: 1048
diff changeset
  2052
        theReceiver codeOn:aStream inBlock:b for:aCompiler.
1058
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  2053
        theArg notNil ifTrue:[
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  2054
            theArg codeOn:aStream inBlock:b for:aCompiler
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  2055
        ]
1057
97ef980e2a46 better code for
Claus Gittinger <cg@exept.de>
parents: 1048
diff changeset
  2056
    ] ifFalse:[
97ef980e2a46 better code for
Claus Gittinger <cg@exept.de>
parents: 1048
diff changeset
  2057
        theReceiver codeInlineOn:aStream inBlock:b for:aCompiler.
338
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  2058
    ].
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  2059
    aStream nextPut:jmp.
3266
96ed152db6df class: MessageNode
Stefan Vogel <sv@exept.de>
parents: 3164
diff changeset
  2060
    pos2 := aStream position + 1.   "/ remember branch target of right-fail branch 
338
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  2061
    aStream nextPut:0.
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  2062
1057
97ef980e2a46 better code for
Claus Gittinger <cg@exept.de>
parents: 1048
diff changeset
  2063
338
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  2064
    code := aStream contents.
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  2065
    (selector == #ifTrue:ifFalse:) ifTrue:[
3266
96ed152db6df class: MessageNode
Stefan Vogel <sv@exept.de>
parents: 3164
diff changeset
  2066
        code at:pos1 put:(aStream position + 1)
338
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  2067
    ].
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  2068
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  2069
    "/ code the if-block
1059
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  2070
    block1 := argArray at: 1.
1435
be9680c6145c factored out some common code (block-code and value-sending)
Claus Gittinger <cg@exept.de>
parents: 1425
diff changeset
  2071
    self codeBlockEvaluation:block1 on:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler.
338
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  2072
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  2073
    aStream nextPut:#jump.
3266
96ed152db6df class: MessageNode
Stefan Vogel <sv@exept.de>
parents: 3164
diff changeset
  2074
    pos3 := aStream position + 1.
338
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  2075
    aStream nextPut:0.
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  2076
3266
96ed152db6df class: MessageNode
Stefan Vogel <sv@exept.de>
parents: 3164
diff changeset
  2077
    here := aStream position + 1.
338
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  2078
    (selector == #ifFalse:ifTrue:) ifTrue:[
1057
97ef980e2a46 better code for
Claus Gittinger <cg@exept.de>
parents: 1048
diff changeset
  2079
        code at:pos1 put:here
338
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  2080
    ].
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  2081
    code at:pos2 put:here.
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  2082
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  2083
    "/ code the else-block
1059
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  2084
    block2 := argArray at: 2.
1435
be9680c6145c factored out some common code (block-code and value-sending)
Claus Gittinger <cg@exept.de>
parents: 1425
diff changeset
  2085
    self codeBlockEvaluation:block2 on:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler.
3266
96ed152db6df class: MessageNode
Stefan Vogel <sv@exept.de>
parents: 3164
diff changeset
  2086
    code at:pos3 put:(aStream position + 1)
338
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  2087
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  2088
    "Created: 6.9.1996 / 13:08:52 / cg"
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  2089
!
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  2090
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2091
codeOrIfOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2092
    "generate code for (x or:[y]) ifxxx:[ ... ]"
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2093
1059
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  2094
    |theByteCode optByteCode theReceiver theArg pos1 pos2 pos3 code here jmp
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  2095
     block|
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2096
1464
fa19f86d1ef4 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1463
diff changeset
  2097
    aCompiler addLiteral:#or:.
fa19f86d1ef4 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1463
diff changeset
  2098
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2099
    theByteCode := #trueJump.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2100
    theReceiver := receiver receiver.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2101
1463
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  2102
    optByteCode := self optimizedConditionFor:theReceiver with:theByteCode for:aCompiler.
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2103
    optByteCode notNil ifTrue:[
1059
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  2104
        ((optByteCode == #eqJump) or:[optByteCode == #notEqJump]) ifTrue:[
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  2105
            theArg := theReceiver arg1
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  2106
        ].
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  2107
        theReceiver := theReceiver receiver.
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  2108
        theByteCode := optByteCode
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2109
    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2110
    theReceiver codeOn:aStream inBlock:b for:aCompiler.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2111
    theArg notNil ifTrue:[
1059
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  2112
        theArg codeOn:aStream inBlock:b for:aCompiler
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2113
    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2114
    aStream nextPut:theByteCode.
3266
96ed152db6df class: MessageNode
Stefan Vogel <sv@exept.de>
parents: 3164
diff changeset
  2115
    pos1 := aStream position + 1.
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2116
    aStream nextPut:0.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2117
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2118
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2119
    theReceiver := receiver arg1.
434
c48a356d8a34 oops - optimizable or: ... ifTrue/ifFalse generated
Claus Gittinger <cg@exept.de>
parents: 429
diff changeset
  2120
    theArg := nil.
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2121
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2122
"new:"
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2123
    (selector == #ifTrue:) ifTrue:[
1059
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  2124
        theByteCode := #falseJump
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2125
    ] ifFalse:[
1059
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  2126
        theByteCode := #trueJump
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2127
    ].
1463
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  2128
    optByteCode := self optimizedConditionFor:theReceiver with:theByteCode for:aCompiler.
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2129
    optByteCode notNil ifTrue:[
1059
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  2130
        theReceiver isBlock ifTrue:[
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  2131
            theReceiver := theReceiver statements expression
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  2132
        ].
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  2133
        ((optByteCode == #eqJump) or:[optByteCode == #notEqJump]) ifTrue:[
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  2134
            theArg := theReceiver arg1
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  2135
        ].
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  2136
        theReceiver := theReceiver receiver.
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  2137
        theByteCode := optByteCode.
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  2138
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  2139
        theReceiver codeOn:aStream inBlock:b for:aCompiler.
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  2140
        theArg notNil ifTrue:[
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  2141
            theArg codeOn:aStream inBlock:b for:aCompiler
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  2142
        ].
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  2143
        aStream nextPut:theByteCode.
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2144
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2145
    ] ifFalse:[
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2146
"org"
1059
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  2147
        theReceiver codeInlineOn:aStream inBlock:b for:aCompiler.
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  2148
        (selector == #ifTrue:) ifTrue:[
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  2149
            jmp := #falseJump
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  2150
        ] ifFalse:[
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  2151
            jmp := #trueJump
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  2152
        ].
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  2153
        aStream nextPut:jmp
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2154
    ].
3266
96ed152db6df class: MessageNode
Stefan Vogel <sv@exept.de>
parents: 3164
diff changeset
  2155
    pos2 := aStream position + 1.
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2156
    aStream nextPut:0.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2157
    (selector == #ifTrue:) ifTrue:[
3266
96ed152db6df class: MessageNode
Stefan Vogel <sv@exept.de>
parents: 3164
diff changeset
  2158
        (aStream contents) at:pos1 put:(aStream position + 1)
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2159
    ].
1059
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  2160
    block := argArray at: 1.
1435
be9680c6145c factored out some common code (block-code and value-sending)
Claus Gittinger <cg@exept.de>
parents: 1425
diff changeset
  2161
    self codeBlockEvaluation:block on:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler.
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2162
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2163
    code := aStream contents.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2164
    valueNeeded ifTrue:[
1059
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  2165
        aStream nextPut:#jump.
3266
96ed152db6df class: MessageNode
Stefan Vogel <sv@exept.de>
parents: 3164
diff changeset
  2166
        pos3 := aStream position + 1.
1059
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  2167
        aStream nextPut:0.
3266
96ed152db6df class: MessageNode
Stefan Vogel <sv@exept.de>
parents: 3164
diff changeset
  2168
        here := aStream position + 1.
1059
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  2169
        (selector == #ifFalse:) ifTrue:[
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  2170
            code at:pos1 put:here
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  2171
        ].
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  2172
        code at:pos2 put:here.
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  2173
        aStream nextPut:#pushNil.
3266
96ed152db6df class: MessageNode
Stefan Vogel <sv@exept.de>
parents: 3164
diff changeset
  2174
        code at:pos3 put:(aStream position + 1)
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2175
    ] ifFalse:[
3266
96ed152db6df class: MessageNode
Stefan Vogel <sv@exept.de>
parents: 3164
diff changeset
  2176
        here := aStream position + 1.
1059
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  2177
        (selector == #ifFalse:) ifTrue:[
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  2178
            code at:pos1 put:here
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  2179
        ].
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  2180
        code at:pos2 put:here
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2181
    ]
434
c48a356d8a34 oops - optimizable or: ... ifTrue/ifFalse generated
Claus Gittinger <cg@exept.de>
parents: 429
diff changeset
  2182
c48a356d8a34 oops - optimizable or: ... ifTrue/ifFalse generated
Claus Gittinger <cg@exept.de>
parents: 429
diff changeset
  2183
    "Modified: 9.11.1996 / 19:52:26 / cg"
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2184
!
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2185
289
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  2186
codeOrOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  2187
    "generate code for (x or:[y])"
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  2188
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  2189
    |pos1 rightExpr|
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  2190
1464
fa19f86d1ef4 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1463
diff changeset
  2191
    aCompiler addLiteral:#or:.
fa19f86d1ef4 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1463
diff changeset
  2192
289
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  2193
    receiver codeOn:aStream inBlock:b for:aCompiler.
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  2194
    valueNeeded ifTrue:[
1371
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2195
        aStream nextPut:#dup.
289
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  2196
    ].
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  2197
    aStream nextPut:#trueJump.
3266
96ed152db6df class: MessageNode
Stefan Vogel <sv@exept.de>
parents: 3164
diff changeset
  2198
    pos1 := aStream position + 1.
289
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  2199
    aStream nextPut:0.
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  2200
    valueNeeded ifTrue:[
1371
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2201
        aStream nextPut:#drop.
289
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  2202
    ].
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  2203
    rightExpr := argArray at:1.
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  2204
    rightExpr codeInlineOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler.
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  2205
3266
96ed152db6df class: MessageNode
Stefan Vogel <sv@exept.de>
parents: 3164
diff changeset
  2206
    (aStream contents) at:pos1 put:(aStream position + 1)
289
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  2207
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  2208
    "Created: 17.6.1996 / 15:40:22 / cg"
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  2209
    "Modified: 17.6.1996 / 15:47:22 / cg"
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  2210
!
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  2211
436
b34370bb0a74 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 434
diff changeset
  2212
codeQuestOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler
627
b29a02258247 comments
Claus Gittinger <cg@exept.de>
parents: 624
diff changeset
  2213
    "generate code for x ? y. 
b29a02258247 comments
Claus Gittinger <cg@exept.de>
parents: 624
diff changeset
  2214
     However, this is only done for non-send args."
436
b34370bb0a74 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 434
diff changeset
  2215
b34370bb0a74 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 434
diff changeset
  2216
    |pos code|
b34370bb0a74 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 434
diff changeset
  2217
1464
fa19f86d1ef4 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1463
diff changeset
  2218
    aCompiler addLiteral:#'?'.
fa19f86d1ef4 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1463
diff changeset
  2219
436
b34370bb0a74 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 434
diff changeset
  2220
    receiver codeOn:aStream inBlock:b for:aCompiler.
b34370bb0a74 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 434
diff changeset
  2221
    aStream nextPut:#dup.
b34370bb0a74 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 434
diff changeset
  2222
    aStream nextPut:#notNilJump.
3266
96ed152db6df class: MessageNode
Stefan Vogel <sv@exept.de>
parents: 3164
diff changeset
  2223
    pos := aStream position + 1.
437
994414f5126a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 436
diff changeset
  2224
    aStream nextPut:0.
436
b34370bb0a74 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 434
diff changeset
  2225
b34370bb0a74 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 434
diff changeset
  2226
    aStream nextPut:#drop.
b34370bb0a74 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 434
diff changeset
  2227
    (argArray at: 1) codeOn:aStream inBlock:b for:aCompiler.
b34370bb0a74 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 434
diff changeset
  2228
b34370bb0a74 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 434
diff changeset
  2229
    code := aStream contents.
3266
96ed152db6df class: MessageNode
Stefan Vogel <sv@exept.de>
parents: 3164
diff changeset
  2230
    code at:pos put:(aStream position + 1).
909
4917ac8408fb oops - inlined ? for-effect left value on top of stack
Claus Gittinger <cg@exept.de>
parents: 908
diff changeset
  2231
4917ac8408fb oops - inlined ? for-effect left value on top of stack
Claus Gittinger <cg@exept.de>
parents: 908
diff changeset
  2232
    valueNeeded ifFalse:[
4917ac8408fb oops - inlined ? for-effect left value on top of stack
Claus Gittinger <cg@exept.de>
parents: 908
diff changeset
  2233
        aStream nextPut:#drop.
4917ac8408fb oops - inlined ? for-effect left value on top of stack
Claus Gittinger <cg@exept.de>
parents: 908
diff changeset
  2234
    ].
436
b34370bb0a74 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 434
diff changeset
  2235
627
b29a02258247 comments
Claus Gittinger <cg@exept.de>
parents: 624
diff changeset
  2236
    "Created: / 10.11.1996 / 18:28:57 / cg"
b29a02258247 comments
Claus Gittinger <cg@exept.de>
parents: 624
diff changeset
  2237
    "Modified: / 28.10.1997 / 18:16:20 / cg"
436
b34370bb0a74 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 434
diff changeset
  2238
!
b34370bb0a74 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 434
diff changeset
  2239
602
1be5dd333adc inline #repeat
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  2240
codeRepeatOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler
1425
4f698bf5ff76 inline [...] loop
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
  2241
    "generate code for 
4f698bf5ff76 inline [...] loop
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
  2242
        [ ... ] repeat
4f698bf5ff76 inline [...] loop
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
  2243
     and:
4f698bf5ff76 inline [...] loop
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
  2244
        [ ... ] loop
4f698bf5ff76 inline [...] loop
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
  2245
    "
602
1be5dd333adc inline #repeat
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  2246
1be5dd333adc inline #repeat
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  2247
    |pos|
1be5dd333adc inline #repeat
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  2248
3266
96ed152db6df class: MessageNode
Stefan Vogel <sv@exept.de>
parents: 3164
diff changeset
  2249
    pos := aStream position + 1.
602
1be5dd333adc inline #repeat
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  2250
    receiver codeInlineOn:aStream inBlock:b valueNeeded:false for:aCompiler.
1be5dd333adc inline #repeat
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  2251
    aStream nextPut:#jump; nextPut:pos.
1be5dd333adc inline #repeat
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  2252
1be5dd333adc inline #repeat
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  2253
    "Created: 29.8.1997 / 08:14:58 / cg"
1be5dd333adc inline #repeat
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  2254
!
1be5dd333adc inline #repeat
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  2255
104
claus
parents: 103
diff changeset
  2256
codeSendOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2257
    "like code on, but assumes that receiver has already been
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2258
     coded onto stack - needed for cascade"
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2259
1809
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  2260
    |nargs isBuiltIn code litIndex cls clsLitIndex isSuper realReceiver 
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  2261
     noSendDrop alreadyDropped|
1045
ee448a958d19 migration support
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
  2262
1500
3c4cb012b24b Lazy conversion of selector strings to symbols.
Stefan Vogel <sv@exept.de>
parents: 1480
diff changeset
  2263
    selector := selector asSymbol.
1048
6eaeba225e67 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1046
diff changeset
  2264
    noSendDrop := aCompiler class newCodeSet == true.
861
ccaa0ba5e7af generate selector symbols late (when compiling or evaluating)
Claus Gittinger <cg@exept.de>
parents: 856
diff changeset
  2265
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2266
    realReceiver := self realReceiver.
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2267
    isSuper := realReceiver isSuper.
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2268
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2269
    argArray isNil ifTrue:[
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2270
        nargs := 0
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2271
    ] ifFalse:[
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2272
        nargs := argArray size
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2273
    ].
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2274
1809
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  2275
    litIndex := aCompiler addLiteral:selector.
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  2276
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  2277
    isBuiltIn := isSuper not and:[ aCompiler isBuiltInSelector:selector forReceiver:receiver ].
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2278
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2279
    "can we use a send-bytecode ?"
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2280
    isBuiltIn ifTrue:[
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2281
        (nargs > 0) ifTrue:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2282
            (argArray at:1) codeOn:aStream inBlock:b for:aCompiler.
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2283
            (nargs > 1) ifTrue:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2284
                (argArray at:2) codeOn:aStream inBlock:b for:aCompiler
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2285
            ]
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2286
        ].
3108
805f9d928eda Emit LINE16 bytecode insn just before a SEND bytecode is emmited when
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3017
diff changeset
  2287
        lineNr >= 255 ifTrue:[
3164
f11d0862c65e Emit #lineno16 byte codes only, if line number really changes
Stefan Vogel <sv@exept.de>
parents: 3108
diff changeset
  2288
            self codeLineNumber: lineNr on: aStream for:aCompiler.  
3108
805f9d928eda Emit LINE16 bytecode insn just before a SEND bytecode is emmited when
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3017
diff changeset
  2289
        ].
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2290
        aStream nextPut:selector.
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2291
        (aCompiler hasLineNumber:selector) ifTrue:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2292
            aStream nextPut:lineNr.
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2293
        ].
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2294
        valueNeeded ifFalse:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2295
            aStream nextPut:#drop
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2296
        ].
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2297
        ^ self
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2298
    ].
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2299
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2300
    argArray notNil ifTrue:[
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2301
        argArray do:[:arg |
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2302
            arg codeOn:aStream inBlock:b for:aCompiler
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2303
        ]
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2304
    ].
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2305
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2306
    isSuper ifTrue:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2307
        cls := aCompiler targetClass.
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2308
        realReceiver isHere ifTrue:[
1809
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  2309
            "/ same code as supersend, but targetClass starts search
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2310
        ] ifFalse:[
1809
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  2311
            "/ targetClasses superclass starts search
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2312
            cls := cls superclass.
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2313
        ].
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2314
        clsLitIndex := aCompiler addLiteral:cls.
3164
f11d0862c65e Emit #lineno16 byte codes only, if line number really changes
Stefan Vogel <sv@exept.de>
parents: 3108
diff changeset
  2315
        self emitSuperSendLiteralIndex:litIndex classLiteralIndex:clsLitIndex numArgs:nargs line:lineNr on:aStream for:aCompiler.
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2316
        valueNeeded ifFalse:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2317
            aStream nextPut:#drop
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2318
        ].
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2319
        ^ self
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2320
    ].
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2321
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2322
    (nargs == 0) ifTrue:[
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2323
        (selector == #yourself) ifTrue:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2324
            "yourself is often added to get the receiver -
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2325
             we get it without the yourself-message"
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2326
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2327
            valueNeeded ifFalse:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2328
                aStream nextPut:#drop
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2329
            ].
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2330
            ^ self
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2331
        ].
49
02660b790c3e *** empty log message ***
claus
parents: 48
diff changeset
  2332
    ].
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2333
1809
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  2334
    alreadyDropped := false.
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  2335
    valueNeeded ifTrue:[ noSendDrop := true ].
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  2336
117
claus
parents: 111
diff changeset
  2337
    litIndex <= 255 ifTrue:[
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2338
        (nargs <= 3) ifTrue:[
1809
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  2339
            noSendDrop ifTrue:[
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2340
                code := #(send0 send1 send2 send3) at:(nargs+1).
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2341
            ] ifFalse:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2342
                code := #(sendDrop0 sendDrop1 sendDrop2 sendDrop3) at:(nargs+1).
1809
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  2343
                alreadyDropped := true.
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2344
            ].
3108
805f9d928eda Emit LINE16 bytecode insn just before a SEND bytecode is emmited when
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3017
diff changeset
  2345
            lineNr >= 255 ifTrue:[
3164
f11d0862c65e Emit #lineno16 byte codes only, if line number really changes
Stefan Vogel <sv@exept.de>
parents: 3108
diff changeset
  2346
                self codeLineNumber: lineNr on: aStream for:aCompiler.  
3108
805f9d928eda Emit LINE16 bytecode insn just before a SEND bytecode is emmited when
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3017
diff changeset
  2347
            ].
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2348
            aStream nextPut:code; nextPut:lineNr; nextPut:litIndex.
1809
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  2349
            valueNeeded ifFalse:[
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  2350
                alreadyDropped ifFalse:[
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  2351
                    aStream nextPut:#drop
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  2352
                ].
1045
ee448a958d19 migration support
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
  2353
            ].
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2354
            ^ self
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2355
        ].
106
claus
parents: 104
diff changeset
  2356
1809
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  2357
        noSendDrop ifTrue:[
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2358
            code := #send
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2359
        ] ifFalse:[
1809
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  2360
            code := #sendDrop.
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  2361
            alreadyDropped := true.
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2362
        ].
3108
805f9d928eda Emit LINE16 bytecode insn just before a SEND bytecode is emmited when
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3017
diff changeset
  2363
        lineNr >= 255 ifTrue:[
3164
f11d0862c65e Emit #lineno16 byte codes only, if line number really changes
Stefan Vogel <sv@exept.de>
parents: 3108
diff changeset
  2364
            self codeLineNumber: lineNr on: aStream for:aCompiler.  
3108
805f9d928eda Emit LINE16 bytecode insn just before a SEND bytecode is emmited when
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3017
diff changeset
  2365
        ].
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2366
        aStream nextPut:code; nextPut:lineNr; nextPut:litIndex; nextPut:nargs.
1809
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  2367
        valueNeeded ifFalse:[
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  2368
            alreadyDropped ifFalse:[
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  2369
                aStream nextPut:#drop
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  2370
            ].
1045
ee448a958d19 migration support
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
  2371
        ].
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2372
        ^ self
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2373
    ].
49
02660b790c3e *** empty log message ***
claus
parents: 48
diff changeset
  2374
3164
f11d0862c65e Emit #lineno16 byte codes only, if line number really changes
Stefan Vogel <sv@exept.de>
parents: 3108
diff changeset
  2375
    self emitSendLiteralIndex:litIndex numArgs:nargs line:lineNr on:aStream for:aCompiler.
1809
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  2376
    valueNeeded ifFalse:[
1045
ee448a958d19 migration support
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
  2377
        aStream nextPut:#drop
ee448a958d19 migration support
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
  2378
    ].
189
673580572edd fixed cascades involving super sends (i.e. super foo; bar)
Claus Gittinger <cg@exept.de>
parents: 186
diff changeset
  2379
3108
805f9d928eda Emit LINE16 bytecode insn just before a SEND bytecode is emmited when
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3017
diff changeset
  2380
    "Modified: / 16-07-1998 / 20:26:52 / cg"
805f9d928eda Emit LINE16 bytecode insn just before a SEND bytecode is emmited when
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3017
diff changeset
  2381
    "Modified: / 13-04-2013 / 10:46:45 / Jan Vrany <jan.vrany@fit.cvut.cz>"
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2382
!
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2383
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2384
codeTimesRepeatOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2385
    "generate code for n timesRepeat:[ ... ]"
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2386
908
294e131f2f6d oops - 0 timesRepeat (with constant receiver) did it once
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  2387
    |pos1 pos2 lateEval loopCount|
349
7632e597a3df no need to keep receiver on stack for
Claus Gittinger <cg@exept.de>
parents: 338
diff changeset
  2388
7632e597a3df no need to keep receiver on stack for
Claus Gittinger <cg@exept.de>
parents: 338
diff changeset
  2389
    lateEval := false.
528
0a35ed44989f oops - timesRepeat dupped one too many
Claus Gittinger <cg@exept.de>
parents: 437
diff changeset
  2390
908
294e131f2f6d oops - 0 timesRepeat (with constant receiver) did it once
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  2391
    receiver isConstant ifTrue:[
294e131f2f6d oops - 0 timesRepeat (with constant receiver) did it once
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  2392
        loopCount := receiver evaluate.
856
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2393
        (loopCount isMemberOf:SmallInteger) ifFalse:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2394
            loopCount := nil.
908
294e131f2f6d oops - 0 timesRepeat (with constant receiver) did it once
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  2395
        ] ifTrue:[
294e131f2f6d oops - 0 timesRepeat (with constant receiver) did it once
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  2396
            loopCount <= 0 ifTrue:[
294e131f2f6d oops - 0 timesRepeat (with constant receiver) did it once
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  2397
                "/ thats it - all we need is the receiver on the stack
294e131f2f6d oops - 0 timesRepeat (with constant receiver) did it once
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  2398
                valueNeeded ifTrue:[
294e131f2f6d oops - 0 timesRepeat (with constant receiver) did it once
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  2399
                    receiver codeOn:aStream inBlock:b for:aCompiler.
294e131f2f6d oops - 0 timesRepeat (with constant receiver) did it once
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  2400
                ].
294e131f2f6d oops - 0 timesRepeat (with constant receiver) did it once
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  2401
                ^ self
294e131f2f6d oops - 0 timesRepeat (with constant receiver) did it once
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  2402
            ]
294e131f2f6d oops - 0 timesRepeat (with constant receiver) did it once
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  2403
        ].
856
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2404
    ].
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2405
908
294e131f2f6d oops - 0 timesRepeat (with constant receiver) did it once
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  2406
    receiver codeOn:aStream inBlock:b for:aCompiler.
294e131f2f6d oops - 0 timesRepeat (with constant receiver) did it once
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  2407
349
7632e597a3df no need to keep receiver on stack for
Claus Gittinger <cg@exept.de>
parents: 338
diff changeset
  2408
    valueNeeded ifTrue:[
856
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2409
        "/ easily reconstructable - no need to keep on stack
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2410
        loopCount notNil ifTrue:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2411
            lateEval := true.
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2412
        ].
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2413
        lateEval ifFalse:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2414
            aStream nextPut:#dup
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2415
        ].
349
7632e597a3df no need to keep receiver on stack for
Claus Gittinger <cg@exept.de>
parents: 338
diff changeset
  2416
    ].
96
claus
parents: 95
diff changeset
  2417
856
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2418
    loopCount isNil ifTrue:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2419
        aStream nextPut:#pushgt0; nextPut:lineNr; nextPut:#falseJump.
3266
96ed152db6df class: MessageNode
Stefan Vogel <sv@exept.de>
parents: 3164
diff changeset
  2420
        pos2 := aStream position + 1.
856
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2421
        aStream nextPut:0.
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2422
    ].
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2423
3266
96ed152db6df class: MessageNode
Stefan Vogel <sv@exept.de>
parents: 3164
diff changeset
  2424
    pos1 := aStream position + 1.
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2425
    (argArray at:1) codeInlineOn:aStream inBlock:b valueNeeded:false for:aCompiler.
856
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2426
    aStream nextPut:#minus1; nextPut:lineNr.
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2427
    aStream nextPut:#pushgt0; nextPut:lineNr.
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2428
    aStream nextPut:#trueJump; nextPut:pos1.
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2429
856
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2430
    pos2 notNil ifTrue:[
3266
96ed152db6df class: MessageNode
Stefan Vogel <sv@exept.de>
parents: 3164
diff changeset
  2431
        (aStream contents) at:pos2 put:(aStream position + 1).
856
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2432
    ].
528
0a35ed44989f oops - timesRepeat dupped one too many
Claus Gittinger <cg@exept.de>
parents: 437
diff changeset
  2433
    aStream nextPut:#drop.  "/ drop run variable
856
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2434
349
7632e597a3df no need to keep receiver on stack for
Claus Gittinger <cg@exept.de>
parents: 338
diff changeset
  2435
    lateEval ifTrue:[
908
294e131f2f6d oops - 0 timesRepeat (with constant receiver) did it once
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  2436
        receiver codeOn:aStream inBlock:b for:aCompiler.
349
7632e597a3df no need to keep receiver on stack for
Claus Gittinger <cg@exept.de>
parents: 338
diff changeset
  2437
    ]
7632e597a3df no need to keep receiver on stack for
Claus Gittinger <cg@exept.de>
parents: 338
diff changeset
  2438
528
0a35ed44989f oops - timesRepeat dupped one too many
Claus Gittinger <cg@exept.de>
parents: 437
diff changeset
  2439
    "Modified: 27.5.1997 / 14:28:49 / cg"
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2440
!
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2441
565
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2442
codeToByDoOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2443
    "generate code for a to:b by:c do:[:arg | ... ]"
561
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2444
565
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2445
    |pos pos2 start stop step lateEval theBlock loopVarIndex
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2446
     stepVal stopVarIndex|
561
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2447
565
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2448
    "/ NOTICE: could compile it as a timesRepeat-like loop, if
561
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2449
    "/ the loop-counter is not accessed within the loop-block.
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2450
    "/ This generates somewhat (15%) faster code, but makes
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2451
    "/ debugging somewhat difficult (no loop-value seen in debugger).
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2452
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2453
    start := receiver.
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2454
    stop := (argArray at:1).
565
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2455
    step := (argArray at:2).
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2456
1397
969f505b6111 #errorSignal -> #description
Stefan Vogel <sv@exept.de>
parents: 1389
diff changeset
  2457
"/    stop isConstant ifFalse:[self error:'should not happen' mayProceed:true].
969f505b6111 #errorSignal -> #description
Stefan Vogel <sv@exept.de>
parents: 1389
diff changeset
  2458
"/    (stop evaluate isMemberOf:SmallInteger) ifFalse:[self error:'should not happen' mayProceed:true].
969f505b6111 #errorSignal -> #description
Stefan Vogel <sv@exept.de>
parents: 1389
diff changeset
  2459
969f505b6111 #errorSignal -> #description
Stefan Vogel <sv@exept.de>
parents: 1389
diff changeset
  2460
    step isConstant ifFalse:[self error:'should not happen' mayProceed:true].
565
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2461
    stepVal := step evaluate.
1397
969f505b6111 #errorSignal -> #description
Stefan Vogel <sv@exept.de>
parents: 1389
diff changeset
  2462
    (stepVal isMemberOf:SmallInteger) ifFalse:[
969f505b6111 #errorSignal -> #description
Stefan Vogel <sv@exept.de>
parents: 1389
diff changeset
  2463
        self error:'should not happen' mayProceed:true
969f505b6111 #errorSignal -> #description
Stefan Vogel <sv@exept.de>
parents: 1389
diff changeset
  2464
    ].
561
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2465
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2466
    start codeOn:aStream inBlock:b for:aCompiler.
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2467
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2468
    lateEval := false.
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2469
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2470
    valueNeeded ifTrue:[
1281
e70c494950b2 ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents: 1266
diff changeset
  2471
        "/ easily reconstructable - no need to keep on stack
e70c494950b2 ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents: 1266
diff changeset
  2472
        start isConstant ifTrue:[
e70c494950b2 ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents: 1266
diff changeset
  2473
            (start evaluate isMemberOf:SmallInteger) ifTrue:[
e70c494950b2 ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents: 1266
diff changeset
  2474
                lateEval := true.
e70c494950b2 ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents: 1266
diff changeset
  2475
            ]
e70c494950b2 ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents: 1266
diff changeset
  2476
        ].
e70c494950b2 ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents: 1266
diff changeset
  2477
        lateEval ifFalse:[
e70c494950b2 ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents: 1266
diff changeset
  2478
            aStream nextPut:#dup
e70c494950b2 ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents: 1266
diff changeset
  2479
        ].
561
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2480
    ].
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2481
565
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2482
    "/ if stop is not constant, and not an argVar,
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2483
    "/  evaluate it into a temp slot ...
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2484
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2485
    (stop isConstant and:[stop type == #Integer]) ifFalse:[
1281
e70c494950b2 ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents: 1266
diff changeset
  2486
        "/ a method/blockArg is constant as well ...
e70c494950b2 ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents: 1266
diff changeset
  2487
        (stop isVariable and:[stop isArgument]) ifFalse:[
e70c494950b2 ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents: 1266
diff changeset
  2488
            stop codeOn:aStream inBlock:b for:aCompiler.
e70c494950b2 ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents: 1266
diff changeset
  2489
e70c494950b2 ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents: 1266
diff changeset
  2490
            b isNil ifTrue:[
e70c494950b2 ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents: 1266
diff changeset
  2491
                stopVarIndex := aCompiler addTempVar.
e70c494950b2 ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents: 1266
diff changeset
  2492
                aStream nextPut:#storeMethodVar; nextPut:stopVarIndex.
e70c494950b2 ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents: 1266
diff changeset
  2493
            ] ifFalse:[
e70c494950b2 ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents: 1266
diff changeset
  2494
                stopVarIndex := b addTempVar.
e70c494950b2 ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents: 1266
diff changeset
  2495
                aStream nextPut:#storeBlockVar; nextPut:stopVarIndex.
e70c494950b2 ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents: 1266
diff changeset
  2496
            ].
e70c494950b2 ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents: 1266
diff changeset
  2497
        ]
565
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2498
    ].
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2499
3266
96ed152db6df class: MessageNode
Stefan Vogel <sv@exept.de>
parents: 3164
diff changeset
  2500
    pos := aStream position + 1.
561
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2501
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2502
    aStream nextPut:#dup.
565
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2503
    stopVarIndex notNil ifTrue:[
1281
e70c494950b2 ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents: 1266
diff changeset
  2504
        b isNil ifTrue:[
e70c494950b2 ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents: 1266
diff changeset
  2505
            aStream nextPut:#pushMethodVar; nextPut:stopVarIndex.
e70c494950b2 ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents: 1266
diff changeset
  2506
        ] ifFalse:[
e70c494950b2 ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents: 1266
diff changeset
  2507
            aStream nextPut:#pushBlockVar; nextPut:stopVarIndex.
e70c494950b2 ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents: 1266
diff changeset
  2508
        ]
565
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2509
    ] ifFalse:[
1281
e70c494950b2 ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents: 1266
diff changeset
  2510
        stop codeOn:aStream inBlock:b for:aCompiler.
565
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2511
    ].
1281
e70c494950b2 ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents: 1266
diff changeset
  2512
    stepVal >= 0 ifTrue:[
e70c494950b2 ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents: 1266
diff changeset
  2513
        aStream nextPut:#>.
565
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2514
    ] ifFalse:[
1281
e70c494950b2 ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents: 1266
diff changeset
  2515
        aStream nextPut:#<.
565
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2516
    ].
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2517
    (aCompiler hasLineNumber:selector) ifTrue:[
1281
e70c494950b2 ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents: 1266
diff changeset
  2518
        aStream nextPut:lineNr.
565
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2519
    ].
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2520
    aStream nextPut:#trueJump.
3266
96ed152db6df class: MessageNode
Stefan Vogel <sv@exept.de>
parents: 3164
diff changeset
  2521
    pos2 := aStream position + 1.
565
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2522
    aStream nextPut:0.
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2523
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2524
    theBlock := argArray at:3.
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2525
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2526
    "/ need a temporary in the outer context for
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2527
    "/ the loop ...
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2528
    b isNil ifTrue:[
1281
e70c494950b2 ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents: 1266
diff changeset
  2529
        loopVarIndex := aCompiler addTempVar.
e70c494950b2 ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents: 1266
diff changeset
  2530
        aStream nextPut:#dup.
e70c494950b2 ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents: 1266
diff changeset
  2531
        aStream nextPut:#storeMethodVar; nextPut:loopVarIndex.
565
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2532
    ] ifFalse:[
1281
e70c494950b2 ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents: 1266
diff changeset
  2533
        loopVarIndex := b addTempVar.
e70c494950b2 ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents: 1266
diff changeset
  2534
        aStream nextPut:#dup.
e70c494950b2 ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents: 1266
diff changeset
  2535
        aStream nextPut:#storeBlockVar; nextPut:loopVarIndex.
565
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2536
    ].
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2537
    theBlock indexOfFirstTemp:loopVarIndex.
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2538
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2539
    theBlock codeInlineOn:aStream inBlock:b valueNeeded:false for:aCompiler.
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2540
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2541
    "/ increment/decrement counter & jump back.
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2542
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2543
    stepVal == 1 ifTrue:[
1281
e70c494950b2 ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents: 1266
diff changeset
  2544
        aStream nextPut:#plus1; nextPut:lineNr.
565
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2545
    ] ifFalse:[
1281
e70c494950b2 ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents: 1266
diff changeset
  2546
        stepVal == -1 ifTrue:[
e70c494950b2 ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents: 1266
diff changeset
  2547
            aStream nextPut:#minus1; nextPut:lineNr.
e70c494950b2 ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents: 1266
diff changeset
  2548
        ] ifFalse:[
e70c494950b2 ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents: 1266
diff changeset
  2549
            step codeOn:aStream inBlock:b for:aCompiler.
e70c494950b2 ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents: 1266
diff changeset
  2550
            aStream nextPut:#+.
e70c494950b2 ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents: 1266
diff changeset
  2551
            (aCompiler hasLineNumber:#+) ifTrue:[
e70c494950b2 ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents: 1266
diff changeset
  2552
                aStream nextPut:lineNr.
e70c494950b2 ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents: 1266
diff changeset
  2553
            ].
e70c494950b2 ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents: 1266
diff changeset
  2554
        ]
565
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2555
    ].
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2556
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2557
    aStream nextPut:#jump; nextPut:pos.
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2558
3266
96ed152db6df class: MessageNode
Stefan Vogel <sv@exept.de>
parents: 3164
diff changeset
  2559
    (aStream contents) at:pos2 put:(aStream position + 1).
565
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2560
    aStream nextPut:#drop.  "/ drop run variable
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2561
    lateEval ifTrue:[
1281
e70c494950b2 ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents: 1266
diff changeset
  2562
        start codeOn:aStream inBlock:b for:aCompiler.
565
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2563
    ].
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2564
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2565
    "/ no need to nil-out loop-tempVar to help GC
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2566
    "/ (its integer, anyway).
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2567
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2568
    b isNil ifTrue:[
1281
e70c494950b2 ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents: 1266
diff changeset
  2569
        aCompiler removeTempVar
565
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2570
    ] ifFalse:[
1281
e70c494950b2 ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents: 1266
diff changeset
  2571
        b removeTempVar
565
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2572
    ].
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2573
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2574
    stopVarIndex notNil ifTrue:[
1281
e70c494950b2 ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents: 1266
diff changeset
  2575
        b isNil ifTrue:[
e70c494950b2 ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents: 1266
diff changeset
  2576
            aCompiler removeTempVar
e70c494950b2 ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents: 1266
diff changeset
  2577
        ] ifFalse:[
e70c494950b2 ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents: 1266
diff changeset
  2578
            b removeTempVar
e70c494950b2 ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents: 1266
diff changeset
  2579
        ]
565
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2580
    ].
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2581
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2582
    "Created: 27.6.1997 / 12:48:18 / cg"
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2583
    "Modified: 27.6.1997 / 13:43:06 / cg"
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2584
!
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2585
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2586
codeToDoOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2587
    "generate code for n to:n do:[:unusedArg | ... ]"
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2588
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2589
    |pos pos2 start stop lateEval theBlock loopVarIndex
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2590
     stopVarIndex|
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2591
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2592
    "/ NOTICE: could compile it as a timesRepeat, if
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2593
    "/ the loop-counter is not accessed within the loop-block.
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2594
    "/ This generates somewhat (15%) faster code, but makes
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2595
    "/ debugging somewhat difficult (no loop-value seen in debugger).
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2596
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2597
    start := receiver.
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2598
    stop := (argArray at:1).
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2599
"/    stop isConstant ifFalse:[self halt:'should not happen'].
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2600
"/    (stop evaluate isMemberOf:SmallInteger) ifFalse:[self halt:'should not happen'].
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2601
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2602
    start codeOn:aStream inBlock:b for:aCompiler.
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2603
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2604
    lateEval := false.
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2605
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2606
    valueNeeded ifTrue:[
1371
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2607
        "/ easily reconstructable - no need to keep on stack
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2608
        start isConstant ifTrue:[
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2609
            (start evaluate isMemberOf:SmallInteger) ifTrue:[
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2610
                lateEval := true.
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2611
            ]
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2612
        ].
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2613
        lateEval ifFalse:[
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2614
            aStream nextPut:#dup
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2615
        ].
565
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2616
    ].
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2617
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2618
    "/ if stop is not constant, and not an argVar,
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2619
    "/  evaluate it into a temp slot ...
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2620
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2621
    (stop isConstant and:[stop type == #Integer]) ifFalse:[
1371
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2622
        "/ a method/blockArg is constant as well ...
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2623
        (stop isVariable and:[stop isArgument]) ifFalse:[
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2624
            stop codeOn:aStream inBlock:b for:aCompiler.
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2625
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2626
            b isNil ifTrue:[
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2627
                stopVarIndex := aCompiler addTempVar.
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2628
                aStream nextPut:#storeMethodVar; nextPut:stopVarIndex.
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2629
            ] ifFalse:[
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2630
                stopVarIndex := b addTempVar.
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2631
                aStream nextPut:#storeBlockVar; nextPut:stopVarIndex.
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2632
            ].
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2633
        ]
565
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2634
    ].
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2635
3266
96ed152db6df class: MessageNode
Stefan Vogel <sv@exept.de>
parents: 3164
diff changeset
  2636
    pos := aStream position + 1.
565
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2637
624
e71abe9654e6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 602
diff changeset
  2638
    aStream nextPut:#lineno; nextPut:lineNr.
e71abe9654e6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 602
diff changeset
  2639
565
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2640
    aStream nextPut:#dup.
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2641
    stopVarIndex notNil ifTrue:[
1371
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2642
        b isNil ifTrue:[
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2643
            aStream nextPut:#pushMethodVar; nextPut:stopVarIndex.
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2644
        ] ifFalse:[
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2645
            aStream nextPut:#pushBlockVar; nextPut:stopVarIndex.
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2646
        ]
565
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2647
    ] ifFalse:[
1371
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2648
        stop codeOn:aStream inBlock:b for:aCompiler.
565
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2649
    ].
561
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2650
    aStream nextPut:#>.
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2651
    (aCompiler hasLineNumber:selector) ifTrue:[
1371
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2652
        aStream nextPut:lineNr.
561
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2653
    ].
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2654
    aStream nextPut:#trueJump.
3266
96ed152db6df class: MessageNode
Stefan Vogel <sv@exept.de>
parents: 3164
diff changeset
  2655
    pos2 := aStream position + 1.
561
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2656
    aStream nextPut:0.
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2657
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2658
    theBlock := argArray at:2.
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2659
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2660
    "/ need a temporary in the outer context for
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2661
    "/ the loop ...
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2662
    b isNil ifTrue:[
1371
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2663
        loopVarIndex := aCompiler addTempVar.
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2664
        aStream nextPut:#dup.
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2665
        aStream nextPut:#storeMethodVar; nextPut:loopVarIndex.
561
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2666
    ] ifFalse:[
1371
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2667
        loopVarIndex := b addTempVar.
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2668
        aStream nextPut:#dup.
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2669
        aStream nextPut:#storeBlockVar; nextPut:loopVarIndex.
561
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2670
    ].
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2671
    theBlock indexOfFirstTemp:loopVarIndex.
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2672
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2673
    theBlock codeInlineOn:aStream inBlock:b valueNeeded:false for:aCompiler.
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2674
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2675
    "/ increment counter & jump back.
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2676
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2677
    aStream nextPut:#plus1; nextPut:lineNr; nextPut:#jump; nextPut:pos.
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2678
3266
96ed152db6df class: MessageNode
Stefan Vogel <sv@exept.de>
parents: 3164
diff changeset
  2679
    (aStream contents) at:pos2 put:(aStream position + 1).
561
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2680
    aStream nextPut:#drop.  "/ drop run variable
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2681
    lateEval ifTrue:[
1371
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2682
        start codeOn:aStream inBlock:b for:aCompiler.
561
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2683
    ].
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2684
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2685
    "/ no need to nil-out loop-tempVar to help GC
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2686
    "/ (its integer, anyway).
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2687
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2688
    b isNil ifTrue:[
1371
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2689
        aCompiler removeTempVar
561
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2690
    ] ifFalse:[
1371
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2691
        b removeTempVar
565
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2692
    ].
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2693
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2694
    stopVarIndex notNil ifTrue:[
1371
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2695
        b isNil ifTrue:[
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2696
            aCompiler removeTempVar
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2697
        ] ifFalse:[
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2698
            b removeTempVar
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2699
        ]
565
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2700
    ].
561
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2701
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2702
    "Created: 26.6.1997 / 10:58:47 / cg"
624
e71abe9654e6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 602
diff changeset
  2703
    "Modified: 19.10.1997 / 01:31:40 / cg"
561
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2704
!
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2705
1435
be9680c6145c factored out some common code (block-code and value-sending)
Claus Gittinger <cg@exept.de>
parents: 1425
diff changeset
  2706
codeValueSendOn:aStream for:aCompiler
be9680c6145c factored out some common code (block-code and value-sending)
Claus Gittinger <cg@exept.de>
parents: 1425
diff changeset
  2707
    "/ send #value to the top of the stack ...
be9680c6145c factored out some common code (block-code and value-sending)
Claus Gittinger <cg@exept.de>
parents: 1425
diff changeset
  2708
    aStream nextPut:#value.
be9680c6145c factored out some common code (block-code and value-sending)
Claus Gittinger <cg@exept.de>
parents: 1425
diff changeset
  2709
    (aCompiler hasLineNumber:#value) ifTrue:[
be9680c6145c factored out some common code (block-code and value-sending)
Claus Gittinger <cg@exept.de>
parents: 1425
diff changeset
  2710
        aStream nextPut:lineNr.
be9680c6145c factored out some common code (block-code and value-sending)
Claus Gittinger <cg@exept.de>
parents: 1425
diff changeset
  2711
    ]
be9680c6145c factored out some common code (block-code and value-sending)
Claus Gittinger <cg@exept.de>
parents: 1425
diff changeset
  2712
!
be9680c6145c factored out some common code (block-code and value-sending)
Claus Gittinger <cg@exept.de>
parents: 1425
diff changeset
  2713
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2714
codeWhileOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler
200
b2f77bd77070 inline code for [...] whileXXX
Claus Gittinger <cg@exept.de>
parents: 199
diff changeset
  2715
    "generate code for
817
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2716
        [...] whileXXX:[ ... ] 
200
b2f77bd77070 inline code for [...] whileXXX
Claus Gittinger <cg@exept.de>
parents: 199
diff changeset
  2717
     and also 
817
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2718
        [...] whileXXX
200
b2f77bd77070 inline code for [...] whileXXX
Claus Gittinger <cg@exept.de>
parents: 199
diff changeset
  2719
    "
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2720
200
b2f77bd77070 inline code for [...] whileXXX
Claus Gittinger <cg@exept.de>
parents: 199
diff changeset
  2721
    |pos pos2 theReceiver theArg theByteCode optByteCode needLineNr blockExpr
856
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2722
     hasLoopBlock fastReceiver condStats constCondition|
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2723
200
b2f77bd77070 inline code for [...] whileXXX
Claus Gittinger <cg@exept.de>
parents: 199
diff changeset
  2724
    hasLoopBlock := true.
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2725
    (selector == #whileTrue:) ifTrue:[
817
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2726
        theByteCode := #falseJump.
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2727
    ] ifFalse:[
817
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2728
        (selector == #whileFalse:) ifTrue:[
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2729
            theByteCode := #trueJump
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2730
        ] ifFalse:[
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2731
            hasLoopBlock := false.
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2732
            (selector == #whileTrue) ifTrue:[
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2733
                theByteCode := #trueJump
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2734
            ] ifFalse:[
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2735
                theByteCode := #falseJump
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2736
            ].
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2737
        ]
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2738
    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2739
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2740
    theReceiver := receiver.
370
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  2741
856
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2742
    (receiver isBlock
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2743
    and:[(condStats := receiver statements) notNil
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2744
    and:[condStats nextStatement isNil
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2745
    and:[condStats expression notNil]]])
370
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  2746
    ifTrue:[
817
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2747
        fastReceiver := receiver statements expression.
1463
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  2748
        optByteCode := self optimizedConditionFor:fastReceiver with:theByteCode for:aCompiler.
370
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  2749
    ] ifFalse:[
1463
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  2750
        optByteCode := self optimizedConditionFor:theReceiver with:theByteCode for:aCompiler.
370
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  2751
    ].
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  2752
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2753
    optByteCode notNil ifTrue:[
817
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2754
        ((optByteCode == #eqJump) or:[optByteCode == #notEqJump]) ifTrue:[
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2755
            theArg := receiver statements expression arg1
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2756
        ].
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2757
        theReceiver := receiver statements expression receiver.
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2758
        theByteCode := optByteCode
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2759
    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2760
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2761
"/ OLD:
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2762
"/    valueNeeded ifTrue:[aStream nextPut:#pushNil].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2763
"/
167
d3dbd739c65a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 166
diff changeset
  2764
    needLineNr := true.
d3dbd739c65a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 166
diff changeset
  2765
3266
96ed152db6df class: MessageNode
Stefan Vogel <sv@exept.de>
parents: 3164
diff changeset
  2766
    pos := aStream position + 1.
386
2f66de89a89b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 371
diff changeset
  2767
389
8aa5f9f08139 care for lineNumber in while-loop
Claus Gittinger <cg@exept.de>
parents: 386
diff changeset
  2768
"/    aCompiler lineNumberInfo == #full ifTrue:[
817
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2769
        self codeLineNumber:lineNr on:aStream for:aCompiler.
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2770
        needLineNr := false.
389
8aa5f9f08139 care for lineNumber in while-loop
Claus Gittinger <cg@exept.de>
parents: 386
diff changeset
  2771
"/    ].
386
2f66de89a89b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 371
diff changeset
  2772
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2773
    optByteCode notNil ifTrue:[
817
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2774
        theReceiver codeOn:aStream inBlock:b for:aCompiler.
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2775
        theArg notNil ifTrue:[
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2776
            theArg codeOn:aStream inBlock:b for:aCompiler
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2777
        ]
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2778
    ] ifFalse:[
856
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2779
        (fastReceiver notNil 
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2780
        and:[fastReceiver isConstant]) ifTrue:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2781
            constCondition := fastReceiver evaluate.
817
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2782
            theByteCode == #trueJump ifTrue:[
856
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2783
                constCondition == true ifTrue:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2784
                    theByteCode := #jump
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2785
                ] ifFalse:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2786
                    constCondition == false ifTrue:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2787
                        theByteCode := #never
817
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2788
                    ]
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2789
                ]
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2790
            ] ifFalse:[
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2791
                theByteCode == #falseJump ifTrue:[
856
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2792
                    constCondition == false ifTrue:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2793
                        theByteCode := #jump
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2794
                    ] ifFalse:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2795
                        constCondition == true ifTrue:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2796
                            theByteCode := #never
817
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2797
                        ]
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2798
                    ]
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2799
                ]
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2800
            ]
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2801
        ].
167
d3dbd739c65a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 166
diff changeset
  2802
856
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2803
        (theByteCode ~~ #jump and:[theByteCode ~~ #never]) ifTrue:[
817
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2804
            theReceiver codeInlineOn:aStream inBlock:b for:aCompiler.
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2805
        ].
370
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  2806
817
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2807
        "/
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2808
        "/ cannot enable code below 
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2809
        "/ (tiny loops would not be debuggable with next, since lineNo remains the same)
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2810
        "/ think about it ...
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2811
        "/
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2812
        blockExpr := theReceiver simpleSendBlockExpression.
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2813
        blockExpr notNil ifTrue:[
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2814
            blockExpr isMessage ifTrue:[
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2815
                (aCompiler hasLineNumber:(blockExpr selector)) ifTrue:[
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2816
                    blockExpr lineNumber == lineNr ifTrue:[
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2817
                        needLineNr := false
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2818
                    ]
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2819
                ]
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2820
            ]
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2821
        ].
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2822
    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2823
167
d3dbd739c65a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 166
diff changeset
  2824
    needLineNr ifTrue:[
3266
96ed152db6df class: MessageNode
Stefan Vogel <sv@exept.de>
parents: 3164
diff changeset
  2825
        self codeLineNumber:lineNr on:aStream for:aCompiler.
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2826
    ].
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2827
200
b2f77bd77070 inline code for [...] whileXXX
Claus Gittinger <cg@exept.de>
parents: 199
diff changeset
  2828
    hasLoopBlock ifFalse:[
817
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2829
        "/ simple [...] whileXXX
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2830
        theByteCode ~~ #never ifTrue:[
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2831
            aStream nextPut:theByteCode; nextPut:pos.
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2832
        ].
370
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  2833
817
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2834
        valueNeeded ifTrue:[aStream nextPut:#pushNil].
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2835
        ^ self
200
b2f77bd77070 inline code for [...] whileXXX
Claus Gittinger <cg@exept.de>
parents: 199
diff changeset
  2836
    ].
b2f77bd77070 inline code for [...] whileXXX
Claus Gittinger <cg@exept.de>
parents: 199
diff changeset
  2837
b2f77bd77070 inline code for [...] whileXXX
Claus Gittinger <cg@exept.de>
parents: 199
diff changeset
  2838
    "/ [...] whileXXX:[...]
b2f77bd77070 inline code for [...] whileXXX
Claus Gittinger <cg@exept.de>
parents: 199
diff changeset
  2839
370
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  2840
    theByteCode ~~ #never ifTrue:[
817
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2841
        aStream nextPut:theByteCode.
3266
96ed152db6df class: MessageNode
Stefan Vogel <sv@exept.de>
parents: 3164
diff changeset
  2842
        pos2 := aStream position + 1.
817
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2843
        aStream nextPut:0.
370
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  2844
    ].
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  2845
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2846
    (argArray at:1) codeInlineOn:aStream inBlock:b valueNeeded:false for:aCompiler.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2847
    aStream nextPut:#jump; nextPut:pos.
370
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  2848
    theByteCode ~~ #never ifTrue:[
3266
96ed152db6df class: MessageNode
Stefan Vogel <sv@exept.de>
parents: 3164
diff changeset
  2849
        (aStream contents) at:pos2 put:(aStream position + 1).
370
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  2850
    ].
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  2851
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2852
    valueNeeded ifTrue:[aStream nextPut:#pushNil].
167
d3dbd739c65a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 166
diff changeset
  2853
389
8aa5f9f08139 care for lineNumber in while-loop
Claus Gittinger <cg@exept.de>
parents: 386
diff changeset
  2854
    "Modified: 22.10.1996 / 21:34:37 / cg"
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2855
!
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2856
856
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2857
new_codeWhileOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2858
    "generate code for
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2859
        [...] whileXXX:[ ... ] 
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2860
     and also 
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2861
        [...] whileXXX
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2862
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2863
     This generates the check at the end and should generate better
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2864
     code (only 1 conditional-branch at the end instead of 2 branches).
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2865
     However, for now, it is disabled, since the JIT has special provisions
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2866
     to detect loops and actually generates better machine code for the
910
eb4849c04fff comment
Claus Gittinger <cg@exept.de>
parents: 909
diff changeset
  2867
     old bytecode sequence ... (sigh)
856
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2868
    "
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2869
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2870
    |pos pos0 theReceiver theArg theByteCode optByteCode needLineNr blockExpr
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2871
     hasLoopBlock fastReceiver condStats constCondition|
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2872
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2873
    hasLoopBlock := true.
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2874
    (selector == #whileTrue:) ifTrue:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2875
        theByteCode := #trueJump.
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2876
    ] ifFalse:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2877
        (selector == #whileFalse:) ifTrue:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2878
            theByteCode := #falseJump
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2879
        ] ifFalse:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2880
            hasLoopBlock := false.
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2881
            (selector == #whileTrue) ifTrue:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2882
                theByteCode := #trueJump
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2883
            ] ifFalse:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2884
                theByteCode := #falseJump
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2885
            ].
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2886
        ]
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2887
    ].
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2888
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2889
    theReceiver := receiver.
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2890
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2891
    (receiver isBlock
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2892
    and:[(condStats := receiver statements) notNil
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2893
    and:[condStats nextStatement isNil
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2894
    and:[(fastReceiver := condStats expression) notNil]]])
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2895
    ifTrue:[
1463
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  2896
        optByteCode := self optimizedConditionFor:fastReceiver with:theByteCode for:aCompiler.
856
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2897
    ] ifFalse:[
1463
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  2898
        optByteCode := self optimizedConditionFor:theReceiver with:theByteCode for:aCompiler.
856
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2899
    ].
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2900
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2901
    optByteCode notNil ifTrue:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2902
        ((optByteCode == #eqJump) or:[optByteCode == #notEqJump]) ifTrue:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2903
            theArg := receiver statements expression arg1
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2904
        ].
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2905
        theReceiver := receiver statements expression receiver.
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2906
        theByteCode := optByteCode
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2907
    ].
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2908
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2909
    needLineNr := true.
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2910
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2911
    hasLoopBlock ifTrue:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2912
        (argArray at:1) isEmptyBlock ifFalse:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2913
            aStream nextPut:#jump.
3266
96ed152db6df class: MessageNode
Stefan Vogel <sv@exept.de>
parents: 3164
diff changeset
  2914
            pos0 := aStream position + 1.
856
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2915
            aStream nextPut:0.
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2916
3266
96ed152db6df class: MessageNode
Stefan Vogel <sv@exept.de>
parents: 3164
diff changeset
  2917
            pos := aStream position + 1.
856
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2918
            (argArray at:1) codeInlineOn:aStream inBlock:b valueNeeded:false for:aCompiler.
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2919
3266
96ed152db6df class: MessageNode
Stefan Vogel <sv@exept.de>
parents: 3164
diff changeset
  2920
            (aStream contents) at:pos0 put:(aStream position + 1).
856
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2921
        ]
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2922
    ] ifFalse:[
3266
96ed152db6df class: MessageNode
Stefan Vogel <sv@exept.de>
parents: 3164
diff changeset
  2923
        pos := aStream position + 1.
856
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2924
    ].
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2925
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2926
    optByteCode isNil ifTrue:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2927
        blockExpr := theReceiver simpleSendBlockExpression.
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2928
        blockExpr notNil ifTrue:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2929
            blockExpr isMessage ifTrue:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2930
                (aCompiler hasLineNumber:(blockExpr selector)) ifTrue:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2931
                    blockExpr lineNumber == lineNr ifTrue:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2932
                        needLineNr := false
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2933
                    ]
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2934
                ]
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2935
            ]
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2936
        ].
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2937
    ].
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2938
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2939
    needLineNr ifTrue:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2940
        self codeLineNumber:lineNr on:aStream for:aCompiler.
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2941
    ].
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2942
    needLineNr := false.
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2943
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2944
    optByteCode notNil ifTrue:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2945
        theReceiver codeOn:aStream inBlock:b for:aCompiler.
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2946
        theArg notNil ifTrue:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2947
            theArg codeOn:aStream inBlock:b for:aCompiler
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2948
        ]
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2949
    ] ifFalse:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2950
        (fastReceiver notNil 
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2951
        and:[fastReceiver isConstant]) ifTrue:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2952
            constCondition := fastReceiver evaluate.
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2953
            theByteCode == #trueJump ifTrue:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2954
                constCondition == true ifTrue:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2955
                    theByteCode := #jump
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2956
                ] ifFalse:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2957
                    constCondition == false ifTrue:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2958
                        theByteCode := #never
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2959
                    ]
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2960
                ]
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2961
            ] ifFalse:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2962
                theByteCode == #falseJump ifTrue:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2963
                    constCondition == false ifTrue:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2964
                        theByteCode := #jump
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2965
                    ] ifFalse:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2966
                        constCondition == true ifTrue:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2967
                            theByteCode := #never
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2968
                        ]
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2969
                    ]
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2970
                ]
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2971
            ]
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2972
        ].
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2973
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2974
        (theByteCode ~~ #jump and:[theByteCode ~~ #never]) ifTrue:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2975
            theReceiver codeInlineOn:aStream inBlock:b for:aCompiler.
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2976
        ].
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2977
    ].
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2978
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2979
    hasLoopBlock ifFalse:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2980
        "/ simple [...] whileXXX
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2981
        theByteCode ~~ #never ifTrue:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2982
            aStream nextPut:theByteCode; nextPut:pos.
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2983
        ].
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2984
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2985
        valueNeeded ifTrue:[aStream nextPut:#pushNil].
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2986
        ^ self
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2987
    ].
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2988
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2989
    "/ [...] whileXXX:[...]
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2990
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2991
    theByteCode ~~ #never ifTrue:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2992
        aStream nextPut:theByteCode.
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2993
        aStream nextPut:pos.
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2994
    ].
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2995
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2996
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2997
    valueNeeded ifTrue:[aStream nextPut:#pushNil].
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2998
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2999
    "Modified: 22.10.1996 / 21:34:37 / cg"
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  3000
!
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  3001
1463
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  3002
optimizedConditionFor:aReceiver with:aByteCode for:aCompiler
186
05a99f1bd747 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 167
diff changeset
  3003
    |rec sel stats|
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  3004
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  3005
    rec := aReceiver.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  3006
    (rec isBlock) ifTrue:[
1463
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  3007
        (stats := rec statements) notNil ifTrue:[
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  3008
            stats nextStatement isNil ifTrue:[
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  3009
                rec := rec statements expression
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  3010
            ]
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  3011
        ]
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  3012
    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  3013
    (rec isUnaryMessage) ifTrue:[
1463
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  3014
        sel := rec selector.
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  3015
        (sel == #isNil) ifTrue:[
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  3016
            "/
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  3017
            "/ isNil trueJmp  -> nilJump
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  3018
            "/ isNil falseJmp -> notNilJump
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  3019
            "/
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  3020
            aCompiler addLiteral:#isNil.
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  3021
            (aByteCode == #trueJump) ifTrue:[^ #nilJump].
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  3022
            (aByteCode == #falseJump) ifTrue:[^ #notNilJump]
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  3023
        ].
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  3024
        (sel == #notNil) ifTrue:[
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  3025
            "/
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  3026
            "/ notNil trueJmp  -> notNilJump
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  3027
            "/ notNil falseJmp -> nilJump
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  3028
            "/
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  3029
            aCompiler addLiteral:#notNil.
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  3030
            (aByteCode == #trueJump) ifTrue:[^ #notNilJump].
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  3031
            (aByteCode == #falseJump) ifTrue:[^ #nilJump]
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  3032
        ].
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  3033
        (sel == #not) ifTrue:[
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  3034
            "/
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  3035
            "/ not trueJmp  -> falseJump
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  3036
            "/ not falseJmp -> trueJump
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  3037
            "/
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  3038
            aCompiler addLiteral:#not.
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  3039
            (aByteCode == #trueJump) ifTrue:[^ #falseJump].
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  3040
            (aByteCode == #falseJump) ifTrue:[^ #trueJump]
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  3041
        ].
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  3042
        ^ nil
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  3043
    ].
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  3044
    (rec isBinaryMessage) ifTrue:[
1463
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  3045
        sel := rec selector.
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  3046
        rec arg1 isConstant ifTrue:[
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  3047
            (rec arg1 value == 0) ifTrue:[
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  3048
                "/
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  3049
                "/ ==0 trueJmp  -> zeroJump
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  3050
                "/ ==0 falseJmp -> notZeroJump
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  3051
                "/
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  3052
                (sel == #==) ifTrue:[
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  3053
                    aCompiler addLiteral:#==.
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  3054
                    (aByteCode == #trueJump) ifTrue:[^ #zeroJump].
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  3055
                    (aByteCode == #falseJump) ifTrue:[^ #notZeroJump]
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  3056
                ].
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  3057
                "/
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  3058
                "/ ~~0 trueJmp  -> notZeroJump
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  3059
                "/ ~~0 falseJmp -> zeroJump
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  3060
                "/
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  3061
                (sel == #~~) ifTrue:[
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  3062
                    aCompiler addLiteral:#~~.
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  3063
                    (aByteCode == #falseJump) ifTrue:[^ #zeroJump].
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  3064
                    (aByteCode == #trueJump) ifTrue:[^ #notZeroJump]
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  3065
                ].
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  3066
                ^ nil
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  3067
            ]
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  3068
        ].
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  3069
        (sel == #==) ifTrue:[
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  3070
            "/
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  3071
            "/ == trueJmp  -> eqJump
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  3072
            "/ == falseJmp -> notEqJump
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  3073
            "/
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  3074
            aCompiler addLiteral:#==.
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  3075
            (aByteCode == #trueJump) ifTrue:[^ #eqJump].
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  3076
            (aByteCode == #falseJump) ifTrue:[^ #notEqJump]
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  3077
        ].
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  3078
        (sel == #~~) ifTrue:[
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  3079
            "/
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  3080
            "/ ~~ trueJmp  -> notEqJump
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  3081
            "/ ~~ falseJmp -> eqJump
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  3082
            "/
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  3083
            aCompiler addLiteral:#~~.
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  3084
            (aByteCode == #falseJump) ifTrue:[^ #eqJump].
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  3085
            (aByteCode == #trueJump) ifTrue:[^ #notEqJump]
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  3086
        ]
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  3087
    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  3088
    ^ nil
992
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  3089
!
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  3090
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  3091
tryFoldedIfOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  3092
    |rVal branch|
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  3093
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  3094
    receiver isConstant ifTrue:[
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  3095
        rVal := receiver evaluate.
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  3096
        rVal == true ifTrue:[
1248
ba526cbb348a fixed optimization of: <true|false> ifTrue/false: non-block
Claus Gittinger <cg@exept.de>
parents: 1197
diff changeset
  3097
            (selector == #ifFalse:) ifTrue:[
1422
cdee45eb0303 oops - wrong code was generatedd for inlined
Claus Gittinger <cg@exept.de>
parents: 1397
diff changeset
  3098
                valueNeeded ifTrue:[
cdee45eb0303 oops - wrong code was generatedd for inlined
Claus Gittinger <cg@exept.de>
parents: 1397
diff changeset
  3099
                    "/ true ifFalse:[] - evaluates to nil.
cdee45eb0303 oops - wrong code was generatedd for inlined
Claus Gittinger <cg@exept.de>
parents: 1397
diff changeset
  3100
                    aStream nextPut:#pushNil
cdee45eb0303 oops - wrong code was generatedd for inlined
Claus Gittinger <cg@exept.de>
parents: 1397
diff changeset
  3101
                ].
1248
ba526cbb348a fixed optimization of: <true|false> ifTrue/false: non-block
Claus Gittinger <cg@exept.de>
parents: 1197
diff changeset
  3102
                ^ true.
ba526cbb348a fixed optimization of: <true|false> ifTrue/false: non-block
Claus Gittinger <cg@exept.de>
parents: 1197
diff changeset
  3103
            ].
992
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  3104
            ((selector == #ifTrue:) or:[selector == #ifTrue:ifFalse:]) ifTrue:[
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  3105
                branch := (argArray at: 1).
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  3106
            ].
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  3107
            (selector == #ifFalse:ifTrue:) ifTrue:[
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  3108
                branch := (argArray at: 2).
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  3109
            ].
1248
ba526cbb348a fixed optimization of: <true|false> ifTrue/false: non-block
Claus Gittinger <cg@exept.de>
parents: 1197
diff changeset
  3110
        ].
ba526cbb348a fixed optimization of: <true|false> ifTrue/false: non-block
Claus Gittinger <cg@exept.de>
parents: 1197
diff changeset
  3111
        rVal == false ifTrue:[
ba526cbb348a fixed optimization of: <true|false> ifTrue/false: non-block
Claus Gittinger <cg@exept.de>
parents: 1197
diff changeset
  3112
            (selector == #ifTrue:) ifTrue:[
1422
cdee45eb0303 oops - wrong code was generatedd for inlined
Claus Gittinger <cg@exept.de>
parents: 1397
diff changeset
  3113
                valueNeeded ifTrue:[
cdee45eb0303 oops - wrong code was generatedd for inlined
Claus Gittinger <cg@exept.de>
parents: 1397
diff changeset
  3114
                    "/ false ifTrue:[] - evaluates to nil.
cdee45eb0303 oops - wrong code was generatedd for inlined
Claus Gittinger <cg@exept.de>
parents: 1397
diff changeset
  3115
                    aStream nextPut:#pushNil
cdee45eb0303 oops - wrong code was generatedd for inlined
Claus Gittinger <cg@exept.de>
parents: 1397
diff changeset
  3116
                ].
992
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  3117
                ^ true.
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  3118
            ].
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  3119
            ((selector == #ifFalse:) or:[selector == #ifFalse:ifTrue:]) ifTrue:[
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  3120
                branch := (argArray at: 1).
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  3121
            ].
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  3122
            (selector == #ifTrue:ifFalse:) ifTrue:[
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  3123
                branch := (argArray at: 2).
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  3124
            ].
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  3125
        ].
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  3126
        branch notNil ifTrue:[
1435
be9680c6145c factored out some common code (block-code and value-sending)
Claus Gittinger <cg@exept.de>
parents: 1425
diff changeset
  3127
            self codeBlockEvaluation:branch on:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler.
992
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  3128
            ^ true.
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  3129
        ]
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  3130
    ].
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  3131
    ^ false
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  3132
! !
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  3133
1080
bd3f19f6009a category change
Claus Gittinger <cg@exept.de>
parents: 1059
diff changeset
  3134
!MessageNode methodsFor:'printing & storing'!
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  3135
1588
4c3183dfaa5f printing
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  3136
printOn:aStream indent:i 
4c3183dfaa5f printing
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  3137
    |selectorParts|
4c3183dfaa5f printing
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  3138
4c3183dfaa5f printing
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  3139
    (#( whileTrue: whileFalse: ) includes:selector) ifTrue:[
888
5858090fc8c3 changed #printOn: to indent
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
  3140
        receiver isBlock ifTrue:[
5858090fc8c3 changed #printOn: to indent
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
  3141
            ^ self printWhileOn:aStream indent:i
5858090fc8c3 changed #printOn: to indent
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
  3142
        ].
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  3143
    ].
2521
daf48e62f93d changed: #printOn:indent:
Claus Gittinger <cg@exept.de>
parents: 2496
diff changeset
  3144
    selectorParts := selector asSymbol keywords.
1588
4c3183dfaa5f printing
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  3145
    receiver printOn:aStream indent:i parenthized:(receiver precedence <= self precedence).
1791
cd786d318d6f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1727
diff changeset
  3146
    argArray notNil ifTrue:[
cd786d318d6f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1727
diff changeset
  3147
        argArray with:selectorParts
cd786d318d6f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1727
diff changeset
  3148
            do:[:arg :selPart | 
cd786d318d6f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1727
diff changeset
  3149
                aStream
cd786d318d6f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1727
diff changeset
  3150
                    cr;
cd786d318d6f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1727
diff changeset
  3151
                    spaces:i + 4;
2542
251e766c3530 changed: #printOn:indent:
Claus Gittinger <cg@exept.de>
parents: 2521
diff changeset
  3152
                    nextPutAll:selPart.
251e766c3530 changed: #printOn:indent:
Claus Gittinger <cg@exept.de>
parents: 2521
diff changeset
  3153
                arg printOn:aStream 
251e766c3530 changed: #printOn:indent:
Claus Gittinger <cg@exept.de>
parents: 2521
diff changeset
  3154
                    indent:i + 4 
251e766c3530 changed: #printOn:indent:
Claus Gittinger <cg@exept.de>
parents: 2521
diff changeset
  3155
                    parenthized:(arg precedence <= self precedence).
1791
cd786d318d6f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1727
diff changeset
  3156
            ]
cd786d318d6f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1727
diff changeset
  3157
    ].
cd786d318d6f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1727
diff changeset
  3158
2542
251e766c3530 changed: #printOn:indent:
Claus Gittinger <cg@exept.de>
parents: 2521
diff changeset
  3159
    "Modified: / 06-07-2011 / 09:44:55 / cg"
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  3160
!
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  3161
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  3162
printWhileOn:aStream indent:i
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  3163
    "special handling of whileTrue/whileFalse"
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  3164
1588
4c3183dfaa5f printing
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  3165
    |arg|
4c3183dfaa5f printing
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  3166
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  3167
    aStream nextPutAll:'['.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  3168
    receiver statements printOn:aStream indent:i.
1588
4c3183dfaa5f printing
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  3169
    aStream nextPutAll:'] ',selector,' '.
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  3170
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  3171
    arg := argArray at:1.
1588
4c3183dfaa5f printing
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  3172
    arg printOn:aStream indent:i parenthized:(arg precedence <= self precedence).
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  3173
! !
106
claus
parents: 104
diff changeset
  3174
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  3175
!MessageNode methodsFor:'queries'!
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  3176
1565
9388e72e2dff Define #argumentCount as ANSI alias for #numArgs
Stefan Vogel <sv@exept.de>
parents: 1533
diff changeset
  3177
argumentCount
9388e72e2dff Define #argumentCount as ANSI alias for #numArgs
Stefan Vogel <sv@exept.de>
parents: 1533
diff changeset
  3178
    "VisualAge/ANSI compatibility - same as numArgs"
9388e72e2dff Define #argumentCount as ANSI alias for #numArgs
Stefan Vogel <sv@exept.de>
parents: 1533
diff changeset
  3179
9388e72e2dff Define #argumentCount as ANSI alias for #numArgs
Stefan Vogel <sv@exept.de>
parents: 1533
diff changeset
  3180
    ^ argArray size
9388e72e2dff Define #argumentCount as ANSI alias for #numArgs
Stefan Vogel <sv@exept.de>
parents: 1533
diff changeset
  3181
!
9388e72e2dff Define #argumentCount as ANSI alias for #numArgs
Stefan Vogel <sv@exept.de>
parents: 1533
diff changeset
  3182
395
16156d8711c2 added block collector
Claus Gittinger <cg@exept.de>
parents: 389
diff changeset
  3183
collectBlocksInto:aCollection
16156d8711c2 added block collector
Claus Gittinger <cg@exept.de>
parents: 389
diff changeset
  3184
    receiver collectBlocksInto:aCollection.
16156d8711c2 added block collector
Claus Gittinger <cg@exept.de>
parents: 389
diff changeset
  3185
    argArray size > 0 ifTrue:[
1727
58820b0c1e7a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1724
diff changeset
  3186
        argArray do:[:arg |
58820b0c1e7a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1724
diff changeset
  3187
            arg collectBlocksInto:aCollection.
58820b0c1e7a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1724
diff changeset
  3188
        ]
395
16156d8711c2 added block collector
Claus Gittinger <cg@exept.de>
parents: 389
diff changeset
  3189
    ].
16156d8711c2 added block collector
Claus Gittinger <cg@exept.de>
parents: 389
diff changeset
  3190
16156d8711c2 added block collector
Claus Gittinger <cg@exept.de>
parents: 389
diff changeset
  3191
    "Created: 23.10.1996 / 15:44:49 / cg"
16156d8711c2 added block collector
Claus Gittinger <cg@exept.de>
parents: 389
diff changeset
  3192
    "Modified: 23.10.1996 / 16:03:46 / cg"
16156d8711c2 added block collector
Claus Gittinger <cg@exept.de>
parents: 389
diff changeset
  3193
!
16156d8711c2 added block collector
Claus Gittinger <cg@exept.de>
parents: 389
diff changeset
  3194
2384
3854f86e767a added: #containsReturn
Claus Gittinger <cg@exept.de>
parents: 2345
diff changeset
  3195
containsReturn
3854f86e767a added: #containsReturn
Claus Gittinger <cg@exept.de>
parents: 2345
diff changeset
  3196
    receiver containsReturn ifTrue:[^ true].
3854f86e767a added: #containsReturn
Claus Gittinger <cg@exept.de>
parents: 2345
diff changeset
  3197
    ^ self arguments contains:[:arg | arg containsReturn]
3854f86e767a added: #containsReturn
Claus Gittinger <cg@exept.de>
parents: 2345
diff changeset
  3198
!
3854f86e767a added: #containsReturn
Claus Gittinger <cg@exept.de>
parents: 2345
diff changeset
  3199
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  3200
isCascade
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  3201
    ^ false
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  3202
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  3203
    "Created: / 16.7.1998 / 20:03:42 / cg"
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  3204
!
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  3205
1384
0db9682870d9 evaluate -> evaluateIn:
Claus Gittinger <cg@exept.de>
parents: 1382
diff changeset
  3206
numArgs
0db9682870d9 evaluate -> evaluateIn:
Claus Gittinger <cg@exept.de>
parents: 1382
diff changeset
  3207
    ^ argArray size
0db9682870d9 evaluate -> evaluateIn:
Claus Gittinger <cg@exept.de>
parents: 1382
diff changeset
  3208
!
0db9682870d9 evaluate -> evaluateIn:
Claus Gittinger <cg@exept.de>
parents: 1382
diff changeset
  3209
1588
4c3183dfaa5f printing
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  3210
precedence
4c3183dfaa5f printing
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  3211
    ^ 10
4c3183dfaa5f printing
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  3212
4c3183dfaa5f printing
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  3213
    "Created: / 20-04-2005 / 14:10:59 / cg"
4c3183dfaa5f printing
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  3214
!
4c3183dfaa5f printing
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  3215
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  3216
realReceiver
746
429cfc59b440 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 744
diff changeset
  3217
    receiver isCascade ifTrue:[
429cfc59b440 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 744
diff changeset
  3218
        ^ receiver realReceiver
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  3219
    ].
746
429cfc59b440 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 744
diff changeset
  3220
    self isCascade ifTrue:[
429cfc59b440 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 744
diff changeset
  3221
        ^ receiver receiver
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  3222
    ].
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  3223
746
429cfc59b440 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 744
diff changeset
  3224
    ^ receiver
429cfc59b440 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 744
diff changeset
  3225
429cfc59b440 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 744
diff changeset
  3226
    "Modified: / 17.7.1998 / 02:09:05 / cg"
2268
Claus Gittinger <cg@exept.de>
parents: 2208
diff changeset
  3227
!
Claus Gittinger <cg@exept.de>
parents: 2208
diff changeset
  3228
Claus Gittinger <cg@exept.de>
parents: 2208
diff changeset
  3229
withConstantValueDo:aBlock
Claus Gittinger <cg@exept.de>
parents: 2208
diff changeset
  3230
    "return true, if this evaluates to a constant value
3016
382e4e75d795 class: MessageNode
Claus Gittinger <cg@exept.de>
parents: 2941
diff changeset
  3231
     and evaluate aBlock with it. Used for constant folding"
382e4e75d795 class: MessageNode
Claus Gittinger <cg@exept.de>
parents: 2941
diff changeset
  3232
3017
c891786676f3 class: MessageNode
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  3233
    |recVal argValues allArgsConstant fold cond2 condVal2|
2268
Claus Gittinger <cg@exept.de>
parents: 2208
diff changeset
  3234
2273
d952d08cf43c changed: #withConstantValueDo:
Claus Gittinger <cg@exept.de>
parents: 2270
diff changeset
  3235
    (receiver isGlobal and:[receiver name = 'Smalltalk']) ifTrue:[
3017
c891786676f3 class: MessageNode
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  3236
        "/ (Smalltalk respondsTo:#isSmalltalkX) -> true
c891786676f3 class: MessageNode
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  3237
        (selector == #respondsTo:) ifTrue:[
c891786676f3 class: MessageNode
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  3238
            argArray size == 1 ifTrue:[
c891786676f3 class: MessageNode
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  3239
                argArray first isConstant ifTrue:[
c891786676f3 class: MessageNode
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  3240
                    argArray first value == #isSmalltalkX ifTrue:[
c891786676f3 class: MessageNode
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  3241
                        "/ true here !!
c891786676f3 class: MessageNode
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  3242
                        aBlock value:true.
c891786676f3 class: MessageNode
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  3243
                        ^ true
c891786676f3 class: MessageNode
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  3244
                    ].
c891786676f3 class: MessageNode
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  3245
                ].
c891786676f3 class: MessageNode
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  3246
            ].
c891786676f3 class: MessageNode
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  3247
        ].
c891786676f3 class: MessageNode
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  3248
        "/ (Smalltalk isSmalltalkX) -> true
2273
d952d08cf43c changed: #withConstantValueDo:
Claus Gittinger <cg@exept.de>
parents: 2270
diff changeset
  3249
        (selector == #isSmalltalkX) ifTrue:[
d952d08cf43c changed: #withConstantValueDo:
Claus Gittinger <cg@exept.de>
parents: 2270
diff changeset
  3250
            "/ true here !!
d952d08cf43c changed: #withConstantValueDo:
Claus Gittinger <cg@exept.de>
parents: 2270
diff changeset
  3251
            aBlock value:true.
d952d08cf43c changed: #withConstantValueDo:
Claus Gittinger <cg@exept.de>
parents: 2270
diff changeset
  3252
            ^ true
d952d08cf43c changed: #withConstantValueDo:
Claus Gittinger <cg@exept.de>
parents: 2270
diff changeset
  3253
        ].
d952d08cf43c changed: #withConstantValueDo:
Claus Gittinger <cg@exept.de>
parents: 2270
diff changeset
  3254
    ].
d952d08cf43c changed: #withConstantValueDo:
Claus Gittinger <cg@exept.de>
parents: 2270
diff changeset
  3255
2268
Claus Gittinger <cg@exept.de>
parents: 2208
diff changeset
  3256
    (receiver withConstantValueDo:[:val | recVal := val]) ifTrue:[
Claus Gittinger <cg@exept.de>
parents: 2208
diff changeset
  3257
        argValues := Array new:argArray size.
Claus Gittinger <cg@exept.de>
parents: 2208
diff changeset
  3258
        allArgsConstant := true.
2270
Claus Gittinger <cg@exept.de>
parents: 2268
diff changeset
  3259
        argArray notNil ifTrue:[
Claus Gittinger <cg@exept.de>
parents: 2268
diff changeset
  3260
            argArray doWithIndex:[:arg :index |
Claus Gittinger <cg@exept.de>
parents: 2268
diff changeset
  3261
                allArgsConstant := allArgsConstant
2268
Claus Gittinger <cg@exept.de>
parents: 2208
diff changeset
  3262
                                and:[ arg withConstantValueDo:[:val | argValues at:index put:val] ]
2270
Claus Gittinger <cg@exept.de>
parents: 2268
diff changeset
  3263
            ].
2268
Claus Gittinger <cg@exept.de>
parents: 2208
diff changeset
  3264
        ].
Claus Gittinger <cg@exept.de>
parents: 2208
diff changeset
  3265
        allArgsConstant ifTrue:[
3016
382e4e75d795 class: MessageNode
Claus Gittinger <cg@exept.de>
parents: 2941
diff changeset
  3266
            fold := true.
382e4e75d795 class: MessageNode
Claus Gittinger <cg@exept.de>
parents: 2941
diff changeset
  3267
2268
Claus Gittinger <cg@exept.de>
parents: 2208
diff changeset
  3268
            "/ only a few messages are checked:
Claus Gittinger <cg@exept.de>
parents: 2208
diff changeset
  3269
            recVal isNumber ifTrue:[
Claus Gittinger <cg@exept.de>
parents: 2208
diff changeset
  3270
                (#(positive negative abs negated + - * == = ~= ~~) includes:selector) ifFalse:[
3016
382e4e75d795 class: MessageNode
Claus Gittinger <cg@exept.de>
parents: 2941
diff changeset
  3271
                    recVal isInteger ifTrue:[
382e4e75d795 class: MessageNode
Claus Gittinger <cg@exept.de>
parents: 2941
diff changeset
  3272
                        (#(<< bitShift: bitAnd: bitOr:) includes:selector) ifFalse:[
382e4e75d795 class: MessageNode
Claus Gittinger <cg@exept.de>
parents: 2941
diff changeset
  3273
                            ^ false
382e4e75d795 class: MessageNode
Claus Gittinger <cg@exept.de>
parents: 2941
diff changeset
  3274
                        ].
382e4e75d795 class: MessageNode
Claus Gittinger <cg@exept.de>
parents: 2941
diff changeset
  3275
                    ] ifFalse:[
382e4e75d795 class: MessageNode
Claus Gittinger <cg@exept.de>
parents: 2941
diff changeset
  3276
                        ^ false
382e4e75d795 class: MessageNode
Claus Gittinger <cg@exept.de>
parents: 2941
diff changeset
  3277
                    ]
2268
Claus Gittinger <cg@exept.de>
parents: 2208
diff changeset
  3278
                ].
2331
471a6febf163 changed: #withConstantValueDo:
Claus Gittinger <cg@exept.de>
parents: 2329
diff changeset
  3279
            ] ifFalse:[
471a6febf163 changed: #withConstantValueDo:
Claus Gittinger <cg@exept.de>
parents: 2329
diff changeset
  3280
                recVal isBoolean ifTrue:[
471a6febf163 changed: #withConstantValueDo:
Claus Gittinger <cg@exept.de>
parents: 2329
diff changeset
  3281
                    (#(not && || ) includes:selector) ifFalse:[
471a6febf163 changed: #withConstantValueDo:
Claus Gittinger <cg@exept.de>
parents: 2329
diff changeset
  3282
                        ^ false
471a6febf163 changed: #withConstantValueDo:
Claus Gittinger <cg@exept.de>
parents: 2329
diff changeset
  3283
                    ].
471a6febf163 changed: #withConstantValueDo:
Claus Gittinger <cg@exept.de>
parents: 2329
diff changeset
  3284
                ] ifFalse:[
471a6febf163 changed: #withConstantValueDo:
Claus Gittinger <cg@exept.de>
parents: 2329
diff changeset
  3285
                    recVal isString ifTrue:[
471a6febf163 changed: #withConstantValueDo:
Claus Gittinger <cg@exept.de>
parents: 2329
diff changeset
  3286
                        (#(size) includes:selector) ifFalse:[
471a6febf163 changed: #withConstantValueDo:
Claus Gittinger <cg@exept.de>
parents: 2329
diff changeset
  3287
                            ^ false
471a6febf163 changed: #withConstantValueDo:
Claus Gittinger <cg@exept.de>
parents: 2329
diff changeset
  3288
                        ].
2925
9ab2302a632d changed: #withConstantValueDo:
Claus Gittinger <cg@exept.de>
parents: 2893
diff changeset
  3289
                    ] ifFalse:[
9ab2302a632d changed: #withConstantValueDo:
Claus Gittinger <cg@exept.de>
parents: 2893
diff changeset
  3290
                        recVal isArray ifTrue:[
9ab2302a632d changed: #withConstantValueDo:
Claus Gittinger <cg@exept.de>
parents: 2893
diff changeset
  3291
                            (#(size) includes:selector) ifFalse:[
9ab2302a632d changed: #withConstantValueDo:
Claus Gittinger <cg@exept.de>
parents: 2893
diff changeset
  3292
                                ^ false
9ab2302a632d changed: #withConstantValueDo:
Claus Gittinger <cg@exept.de>
parents: 2893
diff changeset
  3293
                            ].
3016
382e4e75d795 class: MessageNode
Claus Gittinger <cg@exept.de>
parents: 2941
diff changeset
  3294
                        ] ifFalse:[
382e4e75d795 class: MessageNode
Claus Gittinger <cg@exept.de>
parents: 2941
diff changeset
  3295
                            ^ false
382e4e75d795 class: MessageNode
Claus Gittinger <cg@exept.de>
parents: 2941
diff changeset
  3296
                        ]
2331
471a6febf163 changed: #withConstantValueDo:
Claus Gittinger <cg@exept.de>
parents: 2329
diff changeset
  3297
                    ].
471a6febf163 changed: #withConstantValueDo:
Claus Gittinger <cg@exept.de>
parents: 2329
diff changeset
  3298
                ]
2268
Claus Gittinger <cg@exept.de>
parents: 2208
diff changeset
  3299
            ].
3016
382e4e75d795 class: MessageNode
Claus Gittinger <cg@exept.de>
parents: 2941
diff changeset
  3300
        
2268
Claus Gittinger <cg@exept.de>
parents: 2208
diff changeset
  3301
            aBlock value:(recVal perform:selector withArguments:argValues).
Claus Gittinger <cg@exept.de>
parents: 2208
diff changeset
  3302
            ^ true
Claus Gittinger <cg@exept.de>
parents: 2208
diff changeset
  3303
        ].
3017
c891786676f3 class: MessageNode
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  3304
c891786676f3 class: MessageNode
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  3305
        "/ detects: ((Smalltalk respondsTo:#isSmalltalkX) and:[Smalltalk isSmalltalkX]) ifTrue:[
c891786676f3 class: MessageNode
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  3306
        selector == #and: ifTrue:[
c891786676f3 class: MessageNode
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  3307
            recVal == false ifTrue:[
c891786676f3 class: MessageNode
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  3308
                "/ false here !!
c891786676f3 class: MessageNode
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  3309
                aBlock value:recVal.
c891786676f3 class: MessageNode
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  3310
                ^ true "/ constant
c891786676f3 class: MessageNode
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  3311
            ].
c891786676f3 class: MessageNode
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  3312
            recVal == true ifTrue:[
c891786676f3 class: MessageNode
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  3313
                argArray first isBlockNode ifTrue:[
c891786676f3 class: MessageNode
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  3314
                    argArray first isSingleExpressionBlock ifTrue:[
c891786676f3 class: MessageNode
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  3315
                        cond2 := argArray first simpleSendBlockExpression.
c891786676f3 class: MessageNode
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  3316
                        cond2 notNil ifTrue:[
c891786676f3 class: MessageNode
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  3317
                            (cond2 withConstantValueDo:[:val | condVal2 := val]) ifTrue:[
c891786676f3 class: MessageNode
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  3318
                                aBlock value:condVal2.
c891786676f3 class: MessageNode
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  3319
                                ^ true "/ constant
c891786676f3 class: MessageNode
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  3320
                            ]
c891786676f3 class: MessageNode
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  3321
                        ]
c891786676f3 class: MessageNode
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  3322
                    ]                                          
c891786676f3 class: MessageNode
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  3323
                ]
c891786676f3 class: MessageNode
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  3324
            ].
c891786676f3 class: MessageNode
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  3325
        ].
2268
Claus Gittinger <cg@exept.de>
parents: 2208
diff changeset
  3326
    ].
Claus Gittinger <cg@exept.de>
parents: 2208
diff changeset
  3327
    ^ false
2925
9ab2302a632d changed: #withConstantValueDo:
Claus Gittinger <cg@exept.de>
parents: 2893
diff changeset
  3328
9ab2302a632d changed: #withConstantValueDo:
Claus Gittinger <cg@exept.de>
parents: 2893
diff changeset
  3329
    "Modified: / 12-09-2012 / 12:27:52 / cg"
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  3330
! !
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  3331
2321
3eb00a4f2c8a category change
Claus Gittinger <cg@exept.de>
parents: 2273
diff changeset
  3332
!MessageNode methodsFor:'testing'!
3eb00a4f2c8a category change
Claus Gittinger <cg@exept.de>
parents: 2273
diff changeset
  3333
3eb00a4f2c8a category change
Claus Gittinger <cg@exept.de>
parents: 2273
diff changeset
  3334
isMessage
3eb00a4f2c8a category change
Claus Gittinger <cg@exept.de>
parents: 2273
diff changeset
  3335
    ^ true
3eb00a4f2c8a category change
Claus Gittinger <cg@exept.de>
parents: 2273
diff changeset
  3336
! !
3eb00a4f2c8a category change
Claus Gittinger <cg@exept.de>
parents: 2273
diff changeset
  3337
2601
0bee48798eac - added acceptVisior:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2562
diff changeset
  3338
!MessageNode methodsFor:'visiting'!
0bee48798eac - added acceptVisior:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2562
diff changeset
  3339
0bee48798eac - added acceptVisior:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2562
diff changeset
  3340
acceptVisitor:aVisitor 
0bee48798eac - added acceptVisior:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2562
diff changeset
  3341
    "Double dispatch back to the visitor, passing my type encoded in
0bee48798eac - added acceptVisior:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2562
diff changeset
  3342
     the selector (visitor pattern)"
0bee48798eac - added acceptVisior:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2562
diff changeset
  3343
0bee48798eac - added acceptVisior:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2562
diff changeset
  3344
    "stub code automatically generated - please change if required"
0bee48798eac - added acceptVisior:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2562
diff changeset
  3345
0bee48798eac - added acceptVisior:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2562
diff changeset
  3346
    ^ aVisitor visitMessageNode:self
0bee48798eac - added acceptVisior:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2562
diff changeset
  3347
! !
0bee48798eac - added acceptVisior:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2562
diff changeset
  3348
370
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  3349
!MessageNode class methodsFor:'documentation'!
148
ef0e604209ec version method at the end
Claus Gittinger <cg@exept.de>
parents: 140
diff changeset
  3350
3017
c891786676f3 class: MessageNode
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  3351
version
3290
ed93979b62ac class: MessageNode
Claus Gittinger <cg@exept.de>
parents: 3278
diff changeset
  3352
    ^ '$Header: /cvs/stx/stx/libcomp/MessageNode.st,v 1.201 2013-08-26 13:44:37 cg Exp $'
3017
c891786676f3 class: MessageNode
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  3353
!
c891786676f3 class: MessageNode
Claus Gittinger <cg@exept.de>
parents: 3016
diff changeset
  3354
2496
4d67e1d9423b Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2489
diff changeset
  3355
version_CVS
3290
ed93979b62ac class: MessageNode
Claus Gittinger <cg@exept.de>
parents: 3278
diff changeset
  3356
    ^ '$Header: /cvs/stx/stx/libcomp/MessageNode.st,v 1.201 2013-08-26 13:44:37 cg Exp $'
2268
Claus Gittinger <cg@exept.de>
parents: 2208
diff changeset
  3357
!
Claus Gittinger <cg@exept.de>
parents: 2208
diff changeset
  3358
2496
4d67e1d9423b Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2489
diff changeset
  3359
version_SVN
3164
f11d0862c65e Emit #lineno16 byte codes only, if line number really changes
Stefan Vogel <sv@exept.de>
parents: 3108
diff changeset
  3360
    ^ '$ Id $'
148
ef0e604209ec version method at the end
Claus Gittinger <cg@exept.de>
parents: 140
diff changeset
  3361
! !
3016
382e4e75d795 class: MessageNode
Claus Gittinger <cg@exept.de>
parents: 2941
diff changeset
  3362