Holy Code Mutation, Batman!!

3 views
Skip to first unread message

Dan Cook

unread,
Oct 2, 2008, 2:32:39 AM10/2/08
to Antidisassemblage
I JUST stumbled upon a SICK AMAZING use for code mutation to make
expression handling intensely efficient. It would allow expressions
to expand in depth without limit, without running out of registers (in
fact, without juggling registers at all), without using the stack to
store values, and without adding extra space for temp vars. The trick
is actually in the *without adding EXTRA SPACE, for temp vars.

I explain by with this example, where every 'exp' is an expression and
'+' is any operation:

(exp1 + (exp2 + (exp3 + exp4) ) )

This is resolved like so:

do exp1, store the result somewhere
do exp2, store the result somewhere
do exp3, store the result somewhere
do exp4, hold onto this value
recall exp3 result and combine with current result
recall exp2 result and combine with current result
recall exp1 result and combine with current result

The CURRENT solution is to "store the result" in a register, but this
requires a lot of juggling. "somewhere" COULD be the stack, but that
has potential problems. I suggest that "somewhere" be the actual
location of an arbitrary value being loaded into a register (THAT
instruction being the "recall" of the result). Example:

;do exp1
LD (recall1+?), theResult
;do exp2
LD (recall2+?), theResult
;do exp3
LD (recall3+?), theResult
;do exp4, hold onto this value
recall3:
;combine result with arbitrary value
recall2:
;combine result with arbitrary value
recall1:
;combine result with arbitrary value

Where '?' is whatever offset of that arbitrary value from the label.
The LD instruction from A and HL to an address is only 3 bytes, and
changing an instruction to use an immediate value rather than a
register usually adds another byte (or two for 16-bit values). That's
almost exactly the same to do the most efficient register-juggling
possible, but with the bonus of unlimited "juggles" at once w/o
affecting registers or the stack. Added bonus for therefore almost
ALWAYS having the A and HL registers available for use.

However, SquirrelBox is so tangled up that I doubt I will ever put
that in :-P But hey, it's a thought. Possibly doable from the point
of view of an optimizer though :-) ... (if nothing else, for sure
when I make a better better language some day. Hopefully soon after
this gets off the ground, though I will continue to maintain it)
Reply all
Reply to author
Forward
0 new messages