summaryrefslogtreecommitdiffhomepage
path: root/doc/mruby3.1.md
blob: 1a8c621a9976d0121fcc7557a52ff979c7b86456 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# User visible changes in `mruby3.1` from `mruby3.0`

# Build System

## `build_config` directory

Several configurations for new platforms are added:

* `cross-mingw-winetest.rb`
* `cross-mingw.rb`
* `nintendo_switch.rb`
* `serenity.rb`

Some new configurations for added for convenience.

* `minimal`: minimal configuration
* `host-f32`: compiles with `mrb_float` as 32 bit `float`
* `host-nofloat`: compiles with no float configuration

And `android_arm64-v8a.rb` was renamed to `android_arm64_v8a.rb` for consistency.

# Language Changes

## Keyword Arguments

CRuby3.0 compatible keyword arguments are introduced.
Keyword arguments are basically separated from ordinal arguments

# Configuration Options Changed

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 `_etext` is available on your platform.
* `MRB_NO_DEFAULT_RO_DATA_P`: define this macro to avoid using predefined `mrb_ro_data_p()` function

# Internal Changes

## Reintroduced Instructions

`mruby3.0` removed `OP_EXT1`, `OP_EXT2`, `OP_EXT3` for operand extension. But the operand size limitations was too tight for real-world application.
`mruby3.1` reintroduces those extension instructions.

## Removed Instructions

`mruby3.1` removed following instructions.

* `OP_LOADL16`
* `OP_LOADSYM16`
* `OP_STRING16`
* `OP_LAMBDA16`
* `OP_BLOCK16`
* `OP_METHOD16`
* `OP_EXEC16`

Those instructions are no longer needed by reintroduction of extension instructions.

* `OP_SENDV`
* `OP_SENDVB`

Those instructions for method calls with variable number of arguments are no longer needed. They are covered by `OP_SEND` instruction with `n=15`.

## New Instructions

`mruby3.1` introduces following new instructions.

* `OP_GETIDX`: takes 2 operands `a[b]`
* `OP_SETIDX`: takes 3 operands `a[b]=c`
* `OP_SSEND`: takes 3 operands `a=self.b(c...)`; see `OP_SEND`
* `OP_SSENDB`: takes 3 operands `a=self.b(c...){...}`; see `OP_SEND`

### `OP_GETIDX` and `OP_SETIDX`

Execute `obj[int]` and `obj[int] = value` respectively, where `obj` is `string|array|hash`.

### `OP_SSEND` and `OP_SSENDB`

They are similar to `OP_SEND` and `OP_SENDB` respectively. They initialize the `R[a]` by `self` first so that we can skip one `OP_LOADSELF` instruction for each call.

## Changed Instructions

### `OP_SEND` and `OP_SENDB`

Method calling instructions are unified. Now `OP_SEND` and `OP_SENDB` (method call with a block) can support both splat arguments and keyword arguments as well.

The brief description of the instructions:

|`OP_SEND`   | BBB | `R(a) = call(R(a),Syms(b),R(a+1..n),R(a+n+1),R(a+n+2)..nk) c=n|nk<<4`                    |
|`OP_SENDB`  | BBB | `R(a) = call(R(a),Syms(b),R(a+1..n),R(a+n+1..nk),R(a+n+2..nk),&R(a+n+2*nk+2)) c=n|nk<<4` |

When `n == 15`, the method takes arguments packed in an array. When `nk == 15`, the method takes keyword arguments packed in a hash.

### `OP_ARYPUSH`

Now takes 2 operands and pushes multiple entries to an array.

## `String#hash` now use `FNV1a` algorithm

For better and faster hash values.