×閉じる
mruby/c|レポート mruby/c

mruby/c 3.4 をリリースしました

2025年07月01日

mruby/c 3.4 をリリースしました| mruby/c 3.4 has been released
日本語の後に英語が続きます| English follows after Japanese

img_ogp

mruby/c 3.4では、新たにモジュールをサポートしました。その他、多くの機能の追加や試験導入、機能改善、バグフィックスが行われています。

mruby/c 3.4のリリースに関するトピックスを以下のとおり紹介します。

機能追加

  • モジュールのサポート (54187be, aadeb50, 2bc79af)
    プログラミング言語「Ruby」の特徴的な機能の一つであるモジュールをサポートしました。モジュールは、複数のメソッドや定数をまとめて管理し、名前空間を提供することでクラスやメソッドの名前の衝突を避けることができます。また、モジュールをクラスにincludeすることで、その機能(メソッドや定数)をクラスに取り込むこと(Mix-in)ができるため、コードの再利用性を高め、機能の共通化・整理に役立ちます。
  • Array#uniq、Array#uniq! の追加 (056d4c3)
    Arrayクラスに重複要素を取り除いた新しい配列を返す#uniqメソッドと、selfから重複要素を取り除く#uniq!メソッドを追加しました。これにより、配列から重複した要素を効率的に処理することが可能になります。
  • [Experimental] method_missing のサポート (21ef065, PR#221)
    Rubyの強力なメタプログラミング機能の一つであるmethod_missingを試験的にサポートしました。method_missingは、クラスに定義されていないメソッドが呼び出されたときに自動的に呼び出される特別なメソッドです。これにより、未定義のメソッドに対する動的な処理が可能となり、エラーを柔軟に扱うことができます。
  • [Experimental] C言語で定義したクラスにおける destructor のサポート (e5fa70a)
    C言語でクラスを定義した場合において、オブジェクトが廃棄されるときに自動的に指定したメソッドが呼ばれる機能 (destructor) を試験的にサポートしました。これにより、動的に確保したメモリやリソースの解放処理を行うことで、確実かつ安全なリソース管理を実現します。
  • [Experimental] C言語でメソッドを書く際の引数取得ヘルパーマクロの追加 (Issue#230, c213e65, 78f4b42)
    C言語でメソッドを書く際に、RubyからCへの引数の受け渡しを簡易に記述することができる、コンビニエンスマクロを追加しました。このマクロは、引数が与えられたかどうかの確認と、引数をC言語のデータ型で取得するための機能を有します。
  • public、private、protected の追加と留意事項 (58ec64d)
    mruby 3.4でメソッドの可視性をコントロールする publicprivateprotectedが追加されました。そのため mruby/cでもこれらを追加しましたが、mrubyとの互換性を維持するためでmruby/cでは何も実行しません。

機能改善

  • Proc オブジェクトの内部改善 (f89adbc, 2dce82b)
    Procオブジェクトの内部構造が改善され、ブロックとメソッドの区別が明確になりました。これにより、Procオブジェクトの挙動がより予測可能になり、デバッグや保守が容易になります。
  • String#[]、String#[]= でRangeに対応 (604f4ae, 841fcab)
    これまで整数しか使えなかったStringクラスが、Rangeに対応しました。これにより、文字列の一部を抽出できます。具体的には、String#[]メソッドでRangeを指定することで、その範囲内の文字列を返します。
  • 除算および剰余演算子をCRubyとの互換性を向上 (800fb8d)
    除算演算子 (/) および剰余演算子 (%) の動作をCRubyとの互換性を高めるように修正しました。これにより、既存のCRubyコードの移植や相互運用がよりスムーズになります。
  • 定数探索の方法をCRubyとの互換性を向上 (b889970)
    定数探索の動作をCRubyとの互換性を高めるように修正を行いました。
  • 例外メッセージの整理 (07c4521)
    エラー発生時に表示される例外メッセージが整理され、より明確で理解しやすくなりました。これにより、プログラムの問題を素早く原因を特定し、デバッグ作業を効率的に進めることができます。

バグフィックス

  • 同じ名前のメソッドが定義されたときの動作を改善 (fffcf7b)
    同じ名前を持つメソッドを複数回定義した場合、エイリアスを併用すると動作不定となる問題を解消しました。
  • Task#list() メソッドに関する不具合の修正 (82806e9)
    Task#list()メソッドに関する不具合を修正し、タスクの一覧を正しく取得できるようになりました。
  • mrbc_cleanup 関数のバグを修正 (eb09986)
    実行後の状態を初期状態へ戻すcleanup関数が過去のバージョンアップにより不十分な動作となっていた問題を解消しました。 

プラットフォーム対応

  • STM32マイコンのHALを追加 (1aabd5e, hal/stm32)
    STM32マイコンのHAL(Hardware Abstraction Layer / ハードウェア抽象化レイヤー)を追加しました。
    これにより、STM32マイコンのプログラムを階層化する際、上位のプログラムをハードウェアに依存することなく抽象化できるので、プログラムの移植性を高められます。つまり、異なるSTMマイコンで開発する際に、HALより上位層のプログラムに変更を加えることなく移植できます。
    このチュートリアルは「mruby/cでSTM32マイコンを動かす」をご覧ください。

予告

    • Taskクラスの一部クラスメソッド廃止
      Taskクラスの一部クラスメソッドは、次期バージョンで廃止し、同一機能のインスタンスメソッドのみとする予定です。この変更は、タスクオブジェクトの役割をより明確にするための変更です。この変更に伴い、以下のメソッドはインスタンスを使うよう書き換える必要があります。

      Task.getTask.current
      Task.nameTask.current.name
      Task.priorityTask.current.priority
      Task.suspendTask.current.suspend

 

注記

  • [Experimental]の表記がある機能について、mruby/c 3.4でのサポートは試験的なものです。今後のフィードバックや利用状況を踏まえて、さらなる機能改善や正式サポートを検討します。
  • GitHubリポジトリで行われている自動テストを、ローカル環境でも実行できます。テストの方法については、「How to run tests?」にまとめられています。
  • mruby/c 3.4 で実装されているクラス・ライブラリの一覧を「クラス・ライブラリ一覧」に示しています。

ダウンロード

https://github.com/mrubyc/mrubyc/releases/tag/release3.4

mruby/c 3.4のリリースにおいて、バグフィックスと改良に取り組んでいただいた全てのコントリビュータに感謝します。

mruby/cについて

mruby/c(エムルビー・スラッシュ・シー)は、プログラミング言語「Ruby」の高い開発生産性と優れた可読性の特徴を継承した、組み込みシステム向けの軽量なRuby実装です。プログラム実行に必要なメモリ消費量が約40KBと非常に小さく、リソースに制約のあるワンチップマイコン上でも動作します。そのため、センサーネットワークやウェアラブルデバイスなどの小型IoT機器のソフトウェア開発はもちろん、既存デバイスへのDSL(ドメイン固有言語)追加にも適しています。mruby/cは、しまねソフト研究開発センターと国立大学法人九州工業大学(田中和明准教授)の共同研究によって開発し、オープンソース(3条項 BSDライセンス)として公開されています。

しまねソフト研究開発センターの「mruby/c」に関する取組はこちらのページをご覧ください。
また、「mruby/c」の活用に向けた不明点やご相談がありましたら、こちらのページよりお問合せください。

お問い合わせ先

しまねソフト研究開発センター
Phone:0852-61-2225
Email:itoc@s-itoc.jp

 


mruby/c 3.4 released

mruby/c 3.4 adds support for Module. Many other features, improvements, and bug fixes are also included.
The following highlights summarize key updates in the mruby/c 3.4 release.

New Features

  • Module Support (54187be, aadeb50, 2bc79af)
    Support for Module has been added, a distinctive feature in Ruby. Module allows grouping related methods and constants, and provides a namespace to avoid naming collisions of other classes and methods. Using include, the methods and constants defined in a Module can be mixed into a class(the mixin facility), promoting code reusability and helping organize common functionality.
  • Add Array#uniq and Array#uniq! (056d4c3)
    The Array class now supports uniq, which returns a new array with duplicate elements removed, and uniq!, which eliminates duplicate elements from self. These methods improve the ease and efficiency of handling duplicates in array processing.
  • [Experimental] method_missing Support  (21ef065, PR#221)
    Experimental support has been added for method_missing, a metaprogramming feature in Ruby. When an undefined method is invoked, this special method is called automatically, allowing dynamic handling of undefined methods and flexible error management.
  • [Experimental] Destructor Support for C-defined Classes (e5fa70a)
    For classes defined in C, a destructor mechanism has been introduced on an experimental basis. A designated method can now be automatically invoked when an object is finalized, enabling proper resource deallocation and safer memory management.
  • [Experimental] Add Argument Helper Macros when writing methods in C  (Issue#230, c213e65, 78f4b42)
    Convenience macros have been added to simplify argument handling from Ruby to C when writing methods in C. These macros can check if an argument has been provided, and allow arguments to be retrieved directly in C data types.
  • Add public, private, protected and Considerations (58ec64d)
    Support for public, private, and protected —used to control method visibility— has been added for compatibility with mruby 3.4. These keywords have been added to mruby/c to maintain compatibility with mruby. However, they are currently non-functional (no-ops) and do not enforce visibility.

Improvements

  • Internal Enhancements to Proc Objects (f89adbc, 2dce82b)
    The internal structure of Proc objects has been refined to better distinguish between blocks and methods. This improves predictability and simplifies debugging and maintenance.
  • String#[] and String#[]= Now Support Range (604f4ae, 841fcab)
    The String class methods now support Range objects in addition to integers. This enables substring extraction. Specifically, specifying a Range with the String#[] method returns the substring within that range.
  • Improved Compatibility of / and % Operators with CRuby (800fb8d)
    The behavior of the division (/) and modulo (%) operators has been aligned more closely with CRuby, enhancing code portability.
  • Enhanced Constant Lookup Compatibility with CRuby (b889970)
    Constant lookup has been updated to better match the behavior of Ruby, improving interoperability and portability.
  • Organize Exception Messages (07c4521)
    Error messages produced by the runtime have been improved for clarity and readability. These enhancements help developers identify the cause of program problems quickly and resolve issues more efficiently.

Fixes

  • Fixed Method Redefinition Behavior (fffcf7b)
    An issue where redefining a method —especially using aliases— could lead to undefined behavior has been resolved.
  • Bug Fix in Task#list() Method (82806e9)
    A bug that prevented the correct retrieval of the task list has been fixed.
  • Fix in mrbc_cleanup Function (eb09986)
    An issue that cleanup function (used to reset the execution state) was not working properly due to a previous upgrade has been fixed.

Platform Support

  • HAL Support for STM32 microcontrollers (1aabd5e, hal/stm32)
    The Hardware Abstraction Layer (HAL) for STM32 Microcontrollers has been added. This allows upper-layer code to be written without direct hardware dependency, improving portability across STM32 family of 32-bit microcontrollers.This means that when developing with a different STM microcontroller, programs above the HAL can be transplanted without altering any changes.
    Please refer to the tutorial on ”Running mruby/c on STM32 microcontrollers” for an overview. *This page is only available in Japanese.

Notice (Deprecations)

    • Deprecation of Some Class Methods in Task
      Several class methods in the Task class are scheduled to be removed in the next version. Their functionalities will be retained in instance methods  to clarify the role of the task object more clearly. Users are advised to update code to use instances accordingly.

      Task.getTask.current
      Task.nameTask.current.name
      Task.priorityTask.current.priority
      Task.suspendTask.current.suspend

 

Note

  • Features marked as [Experimental] in this release are provisional in mruby/c 3.4. We will consider improvements and official support based on user feedback and usage.
  • Automated testing with GitHub repository can be run for development environments on local machines.The testing procedure is summarized in "How to run tests?".
  • Learn to Implement & Used class libraries In mruby/c 3.4, please refer to "List of Class Libraries".
    *This page is only available in Japanese.

Download

https://github.com/mrubyc/mrubyc/releases/tag/release3.4

Thanks to the all contributors who helped with this release of mruby/c 3.4.

About mruby/c

mruby/c is a lightweight implementation of Ruby, designed specifically for embedded systems. It retains the features of Ruby, such as high code readability and development productivity, while minimizing memory usage to as low as around 40KB. This makes it well suited for single-chip microcontrollers and other resource-constrained environments, as well as for developing software for small devices such as wearable devices and sensor networks, and for adding Domain-Specific Languages(DSL) to existing products.

mruby/c is a collaborative research and development effort between Shimane IT Open-Innovation Center and Kyushu Institute of Technology (Associate Professor Kazuaki Tanaka), and is released as open-source software under the 3-clause BSD license. Please open an issue on GitHub if you have any questions or feature requests.

Contact Us

Shimane IT Open-Innovation Center
Phone:0852-61-2225
Email:itoc@s-itoc.jp

 

 

このページのトップへ