MessageNode.st
author Claus Gittinger <cg@exept.de>
Fri, 27 Jun 1997 18:33:17 +0200
changeset 567 a6e4c44ff326
parent 565 00673e9d6edc
child 570 e55ab798d077
permissions -rw-r--r--
checkin from browser
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
     1
"
4
f6fd83437415 *** empty log message ***
claus
parents: 3
diff changeset
     2
 COPYRIGHT (c) 1989 by Claus Gittinger
47
f861ad42703e *** empty log message ***
claus
parents: 39
diff changeset
     3
	      All Rights Reserved
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
     4
7ad01559b262 Initial revision
claus
parents:
diff changeset
     5
 This software is furnished under a license and may be used
7ad01559b262 Initial revision
claus
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
7ad01559b262 Initial revision
claus
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
7ad01559b262 Initial revision
claus
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
7ad01559b262 Initial revision
claus
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
7ad01559b262 Initial revision
claus
parents:
diff changeset
    10
 hereby transferred.
7ad01559b262 Initial revision
claus
parents:
diff changeset
    11
"
7ad01559b262 Initial revision
claus
parents:
diff changeset
    12
7ad01559b262 Initial revision
claus
parents:
diff changeset
    13
ParseNode subclass:#MessageNode
166
9f6c57a3bce1 no line number bytecode in if-else if not needed
Claus Gittinger <cg@exept.de>
parents: 163
diff changeset
    14
	instanceVariableNames:'receiver selector argArray lineNr'
9f6c57a3bce1 no line number bytecode in if-else if not needed
Claus Gittinger <cg@exept.de>
parents: 163
diff changeset
    15
	classVariableNames:''
9f6c57a3bce1 no line number bytecode in if-else if not needed
Claus Gittinger <cg@exept.de>
parents: 163
diff changeset
    16
	poolDictionaries:''
9f6c57a3bce1 no line number bytecode in if-else if not needed
Claus Gittinger <cg@exept.de>
parents: 163
diff changeset
    17
	category:'System-Compiler-Support'
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
    18
!
7ad01559b262 Initial revision
claus
parents:
diff changeset
    19
370
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
    20
!MessageNode class methodsFor:'documentation'!
20
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
    21
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
    22
copyright
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
    23
"
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
    24
 COPYRIGHT (c) 1989 by Claus Gittinger
47
f861ad42703e *** empty log message ***
claus
parents: 39
diff changeset
    25
	      All Rights Reserved
20
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
    26
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
    27
 This software is furnished under a license and may be used
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
    28
 only in accordance with the terms of that license and with the
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
    29
 inclusion of the above copyright notice.   This software may not
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
    30
 be provided or otherwise made available to, or used by, any
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
    31
 other person.  No title to or ownership of the software is
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
    32
 hereby transferred.
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
    33
"
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
    34
!
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
    35
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
    36
documentation
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
    37
"
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
    38
    node for parse-trees, representing message sends
261
0372e948ca2d commentary
Claus Gittinger <cg@exept.de>
parents: 253
diff changeset
    39
    This is a helper class for the compiler.
263
3b21d0991eff documentation
Claus Gittinger <cg@exept.de>
parents: 261
diff changeset
    40
3b21d0991eff documentation
Claus Gittinger <cg@exept.de>
parents: 261
diff changeset
    41
    [author:]
3b21d0991eff documentation
Claus Gittinger <cg@exept.de>
parents: 261
diff changeset
    42
        Claus Gittinger
20
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
    43
"
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
    44
! !
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
    45
370
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
    46
!MessageNode class methodsFor:'instance creation'!
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
    47
7ad01559b262 Initial revision
claus
parents:
diff changeset
    48
receiver:recNode selector:selectorString 
7ad01559b262 Initial revision
claus
parents:
diff changeset
    49
    ^ (self basicNew) receiver:recNode selector:selectorString args:nil lineno:0
7ad01559b262 Initial revision
claus
parents:
diff changeset
    50
!
7ad01559b262 Initial revision
claus
parents:
diff changeset
    51
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
    52
receiver:recNode selector:selectorString arg1:argNode1 arg2:argNode2 fold:folding
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
    53
    |result recVal argVal selector|
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
    54
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
    55
    "
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
    56
     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
    57
     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
    58
     enhancing the compiler ....
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
    59
     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
    60
     allowing constant arrays of complex objects.
140
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
     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
    63
    "
212
ff39051e219f more constant folding options
Claus Gittinger <cg@exept.de>
parents: 204
diff changeset
    64
    folding notNil ifTrue:[
ff39051e219f more constant folding options
Claus Gittinger <cg@exept.de>
parents: 204
diff changeset
    65
	"/
ff39051e219f more constant folding options
Claus Gittinger <cg@exept.de>
parents: 204
diff changeset
    66
	"/ do constant folding ...
ff39051e219f more constant folding options
Claus Gittinger <cg@exept.de>
parents: 204
diff changeset
    67
	"/
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
    68
	(recNode isConstant and:[argNode1 isConstant]) ifTrue:[
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
    69
	    "check if we can do it ..."
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
    70
	    selector := selectorString asSymbolIfInterned.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
    71
	    selector notNil ifTrue:[
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
    72
		recVal := recNode evaluate.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
    73
		(recVal respondsTo:selector) ifTrue:[
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
    74
		    "
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
    75
		     we could do much more here - but then, we need a dependency from
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
    76
		     the folded selectors method to the method we generate code for ...
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
    77
		     limit optimizations to those that will never change
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
    78
		     (or - if you change them - you will crash so bad ...)
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
    79
		    "
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
    80
		    argVal := argNode1 evaluate.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
    81
		    ((recVal isMemberOf:Array) and:[argVal isMemberOf:Array]) ifTrue:[
212
ff39051e219f more constant folding options
Claus Gittinger <cg@exept.de>
parents: 204
diff changeset
    82
			folding == #full ifTrue:[
ff39051e219f more constant folding options
Claus Gittinger <cg@exept.de>
parents: 204
diff changeset
    83
			    (selector == #with:collect:) ifTrue:[
ff39051e219f more constant folding options
Claus Gittinger <cg@exept.de>
parents: 204
diff changeset
    84
			        (argNode2 isMemberOf:BlockNode) ifTrue:[
ff39051e219f more constant folding options
Claus Gittinger <cg@exept.de>
parents: 204
diff changeset
    85
				    SignalSet anySignal handle:[:ex |
ff39051e219f more constant folding options
Claus Gittinger <cg@exept.de>
parents: 204
diff changeset
    86
				        ^ 'error in constant expression (' , ex errorString , ')'
ff39051e219f more constant folding options
Claus Gittinger <cg@exept.de>
parents: 204
diff changeset
    87
				    ] do:[
ff39051e219f more constant folding options
Claus Gittinger <cg@exept.de>
parents: 204
diff changeset
    88
				        result := recVal perform:selector with:argVal with:(argNode2 evaluate).
ff39051e219f more constant folding options
Claus Gittinger <cg@exept.de>
parents: 204
diff changeset
    89
				    ].
ff39051e219f more constant folding options
Claus Gittinger <cg@exept.de>
parents: 204
diff changeset
    90
				    ^ ConstantNode type:(ConstantNode typeOfConstant:result) value:result
ff39051e219f more constant folding options
Claus Gittinger <cg@exept.de>
parents: 204
diff changeset
    91
				]
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
    92
			    ]
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
    93
			]
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
    94
		    ]
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
    95
		]
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
    96
	    ]
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
    97
	]
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
    98
    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
    99
    ^ (self basicNew) receiver:recNode selector:selectorString args:(Array with:argNode1 with:argNode2) lineno:0
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   100
!
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   101
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   102
receiver:recNode selector:selectorString arg:argNode
212
ff39051e219f more constant folding options
Claus Gittinger <cg@exept.de>
parents: 204
diff changeset
   103
    ^ self receiver:recNode selector:selectorString arg:argNode fold:nil
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   104
!
7ad01559b262 Initial revision
claus
parents:
diff changeset
   105
7ad01559b262 Initial revision
claus
parents:
diff changeset
   106
receiver:recNode selector:selectorString arg:argNode fold:folding
212
ff39051e219f more constant folding options
Claus Gittinger <cg@exept.de>
parents: 204
diff changeset
   107
    |result recVal argVal selector globalName canFold|
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   108
20
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
   109
   "
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
   110
     The constant folding code can usually not optimize much
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
   111
     - this may change when some kind of constant/macro declaration is added to smalltalk.
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
   112
    "
212
ff39051e219f more constant folding options
Claus Gittinger <cg@exept.de>
parents: 204
diff changeset
   113
    folding notNil ifTrue:[
ff39051e219f more constant folding options
Claus Gittinger <cg@exept.de>
parents: 204
diff changeset
   114
	selector := selectorString asSymbolIfInterned.
ff39051e219f more constant folding options
Claus Gittinger <cg@exept.de>
parents: 204
diff changeset
   115
	selector notNil ifTrue:[
ff39051e219f more constant folding options
Claus Gittinger <cg@exept.de>
parents: 204
diff changeset
   116
ff39051e219f more constant folding options
Claus Gittinger <cg@exept.de>
parents: 204
diff changeset
   117
	    "/
ff39051e219f more constant folding options
Claus Gittinger <cg@exept.de>
parents: 204
diff changeset
   118
	    "/ do constant folding ...
ff39051e219f more constant folding options
Claus Gittinger <cg@exept.de>
parents: 204
diff changeset
   119
	    "/
ff39051e219f more constant folding options
Claus Gittinger <cg@exept.de>
parents: 204
diff changeset
   120
	    canFold := false.
ff39051e219f more constant folding options
Claus Gittinger <cg@exept.de>
parents: 204
diff changeset
   121
ff39051e219f more constant folding options
Claus Gittinger <cg@exept.de>
parents: 204
diff changeset
   122
            (recNode isGlobal and:[argNode isConstant]) ifTrue:[
ff39051e219f more constant folding options
Claus Gittinger <cg@exept.de>
parents: 204
diff changeset
   123
                globalName := recNode name.
ff39051e219f more constant folding options
Claus Gittinger <cg@exept.de>
parents: 204
diff changeset
   124
                recVal := recNode evaluate.
ff39051e219f more constant folding options
Claus Gittinger <cg@exept.de>
parents: 204
diff changeset
   125
ff39051e219f more constant folding options
Claus Gittinger <cg@exept.de>
parents: 204
diff changeset
   126
                (globalName = 'SmallInteger') ifTrue:[
ff39051e219f more constant folding options
Claus Gittinger <cg@exept.de>
parents: 204
diff changeset
   127
                    ( #( bitMaskFor: ) includes:selector)
ff39051e219f more constant folding options
Claus Gittinger <cg@exept.de>
parents: 204
diff changeset
   128
                    ifTrue:[
ff39051e219f more constant folding options
Claus Gittinger <cg@exept.de>
parents: 204
diff changeset
   129
                        canFold := true
ff39051e219f more constant folding options
Claus Gittinger <cg@exept.de>
parents: 204
diff changeset
   130
                    ]
ff39051e219f more constant folding options
Claus Gittinger <cg@exept.de>
parents: 204
diff changeset
   131
                ].
ff39051e219f more constant folding options
Claus Gittinger <cg@exept.de>
parents: 204
diff changeset
   132
                (globalName = 'Float') ifTrue:[
ff39051e219f more constant folding options
Claus Gittinger <cg@exept.de>
parents: 204
diff changeset
   133
                    ( #( pi unity zero ) includes:selector)
ff39051e219f more constant folding options
Claus Gittinger <cg@exept.de>
parents: 204
diff changeset
   134
                    ifTrue:[
ff39051e219f more constant folding options
Claus Gittinger <cg@exept.de>
parents: 204
diff changeset
   135
                        (recVal respondsTo:selector) ifTrue:[
ff39051e219f more constant folding options
Claus Gittinger <cg@exept.de>
parents: 204
diff changeset
   136
                            canFold := true
ff39051e219f more constant folding options
Claus Gittinger <cg@exept.de>
parents: 204
diff changeset
   137
                        ]
ff39051e219f more constant folding options
Claus Gittinger <cg@exept.de>
parents: 204
diff changeset
   138
                    ]
ff39051e219f more constant folding options
Claus Gittinger <cg@exept.de>
parents: 204
diff changeset
   139
                ]
ff39051e219f more constant folding options
Claus Gittinger <cg@exept.de>
parents: 204
diff changeset
   140
            ].
ff39051e219f more constant folding options
Claus Gittinger <cg@exept.de>
parents: 204
diff changeset
   141
ff39051e219f more constant folding options
Claus Gittinger <cg@exept.de>
parents: 204
diff changeset
   142
	    (recNode isConstant and:[argNode isConstant]) ifTrue:[
ff39051e219f more constant folding options
Claus Gittinger <cg@exept.de>
parents: 204
diff changeset
   143
	        "check if we can do it ..."
47
f861ad42703e *** empty log message ***
claus
parents: 39
diff changeset
   144
		recVal := recNode evaluate.
212
ff39051e219f more constant folding options
Claus Gittinger <cg@exept.de>
parents: 204
diff changeset
   145
		"
ff39051e219f more constant folding options
Claus Gittinger <cg@exept.de>
parents: 204
diff changeset
   146
		 we could do much more here - but then, we need a dependency from
ff39051e219f more constant folding options
Claus Gittinger <cg@exept.de>
parents: 204
diff changeset
   147
		 the folded selectors method to the method we generate code for ...
ff39051e219f more constant folding options
Claus Gittinger <cg@exept.de>
parents: 204
diff changeset
   148
		 limit optimizations to those that will never change
ff39051e219f more constant folding options
Claus Gittinger <cg@exept.de>
parents: 204
diff changeset
   149
		 (or - if you change them - you will crash so bad ...)
ff39051e219f more constant folding options
Claus Gittinger <cg@exept.de>
parents: 204
diff changeset
   150
		"
ff39051e219f more constant folding options
Claus Gittinger <cg@exept.de>
parents: 204
diff changeset
   151
		argVal := argNode evaluate.
ff39051e219f more constant folding options
Claus Gittinger <cg@exept.de>
parents: 204
diff changeset
   152
		(recVal respondsToArithmetic and:[argVal respondsToArithmetic]) ifTrue:[
ff39051e219f more constant folding options
Claus Gittinger <cg@exept.de>
parents: 204
diff changeset
   153
		    ( #( + - * / // \\ min: max: quo:) includes:selector) ifTrue:[
ff39051e219f more constant folding options
Claus Gittinger <cg@exept.de>
parents: 204
diff changeset
   154
			(#( / // \\ ) includes:selector) ifTrue:[
ff39051e219f more constant folding options
Claus Gittinger <cg@exept.de>
parents: 204
diff changeset
   155
			    argVal = 0 ifTrue:[
ff39051e219f more constant folding options
Claus Gittinger <cg@exept.de>
parents: 204
diff changeset
   156
				^ 'division by zero in constant expression'
ff39051e219f more constant folding options
Claus Gittinger <cg@exept.de>
parents: 204
diff changeset
   157
			    ].
ff39051e219f more constant folding options
Claus Gittinger <cg@exept.de>
parents: 204
diff changeset
   158
			].
ff39051e219f more constant folding options
Claus Gittinger <cg@exept.de>
parents: 204
diff changeset
   159
			canFold := true
ff39051e219f more constant folding options
Claus Gittinger <cg@exept.de>
parents: 204
diff changeset
   160
		    ].
ff39051e219f more constant folding options
Claus Gittinger <cg@exept.de>
parents: 204
diff changeset
   161
		    ( #( @ ) includes:selector) ifTrue:[
ff39051e219f more constant folding options
Claus Gittinger <cg@exept.de>
parents: 204
diff changeset
   162
			canFold := (folding == #full)
ff39051e219f more constant folding options
Claus Gittinger <cg@exept.de>
parents: 204
diff changeset
   163
		    ]
ff39051e219f more constant folding options
Claus Gittinger <cg@exept.de>
parents: 204
diff changeset
   164
		].
ff39051e219f more constant folding options
Claus Gittinger <cg@exept.de>
parents: 204
diff changeset
   165
		(recVal isMemberOf:String) ifTrue:[
ff39051e219f more constant folding options
Claus Gittinger <cg@exept.de>
parents: 204
diff changeset
   166
		    (argVal isInteger and:[selector == #at:]) ifTrue:[
ff39051e219f more constant folding options
Claus Gittinger <cg@exept.de>
parents: 204
diff changeset
   167
			canFold := (folding >= #level2) or:[folding == #full].
ff39051e219f more constant folding options
Claus Gittinger <cg@exept.de>
parents: 204
diff changeset
   168
		    ].
ff39051e219f more constant folding options
Claus Gittinger <cg@exept.de>
parents: 204
diff changeset
   169
		    ((argVal isMemberOf:String) and:[selector == #',']) ifTrue:[
ff39051e219f more constant folding options
Claus Gittinger <cg@exept.de>
parents: 204
diff changeset
   170
			canFold := (folding >= #level2) or:[folding == #full].
ff39051e219f more constant folding options
Claus Gittinger <cg@exept.de>
parents: 204
diff changeset
   171
		    ]
ff39051e219f more constant folding options
Claus Gittinger <cg@exept.de>
parents: 204
diff changeset
   172
		].
ff39051e219f more constant folding options
Claus Gittinger <cg@exept.de>
parents: 204
diff changeset
   173
	    ].
ff39051e219f more constant folding options
Claus Gittinger <cg@exept.de>
parents: 204
diff changeset
   174
ff39051e219f more constant folding options
Claus Gittinger <cg@exept.de>
parents: 204
diff changeset
   175
	    canFold ifTrue:[
47
f861ad42703e *** empty log message ***
claus
parents: 39
diff changeset
   176
		(recVal respondsTo:selector) ifTrue:[
212
ff39051e219f more constant folding options
Claus Gittinger <cg@exept.de>
parents: 204
diff changeset
   177
		    SignalSet anySignal handle:[:ex |
ff39051e219f more constant folding options
Claus Gittinger <cg@exept.de>
parents: 204
diff changeset
   178
		        ^ 'error in constant expression (' , ex errorString , ')'
ff39051e219f more constant folding options
Claus Gittinger <cg@exept.de>
parents: 204
diff changeset
   179
		    ] do:[
ff39051e219f more constant folding options
Claus Gittinger <cg@exept.de>
parents: 204
diff changeset
   180
		        result := recVal perform:selector with:argVal.
47
f861ad42703e *** empty log message ***
claus
parents: 39
diff changeset
   181
		    ].
212
ff39051e219f more constant folding options
Claus Gittinger <cg@exept.de>
parents: 204
diff changeset
   182
		    ^ ConstantNode type:(ConstantNode typeOfConstant:result) value:result
47
f861ad42703e *** empty log message ***
claus
parents: 39
diff changeset
   183
		]
f861ad42703e *** empty log message ***
claus
parents: 39
diff changeset
   184
	    ]
212
ff39051e219f more constant folding options
Claus Gittinger <cg@exept.de>
parents: 204
diff changeset
   185
	]
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   186
    ].
212
ff39051e219f more constant folding options
Claus Gittinger <cg@exept.de>
parents: 204
diff changeset
   187
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   188
    ^ (self basicNew) receiver:recNode selector:selectorString args:(Array with:argNode) lineno:0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   189
!
7ad01559b262 Initial revision
claus
parents:
diff changeset
   190
7ad01559b262 Initial revision
claus
parents:
diff changeset
   191
receiver:recNode selector:selectorString args:anArray
212
ff39051e219f more constant folding options
Claus Gittinger <cg@exept.de>
parents: 204
diff changeset
   192
    ^ self receiver:recNode selector:selectorString args:anArray fold:nil
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   193
!
7ad01559b262 Initial revision
claus
parents:
diff changeset
   194
7ad01559b262 Initial revision
claus
parents:
diff changeset
   195
receiver:recNode selector:selectorString args:argArray fold:folding
117
claus
parents: 111
diff changeset
   196
    |numArgs|
claus
parents: 111
diff changeset
   197
212
ff39051e219f more constant folding options
Claus Gittinger <cg@exept.de>
parents: 204
diff changeset
   198
    folding notNil ifTrue:[
231
168d581377a2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 212
diff changeset
   199
        numArgs := argArray size.
168d581377a2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 212
diff changeset
   200
        (numArgs == 1) ifTrue:[
168d581377a2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 212
diff changeset
   201
            ^ self receiver:recNode selector:selectorString arg:(argArray at:1) fold:folding 
168d581377a2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 212
diff changeset
   202
        ].
20
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
   203
231
168d581377a2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 212
diff changeset
   204
        "uncomment the follwoing for a nice array initializer optimization ..."
212
ff39051e219f more constant folding options
Claus Gittinger <cg@exept.de>
parents: 204
diff changeset
   205
        (numArgs == 2) ifTrue:[
ff39051e219f more constant folding options
Claus Gittinger <cg@exept.de>
parents: 204
diff changeset
   206
            ^ self receiver:recNode selector:selectorString arg1:(argArray at:1) arg2:(argArray at:2) fold:folding 
ff39051e219f more constant folding options
Claus Gittinger <cg@exept.de>
parents: 204
diff changeset
   207
        ].
231
168d581377a2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 212
diff changeset
   208
        numArgs > Method maxNumberOfArguments ifTrue:[
168d581377a2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 212
diff changeset
   209
            ^ 'too many arguments for current VM implementation'.
168d581377a2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 212
diff changeset
   210
        ].
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   211
    ].
117
claus
parents: 111
diff changeset
   212
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   213
    ^ (self basicNew) receiver:recNode selector:selectorString args:argArray lineno:0
117
claus
parents: 111
diff changeset
   214
claus
parents: 111
diff changeset
   215
    "Modified: 3.9.1995 / 16:41:39 / claus"
231
168d581377a2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 212
diff changeset
   216
    "Modified: 21.3.1996 / 16:07:34 / cg"
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   217
! !
7ad01559b262 Initial revision
claus
parents:
diff changeset
   218
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   219
!MessageNode methodsFor:'accessing'!
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   220
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   221
arg1
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   222
    ^ argArray at:1
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   223
!
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   224
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   225
args
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   226
    ^ argArray
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   227
!
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   228
543
de47f8969fd9 more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
   229
arguments
de47f8969fd9 more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
   230
    ^ argArray ? #()
de47f8969fd9 more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
   231
de47f8969fd9 more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
   232
    "Created: 19.6.1997 / 17:31:14 / cg"
de47f8969fd9 more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
   233
    "Modified: 19.6.1997 / 17:32:25 / cg"
de47f8969fd9 more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
   234
!
de47f8969fd9 more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
   235
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   236
lineNumber
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   237
     ^ lineNr
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   238
!
7ad01559b262 Initial revision
claus
parents:
diff changeset
   239
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   240
lineNumber:num
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   241
     lineNr := num
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   242
!
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   243
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   244
receiver
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   245
    ^ receiver
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   246
!
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   247
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   248
receiver:r selector:s args:a lineno:l
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   249
    receiver := r.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   250
    selector := s asSymbol.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   251
    argArray := a.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   252
    lineNr := l
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   253
!
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   254
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   255
selector
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   256
    ^ selector
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   257
! !
7ad01559b262 Initial revision
claus
parents:
diff changeset
   258
7ad01559b262 Initial revision
claus
parents:
diff changeset
   259
!MessageNode methodsFor:'checks'!
7ad01559b262 Initial revision
claus
parents:
diff changeset
   260
7ad01559b262 Initial revision
claus
parents:
diff changeset
   261
plausibilityCheck
7ad01559b262 Initial revision
claus
parents:
diff changeset
   262
    |rec arg operand|
7ad01559b262 Initial revision
claus
parents:
diff changeset
   263
3
b63b8a6b71fb *** empty log message ***
claus
parents: 0
diff changeset
   264
    "
b63b8a6b71fb *** empty log message ***
claus
parents: 0
diff changeset
   265
     it once took me almost an hour, to find a '==' which
b63b8a6b71fb *** empty log message ***
claus
parents: 0
diff changeset
   266
     should have been an '=' (you cannot compare floats with ==)
19
84a1ddf215a5 *** empty log message ***
claus
parents: 15
diff changeset
   267
     (well, I looked at the '==' at least 50 times -
84a1ddf215a5 *** empty log message ***
claus
parents: 15
diff changeset
   268
      - but didn't think about it ...).
84a1ddf215a5 *** empty log message ***
claus
parents: 15
diff changeset
   269
     thats reason enough to add this check here.
84a1ddf215a5 *** empty log message ***
claus
parents: 15
diff changeset
   270
     I will add more as heuristic knowledge increases ...
84a1ddf215a5 *** empty log message ***
claus
parents: 15
diff changeset
   271
     (send me comments on common programming errors ...)
84a1ddf215a5 *** empty log message ***
claus
parents: 15
diff changeset
   272
    "
84a1ddf215a5 *** empty log message ***
claus
parents: 15
diff changeset
   273
84a1ddf215a5 *** empty log message ***
claus
parents: 15
diff changeset
   274
    "
84a1ddf215a5 *** empty log message ***
claus
parents: 15
diff changeset
   275
     check #== appled to Floats, Strings or Fractions
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   276
    "
7ad01559b262 Initial revision
claus
parents:
diff changeset
   277
    ((selector == #==) or:[selector == #~~]) ifTrue:[
47
f861ad42703e *** empty log message ***
claus
parents: 39
diff changeset
   278
	receiver isConstant ifTrue:[
f861ad42703e *** empty log message ***
claus
parents: 39
diff changeset
   279
	    rec := receiver evaluate.
f861ad42703e *** empty log message ***
claus
parents: 39
diff changeset
   280
	    ((rec isMemberOf:String) or:[
f861ad42703e *** empty log message ***
claus
parents: 39
diff changeset
   281
	     (rec isMemberOf:Float) or:[
f861ad42703e *** empty log message ***
claus
parents: 39
diff changeset
   282
	     (rec isMemberOf:Fraction)]]) ifTrue:[
f861ad42703e *** empty log message ***
claus
parents: 39
diff changeset
   283
		operand := rec
f861ad42703e *** empty log message ***
claus
parents: 39
diff changeset
   284
	    ].
f861ad42703e *** empty log message ***
claus
parents: 39
diff changeset
   285
	].
f861ad42703e *** empty log message ***
claus
parents: 39
diff changeset
   286
	(argArray at:1) isConstant ifTrue:[
f861ad42703e *** empty log message ***
claus
parents: 39
diff changeset
   287
	    arg := (argArray at:1) evaluate.
f861ad42703e *** empty log message ***
claus
parents: 39
diff changeset
   288
	    ((arg isMemberOf:String) or:[
f861ad42703e *** empty log message ***
claus
parents: 39
diff changeset
   289
	     (arg isMemberOf:Float) or:[
f861ad42703e *** empty log message ***
claus
parents: 39
diff changeset
   290
	     (arg isMemberOf:Fraction)]]) ifTrue:[
f861ad42703e *** empty log message ***
claus
parents: 39
diff changeset
   291
		operand := arg
f861ad42703e *** empty log message ***
claus
parents: 39
diff changeset
   292
	    ].
f861ad42703e *** empty log message ***
claus
parents: 39
diff changeset
   293
	].
f861ad42703e *** empty log message ***
claus
parents: 39
diff changeset
   294
	operand notNil ifTrue:[
f861ad42703e *** empty log message ***
claus
parents: 39
diff changeset
   295
	    (selector == #==) ifTrue:[
f861ad42703e *** empty log message ***
claus
parents: 39
diff changeset
   296
		^ 'identity compare is unsafe here'
f861ad42703e *** empty log message ***
claus
parents: 39
diff changeset
   297
	    ].
f861ad42703e *** empty log message ***
claus
parents: 39
diff changeset
   298
	    ^ 'identity compare will usually return true here'
f861ad42703e *** empty log message ***
claus
parents: 39
diff changeset
   299
	]
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   300
    ].
3
b63b8a6b71fb *** empty log message ***
claus
parents: 0
diff changeset
   301
b63b8a6b71fb *** empty log message ***
claus
parents: 0
diff changeset
   302
    "
19
84a1ddf215a5 *** empty log message ***
claus
parents: 15
diff changeset
   303
     [...] ifTrue:...
3
b63b8a6b71fb *** empty log message ***
claus
parents: 0
diff changeset
   304
     an error often occuring when you are a beginner ...
b63b8a6b71fb *** empty log message ***
claus
parents: 0
diff changeset
   305
    "
b63b8a6b71fb *** empty log message ***
claus
parents: 0
diff changeset
   306
    ((selector == #ifTrue:) or:[selector == #ifFalse:]) ifTrue:[
47
f861ad42703e *** empty log message ***
claus
parents: 39
diff changeset
   307
	receiver isBlock ifTrue:[
f861ad42703e *** empty log message ***
claus
parents: 39
diff changeset
   308
	    (Block canUnderstand:selector) ifFalse:[
f861ad42703e *** empty log message ***
claus
parents: 39
diff changeset
   309
		^ 'blocks usually do not respond to ' , selector , ' messages'
f861ad42703e *** empty log message ***
claus
parents: 39
diff changeset
   310
	    ].
f861ad42703e *** empty log message ***
claus
parents: 39
diff changeset
   311
	].
f861ad42703e *** empty log message ***
claus
parents: 39
diff changeset
   312
	(argArray at:1) isBlock ifFalse:[
f861ad42703e *** empty log message ***
claus
parents: 39
diff changeset
   313
	    ^ 'will fail at runtime, if argument to ' , selector , ' does not evaluate to a block'
f861ad42703e *** empty log message ***
claus
parents: 39
diff changeset
   314
	]
3
b63b8a6b71fb *** empty log message ***
claus
parents: 0
diff changeset
   315
    ].
19
84a1ddf215a5 *** empty log message ***
claus
parents: 15
diff changeset
   316
    ((selector == #ifTrue:ifFalse:) or:[selector == #ifFalse:ifTrue:]) ifTrue:[
47
f861ad42703e *** empty log message ***
claus
parents: 39
diff changeset
   317
	receiver isBlock ifTrue:[
f861ad42703e *** empty log message ***
claus
parents: 39
diff changeset
   318
	    (Block canUnderstand:selector) ifFalse:[
f861ad42703e *** empty log message ***
claus
parents: 39
diff changeset
   319
		^ 'blocks usually do not respond to ' , selector , ' messages'
f861ad42703e *** empty log message ***
claus
parents: 39
diff changeset
   320
	    ].
f861ad42703e *** empty log message ***
claus
parents: 39
diff changeset
   321
	].
f861ad42703e *** empty log message ***
claus
parents: 39
diff changeset
   322
	(argArray at:1) isBlock ifFalse:[
f861ad42703e *** empty log message ***
claus
parents: 39
diff changeset
   323
	    ^ 'will fail at runtime, if 1st. argument to ' , selector , ' does not evaluate to a block'
f861ad42703e *** empty log message ***
claus
parents: 39
diff changeset
   324
	].
f861ad42703e *** empty log message ***
claus
parents: 39
diff changeset
   325
	(argArray at:2) isBlock ifFalse:[
f861ad42703e *** empty log message ***
claus
parents: 39
diff changeset
   326
	    ^ 'will fail at runtime, if 2nd. argument to ' , selector , ' does not evaluate to a block'
f861ad42703e *** empty log message ***
claus
parents: 39
diff changeset
   327
	]
3
b63b8a6b71fb *** empty log message ***
claus
parents: 0
diff changeset
   328
    ].
19
84a1ddf215a5 *** empty log message ***
claus
parents: 15
diff changeset
   329
84a1ddf215a5 *** empty log message ***
claus
parents: 15
diff changeset
   330
    "
84a1ddf215a5 *** empty log message ***
claus
parents: 15
diff changeset
   331
     (...) whileTrue:[
84a1ddf215a5 *** empty log message ***
claus
parents: 15
diff changeset
   332
    "
3
b63b8a6b71fb *** empty log message ***
claus
parents: 0
diff changeset
   333
    ((selector == #whileTrue:) or:[selector == #whileFalse:]) ifTrue:[
47
f861ad42703e *** empty log message ***
claus
parents: 39
diff changeset
   334
	receiver isBlock ifFalse:[
f861ad42703e *** empty log message ***
claus
parents: 39
diff changeset
   335
	    "
f861ad42703e *** empty log message ***
claus
parents: 39
diff changeset
   336
	     only warn, if code was originally parenthized
f861ad42703e *** empty log message ***
claus
parents: 39
diff changeset
   337
	    "
f861ad42703e *** empty log message ***
claus
parents: 39
diff changeset
   338
	    receiver parenthized ifTrue:[
f861ad42703e *** empty log message ***
claus
parents: 39
diff changeset
   339
		^ 'will fail at runtime, if receiver of ' , selector , ' does not evaluate to a block'
f861ad42703e *** empty log message ***
claus
parents: 39
diff changeset
   340
	    ]
f861ad42703e *** empty log message ***
claus
parents: 39
diff changeset
   341
	].
f861ad42703e *** empty log message ***
claus
parents: 39
diff changeset
   342
	(argArray at:1) isBlock ifFalse:[
f861ad42703e *** empty log message ***
claus
parents: 39
diff changeset
   343
	    ^ 'will fail at runtime, if argument to ' , selector , ' does not evaluate to a block'
f861ad42703e *** empty log message ***
claus
parents: 39
diff changeset
   344
	].
3
b63b8a6b71fb *** empty log message ***
claus
parents: 0
diff changeset
   345
    ].
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   346
    ^ nil
7ad01559b262 Initial revision
claus
parents:
diff changeset
   347
! !
7ad01559b262 Initial revision
claus
parents:
diff changeset
   348
7ad01559b262 Initial revision
claus
parents:
diff changeset
   349
!MessageNode methodsFor:'code generation'!
7ad01559b262 Initial revision
claus
parents:
diff changeset
   350
338
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
   351
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
   352
    "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
   353
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
   354
    |theByteCode optByteCode theReceiver theArg pos1 pos2 pos3 code here jmp|
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
   355
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
   356
    theByteCode := #falseJump.
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
   357
    theReceiver := receiver receiver.
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
   358
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
   359
    optByteCode := self optimizedConditionFor:theReceiver
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
   360
                                         with:theByteCode.
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
   361
    optByteCode notNil ifTrue:[
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
   362
        ((optByteCode == #eqJump) or:[optByteCode == #notEqJump]) ifTrue:[
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
   363
            theArg := theReceiver arg1
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
   364
        ].
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
   365
        theReceiver := theReceiver receiver.
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
   366
        theByteCode := optByteCode
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
   367
    ].
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
   368
    "/ 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
   369
    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
   370
    theArg notNil ifTrue:[
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
   371
        theArg 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
   372
    ].
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
   373
    aStream nextPut:theByteCode.
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
   374
    pos1 := aStream position.   "/ remember branch target of left-fail branch
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
   375
    aStream nextPut:0.
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
   376
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
   377
    "/ 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
   378
    theReceiver := receiver arg1.
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
   379
    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
   380
    (selector == #ifTrue:ifFalse:) ifTrue:[
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
   381
        jmp := #falseJump
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
   382
    ] ifFalse:[
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
   383
        jmp := #trueJump
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
   384
    ].
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
   385
    aStream nextPut:jmp.
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
   386
    pos2 := aStream position.   "/ remember branch target of right-fail branch 
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
   387
    aStream nextPut:0.
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
   388
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
   389
    code := aStream contents.
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
   390
    (selector == #ifFalse:ifTrue:) ifTrue:[
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
   391
        code at:pos1 put:(aStream position)
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
   392
    ].
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
   393
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
   394
    "/ code the if-block
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
   395
    (argArray at: 1) codeInlineOn: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
   396
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
   397
    aStream nextPut:#jump.
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
   398
    pos3 := aStream position.
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
   399
    aStream nextPut:0.
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
   400
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
   401
    here := aStream position.
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
   402
    (selector == #ifTrue:ifFalse:) ifTrue:[
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
   403
        code at:pos1 put:here
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
   404
    ].
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
   405
    code at:pos2 put:here.
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
   406
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
   407
    "/ code the else-block
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
   408
    (argArray at: 2) codeInlineOn: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
   409
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
   410
    code at:pos3 put:(aStream position)
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
   411
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
   412
    "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
   413
!
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
   414
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   415
codeAndIfOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   416
    "generate code for (x and:[y]) ifxxx:[ ... ]"
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   417
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   418
    |theByteCode optByteCode theReceiver theArg pos1 pos2 pos3 code here jmp|
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   419
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   420
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   421
    theByteCode := #falseJump.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   422
    theReceiver := receiver receiver.
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   423
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   424
    optByteCode := self optimizedConditionFor:theReceiver
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   425
					 with:theByteCode.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   426
    optByteCode notNil ifTrue:[
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   427
	((optByteCode == #eqJump) or:[optByteCode == #notEqJump]) ifTrue:[
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   428
	    theArg := theReceiver arg1
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   429
	].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   430
	theReceiver := theReceiver receiver.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   431
	theByteCode := optByteCode
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   432
    ].
104
claus
parents: 103
diff changeset
   433
    theReceiver codeOn:aStream inBlock:b for:aCompiler.
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   434
    theArg notNil ifTrue:[
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   435
	theArg codeOn:aStream inBlock:b for:aCompiler
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   436
    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   437
    aStream nextPut:theByteCode.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   438
    pos1 := aStream position.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   439
    aStream nextPut:0.
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   440
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   441
    theReceiver := receiver arg1.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   442
    theReceiver codeInlineOn:aStream inBlock:b for:aCompiler.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   443
    (selector == #ifTrue:) ifTrue:[
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   444
	jmp := #falseJump
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   445
    ] ifFalse:[
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   446
	jmp := #trueJump
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   447
    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   448
    aStream nextPut:jmp.
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   449
    pos2 := aStream position.
7ad01559b262 Initial revision
claus
parents:
diff changeset
   450
    aStream nextPut:0.
7ad01559b262 Initial revision
claus
parents:
diff changeset
   451
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   452
    code := aStream contents.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   453
    (selector == #ifFalse:) ifTrue:[
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   454
	code at:pos1 put:(aStream position)
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   455
    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   456
    (argArray at: 1) codeInlineOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   457
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   458
    valueNeeded ifTrue:[
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   459
	aStream nextPut:#jump.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   460
	pos3 := aStream position.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   461
	aStream nextPut:0.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   462
	here := aStream position.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   463
	(selector == #ifTrue:) ifTrue:[
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   464
	    code at:pos1 put:here
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   465
	].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   466
	code at:pos2 put:here.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   467
	aStream nextPut:#pushNil.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   468
	code at:pos3 put:(aStream position)
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   469
    ] ifFalse:[
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   470
	here := aStream position.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   471
	(selector == #ifTrue:) ifTrue:[
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   472
	    code at:pos1 put:here
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   473
	].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   474
	code at:pos2 put:here
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   475
    ]
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   476
!
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   477
289
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
   478
codeAndOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
   479
    "generate code for (x and:[y])"
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   480
289
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
   481
    |pos1 rightExpr|
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
   482
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
   483
    receiver codeOn:aStream inBlock:b for:aCompiler.
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
   484
    valueNeeded ifTrue:[
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
   485
        aStream nextPut:#dup.
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   486
    ].
289
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
   487
    aStream nextPut:#falseJump.
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
   488
    pos1 := aStream position.
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
   489
    aStream nextPut:0.
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
   490
    valueNeeded ifTrue:[
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
   491
        aStream nextPut:#drop.
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   492
    ].
289
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
   493
    rightExpr := argArray at:1.
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
   494
    rightExpr codeInlineOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler.
163
9a7dfd547e69 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   495
289
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
   496
    (aStream contents) at:pos1 put:(aStream position)
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
   497
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
   498
    "Created: 17.6.1996 / 15:46:42 / cg"
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
   499
    "Modified: 17.6.1996 / 15:47:44 / cg"
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   500
!
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   501
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   502
codeForCascadeOn:aStream inBlock:b for:aCompiler
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   503
    "like codeOn, but always leave the receiver instead of the result"
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   504
189
673580572edd fixed cascades involving super sends (i.e. super foo; bar)
Claus Gittinger <cg@exept.de>
parents: 186
diff changeset
   505
    |nargs isBuiltIn code codeL litIndex cls clsLitIndex|
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   506
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   507
    argArray isNil ifTrue:[
253
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
   508
        nargs := 0
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   509
    ] ifFalse:[
253
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
   510
        nargs := argArray size
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   511
    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   512
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   513
    isBuiltIn := false.
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   514
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   515
    (nargs == 0) ifTrue:[
253
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
   516
        isBuiltIn := aCompiler isBuiltInUnarySelector:selector forReceiver:receiver
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   517
    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   518
    (nargs == 1) ifTrue:[
253
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
   519
        isBuiltIn := aCompiler isBuiltIn1ArgSelector:selector forReceiver:receiver
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   520
    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   521
    (nargs == 2) ifTrue:[
253
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
   522
        isBuiltIn := aCompiler isBuiltIn2ArgSelector:selector forReceiver:receiver
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   523
    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   524
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   525
    receiver codeOn:aStream inBlock:b for:aCompiler.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   526
    aStream nextPut:#dup.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   527
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   528
    "can we use a send-bytecode ?"
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   529
    isBuiltIn ifTrue:[
253
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
   530
        receiver isSuper ifFalse:[
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
   531
            (nargs > 0) ifTrue:[
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
   532
                (argArray at:1) codeOn:aStream inBlock:b for:aCompiler.
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
   533
                (nargs > 1) ifTrue:[
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
   534
                    (argArray at:2) codeOn:aStream inBlock:b for:aCompiler
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
   535
                ]
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
   536
            ].
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
   537
            aStream nextPut:selector.
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
   538
            (aCompiler hasLineNumber:selector) ifTrue:[
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
   539
                aStream nextPut:lineNr.
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
   540
            ].
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
   541
            aStream nextPut:#drop.
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
   542
            ^ self
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
   543
        ]
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   544
    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   545
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   546
    "no - generate a send"
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   547
    argArray notNil ifTrue:[
253
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
   548
        argArray do:[:arg |
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
   549
            arg codeOn:aStream inBlock:b for:aCompiler
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
   550
        ]
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   551
    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   552
    litIndex := aCompiler addLiteral:selector.
189
673580572edd fixed cascades involving super sends (i.e. super foo; bar)
Claus Gittinger <cg@exept.de>
parents: 186
diff changeset
   553
673580572edd fixed cascades involving super sends (i.e. super foo; bar)
Claus Gittinger <cg@exept.de>
parents: 186
diff changeset
   554
    receiver isSuper ifTrue:[
253
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
   555
        cls := aCompiler targetClass.
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
   556
        receiver isHere ifTrue:[
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
   557
            code := #hereSend.
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
   558
            codeL := #hereSendL.
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
   559
        ] ifFalse:[
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
   560
            code := #superSend.
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
   561
            codeL := #superSendL.
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
   562
            cls := cls superclass.
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
   563
        ].
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
   564
        clsLitIndex := aCompiler addLiteral:cls.
189
673580572edd fixed cascades involving super sends (i.e. super foo; bar)
Claus Gittinger <cg@exept.de>
parents: 186
diff changeset
   565
253
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
   566
        (litIndex <= 255 and:[clsLitIndex <= 255]) ifTrue:[
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
   567
            aStream nextPut:code; nextPut:lineNr; nextPut:litIndex; nextPut:nargs; nextPut:clsLitIndex; nextPut:#drop.
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
   568
            ^ self
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
   569
        ].
189
673580572edd fixed cascades involving super sends (i.e. super foo; bar)
Claus Gittinger <cg@exept.de>
parents: 186
diff changeset
   570
253
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
   571
        "need 16bit litIndex"
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
   572
        aStream nextPut:codeL; nextPut:lineNr; nextPut:litIndex; nextPut:0; nextPut:nargs; nextPut:clsLitIndex; nextPut:0; nextPut:#drop.
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
   573
        ^ self
189
673580572edd fixed cascades involving super sends (i.e. super foo; bar)
Claus Gittinger <cg@exept.de>
parents: 186
diff changeset
   574
    ].
673580572edd fixed cascades involving super sends (i.e. super foo; bar)
Claus Gittinger <cg@exept.de>
parents: 186
diff changeset
   575
673580572edd fixed cascades involving super sends (i.e. super foo; bar)
Claus Gittinger <cg@exept.de>
parents: 186
diff changeset
   576
    litIndex <= 255 ifTrue:[
253
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
   577
        (nargs <= 3) ifTrue:[
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
   578
            code := #(sendDrop0 sendDrop1 sendDrop2 sendDrop3) at:(nargs+1).
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
   579
            aStream nextPut:code; nextPut:lineNr; nextPut:litIndex.
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
   580
            ^ self
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
   581
        ].
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   582
253
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
   583
        aStream nextPut:#sendDrop; nextPut:lineNr; nextPut:litIndex; nextPut:nargs.
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
   584
        ^ self
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   585
    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   586
    "need 16bit litIndex"
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   587
    aStream nextPut:#sendDropL; nextPut:lineNr; nextPut:litIndex; nextPut:0; nextPut:nargs
189
673580572edd fixed cascades involving super sends (i.e. super foo; bar)
Claus Gittinger <cg@exept.de>
parents: 186
diff changeset
   588
253
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
   589
    "Modified: 17.4.1996 / 22:33:24 / cg"
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   590
!
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   591
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   592
codeForSideEffectOn:aStream inBlock:b for:aCompiler
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   593
    self codeOn:aStream inBlock:b valueNeeded:false for:aCompiler
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   594
!
7ad01559b262 Initial revision
claus
parents:
diff changeset
   595
104
claus
parents: 103
diff changeset
   596
codeIfElseOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   597
    "generate code for x ifxxx:[ ... ] yyy:[ ...]"
7ad01559b262 Initial revision
claus
parents:
diff changeset
   598
334
cd7491b7ad33 dont code a jump after if-part if it ends in a return.
Claus Gittinger <cg@exept.de>
parents: 309
diff changeset
   599
    |pos pos2 theReceiver theArg theByteCode optByteCode subsel code needLineNr
cd7491b7ad33 dont code a jump after if-part if it ends in a return.
Claus Gittinger <cg@exept.de>
parents: 309
diff changeset
   600
     needJump block1|
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   601
7ad01559b262 Initial revision
claus
parents:
diff changeset
   602
    theReceiver := receiver.
76
55d64cb1ffea *** empty log message ***
claus
parents: 75
diff changeset
   603
55d64cb1ffea *** empty log message ***
claus
parents: 75
diff changeset
   604
    (theReceiver isMessage) ifTrue:[
334
cd7491b7ad33 dont code a jump after if-part if it ends in a return.
Claus Gittinger <cg@exept.de>
parents: 309
diff changeset
   605
        subsel := theReceiver selector.
cd7491b7ad33 dont code a jump after if-part if it ends in a return.
Claus Gittinger <cg@exept.de>
parents: 309
diff changeset
   606
        (subsel == #and:) ifTrue:[
cd7491b7ad33 dont code a jump after if-part if it ends in a return.
Claus Gittinger <cg@exept.de>
parents: 309
diff changeset
   607
            self codeAndIfElseOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler.
cd7491b7ad33 dont code a jump after if-part if it ends in a return.
Claus Gittinger <cg@exept.de>
parents: 309
diff changeset
   608
            ^ self
cd7491b7ad33 dont code a jump after if-part if it ends in a return.
Claus Gittinger <cg@exept.de>
parents: 309
diff changeset
   609
        ].
cd7491b7ad33 dont code a jump after if-part if it ends in a return.
Claus Gittinger <cg@exept.de>
parents: 309
diff changeset
   610
        (subsel == #or:) ifTrue:[
cd7491b7ad33 dont code a jump after if-part if it ends in a return.
Claus Gittinger <cg@exept.de>
parents: 309
diff changeset
   611
            self codeOrIfElseOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler.
cd7491b7ad33 dont code a jump after if-part if it ends in a return.
Claus Gittinger <cg@exept.de>
parents: 309
diff changeset
   612
            ^ self
cd7491b7ad33 dont code a jump after if-part if it ends in a return.
Claus Gittinger <cg@exept.de>
parents: 309
diff changeset
   613
        ]
76
55d64cb1ffea *** empty log message ***
claus
parents: 75
diff changeset
   614
    ].
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   615
    (selector == #ifTrue:ifFalse:) ifTrue:[
334
cd7491b7ad33 dont code a jump after if-part if it ends in a return.
Claus Gittinger <cg@exept.de>
parents: 309
diff changeset
   616
        theByteCode := #falseJump
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   617
    ] ifFalse:[
334
cd7491b7ad33 dont code a jump after if-part if it ends in a return.
Claus Gittinger <cg@exept.de>
parents: 309
diff changeset
   618
        (selector == #ifFalse:ifTrue:) ifTrue:[
cd7491b7ad33 dont code a jump after if-part if it ends in a return.
Claus Gittinger <cg@exept.de>
parents: 309
diff changeset
   619
            theByteCode := #trueJump
cd7491b7ad33 dont code a jump after if-part if it ends in a return.
Claus Gittinger <cg@exept.de>
parents: 309
diff changeset
   620
        ]
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   621
    ].
7ad01559b262 Initial revision
claus
parents:
diff changeset
   622
    optByteCode := self optimizedConditionFor:theReceiver
334
cd7491b7ad33 dont code a jump after if-part if it ends in a return.
Claus Gittinger <cg@exept.de>
parents: 309
diff changeset
   623
                                         with:theByteCode.
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   624
    optByteCode notNil ifTrue:[
334
cd7491b7ad33 dont code a jump after if-part if it ends in a return.
Claus Gittinger <cg@exept.de>
parents: 309
diff changeset
   625
        ((optByteCode == #eqJump) or:[optByteCode == #notEqJump]) ifTrue:[
cd7491b7ad33 dont code a jump after if-part if it ends in a return.
Claus Gittinger <cg@exept.de>
parents: 309
diff changeset
   626
            theArg := theReceiver arg1
cd7491b7ad33 dont code a jump after if-part if it ends in a return.
Claus Gittinger <cg@exept.de>
parents: 309
diff changeset
   627
        ].
cd7491b7ad33 dont code a jump after if-part if it ends in a return.
Claus Gittinger <cg@exept.de>
parents: 309
diff changeset
   628
        theReceiver := theReceiver receiver.
cd7491b7ad33 dont code a jump after if-part if it ends in a return.
Claus Gittinger <cg@exept.de>
parents: 309
diff changeset
   629
        theByteCode := optByteCode
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   630
    ].
7ad01559b262 Initial revision
claus
parents:
diff changeset
   631
    theByteCode notNil ifTrue:[
334
cd7491b7ad33 dont code a jump after if-part if it ends in a return.
Claus Gittinger <cg@exept.de>
parents: 309
diff changeset
   632
        theReceiver codeOn:aStream inBlock:b for:aCompiler.
53
c5dd7abf8431 *** empty log message ***
claus
parents: 52
diff changeset
   633
334
cd7491b7ad33 dont code a jump after if-part if it ends in a return.
Claus Gittinger <cg@exept.de>
parents: 309
diff changeset
   634
        needLineNr := true.
cd7491b7ad33 dont code a jump after if-part if it ends in a return.
Claus Gittinger <cg@exept.de>
parents: 309
diff changeset
   635
        theArg isNil ifTrue:[
cd7491b7ad33 dont code a jump after if-part if it ends in a return.
Claus Gittinger <cg@exept.de>
parents: 309
diff changeset
   636
            theReceiver isMessage ifTrue:[
cd7491b7ad33 dont code a jump after if-part if it ends in a return.
Claus Gittinger <cg@exept.de>
parents: 309
diff changeset
   637
                (aCompiler hasLineNumber:(theReceiver selector)) ifTrue:[
cd7491b7ad33 dont code a jump after if-part if it ends in a return.
Claus Gittinger <cg@exept.de>
parents: 309
diff changeset
   638
                    theReceiver lineNumber == lineNr ifTrue:[
cd7491b7ad33 dont code a jump after if-part if it ends in a return.
Claus Gittinger <cg@exept.de>
parents: 309
diff changeset
   639
                        needLineNr := false
cd7491b7ad33 dont code a jump after if-part if it ends in a return.
Claus Gittinger <cg@exept.de>
parents: 309
diff changeset
   640
                    ]
cd7491b7ad33 dont code a jump after if-part if it ends in a return.
Claus Gittinger <cg@exept.de>
parents: 309
diff changeset
   641
                ]
cd7491b7ad33 dont code a jump after if-part if it ends in a return.
Claus Gittinger <cg@exept.de>
parents: 309
diff changeset
   642
            ]
434
c48a356d8a34 oops - optimizable or: ... ifTrue/ifFalse generated
Claus Gittinger <cg@exept.de>
parents: 429
diff changeset
   643
        ] ifFalse:[
334
cd7491b7ad33 dont code a jump after if-part if it ends in a return.
Claus Gittinger <cg@exept.de>
parents: 309
diff changeset
   644
            theArg codeOn:aStream inBlock:b for:aCompiler
cd7491b7ad33 dont code a jump after if-part if it ends in a return.
Claus Gittinger <cg@exept.de>
parents: 309
diff changeset
   645
        ].
53
c5dd7abf8431 *** empty log message ***
claus
parents: 52
diff changeset
   646
334
cd7491b7ad33 dont code a jump after if-part if it ends in a return.
Claus Gittinger <cg@exept.de>
parents: 309
diff changeset
   647
        needLineNr ifTrue:[
cd7491b7ad33 dont code a jump after if-part if it ends in a return.
Claus Gittinger <cg@exept.de>
parents: 309
diff changeset
   648
            (lineNr between:1 and:255) ifTrue:[
cd7491b7ad33 dont code a jump after if-part if it ends in a return.
Claus Gittinger <cg@exept.de>
parents: 309
diff changeset
   649
                aStream nextPut:#lineno; nextPut:lineNr.
cd7491b7ad33 dont code a jump after if-part if it ends in a return.
Claus Gittinger <cg@exept.de>
parents: 309
diff changeset
   650
            ]
cd7491b7ad33 dont code a jump after if-part if it ends in a return.
Claus Gittinger <cg@exept.de>
parents: 309
diff changeset
   651
        ].
166
9f6c57a3bce1 no line number bytecode in if-else if not needed
Claus Gittinger <cg@exept.de>
parents: 163
diff changeset
   652
334
cd7491b7ad33 dont code a jump after if-part if it ends in a return.
Claus Gittinger <cg@exept.de>
parents: 309
diff changeset
   653
        aStream nextPut:theByteCode.
cd7491b7ad33 dont code a jump after if-part if it ends in a return.
Claus Gittinger <cg@exept.de>
parents: 309
diff changeset
   654
        pos := aStream position.
cd7491b7ad33 dont code a jump after if-part if it ends in a return.
Claus Gittinger <cg@exept.de>
parents: 309
diff changeset
   655
        aStream nextPut:0.
cd7491b7ad33 dont code a jump after if-part if it ends in a return.
Claus Gittinger <cg@exept.de>
parents: 309
diff changeset
   656
        block1 := argArray at:1.
cd7491b7ad33 dont code a jump after if-part if it ends in a return.
Claus Gittinger <cg@exept.de>
parents: 309
diff changeset
   657
        block1 codeInlineOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler.
cd7491b7ad33 dont code a jump after if-part if it ends in a return.
Claus Gittinger <cg@exept.de>
parents: 309
diff changeset
   658
        needJump := true.
cd7491b7ad33 dont code a jump after if-part if it ends in a return.
Claus Gittinger <cg@exept.de>
parents: 309
diff changeset
   659
        (block1 isBlock and:[block1 endsWithReturn]) ifTrue:[
cd7491b7ad33 dont code a jump after if-part if it ends in a return.
Claus Gittinger <cg@exept.de>
parents: 309
diff changeset
   660
            needJump := false
cd7491b7ad33 dont code a jump after if-part if it ends in a return.
Claus Gittinger <cg@exept.de>
parents: 309
diff changeset
   661
        ].
cd7491b7ad33 dont code a jump after if-part if it ends in a return.
Claus Gittinger <cg@exept.de>
parents: 309
diff changeset
   662
        needJump ifTrue:[
cd7491b7ad33 dont code a jump after if-part if it ends in a return.
Claus Gittinger <cg@exept.de>
parents: 309
diff changeset
   663
            aStream nextPut:#jump.
cd7491b7ad33 dont code a jump after if-part if it ends in a return.
Claus Gittinger <cg@exept.de>
parents: 309
diff changeset
   664
            pos2 := aStream position.
cd7491b7ad33 dont code a jump after if-part if it ends in a return.
Claus Gittinger <cg@exept.de>
parents: 309
diff changeset
   665
            aStream nextPut:0.
cd7491b7ad33 dont code a jump after if-part if it ends in a return.
Claus Gittinger <cg@exept.de>
parents: 309
diff changeset
   666
        ].
cd7491b7ad33 dont code a jump after if-part if it ends in a return.
Claus Gittinger <cg@exept.de>
parents: 309
diff changeset
   667
        code := aStream contents.
cd7491b7ad33 dont code a jump after if-part if it ends in a return.
Claus Gittinger <cg@exept.de>
parents: 309
diff changeset
   668
        code at:pos put:(aStream position).
cd7491b7ad33 dont code a jump after if-part if it ends in a return.
Claus Gittinger <cg@exept.de>
parents: 309
diff changeset
   669
        (argArray at:2) codeInlineOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler.
cd7491b7ad33 dont code a jump after if-part if it ends in a return.
Claus Gittinger <cg@exept.de>
parents: 309
diff changeset
   670
        needJump ifTrue:[
cd7491b7ad33 dont code a jump after if-part if it ends in a return.
Claus Gittinger <cg@exept.de>
parents: 309
diff changeset
   671
            code at:pos2 put:(aStream position)
cd7491b7ad33 dont code a jump after if-part if it ends in a return.
Claus Gittinger <cg@exept.de>
parents: 309
diff changeset
   672
        ]
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   673
    ]
166
9f6c57a3bce1 no line number bytecode in if-else if not needed
Claus Gittinger <cg@exept.de>
parents: 163
diff changeset
   674
434
c48a356d8a34 oops - optimizable or: ... ifTrue/ifFalse generated
Claus Gittinger <cg@exept.de>
parents: 429
diff changeset
   675
    "Modified: 9.11.1996 / 19:53:52 / cg"
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   676
!
7ad01559b262 Initial revision
claus
parents:
diff changeset
   677
104
claus
parents: 103
diff changeset
   678
codeIfOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   679
    "generate code for x ifxxx:[ ... ]"
7ad01559b262 Initial revision
claus
parents:
diff changeset
   680
103
claus
parents: 102
diff changeset
   681
    |pos pos2 theReceiver theArg theByteCode optByteCode subsel code
claus
parents: 102
diff changeset
   682
     needLineNr|
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   683
7ad01559b262 Initial revision
claus
parents:
diff changeset
   684
    theReceiver := receiver.
7ad01559b262 Initial revision
claus
parents:
diff changeset
   685
76
55d64cb1ffea *** empty log message ***
claus
parents: 75
diff changeset
   686
    (theReceiver isMessage) ifTrue:[
308
fe3b95e6d9c0 oops - dont try to inline: (expr or:expr2) ifXXX
Claus Gittinger <cg@exept.de>
parents: 289
diff changeset
   687
        subsel := theReceiver selector.
fe3b95e6d9c0 oops - dont try to inline: (expr or:expr2) ifXXX
Claus Gittinger <cg@exept.de>
parents: 289
diff changeset
   688
fe3b95e6d9c0 oops - dont try to inline: (expr or:expr2) ifXXX
Claus Gittinger <cg@exept.de>
parents: 289
diff changeset
   689
        (subsel == #and:) ifTrue:[
309
11b78163a914 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 308
diff changeset
   690
            theReceiver arg1 isBlock ifTrue:[
308
fe3b95e6d9c0 oops - dont try to inline: (expr or:expr2) ifXXX
Claus Gittinger <cg@exept.de>
parents: 289
diff changeset
   691
                self codeAndIfOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler.
fe3b95e6d9c0 oops - dont try to inline: (expr or:expr2) ifXXX
Claus Gittinger <cg@exept.de>
parents: 289
diff changeset
   692
                ^ self
fe3b95e6d9c0 oops - dont try to inline: (expr or:expr2) ifXXX
Claus Gittinger <cg@exept.de>
parents: 289
diff changeset
   693
            ]
fe3b95e6d9c0 oops - dont try to inline: (expr or:expr2) ifXXX
Claus Gittinger <cg@exept.de>
parents: 289
diff changeset
   694
        ].
fe3b95e6d9c0 oops - dont try to inline: (expr or:expr2) ifXXX
Claus Gittinger <cg@exept.de>
parents: 289
diff changeset
   695
        (subsel == #or:) ifTrue:[
309
11b78163a914 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 308
diff changeset
   696
            theReceiver arg1 isBlock ifTrue:[
308
fe3b95e6d9c0 oops - dont try to inline: (expr or:expr2) ifXXX
Claus Gittinger <cg@exept.de>
parents: 289
diff changeset
   697
                self codeOrIfOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler.
fe3b95e6d9c0 oops - dont try to inline: (expr or:expr2) ifXXX
Claus Gittinger <cg@exept.de>
parents: 289
diff changeset
   698
                ^ self
fe3b95e6d9c0 oops - dont try to inline: (expr or:expr2) ifXXX
Claus Gittinger <cg@exept.de>
parents: 289
diff changeset
   699
            ]
fe3b95e6d9c0 oops - dont try to inline: (expr or:expr2) ifXXX
Claus Gittinger <cg@exept.de>
parents: 289
diff changeset
   700
        ]
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   701
    ].
7ad01559b262 Initial revision
claus
parents:
diff changeset
   702
    (selector == #ifTrue:) ifTrue:[
308
fe3b95e6d9c0 oops - dont try to inline: (expr or:expr2) ifXXX
Claus Gittinger <cg@exept.de>
parents: 289
diff changeset
   703
        theByteCode := #falseJump
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   704
    ] ifFalse:[
308
fe3b95e6d9c0 oops - dont try to inline: (expr or:expr2) ifXXX
Claus Gittinger <cg@exept.de>
parents: 289
diff changeset
   705
        theByteCode := #trueJump
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   706
    ].
7ad01559b262 Initial revision
claus
parents:
diff changeset
   707
    optByteCode := self optimizedConditionFor:theReceiver
308
fe3b95e6d9c0 oops - dont try to inline: (expr or:expr2) ifXXX
Claus Gittinger <cg@exept.de>
parents: 289
diff changeset
   708
                                         with:theByteCode.
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   709
    optByteCode notNil ifTrue:[
308
fe3b95e6d9c0 oops - dont try to inline: (expr or:expr2) ifXXX
Claus Gittinger <cg@exept.de>
parents: 289
diff changeset
   710
        ((optByteCode == #eqJump) or:[optByteCode == #notEqJump]) ifTrue:[
fe3b95e6d9c0 oops - dont try to inline: (expr or:expr2) ifXXX
Claus Gittinger <cg@exept.de>
parents: 289
diff changeset
   711
            theArg := theReceiver arg1
fe3b95e6d9c0 oops - dont try to inline: (expr or:expr2) ifXXX
Claus Gittinger <cg@exept.de>
parents: 289
diff changeset
   712
        ].
fe3b95e6d9c0 oops - dont try to inline: (expr or:expr2) ifXXX
Claus Gittinger <cg@exept.de>
parents: 289
diff changeset
   713
        theReceiver := theReceiver receiver.
fe3b95e6d9c0 oops - dont try to inline: (expr or:expr2) ifXXX
Claus Gittinger <cg@exept.de>
parents: 289
diff changeset
   714
        theByteCode := optByteCode
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   715
    ].
7ad01559b262 Initial revision
claus
parents:
diff changeset
   716
104
claus
parents: 103
diff changeset
   717
    theReceiver codeOn:aStream inBlock:b for:aCompiler.
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   718
    theArg notNil ifTrue:[
308
fe3b95e6d9c0 oops - dont try to inline: (expr or:expr2) ifXXX
Claus Gittinger <cg@exept.de>
parents: 289
diff changeset
   719
        theArg codeOn:aStream inBlock:b for:aCompiler
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   720
    ].
53
c5dd7abf8431 *** empty log message ***
claus
parents: 52
diff changeset
   721
103
claus
parents: 102
diff changeset
   722
    needLineNr := true.
claus
parents: 102
diff changeset
   723
    theArg isNil ifTrue:[
308
fe3b95e6d9c0 oops - dont try to inline: (expr or:expr2) ifXXX
Claus Gittinger <cg@exept.de>
parents: 289
diff changeset
   724
        theReceiver isMessage ifTrue:[
fe3b95e6d9c0 oops - dont try to inline: (expr or:expr2) ifXXX
Claus Gittinger <cg@exept.de>
parents: 289
diff changeset
   725
            (aCompiler hasLineNumber:(theReceiver selector)) ifTrue:[
fe3b95e6d9c0 oops - dont try to inline: (expr or:expr2) ifXXX
Claus Gittinger <cg@exept.de>
parents: 289
diff changeset
   726
                theReceiver lineNumber == lineNr ifTrue:[
fe3b95e6d9c0 oops - dont try to inline: (expr or:expr2) ifXXX
Claus Gittinger <cg@exept.de>
parents: 289
diff changeset
   727
                    needLineNr := false
fe3b95e6d9c0 oops - dont try to inline: (expr or:expr2) ifXXX
Claus Gittinger <cg@exept.de>
parents: 289
diff changeset
   728
                ]
fe3b95e6d9c0 oops - dont try to inline: (expr or:expr2) ifXXX
Claus Gittinger <cg@exept.de>
parents: 289
diff changeset
   729
            ]
fe3b95e6d9c0 oops - dont try to inline: (expr or:expr2) ifXXX
Claus Gittinger <cg@exept.de>
parents: 289
diff changeset
   730
        ]
103
claus
parents: 102
diff changeset
   731
    ].
claus
parents: 102
diff changeset
   732
claus
parents: 102
diff changeset
   733
    needLineNr ifTrue:[
308
fe3b95e6d9c0 oops - dont try to inline: (expr or:expr2) ifXXX
Claus Gittinger <cg@exept.de>
parents: 289
diff changeset
   734
        (lineNr between:1 and:255) ifTrue:[
fe3b95e6d9c0 oops - dont try to inline: (expr or:expr2) ifXXX
Claus Gittinger <cg@exept.de>
parents: 289
diff changeset
   735
            aStream nextPut:#lineno; nextPut:lineNr.
fe3b95e6d9c0 oops - dont try to inline: (expr or:expr2) ifXXX
Claus Gittinger <cg@exept.de>
parents: 289
diff changeset
   736
        ]
53
c5dd7abf8431 *** empty log message ***
claus
parents: 52
diff changeset
   737
    ].
c5dd7abf8431 *** empty log message ***
claus
parents: 52
diff changeset
   738
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   739
    aStream nextPut:theByteCode.
7ad01559b262 Initial revision
claus
parents:
diff changeset
   740
    pos := aStream position.
7ad01559b262 Initial revision
claus
parents:
diff changeset
   741
    aStream nextPut:0.
104
claus
parents: 103
diff changeset
   742
    (argArray at: 1) codeInlineOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler.
76
55d64cb1ffea *** empty log message ***
claus
parents: 75
diff changeset
   743
55d64cb1ffea *** empty log message ***
claus
parents: 75
diff changeset
   744
    code := aStream contents.
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   745
    valueNeeded ifTrue:[
308
fe3b95e6d9c0 oops - dont try to inline: (expr or:expr2) ifXXX
Claus Gittinger <cg@exept.de>
parents: 289
diff changeset
   746
        aStream nextPut:#jump.
fe3b95e6d9c0 oops - dont try to inline: (expr or:expr2) ifXXX
Claus Gittinger <cg@exept.de>
parents: 289
diff changeset
   747
        pos2 := aStream position.
fe3b95e6d9c0 oops - dont try to inline: (expr or:expr2) ifXXX
Claus Gittinger <cg@exept.de>
parents: 289
diff changeset
   748
        aStream nextPut:0.
fe3b95e6d9c0 oops - dont try to inline: (expr or:expr2) ifXXX
Claus Gittinger <cg@exept.de>
parents: 289
diff changeset
   749
        code at:pos put:(aStream position).
fe3b95e6d9c0 oops - dont try to inline: (expr or:expr2) ifXXX
Claus Gittinger <cg@exept.de>
parents: 289
diff changeset
   750
        aStream nextPut:#pushNil.
fe3b95e6d9c0 oops - dont try to inline: (expr or:expr2) ifXXX
Claus Gittinger <cg@exept.de>
parents: 289
diff changeset
   751
        code at:pos2 put:(aStream position)
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   752
    ] ifFalse:[
308
fe3b95e6d9c0 oops - dont try to inline: (expr or:expr2) ifXXX
Claus Gittinger <cg@exept.de>
parents: 289
diff changeset
   753
        code at:pos put:(aStream position)
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   754
    ]
308
fe3b95e6d9c0 oops - dont try to inline: (expr or:expr2) ifXXX
Claus Gittinger <cg@exept.de>
parents: 289
diff changeset
   755
309
11b78163a914 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 308
diff changeset
   756
    "Modified: 18.7.1996 / 10:04:13 / cg"
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   757
!
7ad01559b262 Initial revision
claus
parents:
diff changeset
   758
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   759
codeOn:aStream inBlock:b for:aCompiler
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   760
    self codeOn:aStream inBlock:b valueNeeded:true for:aCompiler
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   761
!
7ad01559b262 Initial revision
claus
parents:
diff changeset
   762
104
claus
parents: 103
diff changeset
   763
codeOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler
245
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   764
    |recType nargs isBuiltIn litIndex cls clsLitIndex code isSpecial
565
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   765
     specialCode stackTop arg1 arg2 arg3 okToInline|
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   766
7ad01559b262 Initial revision
claus
parents:
diff changeset
   767
    argArray isNil ifTrue:[
245
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   768
        nargs := 0
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   769
    ] ifFalse:[
245
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   770
        nargs := argArray size
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   771
    ].
7ad01559b262 Initial revision
claus
parents:
diff changeset
   772
199
1b3b350a3f59 moved bytecode query methods into compiler;
Claus Gittinger <cg@exept.de>
parents: 189
diff changeset
   773
    isBuiltIn := isSpecial := false.
117
claus
parents: 111
diff changeset
   774
    recType := receiver type.
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   775
7ad01559b262 Initial revision
claus
parents:
diff changeset
   776
    (nargs == 0) ifTrue:[
245
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   777
        (recType == #ThisContext) ifTrue:[
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   778
            valueNeeded ifFalse:[
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   779
                "for now, only do it in methods"
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   780
                b isNil ifTrue:[
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   781
                    (selector == #restart) ifTrue:[
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   782
                        aStream nextPut:#jump; nextPut:1.      "jump to start"
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   783
                        ^ self
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   784
                    ].
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   785
                ].
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   786
                (selector == #return) ifTrue:[  "^ nil"
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   787
                    aStream nextPut:#retNil.
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   788
                    ^ self
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   789
                ].
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   790
            ]
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   791
        ].
52
d80ec10c3321 *** empty log message ***
claus
parents: 49
diff changeset
   792
245
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   793
        receiver isBlock ifTrue:[
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   794
            selector == #value ifTrue:[
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   795
                receiver codeInlineOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler.
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   796
                ^ self
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   797
            ].
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   798
            ((selector == #whileTrue) or:[selector == #whileFalse]) ifTrue:[
436
b34370bb0a74 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 434
diff changeset
   799
                ^ self codeWhileOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler.
245
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   800
            ].
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   801
        ].
436
b34370bb0a74 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 434
diff changeset
   802
253
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
   803
        isBuiltIn := aCompiler isBuiltInUnarySelector:selector forReceiver:receiver.
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   804
    ].
7ad01559b262 Initial revision
claus
parents:
diff changeset
   805
7ad01559b262 Initial revision
claus
parents:
diff changeset
   806
    (nargs == 1) ifTrue:[
550
b69b0193058e fixed inline compilation of
Claus Gittinger <cg@exept.de>
parents: 543
diff changeset
   807
        arg1 := argArray at:1.
b69b0193058e fixed inline compilation of
Claus Gittinger <cg@exept.de>
parents: 543
diff changeset
   808
245
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   809
        (recType == #ThisContext) ifTrue:[
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   810
            valueNeeded ifFalse:[
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   811
                (selector == #return:) ifTrue:[
550
b69b0193058e fixed inline compilation of
Claus Gittinger <cg@exept.de>
parents: 543
diff changeset
   812
                    arg1 codeOn:aStream inBlock:b for:aCompiler.  "^ value"
245
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   813
                    aStream nextPut:#retTop.
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   814
                    ^ self
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   815
                ].
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   816
             ].
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   817
        ].
19
84a1ddf215a5 *** empty log message ***
claus
parents: 15
diff changeset
   818
436
b34370bb0a74 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 434
diff changeset
   819
        (arg1 isBlock) ifTrue:[
245
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   820
            ((selector == #ifTrue:) or:[selector == #ifFalse:]) ifTrue:[
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   821
                receiver isBlock ifFalse:[
436
b34370bb0a74 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 434
diff changeset
   822
                    ^ self codeIfOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler.
245
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   823
                ].
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   824
            ].
289
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
   825
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
   826
            (selector == #or:) ifTrue:[
436
b34370bb0a74 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 434
diff changeset
   827
                ^ self codeOrOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler.
245
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   828
            ].
289
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
   829
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
   830
            (selector == #and:) ifTrue:[
436
b34370bb0a74 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 434
diff changeset
   831
                ^ self codeAndOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler.
289
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
   832
            ].
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
   833
245
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   834
            (selector == #timesRepeat:) ifTrue:[
564
ffac5191213f always inline #timesRepeat: (as #> 0 ... - 1)
Claus Gittinger <cg@exept.de>
parents: 561
diff changeset
   835
                "/ now, always inline #timesRepeat:;
ffac5191213f always inline #timesRepeat: (as #> 0 ... - 1)
Claus Gittinger <cg@exept.de>
parents: 561
diff changeset
   836
                "/ the receiver must understand #> and #-
ffac5191213f always inline #timesRepeat: (as #> 0 ... - 1)
Claus Gittinger <cg@exept.de>
parents: 561
diff changeset
   837
                
567
a6e4c44ff326 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 565
diff changeset
   838
               ^ self codeTimesRepeatOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler.
245
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   839
            ].
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   840
245
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   841
            ((selector == #whileTrue:) or:[selector == #whileFalse:]) ifTrue:[
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   842
                (receiver isBlock) ifTrue:[
436
b34370bb0a74 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 434
diff changeset
   843
                    ^ self codeWhileOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler.
245
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   844
                ]
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   845
            ]
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   846
        ].
436
b34370bb0a74 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 434
diff changeset
   847
b34370bb0a74 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 434
diff changeset
   848
        selector == #? ifTrue:[
b34370bb0a74 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 434
diff changeset
   849
            arg1 isMessage ifFalse:[
b34370bb0a74 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 434
diff changeset
   850
                ^ self codeQuestOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler.
b34370bb0a74 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 434
diff changeset
   851
            ]
b34370bb0a74 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 434
diff changeset
   852
        ].
b34370bb0a74 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 434
diff changeset
   853
400
e5cfc008be47 bytecode changes - some more are now special-send codes
Claus Gittinger <cg@exept.de>
parents: 395
diff changeset
   854
        isBuiltIn := aCompiler isBuiltIn1ArgSelector:selector forReceiver:receiver.
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   855
    ].
7ad01559b262 Initial revision
claus
parents:
diff changeset
   856
7ad01559b262 Initial revision
claus
parents:
diff changeset
   857
    (nargs == 2) ifTrue:[
536
9fe0b3be6672 better code for <int> to: <int> do:[unusedArg | ...]
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
   858
        arg1 := argArray at:1.
550
b69b0193058e fixed inline compilation of
Claus Gittinger <cg@exept.de>
parents: 543
diff changeset
   859
        arg2 := argArray at:2.
536
9fe0b3be6672 better code for <int> to: <int> do:[unusedArg | ...]
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
   860
245
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   861
        ((selector == #ifTrue:ifFalse:) or:[selector == #ifFalse:ifTrue:]) ifTrue:[
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   862
            receiver isBlock ifFalse:[
536
9fe0b3be6672 better code for <int> to: <int> do:[unusedArg | ...]
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
   863
                arg1 isBlock ifTrue:[
550
b69b0193058e fixed inline compilation of
Claus Gittinger <cg@exept.de>
parents: 543
diff changeset
   864
                    arg2 isBlock ifTrue:[
436
b34370bb0a74 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 434
diff changeset
   865
                        ^ self codeIfElseOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler.
245
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   866
                    ]
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   867
                ]
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   868
            ]
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   869
        ].
536
9fe0b3be6672 better code for <int> to: <int> do:[unusedArg | ...]
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
   870
9fe0b3be6672 better code for <int> to: <int> do:[unusedArg | ...]
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
   871
        selector == #to:do: ifTrue:[
565
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   872
            okToInline := true.
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   873
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   874
            (arg2 isBlock and:[arg2 numArgs == 1]) ifFalse:[
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   875
                okToInline := false.
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   876
            ].
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   877
            okToInline ifTrue:[
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   878
                ^ self codeToDoOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler
536
9fe0b3be6672 better code for <int> to: <int> do:[unusedArg | ...]
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
   879
            ]
9fe0b3be6672 better code for <int> to: <int> do:[unusedArg | ...]
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
   880
        ].
9fe0b3be6672 better code for <int> to: <int> do:[unusedArg | ...]
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
   881
400
e5cfc008be47 bytecode changes - some more are now special-send codes
Claus Gittinger <cg@exept.de>
parents: 395
diff changeset
   882
        isBuiltIn := aCompiler isBuiltIn2ArgSelector:selector forReceiver:receiver.
531
1d037c37e5a2 code cleanup
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   883
    ].
1d037c37e5a2 code cleanup
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   884
565
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   885
    (nargs == 3) ifTrue:[
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   886
        arg1 := argArray at:1.
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   887
        arg2 := argArray at:2.
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   888
        arg3 := argArray at:3.
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   889
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   890
        selector == #to:by:do: ifTrue:[
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   891
            okToInline := true.
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   892
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   893
            (arg2 isConstant and:[arg2 type == #Integer]) ifFalse:[
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   894
                "/ step must be a constant (need to know how to compare)
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   895
                okToInline := false.
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   896
            ].
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   897
            (arg3 isBlock and:[arg3 numArgs == 1]) ifFalse:[
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   898
                okToInline := false.
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   899
            ].
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   900
            okToInline ifTrue:[
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   901
                ^ self 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
   902
            ]
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   903
        ].
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   904
    ].
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   905
531
1d037c37e5a2 code cleanup
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   906
    isBuiltIn ifFalse:[
1d037c37e5a2 code cleanup
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   907
        specialCode := aCompiler specialSendCodeFor:selector.
1d037c37e5a2 code cleanup
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   908
        isSpecial := specialCode notNil.
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   909
    ].
7ad01559b262 Initial revision
claus
parents:
diff changeset
   910
7ad01559b262 Initial revision
claus
parents:
diff changeset
   911
    "can we use a send-bytecode ?"
199
1b3b350a3f59 moved bytecode query methods into compiler;
Claus Gittinger <cg@exept.de>
parents: 189
diff changeset
   912
    (isBuiltIn or:[isSpecial]) ifTrue:[
245
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   913
        receiver isSuper ifFalse:[
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   914
            receiver codeOn:aStream inBlock:b for:aCompiler.
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   915
            (nargs > 0) ifTrue:[
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   916
                (argArray at:1) codeOn:aStream inBlock:b for:aCompiler.
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   917
                (nargs > 1) ifTrue:[
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   918
                    (argArray at:2) codeOn:aStream inBlock:b for:aCompiler
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   919
                ]
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   920
            ].
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   921
            aStream nextPut:selector.
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   922
            (aCompiler hasLineNumber:selector) ifTrue:[
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   923
                aStream nextPut:lineNr.
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   924
            ].
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   925
            isSpecial ifTrue:[
531
1d037c37e5a2 code cleanup
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   926
                aStream nextPut:specialCode
245
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   927
            ].
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   928
            valueNeeded ifFalse:[
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   929
                aStream nextPut:#drop
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   930
            ].
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   931
            ^ self
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   932
        ]
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   933
    ].
7ad01559b262 Initial revision
claus
parents:
diff changeset
   934
7ad01559b262 Initial revision
claus
parents:
diff changeset
   935
    ((nargs == 0) and:[selector == #yourself]) ifTrue:[
245
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   936
        "yourself is often added to get the receiver -
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   937
         we get it without the yourself-message"
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   938
245
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   939
        valueNeeded ifTrue:[
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   940
            receiver codeOn:aStream inBlock:b for:aCompiler
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   941
        ].
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   942
        ^ self
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   943
    ].
7ad01559b262 Initial revision
claus
parents:
diff changeset
   944
7ad01559b262 Initial revision
claus
parents:
diff changeset
   945
    "no - generate a send"
117
claus
parents: 111
diff changeset
   946
claus
parents: 111
diff changeset
   947
    receiver isSuper ifTrue:[
245
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   948
        cls := aCompiler targetClass.
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   949
        receiver isHere ifTrue:[
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   950
            code := #hereSend.
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   951
        ] ifFalse:[
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   952
            code := #superSend.
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   953
            cls := cls superclass.
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   954
        ].
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   955
        clsLitIndex := aCompiler addLiteral:cls.
117
claus
parents: 111
diff changeset
   956
    ] ifFalse:[
245
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   957
        clsLitIndex := 0.
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   958
    ].
106
claus
parents: 104
diff changeset
   959
117
claus
parents: 111
diff changeset
   960
    litIndex := aCompiler addLiteral:selector.
claus
parents: 111
diff changeset
   961
    (litIndex <= 255 and:[clsLitIndex <= 255]) ifTrue:[
245
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   962
        stackTop := nil.
117
claus
parents: 111
diff changeset
   963
245
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   964
        (recType ~~ #Self) ifTrue:[
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   965
            receiver codeOn:aStream inBlock:b for:aCompiler.
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   966
            receiver isConstant ifTrue:[ 
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   967
                stackTop := receiver
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   968
            ]
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   969
        ].
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   970
        argArray notNil ifTrue:[
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   971
            argArray do:[:arg |
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   972
                (stackTop notNil 
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   973
                and:[arg canReuseAsArg:stackTop]) ifTrue:[
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   974
                    aStream nextPut:#dup.
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   975
"/ 'reuse:' print. stackTop print. ' in ' print. aCompiler selector printNL.
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   976
                ] ifFalse:[
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   977
                    arg codeOn:aStream inBlock:b for:aCompiler.
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   978
                    stackTop := arg.
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   979
                ]
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   980
            ]
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   981
        ].
106
claus
parents: 104
diff changeset
   982
245
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   983
        receiver isSuper ifTrue:[
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   984
            aStream nextPut:code; nextPut:lineNr; nextPut:litIndex; nextPut:nargs; nextPut:clsLitIndex.
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   985
            valueNeeded ifFalse:[
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   986
                aStream nextPut:#drop
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   987
            ].
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   988
            ^ self
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   989
        ].
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   990
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   991
        (nargs <= 3) ifTrue:[
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   992
            |codes|
106
claus
parents: 104
diff changeset
   993
245
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   994
            valueNeeded ifTrue:[
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   995
                (receiver type == #Self) ifTrue:[
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   996
                    codes := #(sendSelf0 sendSelf1 sendSelf2 sendSelf3)
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   997
                ] ifFalse:[
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   998
                    codes := #(send0 send1 send2 send3)
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   999
                ]
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
  1000
            ] ifFalse:[
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
  1001
                (receiver type == #Self) ifTrue:[
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
  1002
                    codes := #(sendSelfDrop0 sendSelfDrop1 sendSelfDrop2 sendSelfDrop3)
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
  1003
                ] ifFalse:[
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
  1004
                    codes := #(sendDrop0 sendDrop1 sendDrop2 sendDrop3)
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
  1005
                ]
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
  1006
            ].
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
  1007
            aStream nextPut:(codes at:(nargs + 1)); nextPut:lineNr; nextPut:litIndex.
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
  1008
            ^ self
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
  1009
        ].
106
claus
parents: 104
diff changeset
  1010
245
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
  1011
        (recType == #Self) ifTrue:[
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
  1012
            code := #sendSelf
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
  1013
        ] ifFalse:[
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
  1014
            valueNeeded ifTrue:[
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
  1015
                code := #send
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
  1016
            ] ifFalse:[
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
  1017
                code := #sendDrop
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
  1018
            ]
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
  1019
        ].
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
  1020
        aStream nextPut:code; nextPut:lineNr; nextPut:litIndex; nextPut:nargs.
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
  1021
        valueNeeded ifFalse:[
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
  1022
            (recType == #Self) ifTrue:[
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
  1023
                aStream nextPut:#drop
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
  1024
            ]
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
  1025
        ].
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
  1026
        ^ self
106
claus
parents: 104
diff changeset
  1027
    ].
claus
parents: 104
diff changeset
  1028
claus
parents: 104
diff changeset
  1029
    "needs 16bit literal index"
117
claus
parents: 111
diff changeset
  1030
48
86595b70333e *** empty log message ***
claus
parents: 47
diff changeset
  1031
    receiver isSuper ifTrue:[
245
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
  1032
        argArray notNil ifTrue:[
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
  1033
            argArray do:[:arg |
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
  1034
                arg codeOn:aStream inBlock:b for:aCompiler
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
  1035
            ]
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
  1036
        ].
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
  1037
        receiver isHere ifTrue:[
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
  1038
            code := #hereSendL
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
  1039
        ] ifFalse:[
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
  1040
            code := #superSendL.
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
  1041
        ].
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
  1042
        aStream nextPut:code; nextPut:lineNr; nextPut:litIndex; nextPut:0; nextPut:nargs; nextPut:clsLitIndex; nextPut:0.
117
claus
parents: 111
diff changeset
  1043
    ] ifFalse:[
245
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
  1044
        recType ~~ #Self ifTrue:[
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
  1045
            receiver codeOn:aStream inBlock:b for:aCompiler.
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
  1046
        ].
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
  1047
        argArray notNil ifTrue:[
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
  1048
            argArray do:[:arg |
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
  1049
                arg codeOn:aStream inBlock:b for:aCompiler
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
  1050
            ]
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
  1051
        ].
117
claus
parents: 111
diff changeset
  1052
245
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
  1053
        recType == #Self ifTrue:[
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
  1054
            code := #sendSelfL
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
  1055
        ] ifFalse:[
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
  1056
            code := #sendL
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
  1057
        ].
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
  1058
        aStream nextPut:code; nextPut:lineNr; nextPut:litIndex; nextPut:0; nextPut:nargs.
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1059
    ].
117
claus
parents: 111
diff changeset
  1060
    valueNeeded ifFalse:[
245
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
  1061
        aStream nextPut:#drop
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1062
    ].
117
claus
parents: 111
diff changeset
  1063
claus
parents: 111
diff changeset
  1064
    "Modified: 3.9.1995 / 12:55:42 / claus"
567
a6e4c44ff326 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 565
diff changeset
  1065
    "Modified: 27.6.1997 / 15:08:45 / cg"
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1066
!
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1067
338
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1068
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
  1069
    "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
  1070
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1071
    |theByteCode optByteCode theReceiver theArg pos1 pos2 pos3 code here jmp|
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1072
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1073
    theByteCode := #trueJump.
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1074
    theReceiver := receiver receiver.
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1075
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1076
    optByteCode := self optimizedConditionFor:theReceiver
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1077
                                         with:theByteCode.
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1078
    optByteCode notNil ifTrue:[
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1079
        ((optByteCode == #eqJump) or:[optByteCode == #notEqJump]) ifTrue:[
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1080
            theArg := theReceiver arg1
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1081
        ].
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1082
        theReceiver := theReceiver receiver.
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1083
        theByteCode := optByteCode
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1084
    ].
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1085
    "/ 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
  1086
    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
  1087
    theArg notNil ifTrue:[
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1088
        theArg 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
  1089
    ].
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1090
    aStream nextPut:theByteCode.
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1091
    pos1 := aStream position.   "/ remember branch target of left-ok branch
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1092
    aStream nextPut:0.
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1093
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1094
    "/ 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
  1095
    theReceiver := receiver arg1.
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1096
    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
  1097
    (selector == #ifTrue:ifFalse:) ifTrue:[
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1098
        jmp := #falseJump
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1099
    ] ifFalse:[
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1100
        jmp := #trueJump
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1101
    ].
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1102
    aStream nextPut:jmp.
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1103
    pos2 := aStream position.   "/ remember branch target of right-fail branch 
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1104
    aStream nextPut:0.
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1105
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1106
    code := aStream contents.
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1107
    (selector == #ifTrue:ifFalse:) ifTrue:[
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1108
        code at:pos1 put:(aStream position)
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1109
    ].
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1110
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1111
    "/ code the if-block
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1112
    (argArray at: 1) codeInlineOn: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
  1113
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1114
    aStream nextPut:#jump.
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1115
    pos3 := aStream position.
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1116
    aStream nextPut:0.
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1117
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1118
    here := aStream position.
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1119
    (selector == #ifFalse:ifTrue:) ifTrue:[
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1120
        code at:pos1 put:here
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1121
    ].
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1122
    code at:pos2 put:here.
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1123
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1124
    "/ code the else-block
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1125
    (argArray at: 2) codeInlineOn: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
  1126
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1127
    code at:pos3 put:(aStream position)
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1128
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1129
    "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
  1130
!
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1131
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1132
codeOrIfOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1133
    "generate code for (x or:[y]) ifxxx:[ ... ]"
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1134
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1135
    |theByteCode optByteCode theReceiver theArg pos1 pos2 pos3 code here jmp|
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1136
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1137
    theByteCode := #trueJump.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1138
    theReceiver := receiver receiver.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1139
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1140
    optByteCode := self optimizedConditionFor:theReceiver with:theByteCode.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1141
    optByteCode notNil ifTrue:[
434
c48a356d8a34 oops - optimizable or: ... ifTrue/ifFalse generated
Claus Gittinger <cg@exept.de>
parents: 429
diff changeset
  1142
        ((optByteCode == #eqJump) or:[optByteCode == #notEqJump]) ifTrue:[
c48a356d8a34 oops - optimizable or: ... ifTrue/ifFalse generated
Claus Gittinger <cg@exept.de>
parents: 429
diff changeset
  1143
            theArg := theReceiver arg1
c48a356d8a34 oops - optimizable or: ... ifTrue/ifFalse generated
Claus Gittinger <cg@exept.de>
parents: 429
diff changeset
  1144
        ].
c48a356d8a34 oops - optimizable or: ... ifTrue/ifFalse generated
Claus Gittinger <cg@exept.de>
parents: 429
diff changeset
  1145
        theReceiver := theReceiver receiver.
c48a356d8a34 oops - optimizable or: ... ifTrue/ifFalse generated
Claus Gittinger <cg@exept.de>
parents: 429
diff changeset
  1146
        theByteCode := optByteCode
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1147
    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1148
    theReceiver codeOn:aStream inBlock:b for:aCompiler.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1149
    theArg notNil ifTrue:[
434
c48a356d8a34 oops - optimizable or: ... ifTrue/ifFalse generated
Claus Gittinger <cg@exept.de>
parents: 429
diff changeset
  1150
        theArg codeOn:aStream inBlock:b for:aCompiler
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1151
    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1152
    aStream nextPut:theByteCode.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1153
    pos1 := aStream position.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1154
    aStream nextPut:0.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1155
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1156
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1157
    theReceiver := receiver arg1.
434
c48a356d8a34 oops - optimizable or: ... ifTrue/ifFalse generated
Claus Gittinger <cg@exept.de>
parents: 429
diff changeset
  1158
    theArg := nil.
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1159
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1160
"new:"
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1161
    (selector == #ifTrue:) ifTrue:[
434
c48a356d8a34 oops - optimizable or: ... ifTrue/ifFalse generated
Claus Gittinger <cg@exept.de>
parents: 429
diff changeset
  1162
        theByteCode := #falseJump
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1163
    ] ifFalse:[
434
c48a356d8a34 oops - optimizable or: ... ifTrue/ifFalse generated
Claus Gittinger <cg@exept.de>
parents: 429
diff changeset
  1164
        theByteCode := #trueJump
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1165
    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1166
    optByteCode := self optimizedConditionFor:theReceiver with:theByteCode.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1167
    optByteCode notNil ifTrue:[
434
c48a356d8a34 oops - optimizable or: ... ifTrue/ifFalse generated
Claus Gittinger <cg@exept.de>
parents: 429
diff changeset
  1168
        theReceiver isBlock ifTrue:[
c48a356d8a34 oops - optimizable or: ... ifTrue/ifFalse generated
Claus Gittinger <cg@exept.de>
parents: 429
diff changeset
  1169
            theReceiver := theReceiver statements expression
c48a356d8a34 oops - optimizable or: ... ifTrue/ifFalse generated
Claus Gittinger <cg@exept.de>
parents: 429
diff changeset
  1170
        ].
c48a356d8a34 oops - optimizable or: ... ifTrue/ifFalse generated
Claus Gittinger <cg@exept.de>
parents: 429
diff changeset
  1171
        ((optByteCode == #eqJump) or:[optByteCode == #notEqJump]) ifTrue:[
c48a356d8a34 oops - optimizable or: ... ifTrue/ifFalse generated
Claus Gittinger <cg@exept.de>
parents: 429
diff changeset
  1172
            theArg := theReceiver arg1
c48a356d8a34 oops - optimizable or: ... ifTrue/ifFalse generated
Claus Gittinger <cg@exept.de>
parents: 429
diff changeset
  1173
        ].
c48a356d8a34 oops - optimizable or: ... ifTrue/ifFalse generated
Claus Gittinger <cg@exept.de>
parents: 429
diff changeset
  1174
        theReceiver := theReceiver receiver.
c48a356d8a34 oops - optimizable or: ... ifTrue/ifFalse generated
Claus Gittinger <cg@exept.de>
parents: 429
diff changeset
  1175
        theByteCode := optByteCode.
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1176
434
c48a356d8a34 oops - optimizable or: ... ifTrue/ifFalse generated
Claus Gittinger <cg@exept.de>
parents: 429
diff changeset
  1177
        theReceiver codeOn:aStream inBlock:b for:aCompiler.
c48a356d8a34 oops - optimizable or: ... ifTrue/ifFalse generated
Claus Gittinger <cg@exept.de>
parents: 429
diff changeset
  1178
        theArg notNil ifTrue:[
c48a356d8a34 oops - optimizable or: ... ifTrue/ifFalse generated
Claus Gittinger <cg@exept.de>
parents: 429
diff changeset
  1179
            theArg codeOn:aStream inBlock:b for:aCompiler
c48a356d8a34 oops - optimizable or: ... ifTrue/ifFalse generated
Claus Gittinger <cg@exept.de>
parents: 429
diff changeset
  1180
        ].
c48a356d8a34 oops - optimizable or: ... ifTrue/ifFalse generated
Claus Gittinger <cg@exept.de>
parents: 429
diff changeset
  1181
        aStream nextPut:theByteCode.
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1182
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1183
    ] ifFalse:[
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1184
"org"
434
c48a356d8a34 oops - optimizable or: ... ifTrue/ifFalse generated
Claus Gittinger <cg@exept.de>
parents: 429
diff changeset
  1185
        theReceiver codeInlineOn:aStream inBlock:b for:aCompiler.
c48a356d8a34 oops - optimizable or: ... ifTrue/ifFalse generated
Claus Gittinger <cg@exept.de>
parents: 429
diff changeset
  1186
        (selector == #ifTrue:) ifTrue:[
c48a356d8a34 oops - optimizable or: ... ifTrue/ifFalse generated
Claus Gittinger <cg@exept.de>
parents: 429
diff changeset
  1187
            jmp := #falseJump
c48a356d8a34 oops - optimizable or: ... ifTrue/ifFalse generated
Claus Gittinger <cg@exept.de>
parents: 429
diff changeset
  1188
        ] ifFalse:[
c48a356d8a34 oops - optimizable or: ... ifTrue/ifFalse generated
Claus Gittinger <cg@exept.de>
parents: 429
diff changeset
  1189
            jmp := #trueJump
c48a356d8a34 oops - optimizable or: ... ifTrue/ifFalse generated
Claus Gittinger <cg@exept.de>
parents: 429
diff changeset
  1190
        ].
c48a356d8a34 oops - optimizable or: ... ifTrue/ifFalse generated
Claus Gittinger <cg@exept.de>
parents: 429
diff changeset
  1191
        aStream nextPut:jmp
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1192
    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1193
    pos2 := aStream position.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1194
    aStream nextPut:0.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1195
    (selector == #ifTrue:) ifTrue:[
434
c48a356d8a34 oops - optimizable or: ... ifTrue/ifFalse generated
Claus Gittinger <cg@exept.de>
parents: 429
diff changeset
  1196
        (aStream contents) at:pos1 put:(aStream position)
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1197
    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1198
    (argArray at: 1) codeInlineOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1199
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1200
    code := aStream contents.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1201
    valueNeeded ifTrue:[
434
c48a356d8a34 oops - optimizable or: ... ifTrue/ifFalse generated
Claus Gittinger <cg@exept.de>
parents: 429
diff changeset
  1202
        aStream nextPut:#jump.
c48a356d8a34 oops - optimizable or: ... ifTrue/ifFalse generated
Claus Gittinger <cg@exept.de>
parents: 429
diff changeset
  1203
        pos3 := aStream position.
c48a356d8a34 oops - optimizable or: ... ifTrue/ifFalse generated
Claus Gittinger <cg@exept.de>
parents: 429
diff changeset
  1204
        aStream nextPut:0.
c48a356d8a34 oops - optimizable or: ... ifTrue/ifFalse generated
Claus Gittinger <cg@exept.de>
parents: 429
diff changeset
  1205
        here := aStream position.
c48a356d8a34 oops - optimizable or: ... ifTrue/ifFalse generated
Claus Gittinger <cg@exept.de>
parents: 429
diff changeset
  1206
        (selector == #ifFalse:) ifTrue:[
c48a356d8a34 oops - optimizable or: ... ifTrue/ifFalse generated
Claus Gittinger <cg@exept.de>
parents: 429
diff changeset
  1207
            code at:pos1 put:here
c48a356d8a34 oops - optimizable or: ... ifTrue/ifFalse generated
Claus Gittinger <cg@exept.de>
parents: 429
diff changeset
  1208
        ].
c48a356d8a34 oops - optimizable or: ... ifTrue/ifFalse generated
Claus Gittinger <cg@exept.de>
parents: 429
diff changeset
  1209
        code at:pos2 put:here.
c48a356d8a34 oops - optimizable or: ... ifTrue/ifFalse generated
Claus Gittinger <cg@exept.de>
parents: 429
diff changeset
  1210
        aStream nextPut:#pushNil.
c48a356d8a34 oops - optimizable or: ... ifTrue/ifFalse generated
Claus Gittinger <cg@exept.de>
parents: 429
diff changeset
  1211
        code at:pos3 put:(aStream position)
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1212
    ] ifFalse:[
434
c48a356d8a34 oops - optimizable or: ... ifTrue/ifFalse generated
Claus Gittinger <cg@exept.de>
parents: 429
diff changeset
  1213
        here := aStream position.
c48a356d8a34 oops - optimizable or: ... ifTrue/ifFalse generated
Claus Gittinger <cg@exept.de>
parents: 429
diff changeset
  1214
        (selector == #ifFalse:) ifTrue:[
c48a356d8a34 oops - optimizable or: ... ifTrue/ifFalse generated
Claus Gittinger <cg@exept.de>
parents: 429
diff changeset
  1215
            code at:pos1 put:here
c48a356d8a34 oops - optimizable or: ... ifTrue/ifFalse generated
Claus Gittinger <cg@exept.de>
parents: 429
diff changeset
  1216
        ].
c48a356d8a34 oops - optimizable or: ... ifTrue/ifFalse generated
Claus Gittinger <cg@exept.de>
parents: 429
diff changeset
  1217
        code at:pos2 put:here
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1218
    ]
434
c48a356d8a34 oops - optimizable or: ... ifTrue/ifFalse generated
Claus Gittinger <cg@exept.de>
parents: 429
diff changeset
  1219
c48a356d8a34 oops - optimizable or: ... ifTrue/ifFalse generated
Claus Gittinger <cg@exept.de>
parents: 429
diff changeset
  1220
    "Modified: 9.11.1996 / 19:52:26 / cg"
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1221
!
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1222
289
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  1223
codeOrOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  1224
    "generate code for (x or:[y])"
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  1225
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  1226
    |pos1 rightExpr|
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  1227
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  1228
    receiver codeOn:aStream inBlock:b for:aCompiler.
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  1229
    valueNeeded ifTrue:[
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  1230
        aStream nextPut:#dup.
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  1231
    ].
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  1232
    aStream nextPut:#trueJump.
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  1233
    pos1 := aStream position.
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  1234
    aStream nextPut:0.
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  1235
    valueNeeded ifTrue:[
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  1236
        aStream nextPut:#drop.
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  1237
    ].
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  1238
    rightExpr := argArray at:1.
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  1239
    rightExpr codeInlineOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler.
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  1240
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  1241
    (aStream contents) at:pos1 put:(aStream position)
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  1242
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  1243
    "Created: 17.6.1996 / 15:40:22 / cg"
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  1244
    "Modified: 17.6.1996 / 15:47:22 / cg"
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  1245
!
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  1246
436
b34370bb0a74 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 434
diff changeset
  1247
codeQuestOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler
b34370bb0a74 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 434
diff changeset
  1248
    "generate code for x ? y. However, this is only done for non-send
b34370bb0a74 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 434
diff changeset
  1249
     args."
b34370bb0a74 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 434
diff changeset
  1250
b34370bb0a74 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 434
diff changeset
  1251
    |pos code|
b34370bb0a74 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 434
diff changeset
  1252
b34370bb0a74 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 434
diff changeset
  1253
    receiver codeOn:aStream inBlock:b for:aCompiler.
b34370bb0a74 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 434
diff changeset
  1254
    aStream nextPut:#dup.
b34370bb0a74 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 434
diff changeset
  1255
    aStream nextPut:#notNilJump.
b34370bb0a74 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 434
diff changeset
  1256
    pos := aStream position.
437
994414f5126a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 436
diff changeset
  1257
    aStream nextPut:0.
436
b34370bb0a74 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 434
diff changeset
  1258
b34370bb0a74 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 434
diff changeset
  1259
    aStream nextPut:#drop.
b34370bb0a74 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 434
diff changeset
  1260
    (argArray at: 1) codeOn:aStream inBlock:b for:aCompiler.
b34370bb0a74 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 434
diff changeset
  1261
b34370bb0a74 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 434
diff changeset
  1262
    code := aStream contents.
b34370bb0a74 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 434
diff changeset
  1263
    code at:pos put:(aStream position)
b34370bb0a74 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 434
diff changeset
  1264
b34370bb0a74 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 434
diff changeset
  1265
    "Created: 10.11.1996 / 18:28:57 / cg"
b34370bb0a74 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 434
diff changeset
  1266
!
b34370bb0a74 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 434
diff changeset
  1267
104
claus
parents: 103
diff changeset
  1268
codeSendOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1269
    "like code on, but assumes that receiver has already been
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1270
     coded onto stack - needed for cascade"
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1271
189
673580572edd fixed cascades involving super sends (i.e. super foo; bar)
Claus Gittinger <cg@exept.de>
parents: 186
diff changeset
  1272
    |nargs isBuiltIn code codeL litIndex cls clsLitIndex|
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1273
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1274
    argArray isNil ifTrue:[
253
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
  1275
        nargs := 0
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1276
    ] ifFalse:[
253
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
  1277
        nargs := argArray size
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1278
    ].
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1279
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1280
    isBuiltIn := false.
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1281
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1282
    (nargs == 0) ifTrue:[
253
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
  1283
        isBuiltIn := aCompiler isBuiltInUnarySelector:selector forReceiver:receiver
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1284
    ].
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1285
    (nargs == 1) ifTrue:[
253
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
  1286
        isBuiltIn := aCompiler isBuiltIn1ArgSelector:selector forReceiver:receiver
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1287
    ].
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1288
    (nargs == 2) ifTrue:[
253
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
  1289
        isBuiltIn := aCompiler isBuiltIn2ArgSelector:selector forReceiver:receiver
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1290
    ].
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1291
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1292
    "can we use a send-bytecode ?"
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1293
    isBuiltIn ifTrue:[
253
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
  1294
        receiver isSuper ifFalse:[
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
  1295
            (nargs > 0) ifTrue:[
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
  1296
                (argArray at:1) codeOn:aStream inBlock:b for:aCompiler.
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
  1297
                (nargs > 1) ifTrue:[
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
  1298
                    (argArray at:2) codeOn:aStream inBlock:b for:aCompiler
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
  1299
                ]
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
  1300
            ].
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
  1301
            aStream nextPut:selector.
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
  1302
            (aCompiler hasLineNumber:selector) ifTrue:[
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
  1303
                aStream nextPut:lineNr.
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
  1304
            ].
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
  1305
            valueNeeded ifFalse:[
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
  1306
                aStream nextPut:#drop
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
  1307
            ].
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
  1308
            ^ self
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
  1309
        ]
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1310
    ].
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1311
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1312
    argArray notNil ifTrue:[
253
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
  1313
        argArray do:[:arg |
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
  1314
            arg codeOn:aStream inBlock:b for:aCompiler
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
  1315
        ]
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1316
    ].
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1317
48
86595b70333e *** empty log message ***
claus
parents: 47
diff changeset
  1318
    receiver isSuper ifTrue:[
189
673580572edd fixed cascades involving super sends (i.e. super foo; bar)
Claus Gittinger <cg@exept.de>
parents: 186
diff changeset
  1319
253
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
  1320
        cls := aCompiler targetClass.
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
  1321
        receiver isHere ifTrue:[
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
  1322
            code := #hereSend.
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
  1323
            codeL := #hereSendL
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
  1324
        ] ifFalse:[
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
  1325
            code := #superSend.
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
  1326
            codeL := #superSend.
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
  1327
            cls := cls superclass.
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
  1328
        ].
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
  1329
        clsLitIndex := aCompiler addLiteral:cls.
189
673580572edd fixed cascades involving super sends (i.e. super foo; bar)
Claus Gittinger <cg@exept.de>
parents: 186
diff changeset
  1330
253
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
  1331
        litIndex := aCompiler addLiteral:selector.
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
  1332
        (litIndex <= 255 and:[clsLitIndex <= 255]) ifTrue:[
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
  1333
            aStream nextPut:code; nextPut:lineNr; nextPut:litIndex; nextPut:nargs; nextPut:clsLitIndex.
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
  1334
        ] ifFalse:[
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
  1335
            aStream nextPut:codeL; nextPut:lineNr; nextPut:litIndex; nextPut:0; nextPut:nargs; nextPut:clsLitIndex; nextPut:0.
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
  1336
        ].
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
  1337
        valueNeeded ifFalse:[
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
  1338
            aStream nextPut:#drop
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
  1339
        ].
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
  1340
        ^ self
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1341
    ].
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1342
    (nargs == 0) ifTrue:[
253
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
  1343
        (selector == #yourself) ifTrue:[
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
  1344
            "yourself is often added to get the receiver -
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
  1345
             we get it without the yourself-message"
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1346
253
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
  1347
            valueNeeded ifFalse:[
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
  1348
                aStream nextPut:#drop
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
  1349
            ].
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
  1350
            ^ self
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
  1351
        ].
49
02660b790c3e *** empty log message ***
claus
parents: 48
diff changeset
  1352
    ].
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1353
117
claus
parents: 111
diff changeset
  1354
    litIndex := aCompiler addLiteral:selector.
claus
parents: 111
diff changeset
  1355
    litIndex <= 255 ifTrue:[
253
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
  1356
        (nargs <= 3) ifTrue:[
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
  1357
            valueNeeded ifTrue:[
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
  1358
                code := #(send0 send1 send2 send3) at:(nargs+1).
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
  1359
            ] ifFalse:[
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
  1360
                code := #(sendDrop0 sendDrop1 sendDrop2 sendDrop3) at:(nargs+1).
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
  1361
            ].
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
  1362
            aStream nextPut:code; nextPut:lineNr; nextPut:litIndex.
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
  1363
            ^ self
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
  1364
        ].
106
claus
parents: 104
diff changeset
  1365
253
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
  1366
        valueNeeded ifTrue:[
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
  1367
            code := #send
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
  1368
        ] ifFalse:[
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
  1369
            code := #sendDrop
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
  1370
        ].
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
  1371
        aStream nextPut:code; nextPut:lineNr; nextPut:litIndex; nextPut:nargs.
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
  1372
        ^ self
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1373
    ].
49
02660b790c3e *** empty log message ***
claus
parents: 48
diff changeset
  1374
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1375
    valueNeeded ifTrue:[
253
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
  1376
        code := #sendL
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1377
    ] ifFalse:[
253
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
  1378
        code := #sendDropL
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1379
    ].
117
claus
parents: 111
diff changeset
  1380
    aStream nextPut:code; nextPut:lineNr; nextPut:litIndex; nextPut:0; nextPut:nargs
189
673580572edd fixed cascades involving super sends (i.e. super foo; bar)
Claus Gittinger <cg@exept.de>
parents: 186
diff changeset
  1381
253
759ba0ddb672 oops - must check for receiver when attempting built-in basicNew
Claus Gittinger <cg@exept.de>
parents: 245
diff changeset
  1382
    "Modified: 17.4.1996 / 22:33:35 / cg"
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1383
!
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1384
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1385
codeTimesRepeatOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1386
    "generate code for n timesRepeat:[ ... ]"
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1387
349
7632e597a3df no need to keep receiver on stack for
Claus Gittinger <cg@exept.de>
parents: 338
diff changeset
  1388
    |pos pos2 theReceiver lateEval|
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1389
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1390
    theReceiver := receiver.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1391
    theReceiver 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
  1392
7632e597a3df no need to keep receiver on stack for
Claus Gittinger <cg@exept.de>
parents: 338
diff changeset
  1393
    lateEval := false.
528
0a35ed44989f oops - timesRepeat dupped one too many
Claus Gittinger <cg@exept.de>
parents: 437
diff changeset
  1394
349
7632e597a3df no need to keep receiver on stack for
Claus Gittinger <cg@exept.de>
parents: 338
diff changeset
  1395
    valueNeeded ifTrue:[
528
0a35ed44989f oops - timesRepeat dupped one too many
Claus Gittinger <cg@exept.de>
parents: 437
diff changeset
  1396
        "/ easily reconstructable - no need to keep on stack
349
7632e597a3df no need to keep receiver on stack for
Claus Gittinger <cg@exept.de>
parents: 338
diff changeset
  1397
        theReceiver isConstant ifTrue:[
7632e597a3df no need to keep receiver on stack for
Claus Gittinger <cg@exept.de>
parents: 338
diff changeset
  1398
            (theReceiver evaluate isMemberOf:SmallInteger) ifTrue:[
7632e597a3df no need to keep receiver on stack for
Claus Gittinger <cg@exept.de>
parents: 338
diff changeset
  1399
                lateEval := true.
7632e597a3df no need to keep receiver on stack for
Claus Gittinger <cg@exept.de>
parents: 338
diff changeset
  1400
            ]
7632e597a3df no need to keep receiver on stack for
Claus Gittinger <cg@exept.de>
parents: 338
diff changeset
  1401
        ].
528
0a35ed44989f oops - timesRepeat dupped one too many
Claus Gittinger <cg@exept.de>
parents: 437
diff changeset
  1402
        lateEval ifFalse:[
0a35ed44989f oops - timesRepeat dupped one too many
Claus Gittinger <cg@exept.de>
parents: 437
diff changeset
  1403
            aStream nextPut:#dup
0a35ed44989f oops - timesRepeat dupped one too many
Claus Gittinger <cg@exept.de>
parents: 437
diff changeset
  1404
        ].
349
7632e597a3df no need to keep receiver on stack for
Claus Gittinger <cg@exept.de>
parents: 338
diff changeset
  1405
    ].
96
claus
parents: 95
diff changeset
  1406
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1407
    pos := aStream position.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1408
    aStream nextPut:#pushgt0; nextPut:lineNr; nextPut:#falseJump.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1409
    pos2 := aStream position.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1410
    aStream nextPut:0.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1411
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1412
    (argArray at:1) codeInlineOn:aStream inBlock:b valueNeeded:false for:aCompiler.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1413
    aStream nextPut:#minus1; nextPut:lineNr; nextPut:#jump; nextPut:pos.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1414
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1415
    (aStream contents) at:pos2 put:(aStream position).
528
0a35ed44989f oops - timesRepeat dupped one too many
Claus Gittinger <cg@exept.de>
parents: 437
diff changeset
  1416
    aStream nextPut:#drop.  "/ drop run variable
349
7632e597a3df no need to keep receiver on stack for
Claus Gittinger <cg@exept.de>
parents: 338
diff changeset
  1417
    lateEval ifTrue:[
7632e597a3df no need to keep receiver on stack for
Claus Gittinger <cg@exept.de>
parents: 338
diff changeset
  1418
        theReceiver codeOn:aStream inBlock:b for:aCompiler.
7632e597a3df no need to keep receiver on stack for
Claus Gittinger <cg@exept.de>
parents: 338
diff changeset
  1419
    ]
7632e597a3df no need to keep receiver on stack for
Claus Gittinger <cg@exept.de>
parents: 338
diff changeset
  1420
528
0a35ed44989f oops - timesRepeat dupped one too many
Claus Gittinger <cg@exept.de>
parents: 437
diff changeset
  1421
    "Modified: 27.5.1997 / 14:28:49 / cg"
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1422
!
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1423
565
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1424
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
  1425
    "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
  1426
565
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1427
    |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
  1428
     stepVal stopVarIndex|
561
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  1429
565
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1430
    "/ 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
  1431
    "/ 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
  1432
    "/ 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
  1433
    "/ 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
  1434
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  1435
    start := receiver.
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  1436
    stop := (argArray at:1).
565
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1437
    step := (argArray at:2).
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1438
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1439
"/    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
  1440
"/    (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
  1441
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1442
    step 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
  1443
    stepVal := step evaluate.
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1444
    (stepVal isMemberOf:SmallInteger) ifFalse:[self halt:'should not happen'].
561
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  1445
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  1446
    start codeOn:aStream inBlock:b for:aCompiler.
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  1447
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  1448
    lateEval := false.
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  1449
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  1450
    valueNeeded ifTrue:[
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  1451
        "/ easily reconstructable - no need to keep on stack
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  1452
        start isConstant ifTrue:[
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  1453
            (start evaluate isMemberOf:SmallInteger) ifTrue:[
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  1454
                lateEval := true.
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  1455
            ]
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  1456
        ].
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  1457
        lateEval ifFalse:[
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  1458
            aStream nextPut:#dup
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  1459
        ].
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  1460
    ].
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  1461
565
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1462
    "/ 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
  1463
    "/  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
  1464
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1465
    (stop isConstant and:[stop type == #Integer]) ifFalse:[
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1466
        "/ a method/blockArg is constant as well ...
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1467
        (stop isVariable and:[stop isArgument]) ifFalse:[
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1468
            stop 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
  1469
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1470
            b isNil ifTrue:[
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1471
                stopVarIndex := aCompiler addTempVar.
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1472
                aStream nextPut:#storeMethodVar; nextPut:stopVarIndex.
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1473
            ] ifFalse:[
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1474
                stopVarIndex := b addTempVar.
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1475
                aStream nextPut:#storeBlockVar; nextPut:stopVarIndex.
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1476
            ].
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1477
        ]
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1478
    ].
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1479
561
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  1480
    pos := aStream position.
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  1481
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  1482
    aStream nextPut:#dup.
565
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1483
    stopVarIndex notNil ifTrue:[
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1484
        b isNil ifTrue:[
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1485
            aStream nextPut:#pushMethodVar; nextPut:stopVarIndex.
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1486
        ] ifFalse:[
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1487
            aStream nextPut:#pushBlockVar; nextPut:stopVarIndex.
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1488
        ]
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1489
    ] ifFalse:[
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1490
        stop 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
  1491
    ].
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1492
    stepVal > 0 ifTrue:[
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1493
        aStream nextPut:#>.
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1494
    ] ifFalse:[
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1495
        aStream nextPut:#<.
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1496
    ].
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1497
    (aCompiler hasLineNumber:selector) ifTrue:[
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1498
        aStream nextPut:lineNr.
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1499
    ].
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1500
    aStream nextPut:#trueJump.
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1501
    pos2 := aStream position.
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1502
    aStream nextPut:0.
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1503
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1504
    theBlock := argArray at:3.
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1505
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1506
    "/ 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
  1507
    "/ the loop ...
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1508
    b isNil ifTrue:[
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1509
        loopVarIndex := aCompiler addTempVar.
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1510
        aStream nextPut:#dup.
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1511
        aStream nextPut:#storeMethodVar; nextPut:loopVarIndex.
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1512
    ] ifFalse:[
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1513
        loopVarIndex := b addTempVar.
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1514
        aStream nextPut:#dup.
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1515
        aStream nextPut:#storeBlockVar; nextPut:loopVarIndex.
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1516
    ].
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1517
    theBlock indexOfFirstTemp:loopVarIndex.
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1518
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1519
    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
  1520
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1521
    "/ increment/decrement counter & jump back.
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1522
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1523
    stepVal == 1 ifTrue:[
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1524
        aStream nextPut:#plus1; nextPut:lineNr.
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1525
    ] ifFalse:[
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1526
        stepVal == -1 ifTrue:[
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1527
            aStream nextPut:#minus1; nextPut:lineNr.
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1528
        ] ifFalse:[
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1529
            step 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
  1530
            aStream nextPut:#+.
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1531
            (aCompiler hasLineNumber:#+) ifTrue:[
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1532
                aStream nextPut:lineNr.
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1533
            ].
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1534
        ]
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1535
    ].
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1536
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1537
    aStream nextPut:#jump; nextPut:pos.
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1538
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1539
    (aStream contents) at:pos2 put:(aStream position).
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1540
    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
  1541
    lateEval ifTrue:[
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1542
        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
  1543
    ].
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1544
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1545
    "/ 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
  1546
    "/ (its integer, anyway).
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1547
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1548
    b isNil ifTrue:[
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1549
        aCompiler removeTempVar
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1550
    ] ifFalse:[
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1551
        b removeTempVar
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1552
    ].
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1553
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1554
    stopVarIndex notNil ifTrue:[
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1555
        b isNil ifTrue:[
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1556
            aCompiler removeTempVar
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1557
        ] ifFalse:[
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1558
            b removeTempVar
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1559
        ]
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1560
    ].
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1561
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1562
    "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
  1563
    "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
  1564
!
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1565
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1566
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
  1567
    "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
  1568
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1569
    |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
  1570
     stopVarIndex|
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1571
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1572
    "/ 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
  1573
    "/ 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
  1574
    "/ 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
  1575
    "/ 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
  1576
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1577
    start := receiver.
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1578
    stop := (argArray at:1).
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1579
"/    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
  1580
"/    (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
  1581
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1582
    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
  1583
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1584
    lateEval := false.
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1585
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1586
    valueNeeded ifTrue:[
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1587
        "/ easily reconstructable - no need to keep on stack
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1588
        start isConstant ifTrue:[
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1589
            (start evaluate isMemberOf:SmallInteger) ifTrue:[
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1590
                lateEval := true.
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1591
            ]
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1592
        ].
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1593
        lateEval ifFalse:[
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1594
            aStream nextPut:#dup
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1595
        ].
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1596
    ].
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1597
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1598
    "/ 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
  1599
    "/  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
  1600
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1601
    (stop isConstant and:[stop type == #Integer]) ifFalse:[
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1602
        "/ a method/blockArg is constant as well ...
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1603
        (stop isVariable and:[stop isArgument]) ifFalse:[
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1604
            stop 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
  1605
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1606
            b isNil ifTrue:[
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1607
                stopVarIndex := aCompiler addTempVar.
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1608
                aStream nextPut:#storeMethodVar; nextPut:stopVarIndex.
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1609
            ] ifFalse:[
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1610
                stopVarIndex := b addTempVar.
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1611
                aStream nextPut:#storeBlockVar; nextPut:stopVarIndex.
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1612
            ].
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1613
        ]
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1614
    ].
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1615
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1616
    pos := aStream position.
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1617
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1618
    aStream nextPut:#dup.
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1619
    stopVarIndex notNil ifTrue:[
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1620
        b isNil ifTrue:[
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1621
            aStream nextPut:#pushMethodVar; nextPut:stopVarIndex.
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1622
        ] ifFalse:[
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1623
            aStream nextPut:#pushBlockVar; nextPut:stopVarIndex.
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1624
        ]
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1625
    ] ifFalse:[
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1626
        stop 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
  1627
    ].
561
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  1628
    aStream nextPut:#>.
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  1629
    (aCompiler hasLineNumber:selector) ifTrue:[
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  1630
        aStream nextPut:lineNr.
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  1631
    ].
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  1632
    aStream nextPut:#trueJump.
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  1633
    pos2 := aStream position.
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  1634
    aStream nextPut:0.
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  1635
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  1636
    theBlock := argArray at:2.
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  1637
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  1638
    "/ 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
  1639
    "/ the loop ...
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  1640
    b isNil ifTrue:[
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  1641
        loopVarIndex := aCompiler addTempVar.
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  1642
        aStream nextPut:#dup.
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  1643
        aStream nextPut:#storeMethodVar; nextPut:loopVarIndex.
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  1644
    ] ifFalse:[
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  1645
        loopVarIndex := b addTempVar.
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  1646
        aStream nextPut:#dup.
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  1647
        aStream nextPut:#storeBlockVar; nextPut:loopVarIndex.
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  1648
    ].
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  1649
    theBlock indexOfFirstTemp:loopVarIndex.
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  1650
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  1651
    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
  1652
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  1653
    "/ increment counter & jump back.
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  1654
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  1655
    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
  1656
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  1657
    (aStream contents) at:pos2 put:(aStream position).
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  1658
    aStream nextPut:#drop.  "/ drop run variable
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  1659
    lateEval ifTrue:[
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  1660
        start codeOn:aStream inBlock:b for:aCompiler.
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  1661
    ].
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  1662
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  1663
    "/ 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
  1664
    "/ (its integer, anyway).
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  1665
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  1666
    b isNil ifTrue:[
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  1667
        aCompiler removeTempVar
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  1668
    ] ifFalse:[
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  1669
        b removeTempVar
565
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1670
    ].
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1671
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1672
    stopVarIndex notNil ifTrue:[
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1673
        b isNil ifTrue:[
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1674
            aCompiler removeTempVar
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1675
        ] ifFalse:[
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1676
            b removeTempVar
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1677
        ]
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1678
    ].
561
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  1679
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  1680
    "Created: 26.6.1997 / 10:58:47 / cg"
565
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1681
    "Modified: 27.6.1997 / 13:21:54 / cg"
561
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  1682
!
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  1683
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1684
codeWhileOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler
200
b2f77bd77070 inline code for [...] whileXXX
Claus Gittinger <cg@exept.de>
parents: 199
diff changeset
  1685
    "generate code for
370
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  1686
        [...] whileXXX:[ ... ] 
200
b2f77bd77070 inline code for [...] whileXXX
Claus Gittinger <cg@exept.de>
parents: 199
diff changeset
  1687
     and also 
370
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  1688
        [...] whileXXX
200
b2f77bd77070 inline code for [...] whileXXX
Claus Gittinger <cg@exept.de>
parents: 199
diff changeset
  1689
    "
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1690
200
b2f77bd77070 inline code for [...] whileXXX
Claus Gittinger <cg@exept.de>
parents: 199
diff changeset
  1691
    |pos pos2 theReceiver theArg theByteCode optByteCode needLineNr blockExpr
370
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  1692
     hasLoopBlock fastReceiver|
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1693
200
b2f77bd77070 inline code for [...] whileXXX
Claus Gittinger <cg@exept.de>
parents: 199
diff changeset
  1694
    hasLoopBlock := true.
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1695
    (selector == #whileTrue:) ifTrue:[
370
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  1696
        theByteCode := #falseJump.
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1697
    ] ifFalse:[
370
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  1698
        (selector == #whileFalse:) ifTrue:[
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  1699
            theByteCode := #trueJump
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  1700
        ] ifFalse:[
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  1701
            hasLoopBlock := false.
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  1702
            (selector == #whileTrue) ifTrue:[
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  1703
                theByteCode := #trueJump
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  1704
            ] ifFalse:[
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  1705
                theByteCode := #falseJump
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  1706
            ].
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  1707
        ]
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1708
    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1709
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1710
    theReceiver := receiver.
370
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  1711
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  1712
(receiver isBlock
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  1713
and:[receiver statements notNil
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  1714
and:[receiver statements nextStatement isNil
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  1715
and:[receiver statements expression notNil]]])
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  1716
    ifTrue:[
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  1717
        fastReceiver := receiver statements expression.
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  1718
        optByteCode := self optimizedConditionFor:fastReceiver with:theByteCode.
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  1719
    ] ifFalse:[
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  1720
        optByteCode := self optimizedConditionFor:theReceiver with:theByteCode.
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  1721
    ].
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  1722
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1723
    optByteCode notNil ifTrue:[
370
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  1724
        ((optByteCode == #eqJump) or:[optByteCode == #notEqJump]) ifTrue:[
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  1725
            theArg := receiver statements expression arg1
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  1726
        ].
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  1727
        theReceiver := receiver statements expression receiver.
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  1728
        theByteCode := optByteCode
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1729
    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1730
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1731
"/ OLD:
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1732
"/    valueNeeded ifTrue:[aStream nextPut:#pushNil].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1733
"/
167
d3dbd739c65a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 166
diff changeset
  1734
    needLineNr := true.
d3dbd739c65a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 166
diff changeset
  1735
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1736
    pos := aStream position.
386
2f66de89a89b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 371
diff changeset
  1737
389
8aa5f9f08139 care for lineNumber in while-loop
Claus Gittinger <cg@exept.de>
parents: 386
diff changeset
  1738
"/    aCompiler lineNumberInfo == #full ifTrue:[
386
2f66de89a89b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 371
diff changeset
  1739
        ParseNode codeLineNumber:lineNr on:aStream for:aCompiler.
389
8aa5f9f08139 care for lineNumber in while-loop
Claus Gittinger <cg@exept.de>
parents: 386
diff changeset
  1740
        needLineNr := false.
8aa5f9f08139 care for lineNumber in while-loop
Claus Gittinger <cg@exept.de>
parents: 386
diff changeset
  1741
"/    ].
386
2f66de89a89b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 371
diff changeset
  1742
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1743
    optByteCode notNil ifTrue:[
370
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  1744
        theReceiver codeOn:aStream inBlock:b for:aCompiler.
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  1745
        theArg notNil ifTrue:[
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  1746
            theArg codeOn:aStream inBlock:b for:aCompiler
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  1747
        ]
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1748
    ] ifFalse:[
370
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  1749
        fastReceiver notNil ifTrue:[
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  1750
            theByteCode == #trueJump ifTrue:[
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  1751
                fastReceiver isConstant ifTrue:[
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  1752
                    fastReceiver evaluate == true ifTrue:[
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  1753
                        theByteCode := #jump
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  1754
                    ] ifFalse:[
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  1755
                        fastReceiver evaluate == false ifTrue:[
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  1756
                            theByteCode := #never
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  1757
                        ]
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  1758
                    ]
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  1759
                ]
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  1760
            ] ifFalse:[
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  1761
                theByteCode == #falseJump ifTrue:[
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  1762
                    fastReceiver isConstant ifTrue:[
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  1763
                        fastReceiver evaluate == false ifTrue:[
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  1764
                            theByteCode := #jump
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  1765
                        ] ifFalse:[
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  1766
                            fastReceiver evaluate == true ifTrue:[
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  1767
                                theByteCode := #never
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  1768
                            ]
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  1769
                        ]
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  1770
                    ]
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  1771
                ]
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  1772
            ]
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  1773
        ].
167
d3dbd739c65a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 166
diff changeset
  1774
370
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  1775
        (theByteCode ~~ #jump
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  1776
        and:[theByteCode ~~ #never]) ifTrue:[
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  1777
            theReceiver codeInlineOn:aStream inBlock:b for:aCompiler.
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  1778
        ].
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  1779
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  1780
        "/
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  1781
        "/ cannot enable code below 
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  1782
        "/ (tiny loops would not be debuggable with next, since lineNo remains the same)
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  1783
        "/ think about it ...
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  1784
        "/
386
2f66de89a89b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 371
diff changeset
  1785
        blockExpr := theReceiver simpleSendBlockExpression.
2f66de89a89b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 371
diff changeset
  1786
        blockExpr notNil ifTrue:[
2f66de89a89b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 371
diff changeset
  1787
            blockExpr isMessage ifTrue:[
2f66de89a89b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 371
diff changeset
  1788
                (aCompiler hasLineNumber:(blockExpr selector)) ifTrue:[
2f66de89a89b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 371
diff changeset
  1789
                    blockExpr lineNumber == lineNr ifTrue:[
2f66de89a89b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 371
diff changeset
  1790
                        needLineNr := false
2f66de89a89b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 371
diff changeset
  1791
                    ]
2f66de89a89b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 371
diff changeset
  1792
                ]
2f66de89a89b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 371
diff changeset
  1793
            ]
2f66de89a89b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 371
diff changeset
  1794
        ].
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1795
    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1796
167
d3dbd739c65a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 166
diff changeset
  1797
    needLineNr ifTrue:[
386
2f66de89a89b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 371
diff changeset
  1798
        ParseNode codeLineNumber:lineNr on:aStream for:aCompiler.
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1799
    ].
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1800
200
b2f77bd77070 inline code for [...] whileXXX
Claus Gittinger <cg@exept.de>
parents: 199
diff changeset
  1801
    hasLoopBlock ifFalse:[
370
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  1802
        "/ simple [...] whileXXX
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  1803
        theByteCode ~~ #never ifTrue:[
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  1804
            aStream nextPut:theByteCode; nextPut:pos.
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  1805
        ].
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  1806
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  1807
        valueNeeded ifTrue:[aStream nextPut:#pushNil].
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  1808
        ^ self
200
b2f77bd77070 inline code for [...] whileXXX
Claus Gittinger <cg@exept.de>
parents: 199
diff changeset
  1809
    ].
b2f77bd77070 inline code for [...] whileXXX
Claus Gittinger <cg@exept.de>
parents: 199
diff changeset
  1810
b2f77bd77070 inline code for [...] whileXXX
Claus Gittinger <cg@exept.de>
parents: 199
diff changeset
  1811
    "/ [...] whileXXX:[...]
b2f77bd77070 inline code for [...] whileXXX
Claus Gittinger <cg@exept.de>
parents: 199
diff changeset
  1812
370
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  1813
    theByteCode ~~ #never ifTrue:[
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  1814
        aStream nextPut:theByteCode.
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  1815
        pos2 := aStream position.
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  1816
        aStream nextPut:0.
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  1817
    ].
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  1818
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1819
    (argArray at:1) codeInlineOn:aStream inBlock:b valueNeeded:false for:aCompiler.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1820
    aStream nextPut:#jump; nextPut:pos.
370
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  1821
    theByteCode ~~ #never ifTrue:[
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  1822
        (aStream contents) at:pos2 put:(aStream position).
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  1823
    ].
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  1824
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1825
    valueNeeded ifTrue:[aStream nextPut:#pushNil].
167
d3dbd739c65a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 166
diff changeset
  1826
389
8aa5f9f08139 care for lineNumber in while-loop
Claus Gittinger <cg@exept.de>
parents: 386
diff changeset
  1827
    "Modified: 22.10.1996 / 21:34:37 / cg"
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1828
!
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1829
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1830
optimizedConditionFor:aReceiver with:aByteCode
186
05a99f1bd747 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 167
diff changeset
  1831
    |rec sel stats|
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1832
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1833
    rec := aReceiver.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1834
    (rec isBlock) ifTrue:[
186
05a99f1bd747 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 167
diff changeset
  1835
	(stats := rec statements) notNil ifTrue:[
05a99f1bd747 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 167
diff changeset
  1836
	    stats nextStatement isNil ifTrue:[
05a99f1bd747 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 167
diff changeset
  1837
		rec := rec statements expression
05a99f1bd747 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 167
diff changeset
  1838
	    ]
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1839
	]
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1840
    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1841
    (rec isUnaryMessage) ifTrue:[
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1842
	sel := rec selector.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1843
	(sel == #isNil) ifTrue:[
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1844
	    "/
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1845
	    "/ isNil trueJmp  -> nilJump
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1846
	    "/ isNil falseJmp -> notNilJump
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1847
	    "/
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1848
	    (aByteCode == #trueJump) ifTrue:[^ #nilJump].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1849
	    (aByteCode == #falseJump) ifTrue:[^ #notNilJump]
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1850
	].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1851
	(sel == #notNil) ifTrue:[
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1852
	    "/
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1853
	    "/ notNil trueJmp  -> notNilJump
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1854
	    "/ notNil falseJmp -> nilJump
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1855
	    "/
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1856
	    (aByteCode == #trueJump) ifTrue:[^ #notNilJump].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1857
	    (aByteCode == #falseJump) ifTrue:[^ #nilJump]
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1858
	].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1859
	(sel == #not) ifTrue:[
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1860
	    "/
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1861
	    "/ not trueJmp  -> falseJump
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1862
	    "/ not falseJmp -> trueJump
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1863
	    "/
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1864
	    (aByteCode == #trueJump) ifTrue:[^ #falseJump].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1865
	    (aByteCode == #falseJump) ifTrue:[^ #trueJump]
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1866
	].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1867
	^ nil
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1868
    ].
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1869
    (rec isBinaryMessage) ifTrue:[
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1870
	sel := rec selector.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1871
	rec arg1 isConstant ifTrue:[
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1872
	    (rec arg1 value == 0) ifTrue:[
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1873
		"/
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1874
		"/ ==0 trueJmp  -> zeroJump
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1875
		"/ ==0 falseJmp -> notZeroJump
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1876
		"/
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1877
		(sel == #==) ifTrue:[
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1878
		    (aByteCode == #trueJump) ifTrue:[^ #zeroJump].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1879
		    (aByteCode == #falseJump) ifTrue:[^ #notZeroJump]
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1880
		].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1881
		"/
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1882
		"/ ~~0 trueJmp  -> notZeroJump
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1883
		"/ ~~0 falseJmp -> zeroJump
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1884
		"/
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1885
		(sel == #~~) ifTrue:[
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1886
		    (aByteCode == #falseJump) ifTrue:[^ #zeroJump].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1887
		    (aByteCode == #trueJump) ifTrue:[^ #notZeroJump]
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1888
		].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1889
		^ nil
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
	].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1892
	(sel == #==) ifTrue:[
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1893
	    "/
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1894
	    "/ == trueJmp  -> eqJump
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1895
	    "/ == falseJmp -> notEqJump
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1896
	    "/
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1897
	    (aByteCode == #trueJump) ifTrue:[^ #eqJump].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1898
	    (aByteCode == #falseJump) ifTrue:[^ #notEqJump]
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1899
	].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1900
	(sel == #~~) ifTrue:[
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1901
	    "/
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1902
	    "/ ~~ trueJmp  -> notEqJump
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1903
	    "/ ~~ falseJmp -> eqJump
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1904
	    "/
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1905
	    (aByteCode == #falseJump) ifTrue:[^ #eqJump].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1906
	    (aByteCode == #trueJump) ifTrue:[^ #notEqJump]
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1907
	]
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1908
    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1909
    ^ nil
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1910
! !
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1911
539
69a1cd05c7d6 added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents: 537
diff changeset
  1912
!MessageNode methodsFor:'enumeration'!
69a1cd05c7d6 added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents: 537
diff changeset
  1913
69a1cd05c7d6 added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents: 537
diff changeset
  1914
nodeDo:anEnumerator
69a1cd05c7d6 added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents: 537
diff changeset
  1915
    "helper for parse tree walking"
69a1cd05c7d6 added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents: 537
diff changeset
  1916
543
de47f8969fd9 more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
  1917
    |args|
de47f8969fd9 more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
  1918
de47f8969fd9 more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
  1919
    args := argArray ? #().
de47f8969fd9 more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
  1920
    ^ anEnumerator doMessage:self receiver:receiver selector:selector arguments:args
539
69a1cd05c7d6 added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents: 537
diff changeset
  1921
69a1cd05c7d6 added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents: 537
diff changeset
  1922
    "Created: 19.6.1997 / 16:46:39 / cg"
543
de47f8969fd9 more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
  1923
    "Modified: 19.6.1997 / 17:08:28 / cg"
539
69a1cd05c7d6 added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents: 537
diff changeset
  1924
! !
69a1cd05c7d6 added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents: 537
diff changeset
  1925
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1926
!MessageNode methodsFor:'evaluating'!
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1927
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1928
evaluate
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1929
    |r nargs argValueArray class|
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1930
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1931
    receiver isSuper ifTrue:[
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1932
	r := receiver value.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1933
	receiver isHere ifTrue:[
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1934
	    class := receiver definingClass.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1935
	] ifFalse:[
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1936
	    class := receiver definingClass superclass.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1937
	].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1938
	argArray notNil ifTrue:[
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1939
	    argValueArray := argArray collect:[:arg | arg evaluate].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1940
	] ifFalse:[
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1941
	    argValueArray := #()
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1942
	].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1943
	^ r perform:selector inClass:class withArguments:argValueArray
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1944
    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1945
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1946
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1947
    argArray isNil ifTrue:[
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1948
	^ (receiver evaluate) perform:selector
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1949
    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1950
    nargs := argArray size.
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1951
    (nargs == 1) ifTrue:[
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1952
	^ (receiver evaluate) perform:selector with:(argArray at:1) evaluate
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1953
    ].
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1954
    (nargs == 2) ifTrue:[
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1955
	^ (receiver evaluate) perform:selector
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1956
				 with:(argArray at:1) evaluate
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1957
				 with:(argArray at:2) evaluate
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1958
    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1959
    (nargs == 3) ifTrue:[
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1960
	^ (receiver evaluate) perform:selector
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1961
				 with:(argArray at:1) evaluate
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1962
				 with:(argArray at:2) evaluate
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1963
				 with:(argArray at:3) evaluate
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1964
    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1965
    r := receiver evaluate.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1966
    argValueArray := argArray collect:[:arg | arg evaluate].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1967
    ^ r perform:selector withArguments:argValueArray
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1968
!
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1969
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1970
evaluateForCascade
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1971
    |r nargs argValueArray class|
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1972
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1973
    receiver isSuper ifTrue:[
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1974
	r := receiver value.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1975
	class := receiver definingClass.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1976
	receiver isHere ifFalse:[
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1977
	    class := class superclass.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1978
	].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1979
	argArray notNil ifTrue:[
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1980
	    argValueArray := argArray collect:[:arg | arg evaluate].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1981
	] ifFalse:[
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1982
	    argValueArray := #()
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1983
	].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1984
	r perform:selector inClass:class withArguments:argValueArray.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1985
	^ r
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1986
    ].
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1987
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1988
    r := receiver evaluate.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1989
    argArray isNil ifTrue:[
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1990
	r perform:selector.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1991
	^ r
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1992
    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1993
    nargs := argArray size.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1994
    (nargs == 1) ifTrue:[
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1995
	r perform:selector with:(argArray at:1) evaluate.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1996
	^ r
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1997
    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1998
    (nargs == 2) ifTrue:[
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1999
	r perform:selector with:(argArray at:1) evaluate
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2000
			   with:(argArray at:2) evaluate.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2001
	^ r
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2002
    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2003
    (nargs == 3) ifTrue:[
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2004
	r perform:selector with:(argArray at:1) evaluate
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2005
			   with:(argArray at:2) evaluate
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2006
			   with:(argArray at:3) evaluate.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2007
	^ r
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2008
    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2009
    argValueArray := argArray collect:[:arg | arg evaluate].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2010
    r perform:selector withArguments:argValueArray.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2011
    ^ r
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2012
! !
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2013
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2014
!MessageNode methodsFor:'printing'!
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2015
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2016
printOn:aStream indent:i
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2017
    |needParen selectorParts index index2 arg|
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2018
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2019
    (#(whileTrue: whileFalse:) includes:selector) ifTrue:[
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2020
	receiver isBlock ifTrue:[
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2021
	    ^ self printWhileOn:aStream indent:i
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2022
	].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2023
    ].
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2024
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2025
    index := 1.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2026
    selectorParts := OrderedCollection new.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2027
    [index == 0] whileFalse:[
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2028
	index2 := selector indexOf:$: startingAt:index.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2029
	index2 ~~ 0 ifTrue:[
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2030
	    selectorParts add:(selector copyFrom:index to:index2).
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2031
	    index2 := index2 + 1
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2032
	].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2033
	index := index2
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2034
    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2035
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2036
    needParen := false.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2037
    receiver isMessage ifTrue:[
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2038
	receiver isUnaryMessage ifFalse:[
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2039
	    receiver isBinaryMessage ifFalse:[
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2040
		needParen := true
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2041
	    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2042
	].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2043
    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2044
    needParen ifTrue:[
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2045
	aStream nextPutAll:'('
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2046
    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2047
    receiver printOn:aStream indent:i.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2048
    needParen ifTrue:[
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2049
	aStream nextPutAll:')'
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2050
    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2051
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2052
    1 to:(argArray size) do:[:argIndex |
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2053
	aStream space.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2054
	(selectorParts at:argIndex) printOn:aStream.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2055
	aStream space.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2056
	arg := argArray at:argIndex.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2057
	needParen := false.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2058
	arg isMessage ifTrue:[
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2059
	    arg isBinaryMessage ifFalse:[
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2060
		arg isUnaryMessage ifFalse:[
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2061
		    needParen := true
47
f861ad42703e *** empty log message ***
claus
parents: 39
diff changeset
  2062
		]
f861ad42703e *** empty log message ***
claus
parents: 39
diff changeset
  2063
	    ].
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2064
	].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2065
	needParen ifTrue:[
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2066
	    aStream nextPutAll:'('
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2067
	].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2068
	arg printOn:aStream indent:i.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2069
	needParen ifTrue:[
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2070
	    aStream nextPutAll:') '
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2071
	].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2072
    ]
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2073
!
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2074
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2075
printWhileOn:aStream indent:i
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2076
    |needParen arg|
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2077
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2078
    "special handling of whileTrue/whileFalse"
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2079
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2080
    aStream nextPutAll:'['.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2081
    receiver statements printOn:aStream indent:i.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2082
    aStream nextPutAll:'] whileTrue: '.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2083
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2084
    arg := argArray at:1.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2085
    needParen := false.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2086
    arg isMessage ifTrue:[
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2087
	arg isBinaryMessage ifFalse:[
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2088
	    arg isUnaryMessage ifFalse:[
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2089
		needParen := true
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2090
	    ]
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2091
	].
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2092
    ].
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2093
    needParen ifTrue:[
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2094
	aStream nextPutAll:'('
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2095
    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2096
    arg printOn:aStream indent:i.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2097
    needParen ifTrue:[
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2098
	aStream nextPutAll:') '
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2099
    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2100
! !
106
claus
parents: 104
diff changeset
  2101
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2102
!MessageNode methodsFor:'queries'!
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2103
395
16156d8711c2 added block collector
Claus Gittinger <cg@exept.de>
parents: 389
diff changeset
  2104
collectBlocksInto:aCollection
16156d8711c2 added block collector
Claus Gittinger <cg@exept.de>
parents: 389
diff changeset
  2105
    receiver collectBlocksInto:aCollection.
16156d8711c2 added block collector
Claus Gittinger <cg@exept.de>
parents: 389
diff changeset
  2106
    argArray size > 0 ifTrue:[
16156d8711c2 added block collector
Claus Gittinger <cg@exept.de>
parents: 389
diff changeset
  2107
        argArray do:[:arg |
16156d8711c2 added block collector
Claus Gittinger <cg@exept.de>
parents: 389
diff changeset
  2108
            arg collectBlocksInto:aCollection.
16156d8711c2 added block collector
Claus Gittinger <cg@exept.de>
parents: 389
diff changeset
  2109
        ]
16156d8711c2 added block collector
Claus Gittinger <cg@exept.de>
parents: 389
diff changeset
  2110
    ].
16156d8711c2 added block collector
Claus Gittinger <cg@exept.de>
parents: 389
diff changeset
  2111
16156d8711c2 added block collector
Claus Gittinger <cg@exept.de>
parents: 389
diff changeset
  2112
    "Created: 23.10.1996 / 15:44:49 / cg"
16156d8711c2 added block collector
Claus Gittinger <cg@exept.de>
parents: 389
diff changeset
  2113
    "Modified: 23.10.1996 / 16:03:46 / cg"
16156d8711c2 added block collector
Claus Gittinger <cg@exept.de>
parents: 389
diff changeset
  2114
!
16156d8711c2 added block collector
Claus Gittinger <cg@exept.de>
parents: 389
diff changeset
  2115
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2116
isMessage
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2117
    ^ true
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2118
! !
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2119
370
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  2120
!MessageNode class methodsFor:'documentation'!
148
ef0e604209ec version method at the end
Claus Gittinger <cg@exept.de>
parents: 140
diff changeset
  2121
ef0e604209ec version method at the end
Claus Gittinger <cg@exept.de>
parents: 140
diff changeset
  2122
version
567
a6e4c44ff326 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 565
diff changeset
  2123
    ^ '$Header: /cvs/stx/stx/libcomp/MessageNode.st,v 1.75 1997-06-27 16:33:17 cg Exp $'
148
ef0e604209ec version method at the end
Claus Gittinger <cg@exept.de>
parents: 140
diff changeset
  2124
! !