Skip to content

Latest commit

 

History

5,343 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NEPLg2.1 - Neknaj Expression Prefix Language General-purpose 2

WebAssembly WASI Prefix Off--side

現在の NEPL は NEPLg2.1 です。

NEPLg2.1 は、式指向、前置記法、オフサイドルールを中核にした WebAssembly / WASI / LLVM 向け言語です。ブロックは : とインデントで表し、値式、型式、関数型、関数リテラル、制御構文を同じ前置記法の考え方で扱います。

NEPLg3 は完全に検討段階で未着手です。doc/neplg3/stdlib/neplg3/ に検討資料や置き場があっても、現行仕様、現行実装、または進行中の self-host 実装として扱いません。

すぐ触る

NEPLg2.1 の構文

NEPLg2.1 では、構文を「値だけが前置」ではなく、型や関数境界まで含めて前置記法に揃えます。

  • 値式は add a bprintln textgrade score のように、関数名を先頭に置きます。
  • 型注釈は %T expr です。let n %i32 40 は「40i32 として検査する」という期待型境界であり、実行時の値を増やしません。
  • 型式も前置です。Vec i32Result i32 strfn i32 fn i32 i32impure fn void unit のように書きます。
  • unit は unit 型かつ unit 値です。0 引数関数の marker は void で、fn void unit\void にだけ使います。
  • 関数型はカリー化に似た見た目ですが、NEPLg2.1 は部分適用を導入しません。add 1 は暗黙の関数値にならず、必要な引数が揃わない呼び出しとして扱われます。
  • ifmatchblock なども式です。ブロックは最後の式を値として返し、不要な値は ; で明示的に捨てます。
  • 正規構文では呼び出し側の explicit generic postfix を使いません。必要な型情報は % 型注釈、引数、戻り値期待型、trait / generic 解決から得ます。

簡単な例:

#entry main
#indent 4
#target std

#import "core/math" as *
#import "std/stdio" as *

fn grade %fn i32 str \score:
    if ge score 90:
        "A"
        else:
            if ge score 70:
                "B"
                else:
                    "C"

fn main %impure fn void unit \void:
    let score %i32 85
    let label %str grade score
    println label

詳しくは NEPLg2.1 surface syntax migration planzero-argument function marker void を参照してください。

現在の実装

このリポジトリの実体は、NEPLg2.1 を基準にした Rust 製コンパイラ、CLI、Web Playground、標準ライブラリ、エディタ向け解析 API、GUI/TUI substrate、NEPLg2.1 self-host 実装です。

nepl-core/        Rust 製コンパイラ core。lexer / parser / typecheck / Resource IR / Wasm / LLVM。
nepl-cli/         CLI。check、run、emit、stdlib root、test mode などを提供する。
nepl-web/         wasm-bindgen 向け compiler API。Web Playground から使う。
nepl-language/    エディタ / LSP 向け共通解析 API。
nepl-lsp/         LSP server。diagnostics、hover、definition、semantic tokens など。
nepl-gui-native/  native GUI smoke runner。minifb は optional feature。
web/              Web Playground frontend。
nodesrc/          doctest、HTML生成、source policy、Playground検証ツール。
stdlib/           NEPLg2.1 標準ライブラリと self-host compiler source。
tests/            compiler / stdlib regression。
examples/         CLI、GUI、TUI寄りの実行サンプル。

標準ライブラリ

stdlib/ は現行 NEPLg2.1 の標準ライブラリです。依存方向は coreallocstdplatforms を基本に分けています。

stdlib/
    core/        allocation や host API に依存しない基本型、trait、math、Option / Result、GUI core。
    alloc/       Vec、String、collections、GUI app / layout / widget など allocation を使う層。
    std/         stdio、streamio、fs、env、timer、GUI host など host 依存の標準 API。
    platforms/   WASI / WASIX / GUI web / GUI terminal など platform backend。
    features/    feature facade。
    nm/          Neknaj Markdown 関連。
    kp/          競技プログラミング向け構造と helper。
    neplg2/      NEPLg2.1 self-host compiler source。
    tests/       stdlib doctest / regression。

よく使う module:

module 内容
core/math i32 算術・比較の基本 API
core/option / core/result Option / Resultmatch 前提の失敗表現
std/stdio print / println / println_i32 など
std/streamio 高速入力や writer を含む stream I/O
std/test doctest / regression 用 assertion
alloc/collections/vec 可変長配列
core/gui / alloc/gui / std/gui GUI/TUI 共通 substrate
platforms/gui/web Web Playground GUI backend

GUI / TUI

GUI と TUI は別々の巨大 framework ではなく、共通の UI substrate として実装しています。

基本方針:

State + Event -> State + Effects
State -> ViewTree
ViewTree + LayoutContext -> LayoutTree
LayoutTree + RenderContext -> DrawCommand stream
DrawCommand stream -> RenderTarget / DrawTarget / Host backend

現在の主な実装:

  • stdlib/core/gui: geometry、color、event、capability、error、draw / render command の基礎。
  • stdlib/alloc/gui: app model、view tree、layout、widget、theme、routing、focus、diff。
  • stdlib/std/gui: runtime、host、window、timer、IME、text measurement、error display。
  • stdlib/platforms/gui/web: Web Playground 向け stdout frame protocol と input bridge。
  • stdlib/platforms/gui/terminal: TUI を GUI substrate の terminal backend として再設計する入口。
  • examples/gui_*.nepl: Counter、Life、Mandelbrot、calculator、scientific calculator、paint、breakout。
  • nepl-gui-native: native 側の最小 runner と platform behavior 検証。

仕様と実装計画は GUI/TUI 標準ライブラリ仕様GUI/TUI 実装計画 を参照してください。

Web Playground とエディタ解析

Web Playground は web/ にあり、Trunk と TypeScript で構成されています。compiler は nepl-web を wasm-bindgen で呼び出します。

現在の editor / language support は、TypeScript の推測だけではなく Rust 側の解析結果を使います。

  • nepl-language は native editor / LSP 向けに lex、parse、name resolution、semantic analysis を提供します。
  • nepl-web は Web Playground 向けに同等の analysis / compile API を wasm から公開します。
  • nepl-lsp は diagnostics、hover、definition、semantic tokens、inlay hints を返します。
  • syntax highlighting は compiler-provided token classification、prefix expression range、%T type range、path namespace分類を使います。

関連文書:

Self-Host

現在進めている self-host は NEPLg2.1 self-host です。場所は stdlib/neplg2/ で、正規の設計入口は NEPLg2.1 セルフホストコンパイラ設計 です。

この self-host 実装は、NEPLg2.1 の % 型注釈、prefix 型式、\ 関数リテラル、void marker、#test、Resource IR 静的検査、compiler artifact、compile-time performance 改良を基準にします。

NEPLg3 self-host は未着手です。NEPLg3 の資料は現行 NEPLg2.1 実装の authority ではありません。

ビルドとテスト

Rust workspace:

cargo build --workspace --locked
cargo test --workspace --locked

CLI:

cargo run -p nepl-cli -- --check --input examples/helloworld.nepl --target std
cargo run -p nepl-cli -- --run --input examples/helloworld.nepl --target std
cargo run -p nepl-cli -- --input examples/helloworld.nepl --output tmp/helloworld --emit wasm,wat-min --target std

Web / Playground:

npm --prefix web run build:ts
trunk build
node nodesrc/cli.js -i tests/playground_editor --playground-editor-tests -o json=tmp/playground-editor-tests.json

Doctest / source policy:

node nodesrc/tests.js -i examples --no-tree -o tmp/examples-tests.json -j 4
node nodesrc/tests.js -i tests/stdlib -i stdlib/tests --no-tree -o tmp/stdlib-tests.json -j 4
node nodesrc/run_source_policy_regressions.js --warn-only
node nodesrc/issues.js check --dir issues
git diff --check

詳しくは CLITesting and doctest workflow を参照してください。なお、一部の古い文書には過去または将来検討用の前提説明が残っている場合があります。現行 NEPLg2.1 の構文 authority は doc/neplg2/ の NEPLg2.1 文書です。

ドキュメント

ドキュメント 内容
doc/README.md ドキュメント全体の入口
doc/neplg2/neplg21_syntax_migration_plan.md NEPLg2.1 構文の authority
doc/neplg2/zero_arg_void_marker_spec.md void marker と unit の分離
doc/neplg2/self_host_neplg21_compiler_design.md NEPLg2.1 self-host compiler 設計
doc/neplg2/gui_standard_library_spec.md GUI/TUI 標準ライブラリ仕様
doc/neplg2/gui_tui_implementation_plan.md GUI/TUI 実装計画
doc/web_playground.md Web Playground
doc/lsp_api.md エディタ / LSP 解析 API
doc/testing.md テストワークフロー
doc/cli.md CLI

About

Prefix + off-side rule language targeting WebAssembly. Everything is prefix; blocks use : + indentation; almost everything is an expression. Entirely designed and supervised by Bem130

Topics

Resources

Stars

3 stars

Watchers

0 watching

Forks

Contributors

Languages