2025-09-28 20:38:09 +09:00
|
|
|
//! ConstantEmissionBox — Const 命令の発行を集約(仕様不変)
|
2025-11-17 00:35:04 +09:00
|
|
|
//!
|
|
|
|
|
//! ✅ Phase 25.1b Fix: All constant emission now uses function-local ID generator
|
|
|
|
|
//! when inside a function context to ensure proper SSA verification.
|
2025-09-28 20:38:09 +09:00
|
|
|
|
|
|
|
|
use crate::mir::builder::MirBuilder;
|
2025-11-21 06:25:17 +09:00
|
|
|
use crate::mir::{ConstValue, MirInstruction, ValueId};
|
2025-09-28 20:38:09 +09:00
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
|
pub fn emit_integer(b: &mut MirBuilder, val: i64) -> ValueId {
|
2025-11-17 00:48:18 +09:00
|
|
|
let dst = b.next_value_id();
|
2025-11-21 06:25:17 +09:00
|
|
|
let _ = b.emit_instruction(MirInstruction::Const {
|
|
|
|
|
dst,
|
|
|
|
|
value: ConstValue::Integer(val),
|
|
|
|
|
});
|
2025-12-02 18:42:21 +09:00
|
|
|
// Phase 84-1: Integer constant type annotation
|
|
|
|
|
b.value_types.insert(dst, crate::mir::MirType::Integer);
|
2025-09-28 20:38:09 +09:00
|
|
|
dst
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
|
pub fn emit_bool(b: &mut MirBuilder, val: bool) -> ValueId {
|
2025-11-17 00:48:18 +09:00
|
|
|
let dst = b.next_value_id();
|
2025-11-21 06:25:17 +09:00
|
|
|
let _ = b.emit_instruction(MirInstruction::Const {
|
|
|
|
|
dst,
|
|
|
|
|
value: ConstValue::Bool(val),
|
|
|
|
|
});
|
2025-12-02 18:42:21 +09:00
|
|
|
// Phase 84-1: Bool constant type annotation
|
|
|
|
|
b.value_types.insert(dst, crate::mir::MirType::Bool);
|
2025-09-28 20:38:09 +09:00
|
|
|
dst
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
|
pub fn emit_float(b: &mut MirBuilder, val: f64) -> ValueId {
|
2025-11-17 00:48:18 +09:00
|
|
|
let dst = b.next_value_id();
|
2025-11-21 06:25:17 +09:00
|
|
|
let _ = b.emit_instruction(MirInstruction::Const {
|
|
|
|
|
dst,
|
|
|
|
|
value: ConstValue::Float(val),
|
|
|
|
|
});
|
2025-12-02 18:42:21 +09:00
|
|
|
// Phase 84-1: Float constant type annotation
|
|
|
|
|
b.value_types.insert(dst, crate::mir::MirType::Float);
|
2025-09-28 20:38:09 +09:00
|
|
|
dst
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
|
pub fn emit_string<S: Into<String>>(b: &mut MirBuilder, s: S) -> ValueId {
|
2025-11-17 00:48:18 +09:00
|
|
|
let dst = b.next_value_id();
|
2025-11-21 06:25:17 +09:00
|
|
|
let _ = b.emit_instruction(MirInstruction::Const {
|
|
|
|
|
dst,
|
|
|
|
|
value: ConstValue::String(s.into()),
|
|
|
|
|
});
|
2025-11-21 13:53:50 +09:00
|
|
|
// 🎯 Phase 3-A: String constant type annotation
|
|
|
|
|
// Ensures string constants have proper Box type for method resolution
|
2025-11-24 14:17:02 +09:00
|
|
|
b.value_types
|
|
|
|
|
.insert(dst, crate::mir::MirType::Box("StringBox".to_string()));
|
2025-11-21 13:53:50 +09:00
|
|
|
b.value_origin_newbox.insert(dst, "StringBox".to_string());
|
2025-09-28 20:38:09 +09:00
|
|
|
dst
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
|
pub fn emit_null(b: &mut MirBuilder) -> ValueId {
|
2025-11-17 00:48:18 +09:00
|
|
|
let dst = b.next_value_id();
|
2025-11-21 06:25:17 +09:00
|
|
|
let _ = b.emit_instruction(MirInstruction::Const {
|
|
|
|
|
dst,
|
|
|
|
|
value: ConstValue::Null,
|
|
|
|
|
});
|
2025-12-02 18:42:21 +09:00
|
|
|
// Phase 84-1: Null constant type annotation
|
|
|
|
|
// Note: MirType has no Null variant, using Unknown as fallback
|
|
|
|
|
b.value_types.insert(dst, crate::mir::MirType::Unknown);
|
2025-09-28 20:38:09 +09:00
|
|
|
dst
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
|
pub fn emit_void(b: &mut MirBuilder) -> ValueId {
|
2025-11-17 00:48:18 +09:00
|
|
|
let dst = b.next_value_id();
|
2025-11-21 06:25:17 +09:00
|
|
|
let _ = b.emit_instruction(MirInstruction::Const {
|
|
|
|
|
dst,
|
|
|
|
|
value: ConstValue::Void,
|
|
|
|
|
});
|
2025-12-02 18:42:21 +09:00
|
|
|
// Phase 84-1: Void constant type annotation
|
|
|
|
|
b.value_types.insert(dst, crate::mir::MirType::Void);
|
2025-09-28 20:38:09 +09:00
|
|
|
dst
|
|
|
|
|
}
|