BuckleScript

BuckleScript

  • 資料
  • 試す
  • API
  • コミュニティ
  • ブログ
  • Languages icon日本語
    • English
    • Español
    • Français
    • 한국어
    • Português (Brasil)
    • Русский
    • 中文
    • 繁體中文
    • 翻訳に参加する
  • GitHub

›上級者向け

はじめに

  • はじめに
  • インストール
  • プロジェクトの作成
  • Try
  • コンセプト

相互運用

  • 概要
  • チートシート
  • 生のJavaScriptの埋め込み
  • 基本的なデータ型
  • Externalの紹介
  • グローバル変数の束縛
  • Null・UndefinedとOption
  • オブジェクト
  • オブジェクト その2
  • クラス
  • 関数
  • Property access
  • Return value wrapping
  • ImportとExport
  • 正規表現
  • 例外
  • JSON
  • Pipe First
  • 変換と補助の生成
  • より良いデータ構造の出力 (デバッグモード)
  • NodeJSの特殊な変数
  • その他
  • ブラウザのサポートとポリフィル

ビルドシステム

  • 概要
  • 設定
  • インターフェースの自動生成
  • Interop with Other Build System
  • パフォーマンス
  • 上級者向け

標準ライブラリ

  • 概要

上級者向け

  • 条件付きコンパイル
  • コンパイラ拡張の為のオプション
  • 既存のOCamlのライブラリの使用
  • ネイティブのOCamlとの違い
  • コンパイラの設計と原則
  • Js_of_ocamlとの比較
Translate

コンパイラの設計と原則

BuckleScript's high level architecture:

Source Language
  |
  | (Reuse OCaml Parser)
  v
Surface Syntax Tree
  |
  | (built in Syntax tree transformation)
  v
Surface Syntax Tree
  |
  | (Reuse OCaml Type checker)
  v
Typedtree
  |
  | (Reuse OCaml pattern match compiler and erase types)
  | (Patches to pass more information down to Lambda )
  |
OCaml Lambda IR
  |
  |
  v
Buckle Lambda IR ------------------+
  |   ^                            |
  |   |                     6 Lambda Passes (lam_* files)
  |   |             Optimization/inlining/dead code elimination
  |   \                            |
  |    \ --------------------------+
  |
  |  Self tail call elimination
  |  Constant folding + propagation
  V
JS IR (J.ml)  ---------------------+
  |   ^                            |
  |   |                     6 JS Passes (js_* files)
  |   |            Optimization/inlining/dead code elimination
  |   \                            |
  |    \  -------------------------+
  |
  |  Smart printer includes scope analysis
  |
  V
Javascript Code

Design Decisions

The design of BuckleScript follows several high-level principles. While those principles might change in the future, they are enforced today and can explain certain technical limitations BS has.

Lambda Representation

As pictured in the diagram above, BuckleScript is primarily based on the Lambda representation of the OCaml compiler. While this representation is quite rich, some information is lost from the upstream representation. The patch to the OCaml compiler tries to enrich this representation in a non-intrusive way (see next section).

Minimal Patch to the OCaml compiler

BuckleScript requires patches to the OCaml compiler. One of the main reasons is to enrich the Lambda representation so that the generated code is as nice as possible. A design goal is to keep those patches minimal and useful for the OCaml compiler in general so that they can later be integrated.

Note: a common question is to wonder why BuckleScript transpiles an OCaml record value to a JavaScript array while a more intuitive representation would be a JavaScript object. This technical decision is a direct consequence of the above 2 design principles: the Lambda layer assumes in a lot of places that a record value is an array and such modification would be too large of a change to OCaml compiler.

Soundness

BuckleScript preserves the soundness of the OCaml language. Assuming the FFI is correctly implemented, the type safety is preserved.

Minimal new symbol creation

In order to make the JavaScript generated code as close as possible to the original OCaml core we thrive to introduce as few new symbols as possible.

← ネイティブのOCamlとの違いJs_of_ocamlとの比較 →
  • Design Decisions
    • Lambda Representation
    • Minimal Patch to the OCaml compiler
    • Soundness
    • Minimal new symbol creation