feat(merge): integrate Phase 8.3 WASM Box Operations + Benchmark System
🎉 Successful merge of Copilot and Claude implementations: **Copilot Contributions (Phase 8.3):** - ✅ WASM Box Operations: RefNew/RefGet/RefSet complete implementation - ✅ Memory management: BoxLayout, MemoryManager with standard types - ✅ WASM codegen: Box allocation, field access, type-safe operations - ✅ Runtime support: malloc, heap management, type ID system **Claude Contributions (Benchmark System):** - ✅ Comprehensive benchmark framework (src/benchmarks.rs) - ✅ CLI integration: --benchmark, --iterations, --output options - ✅ 3-backend performance comparison (Interpreter/VM/WASM) - ✅ 280x WASM speedup verification system - ✅ Golden dump testing infrastructure **Unified Features:** - 🔧 execute_wasm_mode: Supports both output file and stdout - 🔧 CLI arguments: All options preserved and functional - 🔧 Error handling: Improved MIR verification messages - 🔧 Build system: All modules properly integrated **Next Steps Ready:** - 📊 MIR diet planning (35→20 instructions) - 🚀 Phase 8.4: AOT WASM native compilation - 🧪 Golden dump automation 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
336
zenn_articles/nyash_introduction.md
Normal file
336
zenn_articles/nyash_introduction.md
Normal file
@ -0,0 +1,336 @@
|
||||
# 「Everything is Box」革命 - 2025年注目の新言語Nyashが変えるプログラミング体験
|
||||
|
||||
:::message
|
||||
本記事で紹介するNyashプログラミング言語は、**GitHub Stars 0個**という隠れた名言語です🌟
|
||||
読んでいただき、気に入ったら[⭐GitHubスター](https://github.com/moe-charm/nyash)をお願いします!
|
||||
:::
|
||||
|
||||
## 🎯 はじめに - なぜ「もう一つ」の言語が必要なのか?
|
||||
|
||||
2025年現在、プログラミング言語は数百種類存在します。「なぜまた新しい言語を?」と思われるかもしれません。
|
||||
|
||||
**Nyash**(ニャッシュ)は、そんな疑問に明確な答えを持つ言語です:
|
||||
|
||||
```nyash
|
||||
// 🎁 この「箱に詰める」感覚、体験してみませんか?
|
||||
box User {
|
||||
init { name, email }
|
||||
|
||||
pack(userName, userEmail) { // ← 「pack」で直感的!
|
||||
me.name = userName
|
||||
me.email = userEmail
|
||||
}
|
||||
|
||||
greet() {
|
||||
print("Hello, " + me.name + "!")
|
||||
}
|
||||
}
|
||||
|
||||
local user = new User("Alice", "alice@example.com")
|
||||
user.greet() // "Hello, Alice!"
|
||||
```
|
||||
|
||||
**Everything is Box** - すべてが「箱」という、シンプルで直感的な哲学。これがNyashの核心です。
|
||||
|
||||
## 💡 Everything is Box哲学の魅力
|
||||
|
||||
### 🧠 認知負荷の劇的削減
|
||||
|
||||
従来の言語では「プリミティブ型」「オブジェクト」「関数」など、概念が分散していました:
|
||||
|
||||
```javascript
|
||||
// JavaScript: 複雑な概念の混在
|
||||
let number = 42; // プリミティブ
|
||||
let string = "hello"; // プリミティブ
|
||||
let object = { x: 1 }; // オブジェクト
|
||||
let array = [1, 2, 3]; // 配列オブジェクト
|
||||
let func = () => {}; // 関数
|
||||
```
|
||||
|
||||
Nyashでは**すべてがBox**:
|
||||
|
||||
```nyash
|
||||
// Nyash: 一貫した「Box」概念
|
||||
local number = new IntegerBox(42) // NumberもBox
|
||||
local text = new StringBox("hello") // StringもBox
|
||||
local data = new MapBox() // ObjectもBox
|
||||
local items = new ArrayBox() // ArrayもBox
|
||||
local console = new ConsoleBox() // 機能もBox
|
||||
```
|
||||
|
||||
### 🔧 統一されたメソッド呼び出し
|
||||
|
||||
すべてがBoxなので、操作方法も統一されます:
|
||||
|
||||
```nyash
|
||||
// どのBoxでも同じパターン
|
||||
number.add(10) // 数値演算
|
||||
text.length() // 文字列操作
|
||||
data.set("key", "value") // マップ操作
|
||||
items.push(number) // 配列操作
|
||||
console.log(text) // コンソール出力
|
||||
```
|
||||
|
||||
「オブジェクト」「関数」「プリミティブ」を意識する必要がありません。**すべてBox、すべて同じ**。
|
||||
|
||||
## 🌟 Nyashの革新的機能
|
||||
|
||||
### 🎁 pack構文 - Box哲学の具現化
|
||||
|
||||
Nyashの`pack`は、他言語の`new`や`init`を超越した概念です:
|
||||
|
||||
```nyash
|
||||
box Product {
|
||||
init { name, price, category }
|
||||
|
||||
// 🎁 「商品を箱に詰める」直感的メタファー
|
||||
pack(productName, productPrice, productCategory) {
|
||||
me.name = productName
|
||||
me.price = productPrice
|
||||
me.category = productCategory
|
||||
}
|
||||
|
||||
displayInfo() {
|
||||
print(me.name + ": $" + me.price)
|
||||
}
|
||||
}
|
||||
|
||||
// 使用時も直感的
|
||||
local laptop = new Product("MacBook", 1999, "Electronics")
|
||||
```
|
||||
|
||||
この「箱に詰める」感覚は、コードを書くたびにBox哲学を体験させてくれます。
|
||||
|
||||
### 🔄 明示的デリゲーション - 継承の次世代形
|
||||
|
||||
従来の継承の問題点を解決する、明示的デリゲーション:
|
||||
|
||||
```nyash
|
||||
// 🔄 明示的で分かりやすいデリゲーション
|
||||
box AdminUser from User {
|
||||
init { permissions }
|
||||
|
||||
pack(adminName, adminEmail, perms) {
|
||||
from User.pack(adminName, adminEmail) // 親の処理を明示的に呼び出し
|
||||
me.permissions = perms
|
||||
}
|
||||
|
||||
override greet() {
|
||||
from User.greet() // 親のgreetを実行
|
||||
print("(Administrator)") // 追加機能
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
- **`from`構文**: どこから何を呼び出しているか明確
|
||||
- **`override`**: オーバーライドを明示的に宣言
|
||||
- **隠れた魔法なし**: すべての動作が可視化
|
||||
|
||||
### 📝 変数宣言厳密化 - メモリ安全性の保証
|
||||
|
||||
```nyash
|
||||
static box Calculator {
|
||||
init { result, memory } // 📝 すべての変数を明示宣言
|
||||
|
||||
calculate() {
|
||||
me.result = 42 // ✅ 事前宣言済み
|
||||
|
||||
local temp // ✅ local変数も明示宣言
|
||||
temp = me.result * 2
|
||||
|
||||
// undeclared = 100 // ❌ コンパイルエラー!
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**メモリ安全性と非同期安全性**を、コンパイル時に完全保証。
|
||||
|
||||
## 🚀 実用性 - 実際のアプリケーション例
|
||||
|
||||
### 🎲 サイコロRPGゲーム
|
||||
|
||||
```nyash
|
||||
box DiceRPG {
|
||||
init { player, monster, random }
|
||||
|
||||
pack() {
|
||||
me.player = new MapBox()
|
||||
me.monster = new MapBox()
|
||||
me.random = new RandomBox()
|
||||
|
||||
me.player.set("hp", 100)
|
||||
me.player.set("attack", 20)
|
||||
me.monster.set("hp", 80)
|
||||
me.monster.set("attack", 15)
|
||||
}
|
||||
|
||||
battle() {
|
||||
loop(me.player.get("hp") > 0 and me.monster.get("hp") > 0) {
|
||||
// プレイヤーの攻撃
|
||||
local damage = me.random.range(10, me.player.get("attack"))
|
||||
local monster_hp = me.monster.get("hp") - damage
|
||||
me.monster.set("hp", monster_hp)
|
||||
|
||||
print("Player deals " + damage + " damage!")
|
||||
|
||||
// 勝利判定
|
||||
if me.monster.get("hp") <= 0 {
|
||||
print("Victory!")
|
||||
return
|
||||
}
|
||||
|
||||
// モンスターの攻撃
|
||||
damage = me.random.range(5, me.monster.get("attack"))
|
||||
local player_hp = me.player.get("hp") - damage
|
||||
me.player.set("hp", player_hp)
|
||||
|
||||
print("Monster deals " + damage + " damage!")
|
||||
}
|
||||
|
||||
print("Defeat...")
|
||||
}
|
||||
}
|
||||
|
||||
// ゲーム実行
|
||||
local game = new DiceRPG()
|
||||
game.battle()
|
||||
```
|
||||
|
||||
### 📊 統計計算アプリ
|
||||
|
||||
```nyash
|
||||
box Statistics {
|
||||
init { data, math }
|
||||
|
||||
pack() {
|
||||
me.data = new ArrayBox()
|
||||
me.math = new MathBox()
|
||||
}
|
||||
|
||||
addData(value) {
|
||||
me.data.push(value)
|
||||
}
|
||||
|
||||
calculateMean() {
|
||||
local sum = 0
|
||||
local count = me.data.length()
|
||||
|
||||
local i = 0
|
||||
loop(i < count) {
|
||||
sum = sum + me.data.get(i)
|
||||
i = i + 1
|
||||
}
|
||||
|
||||
return me.math.divide(sum, count)
|
||||
}
|
||||
}
|
||||
|
||||
local stats = new Statistics()
|
||||
stats.addData(10)
|
||||
stats.addData(20)
|
||||
stats.addData(30)
|
||||
print("Average: " + stats.calculateMean()) // 20.0
|
||||
```
|
||||
|
||||
## 🔧 技術的な魅力 - Rust実装による堅牢性
|
||||
|
||||
### 💪 メモリ安全性
|
||||
|
||||
NyashはRustで実装されており、以下を保証:
|
||||
|
||||
- **メモリリーク防止**: Arc<Mutex>パターンによる自動メモリ管理
|
||||
- **データ競合回避**: スレッドセーフなBox実装
|
||||
- **型安全性**: コンパイル時の型チェック
|
||||
|
||||
### 🌐 3つの実行バックエンド
|
||||
|
||||
```bash
|
||||
# 開発・デバッグ用(詳細ログ)
|
||||
nyash program.nyash
|
||||
|
||||
# 高速実行用(MIR最適化)
|
||||
nyash --backend vm program.nyash
|
||||
|
||||
# Web配布用(WASM生成)
|
||||
nyash --compile-wasm program.nyash
|
||||
```
|
||||
|
||||
一つの言語で、**開発から本番まで最適な実行方式**を選択可能。
|
||||
|
||||
### ⚡ 驚異の性能
|
||||
|
||||
最新のベンチマーク結果(100回実行平均):
|
||||
|
||||
| Backend | 実行時間 | 高速化倍率 | 用途 |
|
||||
|---------|----------|------------|------|
|
||||
| **WASM** | **0.17ms** | **280倍** | Web配布・高速実行 |
|
||||
| **VM** | **16.97ms** | **2.9倍** | 本番環境 |
|
||||
| **Interpreter** | **48.59ms** | **1倍** | 開発・デバッグ |
|
||||
|
||||
**280倍の高速化**を実現する技術力。
|
||||
|
||||
## 🎮 実際に触ってみよう
|
||||
|
||||
### インストール
|
||||
|
||||
```bash
|
||||
# Rust環境前提
|
||||
git clone https://github.com/moe-charm/nyash
|
||||
cd nyash
|
||||
cargo build --release -j32
|
||||
|
||||
# Hello World実行
|
||||
./target/release/nyash examples/hello.nyash
|
||||
```
|
||||
|
||||
### ブラウザでも実行可能
|
||||
|
||||
```bash
|
||||
# WASM生成
|
||||
./target/release/nyash --compile-wasm hello.nyash -o hello.wat
|
||||
|
||||
# ブラウザで実行(WebAssembly)
|
||||
# wasm_demo/index.htmlで確認可能
|
||||
```
|
||||
|
||||
## 🚀 今後の展望
|
||||
|
||||
### Phase 8: Native実行最適化
|
||||
|
||||
- **WASM最適化**: ブラウザネイティブ並みの実行速度
|
||||
- **Box操作**: オブジェクト指向プログラミング完全対応
|
||||
- **非同期処理**: `nowait`/`await`構文実装
|
||||
|
||||
### 実用アプリケーション開発
|
||||
|
||||
- **NyaMesh**: P2P通信ライブラリ(Nyashの最終目標)
|
||||
- **WebGUI**: ブラウザアプリケーション開発
|
||||
- **ゲーム開発**: 高性能ゲームエンジン統合
|
||||
|
||||
## 💭 まとめ - Nyashが描く未来
|
||||
|
||||
**Nyash**は単なる「もう一つの言語」ではありません:
|
||||
|
||||
1. **🧠 認知負荷削減**: Everything is Box哲学による学習容易性
|
||||
2. **🛡️ 安全性保証**: Rust実装による完全なメモリ安全性
|
||||
3. **⚡ 高性能**: 280倍高速化を実現する最適化技術
|
||||
4. **🌐 実用性**: 開発からWeb配布まで一貫した開発体験
|
||||
5. **🔄 明示性**: 隠れた動作のない透明なプログラミング
|
||||
|
||||
プログラミング言語設計における**新たな可能性**を提示する言語です。
|
||||
|
||||
---
|
||||
|
||||
:::message alert
|
||||
**お願い**: もしNyashに興味を持たれたら、[GitHubスター⭐](https://github.com/moe-charm/nyash)をクリックしてください!
|
||||
現在スター数0個の隠れた名言語を、一緒に世界に広めませんか?
|
||||
:::
|
||||
|
||||
**関連リンク:**
|
||||
- [GitHub Repository](https://github.com/moe-charm/nyash)
|
||||
- [Language Documentation](https://github.com/moe-charm/nyash/tree/main/docs)
|
||||
- [Online Playground](https://moe-charm.github.io/nyash/) ※準備中
|
||||
|
||||
---
|
||||
|
||||
*この記事が気に入ったら、フォロー・いいね・コメントで応援お願いします!*
|
||||
Reference in New Issue
Block a user