nyash

🐱 Nyash プログラミング言語

超真面目に作っている趣味言語
20日でゼロからネイティブバイナリへ - AI駆動の言語革命

🇺🇸 English Version / 英語版はこちら

Selfhost Minimal Core Smoke Everything is Box Performance JIT Ready ブラウザで試す MIT License


開発者向けクイックスタート: docs/DEV_QUICKSTART.md セルフホスト1枚ガイド: docs/self-hosting.md

目次

🧪 Self-Hosting(自己ホスト開発)

MIR注記: Core‑13 最小カーネルは既定で有効(NYASH_MIR_CORE13=1)。旧命令は正規化されます(Array/Ref→BoxCall、TypeCheck/Cast/Barrier/WeakRefの統一)。

純化モード: NYASH_MIR_CORE13_PURE=1 を有効にすると、Optimizer が Load/Store/NewBox/Unary を Core‑13 形に書き換え、残存する非Core‑13命令があればコンパイルを失敗させます。あえて実行が壊れる可能性がありますが、MIR違反を早期に発見するための設計です。

変更履歴(要点): CHANGELOG.md

🎮 今すぐブラウザでNyashを試そう!

👉 ブラウザプレイグラウンドを起動 👈

インストール不要 - ウェブブラウザで即座にNyashを体験!


🚀 速報: ネイティブEXE達成!

2025年8月29日 - 誕生からわずか20日で、Nyashがネイティブ実行ファイルへのコンパイルを実現!

# Nyashソースからネイティブバイナリへ(Craneliftが必要)
cargo build --release --features cranelift-jit
./tools/build_aot.sh program.nyash -o app         # ネイティブEXE
./app                                             # スタンドアロン実行!

20日間で達成したこと:


なぜNyashなのか?

🎯 Everything is Box 哲学

// 従来の言語は複雑な型システムを持つ
// Nyash: 一つの概念がすべてを支配する - Box

static box Main {
    main() {
        // すべての値はBox - 統一、安全、シンプル
        local name = new StringBox("Nyash")
        local count = new IntegerBox(42)
        local data = new MapBox()
        
        // PythonオブジェクトもBox!
        local py = new PyRuntimeBox()
        local math = py.import("math")
        print("sqrt(9) = " + math.getattr("sqrt").call(9).str())
        
        return 0
    }
}

前例のない開発速度

🔌 プラグインファースト・アーキテクチャ

// あらゆる機能がプラグインBoxになれる
local file = new FileBox()          // ファイルI/Oプラグイン
local http = new HttpClientBox()    // ネットワークプラグイン
local py = new PyRuntimeBox()       // Pythonプラグイン

// プラグインもネイティブコードにコンパイル!

🏗️ 複数の実行モード

重要: 現在、JIT ランタイム実行はデバッグ容易性のため封印しています。実行は「インタープリター/VM」、配布は「Cranelift AOT(EXE)/LLVM AOT(EXE)」の4体制です。

1. インタープリターモード (開発用)

./target/release/nyash program.nyash

2. VMモード (本番用)

./target/release/nyash --backend vm program.nyash

3. ネイティブバイナリ(Cranelift AOT) (配布用)

# 事前ビルド(Cranelift)
cargo build --release --features cranelift-jit

./tools/build_aot.sh program.nyash -o myapp
./myapp  # スタンドアロン実行!

4. ネイティブバイナリ(LLVM AOT)

LLVM_SYS_180_PREFIX=$(llvm-config-18 --prefix) \
  cargo build --release --features llvm
NYASH_LLVM_OBJ_OUT=$PWD/nyash_llvm_temp.o \
  ./target/release/nyash --backend llvm program.nyash
# リンクして実行
cc nyash_llvm_temp.o -L crates/nyrt/target/release -Wl,--whole-archive -lnyrt -Wl,--no-whole-archive -lpthread -ldl -lm -o myapp
./myapp

簡易スモークテスト(VM と EXE の出力一致確認):

tools/smoke_aot_vs_vm.sh examples/aot_min_string_len.nyash

LLVM バックエンドの補足

LLVM スモークテスト(クイックチェック)

5. WebAssembly (ブラウザ用)

cargo build --release --features wasm-backend
./target/release/nyash --compile-wasm program.nyash

🧰 タスク実行 (nyash.toml)

nyash.toml[tasks][env] で、ビルド/スモークなどのタスクを簡単に実行できます(MVP)。

例(nyash.toml の末尾に追記):

[env]
RUST_BACKTRACE = "1"

[tasks]
build_llvm = "LLVM_SYS_180_PREFIX=$(llvm-config-18 --prefix) cargo build --release --features llvm"
smoke_obj_array = "NYASH_LLVM_OBJ_OUT={root}/nyash_llvm_temp.o ./target/release/nyash --backend llvm apps/ny-llvm-smoke/main.nyash"

実行:

./target/release/nyash --run-task build_llvm
./target/release/nyash --run-task smoke_obj_array

補足:


🧰 一発ビルド(MVP): nyash --build

nyash.toml を読み、プラグイン → コア → AOT → リンクまでを一発実行する最小ビルド機能です。

基本(Cranelift AOT)

./target/release/nyash --build nyash.toml \
  --app apps/egui-hello-plugin/main.nyash \
  --out app_egui

主なオプション(最小)

注意

📊 パフォーマンスベンチマーク

実世界ベンチマーク結果 (ny_bench.nyash):

モード           | 時間      | 相対速度
----------------|-----------|---------------
インタープリター | 110.10ms  | 1.0x (基準)
VM              | 8.14ms    | 13.5倍高速
Cranelift AOT   | ~4–6ms    | ~20–27倍高速
ネイティブ(LLVM)| ~4ms      | ~27倍高速

🎮 言語機能

クリーンな構文

box GameCharacter {
    private { name, health, skills }
    
    // birthコンストラクタ - Boxに生命を与える!
    birth(characterName) {
        me.name = characterName
        me.health = 100
        me.skills = new ArrayBox()
        print("🌟 " + characterName + " が誕生しました!")
    }
    
    learnSkill(skill) {
        me.skills.push(skill)
        return me  // メソッドチェーン
    }
}

// 使用例
local hero = new GameCharacter("ネコ")
hero.learnSkill("火魔法").learnSkill("回復")

モダンなAsync/Await

// シンプルな並行処理
nowait task1 = fetchDataFromAPI()
nowait task2 = processLocalFiles()

// 待機中に他の作業
updateUI()

// 結果収集
local apiData = await task1
local files = await task2

デリゲーションパターン

// 継承よりコンポジション
box EnhancedArray from ArrayBox {
    private { logger }
    
    override push(item) {
        me.logger.log("追加中: " + item)
        from ArrayBox.push(item)  // 親に委譲
    }
}

🔌 プラグインシステム

Nyashは「Everything is Plugin」アーキテクチャを開拓:

# nyash.toml - プラグイン設定
[libraries."libnyash_python_plugin.so"]
boxes = ["PyRuntimeBox", "PyObjectBox"]

[libraries."libnyash_net_plugin.so"]  
boxes = ["HttpServerBox", "HttpClientBox", "WebSocketBox"]

C/Rustで独自のBox型を作成してシームレスに統合!


🛠️ はじめる

クイックインストール (Linux/Mac/WSL)

# クローンとビルド
git clone https://github.com/moe-charm/nyash.git
cd nyash
cargo build --release --features cranelift-jit

# 最初のプログラムを実行
echo 'print("Hello Nyash!")' > hello.nyash
./target/release/nyash hello.nyash

Windows

# Windows向けクロスコンパイル
cargo install cargo-xwin
cargo xwin build --target x86_64-pc-windows-msvc --release
# target/x86_64-pc-windows-msvc/release/nyash.exe を使用

# WindowsでのネイティブEXE(AOT)ビルド(Cranelift と MSYS2/WSL が必要)
cargo build --release --features cranelift-jit
powershell -ExecutionPolicy Bypass -File tools\build_aot.ps1 -Input examples\aot_min_string_len.nyash -Out app.exe
./app.exe

🌟 独自のイノベーション

1. AI駆動開発

2. Box-Firstアーキテクチャ

3. 観測可能な設計


📚

Python統合

// NyashからPythonライブラリを使用!
local py = new PyRuntimeBox()
local np = py.import("numpy")
local array = np.getattr("array").call([1, 2, 3])
print("NumPy配列: " + array.str())

Webサーバー

local server = new HttpServerBox()
server.start(8080)

loop(true) {
    local request = server.accept()
    local response = new HttpResponseBox()
    response.setStatus(200)
    response.write("Nyashからこんにちは!")
    request.respond(response)
}

ゲーム開発

box GameObject {
    public { x, y, sprite }
    
    update(deltaTime) {
        // 物理シミュレーション
        me.y = me.y + gravity * deltaTime
    }
    
    render(canvas) {
        canvas.drawImage(me.sprite, me.x, me.y)
    }
}

🤝 貢献

革命に参加しよう!以下を歓迎します:

詳細は AGENTS.md(Repository Guidelines)をご参照ください。プロジェクト構成、ビルド/テスト手順、PRの要件を簡潔にまとめています。

📄 ライセンス

MIT ライセンス - プロジェクトで自由に使用してください!


👨‍💻 作者

charmpic - 趣味で言語作ってる人


🎉 歴史的タイムライン

ゼロからネイティブバイナリまで20日間 - 言語開発の新記録!


🚀 Nyash - すべてがBoxであり、Boxがネイティブコードにコンパイルされる場所!

❤️、🤖 AIコラボレーション、そしてプログラミング言語は思考の速度で作れるという信念で構築