ident
All repositories: gitoria
4.6 KB
#!/usr/bin/env python3# tests/letcount.py (copied from tickets.worldapi.org mission 010 via gitoria mission 002; ident mission 009 added `member` and `twice`): the code-order counts of an app tree (antcolony docs/code-order.md) — root .hl files, project.hl lines, and every `let`:# reassigned the name is assigned again later in its block → `let` is right# loop-bound declared inside a for/while body (re-bound each pass —# Hybriel refuses a plain declaration there on pass 2) → `let` is right# member the name is also a member / static / import of the file# (a plain `x = …` would assign that instead of declaring) → `let` is right# twice the name is declared twice in one function (sibling# blocks: Hybriel refuses the 2nd plain declaration) → `let` is right# never none of these → should be a plain declaration# python3 tests/letcount.py . [-v] (-v lists every `let` that should be a plain declaration) (scans *.hl, components/, lib/, tools/, tests/; not plugins/)import os, re, sysroot = sys.argv[1]; verbose = '-v' in sys.argvfiles = []for d in ['', 'components', 'lib', 'tools', 'tests']:p = os.path.join(root, d)if os.path.isdir(p): files += [os.path.join(p, f) for f in sorted(os.listdir(p)) if f.endswith('.hl')]def strip(src):# blank out strings and comments (same length) so braces/names inside them do not countout = list(src); i = 0; n = len(src)while i < n:c = src[i]if src.startswith('//', i):j = src.find('\n', i); j = n if j < 0 else jfor k in range(i, j): out[k] = ' 'i = j; continueif c in '\'"`':j = i + 1while j < n and src[j] != c:if c == "'" and src[j] == '\\' and j + 1 < n and src[j + 1] == "'": j += 2; continuej += 1for k in range(i + 1, min(j, n)):if out[k] != '\n': out[k] = ' 'i = j + 1; continuei += 1return ''.join(out)tot = {'reassigned': 0, 'loop-bound': 0, 'member': 0, 'twice': 0, 'never': 0}per = {}for f in files:s = strip(open(f).read())names = set(re.findall(r'^(?:static\s+)?(?:[A-Z]\w*\s+)?#?(\w+)\s*(?:=|\()', s, re.M))for m in re.finditer(r'^import\s*\{([^}]*)\}', s, re.M): names |= {x.strip() for x in m.group(1).split(',') if x.strip()}names |= set(re.findall(r'^import\s+(\w+)\s+from', s, re.M))opens = []; match = {}; stack = []for i, c in enumerate(s):if c == '{': stack.append(i)elif c == '}' and stack: match[stack.pop()] = ifor m in re.finditer(r'\blet\s+(\w+)\s*=', s):name, p = m.group(1), m.start()encl = [o for o, e in match.items() if o < p < e]encl.sort(reverse=True) # innermost firstinner_end = match[encl[0]] if encl else len(s)kind = 'never'if re.search(r'(?<![\w.#])' + re.escape(name) + r'\s*(=(?!=)|\+\+|--|\+=|-=)', s[m.end():inner_end]): kind = 'reassigned'else:for o in encl:head = s[max(0, o - 300):o]line = head[head.rfind('\n') + 1:] if '\n' in head else headif re.search(r'=>\s*$', head) or re.match(r'\s*(on\s|static\s|\w+\s*\([^)]*\)\s*$)', line) and not re.match(r'\s*(if|for|while|else)\b', line): breakif re.search(r'\b(for|while)\s*\([^{}]*\)\s*$', head): kind = 'loop-bound'; breakif kind == 'never' and name in names: kind = 'member'if kind == 'never':fn = next((o for o in encl if re.search(r'=>\s*$', s[max(0, o - 300):o]) or re.match(r'\s*(on\s|static\s)', s[max(0, o - 300):o].split('\n')[-1])), None)if fn is not None and len(re.findall(r'\blet\s+' + re.escape(name) + r'\s*=', s[fn:match[fn]])) > 1: kind = 'twice'tot[kind] += 1per.setdefault(os.path.relpath(f, root), {'reassigned': 0, 'loop-bound': 0, 'member': 0, 'twice': 0, 'never': 0})[kind] += 1if verbose and kind == 'never': print(f' never: {os.path.relpath(f, root)}:{s.count(chr(10), 0, p) + 1} {name}')rootHl = [f for f in os.listdir(root) if f.endswith('.hl')]pl = sum(1 for _ in open(os.path.join(root, 'project.hl')))print(f'root .hl files: {len(rootHl)} ({" ".join(sorted(rootHl))})')print(f'project.hl lines: {pl}')print(f'let total {sum(tot.values())}: reassigned {tot["reassigned"]}, loop-bound {tot["loop-bound"]}, member name {tot["member"]}, declared twice {tot["twice"]}, never reassigned {tot["never"]}')for f, k in sorted(per.items()): print(f' {f}: {k}')
Branches
- mainmain branch
Latest commits
- 5fdbb6b2ident mission 009: report — scratch folder notemre
- 74235815ident mission 009 (4/4): docs (README files map + same-output test, STATUS, LOG), report, tests/letcount.py + realdata-baseline/comparemre
- fe183516ident mission 009 (3/4): let only where reassigned — 293 never-reassigned lets are plain declarations; kept: reassigned, loop bodies, names of a file member, a name declared twice in one function; same outputmre
- d2e7f91bident mission 009 (2/4): one lib file per topic (login, accounts, identities, apps, invites, selector, notify + helpers, util), function routes as thin wrappers in lib/api.hl, project.hl = the map; same outputmre
- 91017164ident mission 009 (1/4): file moves — the root .hl files into lib/ (api.hl → lib/api-helpers.hl), styles.hl → components/styles.hl; imports adjusted, no other changemre
- f8bdcbc2ident: Hybriel master 06617221 (plugin allocators 3a781359 + 413f60e4, mpackdb 2cb7ae5e, http1 773de63e); all gates greenmre
- ff78726cident: Hybriel master 190aa11d (fc838894 GC correctness, #127, #126 closure scopes); gates all greenmre
- a3a7d21aident: Hybriel master 8efba065 (#126 GC by bytes, #48 lambda params copy); session-writing lambdas take &sessionmre
- 98226b41antcolony#40: mission references point to the moved missionsmre
- ff805b9aantcolony#40: history (LOG.md), worker briefs (missions/) and reports moved here from antcolony, numbered per project; old numbers in antcolony docs/mission-map.mdmre
- 51a7bcdfident: Hybriel master 73267707 (#122); /code uses the new page() signature; pending address passed as parameter; once-checksmre
- 836f644fident#24: installable app (manifest, service worker, data-free offline /start), own iconmre
- 8bebbbf2deploy.sh: back up live storage/.sessions/.env before every deploy (newest 5 kept)mre
- cc063ea2deploy.sh: never send .git or .gitignore to Byrodinmre
- 81b15b7bState of 2026-09-27, before the move to gitoriamre