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)'])
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)'])
def test_storerv_same_nesting_level_in_parameter(self): tbl = SymbolTable() tbl.get_current_nesting_level = MagicMock(return_value=1) tbl.lookup = MagicMock( return_value=LookupResult(ParameterEntity('in_par0', 'cv', 4), 1)) gen = FinalGen(tbl) self.assertEqual(gen.storerv(3, 'in_par0'), ['sw $t3, -4($sp)']) tbl.get_current_nesting_level.assert_called_once() tbl.lookup.assert_called_once_with('in_par0')
def test_storerv_same_nesting_level_temp(self): tbl = SymbolTable() tbl.get_current_nesting_level = MagicMock(return_value=1) tbl.lookup = MagicMock( return_value=LookupResult(TempVariableEntity('temp_var0', 4), 1)) gen = FinalGen(tbl) self.assertEqual(gen.storerv(4, 'temp_var0'), ['sw $t4, -4($sp)']) tbl.get_current_nesting_level.assert_called_once() tbl.lookup.assert_called_once_with('temp_var0')
def test_storerv_global_var(self): tbl = SymbolTable() tbl.get_current_nesting_level = MagicMock(return_value=0) tbl.lookup = MagicMock( return_value=LookupResult(VariableEntity('global_var0', 4), 0)) gen = FinalGen(tbl) self.assertEqual(gen.storerv(2, 'global_var0'), ['sw $t2, -4($s0)']) tbl.get_current_nesting_level.assert_called_once() tbl.lookup.assert_called_once_with('global_var0')