有没有好的Python组件生成模块?

2024-07-04 07:42:47 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在为Python寻找一个好的程序集生成模块。 我找到了这个: PyAsm

但效果不好。 我想执行并生成程序集可执行文件,用于简单的操作,如加法、减法、除法和乘法。 有点像反射。发射.NET中的库。在

我在Linux(Ubuntu12.10 64位)和Python2.7下开发。在

例如,当我试图用PyAsm编译这个简单的子代码时,它会给我一个“分段错误(核心转储)”:

from ctypes import c_int
from pyasm import Program
from pyasm.instructions import push, mov, ret, pop, sub
from pyasm.registers import eax, esp, ebp

def test():
    prog = Program(
        push(ebp),
        mov(ebp, esp),
        mov(eax, ebp.addr+8),
        sub(eax, 10),
        pop(ebp),
        ret(),
    )
    fun = prog.compile(c_int, [c_int])
    assert fun(1234) == 1224

if __name__ == '__main__':
    test()

Tags: fromtestimport程序programpoppushint

热门问题