We are announcing the first stable release of mruby 3.1 series - mruby 3.1.0.
Describes the new features and changes in mruby 3.1.
The main changes in mruby 3.1 are also described in doc/mruby3.1.md.
CRuby3.0 compatible keyword arguments are introduced. Keyword arguments are basically separated from ordinal arguments.
single-line pattern matchingRuby:Feature#15921
Some configuration macros are available:
MRB_WORDBOX_NO_FLOAT_TRUNCATE: by default, float values are packed in the word if possible, but define this macro to allocate float values in the heap.
MRB_USE_RO_DATA_P_ETEXT: define this macro if
_etextis available on your platform.
MRB_NO_DEFAULT_RO_DATA_P: define this macro to avoid using predefined
We have added several new build configurations in the
minimal: minimal configuration
host-f32: compiles with
mrb_floatas 32 bit
host-nofloat: compiles with no float configuration
android_arm64_v8a.rb: renamed from
Mdirective (Q encoding)
Xdirective (back-up by bytes)
@directive (absolute position)
wdirective (BER compression)
mruby -vcode dump output.
mrb_get_args()for receive Class/Module.
mruby-sprintf) Format specifiers
mruby-print) Now expand Array arguments.
Due to improvements in the binary format, mruby binaries are no longer backward compatible.
To run the mruby binaries on mruby 3.1, recompile with the mruby 3.1
0300(means mruby 3.0 or after).
OP_EXT3 for operand extension. But the operand size limitations was too tight for real-world application.
mruby3.1 reintroduces those extension instructions.
mruby3.1 removed following instructions.
Those instructions are no longer needed by reintroduction of extension instructions.
Those instructions for method calls with variable number of arguments are no longer needed. They are covered by
OP_SEND instruction with
mruby3.1 introduces following new instructions.
OP_GETIDX: takes 1 operands
OP_SETIDX: takes 1 operands
OP_SSEND: takes 3 operands
OP_SSENDB: takes 3 operands
OP_SYMBOL: takes 2 operands
R[a] = intern(Pool[b])
obj[int] = value respectively, where
They are similar to
OP_SENDB respectively. They initialize the
self first so that we can skip one
OP_LOADSELF instruction for each call.
Extracts the character string placed in the pool as a symbol.
Method calling instructions are unified. Now
OP_SENDB (method call with a block) can support both splat arguments and keyword arguments as well.
The brief description of the instructions:
Operand C specifies the number of arguments. Lower 4 bits (
n) represents the number of ordinal arguments, and higher 4 bits (
nk) represents the number of keyword arguments.
n == 15, the method takes arguments packed in an array. When
nk == 15, the method takes keyword arguments are packed in a hash.
Now takes 2 operands and pushes multiple entries to an array.
MRB_WORD_BOXING now packs floating point numbers in the word, if the size of
mrb_float is equal or smaller than the size of
mrb_int by default.
If the size of
mrb_int are same, the last 2 bits in the
mrb_float are trimmed and used as flags. If you need full precision, you need to define
MRB_WORDBOX_NO_FLOAT_TRUNCATE as described above.
Previous NaN boxing packs values in NaN representation, but pointer retrievals are far more frequent than floating point number references. So we add constant offset to NaN representation to clear higher bits of pointer representation. This representation is called “Favor Pointer” NaN Boxing.
Also, previous NaN boxing limit the size of
mrb_int to 4 bytes (32 bits) to fit in NaN values. Now we allocate integer values in the heap, if the value does not fit in the 32 bit range, just like we did in Word Boxing.
The code generator was updated to reduce the number of instructions, e.g.
a = 2 * 5
will be interpreted as
a = 10
In addition, we have improved peephole optimizations, for example:
GETIV R4 :@foo MOVE R1 R4
GETIV R1 :@foo
For better and faster hash values.
method_addedhooks on method definitions; #2339
Mpacking bug bfe2bd49
mrb_ary_shift_minitialization bug 27d1e013
Following CVEs do not cause problems in this release. They are fixed in the later release.
We have done 1,076 commits to 287 files with 17,188 additions and 15,549 deletions since mruby 3.0.0. For more detail of the updates, see Commit Log.
Thanks to all the contributors who have worked on bug fixes and improvements in the release of