Example #1
0
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)
Example #2
0
 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)
Example #3
0
 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)
Example #4
0
 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)
Example #5
0
 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)
Example #6
0
 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)
Example #7
0
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)
Example #8
0
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)
Example #9
0
 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)
Example #10
0
File: oop.py Project: chyyuu/pygirl
 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)
Example #11
0
 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)
Example #12
0
 def op_ptreq(self, jitstate, otherbox, reverse):
     equal = self is otherbox.content
     return rvalue.ll_fromvalue(jitstate, equal ^ reverse)
Example #13
0
 def op_ptreq(self, jitstate, otherbox, reverse):
     equal = self is otherbox.content
     return rvalue.ll_fromvalue(jitstate, equal ^ reverse)