author | Claus Gittinger <cg@exept.de> |
Fri, 10 Jan 2020 12:43:49 +0100 | |
changeset 1226 | 175d39242154 |
parent 1201 | 045c36ec4fa4 |
permissions | -rw-r--r-- |
30 | 1 |
" |
2 |
COPYRIGHT (c) 1998 by eXept Software AG |
|
40 | 3 |
All Rights Reserved |
30 | 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 |
" |
|
38 | 12 |
"{ Package: 'stx:libjavascript' }" |
30 | 13 |
|
845
31abcd94bdff
class: JavaScriptFunctionNode
Claus Gittinger <cg@exept.de>
parents:
736
diff
changeset
|
14 |
"{ NameSpace: Smalltalk }" |
31abcd94bdff
class: JavaScriptFunctionNode
Claus Gittinger <cg@exept.de>
parents:
736
diff
changeset
|
15 |
|
0 | 16 |
ParseNode subclass:#JavaScriptFunctionNode |
240 | 17 |
instanceVariableNames:'functionName arguments locals statements environment |
1182 | 18 |
isReturnedFrom lineNr isAsync' |
0 | 19 |
classVariableNames:'' |
20 |
poolDictionaries:'' |
|
47 | 21 |
category:'Languages-JavaScript-Compiling & Parsing' |
0 | 22 |
! |
23 |
||
24 |
!JavaScriptFunctionNode class methodsFor:'documentation'! |
|
25 |
||
30 | 26 |
copyright |
27 |
" |
|
28 |
COPYRIGHT (c) 1998 by eXept Software AG |
|
40 | 29 |
All Rights Reserved |
0 | 30 |
|
30 | 31 |
This software is furnished under a license and may be used |
32 |
only in accordance with the terms of that license and with the |
|
33 |
inclusion of the above copyright notice. This software may not |
|
34 |
be provided or otherwise made available to, or used by, any |
|
35 |
other person. No title to or ownership of the software is |
|
36 |
hereby transferred. |
|
37 |
" |
|
67
058fd3dad518
js-plain vs. js-in-html handling
Claus Gittinger <cg@exept.de>
parents:
65
diff
changeset
|
38 |
! |
058fd3dad518
js-plain vs. js-in-html handling
Claus Gittinger <cg@exept.de>
parents:
65
diff
changeset
|
39 |
|
058fd3dad518
js-plain vs. js-in-html handling
Claus Gittinger <cg@exept.de>
parents:
65
diff
changeset
|
40 |
documentation |
058fd3dad518
js-plain vs. js-in-html handling
Claus Gittinger <cg@exept.de>
parents:
65
diff
changeset
|
41 |
" |
058fd3dad518
js-plain vs. js-in-html handling
Claus Gittinger <cg@exept.de>
parents:
65
diff
changeset
|
42 |
ATTENTION: for protocol compatibility with JavaScriptEnvironment. |
058fd3dad518
js-plain vs. js-in-html handling
Claus Gittinger <cg@exept.de>
parents:
65
diff
changeset
|
43 |
many messages are implemented with an initial underscore. |
058fd3dad518
js-plain vs. js-in-html handling
Claus Gittinger <cg@exept.de>
parents:
65
diff
changeset
|
44 |
These are required as JavaScriptEnvironment catches doesNotUnderstand and |
058fd3dad518
js-plain vs. js-in-html handling
Claus Gittinger <cg@exept.de>
parents:
65
diff
changeset
|
45 |
does some kludgy fiddling there. |
058fd3dad518
js-plain vs. js-in-html handling
Claus Gittinger <cg@exept.de>
parents:
65
diff
changeset
|
46 |
" |
0 | 47 |
! ! |
48 |
||
49 |
!JavaScriptFunctionNode methodsFor:'accessing'! |
|
50 |
||
38 | 51 |
_argVariables |
52 |
^ arguments |
|
53 |
! |
|
54 |
||
55 |
_argVariables:aDictionary |
|
56 |
arguments := aDictionary |
|
57 |
! |
|
58 |
||
59 |
_localVariables |
|
60 |
^ locals |
|
61 |
! |
|
62 |
||
63 |
_localVariables:aDictionary |
|
64 |
locals := aDictionary |
|
65 |
! |
|
66 |
||
19 | 67 |
_outerEnvironment |
68 |
^ environment |
|
69 |
||
70 |
"Created: / 17.5.1998 / 00:41:00 / cg" |
|
71 |
! |
|
72 |
||
73 |
_outerEnvironment:anEnvironment |
|
74 |
environment := anEnvironment |
|
75 |
||
76 |
"Created: / 17.5.1998 / 00:41:11 / cg" |
|
77 |
! |
|
78 |
||
62 | 79 |
_topEnvironment |
80 |
^ environment isNil ifTrue:self ifFalse:[environment _topEnvironment] |
|
81 |
! |
|
82 |
||
0 | 83 |
addLocalVariable:aVariable |
84 |
locals isNil ifTrue:[ |
|
40 | 85 |
locals := OrderedCollection new. |
0 | 86 |
]. |
87 |
locals add:aVariable |
|
88 |
||
89 |
"Created: / 14.5.1998 / 21:56:19 / cg" |
|
90 |
! |
|
91 |
||
1061 | 92 |
allVisibleVariables |
93 |
"return the variable-nodes for visible arguments and locals; |
|
94 |
this includes outer-scope variables" |
|
95 |
||
96 |
|outerVariables locals visibleArguments variablesInThisScope visibleOuterVariables| |
|
97 |
||
98 |
environment notNil ifTrue:[ |
|
99 |
outerVariables := environment allVisibleVariables |
|
100 |
] ifFalse:[ |
|
101 |
outerVariables := #() |
|
102 |
]. |
|
103 |
||
1226 | 104 |
locals := self localVariables ? #(). |
105 |
visibleArguments := (self arguments ? #()) reject:[:arg | locals contains:[:l | l name = arg name]]. |
|
1061 | 106 |
variablesInThisScope := locals , visibleArguments. |
1226 | 107 |
visibleOuterVariables := outerVariables reject:[:arg | variablesInThisScope contains:[:l | l name = arg name]]. |
1061 | 108 |
^ variablesInThisScope,visibleOuterVariables |
109 |
||
110 |
"Created: / 14-02-2019 / 11:12:18 / Claus Gittinger" |
|
111 |
! |
|
112 |
||
858 | 113 |
argumentCount |
1073 | 114 |
^ arguments size "/ argumentCount |
858 | 115 |
|
1073 | 116 |
"Created: / 17-05-1998 / 00:36:04 / cg" |
117 |
"Modified: / 08-03-2019 / 12:49:06 / Claus Gittinger" |
|
858 | 118 |
! |
119 |
||
0 | 120 |
arguments |
121 |
"return the value of the instance variable 'arguments' (automatically generated)" |
|
122 |
||
123 |
^ arguments |
|
124 |
||
125 |
"Created: / 14.5.1998 / 21:26:20 / cg" |
|
126 |
! |
|
127 |
||
128 |
arguments:something |
|
129 |
"set the value of the instance variable 'arguments' (automatically generated)" |
|
130 |
||
131 |
arguments := something. |
|
132 |
||
133 |
"Created: / 14.5.1998 / 21:26:20 / cg" |
|
134 |
! |
|
135 |
||
136 |
functionName |
|
137 |
"return the value of the instance variable 'functionName' (automatically generated)" |
|
138 |
||
139 |
^ functionName |
|
140 |
||
141 |
"Created: / 14.5.1998 / 21:26:18 / cg" |
|
142 |
! |
|
143 |
||
144 |
functionName:something |
|
145 |
"set the value of the instance variable 'functionName' (automatically generated)" |
|
146 |
||
147 |
functionName := something. |
|
148 |
||
149 |
"Created: / 14.5.1998 / 21:26:18 / cg" |
|
150 |
! |
|
151 |
||
1182 | 152 |
isAsync |
153 |
^ isAsync |
|
154 |
! |
|
155 |
||
156 |
isAsync:aBoolean |
|
157 |
isAsync := aBoolean. |
|
158 |
! |
|
159 |
||
238 | 160 |
isReturnedFrom |
161 |
^ isReturnedFrom |
|
162 |
! |
|
163 |
||
164 |
isReturnedFrom:something |
|
165 |
isReturnedFrom := something. |
|
166 |
! |
|
167 |
||
1053 | 168 |
lineNumber |
169 |
^ lineNr |
|
170 |
||
171 |
"Created: / 08-02-2019 / 11:18:45 / Claus Gittinger" |
|
172 |
! |
|
173 |
||
174 |
lineNumber:anInteger |
|
175 |
lineNr := anInteger. |
|
176 |
||
177 |
"Created: / 08-02-2019 / 11:18:48 / Claus Gittinger" |
|
178 |
! |
|
179 |
||
94 | 180 |
localVariableNames |
105 | 181 |
locals isNil ifTrue:[^ #() ]. |
1061 | 182 |
^ (locals asSortedCollection:[:a :b | a index < b index]) |
183 |
collect:[:v | v name]. |
|
184 |
||
185 |
"Modified (format): / 14-02-2019 / 11:12:33 / Claus Gittinger" |
|
94 | 186 |
! |
187 |
||
188 |
localVariables |
|
152 | 189 |
^ locals ? #() |
94 | 190 |
! |
191 |
||
19 | 192 |
numArgs |
193 |
^ arguments size |
|
194 |
||
195 |
"Created: / 17.5.1998 / 00:36:04 / cg" |
|
196 |
! |
|
197 |
||
594
43ffe08fd1bc
class: JavaScriptFunctionNode
Claus Gittinger <cg@exept.de>
parents:
477
diff
changeset
|
198 |
numVars |
913 | 199 |
"return the number of local variables." |
200 |
||
594
43ffe08fd1bc
class: JavaScriptFunctionNode
Claus Gittinger <cg@exept.de>
parents:
477
diff
changeset
|
201 |
^ locals size |
43ffe08fd1bc
class: JavaScriptFunctionNode
Claus Gittinger <cg@exept.de>
parents:
477
diff
changeset
|
202 |
! |
43ffe08fd1bc
class: JavaScriptFunctionNode
Claus Gittinger <cg@exept.de>
parents:
477
diff
changeset
|
203 |
|
0 | 204 |
statements |
205 |
"return the value of the instance variable 'statements' (automatically generated)" |
|
206 |
||
207 |
^ statements |
|
208 |
||
209 |
"Created: / 14.5.1998 / 21:26:22 / cg" |
|
210 |
! |
|
211 |
||
675
cfeedffda1dd
Support for source positions & parent node reference for JavaScript AST (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
653
diff
changeset
|
212 |
statements:aStatementNode |
0 | 213 |
"set the value of the instance variable 'statements' (automatically generated)" |
214 |
||
675
cfeedffda1dd
Support for source positions & parent node reference for JavaScript AST (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
653
diff
changeset
|
215 |
statements := aStatementNode. |
cfeedffda1dd
Support for source positions & parent node reference for JavaScript AST (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
653
diff
changeset
|
216 |
statements notNil ifTrue:[ |
cfeedffda1dd
Support for source positions & parent node reference for JavaScript AST (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
653
diff
changeset
|
217 |
statements parent: self. |
cfeedffda1dd
Support for source positions & parent node reference for JavaScript AST (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
653
diff
changeset
|
218 |
] |
0 | 219 |
|
675
cfeedffda1dd
Support for source positions & parent node reference for JavaScript AST (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
653
diff
changeset
|
220 |
"Created: / 14-05-1998 / 21:26:22 / cg" |
cfeedffda1dd
Support for source positions & parent node reference for JavaScript AST (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
653
diff
changeset
|
221 |
"Modified: / 20-09-2013 / 17:17:31 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
38 | 222 |
! |
223 |
||
736
f8fa644b528d
class: JavaScriptFunctionNode
Claus Gittinger <cg@exept.de>
parents:
732
diff
changeset
|
224 |
variableValue |
f8fa644b528d
class: JavaScriptFunctionNode
Claus Gittinger <cg@exept.de>
parents:
732
diff
changeset
|
225 |
"that is a bad kludge to fix the interpreter, which gets functionNodes as value" |
f8fa644b528d
class: JavaScriptFunctionNode
Claus Gittinger <cg@exept.de>
parents:
732
diff
changeset
|
226 |
|
f8fa644b528d
class: JavaScriptFunctionNode
Claus Gittinger <cg@exept.de>
parents:
732
diff
changeset
|
227 |
^ self |
f8fa644b528d
class: JavaScriptFunctionNode
Claus Gittinger <cg@exept.de>
parents:
732
diff
changeset
|
228 |
! |
f8fa644b528d
class: JavaScriptFunctionNode
Claus Gittinger <cg@exept.de>
parents:
732
diff
changeset
|
229 |
|
38 | 230 |
xxxx_variables |
231 |
|list| |
|
232 |
||
233 |
list := IdentityDictionary new. |
|
234 |
arguments notNil ifTrue:[ |
|
40 | 235 |
arguments do:[:arg | |
236 |
list at:arg name put:arg |
|
237 |
]. |
|
38 | 238 |
]. |
239 |
locals notNil ifTrue:[ |
|
40 | 240 |
locals do:[:var | |
241 |
list at:var name put:var |
|
242 |
]. |
|
38 | 243 |
]. |
244 |
^ list |
|
245 |
||
246 |
"Created: / 17.5.1998 / 00:38:15 / cg" |
|
247 |
"Modified: / 17.5.1998 / 00:40:18 / cg" |
|
0 | 248 |
! ! |
249 |
||
61 | 250 |
!JavaScriptFunctionNode methodsFor:'code generation'! |
251 |
||
252 |
codeVariableSetupOn:codeStream for:aCompiler |
|
253 |
locals isNil ifTrue:[^ self]. |
|
254 |
||
255 |
locals do:[:eachVar | |
|
256 |
"/ generate code to set it up. |
|
257 |
||
258 |
|varNode initExpression setupExpr| |
|
259 |
||
260 |
initExpression := eachVar expressionForSetup. |
|
261 |
initExpression notNil ifTrue:[ |
|
595 | 262 |
self isInnerFunction ifTrue:[ |
263 |
varNode := JavaScriptVariableNode |
|
264 |
type:#BlockVariable |
|
265 |
name:eachVar name |
|
266 |
token:eachVar |
|
267 |
index:eachVar index |
|
268 |
block:self |
|
269 |
from:self |
|
270 |
] ifFalse:[ |
|
271 |
varNode := JavaScriptVariableNode |
|
272 |
type:#MethodVariable |
|
273 |
name:eachVar name |
|
274 |
token:eachVar |
|
275 |
index:eachVar index. |
|
276 |
]. |
|
61 | 277 |
setupExpr := AssignmentNode variable:varNode expression:initExpression. |
595 | 278 |
setupExpr codeForSideEffectOn:codeStream inBlock:(self isInnerFunction ifTrue:[self] ifFalse:[nil]) for:aCompiler. |
61 | 279 |
] |
280 |
] |
|
202 | 281 |
|
282 |
"Modified: / 12-07-2006 / 15:07:00 / cg" |
|
61 | 283 |
! ! |
284 |
||
477 | 285 |
!JavaScriptFunctionNode methodsFor:'enumeration'! |
286 |
||
972 | 287 |
allSubNodesDo:aBlock |
288 |
"evaluate aBlock for each subnode" |
|
720 | 289 |
|
1099 | 290 |
statements notNil ifTrue:[ |
291 |
statements allNodesDo:aBlock |
|
292 |
]. |
|
293 |
||
294 |
"Modified: / 10-07-2019 / 02:32:21 / Claus Gittinger" |
|
720 | 295 |
! |
296 |
||
1114 | 297 |
childrenDo:aBlock |
298 |
"evaluate aBlock for each subnode" |
|
299 |
||
300 |
self statements:statements do:aBlock |
|
301 |
! |
|
302 |
||
642
540746b98a34
class: JavaScriptFunctionNode
Claus Gittinger <cg@exept.de>
parents:
595
diff
changeset
|
303 |
messageSelectorsDo:aBlock |
540746b98a34
class: JavaScriptFunctionNode
Claus Gittinger <cg@exept.de>
parents:
595
diff
changeset
|
304 |
"evaluate aBlock for each message-selector sent by this node and subnodes" |
540746b98a34
class: JavaScriptFunctionNode
Claus Gittinger <cg@exept.de>
parents:
595
diff
changeset
|
305 |
|
1201 | 306 |
statements notNil ifTrue:[ |
307 |
statements allMessageSelectorsDo:aBlock |
|
308 |
]. |
|
642
540746b98a34
class: JavaScriptFunctionNode
Claus Gittinger <cg@exept.de>
parents:
595
diff
changeset
|
309 |
|
540746b98a34
class: JavaScriptFunctionNode
Claus Gittinger <cg@exept.de>
parents:
595
diff
changeset
|
310 |
"Created: / 24-07-2010 / 21:42:25 / cg" |
540746b98a34
class: JavaScriptFunctionNode
Claus Gittinger <cg@exept.de>
parents:
595
diff
changeset
|
311 |
! |
540746b98a34
class: JavaScriptFunctionNode
Claus Gittinger <cg@exept.de>
parents:
595
diff
changeset
|
312 |
|
477 | 313 |
messagesDo:aBlock |
642
540746b98a34
class: JavaScriptFunctionNode
Claus Gittinger <cg@exept.de>
parents:
595
diff
changeset
|
314 |
"evaluate aBlock for each message-node sent by this node and subnodes" |
540746b98a34
class: JavaScriptFunctionNode
Claus Gittinger <cg@exept.de>
parents:
595
diff
changeset
|
315 |
|
964 | 316 |
statements notNil ifTrue:[ |
1201 | 317 |
statements allMessagesDo:aBlock |
964 | 318 |
]. |
477 | 319 |
|
320 |
"Created: / 24-07-2010 / 21:42:25 / cg" |
|
646
5f8020cedfc2
class: JavaScriptFunctionNode
Claus Gittinger <cg@exept.de>
parents:
642
diff
changeset
|
321 |
! |
5f8020cedfc2
class: JavaScriptFunctionNode
Claus Gittinger <cg@exept.de>
parents:
642
diff
changeset
|
322 |
|
1114 | 323 |
statementsDo:aBlock |
324 |
self statements:statements do:aBlock |
|
325 |
! |
|
326 |
||
646
5f8020cedfc2
class: JavaScriptFunctionNode
Claus Gittinger <cg@exept.de>
parents:
642
diff
changeset
|
327 |
variableNodesDo:aBlock |
1061 | 328 |
"evaluate aBlock for each variable-node in this node and subnodes; |
329 |
that is: all references to any variable inside the code" |
|
646
5f8020cedfc2
class: JavaScriptFunctionNode
Claus Gittinger <cg@exept.de>
parents:
642
diff
changeset
|
330 |
|
5f8020cedfc2
class: JavaScriptFunctionNode
Claus Gittinger <cg@exept.de>
parents:
642
diff
changeset
|
331 |
statements variableNodesDo:aBlock |
5f8020cedfc2
class: JavaScriptFunctionNode
Claus Gittinger <cg@exept.de>
parents:
642
diff
changeset
|
332 |
|
5f8020cedfc2
class: JavaScriptFunctionNode
Claus Gittinger <cg@exept.de>
parents:
642
diff
changeset
|
333 |
"Created: / 24-07-2010 / 21:42:25 / cg" |
1061 | 334 |
"Modified (comment): / 14-02-2019 / 11:09:34 / Claus Gittinger" |
477 | 335 |
! ! |
336 |
||
19 | 337 |
!JavaScriptFunctionNode methodsFor:'evaluation'! |
338 |
||
732
644dfb2cfdce
class: JavaScriptFunctionNode
Claus Gittinger <cg@exept.de>
parents:
720
diff
changeset
|
339 |
value |
644dfb2cfdce
class: JavaScriptFunctionNode
Claus Gittinger <cg@exept.de>
parents:
720
diff
changeset
|
340 |
^ self valueWithReceiver:nil arguments:#() |
644dfb2cfdce
class: JavaScriptFunctionNode
Claus Gittinger <cg@exept.de>
parents:
720
diff
changeset
|
341 |
! |
644dfb2cfdce
class: JavaScriptFunctionNode
Claus Gittinger <cg@exept.de>
parents:
720
diff
changeset
|
342 |
|
644dfb2cfdce
class: JavaScriptFunctionNode
Claus Gittinger <cg@exept.de>
parents:
720
diff
changeset
|
343 |
value:arg |
849
e6046ed9ce57
class: JavaScriptFunctionNode
Claus Gittinger <cg@exept.de>
parents:
845
diff
changeset
|
344 |
<context: #return> |
e6046ed9ce57
class: JavaScriptFunctionNode
Claus Gittinger <cg@exept.de>
parents:
845
diff
changeset
|
345 |
|
732
644dfb2cfdce
class: JavaScriptFunctionNode
Claus Gittinger <cg@exept.de>
parents:
720
diff
changeset
|
346 |
^ self valueWithReceiver:nil arguments:{ arg } |
644dfb2cfdce
class: JavaScriptFunctionNode
Claus Gittinger <cg@exept.de>
parents:
720
diff
changeset
|
347 |
! |
644dfb2cfdce
class: JavaScriptFunctionNode
Claus Gittinger <cg@exept.de>
parents:
720
diff
changeset
|
348 |
|
644dfb2cfdce
class: JavaScriptFunctionNode
Claus Gittinger <cg@exept.de>
parents:
720
diff
changeset
|
349 |
value:arg1 value:arg2 |
736
f8fa644b528d
class: JavaScriptFunctionNode
Claus Gittinger <cg@exept.de>
parents:
732
diff
changeset
|
350 |
^ self valueWithReceiver:environment "nil" arguments:{ arg1 . arg2 } |
732
644dfb2cfdce
class: JavaScriptFunctionNode
Claus Gittinger <cg@exept.de>
parents:
720
diff
changeset
|
351 |
! |
644dfb2cfdce
class: JavaScriptFunctionNode
Claus Gittinger <cg@exept.de>
parents:
720
diff
changeset
|
352 |
|
644dfb2cfdce
class: JavaScriptFunctionNode
Claus Gittinger <cg@exept.de>
parents:
720
diff
changeset
|
353 |
value:arg1 value:arg2 value:arg3 |
644dfb2cfdce
class: JavaScriptFunctionNode
Claus Gittinger <cg@exept.de>
parents:
720
diff
changeset
|
354 |
^ self valueWithReceiver:nil arguments:{ arg1 . arg2 . arg3 } |
644dfb2cfdce
class: JavaScriptFunctionNode
Claus Gittinger <cg@exept.de>
parents:
720
diff
changeset
|
355 |
! |
644dfb2cfdce
class: JavaScriptFunctionNode
Claus Gittinger <cg@exept.de>
parents:
720
diff
changeset
|
356 |
|
644dfb2cfdce
class: JavaScriptFunctionNode
Claus Gittinger <cg@exept.de>
parents:
720
diff
changeset
|
357 |
value:arg1 value:arg2 value:arg3 value:arg4 |
644dfb2cfdce
class: JavaScriptFunctionNode
Claus Gittinger <cg@exept.de>
parents:
720
diff
changeset
|
358 |
^ self valueWithReceiver:nil arguments:{ arg1 . arg2 . arg3 . arg4 } |
644dfb2cfdce
class: JavaScriptFunctionNode
Claus Gittinger <cg@exept.de>
parents:
720
diff
changeset
|
359 |
! |
644dfb2cfdce
class: JavaScriptFunctionNode
Claus Gittinger <cg@exept.de>
parents:
720
diff
changeset
|
360 |
|
644dfb2cfdce
class: JavaScriptFunctionNode
Claus Gittinger <cg@exept.de>
parents:
720
diff
changeset
|
361 |
value:arg1 value:arg2 value:arg3 value:arg4 value:arg5 |
644dfb2cfdce
class: JavaScriptFunctionNode
Claus Gittinger <cg@exept.de>
parents:
720
diff
changeset
|
362 |
^ self valueWithReceiver:nil arguments:{ arg1 . arg2 . arg3 . arg4 . arg5 } |
644dfb2cfdce
class: JavaScriptFunctionNode
Claus Gittinger <cg@exept.de>
parents:
720
diff
changeset
|
363 |
! |
644dfb2cfdce
class: JavaScriptFunctionNode
Claus Gittinger <cg@exept.de>
parents:
720
diff
changeset
|
364 |
|
644dfb2cfdce
class: JavaScriptFunctionNode
Claus Gittinger <cg@exept.de>
parents:
720
diff
changeset
|
365 |
value:arg1 value:arg2 value:arg3 value:arg4 value:arg5 value:arg6 |
644dfb2cfdce
class: JavaScriptFunctionNode
Claus Gittinger <cg@exept.de>
parents:
720
diff
changeset
|
366 |
^ self valueWithReceiver:nil arguments:{ arg1 . arg2 . arg3 . arg4 . arg5 . arg6 } |
644dfb2cfdce
class: JavaScriptFunctionNode
Claus Gittinger <cg@exept.de>
parents:
720
diff
changeset
|
367 |
! |
644dfb2cfdce
class: JavaScriptFunctionNode
Claus Gittinger <cg@exept.de>
parents:
720
diff
changeset
|
368 |
|
644dfb2cfdce
class: JavaScriptFunctionNode
Claus Gittinger <cg@exept.de>
parents:
720
diff
changeset
|
369 |
value:arg1 value:arg2 value:arg3 value:arg4 value:arg5 value:arg6 value:arg7 |
644dfb2cfdce
class: JavaScriptFunctionNode
Claus Gittinger <cg@exept.de>
parents:
720
diff
changeset
|
370 |
^ self valueWithReceiver:nil arguments:{ arg1 . arg2 . arg3 . arg4 . arg5 . arg6 . arg7 } |
644dfb2cfdce
class: JavaScriptFunctionNode
Claus Gittinger <cg@exept.de>
parents:
720
diff
changeset
|
371 |
! |
644dfb2cfdce
class: JavaScriptFunctionNode
Claus Gittinger <cg@exept.de>
parents:
720
diff
changeset
|
372 |
|
644dfb2cfdce
class: JavaScriptFunctionNode
Claus Gittinger <cg@exept.de>
parents:
720
diff
changeset
|
373 |
value:arg1 value:arg2 value:arg3 value:arg4 value:arg5 value:arg6 value:arg7 value:arg8 |
644dfb2cfdce
class: JavaScriptFunctionNode
Claus Gittinger <cg@exept.de>
parents:
720
diff
changeset
|
374 |
^ self valueWithReceiver:nil arguments:{ arg1 . arg2 . arg3 . arg4 . arg5 . arg6 . arg7 . arg8 } |
644dfb2cfdce
class: JavaScriptFunctionNode
Claus Gittinger <cg@exept.de>
parents:
720
diff
changeset
|
375 |
! |
644dfb2cfdce
class: JavaScriptFunctionNode
Claus Gittinger <cg@exept.de>
parents:
720
diff
changeset
|
376 |
|
644dfb2cfdce
class: JavaScriptFunctionNode
Claus Gittinger <cg@exept.de>
parents:
720
diff
changeset
|
377 |
valueWithArguments:args |
644dfb2cfdce
class: JavaScriptFunctionNode
Claus Gittinger <cg@exept.de>
parents:
720
diff
changeset
|
378 |
^ self valueWithReceiver:nil arguments:args |
644dfb2cfdce
class: JavaScriptFunctionNode
Claus Gittinger <cg@exept.de>
parents:
720
diff
changeset
|
379 |
! |
644dfb2cfdce
class: JavaScriptFunctionNode
Claus Gittinger <cg@exept.de>
parents:
720
diff
changeset
|
380 |
|
19 | 381 |
valueWithReceiver:rec arguments:args |
736
f8fa644b528d
class: JavaScriptFunctionNode
Claus Gittinger <cg@exept.de>
parents:
732
diff
changeset
|
382 |
|oldValues val this| |
19 | 383 |
|
384 |
(args size ~~ arguments size) ifTrue:[ |
|
67
058fd3dad518
js-plain vs. js-in-html handling
Claus Gittinger <cg@exept.de>
parents:
65
diff
changeset
|
385 |
^ self wrongNumberOfArguments:args size |
19 | 386 |
]. |
387 |
statements isNil ifTrue:[^ nil]. |
|
388 |
||
389 |
oldValues := Array new:(arguments size). |
|
390 |
1 to:arguments size do:[:i | |
|
67
058fd3dad518
js-plain vs. js-in-html handling
Claus Gittinger <cg@exept.de>
parents:
65
diff
changeset
|
391 |
oldValues at:i put:(arguments at:i) value. |
058fd3dad518
js-plain vs. js-in-html handling
Claus Gittinger <cg@exept.de>
parents:
65
diff
changeset
|
392 |
(arguments at:i) value:(args at:i). |
19 | 393 |
]. |
394 |
"/ exitBlock := [:v | |
|
395 |
"/ 1 to:argArray size do:[:i | |
|
396 |
"/ ( blockArgs at:i) value:(oldValues at:i) |
|
397 |
"/ ]. |
|
398 |
"/ ^ v |
|
399 |
"/ ]. |
|
400 |
||
1000 | 401 |
(rec isNil and:[environment notNil]) ifTrue:[ |
736
f8fa644b528d
class: JavaScriptFunctionNode
Claus Gittinger <cg@exept.de>
parents:
732
diff
changeset
|
402 |
"/ another hack |
845
31abcd94bdff
class: JavaScriptFunctionNode
Claus Gittinger <cg@exept.de>
parents:
736
diff
changeset
|
403 |
this := environment _theReceiver. |
736
f8fa644b528d
class: JavaScriptFunctionNode
Claus Gittinger <cg@exept.de>
parents:
732
diff
changeset
|
404 |
] ifFalse:[ |
f8fa644b528d
class: JavaScriptFunctionNode
Claus Gittinger <cg@exept.de>
parents:
732
diff
changeset
|
405 |
this := rec. |
f8fa644b528d
class: JavaScriptFunctionNode
Claus Gittinger <cg@exept.de>
parents:
732
diff
changeset
|
406 |
]. |
f8fa644b528d
class: JavaScriptFunctionNode
Claus Gittinger <cg@exept.de>
parents:
732
diff
changeset
|
407 |
val := statements evaluateAllIn:(Context new receiver:this). |
19 | 408 |
|
409 |
1 to:arguments size do:[:i | |
|
67
058fd3dad518
js-plain vs. js-in-html handling
Claus Gittinger <cg@exept.de>
parents:
65
diff
changeset
|
410 |
(arguments at:i) value:(oldValues at:i) |
19 | 411 |
]. |
412 |
^ val |
|
413 |
||
1000 | 414 |
"Modified: / 17-05-1998 / 00:53:45 / cg" |
415 |
"Modified: / 14-07-2018 / 09:34:41 / Claus Gittinger" |
|
736
f8fa644b528d
class: JavaScriptFunctionNode
Claus Gittinger <cg@exept.de>
parents:
732
diff
changeset
|
416 |
! |
f8fa644b528d
class: JavaScriptFunctionNode
Claus Gittinger <cg@exept.de>
parents:
732
diff
changeset
|
417 |
|
f8fa644b528d
class: JavaScriptFunctionNode
Claus Gittinger <cg@exept.de>
parents:
732
diff
changeset
|
418 |
wrongNumberOfArguments:numArgsGiven |
f8fa644b528d
class: JavaScriptFunctionNode
Claus Gittinger <cg@exept.de>
parents:
732
diff
changeset
|
419 |
"report that the number of arguments given does not match the number expected" |
f8fa644b528d
class: JavaScriptFunctionNode
Claus Gittinger <cg@exept.de>
parents:
732
diff
changeset
|
420 |
|
f8fa644b528d
class: JavaScriptFunctionNode
Claus Gittinger <cg@exept.de>
parents:
732
diff
changeset
|
421 |
WrongNumberOfArgumentsError |
f8fa644b528d
class: JavaScriptFunctionNode
Claus Gittinger <cg@exept.de>
parents:
732
diff
changeset
|
422 |
raiseRequestWith:self |
f8fa644b528d
class: JavaScriptFunctionNode
Claus Gittinger <cg@exept.de>
parents:
732
diff
changeset
|
423 |
errorString:('function got %1 arg(s) where %2 expected' |
f8fa644b528d
class: JavaScriptFunctionNode
Claus Gittinger <cg@exept.de>
parents:
732
diff
changeset
|
424 |
bindWith:numArgsGiven |
f8fa644b528d
class: JavaScriptFunctionNode
Claus Gittinger <cg@exept.de>
parents:
732
diff
changeset
|
425 |
with:arguments size) |
19 | 426 |
! ! |
427 |
||
0 | 428 |
!JavaScriptFunctionNode methodsFor:'printing'! |
429 |
||
430 |
printOn:aStream indent:i |
|
1109 | 431 |
|first| |
0 | 432 |
|
1182 | 433 |
(isAsync ? false) ifTrue:[ |
434 |
aStream nextPutAll:'async '. |
|
435 |
]. |
|
0 | 436 |
aStream nextPutAll:'function '. |
120
28795ec5ba9f
preps for anon functions (blocks)
Claus Gittinger <cg@exept.de>
parents:
105
diff
changeset
|
437 |
functionName notNil ifTrue:[ aStream nextPutAll:functionName ]. |
0 | 438 |
aStream nextPutAll:'('. |
439 |
||
440 |
first := true. |
|
195 | 441 |
arguments notNil ifTrue:[ |
442 |
arguments do:[:anArgVar | |
|
443 |
first ifFalse:[aStream nextPutAll:', ' ]. |
|
444 |
first := false. |
|
0 | 445 |
|
195 | 446 |
aStream nextPutAll:anArgVar name. |
447 |
]. |
|
0 | 448 |
]. |
449 |
aStream nextPutAll:')'. |
|
965 | 450 |
"/ aStream cr. |
451 |
aStream space. |
|
0 | 452 |
aStream nextPutAll:'{'. |
453 |
locals size > 0 ifTrue:[ |
|
120
28795ec5ba9f
preps for anon functions (blocks)
Claus Gittinger <cg@exept.de>
parents:
105
diff
changeset
|
454 |
locals do:[:v | |
28795ec5ba9f
preps for anon functions (blocks)
Claus Gittinger <cg@exept.de>
parents:
105
diff
changeset
|
455 |
aStream cr; spaces:i+4. |
28795ec5ba9f
preps for anon functions (blocks)
Claus Gittinger <cg@exept.de>
parents:
105
diff
changeset
|
456 |
aStream nextPutAll:'var '; nextPutAll:v name; nextPutAll:';'" ; cr" |
28795ec5ba9f
preps for anon functions (blocks)
Claus Gittinger <cg@exept.de>
parents:
105
diff
changeset
|
457 |
]. |
28795ec5ba9f
preps for anon functions (blocks)
Claus Gittinger <cg@exept.de>
parents:
105
diff
changeset
|
458 |
aStream cr. |
0 | 459 |
]. |
460 |
aStream cr; spaces:i+4. |
|
1109 | 461 |
statements notNil ifTrue:[ |
462 |
statements printStatementListOn:aStream indent:i+4. |
|
0 | 463 |
]. |
464 |
aStream cr; spaces:i; nextPutAll:'}'. |
|
465 |
||
466 |
"Created: / 14.5.1998 / 21:29:02 / cg" |
|
2 | 467 |
"Modified: / 15.5.1998 / 15:06:40 / cg" |
0 | 468 |
! ! |
469 |
||
38 | 470 |
!JavaScriptFunctionNode methodsFor:'queries'! |
471 |
||
67
058fd3dad518
js-plain vs. js-in-html handling
Claus Gittinger <cg@exept.de>
parents:
65
diff
changeset
|
472 |
_isFunctionEnvironment |
058fd3dad518
js-plain vs. js-in-html handling
Claus Gittinger <cg@exept.de>
parents:
65
diff
changeset
|
473 |
^ true |
058fd3dad518
js-plain vs. js-in-html handling
Claus Gittinger <cg@exept.de>
parents:
65
diff
changeset
|
474 |
! |
058fd3dad518
js-plain vs. js-in-html handling
Claus Gittinger <cg@exept.de>
parents:
65
diff
changeset
|
475 |
|
65 | 476 |
_isHTMLEnvironment |
477 |
^ false |
|
124 | 478 |
! |
479 |
||
595 | 480 |
home |
481 |
^ nil |
|
1053 | 482 |
! |
483 |
||
484 |
isFunctionNode |
|
485 |
^ true |
|
486 |
||
487 |
"Created: / 08-02-2019 / 10:53:49 / Claus Gittinger" |
|
977 | 488 |
! ! |
489 |
||
490 |
!JavaScriptFunctionNode methodsFor:'testing'! |
|
595 | 491 |
|
492 |
isInlineBlock |
|
493 |
^ false |
|
38 | 494 |
! ! |
495 |
||
653
c548a53fc974
Added JavaScriptParseNodeVisitor
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
646
diff
changeset
|
496 |
!JavaScriptFunctionNode methodsFor:'visiting'! |
c548a53fc974
Added JavaScriptParseNodeVisitor
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
646
diff
changeset
|
497 |
|
c548a53fc974
Added JavaScriptParseNodeVisitor
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
646
diff
changeset
|
498 |
acceptVisitor:visitor |
c548a53fc974
Added JavaScriptParseNodeVisitor
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
646
diff
changeset
|
499 |
"Double dispatch back to the visitor, passing my type encoded in |
c548a53fc974
Added JavaScriptParseNodeVisitor
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
646
diff
changeset
|
500 |
the selector (visitor pattern)" |
c548a53fc974
Added JavaScriptParseNodeVisitor
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
646
diff
changeset
|
501 |
|
c548a53fc974
Added JavaScriptParseNodeVisitor
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
646
diff
changeset
|
502 |
"stub code automatically generated - please change if required" |
c548a53fc974
Added JavaScriptParseNodeVisitor
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
646
diff
changeset
|
503 |
|
c548a53fc974
Added JavaScriptParseNodeVisitor
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
646
diff
changeset
|
504 |
^ visitor visitJavaScriptFunctionNode:self |
c548a53fc974
Added JavaScriptParseNodeVisitor
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
646
diff
changeset
|
505 |
! ! |
c548a53fc974
Added JavaScriptParseNodeVisitor
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
646
diff
changeset
|
506 |
|
0 | 507 |
!JavaScriptFunctionNode class methodsFor:'documentation'! |
508 |
||
509 |
version |
|
510 |
^ '$Header$' |
|
477 | 511 |
! |
512 |
||
513 |
version_CVS |
|
514 |
^ '$Header$' |
|
0 | 515 |
! ! |
594
43ffe08fd1bc
class: JavaScriptFunctionNode
Claus Gittinger <cg@exept.de>
parents:
477
diff
changeset
|
516 |