Files
hakorune/tests/mir_builder_unit.rs
Selfhosting Dev 824ca600ea refactor: 大規模ファイル分割とプラグインリファクタリング
## 🎯 プラグイン整理
-  **nyash-json-plugin**: プロバイダー抽象化、NodeRep統一
-  **nyash-string-plugin**: TLVヘルパー整理
-  **nyash-net-plugin**: HTTPヘルパー分離、ソケット管理改善
-  **nyash-counter-plugin/fixture-plugin**: 基本構造整理

## 📂 mir_interpreter分割
-  **mir_interpreter.rs → mir_interpreter/ディレクトリ**
  - mod.rs: メイン構造体定義
  - execution.rs: 実行エンジン
  - memory.rs: メモリ管理
  - instructions/: 命令別実装

## 🔧 その他の改善
- テストファイル群の最適化
- LLVMコンパイラのメイン関数整理
- 不要なインポート削除

1000行超のファイルを適切なモジュール構造に分割完了!

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-25 01:09:48 +09:00

67 lines
2.0 KiB
Rust

use nyash_rust::ast::{ASTNode, BinaryOperator, LiteralValue, Span};
use nyash_rust::mir::MirBuilder;
#[test]
fn test_literal_building() {
let mut builder = MirBuilder::new();
let ast = ASTNode::Literal {
value: LiteralValue::Integer(42),
span: Span::unknown(),
};
let result = builder.build_module(ast);
assert!(result.is_ok());
let module = result.unwrap();
assert_eq!(module.function_names().len(), 1);
assert!(module.get_function("main").is_some());
}
#[test]
fn test_binary_op_building() {
let mut builder = MirBuilder::new();
let ast = ASTNode::BinaryOp {
left: Box::new(ASTNode::Literal {
value: LiteralValue::Integer(10),
span: Span::unknown(),
}),
operator: BinaryOperator::Add,
right: Box::new(ASTNode::Literal {
value: LiteralValue::Integer(32),
span: Span::unknown(),
}),
span: Span::unknown(),
};
let result = builder.build_module(ast);
assert!(result.is_ok());
let module = result.unwrap();
let function = module.get_function("main").unwrap();
let stats = function.stats();
assert!(stats.instruction_count >= 3);
}
#[test]
fn test_if_statement_building() {
let mut builder = MirBuilder::new();
let ast = ASTNode::If {
condition: Box::new(ASTNode::Literal {
value: LiteralValue::Bool(true),
span: Span::unknown(),
}),
then_body: vec![ASTNode::Literal {
value: LiteralValue::Integer(1),
span: Span::unknown(),
}],
else_body: Some(vec![ASTNode::Literal {
value: LiteralValue::Integer(2),
span: Span::unknown(),
}]),
span: Span::unknown(),
};
let result = builder.build_module(ast);
assert!(result.is_ok());
let module = result.unwrap();
let function = module.get_function("main").unwrap();
assert!(function.blocks.len() >= 3);
let stats = function.stats();
assert!(stats.phi_count >= 1);
}