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