Author: Anton Gulenko <anton.gule...@googlemail.com> Branch: strategies-tagging Changeset: r688:98f32dad569e Date: 2014-03-21 12:07 +0100 http://bitbucket.org/pypy/lang-smalltalk/changeset/98f32dad569e/
Log: Fixed bug in strategies implementation and added test. diff --git a/spyvm/strategies.py b/spyvm/strategies.py --- a/spyvm/strategies.py +++ b/spyvm/strategies.py @@ -27,9 +27,11 @@ def store(self, space, w_obj, n0, w_val): if self.can_contain(space, w_val): return self.do_store(space, w_obj, n0, w_val) - new_strategy = find_strategy_for_objects(space, [w_val]) + new_strategy = self.generelized_strategy_for(space, w_val) return w_obj.store_with_new_strategy(space, new_strategy, n0, w_val) + def generelized_strategy_for(self, space, w_val): + raise NotImplementedError("Abstract base class") def can_contain(self, space, w_val): raise NotImplementedError("Abstract base class") def fetch(self, space, w_obj, n0): @@ -73,6 +75,8 @@ def set_storage_copied_from(self, space, w_obj, w_source_obj, reuse_storage=False): w_obj.int_storage = self.copy_storage_from(space, w_source_obj, reuse_storage) + def generelized_strategy_for(self, space, w_val): + return ListStorageStrategy.singleton def initial_storage(self, space, size): raise NotImplementedError("Abstract base class") def storage_for_list(self, space, collection): @@ -104,6 +108,8 @@ def do_store(self, space, w_obj, n0, w_val): pass + def generelized_strategy_for(self, space, w_val): + return find_strategy_for_objects(space, [w_val]) def set_initial_storage(self, space, w_obj, size): pass def set_storage_for_list(self, space, w_obj, collection): diff --git a/spyvm/test/test_strategies.py b/spyvm/test/test_strategies.py --- a/spyvm/test/test_strategies.py +++ b/spyvm/test/test_strategies.py @@ -120,6 +120,12 @@ a.store(space, 1, arr(1)) assert isinstance(a.strategy, strategies.ListStorageStrategy) +def test_SmallInt_store_Float_to_List(): + a = int_arr(5) + a.store(space, 1, space.wrap_float(2.2)) + assert isinstance(a.strategy, strategies.ListStorageStrategy) + check_arr(a, [12, 2.2, w_nil, w_nil, w_nil]) + # ====== FloatOrNil StorageStrategy def test_AllNil_to_Float(): @@ -159,4 +165,9 @@ a.store(space, 1, arr(1)) assert isinstance(a.strategy, strategies.ListStorageStrategy) +def test_Float_store_SmallInt_to_List(): + a = float_arr(5) + a.store(space, 1, space.wrap_int(2)) + assert isinstance(a.strategy, strategies.ListStorageStrategy) + check_arr(a, [1.2, 2, w_nil, w_nil, w_nil]) \ No newline at end of file _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit