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))
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))
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) )
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) )
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) )
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')
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))
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))
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))
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) )
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()
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))
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))
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)))
def execute(self): return IncrementProgramCounter.after(actions.Pop(self.amount))
def execute(self): index = self.operand_as_int() constant = self.constants[index] return IncrementProgramCounter.after( actions.Push(convert_constant(constant)) )
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))
def execute(self): return IncrementProgramCounter.after( actions.StoreInLocals(index=self.index_in_locals, value=self.peek_op_stack()), Pop() )
def execute(self): value = self.locals.load(self.index_in_locals) return IncrementProgramCounter.after( actions.Push(value) )
def execute(self): return IncrementProgramCounter()
def test_increment_program_counter(): machine = complex_machine() machine.act(IncrementProgramCounter()) assert machine.frames.peek().pc == 1
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_))
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) )
def execute(self): return IncrementProgramCounter.after( actions.Pop(2), actions.Push(self.peek_op_stack(0)), actions.Push(self.peek_op_stack(1)))
def execute(self): value = self.peek_op_stack().value converted = self.target.create_instance(value) return IncrementProgramCounter.after(actions.Pop(), actions.Push(converted))
def execute(self): return IncrementProgramCounter.after( actions.Push(self.value) )