예제 #1
0
    def test_arg(self):
        st = SymbolTable()
        st.arg('a')
        st.arg('b')

        self.assertEquals(st.fetch('a'), Symbol('a', 'auto', 2))
        self.assertEquals(st.fetch('b'), Symbol('b', 'auto', 3))
        self.assertEquals(st.auto_count, 0)
예제 #2
0
    def test_auto(self):
        st = SymbolTable()
        st.auto('x')
        st.auto('y')

        self.assertEquals(st.fetch('x'), Symbol('x', 'auto', -1))
        self.assertEquals(st.fetch('y'), Symbol('y', 'auto', -2))
        self.assertEquals(st.auto_count, 2)
예제 #3
0
    def test_label(self):
        st = SymbolTable()
        st.fetch('x')
        st.label('x', 7)

        sym = st.fetch('x')
        self.assertEquals(sym.kind, 'label')
        self.assertEquals(sym.addr, 7)
        self.assertEquals(st.auto_count, 0)
예제 #4
0
 def test_implicit_label(self):
     st = SymbolTable()
     st.fetch('x')
     self.assertEquals(st.fetch('x').kind, 'label')
     self.assertEquals(st.auto_count, 0)
예제 #5
0
    def test_label_redeclaration(self):
        st = SymbolTable()
        st.auto('x')
        st.extrn('y')
        st.arg('z')

        # Cannot use a variable as a label and then declare it as a different
        # type.
        with self.assertRaises(Redeclaration):
            st.label('x', 7)
        with self.assertRaises(Redeclaration):
            st.label('y', 8)
        with self.assertRaises(Redeclaration):
            st.label('z', 9)
예제 #6
0
    def test_redeclaration(self):
        st = SymbolTable()
        st.auto('x')

        with self.assertRaises(Redeclaration):
            st.auto('x')
        with self.assertRaises(Redeclaration):
            st.arg('x')
        with self.assertRaises(Redeclaration):
            st.label('x', 7)
        with self.assertRaises(Redeclaration):
            st.extrn('x')
예제 #7
0
 def test_implicit_extrn(self):
     st = SymbolTable()
     st.fetch('x', True)
     self.assertEquals(st.fetch('x').kind, 'extrn')
     self.assertEquals(st.auto_count, 0)