Пример #1
0
    def test_storerv_smaller_nesting_level_in_parameter(self):
        tbl = SymbolTable()
        tbl.get_current_nesting_level = MagicMock(return_value=3)
        tbl.lookup = MagicMock(
            return_value=LookupResult(ParameterEntity('in_par0', 'cv', 4), 1))

        gen = FinalGen(tbl)

        self.assertEqual(gen.storerv(3, 'in_par0'),
                         gen.gnlvcode('in_par0') + ['sw $t3, ($t0)'])
Пример #2
0
    def test_loadvr_one_diff_nesting_level_in_parameter(self):
        tbl = SymbolTable()
        tbl.get_current_nesting_level = MagicMock(return_value=2)
        tbl.lookup = MagicMock(
            return_value=LookupResult(ParameterEntity('in_par0', 'cv', 4), 1))

        gen = FinalGen(tbl)

        self.assertEqual(gen.loadvr('in_par0', 1),
                         gen.gnlvcode('in_par0') + ['lw $t1, ($t0)'])
Пример #3
0
    def test_storerv_smaller_nesting_level_local(self):
        tbl = SymbolTable()
        tbl.get_current_nesting_level = MagicMock(return_value=3)
        tbl.lookup = MagicMock(
            return_value=LookupResult(VariableEntity('local_var0', 4), 1))

        gen = FinalGen(tbl)

        self.assertEqual(gen.storerv(1, 'local_var0'),
                         gen.gnlvcode('local_var0') + ['sw $t1, ($t0)'])
Пример #4
0
    def test_gnlvcode_nesting_level_1(self):
        tbl = SymbolTable()
        tbl.get_current_nesting_level = MagicMock(return_value=1)
        tbl.lookup = MagicMock(
            return_value=LookupResult(VariableEntity('var0', 4), 1))

        gen = FinalGen(tbl)

        self.assertEqual(gen.gnlvcode('var0'),
                         ['lw $t0, -4($sp)', 'add $t0, $t0, -4'])
        tbl.get_current_nesting_level.assert_called_once()
        tbl.lookup.assert_called_once_with('var0')