示例#1
0
  /** {@inheritDoc} */
  public SizeableLinkedList<WAMInstruction> compileBodyArguments(
      Functor functor, boolean isFirstBody, FunctorName clauseName, int bodyNumber) {
    SizeableLinkedList<WAMInstruction> result = new SizeableLinkedList<WAMInstruction>();
    SizeableLinkedList<WAMInstruction> instructions;

    Term[] expressions = functor.getArguments();

    for (int i = 0; i < expressions.length; i++) {
      Functor expression = (Functor) expressions[i];

      Integer permVarsRemaining =
          (Integer)
              defaultBuiltIn
                  .getSymbolTable()
                  .get(expression.getSymbolKey(), SYMKEY_PERM_VARS_REMAINING);

      // Select a non-default built-in implementation to compile the functor with, if it is a
      // built-in.
      BuiltIn builtIn;

      if (expression instanceof BuiltIn) {
        builtIn = (BuiltIn) expression;
      } else {
        builtIn = defaultBuiltIn;
      }

      // The 'isFirstBody' parameter is only set to true, when this is the first functor of a rule.
      instructions = builtIn.compileBodyArguments(expression, false, clauseName, bodyNumber);
      result.addAll(instructions);

      // Call the body. The number of permanent variables remaining is specified for environment
      // trimming.
      instructions =
          builtIn.compileBodyCall(expression, false, false, false, 0 /*permVarsRemaining*/);
      result.addAll(instructions);
    }

    return result;
  }
示例#2
0
  /** {@inheritDoc} */
  protected void enterFunctor(Functor functor) {
    String head = traverser.isInHead() ? "/head" : "";
    String last = traverser.isLastBodyFunctor() ? "/last" : "";
    String symKey = functor.getSymbolKey().toString();

    if (traverser.isTopLevel()) {
      addLineToRow("functor(" + symKey + ")" + head + last);
    } else {
      addLineToRow("arg(" + symKey + ")");
    }

    nextRow();
  }