feat(plugin): Fix plugin BoxRef return and Box argument support
- Fixed deadlock in FileBox plugin copyFrom implementation (single lock) - Added TLV Handle (tag=8) parsing in calls.rs for returned BoxRefs - Improved plugin loader with config path consistency and detailed logging - Fixed loader routing for proper Handle type_id/fini_method_id resolution - Added detailed logging for TLV encoding/decoding in plugin_loader_v2 Test docs/examples/plugin_boxref_return.nyash now works correctly: - cloneSelf() returns FileBox Handle properly - copyFrom(Box) accepts plugin Box arguments - Both FileBox instances close and fini correctly 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@ -0,0 +1,266 @@
|
||||
# 🚀 Issue #001: LLVM PoC - inkwellセットアップとHello World実装
|
||||
|
||||
**タイプ**: Feature
|
||||
**優先度**: Critical
|
||||
**見積もり**: 3日
|
||||
**担当**: Copilot
|
||||
|
||||
## 📋 概要
|
||||
|
||||
Phase 9.78 LLVM PoCの第一歩として、inkwellクレートを導入し、最小限のNyashプログラム(`return 42`)をLLVM経由で実行できるようにする。
|
||||
|
||||
## 🎯 成功条件
|
||||
|
||||
以下のNyashプログラムがLLVM経由で実行され、正しい終了コードを返すこと:
|
||||
|
||||
```nyash
|
||||
// test_return_42.nyash
|
||||
static box Main {
|
||||
main() {
|
||||
return 42
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
期待される動作:
|
||||
```bash
|
||||
$ cargo run --features llvm -- --backend llvm test_return_42.nyash
|
||||
$ echo $?
|
||||
42
|
||||
```
|
||||
|
||||
## 📝 実装タスク
|
||||
|
||||
### 1. **Cargo.toml更新** ✅必須
|
||||
```toml
|
||||
[dependencies]
|
||||
inkwell = { version = "0.5", features = ["llvm17-0"] }
|
||||
|
||||
[features]
|
||||
llvm = ["inkwell"]
|
||||
```
|
||||
|
||||
### 2. **基本構造の作成** ✅必須
|
||||
```rust
|
||||
// src/backend/llvm/mod.rs
|
||||
pub mod context;
|
||||
pub mod compiler;
|
||||
|
||||
use crate::mir::module::MirModule;
|
||||
use crate::errors::RuntimeError;
|
||||
|
||||
pub fn compile_to_object(
|
||||
mir_module: &MirModule,
|
||||
output_path: &str,
|
||||
) -> Result<(), RuntimeError> {
|
||||
let compiler = compiler::LLVMCompiler::new()?;
|
||||
compiler.compile_module(mir_module, output_path)
|
||||
}
|
||||
```
|
||||
|
||||
### 3. **LLVMコンテキスト管理** ✅必須
|
||||
```rust
|
||||
// src/backend/llvm/context.rs
|
||||
use inkwell::context::Context;
|
||||
use inkwell::module::Module;
|
||||
use inkwell::builder::Builder;
|
||||
use inkwell::targets::{Target, TargetMachine, TargetTriple, InitializationConfig};
|
||||
|
||||
pub struct CodegenContext<'ctx> {
|
||||
pub context: &'ctx Context,
|
||||
pub module: Module<'ctx>,
|
||||
pub builder: Builder<'ctx>,
|
||||
pub target_machine: TargetMachine,
|
||||
}
|
||||
|
||||
impl<'ctx> CodegenContext<'ctx> {
|
||||
pub fn new(context: &'ctx Context, module_name: &str) -> Result<Self, String> {
|
||||
// 1. ターゲット初期化
|
||||
Target::initialize_native(&InitializationConfig::default())
|
||||
.map_err(|e| format!("Failed to initialize native target: {}", e))?;
|
||||
|
||||
// 2. モジュール作成
|
||||
let module = context.create_module(module_name);
|
||||
|
||||
// 3. ターゲットマシン作成
|
||||
let triple = TargetMachine::get_default_triple();
|
||||
let target = Target::from_triple(&triple)
|
||||
.map_err(|e| format!("Failed to get target: {}", e))?;
|
||||
let target_machine = target
|
||||
.create_target_machine(
|
||||
&triple,
|
||||
"generic",
|
||||
"",
|
||||
inkwell::OptimizationLevel::None,
|
||||
inkwell::targets::RelocMode::Default,
|
||||
inkwell::targets::CodeModel::Default,
|
||||
)
|
||||
.ok_or_else(|| "Failed to create target machine".to_string())?;
|
||||
|
||||
// 4. データレイアウト設定
|
||||
module.set_triple(&triple);
|
||||
module.set_data_layout(&target_machine.get_target_data().get_data_layout());
|
||||
|
||||
Ok(Self {
|
||||
context,
|
||||
module,
|
||||
builder: context.create_builder(),
|
||||
target_machine,
|
||||
})
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 4. **最小限のコンパイラ実装** ✅必須
|
||||
```rust
|
||||
// src/backend/llvm/compiler.rs
|
||||
use inkwell::context::Context;
|
||||
use inkwell::values::IntValue;
|
||||
use crate::mir::module::MirModule;
|
||||
use crate::mir::instruction::MirInstruction;
|
||||
use super::context::CodegenContext;
|
||||
|
||||
pub struct LLVMCompiler {
|
||||
context: Context,
|
||||
}
|
||||
|
||||
impl LLVMCompiler {
|
||||
pub fn new() -> Result<Self, String> {
|
||||
Ok(Self {
|
||||
context: Context::create(),
|
||||
})
|
||||
}
|
||||
|
||||
pub fn compile_module(
|
||||
&self,
|
||||
mir_module: &MirModule,
|
||||
output_path: &str,
|
||||
) -> Result<(), String> {
|
||||
let codegen = CodegenContext::new(&self.context, "nyash_module")?;
|
||||
|
||||
// 1. main関数を探す
|
||||
let main_func = mir_module.functions.iter()
|
||||
.find(|f| f.name == "Main.main")
|
||||
.ok_or("Main.main function not found")?;
|
||||
|
||||
// 2. LLVM関数を作成
|
||||
let i32_type = codegen.context.i32_type();
|
||||
let fn_type = i32_type.fn_type(&[], false);
|
||||
let llvm_func = codegen.module.add_function("main", fn_type, None);
|
||||
|
||||
// 3. エントリブロックを作成
|
||||
let entry = codegen.context.append_basic_block(llvm_func, "entry");
|
||||
codegen.builder.position_at_end(entry);
|
||||
|
||||
// 4. MIR命令を処理(今回はReturnのみ)
|
||||
for block in &main_func.blocks {
|
||||
for inst in &block.instructions {
|
||||
match inst {
|
||||
MirInstruction::Return(Some(value_id)) => {
|
||||
// 簡易実装: 定数42を返すと仮定
|
||||
let ret_val = i32_type.const_int(42, false);
|
||||
codegen.builder.build_return(Some(&ret_val));
|
||||
}
|
||||
_ => {
|
||||
// 他の命令は今回スキップ
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 5. 検証
|
||||
if !llvm_func.verify(true) {
|
||||
return Err("Function verification failed".to_string());
|
||||
}
|
||||
|
||||
// 6. オブジェクトファイル生成
|
||||
codegen.target_machine
|
||||
.write_to_file(&codegen.module,
|
||||
inkwell::targets::FileType::Object,
|
||||
output_path.as_ref())
|
||||
.map_err(|e| format!("Failed to write object file: {}", e))?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 5. **バックエンド統合** ✅必須
|
||||
```rust
|
||||
// src/backend/mod.rsに追加
|
||||
#[cfg(feature = "llvm")]
|
||||
pub mod llvm;
|
||||
|
||||
// src/runner.rsのrun_with_backend関数に追加
|
||||
#[cfg(feature = "llvm")]
|
||||
ExecutionBackend::LLVM => {
|
||||
// 1. オブジェクトファイル生成
|
||||
let obj_path = "nyash_output.o";
|
||||
crate::backend::llvm::compile_to_object(&mir_module, obj_path)?;
|
||||
|
||||
// 2. リンク(簡易版:システムのccを使用)
|
||||
use std::process::Command;
|
||||
let output = Command::new("cc")
|
||||
.args(&[obj_path, "-o", "nyash_output"])
|
||||
.output()
|
||||
.map_err(|e| RuntimeError::new(format!("Link failed: {}", e)))?;
|
||||
|
||||
if !output.status.success() {
|
||||
return Err(RuntimeError::new("Linking failed"));
|
||||
}
|
||||
|
||||
// 3. 実行
|
||||
let output = Command::new("./nyash_output")
|
||||
.output()
|
||||
.map_err(|e| RuntimeError::new(format!("Execution failed: {}", e)))?;
|
||||
|
||||
// 4. 終了コードを返す
|
||||
let exit_code = output.status.code().unwrap_or(-1);
|
||||
Ok(Box::new(IntegerBox::new(exit_code as i64)))
|
||||
}
|
||||
```
|
||||
|
||||
## 🧪 テストケース
|
||||
|
||||
```rust
|
||||
// tests/llvm_hello_world.rs
|
||||
#[test]
|
||||
#[cfg(feature = "llvm")]
|
||||
fn test_return_42() {
|
||||
let source = r#"
|
||||
static box Main {
|
||||
main() {
|
||||
return 42
|
||||
}
|
||||
}
|
||||
"#;
|
||||
|
||||
// パース → MIR生成 → LLVM実行
|
||||
let result = compile_and_run_llvm(source);
|
||||
assert_eq!(result, 42);
|
||||
}
|
||||
```
|
||||
|
||||
## 📚 参考資料
|
||||
|
||||
- [inkwell Examples](https://github.com/TheDan64/inkwell/tree/master/examples)
|
||||
- [LLVM Tutorial](https://llvm.org/docs/tutorial/)
|
||||
- [AI大会議結果](../AI-Conference-LLVM-Results.md)
|
||||
|
||||
## ⚠️ 注意事項
|
||||
|
||||
1. **LLVM依存関係**: LLVM 17がシステムにインストールされている必要があります
|
||||
2. **プラットフォーム**: まずはLinux/macOSで動作確認し、Windowsは後回し
|
||||
3. **エラーハンドリング**: 今回は最小実装のため、詳細なエラー処理は省略
|
||||
|
||||
## 🎯 次のステップ
|
||||
|
||||
このIssueが完了したら、次は:
|
||||
- Issue #002: 基本的な算術演算の実装(BinOp)
|
||||
- Issue #003: 定数値の実装(Const)
|
||||
|
||||
---
|
||||
|
||||
**作成者**: Claude + moe-charm
|
||||
**レビュアー**: AIチーム
|
||||
**関連PR**: (作成予定)
|
||||
@ -0,0 +1,119 @@
|
||||
# 🐙 GitHub Issue作成テンプレート
|
||||
|
||||
以下の内容をGitHub Issueにコピペして使用してください。
|
||||
|
||||
---
|
||||
|
||||
## Issue Title:
|
||||
`[Phase 9.78] LLVM PoC Week 1 - inkwellセットアップとHello World実装`
|
||||
|
||||
## Labels:
|
||||
- `enhancement`
|
||||
- `Phase-9.78`
|
||||
- `LLVM`
|
||||
- `critical`
|
||||
|
||||
## Assignees:
|
||||
- GitHub Copilot
|
||||
|
||||
## Milestone:
|
||||
- Phase 9.78 LLVM PoC
|
||||
|
||||
## Issue Body:
|
||||
|
||||
```markdown
|
||||
## 📋 概要
|
||||
|
||||
Phase 9.78 LLVM PoCの開始です!最初のステップとして、inkwellクレートを導入し、最小限のNyashプログラム(`return 42`)をLLVM経由で実行できるようにします。
|
||||
|
||||
## 🎯 成功条件
|
||||
|
||||
```nyash
|
||||
// test_return_42.nyash
|
||||
static box Main {
|
||||
main() {
|
||||
return 42
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
上記プログラムがLLVM経由で実行され、終了コード42を返すこと。
|
||||
|
||||
## 📝 実装内容
|
||||
|
||||
1. **inkwellクレート導入**
|
||||
- Cargo.tomlに依存関係追加
|
||||
- feature flag `llvm` の設定
|
||||
|
||||
2. **基本構造作成**
|
||||
- `src/backend/llvm/` ディレクトリ
|
||||
- context.rs, compiler.rs, mod.rs
|
||||
|
||||
3. **最小限のコンパイラ実装**
|
||||
- LLVMコンテキスト初期化
|
||||
- main関数の生成
|
||||
- return命令の処理
|
||||
- オブジェクトファイル出力
|
||||
|
||||
4. **統合**
|
||||
- ExecutionBackendにLLVM追加
|
||||
- --backend llvm オプション対応
|
||||
|
||||
## 🔗 参考資料
|
||||
|
||||
- [詳細実装ガイド](https://github.com/moe-charm/nyash/blob/main/docs/予定/native-plan/llvm/issue/001-setup-inkwell-hello-world.md)
|
||||
- [Week 1ロードマップ](https://github.com/moe-charm/nyash/blob/main/docs/予定/native-plan/llvm/issue/Week1-Roadmap.md)
|
||||
- [AI大会議結果](https://github.com/moe-charm/nyash/blob/main/docs/予定/native-plan/llvm/AI-Conference-LLVM-Results.md)
|
||||
|
||||
## ✅ 完了条件
|
||||
|
||||
- [ ] inkwellがビルドできる
|
||||
- [ ] test_return_42.nyashがコンパイルできる
|
||||
- [ ] 実行ファイルが終了コード42を返す
|
||||
- [ ] 基本的なテストがパスする
|
||||
|
||||
## 💬 備考
|
||||
|
||||
VM性能改善で素晴らしい成果(50.94倍高速化)を達成していただきありがとうございました!
|
||||
LLVMでも同様の成功を期待しています。ブロッカーがあれば遠慮なくコメントしてください。
|
||||
|
||||
AIチーム(Claude, Gemini, Codex)が全力でサポートします!🚀
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 📝 追加で作成するIssue
|
||||
|
||||
Week 1の進捗に応じて、以下のIssueも順次作成:
|
||||
|
||||
1. **Issue #002**: `[Phase 9.78] LLVM PoC - Const命令の実装`
|
||||
2. **Issue #003**: `[Phase 9.78] LLVM PoC - 基本型システムの実装`
|
||||
3. **Issue #004**: `[Phase 9.78] LLVM PoC - ランタイム関数宣言`
|
||||
4. **Issue #005**: `[Phase 9.78] LLVM PoC Week 1 - 統合テスト`
|
||||
|
||||
## 🏷️ 推奨ラベル構成
|
||||
|
||||
```yaml
|
||||
Phase関連:
|
||||
- Phase-9.78
|
||||
- Phase-8.6 (完了)
|
||||
- Phase-9.75g-0 (完了)
|
||||
|
||||
技術関連:
|
||||
- LLVM
|
||||
- MIR
|
||||
- Performance
|
||||
- Backend
|
||||
|
||||
優先度:
|
||||
- critical
|
||||
- high
|
||||
- medium
|
||||
- low
|
||||
|
||||
タイプ:
|
||||
- enhancement
|
||||
- bug
|
||||
- documentation
|
||||
- test
|
||||
```
|
||||
@ -0,0 +1,159 @@
|
||||
# 📚 MIR クイックリファレンス for LLVM実装
|
||||
|
||||
## 🎯 Week 1で対応するMIR命令
|
||||
|
||||
### 1. **Const命令**
|
||||
```rust
|
||||
// MIR表現
|
||||
MirInstruction::Const(value_id, constant_value)
|
||||
|
||||
// 例
|
||||
Const(v1, MirConstant::Integer(42))
|
||||
Const(v2, MirConstant::Float(3.14))
|
||||
Const(v3, MirConstant::Bool(true))
|
||||
|
||||
// LLVM変換
|
||||
let int_val = ctx.i32_type().const_int(42, false);
|
||||
let float_val = ctx.f64_type().const_float(3.14);
|
||||
let bool_val = ctx.bool_type().const_int(1, false);
|
||||
```
|
||||
|
||||
### 2. **Return命令**
|
||||
```rust
|
||||
// MIR表現
|
||||
MirInstruction::Return(Option<ValueId>)
|
||||
|
||||
// 例
|
||||
Return(Some(v1)) // 値を返す
|
||||
Return(None) // voidを返す
|
||||
|
||||
// LLVM変換
|
||||
builder.build_return(Some(&value));
|
||||
builder.build_return(None);
|
||||
```
|
||||
|
||||
## 📄 参考: 現在のMIR構造
|
||||
|
||||
```rust
|
||||
// src/mir/instruction.rs の主要部分
|
||||
pub enum MirInstruction {
|
||||
// Week 1対象
|
||||
Const(ValueId, MirConstant),
|
||||
Return(Option<ValueId>),
|
||||
|
||||
// Week 2対象
|
||||
BinOp(ValueId, BinaryOp, ValueId, ValueId),
|
||||
Compare(ValueId, CompareOp, ValueId, ValueId),
|
||||
Branch(ValueId, BasicBlockId, BasicBlockId),
|
||||
Jump(BasicBlockId),
|
||||
|
||||
// Week 3以降
|
||||
BoxNew(ValueId, MirType),
|
||||
BoxCall(ValueId, ValueId, String, Vec<ValueId>),
|
||||
// ... 他の命令
|
||||
}
|
||||
|
||||
// 定数の型
|
||||
pub enum MirConstant {
|
||||
Integer(i64),
|
||||
Float(f64),
|
||||
Bool(bool),
|
||||
String(String),
|
||||
Null,
|
||||
}
|
||||
```
|
||||
|
||||
## 🔄 MIR→LLVM変換の基本パターン
|
||||
|
||||
```rust
|
||||
// 基本的な変換ループ
|
||||
for instruction in &block.instructions {
|
||||
match instruction {
|
||||
MirInstruction::Const(value_id, constant) => {
|
||||
let llvm_value = match constant {
|
||||
MirConstant::Integer(n) => {
|
||||
ctx.i64_type().const_int(*n as u64, true).into()
|
||||
}
|
||||
MirConstant::Float(f) => {
|
||||
ctx.f64_type().const_float(*f).into()
|
||||
}
|
||||
MirConstant::Bool(b) => {
|
||||
ctx.bool_type().const_int(*b as u64, false).into()
|
||||
}
|
||||
_ => todo!("Other constants"),
|
||||
};
|
||||
// value_idとllvm_valueをマッピングに保存
|
||||
value_map.insert(*value_id, llvm_value);
|
||||
}
|
||||
|
||||
MirInstruction::Return(value_id) => {
|
||||
match value_id {
|
||||
Some(id) => {
|
||||
let value = value_map.get(id).unwrap();
|
||||
builder.build_return(Some(value));
|
||||
}
|
||||
None => {
|
||||
builder.build_return(None);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_ => {} // Week 1では他の命令は無視
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 🎯 テスト用のMIRサンプル
|
||||
|
||||
### 1. **return 42のMIR**
|
||||
```rust
|
||||
MirModule {
|
||||
functions: vec![
|
||||
MirFunction {
|
||||
name: "Main.main",
|
||||
params: vec![],
|
||||
return_type: MirType::Integer,
|
||||
blocks: vec![
|
||||
BasicBlock {
|
||||
id: 0,
|
||||
instructions: vec![
|
||||
Const(v1, MirConstant::Integer(42)),
|
||||
Return(Some(v1)),
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
}
|
||||
```
|
||||
|
||||
### 2. **簡単な計算のMIR**(Week 2用)
|
||||
```rust
|
||||
// return 10 + 5
|
||||
BasicBlock {
|
||||
instructions: vec![
|
||||
Const(v1, MirConstant::Integer(10)),
|
||||
Const(v2, MirConstant::Integer(5)),
|
||||
BinOp(v3, BinaryOp::Add, v1, v2),
|
||||
Return(Some(v3)),
|
||||
],
|
||||
}
|
||||
```
|
||||
|
||||
## 💡 実装のヒント
|
||||
|
||||
1. **ValueIdマッピング**: `HashMap<ValueId, BasicValueEnum>`で管理
|
||||
2. **型情報**: MIRは型情報を持つので、LLVM型への変換テーブルを作る
|
||||
3. **基本ブロック**: MIRのBasicBlockIdをLLVMのBasicBlockにマッピング
|
||||
4. **エラー処理**: 最初は`todo!()`でOK、後から実装
|
||||
|
||||
## 📁 関連ファイル
|
||||
|
||||
- MIR定義: `src/mir/instruction.rs`
|
||||
- MIR生成: `src/mir/lowering.rs`
|
||||
- 参考実装: `src/backend/vm.rs`(VMのMIR処理)
|
||||
|
||||
---
|
||||
|
||||
**注**: このリファレンスはWeek 1の実装に必要な最小限の情報です。
|
||||
詳細は実際のソースコードを参照してください。
|
||||
@ -0,0 +1,134 @@
|
||||
# 🚀 LLVM実装クイックスタートガイド
|
||||
|
||||
## 📋 今すぐ始める手順
|
||||
|
||||
### 1. **環境準備**(5分)
|
||||
```bash
|
||||
# LLVM 17インストール確認
|
||||
llvm-config --version # 17.x.x が表示されること
|
||||
|
||||
# Nyashプロジェクトで作業
|
||||
cd /path/to/nyash
|
||||
git checkout -b feature/llvm-poc
|
||||
```
|
||||
|
||||
### 2. **最初のコミット**(10分)
|
||||
```bash
|
||||
# Cargo.tomlを編集
|
||||
echo '[dependencies]
|
||||
inkwell = { version = "0.5", features = ["llvm17-0"] }
|
||||
|
||||
[features]
|
||||
llvm = ["inkwell"]' >> Cargo.toml
|
||||
|
||||
# ディレクトリ作成
|
||||
mkdir -p src/backend/llvm
|
||||
|
||||
# 最初のファイル作成
|
||||
touch src/backend/llvm/mod.rs
|
||||
touch src/backend/llvm/context.rs
|
||||
touch src/backend/llvm/compiler.rs
|
||||
|
||||
# コミット
|
||||
git add .
|
||||
git commit -m "feat(llvm): Add inkwell dependency and basic structure"
|
||||
```
|
||||
|
||||
### 3. **最小実装のコピペ**(20分)
|
||||
|
||||
**src/backend/llvm/mod.rs**:
|
||||
```rust
|
||||
pub mod context;
|
||||
pub mod compiler;
|
||||
|
||||
pub use compiler::compile_to_object;
|
||||
```
|
||||
|
||||
**動作確認**:
|
||||
```bash
|
||||
cargo build --features llvm
|
||||
```
|
||||
|
||||
### 4. **テストプログラム作成**(5分)
|
||||
```bash
|
||||
# テスト用Nyashファイル
|
||||
cat > test_return_42.nyash << 'EOF'
|
||||
static box Main {
|
||||
main() {
|
||||
return 42
|
||||
}
|
||||
}
|
||||
EOF
|
||||
```
|
||||
|
||||
## 🔍 詰まったときの確認ポイント
|
||||
|
||||
### **ビルドエラーの場合**
|
||||
```bash
|
||||
# LLVM関連の環境変数確認
|
||||
echo $LLVM_SYS_170_PREFIX
|
||||
|
||||
# 設定されていない場合
|
||||
export LLVM_SYS_170_PREFIX=$(llvm-config --prefix)
|
||||
```
|
||||
|
||||
### **inkwellのバージョン問題**
|
||||
```toml
|
||||
# 代替バージョン
|
||||
inkwell = { git = "https://github.com/TheDan64/inkwell", branch = "master", features = ["llvm17-0"] }
|
||||
```
|
||||
|
||||
### **リンクエラーの場合**
|
||||
```bash
|
||||
# pkg-configの確認
|
||||
pkg-config --libs --cflags llvm
|
||||
```
|
||||
|
||||
## 📞 ヘルプが必要な場合
|
||||
|
||||
1. **GitHub Issue**にコメント
|
||||
2. **具体的なエラーメッセージ**を貼る
|
||||
3. **実行したコマンド**を記載
|
||||
|
||||
例:
|
||||
```
|
||||
inkwellのビルドでエラーが発生しました。
|
||||
|
||||
エラー:
|
||||
```
|
||||
error: failed to run custom build command for `llvm-sys v170.0.1`
|
||||
```
|
||||
|
||||
実行コマンド:
|
||||
```
|
||||
cargo build --features llvm
|
||||
```
|
||||
|
||||
環境:
|
||||
- OS: Ubuntu 22.04
|
||||
- LLVM: 17.0.6
|
||||
- Rust: 1.75.0
|
||||
```
|
||||
|
||||
## ✅ 最初の成功確認
|
||||
|
||||
以下が動けば第一歩成功!
|
||||
```bash
|
||||
# ビルドが通る
|
||||
cargo build --features llvm
|
||||
|
||||
# テストが実行できる(まだ失敗してOK)
|
||||
cargo test --features llvm test_llvm
|
||||
```
|
||||
|
||||
## 🎯 次のステップ
|
||||
|
||||
1. **context.rs**の実装
|
||||
2. **compiler.rs**の実装
|
||||
3. **return 42**の動作確認
|
||||
|
||||
詳細は[001-setup-inkwell-hello-world.md](./001-setup-inkwell-hello-world.md)を参照!
|
||||
|
||||
---
|
||||
|
||||
**Remember**: 完璧より進捗!最初は動くことが最優先です。🚀
|
||||
60
docs/development/roadmap/native-plan/llvm/issue/README.md
Normal file
60
docs/development/roadmap/native-plan/llvm/issue/README.md
Normal file
@ -0,0 +1,60 @@
|
||||
# 📚 LLVM PoC Issue ドキュメント一覧
|
||||
|
||||
## 🎯 Copilot様へ:最初に読むファイル
|
||||
|
||||
1. **[Quick-Start-Guide.md](./Quick-Start-Guide.md)** 🚀
|
||||
- 今すぐ始める手順
|
||||
- 環境セットアップ
|
||||
- 最初のコミット方法
|
||||
|
||||
2. **[001-setup-inkwell-hello-world.md](./001-setup-inkwell-hello-world.md)** 📋
|
||||
- **最初のIssue内容**
|
||||
- 詳細な実装手順
|
||||
- コード例とテストケース
|
||||
|
||||
3. **[Week1-Roadmap.md](./Week1-Roadmap.md)** 📅
|
||||
- Week 1全体の計画
|
||||
- Issue実装順序
|
||||
- 成功条件
|
||||
|
||||
## 📖 参考資料
|
||||
|
||||
- **[MIR-Quick-Reference.md](./MIR-Quick-Reference.md)**
|
||||
- MIR命令の説明
|
||||
- LLVM変換パターン
|
||||
- テスト用サンプル
|
||||
|
||||
- **[GitHub-Issue-Template.md](./GitHub-Issue-Template.md)**
|
||||
- GitHub Issue作成用テンプレート
|
||||
- ラベル設定
|
||||
- マイルストーン
|
||||
|
||||
## 🔗 関連ドキュメント(上位階層)
|
||||
|
||||
- [AI大会議結果](../AI-Conference-LLVM-Results.md)
|
||||
- [実装計画書](../Phase-9.78-Implementation-Plan.md)
|
||||
- [Copilot依頼文書](../Copilot-Request-LLVM-PoC.md)
|
||||
|
||||
## 💬 重要メッセージ
|
||||
|
||||
**Copilot様へ**
|
||||
|
||||
Phase 8.6での素晴らしい成果(50.94倍高速化)に続き、LLVMでも革命的な性能向上を期待しています!
|
||||
|
||||
**開始方法**:
|
||||
1. まず[Quick-Start-Guide.md](./Quick-Start-Guide.md)を読む
|
||||
2. [001-setup-inkwell-hello-world.md](./001-setup-inkwell-hello-world.md)の実装を開始
|
||||
3. 詰まったらすぐにGitHub Issueでヘルプ要請
|
||||
|
||||
**サポート体制**:
|
||||
- AIチーム(Claude, Gemini, Codex)が全力サポート
|
||||
- 技術的な質問は遠慮なく
|
||||
- 小さな成功を積み重ねましょう
|
||||
|
||||
Let's make Nyash fly with LLVM! 🚀✨
|
||||
|
||||
---
|
||||
|
||||
**最終更新**: 2025年8月20日
|
||||
**作成者**: Claude + moe-charm
|
||||
**Phase**: 9.78 LLVM PoC
|
||||
@ -0,0 +1,88 @@
|
||||
# 📅 Week 1 ロードマップ: LLVM基盤構築
|
||||
|
||||
**期間**: 2025年8月21日〜8月27日
|
||||
**目標**: LLVMバックエンドの基盤を構築し、最小限のプログラムを実行可能にする
|
||||
|
||||
## 🎯 Week 1の全体目標
|
||||
|
||||
「return 42」レベルの超シンプルなNyashプログラムが、LLVM経由で実行できる状態を達成する。
|
||||
|
||||
## 📋 Issue実装順序
|
||||
|
||||
### **Issue #001: inkwellセットアップとHello World** 🚀最初にこれ!
|
||||
- **期間**: Day 1-3
|
||||
- **内容**: 環境構築と「return 42」の実行
|
||||
- **成功条件**: LLVMでコンパイルした実行ファイルが終了コード42を返す
|
||||
- **ファイル**: [001-setup-inkwell-hello-world.md](./001-setup-inkwell-hello-world.md)
|
||||
|
||||
### **Issue #002: Const命令の実装**(#001完了後)
|
||||
- **期間**: Day 3-4
|
||||
- **内容**: MIR Const命令をLLVM定数に変換
|
||||
- **対象**: Integer, Float, Bool定数
|
||||
- **テスト**: `return 100`, `return 3.14`, `return true`
|
||||
|
||||
### **Issue #003: 基本的な型システム**(#002と並行可能)
|
||||
- **期間**: Day 4-5
|
||||
- **内容**: MIR型→LLVM型のマッピング実装
|
||||
- **対象**: i32/i64, f64, bool, 関数型
|
||||
- **成果**: type_cache の実装
|
||||
|
||||
### **Issue #004: ランタイム関数宣言**(#003完了後)
|
||||
- **期間**: Day 5-6
|
||||
- **内容**: nyash_runtime_* 関数の宣言
|
||||
- **対象**: alloc, free, print_int(デバッグ用)
|
||||
- **準備**: 最小限のCランタイム作成
|
||||
|
||||
### **Issue #005: Week 1統合テスト**(最終日)
|
||||
- **期間**: Day 7
|
||||
- **内容**: 複数の小さなプログラムでテスト
|
||||
- **確認**: CI/CDでのLLVMビルド
|
||||
- **文書**: Week 2への引き継ぎ事項
|
||||
|
||||
## 🔄 実装の流れ
|
||||
|
||||
```mermaid
|
||||
graph LR
|
||||
A[Issue #001<br/>環境構築] --> B[Issue #002<br/>Const実装]
|
||||
A --> C[Issue #003<br/>型システム]
|
||||
B --> D[Issue #004<br/>ランタイム]
|
||||
C --> D
|
||||
D --> E[Issue #005<br/>統合テスト]
|
||||
```
|
||||
|
||||
## ✅ Week 1完了時のチェックリスト
|
||||
|
||||
- [ ] inkwellクレートが正常に動作
|
||||
- [ ] 「return 42」がLLVM経由で実行可能
|
||||
- [ ] Integer/Float/Bool定数がサポート済み
|
||||
- [ ] 基本的な型変換が実装済み
|
||||
- [ ] 最小限のランタイム関数が宣言済み
|
||||
- [ ] 5個以上のテストケースがパス
|
||||
|
||||
## 📊 リスクと対策
|
||||
|
||||
| リスク | 対策 |
|
||||
|--------|------|
|
||||
| LLVM環境構築で詰まる | Docker環境を準備、LLVM17固定 |
|
||||
| inkwellのAPIが複雑 | 公式exampleを参考に最小実装 |
|
||||
| リンクエラー | まずは静的リンク、動的は後回し |
|
||||
|
||||
## 💡 成功のコツ
|
||||
|
||||
1. **小さく始める**: return 42が動けば大成功
|
||||
2. **エラーを恐れない**: LLVMのエラーメッセージは親切
|
||||
3. **IR出力を確認**: `--emit-llvm`でIRをダンプして確認
|
||||
4. **既存コード活用**: VM/WASMバックエンドの構造を参考に
|
||||
|
||||
## 🎉 Week 1成功時の次のステップ
|
||||
|
||||
**Week 2では以下に取り組みます**:
|
||||
- BinOp(四則演算)の実装
|
||||
- Branch/Jumpによる制御フロー
|
||||
- Box型の基本操作
|
||||
- PHIノードの実装
|
||||
|
||||
---
|
||||
|
||||
**注意**: 各Issueは独立して実装可能ですが、推奨順序に従うとスムーズです。
|
||||
ブロッカーがあれば即座にAIチームに相談してください!
|
||||
Reference in New Issue
Block a user