author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Tue, 24 Sep 2013 23:18:24 +0200 | |
branch | initialV |
changeset 1180 | 01c6be61f29c |
parent 652 | e55b2faa8385 |
child 848 | 239f8d260f0e |
permissions | -rw-r--r-- |
155 | 1 |
" |
2 |
COPYRIGHT (c) 2005 by eXept Software AG |
|
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 |
" |
|
123 | 12 |
"{ Package: 'stx:libjavascript' }" |
13 |
||
14 |
JavaScriptFunctionNode subclass:#JavaScriptInnerFunctionNode |
|
133 | 15 |
instanceVariableNames:'indexOfFirstTemp' |
123 | 16 |
classVariableNames:'' |
17 |
poolDictionaries:'' |
|
18 |
category:'Languages-JavaScript-Compiling & Parsing' |
|
19 |
! |
|
20 |
||
155 | 21 |
!JavaScriptInnerFunctionNode class methodsFor:'documentation'! |
22 |
||
23 |
copyright |
|
24 |
" |
|
25 |
COPYRIGHT (c) 2005 by eXept Software AG |
|
26 |
All Rights Reserved |
|
27 |
||
28 |
This software is furnished under a license and may be used |
|
29 |
only in accordance with the terms of that license and with the |
|
30 |
inclusion of the above copyright notice. This software may not |
|
31 |
be provided or otherwise made available to, or used by, any |
|
32 |
other person. No title to or ownership of the software is |
|
33 |
hereby transferred. |
|
34 |
" |
|
35 |
! ! |
|
123 | 36 |
|
37 |
!JavaScriptInnerFunctionNode methodsFor:'accessing'! |
|
38 |
||
39 |
blockArgAccessed:aBoolean |
|
40 |
! |
|
41 |
||
133 | 42 |
home:anEnvironment |
43 |
environment := anEnvironment |
|
44 |
! |
|
45 |
||
46 |
indexOfFirstTemp |
|
596 | 47 |
indexOfFirstTemp isNil ifTrue:[ ^ self numVars ]. |
133 | 48 |
^ indexOfFirstTemp |
49 |
! |
|
50 |
||
51 |
indexOfFirstTemp:index |
|
52 |
indexOfFirstTemp := index |
|
123 | 53 |
! ! |
54 |
||
55 |
!JavaScriptInnerFunctionNode methodsFor:'code generation'! |
|
56 |
||
57 |
codeOn:aStream inBlock:b for:aCompiler |
|
131
bb82bf09b928
oops - return is a local return
Claus Gittinger <cg@exept.de>
parents:
123
diff
changeset
|
58 |
"this generates a block for the inner function; |
bb82bf09b928
oops - return is a local return
Claus Gittinger <cg@exept.de>
parents:
123
diff
changeset
|
59 |
Difference from block: |
bb82bf09b928
oops - return is a local return
Claus Gittinger <cg@exept.de>
parents:
123
diff
changeset
|
60 |
return is a local return; |
bb82bf09b928
oops - return is a local return
Claus Gittinger <cg@exept.de>
parents:
123
diff
changeset
|
61 |
if return is missing, retval is nil" |
123 | 62 |
|
63 |
|pos thisStatement nextStatement lastStatement code |
|
64 |
maxNumTemp| |
|
65 |
||
66 |
maxNumTemp := 10. |
|
67 |
||
637
bfb2c2642b7b
class: JavaScriptInnerFunctionNode
Stefan Vogel <sv@exept.de>
parents:
596
diff
changeset
|
68 |
pos := aStream position + 1. |
123 | 69 |
|
70 |
aStream nextPut:#makeBlock. "+0" |
|
71 |
aStream nextPut:0. "+1" |
|
596 | 72 |
aStream nextPut:(self numVars + maxNumTemp). "+2" |
123 | 73 |
aStream nextPut:(arguments size). "+3" |
74 |
||
596 | 75 |
self codeVariableSetupOn:aStream for:self. |
76 |
||
123 | 77 |
statements isEmptyOrNil ifTrue:[ |
78 |
aStream nextPut:#retNil. |
|
131
bb82bf09b928
oops - return is a local return
Claus Gittinger <cg@exept.de>
parents:
123
diff
changeset
|
79 |
] ifFalse:[ |
bb82bf09b928
oops - return is a local return
Claus Gittinger <cg@exept.de>
parents:
123
diff
changeset
|
80 |
lastStatement := nil. "+4" |
123 | 81 |
thisStatement := statements. |
82 |
[thisStatement notNil] whileTrue:[ |
|
83 |
nextStatement := thisStatement nextStatement. |
|
131
bb82bf09b928
oops - return is a local return
Claus Gittinger <cg@exept.de>
parents:
123
diff
changeset
|
84 |
thisStatement codeForSideEffectOn:aStream inBlock:self for:aCompiler. |
bb82bf09b928
oops - return is a local return
Claus Gittinger <cg@exept.de>
parents:
123
diff
changeset
|
85 |
lastStatement := thisStatement. |
123 | 86 |
thisStatement := nextStatement |
87 |
]. |
|
88 |
||
131
bb82bf09b928
oops - return is a local return
Claus Gittinger <cg@exept.de>
parents:
123
diff
changeset
|
89 |
lastStatement isReturnNode ifFalse:[ |
bb82bf09b928
oops - return is a local return
Claus Gittinger <cg@exept.de>
parents:
123
diff
changeset
|
90 |
aStream nextPut:#retNil. |
bb82bf09b928
oops - return is a local return
Claus Gittinger <cg@exept.de>
parents:
123
diff
changeset
|
91 |
]. |
bb82bf09b928
oops - return is a local return
Claus Gittinger <cg@exept.de>
parents:
123
diff
changeset
|
92 |
"/ |
bb82bf09b928
oops - return is a local return
Claus Gittinger <cg@exept.de>
parents:
123
diff
changeset
|
93 |
"/ lastStatement |
bb82bf09b928
oops - return is a local return
Claus Gittinger <cg@exept.de>
parents:
123
diff
changeset
|
94 |
"/ codeForSimpleReturnOn:aStream |
bb82bf09b928
oops - return is a local return
Claus Gittinger <cg@exept.de>
parents:
123
diff
changeset
|
95 |
"/ inBlock:self |
bb82bf09b928
oops - return is a local return
Claus Gittinger <cg@exept.de>
parents:
123
diff
changeset
|
96 |
"/ lineNumber:lastStatement lineNumber |
bb82bf09b928
oops - return is a local return
Claus Gittinger <cg@exept.de>
parents:
123
diff
changeset
|
97 |
"/ for:aCompiler. |
123 | 98 |
]. |
99 |
||
100 |
code := (aStream contents). |
|
101 |
"/ sigh - during coding, inlined subBlocks may have added more |
|
102 |
"/ tempVars; patch the nvar byte ... |
|
103 |
||
596 | 104 |
code at:pos+2 put:(self numVars + maxNumTemp). |
123 | 105 |
|
106 |
"set the end of the block's code" |
|
637
bfb2c2642b7b
class: JavaScriptInnerFunctionNode
Stefan Vogel <sv@exept.de>
parents:
596
diff
changeset
|
107 |
code at:pos+1 put:(aStream position + 1) |
133 | 108 |
! |
109 |
||
110 |
rememberOuterBlockVarAccess:aVariableNode |
|
111 |
"/ accessedOuterBlockVars isNil ifTrue:[ |
|
112 |
"/ accessedOuterBlockVars := OrderedCollection new. |
|
113 |
"/ ]. |
|
114 |
"/ accessedOuterBlockVars add:aVariableNode |
|
123 | 115 |
! ! |
116 |
||
465 | 117 |
!JavaScriptInnerFunctionNode methodsFor:'evaluation'! |
118 |
||
119 |
evaluateIn:anEnvironment |
|
120 |
^ self |
|
121 |
! ! |
|
122 |
||
123 | 123 |
!JavaScriptInnerFunctionNode methodsFor:'queries'! |
124 |
||
133 | 125 |
home |
126 |
^ environment |
|
127 |
! |
|
128 |
||
123 | 129 |
isInlineBlock |
130 |
^ false |
|
133 | 131 |
! |
132 |
||
596 | 133 |
isInnerFunction |
134 |
^ true |
|
135 |
! |
|
136 |
||
133 | 137 |
isJavaScriptBlock |
138 |
^ true |
|
123 | 139 |
! ! |
140 |
||
652
e55b2faa8385
Added JavaScriptParseNodeVisitor
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
637
diff
changeset
|
141 |
!JavaScriptInnerFunctionNode methodsFor:'visiting'! |
e55b2faa8385
Added JavaScriptParseNodeVisitor
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
637
diff
changeset
|
142 |
|
e55b2faa8385
Added JavaScriptParseNodeVisitor
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
637
diff
changeset
|
143 |
acceptVisitor:visitor |
e55b2faa8385
Added JavaScriptParseNodeVisitor
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
637
diff
changeset
|
144 |
"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
|
145 |
the selector (visitor pattern)" |
e55b2faa8385
Added JavaScriptParseNodeVisitor
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
637
diff
changeset
|
146 |
|
e55b2faa8385
Added JavaScriptParseNodeVisitor
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
637
diff
changeset
|
147 |
"stub code automatically generated - please change if required" |
e55b2faa8385
Added JavaScriptParseNodeVisitor
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
637
diff
changeset
|
148 |
|
e55b2faa8385
Added JavaScriptParseNodeVisitor
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
637
diff
changeset
|
149 |
^ visitor visitJavaScriptInnerFunctionNode:self |
e55b2faa8385
Added JavaScriptParseNodeVisitor
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
637
diff
changeset
|
150 |
! ! |
e55b2faa8385
Added JavaScriptParseNodeVisitor
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
637
diff
changeset
|
151 |
|
123 | 152 |
!JavaScriptInnerFunctionNode class methodsFor:'documentation'! |
153 |
||
154 |
version |
|
155 |
^ '$Header$' |
|
465 | 156 |
! |
157 |
||
158 |
version_CVS |
|
159 |
^ '$Header$' |
|
123 | 160 |
! ! |
596 | 161 |