pypyjvm / pypy / translator / stm /

from pypy.rpython.lltypesystem import lltype, rffi
from pypy.objspace.flow.model import Constant
from import cdecl, c_string_constant
from pypy.translator.stm.llstm import size_of_voidp

def _stm_generic_get(funcgen, op, (expr_type, expr_ptr, expr_field)):
    T = funcgen.lltypemap(op.result)
    resulttypename = funcgen.db.gettype(T)
    cresulttypename = cdecl(resulttypename, '')
    newvalue = funcgen.expr(op.result, special_case_void=False)
    assert T is not lltype.Void
    fieldsize = rffi.sizeof(T)
    assert fieldsize in (1, 2, 4, 8)
    if T == lltype.Float:
        assert fieldsize == 8
        fieldsize = '8f'
    elif T == lltype.SingleFloat:
        assert fieldsize == 4
        fieldsize = '4f'
    if expr_type is not None:     # optimization for the common case
        return '%s = RPY_STM_FIELD(%s, %s, %s, %s, %s);' % (
            newvalue, cresulttypename, fieldsize,
            expr_type, expr_ptr, expr_field)
        return '%s = RPY_STM_ARRAY(%s, %s, %s, %s);' % (
            newvalue, cresulttypename, fieldsize,
            expr_ptr, expr_field)

def field_expr(funcgen, args):
    STRUCT = funcgen.lltypemap(args[0]).TO
    structdef = funcgen.db.gettypedefnode(STRUCT)
    fldname = structdef.c_struct_field_name(args[1].value)
    ptr = funcgen.expr(args[0])
    return ('%s %s' % (structdef.typetag,, ptr, fldname)

def stm_getfield(funcgen, op):
    access_info = field_expr(funcgen, op.args)
    return _stm_generic_get(funcgen, op, access_info)

def array_expr(funcgen, args):
    ARRAY = funcgen.lltypemap(args[0]).TO
    ptr = funcgen.expr(args[0])
    index = funcgen.expr(args[1])
    arraydef = funcgen.db.gettypedefnode(ARRAY)
    return (None, ptr, arraydef.itemindex_access_expr(ptr, index))

def stm_getarrayitem(funcgen, op):
    access_info = array_expr(funcgen, op.args)
    return _stm_generic_get(funcgen, op, access_info)

def stm_getinteriorfield(funcgen, op):
    ptr = funcgen.expr(op.args[0])
    expr = funcgen.interior_expr(op.args)
    access_info = (None, ptr, expr)
    return _stm_generic_get(funcgen, op, access_info)

def stm_become_inevitable(funcgen, op):
    info = op.args[0].value
    string_literal = c_string_constant(info)
    return 'stm_try_inevitable(STM_EXPLAIN1(%s));' % (string_literal,)

def op_stm(funcgen, op):
    func = globals()[op.opname]
    return func(funcgen, op)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.