<commit_before>package som.interpreter.actors;

import java.util.Arrays;
import java.util.concurrent.RecursiveAction;

import som.VM;
import som.compiler.AccessModifier;
import som.interpreter.Types;
import som.interpreter.actors.SPromise.SResolver;
import som.interpreter.nodes.dispatch.Dispatchable;
import som.vmobjects.SSymbol;

import com.oracle.truffle.api.CompilerAsserts;


public final class EventualMessage extends RecursiveAction {
  private static final long serialVersionUID = -7994739264831630827L;

  private Actor target;
  private final SSymbol  selector;
  private final Object[] args;
  private final SResolver resolver;

  private Actor sender;

  public EventualMessage(final Actor target, final SSymbol selector,
      final Object[] args, final SResolver resolver, final Actor sender) {
    this.target   = target;
    this.selector = selector;
    this.args     = args;
    this.resolver = resolver;
    assert resolver != null;

    this.sender = sender;
  }

  public void setReceiverForEventualPromiseSend(final Object rcvr, final Actor target, final Actor sendingActor) {
    this.target = target; // for sends to far references, we need to adjust the target
    this.sender = sendingActor;

    assert !(rcvr instanceof SFarReference) || ((SFarReference) rcvr).getActor() == target;

    args[0] = target.wrapForUse(rcvr, sendingActor);
    assert !(args[0] instanceof SFarReference) : "this should not happen, because we need to redirect messages to the other actor, and normally we just unwrapped this";
    assert !(args[0] instanceof SPromise);

    for (int i = 1; i < args.length; i++) {
      args[i] = target.wrapForUse(args[i], sendingActor);
    }
  }

  public Actor getTarget() {
    return target;
  }

  public boolean isReceiverSet() {
    return args[0] != null;
  }

  @Override
  protected void compute() {
    actorThreadLocal.set(target);

    try {
      executeMessage();
    } catch (Throwable t) {
      t.printStackTrace();
    }

    actorThreadLocal.set(null);
    target.enqueueNextMessageForProcessing();
  }

  protected void executeMessage() {
    CompilerAsserts.neverPartOfCompilation("Not Optimized! But also not sure it can be part of compilation anyway");

    assert sender != null;

    Object rcvrObj = args[0];
    assert rcvrObj != null;

    Object result;
    assert !(rcvrObj instanceof SFarReference);
    assert !(rcvrObj instanceof SPromise);

    Dispatchable disp = Types.getClassOf(rcvrObj).
        lookupMessage(selector, AccessModifier.PUBLIC);
    if (disp == null) {<commit_msg>Exit VM as soon as we got an uncaught exception<commit_after>package som.interpreter.actors;

import java.util.Arrays;
import java.util.concurrent.RecursiveAction;

import som.VM;
import som.compiler.AccessModifier;
import som.interpreter.Types;
import som.interpreter.actors.SPromise.SResolver;
import som.interpreter.nodes.dispatch.Dispatchable;
import som.vmobjects.SSymbol;

import com.oracle.truffle.api.CompilerAsserts;


public final class EventualMessage extends RecursiveAction {
  private static final long serialVersionUID = -7994739264831630827L;

  private Actor target;
  private final SSymbol  selector;
  private final Object[] args;
  private final SResolver resolver;

  private Actor sender;

  public EventualMessage(final Actor target, final SSymbol selector,
      final Object[] args, final SResolver resolver, final Actor sender) {
    this.target   = target;
    this.selector = selector;
    this.args     = args;
    this.resolver = resolver;
    assert resolver != null;

    this.sender = sender;
  }

  public void setReceiverForEventualPromiseSend(final Object rcvr, final Actor target, final Actor sendingActor) {
    this.target = target; // for sends to far references, we need to adjust the target
    this.sender = sendingActor;

    assert !(rcvr instanceof SFarReference) || ((SFarReference) rcvr).getActor() == target;

    args[0] = target.wrapForUse(rcvr, sendingActor);
    assert !(args[0] instanceof SFarReference) : "this should not happen, because we need to redirect messages to the other actor, and normally we just unwrapped this";
    assert !(args[0] instanceof SPromise);

    for (int i = 1; i < args.length; i++) {
      args[i] = target.wrapForUse(args[i], sendingActor);
    }
  }

  public Actor getTarget() {
    return target;
  }

  public boolean isReceiverSet() {
    return args[0] != null;
  }

  @Override
  protected void compute() {
    actorThreadLocal.set(target);

    try {
      executeMessage();
    } catch (Throwable t) {
      t.printStackTrace();
      VM.errorExit("Some EventualMessage failed with Exception.");
    }

    actorThreadLocal.set(null);
    target.enqueueNextMessageForProcessing();
  }

  protected void executeMessage() {
    CompilerAsserts.neverPartOfCompilation("Not Optimized! But also not sure it can be part of compilation anyway");

    assert sender != null;

    Object rcvrObj = args[0];
    assert rcvrObj != null;

    Object result;
    assert !(rcvrObj instanceof SFarReference);
    assert !(rcvrObj instanceof SPromise);

    Dispatchable disp = Types.getClassOf(rcvrObj).
        lookupMessage(selector, AccessModifier.PUBLIC);
    if (disp == null) {
{'fraction_non_alphanumeric': 0.0939712918660287, 'fraction_numerical': 0.009569377990430622, 'mean_word_length': 3.8165898617511522, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2643678', 'n_tokens_mistral': 1548, 'n_tokens_neox': 1501, 'n_words': 454}