author | vranyj1 |
Mon, 10 Dec 2012 19:00:37 +0000 | |
branch | development |
changeset 1864 | 60a8dc26c8c6 |
parent 1818 | 2e5ed72e7dfd |
child 2069 | 75d40b7b986f |
permissions | -rw-r--r-- |
1368 | 1 |
" |
2 |
COPYRIGHT (c) 1996-2011 by Claus Gittinger |
|
3 |
||
4 |
New code and modifications done at SWING Research Group [1]: |
|
5 |
||
6 |
COPYRIGHT (c) 2010-2011 by Jan Vrany, Jan Kurs and Marcel Hlopko |
|
7 |
SWING Research Group, Czech Technical University in Prague |
|
8 |
||
9 |
This software is furnished under a license and may be used |
|
10 |
only in accordance with the terms of that license and with the |
|
11 |
inclusion of the above copyright notice. This software may not |
|
12 |
be provided or otherwise made available to, or used by, any |
|
13 |
other person. No title to or ownership of the software is |
|
14 |
hereby transferred. |
|
15 |
||
16 |
[1] Code written at SWING Research Group contains a signature |
|
17 |
of one of the above copright owners. For exact set of such code, |
|
18 |
see the differences between this version and version stx:libjava |
|
19 |
as of 1.9.2010 |
|
20 |
" |
|
21 |
"{ Package: 'stx:libjava' }" |
|
22 |
||
23 |
Object subclass:#GroovyCompiler |
|
1387 | 24 |
instanceVariableNames:'requestor' |
1368 | 25 |
classVariableNames:'GroovyClassLoader' |
26 |
poolDictionaries:'' |
|
27 |
category:'Languages-Groovy-Compiler' |
|
28 |
! |
|
29 |
||
30 |
!GroovyCompiler class methodsFor:'documentation'! |
|
31 |
||
32 |
copyright |
|
33 |
" |
|
34 |
COPYRIGHT (c) 1996-2011 by Claus Gittinger |
|
35 |
||
36 |
New code and modifications done at SWING Research Group [1]: |
|
37 |
||
38 |
COPYRIGHT (c) 2010-2011 by Jan Vrany, Jan Kurs and Marcel Hlopko |
|
39 |
SWING Research Group, Czech Technical University in Prague |
|
40 |
||
41 |
This software is furnished under a license and may be used |
|
42 |
only in accordance with the terms of that license and with the |
|
43 |
inclusion of the above copyright notice. This software may not |
|
44 |
be provided or otherwise made available to, or used by, any |
|
45 |
other person. No title to or ownership of the software is |
|
46 |
hereby transferred. |
|
47 |
||
48 |
[1] Code written at SWING Research Group contains a signature |
|
49 |
of one of the above copright owners. For exact set of such code, |
|
50 |
see the differences between this version and version stx:libjava |
|
51 |
as of 1.9.2010 |
|
52 |
||
53 |
" |
|
54 |
! ! |
|
55 |
||
56 |
!GroovyCompiler class methodsFor:'initialization'! |
|
57 |
||
58 |
flushGroovyClassLoader |
|
59 |
||
60 |
GroovyClassLoader := nil |
|
61 |
||
62 |
"Created: / 18-02-2012 / 22:25:01 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
63 |
! ! |
|
64 |
||
65 |
!GroovyCompiler class methodsFor:'instance creation'! |
|
66 |
||
67 |
new |
|
68 |
"return an initialized instance" |
|
69 |
||
70 |
^ self basicNew initialize. |
|
71 |
! ! |
|
72 |
||
1453 | 73 |
!GroovyCompiler class methodsFor:'* As yet uncategorized *'! |
74 |
||
75 |
evaluate: source notifying: requestor compile: doCompile |
|
76 |
||
77 |
^self new |
|
78 |
requestor: requestor; |
|
79 |
compile: source |
|
80 |
||
81 |
"Created: / 04-04-2012 / 10:07:55 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
82 |
! ! |
|
83 |
||
1368 | 84 |
!GroovyCompiler class methodsFor:'compiler interface'! |
85 |
||
1388 | 86 |
compile: source |
87 |
"Compiles a new Groovy class given the source code" |
|
88 |
||
89 |
^self new compile: source. |
|
90 |
||
91 |
"Created: / 27-02-2012 / 23:27:54 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
92 |
! |
|
93 |
||
1372
dea574a1b6b3
Some initial class reloading support. Not yet finished, just sketched out.
vranyj1
parents:
1368
diff
changeset
|
94 |
compile: source forClass: class inCategory: category notifying: requestor install: doInstall |
dea574a1b6b3
Some initial class reloading support. Not yet finished, just sketched out.
vranyj1
parents:
1368
diff
changeset
|
95 |
|
dea574a1b6b3
Some initial class reloading support. Not yet finished, just sketched out.
vranyj1
parents:
1368
diff
changeset
|
96 |
"We allways compile whole class" |
dea574a1b6b3
Some initial class reloading support. Not yet finished, just sketched out.
vranyj1
parents:
1368
diff
changeset
|
97 |
|
1387 | 98 |
^self new |
99 |
requestor: requestor; |
|
1388 | 100 |
compile: source. |
1372
dea574a1b6b3
Some initial class reloading support. Not yet finished, just sketched out.
vranyj1
parents:
1368
diff
changeset
|
101 |
|
dea574a1b6b3
Some initial class reloading support. Not yet finished, just sketched out.
vranyj1
parents:
1368
diff
changeset
|
102 |
"Created: / 21-02-2012 / 11:10:57 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
1699
73003b9f58fc
- Support for extension methods finished (ready for testing)
vranyj1
parents:
1697
diff
changeset
|
103 |
! |
73003b9f58fc
- Support for extension methods finished (ready for testing)
vranyj1
parents:
1697
diff
changeset
|
104 |
|
73003b9f58fc
- Support for extension methods finished (ready for testing)
vranyj1
parents:
1697
diff
changeset
|
105 |
compile:aString forClass:aClass inCategory:cat notifying:requestor |
73003b9f58fc
- Support for extension methods finished (ready for testing)
vranyj1
parents:
1697
diff
changeset
|
106 |
install:install skipIfSame:skipIfSame silent:silent |
73003b9f58fc
- Support for extension methods finished (ready for testing)
vranyj1
parents:
1697
diff
changeset
|
107 |
|
73003b9f58fc
- Support for extension methods finished (ready for testing)
vranyj1
parents:
1697
diff
changeset
|
108 |
"HACK. |
73003b9f58fc
- Support for extension methods finished (ready for testing)
vranyj1
parents:
1697
diff
changeset
|
109 |
Problem: |
73003b9f58fc
- Support for extension methods finished (ready for testing)
vranyj1
parents:
1697
diff
changeset
|
110 |
SmalltalkChunkFileReader always uses class's compiler to compile source. |
73003b9f58fc
- Support for extension methods finished (ready for testing)
vranyj1
parents:
1697
diff
changeset
|
111 |
However, when filing in Smalltalk extensions to Java classes, a Smalltalk |
73003b9f58fc
- Support for extension methods finished (ready for testing)
vranyj1
parents:
1697
diff
changeset
|
112 |
code is passed to me. |
73003b9f58fc
- Support for extension methods finished (ready for testing)
vranyj1
parents:
1697
diff
changeset
|
113 |
|
73003b9f58fc
- Support for extension methods finished (ready for testing)
vranyj1
parents:
1697
diff
changeset
|
114 |
See ClassCategoryReader>>fileInFrom:notifying:passChunk:single:silent: |
73003b9f58fc
- Support for extension methods finished (ready for testing)
vranyj1
parents:
1697
diff
changeset
|
115 |
|
73003b9f58fc
- Support for extension methods finished (ready for testing)
vranyj1
parents:
1697
diff
changeset
|
116 |
Workaround: |
73003b9f58fc
- Support for extension methods finished (ready for testing)
vranyj1
parents:
1697
diff
changeset
|
117 |
Detect such a situation and compile using Smalltalk compiler...bad, I know. |
73003b9f58fc
- Support for extension methods finished (ready for testing)
vranyj1
parents:
1697
diff
changeset
|
118 |
Better to move logic from Stream>>fileIn into SmalltalkChunkSourceFileReader. |
73003b9f58fc
- Support for extension methods finished (ready for testing)
vranyj1
parents:
1697
diff
changeset
|
119 |
" |
73003b9f58fc
- Support for extension methods finished (ready for testing)
vranyj1
parents:
1697
diff
changeset
|
120 |
|
73003b9f58fc
- Support for extension methods finished (ready for testing)
vranyj1
parents:
1697
diff
changeset
|
121 |
(requestor isKindOf: SourceFileLoader) ifTrue:[ |
73003b9f58fc
- Support for extension methods finished (ready for testing)
vranyj1
parents:
1697
diff
changeset
|
122 |
^Compiler compile:aString forClass:aClass inCategory:cat notifying:requestor |
73003b9f58fc
- Support for extension methods finished (ready for testing)
vranyj1
parents:
1697
diff
changeset
|
123 |
install:install skipIfSame:skipIfSame silent:silent |
73003b9f58fc
- Support for extension methods finished (ready for testing)
vranyj1
parents:
1697
diff
changeset
|
124 |
]. |
73003b9f58fc
- Support for extension methods finished (ready for testing)
vranyj1
parents:
1697
diff
changeset
|
125 |
|
73003b9f58fc
- Support for extension methods finished (ready for testing)
vranyj1
parents:
1697
diff
changeset
|
126 |
self breakPoint:#jv. |
73003b9f58fc
- Support for extension methods finished (ready for testing)
vranyj1
parents:
1697
diff
changeset
|
127 |
self error: 'Not (yet) supported' |
73003b9f58fc
- Support for extension methods finished (ready for testing)
vranyj1
parents:
1697
diff
changeset
|
128 |
|
73003b9f58fc
- Support for extension methods finished (ready for testing)
vranyj1
parents:
1697
diff
changeset
|
129 |
"Created: / 07-09-2012 / 10:35:43 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
1368 | 130 |
! ! |
131 |
||
1387 | 132 |
!GroovyCompiler methodsFor:'accessing'! |
133 |
||
134 |
requestor |
|
135 |
^ requestor |
|
136 |
! |
|
137 |
||
138 |
requestor:something |
|
139 |
requestor := something. |
|
140 |
! ! |
|
141 |
||
1368 | 142 |
!GroovyCompiler methodsFor:'compiler interface'! |
143 |
||
1388 | 144 |
compile: source |
1368 | 145 |
"Compiles a new Groovy class given the source code" |
146 |
||
147 |
| jclass class | |
|
148 |
||
1387 | 149 |
[ |
1441 | 150 |
"Do no change it to 'GroovyClassLoader compile:' |
151 |
#compile: is already implemented so no interop will |
|
152 |
handle it, sigh" |
|
1387 | 153 |
jclass := GroovyClassLoader |
154 |
perform: #'parseClass(Ljava/lang/String;)Ljava/lang/Class;' |
|
155 |
with: (Java as_String: source). |
|
1441 | 156 |
] on: JAVA org codehaus groovy control CompilationFailedException do:[:cfe| |
157 |
self handleException: cfe. |
|
1387 | 158 |
]. |
1368 | 159 |
jclass isNil ifTrue:[ ^ nil ]. |
160 |
||
161 |
class := JavaVM classForJavaClassObject: jclass. |
|
162 |
class setSource: source. |
|
163 |
^class. |
|
164 |
||
1388 | 165 |
"Created: / 27-02-2012 / 23:27:35 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
1697
0a9d598a6408
- Initial support for fileouting Java extension methods
vranyj1
parents:
1656
diff
changeset
|
166 |
! |
0a9d598a6408
- Initial support for fileouting Java extension methods
vranyj1
parents:
1656
diff
changeset
|
167 |
|
0a9d598a6408
- Initial support for fileouting Java extension methods
vranyj1
parents:
1656
diff
changeset
|
168 |
compile:source in: class notifying: requestor ifFail: block |
0a9d598a6408
- Initial support for fileouting Java extension methods
vranyj1
parents:
1656
diff
changeset
|
169 |
|
0a9d598a6408
- Initial support for fileouting Java extension methods
vranyj1
parents:
1656
diff
changeset
|
170 |
requestor class == SourceFileLoader ifTrue:[ |
0a9d598a6408
- Initial support for fileouting Java extension methods
vranyj1
parents:
1656
diff
changeset
|
171 |
^Compiler compile:source in: class notifying: requestor ifFail: block |
0a9d598a6408
- Initial support for fileouting Java extension methods
vranyj1
parents:
1656
diff
changeset
|
172 |
]. |
0a9d598a6408
- Initial support for fileouting Java extension methods
vranyj1
parents:
1656
diff
changeset
|
173 |
|
0a9d598a6408
- Initial support for fileouting Java extension methods
vranyj1
parents:
1656
diff
changeset
|
174 |
self error:'Not yet supported'. |
0a9d598a6408
- Initial support for fileouting Java extension methods
vranyj1
parents:
1656
diff
changeset
|
175 |
|
0a9d598a6408
- Initial support for fileouting Java extension methods
vranyj1
parents:
1656
diff
changeset
|
176 |
"Created: / 04-09-2012 / 23:56:53 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
1368 | 177 |
! ! |
178 |
||
1387 | 179 |
!GroovyCompiler methodsFor:'error reporting'! |
180 |
||
181 |
error: message line: line from: start to: end |
|
182 |
"notify requestor of an error - if there is no requestor |
|
183 |
put it on the transcript. Requestor is typically the CodeView |
|
184 |
in which the accept/doIt was triggered, or the PositionableStream |
|
185 |
which does the fileIn. The requestor may decide how to highlight the |
|
186 |
error (and/or to abort the compile). |
|
187 |
Return the result passed back by the requestor." |
|
188 |
||
189 |
|err| |
|
190 |
||
191 |
Smalltalk isInitialized ifFalse:[ |
|
192 |
Smalltalk isStandAloneDebug ifTrue:[ |
|
193 |
"/ error during startup |
|
194 |
thisContext fullPrintAll. |
|
195 |
] |
|
196 |
]. |
|
197 |
||
198 |
||
199 |
"/ backward compatibility - will vanish eventually (use a handler, Luke) |
|
200 |
requestor notNil ifTrue:[ |
|
201 |
requestor error:message position:start to:end from:self. |
|
202 |
^ self |
|
203 |
]. |
|
1656
c6fee8f3a640
- fixes for Groovy-Smalltalk interop - SmalltalkEvaluator example works
vranyj1
parents:
1453
diff
changeset
|
204 |
(Smalltalk at:#'Parser::ParseError') isHandled ifTrue:[ |
c6fee8f3a640
- fixes for Groovy-Smalltalk interop - SmalltalkEvaluator example works
vranyj1
parents:
1453
diff
changeset
|
205 |
err := (Smalltalk at:#'Parser::ParseError') new. |
1387 | 206 |
err errorMessage: message startPosition: start endPosition: end. |
207 |
err parameter:self. |
|
208 |
err lineNumber:line. |
|
209 |
err raiseRequest. |
|
210 |
^ self |
|
211 |
]. |
|
212 |
||
213 |
"Created: / 27-02-2012 / 21:10:41 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
214 |
! |
|
215 |
||
1441 | 216 |
handleException: exception |
1387 | 217 |
|
218 |
| errors cause | |
|
219 |
"Arggghhh...that's Javas' clean OO design, sigh." |
|
1441 | 220 |
errors := exception getErrorCollector getErrors. |
1387 | 221 |
cause := errors getFirst getCause. |
222 |
self |
|
1441 | 223 |
error: exception getMessage |
1387 | 224 |
line: cause getLine |
225 |
from: cause getStartColumn |
|
226 |
to: cause getEndColumn. |
|
227 |
||
228 |
"Created: / 27-02-2012 / 21:09:46 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
229 |
! ! |
|
230 |
||
1368 | 231 |
!GroovyCompiler methodsFor:'initialization'! |
232 |
||
233 |
initialize |
|
234 |
||
235 |
self initializeGroovyClassLoader |
|
236 |
||
237 |
"Modified: / 18-02-2012 / 19:18:05 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
238 |
! |
|
239 |
||
240 |
initializeGroovyClassLoader |
|
241 |
| groovy_lang_GroovyClassLoader | |
|
242 |
||
243 |
GroovyClassLoader notNil ifTrue:[ ^ self ]. |
|
244 |
||
1385 | 245 |
JavaVM booted ifFalse:[ JavaVM boot ]. |
1372
dea574a1b6b3
Some initial class reloading support. Not yet finished, just sketched out.
vranyj1
parents:
1368
diff
changeset
|
246 |
groovy_lang_GroovyClassLoader := Java classForName:'stx.libjava.groovy.GroovyClassLoader'. |
1368 | 247 |
GroovyClassLoader := groovy_lang_GroovyClassLoader newCleared. |
248 |
GroovyClassLoader |
|
249 |
perform: #'<init>(Ljava/lang/ClassLoader;)V' |
|
250 |
with: JavaVM systemClassLoader. |
|
251 |
||
252 |
" |
|
253 |
GroovyClassLoader |
|
254 |
GroovyCompiler basicNew initializeGroovyClassLoader. |
|
255 |
GroovyClassLoader := nil. |
|
256 |
" |
|
257 |
||
258 |
"Created: / 18-02-2012 / 19:14:14 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
259 |
! ! |
|
260 |
||
261 |
!GroovyCompiler class methodsFor:'documentation'! |
|
262 |
||
1864 | 263 |
version_HG |
264 |
||
265 |
^ '$Changeset: <not expanded> $' |
|
266 |
! |
|
267 |
||
1368 | 268 |
version_SVN |
1864 | 269 |
^ '§Id§' |
1368 | 270 |
! ! |