Fix bootstrapper cell variable scoping for nested closures

Two bugs in _emit_define_as_def: (1) nested def's _current_cell_vars
was replaced instead of unioned with parent — inner functions lost
access to parent's cell vars (skip_ws/skip_comment used bare pos
instead of _cells['pos']). (2) statement-context set! didn't check
_current_cell_vars, always emitting bare assignment instead of
_cells[...]. (3) nested functions that access parent _cells no longer
shadow it with their own empty _cells = {}.

Fixes UnboundLocalError in bootstrapped parser (sx_parse skip_ws)
that crashed production URL routing.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-14 01:46:15 +00:00
parent 4b746e4c8b
commit b06cc2daca

View File

@@ -2199,7 +2199,6 @@ def sx_parse(source):
def hex_digit_value(ch):
return index_of('0123456789abcdef', lower(ch))
def read_string():
_cells = {}
_cells['pos'] = (_cells['pos'] + 1)
_cells['buf'] = ''
def read_str_loop():
@@ -2236,7 +2235,6 @@ def sx_parse(source):
read_str_loop()
return _cells['buf']
def read_ident():
_cells = {}
start = _cells['pos']
def read_ident_loop():
if sx_truthy(((_cells['pos'] < len_src) if not sx_truthy((_cells['pos'] < len_src)) else ident_char_p(nth(source, _cells['pos'])))):
@@ -2249,7 +2247,6 @@ def sx_parse(source):
_cells['pos'] = (_cells['pos'] + 1)
return make_keyword(read_ident())
def read_number():
_cells = {}
start = _cells['pos']
if sx_truthy(((_cells['pos'] < len_src) if not sx_truthy((_cells['pos'] < len_src)) else (nth(source, _cells['pos']) == '-'))):
_cells['pos'] = (_cells['pos'] + 1)
@@ -2279,7 +2276,6 @@ def sx_parse(source):
else:
return make_symbol(name)
def read_list(close_ch):
_cells = {}
items = []
def read_list_loop():
skip_ws()
@@ -2295,7 +2291,6 @@ def sx_parse(source):
read_list_loop()
return items
def read_map():
_cells = {}
result = {}
def read_map_loop():
skip_ws()
@@ -2314,7 +2309,6 @@ def sx_parse(source):
read_map_loop()
return result
def read_raw_string():
_cells = {}
_cells['buf'] = ''
def raw_loop():
if sx_truthy((_cells['pos'] >= len_src)):