예제 #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
 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.peek_op_stack()
     return IncrementProgramCounter.after(
         actions.Pop(), actions.PutStatic(class_name, field_name, value))
예제 #3
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)
     )
예제 #4
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)
     )
예제 #5
0
    def execute(self):
        value, index, array = (self.peek_op_stack(i) for i in range(3))
        if array.is_null:
            return actions.throw_null_pointer()

        return IncrementProgramCounter.after(
            actions.StoreIntoArray(array=array, index=index.value, value=value),
            Pop(3)
        )
예제 #6
0
    def execute(self):
        for comp_type_string, amount_to_take, index_for_insertion in self.specs:
            if self.matches_comp_types(comp_type_string):
                return IncrementProgramCounter.after(
                    actions.DuplicateTop(
                        amount_to_take=amount_to_take,
                        index_for_insertion=index_for_insertion))

        raise ValueError('No comp type case match')
예제 #7
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))
예제 #8
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))
예제 #9
0
    def execute(self):
        field_ref = self.operand_as_constant()
        name = field_name_from_field_ref(field_ref)
        value = self.peek_op_stack(0)
        obj = self.peek_op_stack(1)

        if obj.is_null:
            return actions.throw_null_pointer()

        return IncrementProgramCounter.after(
            actions.Pop(2), actions.PutField(obj, name, value))
예제 #10
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)
        )
예제 #11
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()
        answer = obj.is_null or is_value_instance_of(
            obj, class_as_descriptor(class_name), self.loader)
        if answer:
            return IncrementProgramCounter()
        else:
            return actions.throw_check_cast()
예제 #12
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))
예제 #13
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))
예제 #14
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)))
예제 #15
0
 def execute(self):
     return IncrementProgramCounter.after(actions.Pop(self.amount))
예제 #16
0
 def execute(self):
     index = self.operand_as_int()
     constant = self.constants[index]
     return IncrementProgramCounter.after(
         actions.Push(convert_constant(constant))
     )
예제 #17
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))
예제 #18
0
 def execute(self):
     return IncrementProgramCounter.after(
         actions.StoreInLocals(index=self.index_in_locals, value=self.peek_op_stack()),
         Pop()
     )
예제 #19
0
 def execute(self):
     value = self.locals.load(self.index_in_locals)
     return IncrementProgramCounter.after(
         actions.Push(value)
     )
예제 #20
0
 def execute(self):
     return IncrementProgramCounter()
예제 #21
0
def test_increment_program_counter():
    machine = complex_machine()
    machine.act(IncrementProgramCounter())
    assert machine.frames.peek().pc == 1
예제 #22
0
 def execute(self):
     class_constant_index = self.operand_as_int()
     class_constant = self.constants[class_constant_index]
     class_name = class_constant.name.value
     class_ = self.loader.get_the_class(class_name)
     return IncrementProgramCounter.after(actions.PushNewInstance(class_))
예제 #23
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)
     )
예제 #24
0
 def execute(self):
     return IncrementProgramCounter.after(
         actions.Pop(2), actions.Push(self.peek_op_stack(0)),
         actions.Push(self.peek_op_stack(1)))
예제 #25
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))
예제 #26
0
 def execute(self):
     return IncrementProgramCounter.after(
         actions.Push(self.value)
     )