Your SlideShare is downloading. ×
0
Shrink to grow
Shrink to grow
Shrink to grow
Shrink to grow
Shrink to grow
Shrink to grow
Shrink to grow
Shrink to grow
Shrink to grow
Shrink to grow
Shrink to grow
Shrink to grow
Shrink to grow
Shrink to grow
Shrink to grow
Shrink to grow
Shrink to grow
Shrink to grow
Shrink to grow
Shrink to grow
Shrink to grow
Shrink to grow
Shrink to grow
Shrink to grow
Shrink to grow
Shrink to grow
Shrink to grow
Shrink to grow
Shrink to grow
Shrink to grow
Shrink to grow
Shrink to grow
Shrink to grow
Shrink to grow
Shrink to grow
Shrink to grow
Shrink to grow
Shrink to grow
Shrink to grow
Shrink to grow
Shrink to grow
Shrink to grow
Shrink to grow
Shrink to grow
Shrink to grow
Shrink to grow
Shrink to grow
Shrink to grow
Shrink to grow
Shrink to grow
Shrink to grow
Shrink to grow
Shrink to grow
Shrink to grow
Shrink to grow
Shrink to grow
Shrink to grow
Shrink to grow
Shrink to grow
Shrink to grow
Shrink to grow
Shrink to grow
Shrink to grow
Shrink to grow
Shrink to grow
Shrink to grow
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Shrink to grow

1,514

Published on

Presentation for RubyKaigi 2013 in Tokyo.

Presentation for RubyKaigi 2013 in Tokyo.

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
1,514
On Slideshare
0
From Embeds
0
Number of Embeds
7
Actions
Shares
0
Downloads
5
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Daniel BovensiepenShrink To Grow
  • 2. mruby
  • 3. m for ...
  • 4. m for ...minimal
  • 5. Binary Size< 100kB
  • 6. Memory Footprint< 40kB RAM
  • 7. m for ...
  • 8. m for ...embedded
  • 9. https://github.com/matsumoto-r/mod_mrubymod_mruby
  • 10. LoadModule mruby_module modules/mod_mruby.soAddHandler mruby-script .rbbackends = ["http://192.168.0.101:8888/","http://192.168.0.102:8888/","http://192.168.0.103:8888/","http://192.168.0.104:8888/",]# write balancing algorithm here.r = Apache::Request.new()r.handler = "proxy-server"r.proxyreq = Apache::PROXYREQ_REVERSEr.filename = "proxy:" +backends[rand(backends.length)] +r.uriApache::return(Apache::OK)https://github.com/matsumoto-r/mod_mrubymod_mruby
  • 11. https://github.com/spiritloose/sqlite3ext-mrubysqlite3ext-mruby
  • 12. $ cat test.rbdef fib(n)n < 2 ? n : fib(n - 1) + fib(n - 2)endcreate_function :fib do |n|fib(n)end$ LD_LIBRARY_PATH=. sqlite3sqlite> .load libsqlite3ext_mruby.so.1.0.0;sqlite> SELECT mrb_load(test.rb);sqlite> SELECT fib(30);832040sqlite>https://github.com/spiritloose/sqlite3ext-mrubysqlite3ext-mruby
  • 13. EmbedArangoDB , Redis,mobiruby, Android, SMCArangoDB: http://www.arangodb.orgRedis: https://github.com/antirez/redis/pull/848mobiruby (iOS): http://mobiruby.orgAndroid: http://podtynnyi.com/2012/11/29/build-mruby-for-android/SMC: http://www.secretmaryo.org, https://github.com/Quintus/SMC
  • 14. m for ...
  • 15. m for ...modular
  • 16. Add/Remove Features(i.e. Fiber, stdio, ObjectSpace, etc.)Standard Library
  • 17. $ ./bin/mirbmirb - Embeddable Interactive Ruby ShellThis is a very early version, please test and reporterrors.Thanks :)> ThreadNameError: uninitialized constant Thread> FiberNameError: uninitialized constant Fiber> eval "puts hello world"NotImplementedError: eval not implemented> print "Test"NotImplementedError: print not available> ObjectSpaceNameError: uninitialized constant ObjectSpace> require fileNoMethodError: undefined method require for mainAdd/Remove Features(i.e. Fiber, stdio, ObjectSpace, etc.)Standard Library
  • 18. RegExpOniguruma & Henry Spencer EngineOverview: http://blog.mruby.sh/201302190729.htmlOniguruma: http://www.geocities.jp/kosako3/oniguruma/Henry Spencer Engine: http://www.arglist.com/regex
  • 19. Howis this possible?
  • 20. Implementationrewritten in C99
  • 21. ImplementationISO 30170:2012
  • 22. EXECUTINGRUBY CODEFive Ways to execute mruby: http://blog.mruby.sh/201207020720.htmlmrbc, mruby and mirb
  • 23. Build SystemMakefile, cmake and ...
  • 24. RakeBuild System
  • 25. MRuby::Build.new do |conf|# load specific toolchain settingstoolchain :gcc# include the default GEMsconf.gembox defaultend# Define cross build settingsMRuby::CrossBuild.new(32bit) do |conf|toolchain :gccconf.cc.flags << "-m32"conf.linker.flags << "-m32"endRakeBuild System
  • 26. mrbgems
  • 27. mrbgemsmgem is like RubyGem but incompatible
  • 28. mrbgems
  • 29. mrbgemsmruby.c CC mruby
  • 30. mrbgemsmruby.c CC mrubymgem activate+mgem +Fiber(i.e. Fiber)
  • 31. Whatcan we do now?
  • 32. mruby on Arduino
  • 33. C++ CodeArduino
  • 34. C++ CodeArduino// Pin 13 has an LED connected on most Arduino boards.// give it a name:int led = 13;// the setup routine runs once when you press reset:void setup() {// initialize the digital pin as an output.pinMode(led, OUTPUT);}// the loop routine runs over and over again forever:void loop() {digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)delay(1000); // wait for a seconddigitalWrite(led, LOW); // turn the LED off by making the voltage LOWdelay(1000); // wait for a second}
  • 35. WorkflowArduino
  • 36. WorkflowArduinocode.cpp
  • 37. WorkflowArduinocode.cpp a.binCross-CC
  • 38. WorkflowArduinocode.cpp a.binCross-CC .Upload
  • 39. Cross-Compile
  • 40. Atmel SAM3X8E (ARM Cortex-M3 based)Cross-Compile
  • 41. Atmel SAM3X8E (ARM Cortex-M3 based)Cross-CompileMRuby::CrossBuild.new("Arduino Due") do |conf|toolchain :gccARDUINO_PATH = /home/daniel/Downloads/arduino-1.5.2BIN_PATH = "#{ARDUINO_PATH}/hardware/tools/g++_arm_none_eabi/bin"SAM_PATH = "#{ARDUINO_PATH}/hardware/arduino/sam"TARGET_PATH = "#{SAM_PATH}/variants/arduino_due_x"conf.cc do |cc|cc.command = "#{BIN_PATH}/arm-none-eabi-gcc"cc.include_paths = ["#{SAM_PATH}/system/libsam -I#{SAM_PATH}/system/CMSIS/CMSIS/Include/","#{SAM_PATH}/system/CMSIS/Device/ATMEL/","#{SAM_PATH}/cores/arduino -I#{TARGET_PATH}","#{MRUBY_ROOT}/include"]cc.flags << -Os -w -ffunction-sections -fdata-sections -nostdlib +--param max-inline-insns-single=500 -Dprintf=iprintf +-mcpu=cortex-m3 -DF_CPU=84000000L -DARDUINO=152 +-D__SAM3X8E__ -mthumb -DUSB_PID=0x003e -DUSB_VID=0x2341 -DUSBCONcc.compile_options = "%{flags} -o %{outfile} -c %{infile}"endconf.archiver do |archiver|archiver.command = "#{BIN_PATH}/arm-none-eabi-ar"archiver.archive_options = rcs %{outfile} %{objs}endconf.bins = []end
  • 42. Arduino EcosystemEmbed
  • 43. Arduino EcosystemEmbed#include "Arduino.h"#include "../mruby_src/include/mruby.h"mrb_state *mrb;/* Init phase of Microcontroller */voidsetup() { }/* Process Loop */voidloop() {mrb = mrb_open();/* Use mruby here */mrb_close(mrb);}
  • 44. Arduino Ecosystem (API)Embed
  • 45. Arduino Ecosystem (API)Embed/* ... */mrb_valuemrb_ar(mrb_state *mrb, mrb_value self) {mrb_int pin;mrb_get_args(mrb, "i", &pin);return mrb_fixnum_value(analogRead(pin));}/* ... *//* Integrate into mruby */RClass *am = mrb_define_module(mrb, "Arduino");mrb_define_module_function(mrb, am, "analog_read", mrb_ar, ARGS_REQ(1));/* ... */
  • 46. Shrink
  • 47. available 96kB SRAM and 512kB FlashShrink
  • 48. available 96kB SRAM and 512kB FlashShrink0160003200048000640008000096000112000128000144000160000nothing mrb_open wrd box nan box flt seglist heap khash mrblib ALL (-flt -wrd) ALL (-nan)Image (bytes) Free Memory (bytes) Execution Time (µs)
  • 49. Shrink96kB SRAM available (~31kB used)512kb Flash available (~86kB used)
  • 50. Workflow (mruby)Arduino
  • 51. Workflow (mruby)Arduinomruby.c
  • 52. Workflow (mruby)Arduinomruby.cmruby¹(host)cc
  • 53. Workflow (mruby)Arduinomruby.cmruby¹(host)ccmruby²(target)cross-cc
  • 54. Workflow (mruby)Arduinocode.rbmruby.cmruby¹(host)ccmruby²(target)cross-cc
  • 55. Workflow (mruby)Arduinocode.rbarray.c(Array)mruby.cmruby¹(host)ccmruby²(target)cross-ccmrbc¹
  • 56. Workflow (mruby)Arduinocode.rbarray.c(Array)code.cppmruby.cmruby¹(host)ccmruby²(target)cross-ccmrbc¹ integrate
  • 57. Workflow (mruby)Arduinocode.rbarray.c(Array)code.cppmruby.cmruby¹(host)ccmruby²(target)code.cpp+mruby²cross-ccmrbc¹ integrate
  • 58. Workflow (mruby)Arduinocode.rbarray.c(Array)code.cppmruby.cmruby¹(host)ccmruby²(target)code.cpp+mruby²a.bincross-ccmrbc¹ integratecross-cc
  • 59. Workflow (mruby)Arduinocode.rbarray.c(Array)code.cppmruby.cmruby¹(host)ccmruby²(target)code.cpp+mruby²a.bin .cross-ccmrbc¹ integratecross-cc upload
  • 60. Workflow (mruby)Arduinocode.rbarray.c(Array)code.cppmruby.cmruby¹(host)ccmruby²(target)code.cpp+mruby²a.bin .cross-ccmrbc¹ integratecross-cc uploadOMG
  • 61. Port mirb to Arduino DueArduino
  • 62. Port mirb to Arduino DueArduino.enter .rb
  • 63. Interactive Arduino Shell (LED Switch)Arduino
  • 64. Interactive Arduino Shell (3D Printer)Arduino
  • 65. Coming Next“Webruby”byXuejie Xiao
  • 66. THX@bovensiepenhttp://mruby.sh

×