예제 #1
0
 def scale_down(self, ref, out):
     if self.type.scale != 1:
         # TODO extract to constant reference
         scaleparam = out.allocate_temp()
         out.write(c.SetConst(scaleparam, self.type.scale))
         out.write(c.OpDiv(ref, scaleparam))
         out.free_temp(scaleparam)
예제 #2
0
 def scale_other_to_this(self, other, otherref, out):
     factor = self.type.scale / other.type.scale
     op = c.OpMul
     if factor < 1:
         factor = 1 / factor
         op = c.OpDiv
     factor = int(factor)
     if factor == 1:
         return otherref, False
     scaled = out.allocate_temp()
     out.write(c.OpAssign(scaled, otherref))
     # TODO extract to constant reference
     scaleparam = out.allocate_temp()
     out.write(c.SetConst(scaleparam, factor))
     out.write(op(scaled, scaleparam))
     out.free_temp(scaleparam)
     return scaled, True
def _branch_apply(out, if_true, if_false, apply):
    inverted = not if_true
    if inverted:
        if_true, if_false = if_false, if_true
    have_false = if_false is not None
    if have_false:
        # Workaround: execute store doesn't set success to 0 if failed
        # See MC-125058
        # Can't use execute store anyway because it locks the success
        # tracker. See MC-125145
        out.write(c.SetConst(c.Var('success_tracker'), 0))
    true_fn = c.Function(if_true.global_name)
    out.write(
        apply(c.ExecuteChain().cond('unless' if inverted else 'if')).run(
            true_fn))
    if have_false:
        false_fn = c.Function(if_false.global_name)
        out.write(c.ExecuteChain().cond('if').score_range(
            c.Var('success_tracker'), c.ScoreRange(0, 0)).run(false_fn))
예제 #4
0
 def set_const_val(self, value, out):
     out.write(c.SetConst(self.ref, self.to_int(value)))
 def apply(self, out, chain, storechain):
     with chain.context(self.var.open_for_write(out)) as ref:
         if storechain.store_type == 'success':
             out.write(c.SetConst(ref, 0))  # MC-125058
         storechain.score(ref)
예제 #6
0
 def apply_const_src(self, ref, val, out):
     srcref = out.allocate_temp()
     out.write(c.SetConst(srcref, val))
     out.write(self.with_ref(ref, srcref))
     out.free_temp(srcref)
예제 #7
0
 def extended_setup(self, up, down):
     for i in range(self.page_size):
         slot = c.Var('memory_slot_%d' % i)
         up.append(c.SetConst(slot, 0).resolve(self.scope))