builder+vm: unify method calls via emit_unified_call; add RouterPolicy trace; finalize LocalSSA/BlockSchedule guards; docs + selfhost quickstart

- Unify standard method calls to emit_unified_call; route via RouterPolicy and apply rewrite::{special,known} at a single entry.\n- Stabilize emit-time invariants: LocalSSA finalize + BlockSchedule PHI→Copy→Call ordering; metadata propagation on copies.\n- Known rewrite default ON (userbox only, strict guards) with opt-out flag NYASH_REWRITE_KNOWN_DEFAULT=0.\n- Expand TypeAnnotation whitelist (is_digit_char/is_hex_digit_char/is_alpha_char/Map.has).\n- Docs: unified-method-resolution design note; Quick Reference normalization note; selfhosting/quickstart.\n- Tools: add tools/selfhost_smoke.sh (dev-only).\n- Keep behavior unchanged for Unknown/core/user-instance via BoxCall fallback; all tests green (quick/integration).
This commit is contained in:
nyash-codex
2025-09-28 20:38:09 +09:00
parent e442e5f612
commit dd65cf7e4c
60 changed files with 2523 additions and 471 deletions

View File

@ -0,0 +1,57 @@
//! FunctionEmissionBox — MirFunction 直編集時の発行ヘルパ仕様不変・dev補助
//!
//! MirBuilder 経由ではなく MirFunction/BasicBlock を直接編集する箇所dev 補助)向けに、
//! よく使う Const/Return/Jump の発行を薄い関数で提供する。
use crate::mir::{BasicBlockId, ConstValue, MirFunction, MirInstruction, ValueId};
#[inline]
pub fn emit_const_integer(f: &mut MirFunction, bb: BasicBlockId, val: i64) -> ValueId {
let dst = f.next_value_id();
if let Some(block) = f.get_block_mut(bb) {
block.add_instruction(MirInstruction::Const { dst, value: ConstValue::Integer(val) });
}
dst
}
#[inline]
pub fn emit_const_bool(f: &mut MirFunction, bb: BasicBlockId, val: bool) -> ValueId {
let dst = f.next_value_id();
if let Some(block) = f.get_block_mut(bb) {
block.add_instruction(MirInstruction::Const { dst, value: ConstValue::Bool(val) });
}
dst
}
#[inline]
pub fn emit_const_string<S: Into<String>>(f: &mut MirFunction, bb: BasicBlockId, s: S) -> ValueId {
let dst = f.next_value_id();
if let Some(block) = f.get_block_mut(bb) {
block.add_instruction(MirInstruction::Const { dst, value: ConstValue::String(s.into()) });
}
dst
}
#[inline]
pub fn emit_const_void(f: &mut MirFunction, bb: BasicBlockId) -> ValueId {
let dst = f.next_value_id();
if let Some(block) = f.get_block_mut(bb) {
block.add_instruction(MirInstruction::Const { dst, value: ConstValue::Void });
}
dst
}
#[inline]
pub fn emit_return_value(f: &mut MirFunction, bb: BasicBlockId, value: ValueId) {
if let Some(block) = f.get_block_mut(bb) {
block.add_instruction(MirInstruction::Return { value: Some(value) });
}
}
#[inline]
pub fn emit_jump(f: &mut MirFunction, bb: BasicBlockId, target: BasicBlockId) {
if let Some(block) = f.get_block_mut(bb) {
block.add_instruction(MirInstruction::Jump { target });
}
}