author | Claus Gittinger <cg@exept.de> |
Thu, 27 Jun 2019 15:21:18 +0200 | |
changeset 24377 | 2fbcb2fa6c43 |
parent 21920 | 56d37fc40d49 |
permissions | -rw-r--r-- |
156 | 1 |
" |
2 |
COPYRIGHT (c) 1994 by Claus Gittinger |
|
3 |
All Rights Reserved |
|
4 |
||
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
5350 | 12 |
"{ Package: 'stx:libbasic' }" |
13 |
||
19446 | 14 |
"{ NameSpace: Smalltalk }" |
15 |
||
5350 | 16 |
Block variableSubclass:#CheapBlock |
1181
6637fee79d7b
only Block & CheapBlock are fixed - subclasses may look different
Claus Gittinger <cg@exept.de>
parents:
920
diff
changeset
|
17 |
instanceVariableNames:'selfValue method' |
6637fee79d7b
only Block & CheapBlock are fixed - subclasses may look different
Claus Gittinger <cg@exept.de>
parents:
920
diff
changeset
|
18 |
classVariableNames:'' |
6637fee79d7b
only Block & CheapBlock are fixed - subclasses may look different
Claus Gittinger <cg@exept.de>
parents:
920
diff
changeset
|
19 |
poolDictionaries:'' |
6637fee79d7b
only Block & CheapBlock are fixed - subclasses may look different
Claus Gittinger <cg@exept.de>
parents:
920
diff
changeset
|
20 |
category:'Kernel-Methods' |
156 | 21 |
! |
22 |
||
23 |
!CheapBlock class methodsFor:'documentation'! |
|
24 |
||
25 |
copyright |
|
26 |
" |
|
27 |
COPYRIGHT (c) 1994 by Claus Gittinger |
|
28 |
All Rights Reserved |
|
29 |
||
30 |
This software is furnished under a license and may be used |
|
31 |
only in accordance with the terms of that license and with the |
|
32 |
inclusion of the above copyright notice. This software may not |
|
33 |
be provided or otherwise made available to, or used by, any |
|
34 |
other person. No title to or ownership of the software is |
|
35 |
hereby transferred. |
|
36 |
" |
|
37 |
! |
|
38 |
||
39 |
documentation |
|
40 |
" |
|
222 | 41 |
CheapBlocks are blocks which do not need their home-context |
1254 | 42 |
(i.e. blocks that do not access any method arguments |
43 |
or method locals). |
|
44 |
||
45 |
CheapBlocks are never created explicitely; the only creation |
|
46 |
is done by the compilers, when some sourceCode is compiled to either |
|
2243 | 47 |
machine or byteCode, and the generated block is found to neither access |
48 |
any variables from its homeContext nor does a method-return. |
|
49 |
CheapBlocks create less overhead to the runtime system, in that they |
|
20786 | 50 |
do not keep the creating context from being reclaimed (but, don't expect |
2243 | 51 |
too much of a difference ;-) |
1254 | 52 |
|
156 | 53 |
Since they have no reference to the home, they must store their |
1254 | 54 |
creating method explicitely - otherwise, the system had no |
55 |
chance of finding the source-position of the block. |
|
156 | 56 |
|
1293 | 57 |
[Instance variables:] |
156 | 58 |
|
1254 | 59 |
selfValue <Object> copied self value |
21417 | 60 |
(if it's a copying block) |
222 | 61 |
|
62 |
method <Method> method where block was created |
|
156 | 63 |
|
64 |
NOTICE: layout known by runtime system and compiler - do not change |
|
1293 | 65 |
|
66 |
[author:] |
|
67 |
Claus Gittinger |
|
68 |
||
69 |
[see also:] |
|
70 |
Block Context Method |
|
71 |
( contexts, stacks & unwinding :html: programming/contexts.html ) |
|
156 | 72 |
" |
1181
6637fee79d7b
only Block & CheapBlock are fixed - subclasses may look different
Claus Gittinger <cg@exept.de>
parents:
920
diff
changeset
|
73 |
! ! |
6637fee79d7b
only Block & CheapBlock are fixed - subclasses may look different
Claus Gittinger <cg@exept.de>
parents:
920
diff
changeset
|
74 |
|
6637fee79d7b
only Block & CheapBlock are fixed - subclasses may look different
Claus Gittinger <cg@exept.de>
parents:
920
diff
changeset
|
75 |
!CheapBlock class methodsFor:'queries'! |
623 | 76 |
|
1181
6637fee79d7b
only Block & CheapBlock are fixed - subclasses may look different
Claus Gittinger <cg@exept.de>
parents:
920
diff
changeset
|
77 |
isBuiltInClass |
1264 | 78 |
"return true if this class is known by the run-time-system. |
79 |
Here, true is returned for myself, false for subclasses." |
|
1181
6637fee79d7b
only Block & CheapBlock are fixed - subclasses may look different
Claus Gittinger <cg@exept.de>
parents:
920
diff
changeset
|
80 |
|
6637fee79d7b
only Block & CheapBlock are fixed - subclasses may look different
Claus Gittinger <cg@exept.de>
parents:
920
diff
changeset
|
81 |
^ self == CheapBlock |
6637fee79d7b
only Block & CheapBlock are fixed - subclasses may look different
Claus Gittinger <cg@exept.de>
parents:
920
diff
changeset
|
82 |
|
6637fee79d7b
only Block & CheapBlock are fixed - subclasses may look different
Claus Gittinger <cg@exept.de>
parents:
920
diff
changeset
|
83 |
"Created: 16.4.1996 / 11:25:23 / cg" |
1264 | 84 |
"Modified: 23.4.1996 / 15:56:46 / cg" |
156 | 85 |
! ! |
86 |
||
87 |
!CheapBlock methodsFor:'accessing'! |
|
88 |
||
2694
46ba8cbdc013
added #homeMethod for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
2247
diff
changeset
|
89 |
homeMethod |
19446 | 90 |
"return the receiver's home method. |
91 |
That's the method where the block was created." |
|
161 | 92 |
|
93 |
^ method |
|
2694
46ba8cbdc013
added #homeMethod for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
2247
diff
changeset
|
94 |
|
46ba8cbdc013
added #homeMethod for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
2247
diff
changeset
|
95 |
"Created: 19.6.1997 / 16:14:35 / cg" |
46ba8cbdc013
added #homeMethod for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
2247
diff
changeset
|
96 |
"Modified: 19.6.1997 / 16:15:44 / cg" |
46ba8cbdc013
added #homeMethod for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
2247
diff
changeset
|
97 |
! |
46ba8cbdc013
added #homeMethod for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
2247
diff
changeset
|
98 |
|
623 | 99 |
selfValue |
100 |
"return the copied self" |
|
101 |
||
102 |
^ selfValue |
|
1796 | 103 |
! |
104 |
||
105 |
setMethod:aMethod |
|
19446 | 106 |
"set the receiver's home method. |
1796 | 107 |
This is a private entry for the compiler" |
108 |
||
109 |
method := aMethod |
|
110 |
||
111 |
"Created: 21.10.1996 / 13:58:29 / cg" |
|
156 | 112 |
! ! |
113 |
||
2247 | 114 |
!CheapBlock methodsFor:'conversion'! |
115 |
||
5350 | 116 |
asVarArgBlock |
2247 | 117 |
"convert myself into a varArg block; |
118 |
this one has 1 formal argument, which gets the list |
|
119 |
of actual arguments when evaluated." |
|
120 |
||
121 |
nargs ~~ 1 ifTrue:[ |
|
122 |
self error:'vararg blocks must take exactly 1 argument - the arg list'. |
|
123 |
^ nil |
|
124 |
]. |
|
125 |
||
126 |
self changeClassTo:VarArgCheapBlock. |
|
127 |
^ self |
|
128 |
||
129 |
" |
|
130 |
|b| |
|
131 |
||
5350 | 132 |
b := [:argList | argList printCR] asVarArgBlock. |
2247 | 133 |
b value. |
134 |
b value:'arg1' value:'arg2' value:'arg3' value:'arg4' |
|
135 |
" |
|
136 |
||
137 |
"Created: 23.1.1997 / 13:35:28 / cg" |
|
138 |
"Modified: 23.1.1997 / 13:35:48 / cg" |
|
139 |
! ! |
|
140 |
||
156 | 141 |
!CheapBlock methodsFor:'printing & storing'! |
142 |
||
143 |
printOn:aStream |
|
144 |
"append a a printed representation of the block to aStream" |
|
145 |
||
1852
89b2328f4203
use new Method>>who interface
Claus Gittinger <cg@exept.de>
parents:
1796
diff
changeset
|
146 |
|who| |
156 | 147 |
|
148 |
" |
|
149 |
cheap blocks have no home context, but a method instead |
|
150 |
" |
|
151 |
||
152 |
aStream nextPutAll:'[] in '. |
|
153 |
" |
|
154 |
find out, for which class this method was for ... |
|
155 |
" |
|
156 |
method notNil ifTrue:[ |
|
1852
89b2328f4203
use new Method>>who interface
Claus Gittinger <cg@exept.de>
parents:
1796
diff
changeset
|
157 |
who := method who. |
89b2328f4203
use new Method>>who interface
Claus Gittinger <cg@exept.de>
parents:
1796
diff
changeset
|
158 |
who notNil ifTrue:[ |
16917 | 159 |
aStream nextPutAll:(who methodClass name , '>>' , who methodSelector). |
1852
89b2328f4203
use new Method>>who interface
Claus Gittinger <cg@exept.de>
parents:
1796
diff
changeset
|
160 |
aStream nextPutAll:' (optimized)'. |
89b2328f4203
use new Method>>who interface
Claus Gittinger <cg@exept.de>
parents:
1796
diff
changeset
|
161 |
^ self |
89b2328f4203
use new Method>>who interface
Claus Gittinger <cg@exept.de>
parents:
1796
diff
changeset
|
162 |
]. |
156 | 163 |
]. |
164 |
" |
|
165 |
currently, some cheap blocks don't know where they have been created |
|
166 |
" |
|
167 |
aStream nextPutAll:' ??? (optimized)'. |
|
168 |
^ self |
|
1852
89b2328f4203
use new Method>>who interface
Claus Gittinger <cg@exept.de>
parents:
1796
diff
changeset
|
169 |
|
89b2328f4203
use new Method>>who interface
Claus Gittinger <cg@exept.de>
parents:
1796
diff
changeset
|
170 |
"Modified: 1.11.1996 / 16:21:19 / cg" |
156 | 171 |
! ! |
1181
6637fee79d7b
only Block & CheapBlock are fixed - subclasses may look different
Claus Gittinger <cg@exept.de>
parents:
920
diff
changeset
|
172 |
|
16277 | 173 |
!CheapBlock methodsFor:'testing'! |
174 |
||
175 |
isCheapBlock |
|
176 |
^ true |
|
177 |
! ! |
|
178 |
||
1181
6637fee79d7b
only Block & CheapBlock are fixed - subclasses may look different
Claus Gittinger <cg@exept.de>
parents:
920
diff
changeset
|
179 |
!CheapBlock class methodsFor:'documentation'! |
6637fee79d7b
only Block & CheapBlock are fixed - subclasses may look different
Claus Gittinger <cg@exept.de>
parents:
920
diff
changeset
|
180 |
|
6637fee79d7b
only Block & CheapBlock are fixed - subclasses may look different
Claus Gittinger <cg@exept.de>
parents:
920
diff
changeset
|
181 |
version |
19446 | 182 |
^ '$Header$' |
1181
6637fee79d7b
only Block & CheapBlock are fixed - subclasses may look different
Claus Gittinger <cg@exept.de>
parents:
920
diff
changeset
|
183 |
! ! |
16277 | 184 |