Esempio n. 1
0
  private void assembleAction() {
    String line;
    messages = new Vector();

    mainFrame.resetExecWindow();

    save();

    assembleFailed = false;
    haveAssemblyErrors = false;

    if (Assembler.version()) {
      while ((line = Assembler.output()) != null) {
        messages.addElement(line);
      }

      Assembler.setPaths(baseName, sourcePath);

      if (Assembler.assemble()) {
        while ((line = Assembler.output()) != null) {
          System.out.println(line);

          messages.addElement(line);

          if (line.startsWith(" [ERROR:")) {
            haveAssemblyErrors = true;
          }
        }

        messageList.setListData(messages);
        messageList.ensureIndexIsVisible(0);

        mainFrame.showExecWindow(baseName);
      } else {
        assembleFailed = true;
      }
    } else {
      assembleFailed = true;
    }

    if (assembleFailed) {
      String message =
          String.format(
              "Autocoder failed!\nVerify the correctness of autocoder path\n%s",
              AssemblerOptions.assemblerPath);
      System.out.println(message);

      JOptionPane.showMessageDialog(this, message, "ROPE", JOptionPane.ERROR_MESSAGE);
    }
  }
Esempio n. 2
0
 private void verifyAssembly(String templateName) throws Exception {
   StringWriter output = new StringWriter();
   assembler.assemble(
       createClassPathUrl("templates/" + templateName + ".xhtml"), namespace, output);
   String expectedOutput = loadText(createClassPathUrl("solutions/" + templateName + ".html"));
   assertEquals(expectedOutput, output.toString());
 }
  private void assemble() {
    if (sourceFile == null) {
      printError("-i : No source file specified");
    }

    if (assembler == null) {
      printError("-f : No format specified");
    }

    print("...Assembling " + sourceFile.getName());

    assembler.assemble(sourceFile);

    print("..." + assembler.getErrors().length + " error(s) found");

    try {
      PrintWriter output = null;

      if (!assembler.hasErrors()) {
        if (!machineCode) {
          print("...saving .pco file");

          output = new PrintWriter(new FileWriter(baseFileName + ".pco"));

          for (Instruction instruction : assembler.getInstructions()) {
            output.print(instruction.getInstruction());
            output.println(" ;" + instruction.getSourceCode());
          }
        } else {
          print("Machine code file varified");
        }
      } else {
        print("...saving .err file");

        output = new PrintWriter(new FileWriter(baseFileName + ".err"));
        for (AssemblyError error : assembler.getErrors()) {
          output.println(error.toString());
        }
      }

      if (output != null) {
        output.close();
      }
    } catch (IOException e) {
      printError(e.getMessage());
    }
  }
Esempio n. 4
0
  @Test
  public void testMinimalTemplate() throws Exception {
    final String INPUT = "<html xmlns=\"http://www.w3.org/1999/xhtml\"/>";
    final String EXPECTED_OUTPUT =
        "<!DOCTYPE html>\n" + "<html xmlns=\"http://www.w3.org/1999/xhtml\"/>";

    StringWriter output = new StringWriter();
    assembler.assemble(createLiteralUrl(INPUT), output);
    assertEquals(EXPECTED_OUTPUT, output.toString());
  }
Esempio n. 5
0
  @Test
  public void testMissingDocumentElement() throws Exception {
    final String INPUT = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";

    Throwable error = null;
    try {
      assembler.assemble(createLiteralUrl(INPUT), new StringWriter());
    } catch (AssemblerException e) {
      error = e.getCause();
    }
    assertNotNull(error);
  }
Esempio n. 6
0
  @Test
  public void testBadInputPath() throws Exception {
    final String BAD_PATH = "no-such";

    Throwable error = null;
    try {
      assembler.assemble(createClassPathUrl(BAD_PATH), new StringWriter());
    } catch (AssemblerException e) {
      error = e.getCause();
    }
    assertEquals(BAD_PATH, error.getMessage());
  }
  private void execute() {
    if (sourceFile == null) {
      printError("-i : No source file specified");
    }

    if (assembler == null || computer == null) {
      printError("-f : No format specified");
    }

    if (assembler.hasErrors()) {
      printError("Unable to execute file due to errors");
    }

    print("...preparing to execute program");

    if (trace) {
      print("...opening computer trace files");
      addTraceListeners();
    }

    computer.setExecutionSpeed(ExecutionSpeed.FULL);
    computer.setInstructions(assembler.getInstructions());

    computer.addComputerListener(
        new ComputerAdapter() {
          public void computerStarted(Computer computer) {
            print("...Execution started");
          }

          public void computerStopped(Computer computer) {
            print("...Execution complete");
          }
        });

    computer.execute();
  }
Esempio n. 8
0
  @Test
  public void testConflictingIncludeAndContent() throws Exception {
    final String INPUT =
        "<html xmlns=\"http://www.w3.org/1999/xhtml\""
            + " xmlns:dwc=\"http://shopximity.com/schema/dwc\""
            + " dwc:content=\"\""
            + " dwc:include=\"\"/>";

    Throwable error = null;
    try {
      assembler.assemble(createLiteralUrl(INPUT), new StringWriter());
    } catch (AssemblerException e) {
      error = e.getCause();
    }
    // TODO: assert that the error message contains meaningful information.
    assertNotNull(error);
  }