def oop_list_nonzero(jitstate, oopspecdesc, deepfrozen, selfbox): content = selfbox.content if isinstance(content, VirtualList): return rvalue.ll_fromvalue(jitstate, bool(content.item_boxes)) else: return oopspecdesc.residual_call(jitstate, [selfbox], deepfrozen=deepfrozen)
def gengetinteriorarraysize(jitstate, argbox, *indexboxes): if argbox.is_constant(): ptr = rvalue.ll_getvalue(argbox, PTRTYPE) if ptr: # else don't constant-fold the segfault... i = 0 for offset in unroll_path: if offset is None: # array substruct indexbox = indexboxes[i] i += 1 if not indexbox.is_constant(): break # non-constant array index index = rvalue.ll_getvalue(indexbox, lltype.Signed) ptr = ptr[index] else: ptr = getattr(ptr, offset) else: # constant-folding: success assert i == len(indexboxes) return rvalue.ll_fromvalue(jitstate, len(ptr)) argbox = getinterior_all(jitstate, argbox, *indexboxes) genvar = jitstate.curbuilder.genop_getarraysize( arrayfielddesc.arraytoken, argbox.getgenvar(jitstate)) return rvalue.IntRedBox(arrayfielddesc.indexkind, genvar)
def gengetinteriorfield(jitstate, deepfrozen, argbox, *indexboxes): if (immutable or deepfrozen) and argbox.is_constant(): ptr = rvalue.ll_getvalue(argbox, PTRTYPE) if ptr: # else don't constant-fold the segfault... i = 0 for offset in unroll_path: if offset is None: # array substruct indexbox = indexboxes[i] i += 1 if not indexbox.is_constant(): break # non-constant array index index = rvalue.ll_getvalue( indexbox, lltype.Signed) ptr = ptr[index] else: ptr = getattr(ptr, offset) else: # constant-folding: success assert i == len(indexboxes) return rvalue.ll_fromvalue(jitstate, ptr) argbox = getinterior_initial(jitstate, argbox, *indexboxes) if lastoffset is None: # getarrayitem indexbox = indexboxes[-1] genvar = jitstate.curbuilder.genop_getarrayitem( lastfielddesc.arraytoken, argbox.getgenvar(jitstate), indexbox.getgenvar(jitstate)) return lastfielddesc.makebox(jitstate, genvar) else: # getfield return argbox.op_getfield(jitstate, lastfielddesc)
def gengetinteriorfield(jitstate, deepfrozen, argbox, *indexboxes): if (immutable or deepfrozen) and argbox.is_constant(): ptr = rvalue.ll_getvalue(argbox, PTRTYPE) if ptr: # else don't constant-fold the segfault... i = 0 for offset in unroll_path: if offset is None: # array substruct indexbox = indexboxes[i] i += 1 if not indexbox.is_constant(): break # non-constant array index index = rvalue.ll_getvalue(indexbox, lltype.Signed) ptr = ptr[index] else: ptr = getattr(ptr, offset) else: # constant-folding: success assert i == len(indexboxes) return rvalue.ll_fromvalue(jitstate, ptr) argbox = getinterior_initial(jitstate, argbox, *indexboxes) if lastoffset is None: # getarrayitem indexbox = indexboxes[-1] genvar = jitstate.curbuilder.genop_getarrayitem( lastfielddesc.arraytoken, argbox.getgenvar(jitstate), indexbox.getgenvar(jitstate)) return lastfielddesc.makebox(jitstate, genvar) else: # getfield return argbox.op_getfield(jitstate, lastfielddesc)
def op_ptreq(self, jitstate, otherbox, reverse): if self is otherbox.content: answer = True else: gv_outside = self.content_boxes[-1].genvar if gv_outside is self.typedesc.gv_null: answer = False else: return None # fall-back return rvalue.ll_fromvalue(jitstate, answer ^ reverse)
def oop_dict_contains(jitstate, oopspecdesc, deepfrozen, selfbox, keybox): content = selfbox.content if isinstance(content, AbstractVirtualDict) and keybox.is_constant(): try: content.getitem(keybox) res = True except KeyError: res = False return rvalue.ll_fromvalue(jitstate, res) else: return oopspecdesc.residual_call(jitstate, [selfbox, keybox], deepfrozen=deepfrozen)
def do_call(jitstate, argboxes): oopargs = () for i, ARG in unrolling_OOPARGS: v = rvalue.ll_getvalue(argboxes[i], ARG) oopargs += (v,) if not oopargcheck(*oopargs): raise SegfaultException args = () j = 0 for ARG in unrolling_ARGS: if ARG == lltype.Void: v = None else: argsrc = residualargsources[j] j = j + 1 v = oopargs[argsrc] args += (v,) result = fnptr(*args) if FUNCTYPE.RESULT == lltype.Void: return None return rvalue.ll_fromvalue(jitstate, result)
def gengetinteriorarraysize(jitstate, argbox, *indexboxes): if argbox.is_constant(): ptr = rvalue.ll_getvalue(argbox, PTRTYPE) if ptr: # else don't constant-fold the segfault... i = 0 for offset in unroll_path: if offset is None: # array substruct indexbox = indexboxes[i] i += 1 if not indexbox.is_constant(): break # non-constant array index index = rvalue.ll_getvalue( indexbox, lltype.Signed) ptr = ptr[index] else: ptr = getattr(ptr, offset) else: # constant-folding: success assert i == len(indexboxes) return rvalue.ll_fromvalue(jitstate, len(ptr)) argbox = getinterior_all(jitstate, argbox, *indexboxes) genvar = jitstate.curbuilder.genop_getarraysize( arrayfielddesc.arraytoken, argbox.getgenvar(jitstate)) return rvalue.IntRedBox(arrayfielddesc.indexkind, genvar)
def op_ptreq(self, jitstate, otherbox, reverse): equal = self is otherbox.content return rvalue.ll_fromvalue(jitstate, equal ^ reverse)