--- a/GroovyEvaluator.st Wed Aug 21 23:58:08 2013 +0200
+++ b/GroovyEvaluator.st Sat Aug 24 17:29:19 2013 +0100
@@ -22,7 +22,7 @@
Object subclass:#GroovyEvaluator
instanceVariableNames:'requestor source'
- classVariableNames:'WorkspaceBinding'
+ classVariableNames:'WorkspaceShell'
poolDictionaries:''
category:'Languages-Groovy-Compiler'
!
@@ -105,7 +105,7 @@
!
evaluate: sourceObj in: context receiver: receiver notifying: requestorObj logged: logged ifFail: fail
- | binding result wsForWorkspace |
+ | shell binding result wsForWorkspace |
JavaVM booted ifFalse: [
Java initialize.
@@ -115,15 +115,14 @@
requestor := requestorObj.
source := sourceObj.
wsForWorkspace := requestor notNil and: [ requestor application isKindOf: WorkspaceApplication ].
- binding := (JavaVM classForName: 'groovy.lang.Binding') new.
wsForWorkspace ifTrue: [
- WorkspaceBinding isNil ifTrue: [
- WorkspaceBinding := (JavaVM classForName: 'groovy.lang.Binding') new.
+ WorkspaceShell isNil ifTrue: [
+ WorkspaceShell := JAVA stx libjava groovy GroovyShell new.
].
- binding := WorkspaceBinding
+ shell:= WorkspaceShell.
] ifFalse: [
-
+ binding := (JavaVM classForName: 'groovy.lang.Binding') new.
binding setVariable: 'this' to: receiver.
binding setVariable: 'self' to: receiver.
context notNil ifTrue:[
@@ -136,28 +135,36 @@
binding setVariable: entry name to: (context at: entry slot + 1)
].
].
- ]
+ ].
+ shell := JAVA stx libjava groovy GroovyShell new: binding.
].
- result := self evaluate: source withBinding: binding.
+ result := self evaluate: source shell: shell.
^ result class javaUnwrap: result.
"Created: / 17-08-2011 / 08:54:23 / Jan Vrany <jan.vrany@fit.cvut.cz>"
- "Modified: / 07-05-2013 / 11:21:29 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 24-08-2013 / 17:18:24 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
-evaluate: source withBinding: binding
+moreSharedPools: pools
+
+ "Ignored for Java"
+
+ "Created: / 16-08-2011 / 10:15:18 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!GroovyEvaluator methodsFor:'compiler interface-private'!
+
+evaluate: src shell: shell
"Given a binding, evaluates given a code"
- | shell result |
+ | result |
[
- shell := (JavaVM classForName: 'groovy.lang.GroovyShell') newCleared.
- shell perform: #'<init>(Lgroovy/lang/Binding;)V' with: binding.
result := shell
perform: #'evaluate(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/Object;'
- with: (Java as_String: source string)
+ with: (Java as_String: src string)
with: (Java as_String: 'doIt')
] on: JAVA org codehaus groovy control CompilationFailedException do:[:ex|
self syntaxError: ex.
@@ -165,15 +172,7 @@
^ result class javaUnwrap: result.
- "Created: / 21-08-2012 / 14:08:06 / Jan Vrany <jan.vrany@fit.cvut.cz>"
- "Modified: / 07-05-2013 / 11:21:24 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-!
-
-moreSharedPools: pools
-
- "Ignored for Java"
-
- "Created: / 16-08-2011 / 10:15:18 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Created: / 24-08-2013 / 13:48:12 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!GroovyEvaluator methodsFor:'error reporting'!