Exemple #1
0
 def init(self) -> None:
     builder = self.builder
     # Create a register to store the state of the loop index and
     # initialize this register along with the loop index to 0.
     zero = builder.add(LoadInt(0))
     self.index_reg = builder.maybe_spill_assignable(zero)
     self.index_target = builder.get_assignment_target(
         self.index)  # type: Union[Register, AssignmentTarget]
     builder.assign(self.index_target, zero, self.line)
Exemple #2
0
 def init(self, start_reg: Value, end_reg: Value, step: int) -> None:
     builder = self.builder
     self.start_reg = start_reg
     self.end_reg = end_reg
     self.step = step
     self.end_target = builder.maybe_spill(end_reg)
     self.index_reg = builder.maybe_spill_assignable(start_reg)
     # Initialize loop index to 0. Assert that the index target is assignable.
     self.index_target = builder.get_assignment_target(
         self.index)  # type: Union[Register, AssignmentTarget]
     builder.assign(self.index_target, builder.read(self.index_reg, self.line), self.line)
Exemple #3
0
 def init(self, expr_reg: Value, target_type: RType, reverse: bool) -> None:
     builder = self.builder
     self.reverse = reverse
     # Define target to contain the expression, along with the index that will be used
     # for the for-loop. If we are inside of a generator function, spill these into the
     # environment class.
     self.expr_target = builder.maybe_spill(expr_reg)
     if not reverse:
         index_reg = builder.add(LoadInt(0))
     else:
         index_reg = builder.binary_op(self.load_len(), builder.add(LoadInt(1)), '-', self.line)
     self.index_target = builder.maybe_spill_assignable(index_reg)
     self.target_type = target_type