GroovyEvaluator.st
changeset 3619 6f6aa63c36be
parent 3508 622620308fee
child 3621 b714b2f6973c
--- a/GroovyEvaluator.st	Mon Aug 08 00:59:14 2016 +0100
+++ b/GroovyEvaluator.st	Fri Sep 16 14:51:56 2016 +0100
@@ -147,58 +147,52 @@
     ].
     groovyBindingClass := JavaVM classForName: 'groovy.lang.Binding'.
 
-    (isForWorkspace or:[groovyBindingClass isNil]) ifTrue: [
-        "WorkspaceShell isNil"true ifTrue: [
-            WorkspaceShell := groovyShellClass new.
-        ].
-        shell:= WorkspaceShell.
+    shell := groovyShellClass new.
+
+    isForWorkspace ifTrue: [
         Workspace workspaceVariables keysAndValuesDo:[:name :binding |
             bindings at: name put: (Array with: binding with: binding).
         ]
-    ] ifFalse: [ 
-        internalContext := groovyBindingClass new.
-        internalContext setVariable: 'this' to: receiver.
-        internalContext setVariable: 'self' to: receiver.
+    ].
+    bindings at: 'this' put: (Array with: receiver with: [ :v | "ignored" ]).
+    bindings at: 'self' put: (bindings at: 'this').
+    receiver notNil ifTrue:[
+        | instvars |
 
-        receiver notNil ifTrue:[
-            | instvars |
-
-            instvars := receiver class allInstVarNames.
-            instvars withIndexDo:[:name :index|
-                "/ Skip _lockWord_ - should be hidden...
-                (name ~~ #_lockWord_) ifTrue:[
-                    bindings at: name put: (Array with: [ receiver instVarAt: index ] with: [ :v | receiver instVarAt: index put: v ])
-                ].
+        instvars := receiver class allInstVarNames.
+        instvars withIndexDo:[:name :index|
+            "/ Skip _lockWord_ - should be hidden...
+            (name ~~ #_lockWord_) ifTrue:[
+                bindings at: name put: (Array with: [ receiver instVarAt: index ] with: [ :v | receiver instVarAt: index put: v ])
             ].
         ].
+    ].
 
-        context notNil ifTrue:[
-            | pc |
+    context notNil ifTrue:[
+        | pc |
 
-            internalContext setVariable: 'thisContext' to: context.
-            pc := context pc.
-            context method localVariableTable do:[:entry|
-                (pc between: entry startPC and: entry endPC) ifTrue:[
-                    bindings at: entry name put: (Array with: [ context at: entry slot + 1 ] with: [ :v | context at: entry slot + 1 put: v])
-                ].
+        internalContext setVariable: 'thisContext' to: context.
+        pc := context pc.
+        context method localVariableTable do:[:entry|
+            (pc between: entry startPC and: entry endPC) ifTrue:[
+                bindings at: entry name put: (Array with: [ context at: entry slot + 1 ] with: [ :v | context at: entry slot + 1 put: v])
             ].
         ].
-        shell := groovyShellClass new: internalContext.
-        class := receiver class theNonMetaclass.
-        class isJavaClass ifTrue:[
-            "/ Import all classes used by the receriver's class.
-            class constantPool do:[:each|
-                (each isJavaRef and:[each isJavaClassRef]) ifTrue:[
-                    | className |
+    ].
 
-                    className := each javaClassName.
-                    className notNil ifTrue:[
-                        shell addClassImport: className "asDottedJavaClassName. <-- not necessay, already dotted"
-                    ]
+    class := receiver class theNonMetaclass.
+    class isJavaClass ifTrue:[
+        "/ Import all classes used by the receriver's class.
+        class constantPool do:[:each|
+            (each isJavaRef and:[each isJavaClassRef]) ifTrue:[
+                | className |
+
+                className := each javaClassName.
+                className notNil ifTrue:[
+                    shell addClassImport: className "asDottedJavaClassName. <-- not necessay, already dotted"
                 ]
             ]
         ]
-
     ].
 
     result := self evaluate: source shell: shell bindings: bindings.    
@@ -211,7 +205,7 @@
     ^result class javaUnwrap: result.
 
     "Created: / 17-08-2011 / 08:54:23 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 13-06-2014 / 08:23:04 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 16-09-2016 / 12:12:09 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 evaluate:src notifying: requestorObj