Exemple #1
0
    def execute(self):
        obj = self.peek_op_stack()
        if obj.is_null:
            action = actions.throw_null_pointer()
        else:
            action = actions.ThrowObject(obj)

        return Actions(action)
Exemple #2
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)
        )
Exemple #3
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))
Exemple #4
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))
Exemple #5
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)
        )
Exemple #6
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))
Exemple #7
0
def test_int_load_from_null_array():
    array = NULL_VALUE
    index = Integer.create_instance(0)
    assert_instruction(
        instruction='iaload',

        op_stack=[index, array],

        expected=[
            throw_null_pointer()
        ]
    )
Exemple #8
0
def test_int_store_into_null_array():
    value = SOME_INT
    index = Integer.create_instance(1)
    array = NULL_VALUE

    assert_instruction(
        instruction='iastore',

        op_stack=[value, index, array],

        expected=[
            throw_null_pointer()
        ]
    )