Commit Graph

11786 Commits

Author SHA1 Message Date
Yukihiro "Matz" Matsumoto 72d071540c Rename MRB_METHOD_T_STRUCT to MRB_USE_METHOD_T_STRUCT.
It's the first change of renaming configuration options to `MRB_XXX` to
`MRB_USE_XXX` or `MRB_NO_XXX`.
2020-10-12 16:21:38 +09:00
Yukihiro "Matz" Matsumoto dea185e687 Change out-of-range condition of time_t conversion. 2020-10-12 16:21:38 +09:00
Yukihiro "Matz" Matsumoto 968053a35b Avoid out-of-range error for negative time on MRB_TIME_T_UINT.
On platforms where `time_t` is unsigned, negative time can be a result
of integer casting. Out-of-range error is too strict for those cases.
This fix does not address wrong time value in `MRB_WORD_BOXING`. It will
be addressed later (by introducing "big" integers).
2020-10-12 16:21:37 +09:00
Yukihiro "Matz" Matsumoto 66114f8332 Change default mrb_value representation to MRB_WORD_BOXING. 2020-10-12 16:21:37 +09:00
Yukihiro "Matz" Matsumoto 8813ebec07 Skip array embedding if MRB_NO_BOXING and MRB_32BIT; fix #4382
On some platforms, `sizeof(mrb_value) > sizeof(void*)*3`, which makes
`MRB_ARY_EMBED_LEN_MAX` zero. And zero sized array cause compile errors.
2020-10-12 16:21:36 +09:00
Yukihiro "Matz" Matsumoto a93ef815be Add static check for MRB_USE_FLOAT and MRB_WITHOUT_FLOAT. 2020-10-12 16:21:36 +09:00
Yukihiro "Matz" Matsumoto 905d4010bf Fix wrong YAML in .github/workflows/build.yml. 2020-10-12 16:21:36 +09:00
Yukihiro "Matz" Matsumoto 763b39d00b Simplify NaN boxing definitions.
Remove `#ifdef` from `union mrb_value_`.
2020-10-12 16:21:35 +09:00
Yukihiro "Matz" Matsumoto 107c777341 Rename OP_JUW instruction to OP_JMPUW. 2020-10-12 16:21:35 +09:00
Yukihiro "Matz" Matsumoto 500f721f70 Fix typo _hander -> _handler. 2020-10-12 16:21:34 +09:00
Yukihiro "Matz" Matsumoto cb89e1f0d9 Adjust PR #5060 to the latest mruby3 branch. 2020-10-12 16:21:34 +09:00
dearblue 6bc5857125 Suppress warnings for C++
Variables in jump destination block separate declaration and assignment.
2020-10-12 16:21:34 +09:00
dearblue bfb7b491cc Restore the variable pc after longjmp()
Changes made after `setjmp()` are destroyed and need reassignment.
This problem is now caused by the addition of the `OP_JUW` instruction.

When actually building on FreeBSD 12.1 with `clang10 -fsanitize=address`, mrbtest "NameError#name [15.2.31.2.1]" is failed.

However, qualifying `pc` with `volatile` slows down significantly and increases the object code.
Suppress them by qualifying only the variables that restore `pc`.
2020-10-12 16:21:33 +09:00
dearblue c1f112c49a Replace global jump with catch handler implementation
When a global jump occurs, look at the catch handler table to determine where to jump.
In that case, `pc` already shows the following instruction, but since the table shows `begin_offset ... end_offset`, the comparison is done with `begin_offset < pc && pc <= end_offset`.
If there is a corresponding handler, move `pc` to `handler.target_offset` and continue running the VM.

When a global jump across `ensure` is made by `return`, `break`, `next`, `redo` and `retry`, the extended `RBreak` object saves and restores the C-level execution position.
This extended `RBreak` can have tag information, which makes it a pseudo coroutine (the "tag" mimics CRuby).

The implementation of pseudo coroutines by `RBreak` is summarized by `CHECKPOINT_RESTORE ... CHECKPOINT_MAIN ... CHECKPOINT_END` and `throw_tagged_break` / `unwind_ensure` macros.
The restart of processing is branched by `RBREAK_TAG_FOREACH(DISPATCH_CHECKPOINTS)`.

- Not only `rescue` blocks but also `ensure` blocks are now sandwiched between `OP_EXCEPT` and `OP_RAISEIF`.

- Remove the function `ecall()`.
  It is no longer necessary to re-enter the VM to perform an "ensure block".

  This will resolves #1888.

- Added instruction `OP_JUW` (Jump while UnWind).

  It jumps unconditionally like `OP_JMP`, but searches the catch handler table and executes the ensure block.
  Since it searches the catch handler table, it is much heavier than `OP_JMP`.
2020-10-12 16:21:33 +09:00
dearblue 0d7b4deccf Removed push/pop instructions for rescue/ensure
`OP_PUSHERR`, `OP_POPERR`, `OP_EPUSH` and `OP_EPOP` are removed.
2020-10-12 16:21:32 +09:00
dearblue f467b02d45 Extended OP_EXCEPT and OP_RAISE (OP_RAISEIF) instructions
- `OP_EXCEPT` checks if `mrb->exc` is `NULL`, `MRB_TT_EXCEPTION` or
  `MRB_TT_BREAK`.
  If `mrb->exc` is `NULL`, it will be replaced with `nil`.

- If `OP_RAISE` is `nil`, it does nothing and the immediately
  following instruction is executed (like `OP_NOP`).
  Also, in case of `RBreak` object, it moves to the processing for
  `break`.
  With this change, the instruction name is changed from
  `OP_RAISE` to `OP_RAISEIF`.
2020-10-12 16:21:32 +09:00
dearblue a54a3df32c Extended mruby binary format
The catch handler table is combined with iseq block.
This is to prevent the structure from growing by adding a field for the
catch handler table to the `mrb_irep` structure.

"iseq block" and "catch handler table":
  [number of catch handler table (2 bytes)]
  [number of byte code (4 bytes)]
  [iseq (any bytes)]
  [catch handlers (multiple of 7 bytes)]

catch handler:
  [catch type (1 byte)]
  [begin offset (2 bytes)]
  [end offset (2 bytes)]
  [target offset (2 bytes)]

catch type: enum mrb_catch_type (0 = rescue, 1 = ensure)
begin offset: Includes the specified instruction address
end offset: Does not include the specified instruction address
target offset: replaces pc with the specified instruction address

This table is not expanded by `read_irep_record_1()`.
The necessary elements are expanded one by one when used.
2020-10-12 16:21:32 +09:00
Yukihiro "Matz" Matsumoto 3ad6bbc40c Add target/host-cxx.rb to compile mruby with cxx_abi. 2020-10-12 16:21:31 +09:00
Yukihiro "Matz" Matsumoto 67d92c48b5 Avoid breaking the result array by side-effect in C++. 2020-10-12 16:21:31 +09:00
Yukihiro "Matz" Matsumoto 6fbc03b3a8 Revert 4c001673b
Probably I misunderstand strict aliasing rule of C++. The fix in
4c001673b was other way around.
2020-10-12 16:21:30 +09:00
Yukihiro "Matz" Matsumoto 690cafe274 Initialize kdict in OP_ENTER in vm.c. 2020-10-12 16:21:30 +09:00
Yukihiro "Matz" Matsumoto 4e56e0defc Rename union mrb_value to union mrb_value_.
Since some compiler complains when we `typedef` `mrb_value`.
2020-10-12 16:21:30 +09:00
Yukihiro "Matz" Matsumoto 53e46be7e2 Simplify mrb_value structure for MRB_WORD_BOXING. 2020-10-12 16:21:29 +09:00
Yukihiro "Matz" Matsumoto 73e289c54e Simplify mrb_value structure for MRB_NAN_BOXING. 2020-10-12 16:21:29 +09:00
Yukihiro "Matz" Matsumoto ce372122ed Remove mc_clear_by_id.
Clearing all method cache using `memset` is faster than conditional
clear by method id.
2020-10-12 16:21:28 +09:00
Yukihiro "Matz" Matsumoto a733c6e0ea Do not call mrb_mc_clear_by_class at mrb finalization. 2020-10-12 16:21:28 +09:00
Yukihiro "Matz" Matsumoto 425b142168 Refine MRB_NAN_BOXING on 32bit architecture.
You don't need pointer tweaking on 32bit architecture, where pointers
fit in 32bit (lower half of mrb_value).
2020-10-12 16:21:27 +09:00
Yukihiro "Matz" Matsumoto f751c28ca4 Add target/host-m32.rb to compile mruby in 32bit mode.
Tested only on Linux. You need to install 32bit relate libraries,
e.g. libc6-dev-i386.
2020-10-12 16:21:27 +09:00
Yukihiro "Matz" Matsumoto 4281429412 Use memset() to clear method cache. 2020-10-12 16:21:27 +09:00
Yukihiro "Matz" Matsumoto 0e50ea90f3 Add const specifier to cipush(); ref #5052 2020-10-12 16:21:26 +09:00
Yukihiro "Matz" Matsumoto 1eb71b008f Change default boxing scheme from MRB_NO_BOXING.
On 64bit platforms: `MRB_NAN_BOXING`
On 32bit platforms: `MRB_WORD_BOXING`
On debugging: `MRB_NO_BOXING`
2020-10-12 16:21:26 +09:00
Yukihiro "Matz" Matsumoto 84a68ca5ae Make sure bintest only works with host target. 2020-10-12 16:21:26 +09:00
Yukihiro "Matz" Matsumoto 5e9dc72bc5 Pack mrb_value into uint64_t when MRB_NAN_BOXING. 2020-10-12 16:21:25 +09:00
Yukihiro "Matz" Matsumoto 1eacdae319 Use hash table instead of segment list for instance variables. 2020-10-12 16:21:25 +09:00
Yukihiro "Matz" Matsumoto 59b35250cc Rename mrb_hash_modify to hash_modify.
Since it's an internal static function.
2020-10-12 16:21:24 +09:00
Yukihiro "Matz" Matsumoto 2b45d454bc Use mrb_field_write_barrier instead of mrb_write_barrier for push.
When the array is very big, the simpler `mrb_write_barrier` causes
calling `gc_mark_children` for big arrays repeatedly. That would hinder
performance very badly.
2020-10-12 16:21:24 +09:00
Yukihiro "Matz" Matsumoto ff0e3bcea6 Check lv before printing local variable names. 2020-10-12 16:21:24 +09:00
Yukihiro "Matz" Matsumoto 8b3f3c0bf3 Fix the bug by the combination with MRB_64BIT and MRB_INT32.
Which is caused by `MRB_NAN_BOXING`.
2020-10-12 16:21:23 +09:00
Yukihiro "Matz" Matsumoto cf2aabdad6 Run tests for target/boxing.rb. 2020-10-12 16:21:23 +09:00
Yukihiro "Matz" Matsumoto 3d8a38bea4 You don't need to keep index in local variables info in irep. 2020-10-12 16:21:22 +09:00
Yukihiro "Matz" Matsumoto 639946a006 Enable method cache by default.
Introduced `MRB_NO_METHOD_CACHE` which is inverse of `MRB_METHOD_CACHE`
that should be enabled intestinally. In addition, the default cache is
made bigger (128 -> 256).
2020-10-12 16:21:22 +09:00
Yukihiro "Matz" Matsumoto fb5e8ab6d5 Provide a new build target host-gprof that enables profiling. 2020-10-12 16:21:21 +09:00
Yukihiro "Matz" Matsumoto 11955ca1a1 Call #initialize_copy from init_copy only if it's redefined. 2020-10-12 16:21:21 +09:00
Yukihiro "Matz" Matsumoto 52dd0a8cd7 Skip mrb_get_args() in mrb_ary_push(). 2020-10-12 16:21:21 +09:00
Yukihiro "Matz" Matsumoto 6db0162ec7 Upgrade RITE_VM_VERSION to 0300 (means mruby 3.0). 2020-10-12 16:21:20 +09:00
Yukihiro "Matz" Matsumoto dec34d6c7b Split MRB_BINARY_FORMAT to major and minor.
The minor versions should be upper compatible. So mere opcode, section
addition can be done without breaking compiled binary.
2020-10-12 16:21:20 +09:00
Yukihiro "Matz" Matsumoto 8f0ac27196 Update opcode reference and comment.
- no OP_EXT_ anymore
- OP_LOADI16 in right position
2020-10-12 16:21:19 +09:00
Yukihiro "Matz" Matsumoto fd10c72319 Remove OP_EXT[123] from operands. 2020-10-12 16:21:19 +09:00
Yukihiro "Matz" Matsumoto ce7508e0d5 Allow rescue modifier in endless method definitions. 2020-10-12 16:21:19 +09:00
Yukihiro "Matz" Matsumoto c29212cf44 Implement endless-def as in CRuby [Feature#16746]. 2020-10-12 16:21:18 +09:00