예제 #1
0
파일: metavm.py 프로젝트: sota/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):
        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
파일: metavm.py 프로젝트: sota/pypy-old
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
파일: function.py 프로젝트: sota/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)
예제 #4
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)
예제 #5
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))
예제 #6
0
파일: metavm.py 프로젝트: sota/pypy-old
 def __init__(self, instr, mapping):
     if isinstance(instr, str):
         self.instr = InstructionList([PushAllArgs, instr, StoreResult])
     else:
         self.instr = InstructionList(instr)
     self.mapping = mapping
예제 #7
0
파일: opcodes.py 프로젝트: sota/pypy-old
    '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
예제 #8
0
파일: metavm.py 프로젝트: sota/pypy
 def __init__(self, instr, mapping):
     if isinstance(instr, str):
         self.instr = InstructionList([PushAllArgs, instr, StoreResult])
     else:
         self.instr = InstructionList(instr)
     self.mapping = mapping
예제 #9
0
파일: opcodes.py 프로젝트: sota/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