amos 0eb278cdb9 Add 13 more Qwen-measured tasks from batches 26 and 27 (7 HARD, 6 MEDIUM)
Batch 26 commits 5726468 and b57e094 add NuttX time zone sources, ELF
DWARF indirect attributes, Contiki MQTT segments and FreeRTOS TCP overlap
(HARD), plus canmatrix DBC, Contiki NAT64 and UDPard frames (MEDIUM).
Batch 27's last commit cbf719b adds token macros, screen terminal and
homogeneous raster (HARD), plus modal motion, XMODEM and directed
hysteresis (MEDIUM).

These runs finished hours ago but the watcher missed them: it counted
only from each restart. Each task comes from the commit Qwen measured,
its digest matches, and it is still present at the batch branch head.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-04 20:15:50 +08:00

98 lines
3.9 KiB
Python

from decimal import Decimal, localcontext
import re
_WORD = re.compile(r'G[0-9]+|[XYZF][+-]?(?:[0-9]+(?:\.[0-9]*)?|\.[0-9]+)')
def _parse(line):
if not isinstance(line, str) or len(line) > 512 or any(c != '\t' and not 32 <= ord(c) <= 126 for c in line):
raise ValueError('block')
text = []
comment = False
for char in line:
if char == '(':
if comment:
raise ValueError('nested comment')
comment = True
text.append(' ')
elif char == ')':
if not comment:
raise ValueError('closing comment')
comment = False
text.append(' ')
elif char == ';' and not comment:
break
elif not comment:
text.append(char.upper())
if comment:
raise ValueError('open comment')
text = ''.join(text)
fields, modes, setting = {}, {}, False
cursor = 0
while cursor < len(text):
if text[cursor] in ' \t':
cursor += 1
continue
match = _WORD.match(text, cursor)
if match is None:
raise ValueError('word')
word = match.group()
cursor = match.end()
if word[0] == 'G':
code = int(word[1:])
group = {0: 'motion', 1: 'motion', 20: 'units', 21: 'units', 90: 'distance', 91: 'distance', 92: 'setting'}.get(code)
if group is None or group in modes:
raise ValueError('G group')
modes[group] = code
setting = setting or code == 92
else:
key, value = word[0], Decimal(word[1:])
if key in fields or abs(value) > 1000000 or (key == 'F' and value <= 0):
raise ValueError('value')
fields[key] = value
axes = {key: value for key, value in fields.items() if key != 'F'}
if setting and (not axes or 'motion' in modes):
raise ValueError('G92')
return modes, fields, axes, setting
def interpret(blocks):
if not isinstance(blocks, list) or len(blocks) > 256:
raise ValueError('program')
with localcontext() as context:
# At most 511 fractional input digits, one from 25.4, and fewer than
# 12 integral digits after 256 bounded translations: 1024 is exact.
context.prec = 1024
position = [Decimal(0) for _ in range(3)]
offset = [Decimal(0) for _ in range(3)]
units, distance, motion, feed = 21, 90, 0, None
moves = []
def rational(value):
return list(value.as_integer_ratio())
def vector(values):
return [rational(value) for value in values]
for index, line in enumerate(blocks):
modes, fields, axes, setting = _parse(line)
units = modes.get('units', units)
distance = modes.get('distance', distance)
motion = modes.get('motion', motion)
scale = Decimal(1) if units == 21 else Decimal('25.4')
if 'F' in fields:
feed = fields['F'] * scale
if setting:
for i, key in enumerate('XYZ'):
if key in axes:
offset[i] = position[i] - axes[key] * scale
elif axes:
if motion == 1 and feed is None:
raise ValueError('feed required')
end = position[:]
for i, key in enumerate('XYZ'):
if key in axes:
end[i] = axes[key] * scale + (offset[i] if distance == 90 else position[i])
if end == position:
continue
moves.append(dict(line=index, motion='G' + str(motion), start=vector(position), end=vector(end), feed=None if motion == 0 else rational(feed)))
position = end
return dict(moves=moves, position=vector(position), offset=vector(offset), units='G' + str(units), distance='G' + str(distance), motion='G' + str(motion), feed=None if feed is None else rational(feed))