Exemple #1
0
 def execute(self):
     source = self.instruction.pos
     value = self.peek_op_stack()
     switch = self.switch_class.from_instruction(self.instruction)
     offset = switch.find_offset(value.value)
     target = source + offset
     return Actions(actions.Pop(), actions.GoTo(target))
Exemple #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))
Exemple #3
0
 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)
     )
Exemple #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))
Exemple #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))
Exemple #6
0
    def execute(self):
        values = self._get_values()
        result = self.op(*values)

        if result:
            offset = self.operand_as_int()
        else:
            offset = 1

        target = self.instruction.pos + offset
        return Actions(actions.Pop(self.pops), actions.GoTo(target))
Exemple #7
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 #8
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 #9
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))
Exemple #10
0
    def execute(self):
        method_ref = self.operand_as_constant()
        class_name = method_ref.class_.name.value
        key = key_from_method_ref(method_ref)

        class_ = self.loader.get_the_class(class_name)
        method = class_.methods[key]
        num_args = len(method.args) + self.args_to_add
        args = reversed(self.peek_many(num_args))

        return Actions(
            actions.Pop(num_args),
            actions.Invoke(class_name, key, args)
        )
Exemple #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()
        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))
Exemple #12
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)))
Exemple #13
0
 def execute(self):
     value = self.peek_op_stack().value
     converted = self.target.create_instance(value)
     return IncrementProgramCounter.after(actions.Pop(),
                                          actions.Push(converted))
Exemple #14
0
 def execute(self):
     return IncrementProgramCounter.after(
         actions.Pop(2), actions.Push(self.peek_op_stack(0)),
         actions.Push(self.peek_op_stack(1)))
Exemple #15
0
 def execute(self):
     return IncrementProgramCounter.after(actions.Pop(self.amount))
Exemple #16
0
 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))