summaryrefslogtreecommitdiffhomepage
path: root/src
AgeCommit message (Collapse)Author
2021-01-21Merge branch 'avoid-including-presym.inc-in-existing-header-files' of ↵Yukihiro "Matz" Matsumoto
https://github.com/shuujii/mruby into shuujii-avoid-including-presym.inc-in-existing-header-files
2021-01-20Remove CRC16 from dumped mruby binary.Yukihiro "Matz" Matsumoto
`calc_crc_16_ccitt()` consumes a lot of clock cycles in programs like `mrbtest` which loads a lot of dumped binary. Error detection for flaky channels should be done in the higher level. Note: `mruby/c` should be updated to support this change.
2021-01-18Fix that Hash may not contain any empty bucketsKOBAYASHI Shuji
The Hash implementation assumed that there were always empty buckets, but sometimes there were only active or deleted buckets (no empty buckets). Therefore, fix it so that this situation does not occur. ### Example ```ruby # example.rb class A attr_reader :v def initialize(v) @v = v end def ==(o) @v == o.v end def hash; @v end def to_s; "#{self.class}[#{@v}]" end alias eql? == alias inspect to_s end keys = (0..31).map{A.new(_1)} h = {} (0..16).each{h[keys[_1]] = _1} (17..31).each do k = keys[_1] h[k] = _1 h.delete(k) end p h.keys ``` #### Before this patch: ```console $ bin/mruby example.rb [A[0], A[1], A[2], A[3], A[4], A[5], A[6], A[7], A[8], A[9], A[10], A[11], A[12], A[13], A[14], A[15], A[16], A[30], A[31]] ``` #### After this patch: ```console $ bin/mruby example.rb [A[0], A[1], A[2], A[3], A[4], A[5], A[6], A[7], A[8], A[9], A[10], A[11], A[12], A[13], A[14], A[15], A[16]] ```
2021-01-17Fix `int_quo` to do float division; fix #5268Yukihiro "Matz" Matsumoto
2021-01-17Make `mrb_to_flo()` to convert objects, not integer, not float; #5268Yukihiro "Matz" Matsumoto
Thinking `Ratinal` and `Complex` in mind.
2021-01-16Fixed stack position of return value; ref #5272dearblue
When I `#call` the "proc" object created by the `mrb_proc_new_cfunc()` function from Ruby space, the return value did not go into the correct stack position. This can destroy the calling variable. This issue is now caused by #5272. sorry.
2021-01-12Merge branch 'reorganize-ci' of https://github.com/dearblue/mruby into ↵Yukihiro "Matz" Matsumoto
dearblue-reorganize-ci
2021-01-12Silence Windows warnings (cast and `setmode`).Yukihiro "Matz" Matsumoto
2021-01-12Save `NOARG` information in `struct mt_elem`; fix #5257Yukihiro "Matz" Matsumoto
2021-01-12Changed packing format of inline symbols.Yukihiro "Matz" Matsumoto
To make inline symbols packed in 30 bits.
2021-01-11Add missing cast in `ea_next_capa_for`KOBAYASHI Shuji
2021-01-11Avoid including `presym.inc` in existing header filesKOBAYASHI Shuji
Addressed an issue where existing programs linking `libmruby.a` could only be built by adding `<build-dir>/include` to compiler's include path.
2021-01-10Replace `tempirep` with `RProc`dearblue
Previously I used the `RData` object to avoid a memory leak in `mrb_irep` if `src/load.c` failed. ref: https://github.com/mruby/mruby/pull/4250 commit: f1523d24042ca3416dc5b9be7b3fc220ddaed896 Considering that the `RProc` object will be created in the subsequent process, it is preferable to create the `RProc` object from the beginning. Along with this, the inside of `read_irep()` is replaced with the processing centered on the `RProc` object. The global function that returns the `mrb_irep` pointer is still provided for compatibility.
2021-01-10Unified `pc` and `err` of `mrb_callinfo`dearblue
This enhances self-containment. - Changed the `mrb_callinfo::pc` field to point to itself. Previously it indicated the return destination of the previous call level. `mrb_callinfo::pc` will now hold the address to its own `proc->body.irep->iseq`. - Removed `mrb_callinfo::err` field. This is because `mrb_callinfo::pc - 1` is semantically the same as the previous `err`. - The `pc0` and `pc_save` variables in `mrb_vm_exec()` are no longer needed and have been deleted. - It removes the argument because `cipush()` doesn't need to save the previous `pc`.
2021-01-10Changes `stackent` to `stack` of `mrb_callinfo`dearblue
This enhances self-containment. Previously `mrb_context::stack` had the current call level stack, but now it owns it. The `mrb_context::stack` field, which is no longer needed, will be removed.
2021-01-10Unified `target_class` and `env` of `mrb_callinfo`dearblue
If there is `env`, `env->c` means `target_class`.
2021-01-09Detect invalid first byte of UTF-8 char; fix #5269Yukihiro "Matz" Matsumoto
The first byte of UTF-8 character should not be `80..c1`.
2021-01-09Remove unnecessary `#include` in generated filesKOBAYASHI Shuji
2021-01-08Reapply 116e128b because it is back at 456878baKOBAYASHI Shuji
2021-01-06Consider the case a local variable name does not become a named presymKOBAYASHI Shuji
Non-ASCII characters are allowed to local variable names, so they are not always named presym.
2021-01-06Merge branch 'improve-source-scanning-for-presym' of ↵Yukihiro "Matz" Matsumoto
https://github.com/shuujii/mruby into shuujii-improve-source-scanning-for-presym
2021-01-06Allow context switch from C using `mrb_fiber_resume()`.Yukihiro "Matz" Matsumoto
But you still cannot cross C function boundary.
2021-01-03Merge pull request #5255 from shuujii/avoid-64-bit-operations-in-src-hash.cYukihiro "Matz" Matsumoto
Avoid 64-bit operations in `src/hash.c`; close #5201
2021-01-03replace ; to : of OPT_SETGV in codedump.cKatsuyoshi Ito
Maybe it's a typo.
2021-01-03Avoid 64-bit operations in `src/hash.c`; close #5201KOBAYASHI Shuji
The idea of using `size_t` in `ea_next_capa_for` is by @dearblue.
2021-01-02Avoid double inclusion on `<mruby.h>`.Yukihiro "Matz" Matsumoto
2021-01-02Use Jenkins One At A Time Hash for `mrb_str_hash()`.Yukihiro "Matz" Matsumoto
2021-01-02Fixed wrong casting in `OP_LOADI32`.Yukihiro "Matz" Matsumoto
Negative integer `>-65535` had wrong value, e,g, `p(-40550)` printed `4294926746` since Nov. 2020, sigh.
2021-01-02Avoid `uint64_t` in string-to-integer conversion; ref #5201Yukihiro "Matz" Matsumoto
2021-01-02Reduce strength of the hash function; ref #5201Yukihiro "Matz" Matsumoto
Also avoid using `uint64_t`.
2021-01-02Refine "wrong number of arguments" message in `mrb_get_args`KOBAYASHI Shuji
#### Before this patch: ```ruby __send__ #=> wrong number of arguments {}.default(1,2) #=> wrong number of arguments ``` #### After this patch: ```ruby __send__ #=> wrong number of arguments (given 0, expected 1+) {}.default(1,2) #=> wrong number of arguments (given 2, expected 0..1) ```
2020-12-31Removed unusable `GC.test`dearblue
The substance of the method was removed in commit 15ceb35e058a078f632a1ff7d0d424c59d48cd80.
2020-12-29Refine error message from `mrb_get_arg1`KOBAYASHI Shuji
#### Before this patch: ```console $ bin/mruby -e '{}.key?' trace (most recent call last): -e:1: wrong number of arguments (ArgumentError) ``` #### After this patch: ```console $ bin/mruby -e '{}.key?' trace (most recent call last): -e:1: wrong number of arguments (given 0, expected 1) (ArgumentError) ```
2020-12-24Check integer overflow in float bit operations.Yukihiro "Matz" Matsumoto
2020-12-23Fix the integer overflow in `mrb_str_len_to_inum()`.Yukihiro "Matz" Matsumoto
2020-12-15Merge pull request #5223 from ↵Yukihiro "Matz" Matsumoto
shuujii/ensure-initialization-of-RVALUE_zero-in-mrb_obj_alloc Ensure initialization of `RVALUE_zero` in `mrb_obj_alloc`
2020-12-15refactor: remove trailing whitespace from C, Header, Ruby and YAML filesJohn Bampton
Lint
2020-12-15Ensure initialization of `RVALUE_zero` in `mrb_obj_alloc`KOBAYASHI Shuji
Union initialization initializes the first member. The first member of `RVALUE` is `struct free_obj`, but because it is only 4-words, it seems that initialization after the 5th word is not ensured. Therefore, I created 6-words `struct RVALUE_initializer` for initialization and made it the first member.
2020-12-13Fix spellingJohn Bampton
2020-12-13Improve source scanning for presymKOBAYASHI Shuji
The accuracy is greatly improved by using the C preprocessor to scan C sources for presym. C preprocessor can perfectly interpret all comments and preprocessor directives, so it can detect all symbols defined, for example `mrbgems/mruby-socket/src/const.cstub`. Also, as described later, this change will greatly improve the accuracy of presym detection from Ruby sources. ## Result The number of lines in the `presym` file for all gems is as follows: ```console Previous: 999 (false positive = 89, undetected = 297) New: 1207 ``` ## Build process The new build process (with presym) is as follows: 1. Build `mrbc` without presym (more on building without presym later). 2. Compile Ruby sources to C struct format with the `mrbc` created in step 1, and create` mrblib.c` and `gem_init.c`. Note that the symbols in the created files are output as `MRB_SYM` family macros or `mrb_intern_lit` instead of IDs (details will be described later). 3. C preprocessor processes C sources including the created files of step 2 and outputs them as `.i` files. In these files, for example, `MRB_IVSYM(foo)` is converted to `<@! "@" "foo" !@>` and `mrb_define_module(mrb, "Foo")` is converted to `<@! "Foo" !@>`. 4. Scan the files created in step 3 and create `presym` and` presym.inc` files. The files created in step 2 should output all static symbols defined in Ruby sources, including local variables, so we can detect all presyms by just scanning C sources without scanning Ruby sources directly. Further, by this process, the files to be scanned becomes the same as the files to be compiled, so that there is no excess or deficiency. ## Related changes The following changes have been made in relation to realizing this feature. ### Allow build without presym It enables build without presym to achieve the "Build process: 1". This incorporates #5202, see its issue for details. Note that when presym is enabled, even adding a local variable to a Ruby source may change contents of presym and require recompilation of almost all C sources. This is inconvenient, especially during trial and error in development, but this feature is also useful because it does not cause this problem if presym is disabled. ### Automatically create build target for `mrbc` without presym The `mrbc` used in the "Build process: 1" will be built by automatically creating a build target for it. The build name is `SOURCE_BUILD_NAME/mrbc`. ### Constantize output of C struct format by `mrbc` To realizing the "Build process: 2", as mentioned above, symbol IDs are not output directly in C struct format output by `mrbc`. As a result, the output becomes constant regardless of the state of presym at the time of `mrbc` build, and it is possible to detect symbols of Ruby sources in the same way as other C sources. Note that `mrb_intern_lit` is used for symbols that do not become presym, but in this state, the corresponding element in the symbol array cannot be statically initialized, so it is initialized at run time (therefore, in this case, the `const` qualifier is not added to the symbol array). ### Specify arbitrary `mrbc` file To realizing the "Build process: 2", enabled to specify `mrbc` created by another build target or pre-built` mrbc`. Use `MRuby::Build#mrbcfile =` to specify it explicitly. You can omit the "Build process: 1" by specifying pre-built `mrbc`, and you can always use an optimized build to compile Ruby sources faster. I think changes that affect the output of `mrbc` are rare, so in many cases it helps to improve efficiency. With presym, the build will be a little slower due to more build steps, but this feature will improve it a bit. ### Create presym files for each build target This feature was proposed at #5194 and merged once, but was reverted in 5c205e6e due to problems especially with cross-compilation. It has been introduced again because this change solves the problem. The presym files will be created below. * `build/NAME/presym` * `build/NAME/include/mruby/presym.inc` ### Other changes * Because presym detection accuracy is greatly improved as mentioned above, `MRuby::Gem::Specification#cdump?` is set to true by default, and `disable_cdump` is added instead of `enable_cdump`. Also, support for gem specific presym files has been discontinued (https://github.com/mruby/mruby/issues/5151#issuecomment-730967232). * Previously, `mrbc` was automatically created for the `host` build, but it will not be created if the build target for `mrbc` mentioned above is automatically created. At this time, `mrbc` file of the `mrbc` build is copied to` bin/`. * Two types of `.d` files will be created, `.o.d` and `.i.d`. oThis is because if `.i` depends on `presym.inc`, the dependency will circulate, so the `.d` file cannot be shared. * Changed file created with `enable_cxx_exception` to `X-cxx.cxx` from `X.cxx` to use the mruby standard Rake rule. ### Note Almost all C sources will need to be recompiled if there are any changes to `persym.inc` (if not recompiled properly, it will often result in run-time error). If `gcc` toolchain is used, dependencies are resolved by the `.d` file, so it become automatically recompile target, but if not (e.g. MSVC), it is necessary to manually make it recompile target. Also, even if `gcc` toolchain is used, it may not become recompile target if external gems does not use the mruby standard Rake rule. In particular, if the standard rule is overwritten, such as https://github.com/mruby/mruby/pull/5112/files, `.d` file will not be read, so be careful.
2020-12-12Remove positive check for unsigned integer; close #5218Yukihiro "Matz" Matsumoto
2020-12-07Make type of `pc` arguments in `debug.c` consistent; close #5218Yukihiro "Matz" Matsumoto
They used to be `size_t`, `uint32_t` and `ptrdiff_t`. Now all of them made to be `uint32_t`.
2020-12-05Fixed a bug with modules prepended many times.Yukihiro "Matz" Matsumoto
Adjust insertion point in `fix_prepend_module()`.
2020-12-04Make `Module#include` and `Module#prepend` behave like Ruby3.0.Yukihiro "Matz" Matsumoto
Module#include and Module#prepend now affect classes and modules that have already included or prepended the receiver, mirroring the behavior if the arguments were included in the receiver before the other modules and classes included or prepended the receiver. ```ruby class C; end module M1; end module M2; end C.include M1 M1.include M2 p C.ancestors #=> [C, M1, M2, Object, Kernel, BasicObject] ```
2020-12-02Print implicit operands for some instructions.Yukihiro "Matz" Matsumoto
2020-12-02Remove a newline.Yukihiro "Matz" Matsumoto
2020-12-01Revert "Create presym files for each build target" (58ba883e)KOBAYASHI Shuji
Due to the above changes, it may not work with the existing build configurations in cross-compilation (even if we can build without presym), therefore revert it once (ref https://github.com/mruby/mruby/pull/5202#issuecomment-735412643). Sorry for the lack of consideration.
2020-12-01Fix `OP_JMPUW` address bug.Yukihiro "Matz" Matsumoto
2020-11-30Merge pull request #5206 from dearblue/dumpirepYukihiro "Matz" Matsumoto
Improves dump irep
2020-11-30Integrate the output of the catch handler table into iseqdearblue
Alleviates confusingness. ref #5203