예제 #1
0
    def execute(self):
        field_ref = self.operand_as_constant()
        field_name = field_name_from_field_ref(field_ref)
        class_name = field_ref.class_.name.value

        value = self.loader.get_the_statics(class_name)[field_name]
        return IncrementProgramCounter.after(actions.Push(value))
예제 #2
0
파일: math.py 프로젝트: ronyhe/pyjvm
 def execute(self):
     local_index, amount_to_add = [op.value for op in self.instruction.operands]
     original_value = self.locals.load(local_index).value
     new_value = original_value + amount_to_add
     new_instance = Integer.create_instance(new_value)
     return IncrementProgramCounter.after(
         actions.Push(new_instance)
     )
예제 #3
0
파일: math.py 프로젝트: ronyhe/pyjvm
 def execute(self):
     ops = reversed(list(self.peek_many(self.ops)))
     value = self.op(*(op.value for op in ops))
     result = self.type.create_instance(value)
     return IncrementProgramCounter.after(
         actions.Pop(self.ops),
         actions.Push(result)
     )
예제 #4
0
    def execute(self):
        array = self.peek_op_stack()
        if array.is_null:
            return actions.throw_null_pointer()
        else:
            size = len(array.value)
            result = Integer.create_instance(size)

            return IncrementProgramCounter.after(actions.Pop(),
                                                 actions.Push(result))
예제 #5
0
    def execute(self):
        field_ref = self.operand_as_constant()
        name = field_name_from_field_ref(field_ref)
        obj = self.peek_op_stack()
        if obj.is_null:
            return actions.throw_null_pointer()

        value = obj.value.fields[name]
        return IncrementProgramCounter.after(actions.Pop(),
                                             actions.Push(value))
예제 #6
0
    def execute(self):
        index = self.peek_op_stack()
        array = self.peek_op_stack(1)
        if array.is_null:
            return actions.throw_null_pointer()

        value = array.value[index.value]
        return IncrementProgramCounter.after(
            actions.Pop(2),
            actions.Push(value)
        )
예제 #7
0
 def execute(self):
     type_ = self._get_type()
     size = self.peek_op_stack().value
     if size < 0:
         return actions.throw_negative_array_size()
     else:
         elements = [
             type_.create_instance(type_.default_value) for _ in range(size)
         ]
         result = ArrayReferenceType(type_).create_instance(elements)
         return IncrementProgramCounter.after(actions.Pop(),
                                              actions.Push(result))
예제 #8
0
    def execute(self):
        constant_index = self.operand_as_int()
        constant = self.constants[constant_index]
        class_name = constant.name.value

        obj = self.peek_op_stack()
        if obj.is_null:
            answer = False
        else:
            answer = is_value_instance_of(obj, class_as_descriptor(class_name),
                                          self.loader)

        if answer:
            result = Integer.create_instance(1)
        else:
            result = Integer.create_instance(0)

        return IncrementProgramCounter.after(actions.Pop(),
                                             actions.Push(result))
예제 #9
0
    def execute(self):
        class_ = self.operand_as_constant()
        class_name = class_.name.value
        base_type = ObjectReferenceType(class_name)

        num_dimensions = self.operand_as_int(index=1)
        dimensions = [v.value for v in self.peek_many(num_dimensions)]
        if any(d < 0 for d in dimensions):
            return actions.throw_negative_array_size()

        array_type = base_type
        for _ in range(num_dimensions):
            array_type = ArrayReferenceType(array_type)

        array_value = create_levels(
            dimensions,
            lambda: base_type.create_instance(base_type.default_value))

        return IncrementProgramCounter.after(
            actions.Pop(num_dimensions),
            actions.Push(array_type.create_instance(array_value)))
예제 #10
0
파일: conversions.py 프로젝트: ronyhe/pyjvm
 def execute(self):
     value = self.peek_op_stack().value
     converted = self.target.create_instance(value)
     return IncrementProgramCounter.after(actions.Pop(),
                                          actions.Push(converted))
예제 #11
0
 def execute(self):
     return IncrementProgramCounter.after(
         actions.Pop(2), actions.Push(self.peek_op_stack(0)),
         actions.Push(self.peek_op_stack(1)))
예제 #12
0
파일: comparisons.py 프로젝트: ronyhe/pyjvm
 def execute(self):
     values = (value.value for value in self.peek_many(2))
     bool_result = self.op(*values)
     num_result = bool_to_num(bool_result)
     return IncrementProgramCounter.after(actions.Pop(2),
                                          actions.Push(num_result))
예제 #13
0
 def execute(self):
     value = self.locals.load(self.index_in_locals)
     return IncrementProgramCounter.after(
         actions.Push(value)
     )
예제 #14
0
 def execute(self):
     index = self.operand_as_int()
     constant = self.constants[index]
     return IncrementProgramCounter.after(
         actions.Push(convert_constant(constant))
     )
예제 #15
0
 def execute(self):
     """Pushes the literal operand provided in the instruction"""
     value = Integer.create_instance(self.operand_as_int())
     return IncrementProgramCounter.after(
         actions.Push(value)
     )
예제 #16
0
 def execute(self):
     return IncrementProgramCounter.after(
         actions.Push(self.value)
     )