Exemple #1
0
def test_assn6():
    src = \
          '''
          x = a + x
          a = b + 1
          b = c + 1
          c = 1
          x = 1
          x = 2
          '''
    a = gen.Generation(src)
    symtab = a.symbol_pass(SymbolTable())
    numNames = symtab.num_symbols()
    while True:
        a.replace_idents(symtab)
        symtab = a.symbol_pass(symtab)
        if symtab.num_symbols() == numNames:
            break
        numNames = symtab.num_symbols()

    assert symtab.resolveName('c') == ast.Number(1)
    assert symtab.resolveName('b') == ast.Number(2)
    assert symtab.resolveName('a') == ast.Number(3)
    assert symtab.resolveName('x') == ast.Number(2)
    assert symtab.num_symbols() == 4
Exemple #2
0
def assemble_macro(src):
    a = gen.Generation(src)
    symtab = a.symbol_pass(SymbolTable())
    numNames = symtab.num_symbols()
    while True:
        a.replace_idents(symtab)
        symtab = a.symbol_pass(symtab)
        if symtab.num_symbols() == numNames:
            break
        numNames = symtab.num_symbols()
    return symtab
Exemple #3
0
def test_assn4():
    src = \
          '''
          a = b + 1
          b = c + 1
          c = 1
          '''
    a = gen.Generation(src)
    symtab = a.symbol_pass(SymbolTable())
    assert symtab.resolveName('c') == ast.Number(1)
    a.replace_idents(symtab)
    symtab = a.symbol_pass(symtab)
    assert symtab.resolveName('b') == ast.Number(2)
    a.replace_idents(symtab)
    symtab = a.symbol_pass(symtab)
    assert symtab.resolveName('a') == ast.Number(3)
def do_test_generate(src, expected):
    a = gen.Generation(src)
    symtab = a.symbol_pass(SymbolTable())
    numNames = symtab.num_symbols()
    while True:
        a.replace_idents(symtab)
        symtab = a.symbol_pass(symtab)
        if symtab.num_symbols() == numNames:
            break
        numNames = symtab.num_symbols()

    words = a.generate(symtab)
    for w in words:
        print w

    if words != expected:
        print "GENERATED:", words
        print "EXPECTED :", expected
        # print a.ast
        # a.ast.pretty(0)
        util.die()
Exemple #5
0
 def __init__(self, src, include_dirs=()):
     self.gen = gen.Generation(src)
     self.cur_byte = 0
     self.symtab = SymbolTable()
     self.pass1 = []
     self.asm_inst = []
     
     self.symtab = self.gen.symbol_pass(self.symtab)
     # numNames = self.symtab.num_symbols()
     # guard = 0
     
     # while True:
     #     # set a limit to how many passes, just in case.
     #     guard += 1
     #     if guard > 1:
     #         break #util.die("having issues resolving symbols")
         
     #     self.gen.replace_idents(self.symtab)
     #     symtab = self.gen.symbol_pass(self.symtab)
     #     if symtab.num_symbols() == numNames:
     #         break
         
     self.asm_inst = self.gen.generate(self.symtab)
Exemple #6
0
def test_assn1():
    a = gen.Generation("a=1\nb=2\n")
    symtab = a.symbol_pass(SymbolTable())
    assert symtab.num_symbols() == 2
    assert symtab.lookup("a") == ast.Number(1)
    assert symtab.lookup("b") == ast.Number(2)