MessageNode.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Wed, 27 Jul 2011 17:00:21 +0200
changeset 2610 398820190422
parent 2601 0bee48798eac
child 2617 160ca364f3d3
permissions -rw-r--r--
More fixes to keep node position in the source. Not yet fully implemented
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
4d67e1d9423b Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2489
diff changeset
    16
		endLineNr endCharPosition'
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
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
   197
                ]
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
        "/ #perform with a constant selector
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
   203
        "/
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
   204
        (selector == #perform: 
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
   205
        and:[argNode isConstant]) ifTrue:[
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
   206
            argVal := argNode evaluate.
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
   207
            argVal isSymbol ifTrue:[
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
   208
                ^ UnaryNode receiver:recNode selector:argVal fold:folding
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
   209
            ]
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
   210
        ].
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   211
    ].
212
ff39051e219f more constant folding options
Claus Gittinger <cg@exept.de>
parents: 204
diff changeset
   212
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   213
    ^ (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
   214
993
902eec8d132b oops - folding argument is not always a symbol.
Claus Gittinger <cg@exept.de>
parents: 992
diff changeset
   215
    "Modified: / 16.11.1999 / 21:50:33 / cg"
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   216
!
7ad01559b262 Initial revision
claus
parents:
diff changeset
   217
7ad01559b262 Initial revision
claus
parents:
diff changeset
   218
receiver:recNode selector:selectorString args:anArray
212
ff39051e219f more constant folding options
Claus Gittinger <cg@exept.de>
parents: 204
diff changeset
   219
    ^ self receiver:recNode selector:selectorString args:anArray fold:nil
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:argArray fold:folding
639
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
   223
    |numArgs arg1 arg1Val|
117
claus
parents: 111
diff changeset
   224
212
ff39051e219f more constant folding options
Claus Gittinger <cg@exept.de>
parents: 204
diff changeset
   225
    folding notNil ifTrue:[
715
408ac886ffc1 allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents: 676
diff changeset
   226
        numArgs := argArray size.
408ac886ffc1 allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents: 676
diff changeset
   227
        numArgs > 0 ifTrue:[
408ac886ffc1 allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents: 676
diff changeset
   228
            arg1 := (argArray at:1).
408ac886ffc1 allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents: 676
diff changeset
   229
            (numArgs == 1) ifTrue:[
408ac886ffc1 allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents: 676
diff changeset
   230
                ^ 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
   231
            ].
20
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
   232
715
408ac886ffc1 allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents: 676
diff changeset
   233
            "/
408ac886ffc1 allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents: 676
diff changeset
   234
            "/ #perform:... with a constant selector
408ac886ffc1 allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents: 676
diff changeset
   235
            "/
408ac886ffc1 allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents: 676
diff changeset
   236
            numArgs <= 6 ifTrue:[
408ac886ffc1 allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents: 676
diff changeset
   237
                (#(nil
408ac886ffc1 allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents: 676
diff changeset
   238
                   #'perform:with:'
408ac886ffc1 allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents: 676
diff changeset
   239
                   #'perform:with:with:'
408ac886ffc1 allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents: 676
diff changeset
   240
                   #'perform:with:with:with:'
408ac886ffc1 allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents: 676
diff changeset
   241
                   #'perform:with:with:with:with:'
408ac886ffc1 allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents: 676
diff changeset
   242
                   #'perform:with:with:with:with:with:'
408ac886ffc1 allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents: 676
diff changeset
   243
                   #'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
   244
                ) at:numArgs) = selectorString 
408ac886ffc1 allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents: 676
diff changeset
   245
                ifTrue:[
408ac886ffc1 allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents: 676
diff changeset
   246
                    arg1 isConstant ifTrue:[    
408ac886ffc1 allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents: 676
diff changeset
   247
                        arg1Val := arg1 evaluate.
408ac886ffc1 allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents: 676
diff changeset
   248
                        arg1Val isSymbol ifTrue:[
408ac886ffc1 allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents: 676
diff changeset
   249
                            ^ MessageNode 
408ac886ffc1 allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents: 676
diff changeset
   250
                                    receiver:recNode 
408ac886ffc1 allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents: 676
diff changeset
   251
                                    selector:arg1Val
408ac886ffc1 allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents: 676
diff changeset
   252
                                    args:(argArray copyFrom:2)
408ac886ffc1 allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents: 676
diff changeset
   253
                                    fold:folding
408ac886ffc1 allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents: 676
diff changeset
   254
                        ]
408ac886ffc1 allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents: 676
diff changeset
   255
                    ]
408ac886ffc1 allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents: 676
diff changeset
   256
                ]
408ac886ffc1 allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents: 676
diff changeset
   257
            ].
408ac886ffc1 allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents: 676
diff changeset
   258
        ].
639
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
   259
715
408ac886ffc1 allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents: 676
diff changeset
   260
        (numArgs == 2) ifTrue:[
408ac886ffc1 allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents: 676
diff changeset
   261
            ^ 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
   262
        ].
408ac886ffc1 allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents: 676
diff changeset
   263
        numArgs > Method maxNumberOfArguments ifTrue:[
1533
bff4a03d6d48 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1529
diff changeset
   264
            ^ 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
   265
        ].
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   266
    ].
117
claus
parents: 111
diff changeset
   267
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   268
    ^ (self basicNew) receiver:recNode selector:selectorString args:argArray lineno:0
117
claus
parents: 111
diff changeset
   269
639
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
   270
    "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
   271
    "Modified: / 15.5.1998 / 15:32:05 / cg"
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   272
! !
7ad01559b262 Initial revision
claus
parents:
diff changeset
   273
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   274
!MessageNode methodsFor:'accessing'!
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   275
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   276
arg1
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   277
    ^ argArray at:1
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   278
!
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   279
1639
65686abde429 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1629
diff changeset
   280
arg2
65686abde429 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1629
diff changeset
   281
    ^ argArray at:2
65686abde429 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1629
diff changeset
   282
!
65686abde429 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1629
diff changeset
   283
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   284
args
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   285
    ^ argArray
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   286
!
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   287
543
de47f8969fd9 more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
   288
arguments
de47f8969fd9 more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
   289
    ^ argArray ? #()
de47f8969fd9 more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
   290
de47f8969fd9 more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
   291
    "Created: 19.6.1997 / 17:31:14 / cg"
de47f8969fd9 more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
   292
    "Modified: 19.6.1997 / 17:32:25 / cg"
de47f8969fd9 more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
   293
!
de47f8969fd9 more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
   294
2496
4d67e1d9423b Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2489
diff changeset
   295
endCharPosition
4d67e1d9423b Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2489
diff changeset
   296
    ^ endCharPosition
4d67e1d9423b Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2489
diff changeset
   297
!
4d67e1d9423b Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2489
diff changeset
   298
4d67e1d9423b Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2489
diff changeset
   299
endCharPosition:something
4d67e1d9423b Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2489
diff changeset
   300
    endCharPosition := something.
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
endLineNr
4d67e1d9423b Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2489
diff changeset
   304
    ^ endLineNr
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:something
4d67e1d9423b Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2489
diff changeset
   308
    endLineNr := something.
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
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   311
lineNumber
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   312
     ^ lineNr
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   313
!
7ad01559b262 Initial revision
claus
parents:
diff changeset
   314
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   315
lineNumber:num
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   316
     lineNr := num
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   317
!
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   318
2496
4d67e1d9423b Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2489
diff changeset
   319
lines
4d67e1d9423b Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2489
diff changeset
   320
    ^ lines
4d67e1d9423b Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2489
diff changeset
   321
!
4d67e1d9423b Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2489
diff changeset
   322
4d67e1d9423b Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2489
diff changeset
   323
lines:something
4d67e1d9423b Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2489
diff changeset
   324
    lines := something.
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
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   327
receiver
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   328
    ^ receiver
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   329
!
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   330
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   331
receiver:r selector:s args:a lineno:l
2601
0bee48798eac - added acceptVisior:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2562
diff changeset
   332
0bee48798eac - added acceptVisior:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2562
diff changeset
   333
    receiver notNil ifTrue:[receiver parent: nil].
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   334
    receiver := r.
2601
0bee48798eac - added acceptVisior:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2562
diff changeset
   335
    receiver notNil ifTrue:[receiver parent: self].
1500
3c4cb012b24b Lazy conversion of selector strings to symbols.
Stefan Vogel <sv@exept.de>
parents: 1480
diff changeset
   336
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
   337
    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
   338
1500
3c4cb012b24b Lazy conversion of selector strings to symbols.
Stefan Vogel <sv@exept.de>
parents: 1480
diff changeset
   339
"/ 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
   340
"/ 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
   341
"/ during typing
3c4cb012b24b Lazy conversion of selector strings to symbols.
Stefan Vogel <sv@exept.de>
parents: 1480
diff changeset
   342
"/    selector := s asSymbol.
3c4cb012b24b Lazy conversion of selector strings to symbols.
Stefan Vogel <sv@exept.de>
parents: 1480
diff changeset
   343
3c4cb012b24b Lazy conversion of selector strings to symbols.
Stefan Vogel <sv@exept.de>
parents: 1480
diff changeset
   344
    selector := s asSymbolIfInterned ? s.
3c4cb012b24b Lazy conversion of selector strings to symbols.
Stefan Vogel <sv@exept.de>
parents: 1480
diff changeset
   345
2601
0bee48798eac - added acceptVisior:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2562
diff changeset
   346
    argArray isNil ifFalse:[argArray do:[:each|each parent: nil]].
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   347
    argArray := a.
2601
0bee48798eac - added acceptVisior:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2562
diff changeset
   348
    argArray isNil ifFalse:[argArray do:[:each|each parent: self]].
0bee48798eac - added acceptVisior:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2562
diff changeset
   349
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
   350
    argArray notEmptyOrNil ifTrue:[
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
   351
        endPosition := argArray last endPosition
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
   352
    ].
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
   353
574
993d1182782b fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents: 570
diff changeset
   354
    lineNr := l.
993d1182782b fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents: 570
diff changeset
   355
    self checkInlinability.
993d1182782b fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents: 570
diff changeset
   356
2601
0bee48798eac - added acceptVisior:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2562
diff changeset
   357
    "Modified: / 02-07-1997 / 17:01:24 / cg"
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
   358
    "Modified: / 27-07-2011 / 15:05:32 / Jan Vrany <jan.vrany@fit.cvut.cz>"
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   359
!
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   360
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   361
selector
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   362
    ^ selector
595
a90e8d8bf417 remember position of selector
Claus Gittinger <cg@exept.de>
parents: 578
diff changeset
   363
!
a90e8d8bf417 remember position of selector
Claus Gittinger <cg@exept.de>
parents: 578
diff changeset
   364
1384
0db9682870d9 evaluate -> evaluateIn:
Claus Gittinger <cg@exept.de>
parents: 1382
diff changeset
   365
selector:s
1500
3c4cb012b24b Lazy conversion of selector strings to symbols.
Stefan Vogel <sv@exept.de>
parents: 1480
diff changeset
   366
"/ 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
   367
"/ 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
   368
"/ during typing
3c4cb012b24b Lazy conversion of selector strings to symbols.
Stefan Vogel <sv@exept.de>
parents: 1480
diff changeset
   369
"/    selector := s asSymbol.
3c4cb012b24b Lazy conversion of selector strings to symbols.
Stefan Vogel <sv@exept.de>
parents: 1480
diff changeset
   370
3c4cb012b24b Lazy conversion of selector strings to symbols.
Stefan Vogel <sv@exept.de>
parents: 1480
diff changeset
   371
    selector := s asSymbolIfInterned ? s.
3c4cb012b24b Lazy conversion of selector strings to symbols.
Stefan Vogel <sv@exept.de>
parents: 1480
diff changeset
   372
"/    selector := s asSymbol.
1384
0db9682870d9 evaluate -> evaluateIn:
Claus Gittinger <cg@exept.de>
parents: 1382
diff changeset
   373
!
0db9682870d9 evaluate -> evaluateIn:
Claus Gittinger <cg@exept.de>
parents: 1382
diff changeset
   374
595
a90e8d8bf417 remember position of selector
Claus Gittinger <cg@exept.de>
parents: 578
diff changeset
   375
selectorPosition
a90e8d8bf417 remember position of selector
Claus Gittinger <cg@exept.de>
parents: 578
diff changeset
   376
    "return the value of the instance variable 'selectorPosition' (automatically generated)"
a90e8d8bf417 remember position of selector
Claus Gittinger <cg@exept.de>
parents: 578
diff changeset
   377
a90e8d8bf417 remember position of selector
Claus Gittinger <cg@exept.de>
parents: 578
diff changeset
   378
    ^ selectorPosition
a90e8d8bf417 remember position of selector
Claus Gittinger <cg@exept.de>
parents: 578
diff changeset
   379
a90e8d8bf417 remember position of selector
Claus Gittinger <cg@exept.de>
parents: 578
diff changeset
   380
    "Created: 5.8.1997 / 02:49:27 / cg"
a90e8d8bf417 remember position of selector
Claus Gittinger <cg@exept.de>
parents: 578
diff changeset
   381
!
a90e8d8bf417 remember position of selector
Claus Gittinger <cg@exept.de>
parents: 578
diff changeset
   382
a90e8d8bf417 remember position of selector
Claus Gittinger <cg@exept.de>
parents: 578
diff changeset
   383
selectorPosition:something
a90e8d8bf417 remember position of selector
Claus Gittinger <cg@exept.de>
parents: 578
diff changeset
   384
    "set the value of the instance variable 'selectorPosition' (automatically generated)"
a90e8d8bf417 remember position of selector
Claus Gittinger <cg@exept.de>
parents: 578
diff changeset
   385
a90e8d8bf417 remember position of selector
Claus Gittinger <cg@exept.de>
parents: 578
diff changeset
   386
    selectorPosition := something.
a90e8d8bf417 remember position of selector
Claus Gittinger <cg@exept.de>
parents: 578
diff changeset
   387
a90e8d8bf417 remember position of selector
Claus Gittinger <cg@exept.de>
parents: 578
diff changeset
   388
    "Created: 5.8.1997 / 02:49:27 / cg"
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   389
! !
7ad01559b262 Initial revision
claus
parents:
diff changeset
   390
7ad01559b262 Initial revision
claus
parents:
diff changeset
   391
!MessageNode methodsFor:'checks'!
7ad01559b262 Initial revision
claus
parents:
diff changeset
   392
1626
6addd73f7d47 precedence check for if-condition
Claus Gittinger <cg@exept.de>
parents: 1588
diff changeset
   393
checkCondition
2489
da5775ff9f1f comment
Michael Beyl <mb@exept.de>
parents: 2429
diff changeset
   394
    "check ifTrue/ifFalse for plausibility"
da5775ff9f1f comment
Michael Beyl <mb@exept.de>
parents: 2429
diff changeset
   395
2102
0d60bf6818d7 obfuscated code detection
Claus Gittinger <cg@exept.de>
parents: 2096
diff changeset
   396
    |args lastArg receiverSelector or1 or2|
1626
6addd73f7d47 precedence check for if-condition
Claus Gittinger <cg@exept.de>
parents: 1588
diff changeset
   397
6addd73f7d47 precedence check for if-condition
Claus Gittinger <cg@exept.de>
parents: 1588
diff changeset
   398
    receiver isBlock ifTrue:[
6addd73f7d47 precedence check for if-condition
Claus Gittinger <cg@exept.de>
parents: 1588
diff changeset
   399
        (Block canUnderstand:selector) ifFalse:[
6addd73f7d47 precedence check for if-condition
Claus Gittinger <cg@exept.de>
parents: 1588
diff changeset
   400
            ^ 'blocks usually do not respond to ' , selector , ' messages'
6addd73f7d47 precedence check for if-condition
Claus Gittinger <cg@exept.de>
parents: 1588
diff changeset
   401
        ].
6addd73f7d47 precedence check for if-condition
Claus Gittinger <cg@exept.de>
parents: 1588
diff changeset
   402
    ].
6addd73f7d47 precedence check for if-condition
Claus Gittinger <cg@exept.de>
parents: 1588
diff changeset
   403
6addd73f7d47 precedence check for if-condition
Claus Gittinger <cg@exept.de>
parents: 1588
diff changeset
   404
    "/ (rr keyw:ra = a) ifTrue:[ ...]
6addd73f7d47 precedence check for if-condition
Claus Gittinger <cg@exept.de>
parents: 1588
diff changeset
   405
6addd73f7d47 precedence check for if-condition
Claus Gittinger <cg@exept.de>
parents: 1588
diff changeset
   406
    receiver isMessage ifTrue:[
6addd73f7d47 precedence check for if-condition
Claus Gittinger <cg@exept.de>
parents: 1588
diff changeset
   407
        (receiver numArgs > 0) ifTrue:[
2102
0d60bf6818d7 obfuscated code detection
Claus Gittinger <cg@exept.de>
parents: 2096
diff changeset
   408
            receiverSelector := receiver selector asSymbol.
0d60bf6818d7 obfuscated code detection
Claus Gittinger <cg@exept.de>
parents: 2096
diff changeset
   409
            (receiverSelector isKeyword) ifTrue:[
1626
6addd73f7d47 precedence check for if-condition
Claus Gittinger <cg@exept.de>
parents: 1588
diff changeset
   410
                (args := receiver arguments) notEmptyOrNil ifTrue:[
6addd73f7d47 precedence check for if-condition
Claus Gittinger <cg@exept.de>
parents: 1588
diff changeset
   411
                    (lastArg := args last) isMessage ifTrue:[
1989
e6a763ac2587 oops - parenthesized was written with typo
Claus Gittinger <cg@exept.de>
parents: 1809
diff changeset
   412
                        lastArg parenthesized ifFalse:[
1626
6addd73f7d47 precedence check for if-condition
Claus Gittinger <cg@exept.de>
parents: 1588
diff changeset
   413
                            (#( #'=' #'~=' #'==' #'~~' '>' '<' '>=' '<=') 
1629
8f69fe5b0fea *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1628
diff changeset
   414
                            includes:(lastArg selector asSymbol)) ifTrue:[
1628
9641d61e717f precedence check for if-condition
Claus Gittinger <cg@exept.de>
parents: 1627
diff changeset
   415
                                ^ 'possible precedence error in condition (missing parenthesis ?)'
1626
6addd73f7d47 precedence check for if-condition
Claus Gittinger <cg@exept.de>
parents: 1588
diff changeset
   416
                            ]
6addd73f7d47 precedence check for if-condition
Claus Gittinger <cg@exept.de>
parents: 1588
diff changeset
   417
                        ]
2102
0d60bf6818d7 obfuscated code detection
Claus Gittinger <cg@exept.de>
parents: 2096
diff changeset
   418
                    ].
0d60bf6818d7 obfuscated code detection
Claus Gittinger <cg@exept.de>
parents: 2096
diff changeset
   419
                ].
0d60bf6818d7 obfuscated code detection
Claus Gittinger <cg@exept.de>
parents: 2096
diff changeset
   420
0d60bf6818d7 obfuscated code detection
Claus Gittinger <cg@exept.de>
parents: 2096
diff changeset
   421
                (selector == #ifFalse: or:[ selector == #ifFalse:ifTrue: ]) ifTrue:[
0d60bf6818d7 obfuscated code detection
Claus Gittinger <cg@exept.de>
parents: 2096
diff changeset
   422
                    receiverSelector == #or: ifTrue:[
0d60bf6818d7 obfuscated code detection
Claus Gittinger <cg@exept.de>
parents: 2096
diff changeset
   423
                        or1 := receiver receiver.    
0d60bf6818d7 obfuscated code detection
Claus Gittinger <cg@exept.de>
parents: 2096
diff changeset
   424
                        or2 := receiver arg1.
0d60bf6818d7 obfuscated code detection
Claus Gittinger <cg@exept.de>
parents: 2096
diff changeset
   425
                        (or1 isMessage and:[or1 selector = '~~']) ifTrue:[
0d60bf6818d7 obfuscated code detection
Claus Gittinger <cg@exept.de>
parents: 2096
diff changeset
   426
                            (or2 isBlock 
0d60bf6818d7 obfuscated code detection
Claus Gittinger <cg@exept.de>
parents: 2096
diff changeset
   427
                            and:[ or2 isSingleExpressionBlock
0d60bf6818d7 obfuscated code detection
Claus Gittinger <cg@exept.de>
parents: 2096
diff changeset
   428
                            and:[ or2 statements expression isMessage 
0d60bf6818d7 obfuscated code detection
Claus Gittinger <cg@exept.de>
parents: 2096
diff changeset
   429
                            and:[ or2 statements expression selector = '~~']]]) ifTrue:[
0d60bf6818d7 obfuscated code detection
Claus Gittinger <cg@exept.de>
parents: 2096
diff changeset
   430
                                ^ 'please use "((...==...) and:[...==...]) ifTrue:" here\\(are you obfuscating by purpose ?)'
0d60bf6818d7 obfuscated code detection
Claus Gittinger <cg@exept.de>
parents: 2096
diff changeset
   431
                            ].
0d60bf6818d7 obfuscated code detection
Claus Gittinger <cg@exept.de>
parents: 2096
diff changeset
   432
                        ].
0d60bf6818d7 obfuscated code detection
Claus Gittinger <cg@exept.de>
parents: 2096
diff changeset
   433
                    ].
0d60bf6818d7 obfuscated code detection
Claus Gittinger <cg@exept.de>
parents: 2096
diff changeset
   434
                ].
1626
6addd73f7d47 precedence check for if-condition
Claus Gittinger <cg@exept.de>
parents: 1588
diff changeset
   435
            ]
6addd73f7d47 precedence check for if-condition
Claus Gittinger <cg@exept.de>
parents: 1588
diff changeset
   436
        ].
6addd73f7d47 precedence check for if-condition
Claus Gittinger <cg@exept.de>
parents: 1588
diff changeset
   437
    ].
6addd73f7d47 precedence check for if-condition
Claus Gittinger <cg@exept.de>
parents: 1588
diff changeset
   438
6addd73f7d47 precedence check for if-condition
Claus Gittinger <cg@exept.de>
parents: 1588
diff changeset
   439
    ^ nil
6addd73f7d47 precedence check for if-condition
Claus Gittinger <cg@exept.de>
parents: 1588
diff changeset
   440
!
6addd73f7d47 precedence check for if-condition
Claus Gittinger <cg@exept.de>
parents: 1588
diff changeset
   441
2208
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   442
checkGlobalFromNameSpaceConflictFor:aNode
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   443
    "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
   444
     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
   445
     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
   446
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   447
    |fullName shortName|
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   448
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   449
    aNode isGlobalVariable ifTrue:[
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   450
        fullName := aNode name.
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   451
        shortName := Class nameWithoutPrefix:fullName.
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   452
        shortName ~= fullName ifTrue:[
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   453
            (Smalltalk includesKey:shortName) ifTrue:[
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   454
                ^ '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
   455
            ].
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   456
        ].
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   457
    ].
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   458
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   459
    ^ nil.
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   460
!
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   461
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   462
checkIdentityCompare
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   463
    |rec arg1 arg1Value operand|
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
    "
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   466
     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
   467
    "
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   468
    ((selector == #==) or:[selector == #~~]) ifTrue:[
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   469
        (argArray size > 0) ifTrue:[
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   470
            arg1 := argArray at:1
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   471
        ].
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   472
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
         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
   475
         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
   476
         (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
   477
          - 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
   478
         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
   479
         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
   480
         (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
   481
        "
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
        receiver isConstant ifTrue:[
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   484
            rec := receiver evaluate.
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   485
            ((rec isMemberOf:String) or:[
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   486
             (rec isMemberOf:Float) or:[
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   487
             (rec isMemberOf:Fraction)]]) ifTrue:[
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   488
                operand := rec
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
        arg1 isConstant ifTrue:[
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   492
            arg1Value := arg1 evaluate.
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   493
            ((arg1Value isMemberOf:String) or:[
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   494
             (arg1Value isMemberOf:Float) or:[
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   495
             (arg1Value isMemberOf:Fraction)]]) ifTrue:[
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   496
                operand := arg1Value
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   497
            ].
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   498
        ].
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   499
        operand notNil ifTrue:[
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   500
            (selector == #==) ifTrue:[
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   501
                ^ 'identity compare is unsafe here'
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   502
            ].
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   503
            ^ 'identity compare will usually return true here'
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   504
        ]
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   505
    ].
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   506
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   507
    ^ nil
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
574
993d1182782b fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents: 570
diff changeset
   510
checkInlinability
993d1182782b fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents: 570
diff changeset
   511
    "early check for possible inlinability"
993d1182782b fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents: 570
diff changeset
   512
993d1182782b fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents: 570
diff changeset
   513
    |numArgs arg1 arg2 arg3|
993d1182782b fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents: 570
diff changeset
   514
993d1182782b fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents: 570
diff changeset
   515
    (numArgs := argArray size) >= 1 ifTrue:[
676
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   516
        arg1 := argArray at:1.
574
993d1182782b fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents: 570
diff changeset
   517
    ].
993d1182782b fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents: 570
diff changeset
   518
    numArgs == 0 ifTrue:[
676
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   519
        (selector == #whileTrue 
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   520
        or:[selector == #whileFalse]) ifTrue:[
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   521
            receiver isBlock ifTrue:[
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   522
                receiver possiblyInlined:true
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   523
            ].
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   524
        ].
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   525
        (selector == #value) ifTrue:[
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   526
            receiver isBlock ifTrue:[
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   527
                receiver possiblyInlined:true
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   528
            ].
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   529
        ].
1425
4f698bf5ff76 inline [...] loop
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
   530
        ((selector == #repeat) or:[selector == #loop]) ifTrue:[
676
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   531
            receiver isBlock ifTrue:[
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   532
                receiver possiblyInlined:true
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   533
            ].
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   534
        ].
574
993d1182782b fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents: 570
diff changeset
   535
    ].
993d1182782b fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents: 570
diff changeset
   536
993d1182782b fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents: 570
diff changeset
   537
    numArgs == 1 ifTrue:[
676
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   538
        (selector == #or: 
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   539
        or:[selector == #and:]) ifTrue:[
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   540
            arg1 isBlock ifTrue:[
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   541
                arg1 possiblyInlined:true
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   542
            ].
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   543
        ].
576
5cb4af0eea67 also inline and:/or: ...
Claus Gittinger <cg@exept.de>
parents: 574
diff changeset
   544
676
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   545
        (selector == #ifTrue: 
898
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
   546
        or:[selector == #ifFalse:
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
   547
        or:[selector == #ifNil:
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
   548
        or:[selector == #ifNotNil:]]]) ifTrue:[
676
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   549
            arg1 isBlock ifTrue:[
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   550
                arg1 possiblyInlined:true
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   551
            ].
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   552
        ].
574
993d1182782b fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents: 570
diff changeset
   553
676
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   554
        (selector == #whileTrue: 
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   555
        or:[selector == #whileFalse:]) ifTrue:[
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   556
            arg1 isBlock ifTrue:[
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   557
                arg1 possiblyInlined:true
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   558
            ].
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   559
            receiver isBlock ifTrue:[
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   560
                receiver possiblyInlined:true
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   561
            ].
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
        selector == #timesRepeat: ifTrue:[
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   564
            arg1 isBlock ifTrue:[
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   565
                arg1 possiblyInlined:true withSelector:selector.
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   566
            ]
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   567
        ].
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   568
        ^ self
574
993d1182782b fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents: 570
diff changeset
   569
    ].
993d1182782b fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents: 570
diff changeset
   570
    numArgs >= 2 ifTrue:[
676
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   571
        arg2 := argArray at:2.
574
993d1182782b fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents: 570
diff changeset
   572
    ].    
993d1182782b fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents: 570
diff changeset
   573
    numArgs == 2 ifTrue:[
676
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   574
        (selector == #ifTrue:ifFalse:
898
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
   575
        or:[selector == #ifFalse:ifTrue:
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
   576
        or:[selector == #ifNil:ifNotNil:
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
   577
        or:[selector == #ifNotNil:ifNil:]]]) ifTrue:[
676
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   578
            (arg1 isBlock 
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   579
            and:[arg2 isBlock]) ifTrue:[
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   580
                arg1 possiblyInlined:true.
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   581
                arg2 possiblyInlined:true.
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
        ].
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   584
        selector == #to:do: ifTrue:[
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   585
            arg2 isBlock ifTrue:[
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   586
                arg2 possiblyInlined:true withSelector:selector.
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
        ].
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   589
        ^ self
574
993d1182782b fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents: 570
diff changeset
   590
    ].
993d1182782b fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents: 570
diff changeset
   591
    numArgs >= 3 ifTrue:[
676
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   592
        arg3 := argArray at:3.
574
993d1182782b fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents: 570
diff changeset
   593
    ].    
993d1182782b fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents: 570
diff changeset
   594
    numArgs == 3 ifTrue:[
676
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   595
        selector == #to:by:do: ifTrue:[
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   596
            arg3 isBlock ifTrue:[
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   597
                arg3 possiblyInlined:true withSelector:selector.
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   598
            ].
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   599
        ].
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   600
        ^ self
574
993d1182782b fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents: 570
diff changeset
   601
    ].
993d1182782b fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents: 570
diff changeset
   602
    ^ self
993d1182782b fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents: 570
diff changeset
   603
676
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   604
    "Created: / 2.7.1997 / 17:01:10 / cg"
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   605
    "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
   606
!
993d1182782b fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents: 570
diff changeset
   607
2096
b993f62fab49 alreadyWarned selectors
Claus Gittinger <cg@exept.de>
parents: 2028
diff changeset
   608
plausibilityCheckIn:aParser
2208
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   609
    |arg1 msg|
902
4ceee83e5e07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 899
diff changeset
   610
4ceee83e5e07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 899
diff changeset
   611
    (argArray size > 0) ifTrue:[
4ceee83e5e07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 899
diff changeset
   612
        arg1 := argArray at:1
4ceee83e5e07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 899
diff changeset
   613
    ].
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   614
3
b63b8a6b71fb *** empty log message ***
claus
parents: 0
diff changeset
   615
    "
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   616
     check #== applied to Floats, Strings or Fractions
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   617
    "
7ad01559b262 Initial revision
claus
parents:
diff changeset
   618
    ((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
   619
        (msg := self checkIdentityCompare) notNil ifTrue:[^ msg].
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   620
    ].
3
b63b8a6b71fb *** empty log message ***
claus
parents: 0
diff changeset
   621
b63b8a6b71fb *** empty log message ***
claus
parents: 0
diff changeset
   622
    "
19
84a1ddf215a5 *** empty log message ***
claus
parents: 15
diff changeset
   623
     [...] ifTrue:...
3
b63b8a6b71fb *** empty log message ***
claus
parents: 0
diff changeset
   624
     an error often occuring when you are a beginner ...
b63b8a6b71fb *** empty log message ***
claus
parents: 0
diff changeset
   625
    "
b63b8a6b71fb *** empty log message ***
claus
parents: 0
diff changeset
   626
    ((selector == #ifTrue:) or:[selector == #ifFalse:]) ifTrue:[
1626
6addd73f7d47 precedence check for if-condition
Claus Gittinger <cg@exept.de>
parents: 1588
diff changeset
   627
        (msg := self checkCondition) notNil ifTrue:[^ msg].
3
b63b8a6b71fb *** empty log message ***
claus
parents: 0
diff changeset
   628
    ].
19
84a1ddf215a5 *** empty log message ***
claus
parents: 15
diff changeset
   629
    ((selector == #ifTrue:ifFalse:) or:[selector == #ifFalse:ifTrue:]) ifTrue:[
1626
6addd73f7d47 precedence check for if-condition
Claus Gittinger <cg@exept.de>
parents: 1588
diff changeset
   630
        (msg := self checkCondition) notNil ifTrue:[^ msg].
3
b63b8a6b71fb *** empty log message ***
claus
parents: 0
diff changeset
   631
    ].
19
84a1ddf215a5 *** empty log message ***
claus
parents: 15
diff changeset
   632
84a1ddf215a5 *** empty log message ***
claus
parents: 15
diff changeset
   633
    "
84a1ddf215a5 *** empty log message ***
claus
parents: 15
diff changeset
   634
     (...) whileTrue:[
84a1ddf215a5 *** empty log message ***
claus
parents: 15
diff changeset
   635
    "
3
b63b8a6b71fb *** empty log message ***
claus
parents: 0
diff changeset
   636
    ((selector == #whileTrue:) or:[selector == #whileFalse:]) ifTrue:[
2028
a9b5ec797153 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1994
diff changeset
   637
        (receiver isBlock not and:[ receiver parenthesized ]) ifTrue:[
a9b5ec797153 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1994
diff changeset
   638
            "/ only warn, if code was originally parenthized
a9b5ec797153 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1994
diff changeset
   639
            ^ '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
   640
        ].
902
4ceee83e5e07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 899
diff changeset
   641
        arg1 isBlock ifFalse:[
1059
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
   642
            ^ '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
   643
        ].
3
b63b8a6b71fb *** empty log message ***
claus
parents: 0
diff changeset
   644
    ].
902
4ceee83e5e07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 899
diff changeset
   645
2028
a9b5ec797153 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1994
diff changeset
   646
    "
a9b5ec797153 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1994
diff changeset
   647
     [...] ensure:[...]
a9b5ec797153 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1994
diff changeset
   648
    "
a9b5ec797153 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1994
diff changeset
   649
    ((selector == #ensure:) or:[(selector == #ifCurtailed:)]) ifTrue:[
a9b5ec797153 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1994
diff changeset
   650
        (receiver isBlock not and:[ receiver parenthesized ]) ifTrue:[
a9b5ec797153 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1994
diff changeset
   651
            "/ only warn, if code was originally parenthized
a9b5ec797153 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1994
diff changeset
   652
            ^ '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
   653
        ].
a9b5ec797153 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1994
diff changeset
   654
        (arg1 isBlock not and:[ arg1 parenthesized ]) ifTrue:[
a9b5ec797153 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1994
diff changeset
   655
            ^ '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
   656
        ].
a9b5ec797153 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1994
diff changeset
   657
        (arg1 isBlock and:[arg1 isEmptyBlock]) ifTrue:[
a9b5ec797153 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1994
diff changeset
   658
            ^ 'useless ensure (empty block)'
a9b5ec797153 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1994
diff changeset
   659
        ].
a9b5ec797153 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1994
diff changeset
   660
    ].
a9b5ec797153 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1994
diff changeset
   661
905
9d5500bffa74 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 902
diff changeset
   662
    argArray size > 0 ifTrue:[
9d5500bffa74 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 902
diff changeset
   663
        "/ check for a beginners error (using super as arg)
9d5500bffa74 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 902
diff changeset
   664
        "/ as in (something ? super) foo
9d5500bffa74 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 902
diff changeset
   665
9d5500bffa74 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 902
diff changeset
   666
        argArray do:[:arg | arg isSuper ifTrue:[
1192
b13a83abf72f warning message
Claus Gittinger <cg@exept.de>
parents: 1154
diff changeset
   667
                                ^ 'super special semantic only with receiver of message sends'
905
9d5500bffa74 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 902
diff changeset
   668
                            ]
9d5500bffa74 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 902
diff changeset
   669
                    ].
9d5500bffa74 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 902
diff changeset
   670
    ].
1154
8c8787349aaf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1134
diff changeset
   671
2208
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   672
    (selector = #'handle:do:' 
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   673
    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
   674
    or:[ selector = #'ignoreIn:'
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   675
    or:[ selector = #'catch:' ]]]) ifTrue:[
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   676
        (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
   677
    ].
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   678
    (selector = #'on:do:'
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   679
    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
   680
    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
   681
        (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
   682
    ].
334c127f8586 possible name clash check (Error handle:do:) with Error class
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   683
1154
8c8787349aaf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1134
diff changeset
   684
"/    receiver isBlock ifTrue:[
8c8787349aaf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1134
diff changeset
   685
"/        ([] respondsTo:selector) ifFalse:[
8c8787349aaf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1134
diff changeset
   686
"/            ^ 'blocks do not respond to ' , selector , '; Missing ''.'' between statements ?'
8c8787349aaf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1134
diff changeset
   687
"/        ].
8c8787349aaf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1134
diff changeset
   688
"/    ].
8c8787349aaf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1134
diff changeset
   689
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   690
    ^ nil
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   691
2028
a9b5ec797153 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1994
diff changeset
   692
    "Modified: / 28-03-2007 / 14:14:28 / cg"
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   693
! !
7ad01559b262 Initial revision
claus
parents:
diff changeset
   694
7ad01559b262 Initial revision
claus
parents:
diff changeset
   695
!MessageNode methodsFor:'code generation'!
7ad01559b262 Initial revision
claus
parents:
diff changeset
   696
1691
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   697
codeOn:aStream inBlock:b for:aCompiler
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   698
    self codeOn:aStream inBlock:b valueNeeded:true for:aCompiler
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   699
!
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   700
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   701
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
   702
    "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
   703
1691
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   704
    |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
   705
     specialCode stackTop arg1 arg2 arg3 isSuper realReceiver 
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
   706
     noSendDrop alreadyDropped
1994
4094e1eb3399 preps for selectorNamespaces.
Claus Gittinger <cg@exept.de>
parents: 1989
diff changeset
   707
     useSelfSend usedSelector|
4094e1eb3399 preps for selectorNamespaces.
Claus Gittinger <cg@exept.de>
parents: 1989
diff changeset
   708
1691
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   709
    selector := selector asSymbol.
1994
4094e1eb3399 preps for selectorNamespaces.
Claus Gittinger <cg@exept.de>
parents: 1989
diff changeset
   710
    usedSelector := aCompiler nameSpaceSelectorFor:selector.
4094e1eb3399 preps for selectorNamespaces.
Claus Gittinger <cg@exept.de>
parents: 1989
diff changeset
   711
4094e1eb3399 preps for selectorNamespaces.
Claus Gittinger <cg@exept.de>
parents: 1989
diff changeset
   712
    "/ must be added for browsers-search to work on optimized nodes
4094e1eb3399 preps for selectorNamespaces.
Claus Gittinger <cg@exept.de>
parents: 1989
diff changeset
   713
    usedSelector ~~ selector ifTrue:[ aCompiler addLiteral:selector ].
4094e1eb3399 preps for selectorNamespaces.
Claus Gittinger <cg@exept.de>
parents: 1989
diff changeset
   714
    litIndex := aCompiler addLiteral:usedSelector.
1691
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   715
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   716
    noSendDrop := aCompiler class newCodeSet == true.
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   717
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   718
    realReceiver := self realReceiver.
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   719
    isSuper := realReceiver isSuper.
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   720
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   721
    argArray isNil ifTrue:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   722
        nargs := 0
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   723
    ] ifFalse:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   724
        nargs := argArray size.
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   725
        nargs > 0 ifTrue:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   726
            arg1 := argArray at:1.
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   727
            nargs > 1 ifTrue:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   728
                arg2 := argArray at:2.
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   729
                nargs > 2 ifTrue:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   730
                    arg3 := argArray at:3.
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   731
                ]
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   732
            ]    
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   733
        ].
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   734
    ].
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   735
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   736
    recType := receiver type.
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   737
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   738
    (nargs == 0) ifTrue:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   739
        (recType == #ThisContext) ifTrue:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   740
            valueNeeded ifFalse:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   741
                "for now, only do it in methods"
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   742
                b isNil ifTrue:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   743
                    (selector == #restart) ifTrue:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   744
                        aStream nextPut:#jump; nextPut:1.      "jump to start"
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   745
                        ^ self
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   746
                    ].
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   747
                ].
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   748
                (selector == #return) ifTrue:[  "^ nil"
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   749
                    aStream nextPut:#retNil.
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   750
                    ^ self
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   751
                ].
2562
be17095cbb21 comment/format in: #codeOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2542
diff changeset
   752
            ].
be17095cbb21 comment/format in: #codeOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2542
diff changeset
   753
            "/ aCompiler rememberContextReturnablePragma
1691
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
        (receiver isBlock 
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   757
        and:[receiver numArgs == 0
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   758
        and:[receiver isInlinable]]) ifTrue:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   759
            selector == #value ifTrue:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   760
                receiver codeInlineOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler.
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   761
                ^ self
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   762
            ].
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   763
            ((selector == #whileTrue) or:[selector == #whileFalse]) ifTrue:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   764
                ^ self codeWhileOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler.
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   765
            ].
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   766
            ((selector == #repeat) or:[selector == #loop]) ifTrue:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   767
                valueNeeded ifFalse:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   768
                    ^ self codeRepeatOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler.
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   769
                ]
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   770
            ].
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   771
        ].
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   772
    ].
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   773
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   774
    (nargs == 1) ifTrue:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   775
        (recType == #ThisContext) ifTrue:[
2343
e3c3dad6a800 changed: #codeOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   776
            (selector == #return:) ifTrue:[
e3c3dad6a800 changed: #codeOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   777
                arg1 codeOn:aStream inBlock:b for:aCompiler.  "^ value"
e3c3dad6a800 changed: #codeOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   778
                aStream nextPut:#retTop.
e3c3dad6a800 changed: #codeOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   779
                valueNeeded ifTrue:[
e3c3dad6a800 changed: #codeOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   780
                    "/ 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
   781
                    "/ 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
   782
                    aStream nextPut:#pushNil.
1691
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   783
                ].
2343
e3c3dad6a800 changed: #codeOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2331
diff changeset
   784
                ^ self.
1691
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   785
             ].
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   786
        ].
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   787
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   788
        ((selector == #ifNil:) or:[selector == #ifNotNil:]) ifTrue:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   789
            receiver isBlock ifFalse:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   790
                (arg1 isBlock not
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   791
                or:[arg1 numArgs == 0]) ifTrue:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   792
                    ^ self codeIfNilOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler.
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   793
                ].
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   794
                (arg1 isConstant or:[arg1 isVariable]) ifTrue:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   795
                    ^ self codeIfNilOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler.
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   796
                ].
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   797
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   798
            ].
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   799
        ].
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   800
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   801
        (arg1 isBlock 
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   802
        and:[arg1 isInlinable
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   803
        and:[arg1 numArgs == 0]]) ifTrue:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   804
            ((selector == #ifTrue:) or:[selector == #ifFalse:]) ifTrue:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   805
                receiver isBlock ifFalse:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   806
                    ^ self codeIfOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler.
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   807
                ].
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   808
            ].
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   809
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   810
            (selector == #or:) ifTrue:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   811
                ^ self codeOrOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler.
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   812
            ].
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   813
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   814
            (selector == #and:) ifTrue:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   815
                ^ self codeAndOn: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
            (selector == #timesRepeat:) ifTrue:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   819
                "/ now, always inline #timesRepeat:;
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   820
                "/ the receiver must understand #> and #-
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   821
                
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   822
               ^ self codeTimesRepeatOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler.
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   823
            ].
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   824
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   825
            ((selector == #whileTrue:) or:[selector == #whileFalse:]) ifTrue:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   826
                (receiver isBlock 
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   827
                and:[receiver isInlinable
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   828
                and:[receiver numArgs == 0]]) ifTrue:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   829
                    ^ self codeWhileOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler.
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   830
                ]
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   831
            ]
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 == #ifTrue:) or:[selector == #ifFalse:]) ifTrue:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   835
            (arg1 isConstant or:[arg1 isVariable]) ifTrue:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   836
                ^ self codeIfOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler.
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   837
            ].
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   838
        ].
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   839
1994
4094e1eb3399 preps for selectorNamespaces.
Claus Gittinger <cg@exept.de>
parents: 1989
diff changeset
   840
        usedSelector == #? ifTrue:[
1691
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   841
            "/ only do short-circuit optimization, if arg is not a message;
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   842
            "/ (could have side-effects)
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   843
            "/
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   844
            arg1 isMessage ifFalse:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   845
                ^ self codeQuestOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler.
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   846
            ]
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   847
        ].
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   848
    ].
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   849
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   850
    (nargs == 2) ifTrue:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   851
        receiver isBlock ifFalse:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   852
            (arg1 isBlock 
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   853
            and:[arg1 isInlinable
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   854
            and:[arg1 numArgs == 0
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   855
            and:[arg2 isBlock 
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   856
            and:[arg2 isInlinable
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   857
            and:[arg2 numArgs == 0]]]]]) ifTrue:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   858
                ((selector == #ifTrue:ifFalse:) or:[selector == #ifFalse:ifTrue:]) ifTrue:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   859
                    ^ self codeIfElseOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler.
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   860
                ].
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   861
                ((selector == #ifNil:ifNotNil:) or:[selector == #ifNotNil:ifNil:]) ifTrue:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   862
                    ^ self codeIfNilNotNilOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler.
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   863
                ]
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   864
            ].
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   865
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   866
            ((arg1 isConstant or:[arg1 isVariable])
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   867
            and:[arg2 isConstant or:[arg2 isVariable]]) ifTrue:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   868
                ((selector == #ifTrue:ifFalse:) or:[selector == #ifFalse:ifTrue:]) ifTrue:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   869
                    ^ self codeIfElseOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler.
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   870
                ].
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   871
                ((selector == #ifNil:ifNotNil:) or:[selector == #ifNotNil:ifNil:]) ifTrue:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   872
                    ^ self codeIfNilNotNilOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler.
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
        ].
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   876
        selector == #to:do: ifTrue:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   877
            (arg2 isBlock 
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   878
            and:[arg2 isInlinable 
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   879
            and:[arg2 numArgs == 1]]) ifTrue:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   880
                ^ self codeToDoOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   881
            ]
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   882
        ].
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   883
    ].
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   884
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   885
    (nargs == 3) ifTrue:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   886
        selector == #to:by:do: ifTrue:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   887
            "/ step must be a constant (need to know how to compare)
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   888
            (arg2 isConstant 
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   889
            and:[arg2 type == #Integer
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   890
            and:[arg3 isBlock 
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   891
            and:[arg3 isInlinable 
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   892
            and:[arg3 numArgs == 1]]]]) ifTrue:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   893
                ^ self codeToByDoOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   894
            ]
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   895
        ].
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   896
    ].
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   897
1809
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
   898
    isBuiltIn := isSpecial := false.
1691
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   899
    isSuper ifFalse:[
1994
4094e1eb3399 preps for selectorNamespaces.
Claus Gittinger <cg@exept.de>
parents: 1989
diff changeset
   900
        isBuiltIn := aCompiler isBuiltInSelector:usedSelector forReceiver:receiver.
1691
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   901
        isBuiltIn ifFalse:[
1994
4094e1eb3399 preps for selectorNamespaces.
Claus Gittinger <cg@exept.de>
parents: 1989
diff changeset
   902
            specialCode := aCompiler specialSendCodeFor:usedSelector.
1691
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   903
            isSpecial := specialCode notNil.
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   904
        ].
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   905
    ].
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   906
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   907
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   908
    "can we use a send-bytecode ?"
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   909
    (isBuiltIn or:[isSpecial]) ifTrue:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   910
        receiver codeOn:aStream inBlock:b for:aCompiler.
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   911
        (nargs > 0) ifTrue:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   912
            arg1 codeOn:aStream inBlock:b for:aCompiler.
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   913
            (nargs > 1) ifTrue:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   914
                arg2 codeOn:aStream inBlock:b for:aCompiler
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   915
            ]
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   916
        ].
1994
4094e1eb3399 preps for selectorNamespaces.
Claus Gittinger <cg@exept.de>
parents: 1989
diff changeset
   917
        aStream nextPut:usedSelector.
4094e1eb3399 preps for selectorNamespaces.
Claus Gittinger <cg@exept.de>
parents: 1989
diff changeset
   918
        (aCompiler hasLineNumber:usedSelector) ifTrue:[
1691
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   919
            aStream nextPut:lineNr.
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   920
        ].
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   921
        isSpecial ifTrue:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   922
            aStream nextPut:specialCode
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   923
        ].
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   924
        valueNeeded ifFalse:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   925
            aStream nextPut:#drop
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   926
        ].
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   927
        ^ self
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   928
    ].
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   929
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   930
    ((nargs == 0) and:[selector == #yourself]) ifTrue:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   931
        "yourself is often added to get the receiver -
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   932
         we get it without the yourself-message"
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   933
2429
89d05ce26891 changed: #codeOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2399
diff changeset
   934
        (valueNeeded or:[receiver isMessage]) ifTrue:[
1691
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   935
            receiver codeOn:aStream inBlock:b for:aCompiler
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   936
        ].
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   937
        ^ self
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   938
    ].
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   939
2345
d3c1bbb5cddc comment/format in: #codeOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2344
diff changeset
   940
    "not inlinable - generate a send"
1691
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   941
1809
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
   942
    stackTop := nil.
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
   943
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
   944
    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
   945
    useSelfSend ifFalse:[
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
   946
        receiver codeOn:aStream inBlock:b for:aCompiler.
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
   947
        receiver isConstant ifTrue:[ 
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
   948
            stackTop := receiver
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
   949
        ].
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
   950
    ].
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
   951
    argArray notNil ifTrue:[
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
   952
        argArray do:[:arg |
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
   953
            (stackTop notNil and:[arg canReuseAsArg:stackTop]) ifTrue:[
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
   954
                aStream nextPut:#dup.
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
   955
                "/ '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
   956
            ] ifFalse:[
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
   957
                arg codeOn:aStream inBlock:b for:aCompiler.
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
   958
                stackTop := arg.
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
   959
            ]
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
   960
        ]
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
   961
    ].
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
   962
1691
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   963
    isSuper ifTrue:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   964
        cls := aCompiler targetClass.
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   965
        realReceiver isHere ifTrue:[
1809
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
   966
            "/ same code as supersend, but targetClass starts search
1691
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   967
        ] ifFalse:[
1809
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
   968
            "/ targetClasses superclass starts search
1691
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   969
            cls := cls superclass.
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   970
        ].
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   971
        clsLitIndex := aCompiler addLiteral:cls.
1809
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
   972
        self emitSuperSendLiteralIndex:litIndex classLiteralIndex:clsLitIndex numArgs:nargs line:lineNr on:aStream.
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
   973
        valueNeeded ifFalse:[
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
   974
            aStream nextPut:#drop
1691
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   975
        ].
1809
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
   976
        ^ self.
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
   977
    ].
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
   978
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
   979
    valueNeeded ifTrue:[ noSendDrop := true ].
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
   980
    alreadyDropped := false.
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
   981
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
   982
    (litIndex <= 255) ifTrue:[
1691
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   983
        (nargs <= 3) ifTrue:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   984
            |codes|
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   985
1809
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
   986
            noSendDrop ifTrue:[
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
   987
                useSelfSend ifTrue:[
1691
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   988
                    codes := #(sendSelf0 sendSelf1 sendSelf2 sendSelf3)
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   989
                ] ifFalse:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   990
                    codes := #(send0 send1 send2 send3)
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   991
                ]
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   992
            ] ifFalse:[
1809
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
   993
                useSelfSend ifTrue:[
1691
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   994
                    codes := #(sendSelfDrop0 sendSelfDrop1 sendSelfDrop2 sendSelfDrop3)
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   995
                ] ifFalse:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   996
                    codes := #(sendDrop0 sendDrop1 sendDrop2 sendDrop3)
1809
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
   997
                ].
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
   998
                alreadyDropped := true.
1691
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
   999
            ].
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1000
            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
  1001
            valueNeeded ifFalse:[
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  1002
                alreadyDropped ifFalse:[
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  1003
                    aStream nextPut:#drop
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  1004
                ].
1691
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1005
            ].
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1006
            ^ self
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1007
        ].
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
        useSelfSend ifTrue:[
1691
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1010
            code := #sendSelf
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1011
        ] ifFalse:[
1809
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  1012
            noSendDrop ifTrue:[
1691
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1013
                code := #send
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1014
            ] ifFalse:[
1809
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  1015
                code := #sendDrop.
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  1016
                alreadyDropped := true.
1691
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1017
            ]
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1018
        ].
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1019
        aStream nextPut:code; nextPut:lineNr; nextPut:litIndex; nextPut:nargs.
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1020
        valueNeeded ifFalse:[
1809
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  1021
            alreadyDropped ifFalse:[
1691
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1022
                aStream nextPut:#drop
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1023
            ].
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1024
        ].
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1025
        ^ self
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1026
    ].
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1027
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1028
    "needs 16bit literal index"
1809
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  1029
    (litIndex <= 16rFFFF) ifTrue:[
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  1030
        useSelfSend ifTrue:[
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  1031
            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
  1032
        ] ifFalse:[
1809
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  1033
            self emitSendLiteralIndex:litIndex numArgs:nargs line:lineNr on:aStream.
1801
9fd56369b7f1 more long ops
Claus Gittinger <cg@exept.de>
parents: 1791
diff changeset
  1034
        ].
9fd56369b7f1 more long ops
Claus Gittinger <cg@exept.de>
parents: 1791
diff changeset
  1035
    ] ifFalse:[
9fd56369b7f1 more long ops
Claus Gittinger <cg@exept.de>
parents: 1791
diff changeset
  1036
        "needs 32bit literal index"
1809
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  1037
        self emitSendLiteralIndex:litIndex numArgs:nargs line:lineNr on:aStream.
1691
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1038
    ].
1801
9fd56369b7f1 more long ops
Claus Gittinger <cg@exept.de>
parents: 1791
diff changeset
  1039
1691
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1040
    valueNeeded ifFalse:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1041
        aStream nextPut:#drop
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1042
    ].
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1043
1994
4094e1eb3399 preps for selectorNamespaces.
Claus Gittinger <cg@exept.de>
parents: 1989
diff changeset
  1044
    "Modified: / 03-09-1995 / 12:55:42 / claus"
2562
be17095cbb21 comment/format in: #codeOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2542
diff changeset
  1045
    "Modified: / 15-07-2011 / 08:38:33 / cg"
1691
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1046
! !
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1047
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1048
!MessageNode methodsFor:'enumerating'!
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1049
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1050
messagesDo:aBlock
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1051
    aBlock value:self.
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1052
    receiver messagesDo:aBlock.
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1053
    argArray notNil ifTrue:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1054
        argArray do:[:arg | arg messagesDo:aBlock].
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1055
    ]
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1056
!
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1057
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1058
nodeDo:anEnumerator
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1059
    "helper for parse tree walking"
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1060
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1061
    |args|
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1062
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1063
    args := argArray ? #().
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1064
    ^ anEnumerator doMessage:self receiver:receiver selector:selector arguments:args
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1065
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1066
    "Created: 19.6.1997 / 16:46:39 / cg"
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1067
    "Modified: 19.6.1997 / 17:08:28 / cg"
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1068
! !
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1069
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1070
!MessageNode methodsFor:'evaluation'!
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1071
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1072
evaluateForCascadeIn:anEnvironment
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1073
    ^ self evaluateIn:anEnvironment forCascade:true
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1074
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1075
    "Modified: / 20-04-2005 / 12:12:01 / cg"
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1076
!
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1077
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1078
evaluateIn:anEnvironment
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1079
    ^ self evaluateIn:anEnvironment forCascade:false
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1080
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1081
    "Modified: / 20-04-2005 / 12:11:55 / cg"
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1082
!
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1083
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1084
evaluateIn:anEnvironment forCascade:forCascade
2329
50473c5384bb changed: #evaluateIn:forCascade:
Claus Gittinger <cg@exept.de>
parents: 2321
diff changeset
  1085
    |retVal defClass r a1 a2 a3 nargs argValueArray class sel|
1691
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1086
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1087
    sel := self evaluationSelector.
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1088
    receiver isSuper ifTrue:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1089
        r := receiver value.
2329
50473c5384bb changed: #evaluateIn:forCascade:
Claus Gittinger <cg@exept.de>
parents: 2321
diff changeset
  1090
50473c5384bb changed: #evaluateIn:forCascade:
Claus Gittinger <cg@exept.de>
parents: 2321
diff changeset
  1091
        defClass := receiver definingClass.
1691
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1092
        receiver isHere ifTrue:[
2329
50473c5384bb changed: #evaluateIn:forCascade:
Claus Gittinger <cg@exept.de>
parents: 2321
diff changeset
  1093
            class := defClass.
1691
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1094
        ] ifFalse:[
2329
50473c5384bb changed: #evaluateIn:forCascade:
Claus Gittinger <cg@exept.de>
parents: 2321
diff changeset
  1095
            class := defClass superclass.
1691
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1096
        ].
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1097
        argArray notNil ifTrue:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1098
            argValueArray := argArray collect:[:arg | arg evaluateIn:anEnvironment].
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1099
        ] ifFalse:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1100
            argValueArray := #()
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1101
        ].
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1102
        retVal := r perform:sel inClass:class withArguments:argValueArray.
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1103
    ] ifFalse:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1104
        r := receiver evaluateIn:anEnvironment.
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1105
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1106
        argArray isNil ifTrue:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1107
            retVal := r perform:sel
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1108
        ] ifFalse:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1109
            nargs := argArray size.
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1110
            (nargs == 0) ifTrue:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1111
                retVal := r perform:sel
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1112
            ] ifFalse:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1113
                a1 := (argArray at:1) evaluateIn:anEnvironment.
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1114
                (nargs == 1) ifTrue:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1115
                    retVal := r perform:sel with:a1
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1116
                ] ifFalse:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1117
                    a2 := (argArray at:2) evaluateIn:anEnvironment.
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1118
                    (nargs == 2) ifTrue:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1119
                        retVal := r perform:sel with:a1 with:a2
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1120
                    ] ifFalse:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1121
                        a3 := (argArray at:3) evaluateIn:anEnvironment.
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1122
                        (nargs == 3) ifTrue:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1123
                            retVal := r perform:sel with:a1 with:a2 with:a3
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1124
                        ] ifFalse:[
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1125
                            argValueArray := Array new:nargs.
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1126
                            argValueArray at:1 put:a1.
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1127
                            argValueArray at:2 put:a2.
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1128
                            argValueArray at:3 put:a3.
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1129
                            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
  1130
                            retVal := r perform:sel withArguments:argValueArray.
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1131
                        ].
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1132
                    ].
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1133
                ].
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1134
            ].
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
    ^ forCascade ifTrue:[r] ifFalse:[retVal]
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1138
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1139
    "Created: / 20-04-2005 / 12:11:39 / cg"
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1140
!
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1141
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1142
evaluationSelector
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1143
    ^ selector asSymbol
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1144
! !
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1145
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1146
!MessageNode methodsFor:'optimized code generation'!
ab6d550484d7 category
Claus Gittinger <cg@exept.de>
parents: 1688
diff changeset
  1147
338
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1148
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
  1149
    "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
  1150
1059
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1151
    |theByteCode optByteCode theReceiver theArg pos1 pos2 pos3 code here jmp
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1152
     block1 block2|
338
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1153
1464
fa19f86d1ef4 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1463
diff changeset
  1154
    aCompiler addLiteral:#and:.
fa19f86d1ef4 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1463
diff changeset
  1155
338
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1156
    theByteCode := #falseJump.
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1157
    theReceiver := receiver receiver.
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1158
1463
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  1159
    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
  1160
    optByteCode notNil ifTrue:[
1058
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  1161
        ((optByteCode == #eqJump) or:[optByteCode == #notEqJump]) ifTrue:[
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  1162
            theArg := theReceiver arg1
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  1163
        ].
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  1164
        theReceiver := theReceiver receiver.
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  1165
        theByteCode := optByteCode
338
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1166
    ].
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1167
    "/ code the left-of the and-part
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1168
    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
  1169
    theArg notNil ifTrue:[
1058
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  1170
        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
  1171
    ].
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1172
    aStream nextPut:theByteCode.
1371
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  1173
    pos1 := aStream position1Based.   "/ 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
  1174
    aStream nextPut:0.
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1175
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1176
    "/ 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
  1177
    theReceiver := receiver arg1.
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1178
    theReceiver codeInlineOn:aStream inBlock:b for:aCompiler.
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1179
    (selector == #ifTrue:ifFalse:) ifTrue:[
1058
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  1180
        jmp := #falseJump
338
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1181
    ] ifFalse:[
1058
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  1182
        jmp := #trueJump
338
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1183
    ].
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1184
    aStream nextPut:jmp.
1371
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  1185
    pos2 := aStream position1Based.   "/ 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
  1186
    aStream nextPut:0.
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1187
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1188
    code := aStream contents.
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1189
    (selector == #ifFalse:ifTrue:) ifTrue:[
1371
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  1190
        code at:pos1 put:(aStream position1Based)
338
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1191
    ].
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1192
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1193
    "/ code the if-block
1059
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1194
    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
  1195
    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
  1196
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1197
    aStream nextPut:#jump.
1371
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  1198
    pos3 := aStream position1Based.
338
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1199
    aStream nextPut:0.
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1200
1371
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  1201
    here := aStream position1Based.
338
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1202
    (selector == #ifTrue:ifFalse:) ifTrue:[
1058
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  1203
        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
  1204
    ].
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1205
    code at:pos2 put:here.
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1206
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1207
    "/ code the else-block
1059
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1208
    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
  1209
    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
  1210
1371
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  1211
    code at:pos3 put:(aStream position1Based)
338
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1212
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1213
    "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
  1214
!
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1215
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1216
codeAndIfOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1217
    "generate code for (x and:[y]) ifxxx:[ ... ]"
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1218
812
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1219
    |theByteCode optByteCode andBlock theArg pos1 pos2 pos3 code here jmp
1059
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1220
     receiver1 receiver2 optByteCode2 theArg2 block|
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1221
1464
fa19f86d1ef4 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1463
diff changeset
  1222
    aCompiler addLiteral:#and:.
fa19f86d1ef4 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1463
diff changeset
  1223
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1224
    theByteCode := #falseJump.
812
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1225
    receiver1 := receiver receiver.
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1226
1463
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  1227
    optByteCode := self optimizedConditionFor:receiver1 with:theByteCode for:aCompiler.
812
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1228
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1229
    optByteCode notNil ifTrue:[
812
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1230
        ((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
  1231
            theArg := receiver1 arg1
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1232
        ].
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1233
        receiver1 := receiver1 receiver.
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1234
        theByteCode := optByteCode
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1235
    ].
812
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1236
    receiver1 codeOn:aStream inBlock:b for:aCompiler.
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1237
    theArg notNil ifTrue:[
812
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1238
        theArg codeOn:aStream inBlock:b for:aCompiler
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1239
    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1240
    aStream nextPut:theByteCode.
1371
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  1241
    pos1 := aStream position1Based.
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1242
    aStream nextPut:0.
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1243
812
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1244
    andBlock := receiver arg1. "/ the and:-block
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1245
    (selector == #ifTrue:) ifTrue:[
812
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1246
        jmp := #falseJump
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1247
    ] ifFalse:[
812
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1248
        jmp := #trueJump
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1249
    ].
1719
3a774d5c643e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1691
diff changeset
  1250
    (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
  1251
        "/ simple - one statement
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1252
        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
  1253
        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
  1254
    ].
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1255
    optByteCode2 notNil ifTrue:[
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1256
        ((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
  1257
            theArg2 := receiver2 arg1
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1258
        ].
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1259
        receiver2 := receiver2 receiver.
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1260
        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
  1261
        theArg2 notNil ifTrue:[
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1262
            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
  1263
        ].
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1264
        jmp := optByteCode2.
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1265
    ] ifFalse:[
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1266
        andBlock codeInlineOn:aStream inBlock:b for:aCompiler.
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1267
    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1268
    aStream nextPut:jmp.
1371
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  1269
    pos2 := aStream position1Based.
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1270
    aStream nextPut:0.
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1271
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1272
    code := aStream contents.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1273
    (selector == #ifFalse:) ifTrue:[
1371
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  1274
        code at:pos1 put:(aStream position1Based)
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1275
    ].
1059
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1276
    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
  1277
    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
  1278
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1279
    valueNeeded ifTrue:[
812
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1280
        aStream nextPut:#jump.
1371
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  1281
        pos3 := aStream position1Based.
812
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1282
        aStream nextPut:0.
1371
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  1283
        here := aStream position1Based.
812
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1284
        (selector == #ifTrue:) ifTrue:[
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1285
            code at:pos1 put:here
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1286
        ].
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1287
        code at:pos2 put:here.
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1288
        aStream nextPut:#pushNil.
1371
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  1289
        code at:pos3 put:(aStream position1Based)
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1290
    ] ifFalse:[
1371
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  1291
        here := aStream position1Based.
812
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1292
        (selector == #ifTrue:) ifTrue:[
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1293
            code at:pos1 put:here
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1294
        ].
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1295
        code at:pos2 put:here
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1296
    ]
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1297
!
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1298
289
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  1299
codeAndOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  1300
    "generate code for (x and:[y])"
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1301
289
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  1302
    |pos1 rightExpr|
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  1303
1464
fa19f86d1ef4 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1463
diff changeset
  1304
    aCompiler addLiteral:#and:.
fa19f86d1ef4 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1463
diff changeset
  1305
289
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  1306
    receiver codeOn:aStream inBlock:b for:aCompiler.
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  1307
    valueNeeded ifTrue:[
1371
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  1308
        aStream nextPut:#dup.
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1309
    ].
289
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  1310
    aStream nextPut:#falseJump.
1371
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  1311
    pos1 := aStream position1Based.
289
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  1312
    aStream nextPut:0.
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  1313
    valueNeeded ifTrue:[
1371
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  1314
        aStream nextPut:#drop.
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1315
    ].
289
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  1316
    rightExpr := argArray at:1.
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  1317
    rightExpr codeInlineOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler.
163
9a7dfd547e69 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
  1318
1371
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  1319
    (aStream contents) at:pos1 put:(aStream position1Based)
289
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  1320
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  1321
    "Created: 17.6.1996 / 15:46:42 / cg"
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  1322
    "Modified: 17.6.1996 / 15:47:44 / cg"
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1323
!
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1324
1435
be9680c6145c factored out some common code (block-code and value-sending)
Claus Gittinger <cg@exept.de>
parents: 1425
diff changeset
  1325
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
  1326
    "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
  1327
be9680c6145c factored out some common code (block-code and value-sending)
Claus Gittinger <cg@exept.de>
parents: 1425
diff changeset
  1328
    (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
  1329
        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
  1330
    ] ifFalse:[
be9680c6145c factored out some common code (block-code and value-sending)
Claus Gittinger <cg@exept.de>
parents: 1425
diff changeset
  1331
        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
  1332
        aBlock isConstant ifFalse:[
be9680c6145c factored out some common code (block-code and value-sending)
Claus Gittinger <cg@exept.de>
parents: 1425
diff changeset
  1333
            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
  1334
        ].
be9680c6145c factored out some common code (block-code and value-sending)
Claus Gittinger <cg@exept.de>
parents: 1425
diff changeset
  1335
        valueNeeded ifFalse:[
be9680c6145c factored out some common code (block-code and value-sending)
Claus Gittinger <cg@exept.de>
parents: 1425
diff changeset
  1336
            aStream nextPut:#drop
be9680c6145c factored out some common code (block-code and value-sending)
Claus Gittinger <cg@exept.de>
parents: 1425
diff changeset
  1337
        ].
be9680c6145c factored out some common code (block-code and value-sending)
Claus Gittinger <cg@exept.de>
parents: 1425
diff changeset
  1338
    ].
be9680c6145c factored out some common code (block-code and value-sending)
Claus Gittinger <cg@exept.de>
parents: 1425
diff changeset
  1339
!
be9680c6145c factored out some common code (block-code and value-sending)
Claus Gittinger <cg@exept.de>
parents: 1425
diff changeset
  1340
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1341
codeForCascadeOn:aStream inBlock:b for:aCompiler
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1342
    "like codeOn, but always leave the receiver instead of the result"
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1343
1809
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  1344
    |nargs isBuiltIn code litIndex cls clsLitIndex isSuper realReceiver noSendDrop|
1048
6eaeba225e67 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1046
diff changeset
  1345
1500
3c4cb012b24b Lazy conversion of selector strings to symbols.
Stefan Vogel <sv@exept.de>
parents: 1480
diff changeset
  1346
    selector := selector asSymbol.
1048
6eaeba225e67 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1046
diff changeset
  1347
    noSendDrop := aCompiler class newCodeSet == true.
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1348
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1349
    realReceiver := self realReceiver.
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1350
    isSuper := realReceiver isSuper.
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1351
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1352
    argArray isNil ifTrue:[
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1353
        nargs := 0
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1354
    ] ifFalse:[
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1355
        nargs := argArray size
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1356
    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1357
1809
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  1358
    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
  1359
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  1360
    litIndex := aCompiler addLiteral:selector.
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1361
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1362
    receiver codeOn:aStream inBlock:b for:aCompiler.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1363
    aStream nextPut:#dup.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1364
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1365
    "can we use a send-bytecode ?"
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1366
    isBuiltIn ifTrue:[
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1367
        (nargs > 0) ifTrue:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1368
            (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
  1369
            (nargs > 1) ifTrue:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1370
                (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
  1371
            ]
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1372
        ].
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1373
        aStream nextPut:selector.
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1374
        (aCompiler hasLineNumber:selector) ifTrue:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1375
            aStream nextPut:lineNr.
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1376
        ].
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1377
        aStream nextPut:#drop.
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1378
        ^ self
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1379
    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1380
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1381
    "no - generate a send"
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1382
    argArray notNil ifTrue:[
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1383
        argArray do:[:arg |
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1384
            arg codeOn:aStream inBlock:b for:aCompiler
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1385
        ]
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1386
    ].
189
673580572edd fixed cascades involving super sends (i.e. super foo; bar)
Claus Gittinger <cg@exept.de>
parents: 186
diff changeset
  1387
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1388
    isSuper ifTrue:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1389
        cls := aCompiler targetClass.
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1390
        realReceiver isHere ifTrue:[
1809
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  1391
            "/ 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
  1392
        ] ifFalse:[
1809
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  1393
            "/ targetClasses superclass starts search
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1394
            cls := cls superclass.
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1395
        ].
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1396
        clsLitIndex := aCompiler addLiteral:cls.
1809
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  1397
        self emitSuperSendLiteralIndex:litIndex classLiteralIndex:clsLitIndex numArgs:nargs line:lineNr on:aStream.
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  1398
        aStream nextPut:#drop.
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1399
        ^ self
189
673580572edd fixed cascades involving super sends (i.e. super foo; bar)
Claus Gittinger <cg@exept.de>
parents: 186
diff changeset
  1400
    ].
673580572edd fixed cascades involving super sends (i.e. super foo; bar)
Claus Gittinger <cg@exept.de>
parents: 186
diff changeset
  1401
1809
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  1402
    noSendDrop ifFalse:[
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  1403
        litIndex <= 255 ifTrue:[
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  1404
            (nargs <= 3) ifTrue:[
1046
8e5818442eb9 newCode (for rel5)
Claus Gittinger <cg@exept.de>
parents: 1045
diff changeset
  1405
                code := #(sendDrop0 sendDrop1 sendDrop2 sendDrop3) at:(nargs+1).
8e5818442eb9 newCode (for rel5)
Claus Gittinger <cg@exept.de>
parents: 1045
diff changeset
  1406
                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
  1407
                ^ self
1046
8e5818442eb9 newCode (for rel5)
Claus Gittinger <cg@exept.de>
parents: 1045
diff changeset
  1408
            ].
1809
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  1409
            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
  1410
            ^ self
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1411
        ].
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1412
    ].
1809
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  1413
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  1414
    self emitSendLiteralIndex:litIndex numArgs:nargs line:lineNr on:aStream.
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  1415
    aStream nextPut:#drop.
189
673580572edd fixed cascades involving super sends (i.e. super foo; bar)
Claus Gittinger <cg@exept.de>
parents: 186
diff changeset
  1416
886
454c57fbf1c2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 867
diff changeset
  1417
    "Modified: / 4.7.1999 / 19:06:53 / cg"
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1418
!
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1419
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1420
codeForSideEffectOn:aStream inBlock:b for:aCompiler
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1421
    self codeOn:aStream inBlock:b valueNeeded:false for:aCompiler
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1422
!
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1423
843
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1424
codeForSimpleReturnOn:aStream inBlock:b lineNumber:lineNrOrNil for:aCompiler
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1425
    |arg1 rightExpr pos1|
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1426
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1427
    (selector == #and:
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1428
    or:[selector == #or:]) ifTrue:[
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1429
        arg1 := argArray at:1.
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1430
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1431
        "/ for now:
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1432
        "/ only do it for non-blocks, since
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1433
        "/ the JIT compiler is smart enough to
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1434
        "/ specially optimize the resulting code
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1435
        "/ (and not smart enough to optimized the
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1436
        "/  other - actually more efficient - code)
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1437
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1438
        (arg1 isBlock not 
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1439
"/        or:[arg1 isInlinable]
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1440
        ) ifTrue:[
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1441
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1442
            "/ encode #and: as:
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1443
            "/
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1444
            "/      eLeft
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1445
            "/      jmp_false       LBL
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1446
            "/      eRight
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1447
            "/      retTop
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1448
            "/  LBL:
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1449
            "/      retFalse
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1450
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1451
            "/ encode #or: as:
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1452
            "/
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1453
            "/      eLeft
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1454
            "/      jmp_true       LBL
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1455
            "/      eRight
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1456
            "/      retTop
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1457
            "/  LBL:
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1458
            "/      retTrue
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1459
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1460
            receiver codeOn:aStream inBlock:b for:aCompiler.
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1461
            selector == #and: ifTrue:[
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1462
                aStream nextPut:#falseJump.
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1463
            ] ifFalse:[
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1464
                aStream nextPut:#trueJump.
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1465
            ].
1371
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  1466
            pos1 := aStream position1Based.
843
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1467
            aStream nextPut:0.
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1468
        
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1469
            rightExpr := argArray at:1.
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1470
            rightExpr isBlock ifTrue:[
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1471
                rightExpr codeInlineOn:aStream inBlock:b valueNeeded:true for:aCompiler.
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1472
            ] ifFalse:[
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1473
                rightExpr codeOn:aStream inBlock:b for:aCompiler.
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1474
            ].
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1475
            aStream nextPut:#retTop.
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1476
        
1371
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  1477
            (aStream contents) at:pos1 put:(aStream position1Based).
843
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1478
            selector == #and: ifTrue:[
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1479
                aStream nextPut:#retFalse.
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1480
            ] ifFalse:[
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1481
                aStream nextPut:#retTrue
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1482
            ].
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1483
            ^ self.
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1484
        ].
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1485
    ].
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1486
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1487
    super
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1488
        codeForSimpleReturnOn:aStream 
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1489
        inBlock:b 
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1490
        lineNumber:lineNrOrNil 
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1491
        for:aCompiler
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1492
!
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
  1493
104
claus
parents: 103
diff changeset
  1494
codeIfElseOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1495
    "generate code for x ifxxx:[ ... ] yyy:[ ...]"
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1496
334
cd7491b7ad33 dont code a jump after if-part if it ends in a return.
Claus Gittinger <cg@exept.de>
parents: 309
diff changeset
  1497
    |pos pos2 theReceiver theArg theByteCode optByteCode subsel code needLineNr
1059
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1498
     needJump block1 block2|
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1499
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1500
    theReceiver := receiver.
76
55d64cb1ffea *** empty log message ***
claus
parents: 75
diff changeset
  1501
992
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1502
    theReceiver isConstant ifTrue:[
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1503
        (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
  1504
            ^ self
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1505
        ].
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1506
    ].
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1507
76
55d64cb1ffea *** empty log message ***
claus
parents: 75
diff changeset
  1508
    (theReceiver isMessage) ifTrue:[
992
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1509
        subsel := theReceiver selector.
2399
57ba9eb8c502 changed: #codeIfElseOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2384
diff changeset
  1510
        ((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
  1511
            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
  1512
            ^ self
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1513
        ].
2399
57ba9eb8c502 changed: #codeIfElseOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2384
diff changeset
  1514
        ((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
  1515
            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
  1516
            ^ self
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1517
        ]
76
55d64cb1ffea *** empty log message ***
claus
parents: 75
diff changeset
  1518
    ].
2399
57ba9eb8c502 changed: #codeIfElseOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2384
diff changeset
  1519
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1520
    (selector == #ifTrue:ifFalse:) ifTrue:[
992
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1521
        theByteCode := #falseJump
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1522
    ] ifFalse:[
1059
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1523
        theByteCode := #trueJump
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1524
    ].
1463
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  1525
    optByteCode := self optimizedConditionFor:theReceiver with:theByteCode for:aCompiler.
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1526
    optByteCode notNil ifTrue:[
992
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1527
        ((optByteCode == #eqJump) or:[optByteCode == #notEqJump]) ifTrue:[
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1528
            theArg := theReceiver arg1
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1529
        ].
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1530
        theReceiver := theReceiver receiver.
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1531
        theByteCode := optByteCode
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1532
    ].
1059
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1533
    theReceiver codeOn:aStream inBlock:b for:aCompiler.
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1534
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1535
    needLineNr := true.
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1536
    theArg isNil ifTrue:[
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1537
        theReceiver isMessage ifTrue:[
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1538
            (aCompiler hasLineNumber:(theReceiver selector)) ifTrue:[
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1539
                theReceiver lineNumber == lineNr ifTrue:[
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1540
                    needLineNr := false
992
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1541
                ]
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1542
            ]
1059
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1543
        ]
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1544
    ] ifFalse:[
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1545
        theArg codeOn:aStream inBlock:b for:aCompiler
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1546
    ].
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1547
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1548
    needLineNr ifTrue:[
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1549
        (lineNr between:1 and:255) ifTrue:[
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1550
            aStream nextPut:#lineno; nextPut:lineNr.
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1551
        ]
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1552
    ].
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1553
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1554
    aStream nextPut:theByteCode.
1371
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  1555
    pos := aStream position1Based.
1059
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1556
    aStream nextPut:0.
1435
be9680c6145c factored out some common code (block-code and value-sending)
Claus Gittinger <cg@exept.de>
parents: 1425
diff changeset
  1557
    block1 := argArray at:1.
be9680c6145c factored out some common code (block-code and value-sending)
Claus Gittinger <cg@exept.de>
parents: 1425
diff changeset
  1558
    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
  1559
1059
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1560
    needJump := true.
1435
be9680c6145c factored out some common code (block-code and value-sending)
Claus Gittinger <cg@exept.de>
parents: 1425
diff changeset
  1561
    (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
  1562
        needJump := false
1059
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1563
    ].
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1564
    needJump ifTrue:[
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1565
        aStream nextPut:#jump.
1371
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  1566
        pos2 := aStream position1Based.
1059
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1567
        aStream nextPut:0.
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1568
    ].
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1569
    code := aStream contents.
1371
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  1570
    code at:pos put:(aStream position1Based).
1059
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1571
    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
  1572
    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
  1573
    needJump ifTrue:[
1371
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  1574
        code at:pos2 put:(aStream position1Based)
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1575
    ]
166
9f6c57a3bce1 no line number bytecode in if-else if not needed
Claus Gittinger <cg@exept.de>
parents: 163
diff changeset
  1576
2399
57ba9eb8c502 changed: #codeIfElseOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2384
diff changeset
  1577
    "
57ba9eb8c502 changed: #codeIfElseOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2384
diff changeset
  1578
     |a|
57ba9eb8c502 changed: #codeIfElseOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2384
diff changeset
  1579
     (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
  1580
    "
57ba9eb8c502 changed: #codeIfElseOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2384
diff changeset
  1581
57ba9eb8c502 changed: #codeIfElseOn:inBlock:valueNeeded:for:
Claus Gittinger <cg@exept.de>
parents: 2384
diff changeset
  1582
    "Modified: / 21-05-2010 / 15:39:15 / cg"
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1583
!
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1584
898
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1585
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
  1586
    "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
  1587
     or: x ifNil:const1 ifNotNil:const2"
898
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1588
1371
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  1589
    |pos pos2 theReceiver theArg theByteCode code
1059
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1590
     needLineNr block1 block2|
898
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1591
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1592
    theReceiver := receiver.
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1593
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1594
    (selector == #ifNil:ifNotNil:) ifTrue:[
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1595
        theByteCode := #notNilJump
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1596
    ] ifFalse:[
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1597
        theByteCode := #nilJump
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1598
    ].
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1599
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1600
    theReceiver codeOn:aStream inBlock:b for:aCompiler.
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1601
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1602
    needLineNr := true.
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1603
    theArg isNil ifTrue:[
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1604
        theReceiver isMessage ifTrue:[
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1605
            (aCompiler hasLineNumber:(theReceiver selector)) ifTrue:[
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1606
                theReceiver lineNumber == lineNr ifTrue:[
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1607
                    needLineNr := false
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1608
                ]
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1609
            ]
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1610
        ]
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1611
    ].
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1612
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1613
    needLineNr ifTrue:[
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1614
        (lineNr between:1 and:255) ifTrue:[
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1615
            aStream nextPut:#lineno; nextPut:lineNr.
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1616
        ]
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1617
    ].
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1618
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1619
    aStream nextPut:theByteCode.
1371
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  1620
    pos := aStream position1Based.
898
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1621
    aStream nextPut:0.
1059
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1622
    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
  1623
    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
  1624
    aStream nextPut:#jump.
1371
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  1625
    pos2 := aStream position1Based.
898
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1626
    aStream nextPut:0.
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1627
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1628
    code := aStream contents.
1371
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  1629
    code at:pos put:(aStream position1Based).
1059
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1630
    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
  1631
    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
  1632
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1633
    code := aStream contents.
1371
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  1634
    code at:pos2 put:(aStream position1Based)
898
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1635
1034
d4f1640f1aad better code for #ifNil:ifNotNil:, if args are non-block consts
Claus Gittinger <cg@exept.de>
parents: 1017
diff changeset
  1636
    "Modified: / 11.2.2000 / 12:50:36 / cg"
898
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1637
!
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1638
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1639
codeIfNilOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1640
    "generate code for x ifNil:[ ... ]"
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1641
1435
be9680c6145c factored out some common code (block-code and value-sending)
Claus Gittinger <cg@exept.de>
parents: 1425
diff changeset
  1642
    |pos theReceiver theByteCode code needLineNr|
898
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1643
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1644
    theReceiver := receiver.
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1645
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1646
    (selector == #ifNil:) ifTrue:[
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1647
        theByteCode := #notNilJump
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1648
    ] ifFalse:[
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1649
        theByteCode := #nilJump
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1650
    ].
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1651
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1652
    theReceiver codeOn:aStream inBlock:b for:aCompiler.
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1653
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1654
    needLineNr := true.
899
fb678b9e18a7 also inline ifNot:/ifNotNil: for non-block arg.
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  1655
fb678b9e18a7 also inline ifNot:/ifNotNil: for non-block arg.
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  1656
    theReceiver isMessage ifTrue:[
fb678b9e18a7 also inline ifNot:/ifNotNil: for non-block arg.
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  1657
        (aCompiler hasLineNumber:(theReceiver selector)) ifTrue:[
fb678b9e18a7 also inline ifNot:/ifNotNil: for non-block arg.
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  1658
            theReceiver lineNumber == lineNr ifTrue:[
fb678b9e18a7 also inline ifNot:/ifNotNil: for non-block arg.
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  1659
                needLineNr := false
898
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1660
            ]
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1661
        ]
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1662
    ].
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1663
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1664
    needLineNr ifTrue:[
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1665
        (lineNr between:1 and:255) ifTrue:[
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1666
            aStream nextPut:#lineno; nextPut:lineNr.
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1667
        ]
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1668
    ].
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1669
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1670
    valueNeeded ifTrue:[
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1671
        aStream nextPut:#dup.
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1672
    ].
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1673
    aStream nextPut:theByteCode.
1371
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  1674
    pos := aStream position1Based.
898
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1675
    aStream nextPut:0.
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1676
    valueNeeded ifTrue:[
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1677
        aStream nextPut:#drop.
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1678
    ].
899
fb678b9e18a7 also inline ifNot:/ifNotNil: for non-block arg.
Claus Gittinger <cg@exept.de>
parents: 898
diff changeset
  1679
1435
be9680c6145c factored out some common code (block-code and value-sending)
Claus Gittinger <cg@exept.de>
parents: 1425
diff changeset
  1680
    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
  1681
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1682
    code := aStream contents.
1371
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  1683
    code at:pos put:(aStream position1Based)
898
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1684
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1685
    "Modified: / 28.10.1997 / 18:33:42 / cg"
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1686
!
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1687
104
claus
parents: 103
diff changeset
  1688
codeIfOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1689
    "generate code for x ifxxx:[ ... ]"
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1690
103
claus
parents: 102
diff changeset
  1691
    |pos pos2 theReceiver theArg theByteCode optByteCode subsel code
1059
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1692
     needLineNr block|
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1693
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1694
    theReceiver := receiver.
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1695
992
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1696
    theReceiver isConstant ifTrue:[
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1697
        (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
  1698
            ^ self
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1699
        ].
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1700
    ].
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1701
76
55d64cb1ffea *** empty log message ***
claus
parents: 75
diff changeset
  1702
    (theReceiver isMessage) ifTrue:[
992
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1703
        subsel := theReceiver selector.
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1704
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1705
        (subsel == #and:) ifTrue:[
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1706
            theReceiver arg1 isBlock ifTrue:[
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1707
                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
  1708
                ^ self
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1709
            ]
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1710
        ].
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1711
        (subsel == #or:) ifTrue:[
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1712
            theReceiver arg1 isBlock ifTrue:[
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1713
                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
  1714
                ^ self
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1715
            ]
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1716
        ].
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1717
    ].
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1718
    (selector == #ifTrue:) ifTrue:[
992
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1719
        theByteCode := #falseJump
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1720
    ] ifFalse:[
992
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1721
        theByteCode := #trueJump
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1722
    ].
1463
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  1723
    optByteCode := self optimizedConditionFor:theReceiver with:theByteCode for:aCompiler.
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1724
    optByteCode notNil ifTrue:[
992
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1725
        ((optByteCode == #eqJump) or:[optByteCode == #notEqJump]) ifTrue:[
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1726
            theArg := theReceiver arg1
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1727
        ].
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1728
        theReceiver := theReceiver receiver.
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1729
        theByteCode := optByteCode
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1730
    ].
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1731
104
claus
parents: 103
diff changeset
  1732
    theReceiver codeOn:aStream inBlock:b for:aCompiler.
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1733
    theArg notNil ifTrue:[
992
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1734
        theArg codeOn:aStream inBlock:b for:aCompiler
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1735
    ].
53
c5dd7abf8431 *** empty log message ***
claus
parents: 52
diff changeset
  1736
103
claus
parents: 102
diff changeset
  1737
    needLineNr := true.
claus
parents: 102
diff changeset
  1738
    theArg isNil ifTrue:[
992
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1739
        theReceiver isMessage ifTrue:[
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1740
            (aCompiler hasLineNumber:(theReceiver selector)) ifTrue:[
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1741
                theReceiver lineNumber == lineNr ifTrue:[
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1742
                    needLineNr := false
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1743
                ]
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1744
            ]
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1745
        ]
103
claus
parents: 102
diff changeset
  1746
    ].
claus
parents: 102
diff changeset
  1747
claus
parents: 102
diff changeset
  1748
    needLineNr ifTrue:[
992
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1749
        (lineNr between:1 and:255) ifTrue:[
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1750
            aStream nextPut:#lineno; nextPut:lineNr.
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1751
        ]
53
c5dd7abf8431 *** empty log message ***
claus
parents: 52
diff changeset
  1752
    ].
c5dd7abf8431 *** empty log message ***
claus
parents: 52
diff changeset
  1753
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1754
    aStream nextPut:theByteCode.
1371
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  1755
    pos := aStream position1Based.
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1756
    aStream nextPut:0.
1059
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1757
    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
  1758
be9680c6145c factored out some common code (block-code and value-sending)
Claus Gittinger <cg@exept.de>
parents: 1425
diff changeset
  1759
    self codeBlockEvaluation:block on:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler.
76
55d64cb1ffea *** empty log message ***
claus
parents: 75
diff changeset
  1760
55d64cb1ffea *** empty log message ***
claus
parents: 75
diff changeset
  1761
    code := aStream contents.
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1762
    valueNeeded ifTrue:[
992
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1763
        aStream nextPut:#jump.
1371
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  1764
        pos2 := aStream position1Based.
992
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1765
        aStream nextPut:0.
1371
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  1766
        code at:pos put:(aStream position1Based).
992
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  1767
        aStream nextPut:#pushNil.
1371
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  1768
        code at:pos2 put:(aStream position1Based)
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1769
    ] ifFalse:[
1371
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  1770
        code at:pos put:(aStream position1Based)
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1771
    ]
308
fe3b95e6d9c0 oops - dont try to inline: (expr or:expr2) ifXXX
Claus Gittinger <cg@exept.de>
parents: 289
diff changeset
  1772
627
b29a02258247 comments
Claus Gittinger <cg@exept.de>
parents: 624
diff changeset
  1773
    "Modified: / 28.10.1997 / 18:33:42 / cg"
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1774
!
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1775
338
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1776
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
  1777
    "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
  1778
1057
97ef980e2a46 better code for
Claus Gittinger <cg@exept.de>
parents: 1048
diff changeset
  1779
    |theByteCode optByteCode theReceiver theArg pos1 pos2 pos3 code here jmp
1059
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1780
     block1 block2 optJmp blockExpr|
338
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1781
1464
fa19f86d1ef4 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1463
diff changeset
  1782
    aCompiler addLiteral:#or:.
fa19f86d1ef4 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1463
diff changeset
  1783
338
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1784
    theByteCode := #trueJump.
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1785
    theReceiver := receiver receiver.
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1786
1463
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  1787
    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
  1788
    optByteCode notNil ifTrue:[
1057
97ef980e2a46 better code for
Claus Gittinger <cg@exept.de>
parents: 1048
diff changeset
  1789
        ((optByteCode == #eqJump) or:[optByteCode == #notEqJump]) ifTrue:[
97ef980e2a46 better code for
Claus Gittinger <cg@exept.de>
parents: 1048
diff changeset
  1790
            theArg := theReceiver arg1
97ef980e2a46 better code for
Claus Gittinger <cg@exept.de>
parents: 1048
diff changeset
  1791
        ].
97ef980e2a46 better code for
Claus Gittinger <cg@exept.de>
parents: 1048
diff changeset
  1792
        theReceiver := theReceiver receiver.
97ef980e2a46 better code for
Claus Gittinger <cg@exept.de>
parents: 1048
diff changeset
  1793
        theByteCode := optByteCode
338
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1794
    ].
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1795
    "/ 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
  1796
    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
  1797
    theArg notNil ifTrue:[
1057
97ef980e2a46 better code for
Claus Gittinger <cg@exept.de>
parents: 1048
diff changeset
  1798
        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
  1799
    ].
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1800
    aStream nextPut:theByteCode.
1371
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  1801
    pos1 := aStream position1Based.   "/ 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
  1802
    aStream nextPut:0.
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1803
1057
97ef980e2a46 better code for
Claus Gittinger <cg@exept.de>
parents: 1048
diff changeset
  1804
    "/ 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
  1805
    (selector == #ifTrue:ifFalse:) ifTrue:[
1057
97ef980e2a46 better code for
Claus Gittinger <cg@exept.de>
parents: 1048
diff changeset
  1806
        jmp := #falseJump
338
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1807
    ] ifFalse:[
1057
97ef980e2a46 better code for
Claus Gittinger <cg@exept.de>
parents: 1048
diff changeset
  1808
        jmp := #trueJump
97ef980e2a46 better code for
Claus Gittinger <cg@exept.de>
parents: 1048
diff changeset
  1809
    ].
97ef980e2a46 better code for
Claus Gittinger <cg@exept.de>
parents: 1048
diff changeset
  1810
    theReceiver := receiver arg1.
97ef980e2a46 better code for
Claus Gittinger <cg@exept.de>
parents: 1048
diff changeset
  1811
    theArg := nil.
97ef980e2a46 better code for
Claus Gittinger <cg@exept.de>
parents: 1048
diff changeset
  1812
    optJmp := nil.
97ef980e2a46 better code for
Claus Gittinger <cg@exept.de>
parents: 1048
diff changeset
  1813
97ef980e2a46 better code for
Claus Gittinger <cg@exept.de>
parents: 1048
diff changeset
  1814
    (theReceiver isBlock
97ef980e2a46 better code for
Claus Gittinger <cg@exept.de>
parents: 1048
diff changeset
  1815
    and:[theReceiver statements notNil
97ef980e2a46 better code for
Claus Gittinger <cg@exept.de>
parents: 1048
diff changeset
  1816
    and:[theReceiver statements nextStatement isNil]]) ifTrue:[
97ef980e2a46 better code for
Claus Gittinger <cg@exept.de>
parents: 1048
diff changeset
  1817
        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
  1818
        optJmp := self optimizedConditionFor:blockExpr with:jmp for:aCompiler.
1057
97ef980e2a46 better code for
Claus Gittinger <cg@exept.de>
parents: 1048
diff changeset
  1819
        optJmp notNil ifTrue:[
97ef980e2a46 better code for
Claus Gittinger <cg@exept.de>
parents: 1048
diff changeset
  1820
            ((optJmp == #eqJump) or:[optJmp == #notEqJump]) ifTrue:[
97ef980e2a46 better code for
Claus Gittinger <cg@exept.de>
parents: 1048
diff changeset
  1821
                theArg := blockExpr arg1
97ef980e2a46 better code for
Claus Gittinger <cg@exept.de>
parents: 1048
diff changeset
  1822
            ].
97ef980e2a46 better code for
Claus Gittinger <cg@exept.de>
parents: 1048
diff changeset
  1823
            theReceiver := blockExpr receiver.
97ef980e2a46 better code for
Claus Gittinger <cg@exept.de>
parents: 1048
diff changeset
  1824
            jmp := optJmp
97ef980e2a46 better code for
Claus Gittinger <cg@exept.de>
parents: 1048
diff changeset
  1825
        ].
97ef980e2a46 better code for
Claus Gittinger <cg@exept.de>
parents: 1048
diff changeset
  1826
    ].
97ef980e2a46 better code for
Claus Gittinger <cg@exept.de>
parents: 1048
diff changeset
  1827
97ef980e2a46 better code for
Claus Gittinger <cg@exept.de>
parents: 1048
diff changeset
  1828
    optJmp notNil ifTrue:[
97ef980e2a46 better code for
Claus Gittinger <cg@exept.de>
parents: 1048
diff changeset
  1829
        theReceiver codeOn:aStream inBlock:b for:aCompiler.
1058
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  1830
        theArg notNil ifTrue:[
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  1831
            theArg codeOn:aStream inBlock:b for:aCompiler
Claus Gittinger <cg@exept.de>
parents: 1057
diff changeset
  1832
        ]
1057
97ef980e2a46 better code for
Claus Gittinger <cg@exept.de>
parents: 1048
diff changeset
  1833
    ] ifFalse:[
97ef980e2a46 better code for
Claus Gittinger <cg@exept.de>
parents: 1048
diff changeset
  1834
        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
  1835
    ].
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1836
    aStream nextPut:jmp.
1371
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  1837
    pos2 := aStream position1Based.   "/ 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
  1838
    aStream nextPut:0.
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1839
1057
97ef980e2a46 better code for
Claus Gittinger <cg@exept.de>
parents: 1048
diff changeset
  1840
338
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1841
    code := aStream contents.
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1842
    (selector == #ifTrue:ifFalse:) ifTrue:[
1371
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  1843
        code at:pos1 put:(aStream position1Based)
338
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1844
    ].
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1845
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1846
    "/ code the if-block
1059
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1847
    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
  1848
    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
  1849
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1850
    aStream nextPut:#jump.
1371
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  1851
    pos3 := aStream position1Based.
338
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1852
    aStream nextPut:0.
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1853
1371
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  1854
    here := aStream position1Based.
338
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1855
    (selector == #ifFalse:ifTrue:) ifTrue:[
1057
97ef980e2a46 better code for
Claus Gittinger <cg@exept.de>
parents: 1048
diff changeset
  1856
        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
  1857
    ].
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1858
    code at:pos2 put:here.
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1859
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1860
    "/ code the else-block
1059
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1861
    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
  1862
    self codeBlockEvaluation:block2 on:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler.
1371
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  1863
    code at:pos3 put:(aStream position1Based)
338
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1864
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1865
    "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
  1866
!
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1867
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1868
codeOrIfOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1869
    "generate code for (x or:[y]) ifxxx:[ ... ]"
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1870
1059
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1871
    |theByteCode optByteCode theReceiver theArg pos1 pos2 pos3 code here jmp
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1872
     block|
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1873
1464
fa19f86d1ef4 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1463
diff changeset
  1874
    aCompiler addLiteral:#or:.
fa19f86d1ef4 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1463
diff changeset
  1875
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1876
    theByteCode := #trueJump.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1877
    theReceiver := receiver receiver.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1878
1463
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  1879
    optByteCode := self optimizedConditionFor:theReceiver with:theByteCode for:aCompiler.
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1880
    optByteCode notNil ifTrue:[
1059
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1881
        ((optByteCode == #eqJump) or:[optByteCode == #notEqJump]) ifTrue:[
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1882
            theArg := theReceiver arg1
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1883
        ].
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1884
        theReceiver := theReceiver receiver.
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1885
        theByteCode := optByteCode
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1886
    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1887
    theReceiver codeOn:aStream inBlock:b for:aCompiler.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1888
    theArg notNil ifTrue:[
1059
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1889
        theArg codeOn:aStream inBlock:b for:aCompiler
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1890
    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1891
    aStream nextPut:theByteCode.
1371
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  1892
    pos1 := aStream position1Based.
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1893
    aStream nextPut:0.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1894
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1895
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1896
    theReceiver := receiver arg1.
434
c48a356d8a34 oops - optimizable or: ... ifTrue/ifFalse generated
Claus Gittinger <cg@exept.de>
parents: 429
diff changeset
  1897
    theArg := nil.
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1898
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1899
"new:"
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1900
    (selector == #ifTrue:) ifTrue:[
1059
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1901
        theByteCode := #falseJump
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1902
    ] ifFalse:[
1059
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1903
        theByteCode := #trueJump
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1904
    ].
1463
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  1905
    optByteCode := self optimizedConditionFor:theReceiver with:theByteCode for:aCompiler.
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1906
    optByteCode notNil ifTrue:[
1059
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1907
        theReceiver isBlock ifTrue:[
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1908
            theReceiver := theReceiver statements expression
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1909
        ].
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1910
        ((optByteCode == #eqJump) or:[optByteCode == #notEqJump]) ifTrue:[
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1911
            theArg := theReceiver arg1
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1912
        ].
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1913
        theReceiver := theReceiver receiver.
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1914
        theByteCode := optByteCode.
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1915
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1916
        theReceiver codeOn:aStream inBlock:b for:aCompiler.
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1917
        theArg notNil ifTrue:[
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1918
            theArg codeOn:aStream inBlock:b for:aCompiler
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1919
        ].
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1920
        aStream nextPut:theByteCode.
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1921
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1922
    ] ifFalse:[
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1923
"org"
1059
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1924
        theReceiver codeInlineOn:aStream inBlock:b for:aCompiler.
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1925
        (selector == #ifTrue:) ifTrue:[
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1926
            jmp := #falseJump
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1927
        ] ifFalse:[
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1928
            jmp := #trueJump
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1929
        ].
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1930
        aStream nextPut:jmp
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1931
    ].
1371
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  1932
    pos2 := aStream position1Based.
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1933
    aStream nextPut:0.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1934
    (selector == #ifTrue:) ifTrue:[
1371
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  1935
        (aStream contents) at:pos1 put:(aStream position1Based)
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1936
    ].
1059
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1937
    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
  1938
    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
  1939
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1940
    code := aStream contents.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1941
    valueNeeded ifTrue:[
1059
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1942
        aStream nextPut:#jump.
1371
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  1943
        pos3 := aStream position1Based.
1059
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1944
        aStream nextPut:0.
1371
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  1945
        here := aStream position1Based.
1059
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1946
        (selector == #ifFalse:) ifTrue:[
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1947
            code at:pos1 put:here
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1948
        ].
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1949
        code at:pos2 put:here.
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1950
        aStream nextPut:#pushNil.
1371
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  1951
        code at:pos3 put:(aStream position1Based)
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1952
    ] ifFalse:[
1371
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  1953
        here := aStream position1Based.
1059
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1954
        (selector == #ifFalse:) ifTrue:[
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1955
            code at:pos1 put:here
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1956
        ].
7ce5819138e8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1058
diff changeset
  1957
        code at:pos2 put:here
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1958
    ]
434
c48a356d8a34 oops - optimizable or: ... ifTrue/ifFalse generated
Claus Gittinger <cg@exept.de>
parents: 429
diff changeset
  1959
c48a356d8a34 oops - optimizable or: ... ifTrue/ifFalse generated
Claus Gittinger <cg@exept.de>
parents: 429
diff changeset
  1960
    "Modified: 9.11.1996 / 19:52:26 / cg"
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1961
!
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1962
289
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  1963
codeOrOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  1964
    "generate code for (x or:[y])"
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  1965
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  1966
    |pos1 rightExpr|
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  1967
1464
fa19f86d1ef4 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1463
diff changeset
  1968
    aCompiler addLiteral:#or:.
fa19f86d1ef4 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1463
diff changeset
  1969
289
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  1970
    receiver codeOn:aStream inBlock:b for:aCompiler.
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  1971
    valueNeeded ifTrue:[
1371
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  1972
        aStream nextPut:#dup.
289
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  1973
    ].
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  1974
    aStream nextPut:#trueJump.
1371
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  1975
    pos1 := aStream position1Based.
289
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  1976
    aStream nextPut:0.
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  1977
    valueNeeded ifTrue:[
1371
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  1978
        aStream nextPut:#drop.
289
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  1979
    ].
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  1980
    rightExpr := argArray at:1.
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  1981
    rightExpr codeInlineOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler.
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  1982
1371
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  1983
    (aStream contents) at:pos1 put:(aStream position1Based)
289
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  1984
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  1985
    "Created: 17.6.1996 / 15:40:22 / cg"
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  1986
    "Modified: 17.6.1996 / 15:47:22 / cg"
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  1987
!
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  1988
436
b34370bb0a74 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 434
diff changeset
  1989
codeQuestOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler
627
b29a02258247 comments
Claus Gittinger <cg@exept.de>
parents: 624
diff changeset
  1990
    "generate code for x ? y. 
b29a02258247 comments
Claus Gittinger <cg@exept.de>
parents: 624
diff changeset
  1991
     However, this is only done for non-send args."
436
b34370bb0a74 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 434
diff changeset
  1992
b34370bb0a74 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 434
diff changeset
  1993
    |pos code|
b34370bb0a74 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 434
diff changeset
  1994
1464
fa19f86d1ef4 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1463
diff changeset
  1995
    aCompiler addLiteral:#'?'.
fa19f86d1ef4 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1463
diff changeset
  1996
436
b34370bb0a74 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 434
diff changeset
  1997
    receiver codeOn:aStream inBlock:b for:aCompiler.
b34370bb0a74 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 434
diff changeset
  1998
    aStream nextPut:#dup.
b34370bb0a74 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 434
diff changeset
  1999
    aStream nextPut:#notNilJump.
1371
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2000
    pos := aStream position1Based.
437
994414f5126a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 436
diff changeset
  2001
    aStream nextPut:0.
436
b34370bb0a74 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 434
diff changeset
  2002
b34370bb0a74 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 434
diff changeset
  2003
    aStream nextPut:#drop.
b34370bb0a74 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 434
diff changeset
  2004
    (argArray at: 1) codeOn:aStream inBlock:b for:aCompiler.
b34370bb0a74 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 434
diff changeset
  2005
b34370bb0a74 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 434
diff changeset
  2006
    code := aStream contents.
1371
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2007
    code at:pos put:(aStream position1Based).
909
4917ac8408fb oops - inlined ? for-effect left value on top of stack
Claus Gittinger <cg@exept.de>
parents: 908
diff changeset
  2008
4917ac8408fb oops - inlined ? for-effect left value on top of stack
Claus Gittinger <cg@exept.de>
parents: 908
diff changeset
  2009
    valueNeeded ifFalse:[
4917ac8408fb oops - inlined ? for-effect left value on top of stack
Claus Gittinger <cg@exept.de>
parents: 908
diff changeset
  2010
        aStream nextPut:#drop.
4917ac8408fb oops - inlined ? for-effect left value on top of stack
Claus Gittinger <cg@exept.de>
parents: 908
diff changeset
  2011
    ].
436
b34370bb0a74 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 434
diff changeset
  2012
627
b29a02258247 comments
Claus Gittinger <cg@exept.de>
parents: 624
diff changeset
  2013
    "Created: / 10.11.1996 / 18:28:57 / cg"
b29a02258247 comments
Claus Gittinger <cg@exept.de>
parents: 624
diff changeset
  2014
    "Modified: / 28.10.1997 / 18:16:20 / cg"
436
b34370bb0a74 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 434
diff changeset
  2015
!
b34370bb0a74 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 434
diff changeset
  2016
602
1be5dd333adc inline #repeat
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  2017
codeRepeatOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler
1425
4f698bf5ff76 inline [...] loop
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
  2018
    "generate code for 
4f698bf5ff76 inline [...] loop
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
  2019
        [ ... ] repeat
4f698bf5ff76 inline [...] loop
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
  2020
     and:
4f698bf5ff76 inline [...] loop
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
  2021
        [ ... ] loop
4f698bf5ff76 inline [...] loop
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
  2022
    "
602
1be5dd333adc inline #repeat
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  2023
1be5dd333adc inline #repeat
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  2024
    |pos|
1be5dd333adc inline #repeat
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  2025
1371
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2026
    pos := aStream position1Based.
602
1be5dd333adc inline #repeat
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  2027
    receiver codeInlineOn:aStream inBlock:b valueNeeded:false for:aCompiler.
1be5dd333adc inline #repeat
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  2028
    aStream nextPut:#jump; nextPut:pos.
1be5dd333adc inline #repeat
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  2029
1be5dd333adc inline #repeat
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  2030
    "Created: 29.8.1997 / 08:14:58 / cg"
1be5dd333adc inline #repeat
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  2031
!
1be5dd333adc inline #repeat
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  2032
104
claus
parents: 103
diff changeset
  2033
codeSendOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2034
    "like code on, but assumes that receiver has already been
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2035
     coded onto stack - needed for cascade"
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2036
1809
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  2037
    |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
  2038
     noSendDrop alreadyDropped|
1045
ee448a958d19 migration support
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
  2039
1500
3c4cb012b24b Lazy conversion of selector strings to symbols.
Stefan Vogel <sv@exept.de>
parents: 1480
diff changeset
  2040
    selector := selector asSymbol.
1048
6eaeba225e67 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1046
diff changeset
  2041
    noSendDrop := aCompiler class newCodeSet == true.
861
ccaa0ba5e7af generate selector symbols late (when compiling or evaluating)
Claus Gittinger <cg@exept.de>
parents: 856
diff changeset
  2042
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2043
    realReceiver := self realReceiver.
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2044
    isSuper := realReceiver isSuper.
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2045
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2046
    argArray isNil ifTrue:[
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2047
        nargs := 0
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2048
    ] ifFalse:[
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2049
        nargs := argArray size
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2050
    ].
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2051
1809
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  2052
    litIndex := aCompiler addLiteral:selector.
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  2053
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  2054
    isBuiltIn := isSuper not and:[ aCompiler isBuiltInSelector:selector forReceiver:receiver ].
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2055
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2056
    "can we use a send-bytecode ?"
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2057
    isBuiltIn ifTrue:[
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2058
        (nargs > 0) ifTrue:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2059
            (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
  2060
            (nargs > 1) ifTrue:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2061
                (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
  2062
            ]
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2063
        ].
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2064
        aStream nextPut:selector.
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2065
        (aCompiler hasLineNumber:selector) ifTrue:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2066
            aStream nextPut:lineNr.
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2067
        ].
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2068
        valueNeeded ifFalse:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2069
            aStream nextPut:#drop
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2070
        ].
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2071
        ^ self
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2072
    ].
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2073
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2074
    argArray notNil ifTrue:[
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2075
        argArray do:[:arg |
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2076
            arg codeOn:aStream inBlock:b for:aCompiler
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2077
        ]
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2078
    ].
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2079
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2080
    isSuper ifTrue:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2081
        cls := aCompiler targetClass.
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2082
        realReceiver isHere ifTrue:[
1809
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  2083
            "/ 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
  2084
        ] ifFalse:[
1809
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  2085
            "/ targetClasses superclass starts search
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2086
            cls := cls superclass.
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2087
        ].
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2088
        clsLitIndex := aCompiler addLiteral:cls.
1809
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  2089
        self emitSuperSendLiteralIndex:litIndex classLiteralIndex:clsLitIndex numArgs:nargs line:lineNr on:aStream.
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2090
        valueNeeded ifFalse:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2091
            aStream nextPut:#drop
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2092
        ].
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2093
        ^ self
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2094
    ].
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2095
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2096
    (nargs == 0) ifTrue:[
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2097
        (selector == #yourself) ifTrue:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2098
            "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
  2099
             we get it without the yourself-message"
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2100
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2101
            valueNeeded ifFalse:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2102
                aStream nextPut:#drop
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2103
            ].
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2104
            ^ self
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2105
        ].
49
02660b790c3e *** empty log message ***
claus
parents: 48
diff changeset
  2106
    ].
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2107
1809
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  2108
    alreadyDropped := false.
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  2109
    valueNeeded ifTrue:[ noSendDrop := true ].
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  2110
117
claus
parents: 111
diff changeset
  2111
    litIndex <= 255 ifTrue:[
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2112
        (nargs <= 3) ifTrue:[
1809
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  2113
            noSendDrop ifTrue:[
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2114
                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
  2115
            ] ifFalse:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2116
                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
  2117
                alreadyDropped := true.
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2118
            ].
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2119
            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
  2120
            valueNeeded ifFalse:[
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  2121
                alreadyDropped ifFalse:[
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  2122
                    aStream nextPut:#drop
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  2123
                ].
1045
ee448a958d19 migration support
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
  2124
            ].
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2125
            ^ self
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2126
        ].
106
claus
parents: 104
diff changeset
  2127
1809
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  2128
        noSendDrop ifTrue:[
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2129
            code := #send
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2130
        ] ifFalse:[
1809
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  2131
            code := #sendDrop.
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  2132
            alreadyDropped := true.
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2133
        ].
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2134
        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
  2135
        valueNeeded ifFalse:[
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  2136
            alreadyDropped ifFalse:[
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  2137
                aStream nextPut:#drop
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  2138
            ].
1045
ee448a958d19 migration support
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
  2139
        ].
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2140
        ^ self
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2141
    ].
49
02660b790c3e *** empty log message ***
claus
parents: 48
diff changeset
  2142
1809
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  2143
    self emitSendLiteralIndex:litIndex numArgs:nargs line:lineNr on:aStream.
007cb2a08623 some code savers for common code-emit;
Claus Gittinger <cg@exept.de>
parents: 1801
diff changeset
  2144
    valueNeeded ifFalse:[
1045
ee448a958d19 migration support
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
  2145
        aStream nextPut:#drop
ee448a958d19 migration support
Claus Gittinger <cg@exept.de>
parents: 1035
diff changeset
  2146
    ].
189
673580572edd fixed cascades involving super sends (i.e. super foo; bar)
Claus Gittinger <cg@exept.de>
parents: 186
diff changeset
  2147
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2148
    "Modified: / 16.7.1998 / 20:26:52 / cg"
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2149
!
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2150
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2151
codeTimesRepeatOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2152
    "generate code for n timesRepeat:[ ... ]"
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2153
908
294e131f2f6d oops - 0 timesRepeat (with constant receiver) did it once
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  2154
    |pos1 pos2 lateEval loopCount|
349
7632e597a3df no need to keep receiver on stack for
Claus Gittinger <cg@exept.de>
parents: 338
diff changeset
  2155
7632e597a3df no need to keep receiver on stack for
Claus Gittinger <cg@exept.de>
parents: 338
diff changeset
  2156
    lateEval := false.
528
0a35ed44989f oops - timesRepeat dupped one too many
Claus Gittinger <cg@exept.de>
parents: 437
diff changeset
  2157
908
294e131f2f6d oops - 0 timesRepeat (with constant receiver) did it once
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  2158
    receiver isConstant ifTrue:[
294e131f2f6d oops - 0 timesRepeat (with constant receiver) did it once
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  2159
        loopCount := receiver evaluate.
856
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2160
        (loopCount isMemberOf:SmallInteger) ifFalse:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2161
            loopCount := nil.
908
294e131f2f6d oops - 0 timesRepeat (with constant receiver) did it once
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  2162
        ] ifTrue:[
294e131f2f6d oops - 0 timesRepeat (with constant receiver) did it once
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  2163
            loopCount <= 0 ifTrue:[
294e131f2f6d oops - 0 timesRepeat (with constant receiver) did it once
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  2164
                "/ 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
  2165
                valueNeeded ifTrue:[
294e131f2f6d oops - 0 timesRepeat (with constant receiver) did it once
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  2166
                    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
  2167
                ].
294e131f2f6d oops - 0 timesRepeat (with constant receiver) did it once
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  2168
                ^ self
294e131f2f6d oops - 0 timesRepeat (with constant receiver) did it once
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  2169
            ]
294e131f2f6d oops - 0 timesRepeat (with constant receiver) did it once
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  2170
        ].
856
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2171
    ].
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2172
908
294e131f2f6d oops - 0 timesRepeat (with constant receiver) did it once
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  2173
    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
  2174
349
7632e597a3df no need to keep receiver on stack for
Claus Gittinger <cg@exept.de>
parents: 338
diff changeset
  2175
    valueNeeded ifTrue:[
856
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2176
        "/ easily reconstructable - no need to keep on stack
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2177
        loopCount notNil ifTrue:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2178
            lateEval := true.
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2179
        ].
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2180
        lateEval ifFalse:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2181
            aStream nextPut:#dup
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2182
        ].
349
7632e597a3df no need to keep receiver on stack for
Claus Gittinger <cg@exept.de>
parents: 338
diff changeset
  2183
    ].
96
claus
parents: 95
diff changeset
  2184
856
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2185
    loopCount isNil ifTrue:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2186
        aStream nextPut:#pushgt0; nextPut:lineNr; nextPut:#falseJump.
1371
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2187
        pos2 := aStream position1Based.
856
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2188
        aStream nextPut:0.
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2189
    ].
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2190
1371
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2191
    pos1 := aStream position1Based.
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2192
    (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
  2193
    aStream nextPut:#minus1; nextPut:lineNr.
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2194
    aStream nextPut:#pushgt0; nextPut:lineNr.
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2195
    aStream nextPut:#trueJump; nextPut:pos1.
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2196
856
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2197
    pos2 notNil ifTrue:[
1371
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2198
        (aStream contents) at:pos2 put:(aStream position1Based).
856
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2199
    ].
528
0a35ed44989f oops - timesRepeat dupped one too many
Claus Gittinger <cg@exept.de>
parents: 437
diff changeset
  2200
    aStream nextPut:#drop.  "/ drop run variable
856
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2201
349
7632e597a3df no need to keep receiver on stack for
Claus Gittinger <cg@exept.de>
parents: 338
diff changeset
  2202
    lateEval ifTrue:[
908
294e131f2f6d oops - 0 timesRepeat (with constant receiver) did it once
Claus Gittinger <cg@exept.de>
parents: 905
diff changeset
  2203
        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
  2204
    ]
7632e597a3df no need to keep receiver on stack for
Claus Gittinger <cg@exept.de>
parents: 338
diff changeset
  2205
528
0a35ed44989f oops - timesRepeat dupped one too many
Claus Gittinger <cg@exept.de>
parents: 437
diff changeset
  2206
    "Modified: 27.5.1997 / 14:28:49 / cg"
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2207
!
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2208
565
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2209
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
  2210
    "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
  2211
565
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2212
    |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
  2213
     stepVal stopVarIndex|
561
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2214
565
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2215
    "/ 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
  2216
    "/ 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
  2217
    "/ 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
  2218
    "/ 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
  2219
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2220
    start := receiver.
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2221
    stop := (argArray at:1).
565
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2222
    step := (argArray at:2).
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2223
1397
969f505b6111 #errorSignal -> #description
Stefan Vogel <sv@exept.de>
parents: 1389
diff changeset
  2224
"/    stop isConstant ifFalse:[self error:'should not happen' mayProceed:true].
969f505b6111 #errorSignal -> #description
Stefan Vogel <sv@exept.de>
parents: 1389
diff changeset
  2225
"/    (stop evaluate isMemberOf:SmallInteger) ifFalse:[self error:'should not happen' mayProceed:true].
969f505b6111 #errorSignal -> #description
Stefan Vogel <sv@exept.de>
parents: 1389
diff changeset
  2226
969f505b6111 #errorSignal -> #description
Stefan Vogel <sv@exept.de>
parents: 1389
diff changeset
  2227
    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
  2228
    stepVal := step evaluate.
1397
969f505b6111 #errorSignal -> #description
Stefan Vogel <sv@exept.de>
parents: 1389
diff changeset
  2229
    (stepVal isMemberOf:SmallInteger) ifFalse:[
969f505b6111 #errorSignal -> #description
Stefan Vogel <sv@exept.de>
parents: 1389
diff changeset
  2230
        self error:'should not happen' mayProceed:true
969f505b6111 #errorSignal -> #description
Stefan Vogel <sv@exept.de>
parents: 1389
diff changeset
  2231
    ].
561
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2232
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2233
    start codeOn:aStream inBlock:b for:aCompiler.
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2234
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2235
    lateEval := false.
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2236
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2237
    valueNeeded ifTrue:[
1281
e70c494950b2 ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents: 1266
diff changeset
  2238
        "/ 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
  2239
        start isConstant ifTrue:[
e70c494950b2 ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents: 1266
diff changeset
  2240
            (start evaluate isMemberOf:SmallInteger) ifTrue:[
e70c494950b2 ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents: 1266
diff changeset
  2241
                lateEval := true.
e70c494950b2 ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents: 1266
diff changeset
  2242
            ]
e70c494950b2 ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents: 1266
diff changeset
  2243
        ].
e70c494950b2 ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents: 1266
diff changeset
  2244
        lateEval ifFalse:[
e70c494950b2 ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents: 1266
diff changeset
  2245
            aStream nextPut:#dup
e70c494950b2 ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents: 1266
diff changeset
  2246
        ].
561
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2247
    ].
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2248
565
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2249
    "/ 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
  2250
    "/  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
  2251
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2252
    (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
  2253
        "/ 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
  2254
        (stop isVariable and:[stop isArgument]) ifFalse:[
e70c494950b2 ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents: 1266
diff changeset
  2255
            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
  2256
e70c494950b2 ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents: 1266
diff changeset
  2257
            b isNil ifTrue:[
e70c494950b2 ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents: 1266
diff changeset
  2258
                stopVarIndex := aCompiler addTempVar.
e70c494950b2 ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents: 1266
diff changeset
  2259
                aStream nextPut:#storeMethodVar; nextPut:stopVarIndex.
e70c494950b2 ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents: 1266
diff changeset
  2260
            ] ifFalse:[
e70c494950b2 ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents: 1266
diff changeset
  2261
                stopVarIndex := b addTempVar.
e70c494950b2 ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents: 1266
diff changeset
  2262
                aStream nextPut:#storeBlockVar; nextPut:stopVarIndex.
e70c494950b2 ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents: 1266
diff changeset
  2263
            ].
e70c494950b2 ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents: 1266
diff changeset
  2264
        ]
565
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2265
    ].
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2266
1371
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2267
    pos := aStream position1Based.
561
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2268
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2269
    aStream nextPut:#dup.
565
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2270
    stopVarIndex notNil ifTrue:[
1281
e70c494950b2 ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents: 1266
diff changeset
  2271
        b isNil ifTrue:[
e70c494950b2 ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents: 1266
diff changeset
  2272
            aStream nextPut:#pushMethodVar; nextPut:stopVarIndex.
e70c494950b2 ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents: 1266
diff changeset
  2273
        ] ifFalse:[
e70c494950b2 ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents: 1266
diff changeset
  2274
            aStream nextPut:#pushBlockVar; nextPut:stopVarIndex.
e70c494950b2 ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents: 1266
diff changeset
  2275
        ]
565
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2276
    ] ifFalse:[
1281
e70c494950b2 ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents: 1266
diff changeset
  2277
        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
  2278
    ].
1281
e70c494950b2 ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents: 1266
diff changeset
  2279
    stepVal >= 0 ifTrue:[
e70c494950b2 ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents: 1266
diff changeset
  2280
        aStream nextPut:#>.
565
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2281
    ] ifFalse:[
1281
e70c494950b2 ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents: 1266
diff changeset
  2282
        aStream nextPut:#<.
565
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2283
    ].
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2284
    (aCompiler hasLineNumber:selector) ifTrue:[
1281
e70c494950b2 ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents: 1266
diff changeset
  2285
        aStream nextPut:lineNr.
565
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2286
    ].
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2287
    aStream nextPut:#trueJump.
1371
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2288
    pos2 := aStream position1Based.
565
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2289
    aStream nextPut:0.
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2290
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2291
    theBlock := argArray at:3.
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2292
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2293
    "/ 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
  2294
    "/ the loop ...
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2295
    b isNil ifTrue:[
1281
e70c494950b2 ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents: 1266
diff changeset
  2296
        loopVarIndex := aCompiler addTempVar.
e70c494950b2 ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents: 1266
diff changeset
  2297
        aStream nextPut:#dup.
e70c494950b2 ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents: 1266
diff changeset
  2298
        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
  2299
    ] ifFalse:[
1281
e70c494950b2 ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents: 1266
diff changeset
  2300
        loopVarIndex := b addTempVar.
e70c494950b2 ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents: 1266
diff changeset
  2301
        aStream nextPut:#dup.
e70c494950b2 ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents: 1266
diff changeset
  2302
        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
  2303
    ].
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2304
    theBlock indexOfFirstTemp:loopVarIndex.
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2305
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2306
    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
  2307
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2308
    "/ increment/decrement counter & jump back.
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2309
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2310
    stepVal == 1 ifTrue:[
1281
e70c494950b2 ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents: 1266
diff changeset
  2311
        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
  2312
    ] ifFalse:[
1281
e70c494950b2 ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents: 1266
diff changeset
  2313
        stepVal == -1 ifTrue:[
e70c494950b2 ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents: 1266
diff changeset
  2314
            aStream nextPut:#minus1; nextPut:lineNr.
e70c494950b2 ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents: 1266
diff changeset
  2315
        ] ifFalse:[
e70c494950b2 ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents: 1266
diff changeset
  2316
            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
  2317
            aStream nextPut:#+.
e70c494950b2 ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents: 1266
diff changeset
  2318
            (aCompiler hasLineNumber:#+) ifTrue:[
e70c494950b2 ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents: 1266
diff changeset
  2319
                aStream nextPut:lineNr.
e70c494950b2 ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents: 1266
diff changeset
  2320
            ].
e70c494950b2 ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents: 1266
diff changeset
  2321
        ]
565
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2322
    ].
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2323
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2324
    aStream nextPut:#jump; nextPut:pos.
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2325
1371
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2326
    (aStream contents) at:pos2 put:(aStream position1Based).
565
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2327
    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
  2328
    lateEval ifTrue:[
1281
e70c494950b2 ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents: 1266
diff changeset
  2329
        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
  2330
    ].
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2331
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2332
    "/ 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
  2333
    "/ (its integer, anyway).
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2334
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2335
    b isNil ifTrue:[
1281
e70c494950b2 ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents: 1266
diff changeset
  2336
        aCompiler removeTempVar
565
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2337
    ] ifFalse:[
1281
e70c494950b2 ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents: 1266
diff changeset
  2338
        b removeTempVar
565
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2339
    ].
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2340
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2341
    stopVarIndex notNil ifTrue:[
1281
e70c494950b2 ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents: 1266
diff changeset
  2342
        b isNil ifTrue:[
e70c494950b2 ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents: 1266
diff changeset
  2343
            aCompiler removeTempVar
e70c494950b2 ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents: 1266
diff changeset
  2344
        ] ifFalse:[
e70c494950b2 ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents: 1266
diff changeset
  2345
            b removeTempVar
e70c494950b2 ansi error: to:by:do: with 0 increment.
Claus Gittinger <cg@exept.de>
parents: 1266
diff changeset
  2346
        ]
565
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2347
    ].
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2348
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2349
    "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
  2350
    "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
  2351
!
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2352
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2353
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
  2354
    "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
  2355
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2356
    |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
  2357
     stopVarIndex|
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2358
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2359
    "/ 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
  2360
    "/ 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
  2361
    "/ 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
  2362
    "/ 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
  2363
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2364
    start := receiver.
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2365
    stop := (argArray at:1).
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2366
"/    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
  2367
"/    (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
  2368
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2369
    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
  2370
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2371
    lateEval := false.
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2372
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2373
    valueNeeded ifTrue:[
1371
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2374
        "/ 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
  2375
        start isConstant ifTrue:[
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2376
            (start evaluate isMemberOf:SmallInteger) ifTrue:[
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2377
                lateEval := true.
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2378
            ]
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2379
        ].
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2380
        lateEval ifFalse:[
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2381
            aStream nextPut:#dup
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2382
        ].
565
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2383
    ].
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2384
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2385
    "/ 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
  2386
    "/  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
  2387
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2388
    (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
  2389
        "/ 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
  2390
        (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
  2391
            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
  2392
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2393
            b isNil ifTrue:[
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2394
                stopVarIndex := aCompiler addTempVar.
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2395
                aStream nextPut:#storeMethodVar; nextPut:stopVarIndex.
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2396
            ] ifFalse:[
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2397
                stopVarIndex := b addTempVar.
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2398
                aStream nextPut:#storeBlockVar; nextPut:stopVarIndex.
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2399
            ].
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2400
        ]
565
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2401
    ].
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2402
1371
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2403
    pos := aStream position1Based.
565
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2404
624
e71abe9654e6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 602
diff changeset
  2405
    aStream nextPut:#lineno; nextPut:lineNr.
e71abe9654e6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 602
diff changeset
  2406
565
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2407
    aStream nextPut:#dup.
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2408
    stopVarIndex notNil ifTrue:[
1371
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2409
        b isNil ifTrue:[
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2410
            aStream nextPut:#pushMethodVar; nextPut:stopVarIndex.
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2411
        ] ifFalse:[
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2412
            aStream nextPut:#pushBlockVar; nextPut:stopVarIndex.
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2413
        ]
565
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2414
    ] ifFalse:[
1371
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2415
        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
  2416
    ].
561
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2417
    aStream nextPut:#>.
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2418
    (aCompiler hasLineNumber:selector) ifTrue:[
1371
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2419
        aStream nextPut:lineNr.
561
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2420
    ].
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2421
    aStream nextPut:#trueJump.
1371
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2422
    pos2 := aStream position1Based.
561
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2423
    aStream nextPut:0.
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2424
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2425
    theBlock := argArray at:2.
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2426
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2427
    "/ 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
  2428
    "/ the loop ...
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2429
    b isNil ifTrue:[
1371
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2430
        loopVarIndex := aCompiler addTempVar.
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2431
        aStream nextPut:#dup.
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2432
        aStream nextPut:#storeMethodVar; nextPut:loopVarIndex.
561
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2433
    ] ifFalse:[
1371
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2434
        loopVarIndex := b addTempVar.
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2435
        aStream nextPut:#dup.
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2436
        aStream nextPut:#storeBlockVar; nextPut:loopVarIndex.
561
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2437
    ].
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2438
    theBlock indexOfFirstTemp:loopVarIndex.
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2439
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2440
    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
  2441
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2442
    "/ increment counter & jump back.
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2443
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2444
    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
  2445
1371
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2446
    (aStream contents) at:pos2 put:(aStream position1Based).
561
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2447
    aStream nextPut:#drop.  "/ drop run variable
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2448
    lateEval ifTrue:[
1371
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2449
        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
  2450
    ].
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2451
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2452
    "/ 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
  2453
    "/ (its integer, anyway).
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2454
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2455
    b isNil ifTrue:[
1371
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2456
        aCompiler removeTempVar
561
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2457
    ] ifFalse:[
1371
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2458
        b removeTempVar
565
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2459
    ].
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2460
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2461
    stopVarIndex notNil ifTrue:[
1371
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2462
        b isNil ifTrue:[
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2463
            aCompiler removeTempVar
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2464
        ] ifFalse:[
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2465
            b removeTempVar
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2466
        ]
565
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2467
    ].
561
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2468
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2469
    "Created: 26.6.1997 / 10:58:47 / cg"
624
e71abe9654e6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 602
diff changeset
  2470
    "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
  2471
!
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2472
1435
be9680c6145c factored out some common code (block-code and value-sending)
Claus Gittinger <cg@exept.de>
parents: 1425
diff changeset
  2473
codeValueSendOn:aStream for:aCompiler
be9680c6145c factored out some common code (block-code and value-sending)
Claus Gittinger <cg@exept.de>
parents: 1425
diff changeset
  2474
    "/ 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
  2475
    aStream nextPut:#value.
be9680c6145c factored out some common code (block-code and value-sending)
Claus Gittinger <cg@exept.de>
parents: 1425
diff changeset
  2476
    (aCompiler hasLineNumber:#value) ifTrue:[
be9680c6145c factored out some common code (block-code and value-sending)
Claus Gittinger <cg@exept.de>
parents: 1425
diff changeset
  2477
        aStream nextPut:lineNr.
be9680c6145c factored out some common code (block-code and value-sending)
Claus Gittinger <cg@exept.de>
parents: 1425
diff changeset
  2478
    ]
be9680c6145c factored out some common code (block-code and value-sending)
Claus Gittinger <cg@exept.de>
parents: 1425
diff changeset
  2479
!
be9680c6145c factored out some common code (block-code and value-sending)
Claus Gittinger <cg@exept.de>
parents: 1425
diff changeset
  2480
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2481
codeWhileOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler
200
b2f77bd77070 inline code for [...] whileXXX
Claus Gittinger <cg@exept.de>
parents: 199
diff changeset
  2482
    "generate code for
817
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2483
        [...] whileXXX:[ ... ] 
200
b2f77bd77070 inline code for [...] whileXXX
Claus Gittinger <cg@exept.de>
parents: 199
diff changeset
  2484
     and also 
817
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2485
        [...] whileXXX
200
b2f77bd77070 inline code for [...] whileXXX
Claus Gittinger <cg@exept.de>
parents: 199
diff changeset
  2486
    "
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2487
200
b2f77bd77070 inline code for [...] whileXXX
Claus Gittinger <cg@exept.de>
parents: 199
diff changeset
  2488
    |pos pos2 theReceiver theArg theByteCode optByteCode needLineNr blockExpr
856
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2489
     hasLoopBlock fastReceiver condStats constCondition|
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2490
200
b2f77bd77070 inline code for [...] whileXXX
Claus Gittinger <cg@exept.de>
parents: 199
diff changeset
  2491
    hasLoopBlock := true.
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2492
    (selector == #whileTrue:) ifTrue:[
817
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2493
        theByteCode := #falseJump.
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2494
    ] ifFalse:[
817
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2495
        (selector == #whileFalse:) ifTrue:[
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2496
            theByteCode := #trueJump
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2497
        ] ifFalse:[
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2498
            hasLoopBlock := false.
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2499
            (selector == #whileTrue) ifTrue:[
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2500
                theByteCode := #trueJump
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2501
            ] ifFalse:[
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2502
                theByteCode := #falseJump
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2503
            ].
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2504
        ]
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2505
    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2506
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2507
    theReceiver := receiver.
370
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  2508
856
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2509
    (receiver isBlock
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2510
    and:[(condStats := receiver statements) notNil
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2511
    and:[condStats nextStatement isNil
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2512
    and:[condStats expression notNil]]])
370
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  2513
    ifTrue:[
817
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2514
        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
  2515
        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
  2516
    ] ifFalse:[
1463
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  2517
        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
  2518
    ].
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  2519
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2520
    optByteCode notNil ifTrue:[
817
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2521
        ((optByteCode == #eqJump) or:[optByteCode == #notEqJump]) ifTrue:[
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2522
            theArg := receiver statements expression arg1
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2523
        ].
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2524
        theReceiver := receiver statements expression receiver.
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2525
        theByteCode := optByteCode
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2526
    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2527
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2528
"/ OLD:
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2529
"/    valueNeeded ifTrue:[aStream nextPut:#pushNil].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2530
"/
167
d3dbd739c65a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 166
diff changeset
  2531
    needLineNr := true.
d3dbd739c65a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 166
diff changeset
  2532
1371
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2533
    pos := aStream position1Based.
386
2f66de89a89b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 371
diff changeset
  2534
389
8aa5f9f08139 care for lineNumber in while-loop
Claus Gittinger <cg@exept.de>
parents: 386
diff changeset
  2535
"/    aCompiler lineNumberInfo == #full ifTrue:[
817
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2536
        self codeLineNumber:lineNr on:aStream for:aCompiler.
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2537
        needLineNr := false.
389
8aa5f9f08139 care for lineNumber in while-loop
Claus Gittinger <cg@exept.de>
parents: 386
diff changeset
  2538
"/    ].
386
2f66de89a89b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 371
diff changeset
  2539
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2540
    optByteCode notNil ifTrue:[
817
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2541
        theReceiver codeOn:aStream inBlock:b for:aCompiler.
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2542
        theArg notNil ifTrue:[
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2543
            theArg codeOn:aStream inBlock:b for:aCompiler
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2544
        ]
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2545
    ] ifFalse:[
856
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2546
        (fastReceiver notNil 
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2547
        and:[fastReceiver isConstant]) ifTrue:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2548
            constCondition := fastReceiver evaluate.
817
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2549
            theByteCode == #trueJump ifTrue:[
856
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2550
                constCondition == true ifTrue:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2551
                    theByteCode := #jump
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2552
                ] ifFalse:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2553
                    constCondition == false ifTrue:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2554
                        theByteCode := #never
817
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2555
                    ]
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2556
                ]
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2557
            ] ifFalse:[
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2558
                theByteCode == #falseJump ifTrue:[
856
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2559
                    constCondition == false ifTrue:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2560
                        theByteCode := #jump
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2561
                    ] ifFalse:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2562
                        constCondition == true ifTrue:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2563
                            theByteCode := #never
817
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2564
                        ]
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2565
                    ]
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2566
                ]
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2567
            ]
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2568
        ].
167
d3dbd739c65a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 166
diff changeset
  2569
856
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2570
        (theByteCode ~~ #jump and:[theByteCode ~~ #never]) ifTrue:[
817
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2571
            theReceiver codeInlineOn:aStream inBlock:b for:aCompiler.
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2572
        ].
370
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  2573
817
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2574
        "/
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2575
        "/ cannot enable code below 
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2576
        "/ (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
  2577
        "/ think about it ...
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2578
        "/
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2579
        blockExpr := theReceiver simpleSendBlockExpression.
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2580
        blockExpr notNil ifTrue:[
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2581
            blockExpr isMessage ifTrue:[
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2582
                (aCompiler hasLineNumber:(blockExpr selector)) ifTrue:[
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2583
                    blockExpr lineNumber == lineNr ifTrue:[
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2584
                        needLineNr := false
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2585
                    ]
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2586
                ]
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2587
            ]
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2588
        ].
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2589
    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2590
167
d3dbd739c65a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 166
diff changeset
  2591
    needLineNr ifTrue:[
817
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2592
        ParseNode codeLineNumber:lineNr on:aStream for:aCompiler.
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2593
    ].
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2594
200
b2f77bd77070 inline code for [...] whileXXX
Claus Gittinger <cg@exept.de>
parents: 199
diff changeset
  2595
    hasLoopBlock ifFalse:[
817
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2596
        "/ simple [...] whileXXX
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2597
        theByteCode ~~ #never ifTrue:[
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2598
            aStream nextPut:theByteCode; nextPut:pos.
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2599
        ].
370
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  2600
817
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2601
        valueNeeded ifTrue:[aStream nextPut:#pushNil].
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2602
        ^ self
200
b2f77bd77070 inline code for [...] whileXXX
Claus Gittinger <cg@exept.de>
parents: 199
diff changeset
  2603
    ].
b2f77bd77070 inline code for [...] whileXXX
Claus Gittinger <cg@exept.de>
parents: 199
diff changeset
  2604
b2f77bd77070 inline code for [...] whileXXX
Claus Gittinger <cg@exept.de>
parents: 199
diff changeset
  2605
    "/ [...] whileXXX:[...]
b2f77bd77070 inline code for [...] whileXXX
Claus Gittinger <cg@exept.de>
parents: 199
diff changeset
  2606
370
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  2607
    theByteCode ~~ #never ifTrue:[
817
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2608
        aStream nextPut:theByteCode.
1371
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2609
        pos2 := aStream position1Based.
817
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2610
        aStream nextPut:0.
370
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  2611
    ].
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  2612
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2613
    (argArray at:1) codeInlineOn:aStream inBlock:b valueNeeded:false for:aCompiler.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2614
    aStream nextPut:#jump; nextPut:pos.
370
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  2615
    theByteCode ~~ #never ifTrue:[
1371
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2616
        (aStream contents) at:pos2 put:(aStream position1Based).
370
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  2617
    ].
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  2618
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2619
    valueNeeded ifTrue:[aStream nextPut:#pushNil].
167
d3dbd739c65a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 166
diff changeset
  2620
389
8aa5f9f08139 care for lineNumber in while-loop
Claus Gittinger <cg@exept.de>
parents: 386
diff changeset
  2621
    "Modified: 22.10.1996 / 21:34:37 / cg"
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2622
!
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2623
856
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2624
new_codeWhileOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2625
    "generate code for
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2626
        [...] whileXXX:[ ... ] 
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2627
     and also 
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2628
        [...] whileXXX
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2629
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2630
     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
  2631
     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
  2632
     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
  2633
     to detect loops and actually generates better machine code for the
910
eb4849c04fff comment
Claus Gittinger <cg@exept.de>
parents: 909
diff changeset
  2634
     old bytecode sequence ... (sigh)
856
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2635
    "
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2636
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2637
    |pos pos0 theReceiver theArg theByteCode optByteCode needLineNr blockExpr
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2638
     hasLoopBlock fastReceiver condStats constCondition|
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2639
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2640
    hasLoopBlock := true.
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2641
    (selector == #whileTrue:) ifTrue:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2642
        theByteCode := #trueJump.
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2643
    ] ifFalse:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2644
        (selector == #whileFalse:) ifTrue:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2645
            theByteCode := #falseJump
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2646
        ] ifFalse:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2647
            hasLoopBlock := false.
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2648
            (selector == #whileTrue) ifTrue:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2649
                theByteCode := #trueJump
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2650
            ] ifFalse:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2651
                theByteCode := #falseJump
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2652
            ].
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2653
        ]
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2654
    ].
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2655
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2656
    theReceiver := receiver.
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2657
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2658
    (receiver isBlock
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2659
    and:[(condStats := receiver statements) notNil
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2660
    and:[condStats nextStatement isNil
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2661
    and:[(fastReceiver := condStats expression) notNil]]])
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2662
    ifTrue:[
1463
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  2663
        optByteCode := self optimizedConditionFor:fastReceiver with:theByteCode for:aCompiler.
856
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2664
    ] ifFalse:[
1463
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  2665
        optByteCode := self optimizedConditionFor:theReceiver with:theByteCode for:aCompiler.
856
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2666
    ].
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2667
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2668
    optByteCode notNil ifTrue:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2669
        ((optByteCode == #eqJump) or:[optByteCode == #notEqJump]) ifTrue:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2670
            theArg := receiver statements expression arg1
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2671
        ].
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2672
        theReceiver := receiver statements expression receiver.
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2673
        theByteCode := optByteCode
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2674
    ].
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2675
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2676
    needLineNr := true.
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2677
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2678
    hasLoopBlock ifTrue:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2679
        (argArray at:1) isEmptyBlock ifFalse:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2680
            aStream nextPut:#jump.
1371
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2681
            pos0 := aStream position1Based.
856
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2682
            aStream nextPut:0.
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2683
1371
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2684
            pos := aStream position1Based.
856
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2685
            (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
  2686
1371
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2687
            (aStream contents) at:pos0 put:(aStream position1Based).
856
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2688
        ]
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2689
    ] ifFalse:[
1371
de4c37ac12fc code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents: 1281
diff changeset
  2690
        pos := aStream position1Based.
856
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2691
    ].
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2692
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2693
    optByteCode isNil ifTrue:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2694
        blockExpr := theReceiver simpleSendBlockExpression.
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2695
        blockExpr notNil ifTrue:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2696
            blockExpr isMessage ifTrue:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2697
                (aCompiler hasLineNumber:(blockExpr selector)) ifTrue:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2698
                    blockExpr lineNumber == lineNr ifTrue:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2699
                        needLineNr := false
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2700
                    ]
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2701
                ]
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2702
            ]
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2703
        ].
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2704
    ].
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2705
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2706
    needLineNr ifTrue:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2707
        self codeLineNumber:lineNr on:aStream for:aCompiler.
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2708
    ].
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2709
    needLineNr := false.
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2710
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2711
    optByteCode notNil ifTrue:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2712
        theReceiver codeOn:aStream inBlock:b for:aCompiler.
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2713
        theArg notNil ifTrue:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2714
            theArg codeOn:aStream inBlock:b for:aCompiler
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2715
        ]
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2716
    ] ifFalse:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2717
        (fastReceiver notNil 
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2718
        and:[fastReceiver isConstant]) ifTrue:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2719
            constCondition := fastReceiver evaluate.
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2720
            theByteCode == #trueJump ifTrue:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2721
                constCondition == true ifTrue:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2722
                    theByteCode := #jump
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2723
                ] ifFalse:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2724
                    constCondition == false ifTrue:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2725
                        theByteCode := #never
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2726
                    ]
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2727
                ]
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2728
            ] ifFalse:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2729
                theByteCode == #falseJump ifTrue:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2730
                    constCondition == false ifTrue:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2731
                        theByteCode := #jump
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2732
                    ] ifFalse:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2733
                        constCondition == true ifTrue:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2734
                            theByteCode := #never
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2735
                        ]
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2736
                    ]
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2737
                ]
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2738
            ]
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2739
        ].
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2740
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2741
        (theByteCode ~~ #jump and:[theByteCode ~~ #never]) ifTrue:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2742
            theReceiver codeInlineOn:aStream inBlock:b for:aCompiler.
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2743
        ].
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2744
    ].
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2745
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2746
    hasLoopBlock ifFalse:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2747
        "/ simple [...] whileXXX
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2748
        theByteCode ~~ #never ifTrue:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2749
            aStream nextPut:theByteCode; nextPut:pos.
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2750
        ].
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2751
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2752
        valueNeeded ifTrue:[aStream nextPut:#pushNil].
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2753
        ^ self
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2754
    ].
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2755
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2756
    "/ [...] whileXXX:[...]
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2757
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2758
    theByteCode ~~ #never ifTrue:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2759
        aStream nextPut:theByteCode.
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2760
        aStream nextPut:pos.
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2761
    ].
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2762
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2763
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2764
    valueNeeded ifTrue:[aStream nextPut:#pushNil].
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2765
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2766
    "Modified: 22.10.1996 / 21:34:37 / cg"
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2767
!
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2768
1463
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  2769
optimizedConditionFor:aReceiver with:aByteCode for:aCompiler
186
05a99f1bd747 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 167
diff changeset
  2770
    |rec sel stats|
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2771
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2772
    rec := aReceiver.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2773
    (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
  2774
        (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
  2775
            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
  2776
                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
  2777
            ]
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  2778
        ]
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2779
    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2780
    (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
  2781
        sel := rec selector.
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  2782
        (sel == #isNil) ifTrue:[
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  2783
            "/
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  2784
            "/ isNil trueJmp  -> nilJump
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  2785
            "/ isNil falseJmp -> notNilJump
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  2786
            "/
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  2787
            aCompiler addLiteral:#isNil.
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  2788
            (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
  2789
            (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
  2790
        ].
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  2791
        (sel == #notNil) ifTrue:[
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  2792
            "/
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  2793
            "/ notNil trueJmp  -> notNilJump
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  2794
            "/ notNil falseJmp -> nilJump
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  2795
            "/
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  2796
            aCompiler addLiteral:#notNil.
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  2797
            (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
  2798
            (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
  2799
        ].
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  2800
        (sel == #not) ifTrue:[
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  2801
            "/
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  2802
            "/ not trueJmp  -> falseJump
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  2803
            "/ not falseJmp -> trueJump
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  2804
            "/
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  2805
            aCompiler addLiteral:#not.
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  2806
            (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
  2807
            (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
  2808
        ].
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  2809
        ^ nil
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2810
    ].
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2811
    (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
  2812
        sel := rec selector.
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  2813
        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
  2814
            (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
  2815
                "/
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  2816
                "/ ==0 trueJmp  -> zeroJump
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  2817
                "/ ==0 falseJmp -> notZeroJump
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  2818
                "/
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  2819
                (sel == #==) ifTrue:[
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  2820
                    aCompiler addLiteral:#==.
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  2821
                    (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
  2822
                    (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
  2823
                ].
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  2824
                "/
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  2825
                "/ ~~0 trueJmp  -> notZeroJump
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  2826
                "/ ~~0 falseJmp -> zeroJump
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  2827
                "/
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  2828
                (sel == #~~) ifTrue:[
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  2829
                    aCompiler addLiteral:#~~.
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  2830
                    (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
  2831
                    (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
  2832
                ].
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  2833
                ^ nil
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  2834
            ]
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  2835
        ].
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  2836
        (sel == #==) ifTrue:[
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  2837
            "/
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  2838
            "/ == trueJmp  -> eqJump
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  2839
            "/ == falseJmp -> notEqJump
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  2840
            "/
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  2841
            aCompiler addLiteral:#==.
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  2842
            (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
  2843
            (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
  2844
        ].
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  2845
        (sel == #~~) ifTrue:[
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  2846
            "/
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  2847
            "/ ~~ trueJmp  -> notEqJump
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  2848
            "/ ~~ falseJmp -> eqJump
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  2849
            "/
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  2850
            aCompiler addLiteral:#~~.
14c0b5d19e13 make sure, all literals are present in the methods literal-table.
Claus Gittinger <cg@exept.de>
parents: 1435
diff changeset
  2851
            (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
  2852
            (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
  2853
        ]
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2854
    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2855
    ^ nil
992
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  2856
!
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  2857
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  2858
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
  2859
    |rVal branch|
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  2860
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  2861
    receiver isConstant ifTrue:[
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  2862
        rVal := receiver evaluate.
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  2863
        rVal == true ifTrue:[
1248
ba526cbb348a fixed optimization of: <true|false> ifTrue/false: non-block
Claus Gittinger <cg@exept.de>
parents: 1197
diff changeset
  2864
            (selector == #ifFalse:) ifTrue:[
1422
cdee45eb0303 oops - wrong code was generatedd for inlined
Claus Gittinger <cg@exept.de>
parents: 1397
diff changeset
  2865
                valueNeeded ifTrue:[
cdee45eb0303 oops - wrong code was generatedd for inlined
Claus Gittinger <cg@exept.de>
parents: 1397
diff changeset
  2866
                    "/ true ifFalse:[] - evaluates to nil.
cdee45eb0303 oops - wrong code was generatedd for inlined
Claus Gittinger <cg@exept.de>
parents: 1397
diff changeset
  2867
                    aStream nextPut:#pushNil
cdee45eb0303 oops - wrong code was generatedd for inlined
Claus Gittinger <cg@exept.de>
parents: 1397
diff changeset
  2868
                ].
1248
ba526cbb348a fixed optimization of: <true|false> ifTrue/false: non-block
Claus Gittinger <cg@exept.de>
parents: 1197
diff changeset
  2869
                ^ true.
ba526cbb348a fixed optimization of: <true|false> ifTrue/false: non-block
Claus Gittinger <cg@exept.de>
parents: 1197
diff changeset
  2870
            ].
992
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  2871
            ((selector == #ifTrue:) or:[selector == #ifTrue:ifFalse:]) ifTrue:[
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  2872
                branch := (argArray at: 1).
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  2873
            ].
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  2874
            (selector == #ifFalse:ifTrue:) ifTrue:[
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  2875
                branch := (argArray at: 2).
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  2876
            ].
1248
ba526cbb348a fixed optimization of: <true|false> ifTrue/false: non-block
Claus Gittinger <cg@exept.de>
parents: 1197
diff changeset
  2877
        ].
ba526cbb348a fixed optimization of: <true|false> ifTrue/false: non-block
Claus Gittinger <cg@exept.de>
parents: 1197
diff changeset
  2878
        rVal == false ifTrue:[
ba526cbb348a fixed optimization of: <true|false> ifTrue/false: non-block
Claus Gittinger <cg@exept.de>
parents: 1197
diff changeset
  2879
            (selector == #ifTrue:) ifTrue:[
1422
cdee45eb0303 oops - wrong code was generatedd for inlined
Claus Gittinger <cg@exept.de>
parents: 1397
diff changeset
  2880
                valueNeeded ifTrue:[
cdee45eb0303 oops - wrong code was generatedd for inlined
Claus Gittinger <cg@exept.de>
parents: 1397
diff changeset
  2881
                    "/ false ifTrue:[] - evaluates to nil.
cdee45eb0303 oops - wrong code was generatedd for inlined
Claus Gittinger <cg@exept.de>
parents: 1397
diff changeset
  2882
                    aStream nextPut:#pushNil
cdee45eb0303 oops - wrong code was generatedd for inlined
Claus Gittinger <cg@exept.de>
parents: 1397
diff changeset
  2883
                ].
992
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  2884
                ^ true.
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  2885
            ].
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  2886
            ((selector == #ifFalse:) or:[selector == #ifFalse:ifTrue:]) ifTrue:[
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  2887
                branch := (argArray at: 1).
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  2888
            ].
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  2889
            (selector == #ifTrue:ifFalse:) ifTrue:[
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  2890
                branch := (argArray at: 2).
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  2891
            ].
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  2892
        ].
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  2893
        branch notNil ifTrue:[
1435
be9680c6145c factored out some common code (block-code and value-sending)
Claus Gittinger <cg@exept.de>
parents: 1425
diff changeset
  2894
            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
  2895
            ^ true.
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  2896
        ]
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  2897
    ].
7e8ef3583a43 do not emit conditionalBranch, if receiver of
Claus Gittinger <cg@exept.de>
parents: 910
diff changeset
  2898
    ^ false
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2899
! !
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2900
1080
bd3f19f6009a category change
Claus Gittinger <cg@exept.de>
parents: 1059
diff changeset
  2901
!MessageNode methodsFor:'printing & storing'!
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2902
1588
4c3183dfaa5f printing
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  2903
printOn:aStream indent:i 
4c3183dfaa5f printing
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  2904
    |selectorParts|
4c3183dfaa5f printing
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  2905
4c3183dfaa5f printing
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  2906
    (#( whileTrue: whileFalse: ) includes:selector) ifTrue:[
888
5858090fc8c3 changed #printOn: to indent
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
  2907
        receiver isBlock ifTrue:[
5858090fc8c3 changed #printOn: to indent
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
  2908
            ^ self printWhileOn:aStream indent:i
5858090fc8c3 changed #printOn: to indent
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
  2909
        ].
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2910
    ].
2521
daf48e62f93d changed: #printOn:indent:
Claus Gittinger <cg@exept.de>
parents: 2496
diff changeset
  2911
    selectorParts := selector asSymbol keywords.
1588
4c3183dfaa5f printing
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  2912
    receiver printOn:aStream indent:i parenthized:(receiver precedence <= self precedence).
1791
cd786d318d6f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1727
diff changeset
  2913
    argArray notNil ifTrue:[
cd786d318d6f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1727
diff changeset
  2914
        argArray with:selectorParts
cd786d318d6f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1727
diff changeset
  2915
            do:[:arg :selPart | 
cd786d318d6f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1727
diff changeset
  2916
                aStream
cd786d318d6f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1727
diff changeset
  2917
                    cr;
cd786d318d6f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1727
diff changeset
  2918
                    spaces:i + 4;
2542
251e766c3530 changed: #printOn:indent:
Claus Gittinger <cg@exept.de>
parents: 2521
diff changeset
  2919
                    nextPutAll:selPart.
251e766c3530 changed: #printOn:indent:
Claus Gittinger <cg@exept.de>
parents: 2521
diff changeset
  2920
                arg printOn:aStream 
251e766c3530 changed: #printOn:indent:
Claus Gittinger <cg@exept.de>
parents: 2521
diff changeset
  2921
                    indent:i + 4 
251e766c3530 changed: #printOn:indent:
Claus Gittinger <cg@exept.de>
parents: 2521
diff changeset
  2922
                    parenthized:(arg precedence <= self precedence).
1791
cd786d318d6f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1727
diff changeset
  2923
            ]
cd786d318d6f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1727
diff changeset
  2924
    ].
cd786d318d6f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1727
diff changeset
  2925
2542
251e766c3530 changed: #printOn:indent:
Claus Gittinger <cg@exept.de>
parents: 2521
diff changeset
  2926
    "Modified: / 06-07-2011 / 09:44:55 / cg"
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2927
!
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2928
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2929
printWhileOn:aStream indent:i
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2930
    "special handling of whileTrue/whileFalse"
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2931
1588
4c3183dfaa5f printing
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  2932
    |arg|
4c3183dfaa5f printing
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  2933
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2934
    aStream nextPutAll:'['.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2935
    receiver statements printOn:aStream indent:i.
1588
4c3183dfaa5f printing
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  2936
    aStream nextPutAll:'] ',selector,' '.
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2937
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2938
    arg := argArray at:1.
1588
4c3183dfaa5f printing
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  2939
    arg printOn:aStream indent:i parenthized:(arg precedence <= self precedence).
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2940
! !
106
claus
parents: 104
diff changeset
  2941
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2942
!MessageNode methodsFor:'queries'!
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2943
1565
9388e72e2dff Define #argumentCount as ANSI alias for #numArgs
Stefan Vogel <sv@exept.de>
parents: 1533
diff changeset
  2944
argumentCount
9388e72e2dff Define #argumentCount as ANSI alias for #numArgs
Stefan Vogel <sv@exept.de>
parents: 1533
diff changeset
  2945
    "VisualAge/ANSI compatibility - same as numArgs"
9388e72e2dff Define #argumentCount as ANSI alias for #numArgs
Stefan Vogel <sv@exept.de>
parents: 1533
diff changeset
  2946
9388e72e2dff Define #argumentCount as ANSI alias for #numArgs
Stefan Vogel <sv@exept.de>
parents: 1533
diff changeset
  2947
    ^ argArray size
9388e72e2dff Define #argumentCount as ANSI alias for #numArgs
Stefan Vogel <sv@exept.de>
parents: 1533
diff changeset
  2948
!
9388e72e2dff Define #argumentCount as ANSI alias for #numArgs
Stefan Vogel <sv@exept.de>
parents: 1533
diff changeset
  2949
395
16156d8711c2 added block collector
Claus Gittinger <cg@exept.de>
parents: 389
diff changeset
  2950
collectBlocksInto:aCollection
16156d8711c2 added block collector
Claus Gittinger <cg@exept.de>
parents: 389
diff changeset
  2951
    receiver collectBlocksInto:aCollection.
16156d8711c2 added block collector
Claus Gittinger <cg@exept.de>
parents: 389
diff changeset
  2952
    argArray size > 0 ifTrue:[
1727
58820b0c1e7a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1724
diff changeset
  2953
        argArray do:[:arg |
58820b0c1e7a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1724
diff changeset
  2954
            arg collectBlocksInto:aCollection.
58820b0c1e7a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1724
diff changeset
  2955
        ]
395
16156d8711c2 added block collector
Claus Gittinger <cg@exept.de>
parents: 389
diff changeset
  2956
    ].
16156d8711c2 added block collector
Claus Gittinger <cg@exept.de>
parents: 389
diff changeset
  2957
16156d8711c2 added block collector
Claus Gittinger <cg@exept.de>
parents: 389
diff changeset
  2958
    "Created: 23.10.1996 / 15:44:49 / cg"
16156d8711c2 added block collector
Claus Gittinger <cg@exept.de>
parents: 389
diff changeset
  2959
    "Modified: 23.10.1996 / 16:03:46 / cg"
16156d8711c2 added block collector
Claus Gittinger <cg@exept.de>
parents: 389
diff changeset
  2960
!
16156d8711c2 added block collector
Claus Gittinger <cg@exept.de>
parents: 389
diff changeset
  2961
2384
3854f86e767a added: #containsReturn
Claus Gittinger <cg@exept.de>
parents: 2345
diff changeset
  2962
containsReturn
3854f86e767a added: #containsReturn
Claus Gittinger <cg@exept.de>
parents: 2345
diff changeset
  2963
    receiver containsReturn ifTrue:[^ true].
3854f86e767a added: #containsReturn
Claus Gittinger <cg@exept.de>
parents: 2345
diff changeset
  2964
    ^ self arguments contains:[:arg | arg containsReturn]
3854f86e767a added: #containsReturn
Claus Gittinger <cg@exept.de>
parents: 2345
diff changeset
  2965
!
3854f86e767a added: #containsReturn
Claus Gittinger <cg@exept.de>
parents: 2345
diff changeset
  2966
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2967
isCascade
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2968
    ^ false
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2969
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2970
    "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
  2971
!
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2972
1384
0db9682870d9 evaluate -> evaluateIn:
Claus Gittinger <cg@exept.de>
parents: 1382
diff changeset
  2973
numArgs
0db9682870d9 evaluate -> evaluateIn:
Claus Gittinger <cg@exept.de>
parents: 1382
diff changeset
  2974
    ^ argArray size
0db9682870d9 evaluate -> evaluateIn:
Claus Gittinger <cg@exept.de>
parents: 1382
diff changeset
  2975
!
0db9682870d9 evaluate -> evaluateIn:
Claus Gittinger <cg@exept.de>
parents: 1382
diff changeset
  2976
1588
4c3183dfaa5f printing
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  2977
precedence
4c3183dfaa5f printing
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  2978
    ^ 10
4c3183dfaa5f printing
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  2979
4c3183dfaa5f printing
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  2980
    "Created: / 20-04-2005 / 14:10:59 / cg"
4c3183dfaa5f printing
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  2981
!
4c3183dfaa5f printing
Claus Gittinger <cg@exept.de>
parents: 1587
diff changeset
  2982
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2983
realReceiver
746
429cfc59b440 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 744
diff changeset
  2984
    receiver isCascade ifTrue:[
429cfc59b440 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 744
diff changeset
  2985
        ^ receiver realReceiver
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2986
    ].
746
429cfc59b440 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 744
diff changeset
  2987
    self isCascade ifTrue:[
429cfc59b440 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 744
diff changeset
  2988
        ^ receiver receiver
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2989
    ].
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2990
746
429cfc59b440 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 744
diff changeset
  2991
    ^ receiver
429cfc59b440 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 744
diff changeset
  2992
429cfc59b440 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 744
diff changeset
  2993
    "Modified: / 17.7.1998 / 02:09:05 / cg"
2268
Claus Gittinger <cg@exept.de>
parents: 2208
diff changeset
  2994
!
Claus Gittinger <cg@exept.de>
parents: 2208
diff changeset
  2995
Claus Gittinger <cg@exept.de>
parents: 2208
diff changeset
  2996
withConstantValueDo:aBlock
Claus Gittinger <cg@exept.de>
parents: 2208
diff changeset
  2997
    "return true, if this evaluates to a constant value
Claus Gittinger <cg@exept.de>
parents: 2208
diff changeset
  2998
     and evaluate aBlock with it"
Claus Gittinger <cg@exept.de>
parents: 2208
diff changeset
  2999
Claus Gittinger <cg@exept.de>
parents: 2208
diff changeset
  3000
    |recVal argValues allArgsConstant|
Claus Gittinger <cg@exept.de>
parents: 2208
diff changeset
  3001
2273
d952d08cf43c changed: #withConstantValueDo:
Claus Gittinger <cg@exept.de>
parents: 2270
diff changeset
  3002
    (receiver isGlobal and:[receiver name = 'Smalltalk']) ifTrue:[
d952d08cf43c changed: #withConstantValueDo:
Claus Gittinger <cg@exept.de>
parents: 2270
diff changeset
  3003
        (selector == #isSmalltalkX) ifTrue:[
d952d08cf43c changed: #withConstantValueDo:
Claus Gittinger <cg@exept.de>
parents: 2270
diff changeset
  3004
            "/ true here !!
d952d08cf43c changed: #withConstantValueDo:
Claus Gittinger <cg@exept.de>
parents: 2270
diff changeset
  3005
            aBlock value:true.
d952d08cf43c changed: #withConstantValueDo:
Claus Gittinger <cg@exept.de>
parents: 2270
diff changeset
  3006
            ^ true
d952d08cf43c changed: #withConstantValueDo:
Claus Gittinger <cg@exept.de>
parents: 2270
diff changeset
  3007
        ].
d952d08cf43c changed: #withConstantValueDo:
Claus Gittinger <cg@exept.de>
parents: 2270
diff changeset
  3008
    ].
d952d08cf43c changed: #withConstantValueDo:
Claus Gittinger <cg@exept.de>
parents: 2270
diff changeset
  3009
2268
Claus Gittinger <cg@exept.de>
parents: 2208
diff changeset
  3010
    (receiver withConstantValueDo:[:val | recVal := val]) ifTrue:[
Claus Gittinger <cg@exept.de>
parents: 2208
diff changeset
  3011
        argValues := Array new:argArray size.
Claus Gittinger <cg@exept.de>
parents: 2208
diff changeset
  3012
        allArgsConstant := true.
2270
Claus Gittinger <cg@exept.de>
parents: 2268
diff changeset
  3013
        argArray notNil ifTrue:[
Claus Gittinger <cg@exept.de>
parents: 2268
diff changeset
  3014
            argArray doWithIndex:[:arg :index |
Claus Gittinger <cg@exept.de>
parents: 2268
diff changeset
  3015
                allArgsConstant := allArgsConstant
2268
Claus Gittinger <cg@exept.de>
parents: 2208
diff changeset
  3016
                                and:[ arg withConstantValueDo:[:val | argValues at:index put:val] ]
2270
Claus Gittinger <cg@exept.de>
parents: 2268
diff changeset
  3017
            ].
2268
Claus Gittinger <cg@exept.de>
parents: 2208
diff changeset
  3018
        ].
Claus Gittinger <cg@exept.de>
parents: 2208
diff changeset
  3019
        allArgsConstant ifTrue:[
Claus Gittinger <cg@exept.de>
parents: 2208
diff changeset
  3020
            "/ only a few messages are checked:
Claus Gittinger <cg@exept.de>
parents: 2208
diff changeset
  3021
            recVal isNumber ifTrue:[
Claus Gittinger <cg@exept.de>
parents: 2208
diff changeset
  3022
                (#(positive negative abs negated + - * == = ~= ~~) includes:selector) ifFalse:[
Claus Gittinger <cg@exept.de>
parents: 2208
diff changeset
  3023
                    ^ false
Claus Gittinger <cg@exept.de>
parents: 2208
diff changeset
  3024
                ].
2331
471a6febf163 changed: #withConstantValueDo:
Claus Gittinger <cg@exept.de>
parents: 2329
diff changeset
  3025
            ] ifFalse:[
471a6febf163 changed: #withConstantValueDo:
Claus Gittinger <cg@exept.de>
parents: 2329
diff changeset
  3026
                recVal isBoolean ifTrue:[
471a6febf163 changed: #withConstantValueDo:
Claus Gittinger <cg@exept.de>
parents: 2329
diff changeset
  3027
                    (#(not && || ) includes:selector) ifFalse:[
471a6febf163 changed: #withConstantValueDo:
Claus Gittinger <cg@exept.de>
parents: 2329
diff changeset
  3028
                        ^ false
471a6febf163 changed: #withConstantValueDo:
Claus Gittinger <cg@exept.de>
parents: 2329
diff changeset
  3029
                    ].
471a6febf163 changed: #withConstantValueDo:
Claus Gittinger <cg@exept.de>
parents: 2329
diff changeset
  3030
                ] ifFalse:[
471a6febf163 changed: #withConstantValueDo:
Claus Gittinger <cg@exept.de>
parents: 2329
diff changeset
  3031
                    recVal isString ifTrue:[
471a6febf163 changed: #withConstantValueDo:
Claus Gittinger <cg@exept.de>
parents: 2329
diff changeset
  3032
                        (#(size) includes:selector) ifFalse:[
471a6febf163 changed: #withConstantValueDo:
Claus Gittinger <cg@exept.de>
parents: 2329
diff changeset
  3033
                            ^ false
471a6febf163 changed: #withConstantValueDo:
Claus Gittinger <cg@exept.de>
parents: 2329
diff changeset
  3034
                        ].
471a6febf163 changed: #withConstantValueDo:
Claus Gittinger <cg@exept.de>
parents: 2329
diff changeset
  3035
                    ].
471a6febf163 changed: #withConstantValueDo:
Claus Gittinger <cg@exept.de>
parents: 2329
diff changeset
  3036
                ]
2268
Claus Gittinger <cg@exept.de>
parents: 2208
diff changeset
  3037
            ].
Claus Gittinger <cg@exept.de>
parents: 2208
diff changeset
  3038
            aBlock value:(recVal perform:selector withArguments:argValues).
Claus Gittinger <cg@exept.de>
parents: 2208
diff changeset
  3039
            ^ true
Claus Gittinger <cg@exept.de>
parents: 2208
diff changeset
  3040
        ].
Claus Gittinger <cg@exept.de>
parents: 2208
diff changeset
  3041
    ].
Claus Gittinger <cg@exept.de>
parents: 2208
diff changeset
  3042
    ^ false
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  3043
! !
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  3044
2321
3eb00a4f2c8a category change
Claus Gittinger <cg@exept.de>
parents: 2273
diff changeset
  3045
!MessageNode methodsFor:'testing'!
3eb00a4f2c8a category change
Claus Gittinger <cg@exept.de>
parents: 2273
diff changeset
  3046
3eb00a4f2c8a category change
Claus Gittinger <cg@exept.de>
parents: 2273
diff changeset
  3047
isMessage
3eb00a4f2c8a category change
Claus Gittinger <cg@exept.de>
parents: 2273
diff changeset
  3048
    ^ true
3eb00a4f2c8a category change
Claus Gittinger <cg@exept.de>
parents: 2273
diff changeset
  3049
! !
3eb00a4f2c8a category change
Claus Gittinger <cg@exept.de>
parents: 2273
diff changeset
  3050
2601
0bee48798eac - added acceptVisior:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2562
diff changeset
  3051
!MessageNode methodsFor:'visiting'!
0bee48798eac - added acceptVisior:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2562
diff changeset
  3052
0bee48798eac - added acceptVisior:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2562
diff changeset
  3053
acceptVisitor:aVisitor 
0bee48798eac - added acceptVisior:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2562
diff changeset
  3054
    "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
  3055
     the selector (visitor pattern)"
0bee48798eac - added acceptVisior:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2562
diff changeset
  3056
0bee48798eac - added acceptVisior:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2562
diff changeset
  3057
    "stub code automatically generated - please change if required"
0bee48798eac - added acceptVisior:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2562
diff changeset
  3058
0bee48798eac - added acceptVisior:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2562
diff changeset
  3059
    ^ aVisitor visitMessageNode:self
0bee48798eac - added acceptVisior:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2562
diff changeset
  3060
! !
0bee48798eac - added acceptVisior:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2562
diff changeset
  3061
370
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  3062
!MessageNode class methodsFor:'documentation'!
148
ef0e604209ec version method at the end
Claus Gittinger <cg@exept.de>
parents: 140
diff changeset
  3063
2496
4d67e1d9423b Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2489
diff changeset
  3064
version_CVS
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
  3065
    ^ '$Header: /cvs/stx/stx/libcomp/MessageNode.st,v 1.184 2011-07-27 15:00:21 vrany Exp $'
2268
Claus Gittinger <cg@exept.de>
parents: 2208
diff changeset
  3066
!
Claus Gittinger <cg@exept.de>
parents: 2208
diff changeset
  3067
2496
4d67e1d9423b Jan's changes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2489
diff changeset
  3068
version_SVN
2521
daf48e62f93d changed: #printOn:indent:
Claus Gittinger <cg@exept.de>
parents: 2496
diff changeset
  3069
    ^ '§ Id §'
148
ef0e604209ec version method at the end
Claus Gittinger <cg@exept.de>
parents: 140
diff changeset
  3070
! !