from  compyler.codeObjectAssembler import codeObjectAssembler
from pyasm.x86cpToMemory import CpToMemory
import unittest
import cStringIO
import sys

"""
 Most of the time here is spent in PyLong_Add for any serious sequence.
 Still, it shows that we don't run any slower than CPython.

 There is also a floating point version.  Although this isn't accurate,
 it is a better comparison of interpreted vs. compiled code, since 
 we don't get into the long addition.
"""

import gc
gc.set_debug(gc.DEBUG_LEAK)


text = """

def fib_asm(x):
    a = 0
    b = 1
    for i in range(x):
        a, b = b, a+b

def fib_asm_float(x):
    a = 0.0
    b = 1.0
    for i in range(x):
        a, b = b, a+b

"""

x = codeObjectAssembler()
co = compile(text,"","exec")
assem = x.assembleCodeObject(co)
mem = CpToMemory(assem)
mem.MakeMemory()
mem.BindPythonFunctions(globals())
main()

def fib_bytecode(x):
    a = 0
    b = 1
    for i in range(x):
        a, b = b, a+b

def fib_bytecode_float(x):
    a = 0.0
    b = 1.0
    for i in range(x):
        a, b = b, a+b

        
