| 1 |
# mruby configuration macros |
| 2 |
|
| 3 |
## The configuration file |
| 4 |
|
| 5 |
You can do the build configuration in the build configuration file. The default |
| 6 |
configuration file is `build_config/default.rb`. |
| 7 |
|
| 8 |
You can specify your own configuration file by the `MRUBY_CONFIG` environment |
| 9 |
variable (you can use `CONFIG` for shorthand for `MRUBY_CONFIG`). If the path |
| 10 |
doesn't exist, `build_config/${MRUBY_CONFIG}.rb` is used. |
| 11 |
|
| 12 |
## How to use these macros |
| 13 |
|
| 14 |
Just add the configuration value to the `MRuby::Build#defines` attribute. |
| 15 |
This is the same for `MRuby::CrossBuild`. |
| 16 |
|
| 17 |
```ruby |
| 18 |
# build_config.rb |
| 19 |
|
| 20 |
MRuby::Build.new do |conf| |
| 21 |
... |
| 22 |
conf.defines << 'MRB_GC_FIXED_ARENA' |
| 23 |
conf.defines << 'MRB_NO_METHOD_CACHE' |
| 24 |
... |
| 25 |
end |
| 26 |
``` |
| 27 |
|
| 28 |
***NOTE*** |
| 29 |
|
| 30 |
- Use common definitions (`conf.defines`) instead of per-compiler definitions (e.g., `conf.cc.defines`) unless there is a special reason not to. |
| 31 |
- It is now deprecated to edit the `include/mruby/mrbconf.h` file or give it directly as a compiler flag, as was the case before. |
| 32 |
|
| 33 |
## stdio setting |
| 34 |
|
| 35 |
`MRB_NO_STDIO` |
| 36 |
|
| 37 |
- When defined `<stdio.h>` functions won't be used. |
| 38 |
- Some features will be disabled when this is enabled: |
| 39 |
- `mrb_irep` load/dump from/to file. |
| 40 |
- Compiling mruby script from a file. |
| 41 |
- Printing features in **src/print.c**. |
| 42 |
|
| 43 |
## Debug macros |
| 44 |
|
| 45 |
`MRB_USE_DEBUG_HOOK` |
| 46 |
|
| 47 |
- When defined code fetch hook and debug OP hook will be enabled. |
| 48 |
- When using any of the hook set function pointer `code_fetch_hook` and/or `debug_op_hook` of `mrb_state`. |
| 49 |
- Fetch hook will be called before any OP. |
| 50 |
- Debug OP hook will be called when dispatching `OP_DEBUG`. |
| 51 |
|
| 52 |
`MRB_DEBUG` |
| 53 |
|
| 54 |
- When defined `mrb_assert*` macro will be defined with macros from `<assert.h>`. |
| 55 |
- Could be enabled via `enable_debug` method of `MRuby::Build`. |
| 56 |
|
| 57 |
## Stack configuration |
| 58 |
|
| 59 |
`MRB_STACK_EXTEND_DOUBLING` |
| 60 |
|
| 61 |
- If defined doubles the stack size when extending it. |
| 62 |
- Otherwise extends stack with `MRB_STACK_GROWTH`. |
| 63 |
|
| 64 |
`MRB_STACK_GROWTH` |
| 65 |
|
| 66 |
- Default value is `128`. |
| 67 |
- Used in stack extending. |
| 68 |
- Ignored when `MRB_STACK_EXTEND_DOUBLING` is defined. |
| 69 |
|
| 70 |
`MRB_STACK_MAX` |
| 71 |
|
| 72 |
- Default value is `0x40000 - MRB_STACK_GROWTH`. |
| 73 |
- Raises `RuntimeError` when stack size exceeds this value. |
| 74 |
|
| 75 |
## Primitive type configuration |
| 76 |
|
| 77 |
`MRB_USE_FLOAT32` |
| 78 |
|
| 79 |
- When defined single-precision floating-point type(C type `float`) is used as `mrb_float`. |
| 80 |
- Otherwise, double-precision floating-point type(C type `double`) is used as `mrb_float`. |
| 81 |
|
| 82 |
`MRB_NO_FLOAT` |
| 83 |
|
| 84 |
- When defined removes floating-point numbers from mruby. |
| 85 |
- It makes mruby easier to handle in "Micro-controller without FPU" and "Kernel Space". |
| 86 |
|
| 87 |
`MRB_INT32` |
| 88 |
|
| 89 |
- When defined, or `MRB_INT64` are not defined on 32-bit CPU mode, `mrb_int` will be defined as `int32_t`. |
| 90 |
- Conflicts with `MRB_INT64`. |
| 91 |
|
| 92 |
`MRB_INT64` |
| 93 |
|
| 94 |
- When defined, or `MRB_INT32` are not defined on 64-bit CPU mode, `mrb_int` will be defined as `int64_t`. |
| 95 |
- Conflicts with `MRB_INT32`. |
| 96 |
|
| 97 |
## Garbage collector configuration |
| 98 |
|
| 99 |
`MRB_GC_STRESS` |
| 100 |
|
| 101 |
- When defined full GC is emitted per each `RBasic` allocation. |
| 102 |
- Mainly used in memory manager debugging. |
| 103 |
- If defined at the same time as `MRB_DEBUG`, full GC is emitted also per each heap allocation (`mrb_malloc()` or etc.). |
| 104 |
This configuration slows down mruby execution by a factor of 2 to 3 or even more. |
| 105 |
|
| 106 |
`MRB_GC_TURN_OFF_GENERATIONAL` |
| 107 |
|
| 108 |
- When defined turns generational GC by default. |
| 109 |
|
| 110 |
`MRB_GC_FIXED_ARENA` |
| 111 |
|
| 112 |
- When defined used fixed size GC arena. |
| 113 |
- Raises `RuntimeError` when this is defined and GC arena size exceeds `MRB_GC_ARENA_SIZE`. |
| 114 |
- Useful tracking unnecessary mruby object allocation. |
| 115 |
|
| 116 |
`MRB_GC_ARENA_SIZE` |
| 117 |
|
| 118 |
- Default value is `100`. |
| 119 |
- Ignored when `MRB_GC_FIXED_ARENA` isn't defined. |
| 120 |
- Defines fixed GC arena size. |
| 121 |
|
| 122 |
`MRB_HEAP_PAGE_SIZE` |
| 123 |
|
| 124 |
- Defines value is `1024`. |
| 125 |
- Specifies number of `RBasic` per each heap page. |
| 126 |
- To calculate the number of bytes per heap page, it is "(size of management data per heap page) + (size per object) * `MRB_HEAP_PAGE_SIZE`". |
| 127 |
In mruby 3.1.0, the "size of management data per heap page" is 6 words, also "size per object" is 6 words. |
| 128 |
For a 32-bit CPU, `(6 * 4) + (6 * 4) * MRB_HEAP_PAGE_SIZE` gives the bytes of size per heap page. |
| 129 |
Conversely, for example, to keep the size per heap page to 4 Ki bytes, |
| 130 |
calculate `(4096 - (6 * 4)) / (6 * 4)` to specify `MRB_HEAP_PAGE_SIZE=169`. |
| 131 |
|
| 132 |
## Memory pool configuration |
| 133 |
|
| 134 |
`POOL_ALIGNMENT` |
| 135 |
|
| 136 |
- Default value is `4`. |
| 137 |
- If you're allocating data types that requires alignment more than default value define the |
| 138 |
largest value of required alignment. |
| 139 |
|
| 140 |
`POOL_PAGE_SIZE` |
| 141 |
|
| 142 |
- Default value is `16000`. |
| 143 |
- Specifies page size of pool page. |
| 144 |
- Smaller the value is increases memory overhead. |
| 145 |
|
| 146 |
## State atexit configuration |
| 147 |
|
| 148 |
`MRB_FIXED_STATE_ATEXIT_STACK` |
| 149 |
|
| 150 |
- If defined enables fixed size `mrb_state` atexit stack. |
| 151 |
- Raises `RuntimeError` when `mrb_state_atexit` call count to same `mrb_state` exceeds |
| 152 |
`MRB_FIXED_STATE_ATEXIT_STACK_SIZE`'s value. |
| 153 |
|
| 154 |
`MRB_FIXED_STATE_ATEXIT_STACK_SIZE` |
| 155 |
|
| 156 |
- Default value is `5`. |
| 157 |
- If `MRB_FIXED_STATE_ATEXIT_STACK` isn't defined this macro is ignored. |
| 158 |
|
| 159 |
## `mrb_value` configuration |
| 160 |
|
| 161 |
`MRB_ENDIAN_BIG` |
| 162 |
|
| 163 |
- If defined compiles mruby for big endian machines. |
| 164 |
- Used in `MRB_NAN_BOXING`. |
| 165 |
- Some mrbgem use this mrbconf. |
| 166 |
|
| 167 |
`MRB_NAN_BOXING` |
| 168 |
|
| 169 |
- If defined represent `mrb_value` in boxed `double`. |
| 170 |
- Conflicts with `MRB_USE_FLOAT32` and `MRB_NO_FLOAT`. |
| 171 |
|
| 172 |
`MRB_WORD_BOXING` |
| 173 |
|
| 174 |
- If defined represent `mrb_value` as a word. |
| 175 |
- If defined `Float` will be a mruby object with `RBasic`. |
| 176 |
|
| 177 |
## Reduce heap memory configuration |
| 178 |
|
| 179 |
`MRB_USE_ETEXT_RO_DATA_P` |
| 180 |
|
| 181 |
- Use `etext` and `edata` section addresses defined by the linker to detect read-only data. |
| 182 |
- Those addresses are widely available, but not portable, nor standardized. |
| 183 |
- This macro is defined by default on User-mode Linux. |
| 184 |
|
| 185 |
`MRB_NO_DEFAULT_RO_DATA_P` |
| 186 |
|
| 187 |
- Define this macro when the default `mrb_ro_data_p()` does not work for any reason. |
| 188 |
|
| 189 |
`MRB_USE_CUSTOM_RO_DATA_P` |
| 190 |
|
| 191 |
- Please try if `MRB_USE_LINK_TIME_RO_DATA_P` is not available. |
| 192 |
- The `mrb_ro_data_p()` function is implemented by the user in an arbitrary file. |
| 193 |
- The prototype declaration is `mrb_bool mrb_ro_data_p(const char *ptr)`. |
| 194 |
- Return `TRUE` if `ptr` is in the read-only section, otherwise return `FALSE`. |
| 195 |
|
| 196 |
## Other configuration |
| 197 |
|
| 198 |
`MRB_MALLOC_TRIM` |
| 199 |
|
| 200 |
- call malloc_trim(0) for each mrb_full_gc() call |
| 201 |
|
| 202 |
`MRB_UTF8_STRING` |
| 203 |
|
| 204 |
- Adds UTF-8 encoding support to character-oriented String instance methods. |
| 205 |
- If it isn't defined, they only support the US-ASCII encoding. |
| 206 |
|
| 207 |
`MRB_STR_LENGTH_MAX` |
| 208 |
|
| 209 |
- The maximum length of strings (default 1MB) |
| 210 |
- set this value to zero to skip the check |
| 211 |
|
| 212 |
`MRB_ARY_LENGTH_MAX` |
| 213 |
|
| 214 |
- The maximum length of strings (default 1MB) |
| 215 |
- set this value to zero to skip the check |
| 216 |
|
| 217 |
`MRB_FUNCALL_ARGC_MAX` |
| 218 |
|
| 219 |
- Default value is `16`. |
| 220 |
- Specifies 4th argument(`argc`) max value of `mrb_funcall`. |
| 221 |
- Raises `ArgumentError` when the `argc` argument is bigger then this value `mrb_funcall`. |
| 222 |
|
| 223 |
`KHASH_DEFAULT_SIZE` |
| 224 |
|
| 225 |
- Default value is `32`. |
| 226 |
- Specifies default size of khash table bucket. |
| 227 |
- Used in `kh_init_ ## name` function. |
| 228 |
|
| 229 |
`MRB_NO_METHOD_CACHE` |
| 230 |
|
| 231 |
- Disable method cache to save memory. |
| 232 |
|
| 233 |
`MRB_METHOD_CACHE_SIZE` |
| 234 |
|
| 235 |
- Default value is `256`. |
| 236 |
- Ignored if `MRB_NO_METHOD_CACHE` is defined. |
| 237 |
- Need to be the power of 2. |
| 238 |
|
| 239 |
`MRB_USE_METHOD_T_STRUCT` |
| 240 |
|
| 241 |
- Use C struct to represent `mrb_method_t` |
| 242 |
- No `MRB_USE_METHOD_T_STRUCT` requires highest 2 bits of function pointers to be zero |
| 243 |
- Define this macro on machines that use higher bits of pointers |
| 244 |
|
| 245 |
`MRB_USE_ALL_SYMBOLS` |
| 246 |
|
| 247 |
- Make it available `Symbol.all_symbols` in `mrbgems/mruby-symbol-ext` |
| 248 |
- Increase heap memory usage. |
| 249 |
|
| 250 |
`MRB_USE_VM_SWITCH_DISPATCH` |
| 251 |
|
| 252 |
- Turn on switch dispatch in VM loop |