author | hlopkmar |
Sat, 01 Dec 2012 22:06:11 +0000 | |
branch | development |
changeset 1851 | d74d5dc547f3 |
parent 1818 | 2e5ed72e7dfd |
child 1864 | 60a8dc26c8c6 |
permissions | -rw-r--r-- |
917 | 1 |
" |
2 |
COPYRIGHT (c) 1996-2011 by Claus Gittinger |
|
1152 | 3 |
|
1155 | 4 |
New code and modifications done at SWING Research Group [1]: |
1152 | 5 |
|
917 | 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 |
||
1155 | 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 |
|
1152 | 19 |
as of 1.9.2010 |
917 | 20 |
" |
21 |
"{ Package: 'stx:libjava' }" |
|
22 |
||
1370 | 23 |
Object subclass:#GroovyEvaluator |
1639 | 24 |
instanceVariableNames:'requestor source' |
1044
84b7d94d9eb8
Java Workspace now share same binding (i.e., workspace variables are remembered)
vranyj1
parents:
1033
diff
changeset
|
25 |
classVariableNames:'WorkspaceBinding' |
917 | 26 |
poolDictionaries:'' |
1656
c6fee8f3a640
- fixes for Groovy-Smalltalk interop - SmalltalkEvaluator example works
vranyj1
parents:
1649
diff
changeset
|
27 |
category:'Languages-Groovy-Compiler' |
917 | 28 |
! |
29 |
||
1370 | 30 |
!GroovyEvaluator class methodsFor:'documentation'! |
917 | 31 |
|
32 |
copyright |
|
33 |
" |
|
34 |
COPYRIGHT (c) 1996-2011 by Claus Gittinger |
|
1152 | 35 |
|
1155 | 36 |
New code and modifications done at SWING Research Group [1]: |
1152 | 37 |
|
917 | 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 |
||
1155 | 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 |
|
1152 | 51 |
as of 1.9.2010 |
917 | 52 |
|
53 |
" |
|
54 |
! ! |
|
55 |
||
1478 | 56 |
!GroovyEvaluator class methodsFor:'* As yet uncategorized *'! |
57 |
||
58 |
evaluate: source in: context receiver: receiver notifying: requestor logged: log ifFail: failblock |
|
59 |
^self new evaluate: source in: context receiver: receiver notifying: requestor logged: log ifFail: failblock |
|
60 |
||
61 |
"Created: / 13-04-2012 / 17:24:05 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
62 |
! ! |
|
63 |
||
1370 | 64 |
!GroovyEvaluator class methodsFor:'utilities'! |
1204 | 65 |
|
66 |
flushWorkspaceBinding |
|
67 |
||
68 |
WorkspaceBinding := nil |
|
69 |
||
70 |
"Created: / 02-12-2011 / 23:23:48 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
71 |
! ! |
|
72 |
||
1691 | 73 |
|
1581
70fbc03d2d82
Java reflection support refactoring - moved to use JavaMirrors
vranyj1
parents:
1478
diff
changeset
|
74 |
!GroovyEvaluator methodsFor:'accessing'! |
1459 | 75 |
|
1581
70fbc03d2d82
Java reflection support refactoring - moved to use JavaMirrors
vranyj1
parents:
1478
diff
changeset
|
76 |
currentNameSpace: ns |
1459 | 77 |
ns notNil ifTrue:[ |
78 |
self error:'Smalltalk namespaces not supported by Groovy' |
|
79 |
]. |
|
80 |
||
1581
70fbc03d2d82
Java reflection support refactoring - moved to use JavaMirrors
vranyj1
parents:
1478
diff
changeset
|
81 |
"Created: / 01-08-2012 / 11:18:05 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
70fbc03d2d82
Java reflection support refactoring - moved to use JavaMirrors
vranyj1
parents:
1478
diff
changeset
|
82 |
! |
70fbc03d2d82
Java reflection support refactoring - moved to use JavaMirrors
vranyj1
parents:
1478
diff
changeset
|
83 |
|
70fbc03d2d82
Java reflection support refactoring - moved to use JavaMirrors
vranyj1
parents:
1478
diff
changeset
|
84 |
currentNamespace: ns |
70fbc03d2d82
Java reflection support refactoring - moved to use JavaMirrors
vranyj1
parents:
1478
diff
changeset
|
85 |
self currentNameSpace: ns |
70fbc03d2d82
Java reflection support refactoring - moved to use JavaMirrors
vranyj1
parents:
1478
diff
changeset
|
86 |
|
1459 | 87 |
"Created: / 07-04-2012 / 09:26:39 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
88 |
! ! |
|
89 |
||
1370 | 90 |
!GroovyEvaluator methodsFor:'compiler interface'! |
917 | 91 |
|
1691 | 92 |
evaluate:src |
93 |
| result | |
|
971 | 94 |
|
1691 | 95 |
result := self evaluate:src in: nil receiver: nil notifying: nil logged: false ifFail: [self error:'Evaluation failed']. |
96 |
^result. |
|
971 | 97 |
|
98 |
"Created: / 02-09-2011 / 10:24:46 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
99 |
! |
|
100 |
||
1639 | 101 |
evaluate: sourceObj in: context receiver: receiver notifying: requestorObj logged: logged ifFail: fail |
102 |
| binding result wsForWorkspace | |
|
918 | 103 |
|
1033 | 104 |
JavaVM booted ifFalse: [ |
959 | 105 |
Java initialize. |
106 |
JavaVM initializeVM. |
|
107 |
]. |
|
1639 | 108 |
|
109 |
requestor := requestorObj. |
|
110 |
source := sourceObj. |
|
111 |
wsForWorkspace := requestor notNil and: [ requestor application isKindOf: WorkspaceApplication ]. |
|
112 |
binding := (Java classForName: 'groovy.lang.Binding') new. |
|
113 |
||
114 |
wsForWorkspace ifTrue: [ |
|
1044
84b7d94d9eb8
Java Workspace now share same binding (i.e., workspace variables are remembered)
vranyj1
parents:
1033
diff
changeset
|
115 |
WorkspaceBinding isNil ifTrue: [ |
84b7d94d9eb8
Java Workspace now share same binding (i.e., workspace variables are remembered)
vranyj1
parents:
1033
diff
changeset
|
116 |
WorkspaceBinding := (JavaVM classForName: 'groovy.lang.Binding') new. |
84b7d94d9eb8
Java Workspace now share same binding (i.e., workspace variables are remembered)
vranyj1
parents:
1033
diff
changeset
|
117 |
]. |
84b7d94d9eb8
Java Workspace now share same binding (i.e., workspace variables are remembered)
vranyj1
parents:
1033
diff
changeset
|
118 |
binding := WorkspaceBinding |
84b7d94d9eb8
Java Workspace now share same binding (i.e., workspace variables are remembered)
vranyj1
parents:
1033
diff
changeset
|
119 |
] ifFalse: [ |
1639 | 120 |
|
1612 | 121 |
binding setVariable: 'this' to: receiver. |
122 |
binding setVariable: 'self' to: receiver. |
|
123 |
context notNil ifTrue:[ |
|
1626 | 124 |
| pc | |
125 |
||
1612 | 126 |
binding setVariable: 'thisContext' to: context. |
1626 | 127 |
pc := context pc. |
128 |
context method localVariableTable do:[:entry| |
|
129 |
(pc between: entry startPC and: entry endPC) ifTrue:[ |
|
130 |
binding setVariable: entry name to: (context at: entry slot + 1) |
|
131 |
]. |
|
132 |
]. |
|
1612 | 133 |
] |
134 |
||
1044
84b7d94d9eb8
Java Workspace now share same binding (i.e., workspace variables are remembered)
vranyj1
parents:
1033
diff
changeset
|
135 |
]. |
84b7d94d9eb8
Java Workspace now share same binding (i.e., workspace variables are remembered)
vranyj1
parents:
1033
diff
changeset
|
136 |
|
1639 | 137 |
result := self evaluate: source withBinding: binding. |
138 |
^ result class javaUnwrap: result. |
|
918 | 139 |
|
140 |
"Created: / 17-08-2011 / 08:54:23 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
141 |
! |
|
142 |
||
1639 | 143 |
evaluate: source withBinding: binding |
144 |
"Given a binding, evaluates given a code" |
|
145 |
||
146 |
| shell result | |
|
147 |
||
148 |
[ |
|
149 |
shell := (Java classForName: 'groovy.lang.GroovyShell') newCleared. |
|
150 |
shell perform: #'<init>(Lgroovy/lang/Binding;)V' with: binding. |
|
151 |
result := shell |
|
152 |
perform: #'evaluate(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/Object;' |
|
153 |
with: (Java as_String: source string) |
|
154 |
with: (Java as_String: 'doIt') |
|
155 |
] on: JAVA org codehaus groovy control CompilationFailedException do:[:ex| |
|
156 |
self syntaxError: ex. |
|
157 |
]. |
|
158 |
||
159 |
^ result class javaUnwrap: result. |
|
160 |
||
161 |
"Created: / 21-08-2012 / 14:08:06 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
162 |
! |
|
163 |
||
917 | 164 |
moreSharedPools: pools |
165 |
||
166 |
"Ignored for Java" |
|
167 |
||
168 |
"Created: / 16-08-2011 / 10:15:18 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
169 |
! ! |
|
170 |
||
1639 | 171 |
!GroovyEvaluator methodsFor:'error reporting'! |
172 |
||
173 |
syntaxError: exception |
|
174 |
| error cause | |
|
1202
7d9f24940ed5
- JavaVM: fix in method/ctor invocation using reflection
vranyj1
parents:
1155
diff
changeset
|
175 |
|
1639 | 176 |
error := exception getErrorCollector getError: 0. |
177 |
cause := error getCause. |
|
178 |
self syntaxError: exception cause: cause. |
|
1202
7d9f24940ed5
- JavaVM: fix in method/ctor invocation using reflection
vranyj1
parents:
1155
diff
changeset
|
179 |
|
1639 | 180 |
"Created: / 21-08-2012 / 14:17:41 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
181 |
! |
|
1202
7d9f24940ed5
- JavaVM: fix in method/ctor invocation using reflection
vranyj1
parents:
1155
diff
changeset
|
182 |
|
1639 | 183 |
syntaxError:message cause: cause |
184 |
"Notify requestor of an error - if there is no requestor |
|
185 |
put it on the transcript. Requestor is typically the CodeView |
|
186 |
in which the accept/doIt was triggered, or the PositionableStream |
|
187 |
which does the fileIn. The requestor may decide how to highlight the |
|
188 |
error (and/or to abort the compile). |
|
189 |
Return the result passed back by the requestor." |
|
1202
7d9f24940ed5
- JavaVM: fix in method/ctor invocation using reflection
vranyj1
parents:
1155
diff
changeset
|
190 |
|
1639 | 191 |
| sourceStream startCol endCol | |
192 |
||
193 |
(Smalltalk isInitialized not and:[Smalltalk isStandAloneDebug]) ifTrue:[ |
|
194 |
"/ error during startup, but sometimes we expect an error and want to supress it |
|
1656
c6fee8f3a640
- fixes for Groovy-Smalltalk interop - SmalltalkEvaluator example works
vranyj1
parents:
1649
diff
changeset
|
195 |
(Smalltalk at:#Parser) parseWarningSignal query ~~ #ignore ifTrue:[ |
1639 | 196 |
thisContext fullPrintAll. |
197 |
]. |
|
198 |
]. |
|
199 |
||
200 |
||
201 |
"/ backward compatibility - will vanish eventually (use a handler, Luke) |
|
202 |
||
203 |
sourceStream := source string readStream. |
|
204 |
cause getLine - 1 timesRepeat:[ sourceStream nextLine ]. |
|
205 |
startCol := sourceStream position - 1 + cause getStartColumn. |
|
206 |
endCol := sourceStream position - 1 + cause getEndColumn. |
|
207 |
||
208 |
(requestor notNil and:[requestor isTextView]) ifTrue:[ |
|
209 |
requestor error: cause getOriginalMessage position: startCol to: endCol from: self. |
|
210 |
^ self |
|
211 |
]. |
|
1656
c6fee8f3a640
- fixes for Groovy-Smalltalk interop - SmalltalkEvaluator example works
vranyj1
parents:
1649
diff
changeset
|
212 |
(Smalltalk at:#'Parser::ParseError') isHandled ifTrue:[ |
c6fee8f3a640
- fixes for Groovy-Smalltalk interop - SmalltalkEvaluator example works
vranyj1
parents:
1649
diff
changeset
|
213 |
(Smalltalk at:#'Parser::ParseError') new |
1639 | 214 |
errorMessage: cause getOriginalMessage startPosition:startCol endPosition:endCol; |
215 |
parameter:self; |
|
216 |
lineNumber:cause getLine; |
|
217 |
raiseRequest. |
|
218 |
]. |
|
219 |
||
220 |
"Created: / 21-08-2012 / 17:10:11 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1202
7d9f24940ed5
- JavaVM: fix in method/ctor invocation using reflection
vranyj1
parents:
1155
diff
changeset
|
221 |
! ! |
7d9f24940ed5
- JavaVM: fix in method/ctor invocation using reflection
vranyj1
parents:
1155
diff
changeset
|
222 |
|
1370 | 223 |
!GroovyEvaluator class methodsFor:'documentation'! |
917 | 224 |
|
225 |
version_SVN |
|
226 |
^ '$Id$' |
|
227 |
! ! |
|
1691 | 228 |