Skip to content

Commit

Permalink
Refactor ExecuteTopLevelContextNode
Browse files Browse the repository at this point in the history
  • Loading branch information
fniephaus committed Dec 26, 2023
1 parent aa239d4 commit 876d77e
Showing 1 changed file with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,26 +109,27 @@ private void executeLoop() {

@TruffleBoundary
private static ContextObject returnTo(final ContextObject activeContext, final AbstractSqueakObject sender, final Object returnValue) {
if (sender == NilObject.SINGLETON) {
if (!(sender instanceof final ContextObject senderContext)) {
assert sender == NilObject.SINGLETON;
throw returnToTopLevel(activeContext, returnValue);
}
final ContextObject targetContext = (ContextObject) sender;
final ContextObject context;
if (targetContext.isPrimitiveContext()) {
context = (ContextObject) targetContext.getFrameSender(); // skip primitive contexts.
if (senderContext.isPrimitiveContext()) {
context = (ContextObject) senderContext.getFrameSender(); // skip primitive contexts.
} else {
context = targetContext;
context = senderContext;
}
context.push(returnValue);
return context;
}

@TruffleBoundary
private ContextObject commonNLReturn(final AbstractSqueakObject sender, final ContextObject targetContext, final Object returnValue) {
if (sender == NilObject.SINGLETON) {
if (!(sender instanceof final ContextObject senderContext)) {
assert sender == NilObject.SINGLETON;
throw returnToTopLevel(targetContext, returnValue);
}
ContextObject context = (ContextObject) sender;
ContextObject context = senderContext;
while (context != targetContext) {
final AbstractSqueakObject currentSender = context.getSender();
if (currentSender instanceof final ContextObject o) {
Expand Down Expand Up @@ -160,11 +161,11 @@ private ContextObject commonReturn(final ContextObject startContext, final Conte
*/
AbstractSqueakObject contextOrNil = startContext;
while (contextOrNil != targetContext) {
if (contextOrNil == NilObject.SINGLETON) {
if (!(contextOrNil instanceof final ContextObject context)) {
/* "error: sender's instruction pointer or context is nil; cannot return" */
assert contextOrNil == NilObject.SINGLETON;
return sendCannotReturn(startContext, returnValue);
}
final ContextObject context = (ContextObject) contextOrNil;
assert !context.isPrimitiveContext();
if (context.getCodeObject().isUnwindMarked()) {
assert !context.hasClosure();
Expand Down

0 comments on commit 876d77e

Please sign in to comment.