4. JavaScript as an Embedded DSL
¨ authors
¤ Grzegorz Kossakowski, Nada Amin, Tiark
Rompf, and Martin Odersky
¨ published
¤ ECOOP 2012 – Object-‐‑‒Oriented
Programming, vol. 7313, p. 409-‐‑‒434
¨ abstract
¤ Javascriptを出⼒力力するScalaの内部DSLを作った。
¤ 「Lightweight Modular Staging」の応⽤用
5. Multi-Staging Programming(MSP)
¨ 段階に分けてコードを変換
¤ 例例:
記述性の⾼高いコード → 効率率率のよいコードに変換 → 実⾏行行
¨ コード⽣生成時をStaging, ⽣生成後をStagedという
¨ MSPの例例
¤ O. Kiselyov, K. N. Swadi, and W. Taha. A
methodology for generating verified combinatorial
circuits. In G. C. Buttazzo, editor, EMSOFT, pages
249–258. ACM, 2004.
¤ MetaOcamlを使⽤用したFFT(⾼高速フーリエ変換)
8. Expression Problem
¨ データ構造やその操作を追加した時に、下記
の条件すべてを満たせるか?
¤ Extensibility in both dimensions
(データ構造と操作の両⽅方の意)
¤ Strong static type safety
¤ No modification or duplication
¤ Separate compilation
¤ Independent extensibility(Scalaチームにより追加)
10. 主役はTrait
¨ それぞれの拡張をTraitにして分割
¨ JS traitはDSL内で何が使えるかの定義をまと
めたもの
¨ ノードの種類ごとにtraitが分割されている。
trait JS extends LiftNumeric with NumericOps with
OrderingOps with Equal with IfThenElse with
While with LiftBoolean with BooleanOps with
LiftString with StringOps with DynamicBase with
Arrays with Variables with JSFunctions with
JSLiteral
11. 構文木のノードを変換
構文木→JS
構文木のノードを変換
構文木→JS
Generator
Scala → JS 全体像
DSLの記述
DSL内で使える部品
(インターフェース)
部品の実装
(DSL→構文木)
Javascript
Generator
mix in
implement
mix in
mix in
DSL内で使える部品
(インターフェース)
部品の実装
(DSL→構文木)
部品の実装
(DSL→構文木)
DSL内で使える部品
(定義のみ)
構文木のノードを変換
構文木→JS
mix in
Trait
Instance
correspond
24. 参考文献
¨ Lightweight Modular Staging: A Pragmatic
Approach to Runtime Code Generation and
Compiled DSLs
by Tiark Rompf and Martin Odersky, EPFL
GPCE 2010, Eindhoven, The Netherlands,
October 2010
¨ A Gentle Introduction to Multi-‐‑‒stage
Programming
by Walid Taha
¨ Matthias Zenger, Martin Odersky,
Independently Extensible Solutions to the
Expression Problem, I&C Technical Report No.
200433, March 2004.