Example #1
0
 def gen_assign(n, g=True):
     slot = c.Var('memory_slot_%d' % n)
     self.define_objective('memory_slot_%d' % n, None)
     return c.ExecuteChain() \
             .cond('if') \
             .score_range(mar, c.ScoreRange(n, n)) \
             .run(c.OpAssign(mbr if g else slot, slot if g else mbr))
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))
 def apply(self, exec, chain, out):
     with exec.context(self.var.open_for_read(out)) as ref:
         chain.cond(self.condtype).score_range(
             ref, c.ScoreRange(self.min, self.max))
Example #4
0
 def apply(self, out, func):
     range = c.ScoreRange(self.min, self.max)
     with self.var.open_for_read(out) as var:
         _branch_apply(out, func.namespace, self.if_true, self.if_false,
                       lambda cond: cond.score_range(var, range))
Example #5
0
 def gen_fn(fn, p):
     return c.ExecuteChain() \
            .cond('if') \
            .score_range(mar, c.ScoreRange(p.min, p.max)) \
            .run(c.Function(pair_name(fn, p)))