Dan Sugalski <[EMAIL PROTECTED]> wrote:
> Well... about that. It's actually easily doable with a bit of
> trickery. We can either:

I have trickery number 4) here. Dunno if its doable, but worth
considering IMHO:

Here is mmd.pasm (using bxor but substitute any math/bitwise/... op).
Comments inline.

_main:
    new P16, .PerlInt
    new P17, .PerlInt
    new P18, .PerlInt
    set P17, 0b101
    set P18, 0b100
# might call a PASM sub or not, who knows
    bxor P16, P17, P18
#
    print P16
    print "\n"

# plain MMD
# install PASM handler for overloaded bxor
.include "pmctypes.pasm"
.include "vtable_constants.pasm"
    find_global P19, "PerlInt_bxor"
    mmdvtregister .VTABLE_BXOR, .PerlInt, .PerlInt, P19
    bxor P16, P17, P18
    print P16
    print "\n"

# So, now when the compiler see's[1] a mmdvtregister .. BXOR, it changes
# the emitted code sequence of all bxor_p_p_p opcodes to:

# recompile each bxor_p_p_p
    mmdvtfind P20, .VTABLE_BXOR, .PerlInt, .PerlInt
    isnull P20, bxor_normal_1
    set P5, P17
    set P6, P18
    set P7, P16
    set P0, P20
    pushtopp
    invokecc
    poptopp
    branch bxor_done_1
bxor_normal_1:
    bxor P16, P17, P18
bxor_done_1:
# end bxor_p_p_p

# the recompiled code could be compacted a bit by some helper opcodes,
# but it shows what could happen

    print P16
    print "\n"

    end

.pcc_sub PerlInt_bxor:
    set I16, P5
    set I17, P6
    bxor I18, I16, I17
    set P7, I18
    invoke P1

[1] would need a flag in loaded byte code too or such

Comments?
leo

Reply via email to