mir/vm: SSA pin+PHI + short-circuit; user-defined method calls → functions; entry single-pred PHIs; compare-operand pin; VM BoxCall fallback to InstanceBox methods; docs: update CURRENT_TASK (plan + acceptance)
- Lower And/Or to branch+PHI (RHS not evaluated) - Always slotify compare operands (dominance safety) - Insert single-predecessor PHIs at then/else/short-circuit entries - pin_to_slot now logs (NYASH_PIN_TRACE) and participates in PHI - Rewrite user-defined instance method calls to Box.method/Arity (builder) - VM fallback: BoxCall on InstanceBox dispatches to lowered functions with 'me'+args - Keep plugin/BoxCall path for core boxes (String/Array/Map) - Add env-gated pre-pin for if/loop (NYASH_MIR_PREPIN) - CURRENT_TASK: add SSA/userbox plan, debug steps, acceptance criteria
This commit is contained in:
@ -481,6 +481,23 @@ impl MirInterpreter {
|
||||
))),
|
||||
}
|
||||
} else {
|
||||
// Dynamic fallback for user-defined InstanceBox: dispatch to lowered function "Class.method/Arity"
|
||||
if let Some(inst) = recv_box.as_any().downcast_ref::<crate::instance_v2::InstanceBox>() {
|
||||
let class_name = inst.class_name.clone();
|
||||
let arity = args.len(); // function name arity excludes 'me'
|
||||
let fname = format!("{}.{}{}", class_name, method, format!("/{}", arity));
|
||||
if let Some(func) = self.functions.get(&fname).cloned() {
|
||||
let mut argv: Vec<VMValue> = Vec::with_capacity(arity + 1);
|
||||
// Pass receiver as first arg ('me')
|
||||
argv.push(recv.clone());
|
||||
for a in args {
|
||||
argv.push(self.reg_load(*a)?);
|
||||
}
|
||||
let ret = self.exec_function_inner(&func, Some(&argv))?;
|
||||
if let Some(d) = dst { self.regs.insert(d, ret); }
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
Err(VMError::InvalidInstruction(format!(
|
||||
"BoxCall unsupported on {}.{}",
|
||||
recv_box.type_name(),
|
||||
|
||||
@ -38,6 +38,11 @@ impl MirInterpreter {
|
||||
use BinaryOp::*;
|
||||
use VMValue::*;
|
||||
Ok(match (op, a, b) {
|
||||
// Safety valve: treat Void as 0 for + (dev fallback for scanners)
|
||||
(Add, VMValue::Void, Integer(y)) => Integer(y),
|
||||
(Add, Integer(x), VMValue::Void) => Integer(x),
|
||||
(Add, VMValue::Void, Float(y)) => Float(y),
|
||||
(Add, Float(x), VMValue::Void) => Float(x),
|
||||
(Add, Integer(x), Integer(y)) => Integer(x + y),
|
||||
(Add, String(s), Integer(y)) => String(format!("{}{}", s, y)),
|
||||
(Add, String(s), Float(y)) => String(format!("{}{}", s, y)),
|
||||
|
||||
Reference in New Issue
Block a user