MessageNode.st
author Claus Gittinger <cg@exept.de>
Sat, 10 Jul 1999 00:41:36 +0200
changeset 898 8db540a5fda8
parent 888 5858090fc8c3
child 899 fb678b9e18a7
permissions -rw-r--r--
inline code for ifNil: / ifNotNil: / ifNil:ifNotNil: / ifNotNil:ifNil:
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:[
715
408ac886ffc1 allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents: 676
diff changeset
   220
        numArgs := argArray size.
408ac886ffc1 allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents: 676
diff changeset
   221
        numArgs > 0 ifTrue:[
408ac886ffc1 allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents: 676
diff changeset
   222
            arg1 := (argArray at:1).
408ac886ffc1 allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents: 676
diff changeset
   223
            (numArgs == 1) ifTrue:[
408ac886ffc1 allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents: 676
diff changeset
   224
                ^ self receiver:recNode selector:selectorString arg:arg1 fold:folding 
408ac886ffc1 allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents: 676
diff changeset
   225
            ].
20
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
   226
715
408ac886ffc1 allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents: 676
diff changeset
   227
            "/
408ac886ffc1 allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents: 676
diff changeset
   228
            "/ #perform:... with a constant selector
408ac886ffc1 allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents: 676
diff changeset
   229
            "/
408ac886ffc1 allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents: 676
diff changeset
   230
            numArgs <= 6 ifTrue:[
408ac886ffc1 allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents: 676
diff changeset
   231
                (#(nil
408ac886ffc1 allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents: 676
diff changeset
   232
                   #'perform:with:'
408ac886ffc1 allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents: 676
diff changeset
   233
                   #'perform:with:with:'
408ac886ffc1 allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents: 676
diff changeset
   234
                   #'perform:with:with:with:'
408ac886ffc1 allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents: 676
diff changeset
   235
                   #'perform:with:with:with:with:'
408ac886ffc1 allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents: 676
diff changeset
   236
                   #'perform:with:with:with:with:with:'
408ac886ffc1 allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents: 676
diff changeset
   237
                   #'perform:with:with:with:with:with:with:'
408ac886ffc1 allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents: 676
diff changeset
   238
                ) at:numArgs) = selectorString 
408ac886ffc1 allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents: 676
diff changeset
   239
                ifTrue:[
408ac886ffc1 allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents: 676
diff changeset
   240
                    arg1 isConstant ifTrue:[    
408ac886ffc1 allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents: 676
diff changeset
   241
                        arg1Val := arg1 evaluate.
408ac886ffc1 allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents: 676
diff changeset
   242
                        arg1Val isSymbol ifTrue:[
408ac886ffc1 allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents: 676
diff changeset
   243
                            ^ MessageNode 
408ac886ffc1 allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents: 676
diff changeset
   244
                                    receiver:recNode 
408ac886ffc1 allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents: 676
diff changeset
   245
                                    selector:arg1Val
408ac886ffc1 allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents: 676
diff changeset
   246
                                    args:(argArray copyFrom:2)
408ac886ffc1 allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents: 676
diff changeset
   247
                                    fold:folding
408ac886ffc1 allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents: 676
diff changeset
   248
                        ]
408ac886ffc1 allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents: 676
diff changeset
   249
                    ]
408ac886ffc1 allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents: 676
diff changeset
   250
                ]
408ac886ffc1 allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents: 676
diff changeset
   251
            ].
408ac886ffc1 allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents: 676
diff changeset
   252
        ].
639
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
   253
715
408ac886ffc1 allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents: 676
diff changeset
   254
        (numArgs == 2) ifTrue:[
408ac886ffc1 allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents: 676
diff changeset
   255
            ^ self receiver:recNode selector:selectorString arg1:arg1 arg2:(argArray at:2) fold:folding 
408ac886ffc1 allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents: 676
diff changeset
   256
        ].
408ac886ffc1 allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents: 676
diff changeset
   257
        numArgs > Method maxNumberOfArguments ifTrue:[
408ac886ffc1 allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents: 676
diff changeset
   258
            ^ 'too many arguments for current VM implementation'.
408ac886ffc1 allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents: 676
diff changeset
   259
        ].
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   260
    ].
117
claus
parents: 111
diff changeset
   261
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   262
    ^ (self basicNew) receiver:recNode selector:selectorString args:argArray lineno:0
117
claus
parents: 111
diff changeset
   263
639
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
   264
    "Modified: / 3.9.1995 / 16:41:39 / claus"
715
408ac886ffc1 allow 0-args in #receiver:selector:args:fold:
Claus Gittinger <cg@exept.de>
parents: 676
diff changeset
   265
    "Modified: / 15.5.1998 / 15:32:05 / cg"
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   266
! !
7ad01559b262 Initial revision
claus
parents:
diff changeset
   267
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   268
!MessageNode methodsFor:'accessing'!
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   269
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   270
arg1
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   271
    ^ argArray at:1
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   272
!
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   273
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   274
args
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   275
    ^ argArray
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   276
!
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   277
543
de47f8969fd9 more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
   278
arguments
de47f8969fd9 more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
   279
    ^ argArray ? #()
de47f8969fd9 more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
   280
de47f8969fd9 more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
   281
    "Created: 19.6.1997 / 17:31:14 / cg"
de47f8969fd9 more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
   282
    "Modified: 19.6.1997 / 17:32:25 / cg"
de47f8969fd9 more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
   283
!
de47f8969fd9 more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
   284
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   285
lineNumber
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   286
     ^ lineNr
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   287
!
7ad01559b262 Initial revision
claus
parents:
diff changeset
   288
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   289
lineNumber:num
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   290
     lineNr := num
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   291
!
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   292
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   293
receiver
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   294
    ^ receiver
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   295
!
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   296
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   297
receiver:r selector:s args:a lineno:l
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   298
    receiver := r.
861
ccaa0ba5e7af generate selector symbols late (when compiling or evaluating)
Claus Gittinger <cg@exept.de>
parents: 856
diff changeset
   299
    selector := s asSymbolIfInterned ? s.
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   300
    argArray := a.
574
993d1182782b fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents: 570
diff changeset
   301
    lineNr := l.
993d1182782b fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents: 570
diff changeset
   302
    self checkInlinability.
993d1182782b fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents: 570
diff changeset
   303
993d1182782b fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents: 570
diff changeset
   304
    "Modified: 2.7.1997 / 17:01:24 / cg"
861
ccaa0ba5e7af generate selector symbols late (when compiling or evaluating)
Claus Gittinger <cg@exept.de>
parents: 856
diff changeset
   305
ccaa0ba5e7af generate selector symbols late (when compiling or evaluating)
Claus Gittinger <cg@exept.de>
parents: 856
diff changeset
   306
ccaa0ba5e7af generate selector symbols late (when compiling or evaluating)
Claus Gittinger <cg@exept.de>
parents: 856
diff changeset
   307
ccaa0ba5e7af generate selector symbols late (when compiling or evaluating)
Claus Gittinger <cg@exept.de>
parents: 856
diff changeset
   308
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   309
!
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   310
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   311
selector
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   312
    ^ selector
595
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
a90e8d8bf417 remember position of selector
Claus Gittinger <cg@exept.de>
parents: 578
diff changeset
   315
selectorPosition
a90e8d8bf417 remember position of selector
Claus Gittinger <cg@exept.de>
parents: 578
diff changeset
   316
    "return the value of the instance variable 'selectorPosition' (automatically generated)"
a90e8d8bf417 remember position of selector
Claus Gittinger <cg@exept.de>
parents: 578
diff changeset
   317
a90e8d8bf417 remember position of selector
Claus Gittinger <cg@exept.de>
parents: 578
diff changeset
   318
    ^ selectorPosition
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
    "Created: 5.8.1997 / 02:49:27 / cg"
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
a90e8d8bf417 remember position of selector
Claus Gittinger <cg@exept.de>
parents: 578
diff changeset
   323
selectorPosition:something
a90e8d8bf417 remember position of selector
Claus Gittinger <cg@exept.de>
parents: 578
diff changeset
   324
    "set the value of the instance variable 'selectorPosition' (automatically generated)"
a90e8d8bf417 remember position of selector
Claus Gittinger <cg@exept.de>
parents: 578
diff changeset
   325
a90e8d8bf417 remember position of selector
Claus Gittinger <cg@exept.de>
parents: 578
diff changeset
   326
    selectorPosition := something.
a90e8d8bf417 remember position of selector
Claus Gittinger <cg@exept.de>
parents: 578
diff changeset
   327
a90e8d8bf417 remember position of selector
Claus Gittinger <cg@exept.de>
parents: 578
diff changeset
   328
    "Created: 5.8.1997 / 02:49:27 / cg"
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   329
! !
7ad01559b262 Initial revision
claus
parents:
diff changeset
   330
7ad01559b262 Initial revision
claus
parents:
diff changeset
   331
!MessageNode methodsFor:'checks'!
7ad01559b262 Initial revision
claus
parents:
diff changeset
   332
574
993d1182782b fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents: 570
diff changeset
   333
checkInlinability
993d1182782b fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents: 570
diff changeset
   334
    "early check for possible inlinability"
993d1182782b fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents: 570
diff changeset
   335
993d1182782b fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents: 570
diff changeset
   336
    |numArgs arg1 arg2 arg3|
993d1182782b fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents: 570
diff changeset
   337
993d1182782b fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents: 570
diff changeset
   338
    (numArgs := argArray size) >= 1 ifTrue:[
676
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   339
        arg1 := argArray at:1.
574
993d1182782b fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents: 570
diff changeset
   340
    ].
993d1182782b fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents: 570
diff changeset
   341
    numArgs == 0 ifTrue:[
676
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   342
        (selector == #whileTrue 
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   343
        or:[selector == #whileFalse]) ifTrue:[
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   344
            receiver isBlock ifTrue:[
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   345
                receiver possiblyInlined:true
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
        ].
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   348
        (selector == #value) ifTrue:[
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   349
            receiver isBlock ifTrue:[
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   350
                receiver possiblyInlined:true
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   351
            ].
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   352
        ].
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   353
        (selector == #repeat) ifTrue:[
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   354
            receiver isBlock ifTrue:[
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   355
                receiver possiblyInlined:true
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   356
            ].
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   357
        ].
574
993d1182782b fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents: 570
diff changeset
   358
    ].
993d1182782b fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents: 570
diff changeset
   359
993d1182782b fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents: 570
diff changeset
   360
    numArgs == 1 ifTrue:[
676
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   361
        (selector == #or: 
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   362
        or:[selector == #and:]) ifTrue:[
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   363
            arg1 isBlock ifTrue:[
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   364
                arg1 possiblyInlined:true
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   365
            ].
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   366
        ].
576
5cb4af0eea67 also inline and:/or: ...
Claus Gittinger <cg@exept.de>
parents: 574
diff changeset
   367
676
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   368
        (selector == #ifTrue: 
898
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
   369
        or:[selector == #ifFalse:
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
   370
        or:[selector == #ifNil:
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
   371
        or:[selector == #ifNotNil:]]]) ifTrue:[
676
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   372
            arg1 isBlock ifTrue:[
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   373
                arg1 possiblyInlined:true
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   374
            ].
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   375
        ].
574
993d1182782b fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents: 570
diff changeset
   376
676
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   377
        (selector == #whileTrue: 
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   378
        or:[selector == #whileFalse:]) 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
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
            receiver isBlock ifTrue:[
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   383
                receiver possiblyInlined:true
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   384
            ].
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   385
        ].
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   386
        selector == #timesRepeat: ifTrue:[
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   387
            arg1 isBlock ifTrue:[
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   388
                arg1 possiblyInlined:true withSelector:selector.
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   389
            ]
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   390
        ].
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   391
        ^ self
574
993d1182782b fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents: 570
diff changeset
   392
    ].
993d1182782b fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents: 570
diff changeset
   393
    numArgs >= 2 ifTrue:[
676
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   394
        arg2 := argArray at:2.
574
993d1182782b fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents: 570
diff changeset
   395
    ].    
993d1182782b fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents: 570
diff changeset
   396
    numArgs == 2 ifTrue:[
676
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   397
        (selector == #ifTrue:ifFalse:
898
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
   398
        or:[selector == #ifFalse:ifTrue:
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
   399
        or:[selector == #ifNil:ifNotNil:
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
   400
        or:[selector == #ifNotNil:ifNil:]]]) ifTrue:[
676
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   401
            (arg1 isBlock 
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   402
            and:[arg2 isBlock]) ifTrue:[
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   403
                arg1 possiblyInlined:true.
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   404
                arg2 possiblyInlined:true.
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   405
            ].
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   406
        ].
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   407
        selector == #to:do: ifTrue:[
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   408
            arg2 isBlock ifTrue:[
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   409
                arg2 possiblyInlined:true withSelector:selector.
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   410
            ].
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
        ^ self
574
993d1182782b fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents: 570
diff changeset
   413
    ].
993d1182782b fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents: 570
diff changeset
   414
    numArgs >= 3 ifTrue:[
676
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   415
        arg3 := argArray at:3.
574
993d1182782b fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents: 570
diff changeset
   416
    ].    
993d1182782b fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents: 570
diff changeset
   417
    numArgs == 3 ifTrue:[
676
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   418
        selector == #to:by:do: ifTrue:[
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   419
            arg3 isBlock ifTrue:[
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   420
                arg3 possiblyInlined:true withSelector:selector.
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   421
            ].
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   422
        ].
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   423
        ^ self
574
993d1182782b fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents: 570
diff changeset
   424
    ].
993d1182782b fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents: 570
diff changeset
   425
    ^ self
993d1182782b fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents: 570
diff changeset
   426
676
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   427
    "Created: / 2.7.1997 / 17:01:10 / cg"
69d1fe23a2b4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 639
diff changeset
   428
    "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
   429
!
993d1182782b fixed inlining of blocks where subBlocks
Claus Gittinger <cg@exept.de>
parents: 570
diff changeset
   430
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   431
plausibilityCheck
7ad01559b262 Initial revision
claus
parents:
diff changeset
   432
    |rec arg operand|
7ad01559b262 Initial revision
claus
parents:
diff changeset
   433
3
b63b8a6b71fb *** empty log message ***
claus
parents: 0
diff changeset
   434
    "
b63b8a6b71fb *** empty log message ***
claus
parents: 0
diff changeset
   435
     it once took me almost an hour, to find a '==' which
b63b8a6b71fb *** empty log message ***
claus
parents: 0
diff changeset
   436
     should have been an '=' (you cannot compare floats with ==)
19
84a1ddf215a5 *** empty log message ***
claus
parents: 15
diff changeset
   437
     (well, I looked at the '==' at least 50 times -
84a1ddf215a5 *** empty log message ***
claus
parents: 15
diff changeset
   438
      - but didn't think about it ...).
84a1ddf215a5 *** empty log message ***
claus
parents: 15
diff changeset
   439
     thats reason enough to add this check here.
84a1ddf215a5 *** empty log message ***
claus
parents: 15
diff changeset
   440
     I will add more as heuristic knowledge increases ...
84a1ddf215a5 *** empty log message ***
claus
parents: 15
diff changeset
   441
     (send me comments on common programming errors ...)
84a1ddf215a5 *** empty log message ***
claus
parents: 15
diff changeset
   442
    "
84a1ddf215a5 *** empty log message ***
claus
parents: 15
diff changeset
   443
84a1ddf215a5 *** empty log message ***
claus
parents: 15
diff changeset
   444
    "
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   445
     check #== applied to Floats, Strings or Fractions
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   446
    "
7ad01559b262 Initial revision
claus
parents:
diff changeset
   447
    ((selector == #==) or:[selector == #~~]) ifTrue:[
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   448
        receiver isConstant ifTrue:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   449
            rec := receiver evaluate.
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   450
            ((rec isMemberOf:String) or:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   451
             (rec isMemberOf:Float) or:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   452
             (rec isMemberOf:Fraction)]]) ifTrue:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   453
                operand := rec
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   454
            ].
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   455
        ].
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   456
        (argArray at:1) isConstant ifTrue:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   457
            arg := (argArray at:1) evaluate.
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   458
            ((arg isMemberOf:String) or:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   459
             (arg isMemberOf:Float) or:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   460
             (arg isMemberOf:Fraction)]]) ifTrue:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   461
                operand := arg
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   462
            ].
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   463
        ].
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   464
        operand notNil ifTrue:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   465
            (selector == #==) ifTrue:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   466
                ^ 'identity compare is unsafe here'
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   467
            ].
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   468
            ^ 'identity compare will usually return true here'
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   469
        ]
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   470
    ].
3
b63b8a6b71fb *** empty log message ***
claus
parents: 0
diff changeset
   471
b63b8a6b71fb *** empty log message ***
claus
parents: 0
diff changeset
   472
    "
19
84a1ddf215a5 *** empty log message ***
claus
parents: 15
diff changeset
   473
     [...] ifTrue:...
3
b63b8a6b71fb *** empty log message ***
claus
parents: 0
diff changeset
   474
     an error often occuring when you are a beginner ...
b63b8a6b71fb *** empty log message ***
claus
parents: 0
diff changeset
   475
    "
b63b8a6b71fb *** empty log message ***
claus
parents: 0
diff changeset
   476
    ((selector == #ifTrue:) or:[selector == #ifFalse:]) ifTrue:[
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   477
        receiver isBlock ifTrue:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   478
            (Block canUnderstand:selector) ifFalse:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   479
                ^ 'blocks usually do not respond to ' , selector , ' messages'
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   480
            ].
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   481
        ].
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   482
        (argArray at:1) isBlock ifFalse:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   483
            ^ 'will fail at runtime, if argument to ' , selector , ' does not evaluate to a block'
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   484
        ]
3
b63b8a6b71fb *** empty log message ***
claus
parents: 0
diff changeset
   485
    ].
19
84a1ddf215a5 *** empty log message ***
claus
parents: 15
diff changeset
   486
    ((selector == #ifTrue:ifFalse:) or:[selector == #ifFalse:ifTrue:]) ifTrue:[
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   487
        receiver isBlock ifTrue:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   488
            (Block canUnderstand:selector) ifFalse:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   489
                ^ 'blocks usually do not respond to ' , selector , ' messages'
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   490
            ].
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   491
        ].
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   492
        (argArray at:1) isBlock ifFalse:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   493
            ^ 'will fail at runtime, if 1st. argument to ' , selector , ' does not evaluate to a block'
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   494
        ].
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   495
        (argArray at:2) isBlock ifFalse:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   496
            ^ 'will fail at runtime, if 2nd. argument to ' , selector , ' does not evaluate to a block'
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   497
        ]
3
b63b8a6b71fb *** empty log message ***
claus
parents: 0
diff changeset
   498
    ].
19
84a1ddf215a5 *** empty log message ***
claus
parents: 15
diff changeset
   499
84a1ddf215a5 *** empty log message ***
claus
parents: 15
diff changeset
   500
    "
84a1ddf215a5 *** empty log message ***
claus
parents: 15
diff changeset
   501
     (...) whileTrue:[
84a1ddf215a5 *** empty log message ***
claus
parents: 15
diff changeset
   502
    "
3
b63b8a6b71fb *** empty log message ***
claus
parents: 0
diff changeset
   503
    ((selector == #whileTrue:) or:[selector == #whileFalse:]) ifTrue:[
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   504
        receiver isBlock ifFalse:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   505
            "
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   506
             only warn, if code was originally parenthized
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   507
            "
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   508
            receiver parenthized ifTrue:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   509
                ^ 'will fail at runtime, if receiver of ' , selector , ' does not evaluate to a block'
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   510
            ]
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   511
        ].
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   512
        (argArray at:1) isBlock ifFalse:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   513
            ^ 'will fail at runtime, if argument to ' , selector , ' does not evaluate to a block'
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   514
        ].
3
b63b8a6b71fb *** empty log message ***
claus
parents: 0
diff changeset
   515
    ].
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   516
    ^ nil
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   517
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   518
    "Modified: / 16.7.1998 / 20:29:53 / cg"
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   519
! !
7ad01559b262 Initial revision
claus
parents:
diff changeset
   520
7ad01559b262 Initial revision
claus
parents:
diff changeset
   521
!MessageNode methodsFor:'code generation'!
7ad01559b262 Initial revision
claus
parents:
diff changeset
   522
338
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
   523
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
   524
    "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
   525
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
   526
    |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
   527
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
   528
    theByteCode := #falseJump.
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
   529
    theReceiver := receiver receiver.
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
   530
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
   531
    optByteCode := self optimizedConditionFor:theReceiver
639
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
   532
					 with:theByteCode.
338
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
   533
    optByteCode notNil ifTrue:[
639
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
   534
	((optByteCode == #eqJump) or:[optByteCode == #notEqJump]) ifTrue:[
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
   535
	    theArg := theReceiver arg1
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
   536
	].
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
   537
	theReceiver := theReceiver receiver.
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
   538
	theByteCode := optByteCode
338
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
   539
    ].
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
   540
    "/ 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
   541
    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
   542
    theArg notNil ifTrue:[
639
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
   543
	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
   544
    ].
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
   545
    aStream nextPut:theByteCode.
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
   546
    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
   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 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
   550
    theReceiver := receiver arg1.
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
   551
    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
   552
    (selector == #ifTrue:ifFalse:) ifTrue:[
639
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
   553
	jmp := #falseJump
338
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
   554
    ] ifFalse:[
639
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
   555
	jmp := #trueJump
338
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:jmp.
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
   558
    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
   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
    code := aStream contents.
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
   562
    (selector == #ifFalse:ifTrue:) ifTrue:[
639
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
   563
	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
   564
    ].
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
   565
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
   566
    "/ code the if-block
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
   567
    (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
   568
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
   569
    aStream nextPut:#jump.
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
   570
    pos3 := aStream position.
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
   571
    aStream nextPut:0.
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
   572
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
   573
    here := aStream position.
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
   574
    (selector == #ifTrue:ifFalse:) ifTrue:[
639
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
   575
	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
   576
    ].
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
   577
    code at:pos2 put:here.
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
   578
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
   579
    "/ code the else-block
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
   580
    (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
   581
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
   582
    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
   583
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
   584
    "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
   585
!
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
   586
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   587
codeAndIfOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   588
    "generate code for (x and:[y]) ifxxx:[ ... ]"
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   589
812
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   590
    |theByteCode optByteCode andBlock theArg pos1 pos2 pos3 code here jmp
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   591
     receiver1 receiver2 optByteCode2 theArg2|
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   592
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   593
    theByteCode := #falseJump.
812
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   594
    receiver1 := receiver receiver.
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   595
812
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   596
    optByteCode := self optimizedConditionFor:receiver1
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   597
                                         with:theByteCode.
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   598
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   599
    optByteCode notNil ifTrue:[
812
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   600
        ((optByteCode == #eqJump) or:[optByteCode == #notEqJump]) ifTrue:[
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   601
            theArg := receiver1 arg1
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   602
        ].
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   603
        receiver1 := receiver1 receiver.
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   604
        theByteCode := optByteCode
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   605
    ].
812
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   606
    receiver1 codeOn:aStream inBlock:b for:aCompiler.
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   607
    theArg notNil ifTrue:[
812
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   608
        theArg codeOn:aStream inBlock:b for:aCompiler
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   609
    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   610
    aStream nextPut:theByteCode.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   611
    pos1 := aStream position.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   612
    aStream nextPut:0.
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   613
812
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   614
    andBlock := receiver arg1. "/ the and:-block
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   615
    (selector == #ifTrue:) ifTrue:[
812
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   616
        jmp := #falseJump
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   617
    ] ifFalse:[
812
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   618
        jmp := #trueJump
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   619
    ].
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   620
    andBlock statements nextStatement isNil ifTrue:[
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   621
        "/ simple - one statement
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   622
        receiver2 := andBlock statements expression.
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   623
        optByteCode2 := self optimizedConditionFor:receiver2
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   624
                                              with:jmp.
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   625
    ].
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   626
    optByteCode2 notNil ifTrue:[
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   627
        ((optByteCode2 == #eqJump) or:[optByteCode2 == #notEqJump]) ifTrue:[
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   628
            theArg2 := receiver2 arg1
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   629
        ].
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   630
        receiver2 := receiver2 receiver.
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   631
        receiver2 codeOn:aStream inBlock:b for:aCompiler.
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   632
        theArg2 notNil ifTrue:[
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   633
            theArg2 codeOn:aStream inBlock:b for:aCompiler
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   634
        ].
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   635
        jmp := optByteCode2.
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   636
    ] ifFalse:[
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   637
        andBlock codeInlineOn:aStream inBlock:b for:aCompiler.
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   638
    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   639
    aStream nextPut:jmp.
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   640
    pos2 := aStream position.
7ad01559b262 Initial revision
claus
parents:
diff changeset
   641
    aStream nextPut:0.
7ad01559b262 Initial revision
claus
parents:
diff changeset
   642
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   643
    code := aStream contents.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   644
    (selector == #ifFalse:) ifTrue:[
812
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   645
        code at:pos1 put:(aStream position)
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   646
    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   647
    (argArray at: 1) codeInlineOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   648
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   649
    valueNeeded ifTrue:[
812
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   650
        aStream nextPut:#jump.
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   651
        pos3 := aStream position.
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   652
        aStream nextPut:0.
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   653
        here := aStream position.
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   654
        (selector == #ifTrue:) ifTrue:[
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   655
            code at:pos1 put:here
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   656
        ].
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   657
        code at:pos2 put:here.
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   658
        aStream nextPut:#pushNil.
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   659
        code at:pos3 put:(aStream position)
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   660
    ] ifFalse:[
812
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   661
        here := aStream position.
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   662
        (selector == #ifTrue:) ifTrue:[
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   663
            code at:pos1 put:here
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   664
        ].
367d2e8eb499 slightly better code for optimizable and:[...] block in if.
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
   665
        code at:pos2 put:here
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
!
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   668
289
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
   669
codeAndOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
   670
    "generate code for (x and:[y])"
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   671
289
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
   672
    |pos1 rightExpr|
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
   673
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
   674
    receiver codeOn:aStream inBlock:b for:aCompiler.
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
   675
    valueNeeded ifTrue:[
639
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
   676
	aStream nextPut:#dup.
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   677
    ].
289
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
   678
    aStream nextPut:#falseJump.
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
   679
    pos1 := aStream position.
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
   680
    aStream nextPut:0.
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
   681
    valueNeeded ifTrue:[
639
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
   682
	aStream nextPut:#drop.
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   683
    ].
289
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
   684
    rightExpr := argArray at:1.
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
   685
    rightExpr codeInlineOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler.
163
9a7dfd547e69 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   686
289
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
   687
    (aStream contents) at:pos1 put:(aStream position)
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
   688
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
   689
    "Created: 17.6.1996 / 15:46:42 / cg"
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
   690
    "Modified: 17.6.1996 / 15:47:44 / cg"
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   691
!
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   692
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   693
codeForCascadeOn:aStream inBlock:b for:aCompiler
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   694
    "like codeOn, but always leave the receiver instead of the result"
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   695
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   696
    |nargs isBuiltIn code codeL litIndex cls clsLitIndex isSuper realReceiver|
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   697
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   698
    realReceiver := self realReceiver.
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   699
    isSuper := realReceiver isSuper.
886
454c57fbf1c2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 867
diff changeset
   700
    selector := selector asSymbol.
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   701
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   702
    argArray isNil ifTrue:[
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   703
        nargs := 0
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   704
    ] ifFalse:[
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   705
        nargs := argArray size
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   706
    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   707
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   708
    isBuiltIn := false.
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   709
    isSuper ifFalse:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   710
        (nargs == 0) ifTrue:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   711
            isBuiltIn := aCompiler isBuiltInUnarySelector:selector forReceiver:receiver
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   712
        ].
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   713
        (nargs == 1) ifTrue:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   714
            isBuiltIn := aCompiler isBuiltIn1ArgSelector:selector forReceiver:receiver
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   715
        ].
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   716
        (nargs == 2) ifTrue:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   717
            isBuiltIn := aCompiler isBuiltIn2ArgSelector:selector forReceiver:receiver
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   718
        ].
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   719
    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   720
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   721
    receiver codeOn:aStream inBlock:b for:aCompiler.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   722
    aStream nextPut:#dup.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   723
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   724
    "can we use a send-bytecode ?"
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   725
    isBuiltIn ifTrue:[
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   726
        (nargs > 0) ifTrue:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   727
            (argArray at:1) codeOn:aStream inBlock:b for:aCompiler.
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   728
            (nargs > 1) ifTrue:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   729
                (argArray at:2) codeOn:aStream inBlock:b for:aCompiler
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   730
            ]
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   731
        ].
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   732
        aStream nextPut:selector.
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   733
        (aCompiler hasLineNumber:selector) ifTrue:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   734
            aStream nextPut:lineNr.
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   735
        ].
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   736
        aStream nextPut:#drop.
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   737
        ^ self
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   738
    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   739
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   740
    "no - generate a send"
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   741
    argArray notNil ifTrue:[
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   742
        argArray do:[:arg |
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   743
            arg codeOn:aStream inBlock:b for:aCompiler
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   744
        ]
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
    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
   747
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   748
    isSuper ifTrue:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   749
        cls := aCompiler targetClass.
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   750
        realReceiver isHere ifTrue:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   751
            code := #hereSend.
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   752
            codeL := #hereSendL.
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   753
        ] ifFalse:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   754
            code := #superSend.
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   755
            codeL := #superSendL.
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   756
            cls := cls superclass.
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   757
        ].
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   758
        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
   759
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   760
        (litIndex <= 255 and:[clsLitIndex <= 255]) ifTrue:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   761
            aStream nextPut:code; nextPut:lineNr; nextPut:litIndex; nextPut:nargs; nextPut:clsLitIndex; nextPut:#drop.
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   762
            ^ self
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   763
        ].
189
673580572edd fixed cascades involving super sends (i.e. super foo; bar)
Claus Gittinger <cg@exept.de>
parents: 186
diff changeset
   764
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   765
        "need 16bit litIndex"
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   766
        aStream nextPut:codeL; nextPut:lineNr; nextPut:litIndex; nextPut:0; nextPut:nargs; nextPut:clsLitIndex; nextPut:0; nextPut:#drop.
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   767
        ^ self
189
673580572edd fixed cascades involving super sends (i.e. super foo; bar)
Claus Gittinger <cg@exept.de>
parents: 186
diff changeset
   768
    ].
673580572edd fixed cascades involving super sends (i.e. super foo; bar)
Claus Gittinger <cg@exept.de>
parents: 186
diff changeset
   769
673580572edd fixed cascades involving super sends (i.e. super foo; bar)
Claus Gittinger <cg@exept.de>
parents: 186
diff changeset
   770
    litIndex <= 255 ifTrue:[
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   771
        (nargs <= 3) ifTrue:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   772
            code := #(sendDrop0 sendDrop1 sendDrop2 sendDrop3) at:(nargs+1).
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   773
            aStream nextPut:code; nextPut:lineNr; nextPut:litIndex.
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   774
            ^ self
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   775
        ].
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   776
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   777
        aStream nextPut:#sendDrop; nextPut:lineNr; nextPut:litIndex; nextPut:nargs.
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   778
        ^ self
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   779
    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   780
    "need 16bit litIndex"
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   781
    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
   782
886
454c57fbf1c2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 867
diff changeset
   783
    "Modified: / 4.7.1999 / 19:06:53 / cg"
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   784
!
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   785
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   786
codeForSideEffectOn:aStream inBlock:b for:aCompiler
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   787
    self codeOn:aStream inBlock:b valueNeeded:false for:aCompiler
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   788
!
7ad01559b262 Initial revision
claus
parents:
diff changeset
   789
843
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   790
codeForSimpleReturnOn:aStream inBlock:b lineNumber:lineNrOrNil for:aCompiler
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   791
    |arg1 rightExpr pos1|
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   792
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   793
    (selector == #and:
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   794
    or:[selector == #or:]) ifTrue:[
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   795
        arg1 := argArray at:1.
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   796
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   797
        "/ for now:
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   798
        "/ only do it for non-blocks, since
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   799
        "/ the JIT compiler is smart enough to
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   800
        "/ specially optimize the resulting code
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   801
        "/ (and not smart enough to optimized the
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   802
        "/  other - actually more efficient - code)
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   803
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   804
        (arg1 isBlock not 
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   805
"/        or:[arg1 isInlinable]
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   806
        ) ifTrue:[
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   807
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   808
            "/ encode #and: as:
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   809
            "/
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   810
            "/      eLeft
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   811
            "/      jmp_false       LBL
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   812
            "/      eRight
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   813
            "/      retTop
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   814
            "/  LBL:
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   815
            "/      retFalse
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   816
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   817
            "/ encode #or: as:
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   818
            "/
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   819
            "/      eLeft
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   820
            "/      jmp_true       LBL
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   821
            "/      eRight
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   822
            "/      retTop
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   823
            "/  LBL:
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   824
            "/      retTrue
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   825
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   826
            receiver codeOn:aStream inBlock:b for:aCompiler.
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   827
            selector == #and: ifTrue:[
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   828
                aStream nextPut:#falseJump.
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   829
            ] ifFalse:[
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   830
                aStream nextPut:#trueJump.
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   831
            ].
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   832
            pos1 := aStream position.
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   833
            aStream nextPut:0.
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   834
        
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   835
            rightExpr := argArray at:1.
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   836
            rightExpr isBlock ifTrue:[
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   837
                rightExpr codeInlineOn:aStream inBlock:b valueNeeded:true for:aCompiler.
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   838
            ] ifFalse:[
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   839
                rightExpr codeOn:aStream inBlock:b for:aCompiler.
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   840
            ].
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   841
            aStream nextPut:#retTop.
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   842
        
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   843
            (aStream contents) at:pos1 put:(aStream position).
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   844
            selector == #and: ifTrue:[
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   845
                aStream nextPut:#retFalse.
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   846
            ] ifFalse:[
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   847
                aStream nextPut:#retTrue
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   848
            ].
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   849
            ^ self.
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   850
        ].
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   851
    ].
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   852
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   853
    super
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   854
        codeForSimpleReturnOn:aStream 
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   855
        inBlock:b 
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   856
        lineNumber:lineNrOrNil 
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   857
        for:aCompiler
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   858
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   859
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   860
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   861
!
522c116f86d9 boolean-return expression rewrite
Claus Gittinger <cg@exept.de>
parents: 817
diff changeset
   862
104
claus
parents: 103
diff changeset
   863
codeIfElseOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   864
    "generate code for x ifxxx:[ ... ] yyy:[ ...]"
7ad01559b262 Initial revision
claus
parents:
diff changeset
   865
334
cd7491b7ad33 dont code a jump after if-part if it ends in a return.
Claus Gittinger <cg@exept.de>
parents: 309
diff changeset
   866
    |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
   867
     needJump block1|
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   868
7ad01559b262 Initial revision
claus
parents:
diff changeset
   869
    theReceiver := receiver.
76
55d64cb1ffea *** empty log message ***
claus
parents: 75
diff changeset
   870
55d64cb1ffea *** empty log message ***
claus
parents: 75
diff changeset
   871
    (theReceiver isMessage) ifTrue:[
639
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
   872
	subsel := theReceiver selector.
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
   873
	(subsel == #and:) ifTrue:[
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
   874
	    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
   875
	    ^ self
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
   876
	].
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
   877
	(subsel == #or:) ifTrue:[
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
   878
	    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
   879
	    ^ self
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
   880
	]
76
55d64cb1ffea *** empty log message ***
claus
parents: 75
diff changeset
   881
    ].
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   882
    (selector == #ifTrue:ifFalse:) ifTrue:[
639
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
   883
	theByteCode := #falseJump
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   884
    ] ifFalse:[
639
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
   885
	(selector == #ifFalse:ifTrue:) ifTrue:[
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
   886
	    theByteCode := #trueJump
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
   887
	]
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   888
    ].
7ad01559b262 Initial revision
claus
parents:
diff changeset
   889
    optByteCode := self optimizedConditionFor:theReceiver
639
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
   890
					 with:theByteCode.
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   891
    optByteCode notNil ifTrue:[
639
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
   892
	((optByteCode == #eqJump) or:[optByteCode == #notEqJump]) ifTrue:[
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
   893
	    theArg := theReceiver arg1
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
   894
	].
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
   895
	theReceiver := theReceiver receiver.
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
   896
	theByteCode := optByteCode
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   897
    ].
7ad01559b262 Initial revision
claus
parents:
diff changeset
   898
    theByteCode notNil ifTrue:[
639
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
   899
	theReceiver codeOn:aStream inBlock:b for:aCompiler.
53
c5dd7abf8431 *** empty log message ***
claus
parents: 52
diff changeset
   900
639
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
   901
	needLineNr := true.
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
   902
	theArg isNil ifTrue:[
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
   903
	    theReceiver isMessage ifTrue:[
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
   904
		(aCompiler hasLineNumber:(theReceiver selector)) ifTrue:[
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
   905
		    theReceiver lineNumber == lineNr ifTrue:[
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
   906
			needLineNr := false
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
   907
		    ]
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
   908
		]
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
   909
	    ]
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
   910
	] ifFalse:[
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
   911
	    theArg codeOn:aStream inBlock:b for:aCompiler
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
   912
	].
53
c5dd7abf8431 *** empty log message ***
claus
parents: 52
diff changeset
   913
639
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
   914
	needLineNr ifTrue:[
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
   915
	    (lineNr between:1 and:255) ifTrue:[
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
   916
		aStream nextPut:#lineno; nextPut:lineNr.
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
   917
	    ]
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
   918
	].
166
9f6c57a3bce1 no line number bytecode in if-else if not needed
Claus Gittinger <cg@exept.de>
parents: 163
diff changeset
   919
639
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
   920
	aStream nextPut:theByteCode.
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
   921
	pos := aStream position.
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
   922
	aStream nextPut:0.
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
   923
	block1 := argArray at:1.
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
   924
	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
   925
	needJump := true.
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
   926
	(block1 isBlock and:[block1 endsWithReturn]) ifTrue:[
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
   927
	    needJump := false
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
   928
	].
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
   929
	needJump ifTrue:[
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
   930
	    aStream nextPut:#jump.
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
   931
	    pos2 := aStream position.
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
   932
	    aStream nextPut:0.
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
   933
	].
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
   934
	code := aStream contents.
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
   935
	code at:pos put:(aStream position).
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
   936
	(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
   937
	needJump ifTrue:[
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
   938
	    code at:pos2 put:(aStream position)
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
    ]
166
9f6c57a3bce1 no line number bytecode in if-else if not needed
Claus Gittinger <cg@exept.de>
parents: 163
diff changeset
   941
434
c48a356d8a34 oops - optimizable or: ... ifTrue/ifFalse generated
Claus Gittinger <cg@exept.de>
parents: 429
diff changeset
   942
    "Modified: 9.11.1996 / 19:53:52 / cg"
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   943
!
7ad01559b262 Initial revision
claus
parents:
diff changeset
   944
898
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
   945
codeIfNilNotNilOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
   946
    "generate code for x ifNil:[ ... ] ifNotNil:[...]"
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
   947
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
   948
    |pos pos2 theReceiver theArg theByteCode optByteCode subsel code
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
   949
     needLineNr|
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
   950
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
   951
    theReceiver := receiver.
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
   952
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
   953
    (selector == #ifNil:ifNotNil:) ifTrue:[
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
   954
        theByteCode := #notNilJump
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
   955
    ] ifFalse:[
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
   956
        theByteCode := #nilJump
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
   957
    ].
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
   958
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
   959
    theReceiver codeOn:aStream inBlock:b for:aCompiler.
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
   960
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
   961
    needLineNr := true.
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
   962
    theArg isNil ifTrue:[
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
   963
        theReceiver isMessage ifTrue:[
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
   964
            (aCompiler hasLineNumber:(theReceiver selector)) ifTrue:[
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
   965
                theReceiver lineNumber == lineNr ifTrue:[
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
   966
                    needLineNr := false
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
   967
                ]
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
   968
            ]
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
   969
        ]
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
   970
    ].
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
   971
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
   972
    needLineNr ifTrue:[
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
   973
        (lineNr between:1 and:255) ifTrue:[
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
   974
            aStream nextPut:#lineno; nextPut:lineNr.
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
   975
        ]
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
   976
    ].
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
   977
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
   978
    aStream nextPut:theByteCode.
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
   979
    pos := aStream position.
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
   980
    aStream nextPut:0.
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
   981
    (argArray at: 1) codeInlineOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler.
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
   982
    aStream nextPut:#jump.
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
   983
    pos2 := aStream position.
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
   984
    aStream nextPut:0.
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
   985
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
   986
    code := aStream contents.
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
   987
    code at:pos put:(aStream position).
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
   988
    (argArray at: 2) codeInlineOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler.
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
   989
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
   990
    code := aStream contents.
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
   991
    code at:pos2 put:(aStream position)
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
   992
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
   993
    "Modified: / 28.10.1997 / 18:33:42 / cg"
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
   994
!
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
   995
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
   996
codeIfNilOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
   997
    "generate code for x ifNil:[ ... ]"
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
   998
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
   999
    |pos pos2 theReceiver theArg theByteCode optByteCode subsel code
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1000
     needLineNr|
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1001
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1002
    theReceiver := receiver.
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1003
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1004
    (selector == #ifNil:) ifTrue:[
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1005
        theByteCode := #notNilJump
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1006
    ] ifFalse:[
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1007
        theByteCode := #nilJump
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1008
    ].
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1009
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1010
    theReceiver codeOn:aStream inBlock:b for:aCompiler.
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1011
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1012
    needLineNr := true.
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1013
    theArg isNil ifTrue:[
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1014
        theReceiver isMessage ifTrue:[
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1015
            (aCompiler hasLineNumber:(theReceiver selector)) ifTrue:[
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1016
                theReceiver lineNumber == lineNr ifTrue:[
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1017
                    needLineNr := false
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1018
                ]
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1019
            ]
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1020
        ]
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1021
    ].
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1022
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1023
    needLineNr ifTrue:[
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1024
        (lineNr between:1 and:255) ifTrue:[
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1025
            aStream nextPut:#lineno; nextPut:lineNr.
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1026
        ]
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1027
    ].
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1028
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1029
    valueNeeded ifTrue:[
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1030
        aStream nextPut:#dup.
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1031
    ].
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1032
    aStream nextPut:theByteCode.
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1033
    pos := aStream position.
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1034
    aStream nextPut:0.
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1035
    valueNeeded ifTrue:[
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1036
        aStream nextPut:#drop.
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1037
    ].
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1038
    (argArray at: 1) codeInlineOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler.
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1039
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1040
    code := aStream contents.
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1041
    code at:pos put:(aStream position)
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1042
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1043
    "Modified: / 28.10.1997 / 18:33:42 / cg"
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1044
!
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1045
104
claus
parents: 103
diff changeset
  1046
codeIfOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1047
    "generate code for x ifxxx:[ ... ]"
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1048
103
claus
parents: 102
diff changeset
  1049
    |pos pos2 theReceiver theArg theByteCode optByteCode subsel code
claus
parents: 102
diff changeset
  1050
     needLineNr|
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1051
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1052
    theReceiver := receiver.
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1053
76
55d64cb1ffea *** empty log message ***
claus
parents: 75
diff changeset
  1054
    (theReceiver isMessage) ifTrue:[
639
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1055
	subsel := theReceiver selector.
308
fe3b95e6d9c0 oops - dont try to inline: (expr or:expr2) ifXXX
Claus Gittinger <cg@exept.de>
parents: 289
diff changeset
  1056
639
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1057
	(subsel == #and:) ifTrue:[
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1058
	    theReceiver arg1 isBlock ifTrue:[
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1059
		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
  1060
		^ self
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1061
	    ]
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1062
	].
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1063
	(subsel == #or:) ifTrue:[
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1064
	    theReceiver arg1 isBlock ifTrue:[
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1065
		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
  1066
		^ self
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1067
	    ]
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1068
	].
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1069
    ].
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1070
    (selector == #ifTrue:) ifTrue:[
639
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1071
	theByteCode := #falseJump
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1072
    ] ifFalse:[
639
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1073
	theByteCode := #trueJump
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1074
    ].
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1075
    optByteCode := self optimizedConditionFor:theReceiver
639
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1076
					 with:theByteCode.
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1077
    optByteCode notNil ifTrue:[
639
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1078
	((optByteCode == #eqJump) or:[optByteCode == #notEqJump]) ifTrue:[
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1079
	    theArg := theReceiver arg1
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1080
	].
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1081
	theReceiver := theReceiver receiver.
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1082
	theByteCode := optByteCode
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1083
    ].
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1084
104
claus
parents: 103
diff changeset
  1085
    theReceiver codeOn:aStream inBlock:b for:aCompiler.
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1086
    theArg notNil ifTrue:[
639
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1087
	theArg codeOn:aStream inBlock:b for:aCompiler
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1088
    ].
53
c5dd7abf8431 *** empty log message ***
claus
parents: 52
diff changeset
  1089
103
claus
parents: 102
diff changeset
  1090
    needLineNr := true.
claus
parents: 102
diff changeset
  1091
    theArg isNil ifTrue:[
639
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1092
	theReceiver isMessage ifTrue:[
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1093
	    (aCompiler hasLineNumber:(theReceiver selector)) ifTrue:[
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1094
		theReceiver lineNumber == lineNr ifTrue:[
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1095
		    needLineNr := false
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1096
		]
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1097
	    ]
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1098
	]
103
claus
parents: 102
diff changeset
  1099
    ].
claus
parents: 102
diff changeset
  1100
claus
parents: 102
diff changeset
  1101
    needLineNr ifTrue:[
639
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1102
	(lineNr between:1 and:255) ifTrue:[
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1103
	    aStream nextPut:#lineno; nextPut:lineNr.
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1104
	]
53
c5dd7abf8431 *** empty log message ***
claus
parents: 52
diff changeset
  1105
    ].
c5dd7abf8431 *** empty log message ***
claus
parents: 52
diff changeset
  1106
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1107
    aStream nextPut:theByteCode.
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1108
    pos := aStream position.
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1109
    aStream nextPut:0.
104
claus
parents: 103
diff changeset
  1110
    (argArray at: 1) codeInlineOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler.
76
55d64cb1ffea *** empty log message ***
claus
parents: 75
diff changeset
  1111
55d64cb1ffea *** empty log message ***
claus
parents: 75
diff changeset
  1112
    code := aStream contents.
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1113
    valueNeeded ifTrue:[
639
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1114
	aStream nextPut:#jump.
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1115
	pos2 := aStream position.
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1116
	aStream nextPut:0.
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1117
	code at:pos put:(aStream position).
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1118
	aStream nextPut:#pushNil.
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1119
	code at:pos2 put:(aStream position)
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1120
    ] ifFalse:[
639
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1121
	code at:pos put:(aStream position)
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1122
    ]
308
fe3b95e6d9c0 oops - dont try to inline: (expr or:expr2) ifXXX
Claus Gittinger <cg@exept.de>
parents: 289
diff changeset
  1123
627
b29a02258247 comments
Claus Gittinger <cg@exept.de>
parents: 624
diff changeset
  1124
    "Modified: / 28.10.1997 / 18:33:42 / cg"
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1125
!
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1126
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1127
codeOn:aStream inBlock:b for:aCompiler
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1128
    self codeOn:aStream inBlock:b valueNeeded:true for:aCompiler
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1129
!
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1130
104
claus
parents: 103
diff changeset
  1131
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
  1132
    |recType nargs isBuiltIn litIndex cls clsLitIndex code isSpecial
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1133
     specialCode stackTop arg1 arg2 arg3 isSuper realReceiver|
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1134
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1135
    realReceiver := self realReceiver.
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1136
    isSuper := realReceiver isSuper.
867
7d20544c2c63 oops - late selector as symbol
Claus Gittinger <cg@exept.de>
parents: 861
diff changeset
  1137
    selector := selector asSymbol.
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1138
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1139
    argArray isNil ifTrue:[
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1140
        nargs := 0
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1141
    ] ifFalse:[
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1142
        nargs := argArray size.
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1143
        nargs > 0 ifTrue:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1144
            arg1 := argArray at:1.
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1145
            nargs > 1 ifTrue:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1146
                arg2 := argArray at:2.
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1147
                nargs > 2 ifTrue:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1148
                    arg3 := argArray at:3.
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1149
                ]
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1150
            ]    
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1151
        ].
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1152
    ].
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1153
199
1b3b350a3f59 moved bytecode query methods into compiler;
Claus Gittinger <cg@exept.de>
parents: 189
diff changeset
  1154
    isBuiltIn := isSpecial := false.
117
claus
parents: 111
diff changeset
  1155
    recType := receiver type.
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1156
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1157
    (nargs == 0) ifTrue:[
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1158
        (recType == #ThisContext) ifTrue:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1159
            valueNeeded ifFalse:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1160
                "for now, only do it in methods"
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1161
                b isNil ifTrue:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1162
                    (selector == #restart) ifTrue:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1163
                        aStream nextPut:#jump; nextPut:1.      "jump to start"
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1164
                        ^ self
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1165
                    ].
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1166
                ].
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1167
                (selector == #return) ifTrue:[  "^ nil"
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1168
                    aStream nextPut:#retNil.
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1169
                    ^ self
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1170
                ].
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1171
            ]
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1172
        ].
52
d80ec10c3321 *** empty log message ***
claus
parents: 49
diff changeset
  1173
851
4afe809029f6 oops - care for block-num-args being correct when
Claus Gittinger <cg@exept.de>
parents: 843
diff changeset
  1174
        (receiver isBlock 
4afe809029f6 oops - care for block-num-args being correct when
Claus Gittinger <cg@exept.de>
parents: 843
diff changeset
  1175
        and:[receiver numArgs == 0
4afe809029f6 oops - care for block-num-args being correct when
Claus Gittinger <cg@exept.de>
parents: 843
diff changeset
  1176
        and:[receiver isInlinable]]) ifTrue:[
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1177
            selector == #value ifTrue:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1178
                receiver codeInlineOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler.
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1179
                ^ self
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1180
            ].
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1181
            ((selector == #whileTrue) or:[selector == #whileFalse]) ifTrue:[
851
4afe809029f6 oops - care for block-num-args being correct when
Claus Gittinger <cg@exept.de>
parents: 843
diff changeset
  1182
                ^ self codeWhileOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler.
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1183
            ].
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1184
            (selector == #repeat) ifTrue:[
851
4afe809029f6 oops - care for block-num-args being correct when
Claus Gittinger <cg@exept.de>
parents: 843
diff changeset
  1185
                valueNeeded ifFalse:[
4afe809029f6 oops - care for block-num-args being correct when
Claus Gittinger <cg@exept.de>
parents: 843
diff changeset
  1186
                    ^ self codeRepeatOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler.
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1187
                ]
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1188
            ].
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1189
        ].
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1190
        isSuper ifFalse:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1191
            isBuiltIn := aCompiler isBuiltInUnarySelector:selector forReceiver:receiver.
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1192
        ]
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1193
    ].
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1194
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1195
    (nargs == 1) ifTrue:[
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1196
        (recType == #ThisContext) ifTrue:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1197
            valueNeeded ifFalse:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1198
                (selector == #return:) ifTrue:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1199
                    arg1 codeOn:aStream inBlock:b for:aCompiler.  "^ value"
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1200
                    aStream nextPut:#retTop.
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1201
                    ^ self
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1202
                ].
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1203
             ].
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1204
        ].
19
84a1ddf215a5 *** empty log message ***
claus
parents: 15
diff changeset
  1205
851
4afe809029f6 oops - care for block-num-args being correct when
Claus Gittinger <cg@exept.de>
parents: 843
diff changeset
  1206
        (arg1 isBlock 
4afe809029f6 oops - care for block-num-args being correct when
Claus Gittinger <cg@exept.de>
parents: 843
diff changeset
  1207
        and:[arg1 isInlinable
4afe809029f6 oops - care for block-num-args being correct when
Claus Gittinger <cg@exept.de>
parents: 843
diff changeset
  1208
        and:[arg1 numArgs == 0]]) ifTrue:[
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1209
            ((selector == #ifTrue:) or:[selector == #ifFalse:]) ifTrue:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1210
                receiver isBlock ifFalse:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1211
                    ^ self codeIfOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler.
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1212
                ].
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1213
            ].
898
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1214
            ((selector == #ifNil:) or:[selector == #ifNotNil:]) ifTrue:[
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1215
                receiver isBlock ifFalse:[
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1216
                    ^ self codeIfNilOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler.
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1217
                ].
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1218
            ].
289
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  1219
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1220
            (selector == #or:) ifTrue:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1221
                ^ self codeOrOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler.
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1222
            ].
289
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  1223
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1224
            (selector == #and:) ifTrue:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1225
                ^ self codeAndOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler.
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1226
            ].
289
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  1227
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1228
            (selector == #timesRepeat:) ifTrue:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1229
                "/ now, always inline #timesRepeat:;
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1230
                "/ the receiver must understand #> and #-
564
ffac5191213f always inline #timesRepeat: (as #> 0 ... - 1)
Claus Gittinger <cg@exept.de>
parents: 561
diff changeset
  1231
                
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1232
               ^ self codeTimesRepeatOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler.
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1233
            ].
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1234
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1235
            ((selector == #whileTrue:) or:[selector == #whileFalse:]) ifTrue:[
851
4afe809029f6 oops - care for block-num-args being correct when
Claus Gittinger <cg@exept.de>
parents: 843
diff changeset
  1236
                (receiver isBlock 
4afe809029f6 oops - care for block-num-args being correct when
Claus Gittinger <cg@exept.de>
parents: 843
diff changeset
  1237
                and:[receiver isInlinable
4afe809029f6 oops - care for block-num-args being correct when
Claus Gittinger <cg@exept.de>
parents: 843
diff changeset
  1238
                and:[receiver numArgs == 0]]) ifTrue:[
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1239
                    ^ self codeWhileOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler.
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1240
                ]
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1241
            ]
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1242
        ].
436
b34370bb0a74 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 434
diff changeset
  1243
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1244
        selector == #? ifTrue:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1245
            "/ only do short-circuit optimization, if arg is not a message;
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1246
            "/ (could have side-effects)
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1247
            "/
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1248
            arg1 isMessage ifFalse:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1249
                ^ self codeQuestOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler.
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1250
            ]
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1251
        ].
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1252
        isSuper ifFalse:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1253
            isBuiltIn := aCompiler isBuiltIn1ArgSelector:selector forReceiver:receiver.
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1254
        ]
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1255
    ].
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1256
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1257
    (nargs == 2) ifTrue:[
898
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1258
        receiver isBlock ifFalse:[
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1259
            (arg1 isBlock 
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1260
            and:[arg1 isInlinable
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1261
            and:[arg1 numArgs == 0
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1262
            and:[arg2 isBlock 
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1263
            and:[arg2 isInlinable
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1264
            and:[arg2 numArgs == 0]]]]]) ifTrue:[
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1265
                ((selector == #ifTrue:ifFalse:) or:[selector == #ifFalse:ifTrue:]) ifTrue:[
851
4afe809029f6 oops - care for block-num-args being correct when
Claus Gittinger <cg@exept.de>
parents: 843
diff changeset
  1266
                    ^ self codeIfElseOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler.
898
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1267
                ].
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1268
                ((selector == #ifNil:ifNotNil:) or:[selector == #ifNotNil:ifNil:]) ifTrue:[
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  1269
                    ^ self codeIfNilNotNilOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler.
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1270
                ]
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1271
            ]
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1272
        ].
536
9fe0b3be6672 better code for <int> to: <int> do:[unusedArg | ...]
Claus Gittinger <cg@exept.de>
parents: 531
diff changeset
  1273
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1274
        selector == #to:do: ifTrue:[
851
4afe809029f6 oops - care for block-num-args being correct when
Claus Gittinger <cg@exept.de>
parents: 843
diff changeset
  1275
            (arg2 isBlock 
4afe809029f6 oops - care for block-num-args being correct when
Claus Gittinger <cg@exept.de>
parents: 843
diff changeset
  1276
            and:[arg2 isInlinable 
4afe809029f6 oops - care for block-num-args being correct when
Claus Gittinger <cg@exept.de>
parents: 843
diff changeset
  1277
            and:[arg2 numArgs == 1]]) ifTrue:[
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1278
                ^ self codeToDoOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1279
            ]
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1280
        ].
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1281
        isSuper ifFalse:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1282
            isBuiltIn := aCompiler isBuiltIn2ArgSelector:selector forReceiver:receiver.
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1283
        ]
531
1d037c37e5a2 code cleanup
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1284
    ].
1d037c37e5a2 code cleanup
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1285
565
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1286
    (nargs == 3) ifTrue:[
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1287
        selector == #to:by:do: ifTrue:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1288
            "/ step must be a constant (need to know how to compare)
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1289
            (arg2 isConstant 
851
4afe809029f6 oops - care for block-num-args being correct when
Claus Gittinger <cg@exept.de>
parents: 843
diff changeset
  1290
            and:[arg2 type == #Integer
4afe809029f6 oops - care for block-num-args being correct when
Claus Gittinger <cg@exept.de>
parents: 843
diff changeset
  1291
            and:[arg3 isBlock 
4afe809029f6 oops - care for block-num-args being correct when
Claus Gittinger <cg@exept.de>
parents: 843
diff changeset
  1292
            and:[arg3 isInlinable 
4afe809029f6 oops - care for block-num-args being correct when
Claus Gittinger <cg@exept.de>
parents: 843
diff changeset
  1293
            and:[arg3 numArgs == 1]]]]) ifTrue:[
4afe809029f6 oops - care for block-num-args being correct when
Claus Gittinger <cg@exept.de>
parents: 843
diff changeset
  1294
                ^ self codeToByDoOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1295
            ]
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1296
        ].
565
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1297
    ].
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1298
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1299
    isSuper ifFalse:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1300
        isBuiltIn ifFalse:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1301
            specialCode := aCompiler specialSendCodeFor:selector.
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1302
            isSpecial := specialCode notNil.
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1303
        ].
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1304
    ].
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1305
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1306
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1307
    "can we use a send-bytecode ?"
199
1b3b350a3f59 moved bytecode query methods into compiler;
Claus Gittinger <cg@exept.de>
parents: 189
diff changeset
  1308
    (isBuiltIn or:[isSpecial]) ifTrue:[
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1309
        receiver codeOn:aStream inBlock:b for:aCompiler.
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1310
        (nargs > 0) ifTrue:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1311
            arg1 codeOn:aStream inBlock:b for:aCompiler.
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1312
            (nargs > 1) ifTrue:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1313
                arg2 codeOn:aStream inBlock:b for:aCompiler
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1314
            ]
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1315
        ].
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1316
        aStream nextPut:selector.
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1317
        (aCompiler hasLineNumber:selector) ifTrue:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1318
            aStream nextPut:lineNr.
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1319
        ].
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1320
        isSpecial ifTrue:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1321
            aStream nextPut:specialCode
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1322
        ].
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1323
        valueNeeded ifFalse:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1324
            aStream nextPut:#drop
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1325
        ].
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1326
        ^ self
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1327
    ].
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1328
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1329
    ((nargs == 0) and:[selector == #yourself]) ifTrue:[
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1330
        "yourself is often added to get the receiver -
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1331
         we get it without the yourself-message"
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1332
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1333
        valueNeeded ifTrue:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1334
            receiver codeOn:aStream inBlock:b for:aCompiler
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1335
        ].
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1336
        ^ self
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1337
    ].
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1338
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1339
    "no - generate a send"
117
claus
parents: 111
diff changeset
  1340
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1341
    isSuper ifTrue:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1342
        cls := aCompiler targetClass.
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1343
        realReceiver isHere ifTrue:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1344
            code := #hereSend.
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1345
        ] ifFalse:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1346
            code := #superSend.
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1347
            cls := cls superclass.
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1348
        ].
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1349
        clsLitIndex := aCompiler addLiteral:cls.
117
claus
parents: 111
diff changeset
  1350
    ] ifFalse:[
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1351
        clsLitIndex := 0.
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1352
    ].
106
claus
parents: 104
diff changeset
  1353
117
claus
parents: 111
diff changeset
  1354
    litIndex := aCompiler addLiteral:selector.
claus
parents: 111
diff changeset
  1355
    (litIndex <= 255 and:[clsLitIndex <= 255]) ifTrue:[
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1356
        stackTop := nil.
117
claus
parents: 111
diff changeset
  1357
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1358
        (recType ~~ #Self) ifTrue:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1359
            receiver codeOn:aStream inBlock:b for:aCompiler.
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1360
            receiver isConstant ifTrue:[ 
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1361
                stackTop := receiver
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1362
            ]
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1363
        ].
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1364
        argArray notNil ifTrue:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1365
            argArray do:[:arg |
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1366
                (stackTop notNil 
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1367
                and:[arg canReuseAsArg:stackTop]) ifTrue:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1368
                    aStream nextPut:#dup.
245
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
  1369
"/ 'reuse:' print. stackTop print. ' in ' print. aCompiler selector printNL.
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1370
                ] ifFalse:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1371
                    arg codeOn:aStream inBlock:b for:aCompiler.
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1372
                    stackTop := arg.
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1373
                ]
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1374
            ]
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1375
        ].
106
claus
parents: 104
diff changeset
  1376
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1377
        isSuper ifTrue:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1378
            aStream nextPut:code; nextPut:lineNr; nextPut:litIndex; nextPut:nargs; nextPut:clsLitIndex.
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1379
            valueNeeded ifFalse:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1380
                aStream nextPut:#drop
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1381
            ].
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1382
            ^ self
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1383
        ].
245
8a78aa886351 use dup if possible when pushing args
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
  1384
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1385
        (nargs <= 3) ifTrue:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1386
            |codes|
106
claus
parents: 104
diff changeset
  1387
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1388
            valueNeeded ifTrue:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1389
                (recType == #Self) ifTrue:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1390
                    codes := #(sendSelf0 sendSelf1 sendSelf2 sendSelf3)
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1391
                ] ifFalse:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1392
                    codes := #(send0 send1 send2 send3)
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1393
                ]
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1394
            ] ifFalse:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1395
                (recType == #Self) ifTrue:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1396
                    codes := #(sendSelfDrop0 sendSelfDrop1 sendSelfDrop2 sendSelfDrop3)
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1397
                ] ifFalse:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1398
                    codes := #(sendDrop0 sendDrop1 sendDrop2 sendDrop3)
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1399
                ]
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1400
            ].
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1401
            aStream nextPut:(codes at:(nargs + 1)); nextPut:lineNr; nextPut:litIndex.
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1402
            ^ self
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1403
        ].
106
claus
parents: 104
diff changeset
  1404
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1405
        (recType == #Self) ifTrue:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1406
            code := #sendSelf
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1407
        ] ifFalse:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1408
            valueNeeded ifTrue:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1409
                code := #send
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1410
            ] ifFalse:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1411
                code := #sendDrop
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1412
            ]
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1413
        ].
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1414
        aStream nextPut:code; nextPut:lineNr; nextPut:litIndex; nextPut:nargs.
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1415
        valueNeeded ifFalse:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1416
            (recType == #Self) ifTrue:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1417
                aStream nextPut:#drop
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1418
            ]
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1419
        ].
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1420
        ^ self
106
claus
parents: 104
diff changeset
  1421
    ].
claus
parents: 104
diff changeset
  1422
claus
parents: 104
diff changeset
  1423
    "needs 16bit literal index"
117
claus
parents: 111
diff changeset
  1424
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1425
    isSuper ifTrue:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1426
        argArray notNil ifTrue:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1427
            argArray do:[:arg |
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1428
                arg codeOn:aStream inBlock:b for:aCompiler
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1429
            ]
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1430
        ].
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1431
        realReceiver isHere ifTrue:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1432
            code := #hereSendL
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1433
        ] ifFalse:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1434
            code := #superSendL.
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1435
        ].
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1436
        aStream nextPut:code; nextPut:lineNr; nextPut:litIndex; nextPut:0; nextPut:nargs; nextPut:clsLitIndex; nextPut:0.
117
claus
parents: 111
diff changeset
  1437
    ] ifFalse:[
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1438
        recType ~~ #Self ifTrue:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1439
            receiver codeOn:aStream inBlock:b for:aCompiler.
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1440
        ].
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1441
        argArray notNil ifTrue:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1442
            argArray do:[:arg |
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1443
                arg codeOn:aStream inBlock:b for:aCompiler
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1444
            ]
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1445
        ].
117
claus
parents: 111
diff changeset
  1446
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1447
        recType == #Self ifTrue:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1448
            code := #sendSelfL
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1449
        ] ifFalse:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1450
            code := #sendL
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1451
        ].
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1452
        aStream nextPut:code; nextPut:lineNr; nextPut:litIndex; nextPut:0; nextPut:nargs.
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1453
    ].
117
claus
parents: 111
diff changeset
  1454
    valueNeeded ifFalse:[
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1455
        aStream nextPut:#drop
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1456
    ].
117
claus
parents: 111
diff changeset
  1457
627
b29a02258247 comments
Claus Gittinger <cg@exept.de>
parents: 624
diff changeset
  1458
    "Modified: / 3.9.1995 / 12:55:42 / claus"
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1459
    "Modified: / 16.7.1998 / 20:26:38 / cg"
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1460
!
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1461
338
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1462
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
  1463
    "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
  1464
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1465
    |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
  1466
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1467
    theByteCode := #trueJump.
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1468
    theReceiver := receiver receiver.
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1469
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1470
    optByteCode := self optimizedConditionFor:theReceiver
639
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1471
					 with:theByteCode.
338
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1472
    optByteCode notNil ifTrue:[
639
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1473
	((optByteCode == #eqJump) or:[optByteCode == #notEqJump]) ifTrue:[
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1474
	    theArg := theReceiver arg1
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1475
	].
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1476
	theReceiver := theReceiver receiver.
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1477
	theByteCode := optByteCode
338
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1478
    ].
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1479
    "/ 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
  1480
    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
  1481
    theArg notNil ifTrue:[
639
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1482
	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
  1483
    ].
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1484
    aStream nextPut:theByteCode.
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1485
    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
  1486
    aStream nextPut:0.
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1487
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1488
    "/ 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
  1489
    theReceiver := receiver arg1.
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1490
    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
  1491
    (selector == #ifTrue:ifFalse:) ifTrue:[
639
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1492
	jmp := #falseJump
338
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1493
    ] ifFalse:[
639
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1494
	jmp := #trueJump
338
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1495
    ].
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1496
    aStream nextPut:jmp.
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1497
    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
  1498
    aStream nextPut:0.
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1499
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1500
    code := aStream contents.
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1501
    (selector == #ifTrue:ifFalse:) ifTrue:[
639
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1502
	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
  1503
    ].
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1504
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1505
    "/ code the if-block
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1506
    (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
  1507
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1508
    aStream nextPut:#jump.
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1509
    pos3 := aStream position.
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1510
    aStream nextPut:0.
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1511
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1512
    here := aStream position.
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1513
    (selector == #ifFalse:ifTrue:) ifTrue:[
639
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1514
	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
  1515
    ].
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1516
    code at:pos2 put:here.
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1517
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1518
    "/ code the else-block
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1519
    (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
  1520
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1521
    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
  1522
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1523
    "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
  1524
!
8ab1a2715ab1 better code for (expr and:/or:[expr2]) ifXXX:[ .. ] ifYYY:[ ... ]
Claus Gittinger <cg@exept.de>
parents: 334
diff changeset
  1525
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1526
codeOrIfOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1527
    "generate code for (x or:[y]) ifxxx:[ ... ]"
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1528
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1529
    |theByteCode optByteCode theReceiver theArg pos1 pos2 pos3 code here jmp|
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1530
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1531
    theByteCode := #trueJump.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1532
    theReceiver := receiver receiver.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1533
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1534
    optByteCode := self optimizedConditionFor:theReceiver with:theByteCode.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1535
    optByteCode notNil ifTrue:[
639
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1536
	((optByteCode == #eqJump) or:[optByteCode == #notEqJump]) ifTrue:[
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1537
	    theArg := theReceiver arg1
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
	theReceiver := theReceiver receiver.
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1540
	theByteCode := optByteCode
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1541
    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1542
    theReceiver codeOn:aStream inBlock:b for:aCompiler.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1543
    theArg notNil ifTrue:[
639
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1544
	theArg codeOn:aStream inBlock:b for:aCompiler
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1545
    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1546
    aStream nextPut:theByteCode.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1547
    pos1 := aStream position.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1548
    aStream nextPut:0.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1549
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1550
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1551
    theReceiver := receiver arg1.
434
c48a356d8a34 oops - optimizable or: ... ifTrue/ifFalse generated
Claus Gittinger <cg@exept.de>
parents: 429
diff changeset
  1552
    theArg := nil.
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1553
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1554
"new:"
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1555
    (selector == #ifTrue:) ifTrue:[
639
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1556
	theByteCode := #falseJump
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1557
    ] ifFalse:[
639
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1558
	theByteCode := #trueJump
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1559
    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1560
    optByteCode := self optimizedConditionFor:theReceiver with:theByteCode.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1561
    optByteCode notNil ifTrue:[
639
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1562
	theReceiver isBlock ifTrue:[
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1563
	    theReceiver := theReceiver statements expression
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1564
	].
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1565
	((optByteCode == #eqJump) or:[optByteCode == #notEqJump]) ifTrue:[
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1566
	    theArg := theReceiver arg1
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1567
	].
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1568
	theReceiver := theReceiver receiver.
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1569
	theByteCode := optByteCode.
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1570
639
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1571
	theReceiver codeOn:aStream inBlock:b for:aCompiler.
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1572
	theArg notNil ifTrue:[
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1573
	    theArg codeOn:aStream inBlock:b for:aCompiler
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1574
	].
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1575
	aStream nextPut:theByteCode.
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1576
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1577
    ] ifFalse:[
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1578
"org"
639
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1579
	theReceiver codeInlineOn:aStream inBlock:b for:aCompiler.
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1580
	(selector == #ifTrue:) ifTrue:[
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1581
	    jmp := #falseJump
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1582
	] ifFalse:[
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1583
	    jmp := #trueJump
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1584
	].
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1585
	aStream nextPut:jmp
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1586
    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1587
    pos2 := aStream position.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1588
    aStream nextPut:0.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1589
    (selector == #ifTrue:) ifTrue:[
639
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1590
	(aStream contents) at:pos1 put:(aStream position)
140
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
    (argArray at: 1) codeInlineOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1593
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1594
    code := aStream contents.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1595
    valueNeeded ifTrue:[
639
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1596
	aStream nextPut:#jump.
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1597
	pos3 := aStream position.
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1598
	aStream nextPut:0.
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1599
	here := aStream position.
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1600
	(selector == #ifFalse:) ifTrue:[
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1601
	    code at:pos1 put:here
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1602
	].
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1603
	code at:pos2 put:here.
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1604
	aStream nextPut:#pushNil.
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1605
	code at:pos3 put:(aStream position)
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1606
    ] ifFalse:[
639
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1607
	here := aStream position.
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1608
	(selector == #ifFalse:) ifTrue:[
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1609
	    code at:pos1 put:here
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1610
	].
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1611
	code at:pos2 put:here
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1612
    ]
434
c48a356d8a34 oops - optimizable or: ... ifTrue/ifFalse generated
Claus Gittinger <cg@exept.de>
parents: 429
diff changeset
  1613
c48a356d8a34 oops - optimizable or: ... ifTrue/ifFalse generated
Claus Gittinger <cg@exept.de>
parents: 429
diff changeset
  1614
    "Modified: 9.11.1996 / 19:52:26 / cg"
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1615
!
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1616
289
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  1617
codeOrOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  1618
    "generate code for (x or:[y])"
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  1619
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  1620
    |pos1 rightExpr|
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  1621
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  1622
    receiver codeOn:aStream inBlock:b for:aCompiler.
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  1623
    valueNeeded ifTrue:[
639
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1624
	aStream nextPut:#dup.
289
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  1625
    ].
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  1626
    aStream nextPut:#trueJump.
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  1627
    pos1 := aStream position.
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  1628
    aStream nextPut:0.
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  1629
    valueNeeded ifTrue:[
639
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1630
	aStream nextPut:#drop.
289
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  1631
    ].
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  1632
    rightExpr := argArray at:1.
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  1633
    rightExpr codeInlineOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler.
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  1634
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  1635
    (aStream contents) at:pos1 put:(aStream position)
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  1636
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  1637
    "Created: 17.6.1996 / 15:40:22 / cg"
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  1638
    "Modified: 17.6.1996 / 15:47:22 / cg"
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  1639
!
7134d1233ba6 better code for and: / or:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
  1640
436
b34370bb0a74 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 434
diff changeset
  1641
codeQuestOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler
627
b29a02258247 comments
Claus Gittinger <cg@exept.de>
parents: 624
diff changeset
  1642
    "generate code for x ? y. 
b29a02258247 comments
Claus Gittinger <cg@exept.de>
parents: 624
diff changeset
  1643
     However, this is only done for non-send args."
436
b34370bb0a74 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 434
diff changeset
  1644
b34370bb0a74 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 434
diff changeset
  1645
    |pos code|
b34370bb0a74 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 434
diff changeset
  1646
b34370bb0a74 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 434
diff changeset
  1647
    receiver codeOn:aStream inBlock:b for:aCompiler.
b34370bb0a74 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 434
diff changeset
  1648
    aStream nextPut:#dup.
b34370bb0a74 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 434
diff changeset
  1649
    aStream nextPut:#notNilJump.
b34370bb0a74 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 434
diff changeset
  1650
    pos := aStream position.
437
994414f5126a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 436
diff changeset
  1651
    aStream nextPut:0.
436
b34370bb0a74 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 434
diff changeset
  1652
b34370bb0a74 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 434
diff changeset
  1653
    aStream nextPut:#drop.
b34370bb0a74 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 434
diff changeset
  1654
    (argArray at: 1) codeOn:aStream inBlock:b for:aCompiler.
b34370bb0a74 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 434
diff changeset
  1655
b34370bb0a74 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 434
diff changeset
  1656
    code := aStream contents.
b34370bb0a74 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 434
diff changeset
  1657
    code at:pos put:(aStream position)
b34370bb0a74 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 434
diff changeset
  1658
627
b29a02258247 comments
Claus Gittinger <cg@exept.de>
parents: 624
diff changeset
  1659
    "Created: / 10.11.1996 / 18:28:57 / cg"
b29a02258247 comments
Claus Gittinger <cg@exept.de>
parents: 624
diff changeset
  1660
    "Modified: / 28.10.1997 / 18:16:20 / cg"
436
b34370bb0a74 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 434
diff changeset
  1661
!
b34370bb0a74 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 434
diff changeset
  1662
602
1be5dd333adc inline #repeat
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1663
codeRepeatOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler
1be5dd333adc inline #repeat
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1664
    "generate code for [ ... ] repeat"
1be5dd333adc inline #repeat
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1665
1be5dd333adc inline #repeat
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1666
    |pos|
1be5dd333adc inline #repeat
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1667
1be5dd333adc inline #repeat
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1668
    pos := aStream position.
1be5dd333adc inline #repeat
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1669
    receiver codeInlineOn:aStream inBlock:b valueNeeded:false for:aCompiler.
1be5dd333adc inline #repeat
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1670
    aStream nextPut:#jump; nextPut:pos.
1be5dd333adc inline #repeat
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1671
1be5dd333adc inline #repeat
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1672
    "Created: 29.8.1997 / 08:14:58 / cg"
1be5dd333adc inline #repeat
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1673
!
1be5dd333adc inline #repeat
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1674
104
claus
parents: 103
diff changeset
  1675
codeSendOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1676
    "like code on, but assumes that receiver has already been
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1677
     coded onto stack - needed for cascade"
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1678
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1679
    |nargs isBuiltIn code codeL litIndex cls clsLitIndex isSuper realReceiver|
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1680
861
ccaa0ba5e7af generate selector symbols late (when compiling or evaluating)
Claus Gittinger <cg@exept.de>
parents: 856
diff changeset
  1681
    selector := selector asSymbol.
ccaa0ba5e7af generate selector symbols late (when compiling or evaluating)
Claus Gittinger <cg@exept.de>
parents: 856
diff changeset
  1682
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1683
    realReceiver := self realReceiver.
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1684
    isSuper := realReceiver isSuper.
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1685
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1686
    argArray isNil ifTrue:[
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1687
        nargs := 0
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1688
    ] ifFalse:[
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1689
        nargs := argArray size
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1690
    ].
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1691
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1692
    isBuiltIn := false.
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1693
    isSuper ifFalse:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1694
        (nargs == 0) ifTrue:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1695
            isBuiltIn := aCompiler isBuiltInUnarySelector:selector forReceiver:receiver
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1696
        ].
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1697
        (nargs == 1) ifTrue:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1698
            isBuiltIn := aCompiler isBuiltIn1ArgSelector:selector forReceiver:receiver
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1699
        ].
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1700
        (nargs == 2) ifTrue:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1701
            isBuiltIn := aCompiler isBuiltIn2ArgSelector:selector forReceiver:receiver
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1702
        ].
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1703
    ].
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1704
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1705
    "can we use a send-bytecode ?"
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1706
    isBuiltIn ifTrue:[
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1707
        (nargs > 0) ifTrue:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1708
            (argArray at:1) codeOn:aStream inBlock:b for:aCompiler.
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1709
            (nargs > 1) ifTrue:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1710
                (argArray at:2) codeOn:aStream inBlock:b for:aCompiler
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1711
            ]
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1712
        ].
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1713
        aStream nextPut:selector.
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1714
        (aCompiler hasLineNumber:selector) ifTrue:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1715
            aStream nextPut:lineNr.
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1716
        ].
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1717
        valueNeeded ifFalse:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1718
            aStream nextPut:#drop
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1719
        ].
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1720
        ^ self
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1721
    ].
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1722
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1723
    argArray notNil ifTrue:[
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1724
        argArray do:[:arg |
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1725
            arg codeOn:aStream inBlock:b for:aCompiler
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1726
        ]
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1727
    ].
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1728
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1729
    isSuper ifTrue:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1730
        cls := aCompiler targetClass.
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1731
        realReceiver isHere ifTrue:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1732
            code := #hereSend.
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1733
            codeL := #hereSendL
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1734
        ] ifFalse:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1735
            code := #superSend.
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1736
            codeL := #superSend.
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1737
            cls := cls superclass.
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1738
        ].
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1739
        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
  1740
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1741
        litIndex := aCompiler addLiteral:selector.
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1742
        (litIndex <= 255 and:[clsLitIndex <= 255]) ifTrue:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1743
            aStream nextPut:code; nextPut:lineNr; nextPut:litIndex; nextPut:nargs; nextPut:clsLitIndex.
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1744
        ] ifFalse:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1745
            aStream nextPut:codeL; nextPut:lineNr; nextPut:litIndex; nextPut:0; nextPut:nargs; nextPut:clsLitIndex; nextPut:0.
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1746
        ].
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1747
        valueNeeded ifFalse:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1748
            aStream nextPut:#drop
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1749
        ].
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1750
        ^ self
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1751
    ].
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1752
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1753
    (nargs == 0) ifTrue:[
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1754
        (selector == #yourself) ifTrue:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1755
            "yourself is often added to get the receiver -
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1756
             we get it without the yourself-message"
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1757
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1758
            valueNeeded ifFalse:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1759
                aStream nextPut:#drop
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1760
            ].
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1761
            ^ self
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1762
        ].
49
02660b790c3e *** empty log message ***
claus
parents: 48
diff changeset
  1763
    ].
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1764
117
claus
parents: 111
diff changeset
  1765
    litIndex := aCompiler addLiteral:selector.
claus
parents: 111
diff changeset
  1766
    litIndex <= 255 ifTrue:[
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1767
        (nargs <= 3) ifTrue:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1768
            valueNeeded ifTrue:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1769
                code := #(send0 send1 send2 send3) at:(nargs+1).
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1770
            ] ifFalse:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1771
                code := #(sendDrop0 sendDrop1 sendDrop2 sendDrop3) at:(nargs+1).
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1772
            ].
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1773
            aStream nextPut:code; nextPut:lineNr; nextPut:litIndex.
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1774
            ^ self
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1775
        ].
106
claus
parents: 104
diff changeset
  1776
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1777
        valueNeeded ifTrue:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1778
            code := #send
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1779
        ] ifFalse:[
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1780
            code := #sendDrop
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1781
        ].
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1782
        aStream nextPut:code; nextPut:lineNr; nextPut:litIndex; nextPut:nargs.
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1783
        ^ self
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1784
    ].
49
02660b790c3e *** empty log message ***
claus
parents: 48
diff changeset
  1785
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1786
    valueNeeded ifTrue:[
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1787
        code := #sendL
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1788
    ] ifFalse:[
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1789
        code := #sendDropL
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1790
    ].
117
claus
parents: 111
diff changeset
  1791
    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
  1792
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  1793
    "Modified: / 16.7.1998 / 20:26:52 / cg"
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1794
!
7ad01559b262 Initial revision
claus
parents:
diff changeset
  1795
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1796
codeTimesRepeatOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1797
    "generate code for n timesRepeat:[ ... ]"
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1798
856
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  1799
    |pos1 pos2 theReceiver lateEval loopCount|
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1800
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1801
    theReceiver := receiver.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1802
    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
  1803
7632e597a3df no need to keep receiver on stack for
Claus Gittinger <cg@exept.de>
parents: 338
diff changeset
  1804
    lateEval := false.
528
0a35ed44989f oops - timesRepeat dupped one too many
Claus Gittinger <cg@exept.de>
parents: 437
diff changeset
  1805
856
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  1806
    theReceiver isConstant ifTrue:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  1807
        loopCount := theReceiver evaluate.
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  1808
        (loopCount isMemberOf:SmallInteger) ifFalse:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  1809
            loopCount := nil.
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  1810
        ]
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  1811
    ].
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  1812
349
7632e597a3df no need to keep receiver on stack for
Claus Gittinger <cg@exept.de>
parents: 338
diff changeset
  1813
    valueNeeded ifTrue:[
856
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  1814
        "/ easily reconstructable - no need to keep on stack
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  1815
        loopCount notNil ifTrue:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  1816
            lateEval := true.
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  1817
        ].
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  1818
        lateEval ifFalse:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  1819
            aStream nextPut:#dup
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  1820
        ].
349
7632e597a3df no need to keep receiver on stack for
Claus Gittinger <cg@exept.de>
parents: 338
diff changeset
  1821
    ].
96
claus
parents: 95
diff changeset
  1822
856
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  1823
    loopCount isNil ifTrue:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  1824
        aStream nextPut:#pushgt0; nextPut:lineNr; nextPut:#falseJump.
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  1825
        pos2 := aStream position.
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  1826
        aStream nextPut:0.
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  1827
    ].
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1828
856
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  1829
    pos1 := aStream position.
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1830
    (argArray at:1) codeInlineOn:aStream inBlock:b valueNeeded:false for:aCompiler.
856
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  1831
    aStream nextPut:#minus1; nextPut:lineNr.
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  1832
    aStream nextPut:#pushgt0; nextPut:lineNr.
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  1833
    aStream nextPut:#trueJump; nextPut:pos1.
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1834
856
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  1835
    pos2 notNil ifTrue:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  1836
        (aStream contents) at:pos2 put:(aStream position).
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  1837
    ].
528
0a35ed44989f oops - timesRepeat dupped one too many
Claus Gittinger <cg@exept.de>
parents: 437
diff changeset
  1838
    aStream nextPut:#drop.  "/ drop run variable
856
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  1839
349
7632e597a3df no need to keep receiver on stack for
Claus Gittinger <cg@exept.de>
parents: 338
diff changeset
  1840
    lateEval ifTrue:[
856
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  1841
        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
  1842
    ]
7632e597a3df no need to keep receiver on stack for
Claus Gittinger <cg@exept.de>
parents: 338
diff changeset
  1843
528
0a35ed44989f oops - timesRepeat dupped one too many
Claus Gittinger <cg@exept.de>
parents: 437
diff changeset
  1844
    "Modified: 27.5.1997 / 14:28:49 / cg"
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1845
!
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  1846
565
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1847
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
  1848
    "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
  1849
565
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1850
    |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
  1851
     stepVal stopVarIndex|
561
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  1852
565
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1853
    "/ 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
  1854
    "/ 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
  1855
    "/ 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
  1856
    "/ 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
  1857
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  1858
    start := receiver.
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  1859
    stop := (argArray at:1).
565
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1860
    step := (argArray at:2).
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1861
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1862
"/    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
  1863
"/    (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
  1864
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1865
    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
  1866
    stepVal := step evaluate.
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1867
    (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
  1868
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  1869
    start codeOn:aStream inBlock:b for:aCompiler.
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  1870
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  1871
    lateEval := false.
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  1872
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  1873
    valueNeeded ifTrue:[
639
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1874
	"/ easily reconstructable - no need to keep on stack
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1875
	start isConstant ifTrue:[
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1876
	    (start evaluate isMemberOf:SmallInteger) ifTrue:[
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1877
		lateEval := true.
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1878
	    ]
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1879
	].
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1880
	lateEval ifFalse:[
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1881
	    aStream nextPut:#dup
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1882
	].
561
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  1883
    ].
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  1884
565
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1885
    "/ 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
  1886
    "/  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
  1887
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1888
    (stop isConstant and:[stop type == #Integer]) ifFalse:[
639
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1889
	"/ a method/blockArg is constant as well ...
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1890
	(stop isVariable and:[stop isArgument]) ifFalse:[
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1891
	    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
  1892
639
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1893
	    b isNil ifTrue:[
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1894
		stopVarIndex := aCompiler addTempVar.
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1895
		aStream nextPut:#storeMethodVar; nextPut:stopVarIndex.
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1896
	    ] ifFalse:[
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1897
		stopVarIndex := b addTempVar.
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1898
		aStream nextPut:#storeBlockVar; nextPut:stopVarIndex.
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1899
	    ].
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1900
	]
565
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1901
    ].
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1902
561
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  1903
    pos := aStream position.
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  1904
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  1905
    aStream nextPut:#dup.
565
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1906
    stopVarIndex notNil ifTrue:[
639
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1907
	b isNil ifTrue:[
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1908
	    aStream nextPut:#pushMethodVar; nextPut:stopVarIndex.
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1909
	] ifFalse:[
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1910
	    aStream nextPut:#pushBlockVar; nextPut:stopVarIndex.
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1911
	]
565
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1912
    ] ifFalse:[
639
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1913
	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
  1914
    ].
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1915
    stepVal > 0 ifTrue:[
639
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1916
	aStream nextPut:#>.
565
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1917
    ] ifFalse:[
639
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1918
	aStream nextPut:#<.
565
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1919
    ].
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1920
    (aCompiler hasLineNumber:selector) ifTrue:[
639
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1921
	aStream nextPut:lineNr.
565
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1922
    ].
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1923
    aStream nextPut:#trueJump.
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1924
    pos2 := aStream position.
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1925
    aStream nextPut:0.
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1926
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1927
    theBlock := argArray at:3.
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1928
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1929
    "/ 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
  1930
    "/ the loop ...
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1931
    b isNil ifTrue:[
639
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1932
	loopVarIndex := aCompiler addTempVar.
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1933
	aStream nextPut:#dup.
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1934
	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
  1935
    ] ifFalse:[
639
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1936
	loopVarIndex := b addTempVar.
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1937
	aStream nextPut:#dup.
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1938
	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
  1939
    ].
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1940
    theBlock indexOfFirstTemp:loopVarIndex.
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1941
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1942
    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
  1943
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1944
    "/ increment/decrement counter & jump back.
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1945
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1946
    stepVal == 1 ifTrue:[
639
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1947
	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
  1948
    ] ifFalse:[
639
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1949
	stepVal == -1 ifTrue:[
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1950
	    aStream nextPut:#minus1; nextPut:lineNr.
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1951
	] ifFalse:[
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1952
	    step codeOn:aStream inBlock:b for:aCompiler.
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1953
	    aStream nextPut:#+.
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1954
	    (aCompiler hasLineNumber:#+) ifTrue:[
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1955
		aStream nextPut:lineNr.
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1956
	    ].
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1957
	]
565
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1958
    ].
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1959
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1960
    aStream nextPut:#jump; nextPut:pos.
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1961
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1962
    (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
  1963
    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
  1964
    lateEval ifTrue:[
639
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1965
	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
  1966
    ].
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1967
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1968
    "/ 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
  1969
    "/ (its integer, anyway).
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1970
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1971
    b isNil ifTrue:[
639
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1972
	aCompiler removeTempVar
565
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1973
    ] ifFalse:[
639
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1974
	b removeTempVar
565
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1975
    ].
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1976
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1977
    stopVarIndex notNil ifTrue:[
639
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1978
	b isNil ifTrue:[
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1979
	    aCompiler removeTempVar
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1980
	] ifFalse:[
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1981
	    b removeTempVar
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  1982
	]
565
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1983
    ].
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1984
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1985
    "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
  1986
    "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
  1987
!
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1988
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1989
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
  1990
    "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
  1991
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1992
    |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
  1993
     stopVarIndex|
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1994
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  1995
    "/ 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
  1996
    "/ 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
  1997
    "/ 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
  1998
    "/ 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
  1999
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2000
    start := receiver.
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2001
    stop := (argArray at:1).
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2002
"/    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
  2003
"/    (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
  2004
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2005
    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
  2006
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2007
    lateEval := false.
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2008
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2009
    valueNeeded ifTrue:[
639
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  2010
	"/ easily reconstructable - no need to keep on stack
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  2011
	start isConstant ifTrue:[
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  2012
	    (start evaluate isMemberOf:SmallInteger) ifTrue:[
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  2013
		lateEval := true.
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  2014
	    ]
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  2015
	].
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  2016
	lateEval ifFalse:[
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  2017
	    aStream nextPut:#dup
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  2018
	].
565
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2019
    ].
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2020
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2021
    "/ 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
  2022
    "/  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
  2023
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2024
    (stop isConstant and:[stop type == #Integer]) ifFalse:[
639
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  2025
	"/ a method/blockArg is constant as well ...
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  2026
	(stop isVariable and:[stop isArgument]) ifFalse:[
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  2027
	    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
  2028
639
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  2029
	    b isNil ifTrue:[
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  2030
		stopVarIndex := aCompiler addTempVar.
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  2031
		aStream nextPut:#storeMethodVar; nextPut:stopVarIndex.
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  2032
	    ] ifFalse:[
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  2033
		stopVarIndex := b addTempVar.
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  2034
		aStream nextPut:#storeBlockVar; nextPut:stopVarIndex.
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  2035
	    ].
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  2036
	]
565
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2037
    ].
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2038
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2039
    pos := aStream position.
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2040
624
e71abe9654e6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 602
diff changeset
  2041
    aStream nextPut:#lineno; nextPut:lineNr.
e71abe9654e6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 602
diff changeset
  2042
565
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2043
    aStream nextPut:#dup.
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2044
    stopVarIndex notNil ifTrue:[
639
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  2045
	b isNil ifTrue:[
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  2046
	    aStream nextPut:#pushMethodVar; nextPut:stopVarIndex.
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  2047
	] ifFalse:[
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  2048
	    aStream nextPut:#pushBlockVar; nextPut:stopVarIndex.
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  2049
	]
565
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2050
    ] ifFalse:[
639
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  2051
	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
  2052
    ].
561
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2053
    aStream nextPut:#>.
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2054
    (aCompiler hasLineNumber:selector) ifTrue:[
639
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  2055
	aStream nextPut:lineNr.
561
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2056
    ].
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2057
    aStream nextPut:#trueJump.
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2058
    pos2 := aStream position.
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2059
    aStream nextPut:0.
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2060
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2061
    theBlock := argArray at:2.
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2062
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2063
    "/ 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
  2064
    "/ the loop ...
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2065
    b isNil ifTrue:[
639
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  2066
	loopVarIndex := aCompiler addTempVar.
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  2067
	aStream nextPut:#dup.
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  2068
	aStream nextPut:#storeMethodVar; nextPut:loopVarIndex.
561
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2069
    ] ifFalse:[
639
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  2070
	loopVarIndex := b addTempVar.
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  2071
	aStream nextPut:#dup.
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  2072
	aStream nextPut:#storeBlockVar; nextPut:loopVarIndex.
561
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2073
    ].
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2074
    theBlock indexOfFirstTemp:loopVarIndex.
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2075
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2076
    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
  2077
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2078
    "/ increment counter & jump back.
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2079
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2080
    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
  2081
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2082
    (aStream contents) at:pos2 put:(aStream position).
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2083
    aStream nextPut:#drop.  "/ drop run variable
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2084
    lateEval ifTrue:[
639
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  2085
	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
  2086
    ].
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2087
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2088
    "/ 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
  2089
    "/ (its integer, anyway).
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2090
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2091
    b isNil ifTrue:[
639
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  2092
	aCompiler removeTempVar
561
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2093
    ] ifFalse:[
639
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  2094
	b removeTempVar
565
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2095
    ].
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2096
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2097
    stopVarIndex notNil ifTrue:[
639
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  2098
	b isNil ifTrue:[
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  2099
	    aCompiler removeTempVar
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  2100
	] ifFalse:[
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  2101
	    b removeTempVar
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  2102
	]
565
00673e9d6edc more inlining of #to:do: and #to:by:do:
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
  2103
    ].
561
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2104
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2105
    "Created: 26.6.1997 / 10:58:47 / cg"
624
e71abe9654e6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 602
diff changeset
  2106
    "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
  2107
!
19279079cc9a inline toDo blocks withs constant start/stop
Claus Gittinger <cg@exept.de>
parents: 552
diff changeset
  2108
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2109
codeWhileOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler
200
b2f77bd77070 inline code for [...] whileXXX
Claus Gittinger <cg@exept.de>
parents: 199
diff changeset
  2110
    "generate code for
817
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2111
        [...] whileXXX:[ ... ] 
200
b2f77bd77070 inline code for [...] whileXXX
Claus Gittinger <cg@exept.de>
parents: 199
diff changeset
  2112
     and also 
817
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2113
        [...] whileXXX
200
b2f77bd77070 inline code for [...] whileXXX
Claus Gittinger <cg@exept.de>
parents: 199
diff changeset
  2114
    "
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2115
200
b2f77bd77070 inline code for [...] whileXXX
Claus Gittinger <cg@exept.de>
parents: 199
diff changeset
  2116
    |pos pos2 theReceiver theArg theByteCode optByteCode needLineNr blockExpr
856
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2117
     hasLoopBlock fastReceiver condStats constCondition|
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2118
200
b2f77bd77070 inline code for [...] whileXXX
Claus Gittinger <cg@exept.de>
parents: 199
diff changeset
  2119
    hasLoopBlock := true.
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2120
    (selector == #whileTrue:) ifTrue:[
817
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2121
        theByteCode := #falseJump.
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2122
    ] ifFalse:[
817
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2123
        (selector == #whileFalse:) ifTrue:[
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2124
            theByteCode := #trueJump
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2125
        ] ifFalse:[
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2126
            hasLoopBlock := false.
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2127
            (selector == #whileTrue) ifTrue:[
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2128
                theByteCode := #trueJump
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2129
            ] ifFalse:[
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2130
                theByteCode := #falseJump
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2131
            ].
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2132
        ]
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2133
    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2134
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2135
    theReceiver := receiver.
370
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  2136
856
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2137
    (receiver isBlock
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2138
    and:[(condStats := receiver statements) notNil
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2139
    and:[condStats nextStatement isNil
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2140
    and:[condStats expression notNil]]])
370
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  2141
    ifTrue:[
817
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2142
        fastReceiver := receiver statements expression.
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2143
        optByteCode := self optimizedConditionFor:fastReceiver with:theByteCode.
370
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  2144
    ] ifFalse:[
817
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2145
        optByteCode := self optimizedConditionFor:theReceiver with:theByteCode.
370
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  2146
    ].
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  2147
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2148
    optByteCode notNil ifTrue:[
817
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2149
        ((optByteCode == #eqJump) or:[optByteCode == #notEqJump]) ifTrue:[
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2150
            theArg := receiver statements expression arg1
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2151
        ].
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2152
        theReceiver := receiver statements expression receiver.
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2153
        theByteCode := optByteCode
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2154
    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2155
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2156
"/ OLD:
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2157
"/    valueNeeded ifTrue:[aStream nextPut:#pushNil].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2158
"/
167
d3dbd739c65a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 166
diff changeset
  2159
    needLineNr := true.
d3dbd739c65a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 166
diff changeset
  2160
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2161
    pos := aStream position.
386
2f66de89a89b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 371
diff changeset
  2162
389
8aa5f9f08139 care for lineNumber in while-loop
Claus Gittinger <cg@exept.de>
parents: 386
diff changeset
  2163
"/    aCompiler lineNumberInfo == #full ifTrue:[
817
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2164
        self codeLineNumber:lineNr on:aStream for:aCompiler.
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2165
        needLineNr := false.
389
8aa5f9f08139 care for lineNumber in while-loop
Claus Gittinger <cg@exept.de>
parents: 386
diff changeset
  2166
"/    ].
386
2f66de89a89b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 371
diff changeset
  2167
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2168
    optByteCode notNil ifTrue:[
817
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2169
        theReceiver codeOn:aStream inBlock:b for:aCompiler.
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2170
        theArg notNil ifTrue:[
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2171
            theArg codeOn:aStream inBlock:b for:aCompiler
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2172
        ]
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2173
    ] ifFalse:[
856
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2174
        (fastReceiver notNil 
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2175
        and:[fastReceiver isConstant]) ifTrue:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2176
            constCondition := fastReceiver evaluate.
817
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2177
            theByteCode == #trueJump ifTrue:[
856
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2178
                constCondition == true ifTrue:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2179
                    theByteCode := #jump
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2180
                ] ifFalse:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2181
                    constCondition == false ifTrue:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2182
                        theByteCode := #never
817
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2183
                    ]
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2184
                ]
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2185
            ] ifFalse:[
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2186
                theByteCode == #falseJump ifTrue:[
856
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2187
                    constCondition == false ifTrue:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2188
                        theByteCode := #jump
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2189
                    ] ifFalse:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2190
                        constCondition == true ifTrue:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2191
                            theByteCode := #never
817
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2192
                        ]
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2193
                    ]
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2194
                ]
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2195
            ]
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2196
        ].
167
d3dbd739c65a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 166
diff changeset
  2197
856
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2198
        (theByteCode ~~ #jump and:[theByteCode ~~ #never]) ifTrue:[
817
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2199
            theReceiver codeInlineOn:aStream inBlock:b for:aCompiler.
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2200
        ].
370
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  2201
817
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2202
        "/
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2203
        "/ cannot enable code below 
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2204
        "/ (tiny loops would not be debuggable with next, since lineNo remains the same)
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2205
        "/ think about it ...
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2206
        "/
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2207
        blockExpr := theReceiver simpleSendBlockExpression.
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2208
        blockExpr notNil ifTrue:[
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2209
            blockExpr isMessage ifTrue:[
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2210
                (aCompiler hasLineNumber:(blockExpr selector)) ifTrue:[
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2211
                    blockExpr lineNumber == lineNr ifTrue:[
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2212
                        needLineNr := false
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2213
                    ]
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2214
                ]
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2215
            ]
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2216
        ].
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2217
    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2218
167
d3dbd739c65a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 166
diff changeset
  2219
    needLineNr ifTrue:[
817
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2220
        ParseNode codeLineNumber:lineNr on:aStream for:aCompiler.
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2221
    ].
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2222
200
b2f77bd77070 inline code for [...] whileXXX
Claus Gittinger <cg@exept.de>
parents: 199
diff changeset
  2223
    hasLoopBlock ifFalse:[
817
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2224
        "/ simple [...] whileXXX
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2225
        theByteCode ~~ #never ifTrue:[
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2226
            aStream nextPut:theByteCode; nextPut:pos.
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2227
        ].
370
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  2228
817
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2229
        valueNeeded ifTrue:[aStream nextPut:#pushNil].
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2230
        ^ self
200
b2f77bd77070 inline code for [...] whileXXX
Claus Gittinger <cg@exept.de>
parents: 199
diff changeset
  2231
    ].
b2f77bd77070 inline code for [...] whileXXX
Claus Gittinger <cg@exept.de>
parents: 199
diff changeset
  2232
b2f77bd77070 inline code for [...] whileXXX
Claus Gittinger <cg@exept.de>
parents: 199
diff changeset
  2233
    "/ [...] whileXXX:[...]
b2f77bd77070 inline code for [...] whileXXX
Claus Gittinger <cg@exept.de>
parents: 199
diff changeset
  2234
370
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  2235
    theByteCode ~~ #never ifTrue:[
817
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2236
        aStream nextPut:theByteCode.
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2237
        pos2 := aStream position.
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2238
        aStream nextPut:0.
370
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  2239
    ].
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  2240
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2241
    (argArray at:1) codeInlineOn:aStream inBlock:b valueNeeded:false for:aCompiler.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2242
    aStream nextPut:#jump; nextPut:pos.
370
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  2243
    theByteCode ~~ #never ifTrue:[
817
8de90dbed4bb checkin from browser
Claus Gittinger <cg@exept.de>
parents: 812
diff changeset
  2244
        (aStream contents) at:pos2 put:(aStream position).
370
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  2245
    ].
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  2246
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2247
    valueNeeded ifTrue:[aStream nextPut:#pushNil].
167
d3dbd739c65a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 166
diff changeset
  2248
389
8aa5f9f08139 care for lineNumber in while-loop
Claus Gittinger <cg@exept.de>
parents: 386
diff changeset
  2249
    "Modified: 22.10.1996 / 21:34:37 / cg"
140
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
856
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2252
new_codeWhileOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2253
    "generate code for
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2254
        [...] whileXXX:[ ... ] 
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2255
     and also 
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2256
        [...] whileXXX
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2257
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2258
     This generates the check at the end and should generate better
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2259
     code (only 1 conditional-branch at the end instead of 2 branches).
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2260
     However, for now, it is disabled, since the JIT has special provisions
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2261
     to detect loops and actually generates better machine code for the
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2262
     old bytecode sequence ... (sign)
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2263
    "
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2264
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2265
    |pos pos0 theReceiver theArg theByteCode optByteCode needLineNr blockExpr
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2266
     hasLoopBlock fastReceiver condStats constCondition|
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2267
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2268
    hasLoopBlock := true.
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2269
    (selector == #whileTrue:) ifTrue:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2270
        theByteCode := #trueJump.
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2271
    ] ifFalse:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2272
        (selector == #whileFalse:) ifTrue:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2273
            theByteCode := #falseJump
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2274
        ] ifFalse:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2275
            hasLoopBlock := false.
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2276
            (selector == #whileTrue) ifTrue:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2277
                theByteCode := #trueJump
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2278
            ] ifFalse:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2279
                theByteCode := #falseJump
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2280
            ].
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2281
        ]
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2282
    ].
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2283
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2284
    theReceiver := receiver.
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2285
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2286
    (receiver isBlock
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2287
    and:[(condStats := receiver statements) notNil
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2288
    and:[condStats nextStatement isNil
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2289
    and:[(fastReceiver := condStats expression) notNil]]])
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2290
    ifTrue:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2291
        optByteCode := self optimizedConditionFor:fastReceiver with:theByteCode.
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2292
    ] ifFalse:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2293
        optByteCode := self optimizedConditionFor:theReceiver with:theByteCode.
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2294
    ].
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2295
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2296
    optByteCode notNil ifTrue:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2297
        ((optByteCode == #eqJump) or:[optByteCode == #notEqJump]) ifTrue:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2298
            theArg := receiver statements expression arg1
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2299
        ].
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2300
        theReceiver := receiver statements expression receiver.
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2301
        theByteCode := optByteCode
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2302
    ].
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2303
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2304
    needLineNr := true.
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2305
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2306
    hasLoopBlock ifTrue:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2307
        (argArray at:1) isEmptyBlock ifFalse:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2308
            aStream nextPut:#jump.
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2309
            pos0 := aStream position.
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2310
            aStream nextPut:0.
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2311
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2312
            pos := aStream position.
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2313
            (argArray at:1) codeInlineOn:aStream inBlock:b valueNeeded:false for:aCompiler.
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2314
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2315
            (aStream contents) at:pos0 put:(aStream position).
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2316
        ]
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2317
    ] ifFalse:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2318
        pos := aStream position.
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2319
    ].
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2320
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2321
    optByteCode isNil ifTrue:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2322
        blockExpr := theReceiver simpleSendBlockExpression.
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2323
        blockExpr notNil ifTrue:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2324
            blockExpr isMessage ifTrue:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2325
                (aCompiler hasLineNumber:(blockExpr selector)) ifTrue:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2326
                    blockExpr lineNumber == lineNr ifTrue:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2327
                        needLineNr := false
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2328
                    ]
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2329
                ]
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2330
            ]
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2331
        ].
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2332
    ].
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2333
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2334
    needLineNr ifTrue:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2335
        self codeLineNumber:lineNr on:aStream for:aCompiler.
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2336
    ].
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2337
    needLineNr := false.
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2338
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2339
    optByteCode notNil ifTrue:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2340
        theReceiver codeOn:aStream inBlock:b for:aCompiler.
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2341
        theArg notNil ifTrue:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2342
            theArg codeOn:aStream inBlock:b for:aCompiler
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2343
        ]
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2344
    ] ifFalse:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2345
        (fastReceiver notNil 
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2346
        and:[fastReceiver isConstant]) ifTrue:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2347
            constCondition := fastReceiver evaluate.
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2348
            theByteCode == #trueJump ifTrue:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2349
                constCondition == true ifTrue:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2350
                    theByteCode := #jump
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2351
                ] ifFalse:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2352
                    constCondition == false ifTrue:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2353
                        theByteCode := #never
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2354
                    ]
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2355
                ]
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2356
            ] ifFalse:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2357
                theByteCode == #falseJump ifTrue:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2358
                    constCondition == false ifTrue:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2359
                        theByteCode := #jump
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2360
                    ] ifFalse:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2361
                        constCondition == true ifTrue:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2362
                            theByteCode := #never
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2363
                        ]
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2364
                    ]
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2365
                ]
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2366
            ]
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2367
        ].
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2368
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2369
        (theByteCode ~~ #jump and:[theByteCode ~~ #never]) ifTrue:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2370
            theReceiver codeInlineOn:aStream inBlock:b for:aCompiler.
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2371
        ].
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2372
    ].
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2373
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2374
    hasLoopBlock ifFalse:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2375
        "/ simple [...] whileXXX
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2376
        theByteCode ~~ #never ifTrue:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2377
            aStream nextPut:theByteCode; nextPut:pos.
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2378
        ].
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2379
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2380
        valueNeeded ifTrue:[aStream nextPut:#pushNil].
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2381
        ^ self
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2382
    ].
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2383
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2384
    "/ [...] whileXXX:[...]
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2385
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2386
    theByteCode ~~ #never ifTrue:[
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2387
        aStream nextPut:theByteCode.
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2388
        aStream nextPut:pos.
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2389
    ].
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2390
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2391
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2392
    valueNeeded ifTrue:[aStream nextPut:#pushNil].
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2393
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2394
    "Modified: 22.10.1996 / 21:34:37 / cg"
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2395
!
bcc52caf1192 timesRepeat: - check at loop-end
Claus Gittinger <cg@exept.de>
parents: 851
diff changeset
  2396
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2397
optimizedConditionFor:aReceiver with:aByteCode
186
05a99f1bd747 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 167
diff changeset
  2398
    |rec sel stats|
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2399
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2400
    rec := aReceiver.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2401
    (rec isBlock) ifTrue:[
186
05a99f1bd747 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 167
diff changeset
  2402
	(stats := rec statements) notNil ifTrue:[
05a99f1bd747 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 167
diff changeset
  2403
	    stats nextStatement isNil ifTrue:[
05a99f1bd747 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 167
diff changeset
  2404
		rec := rec statements expression
05a99f1bd747 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 167
diff changeset
  2405
	    ]
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2406
	]
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2407
    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2408
    (rec isUnaryMessage) ifTrue:[
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2409
	sel := rec selector.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2410
	(sel == #isNil) ifTrue:[
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2411
	    "/
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2412
	    "/ isNil trueJmp  -> nilJump
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2413
	    "/ isNil falseJmp -> notNilJump
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2414
	    "/
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2415
	    (aByteCode == #trueJump) ifTrue:[^ #nilJump].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2416
	    (aByteCode == #falseJump) ifTrue:[^ #notNilJump]
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2417
	].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2418
	(sel == #notNil) ifTrue:[
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2419
	    "/
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2420
	    "/ notNil trueJmp  -> notNilJump
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2421
	    "/ notNil falseJmp -> nilJump
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2422
	    "/
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2423
	    (aByteCode == #trueJump) ifTrue:[^ #notNilJump].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2424
	    (aByteCode == #falseJump) ifTrue:[^ #nilJump]
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2425
	].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2426
	(sel == #not) ifTrue:[
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2427
	    "/
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2428
	    "/ not trueJmp  -> falseJump
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2429
	    "/ not falseJmp -> trueJump
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2430
	    "/
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2431
	    (aByteCode == #trueJump) ifTrue:[^ #falseJump].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2432
	    (aByteCode == #falseJump) ifTrue:[^ #trueJump]
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2433
	].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2434
	^ nil
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2435
    ].
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2436
    (rec isBinaryMessage) ifTrue:[
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2437
	sel := rec selector.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2438
	rec arg1 isConstant ifTrue:[
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2439
	    (rec arg1 value == 0) ifTrue:[
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2440
		"/
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2441
		"/ ==0 trueJmp  -> zeroJump
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2442
		"/ ==0 falseJmp -> notZeroJump
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2443
		"/
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2444
		(sel == #==) ifTrue:[
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2445
		    (aByteCode == #trueJump) ifTrue:[^ #zeroJump].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2446
		    (aByteCode == #falseJump) ifTrue:[^ #notZeroJump]
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2447
		].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2448
		"/
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2449
		"/ ~~0 trueJmp  -> notZeroJump
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2450
		"/ ~~0 falseJmp -> zeroJump
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2451
		"/
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2452
		(sel == #~~) ifTrue:[
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2453
		    (aByteCode == #falseJump) ifTrue:[^ #zeroJump].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2454
		    (aByteCode == #trueJump) ifTrue:[^ #notZeroJump]
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2455
		].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2456
		^ nil
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2457
	    ]
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2458
	].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2459
	(sel == #==) ifTrue:[
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2460
	    "/
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2461
	    "/ == trueJmp  -> eqJump
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2462
	    "/ == falseJmp -> notEqJump
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2463
	    "/
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2464
	    (aByteCode == #trueJump) ifTrue:[^ #eqJump].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2465
	    (aByteCode == #falseJump) ifTrue:[^ #notEqJump]
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2466
	].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2467
	(sel == #~~) ifTrue:[
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2468
	    "/
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2469
	    "/ ~~ trueJmp  -> notEqJump
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2470
	    "/ ~~ falseJmp -> eqJump
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2471
	    "/
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2472
	    (aByteCode == #falseJump) ifTrue:[^ #eqJump].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2473
	    (aByteCode == #trueJump) ifTrue:[^ #notEqJump]
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2474
	]
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2475
    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2476
    ^ nil
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2477
! !
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2478
539
69a1cd05c7d6 added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents: 537
diff changeset
  2479
!MessageNode methodsFor:'enumeration'!
69a1cd05c7d6 added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents: 537
diff changeset
  2480
69a1cd05c7d6 added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents: 537
diff changeset
  2481
nodeDo:anEnumerator
69a1cd05c7d6 added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents: 537
diff changeset
  2482
    "helper for parse tree walking"
69a1cd05c7d6 added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents: 537
diff changeset
  2483
543
de47f8969fd9 more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
  2484
    |args|
de47f8969fd9 more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
  2485
de47f8969fd9 more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
  2486
    args := argArray ? #().
de47f8969fd9 more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
  2487
    ^ 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
  2488
69a1cd05c7d6 added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents: 537
diff changeset
  2489
    "Created: 19.6.1997 / 16:46:39 / cg"
543
de47f8969fd9 more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
  2490
    "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
  2491
! !
69a1cd05c7d6 added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents: 537
diff changeset
  2492
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2493
!MessageNode methodsFor:'evaluating'!
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2494
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2495
evaluate
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2496
    |r nargs argValueArray class|
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2497
861
ccaa0ba5e7af generate selector symbols late (when compiling or evaluating)
Claus Gittinger <cg@exept.de>
parents: 856
diff changeset
  2498
    selector := selector asSymbol.
ccaa0ba5e7af generate selector symbols late (when compiling or evaluating)
Claus Gittinger <cg@exept.de>
parents: 856
diff changeset
  2499
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2500
    receiver isSuper ifTrue:[
861
ccaa0ba5e7af generate selector symbols late (when compiling or evaluating)
Claus Gittinger <cg@exept.de>
parents: 856
diff changeset
  2501
        r := receiver value.
ccaa0ba5e7af generate selector symbols late (when compiling or evaluating)
Claus Gittinger <cg@exept.de>
parents: 856
diff changeset
  2502
        receiver isHere ifTrue:[
ccaa0ba5e7af generate selector symbols late (when compiling or evaluating)
Claus Gittinger <cg@exept.de>
parents: 856
diff changeset
  2503
            class := receiver definingClass.
ccaa0ba5e7af generate selector symbols late (when compiling or evaluating)
Claus Gittinger <cg@exept.de>
parents: 856
diff changeset
  2504
        ] ifFalse:[
ccaa0ba5e7af generate selector symbols late (when compiling or evaluating)
Claus Gittinger <cg@exept.de>
parents: 856
diff changeset
  2505
            class := receiver definingClass superclass.
ccaa0ba5e7af generate selector symbols late (when compiling or evaluating)
Claus Gittinger <cg@exept.de>
parents: 856
diff changeset
  2506
        ].
ccaa0ba5e7af generate selector symbols late (when compiling or evaluating)
Claus Gittinger <cg@exept.de>
parents: 856
diff changeset
  2507
        argArray notNil ifTrue:[
ccaa0ba5e7af generate selector symbols late (when compiling or evaluating)
Claus Gittinger <cg@exept.de>
parents: 856
diff changeset
  2508
            argValueArray := argArray collect:[:arg | arg evaluate].
ccaa0ba5e7af generate selector symbols late (when compiling or evaluating)
Claus Gittinger <cg@exept.de>
parents: 856
diff changeset
  2509
        ] ifFalse:[
ccaa0ba5e7af generate selector symbols late (when compiling or evaluating)
Claus Gittinger <cg@exept.de>
parents: 856
diff changeset
  2510
            argValueArray := #()
ccaa0ba5e7af generate selector symbols late (when compiling or evaluating)
Claus Gittinger <cg@exept.de>
parents: 856
diff changeset
  2511
        ].
ccaa0ba5e7af generate selector symbols late (when compiling or evaluating)
Claus Gittinger <cg@exept.de>
parents: 856
diff changeset
  2512
        ^ r perform:selector inClass:class withArguments:argValueArray
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2513
    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2514
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2515
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2516
    argArray isNil ifTrue:[
861
ccaa0ba5e7af generate selector symbols late (when compiling or evaluating)
Claus Gittinger <cg@exept.de>
parents: 856
diff changeset
  2517
        ^ (receiver evaluate) perform:selector
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2518
    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2519
    nargs := argArray size.
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2520
    (nargs == 1) ifTrue:[
861
ccaa0ba5e7af generate selector symbols late (when compiling or evaluating)
Claus Gittinger <cg@exept.de>
parents: 856
diff changeset
  2521
        ^ (receiver evaluate) perform:selector with:(argArray at:1) evaluate
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2522
    ].
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2523
    (nargs == 2) ifTrue:[
861
ccaa0ba5e7af generate selector symbols late (when compiling or evaluating)
Claus Gittinger <cg@exept.de>
parents: 856
diff changeset
  2524
        ^ (receiver evaluate) perform:selector
ccaa0ba5e7af generate selector symbols late (when compiling or evaluating)
Claus Gittinger <cg@exept.de>
parents: 856
diff changeset
  2525
                                 with:(argArray at:1) evaluate
ccaa0ba5e7af generate selector symbols late (when compiling or evaluating)
Claus Gittinger <cg@exept.de>
parents: 856
diff changeset
  2526
                                 with:(argArray at:2) evaluate
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2527
    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2528
    (nargs == 3) ifTrue:[
861
ccaa0ba5e7af generate selector symbols late (when compiling or evaluating)
Claus Gittinger <cg@exept.de>
parents: 856
diff changeset
  2529
        ^ (receiver evaluate) perform:selector
ccaa0ba5e7af generate selector symbols late (when compiling or evaluating)
Claus Gittinger <cg@exept.de>
parents: 856
diff changeset
  2530
                                 with:(argArray at:1) evaluate
ccaa0ba5e7af generate selector symbols late (when compiling or evaluating)
Claus Gittinger <cg@exept.de>
parents: 856
diff changeset
  2531
                                 with:(argArray at:2) evaluate
ccaa0ba5e7af generate selector symbols late (when compiling or evaluating)
Claus Gittinger <cg@exept.de>
parents: 856
diff changeset
  2532
                                 with:(argArray at:3) evaluate
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2533
    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2534
    r := receiver evaluate.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2535
    argValueArray := argArray collect:[:arg | arg evaluate].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2536
    ^ r perform:selector withArguments:argValueArray
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2537
!
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2538
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2539
evaluateForCascade
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2540
    |r nargs argValueArray class|
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2541
861
ccaa0ba5e7af generate selector symbols late (when compiling or evaluating)
Claus Gittinger <cg@exept.de>
parents: 856
diff changeset
  2542
    selector := selector asSymbol.
ccaa0ba5e7af generate selector symbols late (when compiling or evaluating)
Claus Gittinger <cg@exept.de>
parents: 856
diff changeset
  2543
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2544
    receiver isSuper ifTrue:[
861
ccaa0ba5e7af generate selector symbols late (when compiling or evaluating)
Claus Gittinger <cg@exept.de>
parents: 856
diff changeset
  2545
        r := receiver value.
ccaa0ba5e7af generate selector symbols late (when compiling or evaluating)
Claus Gittinger <cg@exept.de>
parents: 856
diff changeset
  2546
        class := receiver definingClass.
ccaa0ba5e7af generate selector symbols late (when compiling or evaluating)
Claus Gittinger <cg@exept.de>
parents: 856
diff changeset
  2547
        receiver isHere ifFalse:[
ccaa0ba5e7af generate selector symbols late (when compiling or evaluating)
Claus Gittinger <cg@exept.de>
parents: 856
diff changeset
  2548
            class := class superclass.
ccaa0ba5e7af generate selector symbols late (when compiling or evaluating)
Claus Gittinger <cg@exept.de>
parents: 856
diff changeset
  2549
        ].
ccaa0ba5e7af generate selector symbols late (when compiling or evaluating)
Claus Gittinger <cg@exept.de>
parents: 856
diff changeset
  2550
        argArray notNil ifTrue:[
ccaa0ba5e7af generate selector symbols late (when compiling or evaluating)
Claus Gittinger <cg@exept.de>
parents: 856
diff changeset
  2551
            argValueArray := argArray collect:[:arg | arg evaluate].
ccaa0ba5e7af generate selector symbols late (when compiling or evaluating)
Claus Gittinger <cg@exept.de>
parents: 856
diff changeset
  2552
        ] ifFalse:[
ccaa0ba5e7af generate selector symbols late (when compiling or evaluating)
Claus Gittinger <cg@exept.de>
parents: 856
diff changeset
  2553
            argValueArray := #()
ccaa0ba5e7af generate selector symbols late (when compiling or evaluating)
Claus Gittinger <cg@exept.de>
parents: 856
diff changeset
  2554
        ].
ccaa0ba5e7af generate selector symbols late (when compiling or evaluating)
Claus Gittinger <cg@exept.de>
parents: 856
diff changeset
  2555
        r perform:selector inClass:class withArguments:argValueArray.
ccaa0ba5e7af generate selector symbols late (when compiling or evaluating)
Claus Gittinger <cg@exept.de>
parents: 856
diff changeset
  2556
        ^ r
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2557
    ].
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2558
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2559
    r := receiver evaluate.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2560
    argArray isNil ifTrue:[
861
ccaa0ba5e7af generate selector symbols late (when compiling or evaluating)
Claus Gittinger <cg@exept.de>
parents: 856
diff changeset
  2561
        r perform:selector.
ccaa0ba5e7af generate selector symbols late (when compiling or evaluating)
Claus Gittinger <cg@exept.de>
parents: 856
diff changeset
  2562
        ^ r
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2563
    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2564
    nargs := argArray size.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2565
    (nargs == 1) ifTrue:[
861
ccaa0ba5e7af generate selector symbols late (when compiling or evaluating)
Claus Gittinger <cg@exept.de>
parents: 856
diff changeset
  2566
        r perform:selector with:(argArray at:1) evaluate.
ccaa0ba5e7af generate selector symbols late (when compiling or evaluating)
Claus Gittinger <cg@exept.de>
parents: 856
diff changeset
  2567
        ^ r
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2568
    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2569
    (nargs == 2) ifTrue:[
861
ccaa0ba5e7af generate selector symbols late (when compiling or evaluating)
Claus Gittinger <cg@exept.de>
parents: 856
diff changeset
  2570
        r perform:selector with:(argArray at:1) evaluate
ccaa0ba5e7af generate selector symbols late (when compiling or evaluating)
Claus Gittinger <cg@exept.de>
parents: 856
diff changeset
  2571
                           with:(argArray at:2) evaluate.
ccaa0ba5e7af generate selector symbols late (when compiling or evaluating)
Claus Gittinger <cg@exept.de>
parents: 856
diff changeset
  2572
        ^ r
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2573
    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2574
    (nargs == 3) ifTrue:[
861
ccaa0ba5e7af generate selector symbols late (when compiling or evaluating)
Claus Gittinger <cg@exept.de>
parents: 856
diff changeset
  2575
        r perform:selector with:(argArray at:1) evaluate
ccaa0ba5e7af generate selector symbols late (when compiling or evaluating)
Claus Gittinger <cg@exept.de>
parents: 856
diff changeset
  2576
                           with:(argArray at:2) evaluate
ccaa0ba5e7af generate selector symbols late (when compiling or evaluating)
Claus Gittinger <cg@exept.de>
parents: 856
diff changeset
  2577
                           with:(argArray at:3) evaluate.
ccaa0ba5e7af generate selector symbols late (when compiling or evaluating)
Claus Gittinger <cg@exept.de>
parents: 856
diff changeset
  2578
        ^ r
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2579
    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2580
    argValueArray := argArray collect:[:arg | arg evaluate].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2581
    r perform:selector withArguments:argValueArray.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2582
    ^ r
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2583
! !
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2584
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2585
!MessageNode methodsFor:'printing'!
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2586
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2587
printOn:aStream indent:i
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2588
    |needParen selectorParts index index2 arg|
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2589
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2590
    (#(whileTrue: whileFalse:) includes:selector) ifTrue:[
888
5858090fc8c3 changed #printOn: to indent
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
  2591
        receiver isBlock ifTrue:[
5858090fc8c3 changed #printOn: to indent
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
  2592
            ^ self printWhileOn:aStream indent:i
5858090fc8c3 changed #printOn: to indent
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
  2593
        ].
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2594
    ].
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2595
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2596
    index := 1.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2597
    selectorParts := OrderedCollection new.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2598
    [index == 0] whileFalse:[
888
5858090fc8c3 changed #printOn: to indent
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
  2599
        index2 := selector indexOf:$: startingAt:index.
5858090fc8c3 changed #printOn: to indent
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
  2600
        index2 ~~ 0 ifTrue:[
5858090fc8c3 changed #printOn: to indent
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
  2601
            selectorParts add:(selector copyFrom:index to:index2).
5858090fc8c3 changed #printOn: to indent
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
  2602
            index2 := index2 + 1
5858090fc8c3 changed #printOn: to indent
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
  2603
        ].
5858090fc8c3 changed #printOn: to indent
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
  2604
        index := index2
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2605
    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2606
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2607
    needParen := false.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2608
    receiver isMessage ifTrue:[
888
5858090fc8c3 changed #printOn: to indent
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
  2609
        receiver isUnaryMessage ifFalse:[
5858090fc8c3 changed #printOn: to indent
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
  2610
            receiver isBinaryMessage ifFalse:[
5858090fc8c3 changed #printOn: to indent
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
  2611
                needParen := true
5858090fc8c3 changed #printOn: to indent
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
  2612
            ].
5858090fc8c3 changed #printOn: to indent
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
  2613
        ].
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2614
    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2615
    needParen ifTrue:[
888
5858090fc8c3 changed #printOn: to indent
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
  2616
        aStream nextPutAll:'('
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2617
    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2618
    receiver printOn:aStream indent:i.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2619
    needParen ifTrue:[
888
5858090fc8c3 changed #printOn: to indent
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
  2620
        aStream nextPutAll:')'
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2621
    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2622
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2623
    1 to:(argArray size) do:[:argIndex |
888
5858090fc8c3 changed #printOn: to indent
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
  2624
        aStream cr.
5858090fc8c3 changed #printOn: to indent
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
  2625
        aStream spaces:i+4.
5858090fc8c3 changed #printOn: to indent
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
  2626
        (selectorParts at:argIndex) printOn:aStream.
5858090fc8c3 changed #printOn: to indent
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
  2627
"/        aStream space.
5858090fc8c3 changed #printOn: to indent
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
  2628
        arg := argArray at:argIndex.
5858090fc8c3 changed #printOn: to indent
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
  2629
        needParen := false.
5858090fc8c3 changed #printOn: to indent
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
  2630
        arg isMessage ifTrue:[
5858090fc8c3 changed #printOn: to indent
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
  2631
            arg isBinaryMessage ifFalse:[
5858090fc8c3 changed #printOn: to indent
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
  2632
                arg isUnaryMessage ifFalse:[
5858090fc8c3 changed #printOn: to indent
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
  2633
                    needParen := true
5858090fc8c3 changed #printOn: to indent
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
  2634
                ]
5858090fc8c3 changed #printOn: to indent
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
  2635
            ].
5858090fc8c3 changed #printOn: to indent
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
  2636
        ].
5858090fc8c3 changed #printOn: to indent
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
  2637
        needParen ifTrue:[
5858090fc8c3 changed #printOn: to indent
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
  2638
            aStream nextPutAll:'('
5858090fc8c3 changed #printOn: to indent
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
  2639
        ].
5858090fc8c3 changed #printOn: to indent
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
  2640
        arg printOn:aStream indent:i+4.
5858090fc8c3 changed #printOn: to indent
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
  2641
        needParen ifTrue:[
5858090fc8c3 changed #printOn: to indent
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
  2642
            aStream nextPutAll:') '
5858090fc8c3 changed #printOn: to indent
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
  2643
        ].
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2644
    ]
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2645
!
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2646
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2647
printWhileOn:aStream indent:i
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2648
    |needParen arg|
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2649
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2650
    "special handling of whileTrue/whileFalse"
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2651
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2652
    aStream nextPutAll:'['.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2653
    receiver statements printOn:aStream indent:i.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2654
    aStream nextPutAll:'] whileTrue: '.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2655
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2656
    arg := argArray at:1.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2657
    needParen := false.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2658
    arg isMessage ifTrue:[
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2659
	arg isBinaryMessage ifFalse:[
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2660
	    arg isUnaryMessage ifFalse:[
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2661
		needParen := true
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2662
	    ]
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2663
	].
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2664
    ].
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2665
    needParen ifTrue:[
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2666
	aStream nextPutAll:'('
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2667
    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2668
    arg printOn:aStream indent:i.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2669
    needParen ifTrue:[
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2670
	aStream nextPutAll:') '
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2671
    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2672
! !
106
claus
parents: 104
diff changeset
  2673
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2674
!MessageNode methodsFor:'queries'!
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2675
395
16156d8711c2 added block collector
Claus Gittinger <cg@exept.de>
parents: 389
diff changeset
  2676
collectBlocksInto:aCollection
16156d8711c2 added block collector
Claus Gittinger <cg@exept.de>
parents: 389
diff changeset
  2677
    receiver collectBlocksInto:aCollection.
16156d8711c2 added block collector
Claus Gittinger <cg@exept.de>
parents: 389
diff changeset
  2678
    argArray size > 0 ifTrue:[
639
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  2679
	argArray do:[:arg |
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  2680
	    arg collectBlocksInto:aCollection.
f3dce3a697f0 inline #perform: messages with constant selector
Claus Gittinger <cg@exept.de>
parents: 627
diff changeset
  2681
	]
395
16156d8711c2 added block collector
Claus Gittinger <cg@exept.de>
parents: 389
diff changeset
  2682
    ].
16156d8711c2 added block collector
Claus Gittinger <cg@exept.de>
parents: 389
diff changeset
  2683
16156d8711c2 added block collector
Claus Gittinger <cg@exept.de>
parents: 389
diff changeset
  2684
    "Created: 23.10.1996 / 15:44:49 / cg"
16156d8711c2 added block collector
Claus Gittinger <cg@exept.de>
parents: 389
diff changeset
  2685
    "Modified: 23.10.1996 / 16:03:46 / cg"
16156d8711c2 added block collector
Claus Gittinger <cg@exept.de>
parents: 389
diff changeset
  2686
!
16156d8711c2 added block collector
Claus Gittinger <cg@exept.de>
parents: 389
diff changeset
  2687
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2688
isCascade
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2689
    ^ false
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2690
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2691
    "Created: / 16.7.1998 / 20:03:42 / cg"
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2692
!
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2693
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2694
isMessage
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2695
    ^ true
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2696
!
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2697
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2698
realReceiver
746
429cfc59b440 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 744
diff changeset
  2699
    receiver isCascade ifTrue:[
429cfc59b440 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 744
diff changeset
  2700
        ^ receiver realReceiver
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2701
    ].
746
429cfc59b440 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 744
diff changeset
  2702
    self isCascade ifTrue:[
429cfc59b440 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 744
diff changeset
  2703
        ^ receiver receiver
744
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2704
    ].
e871f9f072f8 changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
  2705
746
429cfc59b440 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 744
diff changeset
  2706
    ^ receiver
429cfc59b440 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 744
diff changeset
  2707
429cfc59b440 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 744
diff changeset
  2708
    "Modified: / 17.7.1998 / 02:09:05 / cg"
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
  2709
! !
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
  2710
370
09c13380b03b slightly better code for "[true] whileTrue:[ ...]"
Claus Gittinger <cg@exept.de>
parents: 349
diff changeset
  2711
!MessageNode class methodsFor:'documentation'!
148
ef0e604209ec version method at the end
Claus Gittinger <cg@exept.de>
parents: 140
diff changeset
  2712
ef0e604209ec version method at the end
Claus Gittinger <cg@exept.de>
parents: 140
diff changeset
  2713
version
898
8db540a5fda8 inline code for
Claus Gittinger <cg@exept.de>
parents: 888
diff changeset
  2714
    ^ '$Header: /cvs/stx/stx/libcomp/MessageNode.st,v 1.98 1999-07-09 22:41:36 cg Exp $'
148
ef0e604209ec version method at the end
Claus Gittinger <cg@exept.de>
parents: 140
diff changeset
  2715
! !