refactor: Gemini/ChatGPT collaborative refactoring + build fixes
Major changes: - Split runner module: 1358→580 lines (via Gemini) - Create new modules: dispatch.rs, selfhost.rs, pipeline.rs, pipe_io.rs - Fix build errors from incomplete method migrations - Add warning to CLAUDE.md about JIT/Cranelift not working - Create interpreter.rs mode module - Refactor loop builder into separate module Build status: - ✅ Executable builds successfully - ✅ Basic execution works (tested with print) - ⚠️ 106 warnings remain (to be cleaned up next) - ⚠️ execute_mir_mode still in mod.rs (needs further migration) Note: ChatGPT correctly fixed runner.execute_mir_mode() calls that I incorrectly changed to super::modes::mir:: 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
use std::fs;
|
||||
use super::{BasicBlock, BasicBlockId};
|
||||
use crate::mir::{TypeOpKind, WeakRefOp, BarrierOp};
|
||||
|
||||
// Resolve include path using nyash.toml include.roots if present
|
||||
pub(super) fn resolve_include_path_builder(filename: &str) -> String {
|
||||
@ -69,3 +70,86 @@ impl super::MirBuilder {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Call/Type/WeakRef emission helpers (moved from builder.rs)
|
||||
impl super::MirBuilder {
|
||||
/// Emit a Box method call or plugin call (unified BoxCall)
|
||||
pub(super) fn emit_box_or_plugin_call(
|
||||
&mut self,
|
||||
dst: Option<super::ValueId>,
|
||||
box_val: super::ValueId,
|
||||
method: String,
|
||||
method_id: Option<u16>,
|
||||
args: Vec<super::ValueId>,
|
||||
effects: super::EffectMask,
|
||||
) -> Result<(), String> {
|
||||
self.emit_instruction(super::MirInstruction::BoxCall { dst, box_val, method: method.clone(), method_id, args, effects })?;
|
||||
if let Some(d) = dst {
|
||||
let mut recv_box: Option<String> = self.value_origin_newbox.get(&box_val).cloned();
|
||||
if recv_box.is_none() {
|
||||
if let Some(t) = self.value_types.get(&box_val) {
|
||||
match t { super::MirType::String => recv_box = Some("StringBox".to_string()), super::MirType::Box(name) => recv_box = Some(name.clone()), _ => {} }
|
||||
}
|
||||
}
|
||||
if let Some(bt) = recv_box {
|
||||
if let Some(mt) = self.plugin_method_sigs.get(&(bt.clone(), method.clone())) {
|
||||
self.value_types.insert(d, mt.clone());
|
||||
} else {
|
||||
let inferred: Option<super::MirType> = match (bt.as_str(), method.as_str()) {
|
||||
("StringBox", "length") | ("StringBox", "len") => Some(super::MirType::Integer),
|
||||
("StringBox", "is_empty") => Some(super::MirType::Bool),
|
||||
("StringBox", "charCodeAt") => Some(super::MirType::Integer),
|
||||
("StringBox", "substring") | ("StringBox", "concat") | ("StringBox", "replace") | ("StringBox", "trim") | ("StringBox", "toUpper") | ("StringBox", "toLower") => Some(super::MirType::String),
|
||||
("ArrayBox", "length") => Some(super::MirType::Integer),
|
||||
("MapBox", "size") => Some(super::MirType::Integer),
|
||||
("MapBox", "has") => Some(super::MirType::Bool),
|
||||
("MapBox", "get") => Some(super::MirType::Box("Any".to_string())),
|
||||
_ => None,
|
||||
};
|
||||
if let Some(mt) = inferred { self.value_types.insert(d, mt); }
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub(super) fn emit_type_check(&mut self, value: super::ValueId, expected_type: String) -> Result<super::ValueId, String> {
|
||||
let dst = self.value_gen.next();
|
||||
self.emit_instruction(super::MirInstruction::TypeOp { dst, op: TypeOpKind::Check, value, ty: super::MirType::Box(expected_type) })?;
|
||||
Ok(dst)
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub(super) fn emit_cast(&mut self, value: super::ValueId, target_type: super::MirType) -> Result<super::ValueId, String> {
|
||||
let dst = self.value_gen.next();
|
||||
self.emit_instruction(super::MirInstruction::TypeOp { dst, op: TypeOpKind::Cast, value, ty: target_type.clone() })?;
|
||||
Ok(dst)
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub(super) fn emit_weak_new(&mut self, box_val: super::ValueId) -> Result<super::ValueId, String> {
|
||||
if crate::config::env::mir_core13_pure() { return Ok(box_val); }
|
||||
let dst = self.value_gen.next();
|
||||
self.emit_instruction(super::MirInstruction::WeakRef { dst, op: WeakRefOp::New, value: box_val })?;
|
||||
Ok(dst)
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub(super) fn emit_weak_load(&mut self, weak_ref: super::ValueId) -> Result<super::ValueId, String> {
|
||||
if crate::config::env::mir_core13_pure() { return Ok(weak_ref); }
|
||||
let dst = self.value_gen.next();
|
||||
self.emit_instruction(super::MirInstruction::WeakRef { dst, op: WeakRefOp::Load, value: weak_ref })?;
|
||||
Ok(dst)
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub(super) fn emit_barrier_read(&mut self, ptr: super::ValueId) -> Result<(), String> {
|
||||
self.emit_instruction(super::MirInstruction::Barrier { op: BarrierOp::Read, ptr })
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub(super) fn emit_barrier_write(&mut self, ptr: super::ValueId) -> Result<(), String> {
|
||||
self.emit_instruction(super::MirInstruction::Barrier { op: BarrierOp::Write, ptr })
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user