broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(data, kinds):
    pos = 0
    out = []
    for kind in kinds:
        bits = 32 if kind in ('u32', 's32') else 64
        maxlen = (bits + 6) // 7
        result = 0
        shift = 0
        n = 0
        while True:
            if pos >= len(data):
                return out + [['unexpected-end', pos]]
            byte = data[pos]
            pos += 1
            n += 1
            result |= (byte & 0x7F) << shift
            shift += 7
            if (byte & 0x80) == 0:
                break
            if n == maxlen:
                return out + [['too-long', pos]]
        if kind[0] == 's' and byte & 0x40:
            result -= 1 << shift
        if kind == 's32' and not -(1 << 31) <= result <= (1 << 31):
            return out + [['out-of-range', pos]]
        if kind == 'u32' and result >= (1 << 32):
            return out + [['out-of-range', pos]]
        out.append(result)
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression: mixed immediates', ([237, 7, 179, 127, 127], ['u32', 's32', 's64']), [1005, -77, -1]),
  ('single byte 0x7F', ([127, 127], ['u32', 's32']), [127, -1]),
  ('five-byte u32 is the maximum length', ([128, 128, 128, 128, 1], ['u32']), [268435456]),
  ('six-byte u32 is too long', ([128, 128, 128, 128, 128, 0, 1], ['u32', 'u32']), [['too-long', 5]]),
  ('s32 2^31 out of range, -2^31 in range',
   ([128, 128, 128, 128, 120, 128, 128, 128, 128, 8], ['s32', 's32']),
   [-2147483648, ['out-of-range', 10]]),
  ('u32 with bit 6 set in last byte stays positive', ([65, 128, 64], ['u32', 'u32']), [65, 8192]),
  ('negative s64 spanning several bytes', ([255, 255, 255, 255, 255, 95], ['s64']), [-1099511627777]),
  ('truncated immediate', ([128, 129], ['u64']), [['unexpected-end', 2]])],
 [('regression: mixed immediates', ([213, 15, 230, 126, 127], ['u32', 's32', 's64']), [2005, -154, -1]),
  ('single byte 0x7F', ([127, 127], ['u32', 's32']), [127, -1]),
  ('five-byte u32 is the maximum length', ([128, 128, 128, 128, 2], ['u32']), [536870912]),
  ('six-byte u32 is too long', ([128, 128, 128, 128, 128, 0, 2], ['u32', 'u32']), [['too-long', 5]]),
  ('s32 2^31 out of range, -2^31 in range',
   ([128, 128, 128, 128, 120, 128, 128, 128, 128, 8], ['s32', 's32']),
   [-2147483648, ['out-of-range', 10]]),
  ('u32 with bit 6 set in last byte stays positive', ([66, 128, 64], ['u32', 'u32']), [66, 8192]),
  ('negative s64 spanning several bytes', ([254, 255, 255, 255, 255, 95], ['s64']), [-1099511627778]),
  ('truncated immediate', ([128, 130], ['u64']), [['unexpected-end', 2]])],
 [('regression: mixed immediates', ([189, 23, 153, 126, 127], ['u32', 's32', 's64']), [3005, -231, -1]),
  ('single byte 0x7F', ([127, 127], ['u32', 's32']), [127, -1]),
  ('five-byte u32 is the maximum length', ([128, 128, 128, 128, 3], ['u32']), [805306368]),
  ('six-byte u32 is too long', ([128, 128, 128, 128, 128, 0, 3], ['u32', 'u32']), [['too-long', 5]]),
  ('s32 2^31 out of range, -2^31 in range',
   ([128, 128, 128, 128, 120, 128, 128, 128, 128, 8], ['s32', 's32']),
   [-2147483648, ['out-of-range', 10]]),
  ('u32 with bit 6 set in last byte stays positive', ([67, 128, 64], ['u32', 'u32']), [67, 8192]),
  ('negative s64 spanning several bytes', ([253, 255, 255, 255, 255, 95], ['s64']), [-1099511627779]),
  ('truncated immediate', ([128, 131], ['u64']), [['unexpected-end', 2]])],
 [('regression: mixed immediates', ([165, 31, 204, 125, 127], ['u32', 's32', 's64']), [4005, -308, -1]),
  ('single byte 0x7F', ([127, 127], ['u32', 's32']), [127, -1]),
  ('five-byte u32 is the maximum length', ([128, 128, 128, 128, 4], ['u32']), [1073741824]),
  ('six-byte u32 is too long', ([128, 128, 128, 128, 128, 0, 4], ['u32', 'u32']), [['too-long', 5]]),
  ('s32 2^31 out of range, -2^31 in range',
   ([128, 128, 128, 128, 120, 128, 128, 128, 128, 8], ['s32', 's32']),
   [-2147483648, ['out-of-range', 10]]),
  ('u32 with bit 6 set in last byte stays positive', ([68, 128, 64], ['u32', 'u32']), [68, 8192]),
  ('negative s64 spanning several bytes', ([252, 255, 255, 255, 255, 95], ['s64']), [-1099511627780]),
  ('truncated immediate', ([128, 132], ['u64']), [['unexpected-end', 2]])],
 [('regression: mixed immediates', ([141, 39, 255, 124, 127], ['u32', 's32', 's64']), [5005, -385, -1]),
  ('single byte 0x7F', ([127, 127], ['u32', 's32']), [127, -1]),
  ('five-byte u32 is the maximum length', ([128, 128, 128, 128, 5], ['u32']), [1342177280]),
  ('six-byte u32 is too long', ([128, 128, 128, 128, 128, 0, 5], ['u32', 'u32']), [['too-long', 5]]),
  ('s32 2^31 out of range, -2^31 in range',
   ([128, 128, 128, 128, 120, 128, 128, 128, 128, 8], ['s32', 's32']),
   [-2147483648, ['out-of-range', 10]]),
  ('u32 with bit 6 set in last byte stays positive', ([69, 128, 64], ['u32', 'u32']), [69, 8192]),
  ('negative s64 spanning several bytes', ([251, 255, 255, 255, 255, 95], ['s64']), [-1099511627781]),
  ('truncated immediate', ([128, 133], ['u64']), [['unexpected-end', 2]])]]
for label, args, expected in cases[N - 1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(data, kinds):
    pos = 0
    out = []
    for kind in kinds:
        bits = 32 if kind in ('u32', 's32') else 64
        maxlen = (bits + 6) // 7
        result = 0
        shift = 0
        n = 0
        while True:
            if pos >= len(data):
                return out + [['unexpected-end', pos]]
            byte = data[pos]
            pos += 1
            n += 1
            result |= (byte & 0x7F) << shift
            shift += 7
            if (byte & 0x80) == 0:
                break
            if n == maxlen:
                return out + [['too-long', pos]]
        if kind[0] == 's' and byte & 0x40:
            result -= 1 << shift
        if kind == 's32' and not 0 <= result < (1 << 32):
            return out + [['out-of-range', pos]]
        if kind == 'u32' and result >= (1 << 32):
            return out + [['out-of-range', pos]]
        out.append(result)
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression: mixed immediates', ([237, 7, 179, 127, 127], ['u32', 's32', 's64']), [1005, -77, -1]),
  ('single byte 0x7F', ([127, 127], ['u32', 's32']), [127, -1]),
  ('five-byte u32 is the maximum length', ([128, 128, 128, 128, 1], ['u32']), [268435456]),
  ('six-byte u32 is too long', ([128, 128, 128, 128, 128, 0, 1], ['u32', 'u32']), [['too-long', 5]]),
  ('s32 2^31 out of range, -2^31 in range',
   ([128, 128, 128, 128, 120, 128, 128, 128, 128, 8], ['s32', 's32']),
   [-2147483648, ['out-of-range', 10]]),
  ('u32 with bit 6 set in last byte stays positive', ([65, 128, 64], ['u32', 'u32']), [65, 8192]),
  ('negative s64 spanning several bytes', ([255, 255, 255, 255, 255, 95], ['s64']), [-1099511627777]),
  ('truncated immediate', ([128, 129], ['u64']), [['unexpected-end', 2]])],
 [('regression: mixed immediates', ([213, 15, 230, 126, 127], ['u32', 's32', 's64']), [2005, -154, -1]),
  ('single byte 0x7F', ([127, 127], ['u32', 's32']), [127, -1]),
  ('five-byte u32 is the maximum length', ([128, 128, 128, 128, 2], ['u32']), [536870912]),
  ('six-byte u32 is too long', ([128, 128, 128, 128, 128, 0, 2], ['u32', 'u32']), [['too-long', 5]]),
  ('s32 2^31 out of range, -2^31 in range',
   ([128, 128, 128, 128, 120, 128, 128, 128, 128, 8], ['s32', 's32']),
   [-2147483648, ['out-of-range', 10]]),
  ('u32 with bit 6 set in last byte stays positive', ([66, 128, 64], ['u32', 'u32']), [66, 8192]),
  ('negative s64 spanning several bytes', ([254, 255, 255, 255, 255, 95], ['s64']), [-1099511627778]),
  ('truncated immediate', ([128, 130], ['u64']), [['unexpected-end', 2]])],
 [('regression: mixed immediates', ([189, 23, 153, 126, 127], ['u32', 's32', 's64']), [3005, -231, -1]),
  ('single byte 0x7F', ([127, 127], ['u32', 's32']), [127, -1]),
  ('five-byte u32 is the maximum length', ([128, 128, 128, 128, 3], ['u32']), [805306368]),
  ('six-byte u32 is too long', ([128, 128, 128, 128, 128, 0, 3], ['u32', 'u32']), [['too-long', 5]]),
  ('s32 2^31 out of range, -2^31 in range',
   ([128, 128, 128, 128, 120, 128, 128, 128, 128, 8], ['s32', 's32']),
   [-2147483648, ['out-of-range', 10]]),
  ('u32 with bit 6 set in last byte stays positive', ([67, 128, 64], ['u32', 'u32']), [67, 8192]),
  ('negative s64 spanning several bytes', ([253, 255, 255, 255, 255, 95], ['s64']), [-1099511627779]),
  ('truncated immediate', ([128, 131], ['u64']), [['unexpected-end', 2]])],
 [('regression: mixed immediates', ([165, 31, 204, 125, 127], ['u32', 's32', 's64']), [4005, -308, -1]),
  ('single byte 0x7F', ([127, 127], ['u32', 's32']), [127, -1]),
  ('five-byte u32 is the maximum length', ([128, 128, 128, 128, 4], ['u32']), [1073741824]),
  ('six-byte u32 is too long', ([128, 128, 128, 128, 128, 0, 4], ['u32', 'u32']), [['too-long', 5]]),
  ('s32 2^31 out of range, -2^31 in range',
   ([128, 128, 128, 128, 120, 128, 128, 128, 128, 8], ['s32', 's32']),
   [-2147483648, ['out-of-range', 10]]),
  ('u32 with bit 6 set in last byte stays positive', ([68, 128, 64], ['u32', 'u32']), [68, 8192]),
  ('negative s64 spanning several bytes', ([252, 255, 255, 255, 255, 95], ['s64']), [-1099511627780]),
  ('truncated immediate', ([128, 132], ['u64']), [['unexpected-end', 2]])],
 [('regression: mixed immediates', ([141, 39, 255, 124, 127], ['u32', 's32', 's64']), [5005, -385, -1]),
  ('single byte 0x7F', ([127, 127], ['u32', 's32']), [127, -1]),
  ('five-byte u32 is the maximum length', ([128, 128, 128, 128, 5], ['u32']), [1342177280]),
  ('six-byte u32 is too long', ([128, 128, 128, 128, 128, 0, 5], ['u32', 'u32']), [['too-long', 5]]),
  ('s32 2^31 out of range, -2^31 in range',
   ([128, 128, 128, 128, 120, 128, 128, 128, 128, 8], ['s32', 's32']),
   [-2147483648, ['out-of-range', 10]]),
  ('u32 with bit 6 set in last byte stays positive', ([69, 128, 64], ['u32', 'u32']), [69, 8192]),
  ('negative s64 spanning several bytes', ([251, 255, 255, 255, 255, 95], ['s64']), [-1099511627781]),
  ('truncated immediate', ([128, 133], ['u64']), [['unexpected-end', 2]])]]
for label, args, expected in cases[N - 1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
A positive signed immediate one past the int32 maximum is accepted.

Decode consecutive LEB128 immediates of kinds u32, s32, u64, s64 from a byte list: 7 payload bits per byte, least significant group first, bit 0x80 means another byte follows; at most ceil(bits/7) bytes (5 for 32-bit, 10 for 64-bit). Signed kinds sign-extend from bit 0x40 of the final byte; u32/s32 values outside their range are errors. Return decoded values followed by the first error, if any: ["unexpected-end", pos], ["too-long", pos] or ["out-of-range", pos].

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(data, kinds):
    pos = 0
    out = []
    for kind in kinds:
        bits = 32 if kind in ('u32', 's32') else 64
        maxlen = (bits + 6) // 7
        result = 0
        shift = 0
        n = 0
        while True:
            if pos >= len(data):
                return out + [['unexpected-end', pos]]
            byte = data[pos]
            pos += 1
            n += 1
            result |= (byte & 0x7F) << shift
            shift += 7
            if (byte & 0x80) == 0:
                break
            if n == maxlen:
                return out + [['too-long', pos]]
        if kind != 'u64' and byte & 0x40:
            result -= 1 << shift
        if kind == 's32' and not -(1 << 31) <= result < (1 << 31):
            return out + [['out-of-range', pos]]
        if kind == 'u32' and result >= (1 << 32):
            return out + [['out-of-range', pos]]
        out.append(result)
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression: mixed immediates', ([237, 7, 179, 127, 127], ['u32', 's32', 's64']), [1005, -77, -1]),
  ('single byte 0x7F', ([127, 127], ['u32', 's32']), [127, -1]),
  ('five-byte u32 is the maximum length', ([128, 128, 128, 128, 1], ['u32']), [268435456]),
  ('six-byte u32 is too long', ([128, 128, 128, 128, 128, 0, 1], ['u32', 'u32']), [['too-long', 5]]),
  ('s32 2^31 out of range, -2^31 in range',
   ([128, 128, 128, 128, 120, 128, 128, 128, 128, 8], ['s32', 's32']),
   [-2147483648, ['out-of-range', 10]]),
  ('u32 with bit 6 set in last byte stays positive', ([65, 128, 64], ['u32', 'u32']), [65, 8192]),
  ('negative s64 spanning several bytes', ([255, 255, 255, 255, 255, 95], ['s64']), [-1099511627777]),
  ('truncated immediate', ([128, 129], ['u64']), [['unexpected-end', 2]])],
 [('regression: mixed immediates', ([213, 15, 230, 126, 127], ['u32', 's32', 's64']), [2005, -154, -1]),
  ('single byte 0x7F', ([127, 127], ['u32', 's32']), [127, -1]),
  ('five-byte u32 is the maximum length', ([128, 128, 128, 128, 2], ['u32']), [536870912]),
  ('six-byte u32 is too long', ([128, 128, 128, 128, 128, 0, 2], ['u32', 'u32']), [['too-long', 5]]),
  ('s32 2^31 out of range, -2^31 in range',
   ([128, 128, 128, 128, 120, 128, 128, 128, 128, 8], ['s32', 's32']),
   [-2147483648, ['out-of-range', 10]]),
  ('u32 with bit 6 set in last byte stays positive', ([66, 128, 64], ['u32', 'u32']), [66, 8192]),
  ('negative s64 spanning several bytes', ([254, 255, 255, 255, 255, 95], ['s64']), [-1099511627778]),
  ('truncated immediate', ([128, 130], ['u64']), [['unexpected-end', 2]])],
 [('regression: mixed immediates', ([189, 23, 153, 126, 127], ['u32', 's32', 's64']), [3005, -231, -1]),
  ('single byte 0x7F', ([127, 127], ['u32', 's32']), [127, -1]),
  ('five-byte u32 is the maximum length', ([128, 128, 128, 128, 3], ['u32']), [805306368]),
  ('six-byte u32 is too long', ([128, 128, 128, 128, 128, 0, 3], ['u32', 'u32']), [['too-long', 5]]),
  ('s32 2^31 out of range, -2^31 in range',
   ([128, 128, 128, 128, 120, 128, 128, 128, 128, 8], ['s32', 's32']),
   [-2147483648, ['out-of-range', 10]]),
  ('u32 with bit 6 set in last byte stays positive', ([67, 128, 64], ['u32', 'u32']), [67, 8192]),
  ('negative s64 spanning several bytes', ([253, 255, 255, 255, 255, 95], ['s64']), [-1099511627779]),
  ('truncated immediate', ([128, 131], ['u64']), [['unexpected-end', 2]])],
 [('regression: mixed immediates', ([165, 31, 204, 125, 127], ['u32', 's32', 's64']), [4005, -308, -1]),
  ('single byte 0x7F', ([127, 127], ['u32', 's32']), [127, -1]),
  ('five-byte u32 is the maximum length', ([128, 128, 128, 128, 4], ['u32']), [1073741824]),
  ('six-byte u32 is too long', ([128, 128, 128, 128, 128, 0, 4], ['u32', 'u32']), [['too-long', 5]]),
  ('s32 2^31 out of range, -2^31 in range',
   ([128, 128, 128, 128, 120, 128, 128, 128, 128, 8], ['s32', 's32']),
   [-2147483648, ['out-of-range', 10]]),
  ('u32 with bit 6 set in last byte stays positive', ([68, 128, 64], ['u32', 'u32']), [68, 8192]),
  ('negative s64 spanning several bytes', ([252, 255, 255, 255, 255, 95], ['s64']), [-1099511627780]),
  ('truncated immediate', ([128, 132], ['u64']), [['unexpected-end', 2]])],
 [('regression: mixed immediates', ([141, 39, 255, 124, 127], ['u32', 's32', 's64']), [5005, -385, -1]),
  ('single byte 0x7F', ([127, 127], ['u32', 's32']), [127, -1]),
  ('five-byte u32 is the maximum length', ([128, 128, 128, 128, 5], ['u32']), [1342177280]),
  ('six-byte u32 is too long', ([128, 128, 128, 128, 128, 0, 5], ['u32', 'u32']), [['too-long', 5]]),
  ('s32 2^31 out of range, -2^31 in range',
   ([128, 128, 128, 128, 120, 128, 128, 128, 128, 8], ['s32', 's32']),
   [-2147483648, ['out-of-range', 10]]),
  ('u32 with bit 6 set in last byte stays positive', ([69, 128, 64], ['u32', 'u32']), [69, 8192]),
  ('negative s64 spanning several bytes', ([251, 255, 255, 255, 255, 95], ['s64']), [-1099511627781]),
  ('truncated immediate', ([128, 133], ['u64']), [['unexpected-end', 2]])]]
for label, args, expected in cases[N - 1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

meaning: Fixture-count band, not measured model difficulty

deps: stdlib

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(data, kinds):
    pos = 0
    out = []
    for kind in kinds:
        bits = 32 if kind in ('u32', 's32') else 64
        maxlen = (bits + 6) // 7
        result = 0
        shift = 0
        n = 0
        while True:
            if pos >= len(data):
                return out + [['unexpected-end', pos]]
            byte = data[pos]
            pos += 1
            n += 1
            result |= (byte & 0x7F) << shift
            shift += 7
            if (byte & 0x80) == 0:
                break
            if n == maxlen:
                return out + [['too-long', pos]]
        if kind == 's32' and byte & 0x40:
            result -= 1 << shift
        if kind == 's32' and not -(1 << 31) <= result < (1 << 31):
            return out + [['out-of-range', pos]]
        if kind == 'u32' and result >= (1 << 32):
            return out + [['out-of-range', pos]]
        out.append(result)
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression: mixed immediates', ([237, 7, 179, 127, 127], ['u32', 's32', 's64']), [1005, -77, -1]),
  ('single byte 0x7F', ([127, 127], ['u32', 's32']), [127, -1]),
  ('five-byte u32 is the maximum length', ([128, 128, 128, 128, 1], ['u32']), [268435456]),
  ('six-byte u32 is too long', ([128, 128, 128, 128, 128, 0, 1], ['u32', 'u32']), [['too-long', 5]]),
  ('s32 2^31 out of range, -2^31 in range',
   ([128, 128, 128, 128, 120, 128, 128, 128, 128, 8], ['s32', 's32']),
   [-2147483648, ['out-of-range', 10]]),
  ('u32 with bit 6 set in last byte stays positive', ([65, 128, 64], ['u32', 'u32']), [65, 8192]),
  ('negative s64 spanning several bytes', ([255, 255, 255, 255, 255, 95], ['s64']), [-1099511627777]),
  ('truncated immediate', ([128, 129], ['u64']), [['unexpected-end', 2]])],
 [('regression: mixed immediates', ([213, 15, 230, 126, 127], ['u32', 's32', 's64']), [2005, -154, -1]),
  ('single byte 0x7F', ([127, 127], ['u32', 's32']), [127, -1]),
  ('five-byte u32 is the maximum length', ([128, 128, 128, 128, 2], ['u32']), [536870912]),
  ('six-byte u32 is too long', ([128, 128, 128, 128, 128, 0, 2], ['u32', 'u32']), [['too-long', 5]]),
  ('s32 2^31 out of range, -2^31 in range',
   ([128, 128, 128, 128, 120, 128, 128, 128, 128, 8], ['s32', 's32']),
   [-2147483648, ['out-of-range', 10]]),
  ('u32 with bit 6 set in last byte stays positive', ([66, 128, 64], ['u32', 'u32']), [66, 8192]),
  ('negative s64 spanning several bytes', ([254, 255, 255, 255, 255, 95], ['s64']), [-1099511627778]),
  ('truncated immediate', ([128, 130], ['u64']), [['unexpected-end', 2]])],
 [('regression: mixed immediates', ([189, 23, 153, 126, 127], ['u32', 's32', 's64']), [3005, -231, -1]),
  ('single byte 0x7F', ([127, 127], ['u32', 's32']), [127, -1]),
  ('five-byte u32 is the maximum length', ([128, 128, 128, 128, 3], ['u32']), [805306368]),
  ('six-byte u32 is too long', ([128, 128, 128, 128, 128, 0, 3], ['u32', 'u32']), [['too-long', 5]]),
  ('s32 2^31 out of range, -2^31 in range',
   ([128, 128, 128, 128, 120, 128, 128, 128, 128, 8], ['s32', 's32']),
   [-2147483648, ['out-of-range', 10]]),
  ('u32 with bit 6 set in last byte stays positive', ([67, 128, 64], ['u32', 'u32']), [67, 8192]),
  ('negative s64 spanning several bytes', ([253, 255, 255, 255, 255, 95], ['s64']), [-1099511627779]),
  ('truncated immediate', ([128, 131], ['u64']), [['unexpected-end', 2]])],
 [('regression: mixed immediates', ([165, 31, 204, 125, 127], ['u32', 's32', 's64']), [4005, -308, -1]),
  ('single byte 0x7F', ([127, 127], ['u32', 's32']), [127, -1]),
  ('five-byte u32 is the maximum length', ([128, 128, 128, 128, 4], ['u32']), [1073741824]),
  ('six-byte u32 is too long', ([128, 128, 128, 128, 128, 0, 4], ['u32', 'u32']), [['too-long', 5]]),
  ('s32 2^31 out of range, -2^31 in range',
   ([128, 128, 128, 128, 120, 128, 128, 128, 128, 8], ['s32', 's32']),
   [-2147483648, ['out-of-range', 10]]),
  ('u32 with bit 6 set in last byte stays positive', ([68, 128, 64], ['u32', 'u32']), [68, 8192]),
  ('negative s64 spanning several bytes', ([252, 255, 255, 255, 255, 95], ['s64']), [-1099511627780]),
  ('truncated immediate', ([128, 132], ['u64']), [['unexpected-end', 2]])],
 [('regression: mixed immediates', ([141, 39, 255, 124, 127], ['u32', 's32', 's64']), [5005, -385, -1]),
  ('single byte 0x7F', ([127, 127], ['u32', 's32']), [127, -1]),
  ('five-byte u32 is the maximum length', ([128, 128, 128, 128, 5], ['u32']), [1342177280]),
  ('six-byte u32 is too long', ([128, 128, 128, 128, 128, 0, 5], ['u32', 'u32']), [['too-long', 5]]),
  ('s32 2^31 out of range, -2^31 in range',
   ([128, 128, 128, 128, 120, 128, 128, 128, 128, 8], ['s32', 's32']),
   [-2147483648, ['out-of-range', 10]]),
  ('u32 with bit 6 set in last byte stays positive', ([69, 128, 64], ['u32', 'u32']), [69, 8192]),
  ('negative s64 spanning several bytes', ([251, 255, 255, 255, 255, 95], ['s64']), [-1099511627781]),
  ('truncated immediate', ([128, 133], ['u64']), [['unexpected-end', 2]])]]
for label, args, expected in cases[N - 1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Unsigned 32-bit immediates whose last byte has bit 6 set become negative.

Decode consecutive LEB128 immediates of kinds u32, s32, u64, s64 from a byte list: 7 payload bits per byte, least significant group first, bit 0x80 means another byte follows; at most ceil(bits/7) bytes (5 for 32-bit, 10 for 64-bit). Signed kinds sign-extend from bit 0x40 of the final byte; u32/s32 values outside their range are errors. Return decoded values followed by the first error, if any: ["unexpected-end", pos], ["too-long", pos] or ["out-of-range", pos].

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(body, commands):
    state = 'created'
    pc = 0
    stack = []
    handlers = []
    out = []
    def run(inject, exc):
        nonlocal pc, state
        if exc is not None:
            while handlers and handlers[-1][0] not in (exc, 'Exception'):
                handlers.pop()
            if not handlers:
                state = 'done'
                return ['raised', exc]
            pc = handlers.pop()[1]
        elif state == 'suspended':
            stack.append(inject)
        state = 'running'
        try:
            while True:
                ins = body[pc]
                op = ins[0]
                pc += 1
                if op == 'push':
                    stack.append(ins[1])
                elif op == 'pop':
                    stack.pop()
                elif op == 'add':
                    b = stack.pop()
                    a = stack.pop()
                    stack.append(a + b)
                elif op == 'yield':
                    state = 'suspended'
                    return ['yielded', stack.pop()]
                elif op == 'return':
                    state = 'done'
                    return ['StopIteration', stack.pop()]
                elif op == 'try':
                    handlers.append((ins[1], ins[2]))
                elif op == 'endtry':
                    handlers.pop()
        except (IndexError, TypeError):
            state = 'done'
            return ['vm-error']
    for cmd in commands:
        kind = cmd[0]
        if kind in ('next', 'send'):
            value = cmd[1] if kind == 'send' else None
            if state == 'done':
                out.append(['StopIteration', None])
            elif state == 'created' and value:
                out.append(['TypeError'])
            else:
                out.append(run(value, None))
        elif kind == 'throw':
            if state == 'created' or state == 'done':
                state = 'done'
                out.append(['raised', cmd[1]])
            else:
                out.append(run(None, cmd[1]))
        else:
            state = 'done'
            out.append(['closed'])
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression: send values through two yields',
   ([['push', 1], ['yield'], ['push', 10], ['add'], ['yield'], ['pop'], ['push', 6], ['return']],
    [['next'], ['send', 7], ['next'], ['next']]),
   [['yielded', 1], ['yielded', 17], ['StopIteration', 6], ['StopIteration', None]]),
  ('non-None send to a fresh generator',
   ([['push', 1], ['yield'], ['push', 10], ['add'], ['yield'], ['pop'], ['push', 6], ['return']],
    [['send', 0], ['next'], ['send', 1]]),
   [['TypeError'], ['yielded', 1], ['yielded', 11]]),
  ('sending zero to a suspended generator',
   ([['push', 1], ['yield'], ['push', 10], ['add'], ['yield'], ['pop'], ['push', 6], ['return']],
    [['next'], ['send', 0], ['next']]),
   [['yielded', 1], ['yielded', 10], ['StopIteration', 6]]),
  ('yield hands out and removes the value',
   ([['push', 5], ['push', 1], ['yield'], ['add'], ['return']], [['next'], ['send', 3], ['next']]),
   [['yielded', 1], ['StopIteration', 8], ['StopIteration', None]]),
  ('thrown exception caught by catch-all handler',
   ([['try', 'Exception', 7],
     ['push', 1],
     ['yield'],
     ['pop'],
     ['endtry'],
     ['push', -1],
     ['return'],
     ['push', 43],
     ['yield'],
     ['pop'],
     ['push', 0],
     ['return']],
    [['next'], ['throw', 'ValueError'], ['next']]),
   [['yielded', 1], ['yielded', 43], ['StopIteration', 0]]),
  ('uncaught throw finishes the generator',
   ([['push', 5], ['push', 1], ['yield'], ['add'], ['return']], [['next'], ['throw', 'KeyError'], ['next']]),
   [['yielded', 1], ['raised', 'KeyError'], ['StopIteration', None]]),
  ('closing a fresh generator',
   ([['push', 5], ['push', 1], ['yield'], ['add'], ['return']], [['close'], ['next']]),
   [['closed'], ['StopIteration', None]]),
  ('closing a suspended generator',
   ([['push', 5], ['push', 1], ['yield'], ['add'], ['return']], [['next'], ['close'], ['next']]),
   [['yielded', 1], ['closed'], ['StopIteration', None]]),
  ('control: throw into a fresh generator',
   ([['push', 1], ['yield'], ['push', 10], ['add'], ['yield'], ['pop'], ['push', 6], ['return']],
    [['throw', 'ValueError'], ['next']]),
   [['raised', 'ValueError'], ['StopIteration', None]])],
 [('regression: send values through two yields',
   ([['push', 1], ['yield'], ['push', 10], ['add'], ['yield'], ['pop'], ['push', 7], ['return']],
    [['next'], ['send', 14], ['next'], ['next']]),
   [['yielded', 1], ['yielded', 24], ['StopIteration', 7], ['StopIteration', None]]),
  ('non-None send to a fresh generator',
   ([['push', 1], ['yield'], ['push', 10], ['add'], ['yield'], ['pop'], ['push', 7], ['return']],
    [['send', 0], ['next'], ['send', 2]]),
   [['TypeError'], ['yielded', 1], ['yielded', 12]]),
  ('sending zero to a suspended generator',
   ([['push', 1], ['yield'], ['push', 10], ['add'], ['yield'], ['pop'], ['push', 7], ['return']],
    [['next'], ['send', 0], ['next']]),
   [['yielded', 1], ['yielded', 10], ['StopIteration', 7]]),
  ('yield hands out and removes the value',
   ([['push', 10], ['push', 1], ['yield'], ['add'], ['return']], [['next'], ['send', 3], ['next']]),
   [['yielded', 1], ['StopIteration', 13], ['StopIteration', None]]),
  ('thrown exception caught by catch-all handler',
   ([['try', 'Exception', 7],
     ['push', 1],
     ['yield'],
     ['pop'],
     ['endtry'],
     ['push', -1],
     ['return'],
     ['push', 44],
     ['yield'],
     ['pop'],
     ['push', 0],
     ['return']],
    [['next'], ['throw', 'ValueError'], ['next']]),
   [['yielded', 1], ['yielded', 44], ['StopIteration', 0]]),
  ('uncaught throw finishes the generator',
   ([['push', 10], ['push', 1], ['yield'], ['add'], ['return']], [['next'], ['throw', 'KeyError'], ['next']]),
   [['yielded', 1], ['raised', 'KeyError'], ['StopIteration', None]]),
  ('closing a fresh generator',
   ([['push', 10], ['push', 1], ['yield'], ['add'], ['return']], [['close'], ['next']]),
   [['closed'], ['StopIteration', None]]),
  ('closing a suspended generator',
   ([['push', 10], ['push', 1], ['yield'], ['add'], ['return']], [['next'], ['close'], ['next']]),
   [['yielded', 1], ['closed'], ['StopIteration', None]]),
  ('control: throw into a fresh generator',
   ([['push', 1], ['yield'], ['push', 10], ['add'], ['yield'], ['pop'], ['push', 7], ['return']],
    [['throw', 'ValueError'], ['next']]),
   [['raised', 'ValueError'], ['StopIteration', None]])],
 [('regression: send values through two yields',
   ([['push', 1], ['yield'], ['push', 10], ['add'], ['yield'], ['pop'], ['push', 8], ['return']],
    [['next'], ['send', 21], ['next'], ['next']]),
   [['yielded', 1], ['yielded', 31], ['StopIteration', 8], ['StopIteration', None]]),
  ('non-None send to a fresh generator',
   ([['push', 1], ['yield'], ['push', 10], ['add'], ['yield'], ['pop'], ['push', 8], ['return']],
    [['send', 0], ['next'], ['send', 3]]),
   [['TypeError'], ['yielded', 1], ['yielded', 13]]),
  ('sending zero to a suspended generator',
   ([['push', 1], ['yield'], ['push', 10], ['add'], ['yield'], ['pop'], ['push', 8], ['return']],
    [['next'], ['send', 0], ['next']]),
   [['yielded', 1], ['yielded', 10], ['StopIteration', 8]]),
  ('yield hands out and removes the value',
   ([['push', 15], ['push', 1], ['yield'], ['add'], ['return']], [['next'], ['send', 3], ['next']]),
   [['yielded', 1], ['StopIteration', 18], ['StopIteration', None]]),
  ('thrown exception caught by catch-all handler',
   ([['try', 'Exception', 7],
     ['push', 1],
     ['yield'],
     ['pop'],
     ['endtry'],
     ['push', -1],
     ['return'],
     ['push', 45],
     ['yield'],
     ['pop'],
     ['push', 0],
     ['return']],
    [['next'], ['throw', 'ValueError'], ['next']]),
   [['yielded', 1], ['yielded', 45], ['StopIteration', 0]]),
  ('uncaught throw finishes the generator',
   ([['push', 15], ['push', 1], ['yield'], ['add'], ['return']], [['next'], ['throw', 'KeyError'], ['next']]),
   [['yielded', 1], ['raised', 'KeyError'], ['StopIteration', None]]),
  ('closing a fresh generator',
   ([['push', 15], ['push', 1], ['yield'], ['add'], ['return']], [['close'], ['next']]),
   [['closed'], ['StopIteration', None]]),
  ('closing a suspended generator',
   ([['push', 15], ['push', 1], ['yield'], ['add'], ['return']], [['next'], ['close'], ['next']]),
   [['yielded', 1], ['closed'], ['StopIteration', None]]),
  ('control: throw into a fresh generator',
   ([['push', 1], ['yield'], ['push', 10], ['add'], ['yield'], ['pop'], ['push', 8], ['return']],
    [['throw', 'ValueError'], ['next']]),
   [['raised', 'ValueError'], ['StopIteration', None]])],
 [('regression: send values through two yields',
   ([['push', 1], ['yield'], ['push', 10], ['add'], ['yield'], ['pop'], ['push', 9], ['return']],
    [['next'], ['send', 28], ['next'], ['next']]),
   [['yielded', 1], ['yielded', 38], ['StopIteration', 9], ['StopIteration', None]]),
  ('non-None send to a fresh generator',
   ([['push', 1], ['yield'], ['push', 10], ['add'], ['yield'], ['pop'], ['push', 9], ['return']],
    [['send', 0], ['next'], ['send', 4]]),
   [['TypeError'], ['yielded', 1], ['yielded', 14]]),
  ('sending zero to a suspended generator',
   ([['push', 1], ['yield'], ['push', 10], ['add'], ['yield'], ['pop'], ['push', 9], ['return']],
    [['next'], ['send', 0], ['next']]),
   [['yielded', 1], ['yielded', 10], ['StopIteration', 9]]),
  ('yield hands out and removes the value',
   ([['push', 20], ['push', 1], ['yield'], ['add'], ['return']], [['next'], ['send', 3], ['next']]),
   [['yielded', 1], ['StopIteration', 23], ['StopIteration', None]]),
  ('thrown exception caught by catch-all handler',
   ([['try', 'Exception', 7],
     ['push', 1],
     ['yield'],
     ['pop'],
     ['endtry'],
     ['push', -1],
     ['return'],
     ['push', 46],
     ['yield'],
     ['pop'],
     ['push', 0],
     ['return']],
    [['next'], ['throw', 'ValueError'], ['next']]),
   [['yielded', 1], ['yielded', 46], ['StopIteration', 0]]),
  ('uncaught throw finishes the generator',
   ([['push', 20], ['push', 1], ['yield'], ['add'], ['return']], [['next'], ['throw', 'KeyError'], ['next']]),
   [['yielded', 1], ['raised', 'KeyError'], ['StopIteration', None]]),
  ('closing a fresh generator',
   ([['push', 20], ['push', 1], ['yield'], ['add'], ['return']], [['close'], ['next']]),
   [['closed'], ['StopIteration', None]]),
  ('closing a suspended generator',
   ([['push', 20], ['push', 1], ['yield'], ['add'], ['return']], [['next'], ['close'], ['next']]),
   [['yielded', 1], ['closed'], ['StopIteration', None]]),
  ('control: throw into a fresh generator',
   ([['push', 1], ['yield'], ['push', 10], ['add'], ['yield'], ['pop'], ['push', 9], ['return']],
    [['throw', 'ValueError'], ['next']]),
   [['raised', 'ValueError'], ['StopIteration', None]])],
 [('regression: send values through two yields',
   ([['push', 1], ['yield'], ['push', 10], ['add'], ['yield'], ['pop'], ['push', 10], ['return']],
    [['next'], ['send', 35], ['next'], ['next']]),
   [['yielded', 1], ['yielded', 45], ['StopIteration', 10], ['StopIteration', None]]),
  ('non-None send to a fresh generator',
   ([['push', 1], ['yield'], ['push', 10], ['add'], ['yield'], ['pop'], ['push', 10], ['return']],
    [['send', 0], ['next'], ['send', 5]]),
   [['TypeError'], ['yielded', 1], ['yielded', 15]]),
  ('sending zero to a suspended generator',
   ([['push', 1], ['yield'], ['push', 10], ['add'], ['yield'], ['pop'], ['push', 10], ['return']],
    [['next'], ['send', 0], ['next']]),
   [['yielded', 1], ['yielded', 10], ['StopIteration', 10]]),
  ('yield hands out and removes the value',
   ([['push', 25], ['push', 1], ['yield'], ['add'], ['return']], [['next'], ['send', 3], ['next']]),
   [['yielded', 1], ['StopIteration', 28], ['StopIteration', None]]),
  ('thrown exception caught by catch-all handler',
   ([['try', 'Exception', 7],
     ['push', 1],
     ['yield'],
     ['pop'],
     ['endtry'],
     ['push', -1],
     ['return'],
     ['push', 47],
     ['yield'],
     ['pop'],
     ['push', 0],
     ['return']],
    [['next'], ['throw', 'ValueError'], ['next']]),
   [['yielded', 1], ['yielded', 47], ['StopIteration', 0]]),
  ('uncaught throw finishes the generator',
   ([['push', 25], ['push', 1], ['yield'], ['add'], ['return']], [['next'], ['throw', 'KeyError'], ['next']]),
   [['yielded', 1], ['raised', 'KeyError'], ['StopIteration', None]]),
  ('closing a fresh generator',
   ([['push', 25], ['push', 1], ['yield'], ['add'], ['return']], [['close'], ['next']]),
   [['closed'], ['StopIteration', None]]),
  ('closing a suspended generator',
   ([['push', 25], ['push', 1], ['yield'], ['add'], ['return']], [['next'], ['close'], ['next']]),
   [['yielded', 1], ['closed'], ['StopIteration', None]]),
  ('control: throw into a fresh generator',
   ([['push', 1], ['yield'], ['push', 10], ['add'], ['yield'], ['pop'], ['push', 10], ['return']],
    [['throw', 'ValueError'], ['next']]),
   [['raised', 'ValueError'], ['StopIteration', None]])]]
for label, args, expected in cases[N - 1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(body, commands):
    state = 'created'
    pc = 0
    stack = []
    handlers = []
    out = []
    def run(inject, exc):
        nonlocal pc, state
        if exc is not None:
            while handlers and handlers[-1][0] not in (exc, 'Exception'):
                handlers.pop()
            if not handlers:
                state = 'done'
                return ['raised', exc]
            pc = handlers.pop()[1]
        elif state == 'suspended':
            stack.append(inject)
        state = 'running'
        try:
            while True:
                ins = body[pc]
                op = ins[0]
                pc += 1
                if op == 'push':
                    stack.append(ins[1])
                elif op == 'pop':
                    stack.pop()
                elif op == 'add':
                    b = stack.pop()
                    a = stack.pop()
                    stack.append(a + b)
                elif op == 'yield':
                    state = 'suspended'
                    return ['yielded', stack.pop()]
                elif op == 'return':
                    state = 'done'
                    return ['StopIteration', stack.pop()]
                elif op == 'try':
                    handlers.append((ins[1], ins[2]))
                elif op == 'endtry':
                    handlers.pop()
        except (IndexError, TypeError):
            state = 'done'
            return ['vm-error']
    for cmd in commands:
        kind = cmd[0]
        if kind in ('next', 'send'):
            value = cmd[1] if kind == 'send' else None
            if state == 'done':
                out.append(['StopIteration', None])
            elif value is not None:
                out.append(['TypeError'])
            else:
                out.append(run(value, None))
        elif kind == 'throw':
            if state == 'created' or state == 'done':
                state = 'done'
                out.append(['raised', cmd[1]])
            else:
                out.append(run(None, cmd[1]))
        else:
            state = 'done'
            out.append(['closed'])
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression: send values through two yields',
   ([['push', 1], ['yield'], ['push', 10], ['add'], ['yield'], ['pop'], ['push', 6], ['return']],
    [['next'], ['send', 7], ['next'], ['next']]),
   [['yielded', 1], ['yielded', 17], ['StopIteration', 6], ['StopIteration', None]]),
  ('non-None send to a fresh generator',
   ([['push', 1], ['yield'], ['push', 10], ['add'], ['yield'], ['pop'], ['push', 6], ['return']],
    [['send', 0], ['next'], ['send', 1]]),
   [['TypeError'], ['yielded', 1], ['yielded', 11]]),
  ('sending zero to a suspended generator',
   ([['push', 1], ['yield'], ['push', 10], ['add'], ['yield'], ['pop'], ['push', 6], ['return']],
    [['next'], ['send', 0], ['next']]),
   [['yielded', 1], ['yielded', 10], ['StopIteration', 6]]),
  ('yield hands out and removes the value',
   ([['push', 5], ['push', 1], ['yield'], ['add'], ['return']], [['next'], ['send', 3], ['next']]),
   [['yielded', 1], ['StopIteration', 8], ['StopIteration', None]]),
  ('thrown exception caught by catch-all handler',
   ([['try', 'Exception', 7],
     ['push', 1],
     ['yield'],
     ['pop'],
     ['endtry'],
     ['push', -1],
     ['return'],
     ['push', 43],
     ['yield'],
     ['pop'],
     ['push', 0],
     ['return']],
    [['next'], ['throw', 'ValueError'], ['next']]),
   [['yielded', 1], ['yielded', 43], ['StopIteration', 0]]),
  ('uncaught throw finishes the generator',
   ([['push', 5], ['push', 1], ['yield'], ['add'], ['return']], [['next'], ['throw', 'KeyError'], ['next']]),
   [['yielded', 1], ['raised', 'KeyError'], ['StopIteration', None]]),
  ('closing a fresh generator',
   ([['push', 5], ['push', 1], ['yield'], ['add'], ['return']], [['close'], ['next']]),
   [['closed'], ['StopIteration', None]]),
  ('closing a suspended generator',
   ([['push', 5], ['push', 1], ['yield'], ['add'], ['return']], [['next'], ['close'], ['next']]),
   [['yielded', 1], ['closed'], ['StopIteration', None]]),
  ('control: throw into a fresh generator',
   ([['push', 1], ['yield'], ['push', 10], ['add'], ['yield'], ['pop'], ['push', 6], ['return']],
    [['throw', 'ValueError'], ['next']]),
   [['raised', 'ValueError'], ['StopIteration', None]])],
 [('regression: send values through two yields',
   ([['push', 1], ['yield'], ['push', 10], ['add'], ['yield'], ['pop'], ['push', 7], ['return']],
    [['next'], ['send', 14], ['next'], ['next']]),
   [['yielded', 1], ['yielded', 24], ['StopIteration', 7], ['StopIteration', None]]),
  ('non-None send to a fresh generator',
   ([['push', 1], ['yield'], ['push', 10], ['add'], ['yield'], ['pop'], ['push', 7], ['return']],
    [['send', 0], ['next'], ['send', 2]]),
   [['TypeError'], ['yielded', 1], ['yielded', 12]]),
  ('sending zero to a suspended generator',
   ([['push', 1], ['yield'], ['push', 10], ['add'], ['yield'], ['pop'], ['push', 7], ['return']],
    [['next'], ['send', 0], ['next']]),
   [['yielded', 1], ['yielded', 10], ['StopIteration', 7]]),
  ('yield hands out and removes the value',
   ([['push', 10], ['push', 1], ['yield'], ['add'], ['return']], [['next'], ['send', 3], ['next']]),
   [['yielded', 1], ['StopIteration', 13], ['StopIteration', None]]),
  ('thrown exception caught by catch-all handler',
   ([['try', 'Exception', 7],
     ['push', 1],
     ['yield'],
     ['pop'],
     ['endtry'],
     ['push', -1],
     ['return'],
     ['push', 44],
     ['yield'],
     ['pop'],
     ['push', 0],
     ['return']],
    [['next'], ['throw', 'ValueError'], ['next']]),
   [['yielded', 1], ['yielded', 44], ['StopIteration', 0]]),
  ('uncaught throw finishes the generator',
   ([['push', 10], ['push', 1], ['yield'], ['add'], ['return']], [['next'], ['throw', 'KeyError'], ['next']]),
   [['yielded', 1], ['raised', 'KeyError'], ['StopIteration', None]]),
  ('closing a fresh generator',
   ([['push', 10], ['push', 1], ['yield'], ['add'], ['return']], [['close'], ['next']]),
   [['closed'], ['StopIteration', None]]),
  ('closing a suspended generator',
   ([['push', 10], ['push', 1], ['yield'], ['add'], ['return']], [['next'], ['close'], ['next']]),
   [['yielded', 1], ['closed'], ['StopIteration', None]]),
  ('control: throw into a fresh generator',
   ([['push', 1], ['yield'], ['push', 10], ['add'], ['yield'], ['pop'], ['push', 7], ['return']],
    [['throw', 'ValueError'], ['next']]),
   [['raised', 'ValueError'], ['StopIteration', None]])],
 [('regression: send values through two yields',
   ([['push', 1], ['yield'], ['push', 10], ['add'], ['yield'], ['pop'], ['push', 8], ['return']],
    [['next'], ['send', 21], ['next'], ['next']]),
   [['yielded', 1], ['yielded', 31], ['StopIteration', 8], ['StopIteration', None]]),
  ('non-None send to a fresh generator',
   ([['push', 1], ['yield'], ['push', 10], ['add'], ['yield'], ['pop'], ['push', 8], ['return']],
    [['send', 0], ['next'], ['send', 3]]),
   [['TypeError'], ['yielded', 1], ['yielded', 13]]),
  ('sending zero to a suspended generator',
   ([['push', 1], ['yield'], ['push', 10], ['add'], ['yield'], ['pop'], ['push', 8], ['return']],
    [['next'], ['send', 0], ['next']]),
   [['yielded', 1], ['yielded', 10], ['StopIteration', 8]]),
  ('yield hands out and removes the value',
   ([['push', 15], ['push', 1], ['yield'], ['add'], ['return']], [['next'], ['send', 3], ['next']]),
   [['yielded', 1], ['StopIteration', 18], ['StopIteration', None]]),
  ('thrown exception caught by catch-all handler',
   ([['try', 'Exception', 7],
     ['push', 1],
     ['yield'],
     ['pop'],
     ['endtry'],
     ['push', -1],
     ['return'],
     ['push', 45],
     ['yield'],
     ['pop'],
     ['push', 0],
     ['return']],
    [['next'], ['throw', 'ValueError'], ['next']]),
   [['yielded', 1], ['yielded', 45], ['StopIteration', 0]]),
  ('uncaught throw finishes the generator',
   ([['push', 15], ['push', 1], ['yield'], ['add'], ['return']], [['next'], ['throw', 'KeyError'], ['next']]),
   [['yielded', 1], ['raised', 'KeyError'], ['StopIteration', None]]),
  ('closing a fresh generator',
   ([['push', 15], ['push', 1], ['yield'], ['add'], ['return']], [['close'], ['next']]),
   [['closed'], ['StopIteration', None]]),
  ('closing a suspended generator',
   ([['push', 15], ['push', 1], ['yield'], ['add'], ['return']], [['next'], ['close'], ['next']]),
   [['yielded', 1], ['closed'], ['StopIteration', None]]),
  ('control: throw into a fresh generator',
   ([['push', 1], ['yield'], ['push', 10], ['add'], ['yield'], ['pop'], ['push', 8], ['return']],
    [['throw', 'ValueError'], ['next']]),
   [['raised', 'ValueError'], ['StopIteration', None]])],
 [('regression: send values through two yields',
   ([['push', 1], ['yield'], ['push', 10], ['add'], ['yield'], ['pop'], ['push', 9], ['return']],
    [['next'], ['send', 28], ['next'], ['next']]),
   [['yielded', 1], ['yielded', 38], ['StopIteration', 9], ['StopIteration', None]]),
  ('non-None send to a fresh generator',
   ([['push', 1], ['yield'], ['push', 10], ['add'], ['yield'], ['pop'], ['push', 9], ['return']],
    [['send', 0], ['next'], ['send', 4]]),
   [['TypeError'], ['yielded', 1], ['yielded', 14]]),
  ('sending zero to a suspended generator',
   ([['push', 1], ['yield'], ['push', 10], ['add'], ['yield'], ['pop'], ['push', 9], ['return']],
    [['next'], ['send', 0], ['next']]),
   [['yielded', 1], ['yielded', 10], ['StopIteration', 9]]),
  ('yield hands out and removes the value',
   ([['push', 20], ['push', 1], ['yield'], ['add'], ['return']], [['next'], ['send', 3], ['next']]),
   [['yielded', 1], ['StopIteration', 23], ['StopIteration', None]]),
  ('thrown exception caught by catch-all handler',
   ([['try', 'Exception', 7],
     ['push', 1],
     ['yield'],
     ['pop'],
     ['endtry'],
     ['push', -1],
     ['return'],
     ['push', 46],
     ['yield'],
     ['pop'],
     ['push', 0],
     ['return']],
    [['next'], ['throw', 'ValueError'], ['next']]),
   [['yielded', 1], ['yielded', 46], ['StopIteration', 0]]),
  ('uncaught throw finishes the generator',
   ([['push', 20], ['push', 1], ['yield'], ['add'], ['return']], [['next'], ['throw', 'KeyError'], ['next']]),
   [['yielded', 1], ['raised', 'KeyError'], ['StopIteration', None]]),
  ('closing a fresh generator',
   ([['push', 20], ['push', 1], ['yield'], ['add'], ['return']], [['close'], ['next']]),
   [['closed'], ['StopIteration', None]]),
  ('closing a suspended generator',
   ([['push', 20], ['push', 1], ['yield'], ['add'], ['return']], [['next'], ['close'], ['next']]),
   [['yielded', 1], ['closed'], ['StopIteration', None]]),
  ('control: throw into a fresh generator',
   ([['push', 1], ['yield'], ['push', 10], ['add'], ['yield'], ['pop'], ['push', 9], ['return']],
    [['throw', 'ValueError'], ['next']]),
   [['raised', 'ValueError'], ['StopIteration', None]])],
 [('regression: send values through two yields',
   ([['push', 1], ['yield'], ['push', 10], ['add'], ['yield'], ['pop'], ['push', 10], ['return']],
    [['next'], ['send', 35], ['next'], ['next']]),
   [['yielded', 1], ['yielded', 45], ['StopIteration', 10], ['StopIteration', None]]),
  ('non-None send to a fresh generator',
   ([['push', 1], ['yield'], ['push', 10], ['add'], ['yield'], ['pop'], ['push', 10], ['return']],
    [['send', 0], ['next'], ['send', 5]]),
   [['TypeError'], ['yielded', 1], ['yielded', 15]]),
  ('sending zero to a suspended generator',
   ([['push', 1], ['yield'], ['push', 10], ['add'], ['yield'], ['pop'], ['push', 10], ['return']],
    [['next'], ['send', 0], ['next']]),
   [['yielded', 1], ['yielded', 10], ['StopIteration', 10]]),
  ('yield hands out and removes the value',
   ([['push', 25], ['push', 1], ['yield'], ['add'], ['return']], [['next'], ['send', 3], ['next']]),
   [['yielded', 1], ['StopIteration', 28], ['StopIteration', None]]),
  ('thrown exception caught by catch-all handler',
   ([['try', 'Exception', 7],
     ['push', 1],
     ['yield'],
     ['pop'],
     ['endtry'],
     ['push', -1],
     ['return'],
     ['push', 47],
     ['yield'],
     ['pop'],
     ['push', 0],
     ['return']],
    [['next'], ['throw', 'ValueError'], ['next']]),
   [['yielded', 1], ['yielded', 47], ['StopIteration', 0]]),
  ('uncaught throw finishes the generator',
   ([['push', 25], ['push', 1], ['yield'], ['add'], ['return']], [['next'], ['throw', 'KeyError'], ['next']]),
   [['yielded', 1], ['raised', 'KeyError'], ['StopIteration', None]]),
  ('closing a fresh generator',
   ([['push', 25], ['push', 1], ['yield'], ['add'], ['return']], [['close'], ['next']]),
   [['closed'], ['StopIteration', None]]),
  ('closing a suspended generator',
   ([['push', 25], ['push', 1], ['yield'], ['add'], ['return']], [['next'], ['close'], ['next']]),
   [['yielded', 1], ['closed'], ['StopIteration', None]]),
  ('control: throw into a fresh generator',
   ([['push', 1], ['yield'], ['push', 10], ['add'], ['yield'], ['pop'], ['push', 10], ['return']],
    [['throw', 'ValueError'], ['next']]),
   [['raised', 'ValueError'], ['StopIteration', None]])]]
for label, args, expected in cases[N - 1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
send(0) to a fresh generator starts it instead of raising TypeError.

A generator frame runs body ops push v, pop, add, yield (pop and hand out a value, suspend), return (pop, finish with StopIteration value), try exc target / endtry (handler stack; handler "Exception" catches any thrown name). Commands: next (= send None) and send v resume; resuming a suspended frame pushes the sent value as the result of its yield; sending non-None to a never-started generator is ["TypeError"]; a finished generator answers ["StopIteration", None]. throw into a created or finished generator finishes it with ["raised", exc]; otherwise the innermost matching handler is jumped to, or the generator finishes and re-raises. close finishes the generator. Frame faults are ["vm-error"].

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(body, commands):
    state = 'created'
    pc = 0
    stack = []
    handlers = []
    out = []
    def run(inject, exc):
        nonlocal pc, state
        if exc is not None:
            while handlers and handlers[-1][0] not in (exc, 'Exception'):
                handlers.pop()
            if not handlers:
                state = 'done'
                return ['raised', exc]
            pc = handlers.pop()[1]
        elif state == 'suspended' and inject is not None:
            stack.append(inject)
        state = 'running'
        try:
            while True:
                ins = body[pc]
                op = ins[0]
                pc += 1
                if op == 'push':
                    stack.append(ins[1])
                elif op == 'pop':
                    stack.pop()
                elif op == 'add':
                    b = stack.pop()
                    a = stack.pop()
                    stack.append(a + b)
                elif op == 'yield':
                    state = 'suspended'
                    return ['yielded', stack.pop()]
                elif op == 'return':
                    state = 'done'
                    return ['StopIteration', stack.pop()]
                elif op == 'try':
                    handlers.append((ins[1], ins[2]))
                elif op == 'endtry':
                    handlers.pop()
        except (IndexError, TypeError):
            state = 'done'
            return ['vm-error']
    for cmd in commands:
        kind = cmd[0]
        if kind in ('next', 'send'):
            value = cmd[1] if kind == 'send' else None
            if state == 'done':
                out.append(['StopIteration', None])
            elif state == 'created' and value is not None:
                out.append(['TypeError'])
            else:
                out.append(run(value, None))
        elif kind == 'throw':
            if state == 'created' or state == 'done':
                state = 'done'
                out.append(['raised', cmd[1]])
            else:
                out.append(run(None, cmd[1]))
        else:
            state = 'done'
            out.append(['closed'])
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression: send values through two yields',
   ([['push', 1], ['yield'], ['push', 10], ['add'], ['yield'], ['pop'], ['push', 6], ['return']],
    [['next'], ['send', 7], ['next'], ['next']]),
   [['yielded', 1], ['yielded', 17], ['StopIteration', 6], ['StopIteration', None]]),
  ('non-None send to a fresh generator',
   ([['push', 1], ['yield'], ['push', 10], ['add'], ['yield'], ['pop'], ['push', 6], ['return']],
    [['send', 0], ['next'], ['send', 1]]),
   [['TypeError'], ['yielded', 1], ['yielded', 11]]),
  ('sending zero to a suspended generator',
   ([['push', 1], ['yield'], ['push', 10], ['add'], ['yield'], ['pop'], ['push', 6], ['return']],
    [['next'], ['send', 0], ['next']]),
   [['yielded', 1], ['yielded', 10], ['StopIteration', 6]]),
  ('yield hands out and removes the value',
   ([['push', 5], ['push', 1], ['yield'], ['add'], ['return']], [['next'], ['send', 3], ['next']]),
   [['yielded', 1], ['StopIteration', 8], ['StopIteration', None]]),
  ('thrown exception caught by catch-all handler',
   ([['try', 'Exception', 7],
     ['push', 1],
     ['yield'],
     ['pop'],
     ['endtry'],
     ['push', -1],
     ['return'],
     ['push', 43],
     ['yield'],
     ['pop'],
     ['push', 0],
     ['return']],
    [['next'], ['throw', 'ValueError'], ['next']]),
   [['yielded', 1], ['yielded', 43], ['StopIteration', 0]]),
  ('uncaught throw finishes the generator',
   ([['push', 5], ['push', 1], ['yield'], ['add'], ['return']], [['next'], ['throw', 'KeyError'], ['next']]),
   [['yielded', 1], ['raised', 'KeyError'], ['StopIteration', None]]),
  ('closing a fresh generator',
   ([['push', 5], ['push', 1], ['yield'], ['add'], ['return']], [['close'], ['next']]),
   [['closed'], ['StopIteration', None]]),
  ('closing a suspended generator',
   ([['push', 5], ['push', 1], ['yield'], ['add'], ['return']], [['next'], ['close'], ['next']]),
   [['yielded', 1], ['closed'], ['StopIteration', None]]),
  ('control: throw into a fresh generator',
   ([['push', 1], ['yield'], ['push', 10], ['add'], ['yield'], ['pop'], ['push', 6], ['return']],
    [['throw', 'ValueError'], ['next']]),
   [['raised', 'ValueError'], ['StopIteration', None]])],
 [('regression: send values through two yields',
   ([['push', 1], ['yield'], ['push', 10], ['add'], ['yield'], ['pop'], ['push', 7], ['return']],
    [['next'], ['send', 14], ['next'], ['next']]),
   [['yielded', 1], ['yielded', 24], ['StopIteration', 7], ['StopIteration', None]]),
  ('non-None send to a fresh generator',
   ([['push', 1], ['yield'], ['push', 10], ['add'], ['yield'], ['pop'], ['push', 7], ['return']],
    [['send', 0], ['next'], ['send', 2]]),
   [['TypeError'], ['yielded', 1], ['yielded', 12]]),
  ('sending zero to a suspended generator',
   ([['push', 1], ['yield'], ['push', 10], ['add'], ['yield'], ['pop'], ['push', 7], ['return']],
    [['next'], ['send', 0], ['next']]),
   [['yielded', 1], ['yielded', 10], ['StopIteration', 7]]),
  ('yield hands out and removes the value',
   ([['push', 10], ['push', 1], ['yield'], ['add'], ['return']], [['next'], ['send', 3], ['next']]),
   [['yielded', 1], ['StopIteration', 13], ['StopIteration', None]]),
  ('thrown exception caught by catch-all handler',
   ([['try', 'Exception', 7],
     ['push', 1],
     ['yield'],
     ['pop'],
     ['endtry'],
     ['push', -1],
     ['return'],
     ['push', 44],
     ['yield'],
     ['pop'],
     ['push', 0],
     ['return']],
    [['next'], ['throw', 'ValueError'], ['next']]),
   [['yielded', 1], ['yielded', 44], ['StopIteration', 0]]),
  ('uncaught throw finishes the generator',
   ([['push', 10], ['push', 1], ['yield'], ['add'], ['return']], [['next'], ['throw', 'KeyError'], ['next']]),
   [['yielded', 1], ['raised', 'KeyError'], ['StopIteration', None]]),
  ('closing a fresh generator',
   ([['push', 10], ['push', 1], ['yield'], ['add'], ['return']], [['close'], ['next']]),
   [['closed'], ['StopIteration', None]]),
  ('closing a suspended generator',
   ([['push', 10], ['push', 1], ['yield'], ['add'], ['return']], [['next'], ['close'], ['next']]),
   [['yielded', 1], ['closed'], ['StopIteration', None]]),
  ('control: throw into a fresh generator',
   ([['push', 1], ['yield'], ['push', 10], ['add'], ['yield'], ['pop'], ['push', 7], ['return']],
    [['throw', 'ValueError'], ['next']]),
   [['raised', 'ValueError'], ['StopIteration', None]])],
 [('regression: send values through two yields',
   ([['push', 1], ['yield'], ['push', 10], ['add'], ['yield'], ['pop'], ['push', 8], ['return']],
    [['next'], ['send', 21], ['next'], ['next']]),
   [['yielded', 1], ['yielded', 31], ['StopIteration', 8], ['StopIteration', None]]),
  ('non-None send to a fresh generator',
   ([['push', 1], ['yield'], ['push', 10], ['add'], ['yield'], ['pop'], ['push', 8], ['return']],
    [['send', 0], ['next'], ['send', 3]]),
   [['TypeError'], ['yielded', 1], ['yielded', 13]]),
  ('sending zero to a suspended generator',
   ([['push', 1], ['yield'], ['push', 10], ['add'], ['yield'], ['pop'], ['push', 8], ['return']],
    [['next'], ['send', 0], ['next']]),
   [['yielded', 1], ['yielded', 10], ['StopIteration', 8]]),
  ('yield hands out and removes the value',
   ([['push', 15], ['push', 1], ['yield'], ['add'], ['return']], [['next'], ['send', 3], ['next']]),
   [['yielded', 1], ['StopIteration', 18], ['StopIteration', None]]),
  ('thrown exception caught by catch-all handler',
   ([['try', 'Exception', 7],
     ['push', 1],
     ['yield'],
     ['pop'],
     ['endtry'],
     ['push', -1],
     ['return'],
     ['push', 45],
     ['yield'],
     ['pop'],
     ['push', 0],
     ['return']],
    [['next'], ['throw', 'ValueError'], ['next']]),
   [['yielded', 1], ['yielded', 45], ['StopIteration', 0]]),
  ('uncaught throw finishes the generator',
   ([['push', 15], ['push', 1], ['yield'], ['add'], ['return']], [['next'], ['throw', 'KeyError'], ['next']]),
   [['yielded', 1], ['raised', 'KeyError'], ['StopIteration', None]]),
  ('closing a fresh generator',
   ([['push', 15], ['push', 1], ['yield'], ['add'], ['return']], [['close'], ['next']]),
   [['closed'], ['StopIteration', None]]),
  ('closing a suspended generator',
   ([['push', 15], ['push', 1], ['yield'], ['add'], ['return']], [['next'], ['close'], ['next']]),
   [['yielded', 1], ['closed'], ['StopIteration', None]]),
  ('control: throw into a fresh generator',
   ([['push', 1], ['yield'], ['push', 10], ['add'], ['yield'], ['pop'], ['push', 8], ['return']],
    [['throw', 'ValueError'], ['next']]),
   [['raised', 'ValueError'], ['StopIteration', None]])],
 [('regression: send values through two yields',
   ([['push', 1], ['yield'], ['push', 10], ['add'], ['yield'], ['pop'], ['push', 9], ['return']],
    [['next'], ['send', 28], ['next'], ['next']]),
   [['yielded', 1], ['yielded', 38], ['StopIteration', 9], ['StopIteration', None]]),
  ('non-None send to a fresh generator',
   ([['push', 1], ['yield'], ['push', 10], ['add'], ['yield'], ['pop'], ['push', 9], ['return']],
    [['send', 0], ['next'], ['send', 4]]),
   [['TypeError'], ['yielded', 1], ['yielded', 14]]),
  ('sending zero to a suspended generator',
   ([['push', 1], ['yield'], ['push', 10], ['add'], ['yield'], ['pop'], ['push', 9], ['return']],
    [['next'], ['send', 0], ['next']]),
   [['yielded', 1], ['yielded', 10], ['StopIteration', 9]]),
  ('yield hands out and removes the value',
   ([['push', 20], ['push', 1], ['yield'], ['add'], ['return']], [['next'], ['send', 3], ['next']]),
   [['yielded', 1], ['StopIteration', 23], ['StopIteration', None]]),
  ('thrown exception caught by catch-all handler',
   ([['try', 'Exception', 7],
     ['push', 1],
     ['yield'],
     ['pop'],
     ['endtry'],
     ['push', -1],
     ['return'],
     ['push', 46],
     ['yield'],
     ['pop'],
     ['push', 0],
     ['return']],
    [['next'], ['throw', 'ValueError'], ['next']]),
   [['yielded', 1], ['yielded', 46], ['StopIteration', 0]]),
  ('uncaught throw finishes the generator',
   ([['push', 20], ['push', 1], ['yield'], ['add'], ['return']], [['next'], ['throw', 'KeyError'], ['next']]),
   [['yielded', 1], ['raised', 'KeyError'], ['StopIteration', None]]),
  ('closing a fresh generator',
   ([['push', 20], ['push', 1], ['yield'], ['add'], ['return']], [['close'], ['next']]),
   [['closed'], ['StopIteration', None]]),
  ('closing a suspended generator',
   ([['push', 20], ['push', 1], ['yield'], ['add'], ['return']], [['next'], ['close'], ['next']]),
   [['yielded', 1], ['closed'], ['StopIteration', None]]),
  ('control: throw into a fresh generator',
   ([['push', 1], ['yield'], ['push', 10], ['add'], ['yield'], ['pop'], ['push', 9], ['return']],
    [['throw', 'ValueError'], ['next']]),
   [['raised', 'ValueError'], ['StopIteration', None]])],
 [('regression: send values through two yields',
   ([['push', 1], ['yield'], ['push', 10], ['add'], ['yield'], ['pop'], ['push', 10], ['return']],
    [['next'], ['send', 35], ['next'], ['next']]),
   [['yielded', 1], ['yielded', 45], ['StopIteration', 10], ['StopIteration', None]]),
  ('non-None send to a fresh generator',
   ([['push', 1], ['yield'], ['push', 10], ['add'], ['yield'], ['pop'], ['push', 10], ['return']],
    [['send', 0], ['next'], ['send', 5]]),
   [['TypeError'], ['yielded', 1], ['yielded', 15]]),
  ('sending zero to a suspended generator',
   ([['push', 1], ['yield'], ['push', 10], ['add'], ['yield'], ['pop'], ['push', 10], ['return']],
    [['next'], ['send', 0], ['next']]),
   [['yielded', 1], ['yielded', 10], ['StopIteration', 10]]),
  ('yield hands out and removes the value',
   ([['push', 25], ['push', 1], ['yield'], ['add'], ['return']], [['next'], ['send', 3], ['next']]),
   [['yielded', 1], ['StopIteration', 28], ['StopIteration', None]]),
  ('thrown exception caught by catch-all handler',
   ([['try', 'Exception', 7],
     ['push', 1],
     ['yield'],
     ['pop'],
     ['endtry'],
     ['push', -1],
     ['return'],
     ['push', 47],
     ['yield'],
     ['pop'],
     ['push', 0],
     ['return']],
    [['next'], ['throw', 'ValueError'], ['next']]),
   [['yielded', 1], ['yielded', 47], ['StopIteration', 0]]),
  ('uncaught throw finishes the generator',
   ([['push', 25], ['push', 1], ['yield'], ['add'], ['return']], [['next'], ['throw', 'KeyError'], ['next']]),
   [['yielded', 1], ['raised', 'KeyError'], ['StopIteration', None]]),
  ('closing a fresh generator',
   ([['push', 25], ['push', 1], ['yield'], ['add'], ['return']], [['close'], ['next']]),
   [['closed'], ['StopIteration', None]]),
  ('closing a suspended generator',
   ([['push', 25], ['push', 1], ['yield'], ['add'], ['return']], [['next'], ['close'], ['next']]),
   [['yielded', 1], ['closed'], ['StopIteration', None]]),
  ('control: throw into a fresh generator',
   ([['push', 1], ['yield'], ['push', 10], ['add'], ['yield'], ['pop'], ['push', 10], ['return']],
    [['throw', 'ValueError'], ['next']]),
   [['raised', 'ValueError'], ['StopIteration', None]])]]
for label, args, expected in cases[N - 1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(body, commands):
    state = 'created'
    pc = 0
    stack = []
    handlers = []
    out = []
    def run(inject, exc):
        nonlocal pc, state
        if exc is not None:
            while handlers and handlers[-1][0] not in (exc, 'Exception'):
                handlers.pop()
            if not handlers:
                state = 'done'
                return ['raised', exc]
            pc = handlers.pop()[1]
        elif state == 'suspended' and inject:
            stack.append(inject)
        state = 'running'
        try:
            while True:
                ins = body[pc]
                op = ins[0]
                pc += 1
                if op == 'push':
                    stack.append(ins[1])
                elif op == 'pop':
                    stack.pop()
                elif op == 'add':
                    b = stack.pop()
                    a = stack.pop()
                    stack.append(a + b)
                elif op == 'yield':
                    state = 'suspended'
                    return ['yielded', stack.pop()]
                elif op == 'return':
                    state = 'done'
                    return ['StopIteration', stack.pop()]
                elif op == 'try':
                    handlers.append((ins[1], ins[2]))
                elif op == 'endtry':
                    handlers.pop()
        except (IndexError, TypeError):
            state = 'done'
            return ['vm-error']
    for cmd in commands:
        kind = cmd[0]
        if kind in ('next', 'send'):
            value = cmd[1] if kind == 'send' else None
            if state == 'done':
                out.append(['StopIteration', None])
            elif state == 'created' and value is not None:
                out.append(['TypeError'])
            else:
                out.append(run(value, None))
        elif kind == 'throw':
            if state == 'created' or state == 'done':
                state = 'done'
                out.append(['raised', cmd[1]])
            else:
                out.append(run(None, cmd[1]))
        else:
            state = 'done'
            out.append(['closed'])
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression: send values through two yields',
   ([['push', 1], ['yield'], ['push', 10], ['add'], ['yield'], ['pop'], ['push', 6], ['return']],
    [['next'], ['send', 7], ['next'], ['next']]),
   [['yielded', 1], ['yielded', 17], ['StopIteration', 6], ['StopIteration', None]]),
  ('non-None send to a fresh generator',
   ([['push', 1], ['yield'], ['push', 10], ['add'], ['yield'], ['pop'], ['push', 6], ['return']],
    [['send', 0], ['next'], ['send', 1]]),
   [['TypeError'], ['yielded', 1], ['yielded', 11]]),
  ('sending zero to a suspended generator',
   ([['push', 1], ['yield'], ['push', 10], ['add'], ['yield'], ['pop'], ['push', 6], ['return']],
    [['next'], ['send', 0], ['next']]),
   [['yielded', 1], ['yielded', 10], ['StopIteration', 6]]),
  ('yield hands out and removes the value',
   ([['push', 5], ['push', 1], ['yield'], ['add'], ['return']], [['next'], ['send', 3], ['next']]),
   [['yielded', 1], ['StopIteration', 8], ['StopIteration', None]]),
  ('thrown exception caught by catch-all handler',
   ([['try', 'Exception', 7],
     ['push', 1],
     ['yield'],
     ['pop'],
     ['endtry'],
     ['push', -1],
     ['return'],
     ['push', 43],
     ['yield'],
     ['pop'],
     ['push', 0],
     ['return']],
    [['next'], ['throw', 'ValueError'], ['next']]),
   [['yielded', 1], ['yielded', 43], ['StopIteration', 0]]),
  ('uncaught throw finishes the generator',
   ([['push', 5], ['push', 1], ['yield'], ['add'], ['return']], [['next'], ['throw', 'KeyError'], ['next']]),
   [['yielded', 1], ['raised', 'KeyError'], ['StopIteration', None]]),
  ('closing a fresh generator',
   ([['push', 5], ['push', 1], ['yield'], ['add'], ['return']], [['close'], ['next']]),
   [['closed'], ['StopIteration', None]]),
  ('closing a suspended generator',
   ([['push', 5], ['push', 1], ['yield'], ['add'], ['return']], [['next'], ['close'], ['next']]),
   [['yielded', 1], ['closed'], ['StopIteration', None]]),
  ('control: throw into a fresh generator',
   ([['push', 1], ['yield'], ['push', 10], ['add'], ['yield'], ['pop'], ['push', 6], ['return']],
    [['throw', 'ValueError'], ['next']]),
   [['raised', 'ValueError'], ['StopIteration', None]])],
 [('regression: send values through two yields',
   ([['push', 1], ['yield'], ['push', 10], ['add'], ['yield'], ['pop'], ['push', 7], ['return']],
    [['next'], ['send', 14], ['next'], ['next']]),
   [['yielded', 1], ['yielded', 24], ['StopIteration', 7], ['StopIteration', None]]),
  ('non-None send to a fresh generator',
   ([['push', 1], ['yield'], ['push', 10], ['add'], ['yield'], ['pop'], ['push', 7], ['return']],
    [['send', 0], ['next'], ['send', 2]]),
   [['TypeError'], ['yielded', 1], ['yielded', 12]]),
  ('sending zero to a suspended generator',
   ([['push', 1], ['yield'], ['push', 10], ['add'], ['yield'], ['pop'], ['push', 7], ['return']],
    [['next'], ['send', 0], ['next']]),
   [['yielded', 1], ['yielded', 10], ['StopIteration', 7]]),
  ('yield hands out and removes the value',
   ([['push', 10], ['push', 1], ['yield'], ['add'], ['return']], [['next'], ['send', 3], ['next']]),
   [['yielded', 1], ['StopIteration', 13], ['StopIteration', None]]),
  ('thrown exception caught by catch-all handler',
   ([['try', 'Exception', 7],
     ['push', 1],
     ['yield'],
     ['pop'],
     ['endtry'],
     ['push', -1],
     ['return'],
     ['push', 44],
     ['yield'],
     ['pop'],
     ['push', 0],
     ['return']],
    [['next'], ['throw', 'ValueError'], ['next']]),
   [['yielded', 1], ['yielded', 44], ['StopIteration', 0]]),
  ('uncaught throw finishes the generator',
   ([['push', 10], ['push', 1], ['yield'], ['add'], ['return']], [['next'], ['throw', 'KeyError'], ['next']]),
   [['yielded', 1], ['raised', 'KeyError'], ['StopIteration', None]]),
  ('closing a fresh generator',
   ([['push', 10], ['push', 1], ['yield'], ['add'], ['return']], [['close'], ['next']]),
   [['closed'], ['StopIteration', None]]),
  ('closing a suspended generator',
   ([['push', 10], ['push', 1], ['yield'], ['add'], ['return']], [['next'], ['close'], ['next']]),
   [['yielded', 1], ['closed'], ['StopIteration', None]]),
  ('control: throw into a fresh generator',
   ([['push', 1], ['yield'], ['push', 10], ['add'], ['yield'], ['pop'], ['push', 7], ['return']],
    [['throw', 'ValueError'], ['next']]),
   [['raised', 'ValueError'], ['StopIteration', None]])],
 [('regression: send values through two yields',
   ([['push', 1], ['yield'], ['push', 10], ['add'], ['yield'], ['pop'], ['push', 8], ['return']],
    [['next'], ['send', 21], ['next'], ['next']]),
   [['yielded', 1], ['yielded', 31], ['StopIteration', 8], ['StopIteration', None]]),
  ('non-None send to a fresh generator',
   ([['push', 1], ['yield'], ['push', 10], ['add'], ['yield'], ['pop'], ['push', 8], ['return']],
    [['send', 0], ['next'], ['send', 3]]),
   [['TypeError'], ['yielded', 1], ['yielded', 13]]),
  ('sending zero to a suspended generator',
   ([['push', 1], ['yield'], ['push', 10], ['add'], ['yield'], ['pop'], ['push', 8], ['return']],
    [['next'], ['send', 0], ['next']]),
   [['yielded', 1], ['yielded', 10], ['StopIteration', 8]]),
  ('yield hands out and removes the value',
   ([['push', 15], ['push', 1], ['yield'], ['add'], ['return']], [['next'], ['send', 3], ['next']]),
   [['yielded', 1], ['StopIteration', 18], ['StopIteration', None]]),
  ('thrown exception caught by catch-all handler',
   ([['try', 'Exception', 7],
     ['push', 1],
     ['yield'],
     ['pop'],
     ['endtry'],
     ['push', -1],
     ['return'],
     ['push', 45],
     ['yield'],
     ['pop'],
     ['push', 0],
     ['return']],
    [['next'], ['throw', 'ValueError'], ['next']]),
   [['yielded', 1], ['yielded', 45], ['StopIteration', 0]]),
  ('uncaught throw finishes the generator',
   ([['push', 15], ['push', 1], ['yield'], ['add'], ['return']], [['next'], ['throw', 'KeyError'], ['next']]),
   [['yielded', 1], ['raised', 'KeyError'], ['StopIteration', None]]),
  ('closing a fresh generator',
   ([['push', 15], ['push', 1], ['yield'], ['add'], ['return']], [['close'], ['next']]),
   [['closed'], ['StopIteration', None]]),
  ('closing a suspended generator',
   ([['push', 15], ['push', 1], ['yield'], ['add'], ['return']], [['next'], ['close'], ['next']]),
   [['yielded', 1], ['closed'], ['StopIteration', None]]),
  ('control: throw into a fresh generator',
   ([['push', 1], ['yield'], ['push', 10], ['add'], ['yield'], ['pop'], ['push', 8], ['return']],
    [['throw', 'ValueError'], ['next']]),
   [['raised', 'ValueError'], ['StopIteration', None]])],
 [('regression: send values through two yields',
   ([['push', 1], ['yield'], ['push', 10], ['add'], ['yield'], ['pop'], ['push', 9], ['return']],
    [['next'], ['send', 28], ['next'], ['next']]),
   [['yielded', 1], ['yielded', 38], ['StopIteration', 9], ['StopIteration', None]]),
  ('non-None send to a fresh generator',
   ([['push', 1], ['yield'], ['push', 10], ['add'], ['yield'], ['pop'], ['push', 9], ['return']],
    [['send', 0], ['next'], ['send', 4]]),
   [['TypeError'], ['yielded', 1], ['yielded', 14]]),
  ('sending zero to a suspended generator',
   ([['push', 1], ['yield'], ['push', 10], ['add'], ['yield'], ['pop'], ['push', 9], ['return']],
    [['next'], ['send', 0], ['next']]),
   [['yielded', 1], ['yielded', 10], ['StopIteration', 9]]),
  ('yield hands out and removes the value',
   ([['push', 20], ['push', 1], ['yield'], ['add'], ['return']], [['next'], ['send', 3], ['next']]),
   [['yielded', 1], ['StopIteration', 23], ['StopIteration', None]]),
  ('thrown exception caught by catch-all handler',
   ([['try', 'Exception', 7],
     ['push', 1],
     ['yield'],
     ['pop'],
     ['endtry'],
     ['push', -1],
     ['return'],
     ['push', 46],
     ['yield'],
     ['pop'],
     ['push', 0],
     ['return']],
    [['next'], ['throw', 'ValueError'], ['next']]),
   [['yielded', 1], ['yielded', 46], ['StopIteration', 0]]),
  ('uncaught throw finishes the generator',
   ([['push', 20], ['push', 1], ['yield'], ['add'], ['return']], [['next'], ['throw', 'KeyError'], ['next']]),
   [['yielded', 1], ['raised', 'KeyError'], ['StopIteration', None]]),
  ('closing a fresh generator',
   ([['push', 20], ['push', 1], ['yield'], ['add'], ['return']], [['close'], ['next']]),
   [['closed'], ['StopIteration', None]]),
  ('closing a suspended generator',
   ([['push', 20], ['push', 1], ['yield'], ['add'], ['return']], [['next'], ['close'], ['next']]),
   [['yielded', 1], ['closed'], ['StopIteration', None]]),
  ('control: throw into a fresh generator',
   ([['push', 1], ['yield'], ['push', 10], ['add'], ['yield'], ['pop'], ['push', 9], ['return']],
    [['throw', 'ValueError'], ['next']]),
   [['raised', 'ValueError'], ['StopIteration', None]])],
 [('regression: send values through two yields',
   ([['push', 1], ['yield'], ['push', 10], ['add'], ['yield'], ['pop'], ['push', 10], ['return']],
    [['next'], ['send', 35], ['next'], ['next']]),
   [['yielded', 1], ['yielded', 45], ['StopIteration', 10], ['StopIteration', None]]),
  ('non-None send to a fresh generator',
   ([['push', 1], ['yield'], ['push', 10], ['add'], ['yield'], ['pop'], ['push', 10], ['return']],
    [['send', 0], ['next'], ['send', 5]]),
   [['TypeError'], ['yielded', 1], ['yielded', 15]]),
  ('sending zero to a suspended generator',
   ([['push', 1], ['yield'], ['push', 10], ['add'], ['yield'], ['pop'], ['push', 10], ['return']],
    [['next'], ['send', 0], ['next']]),
   [['yielded', 1], ['yielded', 10], ['StopIteration', 10]]),
  ('yield hands out and removes the value',
   ([['push', 25], ['push', 1], ['yield'], ['add'], ['return']], [['next'], ['send', 3], ['next']]),
   [['yielded', 1], ['StopIteration', 28], ['StopIteration', None]]),
  ('thrown exception caught by catch-all handler',
   ([['try', 'Exception', 7],
     ['push', 1],
     ['yield'],
     ['pop'],
     ['endtry'],
     ['push', -1],
     ['return'],
     ['push', 47],
     ['yield'],
     ['pop'],
     ['push', 0],
     ['return']],
    [['next'], ['throw', 'ValueError'], ['next']]),
   [['yielded', 1], ['yielded', 47], ['StopIteration', 0]]),
  ('uncaught throw finishes the generator',
   ([['push', 25], ['push', 1], ['yield'], ['add'], ['return']], [['next'], ['throw', 'KeyError'], ['next']]),
   [['yielded', 1], ['raised', 'KeyError'], ['StopIteration', None]]),
  ('closing a fresh generator',
   ([['push', 25], ['push', 1], ['yield'], ['add'], ['return']], [['close'], ['next']]),
   [['closed'], ['StopIteration', None]]),
  ('closing a suspended generator',
   ([['push', 25], ['push', 1], ['yield'], ['add'], ['return']], [['next'], ['close'], ['next']]),
   [['yielded', 1], ['closed'], ['StopIteration', None]]),
  ('control: throw into a fresh generator',
   ([['push', 1], ['yield'], ['push', 10], ['add'], ['yield'], ['pop'], ['push', 10], ['return']],
    [['throw', 'ValueError'], ['next']]),
   [['raised', 'ValueError'], ['StopIteration', None]])]]
for label, args, expected in cases[N - 1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
A body that discards its yield result pops the wrong operand after next().

A generator frame runs body ops push v, pop, add, yield (pop and hand out a value, suspend), return (pop, finish with StopIteration value), try exc target / endtry (handler stack; handler "Exception" catches any thrown name). Commands: next (= send None) and send v resume; resuming a suspended frame pushes the sent value as the result of its yield; sending non-None to a never-started generator is ["TypeError"]; a finished generator answers ["StopIteration", None]. throw into a created or finished generator finishes it with ["raised", exc]; otherwise the innermost matching handler is jumped to, or the generator finishes and re-raises. close finishes the generator. Frame faults are ["vm-error"].

split: open-access