BlockNode.st
author Claus Gittinger <cg@exept.de>
Wed, 25 Jun 1997 15:20:43 +0200
changeset 557 8202a13be88b
parent 555 987b766b8b6e
child 559 42cf4afd99b3
permissions -rw-r--r--
preps to move vars of inlined blocks to outer context
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
8202a13be88b preps to move vars of inlined blocks to outer context
Claus Gittinger <cg@exept.de>
parents: 555
diff changeset
    16
		maxNumTemp'
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
555
987b766b8b6e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 553
diff changeset
   101
inlineBlock:aBoolean
987b766b8b6e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 553
diff changeset
   102
    inlineBlock := aBoolean
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   103
!
7ad01559b262 Initial revision
claus
parents:
diff changeset
   104
555
987b766b8b6e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 553
diff changeset
   105
isInlineBlock
987b766b8b6e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 553
diff changeset
   106
    ^ inlineBlock
987b766b8b6e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 553
diff changeset
   107
987b766b8b6e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 553
diff changeset
   108
    "Created: 25.6.1997 / 14:11:33 / cg"
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   109
!
7ad01559b262 Initial revision
claus
parents:
diff changeset
   110
394
728e3b942ad5 remember endLinenr
Claus Gittinger <cg@exept.de>
parents: 386
diff changeset
   111
lineNumber
728e3b942ad5 remember endLinenr
Claus Gittinger <cg@exept.de>
parents: 386
diff changeset
   112
    ^ lineNr
728e3b942ad5 remember endLinenr
Claus Gittinger <cg@exept.de>
parents: 386
diff changeset
   113
728e3b942ad5 remember endLinenr
Claus Gittinger <cg@exept.de>
parents: 386
diff changeset
   114
    "Created: 23.10.1996 / 15:51:50 / cg"
728e3b942ad5 remember endLinenr
Claus Gittinger <cg@exept.de>
parents: 386
diff changeset
   115
!
728e3b942ad5 remember endLinenr
Claus Gittinger <cg@exept.de>
parents: 386
diff changeset
   116
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   117
lineNumber:aNumber
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   118
    lineNr := aNumber
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   119
!
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   120
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   121
needsHome
7ad01559b262 Initial revision
claus
parents:
diff changeset
   122
    ^ needsHome
7ad01559b262 Initial revision
claus
parents:
diff changeset
   123
!
7ad01559b262 Initial revision
claus
parents:
diff changeset
   124
7ad01559b262 Initial revision
claus
parents:
diff changeset
   125
needsHome:aBoolean
7ad01559b262 Initial revision
claus
parents:
diff changeset
   126
    needsHome := aBoolean
6
0cd4e7480440 *** empty log message ***
claus
parents: 4
diff changeset
   127
!
0cd4e7480440 *** empty log message ***
claus
parents: 4
diff changeset
   128
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   129
statements
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   130
    ^ statements
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   131
!
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   132
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   133
statements:s
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   134
    statements := s
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   135
!
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   136
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   137
variables
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   138
    ^ blockVars
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   139
!
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   141
variables:varList
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   142
    blockVars := varList
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   143
! !
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   144
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   145
!BlockNode methodsFor:'block messages'!
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
doesNotUnderstand:aMessage
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   148
    |numArgs kludgeBlock|
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
    (Block implements:(aMessage selector)) ifTrue:[
212
ff39051e219f more constant folding options
Claus Gittinger <cg@exept.de>
parents: 199
diff changeset
   151
ff39051e219f more constant folding options
Claus Gittinger <cg@exept.de>
parents: 199
diff changeset
   152
	"/ mhmh - a message which I dont understand, but Block implements
ff39051e219f more constant folding options
Claus Gittinger <cg@exept.de>
parents: 199
diff changeset
   153
	"/  send it to a kludgeblock, which will evaluate me again ..."
ff39051e219f more constant folding options
Claus Gittinger <cg@exept.de>
parents: 199
diff changeset
   154
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   155
	numArgs := blockArgs size.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   156
	numArgs == 0 ifTrue:[
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   157
	    kludgeBlock := [self value]
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   158
	] ifFalse:[
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   159
	    numArgs == 1 ifTrue:[
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   160
		kludgeBlock := [:a1 | self value:a1].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   161
	    ] ifFalse:[
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   162
		numArgs == 2 ifTrue:[
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   163
		    kludgeBlock := [:a1 :a2 | self value:a1 value:a2].
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 == 3 ifTrue:[
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   166
			kludgeBlock := [:a1 :a2 :a3| self value:a1 value:a2 value:a3].
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 == 4 ifTrue:[
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   169
			    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
   170
			] ifFalse:[
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   171
			    ^ self error:'only support blocks with up-to 4 args'
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   172
			]
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   173
		    ]
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   174
		]
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   175
	    ]
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   176
	].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   177
	^ kludgeBlock perform:aMessage selector withArguments:aMessage arguments
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
    ^ super doesNotUnderstand:aMessage
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   180
! !
7ad01559b262 Initial revision
claus
parents:
diff changeset
   181
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   182
!BlockNode methodsFor:'code generation'!
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   183
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   184
checkForSimpleBlock
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   185
    "simple things can be made cheap blocks right now -
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   186
     resulting in a simple pushLit instruction ..."
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   187
506
3dc049d3a2d7 care for stackSize when creating blocks.
Claus Gittinger <cg@exept.de>
parents: 458
diff changeset
   188
    |cheapy e val code stackSize|
140
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
    statements isNil ifTrue:[
366
3be89590df22 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 333
diff changeset
   191
        "a []-block"
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   192
366
3be89590df22 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 333
diff changeset
   193
        val := nil
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   194
    ] ifFalse:[
366
3be89590df22 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 333
diff changeset
   195
        statements nextStatement notNil ifTrue:[^ nil].
3be89590df22 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 333
diff changeset
   196
        (statements isMemberOf:StatementNode) ifFalse:[^ nil].
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   197
366
3be89590df22 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 333
diff changeset
   198
        e := statements expression.
3be89590df22 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 333
diff changeset
   199
        e isConstant ifFalse:[^ nil].
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   200
366
3be89590df22 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 333
diff changeset
   201
        val := e value.
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   202
    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   203
506
3dc049d3a2d7 care for stackSize when creating blocks.
Claus Gittinger <cg@exept.de>
parents: 458
diff changeset
   204
    stackSize := 0.
3dc049d3a2d7 care for stackSize when creating blocks.
Claus Gittinger <cg@exept.de>
parents: 458
diff changeset
   205
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   206
    val == 0 ifTrue:[
366
3be89590df22 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 333
diff changeset
   207
        "a [0]-block"
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   208
366
3be89590df22 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 333
diff changeset
   209
        code := ByteArray with:(ByteCodeCompiler byteCodeFor:#ret0).
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   210
    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   211
    val == 1 ifTrue:[
366
3be89590df22 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 333
diff changeset
   212
        "a [1]-block"
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   213
506
3dc049d3a2d7 care for stackSize when creating blocks.
Claus Gittinger <cg@exept.de>
parents: 458
diff changeset
   214
        stackSize := 1.
366
3be89590df22 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 333
diff changeset
   215
        code := ByteArray with:(ByteCodeCompiler byteCodeFor:#push1)
3be89590df22 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 333
diff changeset
   216
                          with:(ByteCodeCompiler byteCodeFor:#retTop).
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   217
    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   218
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   219
    val == true ifTrue:[
366
3be89590df22 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 333
diff changeset
   220
        "a [true]-block"
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   221
366
3be89590df22 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 333
diff changeset
   222
        code := ByteArray with:(ByteCodeCompiler byteCodeFor:#retTrue).
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 == false ifTrue:[
366
3be89590df22 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 333
diff changeset
   226
        "a [false]-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:#retFalse).
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 == nil ifTrue:[
366
3be89590df22 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 333
diff changeset
   232
        "a [nil]-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:#retNil).
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
    code notNil ifTrue:[
379
24399d5c465c optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents: 366
diff changeset
   238
        cheapy := CheapBlock
366
3be89590df22 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 333
diff changeset
   239
                    byteCode:code
3be89590df22 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 333
diff changeset
   240
                    numArgs:(blockArgs size)
506
3dc049d3a2d7 care for stackSize when creating blocks.
Claus Gittinger <cg@exept.de>
parents: 458
diff changeset
   241
                    numStack:stackSize
366
3be89590df22 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 333
diff changeset
   242
                    sourcePosition:nil 
3be89590df22 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 333
diff changeset
   243
                    initialPC:nil 
3be89590df22 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 333
diff changeset
   244
                    literals:nil.
3be89590df22 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 333
diff changeset
   245
        ^ ConstantNode type:#Block value:cheapy
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   246
    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   247
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   248
    ^ nil
366
3be89590df22 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 333
diff changeset
   249
506
3dc049d3a2d7 care for stackSize when creating blocks.
Claus Gittinger <cg@exept.de>
parents: 458
diff changeset
   250
    "Modified: 13.4.1997 / 00:05:29 / cg"
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   251
!
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
codeForSideEffectOn:aStream inBlock:b for:aCompiler
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   254
    "generate code for this statement - value not needed.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   255
     For blocks, no code is generated at all."
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   256
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   257
    ^ self
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
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   260
codeInlineOn:aStream inBlock:b for:aCompiler
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   261
    self codeInlineOn:aStream inBlock:b valueNeeded:true for:aCompiler
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
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   264
codeInlineOn:aStream inBlock:b valueNeeded:valueNeeded for:aCompiler
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   265
    |thisStatement nextStatement|
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   266
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   267
    blockVars notNil ifTrue:[
379
24399d5c465c optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents: 366
diff changeset
   268
        "cannot currently compile this block inline (have to move blockvars into
24399d5c465c optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents: 366
diff changeset
   269
         surrounding method. generate a make-block and send it value"
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   270
553
59e4fcf722f6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 544
diff changeset
   271
        self numArgs ~~ 0 ifTrue:[
59e4fcf722f6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 544
diff changeset
   272
            self halt:'unexpected: inlineBlock with args'.
59e4fcf722f6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 544
diff changeset
   273
        ].
59e4fcf722f6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 544
diff changeset
   274
278
8c8c96856b41 showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 263
diff changeset
   275
"/        Transcript showCR:'cannot (yet) compile block with blockvars inline'.
379
24399d5c465c optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents: 366
diff changeset
   276
        self codeOn:aStream inBlock:b for:aCompiler.
24399d5c465c optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents: 366
diff changeset
   277
        aStream nextPut:#value.
24399d5c465c optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents: 366
diff changeset
   278
        (aCompiler hasLineNumber:#value) ifTrue:[
24399d5c465c optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents: 366
diff changeset
   279
            aStream nextPut:lineNr.
24399d5c465c optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents: 366
diff changeset
   280
        ].
24399d5c465c optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents: 366
diff changeset
   281
        valueNeeded ifFalse:[
24399d5c465c optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents: 366
diff changeset
   282
            aStream nextPut:#drop
24399d5c465c optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents: 366
diff changeset
   283
        ].
24399d5c465c optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents: 366
diff changeset
   284
        ^ self
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   285
    ].
379
24399d5c465c optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents: 366
diff changeset
   286
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   287
    inlineBlock := true.
555
987b766b8b6e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 553
diff changeset
   288
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   289
    statements isNil ifTrue:[
379
24399d5c465c optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents: 366
diff changeset
   290
        valueNeeded ifTrue:[
24399d5c465c optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents: 366
diff changeset
   291
            aStream nextPut:#pushNil
24399d5c465c optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents: 366
diff changeset
   292
        ]
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   293
    ] ifFalse:[
379
24399d5c465c optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents: 366
diff changeset
   294
        thisStatement := statements.
24399d5c465c optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents: 366
diff changeset
   295
        [thisStatement notNil] whileTrue:[
24399d5c465c optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents: 366
diff changeset
   296
            nextStatement := thisStatement nextStatement.
24399d5c465c optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents: 366
diff changeset
   297
            (nextStatement notNil or:[valueNeeded not]) ifTrue:[
24399d5c465c optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents: 366
diff changeset
   298
                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
   299
            ] ifFalse:[
24399d5c465c optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents: 366
diff changeset
   300
                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
   301
            ].
24399d5c465c optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents: 366
diff changeset
   302
            thisStatement := nextStatement
24399d5c465c optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents: 366
diff changeset
   303
        ]
24399d5c465c optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents: 366
diff changeset
   304
    ].
386
2f66de89a89b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 379
diff changeset
   305
"/    endLineNr notNil ifTrue:[
2f66de89a89b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 379
diff changeset
   306
"/        ParseNode codeLineNumber:endLineNr on:aStream for:aCompiler
2f66de89a89b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 379
diff changeset
   307
"/    ].
379
24399d5c465c optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents: 366
diff changeset
   308
555
987b766b8b6e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 553
diff changeset
   309
    "Modified: 25.6.1997 / 14:05:16 / cg"
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   310
!
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   311
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   312
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
   313
    |thisStatement nextStatement lastStatement pos code cheapy p0|
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   314
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   315
    cheapy := self checkForSimpleBlock.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   316
    cheapy notNil ifTrue:[
333
96bb5c3dab61 added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents: 278
diff changeset
   317
        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
   318
        ^ self
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   319
    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   320
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   321
    pos := aStream position.
62
a8e1828867a8 *** empty log message ***
claus
parents: 52
diff changeset
   322
555
987b766b8b6e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 553
diff changeset
   323
    aStream nextPut:#makeBlock.                                 "+0"
987b766b8b6e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 553
diff changeset
   324
    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
   325
    aStream nextPut:(blockVars size + maxNumTemp).              "+2"
555
987b766b8b6e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 553
diff changeset
   326
    aStream nextPut:(blockArgs size).                           "+3"
987b766b8b6e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 553
diff changeset
   327
                                                                "+4"
394
728e3b942ad5 remember endLinenr
Claus Gittinger <cg@exept.de>
parents: 386
diff changeset
   328
    p0 := pos+4.
728e3b942ad5 remember endLinenr
Claus Gittinger <cg@exept.de>
parents: 386
diff changeset
   329
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   330
    statements isNil ifTrue:[
379
24399d5c465c optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents: 366
diff changeset
   331
        endLineNr notNil ifTrue:[
24399d5c465c optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents: 366
diff changeset
   332
            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
   333
        ].
24399d5c465c optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents: 366
diff changeset
   334
        aStream nextPut:#pushNil.          
24399d5c465c optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents: 366
diff changeset
   335
        aStream nextPut:#retTop.
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   336
    ] ifFalse:[
333
96bb5c3dab61 added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents: 278
diff changeset
   337
        thisStatement := statements.
96bb5c3dab61 added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents: 278
diff changeset
   338
        [thisStatement notNil] whileTrue:[
96bb5c3dab61 added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents: 278
diff changeset
   339
            nextStatement := thisStatement nextStatement.
96bb5c3dab61 added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents: 278
diff changeset
   340
            nextStatement notNil ifTrue:[
96bb5c3dab61 added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents: 278
diff changeset
   341
                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
   342
            ] ifFalse:[
379
24399d5c465c optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents: 366
diff changeset
   343
                lastStatement := thisStatement
333
96bb5c3dab61 added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents: 278
diff changeset
   344
            ].
96bb5c3dab61 added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents: 278
diff changeset
   345
            thisStatement := nextStatement
379
24399d5c465c optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents: 366
diff changeset
   346
        ].
24399d5c465c optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents: 366
diff changeset
   347
24399d5c465c optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents: 366
diff changeset
   348
        lastStatement isPrimary ifTrue:[
24399d5c465c optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents: 366
diff changeset
   349
            ReturnNode
24399d5c465c optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents: 366
diff changeset
   350
                codeSimpleReturnFor:lastStatement expression 
24399d5c465c optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents: 366
diff changeset
   351
                inBlock:nil 
24399d5c465c optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents: 366
diff changeset
   352
                on:aStream 
24399d5c465c optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents: 366
diff changeset
   353
                inLine:endLineNr 
24399d5c465c optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents: 366
diff changeset
   354
                for:aCompiler
24399d5c465c optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents: 366
diff changeset
   355
        ].
24399d5c465c optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents: 366
diff changeset
   356
        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
   357
        endLineNr notNil ifTrue:[
24399d5c465c optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents: 366
diff changeset
   358
            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
   359
        ].
24399d5c465c optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents: 366
diff changeset
   360
        aStream nextPut:#retTop.
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   361
    ].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   362
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   363
    "check for [0]-block;
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   364
     these are sometimes used as in ... ifAbsent:[0]
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   365
    "
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   366
    code := (aStream contents).
379
24399d5c465c optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents: 366
diff changeset
   367
    (code at:p0) == #lineno ifTrue:[
24399d5c465c optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents: 366
diff changeset
   368
        p0 := p0 + 2
24399d5c465c optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents: 366
diff changeset
   369
    ] ifFalse:[
24399d5c465c optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents: 366
diff changeset
   370
        (code at:p0) == #lineno16 ifTrue:[
24399d5c465c optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents: 366
diff changeset
   371
            p0 := p0 + 3
333
96bb5c3dab61 added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents: 278
diff changeset
   372
        ]
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   373
    ].
379
24399d5c465c optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents: 366
diff changeset
   374
24399d5c465c optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents: 366
diff changeset
   375
    (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
   376
        aStream position:pos.
96bb5c3dab61 added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents: 278
diff changeset
   377
        code grow:pos.
96bb5c3dab61 added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents: 278
diff changeset
   378
        aStream nextPut:#mk0Block.
96bb5c3dab61 added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents: 278
diff changeset
   379
        ^ self
96bb5c3dab61 added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents: 278
diff changeset
   380
    ].    
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   381
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   382
    "check for [nil]-block;
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   383
     these come to play when code in blocks is commented
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   384
     out, or as dummy exception blocks
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   385
    "
379
24399d5c465c optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents: 366
diff changeset
   386
    (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
   387
        aStream position:pos.
96bb5c3dab61 added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents: 278
diff changeset
   388
        code grow:pos.
96bb5c3dab61 added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents: 278
diff changeset
   389
        aStream nextPut:#mkNilBlock.
96bb5c3dab61 added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents: 278
diff changeset
   390
        ^ self
96bb5c3dab61 added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents: 278
diff changeset
   391
    ].    
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   392
379
24399d5c465c optionally mark the blocks-end with a lineNr.
Claus Gittinger <cg@exept.de>
parents: 366
diff changeset
   393
    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
   394
557
8202a13be88b preps to move vars of inlined blocks to outer context
Claus Gittinger <cg@exept.de>
parents: 555
diff changeset
   395
    "Modified: 25.6.1997 / 15:07:30 / cg"
555
987b766b8b6e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 553
diff changeset
   396
! !
987b766b8b6e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 553
diff changeset
   397
987b766b8b6e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 553
diff changeset
   398
!BlockNode methodsFor:'code generation helpers'!
987b766b8b6e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 553
diff changeset
   399
987b766b8b6e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 553
diff changeset
   400
addTempVar
987b766b8b6e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 553
diff changeset
   401
    "add a temporary variable; return its position (1-based).
987b766b8b6e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 553
diff changeset
   402
     Used when a block with args/locals is inlined."
987b766b8b6e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 553
diff changeset
   403
557
8202a13be88b preps to move vars of inlined blocks to outer context
Claus Gittinger <cg@exept.de>
parents: 555
diff changeset
   404
    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
   405
    numTemp := numTemp + 1.
8202a13be88b preps to move vars of inlined blocks to outer context
Claus Gittinger <cg@exept.de>
parents: 555
diff changeset
   406
    maxNumTemp := maxNumTemp max:numTemp.
8202a13be88b preps to move vars of inlined blocks to outer context
Claus Gittinger <cg@exept.de>
parents: 555
diff changeset
   407
    ^ numTemp
555
987b766b8b6e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 553
diff changeset
   408
557
8202a13be88b preps to move vars of inlined blocks to outer context
Claus Gittinger <cg@exept.de>
parents: 555
diff changeset
   409
    "Modified: 25.6.1997 / 15:06:56 / cg"
555
987b766b8b6e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 553
diff changeset
   410
!
987b766b8b6e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 553
diff changeset
   411
987b766b8b6e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 553
diff changeset
   412
removeTempVar
987b766b8b6e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 553
diff changeset
   413
    "remove a temporary variable"
987b766b8b6e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 553
diff changeset
   414
557
8202a13be88b preps to move vars of inlined blocks to outer context
Claus Gittinger <cg@exept.de>
parents: 555
diff changeset
   415
    numTemp := numTemp - 1.
555
987b766b8b6e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 553
diff changeset
   416
987b766b8b6e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 553
diff changeset
   417
    "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
   418
    "Modified: 25.6.1997 / 15:07:07 / cg"
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   419
! !
7ad01559b262 Initial revision
claus
parents:
diff changeset
   420
539
69a1cd05c7d6 added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents: 534
diff changeset
   421
!BlockNode methodsFor:'enumeration'!
69a1cd05c7d6 added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents: 534
diff changeset
   422
69a1cd05c7d6 added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents: 534
diff changeset
   423
nodeDo:anEnumerator
69a1cd05c7d6 added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents: 534
diff changeset
   424
    "helper for parse tree walking"
69a1cd05c7d6 added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents: 534
diff changeset
   425
544
fcfff6f8bc31 more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
   426
    |args|
fcfff6f8bc31 more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
   427
fcfff6f8bc31 more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
   428
    args := blockArgs ? #().
fcfff6f8bc31 more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
   429
    args := args collect:[:var |
fcfff6f8bc31 more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
   430
        |p|
fcfff6f8bc31 more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
   431
fcfff6f8bc31 more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
   432
        p := ParameterNode new.
fcfff6f8bc31 more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
   433
        p variable:var
fcfff6f8bc31 more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
   434
    ].
fcfff6f8bc31 more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
   435
    ^ anEnumerator doBlock:self arguments:args body:statements
539
69a1cd05c7d6 added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents: 534
diff changeset
   436
69a1cd05c7d6 added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents: 534
diff changeset
   437
    "Created: 19.6.1997 / 16:38:30 / cg"
544
fcfff6f8bc31 more ST80 compatible enumeration
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
   438
    "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
   439
! !
69a1cd05c7d6 added node-walk facility (ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents: 534
diff changeset
   440
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   441
!BlockNode methodsFor:'evaluating'!
7ad01559b262 Initial revision
claus
parents:
diff changeset
   442
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   443
evaluate
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   444
    ^ self
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
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   447
exitWith:something
7ad01559b262 Initial revision
claus
parents:
diff changeset
   448
    "return via return-statement"
7ad01559b262 Initial revision
claus
parents:
diff changeset
   449
7ad01559b262 Initial revision
claus
parents:
diff changeset
   450
    home notNil ifTrue:[
45
e8331ba8ad5d *** empty log message ***
claus
parents: 39
diff changeset
   451
	home exitWith:something
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   452
    ].
7ad01559b262 Initial revision
claus
parents:
diff changeset
   453
    exitBlock value:something.
7ad01559b262 Initial revision
claus
parents:
diff changeset
   454
    ^ something
7ad01559b262 Initial revision
claus
parents:
diff changeset
   455
!
7ad01559b262 Initial revision
claus
parents:
diff changeset
   456
7ad01559b262 Initial revision
claus
parents:
diff changeset
   457
value
7ad01559b262 Initial revision
claus
parents:
diff changeset
   458
    (blockArgs size ~~ 0) ifTrue:[
45
e8331ba8ad5d *** empty log message ***
claus
parents: 39
diff changeset
   459
	^ self wrongNumberOfArguments:0
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   460
    ].
7ad01559b262 Initial revision
claus
parents:
diff changeset
   461
    statements isNil ifTrue:[^ nil].
7ad01559b262 Initial revision
claus
parents:
diff changeset
   462
    exitBlock := [:val | ^ val].
7ad01559b262 Initial revision
claus
parents:
diff changeset
   463
    ^ statements evaluate
7ad01559b262 Initial revision
claus
parents:
diff changeset
   464
!
7ad01559b262 Initial revision
claus
parents:
diff changeset
   465
7ad01559b262 Initial revision
claus
parents:
diff changeset
   466
value:anArg
7ad01559b262 Initial revision
claus
parents:
diff changeset
   467
    |oldValue val|
7ad01559b262 Initial revision
claus
parents:
diff changeset
   468
7ad01559b262 Initial revision
claus
parents:
diff changeset
   469
    (blockArgs size ~~ 1) ifTrue:[
45
e8331ba8ad5d *** empty log message ***
claus
parents: 39
diff changeset
   470
	^ self wrongNumberOfArguments:1
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   471
    ].
7ad01559b262 Initial revision
claus
parents:
diff changeset
   472
    statements isNil ifTrue:[^ nil].
7ad01559b262 Initial revision
claus
parents:
diff changeset
   473
7ad01559b262 Initial revision
claus
parents:
diff changeset
   474
    oldValue := (blockArgs at:1) value.
7ad01559b262 Initial revision
claus
parents:
diff changeset
   475
    (blockArgs at:1) value:anArg.
7ad01559b262 Initial revision
claus
parents:
diff changeset
   476
15
992c3d87edbf *** empty log message ***
claus
parents: 6
diff changeset
   477
    exitBlock := [:v | 
45
e8331ba8ad5d *** empty log message ***
claus
parents: 39
diff changeset
   478
	(blockArgs at:1) value:oldValue.
e8331ba8ad5d *** empty log message ***
claus
parents: 39
diff changeset
   479
	^ v
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   480
    ].
7ad01559b262 Initial revision
claus
parents:
diff changeset
   481
7ad01559b262 Initial revision
claus
parents:
diff changeset
   482
    val := statements evaluate.
7ad01559b262 Initial revision
claus
parents:
diff changeset
   483
7ad01559b262 Initial revision
claus
parents:
diff changeset
   484
    (blockArgs at:1) value:oldValue.
7ad01559b262 Initial revision
claus
parents:
diff changeset
   485
    ^ val
7ad01559b262 Initial revision
claus
parents:
diff changeset
   486
!
7ad01559b262 Initial revision
claus
parents:
diff changeset
   487
7ad01559b262 Initial revision
claus
parents:
diff changeset
   488
value:arg1 value:arg2
7ad01559b262 Initial revision
claus
parents:
diff changeset
   489
    |oldValue1 oldValue2 val|
7ad01559b262 Initial revision
claus
parents:
diff changeset
   490
7ad01559b262 Initial revision
claus
parents:
diff changeset
   491
    (blockArgs size ~~ 2) ifTrue:[
45
e8331ba8ad5d *** empty log message ***
claus
parents: 39
diff changeset
   492
	^ self wrongNumberOfArguments:2
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   493
    ].
7ad01559b262 Initial revision
claus
parents:
diff changeset
   494
    statements isNil ifTrue:[^ nil].
7ad01559b262 Initial revision
claus
parents:
diff changeset
   495
7ad01559b262 Initial revision
claus
parents:
diff changeset
   496
    oldValue1 := (blockArgs at:1) value.
7ad01559b262 Initial revision
claus
parents:
diff changeset
   497
    oldValue2 := (blockArgs at:2) value.
7ad01559b262 Initial revision
claus
parents:
diff changeset
   498
    (blockArgs at:1) value:arg1.
7ad01559b262 Initial revision
claus
parents:
diff changeset
   499
    (blockArgs at:2) value:arg2.
7ad01559b262 Initial revision
claus
parents:
diff changeset
   500
15
992c3d87edbf *** empty log message ***
claus
parents: 6
diff changeset
   501
    exitBlock := [:v | 
45
e8331ba8ad5d *** empty log message ***
claus
parents: 39
diff changeset
   502
	(blockArgs at:1) value:oldValue1.
e8331ba8ad5d *** empty log message ***
claus
parents: 39
diff changeset
   503
	(blockArgs at:2) value:oldValue2.
e8331ba8ad5d *** empty log message ***
claus
parents: 39
diff changeset
   504
	^ v
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   505
    ].
7ad01559b262 Initial revision
claus
parents:
diff changeset
   506
7ad01559b262 Initial revision
claus
parents:
diff changeset
   507
    val := statements evaluate.
7ad01559b262 Initial revision
claus
parents:
diff changeset
   508
7ad01559b262 Initial revision
claus
parents:
diff changeset
   509
    (blockArgs at:1) value:oldValue1.
7ad01559b262 Initial revision
claus
parents:
diff changeset
   510
    (blockArgs at:2) value:oldValue2.
7ad01559b262 Initial revision
claus
parents:
diff changeset
   511
    ^ val
7ad01559b262 Initial revision
claus
parents:
diff changeset
   512
!
7ad01559b262 Initial revision
claus
parents:
diff changeset
   513
7ad01559b262 Initial revision
claus
parents:
diff changeset
   514
value:arg1 value:arg2 value:arg3
7ad01559b262 Initial revision
claus
parents:
diff changeset
   515
    |oldValue1 oldValue2 oldValue3 val|
7ad01559b262 Initial revision
claus
parents:
diff changeset
   516
7ad01559b262 Initial revision
claus
parents:
diff changeset
   517
    (blockArgs size ~~ 3) ifTrue:[
45
e8331ba8ad5d *** empty log message ***
claus
parents: 39
diff changeset
   518
	^ self wrongNumberOfArguments:3
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   519
    ].
7ad01559b262 Initial revision
claus
parents:
diff changeset
   520
    statements isNil ifTrue:[^ nil].
7ad01559b262 Initial revision
claus
parents:
diff changeset
   521
7ad01559b262 Initial revision
claus
parents:
diff changeset
   522
    oldValue1 := (blockArgs at:1) value.
7ad01559b262 Initial revision
claus
parents:
diff changeset
   523
    oldValue2 := (blockArgs at:2) value.
7ad01559b262 Initial revision
claus
parents:
diff changeset
   524
    oldValue3 := (blockArgs at:3) value.
7ad01559b262 Initial revision
claus
parents:
diff changeset
   525
    (blockArgs at:1) value:arg1.
7ad01559b262 Initial revision
claus
parents:
diff changeset
   526
    (blockArgs at:2) value:arg2.
7ad01559b262 Initial revision
claus
parents:
diff changeset
   527
    (blockArgs at:3) value:arg3.
7ad01559b262 Initial revision
claus
parents:
diff changeset
   528
15
992c3d87edbf *** empty log message ***
claus
parents: 6
diff changeset
   529
    exitBlock := [:v | 
45
e8331ba8ad5d *** empty log message ***
claus
parents: 39
diff changeset
   530
	(blockArgs at:1) value:oldValue1.
e8331ba8ad5d *** empty log message ***
claus
parents: 39
diff changeset
   531
	(blockArgs at:2) value:oldValue2.
e8331ba8ad5d *** empty log message ***
claus
parents: 39
diff changeset
   532
	(blockArgs at:3) value:oldValue3.
e8331ba8ad5d *** empty log message ***
claus
parents: 39
diff changeset
   533
	^ v
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   534
    ].
7ad01559b262 Initial revision
claus
parents:
diff changeset
   535
7ad01559b262 Initial revision
claus
parents:
diff changeset
   536
    val := statements evaluate.
7ad01559b262 Initial revision
claus
parents:
diff changeset
   537
7ad01559b262 Initial revision
claus
parents:
diff changeset
   538
    (blockArgs at:1) value:oldValue1.
7ad01559b262 Initial revision
claus
parents:
diff changeset
   539
    (blockArgs at:2) value:oldValue2.
7ad01559b262 Initial revision
claus
parents:
diff changeset
   540
    (blockArgs at:3) value:oldValue3.
7ad01559b262 Initial revision
claus
parents:
diff changeset
   541
    ^ val
7ad01559b262 Initial revision
claus
parents:
diff changeset
   542
!
7ad01559b262 Initial revision
claus
parents:
diff changeset
   543
7ad01559b262 Initial revision
claus
parents:
diff changeset
   544
value:arg1 value:arg2 value:arg3 value:arg4
7ad01559b262 Initial revision
claus
parents:
diff changeset
   545
    |oldValue1 oldValue2 oldValue3 oldValue4 val|
7ad01559b262 Initial revision
claus
parents:
diff changeset
   546
7ad01559b262 Initial revision
claus
parents:
diff changeset
   547
    (blockArgs size ~~ 4) ifTrue:[
45
e8331ba8ad5d *** empty log message ***
claus
parents: 39
diff changeset
   548
	^ self wrongNumberOfArguments:4
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   549
    ].
7ad01559b262 Initial revision
claus
parents:
diff changeset
   550
    statements isNil ifTrue:[^ nil].
7ad01559b262 Initial revision
claus
parents:
diff changeset
   551
7ad01559b262 Initial revision
claus
parents:
diff changeset
   552
    oldValue1 := (blockArgs at:1) value.
7ad01559b262 Initial revision
claus
parents:
diff changeset
   553
    oldValue2 := (blockArgs at:2) value.
7ad01559b262 Initial revision
claus
parents:
diff changeset
   554
    oldValue3 := (blockArgs at:3) value.
7ad01559b262 Initial revision
claus
parents:
diff changeset
   555
    oldValue4 := (blockArgs at:4) value.
7ad01559b262 Initial revision
claus
parents:
diff changeset
   556
    (blockArgs at:1) value:arg1.
7ad01559b262 Initial revision
claus
parents:
diff changeset
   557
    (blockArgs at:2) value:arg2.
7ad01559b262 Initial revision
claus
parents:
diff changeset
   558
    (blockArgs at:3) value:arg3.
7ad01559b262 Initial revision
claus
parents:
diff changeset
   559
    (blockArgs at:4) value:arg4.
7ad01559b262 Initial revision
claus
parents:
diff changeset
   560
15
992c3d87edbf *** empty log message ***
claus
parents: 6
diff changeset
   561
    exitBlock := [:v | 
45
e8331ba8ad5d *** empty log message ***
claus
parents: 39
diff changeset
   562
	(blockArgs at:1) value:oldValue1.
e8331ba8ad5d *** empty log message ***
claus
parents: 39
diff changeset
   563
	(blockArgs at:2) value:oldValue2.
e8331ba8ad5d *** empty log message ***
claus
parents: 39
diff changeset
   564
	(blockArgs at:3) value:oldValue3.
e8331ba8ad5d *** empty log message ***
claus
parents: 39
diff changeset
   565
	(blockArgs at:4) value:oldValue4.
e8331ba8ad5d *** empty log message ***
claus
parents: 39
diff changeset
   566
	^ v
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   567
    ].
7ad01559b262 Initial revision
claus
parents:
diff changeset
   568
7ad01559b262 Initial revision
claus
parents:
diff changeset
   569
    val := statements evaluate.
7ad01559b262 Initial revision
claus
parents:
diff changeset
   570
7ad01559b262 Initial revision
claus
parents:
diff changeset
   571
    (blockArgs at:1) value:oldValue1.
7ad01559b262 Initial revision
claus
parents:
diff changeset
   572
    (blockArgs at:2) value:oldValue2.
7ad01559b262 Initial revision
claus
parents:
diff changeset
   573
    (blockArgs at:3) value:oldValue3.
7ad01559b262 Initial revision
claus
parents:
diff changeset
   574
    (blockArgs at:4) value:oldValue4.
7ad01559b262 Initial revision
claus
parents:
diff changeset
   575
    ^ val
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   576
!
3
b63b8a6b71fb *** empty log message ***
claus
parents: 0
diff changeset
   577
b63b8a6b71fb *** empty log message ***
claus
parents: 0
diff changeset
   578
valueWithArguments:argArray
b63b8a6b71fb *** empty log message ***
claus
parents: 0
diff changeset
   579
    |oldValues val|
b63b8a6b71fb *** empty log message ***
claus
parents: 0
diff changeset
   580
b63b8a6b71fb *** empty log message ***
claus
parents: 0
diff changeset
   581
    (blockArgs size ~~ argArray size) ifTrue:[
45
e8331ba8ad5d *** empty log message ***
claus
parents: 39
diff changeset
   582
	^ self wrongNumberOfArguments:argArray size
3
b63b8a6b71fb *** empty log message ***
claus
parents: 0
diff changeset
   583
    ].
b63b8a6b71fb *** empty log message ***
claus
parents: 0
diff changeset
   584
    statements isNil ifTrue:[^ nil].
b63b8a6b71fb *** empty log message ***
claus
parents: 0
diff changeset
   585
b63b8a6b71fb *** empty log message ***
claus
parents: 0
diff changeset
   586
    oldValues := Array new:(argArray size).
b63b8a6b71fb *** empty log message ***
claus
parents: 0
diff changeset
   587
    1 to:argArray size do:[:i |
45
e8331ba8ad5d *** empty log message ***
claus
parents: 39
diff changeset
   588
	oldValues at:i put:(blockArgs at:i) value.
e8331ba8ad5d *** empty log message ***
claus
parents: 39
diff changeset
   589
	(blockArgs at:i) value:(argArray at:i).
3
b63b8a6b71fb *** empty log message ***
claus
parents: 0
diff changeset
   590
    ].
15
992c3d87edbf *** empty log message ***
claus
parents: 6
diff changeset
   591
    exitBlock := [:v | 
45
e8331ba8ad5d *** empty log message ***
claus
parents: 39
diff changeset
   592
	1 to:argArray size do:[:i |
e8331ba8ad5d *** empty log message ***
claus
parents: 39
diff changeset
   593
	   ( blockArgs at:i) value:(oldValues at:i)
e8331ba8ad5d *** empty log message ***
claus
parents: 39
diff changeset
   594
	].
e8331ba8ad5d *** empty log message ***
claus
parents: 39
diff changeset
   595
	^ v
3
b63b8a6b71fb *** empty log message ***
claus
parents: 0
diff changeset
   596
    ].
b63b8a6b71fb *** empty log message ***
claus
parents: 0
diff changeset
   597
b63b8a6b71fb *** empty log message ***
claus
parents: 0
diff changeset
   598
    val := statements evaluate.
b63b8a6b71fb *** empty log message ***
claus
parents: 0
diff changeset
   599
b63b8a6b71fb *** empty log message ***
claus
parents: 0
diff changeset
   600
    1 to:argArray size do:[:i |
45
e8331ba8ad5d *** empty log message ***
claus
parents: 39
diff changeset
   601
	(blockArgs at:i) value:(oldValues at:i)
3
b63b8a6b71fb *** empty log message ***
claus
parents: 0
diff changeset
   602
    ].
b63b8a6b71fb *** empty log message ***
claus
parents: 0
diff changeset
   603
    ^ val
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   604
!
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   605
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   606
wrongNumberOfArguments:numberGiven
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   607
    Block argumentSignal
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   608
	raiseRequestWith:self
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   609
	errorString:('block got ' , numberGiven printString ,
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   610
		     ' args while ' , blockArgs size printString , ' where expected')
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   611
! !
7ad01559b262 Initial revision
claus
parents:
diff changeset
   612
7ad01559b262 Initial revision
claus
parents:
diff changeset
   613
!BlockNode methodsFor:'looping'!
7ad01559b262 Initial revision
claus
parents:
diff changeset
   614
7ad01559b262 Initial revision
claus
parents:
diff changeset
   615
whileFalse:aBlock
26
ce78d7693c78 argument count errors now raise signals
claus
parents: 20
diff changeset
   616
    self value ifTrue:[^ nil].
ce78d7693c78 argument count errors now raise signals
claus
parents: 20
diff changeset
   617
    aBlock value.
ce78d7693c78 argument count errors now raise signals
claus
parents: 20
diff changeset
   618
    thisContext restart
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   619
!
7ad01559b262 Initial revision
claus
parents:
diff changeset
   620
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   621
whileTrue:aBlock
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   622
    self value ifFalse:[^ nil].
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   623
    aBlock value.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   624
    thisContext restart
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   625
! !
7ad01559b262 Initial revision
claus
parents:
diff changeset
   626
7ad01559b262 Initial revision
claus
parents:
diff changeset
   627
!BlockNode methodsFor:'printing'!
7ad01559b262 Initial revision
claus
parents:
diff changeset
   628
7ad01559b262 Initial revision
claus
parents:
diff changeset
   629
printOn:aStream indent:i
98
claus
parents: 96
diff changeset
   630
    |n "{Class: SmallInteger }"|
claus
parents: 96
diff changeset
   631
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   632
    aStream nextPut:$[.
98
claus
parents: 96
diff changeset
   633
    (n := blockArgs size) > 0 ifTrue:[
claus
parents: 96
diff changeset
   634
	1 to:n do:[:index |
96
claus
parents: 62
diff changeset
   635
	    aStream nextPut:$:.
claus
parents: 62
diff changeset
   636
	    aStream nextPutAll:(blockArgs at:index) name.
claus
parents: 62
diff changeset
   637
	    aStream space.
claus
parents: 62
diff changeset
   638
	].
98
claus
parents: 96
diff changeset
   639
	aStream nextPut:$|.
claus
parents: 96
diff changeset
   640
	aStream space.
claus
parents: 96
diff changeset
   641
    ].
claus
parents: 96
diff changeset
   642
    (n := blockVars size) > 0 ifTrue:[
claus
parents: 96
diff changeset
   643
	aStream nextPut:$|.
claus
parents: 96
diff changeset
   644
	1 to:n  do:[:index |
claus
parents: 96
diff changeset
   645
	    aStream nextPutAll:(blockVars at:index) name.
claus
parents: 96
diff changeset
   646
	    aStream space.
claus
parents: 96
diff changeset
   647
	].
claus
parents: 96
diff changeset
   648
	aStream nextPut:$|.
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   649
    ].
7ad01559b262 Initial revision
claus
parents:
diff changeset
   650
    statements notNil ifTrue:[
45
e8331ba8ad5d *** empty log message ***
claus
parents: 39
diff changeset
   651
	aStream cr.
e8331ba8ad5d *** empty log message ***
claus
parents: 39
diff changeset
   652
	statements printAllOn:aStream indent:i + 4.
e8331ba8ad5d *** empty log message ***
claus
parents: 39
diff changeset
   653
	aStream cr. 
e8331ba8ad5d *** empty log message ***
claus
parents: 39
diff changeset
   654
	aStream spaces:i.
0
7ad01559b262 Initial revision
claus
parents:
diff changeset
   655
    ].
7ad01559b262 Initial revision
claus
parents:
diff changeset
   656
    aStream nextPut:$]
7ad01559b262 Initial revision
claus
parents:
diff changeset
   657
! !
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   658
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   659
!BlockNode methodsFor:'private accessing'!
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   660
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   661
setArguments:argList home:h variables:vars
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   662
    inlineBlock := false.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   663
    needsHome := false.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   664
    blockArgs := argList.
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   665
    home := h.
557
8202a13be88b preps to move vars of inlined blocks to outer context
Claus Gittinger <cg@exept.de>
parents: 555
diff changeset
   666
    blockVars := vars.
8202a13be88b preps to move vars of inlined blocks to outer context
Claus Gittinger <cg@exept.de>
parents: 555
diff changeset
   667
    numTemp := maxNumTemp := 0.
8202a13be88b preps to move vars of inlined blocks to outer context
Claus Gittinger <cg@exept.de>
parents: 555
diff changeset
   668
8202a13be88b preps to move vars of inlined blocks to outer context
Claus Gittinger <cg@exept.de>
parents: 555
diff changeset
   669
    "Modified: 25.6.1997 / 15:07:52 / cg"
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
!BlockNode methodsFor:'queries'!
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   673
394
728e3b942ad5 remember endLinenr
Claus Gittinger <cg@exept.de>
parents: 386
diff changeset
   674
collectBlocksInto:aCollection
728e3b942ad5 remember endLinenr
Claus Gittinger <cg@exept.de>
parents: 386
diff changeset
   675
     aCollection add:self.
458
0e032b203043 care for empty blocks
ca
parents: 394
diff changeset
   676
     statements notNil ifTrue:[statements collectBlocksInto:aCollection]
394
728e3b942ad5 remember endLinenr
Claus Gittinger <cg@exept.de>
parents: 386
diff changeset
   677
728e3b942ad5 remember endLinenr
Claus Gittinger <cg@exept.de>
parents: 386
diff changeset
   678
    "Created: 23.10.1996 / 15:45:16 / cg"
728e3b942ad5 remember endLinenr
Claus Gittinger <cg@exept.de>
parents: 386
diff changeset
   679
    "Modified: 23.10.1996 / 16:02:57 / cg"
728e3b942ad5 remember endLinenr
Claus Gittinger <cg@exept.de>
parents: 386
diff changeset
   680
!
728e3b942ad5 remember endLinenr
Claus Gittinger <cg@exept.de>
parents: 386
diff changeset
   681
333
96bb5c3dab61 added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents: 278
diff changeset
   682
endsWithReturn
96bb5c3dab61 added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents: 278
diff changeset
   683
    statements isNil ifTrue:[
96bb5c3dab61 added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents: 278
diff changeset
   684
        ^ false
96bb5c3dab61 added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents: 278
diff changeset
   685
    ].
96bb5c3dab61 added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents: 278
diff changeset
   686
    ^ statements listEndsWithReturn
96bb5c3dab61 added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents: 278
diff changeset
   687
96bb5c3dab61 added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents: 278
diff changeset
   688
    "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
   689
!
96bb5c3dab61 added query if blocks statementList ends in a return;
Claus Gittinger <cg@exept.de>
parents: 278
diff changeset
   690
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   691
isBlock
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   692
    "a kludge, to have blocknodes mimic blocks"
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   693
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   694
    ^ true
168
87497e19c7d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   695
!
87497e19c7d5 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 148
diff changeset
   696
394
728e3b942ad5 remember endLinenr
Claus Gittinger <cg@exept.de>
parents: 386
diff changeset
   697
numArgs
522
df72d3ed66a2 comment
Claus Gittinger <cg@exept.de>
parents: 506
diff changeset
   698
    "return the number of arguments the block represented by myself
df72d3ed66a2 comment
Claus Gittinger <cg@exept.de>
parents: 506
diff changeset
   699
     expects for evaluation"
df72d3ed66a2 comment
Claus Gittinger <cg@exept.de>
parents: 506
diff changeset
   700
394
728e3b942ad5 remember endLinenr
Claus Gittinger <cg@exept.de>
parents: 386
diff changeset
   701
    ^ blockArgs size
728e3b942ad5 remember endLinenr
Claus Gittinger <cg@exept.de>
parents: 386
diff changeset
   702
728e3b942ad5 remember endLinenr
Claus Gittinger <cg@exept.de>
parents: 386
diff changeset
   703
    "Created: 23.10.1996 / 15:57:04 / cg"
522
df72d3ed66a2 comment
Claus Gittinger <cg@exept.de>
parents: 506
diff changeset
   704
    "Modified: 7.5.1997 / 15:34:35 / cg"
394
728e3b942ad5 remember endLinenr
Claus Gittinger <cg@exept.de>
parents: 386
diff changeset
   705
!
728e3b942ad5 remember endLinenr
Claus Gittinger <cg@exept.de>
parents: 386
diff changeset
   706
728e3b942ad5 remember endLinenr
Claus Gittinger <cg@exept.de>
parents: 386
diff changeset
   707
numVars
728e3b942ad5 remember endLinenr
Claus Gittinger <cg@exept.de>
parents: 386
diff changeset
   708
    ^ blockVars size
728e3b942ad5 remember endLinenr
Claus Gittinger <cg@exept.de>
parents: 386
diff changeset
   709
728e3b942ad5 remember endLinenr
Claus Gittinger <cg@exept.de>
parents: 386
diff changeset
   710
    "Created: 23.10.1996 / 16:17:07 / cg"
728e3b942ad5 remember endLinenr
Claus Gittinger <cg@exept.de>
parents: 386
diff changeset
   711
!
728e3b942ad5 remember endLinenr
Claus Gittinger <cg@exept.de>
parents: 386
diff changeset
   712
169
dd594d765c73 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 168
diff changeset
   713
simpleSendBlockExpression
dd594d765c73 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 168
diff changeset
   714
    blockVars notNil ifTrue:[^ nil].
dd594d765c73 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 168
diff changeset
   715
    statements isNil ifTrue:[^ nil].
dd594d765c73 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 168
diff changeset
   716
    statements nextStatement notNil ifTrue:[^ nil].
dd594d765c73 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 168
diff changeset
   717
    ^ statements expression
dd594d765c73 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 168
diff changeset
   718
dd594d765c73 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 168
diff changeset
   719
    "Created: 13.12.1995 / 20:06:09 / cg"
140
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   720
! !
1ef1d1395146 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 135
diff changeset
   721
366
3be89590df22 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 333
diff changeset
   722
!BlockNode class methodsFor:'documentation'!
148
ef0e604209ec version method at the end
Claus Gittinger <cg@exept.de>
parents: 140
diff changeset
   723
ef0e604209ec version method at the end
Claus Gittinger <cg@exept.de>
parents: 140
diff changeset
   724
version
557
8202a13be88b preps to move vars of inlined blocks to outer context
Claus Gittinger <cg@exept.de>
parents: 555
diff changeset
   725
    ^ '$Header: /cvs/stx/stx/libcomp/BlockNode.st,v 1.42 1997-06-25 13:20:43 cg Exp $'
148
ef0e604209ec version method at the end
Claus Gittinger <cg@exept.de>
parents: 140
diff changeset
   726
! !