[pypy-svn] r45955 - in pypy/dist/pypy/translator: cli oosupport oosupport/test_template
antocuni at codespeak.net
antocuni at codespeak.net
Fri Aug 24 17:44:32 CEST 2007
Author: antocuni
Date: Fri Aug 24 17:44:30 2007
New Revision: 45955
Modified:
pypy/dist/pypy/translator/cli/ilgenerator.py
pypy/dist/pypy/translator/oosupport/function.py
pypy/dist/pypy/translator/oosupport/test_template/snippets.py
Log:
"how can it ever worked": when evaluating a link we must set the
corresponding variables only if the condition is true. Else, we might
modify a variable even if we should not.
Modified: pypy/dist/pypy/translator/cli/ilgenerator.py
==============================================================================
--- pypy/dist/pypy/translator/cli/ilgenerator.py (original)
+++ pypy/dist/pypy/translator/cli/ilgenerator.py Fri Aug 24 17:44:30 2007
@@ -373,6 +373,9 @@
def branch_if_equal(self, target_label):
self.ilasm.opcode('beq', target_label)
+ def branch_if_not_equal(self, target_label):
+ self.ilasm.opcode('bne.un', target_label)
+
def push_primitive_constant(self, TYPE, value):
ilasm = self.ilasm
if TYPE is ootype.Void:
Modified: pypy/dist/pypy/translator/oosupport/function.py
==============================================================================
--- pypy/dist/pypy/translator/oosupport/function.py (original)
+++ pypy/dist/pypy/translator/oosupport/function.py Fri Aug 24 17:44:30 2007
@@ -230,13 +230,17 @@
def render_numeric_switch_naive(self, block):
for link in block.exits:
target_label = self._get_block_name(link.target)
- self._setup_link(link)
if link.exitcase == 'default':
+ self._setup_link(link)
self.generator.branch_unconditionally(target_label)
else:
+ next_case = self.next_label('next_case')
self.generator.push_primitive_constant(block.exitswitch.concretetype, link.exitcase)
self.generator.load(block.exitswitch)
- self.generator.branch_if_equal(target_label)
+ self.generator.branch_if_not_equal(next_case)
+ self._setup_link(link)
+ self.generator.branch_unconditionally(target_label)
+ self.set_label(next_case)
def _follow_link(self, link):
target_label = self._get_block_name(link.target)
@@ -258,6 +262,13 @@
# 'b' would be overwritten before being read. To solve, we
# first load all the values on the stack, then store in the
# appropriate places.
+
+ if self._trace_enabled():
+ self._trace('link', writeline=True)
+ for to_load, to_store in linkvars:
+ self._trace_value('%s <-- %s' % (to_store, to_load), to_load)
+ self._trace('', writeline=True)
+
for to_load, to_store in linkvars:
self.generator.load(to_load)
for to_load, to_store in reversed(linkvars):
Modified: pypy/dist/pypy/translator/oosupport/test_template/snippets.py
==============================================================================
--- pypy/dist/pypy/translator/oosupport/test_template/snippets.py (original)
+++ pypy/dist/pypy/translator/oosupport/test_template/snippets.py Fri Aug 24 17:44:30 2007
@@ -48,3 +48,16 @@
obj.x = x + y
return obj.x
assert self.interpret(fn, [1,3]) == 4
+
+ def test_link(self):
+ def fn():
+ plus = False
+ for c in 'a':
+ if c == 'b':
+ plus = True
+ elif c == 'c':
+ binary = True
+ return plus
+ res = self.interpret(fn, [])
+ expected = fn()
+ assert res == expected
More information about the Pypy-commit
mailing list