private Node translateSJOutwhile(SJOutwhile outwhile, QQ qq) {
   String unique = UniqueID.newID("loopCond");
   boolean isInterruptible = outwhile.isInterruptible();
   BooleanLit interruptible = new BooleanLit_c(outwhile.position(), isInterruptible);
   // RAY
   List targets = outwhile.targets();
   String translation;
   Object[] mapping;
   if (targets.size() == 1) {
     if (isInterruptible) {
       translation =
           "{ sessionj.runtime.net.LoopCondition %s = "
               + "sessionj.runtime.net.SJRuntime.negotiateOutsync(%E, %s);"
               + " while (%s.call(%E)) %S }";
       mapping =
           new Object[] {
             unique,
             interruptible,
             ((Local) targets.get(0)).name(),
             unique,
             outwhile.cond(),
             outwhile.body()
           };
     } else {
       translation =
           "{ sessionj.runtime.net.SJRuntime.negotiateOutsync(%E, %s);"
               + " while (sessionj.runtime.net.SJRuntime.outsync(%E, %s)) %S }";
       String sockName = ((Local) targets.get(0)).name();
       mapping =
           new Object[] {interruptible, sockName, outwhile.cond(), sockName, outwhile.body()};
     }
   } else {
     Expr sockArray = buildNewArray(outwhile.position(), targets);
     translation =
         "{ sessionj.runtime.net.LoopCondition %s = "
             + "sessionj.runtime.net.SJRuntime.negotiateOutsync(%E, %E);"
             + " while (%s.call(%E)) %S }";
     mapping =
         new Object[] {unique, interruptible, sockArray, unique, outwhile.cond(), outwhile.body()};
     /*
             BooleanLit interruptible = new BooleanLit_c(outwhile.position(), outwhile.isInterruptible());
             return qq.parseStmt(
     "{ sessionj.runtime.net.LoopCondition %s = " +
     "sessionj.runtime.net.SJRuntime.negotiateOutsync(%E, %E);" +
     " while (%s.call(%E)) %S }",
                     unique,
                     interruptible, sockArray,
                     unique, outwhile.cond(), outwhile.body()
             );*/
   }
   return qq.parseStmt(translation, mapping);
   // YAR
 }
  /** Run all pending passes on <code>job</code>. */
  public boolean runAllPasses(Job job) {
    List pending = job.pendingPasses();

    // Run until there are no more passes.
    if (!pending.isEmpty()) {
      Pass lastPass = (Pass) pending.get(pending.size() - 1);
      return runToPass(job, lastPass);
    }

    return true;
  }
Exemple #3
0
 /**
  * The confluence operator for <code>Initializer</code>s and <code>Constructor</code>s needs to be
  * a little special, as we are only concerned with non-exceptional flows in these cases. This
  * method ensures that a slightly different confluence is performed for these <code>Term</code>s,
  * otherwise <code>confluence(List, Term)</code> is called instead.
  */
 protected Item confluence(List items, List itemKeys, Term node, FlowGraph graph) {
   if (node instanceof Initializer || node instanceof ConstructorDecl) {
     List filtered = filterItemsNonException(items, itemKeys);
     if (filtered.isEmpty()) {
       return createInitDFI();
     } else if (filtered.size() == 1) {
       return (Item) filtered.get(0);
     } else {
       return confluence(filtered, node, graph);
     }
   }
   return confluence(items, node, graph);
 }
Exemple #4
0
  /**
   * Inform this <code>Job</code> that pass <code>p</code> has finished. If <code>okay</code> is
   * <code>true</code>, then the pass was completed successfully; if it is <code>false</code> the
   * pass was not completed successfully.
   *
   * <p>Pass <code>p</code> may be any pending pass.
   */
  public void finishPass(Pass p, boolean okay) {
    List passes = passes();

    status &= okay;

    for (int i = nextPass; i < passes.size(); i++) {
      Pass pass = (Pass) passes.get(i);

      if (pass == p) {
        nextPass = i + 1;
        return;
      }
    }

    throw new InternalCompilerError("Pass " + p + " was not a pending " + "pass.");
  }
  private Node translateSJInwhile(SJInwhile inwhile, QQ qq) {
    List targets = inwhile.targets();

    /*return qq.parseStmt(
    "{ sessionj.runtime.net.SJRuntime.negotiateNormalInwhile(%E);" +
    " while (sessionj.runtime.net.SJRuntime.insync(%E)) %S }",
                    sockArray, sockArray, inwhile.body()
            );*/

    // RAY
    String translation;
    Object[] mapping;
    String target = ((SJInwhile_c) inwhile).arguments().get(0).toString(); // <By MQ>
    if (targets.size() == 1) {
      translation =
          "{ sessionj.runtime.net.SJRuntime.negotiateNormalInwhile("
              + target
              + ", %s);" // <By MQ>
              + " while (sessionj.runtime.net.SJRuntime.insync("
              + target
              + ", %s)) %S }"; // <By MQ>
      // + "\n" + "%s.flush();"; //<By MQ> to flush sends after inwhile
      String sockName = ((Local) targets.get(0)).name();
      return qq.parseStmt(
          translation, new Object[] {sockName, sockName, inwhile.body() /*, sockName*/}); // <By MQ>
    } else {
      Expr sockArray = buildNewArray(inwhile.position(), targets);
      String tmpVarName = SJConstants.SJ_TMP_LOCAL + INWHILE_VAR + (inwhileCounter++);
      translation =
          "{ sessionj.runtime.net.SJSocket[] %s = %E;"
              + " sessionj.runtime.net.SJRuntime.negotiateNormalInwhile("
              + target
              + ", %s);" // <By MQ>
              + " while (sessionj.runtime.net.SJRuntime.insync("
              + target
              + ", %s)) %S }"; // <By MQ>
      mapping = new Object[] {tmpVarName, sockArray, tmpVarName, tmpVarName, inwhile.body()};
    }
    return qq.parseStmt(translation, mapping);
    // YAR
  }
  private Node translateSJOutinwhile(SJOutInwhile outinwhile, QQ qq) {
    List sources = outinwhile.insyncSources();
    List targets = outinwhile.outsyncTargets();

    String loopCond = UniqueID.newID("loopCond");
    String peerInterruptible = UniqueID.newID("peerInterruptible");

    List<Object> subst = new LinkedList<Object>();
    String code;

    // FIXME: this should be better factored. here, should treat sources and targets separately. but
    // also should integrate better with the same "optimisations" in the translation of in/outwhile
    if (sources.size() == 1 && targets.size() == 1) {
      String sourceName = ((Local) sources.get(0)).name();
      String targetName = ((Local) targets.get(0)).name();

      code = "{ sessionj.runtime.net.SJRuntime.negotiateOutsync(false, %s); ";
      subst.add(targetName);
      if (outinwhile.hasCondition()) {
        /*code += "boolean %s = ";
        subst.add(peerInterruptible);*/
        throw new RuntimeException("[SJCompoundOperation] TODO.");
      }
      code += "sessionj.runtime.net.SJRuntime.";
      if (outinwhile.hasCondition()) {
        // code += "negotiateInterruptingInwhile"
        throw new RuntimeException("[SJCompoundOperation] TODO.");
      } else {
        code += "negotiateNormalInwhile";
      }
      code += "(%s); while(sessionj.runtime.net.SJRuntime.outsync(";
      subst.add(sourceName);

      if (outinwhile.hasCondition()) {
        /*code += "interruptingInsync(%E, %s, %E)";
        subst.add(outinwhile.cond());
        subst.add(peerInterruptible);
        subst.add(sourcesArray);*/
        throw new RuntimeException("[SJCompoundOperation] TODO.");
      } else {
        code += "sessionj.runtime.net.SJRuntime.insync(%s)";
        subst.add(sourceName);
      }
      code += ", %s)) %S  }";
      code += "\n" + "%s.flush();"; // <By MQ> to flush sends after outwhile
      subst.add(targetName);
      subst.add(outinwhile.body());
      subst.add(targetName); // <By MQ>
    } else {
      Expr sourcesArray = buildNewArray(outinwhile.position(), sources); // inwhile sockets
      Expr targetsArray = buildNewArray(outinwhile.position(), targets); // outwhile sockets

      subst = new LinkedList<Object>(Arrays.asList(loopCond, targetsArray));
      code =
          "{ sessionj.runtime.net.LoopCondition %s = "
              + "sessionj.runtime.net.SJRuntime.negotiateOutsync(false, %E); ";
      if (outinwhile.hasCondition()) {
        code += "boolean %s = ";
        subst.add(peerInterruptible);
      }
      code += "sessionj.runtime.net.SJRuntime.";
      code += outinwhile.hasCondition() ? "negotiateInterruptingInwhile" : "negotiateNormalInwhile";
      code += "(%E); while(%s.call(sessionj.runtime.net.SJRuntime.";

      subst.add(sourcesArray);
      subst.add(loopCond);

      if (outinwhile.hasCondition()) {
        code += "interruptingInsync(%E, %s, %E)";
        subst.add(outinwhile.cond());
        subst.add(peerInterruptible);
        subst.add(sourcesArray);
      } else {
        code += "insync(%E)";
        subst.add(sourcesArray);
      }
      code += ")) %S  }";
      subst.add(outinwhile.body());
    }

    return qq.parseStmt(code, subst);
  }