from  compyler.codeObjectAssembler import codeObjectAssembler
from pyasm.x86cpToMemory import CpToMemory
import unittest
import cStringIO
import sys
from compyler.test.util import eval_code

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

fib_asm(500000)

"""

loadStoreGlobal = """
a = 0
b = 1

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

fib_asm(500000)

"""

loadStoreAttrs = """

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

fib_asm(500000)

"""

def simpleFunction(*args):
    print args

class test_opcodes_refcounts(unittest.TestCase):
    def test_globals(self):
        self.failUnless(eval_code(loadStoreLocal,"","exec"))
        self.failUnless(eval_code(loadStoreGlobal,"","exec"))
        self.failUnless(eval_code(loadStoreAttrs,"","exec"))

def foo():
    unittest.main()
        
if __name__ == "__main__":
    unittest.main()

