Navigation Menu

Skip to content

Commit

Permalink
Migrate ObjectSubject to ObjectMirror evaluate:with:.
Browse files Browse the repository at this point in the history
  • Loading branch information
rmacnak committed Apr 25, 2019
1 parent e295a71 commit 613be81
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 136 deletions.
54 changes: 12 additions & 42 deletions Inspecting.ns
Expand Up @@ -30,10 +30,8 @@ class Inspecting usingPlatform: platform ide: ide = (
private workspaceManager = ide theWorkspaceManager.
private finalizer = ide finalizer.

private Semaphore = platform squeak Semaphore.
private ToolSet = platform squeak ToolSet.
private PointerFinder = platform squeak PointerFinder.
private UnhandledError = platform squeak UnhandledError.

private primitives = platform squeak VMMirror new. (* BOGUS. Should express reverse objects with mirrors somehow. *)

Expand Down Expand Up @@ -772,46 +770,18 @@ public enclosingObjectName ^<String> = (
public evaluate: expression <String>
ifCompilerError: onCompilerError <[:String]>
ifError: onError <[:NewspeakDebugging ThreadSubject :Exception]> ^<ObjectMirror> = (
| compilerError failed sem result process |
failed:: false.
sem:: Semaphore new.
process::
[
[result:: objectMirror
evaluate: expression
with: workspaceManager workspaceScope
ifCompilerError: [:ex <Exception> |
compilerError:: ex.
sem signal.
process suspend]
ifError: [:ex <Exception> |
failed:: true.
result:: ex.
sem signal.
process suspend].
sem signal]
on: UnhandledError
do: [:ex |
failed ifTrue: [ex pass]. (* don't fire twice *)
failed:: true.
result:: ex exception.
sem signal.
process suspend].
] newProcess.
process
name: 'Evaluating ', expression asString;
resume.
sem wait.
process offList.
compilerError ifNotNil:
[^onCompilerError value: compilerError description].
failed ifFalse:
[^result].
(* position the process to continue in the signalerContext *)
process suspendedContext unwindTo: result signalerContext.
result signalerContext push: result.
process suspendedContext: result signalerContext.
^onError value: (finalizer subjectFor: result in: process) value: result
| scope thread exception process |

scope:: workspaceManager workspaceScope.
[thread:: objectMirror evaluate: expression with: scope]
on: Error
do: [:ex | ^onCompilerError value: ex description].

thread isFulfilled ifTrue: [^thread result].

exception:: thread result reflectee.
process:: thread process.
^onError value: (finalizer subjectFor: exception in: process) value: exception
)
public hasIndexedSlots ^<Boolean> = (
^classMirror reflectee isVariable
Expand Down
105 changes: 47 additions & 58 deletions MirrorsForSqueak.ns
Expand Up @@ -33,6 +33,8 @@ private Map = platform collections Map.
private List = platform collections List.
private IdentitySet = platform squeak IdentitySet.
private IdentityMap = platform squeak IdentityDictionary.
private UnhandledError = platform squeak UnhandledError.
private Semaphore = platform squeak Semaphore.

private Duct = platform ducts Duct.
private WeakStorage = platform ducts WeakStorage.
Expand Down Expand Up @@ -1213,19 +1215,8 @@ public = other <Object> ^<Boolean> = (
^other isKindOfObjectMirror
and: [vmmirror is: reflectee identicalTo: other reflectee]
)
public evaluate: expression <String> ^<ThreadMirror> = (
^self evaluate: expression with: Map new
)
public evaluate: expression <String>
ifCompilerError: compilationErrorHandler <[:Error]>
ifError: evalErrorHandler <[:Error]> ^<ObjectMirror> = (
^self evaluate: expression with: Map new ifCompilerError: compilationErrorHandler ifError: evalErrorHandler
)
public evaluate: expression <String> with: scope <Map[Symbol, ObjectMirror]> ^<ThreadMirror> = (
| rawScope cls mxn mtdMirror state result |
rawScope:: Map new.
scope keysAndValuesDo: [:key :value | rawScope at: key put: value reflectee].

private compileExpression: expression with: rawScope = (
| cls mxn mtdMirror state result |
cls:: vmmirror classOf: reflectee.
mxn:: MixinMirror reflecting: cls mixin.
mtdMirror:: compiler
Expand All @@ -1241,54 +1232,51 @@ public evaluate: expression <String> with: scope <Map[Symbol, ObjectMirror]> ^<T
at: #source put: expression;
at: #debugInfo put: mtdMirror debugInfo.

[result:: vmmirror
object: reflectee
executeMethod: mtdMirror compiledMethod
with: {nil. rawScope}
ifFail: [^Error signal: 'primitiveExecuteMethod failed'].
state:: #fulfilled]
on: Error
do: [:e | result:: e. state:: #broken].

^ThreadMirror
state: state
result: (ObjectMirror reflecting: result)
^mtdMirror compiledMethod
)
public evaluate: expression <String>
with: scope <Map[Symbol, ObjectMirror]>
ifCompilerError: compilationErrorHandler <[:Error]>
ifError: evalErrorHandler <[:Error]> ^<ObjectMirror> = (
(* Evaluate [expression] with the reflectee as the receiver. If [expression] cannot be compiled, activate [compilationErrorHandler] with the exception. If the evaluation of [expression] raises an error, activate [evalErrorHandler] with the error. Otherwise return an ObjectMirror on the result of [expression]. *)
| rawScope cls mxn mtdMirror result |
public evaluate: expression <String> ^<ThreadMirror> = (
^self evaluate: expression with: Map new
)
public evaluate: expression <String> with: scope <Map[Symbol, ObjectMirror]> ^<ThreadMirror> = (
| rawScope expressionMethod state result latch process |
rawScope:: Map new.
scope keysAndValuesDo: [:key :value | rawScope at: key put: value reflectee].
expressionMethod:: compileExpression: expression with: scope.

state:: #running.
latch:: Semaphore new.
process::
[[result:: vmmirror
object: reflectee
executeMethod: expressionMethod
with: {nil. rawScope}
ifFail: [^Error signal: 'primitiveExecuteMethod failed'].
state:: #fulfilled.
latch signal]
on: UnhandledError
do:
[:ex |
result:: ex exception.
state:: #broken.
latch signal.
process suspend].
] newProcess.

process
name: 'Evaluating ', expression asString;
resume.
latch wait.

state = #broken ifTrue:
[(* position the process to continue in the signalerContext *)
process suspendedContext unwindTo: result signalerContext.
result signalerContext push: result.
process suspendedContext: result signalerContext].

[cls:: vmmirror classOf: reflectee.
mxn:: MixinMirror reflecting: cls mixin.
mtdMirror:: compiler
compileExpressionSource: expression asString
debugMapper: nil
withScope: rawScope
inMixin: mxn.

mtdMirror category: #DoIts.
mtdMirror pragmas: {#isExpression -> true}.
mtdMirror methodMixin: cls mixin definingClass.
mtdMirror compiledMethod properties
at: #source put: expression;
at: #debugInfo put: mtdMirror debugInfo]
on: Error
do: [:e | ^compilationErrorHandler cull: e ].

[result:: vmmirror
object: reflectee
executeMethod: mtdMirror compiledMethod
with: {nil. rawScope}
ifFail: [ ^compilationErrorHandler cull: (Error description: 'primitiveExecuteMethod failed') ]]
on: Error
do: [:e | ^evalErrorHandler cull: e].

^ObjectMirror reflecting: result
^ThreadMirror
state: state
result: (ObjectMirror reflecting: result)
process: process
)
public getClass ^<ClassMirror> = (
^ClassMirror reflecting: (vmmirror classOf: reflectee)
Expand Down Expand Up @@ -1399,10 +1387,11 @@ public source = (
)
) : (
)
class ThreadMirror state: s result: r = (
class ThreadMirror state: s result: r process: p = (
|
protected state = s.
public result = r.
public process = p.
|
) (
public isBroken ^<Boolean> = (
Expand Down
11 changes: 7 additions & 4 deletions MirrorsForV8.ns
Expand Up @@ -757,7 +757,7 @@ class MutableNestedClassGroup group: ms within: mb = MutableMirrorGroup group: m
public class ObjectMirror reflecting: r = (|
public reflectee = r.
|) (
public evaluate: expression <String> ^<ThreadMirror> = (
private compileExpression: expression <String> ^<JS[Function]> = (
|
compiler
ir
Expand All @@ -766,8 +766,6 @@ public evaluate: expression <String> ^<ThreadMirror> = (
sb
src
func
state
result
|

compiler:: compilation Compiler new.
Expand All @@ -788,8 +786,13 @@ public evaluate: expression <String> ^<ThreadMirror> = (
writer generateSourceFor: ir function on: sb.
src:: sb asString.
src out.
func:: js call: (js ident: 'eval') with: {'(',src, ')'}.
^js call: (js ident: 'eval') with: {'(',src, ')'}
)
public evaluate: expression <String> ^<ThreadMirror> = (
| func state result |

func:: compileExpression: expression.

[result:: js call: (js propertyOf: func at: (js literal: 'call')) with: {reflectee}.
state:: #fulfilled]
on: Error do: [:e | result:: e. state:: #broken].
Expand Down
32 changes: 0 additions & 32 deletions ProcessFinalizer.ns
Expand Up @@ -30,12 +30,8 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *)
debuggerClass = debuggerClass_.

private WeakRegistry = p squeak WeakRegistry.
private Project = p squeak Project.
private Process = p squeak Process.
private Processor = p squeak Processor.
private UnhandledError = p squeak UnhandledError.
private SyntaxErrorNotification = p squeak SyntaxErrorNotification.
private Semaphore = p squeak Semaphore.
private platform = p.
debuggerRegistry = WeakRegistry new.
|) (
Expand Down Expand Up @@ -71,34 +67,6 @@ public debug: process context: context title: title = (
debuggerFor: thread <ThreadMirror> activation: activation <ActivationMirror> title: title <String> = (
^instanceOfDebuggerClass: debuggerClass for: thread activation: activation title: title
)
do: action <[]> name: description ifError: onError <[:Exception :Process]> = (
| sem process ex failed result |
sem:: Semaphore new.
failed:: false.
process::
[[result:: action value.
sem signal]
on: UnhandledError, SyntaxErrorNotification
do: [:exception |
failed ifTrue: [exception pass]. (* don't fire twice *)
ex:: (exception class name = #SyntaxErrorNotification)
ifTrue: [exception]
ifFalse: [exception exception].
failed:: true.
sem signal.
process suspend]] newProcess.
process
name: description;
resume.
sem wait.
failed ifFalse:
[^result].
(* position the process to continue in the signalerContext. *)
process suspendedContext unwindTo: ex signalerContext.
ex signalerContext push: result.
process suspendedContext: ex signalerContext.
^onError value: ex value: process
)
instanceOfDebuggerClass: klass for: thread <ThreadMirror> activation: activation <ActivationMirror> title: title <String> = (
| debugger |
debugger:: klass thread: thread activation: activation description: title.
Expand Down

0 comments on commit 613be81

Please sign in to comment.