Ejemplo n.º 1
0
  public Interpreter clone() {
    Interpreter clone = new Interpreter();

    clone._useFrames = _useFrames;

    Program instructionList = new Program();
    _inInstructionList.CopyTo(instructionList);
    clone.SetInstructions(instructionList);
    clone.SetRandomParameters(
        _minRandomInt,
        _maxRandomInt,
        _randomIntResolution,
        _minRandomFloat,
        _maxRandomFloat,
        _randomFloatResolution,
        _maxRandomCodeSize,
        _maxPointsInProgram);

    clone._useFrames = _useFrames;

    return clone;
  }
Ejemplo n.º 2
0
  /**
   * Defines the instruction set used for random code generation in this Push interpreter.
   *
   * @param inInstructionList A program consisting of a list of string instruction names to be
   *     placed in the instruction set.
   */
  public void SetInstructions(Program inInstructionList) throws RuntimeException {
    _inInstructionList = new Program();
    inInstructionList.CopyTo(_inInstructionList);

    _randomGenerators.clear();

    for (int n = 0; n < inInstructionList.size(); n++) {
      Object o = inInstructionList.peek(n);
      String name = null;

      if (o instanceof Instruction) {
        String keys[] = _instructions.keySet().toArray(new String[_instructions.size()]);

        for (String key : keys)
          if (_instructions.get(key) == o) {
            name = key;
            break;
          }
      } else if (o instanceof String) {
        name = (String) o;
      } else
        throw new RuntimeException(
            "Instruction list must contain a list of Push instruction names only");

      // Check for registered
      if (name.indexOf("registered.") == 0) {
        String registeredType = name.substring(11);

        if (!registeredType.equals("integer")
            && !registeredType.equals("float")
            && !registeredType.equals("boolean")
            && !registeredType.equals("exec")
            && !registeredType.equals("code")
            && !registeredType.equals("name")
            && !registeredType.equals("input")
            && !registeredType.equals("frame")) {
          System.err.println("Unknown instruction \"" + name + "\" in instruction set");
        } else {
          // Legal stack type, so add all generators matching
          // registeredType to _randomGenerators.
          Object keys[] = _instructions.keySet().toArray();

          for (int i = 0; i < keys.length; i++) {
            String key = (String) keys[i];
            if (key.indexOf(registeredType) == 0) {
              AtomGenerator g = _generators.get(key);
              _randomGenerators.add(g);
            }
          }

          if (registeredType.equals("boolean")) {
            AtomGenerator t = _generators.get("true");
            _randomGenerators.add(t);
            AtomGenerator f = _generators.get("false");
            _randomGenerators.add(f);
          }
          if (registeredType.equals("integer")) {
            AtomGenerator g = _generators.get("integer.erc");
            _randomGenerators.add(g);
          }
          if (registeredType.equals("float")) {
            AtomGenerator g = _generators.get("float.erc");
            _randomGenerators.add(g);
          }
        }
      } else if (name.indexOf("input.makeinputs") == 0) {
        String strnum = name.substring(16);
        int num = Integer.parseInt(strnum);

        for (int i = 0; i < num; i++) {
          DefineInstruction("input.in" + i, new InputInN(i));
          AtomGenerator g = _generators.get("input.in" + i);
          _randomGenerators.add(g);
        }
      } else {
        AtomGenerator g = _generators.get(name);

        if (g == null) {
          throw new RuntimeException("Unknown instruction \"" + name + "\" in instruction set");
        } else {
          _randomGenerators.add(g);
        }
      }
    }
  }