Single Responsibility Principle適用による完全分離: - Phase 1: テスト分離 → instruction/tests.rs (196行) - Phase 2: Display実装分離 → instruction/display.rs (130行) - Phase 3: メソッド実装分離 → instruction/methods.rs (247行) - Phase 4: 統合テスト成功(全コンパイルエラー解決) 技術的成果: - MirInstruction enumを単一責任に集中 - 各実装が独立して保守可能な構造 - EffectMask::read→READ修正も完了 - ビルド成功確認済み(警告のみ) 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
82 lines
1.8 KiB
Rust
82 lines
1.8 KiB
Rust
//! IntegerBox - Integer values in Nyash
|
||
//!
|
||
//! Implements the core IntegerBox type for 64-bit signed integers.
|
||
|
||
use crate::box_trait::{NyashBox, BoxCore, BoxBase, StringBox, BoolBox};
|
||
use std::any::Any;
|
||
use std::fmt::{Debug, Display};
|
||
|
||
/// Integer values in Nyash - 64-bit signed integers
|
||
#[derive(Debug, Clone, PartialEq)]
|
||
pub struct IntegerBox {
|
||
pub value: i64,
|
||
base: BoxBase,
|
||
}
|
||
|
||
impl IntegerBox {
|
||
pub fn new(value: i64) -> Self {
|
||
Self {
|
||
value,
|
||
base: BoxBase::new(),
|
||
}
|
||
}
|
||
|
||
pub fn zero() -> Self {
|
||
Self::new(0)
|
||
}
|
||
}
|
||
|
||
impl BoxCore for IntegerBox {
|
||
fn box_id(&self) -> u64 {
|
||
self.base.id
|
||
}
|
||
|
||
fn parent_type_id(&self) -> Option<std::any::TypeId> {
|
||
self.base.parent_type_id
|
||
}
|
||
|
||
fn fmt_box(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||
write!(f, "{}", self.value)
|
||
}
|
||
|
||
fn as_any(&self) -> &dyn Any {
|
||
self
|
||
}
|
||
|
||
fn as_any_mut(&mut self) -> &mut dyn Any {
|
||
self
|
||
}
|
||
}
|
||
|
||
impl NyashBox for IntegerBox {
|
||
fn to_string_box(&self) -> StringBox {
|
||
StringBox::new(self.value.to_string())
|
||
}
|
||
|
||
fn equals(&self, other: &dyn NyashBox) -> BoolBox {
|
||
if let Some(other_int) = other.as_any().downcast_ref::<IntegerBox>() {
|
||
BoolBox::new(self.value == other_int.value)
|
||
} else {
|
||
BoolBox::new(false)
|
||
}
|
||
}
|
||
|
||
fn type_name(&self) -> &'static str {
|
||
"IntegerBox"
|
||
}
|
||
|
||
fn clone_box(&self) -> Box<dyn NyashBox> {
|
||
Box::new(self.clone())
|
||
}
|
||
|
||
/// 仮実装: clone_boxと同じ(後で修正)
|
||
fn share_box(&self) -> Box<dyn NyashBox> {
|
||
self.clone_box()
|
||
}
|
||
}
|
||
|
||
impl Display for IntegerBox {
|
||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||
self.fmt_box(f)
|
||
}
|
||
} |