 Today, I'd like to talk about Mobilubi. It's my first English presentation. Thank you. Nice to meet you. I'm Yuichiro Masui. I came from Tokyo. Please call me Ichi. My Twitter account and Githa account is Masui Drive. I really love the programming and writing called anytime anywhere, especially with Ruby language. I'm writing called anytime. But my most popular open source product is PHP-based Uki Engine. Just Ruby, Japanese Ruby is not as a programmer. Flow means hot tab. I'm coding while in the hot tab. Now, I'm working at Japanese startup company. Who is the Flugapps? That has released food for the sharing application for the iPhone and Android. But the application are not built on Mobilubi. They are native application. Until September, I had worked at Accelerator that is the latest Titanium mobile. It's JavaScript-based iPhone and Android development framework. But now, I'm working on Mobilubi. It's competitor of Titanium mobile. Mobilubi is my private project. It is not for business. Mobilubi is iPhone application development environment built on Mobilubi. You can create iOS application using Ruby. Mobilubi provides bridge between Cocoa and Mobilubi. You can call native classes and functions instead of Objective-C. Currently, Mobilubi support iOS only. But I have plan for the Android version. I confirmed that Mobilubi can run on the Android devices. I've already released the Mobilubi-based game application. I have a demo. Please. Sorry, please wait. OK. OK, sorry. It's a Mobilubi-based application. It's already released in the iPhone's iOS app store. It's a simple game. It's very smooth animation. It's like a native application. You can download this game from iOS app store. Please search Mobilubi in the store. Mobilubi is the latest Ruby implement by Maths. I had Mobilubi first time at 2010. At that time, it's called LiveVM. Mobilubi is designed for embedded systems. It means small memory and modular structure. Mobilubi is more compact than other Ruby implements. On OS 10, Mobilubi binary is around 406 kilobytes. But the Mobilubi is over 2 megabytes. Mobilubi can even smaller. Mobilubi has modular structure. If you want to remove Maths library, you can remove it easily. So Mobilubi supports multiple virtual machines. Mobilubi does not support yet. Instead, Mobilubi has many limitations. Mobilubi is built on ISO specifications. It means Mobilubi does not support slate and many classes. Almost all Ruby standard libraries are not supported. So Ruby is not supported. And Mobilubi still alpha version. Sometime I found Mobilubi bugs. Mobilubi provide Ruby power to the mobile devices, especially mobile phone. Do you know Wax? Wax is W-A-X. Wax is Rua-based iPhone application tool chain, a development tool chain, similar Mobilubi. Rua is a popular language around embedded systems. The syntax near action-splicked. Wax was born about three years ago, but it is not popular yet. Why? The cause is Rua language, I think. The bridge library is one of good language. Does need powerful language support. I think Rua does not have enough dynamic programming capability. Metaprogramming is most important, most powerful capability in Ruby. Ruby's metaprogramming can make good, lapping native libraries and make DSL for the iOS. Hello World code. iOS developer can understand this sample code. It's really similar objective C. In first half, the code defined new class, myRW, then inherited from yourRW Coco class, and define new delegate methods through define method. MRuby has not support keyword arguments yet. It's two-pointful feature. And MRuby's hash is not ordered. It's same as Ruby 1.8. MyRW defined on Ruby code. It's Ruby class and Objective C class. Ruby and Objective C, both sides can touch myRW class. In second half, create myRW instance and show this art box. When you call Objective C method, you need to start and score as the slideshow. On contrary version, if you want iOS application on Mobi Ruby, you need to understand Objective C and Cocoa libraries. Is this nonsense? I think so too. I'm aiming for the Discord on next version. It looks like a truly Ruby code. It's not similar of Objective C. Actively call lapped SQL and provide good DSL to Ruby programmers. So Mobi Ruby will lapped Cocoa libraries and good DSL to Ruby programmers. But at first, I focused to make Cocoa Bridge on MRuby. It's for baseline of Mobi Ruby. After that, I will make creating new APIs. I will talk about Mobi Ruby internals. Mobi Ruby has made up five components. At first, M Ruby is main components of Mobi Ruby. It was patched and some configuration changed. And second component is M Ruby Cfunk. It's an interface with C function and M Ruby. M Ruby Cfunk provide an interface to M Ruby and C level functions. It's same as Ruby DL library on C Ruby. The code called the puts C function from Ruby. Internally, it's combat Ruby string to C string. Look up puts function pointer to, sorry, look up puts function pointer and calls a function. M Ruby can call all C function without specific extensions. This component is independent from M Ruby, Mobi Ruby. If you want to use it, you can use it. Third component is M Ruby Cocoa. It's an interface to the objective C and Cocoa libraries. M Ruby Cocoa is a bridge for Cocoa libraries, which is the iOS and OS 10 framework. This library provides a transparency communication with M Ruby and Cocoa libraries. M Ruby Cocoa provide create new instance of Cocoa class on M Ruby. You can also inherit it from existing Cocoa class on M Ruby. In earlier Hello World sample, we inherited from UiRudView to MyRudView. UiRudView is a Cocoa class, and MyRudView defined in Ruby. Cocoa and Ruby class can manipulate transparency, natural interface, delegation, and block function supported in this library. In this library, the hardest part is memory management. Objective C use reference counting, and M Ruby use mark and seep. It's different. It's hard to free object correctly in both environments. Now, all Objective C classes release method are overriding. It's awful bottleneck for the performance. It affects all Cocoa objects. Fats are included and not related with M Ruby object. It still has a problem that it cannot detect a circular reference. I will fix some future. Probably, I will rewrite in assemblers. First component is M Ruby common. It's for future release when we release Android version. This library provides common utility among iOS and Android version. Currently, it provides require and load method only. Standard M Ruby does not support required and load methods. Last component is M Ruby iOS. M Ruby iOS is the main part of the M Ruby. It provides iOS specific utility that are included Xcode integration. In the first version, this component is poor. I don't know Xcode deeply. I need to help about Xcode integration. In the future, M Ruby will provide good wrapper APIs. It has some compatibility between iOS and Android. When you use their APIs, you can use Cocoa APIs at the same time. On the load map, I don't have a detailed plan. So it's my private project. I don't have a bus and management section. I am first product level version until end of first quarter of the next year. This version supports almost all objective features. I plan to start writing API and tutorial documents. After that, I will touch next version. It will have a wrapped API. So you can call in Ruby style. Current status, I already released the M Ruby game. Apple never reject this application. In September, I finally released the M Ruby alpha version. It's the first public version. I'm keeping to update. Now I focus to writing test code. Until recently, I wrote a few tests only. I used Travis CI from two weeks ago. I think M Ruby's hardest part is slate because M Ruby does not support slate. I load limited slate feature and testing now. Currently, mobile Ruby is not for ordinary Ruby programmers. It's for M Ruby and Cocoa hackers. If you know objective C and have interest in M Ruby, please join to my project. I have three frequency questions. The big question is the first question. The first question is the first difference from the Ruby motion. Ruby motion is LVM-based and compiled to native code. It's only for iOS, but M Ruby will release Android version. And Ruby motion extended Ruby syntax. And Ruby motion is not open source. Ruby motion and mobile Ruby, maybe we have the same goal, but approach is very different. If you want to make a person, I recommend to use Ruby motion. It's stable and faster than current mobile Ruby. And the second question, can I use Ruby gems? No, M Ruby does not have compatibility with C Ruby extension APIs. You need to write a new extension for M Ruby. Bobby and Matt have discussed about M Ruby's version Ruby gems. And the third question, can I use existing Cocoa libraries? Yes, you can use almost all existing libraries. I think CocoaPot will be a good partner. CocoaPot is a library manager for the Xcode. If you have more questions, please tweet to this account, mobile Ruby, and post to GitHub issues. I really want a teammate. Currently, I'm alone. If you have interest to this project, please contact me. Thank you very much. Hello, everyone. The second part is M Ruby meets RTOS. First of all, let us introduce ourselves. I'm Masayoshi Takahashi. Oh, sorry. Sorry. I'm Masayoshi Takahashi, a Rubyist and web application developer. I've published the founder of the Japan Ruby group. I'm sorry, but I'm not an embedded guide. I'm very newbie for embedded worlds. My name is Yurie Yamane. I'm a hobby programmer. I'm interested in embedded systems. OK. Before our talks, we'd like to ask some questions. Please raise your hand. I've used RTOS. Oh, 1, 2, 3, 4, 5, 6. Thank you. I have about 10 people. And please raise your hand. I love iOS, and not interested in embedded so much. I don't mind. OK, no problem. Thank you very much. I love iOS, too. So today's topics are here. What's embedded systems and showing a demo and explain how to use MLuby with RTOS? But I'm afraid of this talk. As you are aware, I can talk well. And so our talks might be tired and boring. So we can change the title. New title is Ruby for Ninjas. Thank you. I think embedded systems are very different with, for example, web applications and enterprise systems. If web applications and enterprise systems are like Samurai, embedded systems are like Ninja. Ninja, do you know Ninja? Samurai is playing the leading role. And they are powerful soldiers. And they are in front, and they are very remarkable. Embedded systems are very different. They are playing the supporting role. And they are still soldiers. And they are behind, and they control others, control other things. So even if Ruby is widely in Samurai's world, same Ruby might not be fit to Ninja's world, I think. If it be so, what are the needs of embedded systems? Or what are Ninja's rules? The main purpose of embedded systems are controlling other devices, such like sensors or actuators. And the very important needs of embedded systems and embedded Ruby are hidden as much as possible. In other words, they should consume less resources. The resources here are not only space, but also times. Time is resources. Embedded systems are widely spread around us. For example, digital cameras, microwave ovens, vending machines, automobiles, traffic signals, they use embedded systems. Many Ninjas are hidden behind our daily life. We'd like to use M-Ruby with them. But we make a simple M-Ruby demos now. Here is a demo hardware. We use Fujitsu FM3 microcontroller board as an M-Ruby system. Its core is ARM Quatext M3. And it has 128 kilobyte RAM and 1 megabyte ROM. It can be connected to PC on CO. And it has small LED. The application in this demo has two tasks. The first task is M-Ruby interactive shell like IRB. You can send M-Ruby code from PC to the board. Then board evaluates the code and responds the result through serial. The second task is blinking LED tasks. The board has hardware clock, so the task is to use it and turn on and turn off the LED at intervals of one second, per one second. So let's try the demo. We're preparing a serial device and a serial speed. This is a console, and M-Ruby's initialization is done. And this is the board. Thank you. This is ARM chip, and this is LED blinking now. Now type A equals 1, and A B equal 2, and A plus B equal 3. And definition method, def and intervals. So a foo, 3 is 9, and foo, 10 is 100. OK, it works. Let's list our requirements. First, blinking LED cyclically. Second, passing and code generating from M-Ruby code in runtime. Third, serial communication without lost data. We should explain the priority of tasks. Each task has a priority, and if an activated task has higher priority, the lower priority task must become waiting immediately. It's important that LED blinking task has higher priority than M-Ruby task. Let's see cyclic blinking task. LED blinking task is activated at the interval. After turning off the LED, the task is terminated. The interactive M-Ruby task, when the LED task is activated, the status is saved. When LED task is terminated, M-Ruby task is running. M-Ruby task is continued if other tasks are interrupted. Out-of-task system is suited to satisfy these requirements. Out-of-task system, there are many out-ofs in the world, but we choose Topaz SP for our system. Topaz SP is an open source, real-time operating system. Its license is like BSD style, and its code is based on micro-iternal specification adding Topaz original interruption model. Topaz Karnes has many variants. We use Topaz SP because it's the standard profile of Topaz Out-of-task Karnes. Now change to speakers. OK, and now we explain the implementation of the system. And let's see the component of our system. There is Timer, LED, and CO. We use them with two plus one tasks. The main task activates M-Ruby task and LED task. After that, main task is sweeping. In Topaz, you can write your application with three files, C files, and header files, and Cfg files, configuration files of Topaz. Configuration files define tasks and other things. With this file, you can allocate the memory of tasks statically. Statically, memory allocation is important for embedded systems. Then we talk about very basic of M-Ruby internals. The entity of M-Ruby VM is a struct MRBState. The function MRBOpen generate a VM. And it's finished with the function MRBClose. In our demos, we use Passive and Code Generator. But it's optional. When you use compiled code, you don't need Passive and Code Generator. But you want to do like this demo. You must include them. This is the digest of the demo code. Generating context, generating and initialized Passive, and passing Ruby code, generating byte code, and write byte code, and evaluating it. But 100 kilobyte of RAM is too small for MRuby. So we need to diet. We use three ways to shrink our RAM size. Modify, including MRBConf.h, and applying symbol array part, and shrinking MRB leave. First, modifying, including MRBConf.h file. This file uses a macro definition to configure M-Ruby. Such like MRBUseFloat, MRBFuncall.hc.max, and so on. We use these macros to reduce our memories. The second way is applying symbols array patch. Symbol in the M-Ruby are implemented with hash data structure. So our patch changed to use array instead of hash to reduce memory use. The third is shrinking MRB leave. MRB leave is a Ruby standard library written in Ruby. So you can remove it to reduce RAM. By the way, there is an emulator of FM3 board. The emulator is QEMU, QAM patched version with GUI in Java. You can download them on the net from this URL. So the conclusion. You can use MRuby with Altos well. And we hope this talks helps your MRuby life. Thank you so much. Arigato gozaimashita.