Example #1
0
 def SETUP_WITH(self, target):
     # A simpler version than the 'real' 2.7 one:
     # directly call manager.__enter__(), don't use special lookup functions
     # which don't make sense on the RPython type system.
     w_manager = self.peekvalue()
     w_exit = op.getattr(w_manager, const("__exit__")).eval(self)
     self.settopvalue(w_exit)
     w_enter = op.getattr(w_manager, const('__enter__')).eval(self)
     w_result = op.simple_call(w_enter).eval(self)
     block = WithBlock(self, target)
     self.blockstack.append(block)
     self.pushvalue(w_result)
Example #2
0
 def LIST_APPEND(self, oparg):
     w_value = self.popvalue()
     if sys.version_info < (2, 7):
         w_list = self.popvalue()
     else:
         w_list = self.peekvalue(oparg - 1)
     w_append_meth = op.getattr(w_list, const('append')).eval(self)
     op.simple_call(w_append_meth, w_value).eval(self)
Example #3
0
 def import_from(self, w_module, w_name):
     assert isinstance(w_module, Constant)
     assert isinstance(w_name, Constant)
     try:
         return op.getattr(w_module, w_name).eval(self)
     except FlowingError:
         exc = ImportError("cannot import name '%s'" % w_name.value)
         raise Raise(const(exc))
Example #4
0
def _insert_reads(block, varnames):
    assert len(varnames) == len(block.inputargs)
    v_entry1 = Variable('entry')
    for i, name in enumerate(varnames):
        hlop = op.getattr(v_entry1, const(name))
        hlop.result = block.inputargs[i]
        block.operations.insert(i, hlop)
    block.inputargs = [v_entry1]
Example #5
0
def setattr_SomeInstance(annotator, v_obj, v_attr, v_value):
    s_attr = annotator.annotation(v_attr)
    if not s_attr.is_constant() or not isinstance(s_attr.const, str):
        return
    attr = s_attr.const
    setters = _find_property_meth(annotator.annotation(v_obj), attr, 'fset')
    if setters:
        if all(setters):
            get_setter = op.getattr(v_obj, const(attr + '__setter__'))
            return [get_setter, op.simple_call(get_setter.result, v_value)]
        elif not any(setters):
            raise AnnotatorError("Attribute %r is unwritable" % attr)
Example #6
0
def getslice_SomeInstance(annotator, v_obj, v_start, v_stop):
    get_getslice = op.getattr(v_obj, const('__getslice__'))
    return [get_getslice, op.simple_call(get_getslice.result, v_start, v_stop)]
Example #7
0
def next_SomeInstance(annotator, v_arg):
    get_next = op.getattr(v_arg, const('next'))
    return [get_next, op.simple_call(get_next.result)]
Example #8
0
def iter_SomeInstance(annotator, v_arg):
    get_iter = op.getattr(v_arg, const('__iter__'))
    return [get_iter, op.simple_call(get_iter.result)]
Example #9
0
def len_SomeInstance(annotator, v_arg):
    get_len = op.getattr(v_arg, const('__len__'))
    return [get_len, op.simple_call(get_len.result)]
Example #10
0
def iter_SomeInstance(annotator, v_arg):
    get_iter = op.getattr(v_arg, const('__iter__'))
    return [get_iter, op.simple_call(get_iter.result)]
Example #11
0
def setitem_SomeInstance(annotator, v_ins, v_idx, v_value):
    get_setitem = op.getattr(v_ins, const('__setitem__'))
    return [get_setitem, op.simple_call(get_setitem.result, v_idx, v_value)]
Example #12
0
def contains_SomeInstance(annotator, v_ins, v_idx):
    get_contains = op.getattr(v_ins, const('__contains__'))
    return [get_contains, op.simple_call(get_contains.result, v_idx)]
Example #13
0
def setslice_SomeInstance(annotator, v_obj, v_start, v_stop, v_iterable):
    get_setslice = op.getattr(v_obj, const('__setslice__'))
    return [get_setslice,
            op.simple_call(get_setslice.result, v_start, v_stop, v_iterable)]
Example #14
0
def getslice_SomeInstance(annotator, v_obj, v_start, v_stop):
    get_getslice = op.getattr(v_obj, const('__getslice__'))
    return [get_getslice, op.simple_call(get_getslice.result, v_start, v_stop)]
Example #15
0
def next_SomeInstance(annotator, v_arg):
    get_next = op.getattr(v_arg, const('next'))
    return [get_next, op.simple_call(get_next.result)]
Example #16
0
def setslice_SomeInstance(annotator, v_obj, v_start, v_stop, v_iterable):
    get_setslice = op.getattr(v_obj, const('__setslice__'))
    return [
        get_setslice,
        op.simple_call(get_setslice.result, v_start, v_stop, v_iterable)
    ]
Example #17
0
 def LOAD_ATTR(self, nameindex):
     "obj.attributename"
     w_obj = self.popvalue()
     w_attributename = self.getname_w(nameindex)
     w_value = op.getattr(w_obj, w_attributename).eval(self)
     self.pushvalue(w_value)
Example #18
0
def setitem_SomeInstance(annotator, v_ins, v_idx, v_value):
    get_setitem = op.getattr(v_ins, const('__setitem__'))
    return [get_setitem,
            op.simple_call(get_setitem.result, v_idx, v_value)]
Example #19
0
def sc_getattr(ctx, w_obj, w_index, w_default=None):
    if w_default is not None:
        return ctx.appcall(getattr, w_obj, w_index, w_default)
    else:
        from rpython.flowspace.operation import op
        return op.getattr(w_obj, w_index).eval(ctx)
Example #20
0
def sc_getattr(ctx, w_obj, w_index, w_default=None):
    if w_default is not None:
        return ctx.appcall(getattr, w_obj, w_index, w_default)
    else:
        from rpython.flowspace.operation import op
        return op.getattr(w_obj, w_index).eval(ctx)
Example #21
0
 def LOAD_ATTR(self, nameindex):
     "obj.attributename"
     w_obj = self.popvalue()
     w_attributename = self.getname_w(nameindex)
     w_value = op.getattr(w_obj, w_attributename).eval(self)
     self.pushvalue(w_value)
Example #22
0
def len_SomeInstance(annotator, v_arg):
    get_len = op.getattr(v_arg, const('__len__'))
    return [get_len, op.simple_call(get_len.result)]