omarandlorraine / strop

Stochastically generates machine code
MIT License
97 stars 1 forks source link

Trait #43

Closed omarandlorraine closed 1 year ago

omarandlorraine commented 1 year ago

Instead of handing a single closure to the search function, we should hand in a (reference to) an object which impls a suitable trait.

Would make for a neater and more extensible API

omarandlorraine commented 1 year ago

One problem I'm aware of is that the optimize function doesn't seem to get called by the example program. Thus, running

multiply_accumulator_by_constant_6502 4

(i.e. find a 6502 program that multiplies the accumulator by four) might yield something like:

rol a
dec $708f
tsx
asl a

which does leave the accumulator in the desired state, but does also contain several instructions (dec $708f and tsx) which are unnecessary (i.e. dead-code-elimination would remove them).

This should be solved if only an optimization pass were to happen

omarandlorraine commented 1 year ago

Also, multiply_accumulator_by_constant_6502 doesn't work very well with numbers other than 2 and 4. This is because this would need the 6502 sta/adc instructions, which would have to have the same memory address/addressing mode. This is unlikely to happen randomly, so we need to constraint the search space somehow.