author | Claus Gittinger <cg@exept.de> |
Fri, 21 Feb 2020 20:48:14 +0100 | |
changeset 1231 | b7d945ef967a |
parent 1063 | de2e048f6289 |
permissions | -rw-r--r-- |
1063 | 1 |
"{ Encoding: utf8 }" |
2 |
||
155 | 3 |
" |
4 |
COPYRIGHT (c) 2005 by eXept Software AG |
|
5 |
All Rights Reserved |
|
6 |
||
7 |
This software is furnished under a license and may be used |
|
8 |
only in accordance with the terms of that license and with the |
|
9 |
inclusion of the above copyright notice. This software may not |
|
10 |
be provided or otherwise made available to, or used by, any |
|
11 |
other person. No title to or ownership of the software is |
|
12 |
hereby transferred. |
|
13 |
" |
|
123 | 14 |
"{ Package: 'stx:libjavascript' }" |
15 |
||
848
239f8d260f0e
class: JavaScriptInnerFunctionNode
Claus Gittinger <cg@exept.de>
parents:
652
diff
changeset
|
16 |
"{ NameSpace: Smalltalk }" |
239f8d260f0e
class: JavaScriptInnerFunctionNode
Claus Gittinger <cg@exept.de>
parents:
652
diff
changeset
|
17 |
|
123 | 18 |
JavaScriptFunctionNode subclass:#JavaScriptInnerFunctionNode |
133 | 19 |
instanceVariableNames:'indexOfFirstTemp' |
123 | 20 |
classVariableNames:'' |
21 |
poolDictionaries:'' |
|
22 |
category:'Languages-JavaScript-Compiling & Parsing' |
|
23 |
! |
|
24 |
||
155 | 25 |
!JavaScriptInnerFunctionNode class methodsFor:'documentation'! |
26 |
||
27 |
copyright |
|
28 |
" |
|
29 |
COPYRIGHT (c) 2005 by eXept Software AG |
|
30 |
All Rights Reserved |
|
31 |
||
32 |
This software is furnished under a license and may be used |
|
33 |
only in accordance with the terms of that license and with the |
|
34 |
inclusion of the above copyright notice. This software may not |
|
35 |
be provided or otherwise made available to, or used by, any |
|
36 |
other person. No title to or ownership of the software is |
|
37 |
hereby transferred. |
|
38 |
" |
|
39 |
! ! |
|
123 | 40 |
|
41 |
!JavaScriptInnerFunctionNode methodsFor:'accessing'! |
|
42 |
||
43 |
blockArgAccessed:aBoolean |
|
1063 | 44 |
"set/clear the flag stating if any block (=function) argument is accessed in the function" |
45 |
||
46 |
"/ ignore here |
|
47 |
||
48 |
"Modified (comment): / 14-02-2019 / 11:08:06 / Claus Gittinger" |
|
123 | 49 |
! |
50 |
||
133 | 51 |
home:anEnvironment |
52 |
environment := anEnvironment |
|
53 |
! |
|
54 |
||
55 |
indexOfFirstTemp |
|
596 | 56 |
indexOfFirstTemp isNil ifTrue:[ ^ self numVars ]. |
133 | 57 |
^ indexOfFirstTemp |
58 |
! |
|
59 |
||
60 |
indexOfFirstTemp:index |
|
61 |
indexOfFirstTemp := index |
|
123 | 62 |
! ! |
63 |
||
64 |
!JavaScriptInnerFunctionNode methodsFor:'code generation'! |
|
65 |
||
66 |
codeOn:aStream inBlock:b for:aCompiler |
|
131
bb82bf09b928
oops - return is a local return
Claus Gittinger <cg@exept.de>
parents:
123
diff
changeset
|
67 |
"this generates a block for the inner function; |
bb82bf09b928
oops - return is a local return
Claus Gittinger <cg@exept.de>
parents:
123
diff
changeset
|
68 |
Difference from block: |
bb82bf09b928
oops - return is a local return
Claus Gittinger <cg@exept.de>
parents:
123
diff
changeset
|
69 |
return is a local return; |
bb82bf09b928
oops - return is a local return
Claus Gittinger <cg@exept.de>
parents:
123
diff
changeset
|
70 |
if return is missing, retval is nil" |
123 | 71 |
|
72 |
|pos thisStatement nextStatement lastStatement code |
|
73 |
maxNumTemp| |
|
74 |
||
75 |
maxNumTemp := 10. |
|
76 |
||
637
bfb2c2642b7b
class: JavaScriptInnerFunctionNode
Stefan Vogel <sv@exept.de>
parents:
596
diff
changeset
|
77 |
pos := aStream position + 1. |
123 | 78 |
|
79 |
aStream nextPut:#makeBlock. "+0" |
|
80 |
aStream nextPut:0. "+1" |
|
596 | 81 |
aStream nextPut:(self numVars + maxNumTemp). "+2" |
123 | 82 |
aStream nextPut:(arguments size). "+3" |
83 |
||
596 | 84 |
self codeVariableSetupOn:aStream for:self. |
85 |
||
123 | 86 |
statements isEmptyOrNil ifTrue:[ |
87 |
aStream nextPut:#retNil. |
|
131
bb82bf09b928
oops - return is a local return
Claus Gittinger <cg@exept.de>
parents:
123
diff
changeset
|
88 |
] ifFalse:[ |
bb82bf09b928
oops - return is a local return
Claus Gittinger <cg@exept.de>
parents:
123
diff
changeset
|
89 |
lastStatement := nil. "+4" |
123 | 90 |
thisStatement := statements. |
91 |
[thisStatement notNil] whileTrue:[ |
|
92 |
nextStatement := thisStatement nextStatement. |
|
131
bb82bf09b928
oops - return is a local return
Claus Gittinger <cg@exept.de>
parents:
123
diff
changeset
|
93 |
thisStatement codeForSideEffectOn:aStream inBlock:self for:aCompiler. |
bb82bf09b928
oops - return is a local return
Claus Gittinger <cg@exept.de>
parents:
123
diff
changeset
|
94 |
lastStatement := thisStatement. |
123 | 95 |
thisStatement := nextStatement |
96 |
]. |
|
97 |
||
131
bb82bf09b928
oops - return is a local return
Claus Gittinger <cg@exept.de>
parents:
123
diff
changeset
|
98 |
lastStatement isReturnNode ifFalse:[ |
bb82bf09b928
oops - return is a local return
Claus Gittinger <cg@exept.de>
parents:
123
diff
changeset
|
99 |
aStream nextPut:#retNil. |
bb82bf09b928
oops - return is a local return
Claus Gittinger <cg@exept.de>
parents:
123
diff
changeset
|
100 |
]. |
bb82bf09b928
oops - return is a local return
Claus Gittinger <cg@exept.de>
parents:
123
diff
changeset
|
101 |
"/ |
bb82bf09b928
oops - return is a local return
Claus Gittinger <cg@exept.de>
parents:
123
diff
changeset
|
102 |
"/ lastStatement |
bb82bf09b928
oops - return is a local return
Claus Gittinger <cg@exept.de>
parents:
123
diff
changeset
|
103 |
"/ codeForSimpleReturnOn:aStream |
bb82bf09b928
oops - return is a local return
Claus Gittinger <cg@exept.de>
parents:
123
diff
changeset
|
104 |
"/ inBlock:self |
bb82bf09b928
oops - return is a local return
Claus Gittinger <cg@exept.de>
parents:
123
diff
changeset
|
105 |
"/ lineNumber:lastStatement lineNumber |
bb82bf09b928
oops - return is a local return
Claus Gittinger <cg@exept.de>
parents:
123
diff
changeset
|
106 |
"/ for:aCompiler. |
123 | 107 |
]. |
108 |
||
109 |
code := (aStream contents). |
|
110 |
"/ sigh - during coding, inlined subBlocks may have added more |
|
111 |
"/ tempVars; patch the nvar byte ... |
|
112 |
||
596 | 113 |
code at:pos+2 put:(self numVars + maxNumTemp). |
123 | 114 |
|
115 |
"set the end of the block's code" |
|
637
bfb2c2642b7b
class: JavaScriptInnerFunctionNode
Stefan Vogel <sv@exept.de>
parents:
596
diff
changeset
|
116 |
code at:pos+1 put:(aStream position + 1) |
133 | 117 |
! |
118 |
||
119 |
rememberOuterBlockVarAccess:aVariableNode |
|
120 |
"/ accessedOuterBlockVars isNil ifTrue:[ |
|
121 |
"/ accessedOuterBlockVars := OrderedCollection new. |
|
122 |
"/ ]. |
|
123 |
"/ accessedOuterBlockVars add:aVariableNode |
|
123 | 124 |
! ! |
125 |
||
465 | 126 |
!JavaScriptInnerFunctionNode methodsFor:'evaluation'! |
127 |
||
855
08a0245d9f51
class: JavaScriptInnerFunctionNode
Claus Gittinger <cg@exept.de>
parents:
848
diff
changeset
|
128 |
_theReceiver |
08a0245d9f51
class: JavaScriptInnerFunctionNode
Claus Gittinger <cg@exept.de>
parents:
848
diff
changeset
|
129 |
^ nil |
08a0245d9f51
class: JavaScriptInnerFunctionNode
Claus Gittinger <cg@exept.de>
parents:
848
diff
changeset
|
130 |
! |
08a0245d9f51
class: JavaScriptInnerFunctionNode
Claus Gittinger <cg@exept.de>
parents:
848
diff
changeset
|
131 |
|
465 | 132 |
evaluateIn:anEnvironment |
133 |
^ self |
|
848
239f8d260f0e
class: JavaScriptInnerFunctionNode
Claus Gittinger <cg@exept.de>
parents:
652
diff
changeset
|
134 |
! |
239f8d260f0e
class: JavaScriptInnerFunctionNode
Claus Gittinger <cg@exept.de>
parents:
652
diff
changeset
|
135 |
|
239f8d260f0e
class: JavaScriptInnerFunctionNode
Claus Gittinger <cg@exept.de>
parents:
652
diff
changeset
|
136 |
exitWith:something |
239f8d260f0e
class: JavaScriptInnerFunctionNode
Claus Gittinger <cg@exept.de>
parents:
652
diff
changeset
|
137 |
"return via return-statement" |
239f8d260f0e
class: JavaScriptInnerFunctionNode
Claus Gittinger <cg@exept.de>
parents:
652
diff
changeset
|
138 |
|
239f8d260f0e
class: JavaScriptInnerFunctionNode
Claus Gittinger <cg@exept.de>
parents:
652
diff
changeset
|
139 |
|con| |
239f8d260f0e
class: JavaScriptInnerFunctionNode
Claus Gittinger <cg@exept.de>
parents:
652
diff
changeset
|
140 |
|
239f8d260f0e
class: JavaScriptInnerFunctionNode
Claus Gittinger <cg@exept.de>
parents:
652
diff
changeset
|
141 |
"/ here, I am in the tree interpreter; |
239f8d260f0e
class: JavaScriptInnerFunctionNode
Claus Gittinger <cg@exept.de>
parents:
652
diff
changeset
|
142 |
"/ so just walk along the sender chain to find the evaluateAllIn: |
239f8d260f0e
class: JavaScriptInnerFunctionNode
Claus Gittinger <cg@exept.de>
parents:
652
diff
changeset
|
143 |
con := thisContext sender. |
239f8d260f0e
class: JavaScriptInnerFunctionNode
Claus Gittinger <cg@exept.de>
parents:
652
diff
changeset
|
144 |
[ con notNil ] whileTrue:[ |
239f8d260f0e
class: JavaScriptInnerFunctionNode
Claus Gittinger <cg@exept.de>
parents:
652
diff
changeset
|
145 |
((con selector == #value:) and:[ con receiver == self ]) ifTrue:[ |
239f8d260f0e
class: JavaScriptInnerFunctionNode
Claus Gittinger <cg@exept.de>
parents:
652
diff
changeset
|
146 |
con return:something. |
239f8d260f0e
class: JavaScriptInnerFunctionNode
Claus Gittinger <cg@exept.de>
parents:
652
diff
changeset
|
147 |
]. |
239f8d260f0e
class: JavaScriptInnerFunctionNode
Claus Gittinger <cg@exept.de>
parents:
652
diff
changeset
|
148 |
con := con sender. |
239f8d260f0e
class: JavaScriptInnerFunctionNode
Claus Gittinger <cg@exept.de>
parents:
652
diff
changeset
|
149 |
]. |
239f8d260f0e
class: JavaScriptInnerFunctionNode
Claus Gittinger <cg@exept.de>
parents:
652
diff
changeset
|
150 |
|
1001 | 151 |
"/ self halt. |
848
239f8d260f0e
class: JavaScriptInnerFunctionNode
Claus Gittinger <cg@exept.de>
parents:
652
diff
changeset
|
152 |
"/ home notNil ifTrue:[ |
239f8d260f0e
class: JavaScriptInnerFunctionNode
Claus Gittinger <cg@exept.de>
parents:
652
diff
changeset
|
153 |
"/ home exitWith:something |
239f8d260f0e
class: JavaScriptInnerFunctionNode
Claus Gittinger <cg@exept.de>
parents:
652
diff
changeset
|
154 |
"/ ]. |
239f8d260f0e
class: JavaScriptInnerFunctionNode
Claus Gittinger <cg@exept.de>
parents:
652
diff
changeset
|
155 |
^ something |
1001 | 156 |
|
157 |
"Modified: / 14-07-2018 / 09:35:10 / Claus Gittinger" |
|
465 | 158 |
! ! |
159 |
||
123 | 160 |
!JavaScriptInnerFunctionNode methodsFor:'queries'! |
161 |
||
133 | 162 |
home |
163 |
^ environment |
|
976 | 164 |
! ! |
165 |
||
166 |
!JavaScriptInnerFunctionNode methodsFor:'testing'! |
|
133 | 167 |
|
123 | 168 |
isInlineBlock |
169 |
^ false |
|
133 | 170 |
! |
171 |
||
596 | 172 |
isInnerFunction |
173 |
^ true |
|
174 |
! |
|
175 |
||
133 | 176 |
isJavaScriptBlock |
177 |
^ true |
|
123 | 178 |
! ! |
179 |
||
652
e55b2faa8385
Added JavaScriptParseNodeVisitor
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
637
diff
changeset
|
180 |
!JavaScriptInnerFunctionNode methodsFor:'visiting'! |
e55b2faa8385
Added JavaScriptParseNodeVisitor
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
637
diff
changeset
|
181 |
|
e55b2faa8385
Added JavaScriptParseNodeVisitor
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
637
diff
changeset
|
182 |
acceptVisitor:visitor |
e55b2faa8385
Added JavaScriptParseNodeVisitor
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
637
diff
changeset
|
183 |
"Double dispatch back to the visitor, passing my type encoded in |
e55b2faa8385
Added JavaScriptParseNodeVisitor
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
637
diff
changeset
|
184 |
the selector (visitor pattern)" |
e55b2faa8385
Added JavaScriptParseNodeVisitor
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
637
diff
changeset
|
185 |
|
e55b2faa8385
Added JavaScriptParseNodeVisitor
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
637
diff
changeset
|
186 |
"stub code automatically generated - please change if required" |
e55b2faa8385
Added JavaScriptParseNodeVisitor
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
637
diff
changeset
|
187 |
|
e55b2faa8385
Added JavaScriptParseNodeVisitor
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
637
diff
changeset
|
188 |
^ visitor visitJavaScriptInnerFunctionNode:self |
e55b2faa8385
Added JavaScriptParseNodeVisitor
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
637
diff
changeset
|
189 |
! ! |
e55b2faa8385
Added JavaScriptParseNodeVisitor
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
637
diff
changeset
|
190 |
|
123 | 191 |
!JavaScriptInnerFunctionNode class methodsFor:'documentation'! |
192 |
||
193 |
version |
|
194 |
^ '$Header$' |
|
465 | 195 |
! |
196 |
||
197 |
version_CVS |
|
198 |
^ '$Header$' |
|
123 | 199 |
! ! |
596 | 200 |