Skip to content

Commit

Permalink
Add test for DebugMapper's indirect cases.
Browse files Browse the repository at this point in the history
  • Loading branch information
rmacnak committed May 18, 2024
1 parent 0e361da commit 06e8067
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 15 deletions.
20 changes: 20 additions & 0 deletions newspeak/ActivationMirrorTesting.ns
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,26 @@ public testActivationEvaluateEnclosingLocals = (
assert: eval result reflectee equals: 4.
assert: x equals: 4.
)
public testActivationEvaluateEnclosingLocals2 = (
| x closure thread activation eval |
x:: 0. (* Captured, but only in an enclosing closure *)
closure:: [x:: 3. [nil]] value.
thread:: ActivationMirror invokeSuspended: closure.

activation:: thread suspendedActivation.
assert: activation receiver equals: (ObjectMirror reflecting: self).
assert: activation closure equals: (ObjectMirror reflecting: closure).
assert: activation method name equals: #testActivationEvaluateEnclosingLocals2.

eval:: activation evaluate: 'x'.
assert: eval isFulfilled.
assert: eval result reflectee equals: 3.

eval:: activation evaluate: 'x: 4'.
assert: eval isFulfilled.
assert: eval result reflectee equals: 4.
assert: x equals: 4.
)
public testActivationEvaluateWithScope = (
| closure thread activation scope eval |
closure:: [add: 3 to: 4].
Expand Down
11 changes: 5 additions & 6 deletions newspeak/KernelForPrimordialSoup.ns
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ public closure: value = (
(* :pragma: primitive: 173 *)
panic.
)
public enclosingActivation ^<Activation> = (
| c = closure. |
nil = c ifTrue: [^nil].
^definingActivationOf: c
)
(* Return the next unwind marked above the receiver, returning nil if there is none. Search proceeds up to but not including aContext. *)
public findNextUnwindContextUpTo: activation = (
| ctx |
Expand Down Expand Up @@ -91,12 +96,6 @@ public method: value = (
private nonBooleanReceiver: nonBoolean = (
^(NonBooleanReceiver receiver: nonBoolean) signal
)
(* Squeak compatibility for DebugMapper. *)
public outerContext ^<Activation> = (
| c = closure. |
nil = c ifTrue: [^nil].
^definingActivationOf: c
)
public pop = (
|
depth = self size.
Expand Down
2 changes: 1 addition & 1 deletion newspeak/Mirrors.ns
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ private computeDebugMapper = (
^computeDebugInfo mapperForContext: reflectee
)
public enclosingActivation ^<ActivationMirror> = (
| rawEnclosing = reflectee outerContext. |
| rawEnclosing = reflectee enclosingActivation. |
nil = rawEnclosing ifTrue: [^nil].
^ActivationMirror reflecting: rawEnclosing thread: thread
)
Expand Down
14 changes: 7 additions & 7 deletions newspeak/Newspeak2PrimordialSoupCompilation.ns
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ public mapperForContext: ctxt = (
) : (
)
class DebugMapper forContext: ctxt usingDebugInfo: dbgInfo = (|
context <MethodContext> = ctxt.
context <Activation> = ctxt.
debugInfo <DebugInfo> = dbgInfo.
myDepth <Integer> = self depthOfContext: ctxt.
|) (
Expand All @@ -613,29 +613,29 @@ astForContextAtDepth: targetDepth <Integer> ^<AST> = (
returnContext:: (UnresolvedSendAST new
receiver: returnContext;
message: (MessageAST new
selector: #outerContext;
selector: #enclosingActivation;
arguments: {}))].
^returnContext
)
bci = (
^context bci
)
contextAtDepth: targetDepth <Integer> ^<MethodContext> = (
contextAtDepth: targetDepth <Integer> ^<Activation> = (
|
returnContext
|
myDepth >= targetDepth ifFalse: [deny].
returnContext: context.
(myDepth - targetDepth)
timesRepeat: [returnContext: returnContext outerContext].
timesRepeat: [returnContext: returnContext enclosingActivation].
^returnContext
)
depthOfContext: ctxt <MethodContext> ^<Integer> = (
depthOfContext: ctxt <Activation> ^<Integer> = (
^ctxt closure isNil
ifTrue: [0 (* method *)]
ifFalse: [1 + (depthOfContext: ctxt outerContext)]
ifFalse: [1 + (depthOfContext: ctxt enclosingActivation)]
)
public getValueOf: varName <Symbol> ^<Object> = (
| info ctxt vector |
Expand Down Expand Up @@ -2079,7 +2079,7 @@ public compileClassSource: src <String> within: enclosingIR <IntermediateMixin>

^intermediate
)
public compileExpressionSource: src <String> debugMapper: debugMapper <MethodContext> withScope: withScope <Map> inMixin: enclosing <MixinMirror> ^<IntermediateMethod> = (
public compileExpressionSource: src <String> debugMapper: debugMapper <DebugMapper> withScope: withScope <Map> inMixin: enclosing <MixinMirror> ^<IntermediateMethod> = (
(* Compile a DoIt method. If aContext is not nil, compile a DoItIn:ctxt method where accesses to names in scope of the context are rewritten to access through the context. Cog closures complicate this rewriting compared to BlockContexts, as access might be rather indirect. Also, in cases where a temp is only a copied value and not in a remote indirection vector, it would be impractical to handle writes such that they actually track down all places where the temp lives and update them. In these cases, we should merely find the most local copy, which I believe is what closure compiled Squeak does. *)
|
body <CodeBodyAST>
Expand Down
2 changes: 1 addition & 1 deletion newspeak/NewspeakCompilation.ns
Original file line number Diff line number Diff line change
Expand Up @@ -989,7 +989,7 @@ public compileClassHeader: source <String> within: enclosingIR <IntermediateMixi
public compileClassSource: src <String> within: enclosingIR <IntermediateMixin> ^<IntermediateClassDeclaration> = (
subclassResponsibility
)
public compileExpressionSource: src <String> debugMapper: debugMapper <MethodContext> withScope: withScope <Map> inMixin: enclosing <MixinMirror> ^<IntermediateMethod> = (
public compileExpressionSource: src <String> debugMapper: debugMapper <DebugMapper> withScope: withScope <Map> inMixin: enclosing <MixinMirror> ^<IntermediateMethod> = (
subclassResponsibility
)
public compileMethodSource: source <String> within: enclosing <IntermediateMixin> ^<IntermediateMethod> = (
Expand Down

0 comments on commit 06e8067

Please # to comment.