Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Scala製インタプリタをブラウザで動かす3分クッキング
Search
Rikito Taniguchi
September 09, 2017
Technology
230
1
Share
Scala製インタプリタをブラウザで動かす3分クッキング
Rikito Taniguchi
September 09, 2017
More Decks by Rikito Taniguchi
See All by Rikito Taniguchi
GC言語のWasm化とComponent Modelサポートの実践と課題 - Scalaの場合
tanishiking
0
130
Capture Checking / Separation Checking 入門
tanishiking
0
500
Implementing and Evaluating a High-Level Language with WasmGC and the Wasm Component Model: Scala’s Case
tanishiking
0
670
Scala meets WebAssembly
tanishiking
0
910
Why Wasm+WASI for Scala
tanishiking
0
130
Scala to WebAssembly: Exploring the How and Why
tanishiking
1
1.8k
Scala to WebAssembly #scala_waiwai
tanishiking
0
1.8k
Scala Days Madrid 2023 参加レポート
tanishiking
0
100
Tooling for Scala3
tanishiking
0
430
Other Decks in Technology
See All in Technology
AI時代のシステム開発者の仕事_20260328
sengtor
0
320
SaaSに宿る21g
kanyamaguc
2
180
不確実性と戦いながら見積もりを作成するプロセス/mitsumori-process
hirodragon112
1
160
40代からのアウトプット ― 経験は価値ある学びに変わる / 20260404 Naoki Takahashi
shift_evolve
PRO
3
460
ThetaOS - A Mythical Machine comes Alive
aslander
0
230
Oracle Cloud Infrastructure(OCI):Onboarding Session(はじめてのOCI/Oracle Supportご利⽤ガイド)
oracle4engineer
PRO
2
17k
昔話で振り返るAWSの歩み ~S3誕生から20年、クラウドはどう進化したのか~
nrinetcom
PRO
0
120
開発チームとQAエンジニアの新しい協業モデル -年末調整開発チームで実践する【QAリード施策】-
qa
0
550
AIにより大幅に強化された AWS Transform Customを触ってみる
0air
0
230
脳が溶けた話 / Melted Brain
keisuke69
1
1.1k
Even G2 クイックスタートガイド(日本語版)
vrshinobi1
0
160
Physical AI on AWS リファレンスアーキテクチャ / Physical AI on AWS Reference Architecture
aws_shota
1
200
Featured
See All Featured
Large-scale JavaScript Application Architecture
addyosmani
515
110k
Side Projects
sachag
455
43k
Principles of Awesome APIs and How to Build Them.
keavy
128
17k
Everyday Curiosity
cassininazir
0
180
How to build an LLM SEO readiness audit: a practical framework
nmsamuel
1
700
Game over? The fight for quality and originality in the time of robots
wayneb77
1
150
Building AI with AI
inesmontani
PRO
1
840
Neural Spatial Audio Processing for Sound Field Analysis and Control
skoyamalab
0
240
WENDY [Excerpt]
tessaabrams
9
37k
Git: the NoSQL Database
bkeepers
PRO
432
67k
Paper Plane
katiecoart
PRO
0
48k
Getting science done with accelerated Python computing platforms
jacobtomlinson
2
160
Transcript
Scala 製インタプリタをブラウザで動かす 3 分クッ キング id:tanishiking24 Scala 関西 Summit2017 1
こんにちは • • twitter @tanishiking • id:tanishiking24 • Web アプリケーションエンジニア@はてな
• 主に Scala、たまに TypeScript/Perl 2
今日作るもの • https://github.com/tanishiking/MLScala 3
手順 • インタプリタを作る • Scala.js でビルドする • UI を書く •
完成! 4
インタプリタを作る このあたりを参考に頑張る • https://github.com/ksuenaga/IoPLMaterials • http://esumii.github.io/min-caml/ パーサコンビネータに fastparse 使った 5
インタプリタを作る こちらにあらかじめ作ったものが 6
Scala.js でビルドする 公式ドキュメントを参考に build.sbt をいじる • crossProject で shared,js,jvm 用にプロジェクト分ける
• コアロジックは shared 以下につっこむ、雑に全部ごっちゃに すると sbt test が動かなくなったり • https://github.com/scala-js/scala-js/issues/739 7
Scala.js でビルドする • export するモジュールやメソッドを annotation で指定 • プログラムの文字列を入力として print
メソッドに渡した値の 文字列を返す簡素な API import scalajs.js.annotation._ @JSExportTopLevel(”ML”) object Interpreter { @JSExport def interpret(input: String): String = { // ... 8
UI を作る • ビルド成果物の JS を雑に読み込んで、さっき export したメ ソッドを実行したらなんか動く •
標準出力は console に出てくる ... <script src=”./js/target/scala-2.12/mlscala-fastopt.js”></scrip ... <script> const result = ML.interpret('let x = 1 in print x;;'); </script> 評価結果を適当な div につっこんで表示する感じで 9
完成!! http://tanishiking.github.io/MLScala/ 10
まとめ • 普通に動いてすごい • 面白 AltJS くらいの印象だったけど Scala 製モジュールのデモ に良さそう
• ブラウザで動かしたいけど JS で書きたくないモジュールある よね 11