| 1 |
# User visible changes in `mruby3.0` |
| 2 |
|
| 3 |
# Build System |
| 4 |
|
| 5 |
## `build_config` directory |
| 6 |
|
| 7 |
Typical build configuration files are located in `build_config` |
| 8 |
directory. For examples: |
| 9 |
|
| 10 |
- `default`: the default configuration |
| 11 |
- `host-gprof`: compiles with `gprof` for performance tuning |
| 12 |
- `host-m32`: compiles in gcc 32bit mode on 64bit platforms |
| 13 |
- `boxing`: compiles all three boxing options |
| 14 |
- `clang-asan`: compiles with `clang`'s Address Sanitizer |
| 15 |
|
| 16 |
You can specify the build configuration file with the |
| 17 |
`MRUBY_CONFIG` environment variable (or `CONFIG` in short). |
| 18 |
If the value specified by `MRUBY_CONFIG` is not the path to |
| 19 |
the configuration file, `build_config/${MRUBY_CONFIG}.rb` is |
| 20 |
used. So you can specify it as `rake MRUBY_CONFIG=boxing`, |
| 21 |
for example. |
| 22 |
|
| 23 |
# Build Configuration Contribution |
| 24 |
|
| 25 |
When you write a new build configuration description, please |
| 26 |
contribute. We welcome your contribution as a GitHub |
| 27 |
pull-request. |
| 28 |
|
| 29 |
# Language Changes |
| 30 |
|
| 31 |
## New Syntax |
| 32 |
|
| 33 |
We have ported some new syntax from CRuby. |
| 34 |
|
| 35 |
- Single line pattern matching (`12 => x`); |
| 36 |
mruby matches only with local variables at the moment |
| 37 |
- Numbered block parameter (`x.map{_1 * 2}`) |
| 38 |
- End-less `def` (`def double(x) = x*2`) |
| 39 |
|
| 40 |
# Configuration Options Changed |
| 41 |
|
| 42 |
## Renamed for consistency |
| 43 |
|
| 44 |
Some configuration macro names are changed for consistency (use `MRB_USE_XXX` |
| 45 |
or `MRB_NO_XXX`). |
| 46 |
|
| 47 |
| mruby2 | mruby3 | |
| 48 |
|--------------------------------|---------------------------| |
| 49 |
| `MRB_ENABLE_ALL_SYMBOLS` | `MRB_USE_ALL_SYMBOLS` | |
| 50 |
| `MRB_ENABLE_CXX_ABI` | `MRB_USE_CXX_ABI` | |
| 51 |
| `MRB_ENABLE_CXX_EXCEPTION` | `MRB_USE_CXX_EXCEPTION` | |
| 52 |
| `MRB_ENABLE_DEBUG_HOOK` | `MRB_USE_DEBUG_HOOK` | |
| 53 |
| `MRB_DISABLE_DIRECT_THREADING` | `MRB_NO_DIRECT_THREADING` | |
| 54 |
| `MRB_DISABLE_STDIO` | `MRB_NO_STDIO` | |
| 55 |
| `MRB_METHOD_T_STRUCT` | `MRB_USE_METHOD_T_STRUCT` | |
| 56 |
| `MRB_USE_FLOAT` | `MRB_USE_FLOAT32` | |
| 57 |
| `MRB_WITHOUT_FLOAT` | `MRB_NO_FLOAT` | |
| 58 |
| `ENABLE_LINENOISE` | `MRB_USE_LINENOISE` | |
| 59 |
| `ENABLE_READLINE` | `MRB_USE_READLINE` | |
| 60 |
| `DISABLE_MIRB_UNDERSCORE` | `MRB_NO_MIRB_UNDERSCORE` | |
| 61 |
|
| 62 |
- `MRB_USE_FLOAT32` is changed from `MRB_USE_FLOAT` to make sure `float` here |
| 63 |
means using single-precision float, and not the opposite of `MRB_NO_FLOAT`. |
| 64 |
- `MRB_USE_METHOD_T_STRUCT` uses `struct` version of `mrb_method_t`. More |
| 65 |
portable but consumes more memory. Turned on by default on 32bit platforms. |
| 66 |
- `MRB_` prefix is added to those without. |
| 67 |
|
| 68 |
## `MRB_NO_BOXING` |
| 69 |
|
| 70 |
Uses `struct` to represent `mrb_value`. Consumes more memory |
| 71 |
but easier to investigate the internal and to debug. It used |
| 72 |
to be default `mrb_value` representation. Now the default is |
| 73 |
`MRB_WORD_BOXING`. |
| 74 |
|
| 75 |
## `MRB_WORD_BOXING` |
| 76 |
|
| 77 |
Pack `mrb_value` in an `intptr_t` integer. Consumes less |
| 78 |
memory compared to `MRB_NO_BOXING` especially on 32-bit |
| 79 |
platforms. `Fixnum` size is 31 bits so some integer values |
| 80 |
does not fit in `Fixnum` integers. |
| 81 |
|
| 82 |
## `MRB_NAN_BOXING` |
| 83 |
|
| 84 |
Pack `mrb_value` in a floating-point number. Nothing |
| 85 |
changed from previous versions. |
| 86 |
|
| 87 |
## `MRB_USE_MALLOC_TRIM` |
| 88 |
|
| 89 |
Call `malloc_trim(0)` from mrb_full_gc() if this macro is defined. |
| 90 |
If you are using glibc malloc, this macro could reduce memory consumption. |
| 91 |
|
| 92 |
# Command Line Program |
| 93 |
|
| 94 |
## `bin/mruby` (by mrbgems/mruby-bin-mruby) |
| 95 |
|
| 96 |
The mruby3 now automatically detects `*.mrb` files without the `-b` |
| 97 |
switch. Therefore, it can be mixed with the `*.rb` file in combination |
| 98 |
with the `-r` switch and specified at the same time. |
| 99 |
Here's an example that works fine: |
| 100 |
|
| 101 |
```console |
| 102 |
$ bin/mruby app.mrb |
| 103 |
$ bin/mruby -r lib1.mrb -r lib2.rb app.rb |
| 104 |
$ bin/mruby -r lib1.rb -r lib2.rb < app.mrb |
| 105 |
``` |
| 106 |
|
| 107 |
# Internal Changes |
| 108 |
|
| 109 |
## New Instructions |
| 110 |
|
| 111 |
`mruby3` introduces a few new instructions. |
| 112 |
|
| 113 |
Instructions that access pool[i]/syms[i] where i>255. |
| 114 |
|
| 115 |
- `OP_LOADL16` |
| 116 |
- `OP_STRING16` |
| 117 |
- `OP_LOADSYM16` |
| 118 |
|
| 119 |
Instructions that load a 32-bit integer. |
| 120 |
|
| 121 |
- `OP_LOADI32` |
| 122 |
|
| 123 |
Instruction that unwinds jump table for rescue/ensure. |
| 124 |
|
| 125 |
- `OP_JMPUW` |
| 126 |
|
| 127 |
Renamed from `OP_RAISE` |
| 128 |
|
| 129 |
- `OP_RAISEIF` |
| 130 |
|
| 131 |
Instruction that is reserved for the future keyword argument support. |
| 132 |
|
| 133 |
- OP_SENDVK |
| 134 |
|
| 135 |
## Removed Instructions |
| 136 |
|
| 137 |
Instructions for old exception handling |
| 138 |
|
| 139 |
- `OP_ONERR` |
| 140 |
- `OP_POPERR` |
| 141 |
- `OP_EPUSH` |
| 142 |
- `OP_EPOP` |
| 143 |
|
| 144 |
No more operand extension |
| 145 |
|
| 146 |
- `OP_EXT1` |
| 147 |
- `OP_EXT2` |
| 148 |
- `OP_EXT3` |
| 149 |
|
| 150 |
## Changed Instructions |
| 151 |
|
| 152 |
Jump addresses used to be specified by absolute offset from the start of `iseq`. Now they are relative offset from the address of the next instruction. |
| 153 |
|
| 154 |
## `Random` now use `xoshiro128++`. |
| 155 |
|
| 156 |
For better and faster random number generation. |
| 157 |
|
| 158 |
## Preallocated Symbol |
| 159 |
|
| 160 |
Preallocated symbols are interned at compile-time. They can be accessed via symbols macros (e.g. `MRB_SYM()`). |
| 161 |
|
| 162 |
See [Symbols](guides/symbol.md). |