Phase 21.6 solidification: chain green (return/binop/loop/call); add Phase 21.7 normalization plan (methodize static boxes). Update CURRENT_TASK.md and docs.
This commit is contained in:
@ -133,6 +133,46 @@ class NyashLLVMBuilder:
|
||||
# Parse MIR
|
||||
reader = MIRReader(mir_json)
|
||||
functions = reader.get_functions()
|
||||
|
||||
# Pre-scan call sites to estimate arity for global functions when params are missing
|
||||
def _scan_call_arities(funcs: List[Dict[str, Any]]):
|
||||
ar: Dict[str, int] = {}
|
||||
for f in funcs or []:
|
||||
# Build map: const dst -> string name (per-function scope)
|
||||
const_names: Dict[int, str] = {}
|
||||
for bb in (f.get('blocks') or []):
|
||||
for ins in (bb.get('instructions') or []):
|
||||
try:
|
||||
op = ins.get('op')
|
||||
if op == 'const':
|
||||
dst = ins.get('dst')
|
||||
val = ins.get('value') or {}
|
||||
name = None
|
||||
if isinstance(val, dict):
|
||||
v = val.get('value')
|
||||
t = val.get('type')
|
||||
if isinstance(v, str) and (
|
||||
t == 'string' or (isinstance(t, dict) and t.get('box_type') == 'StringBox')
|
||||
):
|
||||
name = v
|
||||
if isinstance(dst, int) and isinstance(name, str):
|
||||
const_names[int(dst)] = name
|
||||
elif op == 'call':
|
||||
func_id = ins.get('func')
|
||||
if isinstance(func_id, int) and func_id in const_names:
|
||||
nm = const_names[func_id]
|
||||
argc = len(ins.get('args') or [])
|
||||
prev = ar.get(nm, 0)
|
||||
if argc > prev:
|
||||
ar[nm] = argc
|
||||
except Exception:
|
||||
continue
|
||||
return ar
|
||||
|
||||
try:
|
||||
self.call_arities = _scan_call_arities(functions)
|
||||
except Exception:
|
||||
self.call_arities = {}
|
||||
|
||||
if not functions:
|
||||
# No functions - create dummy ny_main
|
||||
@ -149,6 +189,12 @@ class NyashLLVMBuilder:
|
||||
params_list = func_data.get("params", []) or []
|
||||
if "." in name:
|
||||
arity = len(params_list)
|
||||
# Dev fallback: when params missing for Box.method, use call-site arity
|
||||
if arity == 0:
|
||||
try:
|
||||
arity = int(self.call_arities.get(name, 0))
|
||||
except Exception:
|
||||
pass
|
||||
else:
|
||||
arity = int(m.group(1)) if m else len(params_list)
|
||||
if name == "ny_main":
|
||||
|
||||
Reference in New Issue
Block a user