Files
visormesh/palm-client/tools/sect2.py
T
rich c713d8ba34 palm-client: modules into segment 2 with a build check; better Unicode display
Segment 1 was back at 27 KB. Settings, Contacts, Channel, Home, Node,
convos, messages, contacts, channels, rowlist and draw move to vmcode2:
segment 1 is now 10.3 KB, segment 2 23.4 KB. tools/sect2.py adds the
VM_SECT2 static declarations.

Checked in the compiled code, the rules in sections.h were too cautious:
literals in a vmcode2 function are emitted into vmcode2, a file's static
const data and calls to unannotated functions go through the __text__
base, and taking a vmcode2 function's address (event handlers, callbacks)
gives its real address. The real traps are shared extern const tables and
-fwritable-strings (PC-relative into .data). tools/check_sections.py runs
after every link and fails the build on any PC-relative reference from
vmcode2 to outside it; python3 added to the toolchain image for it.

Unicode: characters past Latin-1 all became '?', and Windows-1252 quotes
and dashes had no glyph in the small font. Now arrows, check marks, stars,
bullets and node-type marks map to the font's UI symbols, typographic
quotes and dashes to ASCII, any emoji to a new smiley glyph, and
variation selectors / zero-width joiners are dropped.
2026-11-01 17:29:20 -05:00

20 lines
904 B
Python

#!/usr/bin/env python3
"""Puts a C file's static functions in the second code segment: inserts a
'static <signature> VM_SECT2;' forward declaration for each one after the
last #include (see src/sections.h). Run once per file moved; idempotent."""
import re
import sys
for path in sys.argv[1:]:
src = open(path).read()
marker = '/* In the second code segment: see sections.h for the rules. */'
if marker in src:
print(f'{path}: already done')
continue
sigs = re.findall(r'^(static\s+(?!const\s+UInt|UInt8\s+g|Char\s+\*g)[^=;{]*?\w+\s*\([^;{]*?\))\s*\n\{', src, re.M)
decls = '\n'.join(re.sub(r'\s+', ' ', s) + ' VM_SECT2;' for s in sigs)
last_inc = list(re.finditer(r'^#include .*\n', src, re.M))[-1]
src = src[:last_inc.end()] + f'\n{marker}\n{decls}\n' + src[last_inc.end():]
open(path, 'w').write(src)
print(f'{path}: {len(sigs)} static functions')