rem
stringlengths 0
322k
| add
stringlengths 0
2.05M
| context
stringlengths 8
228k
|
---|---|---|
self.check_loops(getfield_raw=1, call=0, call_pure=0)
|
self.check_loops(getfield_raw=1, setfield_raw=1, call=0, call_pure=0)
|
def f(n): x = X() while n > 0: myjitdriver.can_enter_jit(n=n, x=x) myjitdriver.jit_merge_point(n=n, x=x) x.foo = n n -= 1 if action.get() != 0: break action.set(0) return 42
|
expected = """
|
preamble = """
|
def test_merge_guard_class_guard_value(self): ops = """ [p1, i0, i1, i2, p2] guard_class(p1, ConstClass(node_vtable)) [i0] i3 = int_add(i1, i2) guard_value(p1, ConstPtr(myptr)) [i1] jump(p2, i0, i1, i3, p2) """ expected = """ [p1, i0, i1, i2, p2] guard_value(p1, ConstPtr(myptr)) [i0] i3 = int_add(i1, i2) jump(p2, i0, i1, i3, p2) """ self.optimize_loop(ops, expected)
|
jump(p2, i0, i1, i3, p2) """ self.optimize_loop(ops, expected)
|
jump(p2, i0, i1, i3) """ expected = """ [p2, i0, i1, i2] guard_value(p2, ConstPtr(myptr)) [i0] i3 = int_add(i1, i2) jump(ConstPtr(myptr), i0, i1, i3) """ self.optimize_loop(ops, expected, preamble)
|
def test_merge_guard_class_guard_value(self): ops = """ [p1, i0, i1, i2, p2] guard_class(p1, ConstClass(node_vtable)) [i0] i3 = int_add(i1, i2) guard_value(p1, ConstPtr(myptr)) [i1] jump(p2, i0, i1, i3, p2) """ expected = """ [p1, i0, i1, i2, p2] guard_value(p1, ConstPtr(myptr)) [i0] i3 = int_add(i1, i2) jump(p2, i0, i1, i3, p2) """ self.optimize_loop(ops, expected)
|
return RegrDirectory(path, parent)
|
if path.basename == "test": return RegrDirectory(path, parent)
|
def pytest_collect_directory(parent, path): return RegrDirectory(path, parent)
|
print "Loop contains ops not in preamble???"
|
def create_short_preamble(self, preamble, preambleargs, loop, inputargs, token): #return None # Dissable short_preamble = [] loop_i = preamble_i = 0 while loop_i < len(loop)-1 and preamble_i < len(preamble)-1: if self.sameop(preamble[preamble_i], loop[loop_i]): loop_i += 1 preamble_i += 1 else: short_preamble.append(preamble[preamble_i]) preamble_i += 1
|
|
print "Unable to find all input arguments???"
|
def create_short_preamble(self, preamble, preambleargs, loop, inputargs, token): #return None # Dissable short_preamble = [] loop_i = preamble_i = 0 while loop_i < len(loop)-1 and preamble_i < len(preamble)-1: if self.sameop(preamble[preamble_i], loop[loop_i]): loop_i += 1 preamble_i += 1 else: short_preamble.append(preamble[preamble_i]) preamble_i += 1
|
|
print "Op arguments not produced???"
|
def create_short_preamble(self, preamble, preambleargs, loop, inputargs, token): #return None # Dissable short_preamble = [] loop_i = preamble_i = 0 while loop_i < len(loop)-1 and preamble_i < len(preamble)-1: if self.sameop(preamble[preamble_i], loop[loop_i]): loop_i += 1 preamble_i += 1 else: short_preamble.append(preamble[preamble_i]) preamble_i += 1
|
|
if len(lines) > 100: lines = lines[100:] + ["%d more lines..." % (len(lines) - 100)]
|
if len(lines) > LINE_CUTOFF: lines = lines[:LINE_CUTOFF] + ["%d more lines..." % (len(lines) - LINE_CUTOFF)]
|
def postprocess_loop(loop, loops, memo): if loop in memo: return memo.add(loop) if loop is None: return m = re.search("debug_merge_point\('<code object (.*?)> (.*?)'", loop.content) if m is None: name = '?' else: name = m.group(1) + " " + m.group(2) opsno = loop.content.count("\n") lastline = loop.content[loop.content.rfind("\n", 0, len(loop.content) - 2):] m = re.search('descr=<Loop(\d+)', lastline) if m is not None: assert isinstance(loop, FinalBlock) loop.target = loops[int(m.group(1))] bcodes = loop.content.count('debug_merge_point') loop.linksource = "loop" + str(loop.no) loop.header = "%s loop%d\n%d operations\n%d opcodes" % (name, loop.no, opsno, bcodes) loop.header += "\n" * (opsno / 100) if bcodes == 0: loop.ratio = opsno else: loop.ratio = float(opsno) / bcodes content = loop.content lines = content.split("\n") if len(lines) > 100: lines = lines[100:] + ["%d more lines..." % (len(lines) - 100)] for i, line in enumerate(lines): lines[i] = re.sub("\[.*\]", "", line) loop.content = "Logfile at %d\n" % loop.startlineno + "\n".join(lines) loop.postprocess(loops, memo)
|
if self.standalone:
|
if self.standalone and self.exe_name is not None:
|
def task_compile_c(self): """ Compile the generated C code using either makefile or translator/platform """ cbuilder = self.cbuilder kwds = {} if self.standalone: kwds['exe_name'] = self.compute_exe_name().basename cbuilder.compile(**kwds)
|
def ptr_access_expr(self, baseexpr, index):
|
def ptr_access_expr(self, baseexpr, index, dummy=False):
|
def ptr_access_expr(self, baseexpr, index): assert 0 <= index <= sys.maxint, "invalid constant index %r" % (index,) return self.itemindex_access_expr(baseexpr, index)
|
def access_expr(self, baseexpr, index):
|
def access_expr(self, baseexpr, index, dummy=False):
|
def access_expr(self, baseexpr, index): if not isinstance(index, int): assert index.startswith('item') index = int(index[4:]) if not (0 <= index < self.FIXEDARRAY.length): raise IndexError("refusing to generate a statically out-of-bounds" " array indexing") return '%s[%d]' % (baseexpr, index)
|
if start < 0:
|
if check_bounds and start < 0:
|
def array_get_slice_params(self, index): if index.step is not None: raise TypeError("3 arg slices not supported (for no reason)") if index.start is not None: start = index.start if start < 0: start = 0 else: start = 0 if index.stop is not None: stop = index.stop if stop > self._length_: stop = self._length_ else: stop = self._length_ return start, stop
|
if stop > self._length_:
|
if check_bounds and stop > self._length_:
|
def array_get_slice_params(self, index): if index.step is not None: raise TypeError("3 arg slices not supported (for no reason)") if index.start is not None: start = index.start if start < 0: start = 0 else: start = 0 if index.stop is not None: stop = index.stop if stop > self._length_: stop = self._length_ else: stop = self._length_ return start, stop
|
W_DataInstance.__init__(self, space, shape.size * length, address)
|
memsize = shape.size * length if memsize < 8: memsize = 8 W_DataInstance.__init__(self, space, memsize, address)
|
def __init__(self, space, shape, length, address=r_uint(0)): W_DataInstance.__init__(self, space, shape.size * length, address) self.length = length self.shape = shape
|
i = 0
|
i = 1
|
def portal(codeno, frame): i = 0 while 1: driver.jit_merge_point(codeno=codeno, i=i, frame=frame) if i == 1: if frame.j == 0: return portal(2, Frame(frame.j - 1)) elif i == 3: return i += 1 driver.can_enter_jit(codeno=codeno, i=i, frame=frame)
|
if i == 1:
|
if (i >> 1) == 1:
|
def portal(codeno, frame): i = 0 while 1: driver.jit_merge_point(codeno=codeno, i=i, frame=frame) if i == 1: if frame.j == 0: return portal(2, Frame(frame.j - 1)) elif i == 3: return i += 1 driver.can_enter_jit(codeno=codeno, i=i, frame=frame)
|
elif i == 3:
|
elif i == 5:
|
def portal(codeno, frame): i = 0 while 1: driver.jit_merge_point(codeno=codeno, i=i, frame=frame) if i == 1: if frame.j == 0: return portal(2, Frame(frame.j - 1)) elif i == 3: return i += 1 driver.can_enter_jit(codeno=codeno, i=i, frame=frame)
|
main(2, 50)
|
main(2, 5)
|
def main(codeno, j): portal(codeno, Frame(j))
|
self.meta_interp(main, [2, 20], inline=True) self.check_loops(call_assembler=1, call_may_force=0,
|
self.meta_interp(main, [2, 5], inline=True) self.check_loops(call_assembler=2, call_may_force=0,
|
def my_ctc(*args): looptoken = original_ctc(*args) trace.append(looptoken) return looptoken
|
assert isinstance(s_key, annmodel.SomeString)
|
assert annmodel.SomeString(can_be_None=True).contains(s_key)
|
def method_get(self, s_key): assert isinstance(s_key, annmodel.SomeString) return annmodel.SomeInstance(self.valueclassdef, can_be_None=True)
|
print "trying fast call"
|
def call(self, cppthis, args_w): if self.executor is None: raise OperationError(self.space.w_TypeError, self.space.wrap("return type not handled"))
|
|
print "failed"
|
def call(self, cppthis, args_w): if self.executor is None: raise OperationError(self.space.w_TypeError, self.space.wrap("return type not handled"))
|
|
if self.instance.__name__ == 'jit_merge_point': self.annotate_hooks(**kwds_s)
|
def compute_result_annotation(self, **kwds_s): from pypy.annotation import model as annmodel driver = self.instance.im_self keys = kwds_s.keys() keys.sort() expected = ['s_' + name for name in driver.greens + driver.reds if '.' not in name] expected.sort() if keys != expected: raise JitHintError("%s expects the following keyword " "arguments: %s" % (self.instance, expected))
|
|
self.annotate_hook(driver.get_jitcell_at, driver.greens, **kwds_s) self.annotate_hook(driver.set_jitcell_at, driver.greens, [s_jitcell], **kwds_s) self.annotate_hook(driver.get_printable_location, driver.greens, **kwds_s)
|
h = self.annotate_hook return (h(driver.get_jitcell_at, driver.greens, **kwds_s) and h(driver.set_jitcell_at, driver.greens, [s_jitcell], **kwds_s) and h(driver.get_printable_location, driver.greens, **kwds_s))
|
def annotate_hooks(self, **kwds_s): driver = self.instance.im_self s_jitcell = self.bookkeeper.valueoftype(BaseJitCell) self.annotate_hook(driver.get_jitcell_at, driver.greens, **kwds_s) self.annotate_hook(driver.set_jitcell_at, driver.greens, [s_jitcell], **kwds_s) self.annotate_hook(driver.get_printable_location, driver.greens, **kwds_s)
|
return
|
return True
|
def annotate_hook(self, func, variables, args_s=[], **kwds_s): if func is None: return bk = self.bookkeeper s_func = bk.immutablevalue(func) uniquekey = 'jitdriver.%s' % func.func_name args_s = args_s[:] for name in variables: if '.' not in name: s_arg = kwds_s['s_' + name] else: objname, fieldname = name.split('.') s_instance = kwds_s['s_' + objname] s_arg = s_instance.classdef.about_attribute(fieldname) assert s_arg is not None args_s.append(s_arg) bk.emulate_pbc_call(uniquekey, s_func, args_s)
|
assert s_arg is not None
|
if s_arg is None: return False
|
def annotate_hook(self, func, variables, args_s=[], **kwds_s): if func is None: return bk = self.bookkeeper s_func = bk.immutablevalue(func) uniquekey = 'jitdriver.%s' % func.func_name args_s = args_s[:] for name in variables: if '.' not in name: s_arg = kwds_s['s_' + name] else: objname, fieldname = name.split('.') s_instance = kwds_s['s_' + objname] s_arg = s_instance.classdef.about_attribute(fieldname) assert s_arg is not None args_s.append(s_arg) bk.emulate_pbc_call(uniquekey, s_func, args_s)
|
return "%r codec can't decode byte 0x%02x in position %d: %s"%(
|
return "'%s' codec can't decode byte 0x%02x in position %d: %s"%(
|
def descr_str(self, space): return space.appexec([self], """(self): if self.end == self.start + 1: return "%r codec can't decode byte 0x%02x in position %d: %s"%( self.encoding, ord(self.object[self.start]), self.start, self.reason) return "%r codec can't decode bytes in position %d-%d: %s" % ( self.encoding, self.start, self.end - 1, self.reason) """)
|
return "%r codec can't decode bytes in position %d-%d: %s" % (
|
return "'%s' codec can't decode bytes in position %d-%d: %s" % (
|
def descr_str(self, space): return space.appexec([self], """(self): if self.end == self.start + 1: return "%r codec can't decode byte 0x%02x in position %d: %s"%( self.encoding, ord(self.object[self.start]), self.start, self.reason) return "%r codec can't decode bytes in position %d-%d: %s" % ( self.encoding, self.start, self.end - 1, self.reason) """)
|
def setup_initial_paths(executable, nanos, ignore_environment=False, **extra): global os os = nanos
|
def setup_initial_paths(executable, ignore_environment=False, **extra):
|
def setup_initial_paths(executable, nanos, ignore_environment=False, **extra): # a substituted os if we are translated global os os = nanos # find the full path to the executable, assuming that if there is no '/' # in the provided one then we must look along the $PATH if we_are_translated() and IS_WINDOWS and not executable.lower().endswith('.exe'): executable += '.exe' if os.sep in executable or (IS_WINDOWS and DRIVE_LETTER_SEP in executable): pass # the path is already more than just an executable name else: path = os.getenv('PATH') if path: for dir in path.split(os.pathsep): fn = os.path.join(dir, executable) if os.path.isfile(fn): executable = fn break sys.executable = os.path.abspath(executable) newpath = get_library_path(executable) readenv = not ignore_environment path = readenv and os.getenv('PYTHONPATH') if path: newpath = path.split(os.pathsep) + newpath # remove duplicates _seen = {} del sys.path[:] for dir in newpath: if dir not in _seen: sys.path.append(dir) _seen[dir] = True
|
setup_initial_paths(executable, nanos, **cmdline)
|
setup_initial_paths(executable, **cmdline)
|
def entry_point(executable, argv, nanos): try: cmdline = parse_command_line(argv) except CommandLineError, e: print_error(str(e)) return 2 setup_initial_paths(executable, nanos, **cmdline) return run_command_line(**cmdline)
|
s = rffi.wcharpsize2unicode(rffi.cast(rffi.CCHARP, address), maxlength)
|
s = rffi.wcharpsize2unicode(rffi.cast(rffi.CWCHARP, address), maxlength)
|
def wcharp2rawunicode(space, address, maxlength=-1): if maxlength == -1: return wcharp2unicode(space, address) s = rffi.wcharpsize2unicode(rffi.cast(rffi.CCHARP, address), maxlength) return space.wrap(s)
|
raise BufferTooShort(space, rffi.charpsize2str(newbuf, res))
|
raise BufferTooShort(space, space.wrap( rffi.charpsize2str(newbuf, res)))
|
def recv_bytes_into(self, space, w_buffer, offset=0): rwbuffer = space.rwbuffer_w(w_buffer) length = rwbuffer.getlength()
|
def setitem((p, obj)):
|
def setitem((p, obj), s_value):
|
def setitem((p, obj)): assert False,"ptr %r setitem index not an int: %r" % (p.ll_ptrtype, obj)
|
last_instr = hint(self.frame.last_instr, promote=True)
|
last_instr = jit.hint(self.frame.last_instr, promote=True)
|
def send_ex(self, w_arg, exc=False): space = self.space if self.running: raise OperationError(space.w_ValueError, space.wrap('generator already executing')) if self.frame.frame_finished_execution: raise OperationError(space.w_StopIteration, space.w_None) # XXX it's not clear that last_instr should be promoted at all # but as long as it is necessary for call_assembler, let's do it early last_instr = hint(self.frame.last_instr, promote=True) if last_instr == -1: if w_arg and not space.is_w(w_arg, space.w_None): msg = "can't send non-None value to a just-started generator" raise OperationError(space.w_TypeError, space.wrap(msg)) else: if not w_arg: w_arg = space.w_None self.running = True try: try: w_result = self.frame.execute_generator_frame(w_arg, exc) except OperationError: # errors finish a frame self.frame.frame_finished_execution = True raise # if the frame is now marked as finished, it was RETURNed from if self.frame.frame_finished_execution: raise OperationError(space.w_StopIteration, space.w_None) else: return w_result # YIELDed finally: self.frame.f_backref = jit.vref_None self.running = False
|
if platform.name == 'darwin':
|
if platform.name.startswith('darwin'):
|
def first(self): platform = self.compiler.platform if platform.name == 'darwin': # XXX incredible hack for darwin cfiles = self.compiler.cfiles STR = '/*--no-profiling-for-this-file!--*/' no_prof = [] prof = [] for cfile in self.compiler.cfiles: if STR in cfile.read(): no_prof.append(cfile) else: prof.append(cfile) p_eci = self.compiler.eci.merge( ExternalCompilationInfo(compile_extra=['-fprofile-generate'], link_extra=['-fprofile-generate'])) ofiles = platform._compile_o_files(prof, p_eci) _, eci = self.compiler.eci.get_module_files() ofiles += platform._compile_o_files(no_prof, eci) return platform._finish_linking(ofiles, p_eci, None, True) else: return self.build('-fprofile-generate')
|
assert isinstance(_hashlib.new('md5'), _hashlib.HASH)
|
assert _hashlib.new('md5').__class__.__name__ == 'HASH'
|
def test_simple(self): import _hashlib assert isinstance(_hashlib.new('md5'), _hashlib.HASH) assert len(_hashlib.new('md5').hexdigest()) == 32
|
ri_op(self.mc, res.value, l0.value, imm=l1.getint(), cond=fcond)
|
ri_op(self.mc, res.value, l0.value, imm=l1.value, cond=fcond)
|
def f(self, op, regalloc, fcond): assert fcond is not None a0 = op.getarg(0) a1 = op.getarg(1) boxes = list(op.getarglist()) imm_a0 = self._check_imm_arg(a0, imm_size, allow_zero=allow_zero) imm_a1 = self._check_imm_arg(a1, imm_size, allow_zero=allow_zero) if not imm_a0 and imm_a1: l0, box = self._ensure_value_is_boxed(a0, regalloc) boxes.append(box) l1 = regalloc.make_sure_var_in_reg(a1, boxes) elif commutative and imm_a0 and not imm_a1: l1 = regalloc.make_sure_var_in_reg(a0, boxes) l0, box = self._ensure_value_is_boxed(a1, regalloc, boxes) boxes.append(box) else: l0, box = self._ensure_value_is_boxed(a0, regalloc, boxes) boxes.append(box) l1, box = self._ensure_value_is_boxed(a1, regalloc, boxes) boxes.append(box) res = regalloc.force_allocate_reg(op.result, boxes) regalloc.possibly_free_vars(boxes) regalloc.possibly_free_var(op.result)
|
args = op.getarglist()
|
boxes = list(op.getarglist())
|
def f(self, op, regalloc, fcond): assert fcond is not None args = op.getarglist() if not inverse: arg0 = op.getarg(0) arg1 = op.getarg(1) else: arg0 = op.getarg(1) arg1 = op.getarg(0) # XXX consider swapping argumentes if arg0 is const imm_a0 = self._check_imm_arg(arg0) imm_a1 = self._check_imm_arg(arg1) if imm_a1 and not imm_a0: l0 = regalloc.make_sure_var_in_reg(arg0, args, imm_fine=False) l1 = regalloc.make_sure_var_in_reg(arg1, args) res = regalloc.force_allocate_reg(op.result) self.mc.CMP_ri(l0.value, imm=l1.getint(), cond=fcond) else: l0 = regalloc.make_sure_var_in_reg(arg0, args, imm_fine=False) l1 = regalloc.make_sure_var_in_reg(arg1, args, imm_fine=False) res = regalloc.force_allocate_reg(op.result) self.mc.CMP_rr(l0.value, l1.value, cond=fcond)
|
arg0 = op.getarg(0) arg1 = op.getarg(1)
|
arg0, arg1 = boxes
|
def f(self, op, regalloc, fcond): assert fcond is not None args = op.getarglist() if not inverse: arg0 = op.getarg(0) arg1 = op.getarg(1) else: arg0 = op.getarg(1) arg1 = op.getarg(0) # XXX consider swapping argumentes if arg0 is const imm_a0 = self._check_imm_arg(arg0) imm_a1 = self._check_imm_arg(arg1) if imm_a1 and not imm_a0: l0 = regalloc.make_sure_var_in_reg(arg0, args, imm_fine=False) l1 = regalloc.make_sure_var_in_reg(arg1, args) res = regalloc.force_allocate_reg(op.result) self.mc.CMP_ri(l0.value, imm=l1.getint(), cond=fcond) else: l0 = regalloc.make_sure_var_in_reg(arg0, args, imm_fine=False) l1 = regalloc.make_sure_var_in_reg(arg1, args, imm_fine=False) res = regalloc.force_allocate_reg(op.result) self.mc.CMP_rr(l0.value, l1.value, cond=fcond)
|
arg0 = op.getarg(1) arg1 = op.getarg(0)
|
arg1, arg0 = boxes
|
def f(self, op, regalloc, fcond): assert fcond is not None args = op.getarglist() if not inverse: arg0 = op.getarg(0) arg1 = op.getarg(1) else: arg0 = op.getarg(1) arg1 = op.getarg(0) # XXX consider swapping argumentes if arg0 is const imm_a0 = self._check_imm_arg(arg0) imm_a1 = self._check_imm_arg(arg1) if imm_a1 and not imm_a0: l0 = regalloc.make_sure_var_in_reg(arg0, args, imm_fine=False) l1 = regalloc.make_sure_var_in_reg(arg1, args) res = regalloc.force_allocate_reg(op.result) self.mc.CMP_ri(l0.value, imm=l1.getint(), cond=fcond) else: l0 = regalloc.make_sure_var_in_reg(arg0, args, imm_fine=False) l1 = regalloc.make_sure_var_in_reg(arg1, args, imm_fine=False) res = regalloc.force_allocate_reg(op.result) self.mc.CMP_rr(l0.value, l1.value, cond=fcond)
|
l0 = regalloc.make_sure_var_in_reg(arg0, args, imm_fine=False) l1 = regalloc.make_sure_var_in_reg(arg1, args) res = regalloc.force_allocate_reg(op.result)
|
l1 = regalloc.make_sure_var_in_reg(arg1, boxes) else: l1, box = self._ensure_value_is_boxed(arg1, regalloc, forbidden_vars=boxes) boxes.append(box) res = regalloc.force_allocate_reg(op.result) regalloc.possibly_free_vars(boxes) regalloc.possibly_free_var(op.result) inv = c.get_opposite_of(condition) if l1.is_imm():
|
def f(self, op, regalloc, fcond): assert fcond is not None args = op.getarglist() if not inverse: arg0 = op.getarg(0) arg1 = op.getarg(1) else: arg0 = op.getarg(1) arg1 = op.getarg(0) # XXX consider swapping argumentes if arg0 is const imm_a0 = self._check_imm_arg(arg0) imm_a1 = self._check_imm_arg(arg1) if imm_a1 and not imm_a0: l0 = regalloc.make_sure_var_in_reg(arg0, args, imm_fine=False) l1 = regalloc.make_sure_var_in_reg(arg1, args) res = regalloc.force_allocate_reg(op.result) self.mc.CMP_ri(l0.value, imm=l1.getint(), cond=fcond) else: l0 = regalloc.make_sure_var_in_reg(arg0, args, imm_fine=False) l1 = regalloc.make_sure_var_in_reg(arg1, args, imm_fine=False) res = regalloc.force_allocate_reg(op.result) self.mc.CMP_rr(l0.value, l1.value, cond=fcond)
|
l0 = regalloc.make_sure_var_in_reg(arg0, args, imm_fine=False) l1 = regalloc.make_sure_var_in_reg(arg1, args, imm_fine=False) res = regalloc.force_allocate_reg(op.result)
|
def f(self, op, regalloc, fcond): assert fcond is not None args = op.getarglist() if not inverse: arg0 = op.getarg(0) arg1 = op.getarg(1) else: arg0 = op.getarg(1) arg1 = op.getarg(0) # XXX consider swapping argumentes if arg0 is const imm_a0 = self._check_imm_arg(arg0) imm_a1 = self._check_imm_arg(arg1) if imm_a1 and not imm_a0: l0 = regalloc.make_sure_var_in_reg(arg0, args, imm_fine=False) l1 = regalloc.make_sure_var_in_reg(arg1, args) res = regalloc.force_allocate_reg(op.result) self.mc.CMP_ri(l0.value, imm=l1.getint(), cond=fcond) else: l0 = regalloc.make_sure_var_in_reg(arg0, args, imm_fine=False) l1 = regalloc.make_sure_var_in_reg(arg1, args, imm_fine=False) res = regalloc.force_allocate_reg(op.result) self.mc.CMP_rr(l0.value, l1.value, cond=fcond)
|
|
inv = c.get_opposite_of(condition)
|
def f(self, op, regalloc, fcond): assert fcond is not None args = op.getarglist() if not inverse: arg0 = op.getarg(0) arg1 = op.getarg(1) else: arg0 = op.getarg(1) arg1 = op.getarg(0) # XXX consider swapping argumentes if arg0 is const imm_a0 = self._check_imm_arg(arg0) imm_a1 = self._check_imm_arg(arg1) if imm_a1 and not imm_a0: l0 = regalloc.make_sure_var_in_reg(arg0, args, imm_fine=False) l1 = regalloc.make_sure_var_in_reg(arg1, args) res = regalloc.force_allocate_reg(op.result) self.mc.CMP_ri(l0.value, imm=l1.getint(), cond=fcond) else: l0 = regalloc.make_sure_var_in_reg(arg0, args, imm_fine=False) l1 = regalloc.make_sure_var_in_reg(arg1, args, imm_fine=False) res = regalloc.force_allocate_reg(op.result) self.mc.CMP_rr(l0.value, l1.value, cond=fcond)
|
|
regalloc.possibly_free_vars([arg0, arg1, op.result])
|
def f(self, op, regalloc, fcond): assert fcond is not None args = op.getarglist() if not inverse: arg0 = op.getarg(0) arg1 = op.getarg(1) else: arg0 = op.getarg(1) arg1 = op.getarg(0) # XXX consider swapping argumentes if arg0 is const imm_a0 = self._check_imm_arg(arg0) imm_a1 = self._check_imm_arg(arg1) if imm_a1 and not imm_a0: l0 = regalloc.make_sure_var_in_reg(arg0, args, imm_fine=False) l1 = regalloc.make_sure_var_in_reg(arg1, args) res = regalloc.force_allocate_reg(op.result) self.mc.CMP_ri(l0.value, imm=l1.getint(), cond=fcond) else: l0 = regalloc.make_sure_var_in_reg(arg0, args, imm_fine=False) l1 = regalloc.make_sure_var_in_reg(arg1, args, imm_fine=False) res = regalloc.force_allocate_reg(op.result) self.mc.CMP_rr(l0.value, l1.value, cond=fcond)
|
|
''', 100, ([], 4999450000L))
|
''', 170, ([], 4999450000L))
|
def f(a,b): if a < 0: return -1 return a-b
|
charp2rawstring.unwrap_spec = [ObjSpace, r_uint, int]
|
wcharp2rawunicode.unwrap_spec = [ObjSpace, r_uint, int]
|
def wcharp2rawunicode(space, address, maxlength=-1): if maxlength == -1: return wcharp2unicode(space, address) s = rffi.wcharpsize2unicode(rffi.cast(rffi.CCHARP, address), maxlength) return space.wrap(s)
|
assert str(float("inf")).startswith("inf") assert str(float("-INf")).startswith("-inf") assert str(float("-nAn")).startswith("nan")
|
inf = 1e200*1e200 assert float("inf") == inf assert float("-INf") == -inf assert 'nan' in str(float("-nAn")).lower()
|
def test_float_string(self): assert 42 == float("42") assert 42.25 == float("42.25") assert str(float("inf")).startswith("inf") assert str(float("-INf")).startswith("-inf") assert str(float("-nAn")).startswith("nan")
|
return already_warned(space, w_registry, w_altkey, should_set=True)
|
return already_warned(space, w_registry, w_key, should_set=True)
|
def update_registry(space, w_registry, w_text, w_category): w_key = space.newtuple([w_text, w_category]) return already_warned(space, w_registry, w_altkey, should_set=True)
|
filename = filename[:-3]
|
n = len(filename) - 3 assert n >= 0 filename = filename[:n]
|
def normalize_module(space, w_filename): if not space.is_true(w_filename): return space.wrap("<unknown>") filename = space.str_w(w_filename) length = len(filename) if filename.endswith(".py"): filename = filename[:-3] return space.wrap(filename)
|
message = " %s\n" % (line[i:],)
|
def show_warning(space, w_filename, lineno, w_text, w_category, w_sourceline=None): w_name = space.getattr(w_category, space.wrap("__name__")) w_stderr = space.sys.get("stderr") # Print "filename:lineno: category: text\n" message = "%s:%d: %s: %s\n" % (space.str_w(w_filename), lineno, space.str_w(w_name), space.str_w(w_text)) space.call_method(w_stderr, "write", space.wrap(message)) # Print " source_line\n" if w_sourceline: line = space.str_w(w_sourceline) for i in range(len(line)): c = line[i] if c not in ' \t\014': break message = " %s\n" % (line[i:],) space.call_method(w_stderr, "write", space.wrap(message))
|
|
def warn_with_loader(space, w_message, w_category, w_filename, lineno, w_module, w_registry, w_globals):
|
def get_source_line(space, w_globals, lineno): if space.is_w(w_globals, space.w_None): return None
|
def warn_with_loader(space, w_message, w_category, w_filename, lineno, w_module, w_registry, w_globals): # Check/get the requisite pieces needed for the loader. try: w_loader = space.getitem(w_globals, space.wrap("__loader__")) w_module_name = space.getitem(w_globals, space.wrap("__name__")) except OperationError, e: if not e.match(space, space.w_KeyError): raise return # perform standard call # Make sure the loader implements the optional get_source() method. try: w_get_source = space.getattr(w_loader, space.wrap("get_source")) except OperationError, e: if not e.match(space, space.w_AttributeError): raise return # perform standard call # Call get_source() to get the source code. w_source = space.call_function(w_get_source, w_module_name) if space.is_w(w_source, space.w_None): return # perform standard call # Split the source into lines. w_source_list = space.call_method(w_source, "splitlines") # Get the source line. w_source_line = space.getitem(w_source_list, space.wrap(lineno - 1)) # Handle the warning. do_warn_explicit(space, w_category, w_message, (w_filename, lineno, w_module, w_registry), w_source_line) return True
|
return
|
return None
|
def warn_with_loader(space, w_message, w_category, w_filename, lineno, w_module, w_registry, w_globals): # Check/get the requisite pieces needed for the loader. try: w_loader = space.getitem(w_globals, space.wrap("__loader__")) w_module_name = space.getitem(w_globals, space.wrap("__name__")) except OperationError, e: if not e.match(space, space.w_KeyError): raise return # perform standard call # Make sure the loader implements the optional get_source() method. try: w_get_source = space.getattr(w_loader, space.wrap("get_source")) except OperationError, e: if not e.match(space, space.w_AttributeError): raise return # perform standard call # Call get_source() to get the source code. w_source = space.call_function(w_get_source, w_module_name) if space.is_w(w_source, space.w_None): return # perform standard call # Split the source into lines. w_source_list = space.call_method(w_source, "splitlines") # Get the source line. w_source_line = space.getitem(w_source_list, space.wrap(lineno - 1)) # Handle the warning. do_warn_explicit(space, w_category, w_message, (w_filename, lineno, w_module, w_registry), w_source_line) return True
|
return w_source_line @unwrap_spec(ObjSpace, W_Root, W_Root, W_Root, int, W_Root, W_Root, W_Root) def warn_explicit(space, w_message, w_category, w_filename, lineno, w_module=None, w_registry=None, w_module_globals=None): w_source_line = get_source_line(space, w_module_globals, lineno)
|
def warn_with_loader(space, w_message, w_category, w_filename, lineno, w_module, w_registry, w_globals): # Check/get the requisite pieces needed for the loader. try: w_loader = space.getitem(w_globals, space.wrap("__loader__")) w_module_name = space.getitem(w_globals, space.wrap("__name__")) except OperationError, e: if not e.match(space, space.w_KeyError): raise return # perform standard call # Make sure the loader implements the optional get_source() method. try: w_get_source = space.getattr(w_loader, space.wrap("get_source")) except OperationError, e: if not e.match(space, space.w_AttributeError): raise return # perform standard call # Call get_source() to get the source code. w_source = space.call_function(w_get_source, w_module_name) if space.is_w(w_source, space.w_None): return # perform standard call # Split the source into lines. w_source_list = space.call_method(w_source, "splitlines") # Get the source line. w_source_line = space.getitem(w_source_list, space.wrap(lineno - 1)) # Handle the warning. do_warn_explicit(space, w_category, w_message, (w_filename, lineno, w_module, w_registry), w_source_line) return True
|
|
return True @unwrap_spec(ObjSpace, W_Root, W_Root, W_Root, int, W_Root, W_Root, W_Root) def warn_explicit(space, w_message, w_category, w_filename, lineno, w_module=None, w_registry=None, w_module_globals=None): if not space.is_w(w_module_globals, space.w_None): if warn_with_loader(space, w_message, w_category, w_filename, lineno, w_module, w_registry, w_module_globals): return do_warn_explicit(space, w_category, w_message, (w_filename, lineno, w_module, w_registry))
|
def warn_with_loader(space, w_message, w_category, w_filename, lineno, w_module, w_registry, w_globals): # Check/get the requisite pieces needed for the loader. try: w_loader = space.getitem(w_globals, space.wrap("__loader__")) w_module_name = space.getitem(w_globals, space.wrap("__name__")) except OperationError, e: if not e.match(space, space.w_KeyError): raise return # perform standard call # Make sure the loader implements the optional get_source() method. try: w_get_source = space.getattr(w_loader, space.wrap("get_source")) except OperationError, e: if not e.match(space, space.w_AttributeError): raise return # perform standard call # Call get_source() to get the source code. w_source = space.call_function(w_get_source, w_module_name) if space.is_w(w_source, space.w_None): return # perform standard call # Split the source into lines. w_source_list = space.call_method(w_source, "splitlines") # Get the source line. w_source_line = space.getitem(w_source_list, space.wrap(lineno - 1)) # Handle the warning. do_warn_explicit(space, w_category, w_message, (w_filename, lineno, w_module, w_registry), w_source_line) return True
|
|
self._deprecated_buffer_size(space)
|
self._deprecated_max_buffer_size(space)
|
def descr_init(self, space, w_raw, buffer_size=DEFAULT_BUFFER_SIZE, max_buffer_size = -234): if max_buffer_size != -234: self._deprecated_buffer_size(space)
|
if isinstance(result, BorrowedPair):
|
elif isinstance(result, BorrowedPair):
|
def wrapper(*args): from pypy.module.cpyext.pyobject import make_ref, from_ref from pypy.module.cpyext.pyobject import BorrowedPair from pypy.module.cpyext.pyobject import NullPointerException # we hope that malloc removal removes the newtuple() that is # inserted exactly here by the varargs specializer llop.gc_stack_bottom(lltype.Void) # marker for trackgcroot.py rffi.stackcounter.stacks_counter += 1 retval = fatal_value boxed_args = () try: if not we_are_translated() and DEBUG_WRAPPER: print >>sys.stderr, callable, assert len(args) == len(callable.api_func.argtypes) for i, (typ, is_wrapped) in argtypes_enum_ui: arg = args[i] if typ is PyObject and is_wrapped: if arg: arg_conv = from_ref(space, arg) else: arg_conv = None else: arg_conv = arg boxed_args += (arg_conv, ) state = space.fromcache(State) try: result = callable(space, *boxed_args) if not we_are_translated() and DEBUG_WRAPPER: print >>sys.stderr, " DONE" except OperationError, e: failed = True state.set_exception(e) except BaseException, e: failed = True state.set_exception(OperationError(space.w_SystemError, space.wrap(str(e)))) if not we_are_translated(): import traceback traceback.print_exc() else: failed = False
|
def flush(self, length=0):
|
def flush(self, length=sys.maxint):
|
def flush(self, length=0): """ flush( [length] ) -- This is kept for backward compatibility, because each call to decompress() immediately returns as much data as possible. """ if length <= 0: raise OperationError(self.space.w_ValueError, self.space.wrap( "length must be greater than zero")) # We could call rzlib.decompress(self.stream, '', rzlib.Z_FINISH) # which would complain if the input stream so far is not complete; # however CPython's zlib module does not behave like that. # I could not figure out a case in which flush() in CPython # doesn't simply return an empty string without complaining. return self.space.wrap("")
|
return rmodel.inputconst(lltype.Bool, True)
|
op = hop.spaceop hop.genop("same_as", [rmodel.inputconst(lltype.Bool, True)], resultvar=op.result)
|
def gct_gc_writebarrier_before_copy(self, hop): return rmodel.inputconst(lltype.Bool, True) # no write barrier needed
|
mini.token = make_loop_token(len(mini.inputargs), metainterp.jitdriver_sd)
|
mini.token = bridge.token
|
def compile_known_target_bridges(metainterp, bridge): for op in bridge.operations: if op.is_guard(): target = op.getjumptarget() if target: mini = create_empty_loop(metainterp, 'fallback') mini.inputargs = op.getfailargs()[:] jmp = ResOperation(rop.JUMP, mini.inputargs[:], None, target) mini.operations = [jmp] descr = op.getdescr() assert isinstance(descr, ResumeGuardDescr) mini.token = make_loop_token(len(mini.inputargs), metainterp.jitdriver_sd) #descr.compile_and_attach(metainterp, mini) if not we_are_translated(): descr._debug_suboperations = mini.operations send_bridge_to_backend(metainterp.staticdata, descr, mini.inputargs, mini.operations, bridge.token) record_loop_or_bridge(metainterp.staticdata, mini)
|
def saferecursive(func, defl):
|
def saferecursive(func, defl, TLS=TLS):
|
def saferecursive(func, defl): def safe(*args): try: seeing = TLS.seeing except AttributeError: seeing = TLS.seeing = {} seeingkey = tuple([func] + [id(arg) for arg in args]) if seeingkey in seeing: return defl seeing[seeingkey] = True try: return func(*args) finally: del seeing[seeingkey] return safe
|
def safe_equal(x, y):
|
def safe_equal(x, y, TLS=TLS):
|
def safe_equal(x, y): # a specialized version for performance try: seeing = TLS.seeing_eq except AttributeError: seeing = TLS.seeing_eq = {} seeingkey = (id(x), id(y)) if seeingkey in seeing: return True seeing[seeingkey] = True try: return x == y finally: del seeing[seeingkey]
|
def __hash__(self):
|
def __hash__(self, TLS=TLS):
|
def __hash__(self): # cannot use saferecursive() -- see test_lltype.test_hash(). # NB. the __cached_hash should neither be used nor updated # if we enter with hash_level > 0, because the computed # __hash__ can be different in this situation. hash_level = 0 try: hash_level = TLS.nested_hash_level if hash_level == 0: return self.__cached_hash except AttributeError: pass if hash_level >= 3: return 0 items = self.__dict__.items() items.sort() TLS.nested_hash_level = hash_level + 1 try: result = hash((self.__class__,) + tuple(items)) finally: TLS.nested_hash_level = hash_level if hash_level == 0: self.__cached_hash = result return result
|
_cache = weakref.WeakKeyDictionary()
|
_cache = weakref.WeakValueDictionary()
|
def _inline_is_varsize(self, last): raise TypeError("cannot inline a GC array inside a structure")
|
_cache = weakref.WeakKeyDictionary()
|
_cache = weakref.WeakValueDictionary()
|
def build_number(name, type): try: return _numbertypes[type] except KeyError: pass if name is None: raise ValueError('No matching lowlevel type for %r'%type) number = _numbertypes[type] = Number(name, type) return number
|
obj = Ptr._cache[TO]
|
return Ptr._cache[TO]
|
def __new__(cls, TO, use_cache=True): if not use_cache: obj = LowLevelType.__new__(cls) else: try: obj = Ptr._cache[TO] except KeyError: obj = Ptr._cache[TO] = LowLevelType.__new__(cls) except TypeError: obj = LowLevelType.__new__(cls) return obj
|
def __init__(self, TO, use_cache=True): if not isinstance(TO, ContainerType): raise TypeError, ("can only point to a Container type, " "not to %s" % (TO,)) self.TO = TO
|
def __new__(cls, TO, use_cache=True): if not use_cache: obj = LowLevelType.__new__(cls) else: try: obj = Ptr._cache[TO] except KeyError: obj = Ptr._cache[TO] = LowLevelType.__new__(cls) except TypeError: obj = LowLevelType.__new__(cls) return obj
|
|
memo = set()
|
self.loops = set()
|
def compute(self, graphs): dotgen = DotGen('trace') memo = set() for graph in graphs: graph.generate(dotgen, memo) self.source = dotgen.generate(target=None)
|
graph.generate(dotgen, memo)
|
graph.grab_loops(self.loops) self.links = {} self.cache = {} for loop in self.loops: loop.generate(dotgen) loop.getlinks(self.links) self.cache["loop" + str(loop.no)] = loop
|
def compute(self, graphs): dotgen = DotGen('trace') memo = set() for graph in graphs: graph.generate(dotgen, memo) self.source = dotgen.generate(target=None)
|
def generate(self, dotgen, memo): dotgen.emit_node(self.name(), label=self.content,
|
def getlinks(self, links): links[self.linksource] = self.name() def generate(self, dotgen): dotgen.emit_node(self.name(), label=self.header,
|
def generate(self, dotgen, memo): dotgen.emit_node(self.name(), label=self.content, shape='box', fillcolor=get_gradient_color(self.ratio))
|
def generate(self, dotgen, memo): if self in memo:
|
def grab_loops(self, loops): if self in loops:
|
def generate(self, dotgen, memo): if self in memo: return memo.add(self) BasicBlock.generate(self, dotgen, memo) if self.target is not None: dotgen.emit_edge(self.name(), self.target.name()) self.target.generate(dotgen, memo)
|
memo.add(self) BasicBlock.generate(self, dotgen, memo)
|
loops.add(self) if self.target is not None: self.target.grab_loops(loops) def generate(self, dotgen): BasicBlock.generate(self, dotgen)
|
def generate(self, dotgen, memo): if self in memo: return memo.add(self) BasicBlock.generate(self, dotgen, memo) if self.target is not None: dotgen.emit_edge(self.name(), self.target.name()) self.target.generate(dotgen, memo)
|
self.target.generate(dotgen, memo)
|
def generate(self, dotgen, memo): if self in memo: return memo.add(self) BasicBlock.generate(self, dotgen, memo) if self.target is not None: dotgen.emit_edge(self.name(), self.target.name()) self.target.generate(dotgen, memo)
|
|
def generate(self, dotgen, memo): if self in memo:
|
def grab_loops(self, loops): if self in loops:
|
def generate(self, dotgen, memo): if self in memo: return memo.add(self) BasicBlock.generate(self, dotgen, memo) dotgen.emit_edge(self.name(), self.left.name()) dotgen.emit_edge(self.name(), self.right.name()) self.left.generate(dotgen, memo) self.right.generate(dotgen, memo)
|
memo.add(self) BasicBlock.generate(self, dotgen, memo)
|
loops.add(self) self.left.grab_loops(loops) self.right.grab_loops(loops) def generate(self, dotgen): BasicBlock.generate(self, dotgen)
|
def generate(self, dotgen, memo): if self in memo: return memo.add(self) BasicBlock.generate(self, dotgen, memo) dotgen.emit_edge(self.name(), self.left.name()) dotgen.emit_edge(self.name(), self.right.name()) self.left.generate(dotgen, memo) self.right.generate(dotgen, memo)
|
self.left.generate(dotgen, memo) self.right.generate(dotgen, memo) def split_one_loop(allloops, guard_s, guard_content):
|
def split_one_loop(allloops, guard_s, guard_content, lineno):
|
def generate(self, dotgen, memo): if self in memo: return memo.add(self) BasicBlock.generate(self, dotgen, memo) dotgen.emit_edge(self.name(), self.left.name()) dotgen.emit_edge(self.name(), self.right.name()) self.left.generate(dotgen, memo) self.right.generate(dotgen, memo)
|
split_one_loop(real_loops, guard_s, loop)
|
split_one_loop(real_loops, guard_s, loop, counter)
|
def splitloops(loops): real_loops = [] for loop in loops: firstline = loop[:loop.find("\n")] m = re.match('# Loop (\d+)', firstline) if m: no = int(m.group(1)) assert len(real_loops) == no real_loops.append(FinalBlock(loop, None)) else: m = re.search("bridge out of Guard (\d+)", firstline) assert m guard_s = 'Guard' + m.group(1) split_one_loop(real_loops, guard_s, loop) return real_loops
|
loop.content = "%s\n%d operations\n%d opcodes" % (name, opsno, bcodes) loop.content += "\n" * (opsno / 100)
|
loop.linksource = "loop" + str(loop.no) loop.header = "%s loop%d\n%d operations\n%d opcodes" % (name, loop.no, opsno, bcodes) loop.header += "\n" * (opsno / 100)
|
def postprocess_loop(loop, loops, memo): if loop in memo: return memo.add(loop) if loop is None: return m = re.search("debug_merge_point\('<code object (.*?)>", loop.content) if m is None: name = '?' else: name = m.group(1) opsno = loop.content.count("\n") lastline = loop.content[loop.content.rfind("\n", 0, len(loop.content) - 2):] m = re.search('descr=<Loop(\d+)', lastline) if m is not None: assert isinstance(loop, FinalBlock) loop.target = loops[int(m.group(1))] bcodes = loop.content.count('debug_merge_point') loop.content = "%s\n%d operations\n%d opcodes" % (name, opsno, bcodes) loop.content += "\n" * (opsno / 100) if bcodes == 0: loop.ratio = opsno else: loop.ratio = float(opsno) / bcodes loop.postprocess(loops, memo)
|
assert newpath == self.expected_path
|
assert newpath[:len(self.expected_path)] == self.expected_path
|
def test_get_library_path(self): import sys import os sys.path.append(self.goal_dir) try: import app_main app_main.os = os newpath = app_main.get_library_path('/tmp/pypy-c') # stdlib not found assert newpath == sys.path newpath = app_main.get_library_path(self.fake_exe) assert newpath == self.expected_path finally: sys.path.pop()
|
i2 = i1 + (ctypes.sizeof(ctype) + 7) & ~7
|
i2 = i1 + ((ctypes.sizeof(ctype) or 1) + 7) & ~7
|
def allocate_ctypes(ctype): if far_regions: import random pieces = far_regions._ll2ctypes_pieces num = random.randrange(len(pieces)) i1, stop = pieces[num] i2 = i1 + (ctypes.sizeof(ctype) + 7) & ~7 if i2 > stop: raise MemoryError("out of memory in far_regions") pieces[num] = i2, stop p = lltype2ctypes(far_regions.getptr(i1)) return ctypes.cast(p, ctypes.POINTER(ctype)).contents else: return ctype()
|
for desc in descs.keys():
|
for desc in list(descs):
|
def format_simple_call(annotator, oper, what, msg): msg.append("Simple call of incompatible family:") try: descs = annotator.bindings[oper.args[0]].descriptions except (KeyError, AttributeError), e: msg.append(" (%s getting at the binding!)" % ( e.__class__.__name__,)) return for desc in descs.keys(): func = desc.pyobj if func is None: r = repr(desc) else: r = "function %s <%s, line %s>" % (func.func_name, func.func_code.co_filename, func.func_code.co_firstlineno) msg.append(" %s returning" % (r,)) if hasattr(desc, 'getuniquegraph'): graph = desc.getuniquegraph() r = annotator.binding(graph.returnblock.inputargs[0], "(no annotation)") else: r = '?' msg.append(" %s" % (r,)) msg.append("")
|
_CA = rffi.CArray(lltype.Signed)
|
class FloatArrayDescr(BaseArrayDescr): _clsname = 'FloatArrayDescr' _is_array_of_floats = True def get_base_size(self, translate_support_code): basesize, _, _ = symbolic.get_array_token(_AF, translate_support_code) return basesize def get_item_size(self, translate_support_code): return symbolic.get_size(lltype.Float, translate_support_code)
|
def get_item_size(self, translate_support_code): return symbolic.get_size_of_ptr(translate_support_code)
|
basesize, _, _ = symbolic.get_array_token(_CA, translate_support_code) return basesize
|
return 0
|
def get_base_size(self, translate_support_code): basesize, _, _ = symbolic.get_array_token(_CA, translate_support_code) return basesize
|
_, _, ofslength = symbolic.get_array_token(_CA, translate_support_code) return ofslength
|
return -1
|
def get_ofs_length(self, translate_support_code): _, _, ofslength = symbolic.get_array_token(_CA, translate_support_code) return ofslength
|
assert ofslength == arraydescr.get_ofs_length(False)
|
if not ARRAY._hints.get('nolength', False): assert ofslength == arraydescr.get_ofs_length(False)
|
def get_array_descr(gccache, ARRAY): cache = gccache._cache_array try: return cache[ARRAY] except KeyError: # we only support Arrays that are either GcArrays, or raw no-length # non-gc Arrays. if ARRAY._hints.get('nolength', False): assert not isinstance(ARRAY, lltype.GcArray) arraydescr = getArrayNoLengthDescrClass(ARRAY)() else: assert isinstance(ARRAY, lltype.GcArray) arraydescr = getArrayDescrClass(ARRAY)() # verify basic assumption that all arrays' basesize and ofslength # are equal basesize, itemsize, ofslength = symbolic.get_array_token(ARRAY, False) assert basesize == arraydescr.get_base_size(False) assert itemsize == arraydescr.get_item_size(False) assert ofslength == arraydescr.get_ofs_length(False) if isinstance(ARRAY, lltype.GcArray): gccache.init_array_descr(ARRAY, arraydescr) cache[ARRAY] = arraydescr return arraydescr
|
cc = default_cc
|
cc = self.default_cc
|
def __init__(self, cc=None): if cc is None: try: cc = os.environ['CC'] except KeyError: cc = default_cc self.cc = cc
|
if current > 0: current -= 1
|
current = max(current-1, 0)
|
def inline(self, loop_operations, loop_args, jump_args): self.argmap = argmap = {} assert len(loop_args) == len(jump_args) for i in range(len(loop_args)): argmap[loop_args[i]] = jump_args[i]
|
return res
|
return int(res)
|
def libffi_stuff(i, j): lib = CDLL(libm_name) func = lib.getpointer('fabs', [types.double], types.double) res = 0.0 x = float(j) while i > 0: jitdriver2.jit_merge_point(i=i, res=res, func=func, x=x) jitdriver2.can_enter_jit(i=i, res=res, func=func, x=x) func = hint(func, promote=True) argchain = ArgChain() argchain.arg(x) res = func.call(argchain, rffi.DOUBLE) i -= 1 return res
|
expected = f(40, -49)
|
expected = main(40, -49)
|
def main(i, j): return f(i, j) + libffi_stuff(i, j)
|
if shared: cflags = self.cflags + self.shared_only else: cflags = self.cflags + self.standalone_only
|
cflags = self.cflags if sys.maxint > 2147483647: if shared: cflags = self.cflags + self.shared_only else: cflags = self.cflags + self.standalone_only
|
def gen_makefile(self, cfiles, eci, exe_name=None, path=None, shared=False): cfiles = [py.path.local(f) for f in cfiles] cfiles += [py.path.local(f) for f in eci.separate_module_files]
|
[BoxInt(56), ConstInt(78)])
|
[BoxInt(56), ConstInt(78), BoxInt(90)])
|
def ll_portal_runner(g1, g2, r3, r4): assert (g1, g2, r3, r4) == (12, 34, -156, -178) if raiseme: raise raiseme else: return 54321
|
regalloc.force_allocate_reg(op.result, selected_reg=r.r0)
|
def emit_op_call(self, op, regalloc, fcond, save_all_regs=False): locs = [] # all arguments past the 4th go on the stack # XXX support types other than int (one word types) if op.numargs() > 5: stack_args = op.numargs() - 5 n = stack_args*WORD self._adjust_sp(n, regalloc, fcond=fcond) for i in range(5, op.numargs()): reg = regalloc.make_sure_var_in_reg(op.getarg(i)) self.mc.STR_ri(reg.value, r.sp.value, (i-5)*WORD) regalloc.possibly_free_var(reg)
|
|
self.space.wrap(index)))
|
self.space.wrap(index))
|
def next_w(self): if not self.cont: raise OperationError(self.space.w_StopIteration, self.space.w_None) l = [None] * self.num_gears for x in range(0, self.num_gears): index, limit = self.indicies[x] l[x] = self.space.getitem(self.gears_w[x], self.space.wrap(index))) self.roll_gears() return self.space.newtuple(l)
|
parts = logparser.extract_category(log, "jit-log-opt-")
|
parts = logparser.extract_category(log, "jit-log-noopt-")
|
def main(argv): log = logparser.parse_log_file(argv[0]) parts = logparser.extract_category(log, "jit-log-opt-") for i, oplist in enumerate(parts): loop = parse(oplist, no_namespace=True) num_ops = 0 num_dmp = 0 num_guards = 0 for op in loop.operations: if op.getopnum() == rop.DEBUG_MERGE_POINT: num_dmp += 1 else: num_ops += 1 if op.is_guard(): num_guards += 1 print "Loop #%d, length: %d, opcodes: %d, guards: %d, %f" % (i, num_ops, num_dmp, num_guards, num_ops/num_dmp)
|
loop = parse(oplist, no_namespace=True)
|
loop = parse(oplist, no_namespace=True, nonstrict=True)
|
def main(argv): log = logparser.parse_log_file(argv[0]) parts = logparser.extract_category(log, "jit-log-opt-") for i, oplist in enumerate(parts): loop = parse(oplist, no_namespace=True) num_ops = 0 num_dmp = 0 num_guards = 0 for op in loop.operations: if op.getopnum() == rop.DEBUG_MERGE_POINT: num_dmp += 1 else: num_ops += 1 if op.is_guard(): num_guards += 1 print "Loop #%d, length: %d, opcodes: %d, guards: %d, %f" % (i, num_ops, num_dmp, num_guards, num_ops/num_dmp)
|
print "Loop
|
if num_dmp == 0: print "Loop else: print "Loop
|
def main(argv): log = logparser.parse_log_file(argv[0]) parts = logparser.extract_category(log, "jit-log-opt-") for i, oplist in enumerate(parts): loop = parse(oplist, no_namespace=True) num_ops = 0 num_dmp = 0 num_guards = 0 for op in loop.operations: if op.getopnum() == rop.DEBUG_MERGE_POINT: num_dmp += 1 else: num_ops += 1 if op.is_guard(): num_guards += 1 print "Loop #%d, length: %d, opcodes: %d, guards: %d, %f" % (i, num_ops, num_dmp, num_guards, num_ops/num_dmp)
|
from pypy.module.cpyext import structmemberdefs
|
from pypy.module.cpyext.structmemberdefs import *
|
from pypy.interpreter.typedef import TypeDef, GetSetProperty
|
(structmemberdefs.T_SHORT, rffi.SHORT, PyInt_AsLong), (structmemberdefs.T_INT, rffi.INT, PyInt_AsLong), (structmemberdefs.T_LONG, rffi.LONG, PyInt_AsLong), (structmemberdefs.T_USHORT, rffi.USHORT, PyInt_AsUnsignedLong), (structmemberdefs.T_UINT, rffi.UINT, PyInt_AsUnsignedLong), (structmemberdefs.T_ULONG, rffi.ULONG, PyInt_AsUnsignedLong), (structmemberdefs.T_BYTE, rffi.UCHAR, PyInt_AsLong),
|
(T_SHORT, rffi.SHORT, PyInt_AsLong), (T_INT, rffi.INT, PyInt_AsLong), (T_LONG, rffi.LONG, PyInt_AsLong), (T_USHORT, rffi.USHORT, PyInt_AsUnsignedLong), (T_UINT, rffi.UINT, PyInt_AsUnsignedLong), (T_ULONG, rffi.ULONG, PyInt_AsUnsignedLong), (T_BYTE, rffi.UCHAR, PyInt_AsLong),
|
from pypy.interpreter.typedef import TypeDef, GetSetProperty
|
typ, lltype, _ = converter if typ == member_type result = rffi.cast(rffi.CArrayPtr(lltype), addr)
|
typ, lltyp, _ = converter if typ == member_type: result = rffi.cast(rffi.CArrayPtr(lltyp), addr)
|
def PyMember_GetOne(space, obj, w_member): addr = rffi.cast(ADDR, obj) addr += w_member.c_offset member_type = rffi.cast(lltype.Signed, w_member.c_type) for converter in integer_converters: typ, lltype, _ = converter if typ == member_type result = rffi.cast(rffi.CArrayPtr(lltype), addr) w_result = space.wrap(result[0]) return w_result if member_type == structmemberdefs.T_STRING: result = rffi.cast(rffi.CCHARPP, addr) if result[0]: w_result = PyString_FromString(space, result[0]) else: w_result = space.w_None elif member_type == structmemberdefs.T_STRING_INPLACE: result = rffi.cast(rffi.CCHARP, addr) w_result = PyString_FromString(space, result) elif member_type == structmemberdefs.T_CHAR: result = rffi.cast(rffi.CCHARP, addr) w_result = space.wrap(result[0]) elif member_type == structmemberdefs.T_OBJECT: obj_ptr = rffi.cast(PyObjectP, addr) if obj_ptr[0]: w_result = from_ref(space, obj_ptr[0]) else: w_result = space.w_None elif member_type == T_OBJECT_EX: obj_ptr = rffi.cast(PyObjectP, addr) if obj_ptr[0]: w_result = from_ref(space, obj_ptr[0]) else: w_name = space.wrap(rffi.charp2str(w_member.c_name)) raise OperationError(space.w_AttributeError, w_name) else: raise OperationError(space.w_SystemError, space.wrap("bad memberdescr type")) return w_result
|
if member_type == structmemberdefs.T_STRING:
|
if member_type == T_STRING:
|
def PyMember_GetOne(space, obj, w_member): addr = rffi.cast(ADDR, obj) addr += w_member.c_offset member_type = rffi.cast(lltype.Signed, w_member.c_type) for converter in integer_converters: typ, lltype, _ = converter if typ == member_type result = rffi.cast(rffi.CArrayPtr(lltype), addr) w_result = space.wrap(result[0]) return w_result if member_type == structmemberdefs.T_STRING: result = rffi.cast(rffi.CCHARPP, addr) if result[0]: w_result = PyString_FromString(space, result[0]) else: w_result = space.w_None elif member_type == structmemberdefs.T_STRING_INPLACE: result = rffi.cast(rffi.CCHARP, addr) w_result = PyString_FromString(space, result) elif member_type == structmemberdefs.T_CHAR: result = rffi.cast(rffi.CCHARP, addr) w_result = space.wrap(result[0]) elif member_type == structmemberdefs.T_OBJECT: obj_ptr = rffi.cast(PyObjectP, addr) if obj_ptr[0]: w_result = from_ref(space, obj_ptr[0]) else: w_result = space.w_None elif member_type == T_OBJECT_EX: obj_ptr = rffi.cast(PyObjectP, addr) if obj_ptr[0]: w_result = from_ref(space, obj_ptr[0]) else: w_name = space.wrap(rffi.charp2str(w_member.c_name)) raise OperationError(space.w_AttributeError, w_name) else: raise OperationError(space.w_SystemError, space.wrap("bad memberdescr type")) return w_result
|
elif member_type == structmemberdefs.T_STRING_INPLACE:
|
elif member_type == T_STRING_INPLACE:
|
def PyMember_GetOne(space, obj, w_member): addr = rffi.cast(ADDR, obj) addr += w_member.c_offset member_type = rffi.cast(lltype.Signed, w_member.c_type) for converter in integer_converters: typ, lltype, _ = converter if typ == member_type result = rffi.cast(rffi.CArrayPtr(lltype), addr) w_result = space.wrap(result[0]) return w_result if member_type == structmemberdefs.T_STRING: result = rffi.cast(rffi.CCHARPP, addr) if result[0]: w_result = PyString_FromString(space, result[0]) else: w_result = space.w_None elif member_type == structmemberdefs.T_STRING_INPLACE: result = rffi.cast(rffi.CCHARP, addr) w_result = PyString_FromString(space, result) elif member_type == structmemberdefs.T_CHAR: result = rffi.cast(rffi.CCHARP, addr) w_result = space.wrap(result[0]) elif member_type == structmemberdefs.T_OBJECT: obj_ptr = rffi.cast(PyObjectP, addr) if obj_ptr[0]: w_result = from_ref(space, obj_ptr[0]) else: w_result = space.w_None elif member_type == T_OBJECT_EX: obj_ptr = rffi.cast(PyObjectP, addr) if obj_ptr[0]: w_result = from_ref(space, obj_ptr[0]) else: w_name = space.wrap(rffi.charp2str(w_member.c_name)) raise OperationError(space.w_AttributeError, w_name) else: raise OperationError(space.w_SystemError, space.wrap("bad memberdescr type")) return w_result
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.