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

"""
DAMN! This is about 3x the speed of bytcode with a string and
even worse with ints!
"""

import gc
gc.set_debug(gc.DEBUG_LEAK)


text = """

   
def recursive_asm(x):
    if x == 0:
        return 0
    else:
        return x + recursive_asm(x-1)

def recursive_string_asm(x):
    if x == 0:
        return "="
    else:
        return "=" + recursive_string_asm(x-1)


"""

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

def recursive_bytecode(x):
    if x == 0:
        return 0
    else:
        return x + recursive_bytecode(x-1)

def recursive_string_bytecode(x):
    if x == 0:
        return "="
    else:
        return "=" + recursive_string_bytecode(x-1)
