Bytecode disassembler

Brian T. Rice water at tunes.org
Sun Aug 15 22:31:22 PDT 2004


Brian T. Rice wrote:

> Pavel Holejsovsky wrote:
> 
>> Hi Slaters,
>>
>> I wrote attached bytecode disassembling stream, mainly for educational 
>> purposes.  I'd be glad for any comments about this code - both for 
>> implementation and style of interface (Disassembler is ReadStream 
>> clone, working over CompiledMethod, providing strings with single 
>> disassembled instructions).
> 
> Cool! Thank you. This is definitely a nice start. I'm not sure if it 
> helps to make it a stream type, although it's obviously true that the 
> code must be traversed in-order to build up the instruction sequence.
> 
> The only things I really noticed were that it resembled StreamProcessor 
> but doesn't (and probably shouldn't) have the same interface, and that 
> value:typed: is kind of an awkward message name, although I'm not sure 
> what a better one would be. Perhaps printNameOf:type: or something.
> 
>> Sample usage:
>> [] disassembler upToEnd.
>> [|:a b| b: a - 1. (b < 0) ifTrue: a neg ifFalse: a ] disassembler do:
>>   [| :instr | Console ; instr ; '\n' ].
>>
>> or 'hackish' REPL-friendly interface:
>> disass: [ 1 + 1 ].

I thought more about the contents of the results as strings, and it's 
not an easy thing to work on. One thing I have toyed with in my thoughts 
is the idea of having subjective code-sequences to represent / simulate 
bytecodes, so you could have (for your long example):

(
loadSelector: #-.
loadVariable: #i0.
loadLiteral: 1.
sendMessageWithArgs: 2.
storeVariable: #l0.
pop: 1.
loadSelector: #<.
...
).

And each of these would be subjectively layered on the context so that 
an Interpreter would execute these messages in a way that simulated the 
state of the executable VM without being entangled too much in the 
run-time characteristics. Now that I think of it, a specific Interpreter 
must be chosen, so maybe macros are needed or something.

This is a slow solution, but kind of instructive.

Anyway, maybe you'll get some ideas based on it. We will be better off 
with a useful disassembler than without one, of course, so I'd like to 
refine this and add it in to the repository.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: water.vcf
Type: text/x-vcard
Size: 208 bytes
Desc: not available
Url : /archives/slate/attachments/20040815/7ec23be5/water.vcf


More information about the Slate mailing list