merge: resolve conflicts (prefer cranelift-dev for Core-13 defaults; drop modules/using, add env.local/env.box shims)

This commit is contained in:
Tomoaki
2025-09-08 01:28:39 +09:00
373 changed files with 14800 additions and 614 deletions

View File

@ -95,9 +95,39 @@ pub fn compile_and_execute(mir_module: &MirModule, _temp_name: &str) -> Result<B
MirInstruction::Copy { dst, src } => {
if let Some(v) = regs.get(src).cloned() { regs.insert(*dst, v); }
}
MirInstruction::Debug { .. } | MirInstruction::Print { .. } | MirInstruction::Barrier { .. } | MirInstruction::BarrierRead { .. } | MirInstruction::BarrierWrite { .. } | MirInstruction::Safepoint | MirInstruction::Load { .. } | MirInstruction::Store { .. } | MirInstruction::TypeOp { .. } | MirInstruction::Compare { .. } | MirInstruction::NewBox { .. } | MirInstruction::PluginInvoke { .. } | MirInstruction::BoxCall { .. } | MirInstruction::ExternCall { .. } | MirInstruction::RefGet { .. } | MirInstruction::RefSet { .. } | MirInstruction::WeakRef { .. } | MirInstruction::FutureNew { .. } | MirInstruction::FutureSet { .. } | MirInstruction::Await { .. } | MirInstruction::Throw { .. } | MirInstruction::Catch { .. } => {
MirInstruction::Debug { .. } | MirInstruction::Print { .. } | MirInstruction::Barrier { .. } | MirInstruction::BarrierRead { .. } | MirInstruction::BarrierWrite { .. } | MirInstruction::Safepoint | MirInstruction::Load { .. } | MirInstruction::Store { .. } | MirInstruction::TypeOp { .. } | MirInstruction::Compare { .. } | MirInstruction::NewBox { .. } | MirInstruction::PluginInvoke { .. } | MirInstruction::BoxCall { .. } | MirInstruction::RefGet { .. } | MirInstruction::RefSet { .. } | MirInstruction::WeakRef { .. } | MirInstruction::FutureNew { .. } | MirInstruction::FutureSet { .. } | MirInstruction::Await { .. } | MirInstruction::Throw { .. } | MirInstruction::Catch { .. } => {
// ignore for minimal path
}
MirInstruction::ExternCall { dst, iface_name, method_name, args, .. } => {
use crate::backend::vm::VMValue as V;
match (iface_name.as_str(), method_name.as_str()) {
("env.local", "get") => {
if let Some(d) = dst { if let Some(a0) = args.get(0) { if let Some(v) = regs.get(a0).cloned() { regs.insert(*d, v); } } }
}
("env.local", "set") => {
if args.len() >= 2 { if let Some(v) = regs.get(&args[1]).cloned() { regs.insert(args[0], v); } }
// dst ignored
}
("env.box", "new") => {
if let Some(d) = dst {
if let Some(a0) = args.get(0) {
if let Some(V::String(ty)) = regs.get(a0).cloned() {
let reg = crate::runtime::box_registry::get_global_registry();
// Collect args as NyashBox
let mut ny_args: Vec<Box<dyn crate::box_trait::NyashBox>> = Vec::new();
for vid in args.iter().skip(1) {
if let Some(v) = regs.get(vid).cloned() { ny_args.push(v.to_nyash_box()); }
}
if let Ok(b) = reg.create_box(&ty, &ny_args) {
regs.insert(*d, V::from_nyash_box(b));
}
}
}
}
}
_ => { /* ignore other externs in skeleton */ }
}
}
MirInstruction::Phi { .. } => { /* handled above */ }
_ => {}
}

View File

@ -6,12 +6,70 @@ use crate::backend::{VM, VMError, VMValue};
impl VM {
/// Execute ExternCall instruction
pub(crate) fn execute_extern_call(&mut self, dst: Option<ValueId>, iface_name: &str, method_name: &str, args: &[ValueId]) -> Result<ControlFlow, VMError> {
// Core-13 pure shims: env.local.{get,set}, env.box.new
match (iface_name, method_name) {
("env.local", "get") => {
if args.len() != 1 { return Err(VMError::InvalidInstruction("env.local.get arity".into())); }
let ptr = args[0];
let v = self.get_value(ptr).unwrap_or(crate::backend::vm::VMValue::Void);
if let Some(d) = dst { self.set_value(d, v); }
return Ok(ControlFlow::Continue);
}
("env.local", "set") => {
if args.len() != 2 { return Err(VMError::InvalidInstruction("env.local.set arity".into())); }
let ptr = args[0];
let val = self.get_value(args[1])?;
self.set_value(ptr, val);
if let Some(d) = dst { self.set_value(d, crate::backend::vm::VMValue::Void); }
return Ok(ControlFlow::Continue);
}
("env.box", "new") => {
if args.is_empty() { return Err(VMError::InvalidInstruction("env.box.new requires type name".into())); }
// first arg must be Const String type name
let ty = self.get_value(args[0])?;
let ty_name = match ty { crate::backend::vm::VMValue::String(s) => s, _ => return Err(VMError::InvalidInstruction("env.box.new first arg must be string".into())) };
// remaining args as NyashBox
let mut ny_args: Vec<Box<dyn NyashBox>> = Vec::new();
for id in args.iter().skip(1) {
let v = self.get_value(*id)?;
ny_args.push(v.to_nyash_box());
}
let reg = crate::runtime::box_registry::get_global_registry();
match reg.create_box(&ty_name, &ny_args) {
Ok(b) => { if let Some(d) = dst { self.set_value(d, crate::backend::vm::VMValue::from_nyash_box(b)); } }
Err(e) => { return Err(VMError::InvalidInstruction(format!("env.box.new failed for {}: {}", ty_name, e))); }
}
return Ok(ControlFlow::Continue);
}
_ => {}
}
// Optional routing to name→slot handlers for stability and diagnostics
if crate::config::env::extern_route_slots() {
if let Some(slot) = crate::runtime::extern_registry::resolve_slot(iface_name, method_name) {
// Decode args to VMValue as needed by handlers below
let vm_args: Vec<VMValue> = args.iter().filter_map(|a| self.get_value(*a).ok()).collect();
match (iface_name, method_name, slot) {
("env.local", "get", 40) => {
if let Some(d) = dst { if let Some(a0) = args.get(0) { let v = self.get_value(*a0).unwrap_or(VMValue::Void); self.set_value(d, v); } }
return Ok(ControlFlow::Continue);
}
("env.local", "set", 41) => {
if args.len() >= 2 { let ptr = args[0]; let val = vm_args.get(1).cloned().unwrap_or(VMValue::Void); self.set_value(ptr, val); }
if let Some(d) = dst { self.set_value(d, VMValue::Void); }
return Ok(ControlFlow::Continue);
}
("env.box", "new", 50) => {
if vm_args.is_empty() { return Err(VMError::InvalidInstruction("env.box.new requires type".into())); }
let ty = &vm_args[0]; let ty_name = match ty { VMValue::String(s) => s.clone(), _ => return Err(VMError::InvalidInstruction("env.box.new first arg must be string".into())) };
let mut ny_args: Vec<Box<dyn NyashBox>> = Vec::new();
for v in vm_args.iter().skip(1) { ny_args.push(v.to_nyash_box()); }
let reg = crate::runtime::box_registry::get_global_registry();
match reg.create_box(&ty_name, &ny_args) {
Ok(b) => { if let Some(d) = dst { self.set_value(d, VMValue::from_nyash_box(b)); } }
Err(e) => { return Err(VMError::InvalidInstruction(format!("env.box.new failed for {}: {}", ty_name, e))); }
}
return Ok(ControlFlow::Continue);
}
("env.console", m @ ("log" | "warn" | "error" | "println"), 10) => {
if let Some(a0) = vm_args.get(0) {
match m { "warn" => eprintln!("[warn] {}", a0.to_string()), "error" => eprintln!("[error] {}", a0.to_string()), _ => println!("{}", a0.to_string()), }