Skip to content

Commit

Permalink
nits
Browse files Browse the repository at this point in the history
  • Loading branch information
timfel committed Feb 12, 2013
1 parent 9e44457 commit 70f7ed8
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 46 deletions.
39 changes: 0 additions & 39 deletions tests/jit/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,42 +67,3 @@ def test_ivar_while_loop(self, topaz, tmpdir):
i50 = arraylen_gc(p24, descr=<ArrayP 8>)
jump(p0, p1, p3, p4, p5, p6, p9, p49, p31, p32, p24, descr=TargetToken(140148740726904))
""")

def test_int_closure_cells(self, topaz, tmpdir):
traces = self.run(topaz, tmpdir, """
a = 1
(1..10_000).each do |i|
a = i
end
""")
self.assert_matches(traces[0].loop, """
label(p0, p1, p3, p4, p5, p6, p7, p9, i78, p14, p20, p22, p24, p26, p29, p31, f51, p45, p44, p66, descr=TargetToken(140411363672184))
debug_merge_point(0, 0, 'each at LOAD_DEREF')
guard_not_invalidated(descr=<Guard21>)
debug_merge_point(0, 0, 'each at LOAD_DEREF')
debug_merge_point(0, 0, 'each at SEND')
i80 = force_token()
f81 = cast_int_to_float(i78)
i82 = float_lt(f81, f51)
guard_true(i82, descr=<Guard22>)
debug_merge_point(0, 0, 'each at JUMP_IF_FALSE')
debug_merge_point(0, 0, 'each at LOAD_DEREF')
debug_merge_point(0, 0, 'each at YIELD')
i83 = force_token()
debug_merge_point(1, 1, 'block in foo at LOAD_DEREF')
debug_merge_point(1, 1, 'block in foo at STORE_DEREF')
debug_merge_point(1, 1, 'block in foo at RETURN')
debug_merge_point(0, 0, 'each at DISCARD_TOP')
debug_merge_point(0, 0, 'each at LOAD_DEREF')
debug_merge_point(0, 0, 'each at LOAD_CONST')
debug_merge_point(0, 0, 'each at SEND')
i84 = force_token()
setfield_gc(p66, i78, descr=<FieldS topaz.closure.IntCell.inst_intvalue 8>)
i85 = int_add_ovf(i78, 1)
guard_no_overflow(descr=<Guard23>)
debug_merge_point(0, 0, 'each at STORE_DEREF')
debug_merge_point(0, 0, 'each at DISCARD_TOP')
debug_merge_point(0, 0, 'each at JUMP')
debug_merge_point(0, 0, 'each at LOAD_DEREF')
jump(p0, p1, p3, p4, p5, p6, p7, p9, i85, p14, p20, p22, p24, p26, p29, p31, f51, p45, p44, p66, descr=TargetToken(140411363672184))
""")
42 changes: 42 additions & 0 deletions tests/jit/test_closure.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
from .base import BaseJITTest


class TestClosure(BaseJITTest):
def test_int_closure_cells(self, topaz, tmpdir):
traces = self.run(topaz, tmpdir, """
a = 1
(1..10_000).each do |i|
a = i
end
""")
self.assert_matches(traces[0].loop, """
label(p0, p1, p3, p4, p5, p6, p7, p9, i78, p14, p20, p22, p24, p26, p29, p31, f51, p45, p44, p66, descr=TargetToken(140411363672184))
debug_merge_point(0, 0, 'each at LOAD_DEREF')
guard_not_invalidated(descr=<Guard21>)
debug_merge_point(0, 0, 'each at LOAD_DEREF')
debug_merge_point(0, 0, 'each at SEND')
i80 = force_token()
f81 = cast_int_to_float(i78)
i82 = float_lt(f81, f51)
guard_true(i82, descr=<Guard22>)
debug_merge_point(0, 0, 'each at JUMP_IF_FALSE')
debug_merge_point(0, 0, 'each at LOAD_DEREF')
debug_merge_point(0, 0, 'each at YIELD')
i83 = force_token()
debug_merge_point(1, 1, 'block in foo at LOAD_DEREF')
debug_merge_point(1, 1, 'block in foo at STORE_DEREF')
debug_merge_point(1, 1, 'block in foo at RETURN')
debug_merge_point(0, 0, 'each at DISCARD_TOP')
debug_merge_point(0, 0, 'each at LOAD_DEREF')
debug_merge_point(0, 0, 'each at LOAD_CONST')
debug_merge_point(0, 0, 'each at SEND')
i84 = force_token()
setfield_gc(p66, i78, descr=<FieldS topaz.closure.IntCell.inst_intvalue 8>)
i85 = int_add_ovf(i78, 1)
guard_no_overflow(descr=<Guard23>)
debug_merge_point(0, 0, 'each at STORE_DEREF')
debug_merge_point(0, 0, 'each at DISCARD_TOP')
debug_merge_point(0, 0, 'each at JUMP')
debug_merge_point(0, 0, 'each at LOAD_DEREF')
jump(p0, p1, p3, p4, p5, p6, p7, p9, i85, p14, p20, p22, p24, p26, p29, p31, f51, p45, p44, p66, descr=TargetToken(140411363672184))
""")
11 changes: 4 additions & 7 deletions topaz/closure.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,18 @@ def upgrade_to_closure(self, space, frame, pos):

class IntCell(ClosureCell):
def __init__(self, intvalue):
self.w_value = None
ClosureCell.__init__(self, None)
self.intvalue = intvalue

def get(self, space, frame, pos):
if not self.w_value:
if self.w_value is None:
return space.newint(self.intvalue)
else:
return self.w_value
return ClosureCell.get(self, space, frame, pos)

def set(self, space, frame, pos, w_value):
if isinstance(w_value, W_FixnumObject):
self.intvalue = space.int_w(w_value)
self.w_value = None
else:
self.w_value = w_value

def upgrade_to_closure(self, space, frame, pos):
return self
ClosureCell.set(self, space, frame, pos, w_value)

0 comments on commit 70f7ed8

Please sign in to comment.