def testReadErrors(self):
   # errors of parse_word(...) see in testParse(...)
   tests = [
     (
       [
         "123WORD\n",
         "\n",
         "123 1\t\t0 0 0 5 \n my comment",
         "120 1 71 2 3\t \t4 5 long comment\n",
         "   ",
         "3999 -1    63\t\t\t63 63\t63 63",
         "3999 1    0\t\t0 0\t0 0",
         "5000 1 1 1 1 1 1"
       ],
       (
         {
           3999: [-1, 63, 63, 63, 63, 63],
         },
         None,
         [
           (1, InvalidStartAddressError("123WORD")),
           (3, InvalidIntError("my")),
           (4, InvalidMixWordError((1, 71, 2, 3, 4, 5))),
           (7, RepeatedAddressError(3999)),
           (8, InvalidMemAddrError(5000))
         ]
       )
     )
     #,
     #( lines, ( memory, start_address, errors) )
   ]
   for lines, res in tests:
     self.assertEqual(read_memory(lines), res)
 def testReadNoErrors(self):
   # may be need more
   tests = [
     (
       [
         "123\n",
         "\n",
         "123 1\t\t0 0 0 5 2\n my comment",
         "120 1 1 2 3\t \t4 5 long comment\n",
         "   ",
         "3999 -1    63\t\t\t63 63\t63 63"
       ],
       (
         {
           120: [1, 1, 2, 3, 4, 5],
           123: [1, 0, 0, 0, 5, 2],
           3999: [-1, 63, 63, 63, 63, 63],
         },
         123,
         []
       )
     )
     #,
     #( lines, ( memory, start_address, errors) )
   ]
   for lines, res in tests:
     self.assertEqual(read_memory(lines), res)
Example #3
0
 def testReadNoErrors(self):
     # may be need more
     tests = [([
         "123\n", "\n", "123 1\t\t0 0 0 5 2\n my comment",
         "120 1 1 2 3\t \t4 5 long comment\n", "   ",
         "3999 -1    63\t\t\t63 63\t63 63"
     ], ({
         120: [1, 1, 2, 3, 4, 5],
         123: [1, 0, 0, 0, 5, 2],
         3999: [-1, 63, 63, 63, 63, 63],
     }, 123, []))
              #,
              #( lines, ( memory, start_address, errors) )
              ]
     for lines, res in tests:
         self.assertEqual(read_memory(lines), res)
Example #4
0
 def __init__(self, filename):
     file_in = open(filename, "r")
     memory, start_address, errors = read_memory(file_in.readlines())
     if len(errors) > 0:
         self.print_errors(errors)
         raise Exception(ERR_SYNTAX[1])
     self.vmachine = VMachine(memory, start_address)
     self.out_file = open("printer.out", "w")
     self.in_file = open("terminal.in", "r")
     self.vmachine.set_device(self.printer_unit,
                              FileDevice(mode="w", block_size=24 * 5,
                                         lock_time=24 * 2,
                                         file_object=self.out_file))
     self.vmachine.set_device(self.terminal_unit,
                              FileDevice(mode="r", block_size=14 * 5,
                                         lock_time=14 * 2,
                                         file_object=self.in_file))
Example #5
0
 def testReadErrors(self):
     # errors of parse_word(...) see in testParse(...)
     tests = [([
         "123WORD\n", "\n", "123 1\t\t0 0 0 5 \n my comment",
         "120 1 71 2 3\t \t4 5 long comment\n", "   ",
         "3999 -1    63\t\t\t63 63\t63 63", "3999 1    0\t\t0 0\t0 0",
         "5000 1 1 1 1 1 1"
     ], ({
         3999: [-1, 63, 63, 63, 63, 63],
     }, None, [(1, InvalidStartAddressError("123WORD")),
               (3, InvalidIntError("my")),
               (4, InvalidMixWordError((1, 71, 2, 3, 4, 5))),
               (7, RepeatedAddressError(3999)),
               (8, InvalidMemAddrError(5000))]))
              #,
              #( lines, ( memory, start_address, errors) )
              ]
     for lines, res in tests:
         self.assertEqual(read_memory(lines), res)
Example #6
0
  for error in errors:
    print_error(error[0], error[1])

def main():
  if len(sys.argv) != 2: # 1st - program name, 2nd - input filename
    print ERR_INVALID_ARGS[1]
    return ERR_INVALID_ARGS[0]

  try:
    file_in = open(sys.argv[1], "r")
  except IOError, (errno, strerror):
    print "%s (%s): %s" % (ERR_INVALID_INPUT_FILE[1], sys.argv[1], strerror)
    return ERR_INVALID_INPUT_FILE[0]


  memory, start_address, errors = read_memory(file_in.readlines())
  if len(errors) > 0:
    print ERR_SYNTAX[1]
    print_errors(errors)
    return ERR_SYNTAX[0]


  vmachine = VMachine(memory, start_address)
  out_file = open("printer.out", "w")
  in_file = open("terminal.in", "r")
  vmachine.set_device(18, FileDevice(mode = "w", block_size = 24 * 5, lock_time = 24*2, file_object = out_file)) # printer
  vmachine.set_device(19, FileDevice(mode = "r", block_size = 14 * 5, lock_time = 14*2, file_object = in_file)) # input terminal

  try:
    while not vmachine.halted:
      print "----------------------"
Example #7
0
    return_stream = bit_stream[-bit_length:]
    if bit_length > address_length:
        return_stream = '0' * (bit_length - address_length) + bit_stream

    return '0b' + str(return_stream)


if __name__ == '__main__':

    DRAM, chips, times, wait = load_specs()
    processor_clock = DRAM['clock']  #for further time transformations

    try:
        while True:
            block_size, mode, address, now_time = read_memory()
            address = bit_transform(address, DRAM['capacity'])

            #check timings
            wait_time = 0
            if now_time < wait['bus_free']:
                #this time is already in clock cycles
                wait_time = wait['bus_free'] - now_time

            #retrieve indexes
            i_row, i_chip, i_bank, i_column = bit_reading(
                DRAM['chips'], address)

            #access selected chip
            chip = chips[i_chip]
            #access selected bank