Ejemplo n.º 1
0
  /**
   * Constructs the CPU with given program, RAM, call stack, bus, stack and other memory segments.
   */
  public CPU(
      VMProgram program,
      RAM ram,
      CallStack callStack,
      Calculator calculator,
      Bus bus,
      AbsolutePointedMemorySegment stackSegment,
      TrimmedAbsoluteMemorySegment workingStackSegment,
      MemorySegment staticSegment,
      MemorySegment localSegment,
      MemorySegment argSegment,
      MemorySegment thisSegment,
      MemorySegment thatSegment,
      MemorySegment tempSegment,
      File builtInDir) {
    this.program = program;
    this.ram = ram;
    this.callStack = callStack;
    this.calculator = calculator;
    this.bus = bus;

    this.stackSegment = stackSegment;
    this.workingStackSegment = workingStackSegment;
    this.staticSegment = staticSegment;
    this.localSegment = localSegment;
    this.argSegment = argSegment;
    this.thisSegment = thisSegment;
    this.thatSegment = thatSegment;
    this.tempSegment = tempSegment;

    segments = new MemorySegment[HVMInstructionSet.NUMBER_OF_ACTUAL_SEGMENTS];
    segments[HVMInstructionSet.LOCAL_SEGMENT_CODE] = localSegment;
    segments[HVMInstructionSet.ARG_SEGMENT_CODE] = argSegment;
    segments[HVMInstructionSet.THIS_SEGMENT_CODE] = thisSegment;
    segments[HVMInstructionSet.THAT_SEGMENT_CODE] = thatSegment;
    segments[HVMInstructionSet.TEMP_SEGMENT_CODE] = tempSegment;

    stackFrames = new Vector();

    if (program.getGUI() != null) {
      builtInFunctionsRunner = new BuiltInFunctionsRunner(this, builtInDir);
    }
  }