本文整理汇总了Python中pypy.rlib.objectmodel.instantiate函数的典型用法代码示例。如果您正苦于以下问题:Python instantiate函数的具体用法?Python instantiate怎么用?Python instantiate使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了instantiate函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: init_w_object
def init_w_object(self):
""" 0 no fields
1 fixed fields only (all containing pointers)
2 indexable fields only (all containing pointers)
3 both fixed and indexable fields (all containing pointers)
4 both fixed and indexable weak fields (all containing pointers).
5 unused
6 indexable word fields only (no pointers)
7 indexable long (64-bit) fields (only in 64-bit images)
8-11 indexable byte fields only (no pointers) (low 2 bits are low 2 bits of size)
12-15 compiled methods:
# of literal oops specified in method header,
followed by indexable bytes (same interpretation of low 2 bits as above)
"""
if self.w_object is None:
if self.format < 5:
# XXX self.format == 4 is weak
self.w_object = objectmodel.instantiate(model.W_PointersObject)
elif self.format == 5:
raise CorruptImageError("Unknown format 5")
elif self.format == 6:
self.w_object = objectmodel.instantiate(model.W_WordsObject)
elif self.format == 7:
raise CorruptImageError("Unknown format 7, no 64-bit support yet :-)")
elif 8 <= self.format <= 11:
self.w_object = objectmodel.instantiate(model.W_BytesObject)
elif 12 <= self.format <= 15:
self.w_object = objectmodel.instantiate(model.W_CompiledMethod)
else:
assert 0, "not reachable"
return self.w_object
开发者ID:antoine1fr,项目名称:pygirl,代码行数:33,代码来源:squeakimage.py
示例2: f
def f(i):
if i == 1:
cls = A
else:
cls = B
do_stuff(cls)
return instantiate(cls)
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:7,代码来源:test_rbuiltin.py
示例3: wrapint
def wrapint(space, x, w_symbolic=False, w_s=''):
if space.config.objspace.std.withsmallint:
from pypy.objspace.std.smallintobject import W_SmallIntObject
try:
return W_SmallIntObject(x)
except OverflowError:
from pypy.objspace.std.intobject import W_IntObject
return W_IntObject(x, w_symbolic, w_s)
elif space.config.objspace.std.withprebuiltint:
from pypy.objspace.std.intobject import W_IntObject
lower = space.config.objspace.std.prebuiltintfrom
upper = space.config.objspace.std.prebuiltintto
# use r_uint to perform a single comparison (this whole function
# is getting inlined into every caller so keeping the branching
# to a minimum is a good idea)
index = r_uint(x - lower)
if index >= r_uint(upper - lower):
w_res = instantiate(W_IntObject)
else:
w_res = W_IntObject.PREBUILT[index]
# obscure hack to help the CPU cache: we store 'x' even into
# a prebuilt integer's intval. This makes sure that the intval
# field is present in the cache in the common case where it is
# quickly reused. (we could use a prefetch hint if we had that)
w_res.intval = x
return w_res
else:
from pypy.objspace.std.intobject import W_IntObject
return W_IntObject(x, w_symbolic, w_s)
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:29,代码来源:inttype.py
示例4: next_skip_x
def next_skip_x(self, shapelen, step):
shapelen = jit.promote(len(self.res_shape))
offset = self.offset
indices = [0] * shapelen
for i in range(shapelen):
indices[i] = self.indices[i]
done = False
for i in range(shapelen - 1, -1, -1):
if indices[i] < self.res_shape[i] - step:
indices[i] += step
offset += self.strides[i] * step
break
else:
remaining_step = (indices[i] + step) // self.res_shape[i]
this_i_step = step - remaining_step * self.res_shape[i]
offset += self.strides[i] * this_i_step
indices[i] = indices[i] + this_i_step
step = remaining_step
else:
done = True
res = instantiate(ViewIterator)
res.offset = offset
res.indices = indices
res.strides = self.strides
res.backstrides = self.backstrides
res.res_shape = self.res_shape
res._done = done
return res
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:28,代码来源:interp_iter.py
示例5: next
def next(self, shapelen):
shapelen = jit.promote(len(self.res_shape))
offset = self.offset
indices = [0] * shapelen
for i in range(shapelen):
indices[i] = self.indices[i]
done = False
for i in range(shapelen - 1, -1, -1):
if indices[i] < self.res_shape[i] - 1:
indices[i] += 1
offset += self.strides[i]
break
else:
indices[i] = 0
offset -= self.backstrides[i]
else:
done = True
res = instantiate(ViewIterator)
res.offset = offset
res.indices = indices
res.strides = self.strides
res.backstrides = self.backstrides
res.res_shape = self.res_shape
res._done = done
return res
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:25,代码来源:interp_iter.py
示例6: frame_new
def frame_new(space, __args__):
args_w, kwds_w = __args__.unpack()
w_pycode, = args_w
pycode = space.interp_w(PyCode, w_pycode)
w = space.wrap
new_frame = instantiate(space.FrameClass) # XXX fish
return space.wrap(new_frame)
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:7,代码来源:maker.py
示例7: make_socket
def make_socket(fd, family, type, proto, SocketClass=RSocket):
result = instantiate(SocketClass)
result.fd = fd
result.family = family
result.type = type
result.proto = proto
result.timeout = defaults.timeout
return result
开发者ID:alkorzt,项目名称:pypy,代码行数:8,代码来源:rsocket.py
示例8: make_null_address
def make_null_address(family):
klass = familyclass(family)
buf = create_string_buffer(klass.maxlen)
result = instantiate(klass)
result._addr_keepalive2 = buf
result.addr = cast(buf, _c.sockaddr_ptr).contents
result.addrlen = 0
return result, len(buf)
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:8,代码来源:rsocket.py
示例9: from_in6_addr
def from_in6_addr(in6_addr):
sin = _c.sockaddr_in6(sin6_family = AF_INET) # PLAT sin_len
sin.sin6_addr = in6_addr
paddr = cast(pointer(sin), _c.sockaddr_ptr)
result = instantiate(INET6Address)
result.addr = paddr.contents
result.addrlen = sizeof(_c.sockaddr_in6)
return result
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:8,代码来源:rsocket.py
示例10: from_in6_addr
def from_in6_addr(in6_addr):
result = instantiate(INET6Address)
# store the malloc'ed data into 'result' as soon as possible
# to avoid leaks if an exception occurs inbetween
sin = lltype.malloc(_c.sockaddr_in6, flavor='raw', zero=True)
result.setdata(sin, sizeof(_c.sockaddr_in6))
rffi.setintfield(sin, 'c_sin6_family', AF_INET)
rffi.structcopy(sin.c_sin6_addr, in6_addr)
return result
开发者ID:alkorzt,项目名称:pypy,代码行数:9,代码来源:rsocket.py
示例11: make_address
def make_address(addrptr, addrlen, result=None):
family = addrptr.contents.sa_family
if result is None:
result = instantiate(familyclass(family))
elif result.family != family:
raise RSocketError("address family mismatched")
paddr = result._addr_keepalive0 = copy_buffer(cast(addrptr, POINTER(c_char)), addrlen)
result.addr = cast(paddr, _c.sockaddr_ptr).contents
result.addrlen = addrlen
return result
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:10,代码来源:rsocket.py
示例12: makeipv4addr
def makeipv4addr(s_addr, result=None):
if result is None:
result = instantiate(INETAddress)
elif result.family != AF_INET:
raise RSocketError("address family mismatched")
sin = lltype.malloc(_c.sockaddr_in, flavor='raw', zero=True)
result.setdata(sin, sizeof(_c.sockaddr_in))
rffi.setintfield(sin, 'c_sin_family', AF_INET) # PLAT sin_len
rffi.setintfield(sin.c_sin_addr, 'c_s_addr', s_addr)
return result
开发者ID:alkorzt,项目名称:pypy,代码行数:10,代码来源:rsocket.py
示例13: unpickle_block
def unpickle_block(space, w_tup):
w_opname, w_handlerposition, w_valuestackdepth = space.unpackiterable(w_tup)
opname = space.str_w(w_opname)
handlerposition = space.int_w(w_handlerposition)
valuestackdepth = space.int_w(w_valuestackdepth)
assert valuestackdepth >= 0
blk = instantiate(get_block_class(opname))
blk.handlerposition = handlerposition
blk.valuestackdepth = valuestackdepth
return blk
开发者ID:enyst,项目名称:plexnet,代码行数:10,代码来源:pyframe.py
示例14: allocate_instance
def allocate_instance(self, cls, w_subtype):
"""Allocate the memory needed for an instance of an internal or
user-defined type, without actually __init__ializing the instance."""
w_type = self.gettypeobject(cls.typedef)
if self.is_w(w_type, w_subtype):
instance = instantiate(cls)
elif cls.typedef.acceptable_as_base_class:
# the purpose of the above check is to avoid the code below
# to be annotated at all for 'cls' if it is not necessary
w_subtype = w_type.check_user_subclass(w_subtype)
subcls = get_unique_interplevel_subclass(cls, w_subtype.hasdict, w_subtype.nslots != 0, w_subtype.needsdel, w_subtype.weakrefable)
instance = instantiate(subcls)
instance.user_setup(self, w_subtype)
else:
raise OperationError(self.w_TypeError,
self.wrap("%s.__new__(%s): only for the type %s" % (
w_type.name, w_subtype.getname(self, '?'), w_type.name)))
assert isinstance(instance, cls)
return instance
开发者ID:antoine1fr,项目名称:pygirl,代码行数:19,代码来源:objspace.py
示例15: makeipv4addr
def makeipv4addr(s_addr, result=None):
if result is None:
result = instantiate(INETAddress)
elif result.family != AF_INET:
raise RSocketError("address family mismatched")
sin = _c.sockaddr_in(sin_family = AF_INET) # PLAT sin_len
sin.sin_addr.s_addr = s_addr
paddr = cast(pointer(sin), _c.sockaddr_ptr)
result._addr_keepalive1 = sin
result.addr = paddr.contents
result.addrlen = sizeof(_c.sockaddr_in)
return result
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:12,代码来源:rsocket.py
示例16: add_offset
def add_offset(self, ofs):
result = instantiate(AddressLoc)
result._location_code = self._location_code
if self._location_code == 'm':
result.loc_m = (self.loc_m[0], self.loc_m[1] + ofs)
elif self._location_code == 'a':
result.loc_a = self.loc_a[:3] + (self.loc_a[3] + ofs,)
elif self._location_code == 'j':
result.value = self.value + ofs
else:
raise AssertionError(self._location_code)
return result
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:12,代码来源:regloc.py
示例17: copy
def copy(self):
from pypy.rlib.objectmodel import instantiate
result = instantiate(SmartResizableListImplementation)
result._length = self._length
result.size_superblock = self.size_superblock
result.size_datablock = self.size_datablock
result.num_superblocks = self.num_superblocks
result.num_datablocks = self.num_datablocks
result.last_superblock_filled = self.last_superblock_filled
result.index_last = self.index_last
result.data_blocks = [l[:] for l in self.data_blocks]
result.space = self.space
return result
开发者ID:AishwaryaKM,项目名称:python-tutorial,代码行数:13,代码来源:smartresizablelist.py
示例18: make_address
def make_address(addrptr, addrlen, result=None):
family = rffi.cast(lltype.Signed, addrptr.c_sa_family)
if result is None:
result = instantiate(familyclass(family))
elif result.family != family:
raise RSocketError("address family mismatched")
# copy into a new buffer the address that 'addrptr' points to
addrlen = rffi.cast(lltype.Signed, addrlen)
buf = lltype.malloc(rffi.CCHARP.TO, addrlen, flavor='raw')
src = rffi.cast(rffi.CCHARP, addrptr)
for i in range(addrlen):
buf[i] = src[i]
result.setdata(buf, addrlen)
return result
开发者ID:alkorzt,项目名称:pypy,代码行数:14,代码来源:rsocket.py
示例19: bootstrap_class
def bootstrap_class(
space, instsize, w_superclass=None, w_metaclass=None, name="?", format=shadow.POINTERS, varsized=False
):
from pypy.lang.smalltalk import model
w_class = model.W_PointersObject(w_metaclass, 0)
# a dummy placeholder for testing
# XXX
s = instantiate(shadow.ClassShadow)
s.space = space
s._w_self = w_class
s.w_superclass = w_superclass
s.name = name
s.instance_size = instsize
s.instance_kind = format
s.w_methoddict = None
s.instance_varsized = varsized or format != shadow.POINTERS
s.invalid = False
w_class.store_shadow(s)
return w_class
开发者ID:AishwaryaKM,项目名称:python-tutorial,代码行数:20,代码来源:objspace.py
示例20: next
def next(self, shapelen):
offset = self.offset
indices = [0] * shapelen
for i in range(shapelen):
indices[i] = self.indices[i]
done = False
for i in range(shapelen - 1, -1, -1):
if indices[i] < self.arr.shape[i] - 1:
indices[i] += 1
offset += self.arr.strides[i]
break
else:
indices[i] = 0
offset -= self.arr.backstrides[i]
else:
done = True
res = instantiate(ViewIterator)
res.offset = offset
res.indices = indices
res.arr = self.arr
res._done = done
return res
开发者ID:craigkerstiens,项目名称:pypy,代码行数:22,代码来源:interp_numarray.py
注:本文中的pypy.rlib.objectmodel.instantiate函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论