tracker
All repositories: gitoria
1.9 KB
# refparams.py <app dir> [--apply] [files...]: lambda parameters that a body only READS get `&` (hybriel#48: a lambda parameter# copies its argument since 4371b7aa; before it was a reference — `&` restores exactly that for read-only params, without the copy).# Skipped: params assigned (p = …), field-assigned (p.x = / p[k] =), list-mutated (p.push …), aliased (let x = p), defaults.import re,sys,glob,osos.chdir(sys.argv[1]); apply='--apply' in sys.argvfiles=[a for a in sys.argv[2:] if a!='--apply'] or (glob.glob('*.hl')+glob.glob('lib/*.hl')+glob.glob('components/*.hl')+glob.glob('tools/*.hl'))total=0; changed_files=0for f in sorted(files):src=open(f,encoding='utf-8').read(); out=[]; last=0; n=0for m in re.finditer(r'\(([^()]*)\)(\s*=>\s*\{)',src):params=[p.strip() for p in m.group(1).split(',')]if params==[''] : continueif not all(re.match(r'^&?\w+$',p) for p in params): continuei=m.end(); depth=1while depth and i<len(src):c=src[i]; depth += (c=='{') - (c=='}'); i+=1body=src[m.end():i-1]new=[]for p in params:if p.startswith('&'): new.append(p); continuebad = re.search(r'(?<![\w.])%s\s*=(?!=)'%p,body) or re.search(r'(?<![\w.])%s(?:\.\w+|\[[^\]]*\])+\s*=(?!=)'%p,body) \or re.search(r'(?<![\w.])%s(?:\.\w+|\[[^\]]*\])*\.(push|pop|shift|unshift|splice|sort|reverse)\('%p,body) \or re.search(r'=\s*%s\s*$'%p,body,re.M) or re.search(r'=\s*%s\s*[;}]'%p,body) or re.search(r'(?<![\w.])%s\s*(\+\+|--)'%p,body)new.append(p if bad else '&'+p)if new!=params:n+=1out.append(src[last:m.start()]); out.append('('+', '.join(new)+')'); last=m.start()+1+len(m.group(1))+1out.append(src[last:])if n:total+=n; changed_files+=1print(f'{f}: {n} lambdas')if apply: open(f,'w',encoding='utf-8').write(''.join(out))print('total lambdas changed',total,'files',changed_files)
Branches
Latest commits
- 529096e8RV28c: reportmre
- a4047071RV28c: re-vendor Hybriel set day35 (source cb9e480d, bin 4bb25cfa)mre
- 765057fbMerge main into rv28c (LOG.md, STATUS.md: both sides kept)mre
- bf401884Tracker: RV28c startedmre
- 0ff4ecd4Tracker: RV28c briefmre
- 06565b1fRecords: day35 relay note, tickets subscription idmre
- c6dc3e86RV28b: switch to set day35mre
- 24e401b8Tracker: TR7 watch cleanmre
- b0412957Tracker: RV28b handed overmre
- 456940c8Tracker: RULINGS pathmre
- b87a8fdcTracker: worldapi-conductor paths backmre
- 641f3b54Tracker: Apollo answermre
- 8b3cbddaTracker: status, TR7 fix livemre
- ec30162aTracker: TR7 fix livemre
- 54cbec80compose: ignore SIGPIPE (TR7 crash loop, exit 141)mre
- 3e164b63Tracker: status after CL1mre
- 9d686bb3Tracker: CL1 reviewedmre
- b8bba562CL1: crash loop report (SIGPIPE confirmed, trap wrapper option)mre
- 298785f2Tracker: CL1 startedmre
- 36b22710Tracker: port slot, CL1 briefmre