Files
hakorune/docs/spec/include_export.md
Moe Charm c13d9c045e 📚 Phase 12: Nyashスクリプトプラグインシステム設計と埋め込みVM構想
## 主な成果
- Nyashスクリプトでプラグイン作成可能という革命的発見
- C ABI制約の分析と埋め込みVMによる解決策
- MIR/VM/JIT層での箱引数サポートの詳細分析

## ドキュメント作成
- Phase 12基本構想(README.md)
- Gemini/Codex先生の技術分析
- C ABIとの整合性問題と解決策
- 埋め込みVM実装ロードマップ
- 箱引数サポートの技術詳細

## 重要な洞察
- 制約は「リンク時にC ABI必要」のみ
- 埋め込みVMでMIRバイトコード実行により解決可能
- Nyashスクリプト→C ABIプラグイン変換が実現可能

Everything is Box → Everything is Plugin → Everything is Possible!
2025-08-30 22:52:16 +09:00

2.0 KiB
Raw Blame History

Nyash Include/Export Specification (Phase 1)

Overview

  • Goal: Simple, box-first module system for code split and reuse.
  • Principle: One file exports one module (Box). include(path) returns that Box.

Syntax

  • Include expression: local Math = include "lib/math.nyash" local r = Math.add(1, 2)

Rules

  • One static box per file: The included file must define exactly one static box. Zero or multiple is an error.
  • Expression form: include(...) is an expression that evaluates to the included modules Box instance.
  • Caching: The same file is evaluated at most once per run (subsequent includes return the cached module).
  • Path resolution:
    • Relative: include("./x.nyash") resolves relative to the current project root.
    • Roots (nyash.toml): [include.roots] std = "./stdlib" lib = "./lib" Then include("std/string") -> ./stdlib/string.nyash, include("lib/utils") -> ./lib/utils.nyash
    • Extension/index: If extension is omitted, .nyash is appended. If the path is a directory, index.nyash is used.

Backends

  • Interpreter: include is executed at runtime (implemented via execute_include_expr). Returns the Box instance.
  • VM/AOT: include is handled by the MIR builder by reading and parsing the target file and lowering its static box into the same MIR module (no new MIR op added). The include expression lowers into a new Box() for the included static box type.
  • No new MIR instruction was added; existing instructions (Const/NewBox/BoxCall/etc.) are used.

Limitations (Phase 1)

  • Cycles: Circular includes are not yet reported with a dedicated error path. A follow-up change will add active-load tracking and a clear error message with the cycle path.
  • Export box: Reserved for Phase 2. For now, the single static box in the file is the public API.

Examples

  • See examples/include_math.nyash and examples/include_main.nyash.

Rationale

  • Keeps MIR spec stable and relies on build-time module linking for VM/AOT.
  • Aligns with Everything-is-Box: modules are Boxes; methods/fields are the API.