コード例 #1
0
ファイル: macro.py プロジェクト: evilpie/python-js-jit
def log(name, operand, type=c_int):
    if isinstance(operand, Register):
        if isinstance(operand, st):
            type = c_float
            push_fun = [
                sub(esp, 4),
                mov(ebp, esp),
                fld(operand),
                fstp(ebp.addr),
            ]
        else:
            push_fun = push(operand)

        @function(None, type)
        def _debug(value):
            print(name % value)

        return [
            push(eax),
            push(ebx),
            push(ecx),
            push(edx),
            push(ebp),
            push_fun,
            mov(eax, _debug),
            call(eax),
            add(esp, 4),
            pop(ebp),
            pop(edx),
            pop(ecx),
            pop(ebx),
            pop(eax),
        ]
    else:
        raise Exception('operand is not suited: %s' % operand)
コード例 #2
0
ファイル: macro.py プロジェクト: evilpie/python-js-jit
def log(name, operand, type=c_int):
    if isinstance(operand, Register):
        if isinstance(operand, st):
            type = c_float
            push_fun = [
                sub(esp, 4),
                mov(ebp, esp),
                fld(operand),
                fstp(ebp.addr),
            ]
        else:
            push_fun = push(operand)
        @function(None, type)
        def _debug(value):
            print(name % value)
        return [
            push(eax),
            push(ebx),
            push(ecx),
            push(edx),
            push(ebp),
            push_fun,
            mov(eax, _debug),
            call(eax),
            add(esp, 4),
            pop(ebp),
            pop(edx),
            pop(ecx),
            pop(ebx),
            pop(eax),
        ]
    else:
        raise Exception('operand is not suited: %s' % operand)
コード例 #3
0
def test():
    prog = Program(
        push(ebp),
        mov(ebp, esp),
        mov(eax, foo),
        push(1234),
        call(eax),
        add(esp, 4),
        pop(ebp),
        ret(),
    )
    fun = prog.compile()
    fun()
    assert called == 1234
コード例 #4
0
ファイル: test_call.py プロジェクト: evilpie/python-js-jit
def test():
    prog = Program(
        push(ebp),
        mov(ebp, esp),

        mov(eax, foo),
        push(1234),
        call(eax),
        add(esp, 4),
        
        pop(ebp),
        ret(),
    )
    fun = prog.compile()
    fun()
    assert called == 1234
コード例 #5
0
def test_float():
    prog = Program(
        push(ebp),
        mov(ebp, esp),
        fld(ebp.addr + 8),
        sub(esp, 4),
        mov(ebp, esp),
        fstp(ebp.addr),
        mov(eax, bar),
        call(eax),
        add(esp, 4),
        pop(ebp),
        ret(),
    )
    fun = prog.compile(None, [c_float])
    fun(1234.5)
    assert called == 1234.5
コード例 #6
0
ファイル: test_call.py プロジェクト: evilpie/python-js-jit
def test_float():
    prog = Program(
        push(ebp),
        mov(ebp, esp),
        
        fld(ebp.addr+8),
        sub(esp, 4),
        mov(ebp, esp),
        fstp(ebp.addr),
        mov(eax, bar),
        call(eax),
        add(esp, 4),
        
        pop(ebp),
        ret(),
    )
    fun = prog.compile(None, [c_float])
    fun(1234.5)
    assert called == 1234.5