コード例 #1
0
class MapException(MicroInstruction):
    COUNT = 0

    def __init__(self, instr, mapping):
        if isinstance(instr, str):
            self.instr = InstructionList([PushAllArgs, instr, StoreResult])
        else:
            self.instr = InstructionList(instr)
        self.mapping = mapping

    def render(self, generator, op):
        ilasm = generator.ilasm
        label = "__check_block_%d" % MapException.COUNT
        MapException.COUNT += 1
        ilasm.begin_try()
        self.instr.render(generator, op)
        ilasm.leave(label)
        ilasm.end_try()
        for cli_exc, py_exc in self.mapping:
            ilasm.begin_catch(cli_exc)
            ilasm.new("instance void class %s::.ctor()" % py_exc)
            ilasm.opcode("throw")
            ilasm.end_catch()
        ilasm.label(label)
        ilasm.opcode("nop")
コード例 #2
0
class MapException(MicroInstruction):
    COUNT = 0

    def __init__(self, instr, mapping):
        if isinstance(instr, str):
            self.instr = InstructionList([PushAllArgs, instr, StoreResult])
        else:
            self.instr = InstructionList(instr)
        self.mapping = mapping

    def render(self, generator, op):
        ilasm = generator.ilasm
        label = '__check_block_%d' % MapException.COUNT
        MapException.COUNT += 1
        ilasm.begin_try()
        self.instr.render(generator, op)
        ilasm.leave(label)
        ilasm.end_try()
        for cli_exc, py_exc in self.mapping:
            ilasm.begin_catch(cli_exc)
            ilasm.new('instance void class %s::.ctor()' % py_exc)
            ilasm.opcode('throw')
            ilasm.end_catch()
        ilasm.label(label)
        ilasm.opcode('nop')
コード例 #3
0
ファイル: metavm.py プロジェクト: TheDunn/flex-pypy
class MapException(MicroInstruction):
    COUNT = 0
    
    def __init__(self, instr, mapping):
        if isinstance(instr, str):
            self.instr = InstructionList([PushAllArgs, instr, StoreResult])
        else:
            self.instr = InstructionList(instr)
        self.mapping = mapping

    def render(self, generator, op):
        from pypy.translator.cli.function import LastExceptionHandler
        if isinstance(generator, LastExceptionHandler):
            self.render_last(generator, op)
        else:
            self.render_native(generator, op)

    def render_native(self, generator, op):
        ilasm = generator.ilasm
        label = '__check_block_%d' % MapException.COUNT
        MapException.COUNT += 1
        ilasm.begin_try()
        self.instr.render(generator, op)
        ilasm.leave(label)
        ilasm.end_try()
        for cli_exc, py_exc in self.mapping:
            ilasm.begin_catch(cli_exc)
            ilasm.new('instance void class %s::.ctor()' % py_exc)
            ilasm.opcode('throw')
            ilasm.end_catch()
        ilasm.label(label)
        ilasm.opcode('nop')

    def render_last(self, generator, op):
        ilasm = generator.ilasm
        stdflow = '__check_block_%d' % MapException.COUNT
        MapException.COUNT += 1
        premature_return = '__check_block_%d' % MapException.COUNT
        MapException.COUNT += 1
        ilasm.begin_try()
        self.instr.render(generator, op)
        ilasm.leave(stdflow)
        ilasm.end_try()
        for cli_exc, py_exc in self.mapping:
            ilasm.begin_catch(cli_exc)
            ilasm.new('instance void class %s::.ctor()' % py_exc)
            ilasm.opcode('stsfld', 'object last_exception')
            ilasm.leave(stdflow)
            ilasm.end_catch()
        ilasm.label(stdflow)
        ilasm.opcode('nop')
コード例 #4
0
ファイル: function.py プロジェクト: alkorzt/pypy
def render_sub_op(sub_op, db, generator):
    op = sub_op.op
    instr_list = db.genoo.opcodes.get(op.opname, None)
    assert instr_list is not None, 'Unknown opcode: %s ' % op
    assert isinstance(instr_list, InstructionList)
    assert instr_list[-1] is StoreResult, "Cannot inline an operation that doesn't store the result"

    # record that we know about the type of result and args
    db.cts.lltype_to_cts(op.result.concretetype)
    for v in op.args:
        db.cts.lltype_to_cts(v.concretetype)

    instr_list = InstructionList(instr_list[:-1]) # leave the value on the stack if this is a sub-op
    instr_list.render(generator, op)
コード例 #5
0
def fix_opcodes(opcodes):
    for key, value in opcodes.iteritems():
        if type(value) is str:
            value = InstructionList([PushAllArgs, value, StoreResult, CheckLength])
        elif value == []:
            value = InstructionList([CheckLength])
        elif value is not None:
            if StoreResult not in value:
                value.append(StoreResult)
            if CheckLength not in value:
                value.append(CheckLength)
            value = InstructionList(value)

        opcodes[key] = value
コード例 #6
0
def render_sub_op(sub_op, db, generator):
    op = sub_op.op
    instr_list = db.genoo.opcodes.get(op.opname, None)
    assert instr_list is not None, 'Unknown opcode: %s ' % op
    assert isinstance(instr_list, InstructionList)
    assert instr_list[-1] is StoreResult, "Cannot inline an operation that doesn't store the result"

    # record that we know about the type of result and args
    db.cts.lltype_to_cts(op.result.concretetype)
    for v in op.args:
        db.cts.lltype_to_cts(v.concretetype)

    instr_list = InstructionList(instr_list[:-1]) # leave the value on the stack if this is a sub-op
    instr_list.render(generator, op)
コード例 #7
0
def _proc(val):
    if isinstance(val, list):
        # Lists of instructions we leave alone:
        return InstructionList(val)
    elif isinstance(val, jvm.Method) and not val.is_static():
        # For virtual methods, we first push an instance of the relevant
        # class, then the arguments, and then invoke the method.  Note
        # that we only allow virtual methods of certain pre-designated
        # classes to be in the table.
        if val.class_name == jvm.jPyPy.name:
            return InstructionList((PushPyPy, PushAllArgs, val, StoreResult))
        else:
            raise Exception("Unknown class for non-static method")
    # For anything else (static methods, strings, etc) we first push
    # all arguments, then invoke the emit() routine, and finally
    # store the result.
    return InstructionList((PushAllArgs, val, StoreResult))
コード例 #8
0
ファイル: metavm.py プロジェクト: TheDunn/flex-pypy
def fix_opcodes(opcodes):
    for key, value in opcodes.iteritems():
        if type(value) is str:
            value = InstructionList([PushAllArgs, value, StoreResult, CheckLength])
        elif value == []:
            value = InstructionList([CheckLength])
        elif value is not None:
            if StoreResult not in value:
                value.append(StoreResult)
            if CheckLength not in value:
                value.append(CheckLength)
            value = InstructionList(value)

        opcodes[key] = value
コード例 #9
0
ファイル: jsbuiltin.py プロジェクト: griels/pypy-sc
    def __init__(self):
        list_resize = _SetPredefinedField('length')

        self.builtin_map = {
            'll_js_jseval':
            CallBuiltin('eval'),
            'set_on_keydown':
            SetOnEvent('onkeydown'),
            'set_on_keyup':
            SetOnEvent('onkeyup'),
            'setTimeout':
            SetTimeout,
            'll_int_str':
            CallBuiltinMethod('toString', [2]),
            'll_strconcat':
            InstructionList([_PushAllArgs(slice(1, None)), '+']),
            'll_int':
            CallBuiltin('parseInt'),
            #'alert' : CallBuiltin('alert'),
            'seval':
            CallBuiltin('seval'),
            'date':
            NewBuiltin('Date'),
            'll_math.ll_math_fmod':
            InstructionList([_PushAllArgs(slice(1, None)), '%']),
            'll_time_time':
            CallBuiltin('time'),
            'll_time_clock':
            CallBuiltin('clock'),
            'll_os_write':
            CallBuiltin('print'),
            'll_math.ll_math_pow':
            CallBuiltin('Math.pow'),
        }
        self.builtin_obj_map = {
            ootype.String.__class__: {
                'll_strconcat':
                InstructionList([_PushAllArgs(slice(1, None)), '+']),
                'll_strlen':
                _GetPredefinedField('length'),
                'll_stritem_nonneg':
                CallBuiltinMethod('charAt', slice(1, None)),
                'll_streq':
                InstructionList([_PushAllArgs(slice(1, None)), '==']),
                'll_strcmp':
                CallBuiltin('strcmp'),
                'll_startswith':
                CallBuiltin('startswith'),
                'll_endswith':
                CallBuiltin('endswith'),
                'll_split_chr':
                CallBuiltin('splitchr'),
                'll_substring':
                CallBuiltin('substring'),
                'll_lower':
                CallBuiltinMethod('toLowerCase', slice(1, None)),
                'll_upper':
                CallBuiltinMethod('toUpperCase', slice(1, None)),
                'll_find':
                CallBuiltin('findIndexOf'),
                'll_find_char':
                CallBuiltin('findIndexOf'),
                'll_contains':
                CallBuiltin('findIndexOfTrue'),
                'll_replace_chr_chr':
                CallBuiltinMethod('replace', slice(1, None), ['g']),
                'll_count_char':
                CallBuiltin('countCharOf'),
                'll_count':
                CallBuiltin('countOf'),
            },
            ootype.List: {
                'll_setitem_fast': ListSetitem,
                'll_getitem_fast': ListGetitem,
                '_ll_resize': list_resize,
                '_ll_resize_ge': list_resize,
                '_ll_resize_le': list_resize,
                'll_length': _GetPredefinedField('length'),
            },
            ootype.Array: {
                'll_setitem_fast': ListSetitem,
                'll_getitem_fast': ListGetitem,
                'll_length': _GetPredefinedField('length'),
            },
            ootype.Dict: {
                'll_get': ListGetitem,
                'll_set': ListSetitem,
                'll_contains': ListContains,
                'll_get_items_iterator': CallBuiltin('dict_items_iterator'),
                'll_length': CallBuiltin('get_dict_len'),
                'll_remove': ListRemove,
                'll_clear': CallBuiltin('clear_dict'),
            },
            ootype.Record: {
                'll_get': ListGetitem,
                'll_set': ListSetitem,
                'll_contains': ListContains,
            }
        }
        self.fix_opcodes()
コード例 #10
0
 def __init__(self, instr, mapping):
     if isinstance(instr, str):
         self.instr = InstructionList([PushAllArgs, instr, StoreResult])
     else:
         self.instr = InstructionList(instr)
     self.mapping = mapping
コード例 #11
0
    'ullong_lt':
    'clt.un',
    'ullong_le':
    _not('cgt.un'),
    'ullong_eq':
    'ceq',
    'ullong_ne':
    _not('ceq'),
    'ullong_gt':
    'cgt.un',
    'ullong_ge':
    _not('clt.un'),
    'ullong_lshift': [PushAllArgs, 'conv.u4', 'shl'],
    'ullong_rshift': [PushAllArgs, 'conv.i4', 'shr'],
}

opcodes = misc_ops.copy()
opcodes.update(unary_ops)
opcodes.update(binary_ops)

for key, value in opcodes.iteritems():
    if type(value) is str:
        value = InstructionList([PushAllArgs, value, StoreResult])
    elif value is not None:
        if value is not Ignore and StoreResult not in value and not isinstance(
                value[0], MapException):
            value.append(StoreResult)
        value = InstructionList(value)

    opcodes[key] = value
コード例 #12
0
ファイル: opcodes.py プロジェクト: ieure/pypy
    'ullong_mod':               'rem.un',
    'ullong_lt':                'clt.un',
    'ullong_le':                _not('cgt.un'),
    'ullong_eq':                'ceq',
    'ullong_ne':                _not('ceq'),
    'ullong_gt':                'cgt.un',
    'ullong_ge':                _not('clt.un'),
    'ullong_lshift':            [PushAllArgs, 'conv.u4', 'shl'],
    'ullong_rshift':            [PushAllArgs, 'conv.i4', 'shr'],
    'ullong_and':               'and',
    'ullong_or':                'or',

    'oois':                     'ceq',
    'ooisnot':                  _not('ceq'),
}

opcodes = misc_ops.copy()
opcodes.update(unary_ops)
opcodes.update(binary_ops)

for key, value in opcodes.iteritems():
    if type(value) is str:
        value = InstructionList([PushAllArgs, value, StoreResult])
    elif value is not None:
        if value is not Ignore and StoreResult not in value and not isinstance(value[0], MapException):
            value.append(StoreResult)
        value = InstructionList(value)

    opcodes[key] = value

コード例 #13
0
 def __init__(self, instr, mapping):
     if isinstance(instr, str):
         self.instr = InstructionList([PushAllArgs, instr, StoreResult])
     else:
         self.instr = InstructionList(instr)
     self.mapping = mapping