From Resource to Peasauce
I have a list of hobby projects that I've always wanted to find the time and energy to work on, and one of these is an interactive disassembler. Years ago when people used a type of computer called "the Amiga", it had an extremely usable interactive disassembler called Resource. You would point it at a file and it would turn the file into assembly language code and data, after which you would interactively disassemble some more, and finally make it write out a file containing the assembly language source code.
|Disassembled and commented code in Resource.|
|Disassembled code in Peasauce.|
I initially started usng the Tkinter, because it comes with the standard library. Unfortunately, out of the box it just wasn't flexible enough to work in the way I wanted. As an alternative, I first looked at PySide but wasn't able to locate documentation to make it easy to work out if it suited my needs. The website looks like it is in a transitional phase and several links to useful sounding documentation were dead unfortunately. This left wxPython, which I've used before. As a fringe benefit of having a small play around with PySide, I first encountered crashes and then with Anselm Kruis' recent patch to Stackless Python was able verify this decade long ABI incompatibility was fixed and that the crashes went away.
With wxPython, I'm currently using the ListCtrl where it simply knows how many list items there are and requests list items as needed for display. Strangely, as the number of list items increase it gets slower, but that's likely my fault for some reason. As a short term solution while there's minimal interactivity, it's good enough, but the time is almost right for something more dynamic.
The bisect module
I was iterating over ordered lists looking for the right entry, and this was profiling as the place most time was spent. A quick browse of the Python documentation introduced me to a module I'd never heard of before, the bisect module. By keeping two lists instead of one, bisect let me look up objects in the second list by passing it the first list. That makes it sound rather complicated, a simplified piece of example code is a lot more helpful.
lookup_index = bisect.bisect_left(lookup_keys, lookup_key) if lookup_keys[lookup_idx] != lookup_key: lookup_value = lookup_values[lookup_idx-1] else: lookup_value = lookup_values[lookup_idx]While I haven't actually looked, writing this up has made me suspect that if I also bung judicial use of this in the list control virtual item fetching, it might even solve the slowness problem with larger files. Actually going away and looking at the code confirms it. I'll need another indexing list though, and to keep that synchronised with the other two.
My laptop is a little unreliable and addressing that isn't on the table, so a good way to ensure I don't lose the source code should anything happen, is to throw it up on github with everyone else's half completed projects where it can also sit mouldering and abandoned. Or slowly be developed further, of course.
Link: Peasauce on github.