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:
@ -30,6 +30,13 @@ def lower_function(builder, func_data: Dict[str, Any]):
|
||||
# Default: i64(i64, ...) signature; derive arity from '/N' suffix when params missing
|
||||
m = re.search(r"/(\d+)$", name)
|
||||
arity = int(m.group(1)) if m else len(params)
|
||||
# Dev fallback: when params are missing for global (Box.method) functions,
|
||||
# use observed call-site arity if available (scanned in builder.build_from_mir)
|
||||
if arity == 0 and '.' in name:
|
||||
try:
|
||||
arity = int(builder.call_arities.get(name, 0))
|
||||
except Exception:
|
||||
pass
|
||||
param_types = [builder.i64] * arity
|
||||
func_ty = ir.FunctionType(builder.i64, param_types)
|
||||
|
||||
@ -67,11 +74,38 @@ def lower_function(builder, func_data: Dict[str, Any]):
|
||||
if func is None:
|
||||
func = ir.Function(builder.module, func_ty, name=name)
|
||||
|
||||
# Map parameters to vmap (value_id: 0..arity-1)
|
||||
# Map parameters to vmap. Prefer mapping by referenced value-ids that have no
|
||||
# local definition (common in v0 JSON where params appear as lhs/rhs ids).
|
||||
try:
|
||||
arity = len(func.args)
|
||||
# Collect defined and used ids
|
||||
defs = set()
|
||||
uses = set()
|
||||
for bb in (blocks or []):
|
||||
for ins in (bb.get('instructions') or []):
|
||||
try:
|
||||
dstv = ins.get('dst')
|
||||
if isinstance(dstv, int):
|
||||
defs.add(int(dstv))
|
||||
except Exception:
|
||||
pass
|
||||
for k in ('lhs','rhs','value','cond','box_val'):
|
||||
try:
|
||||
v = ins.get(k)
|
||||
if isinstance(v, int):
|
||||
uses.add(int(v))
|
||||
except Exception:
|
||||
pass
|
||||
cand = [vid for vid in uses if vid not in defs]
|
||||
cand.sort()
|
||||
mapped = 0
|
||||
for i in range(min(arity, len(cand))):
|
||||
builder.vmap[int(cand[i])] = func.args[i]
|
||||
mapped += 1
|
||||
# Fallback: also map positional 0..arity-1 to args if not already mapped
|
||||
for i in range(arity):
|
||||
builder.vmap[i] = func.args[i]
|
||||
if i not in builder.vmap:
|
||||
builder.vmap[i] = func.args[i]
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
||||
Reference in New Issue
Block a user