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