Files
hakorune/docs/予定/nyash.link/master-architecture.md
Moe Charm ef7a0de3b0 feat: Prepare for code modularization and cleanup
- Archive old documentation and test files to `docs/archive/` and `local_tests/`.
- Remove various temporary and old files from the project root.
- Add `nekocode-rust` analysis tool and its output files (`nekocode/`, `.nekocode_sessions/`, `analysis.json`).
- Minor updates to `apps/chip8_nyash/chip8_emulator.nyash` and `local_tests` files.

This commit cleans up the repository and sets the stage for further code modularization efforts, particularly in the `src/interpreter` and `src/parser` modules, based on recent analysis.
2025-08-16 01:30:39 +09:00

15 KiB
Raw Blame History

なんでもAPI計画最終統合アーキテクチャ

🌟 革命的ビジョンの実現

📊 統合設計完了状況

  • nyash.link基盤: 依存関係管理システム設計完了
  • FFI-ABI統合: BID×MIR×バックエンド統合設計完了
  • usingシステム: 3種類API統一インポート設計完了
  • 実世界例: ゲーム・データサイエンス・Web・システムプログラミング実証
  • 🎯 最終統合: 全システム統合による革命的開発体験実現

🚀 完成後の開発体験

# === たった一つの構文ですべてが使える ===
using nyashstd        # 組み込み標準ライブラリ
using browser_api     # ブラウザAPICanvas, DOM, WebAudio...
using system_api      # システムAPIlibc, filesystem, network...
using ml_api          # 機械学習TensorFlow, PyTorch, OpenCV...
using game_api        # ゲーム開発SDL, OpenGL, Vulkan...
using mylib          # 自作Nyashモジュール

# 全部同じ記法・同じパフォーマンス・同じエラーハンドリング!
string.upper("hello")                        # 組み込み標準
browser.canvas.fillRect("game", 10, 10, 100, 100, "red")  # ブラウザAPI
system.file.read("/etc/passwd")              # システムAPI
ml.opencv.loadImage("photo.jpg")             # 機械学習API
game.sdl.createWindow("Game", 800, 600)      # ゲームAPI
mylib.processData("input")                   # 自作モジュール

🏗️ 最終統合アーキテクチャ

1. 全体システム構成

┌─────────────────┐    ┌─────────────────┐    ┌─────────────────┐
│   Nyash Code    │    │   nyash.link    │    │  BID Files      │
│                 │    │                 │    │                 │
│ using browser_api│    │ [dependencies]  │    │ browser_api:    │
│ using system_api │───▶│ browser_api =   │───▶│   canvas.yaml   │
│ using mylib     │    │   {bid=...}     │    │   dom.yaml      │
│ canvas.fillRect │    │ system_api =    │    │ system_api:     │
│ file.read       │    │   {bid=...}     │    │   libc.yaml     │
│ mylib.process   │    │ mylib = {path}  │    │   filesystem.yaml│
└─────────────────┘    └─────────────────┘    └─────────────────┘
         │                        │                        │
         └────────────────────────┼────────────────────────┘
                                  ▼
         ┌─────────────────────────────────────────────────────────┐
         │        UniversalNamespaceRegistry                       │
         │  ┌─────────────┐ ┌─────────────┐ ┌─────────────────┐   │
         │  │BuiltinStdlib│ │BidDefinition│ │ExternalModules  │   │
         │  │             │ │             │ │                 │   │
         │  │nyashstd.*   │ │browser_api.*│ │mylib.*          │   │
         │  │string.upper │ │canvas.fill* │ │custom functions │   │
         │  │math.sin     │ │dom.events   │ │                 │   │
         │  │array.length │ │system.file* │ │                 │   │
         │  └─────────────┘ └─────────────┘ └─────────────────┘   │
         └─────────────────────────────────────────────────────────┘
                                  │
                                  ▼
         ┌─────────────────────────────────────────────────────────┐
         │                MIR Generation                           │
         │  ┌─────────────┐ ┌─────────────┐ ┌─────────────────┐   │
         │  │BuiltinCall  │ │ExternCall   │ │ModuleCall       │   │
         │  │             │ │             │ │                 │   │
         │  │string.upper │ │canvas.fill* │ │mylib.process    │   │
         │  │effect:pure  │ │effect:io    │ │effect:io        │   │
         │  │optimize:yes │ │gpu_accel:yes│ │                 │   │
         │  └─────────────┘ └─────────────┘ └─────────────────┘   │
         └─────────────────────────────────────────────────────────┘
                                  │
                                  ▼
         ┌─────────────────────────────────────────────────────────┐
         │            Backend Execution                            │
         │  ┌─────────────┐ ┌─────────────┐ ┌─────────────────┐   │
         │  │     VM      │ │    WASM     │ │      AOT        │   │
         │  │             │ │             │ │                 │   │
         │  │Native Impl  │ │RuntimeImport│ │LLVM ExternFunc  │   │
         │  │Stub Calls   │ │Auto-generated│ │Native Libraries │   │
         │  │             │ │from BID     │ │                 │   │
         │  └─────────────┘ └─────────────┘ └─────────────────┘   │
         └─────────────────────────────────────────────────────────┘

2. nyash.link統合仕様最終版

# nyash.link - 全API統一管理設定
[project]
name = "ultimate-nyash-app"
version = "2.0.0"
description = "Everything is accessible through unified APIs"
license = "MIT"

[dependencies]
# === 組み込み標準ライブラリ ===
nyashstd = { builtin = true }

# === ブラウザ・Web API ===
browser_api = { 
    bid = ["./apis/canvas.yaml", "./apis/dom.yaml", "./apis/webaudio.yaml"],
    target_environments = ["browser"]
}
webgl_api = { 
    bid = "./apis/webgl.yaml",
    target_environments = ["browser"]
}

# === システム・OS API ===
system_api = { 
    bid = ["./apis/libc.yaml", "./apis/filesystem.yaml", "./apis/network.yaml"],
    library = "system",
    target_environments = ["linux", "macos", "windows"]
}
posix_api = {
    bid = "./apis/posix.yaml",
    library = "system",
    target_environments = ["linux", "macos"]
}

# === 機械学習・データサイエンス ===
ml_api = {
    bid = ["./apis/opencv.yaml", "./apis/numpy.yaml"],
    library = ["./libs/opencv.so", "./libs/numpy.so"],
    target_environments = ["linux", "macos"]
}
tensorflow_api = {
    bid = "./apis/tensorflow.yaml",
    library = "./libs/tensorflow.so",
    optional = true  # 環境によってオプション
}

# === ゲーム開発 ===
game_api = {
    bid = ["./apis/sdl.yaml", "./apis/opengl.yaml"],
    library = ["SDL2", "OpenGL"],
    target_environments = ["linux", "macos", "windows"]
}

# === データベース ===
database_api = {
    bid = ["./apis/sqlite.yaml", "./apis/postgresql.yaml"],
    library = ["sqlite3", "pq"],
}

# === ネットワーク・Web ===
http_api = {
    bid = "./apis/http_client.yaml",
    library = "curl"
}

# === Nyashモジュール従来通り ===
mylib = { path = "./src/mylib.nyash" }
utils = { path = "./src/utils/" }
models = { path = "./src/models.nyash" }

# === 将来の外部パッケージ ===
awesome_lib = { 
    version = "^1.2.0", 
    registry = "nyash-pkg",
    bid = "auto"  # パッケージレジストリから自動取得
}

[build]
entry_point = "./src/main.nyash"
backends = ["vm", "wasm", "aot"]
optimization_level = "release"

[targets]
browser = ["browser_api", "webgl_api"]
desktop = ["system_api", "game_api", "ml_api"]
server = ["system_api", "database_api", "http_api"]

[optimization]
# MIRレベル最適化設定
enable_effect_optimization = true
enable_batch_optimization = true  # FFI-ABI呼び出しバッチ化
enable_gpu_acceleration = true
cache_bid_compilation = true

3. BIDエコシステム標準API集

nyash-std-apis/           # 標準APIライブラリ
├── browser/
│   ├── canvas.yaml       # Canvas API
│   ├── dom.yaml          # DOM API  
│   ├── webaudio.yaml     # Web Audio API
│   ├── webgl.yaml        # WebGL API
│   └── fetch.yaml        # Fetch API
├── system/
│   ├── libc.yaml         # C標準ライブラリ
│   ├── filesystem.yaml   # ファイルシステム
│   ├── network.yaml      # ネットワーク
│   ├── process.yaml      # プロセス管理
│   └── threads.yaml      # スレッド・並行処理
├── ml/
│   ├── opencv.yaml       # コンピューターヴィジョン
│   ├── numpy.yaml        # 数値計算
│   ├── tensorflow.yaml   # 機械学習
│   └── pytorch.yaml      # 深層学習
├── game/
│   ├── sdl.yaml          # SDL2ライブラリ
│   ├── opengl.yaml       # OpenGL API
│   ├── vulkan.yaml       # Vulkan API
│   └── physics.yaml      # 物理エンジン
├── database/
│   ├── sqlite.yaml       # SQLite
│   ├── postgresql.yaml   # PostgreSQL
│   ├── mysql.yaml        # MySQL
│   └── redis.yaml        # Redis
└── crypto/
    ├── openssl.yaml      # OpenSSL
    ├── libsodium.yaml    # libsodium
    └── bcrypt.yaml       # bcrypt

🚀 段階的実装戦略(現実的ロードマップ)

Phase 0: 基盤構築2-3週間

// 🎯 最小実装目標
// using nyashstd → 動作

実装内容

  1. USINGトークナイザー - TokenType::USING追加
  2. 基本パーサー - using nyashstd構文解析
  3. BuiltinStdlib基盤 - 組み込み標準ライブラリ
  4. 基本string関数 - upper, lower, split, join

テスト

using nyashstd
assert(string.upper("hello") == "HELLO")

Phase 1: BID基盤4-6週間

// 🎯 外部API基盤目標  
// using console_api → 動作VM Stub

実装内容

  1. BID読み込み - YAML解析・検証システム
  2. UniversalNamespaceRegistry - 統合名前空間管理
  3. MIR ExternCall統合 - BID→MIR変換
  4. VM Stub実装 - console.log等の基本スタブ

テスト

using nyashstd
using console_api
string.upper("test")
console.log("BID integration works!")

Phase 2: WASM統合6-8週間

// 🎯 WASM動作目標
// ブラウザでCanvas API動作

実装内容

  1. WASM RuntimeImports自動生成 - BID→WASM import
  2. 文字列マーシャリング - UTF-8 (ptr,len)対応
  3. Canvas API完全実装 - fillRect, fillText等
  4. ブラウザテスト環境 - HTML/JS統合

テスト

using browser_api
canvas.fillRect("game-canvas", 10, 10, 100, 100, "red")

Phase 3: システムAPI統合8-12週間

// 🎯 ネイティブライブラリ動作目標
// ファイルI/O, システムコール等

実装内容

  1. AOTバックエンド統合 - LLVM IR外部関数
  2. システムライブラリ連携 - libc, filesystem等
  3. エラーハンドリング統合 - 統一エラーモデル
  4. パフォーマンス最適化 - バッチ処理・GPU加速

テスト

using system_api
local content = file.read("/etc/passwd")
file.write("./output.txt", content)

Phase 4: 完全エコシステム12-16週間

// 🎯 実用的アプリケーション開発
// ゲーム・ML・Webアプリ等

実装内容

  1. 標準APIライブラリ - nyash-std-apis完成
  2. パッケージレジストリ - BID共有システム
  3. IDE Language Server - 統合補完・エラー検出
  4. 最適化エンジン - Effect System活用

実用例

# 本格的なゲーム開発
using game_api
using audio_api
game.sdl.createWindow("My Game", 1024, 768)
audio.mixer.playMusic("bgm.ogg")

📊 既存実装との整合性

Phase 9.75eとの関係

Phase 9.75e (既存計画)          なんでもAPI計画 (新設計)
      ↓                              ↓
namespace構文                    using統一構文
依存関係システム          →      nyash.link統合管理
外部ファイル読み込み          →      BID統合システム
                                    ↓
                             完全統合アーキテクチャ

既存MIR/バックエンドとの統合

  • MIR ExternCall: 既存実装活用
  • WASM RuntimeImports: 既存基盤拡張
  • VM Backend: 既存スタブシステム活用
  • 🔧 統合課題: usingシステムとの橋渡し

🌟 長期ビジョンNyashの未来

2025年目標

  • Phase 0-1完了: 基盤・BID統合
  • 実用アプリ: シンプルなブラウザゲーム・ツール
  • コミュニティ: 開発者コミュニティ形成

2026年目標

  • Phase 2-3完了: WASM・システムAPI統合
  • 本格アプリ: ゲーム・データサイエンス・Webアプリ
  • エコシステム: BIDライブラリエコシステム

2027年目標

  • Phase 4完了: 完全エコシステム
  • 産業利用: 企業での実用的活用
  • 言語標準化: BID標準の業界採用

🎯 即座に開始すべき実装

今日のアクション

  1. src/stdlib/mod.rs作成 - 組み込み標準ライブラリ基盤
  2. TokenType::USING追加 - トークナイザー拡張
  3. Phase 0実装開始 - using nyashstd基本動作

今週のアクション

  1. BuiltinStdlib::new()実装 - string関数4種
  2. 基本テスト作成 - using動作確認
  3. Phase 1設計 - BID統合詳細設計

来週のアクション

  1. BID読み込み基盤 - YAML解析システム
  2. UniversalNamespaceRegistry - 統合名前空間管理
  3. console.log実装 - 最初のBID統合テスト

🎉 この最終統合アーキテクチャにより、Nyashが真に「なんでもできる」革命的プログラミング言語になるにゃ

🚀 今すぐPhase 0実装を開始して、プログラミング言語の未来を創造しよう🐱