Skip to content

Commit

Permalink
example1: Cleanup/better structure code.
Browse files Browse the repository at this point in the history
  • Loading branch information
pfalcon committed Oct 15, 2020
1 parent 54d0b34 commit dbfcb76
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions example1.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,25 @@
from jitgen.x86 import *


b = alloc_exec(64)
b = alloc_exec(50)
addr = uctypes.addressof(b)
print("Buf addr:", hex(addr & 0xffffffff))
print("Executable buffer addr:", hex(addr & 0xffffffff))

c = Codegen(b)
c.mov(EAX, 10000)
c.ret()
print(b)
print("code:", hexlify(b))
f = ffi.func("i", addr, "")
print(f)
print(f())
print("result:", f())

c = Codegen(b)
c.push(0)
c.call("mp_obj_new_dict")
c.pop_args(1)
c.ret()
print("code:", hexlify(b))

f = ffi.func("O", uctypes.addressof(b), "")
print(f())
f = ffi.func("O", addr, "")
print("result:", f())

c = Codegen(b)
c.prolog()
Expand All @@ -37,7 +35,6 @@
c.pop_args(2)
c.epilog()
print("code:", hexlify(b))

f = ffi.func("O", uctypes.addressof(b), "O")
f = ffi.func("O", addr, "O")
res = f({1:2})
print("res:", res)
print("result:", res)

0 comments on commit dbfcb76

Please sign in to comment.