Files
hakorune/src/mir/function_emission.rs
nyash-codex dd65cf7e4c 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).
2025-09-28 20:38:09 +09:00

58 lines
1.9 KiB
Rust
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//! 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 });
}
}