Files
hakorune/docs/papers/active/paper-b-nyash-execution-model/chapters/01-introduction.md
Moe Charm e2e25f6615 論文フォルダ整理: ChatGPT5提案による2本立て構造に再編成
- 論文A: MIR13命令とIR設計 (コンパイラ・PL実装者向け)
  - ArrayGet/Set → BoxCall統合による50%削減
  - IC/AOT/TypedArray最適化
  - Everything is Box哲学のMIR実装

- 論文B: Nyash言語と実行モデル (言語理論・分散システム向け)
  - init/fini対称性メモリ管理
  - P2P Intentモデル
  - 多層実行アーキテクチャ(Interpreter→VM→JIT→AOT→WASM)

既存のmir15-fullstack/unified-lifecycleはarchiveに移動
2025-09-03 03:06:24 +09:00

3.8 KiB

Chapter 1: Introduction

Beyond Objects and Functions

What if we could design a programming language where every computational entity—from integers to GUI windows, from network sockets to distributed nodes—shared a single, unified abstraction? Not objects with inheritance hierarchies. Not functions with monadic transformations. Just Boxes.

This is Nyash: a language built on the radical premise that "Everything is Box."

The Box Philosophy

In traditional languages, we juggle multiple abstractions:

  • Objects for encapsulation and inheritance
  • Functions for computation and composition
  • Primitives for efficiency
  • Pointers for indirection
  • Interfaces for polymorphism
  • Modules for organization

Each abstraction brings its own rules, limitations, and cognitive overhead. Nyash replaces this complexity with a single, powerful concept: the Box.

// Everything is truly a Box
local num = 42              // IntegerBox
local str = "Hello"         // StringBox  
local arr = [1, 2, 3]       // ArrayBox
local gui = new EguiBox()   // GUI window is a Box
local peer = new P2PBox()   // Network node is a Box

// And they all work the same way
num.toString()              // "42"
gui.toString()              // "EguiBox{title: 'App'}"
peer.toString()             // "P2PBox{id: 'node1'}"

Three Revolutionary Concepts

1. Symmetric Memory Management (init/fini)

Nyash introduces perfect symmetry between construction and destruction:

box DatabaseConnection {
    init { handle, cache }
    
    birth(connectionString) {
        me.handle = NativeDB.connect(connectionString)
        me.cache = new MapBox()
        print("Connected to database")
    }
    
    fini() {
        me.handle.close()
        print("Disconnected from database")
    }
}

Every birth has its fini. Resources are never leaked. Yet this deterministic model coexists with optional garbage collection—developers choose their memory model per-Box.

2. P2P Intent Communication

Traditional message passing asks "what method to call." Nyash asks "what do you intend to achieve":

box ChatNode from P2PBox {
    onIntent(intent, data, sender) {
        switch intent {
            "chat": me.displayMessage(data.text, sender)
            "file": me.receiveFile(data.content, sender)
            "presence": me.updateStatus(data.status, sender)
        }
    }
}

// Usage is natural
chatNode.send("alice", "chat", {text: "Hello!"})

This intent-based model naturally extends from local method calls to distributed communication without changing the programming model.

3. Transparent Multi-Tier Execution

The same Nyash code runs across five execution tiers:

  1. Interpreter: Instant start, perfect debugging
  2. VM: 10x faster, same semantics
  3. JIT: Near-native speed for hot paths
  4. AOT: Deploy as standalone executables
  5. WASM: Run in browsers and edge computing

Developers write once. The execution tier is a deployment choice, not a language limitation.

Real-World Validation

This isn't theoretical. We've built:

  • NyashCoin: A P2P cryptocurrency in 200 lines
  • Plugin Marketplace: Dynamic code loading with security
  • Cross-platform GUI Apps: Same code on Linux/Windows/Web
  • Distributed Games: Real-time multiplayer with P2P intents

Each demonstrates that simplicity and power are not opposing forces—they're complementary aspects of good design.

Paper Organization

  • Chapter 2: The Box model and Everything is Box philosophy
  • Chapter 3: Symmetric memory management with init/fini
  • Chapter 4: P2P Intent model for distributed programming
  • Chapter 5: Multi-tier execution architecture
  • Chapter 6: Case studies and applications
  • Chapter 7: Evaluation and performance analysis
  • Chapter 8: Related work and comparisons
  • Chapter 9: Conclusion and future directions