本文整理汇总了Python中pypy.jit.backend.llsupport.symbolic.get_array_token函数的典型用法代码示例。如果您正苦于以下问题:Python get_array_token函数的具体用法?Python get_array_token怎么用?Python get_array_token使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_array_token函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_boehm
def test_boehm():
gc_ll_descr = GcLLDescr_boehm(None, None, None)
#
record = []
prev_malloc_fn_ptr = gc_ll_descr.malloc_fn_ptr
def my_malloc_fn_ptr(size):
p = prev_malloc_fn_ptr(size)
record.append((size, p))
return p
gc_ll_descr.malloc_fn_ptr = my_malloc_fn_ptr
#
# ---------- gc_malloc ----------
S = lltype.GcStruct('S', ('x', lltype.Signed))
sizedescr = get_size_descr(gc_ll_descr, S)
p = gc_ll_descr.gc_malloc(sizedescr)
assert record == [(sizedescr.size, p)]
del record[:]
# ---------- gc_malloc_array ----------
A = lltype.GcArray(lltype.Signed)
arraydescr = get_array_descr(gc_ll_descr, A)
p = gc_ll_descr.gc_malloc_array(arraydescr, 10)
assert record == [(arraydescr.basesize +
10 * arraydescr.itemsize, p)]
del record[:]
# ---------- gc_malloc_str ----------
p = gc_ll_descr.gc_malloc_str(10)
basesize, itemsize, ofs_length = symbolic.get_array_token(rstr.STR, False)
assert record == [(basesize + 10 * itemsize, p)]
del record[:]
# ---------- gc_malloc_unicode ----------
p = gc_ll_descr.gc_malloc_unicode(10)
basesize, itemsize, ofs_length = symbolic.get_array_token(rstr.UNICODE,
False)
assert record == [(basesize + 10 * itemsize, p)]
del record[:]
示例2: __init__
def __init__(self, rtyper, stats=None, translate_support_code=False,
annmixlevel=None, gcdescr=None):
self.rtyper = rtyper
self.translate_support_code = translate_support_code
self.compiled_functions = []
self.fail_ops = []
self.in_out_args = []
if translate_support_code:
get_size = llmemory.sizeof
else:
get_size = rffi.sizeof
self._arraydescrs = [
ArrayDescr(get_size(llmemory.GCREF), self.SIZE_GCPTR), # 0
ArrayDescr(get_size(lltype.Signed), self.SIZE_INT), # 1
ArrayDescr(get_size(lltype.Char), self.SIZE_CHAR), # 2
ArrayDescr(get_size(lltype.UniChar), self.SIZE_UNICHAR), # 3
]
self._descr_caches = {}
self.fielddescr_vtable = self.fielddescrof(rclass.OBJECT, 'typeptr')
if sys.maxint == 2147483647:
self.size_of_int = 4
else:
self.size_of_int = 8
if runicode.MAXUNICODE > 0xffff:
self.size_of_unicode = 4
else:
self.size_of_unicode = 2
self.gcarray_gcref = lltype.GcArray(llmemory.GCREF)
self.gcarray_signed = lltype.GcArray(lltype.Signed)
self.gcarray_char = lltype.GcArray(lltype.Char)
self.gcarray_unichar = lltype.GcArray(lltype.UniChar)
basesize, _, ofs_length = symbolic.get_array_token(
self.gcarray_signed, self.translate_support_code)
self.array_index_array = basesize
self.array_index_length = ofs_length
basesize, _, ofs_length = symbolic.get_array_token(
rstr.STR, self.translate_support_code)
self.string_index_array = basesize
self.string_index_length = ofs_length
basesize, _, ofs_length = symbolic.get_array_token(
rstr.UNICODE, self.translate_support_code)
self.unicode_index_array = basesize
self.unicode_index_length = ofs_length
self.vtable_descr = self.fielddescrof(rclass.OBJECT, 'typeptr')
self._ovf_error_instance = self._get_prebuilt_error(OverflowError)
self._zer_error_instance = self._get_prebuilt_error(ZeroDivisionError)
#
# temporary (Boehm only)
from pypy.translator.tool.cbuild import ExternalCompilationInfo
compilation_info = ExternalCompilationInfo(libraries=['gc'])
self.malloc_fn_ptr = rffi.llexternal("GC_malloc",
[rffi.SIZE_T],
llmemory.GCREF,
compilation_info=compilation_info,
sandboxsafe=True,
_nowrapper=True)
assert rffi.sizeof(rffi.SIZE_T) == self.size_of_int
示例3: __init__
def __init__(self, gcdescr, translator, rtyper):
GcLLDescription.__init__(self, gcdescr, translator, rtyper)
# grab a pointer to the Boehm 'malloc' function
malloc_fn_ptr = self.configure_boehm_once()
self.funcptr_for_new = malloc_fn_ptr
def malloc_array(basesize, itemsize, ofs_length, num_elem):
try:
size = ovfcheck(basesize + ovfcheck(itemsize * num_elem))
except OverflowError:
return lltype.nullptr(llmemory.GCREF.TO)
res = self.funcptr_for_new(size)
if not res:
return res
rffi.cast(rffi.CArrayPtr(lltype.Signed), res)[ofs_length/WORD] = num_elem
return res
self.malloc_array = malloc_array
self.GC_MALLOC_ARRAY = lltype.Ptr(lltype.FuncType(
[lltype.Signed] * 4, llmemory.GCREF))
(str_basesize, str_itemsize, str_ofs_length
) = symbolic.get_array_token(rstr.STR, self.translate_support_code)
(unicode_basesize, unicode_itemsize, unicode_ofs_length
) = symbolic.get_array_token(rstr.UNICODE, self.translate_support_code)
def malloc_str(length):
return self.malloc_array(
str_basesize, str_itemsize, str_ofs_length, length
)
def malloc_unicode(length):
return self.malloc_array(
unicode_basesize, unicode_itemsize, unicode_ofs_length, length
)
self.malloc_str = malloc_str
self.malloc_unicode = malloc_unicode
self.GC_MALLOC_STR_UNICODE = lltype.Ptr(lltype.FuncType(
[lltype.Signed], llmemory.GCREF))
# on some platform GC_init is required before any other
# GC_* functions, call it here for the benefit of tests
# XXX move this to tests
init_fn_ptr = rffi.llexternal("GC_init",
[], lltype.Void,
compilation_info=self.compilation_info,
sandboxsafe=True,
_nowrapper=True)
init_fn_ptr()
示例4: do_strsetitem
def do_strsetitem(self, stringbox, indexbox, vbox):
basesize, itemsize, ofs_length = symbolic.get_array_token(rstr.STR,
self.translate_support_code)
index = indexbox.getint()
v = vbox.getint()
a = stringbox.getref_base()
rffi.cast(rffi.CArrayPtr(lltype.Char), a)[index + basesize] = chr(v)
示例5: do_strgetitem
def do_strgetitem(self, stringbox, indexbox):
basesize, itemsize, ofs_length = symbolic.get_array_token(rstr.STR,
self.translate_support_code)
gcref = stringbox.getref_base()
i = indexbox.getint()
v = rffi.cast(rffi.CArrayPtr(lltype.Char), gcref)[basesize + i]
return BoxInt(ord(v))
示例6: gc_malloc_unicode
def gc_malloc_unicode(self, num_elem):
basesize, itemsize, ofs_length = symbolic.get_array_token(rstr.UNICODE,
self.translate_support_code)
size = basesize + num_elem * itemsize
res = self.funcptr_for_new(size)
rffi.cast(rffi.CArrayPtr(lltype.Signed), res)[ofs_length/WORD] = num_elem
return res
示例7: arraydescrof
def arraydescrof(self, A):
basesize, _, ofs_length = symbolic.get_array_token(A,
self.translate_support_code)
if isinstance(basesize, int): # else Symbolics, can't be compared...
assert self.array_index_array == basesize
assert self.array_index_length == ofs_length
itemsize_index = self._get_size_index(A.OF)
return self._arraydescrs[itemsize_index]
示例8: do_unicodesetitem
def do_unicodesetitem(self, stringbox, indexbox, vbox):
basesize, itemsize, ofs_length = symbolic.get_array_token(rstr.UNICODE,
self.translate_support_code)
index = indexbox.getint()
v = vbox.getint()
a = stringbox.getref_base()
basesize = basesize // itemsize
rffi.cast(rffi.CArrayPtr(lltype.UniChar), a)[index + basesize] = unichr(v)
示例9: test_gc_malloc_unicode
def test_gc_malloc_unicode(self):
p = self.gc_ll_descr.gc_malloc_unicode(10)
type_id = self.gc_ll_descr.layoutbuilder.get_type_id(rstr.UNICODE)
tid = llop.combine_ushort(lltype.Signed, type_id, 0)
basesize, itemsize, ofs_length = symbolic.get_array_token(rstr.UNICODE,
True)
assert self.llop1.record == [("varsize", tid, 10,
repr(basesize), repr(itemsize),
repr(ofs_length), p)]
示例10: consider_newstr
def consider_newstr(self, op):
gc_ll_descr = self.assembler.cpu.gc_ll_descr
if gc_ll_descr.get_funcptr_for_newstr is not None:
# framework GC
loc = self.loc(op.args[0])
return self._call(op, [loc])
# boehm GC (XXX kill the following code at some point)
ofs_items, itemsize, ofs = symbolic.get_array_token(rstr.STR, self.translate_support_code)
assert itemsize == 1
return self._malloc_varsize(ofs_items, ofs, 0, op.args[0], op.result)
示例11: get_field_arraylen_descr
def get_field_arraylen_descr(gccache, ARRAY_OR_STRUCT):
cache = gccache._cache_arraylen
try:
return cache[ARRAY_OR_STRUCT]
except KeyError:
tsc = gccache.translate_support_code
(_, _, ofs) = symbolic.get_array_token(ARRAY_OR_STRUCT, tsc)
size = symbolic.get_size(lltype.Signed, tsc)
result = FieldDescr("len", ofs, size, get_type_flag(lltype.Signed))
cache[ARRAY_OR_STRUCT] = result
return result
示例12: consider_newunicode
def consider_newunicode(self, op):
gc_ll_descr = self.assembler.cpu.gc_ll_descr
if gc_ll_descr.get_funcptr_for_newunicode is not None:
# framework GC
loc = self.loc(op.args[0])
return self._call(op, [loc])
# boehm GC (XXX kill the following code at some point)
ofs_items, itemsize, ofs = symbolic.get_array_token(rstr.UNICODE, self.translate_support_code)
if itemsize == 4:
return self._malloc_varsize(ofs_items, ofs, 2, op.args[0], op.result)
elif itemsize == 2:
return self._malloc_varsize(ofs_items, ofs, 1, op.args[0], op.result)
else:
assert False, itemsize
示例13: get_array_descr
def get_array_descr(gccache, ARRAY_OR_STRUCT):
cache = gccache._cache_array
try:
return cache[ARRAY_OR_STRUCT]
except KeyError:
tsc = gccache.translate_support_code
basesize, itemsize, _ = symbolic.get_array_token(ARRAY_OR_STRUCT, tsc)
if isinstance(ARRAY_OR_STRUCT, lltype.Array):
ARRAY_INSIDE = ARRAY_OR_STRUCT
else:
ARRAY_INSIDE = ARRAY_OR_STRUCT._flds[ARRAY_OR_STRUCT._arrayfld]
if ARRAY_INSIDE._hints.get('nolength', False):
lendescr = None
else:
lendescr = get_field_arraylen_descr(gccache, ARRAY_OR_STRUCT)
flag = get_type_flag(ARRAY_INSIDE.OF)
arraydescr = ArrayDescr(basesize, itemsize, lendescr, flag)
if ARRAY_OR_STRUCT._gckind == 'gc':
gccache.init_array_descr(ARRAY_OR_STRUCT, arraydescr)
cache[ARRAY_OR_STRUCT] = arraydescr
return arraydescr
示例14: get_array_descr
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)
if not ARRAY._hints.get('nolength', False):
assert ofslength == arraydescr.get_ofs_length(False)
if isinstance(ARRAY, lltype.GcArray):
gccache.init_array_descr(ARRAY, arraydescr)
cache[ARRAY] = arraydescr
return arraydescr
示例15: get_base_size
def get_base_size(self, translate_support_code):
basesize, _, _ = symbolic.get_array_token(_AF, translate_support_code)
return basesize