示例#1
0
  public void evaluate(Environment aEnvironment, int aStackTop) throws Exception {
    BigNumber x = org.mathpiper.lisp.Utility.getNumber(aEnvironment, aStackTop, 1);
    BigNumber y = org.mathpiper.lisp.Utility.getNumber(aEnvironment, aStackTop, 2);
    long result = 0; // initialize just in case

    if (x.isInteger() && x.isSmall() && y.isInteger() && y.isSmall()) {
      // bits_to_digits uses unsigned long, see numbers.h
      int base = (int) y.toDouble();
      result = Utility.digitsToBits((long) (x.toDouble()), base);
    } else {
      throw new EvaluationException(
          "BitsToDigits: error: arguments ("
              + x.toDouble()
              + ", "
              + y.toDouble()
              + ") must be small integers",
          aEnvironment.iCurrentInput.iStatus.getFileName(),
          aEnvironment.iCurrentInput.iStatus.getLineNumber(),
          aEnvironment.iCurrentInput.iStatus.getLineIndex());
    }
    BigNumber z = new BigNumber(aEnvironment.getPrecision());
    z.setTo((long) result);
    getTopOfStackPointer(aEnvironment, aStackTop)
        .setCons(new org.mathpiper.lisp.cons.NumberCons(z));
  }
  public void evaluate(Environment aEnvironment, int aStackTop) throws Exception {
    String unpatchedString;
    unpatchedString = (String) getArgumentPointer(aEnvironment, aStackTop, 1).car();
    LispError.checkArgument(aEnvironment, aStackTop, unpatchedString != null, 2, "PatchString");

    String resultString;
    StringBuilder resultStringBuilder = new StringBuilder();
    String[] tags = unpatchedString.split("\\?\\>");
    if (tags.length > 1) {
      for (int x = 0; x < tags.length; x++) {
        String[] tag = tags[x].split("\\<\\?");
        if (tag.length > 1) {
          resultStringBuilder.append(tag[0]);
          String scriptCode = tag[1];
          if (scriptCode.endsWith(";")) {
            scriptCode = scriptCode.substring(0, scriptCode.length() - 1);
          }

          StringBuffer oper = new StringBuffer();
          StringOutputStream newOutput = new StringOutputStream(oper);
          MathPiperOutputStream previous = aEnvironment.iCurrentOutput;
          try {
            aEnvironment.iCurrentOutput = newOutput;
            ConsPointer resultPointer =
                Utility.lispEvaluate(aEnvironment, aStackTop, "Eval(" + scriptCode + ");");
            resultString =
                Utility.printMathPiperExpression(aStackTop, resultPointer, aEnvironment, 0);
          } catch (Exception e) {
            throw e;
          } finally {
            aEnvironment.iCurrentOutput = previous;
          }

          resultStringBuilder.append(oper);
        }
      } // end for.
      resultStringBuilder.append(tags[tags.length - 1]);
    } else {
      resultStringBuilder.append(unpatchedString);
    }

    getTopOfStackPointer(aEnvironment, aStackTop)
        .setCons(AtomCons.getInstance(aEnvironment, aStackTop, resultStringBuilder.toString()));
  }
示例#3
0
  public void evaluate(Environment aEnvironment, int aStackTop) throws Exception {

    String htmlText = null;

    ConsPointer consPointer = null;

    Object argument = getArgumentPointer(aEnvironment, aStackTop, 1).car();

    if (argument instanceof String) {
      htmlText = (String) argument;

      htmlText = Utility.stripEndQuotesIfPresent(aEnvironment, aStackTop, htmlText);
    } else if (argument instanceof BuiltinContainer) {
      BuiltinContainer builtinContainer = (BuiltinContainer) argument;
      LispError.check(
          aEnvironment,
          aStackTop,
          builtinContainer.typeName().equals("java.lang.String"),
          "Argument must be a MathPiper string or a Java String object.",
          "ViewHtml");
      htmlText = (String) builtinContainer.getObject();
    } else {
      LispError.raiseError(
          "Argument must be a MathPiper string or a Java String object.",
          "ViewHtml",
          aStackTop,
          aEnvironment);
    } // end else.

    htmlText = FunctionTreePanel.processLatex(htmlText);

    JFrame frame = new JFrame();
    Container contentPane = frame.getContentPane();
    contentPane.setLayout(new java.awt.BorderLayout());
    JEditorPane editorPane = new JEditorPane();
    editorPane.setEditorKit(new javax.swing.text.html.HTMLEditorKit());
    JScrollPane editorScrollPane = new JScrollPane(editorPane);
    editorScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    editorPane.setEditable(false);
    editorPane.setText(htmlText);
    contentPane.add(editorScrollPane);
    frame.pack();
    frame.setAlwaysOnTop(false);
    frame.setTitle("MathPiper");
    frame.setSize(new Dimension(750, 650));
    frame.setResizable(true);
    // frame.setPreferredSize(new Dimension(400, 400));
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);

    JavaObject response = new JavaObject(frame);

    getTopOfStackPointer(aEnvironment, aStackTop)
        .setCons(BuiltinObjectCons.getInstance(aEnvironment, aStackTop, response));
  } // end method.
示例#4
0
  public void evaluate(Environment aEnvironment, int aStackTop) throws Exception {

    java.util.Set<String> variablesSet = ((Map) aEnvironment.getGlobalState().getMap()).keySet();

    java.util.List variablesList = new ArrayList(variablesSet);

    Collections.sort(variablesList, new NameComparator());

    Cons head = Utility.iterableToList(aEnvironment, aStackTop, variablesList);

    getTopOfStackPointer(aEnvironment, aStackTop)
        .setCons(SublistCons.getInstance(aEnvironment, head));
  } // end method.
  public void evaluate(Environment aEnvironment, int aStackTop) throws Exception {
    BigNumber x = org.mathpiper.lisp.Utility.getNumber(aEnvironment, aStackTop, 1);

    Cons resultCons = x.dumpNumber(aEnvironment, aStackTop);

    /*
    ConsPointer isVerbosePointer = Utility.lispEvaluate(aEnvironment, aStackTop, "InVerboseMode();");

    if(((String)isVerbosePointer.car()).equals("True"))
    {
        x.dumpNumber(aEnvironment, aStackTop, aEnvironment.iCurrentOutput);
    }
    */

    getTopOfStackPointer(aEnvironment, aStackTop).setCons(resultCons);
  } // end method.
 public void evaluate(Environment aEnvironment, int aStackTop) throws Exception {
   Utility.delete(aEnvironment, aStackTop, true);
 }
示例#7
0
 public void evaluate(Environment aEnvironment, int aStackTop) throws Exception {
   Utility.putFalseInPointer(aEnvironment, getTopOfStackPointer(aEnvironment, aStackTop));
 }