golf-cpu icon indicating copy to clipboard operation
golf-cpu copied to clipboard

TypeError: can't concat bytes to list

Open setop opened this issue 10 years ago • 1 comments

When running a program which loads data, such as helloworld, I get a TypeError :

$ ./golf.py examples/helloworld.bin 
Traceback (most recent call last):
  File "./golf.py", line 230, in <module>
    ret = golf.run()
  File "./golf.py", line 204, in run
    self.execute_instr(instr_name, instr_args)
  File "./golf.py", line 151, in execute_instr
    elif instr == "lbu":  self.regs[args[0]] = self.load(args[1], 1)
  File "./golf.py", line 89, in load
    return struct.unpack_from("<" + fmts[width], bytes(r + [0] * width))[0]
TypeError: can't concat bytes to list

I have been able to fix it by changing line 89 to :

return struct.unpack_from("<" + fmts[width], bytes(list(r) * width))[0]

I use python 3.4.2

setop avatar Sep 28 '15 20:09 setop

I get the same error, however the line should be changed to:

return struct.unpack_from("<" + fmts[width], bytes(list(r) + [0] * width))[0]

so that reading for uninitialized memory will have 0 as the value.

tyilo avatar Sep 28 '15 20:09 tyilo