BlockNode.st
author Claus Gittinger <cg@exept.de>
Fri, 27 Jun 1997 14:08:18 +0200
changeset 565 00673e9d6edc
parent 562 36bd00734940
child 569 88a1b1d118fd
permissions -rw-r--r--
more inlining of #to:do: and #to:by:do:
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
45
e8331ba8ad5d *** 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:#BlockNode
168
87497e19c7d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
    14
	instanceVariableNames:'blockArgs statements home inlineBlock exitBlock blockVars
557
8202a13be88b preps to move vars of inlined blocks to outer context
Claus Gittinger <cg@exept.de>
parents: 555
diff changeset
    15
		needsHome lineNr endLineNr blockArgAccessedInBlock numTemp
559
42cf4afd99b3 inline blocks withs args
Claus Gittinger <cg@exept.de>
parents: 557
diff changeset
    16
		maxNumTemp indexOfFirstTemp'
168
87497e19c7d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
    17
	classVariableNames:''
87497e19c7d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
    18
	poolDictionaries:''
87497e19c7d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
    19
	category:'System-Compiler-Support'
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
    20
!
7ad01559b262 Initial revision
claus
parents:
diff changeset
    21
366
3be89590df22 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 333
diff changeset
    22
!BlockNode class methodsFor:'documentation'!
20
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
    23
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
    24
copyright
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
    25
"
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
    26
 COPYRIGHT (c) 1989 by Claus Gittinger
45
e8331ba8ad5d *** empty log message ***
claus
parents: 39
diff changeset
    27
	      All Rights Reserved
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
    28
20
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
    29
 This software is furnished under a license and may be used
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
    30
 only in accordance with the terms of that license and with the
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
    31
 inclusion of the above copyright notice.   This software may not
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
    32
 be provided or otherwise made available to, or used by, any
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
    33
 other person.  No title to or ownership of the software is
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
    34
 hereby transferred.
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
    35
"
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
    36
!
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
    37
20
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
    38
documentation
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
    39
"
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
    40
    node for parse-trees, representing blocks
261
0372e948ca2d commentary
Claus Gittinger <cg@exept.de>
parents: 212
diff changeset
    41
    This is a helper class for the compiler.
263
3b21d0991eff documentation
Claus Gittinger <cg@exept.de>
parents: 261
diff changeset
    42
3b21d0991eff documentation
Claus Gittinger <cg@exept.de>
parents: 261
diff changeset
    43
    [author:]
3b21d0991eff documentation
Claus Gittinger <cg@exept.de>
parents: 261
diff changeset
    44
        Claus Gittinger
20
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
    45
"
f8dd8ba75205 *** empty log message ***
claus
parents: 19
diff changeset
    46
! !
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
    47
366
3be89590df22 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 333
diff changeset
    48
!BlockNode class methodsFor:'instance creation'!
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
    49
3
b63b8a6b71fb *** empty log message ***
claus
parents: 0
diff changeset
    50
arguments:argList home:h variables:vars
b63b8a6b71fb *** empty log message ***
claus
parents: 0
diff changeset
    51
    ^ (self basicNew) setArguments:argList home:h variables:vars
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
    52
! !
7ad01559b262 Initial revision
claus
parents:
diff changeset
    53
7ad01559b262 Initial revision
claus
parents:
diff changeset
    54
!BlockNode methodsFor:'accessing'!
7ad01559b262 Initial revision
claus
parents:
diff changeset
    55
7ad01559b262 Initial revision
claus
parents:
diff changeset
    56
arguments
7ad01559b262 Initial revision
claus
parents:
diff changeset
    57
    ^ blockArgs
7ad01559b262 Initial revision
claus
parents:
diff changeset
    58
!
7ad01559b262 Initial revision
claus
parents:
diff changeset
    59
26
ce78d7693c78 argument count errors now raise signals
claus
parents: 20
diff changeset
    60
arguments:argList
ce78d7693c78 argument count errors now raise signals
claus
parents: 20
diff changeset
    61
    blockArgs := argList
ce78d7693c78 argument count errors now raise signals
claus
parents: 20
diff changeset
    62
!
ce78d7693c78 argument count errors now raise signals
claus
parents: 20
diff changeset
    63
534
a500bebd5d7e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
    64
blockArgAccessed
a500bebd5d7e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
    65
    "return true if any block argument is accessed in the block"
a500bebd5d7e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
    66
a500bebd5d7e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
    67
    ^ blockArgAccessedInBlock ? false
a500bebd5d7e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
    68
a500bebd5d7e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
    69
    "Modified: 18.6.1997 / 12:06:31 / cg"
a500bebd5d7e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
    70
!
a500bebd5d7e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
    71
a500bebd5d7e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
    72
blockArgAccessed:aBoolen
a500bebd5d7e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
    73
    "set/clear the flag stating if any block argument is accessed in the block"
a500bebd5d7e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
    74
a500bebd5d7e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
    75
    blockArgAccessedInBlock := aBoolen
a500bebd5d7e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
    76
a500bebd5d7e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
    77
    "Created: 18.6.1997 / 11:35:00 / cg"
a500bebd5d7e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
    78
    "Modified: 18.6.1997 / 12:06:43 / cg"
a500bebd5d7e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
    79
!
a500bebd5d7e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 522
diff changeset
    80
394
728e3b942ad5 remember endLinenr
Claus Gittinger <cg@exept.de>
parents: 386
diff changeset
    81
endLineNumber
728e3b942ad5 remember endLinenr
Claus Gittinger <cg@exept.de>
parents: 386
diff changeset
    82
    ^ endLineNr
728e3b942ad5 remember endLinenr
Claus Gittinger <cg@exept.de>
parents: 386
diff changeset
    83
728e3b942ad5 remember endLinenr
Claus Gittinger <cg@exept.de>
parents: 386
diff changeset
    84
    "Created: 23.10.1996 / 15:51:32 / cg"
728e3b942ad5 remember endLinenr
Claus Gittinger <cg@exept.de>
parents: 386
diff changeset
    85
!
728e3b942ad5 remember endLinenr
Claus Gittinger <cg@exept.de>
parents: 386
diff changeset
    86
379
24399d5c465c optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents: 366
diff changeset
    87
endLineNumber:aNumber
24399d5c465c optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents: 366
diff changeset
    88
    endLineNr := aNumber
24399d5c465c optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents: 366
diff changeset
    89
24399d5c465c optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents: 366
diff changeset
    90
    "Created: 21.10.1996 / 14:17:57 / cg"
24399d5c465c optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents: 366
diff changeset
    91
!
24399d5c465c optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents: 366
diff changeset
    92
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
    93
home
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
    94
    ^ home
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
    95
!
7ad01559b262 Initial revision
claus
parents:
diff changeset
    96
7ad01559b262 Initial revision
claus
parents:
diff changeset
    97
home:aBlock
7ad01559b262 Initial revision
claus
parents:
diff changeset
    98
    home := aBlock
7ad01559b262 Initial revision
claus
parents:
diff changeset
    99
!
7ad01559b262 Initial revision
claus
parents:
diff changeset
   100
559
42cf4afd99b3 inline blocks withs args
Claus Gittinger <cg@exept.de>
parents: 557
diff changeset
   101
indexOfFirstTemp:index
42cf4afd99b3 inline blocks withs args
Claus Gittinger <cg@exept.de>
parents: 557
diff changeset
   102
    indexOfFirstTemp := index
42cf4afd99b3 inline blocks withs args
Claus Gittinger <cg@exept.de>
parents: 557
diff changeset
   103
42cf4afd99b3 inline blocks withs args
Claus Gittinger <cg@exept.de>
parents: 557
diff changeset
   104
    "Created: 25.6.1997 / 17:24:27 / cg"
42cf4afd99b3 inline blocks withs args
Claus Gittinger <cg@exept.de>
parents: 557
diff changeset
   105
!
42cf4afd99b3 inline blocks withs args
Claus Gittinger <cg@exept.de>
parents: 557
diff changeset
   106
555
987b766b8b6e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 553
diff changeset
   107
inlineBlock:aBoolean
987b766b8b6e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 553
diff changeset
   108
    inlineBlock := aBoolean
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   109
!
7ad01559b262 Initial revision
claus
parents:
diff changeset
   110
555
987b766b8b6e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 553
diff changeset
   111
isInlineBlock
987b766b8b6e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 553
diff changeset
   112
    ^ inlineBlock
987b766b8b6e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 553
diff changeset
   113
987b766b8b6e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 553
diff changeset
   114
    "Created: 25.6.1997 / 14:11:33 / cg"
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   115
!
7ad01559b262 Initial revision
claus
parents:
diff changeset
   116
394
728e3b942ad5 remember endLinenr
Claus Gittinger <cg@exept.de>
parents: 386
diff changeset
   117
lineNumber
728e3b942ad5 remember endLinenr
Claus Gittinger <cg@exept.de>
parents: 386
diff changeset
   118
    ^ lineNr
728e3b942ad5 remember endLinenr
Claus Gittinger <cg@exept.de>
parents: 386
diff changeset
   119
728e3b942ad5 remember endLinenr
Claus Gittinger <cg@exept.de>
parents: 386
diff changeset
   120
    "Created: 23.10.1996 / 15:51:50 / cg"
728e3b942ad5 remember endLinenr
Claus Gittinger <cg@exept.de>
parents: 386
diff changeset
   121
!
728e3b942ad5 remember endLinenr
Claus Gittinger <cg@exept.de>
parents: 386
diff changeset
   122
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   123
lineNumber:aNumber
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   124
    lineNr := aNumber
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   125
!
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   126
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   127
needsHome
7ad01559b262 Initial revision
claus
parents:
diff changeset
   128
    ^ needsHome
7ad01559b262 Initial revision
claus
parents:
diff changeset
   129
!
7ad01559b262 Initial revision
claus
parents:
diff changeset
   130
7ad01559b262 Initial revision
claus
parents:
diff changeset
   131
needsHome:aBoolean
7ad01559b262 Initial revision
claus
parents:
diff changeset
   132
    needsHome := aBoolean
6
0cd4e7480440 *** empty log message ***
claus
parents: 4
diff changeset
   133
!
0cd4e7480440 *** empty log message ***
claus
parents: 4
diff changeset
   134
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   135
statements
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   136
    ^ statements
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   137
!
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   138
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   139
statements:s
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   140
    statements := s
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   141
!
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   142
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   143
variables
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   144
    ^ blockVars
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   145
!
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   146
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   147
variables:varList
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   148
    blockVars := varList
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   149
! !
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   150
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   151
!BlockNode methodsFor:'block messages'!
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   152
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   153
doesNotUnderstand:aMessage
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   154
    |numArgs kludgeBlock|
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   155
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   156
    (Block implements:(aMessage selector)) ifTrue:[
212
ff39051e219f more constant folding options
Claus Gittinger <cg@exept.de>
parents: 199
diff changeset
   157
ff39051e219f more constant folding options
Claus Gittinger <cg@exept.de>
parents: 199
diff changeset
   158
	"/ mhmh - a message which I dont understand, but Block implements
ff39051e219f more constant folding options
Claus Gittinger <cg@exept.de>
parents: 199
diff changeset
   159
	"/  send it to a kludgeblock, which will evaluate me again ..."
ff39051e219f more constant folding options
Claus Gittinger <cg@exept.de>
parents: 199
diff changeset
   160
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   161
	numArgs := blockArgs size.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   162
	numArgs == 0 ifTrue:[
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   163
	    kludgeBlock := [self value]
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   164
	] ifFalse:[
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   165
	    numArgs == 1 ifTrue:[
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   166
		kludgeBlock := [:a1 | self value:a1].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   167
	    ] ifFalse:[
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   168
		numArgs == 2 ifTrue:[
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   169
		    kludgeBlock := [:a1 :a2 | self value:a1 value:a2].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   170
		] ifFalse:[
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   171
		    numArgs == 3 ifTrue:[
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   172
			kludgeBlock := [:a1 :a2 :a3| self value:a1 value:a2 value:a3].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   173
		    ] ifFalse:[
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   174
			numArgs == 4 ifTrue:[
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   175
			    kludgeBlock := [:a1 :a2 :a3 :a4| self value:a1 value:a2 value:a3 value:a4].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   176
			] ifFalse:[
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   177
			    ^ self error:'only support blocks with up-to 4 args'
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   178
			]
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   179
		    ]
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   180
		]
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   181
	    ]
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   182
	].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   183
	^ kludgeBlock perform:aMessage selector withArguments:aMessage arguments
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   184
    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   185
    ^ super doesNotUnderstand:aMessage
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   186
! !
7ad01559b262 Initial revision
claus
parents:
diff changeset
   187
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   188
!BlockNode methodsFor:'code generation'!
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   189
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   190
checkForSimpleBlock
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   191
    "simple things can be made cheap blocks right now -
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   192
     resulting in a simple pushLit instruction ..."
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   193
506
3dc049d3a2d7 care for stackSize when creating blocks.
Claus Gittinger <cg@exept.de>
parents: 458
diff changeset
   194
    |cheapy e val code stackSize|
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   195
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   196
    statements isNil ifTrue:[
366
3be89590df22 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 333
diff changeset
   197
        "a []-block"
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   198
366
3be89590df22 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 333
diff changeset
   199
        val := nil
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   200
    ] ifFalse:[
366
3be89590df22 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 333
diff changeset
   201
        statements nextStatement notNil ifTrue:[^ nil].
3be89590df22 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 333
diff changeset
   202
        (statements isMemberOf:StatementNode) ifFalse:[^ nil].
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   203
366
3be89590df22 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 333
diff changeset
   204
        e := statements expression.
3be89590df22 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 333
diff changeset
   205
        e isConstant ifFalse:[^ nil].
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   206
366
3be89590df22 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 333
diff changeset
   207
        val := e value.
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   208
    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   209
506
3dc049d3a2d7 care for stackSize when creating blocks.
Claus Gittinger <cg@exept.de>
parents: 458
diff changeset
   210
    stackSize := 0.
3dc049d3a2d7 care for stackSize when creating blocks.
Claus Gittinger <cg@exept.de>
parents: 458
diff changeset
   211
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   212
    val == 0 ifTrue:[
366
3be89590df22 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 333
diff changeset
   213
        "a [0]-block"
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   214
366
3be89590df22 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 333
diff changeset
   215
        code := ByteArray with:(ByteCodeCompiler byteCodeFor:#ret0).
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   216
    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   217
    val == 1 ifTrue:[
366
3be89590df22 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 333
diff changeset
   218
        "a [1]-block"
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   219
506
3dc049d3a2d7 care for stackSize when creating blocks.
Claus Gittinger <cg@exept.de>
parents: 458
diff changeset
   220
        stackSize := 1.
366
3be89590df22 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 333
diff changeset
   221
        code := ByteArray with:(ByteCodeCompiler byteCodeFor:#push1)
3be89590df22 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 333
diff changeset
   222
                          with:(ByteCodeCompiler byteCodeFor:#retTop).
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   223
    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   224
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   225
    val == true ifTrue:[
366
3be89590df22 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 333
diff changeset
   226
        "a [true]-block"
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   227
366
3be89590df22 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 333
diff changeset
   228
        code := ByteArray with:(ByteCodeCompiler byteCodeFor:#retTrue).
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   229
    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   230
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   231
    val == false ifTrue:[
366
3be89590df22 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 333
diff changeset
   232
        "a [false]-block"
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   233
366
3be89590df22 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 333
diff changeset
   234
        code := ByteArray with:(ByteCodeCompiler byteCodeFor:#retFalse).
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   235
    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   236
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   237
    val == nil ifTrue:[
366
3be89590df22 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 333
diff changeset
   238
        "a [nil]-block"
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   239
366
3be89590df22 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 333
diff changeset
   240
        code := ByteArray with:(ByteCodeCompiler byteCodeFor:#retNil).
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   241
    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   242
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   243
    code notNil ifTrue:[
379
24399d5c465c optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents: 366
diff changeset
   244
        cheapy := CheapBlock
366
3be89590df22 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 333
diff changeset
   245
                    byteCode:code
3be89590df22 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 333
diff changeset
   246
                    numArgs:(blockArgs size)
506
3dc049d3a2d7 care for stackSize when creating blocks.
Claus Gittinger <cg@exept.de>
parents: 458
diff changeset
   247
                    numStack:stackSize
366
3be89590df22 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 333
diff changeset
   248
                    sourcePosition:nil 
3be89590df22 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 333
diff changeset
   249
                    initialPC:nil 
3be89590df22 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 333
diff changeset
   250
                    literals:nil.
3be89590df22 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 333
diff changeset
   251
        ^ ConstantNode type:#Block value:cheapy
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   252
    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   253
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   254
    ^ nil
366
3be89590df22 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 333
diff changeset
   255
506
3dc049d3a2d7 care for stackSize when creating blocks.
Claus Gittinger <cg@exept.de>
parents: 458
diff changeset
   256
    "Modified: 13.4.1997 / 00:05:29 / cg"
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   257
!
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   258
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   259
codeForSideEffectOn:aStream inBlock:b for:aCompiler
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   260
    "generate code for this statement - value not needed.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   261
     For blocks, no code is generated at all."
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   262
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   263
    ^ self
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   264
!
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   265
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   266
codeInlineOn:aStream inBlock:b for:aCompiler
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   267
    self codeInlineOn:aStream inBlock:b valueNeeded:true for:aCompiler
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   268
!
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   269
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   270
codeInlineOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler
559
42cf4afd99b3 inline blocks withs args
Claus Gittinger <cg@exept.de>
parents: 557
diff changeset
   271
    |thisStatement nextStatement tmpIndex firstTempIndex codeBlock|
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   272
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   273
    blockVars notNil ifTrue:[
559
42cf4afd99b3 inline blocks withs args
Claus Gittinger <cg@exept.de>
parents: 557
diff changeset
   274
        "/ have to move blockvars into surrounding context
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   275
559
42cf4afd99b3 inline blocks withs args
Claus Gittinger <cg@exept.de>
parents: 557
diff changeset
   276
        "/ find the first non-inlined block
42cf4afd99b3 inline blocks withs args
Claus Gittinger <cg@exept.de>
parents: 557
diff changeset
   277
        codeBlock := b.
42cf4afd99b3 inline blocks withs args
Claus Gittinger <cg@exept.de>
parents: 557
diff changeset
   278
        [codeBlock notNil and:[codeBlock isInlineBlock]] whileTrue:[
42cf4afd99b3 inline blocks withs args
Claus Gittinger <cg@exept.de>
parents: 557
diff changeset
   279
            codeBlock := codeBlock home.
553
59e4fcf722f6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 544
diff changeset
   280
        ].
59e4fcf722f6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 544
diff changeset
   281
559
42cf4afd99b3 inline blocks withs args
Claus Gittinger <cg@exept.de>
parents: 557
diff changeset
   282
        blockVars do:[:aBlockVar |
42cf4afd99b3 inline blocks withs args
Claus Gittinger <cg@exept.de>
parents: 557
diff changeset
   283
            codeBlock isNil ifTrue:[
42cf4afd99b3 inline blocks withs args
Claus Gittinger <cg@exept.de>
parents: 557
diff changeset
   284
                "/ in method - add more temps to the method
42cf4afd99b3 inline blocks withs args
Claus Gittinger <cg@exept.de>
parents: 557
diff changeset
   285
                tmpIndex := aCompiler addTempVar.
42cf4afd99b3 inline blocks withs args
Claus Gittinger <cg@exept.de>
parents: 557
diff changeset
   286
            ] ifFalse:[
42cf4afd99b3 inline blocks withs args
Claus Gittinger <cg@exept.de>
parents: 557
diff changeset
   287
                "/ in another block - add more temps to the block
42cf4afd99b3 inline blocks withs args
Claus Gittinger <cg@exept.de>
parents: 557
diff changeset
   288
                tmpIndex := codeBlock addTempVar
42cf4afd99b3 inline blocks withs args
Claus Gittinger <cg@exept.de>
parents: 557
diff changeset
   289
            ].
42cf4afd99b3 inline blocks withs args
Claus Gittinger <cg@exept.de>
parents: 557
diff changeset
   290
42cf4afd99b3 inline blocks withs args
Claus Gittinger <cg@exept.de>
parents: 557
diff changeset
   291
            firstTempIndex isNil ifTrue:[
42cf4afd99b3 inline blocks withs args
Claus Gittinger <cg@exept.de>
parents: 557
diff changeset
   292
                firstTempIndex := tmpIndex.
42cf4afd99b3 inline blocks withs args
Claus Gittinger <cg@exept.de>
parents: 557
diff changeset
   293
                indexOfFirstTemp isNil ifTrue:[
42cf4afd99b3 inline blocks withs args
Claus Gittinger <cg@exept.de>
parents: 557
diff changeset
   294
                    indexOfFirstTemp := tmpIndex
42cf4afd99b3 inline blocks withs args
Claus Gittinger <cg@exept.de>
parents: 557
diff changeset
   295
                ].
42cf4afd99b3 inline blocks withs args
Claus Gittinger <cg@exept.de>
parents: 557
diff changeset
   296
            ].
42cf4afd99b3 inline blocks withs args
Claus Gittinger <cg@exept.de>
parents: 557
diff changeset
   297
42cf4afd99b3 inline blocks withs args
Claus Gittinger <cg@exept.de>
parents: 557
diff changeset
   298
            "/ block vars must be nilled 
42cf4afd99b3 inline blocks withs args
Claus Gittinger <cg@exept.de>
parents: 557
diff changeset
   299
            "/ (in case the previous block left some value there).
42cf4afd99b3 inline blocks withs args
Claus Gittinger <cg@exept.de>
parents: 557
diff changeset
   300
            "/ This nilling should be optimized away, if
42cf4afd99b3 inline blocks withs args
Claus Gittinger <cg@exept.de>
parents: 557
diff changeset
   301
            "/ the variable gets a value assigned before the first send.
42cf4afd99b3 inline blocks withs args
Claus Gittinger <cg@exept.de>
parents: 557
diff changeset
   302
42cf4afd99b3 inline blocks withs args
Claus Gittinger <cg@exept.de>
parents: 557
diff changeset
   303
            aStream nextPut:#pushNil.
42cf4afd99b3 inline blocks withs args
Claus Gittinger <cg@exept.de>
parents: 557
diff changeset
   304
            codeBlock isNil ifTrue:[
42cf4afd99b3 inline blocks withs args
Claus Gittinger <cg@exept.de>
parents: 557
diff changeset
   305
                "/ in method
42cf4afd99b3 inline blocks withs args
Claus Gittinger <cg@exept.de>
parents: 557
diff changeset
   306
                (tmpIndex <= 6) ifTrue:[
42cf4afd99b3 inline blocks withs args
Claus Gittinger <cg@exept.de>
parents: 557
diff changeset
   307
                    aStream nextPut:(#(storeMethodVar1 storeMethodVar2
42cf4afd99b3 inline blocks withs args
Claus Gittinger <cg@exept.de>
parents: 557
diff changeset
   308
                                       storeMethodVar3 storeMethodVar4
42cf4afd99b3 inline blocks withs args
Claus Gittinger <cg@exept.de>
parents: 557
diff changeset
   309
                                       storeMethodVar5 storeMethodVar6) at:tmpIndex).
42cf4afd99b3 inline blocks withs args
Claus Gittinger <cg@exept.de>
parents: 557
diff changeset
   310
                ] ifFalse:[
42cf4afd99b3 inline blocks withs args
Claus Gittinger <cg@exept.de>
parents: 557
diff changeset
   311
                    aStream nextPut:#storeMethodVar; nextPut:tmpIndex.
42cf4afd99b3 inline blocks withs args
Claus Gittinger <cg@exept.de>
parents: 557
diff changeset
   312
                ]
42cf4afd99b3 inline blocks withs args
Claus Gittinger <cg@exept.de>
parents: 557
diff changeset
   313
            ] ifFalse:[
42cf4afd99b3 inline blocks withs args
Claus Gittinger <cg@exept.de>
parents: 557
diff changeset
   314
                "/ in another block
42cf4afd99b3 inline blocks withs args
Claus Gittinger <cg@exept.de>
parents: 557
diff changeset
   315
                aStream nextPut:#storeBlockVar; nextPut:tmpIndex.
42cf4afd99b3 inline blocks withs args
Claus Gittinger <cg@exept.de>
parents: 557
diff changeset
   316
            ]
379
24399d5c465c optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents: 366
diff changeset
   317
        ].
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   318
    ].
379
24399d5c465c optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents: 366
diff changeset
   319
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   320
    inlineBlock := true.
555
987b766b8b6e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 553
diff changeset
   321
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   322
    statements isNil ifTrue:[
379
24399d5c465c optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents: 366
diff changeset
   323
        valueNeeded ifTrue:[
24399d5c465c optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents: 366
diff changeset
   324
            aStream nextPut:#pushNil
24399d5c465c optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents: 366
diff changeset
   325
        ]
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   326
    ] ifFalse:[
379
24399d5c465c optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents: 366
diff changeset
   327
        thisStatement := statements.
24399d5c465c optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents: 366
diff changeset
   328
        [thisStatement notNil] whileTrue:[
24399d5c465c optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents: 366
diff changeset
   329
            nextStatement := thisStatement nextStatement.
24399d5c465c optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents: 366
diff changeset
   330
            (nextStatement notNil or:[valueNeeded not]) ifTrue:[
24399d5c465c optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents: 366
diff changeset
   331
                thisStatement codeForSideEffectOn:aStream inBlock:b for:aCompiler
24399d5c465c optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents: 366
diff changeset
   332
            ] ifFalse:[
24399d5c465c optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents: 366
diff changeset
   333
                thisStatement codeOn:aStream inBlock:b for:aCompiler
24399d5c465c optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents: 366
diff changeset
   334
            ].
24399d5c465c optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents: 366
diff changeset
   335
            thisStatement := nextStatement
24399d5c465c optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents: 366
diff changeset
   336
        ]
24399d5c465c optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents: 366
diff changeset
   337
    ].
559
42cf4afd99b3 inline blocks withs args
Claus Gittinger <cg@exept.de>
parents: 557
diff changeset
   338
386
2f66de89a89b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 379
diff changeset
   339
"/    endLineNr notNil ifTrue:[
2f66de89a89b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 379
diff changeset
   340
"/        ParseNode codeLineNumber:endLineNr on:aStream for:aCompiler
2f66de89a89b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 379
diff changeset
   341
"/    ].
379
24399d5c465c optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents: 366
diff changeset
   342
559
42cf4afd99b3 inline blocks withs args
Claus Gittinger <cg@exept.de>
parents: 557
diff changeset
   343
    "/ pop off temps (blockVars).
42cf4afd99b3 inline blocks withs args
Claus Gittinger <cg@exept.de>
parents: 557
diff changeset
   344
    "/ also, they are nilled to prevent any temp stuff
42cf4afd99b3 inline blocks withs args
Claus Gittinger <cg@exept.de>
parents: 557
diff changeset
   345
    "/ from NOT being garbage collected.
42cf4afd99b3 inline blocks withs args
Claus Gittinger <cg@exept.de>
parents: 557
diff changeset
   346
    "/ could optimize here, temps are reused soon.
42cf4afd99b3 inline blocks withs args
Claus Gittinger <cg@exept.de>
parents: 557
diff changeset
   347
42cf4afd99b3 inline blocks withs args
Claus Gittinger <cg@exept.de>
parents: 557
diff changeset
   348
    blockVars notNil ifTrue:[
42cf4afd99b3 inline blocks withs args
Claus Gittinger <cg@exept.de>
parents: 557
diff changeset
   349
        tmpIndex := firstTempIndex.
42cf4afd99b3 inline blocks withs args
Claus Gittinger <cg@exept.de>
parents: 557
diff changeset
   350
        codeBlock isNil ifTrue:[
42cf4afd99b3 inline blocks withs args
Claus Gittinger <cg@exept.de>
parents: 557
diff changeset
   351
            blockVars do:[:dummy |
42cf4afd99b3 inline blocks withs args
Claus Gittinger <cg@exept.de>
parents: 557
diff changeset
   352
                aStream nextPut:#pushNil.
42cf4afd99b3 inline blocks withs args
Claus Gittinger <cg@exept.de>
parents: 557
diff changeset
   353
                aStream nextPut:#storeMethodVar; nextPut:tmpIndex.
42cf4afd99b3 inline blocks withs args
Claus Gittinger <cg@exept.de>
parents: 557
diff changeset
   354
                aCompiler removeTempVar
42cf4afd99b3 inline blocks withs args
Claus Gittinger <cg@exept.de>
parents: 557
diff changeset
   355
            ]    
42cf4afd99b3 inline blocks withs args
Claus Gittinger <cg@exept.de>
parents: 557
diff changeset
   356
        ] ifFalse:[
42cf4afd99b3 inline blocks withs args
Claus Gittinger <cg@exept.de>
parents: 557
diff changeset
   357
            blockVars do:[:dummy | 
42cf4afd99b3 inline blocks withs args
Claus Gittinger <cg@exept.de>
parents: 557
diff changeset
   358
                aStream nextPut:#pushNil.
42cf4afd99b3 inline blocks withs args
Claus Gittinger <cg@exept.de>
parents: 557
diff changeset
   359
                aStream nextPut:#storeBlockVar; nextPut:tmpIndex.
42cf4afd99b3 inline blocks withs args
Claus Gittinger <cg@exept.de>
parents: 557
diff changeset
   360
                codeBlock removeTempVar
42cf4afd99b3 inline blocks withs args
Claus Gittinger <cg@exept.de>
parents: 557
diff changeset
   361
            ]    
42cf4afd99b3 inline blocks withs args
Claus Gittinger <cg@exept.de>
parents: 557
diff changeset
   362
        ].
42cf4afd99b3 inline blocks withs args
Claus Gittinger <cg@exept.de>
parents: 557
diff changeset
   363
        tmpIndex := tmpIndex + 1.
42cf4afd99b3 inline blocks withs args
Claus Gittinger <cg@exept.de>
parents: 557
diff changeset
   364
    ].
42cf4afd99b3 inline blocks withs args
Claus Gittinger <cg@exept.de>
parents: 557
diff changeset
   365
42cf4afd99b3 inline blocks withs args
Claus Gittinger <cg@exept.de>
parents: 557
diff changeset
   366
    "Modified: 26.6.1997 / 10:39:08 / cg"
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   367
!
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   368
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   369
codeOn:aStream inBlock:b for:aCompiler
379
24399d5c465c optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents: 366
diff changeset
   370
    |thisStatement nextStatement lastStatement pos code cheapy p0|
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   371
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   372
    cheapy := self checkForSimpleBlock.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   373
    cheapy notNil ifTrue:[
333
96bb5c3dab61 added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents: 278
diff changeset
   374
        cheapy codeOn:aStream inBlock:b for:aCompiler.
96bb5c3dab61 added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents: 278
diff changeset
   375
        ^ self
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   376
    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   377
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   378
    pos := aStream position.
62
a8e1828867a8 *** empty log message ***
claus
parents: 52
diff changeset
   379
555
987b766b8b6e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 553
diff changeset
   380
    aStream nextPut:#makeBlock.                                 "+0"
987b766b8b6e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 553
diff changeset
   381
    aStream nextPut:0.                                          "+1"
557
8202a13be88b preps to move vars of inlined blocks to outer context
Claus Gittinger <cg@exept.de>
parents: 555
diff changeset
   382
    aStream nextPut:(blockVars size + maxNumTemp).              "+2"
555
987b766b8b6e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 553
diff changeset
   383
    aStream nextPut:(blockArgs size).                           "+3"
987b766b8b6e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 553
diff changeset
   384
                                                                "+4"
394
728e3b942ad5 remember endLinenr
Claus Gittinger <cg@exept.de>
parents: 386
diff changeset
   385
    p0 := pos+4.
728e3b942ad5 remember endLinenr
Claus Gittinger <cg@exept.de>
parents: 386
diff changeset
   386
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   387
    statements isNil ifTrue:[
379
24399d5c465c optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents: 366
diff changeset
   388
        endLineNr notNil ifTrue:[
24399d5c465c optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents: 366
diff changeset
   389
            ParseNode codeLineNumber:endLineNr on:aStream for:aCompiler
24399d5c465c optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents: 366
diff changeset
   390
        ].
24399d5c465c optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents: 366
diff changeset
   391
        aStream nextPut:#pushNil.          
24399d5c465c optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents: 366
diff changeset
   392
        aStream nextPut:#retTop.
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   393
    ] ifFalse:[
333
96bb5c3dab61 added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents: 278
diff changeset
   394
        thisStatement := statements.
96bb5c3dab61 added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents: 278
diff changeset
   395
        [thisStatement notNil] whileTrue:[
96bb5c3dab61 added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents: 278
diff changeset
   396
            nextStatement := thisStatement nextStatement.
96bb5c3dab61 added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents: 278
diff changeset
   397
            nextStatement notNil ifTrue:[
96bb5c3dab61 added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents: 278
diff changeset
   398
                thisStatement codeForSideEffectOn:aStream inBlock:self for:aCompiler
96bb5c3dab61 added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents: 278
diff changeset
   399
            ] ifFalse:[
379
24399d5c465c optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents: 366
diff changeset
   400
                lastStatement := thisStatement
333
96bb5c3dab61 added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents: 278
diff changeset
   401
            ].
96bb5c3dab61 added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents: 278
diff changeset
   402
            thisStatement := nextStatement
379
24399d5c465c optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents: 366
diff changeset
   403
        ].
24399d5c465c optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents: 366
diff changeset
   404
24399d5c465c optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents: 366
diff changeset
   405
        lastStatement isPrimary ifTrue:[
24399d5c465c optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents: 366
diff changeset
   406
            ReturnNode
24399d5c465c optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents: 366
diff changeset
   407
                codeSimpleReturnFor:lastStatement expression 
24399d5c465c optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents: 366
diff changeset
   408
                inBlock:nil 
24399d5c465c optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents: 366
diff changeset
   409
                on:aStream 
24399d5c465c optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents: 366
diff changeset
   410
                inLine:endLineNr 
24399d5c465c optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents: 366
diff changeset
   411
                for:aCompiler
24399d5c465c optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents: 366
diff changeset
   412
        ].
24399d5c465c optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents: 366
diff changeset
   413
        lastStatement codeOn:aStream inBlock:self for:aCompiler.
24399d5c465c optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents: 366
diff changeset
   414
        endLineNr notNil ifTrue:[
24399d5c465c optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents: 366
diff changeset
   415
            ParseNode codeLineNumber:endLineNr on:aStream for:aCompiler
24399d5c465c optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents: 366
diff changeset
   416
        ].
24399d5c465c optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents: 366
diff changeset
   417
        aStream nextPut:#retTop.
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   418
    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   419
562
36bd00734940 care for numVars in makeBlock (inlined blocks add vars)
Claus Gittinger <cg@exept.de>
parents: 559
diff changeset
   420
    code := (aStream contents).
36bd00734940 care for numVars in makeBlock (inlined blocks add vars)
Claus Gittinger <cg@exept.de>
parents: 559
diff changeset
   421
36bd00734940 care for numVars in makeBlock (inlined blocks add vars)
Claus Gittinger <cg@exept.de>
parents: 559
diff changeset
   422
36bd00734940 care for numVars in makeBlock (inlined blocks add vars)
Claus Gittinger <cg@exept.de>
parents: 559
diff changeset
   423
    "/ sigh - during coding, inlined subBlocks may have added more
36bd00734940 care for numVars in makeBlock (inlined blocks add vars)
Claus Gittinger <cg@exept.de>
parents: 559
diff changeset
   424
    "/ tempVars; patch the nvar byte ...
36bd00734940 care for numVars in makeBlock (inlined blocks add vars)
Claus Gittinger <cg@exept.de>
parents: 559
diff changeset
   425
36bd00734940 care for numVars in makeBlock (inlined blocks add vars)
Claus Gittinger <cg@exept.de>
parents: 559
diff changeset
   426
    code at:pos+2 put:(blockVars size + maxNumTemp).
36bd00734940 care for numVars in makeBlock (inlined blocks add vars)
Claus Gittinger <cg@exept.de>
parents: 559
diff changeset
   427
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   428
    "check for [0]-block;
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   429
     these are sometimes used as in ... ifAbsent:[0]
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   430
    "
379
24399d5c465c optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents: 366
diff changeset
   431
    (code at:p0) == #lineno ifTrue:[
24399d5c465c optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents: 366
diff changeset
   432
        p0 := p0 + 2
24399d5c465c optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents: 366
diff changeset
   433
    ] ifFalse:[
24399d5c465c optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents: 366
diff changeset
   434
        (code at:p0) == #lineno16 ifTrue:[
24399d5c465c optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents: 366
diff changeset
   435
            p0 := p0 + 3
333
96bb5c3dab61 added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents: 278
diff changeset
   436
        ]
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   437
    ].
379
24399d5c465c optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents: 366
diff changeset
   438
24399d5c465c optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents: 366
diff changeset
   439
    (code at:p0) == #ret0 ifTrue:[
333
96bb5c3dab61 added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents: 278
diff changeset
   440
        aStream position:pos.
96bb5c3dab61 added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents: 278
diff changeset
   441
        code grow:pos.
96bb5c3dab61 added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents: 278
diff changeset
   442
        aStream nextPut:#mk0Block.
96bb5c3dab61 added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents: 278
diff changeset
   443
        ^ self
96bb5c3dab61 added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents: 278
diff changeset
   444
    ].    
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   445
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   446
    "check for [nil]-block;
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   447
     these come to play when code in blocks is commented
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   448
     out, or as dummy exception blocks
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   449
    "
379
24399d5c465c optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents: 366
diff changeset
   450
    (code at:p0) == #retNil ifTrue:[
333
96bb5c3dab61 added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents: 278
diff changeset
   451
        aStream position:pos.
96bb5c3dab61 added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents: 278
diff changeset
   452
        code grow:pos.
96bb5c3dab61 added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents: 278
diff changeset
   453
        aStream nextPut:#mkNilBlock.
96bb5c3dab61 added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents: 278
diff changeset
   454
        ^ self
96bb5c3dab61 added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents: 278
diff changeset
   455
    ].    
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   456
379
24399d5c465c optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents: 366
diff changeset
   457
    code at:pos+1 put:(aStream position)
333
96bb5c3dab61 added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents: 278
diff changeset
   458
562
36bd00734940 care for numVars in makeBlock (inlined blocks add vars)
Claus Gittinger <cg@exept.de>
parents: 559
diff changeset
   459
    "Modified: 26.6.1997 / 10:48:56 / cg"
555
987b766b8b6e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 553
diff changeset
   460
! !
987b766b8b6e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 553
diff changeset
   461
987b766b8b6e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 553
diff changeset
   462
!BlockNode methodsFor:'code generation helpers'!
987b766b8b6e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 553
diff changeset
   463
987b766b8b6e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 553
diff changeset
   464
addTempVar
987b766b8b6e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 553
diff changeset
   465
    "add a temporary variable; return its position (1-based).
987b766b8b6e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 553
diff changeset
   466
     Used when a block with args/locals is inlined."
987b766b8b6e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 553
diff changeset
   467
559
42cf4afd99b3 inline blocks withs args
Claus Gittinger <cg@exept.de>
parents: 557
diff changeset
   468
    inlineBlock ifTrue:[self halt:'should not happen'].
42cf4afd99b3 inline blocks withs args
Claus Gittinger <cg@exept.de>
parents: 557
diff changeset
   469
557
8202a13be88b preps to move vars of inlined blocks to outer context
Claus Gittinger <cg@exept.de>
parents: 555
diff changeset
   470
    numTemp isNil ifTrue:[numTemp := maxNumTemp := 0].
8202a13be88b preps to move vars of inlined blocks to outer context
Claus Gittinger <cg@exept.de>
parents: 555
diff changeset
   471
    numTemp := numTemp + 1.
8202a13be88b preps to move vars of inlined blocks to outer context
Claus Gittinger <cg@exept.de>
parents: 555
diff changeset
   472
    maxNumTemp := maxNumTemp max:numTemp.
559
42cf4afd99b3 inline blocks withs args
Claus Gittinger <cg@exept.de>
parents: 557
diff changeset
   473
    ^ numTemp + self numVars
555
987b766b8b6e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 553
diff changeset
   474
559
42cf4afd99b3 inline blocks withs args
Claus Gittinger <cg@exept.de>
parents: 557
diff changeset
   475
    "Modified: 26.6.1997 / 09:52:23 / cg"
555
987b766b8b6e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 553
diff changeset
   476
!
987b766b8b6e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 553
diff changeset
   477
987b766b8b6e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 553
diff changeset
   478
removeTempVar
987b766b8b6e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 553
diff changeset
   479
    "remove a temporary variable"
987b766b8b6e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 553
diff changeset
   480
557
8202a13be88b preps to move vars of inlined blocks to outer context
Claus Gittinger <cg@exept.de>
parents: 555
diff changeset
   481
    numTemp := numTemp - 1.
555
987b766b8b6e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 553
diff changeset
   482
987b766b8b6e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 553
diff changeset
   483
    "Created: 25.6.1997 / 14:04:20 / cg"
557
8202a13be88b preps to move vars of inlined blocks to outer context
Claus Gittinger <cg@exept.de>
parents: 555
diff changeset
   484
    "Modified: 25.6.1997 / 15:07:07 / cg"
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   485
! !
7ad01559b262 Initial revision
claus
parents:
diff changeset
   486
539
69a1cd05c7d6 added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents: 534
diff changeset
   487
!BlockNode methodsFor:'enumeration'!
69a1cd05c7d6 added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents: 534
diff changeset
   488
69a1cd05c7d6 added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents: 534
diff changeset
   489
nodeDo:anEnumerator
69a1cd05c7d6 added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents: 534
diff changeset
   490
    "helper for parse tree walking"
69a1cd05c7d6 added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents: 534
diff changeset
   491
544
fcfff6f8bc31 more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
   492
    |args|
fcfff6f8bc31 more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
   493
fcfff6f8bc31 more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
   494
    args := blockArgs ? #().
fcfff6f8bc31 more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
   495
    args := args collect:[:var |
fcfff6f8bc31 more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
   496
        |p|
fcfff6f8bc31 more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
   497
fcfff6f8bc31 more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
   498
        p := ParameterNode new.
fcfff6f8bc31 more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
   499
        p variable:var
fcfff6f8bc31 more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
   500
    ].
fcfff6f8bc31 more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
   501
    ^ anEnumerator doBlock:self arguments:args body:statements
539
69a1cd05c7d6 added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents: 534
diff changeset
   502
69a1cd05c7d6 added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents: 534
diff changeset
   503
    "Created: 19.6.1997 / 16:38:30 / cg"
544
fcfff6f8bc31 more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
   504
    "Modified: 19.6.1997 / 17:17:57 / cg"
539
69a1cd05c7d6 added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents: 534
diff changeset
   505
! !
69a1cd05c7d6 added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents: 534
diff changeset
   506
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   507
!BlockNode methodsFor:'evaluating'!
7ad01559b262 Initial revision
claus
parents:
diff changeset
   508
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   509
evaluate
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   510
    ^ self
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   511
!
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   512
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   513
exitWith:something
7ad01559b262 Initial revision
claus
parents:
diff changeset
   514
    "return via return-statement"
7ad01559b262 Initial revision
claus
parents:
diff changeset
   515
7ad01559b262 Initial revision
claus
parents:
diff changeset
   516
    home notNil ifTrue:[
45
e8331ba8ad5d *** empty log message ***
claus
parents: 39
diff changeset
   517
	home exitWith:something
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   518
    ].
7ad01559b262 Initial revision
claus
parents:
diff changeset
   519
    exitBlock value:something.
7ad01559b262 Initial revision
claus
parents:
diff changeset
   520
    ^ something
7ad01559b262 Initial revision
claus
parents:
diff changeset
   521
!
7ad01559b262 Initial revision
claus
parents:
diff changeset
   522
7ad01559b262 Initial revision
claus
parents:
diff changeset
   523
value
7ad01559b262 Initial revision
claus
parents:
diff changeset
   524
    (blockArgs size ~~ 0) ifTrue:[
45
e8331ba8ad5d *** empty log message ***
claus
parents: 39
diff changeset
   525
	^ self wrongNumberOfArguments:0
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   526
    ].
7ad01559b262 Initial revision
claus
parents:
diff changeset
   527
    statements isNil ifTrue:[^ nil].
7ad01559b262 Initial revision
claus
parents:
diff changeset
   528
    exitBlock := [:val | ^ val].
7ad01559b262 Initial revision
claus
parents:
diff changeset
   529
    ^ statements evaluate
7ad01559b262 Initial revision
claus
parents:
diff changeset
   530
!
7ad01559b262 Initial revision
claus
parents:
diff changeset
   531
7ad01559b262 Initial revision
claus
parents:
diff changeset
   532
value:anArg
7ad01559b262 Initial revision
claus
parents:
diff changeset
   533
    |oldValue val|
7ad01559b262 Initial revision
claus
parents:
diff changeset
   534
7ad01559b262 Initial revision
claus
parents:
diff changeset
   535
    (blockArgs size ~~ 1) ifTrue:[
45
e8331ba8ad5d *** empty log message ***
claus
parents: 39
diff changeset
   536
	^ self wrongNumberOfArguments:1
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   537
    ].
7ad01559b262 Initial revision
claus
parents:
diff changeset
   538
    statements isNil ifTrue:[^ nil].
7ad01559b262 Initial revision
claus
parents:
diff changeset
   539
7ad01559b262 Initial revision
claus
parents:
diff changeset
   540
    oldValue := (blockArgs at:1) value.
7ad01559b262 Initial revision
claus
parents:
diff changeset
   541
    (blockArgs at:1) value:anArg.
7ad01559b262 Initial revision
claus
parents:
diff changeset
   542
15
992c3d87edbf *** empty log message ***
claus
parents: 6
diff changeset
   543
    exitBlock := [:v | 
45
e8331ba8ad5d *** empty log message ***
claus
parents: 39
diff changeset
   544
	(blockArgs at:1) value:oldValue.
e8331ba8ad5d *** empty log message ***
claus
parents: 39
diff changeset
   545
	^ v
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   546
    ].
7ad01559b262 Initial revision
claus
parents:
diff changeset
   547
7ad01559b262 Initial revision
claus
parents:
diff changeset
   548
    val := statements evaluate.
7ad01559b262 Initial revision
claus
parents:
diff changeset
   549
7ad01559b262 Initial revision
claus
parents:
diff changeset
   550
    (blockArgs at:1) value:oldValue.
7ad01559b262 Initial revision
claus
parents:
diff changeset
   551
    ^ val
7ad01559b262 Initial revision
claus
parents:
diff changeset
   552
!
7ad01559b262 Initial revision
claus
parents:
diff changeset
   553
7ad01559b262 Initial revision
claus
parents:
diff changeset
   554
value:arg1 value:arg2
7ad01559b262 Initial revision
claus
parents:
diff changeset
   555
    |oldValue1 oldValue2 val|
7ad01559b262 Initial revision
claus
parents:
diff changeset
   556
7ad01559b262 Initial revision
claus
parents:
diff changeset
   557
    (blockArgs size ~~ 2) ifTrue:[
45
e8331ba8ad5d *** empty log message ***
claus
parents: 39
diff changeset
   558
	^ self wrongNumberOfArguments:2
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   559
    ].
7ad01559b262 Initial revision
claus
parents:
diff changeset
   560
    statements isNil ifTrue:[^ nil].
7ad01559b262 Initial revision
claus
parents:
diff changeset
   561
7ad01559b262 Initial revision
claus
parents:
diff changeset
   562
    oldValue1 := (blockArgs at:1) value.
7ad01559b262 Initial revision
claus
parents:
diff changeset
   563
    oldValue2 := (blockArgs at:2) value.
7ad01559b262 Initial revision
claus
parents:
diff changeset
   564
    (blockArgs at:1) value:arg1.
7ad01559b262 Initial revision
claus
parents:
diff changeset
   565
    (blockArgs at:2) value:arg2.
7ad01559b262 Initial revision
claus
parents:
diff changeset
   566
15
992c3d87edbf *** empty log message ***
claus
parents: 6
diff changeset
   567
    exitBlock := [:v | 
45
e8331ba8ad5d *** empty log message ***
claus
parents: 39
diff changeset
   568
	(blockArgs at:1) value:oldValue1.
e8331ba8ad5d *** empty log message ***
claus
parents: 39
diff changeset
   569
	(blockArgs at:2) value:oldValue2.
e8331ba8ad5d *** empty log message ***
claus
parents: 39
diff changeset
   570
	^ v
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   571
    ].
7ad01559b262 Initial revision
claus
parents:
diff changeset
   572
7ad01559b262 Initial revision
claus
parents:
diff changeset
   573
    val := statements evaluate.
7ad01559b262 Initial revision
claus
parents:
diff changeset
   574
7ad01559b262 Initial revision
claus
parents:
diff changeset
   575
    (blockArgs at:1) value:oldValue1.
7ad01559b262 Initial revision
claus
parents:
diff changeset
   576
    (blockArgs at:2) value:oldValue2.
7ad01559b262 Initial revision
claus
parents:
diff changeset
   577
    ^ val
7ad01559b262 Initial revision
claus
parents:
diff changeset
   578
!
7ad01559b262 Initial revision
claus
parents:
diff changeset
   579
7ad01559b262 Initial revision
claus
parents:
diff changeset
   580
value:arg1 value:arg2 value:arg3
7ad01559b262 Initial revision
claus
parents:
diff changeset
   581
    |oldValue1 oldValue2 oldValue3 val|
7ad01559b262 Initial revision
claus
parents:
diff changeset
   582
7ad01559b262 Initial revision
claus
parents:
diff changeset
   583
    (blockArgs size ~~ 3) ifTrue:[
45
e8331ba8ad5d *** empty log message ***
claus
parents: 39
diff changeset
   584
	^ self wrongNumberOfArguments:3
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   585
    ].
7ad01559b262 Initial revision
claus
parents:
diff changeset
   586
    statements isNil ifTrue:[^ nil].
7ad01559b262 Initial revision
claus
parents:
diff changeset
   587
7ad01559b262 Initial revision
claus
parents:
diff changeset
   588
    oldValue1 := (blockArgs at:1) value.
7ad01559b262 Initial revision
claus
parents:
diff changeset
   589
    oldValue2 := (blockArgs at:2) value.
7ad01559b262 Initial revision
claus
parents:
diff changeset
   590
    oldValue3 := (blockArgs at:3) value.
7ad01559b262 Initial revision
claus
parents:
diff changeset
   591
    (blockArgs at:1) value:arg1.
7ad01559b262 Initial revision
claus
parents:
diff changeset
   592
    (blockArgs at:2) value:arg2.
7ad01559b262 Initial revision
claus
parents:
diff changeset
   593
    (blockArgs at:3) value:arg3.
7ad01559b262 Initial revision
claus
parents:
diff changeset
   594
15
992c3d87edbf *** empty log message ***
claus
parents: 6
diff changeset
   595
    exitBlock := [:v | 
45
e8331ba8ad5d *** empty log message ***
claus
parents: 39
diff changeset
   596
	(blockArgs at:1) value:oldValue1.
e8331ba8ad5d *** empty log message ***
claus
parents: 39
diff changeset
   597
	(blockArgs at:2) value:oldValue2.
e8331ba8ad5d *** empty log message ***
claus
parents: 39
diff changeset
   598
	(blockArgs at:3) value:oldValue3.
e8331ba8ad5d *** empty log message ***
claus
parents: 39
diff changeset
   599
	^ v
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   600
    ].
7ad01559b262 Initial revision
claus
parents:
diff changeset
   601
7ad01559b262 Initial revision
claus
parents:
diff changeset
   602
    val := statements evaluate.
7ad01559b262 Initial revision
claus
parents:
diff changeset
   603
7ad01559b262 Initial revision
claus
parents:
diff changeset
   604
    (blockArgs at:1) value:oldValue1.
7ad01559b262 Initial revision
claus
parents:
diff changeset
   605
    (blockArgs at:2) value:oldValue2.
7ad01559b262 Initial revision
claus
parents:
diff changeset
   606
    (blockArgs at:3) value:oldValue3.
7ad01559b262 Initial revision
claus
parents:
diff changeset
   607
    ^ val
7ad01559b262 Initial revision
claus
parents:
diff changeset
   608
!
7ad01559b262 Initial revision
claus
parents:
diff changeset
   609
7ad01559b262 Initial revision
claus
parents:
diff changeset
   610
value:arg1 value:arg2 value:arg3 value:arg4
7ad01559b262 Initial revision
claus
parents:
diff changeset
   611
    |oldValue1 oldValue2 oldValue3 oldValue4 val|
7ad01559b262 Initial revision
claus
parents:
diff changeset
   612
7ad01559b262 Initial revision
claus
parents:
diff changeset
   613
    (blockArgs size ~~ 4) ifTrue:[
45
e8331ba8ad5d *** empty log message ***
claus
parents: 39
diff changeset
   614
	^ self wrongNumberOfArguments:4
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   615
    ].
7ad01559b262 Initial revision
claus
parents:
diff changeset
   616
    statements isNil ifTrue:[^ nil].
7ad01559b262 Initial revision
claus
parents:
diff changeset
   617
7ad01559b262 Initial revision
claus
parents:
diff changeset
   618
    oldValue1 := (blockArgs at:1) value.
7ad01559b262 Initial revision
claus
parents:
diff changeset
   619
    oldValue2 := (blockArgs at:2) value.
7ad01559b262 Initial revision
claus
parents:
diff changeset
   620
    oldValue3 := (blockArgs at:3) value.
7ad01559b262 Initial revision
claus
parents:
diff changeset
   621
    oldValue4 := (blockArgs at:4) value.
7ad01559b262 Initial revision
claus
parents:
diff changeset
   622
    (blockArgs at:1) value:arg1.
7ad01559b262 Initial revision
claus
parents:
diff changeset
   623
    (blockArgs at:2) value:arg2.
7ad01559b262 Initial revision
claus
parents:
diff changeset
   624
    (blockArgs at:3) value:arg3.
7ad01559b262 Initial revision
claus
parents:
diff changeset
   625
    (blockArgs at:4) value:arg4.
7ad01559b262 Initial revision
claus
parents:
diff changeset
   626
15
992c3d87edbf *** empty log message ***
claus
parents: 6
diff changeset
   627
    exitBlock := [:v | 
45
e8331ba8ad5d *** empty log message ***
claus
parents: 39
diff changeset
   628
	(blockArgs at:1) value:oldValue1.
e8331ba8ad5d *** empty log message ***
claus
parents: 39
diff changeset
   629
	(blockArgs at:2) value:oldValue2.
e8331ba8ad5d *** empty log message ***
claus
parents: 39
diff changeset
   630
	(blockArgs at:3) value:oldValue3.
e8331ba8ad5d *** empty log message ***
claus
parents: 39
diff changeset
   631
	(blockArgs at:4) value:oldValue4.
e8331ba8ad5d *** empty log message ***
claus
parents: 39
diff changeset
   632
	^ v
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   633
    ].
7ad01559b262 Initial revision
claus
parents:
diff changeset
   634
7ad01559b262 Initial revision
claus
parents:
diff changeset
   635
    val := statements evaluate.
7ad01559b262 Initial revision
claus
parents:
diff changeset
   636
7ad01559b262 Initial revision
claus
parents:
diff changeset
   637
    (blockArgs at:1) value:oldValue1.
7ad01559b262 Initial revision
claus
parents:
diff changeset
   638
    (blockArgs at:2) value:oldValue2.
7ad01559b262 Initial revision
claus
parents:
diff changeset
   639
    (blockArgs at:3) value:oldValue3.
7ad01559b262 Initial revision
claus
parents:
diff changeset
   640
    (blockArgs at:4) value:oldValue4.
7ad01559b262 Initial revision
claus
parents:
diff changeset
   641
    ^ val
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   642
!
3
b63b8a6b71fb *** empty log message ***
claus
parents: 0
diff changeset
   643
b63b8a6b71fb *** empty log message ***
claus
parents: 0
diff changeset
   644
valueWithArguments:argArray
b63b8a6b71fb *** empty log message ***
claus
parents: 0
diff changeset
   645
    |oldValues val|
b63b8a6b71fb *** empty log message ***
claus
parents: 0
diff changeset
   646
b63b8a6b71fb *** empty log message ***
claus
parents: 0
diff changeset
   647
    (blockArgs size ~~ argArray size) ifTrue:[
45
e8331ba8ad5d *** empty log message ***
claus
parents: 39
diff changeset
   648
	^ self wrongNumberOfArguments:argArray size
3
b63b8a6b71fb *** empty log message ***
claus
parents: 0
diff changeset
   649
    ].
b63b8a6b71fb *** empty log message ***
claus
parents: 0
diff changeset
   650
    statements isNil ifTrue:[^ nil].
b63b8a6b71fb *** empty log message ***
claus
parents: 0
diff changeset
   651
b63b8a6b71fb *** empty log message ***
claus
parents: 0
diff changeset
   652
    oldValues := Array new:(argArray size).
b63b8a6b71fb *** empty log message ***
claus
parents: 0
diff changeset
   653
    1 to:argArray size do:[:i |
45
e8331ba8ad5d *** empty log message ***
claus
parents: 39
diff changeset
   654
	oldValues at:i put:(blockArgs at:i) value.
e8331ba8ad5d *** empty log message ***
claus
parents: 39
diff changeset
   655
	(blockArgs at:i) value:(argArray at:i).
3
b63b8a6b71fb *** empty log message ***
claus
parents: 0
diff changeset
   656
    ].
15
992c3d87edbf *** empty log message ***
claus
parents: 6
diff changeset
   657
    exitBlock := [:v | 
45
e8331ba8ad5d *** empty log message ***
claus
parents: 39
diff changeset
   658
	1 to:argArray size do:[:i |
e8331ba8ad5d *** empty log message ***
claus
parents: 39
diff changeset
   659
	   ( blockArgs at:i) value:(oldValues at:i)
e8331ba8ad5d *** empty log message ***
claus
parents: 39
diff changeset
   660
	].
e8331ba8ad5d *** empty log message ***
claus
parents: 39
diff changeset
   661
	^ v
3
b63b8a6b71fb *** empty log message ***
claus
parents: 0
diff changeset
   662
    ].
b63b8a6b71fb *** empty log message ***
claus
parents: 0
diff changeset
   663
b63b8a6b71fb *** empty log message ***
claus
parents: 0
diff changeset
   664
    val := statements evaluate.
b63b8a6b71fb *** empty log message ***
claus
parents: 0
diff changeset
   665
b63b8a6b71fb *** empty log message ***
claus
parents: 0
diff changeset
   666
    1 to:argArray size do:[:i |
45
e8331ba8ad5d *** empty log message ***
claus
parents: 39
diff changeset
   667
	(blockArgs at:i) value:(oldValues at:i)
3
b63b8a6b71fb *** empty log message ***
claus
parents: 0
diff changeset
   668
    ].
b63b8a6b71fb *** empty log message ***
claus
parents: 0
diff changeset
   669
    ^ val
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   670
!
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   671
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   672
wrongNumberOfArguments:numberGiven
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   673
    Block argumentSignal
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   674
	raiseRequestWith:self
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   675
	errorString:('block got ' , numberGiven printString ,
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   676
		     ' args while ' , blockArgs size printString , ' where expected')
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   677
! !
7ad01559b262 Initial revision
claus
parents:
diff changeset
   678
7ad01559b262 Initial revision
claus
parents:
diff changeset
   679
!BlockNode methodsFor:'looping'!
7ad01559b262 Initial revision
claus
parents:
diff changeset
   680
7ad01559b262 Initial revision
claus
parents:
diff changeset
   681
whileFalse:aBlock
26
ce78d7693c78 argument count errors now raise signals
claus
parents: 20
diff changeset
   682
    self value ifTrue:[^ nil].
ce78d7693c78 argument count errors now raise signals
claus
parents: 20
diff changeset
   683
    aBlock value.
ce78d7693c78 argument count errors now raise signals
claus
parents: 20
diff changeset
   684
    thisContext restart
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   685
!
7ad01559b262 Initial revision
claus
parents:
diff changeset
   686
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   687
whileTrue:aBlock
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   688
    self value ifFalse:[^ nil].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   689
    aBlock value.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   690
    thisContext restart
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   691
! !
7ad01559b262 Initial revision
claus
parents:
diff changeset
   692
7ad01559b262 Initial revision
claus
parents:
diff changeset
   693
!BlockNode methodsFor:'printing'!
7ad01559b262 Initial revision
claus
parents:
diff changeset
   694
7ad01559b262 Initial revision
claus
parents:
diff changeset
   695
printOn:aStream indent:i
98
claus
parents: 96
diff changeset
   696
    |n "{Class: SmallInteger }"|
claus
parents: 96
diff changeset
   697
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   698
    aStream nextPut:$[.
98
claus
parents: 96
diff changeset
   699
    (n := blockArgs size) > 0 ifTrue:[
claus
parents: 96
diff changeset
   700
	1 to:n do:[:index |
96
claus
parents: 62
diff changeset
   701
	    aStream nextPut:$:.
claus
parents: 62
diff changeset
   702
	    aStream nextPutAll:(blockArgs at:index) name.
claus
parents: 62
diff changeset
   703
	    aStream space.
claus
parents: 62
diff changeset
   704
	].
98
claus
parents: 96
diff changeset
   705
	aStream nextPut:$|.
claus
parents: 96
diff changeset
   706
	aStream space.
claus
parents: 96
diff changeset
   707
    ].
claus
parents: 96
diff changeset
   708
    (n := blockVars size) > 0 ifTrue:[
claus
parents: 96
diff changeset
   709
	aStream nextPut:$|.
claus
parents: 96
diff changeset
   710
	1 to:n  do:[:index |
claus
parents: 96
diff changeset
   711
	    aStream nextPutAll:(blockVars at:index) name.
claus
parents: 96
diff changeset
   712
	    aStream space.
claus
parents: 96
diff changeset
   713
	].
claus
parents: 96
diff changeset
   714
	aStream nextPut:$|.
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   715
    ].
7ad01559b262 Initial revision
claus
parents:
diff changeset
   716
    statements notNil ifTrue:[
45
e8331ba8ad5d *** empty log message ***
claus
parents: 39
diff changeset
   717
	aStream cr.
e8331ba8ad5d *** empty log message ***
claus
parents: 39
diff changeset
   718
	statements printAllOn:aStream indent:i + 4.
e8331ba8ad5d *** empty log message ***
claus
parents: 39
diff changeset
   719
	aStream cr. 
e8331ba8ad5d *** empty log message ***
claus
parents: 39
diff changeset
   720
	aStream spaces:i.
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   721
    ].
7ad01559b262 Initial revision
claus
parents:
diff changeset
   722
    aStream nextPut:$]
7ad01559b262 Initial revision
claus
parents:
diff changeset
   723
! !
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   724
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   725
!BlockNode methodsFor:'private accessing'!
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   726
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   727
setArguments:argList home:h variables:vars
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   728
    inlineBlock := false.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   729
    needsHome := false.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   730
    blockArgs := argList.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   731
    home := h.
557
8202a13be88b preps to move vars of inlined blocks to outer context
Claus Gittinger <cg@exept.de>
parents: 555
diff changeset
   732
    blockVars := vars.
8202a13be88b preps to move vars of inlined blocks to outer context
Claus Gittinger <cg@exept.de>
parents: 555
diff changeset
   733
    numTemp := maxNumTemp := 0.
8202a13be88b preps to move vars of inlined blocks to outer context
Claus Gittinger <cg@exept.de>
parents: 555
diff changeset
   734
8202a13be88b preps to move vars of inlined blocks to outer context
Claus Gittinger <cg@exept.de>
parents: 555
diff changeset
   735
    "Modified: 25.6.1997 / 15:07:52 / cg"
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   736
! !
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   737
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   738
!BlockNode methodsFor:'queries'!
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   739
394
728e3b942ad5 remember endLinenr
Claus Gittinger <cg@exept.de>
parents: 386
diff changeset
   740
collectBlocksInto:aCollection
728e3b942ad5 remember endLinenr
Claus Gittinger <cg@exept.de>
parents: 386
diff changeset
   741
     aCollection add:self.
458
0e032b203043 care for empty blocks
ca
parents: 394
diff changeset
   742
     statements notNil ifTrue:[statements collectBlocksInto:aCollection]
394
728e3b942ad5 remember endLinenr
Claus Gittinger <cg@exept.de>
parents: 386
diff changeset
   743
728e3b942ad5 remember endLinenr
Claus Gittinger <cg@exept.de>
parents: 386
diff changeset
   744
    "Created: 23.10.1996 / 15:45:16 / cg"
728e3b942ad5 remember endLinenr
Claus Gittinger <cg@exept.de>
parents: 386
diff changeset
   745
    "Modified: 23.10.1996 / 16:02:57 / cg"
728e3b942ad5 remember endLinenr
Claus Gittinger <cg@exept.de>
parents: 386
diff changeset
   746
!
728e3b942ad5 remember endLinenr
Claus Gittinger <cg@exept.de>
parents: 386
diff changeset
   747
333
96bb5c3dab61 added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents: 278
diff changeset
   748
endsWithReturn
96bb5c3dab61 added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents: 278
diff changeset
   749
    statements isNil ifTrue:[
96bb5c3dab61 added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents: 278
diff changeset
   750
        ^ false
96bb5c3dab61 added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents: 278
diff changeset
   751
    ].
96bb5c3dab61 added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents: 278
diff changeset
   752
    ^ statements listEndsWithReturn
96bb5c3dab61 added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents: 278
diff changeset
   753
96bb5c3dab61 added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents: 278
diff changeset
   754
    "Created: 19.8.1996 / 14:36:32 / cg"
96bb5c3dab61 added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents: 278
diff changeset
   755
!
96bb5c3dab61 added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents: 278
diff changeset
   756
559
42cf4afd99b3 inline blocks withs args
Claus Gittinger <cg@exept.de>
parents: 557
diff changeset
   757
indexOfFirstTemp
42cf4afd99b3 inline blocks withs args
Claus Gittinger <cg@exept.de>
parents: 557
diff changeset
   758
    ^ indexOfFirstTemp
42cf4afd99b3 inline blocks withs args
Claus Gittinger <cg@exept.de>
parents: 557
diff changeset
   759
42cf4afd99b3 inline blocks withs args
Claus Gittinger <cg@exept.de>
parents: 557
diff changeset
   760
    "Created: 25.6.1997 / 15:39:11 / cg"
42cf4afd99b3 inline blocks withs args
Claus Gittinger <cg@exept.de>
parents: 557
diff changeset
   761
!
42cf4afd99b3 inline blocks withs args
Claus Gittinger <cg@exept.de>
parents: 557
diff changeset
   762
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   763
isBlock
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   764
    "a kludge, to have blocknodes mimic blocks"
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   765
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   766
    ^ true
168
87497e19c7d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   767
!
87497e19c7d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   768
394
728e3b942ad5 remember endLinenr
Claus Gittinger <cg@exept.de>
parents: 386
diff changeset
   769
numArgs
522
df72d3ed66a2 comment
Claus Gittinger <cg@exept.de>
parents: 506
diff changeset
   770
    "return the number of arguments the block represented by myself
df72d3ed66a2 comment
Claus Gittinger <cg@exept.de>
parents: 506
diff changeset
   771
     expects for evaluation"
df72d3ed66a2 comment
Claus Gittinger <cg@exept.de>
parents: 506
diff changeset
   772
394
728e3b942ad5 remember endLinenr
Claus Gittinger <cg@exept.de>
parents: 386
diff changeset
   773
    ^ blockArgs size
728e3b942ad5 remember endLinenr
Claus Gittinger <cg@exept.de>
parents: 386
diff changeset
   774
728e3b942ad5 remember endLinenr
Claus Gittinger <cg@exept.de>
parents: 386
diff changeset
   775
    "Created: 23.10.1996 / 15:57:04 / cg"
522
df72d3ed66a2 comment
Claus Gittinger <cg@exept.de>
parents: 506
diff changeset
   776
    "Modified: 7.5.1997 / 15:34:35 / cg"
394
728e3b942ad5 remember endLinenr
Claus Gittinger <cg@exept.de>
parents: 386
diff changeset
   777
!
728e3b942ad5 remember endLinenr
Claus Gittinger <cg@exept.de>
parents: 386
diff changeset
   778
728e3b942ad5 remember endLinenr
Claus Gittinger <cg@exept.de>
parents: 386
diff changeset
   779
numVars
728e3b942ad5 remember endLinenr
Claus Gittinger <cg@exept.de>
parents: 386
diff changeset
   780
    ^ blockVars size
728e3b942ad5 remember endLinenr
Claus Gittinger <cg@exept.de>
parents: 386
diff changeset
   781
728e3b942ad5 remember endLinenr
Claus Gittinger <cg@exept.de>
parents: 386
diff changeset
   782
    "Created: 23.10.1996 / 16:17:07 / cg"
728e3b942ad5 remember endLinenr
Claus Gittinger <cg@exept.de>
parents: 386
diff changeset
   783
!
728e3b942ad5 remember endLinenr
Claus Gittinger <cg@exept.de>
parents: 386
diff changeset
   784
169
dd594d765c73 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 168
diff changeset
   785
simpleSendBlockExpression
dd594d765c73 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 168
diff changeset
   786
    blockVars notNil ifTrue:[^ nil].
dd594d765c73 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 168
diff changeset
   787
    statements isNil ifTrue:[^ nil].
dd594d765c73 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 168
diff changeset
   788
    statements nextStatement notNil ifTrue:[^ nil].
dd594d765c73 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 168
diff changeset
   789
    ^ statements expression
dd594d765c73 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 168
diff changeset
   790
dd594d765c73 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 168
diff changeset
   791
    "Created: 13.12.1995 / 20:06:09 / cg"
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   792
! !
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   793
366
3be89590df22 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 333
diff changeset
   794
!BlockNode class methodsFor:'documentation'!
148
ef0e604209ec version method at the end
Claus Gittinger <cg@exept.de>
parents: 140
diff changeset
   795
ef0e604209ec version method at the end
Claus Gittinger <cg@exept.de>
parents: 140
diff changeset
   796
version
562
36bd00734940 care for numVars in makeBlock (inlined blocks add vars)
Claus Gittinger <cg@exept.de>
parents: 559
diff changeset
   797
    ^ '$Header: /cvs/stx/stx/libcomp/BlockNode.st,v 1.44 1997-06-26 09:05:30 cg Exp $'
148
ef0e604209ec version method at the end
Claus Gittinger <cg@exept.de>
parents: 140
diff changeset
   798
! !