Handling mails on a text editor • Day 2 / Matz / Keynote • Day 2 / Yutaka Hara / Ruby, Opal and WebAssembly • Day 3 / Kouji Takao / Smalruby : The neat thing to connect Rubyists and Scratchers RubyKaigi 2017 (19, Sep) 4
RubyΞϓϦέʔγϣϯΛ͢Δnݸͷํ๏ • 2011: RubyϚελʔͷಓ • 2012: DIY Programming1 • 2015: Let's Make a Functional Language! • 2017: Ruby, Opal and WebAssembly (see http://yhara.jp/Presentations for other events) 1 "The" RubyKaigi was not held in this year RubyKaigi 2017 (19, Sep) 6
I'm just too fluent in Ruby :-) • "Cached in my brain" 2 • Hash, Enumerable#flat_map, etc. 2 https://www.slideshare.net/mametter/ruby-65182128 (p.69) RubyKaigi 2017 (19, Sep) 12
pad support) module Window OK Basically class Font OK Basically class Image OK Basically class Sound OK Basically class SoundEffect OK Basically class Sprite OK Ongoing (TODO: collision detection) class RenderTarget OK N/A class Shader OK N/A class Shader::Core OK N/A RubyKaigi 2017 (19, Sep) 20
Download and unpack dxoapl-game-x.y.z.zip 2. Edit main.rb 3. Open index.html with Firefox fx fx Chrome is not ok because it raises error when ajax'ing images from file:// RubyKaigi 2017 (19, Sep) 23
of JS) • Example5e function AddFunctions(){ "use asm"; function add1(value){ value = value | 0; // Declare `value` is int var result = 0; result = (value + 1) | 0; return result; } return { add1: add1 } } 5e https://html5experts.jp/chikoski/18980/ RubyKaigi 2017 (19, Sep) 40
use Ruby instead of React, etc.? • The official WebAssembly site says: • "including support for languages other than C/C++" hg hg http://webassembly.org/docs/high-level-goals/ 2. RubyKaigi 2017 (19, Sep) 56
But DXOpal's case was not so meaningful • Same execution speed, easy to port to JS • Could be meaningful when: • Original C code is too long to port • Original C code is too complex to port (eg. cryptography, WebUSB) • Original C code is changed constantly RubyKaigi 2017 (19, Sep) 59
very dynamic • Features to evaluate code in runtime (instance_eval, etc.) • a) Embed entire Ruby processor into WebAssembly • b) Restrict some dynamic features RubyKaigi 2017 (19, Sep) 62
dynamically typed language • Hard to "compile" into statically typed language • a) Wrap everything with struct (very slow) • b) Type inference, type annotation • c) Use Ruby-like static language (Crystal) RubyKaigi 2017 (19, Sep) 63
have Opal already! • to run Ruby code on the browser • (One possible difference: WebAssembly-Ruby may run Ruby's C-extensions) RubyKaigi 2017 (19, Sep) 66
Node.js on AWS lambda (which does not support Ruby) [WebAssembly] <- [*.rb] | [Node.js] | [AWS lambda] • But Net::HTTP , etc. must be ported to use aws-sdk gem • eg. By using Node's API RubyKaigi 2017 (19, Sep) 72
• What is needed • WebAssembly's GC support • Port some corelib/stdlib for WebAssembly • Output LLVM IR for WebAssembly? (I'm not sure) • https://github.com/crystal-lang/crystal/issues/829 RubyKaigi 2017 (19, Sep) 73