Compare commits

..

3834 Commits

Author SHA1 Message Date
mimaki 7d3bc5c3d7 Update version to 3.1.0RC2. 2022-03-31 15:17:17 +09:00
Yukihiro "Matz" Matsumoto f71d389649 codegen.c: fix the negative division regression; fix #5678 2022-03-31 13:05:06 +09:00
Yukihiro "Matz" Matsumoto eaadc5e79f parse.y: empty here-doc delimiter caused infinite loop; fix #5676 2022-03-31 13:01:27 +09:00
Yukihiro "Matz" Matsumoto c627e3b2ab codegen.c: fix a bug in super with keyword arguments; fix #5660 2022-03-31 13:00:34 +09:00
Yukihiro "Matz" Matsumoto 9424e4d4cf parse.y: revert 9e064f2; fix #5647
Need to declare unnamed parameter when argument decomposition used.
2022-03-31 12:59:44 +09:00
Yukihiro "Matz" Matsumoto 64d3f4c730 vm.c: need to adjust argument after packing keyword args; fix #5632
It was caused by #5628.
2022-03-31 12:58:48 +09:00
mimaki 6f2efebbb9 Merge commit '7e7f1b2' into stable 2022-01-17 21:36:52 +09:00
Yukihiro "Matz" Matsumoto 7e7f1b2f1d parse.y: numbered parameters should not appear on toplevel.
Toplevel includes the top of the method/class/module definitions.
2022-01-11 14:52:05 +09:00
Yukihiro "Matz" Matsumoto 3a30cc27da parse.y: move numbered parameter indexing to lexer. 2022-01-11 14:49:41 +09:00
Yukihiro "Matz" Matsumoto 5dfbfb3ecd parse.y: p->nvar (numbered argument index list) may be NULL. 2022-01-10 15:44:15 +09:00
Yukihiro "Matz" Matsumoto 8c7b995962 AUTHORS: update entries [ci skip] 2022-01-10 12:33:01 +09:00
Yukihiro "Matz" Matsumoto 69b1667b5b Merge pull request #5630 from dearblue/dumps
Fixes file header in src/{cdump,dump}.c [ci skip]
2022-01-09 21:46:40 +09:00
dearblue 178daf1a75 Fixes file header in src/{cdump,dump}.c [ci skip]
The file headers were pointing to each other's files.
2022-01-09 16:30:06 +09:00
mimaki f29924c838 Update version to 3.1.0RC. 2022-01-07 14:15:50 +09:00
Yukihiro "Matz" Matsumoto 696589cf27 Merge pull request #5628 from dearblue/super-kwargs
Fixing keyword arguments with `super`
2022-01-06 10:05:05 +09:00
Yukihiro "Matz" Matsumoto b1fc0dd5a4 Merge pull request #5629 from dearblue/nanbox
Allows handling of unaligned cptrs for `MRB_NAN_BOXING`
2022-01-06 10:02:49 +09:00
Yukihiro "Matz" Matsumoto dfa21f2e58 class.c: cancel #5620 which is no longer needed since #5622
This reverts commit d3b7601af9.
2022-01-05 19:40:55 +09:00
Yukihiro "Matz" Matsumoto aaa3bd0e80 mrbc.c: simplify place holder functions; #5622 2022-01-05 19:39:39 +09:00
Yukihiro "Matz" Matsumoto c088af87b8 object.c: Call functions directly from mrb_ensure_int_type(); #5622 2022-01-05 19:00:14 +09:00
dearblue 88b1654725 Allows handling of unaligned cptrs for MRB_NAN_BOXING
It seems to be preferable to be able to handle pointers of type `char` as well.
For this purpose, `mrb_nanbox_tt_inline` has been reorganized.

- `MRB_NANBOX_TT_POINTER` has been split into `MRB_NANBOX_TT_OBJECT` and `MRB_NANBOX_TT_CPTR`
- `MRB_NANBOX_TT_SYMBOL` has been merged into `MRB_NANBOX_TT_MISC`
2022-01-05 17:23:35 +09:00
dearblue 55b2e45a26 Fixing keyword arguments with super
fix #5627
2022-01-05 16:40:13 +09:00
Yukihiro "Matz" Matsumoto d34e1cb84c Merge pull request #5623 from dearblue/more-presym
Improves presym scanning
2022-01-04 11:54:09 +09:00
Yukihiro "Matz" Matsumoto 6c68b516ff Merge pull request #5624 from dearblue/powerof2
Assert that `MRB_METHOD_CACHE_SIZE` is a power of 2
2022-01-04 11:51:00 +09:00
Yukihiro "Matz" Matsumoto 5c75dc9edc Merge pull request #5625 from dearblue/proc_new
Assign after `mrb_irep_incref()` in `mrb_proc_new()`
2022-01-03 08:54:01 +09:00
Yukihiro "Matz" Matsumoto 4e0b162253 Merge pull request #5622 from dearblue/to_f
Call functions directly from `mrb_ensure_float_type()`
2022-01-02 18:04:18 +09:00
Yukihiro "Matz" Matsumoto ab4baba283 Merge pull request #5620 from dearblue/adjust-stacks
Adjusting the stack for after it enters the virtual machine
2022-01-02 18:01:53 +09:00
dearblue bee9665400 Assign after mrb_irep_incref() in mrb_proc_new()
ref. 28ccc664e5
2022-01-02 16:43:43 +09:00
dearblue 82a1b00eb6 Assert that MRB_METHOD_CACHE_SIZE is a power of 2
The `mrb_static_assert_powerof2()` macro has been introduced for this purpose.
2022-01-02 14:59:55 +09:00
dearblue f2d19aaaac Improves presym scanning
The main purpose is to increase the chances of finding presym and to prevent errors due to C++11 lambda expressions.

- The argument to receive the class may be written, for example, `mrb_class_get()`.
- The argument that receives the implementation function of the method may be a C++ lambda expression.
  In this case, if multiple variable declarations are separated by colons, the preprocessor will recognize them as argument delimiters and report an error.
  This patch prevents it from happening.

  ```c++
  // When preprocessing...
  func([] { int x, y, z; })
    // ^^^^^^^^^^          1st argument?
    //             ^       2nd argument?
    //                ^^^^ 3rd argument?
  ```
2022-01-02 11:52:19 +09:00
Yukihiro "Matz" Matsumoto 28ccc664e5 proc.c: should not reference irep when copying failed.
It may cause broken reference count numbers.
2022-01-01 21:02:58 +09:00
dearblue ac22a63ae3 Call functions directly from mrb_ensure_float_type()
ref. commit 7f40b645d2

Currently, the build configurations `MRB_USE_COMPLEX` and `MRB_USE_RATIONAL` are not listed in the documentation.
In other words, they are hidden settings.
They are defined in `mrbgems/mruby-{complex,rational}/mrbgem.rake`.
So this patch assumes that it is safe to refer to these functions in core-gems directly from core functions.

However, applications that link with `libmruby_core.a` will have compatibility issues.
In fact, `mrbgems/mruby-bin-mrbc` links with `libmruby_core.a`, so I had to prepare a dummy function.
2021-12-31 19:12:11 +09:00
Yukihiro "Matz" Matsumoto 3de9ddfb39 vm.c: use prepare_missing in mrb_funcall_with_block
Remove code duplication.
2021-12-31 18:15:41 +09:00
Yukihiro "Matz" Matsumoto 5ca17c2dce Merge pull request #5621 from dearblue/ci-cygwin
Extend the Cygwin CI time limit to 15 minutes.
2021-12-31 16:32:33 +09:00
Yukihiro "Matz" Matsumoto 9fc26eacd1 Merge pull request #5619 from dearblue/properties
Get object properties after `mrb_get_args()`
2021-12-31 15:28:11 +09:00
Yukihiro "Matz" Matsumoto b9e1b9b328 numeric.c: merge mrb_as_float implementation to mrb_ensure_float_type.
Since they are basically duplicated functionality. `mrb_as_float` is now
a macro defined using `mrb_ensure_float_type`; #5620
2021-12-31 15:14:37 +09:00
Yukihiro "Matz" Matsumoto 566a8d3fcb object.c: add conversion to Float from Rational, Complex; #5620 2021-12-31 15:13:04 +09:00
Yukihiro "Matz" Matsumoto 7f40b645d2 numeric.c: mrb_as_float should not call to_f for generic objects.
It should only call `to_f` for Rational and Complex numbers.
Ref #5540 #5613 #5620
2021-12-31 10:54:28 +09:00
Yukihiro "Matz" Matsumoto eea418bcce class.c, variable,c: replace size_t by int.
That reduce memory consumption by iv/mt tables.
2021-12-31 10:54:28 +09:00
dearblue 4c8a8818ec Extend the Cygwin CI time limit to 15 minutes.
The main reason for failure is to exceed the time limit, and even when it succeeds, there is less than a minute left.
The 10-minute time limit seems to be too short.
2021-12-30 22:58:41 +09:00
dearblue d3b7601af9 Adjusting the stack for after it enters the virtual machine
ref. #5613.

I mentioned in #5540 that there was no reentrant to the virtual machine, but in fact it was still a possibility at that point.
Also, the variable `ci` needs to be recalculated at the same time.
2021-12-30 22:45:19 +09:00
dearblue a137ef12f9 Get object properties after mrb_get_args()
ref. #5613

I checked with Valgrind, and the methods that can cause use-after-free are `Array#rotate`, `Array#rotate!`, and `String#byteslice`.
Since `String#rindex` uses `RSTRING_LEN()` indirectly inside the function, no reference to the out-of-bounds range is generated.
2021-12-30 22:34:22 +09:00
Yukihiro "Matz" Matsumoto 77f4a8b669 object.c: move string to float conversion to mrb_f_float. 2021-12-29 16:58:05 +09:00
Yukihiro "Matz" Matsumoto 66a099b1b3 string.c: reorganize str_convert_range using mrb_ensure_int_type 2021-12-29 16:44:35 +09:00
Yukihiro "Matz" Matsumoto b6d31810fe string.c: use mrb_as_int macro. 2021-12-29 16:39:56 +09:00
Yukihiro "Matz" Matsumoto 4f297ac29c object.c: introduce mrb_ensure_{int,float}_type.
Since `mrb_to_integer` and `mrb_to_float` does not convert the object
but checks types, they are named so by historical reason. We introduced
properly named functions.

This commit obsoletes the following functions:

* mrb_to_integer()
* mrb_to_int()
* mrb_to_float()

Use `mrb_ensure_int_type()` instead for the first 2 functions. Use
`mrb_ensure_float_type()` for the last.
2021-12-29 16:39:29 +09:00
Yukihiro "Matz" Matsumoto b6283978c5 object.c: avoid implicit to_i and to_f calls.
mruby have removed `to_int` implicit conversion, so `mrb_to_integer`
should not call `to_i` for conversion.
2021-12-29 16:21:29 +09:00
Yukihiro "Matz" Matsumoto 41e8b210b8 common.h: include <sys/types.h> for ssize_t; #5617 2021-12-29 15:57:45 +09:00
Yukihiro "Matz" Matsumoto 27d1e0132a array.c: fix mrb_ary_shift_m initialization bug.
The `ARY_PTR` and `ARY_LEN` may be modified in `mrb_get_args`.
2021-12-29 15:50:28 +09:00
Yukihiro "Matz" Matsumoto 83f2e75d17 Merge pull request #5616 from mimaki/refine-ssize_t-on-msvc
Fix build error and refine definition of `ssize_t` on MSVC.
2021-12-29 12:58:43 +09:00
mimaki 1f3a385ec5 Fix build error and refine definition of ssize_t on MSVC. 2021-12-28 17:18:59 +09:00
Yukihiro "Matz" Matsumoto 6f5c211c78 Merge pull request #5614 from jbampton/patch-1
Fix word casing in the README
2021-12-28 16:19:52 +09:00
Yukihiro "Matz" Matsumoto 8933a6fcbf Merge pull request #5615 from jbampton/pre-commit-autoupdate
pre-commit autoupdate
2021-12-28 16:19:14 +09:00
John Bampton 69affd6983 pre-commit autoupdate
https://pre-commit.com/#pre-commit-autoupdate
2021-12-28 10:28:14 +10:00
John Bampton c997229ecf Fix word casing in the README
Changed `Actual` to `actual` mid sentence
2021-12-28 10:22:20 +10:00
Yukihiro "Matz" Matsumoto 6de0fcbda2 class.c: remove mt_elem structure to avoid alignment gaps. 2021-12-27 11:15:34 +09:00
Yukihiro "Matz" Matsumoto a388d609ae variable.c: need to initialize size of iv table. 2021-12-27 10:55:17 +09:00
Yukihiro "Matz" Matsumoto 27e57aad0b parse.y: prohibit numbered parameters as arguments; fix #5605 2021-12-27 10:55:17 +09:00
Yukihiro "Matz" Matsumoto e6b6413932 Merge pull request #5612 from dearblue/compar-ext
Fix summary typo for `mrbgems/mruby-compar-ext`
2021-12-26 08:13:23 +09:00
dearblue 65195cd784 Fix summary typo for mrbgems/mruby-compar-ext 2021-12-25 20:46:25 +09:00
Yukihiro "Matz" Matsumoto 39191cd9fa parse.y: allow arguments start with _ to appear multiple times; fix #5604 2021-12-24 07:41:37 +09:00
Yukihiro "Matz" Matsumoto 3b59c95ead pack.c: check integer overflow in unpacking BER; fix #5611 2021-12-23 07:57:58 +09:00
Yukihiro "Matz" Matsumoto 42a6872c2b parse.y: adjust void_expr_error(); fix #5606
Allow void expression on some places e.g. right hand of `rescue`
modifier. In addition, checks added on some places, e.g. left hand of
logical operators.
2021-12-22 14:08:04 +09:00
Yukihiro "Matz" Matsumoto 4e8d376417 Merge pull request #5610 from mruby/dependabot/github_actions/github/super-linter-4.8.5
build(deps): bump github/super-linter from 4.8.4 to 4.8.5
2021-12-21 23:13:43 +09:00
dependabot[bot] 916fbcce2c build(deps): bump github/super-linter from 4.8.4 to 4.8.5
Bumps [github/super-linter](https://github.com/github/super-linter) from 4.8.4 to 4.8.5.
- [Release notes](https://github.com/github/super-linter/releases)
- [Changelog](https://github.com/github/super-linter/blob/main/docs/release-process.md)
- [Commits](https://github.com/github/super-linter/compare/v4.8.4...v4.8.5)

---
updated-dependencies:
- dependency-name: github/super-linter
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-12-21 14:11:38 +00:00
Yukihiro "Matz" Matsumoto 8a5f18a1d8 codegen.c: generate OP_SETIDX; close #5608
Note that the current implantation only calls `[]=` method. No
performance improvement. Just 2 bytes less byte code per assignment.
2021-12-20 17:46:57 +09:00
Yukihiro "Matz" Matsumoto a42b676ae9 vm.c: fix a half-baked implementation of OP_SETIDX; ref #5608 2021-12-20 17:45:10 +09:00
Yukihiro "Matz" Matsumoto 5774a7a38b codedump.c: adjust the position of local variable labels. 2021-12-20 17:44:31 +09:00
Yukihiro "Matz" Matsumoto a17955259e Merge pull request #5602 from dearblue/no-ext-ops
Add `bin/mrbc --no-ext-ops` switch
2021-12-19 19:11:51 +09:00
Yukihiro "Matz" Matsumoto d7812bd3d6 Merge pull request #5603 from dearblue/codegen_error
Print error before cleanup in `codegen_error()`
2021-12-18 19:42:31 +09:00
dearblue 26338fe640 Print error before cleanup in codegen_error()
Previously, it always pointed to the highest scope as the location of the error.

  - example code `code.rb`

    ```ruby
    huge_num = "1" + "0" * 300; eval <<CODE, nil, "test.rb", 1
    class Object
      module A
        #{huge_num}
      end
    end
    CODE
    ```

  - Before this patch

    ```console
    % bin/mruby code.rb
    test.rb:1: integer too big
    trace (most recent call last):
            [1] code.rb:1
    code.rb:1:in eval: codegen error (ScriptError)
    ```

  - After this patch

    ```console
    % bin/mruby code.rb
    test.rb:3: integer too big
    trace (most recent call last):
            [1] code.rb:1
    code.rb:1:in eval: codegen error (ScriptError)
    ```
2021-12-17 23:03:27 +09:00
dearblue 6b8582c95d Add bin/mrbc --no-ext-ops switch
Print an error if `OP_EXT[123]` is needed when generating mruby binary.
This may be useful for mruby/c.

Inspired by #5590.
2021-12-17 23:02:04 +09:00
Yukihiro "Matz" Matsumoto 9b65d0dc86 Merge pull request #5601 from mruby/dependabot/github_actions/actions/upload-artifact-2.3.1
build(deps): bump actions/upload-artifact from 2.2.4 to 2.3.1
2021-12-17 07:49:53 +09:00
dependabot[bot] a7aa0b1da2 build(deps): bump actions/upload-artifact from 2.2.4 to 2.3.1
Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 2.2.4 to 2.3.1.
- [Release notes](https://github.com/actions/upload-artifact/releases)
- [Commits](https://github.com/actions/upload-artifact/compare/v2.2.4...v2.3.1)

---
updated-dependencies:
- dependency-name: actions/upload-artifact
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-12-16 14:08:05 +00:00
Yukihiro "Matz" Matsumoto 57d93c4d76 string-ext.c: fix memory leak in tr_parse_pattern. 2021-12-16 11:39:35 +09:00
Yukihiro "Matz" Matsumoto 0fbdd71dcf boxing_nan.h: remove false description in the comment [ci skip]
Ref #5597
2021-12-15 23:07:34 +09:00
Yukihiro "Matz" Matsumoto a3d240c2ed Merge pull request #5599 from dearblue/loss-digits
Avoid losing the upper digits for mruby binary
2021-12-15 23:07:13 +09:00
Yukihiro "Matz" Matsumoto f5e10c5a79 proc.c: add mrb_state argument to mrb_proc_copy().
The function may invoke the garbage collection and it requires
`mrb_state` to run.
2021-12-14 13:35:18 +09:00
dearblue fa33a5bb0c Avoid losing the upper digits for mruby binary
- `rlen` keeps 16 bits.
- `ilen` keeps 32 bits.

Note that this change will break mruby binary format compatibility.
2021-12-13 22:58:57 +09:00
Yukihiro "Matz" Matsumoto 8a74b2a25d string-ext/string.c: fixed memory leak from tr on exception.
With some refactoring.

* `ret` argument is always non-nil, so no check needed.
* move allocation check right after malloc().
* simplify conditions.
2021-12-13 10:29:16 +09:00
Yukihiro "Matz" Matsumoto d01707d4cf benchmark/bm_ao_render.rb: enable specifying the size of the image. 2021-12-13 10:29:16 +09:00
Yukihiro "Matz" Matsumoto 7b84fd4ce8 variable.c: resurrect size member in iv_tbl.
The existence of this member reduces memory and execution time.
2021-12-13 10:29:15 +09:00
Yukihiro "Matz" Matsumoto 786156d48c class.c: increase first allocated page size. 2021-12-13 10:29:15 +09:00
Yukihiro "Matz" Matsumoto bd4268210e class.c: implement method cache (off by default). 2021-12-13 10:29:15 +09:00
Yukihiro "Matz" Matsumoto 523197c831 Merge pull request #5598 from dearblue/array-combinations
Add `Array#{repeated_combination,repeated_permutation}` methods
2021-12-13 10:28:50 +09:00
dearblue 586525f99a Add Array#{repeated_combination,repeated_permutation} methods
Ruby 1.9.2 feature.

ref: https://docs.ruby-lang.org/ja/3.1.0/method/Array/i/repeated_combination.html
ref: https://docs.ruby-lang.org/ja/3.1.0/method/Array/i/repeated_permutation.html
2021-12-12 21:28:03 +09:00
Yukihiro "Matz" Matsumoto 7349902d5b irep.h: c operand may require 16 bits for BSS operand type.
fix #5593
2021-12-09 14:28:47 +09:00
Yukihiro "Matz" Matsumoto d2a904c884 vm.c (check_method_noarg): the value at kidx may not be a hash. 2021-12-08 16:43:02 +09:00
Yukihiro "Matz" Matsumoto c593e3e30a vm.c: use check_method_noarg() to reduce code duplication; ref #5584 2021-12-08 16:42:23 +09:00
Yukihiro "Matz" Matsumoto 5bad1c7429 vm.c: fix mrb_ci_kidx.
It used to return wrong value for 14 positional arguments.
2021-12-08 16:22:24 +09:00
Yukihiro "Matz" Matsumoto 0b6b042fe8 variable.c: fix clang integer warning. 2021-12-08 13:27:10 +09:00
Yukihiro "Matz" Matsumoto 47092ccfa5 mruby-compiler/mrbgem.rake: fix regexp pattern; close #5591 2021-12-07 23:57:32 +09:00
Yukihiro "Matz" Matsumoto 9935cf1aef variable.c: avoid redundant iv scan in mrb_mod_cv_set().
Now `iv_get()` returns `pos+1` if it finds the entry, so you don't need
to call `iv_put()`. You can replace the entry value by assigning to
`t->ptr[pos-1]`.
2021-12-07 08:19:16 +09:00
Yukihiro "Matz" Matsumoto 856ae52021 bm_ao_rendar.rb: use instance variables instead of class variables.
Class variables are slower than instance variables of classes.
2021-12-06 21:12:23 +09:00
Yukihiro "Matz" Matsumoto e5810db1ad variable.c: reduce array access in iv hash table. 2021-12-04 10:43:58 +09:00
Yukihiro "Matz" Matsumoto 9d554017f0 variable.c: avoid mrb_undef_value() for delete entries.
Instead embed deleted flag in the key (`mrb_sym` only occupies 30bits).
2021-12-03 18:36:29 +09:00
Yukihiro "Matz" Matsumoto 4f2a153ada variable.c: remove size member from iv_tbl to reduce memory.
`iv_size()` is approximated by the allocated table size.
2021-12-03 16:06:25 +09:00
Yukihiro "Matz" Matsumoto d3ebe4894b variable.c: first iv allocation size should be 4 instead of 1. 2021-12-03 15:38:16 +09:00
Yukihiro "Matz" Matsumoto a20c2a08ab variable.c: should not access NULL[0] to avoid asan warnings. 2021-12-03 15:04:14 +09:00
Yukihiro "Matz" Matsumoto 6ac26e4442 parse.y: support anonymous block argument introduced by Ruby3.1. 2021-12-02 18:24:48 +09:00
Yukihiro "Matz" Matsumoto bd88870afb codegen.c: ADDI/SUBI should not be prefixed by OP_EXT; fix #5590
As a general principles numeric instructions should not be prefixed by
`OP_EXT` instructions since they are not supported by "mruby/c".
2021-12-01 14:33:52 +09:00
Yukihiro "Matz" Matsumoto 76659a66ae codegen.c: skip ADDI/SUBI for zero operand. 2021-12-01 14:29:44 +09:00
Yukihiro "Matz" Matsumoto 7d6b8024b5 codegen.c: fix a bug in OP_ADDI and OP_SUBI regarding negative values. 2021-12-01 14:28:27 +09:00
Yukihiro "Matz" Matsumoto 2e2f81a443 codegen.c: get_int_operand to retrieve negative values correctly. 2021-12-01 14:26:22 +09:00
Yukihiro "Matz" Matsumoto 7a31a1743a codedump.c: print OP_EXT explicitly again for debugging purpose. 2021-12-01 13:42:40 +09:00
Yukihiro "Matz" Matsumoto b5842dea58 variable.c: reduce memory usage of instance variable table
This is a fundamentally simplified reimplementation of #5317
by @shuujii

Instead of having array of `struct iv_elem`, we have sequences of keys
and values packed in single chunk of malloc'ed memory. We don't have to
worry about gaps from alignment, especially on 64 bit architecture,
where `sizeof(struct iv_elem)` probably consumes 16 bytes, but
`sizeof(mrb_sym)+sizeof(mrb_value)` is 12 bytes.

In addition, this change could improve memory access locality.

close #5317
2021-12-01 12:27:19 +09:00
Yukihiro "Matz" Matsumoto b137eb2678 vm.c: remove duplicate code in VM. 2021-11-29 23:18:57 +09:00
Yukihiro "Matz" Matsumoto a245c34210 Merge pull request #5589 from dearblue/argerr
Align "wrong number of arguments" messages
2021-11-29 10:14:59 +09:00
Yukihiro "Matz" Matsumoto a0f38005fb Merge pull request #5588 from dearblue/cmath+clang++
Fixed compile error for `mrbgems/mruby-cmath` with `clang++`
2021-11-28 19:04:57 +09:00
Yukihiro "Matz" Matsumoto 6bb2af9666 Merge pull request #5587 from dearblue/args-pass.1
Fix `args_unshift()` in `mrbgems/mruby-method`
2021-11-28 19:03:33 +09:00
dearblue c4bca7cbb3 Align "wrong number of arguments" messages
Make "N for M" into the form "given N, expected M".

As I worked, I noticed that the `argnum_error()` function had a part to include the method name in the message.
I think this part is no longer needed by https://github.com/mruby/mruby/pull/5394.

  - Before this patch

    ```console
    % bin/mruby -e '[1, 2, 3].each 0'
    trace (most recent call last):
            [1] -e:1
    -e:1:in each: 'each': wrong number of arguments (1 for 0) (ArgumentError)
    ```

  - After this patch

    ```console
    % bin/mruby -e '[1, 2, 3].each 0'
    trace (most recent call last):
            [1] -e:1
    -e:1:in each: wrong number of arguments (given 1, expected 0) (ArgumentError)
    ```
2021-11-28 18:21:29 +09:00
dearblue f81bc3de38 Fixed compile error for mrbgems/mruby-cmath with clang++
If the preprocessor check part is only `__clang__`, CI's such as `Ubuntu-2004-clang` will fail to compile.
This is why we limited the addition to FreeBSD and OpenBSD, which have `clang++` in their base systems.
DragonFly BSD and NetBSD have GCC built into their base systems, so nothing is changed.
2021-11-28 17:28:44 +09:00
dearblue 58a9621df7 Fix args_unshift() in mrbgems/mruby-method
Both keyword arguments and block arguments were being destroyed when there were no arguments.
The cause of this is #5585. I' m sorry.
2021-11-28 14:10:37 +09:00
Yukihiro "Matz" Matsumoto e4d6917786 test/kernel.rb: remove duplicate tests; ref #5584 2021-11-26 12:18:41 +09:00
dearblue 668b12e756 Check more MRB_ARGS_NONE()
The `__id__` method implemented in the C function has `MRB_ARGS_NONE()` specified, but it is also effective in the following cases.

```ruby
p nil.__id__ opts: 1 rescue p :a
p nil.method(:__id__).call 1 rescue p :b
p nil.method(:__id__).call opts: 1 rescue p :c
p nil.method(:__id__).to_proc.call 1 rescue p :d
p nil.method(:__id__).to_proc.call opts: 1 rescue p :e
p nil.method(:__id__).unbind.bind_call nil, 1 rescue p :f
p nil.method(:__id__).unbind.bind_call nil, opts: 1 rescue p :g
p nil.__send__ :__id__, 1 rescue p :h
p nil.__send__ :__id__, opts: 1 rescue p :i
```

After applying this patch, all items will output symbols in the same way as CRuby.

For this purpose, add `MRB_PROC_NOARG` to `struct RProc::flags`.
2021-11-26 12:18:41 +09:00
Yukihiro "Matz" Matsumoto b631c226eb Merge pull request #5585 from dearblue/args-pass
Fixed some methods where keyword arguments are not passed
2021-11-25 17:08:32 +09:00
dearblue 16e388863a Fixed some methods where keyword arguments are not passed 2021-11-24 23:35:42 +09:00
Yukihiro "Matz" Matsumoto d6e1114f71 Merge pull request #5581 from mruby/dependabot/github_actions/actions/cache-2.1.7
build(deps): bump actions/cache from 2.1.6 to 2.1.7
2021-11-24 09:39:50 +09:00
dependabot[bot] 9ae657520b build(deps): bump actions/cache from 2.1.6 to 2.1.7
Bumps [actions/cache](https://github.com/actions/cache) from 2.1.6 to 2.1.7.
- [Release notes](https://github.com/actions/cache/releases)
- [Commits](https://github.com/actions/cache/compare/v2.1.6...v2.1.7)

---
updated-dependencies:
- dependency-name: actions/cache
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-11-23 14:12:20 +00:00
Yukihiro "Matz" Matsumoto d627c22924 AUTHORS: update entries [ci skip] 2021-11-23 10:05:16 +09:00
Yukihiro "Matz" Matsumoto 4a84fa5db5 Merge pull request #5580 from dearblue/static-proc
Fixed occurs `SIGSEGV` with `mrbgems/mruby-method`
2021-11-23 10:03:44 +09:00
dearblue b02bd63dc5 Fixed occurs SIGSEGV with mrbgems/mruby-method
Calling the `Method#{parameters,source_location}` method on a static `Proc` object resulted in `SIGSEGV`.
The trigger is https://github.com/mruby/mruby/pull/5402.

The original implementation of the `Method#{parameters,source_location}` method was to temporarily rewrite the object and then call the method of the same name in `Proc`.
Rewriting of objects placed in the ROM section by #5402 above is prohibited by hardware such as the CPU.
This caused a `SIGSEGV`.
2021-11-22 21:55:02 +09:00
Yukihiro "Matz" Matsumoto 01cadd3e70 parse.y: check duplicated argument names; fix #5575 2021-11-21 19:05:50 +09:00
Yukihiro "Matz" Matsumoto f69eafc6bd doc/internal/opcode.md: moved from doc/opcode.md 2021-11-20 14:56:59 +09:00
Yukihiro "Matz" Matsumoto 28f00b23bf doc/opcode.md: update according to #5579 2021-11-20 14:55:09 +09:00
Yukihiro "Matz" Matsumoto a04d2a8865 fixup! parse.y: unnamed rest argument should be mul (*). 2021-11-20 08:50:52 +09:00
Yukihiro "Matz" Matsumoto 2e41b20590 parse.y: unnamed rest argument should be mul (*). 2021-11-20 08:50:52 +09:00
Yukihiro "Matz" Matsumoto 9e064f2353 parse.y: skip unnecessary local_add_f(p, 0). 2021-11-20 08:50:51 +09:00
Yukihiro "Matz" Matsumoto 4c28356b71 Merge pull request #5578 from dearblue/OP_SENDB
Fixes keywords are lost with the `OP_SENDB`
2021-11-20 08:50:42 +09:00
Yukihiro "Matz" Matsumoto c6c789d2e8 Merge pull request #5579 from dearblue/OP_ASET
Fixed a discrepancy in `OP_ASET`
2021-11-20 08:48:05 +09:00
dearblue 6fba0dbece Fixed a discrepancy in OP_ASET
There was a discrepancy in the actual behavior, assertions, and documentation.
Therefore, I modified it based on the actual behavior.
2021-11-19 22:53:01 +09:00
dearblue 279e0122da Fixes keywords are lost with the OP_SENDB
If a splat argument was passed, it could write out of range on the VM stack.

```console
% bin/mruby -e 'def m(*args, **opts, &blk) p [args, opts, blk] end; m(*%w(X Y Z), r: 1, g: 2, b: 3) {}'
[["X", "Y", "Z"], {}, #<Proc:0x80077d7d0>]
```
2021-11-19 22:35:47 +09:00
Yukihiro "Matz" Matsumoto 1a1ff6b3ff Merge pull request #5577 from mruby/dependabot/github_actions/github/super-linter-4.8.4
build(deps): bump github/super-linter from 4.8.3 to 4.8.4
2021-11-18 10:28:35 +09:00
dependabot[bot] a66db89a5d build(deps): bump github/super-linter from 4.8.3 to 4.8.4
Bumps [github/super-linter](https://github.com/github/super-linter) from 4.8.3 to 4.8.4.
- [Release notes](https://github.com/github/super-linter/releases)
- [Changelog](https://github.com/github/super-linter/blob/main/docs/release-process.md)
- [Commits](https://github.com/github/super-linter/compare/v4.8.3...v4.8.4)

---
updated-dependencies:
- dependency-name: github/super-linter
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-11-17 14:09:11 +00:00
Yukihiro "Matz" Matsumoto f4e18a5d84 codegen.c: fixed a bug in post mandatory arguments. 2021-11-17 16:34:44 +09:00
Yukihiro "Matz" Matsumoto f5d9aab372 codegen.c: should not emit the MOVE instruction to the same register. 2021-11-17 16:33:53 +09:00
Yukihiro "Matz" Matsumoto e3e54453a7 Merge pull request #5576 from mruby/dependabot/github_actions/github/super-linter-4.8.3
build(deps): bump github/super-linter from 4.8.1 to 4.8.3
2021-11-16 16:59:10 +09:00
dependabot[bot] 927812a7e6 build(deps): bump github/super-linter from 4.8.1 to 4.8.3
Bumps [github/super-linter](https://github.com/github/super-linter) from 4.8.1 to 4.8.3.
- [Release notes](https://github.com/github/super-linter/releases)
- [Changelog](https://github.com/github/super-linter/blob/main/docs/release-process.md)
- [Commits](https://github.com/github/super-linter/compare/v4.8.1...v4.8.3)

---
updated-dependencies:
- dependency-name: github/super-linter
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-11-15 14:08:13 +00:00
Yukihiro "Matz" Matsumoto e0a3800e5d string-ext/string.c: fixed a memory leak. 2021-11-15 09:49:05 +09:00
Yukihiro "Matz" Matsumoto a0b58eed46 doc/internal/boxing.md: describe how mrb_value represents values. 2021-11-14 17:45:21 +09:00
Yukihiro "Matz" Matsumoto 1fe722cd78 boxing_word.h: fix the error in the comment [ci skip] 2021-11-13 20:59:54 +09:00
Yukihiro "Matz" Matsumoto 4e3df65d6f test/syntax.rb: test argument forwarding without parentheses. 2021-11-12 15:02:49 +09:00
Yukihiro "Matz" Matsumoto 7c1878669a parse.y: should allow newline after .... 2021-11-12 15:02:04 +09:00
Yukihiro "Matz" Matsumoto 885a87e408 parse.y: allow ... in formal arguments without parentheses. 2021-11-10 22:25:02 +09:00
Yukihiro "Matz" Matsumoto 2e0c1b4361 etc.c: improve mrb_obj_id with NaN boxing and Word boxing. 2021-11-09 17:24:53 +09:00
Yukihiro "Matz" Matsumoto a5567fbad4 boxing_nan.h: update mrb_immediate_p and related macros. 2021-11-08 14:33:50 +09:00
Yukihiro "Matz" Matsumoto 5dc91029d1 TODO.md: update. 2021-11-08 14:33:50 +09:00
Yukihiro "Matz" Matsumoto 5c8e184fcf Merge pull request #5437 from dearblue/parse.y
Run the task only once when `parse.y` is updated
2021-11-06 19:58:28 +09:00
Yukihiro "Matz" Matsumoto c3a1456cc8 mruby3.1.md: update. 2021-11-06 18:18:38 +09:00
Yukihiro "Matz" Matsumoto 879f074cd0 mruby3.1.md: update new methods description. 2021-11-05 15:08:44 +09:00
Yukihiro "Matz" Matsumoto d6f6467ad7 boxing_nan.h (mrb_float_p): wrap macro argument by parenthesis. 2021-11-04 20:49:19 +09:00
Yukihiro "Matz" Matsumoto c21a094a7f hash.c: avoid mrb_obj_id to get the hash value if possible. 2021-11-04 15:54:31 +09:00
Yukihiro "Matz" Matsumoto 877e82eb92 Merge pull request #5570 from dearblue/random-bytes
Added `Random.#bytes` method
2021-11-04 15:54:22 +09:00
Yukihiro "Matz" Matsumoto 8f67a0d0e1 Merge pull request #5569 from dearblue/array-product
Added `Array#product` method
2021-11-04 15:54:09 +09:00
Yukihiro "Matz" Matsumoto b940ed69d9 Merge pull request #5571 from mruby/dependabot/github_actions/actions/checkout-2.4.0
build(deps): bump actions/checkout from 2.3.5 to 2.4.0
2021-11-04 07:48:14 +09:00
dependabot[bot] b8b5d4094f build(deps): bump actions/checkout from 2.3.5 to 2.4.0
Bumps [actions/checkout](https://github.com/actions/checkout) from 2.3.5 to 2.4.0.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v2.3.5...v2.4.0)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-11-03 14:06:38 +00:00
Yukihiro "Matz" Matsumoto 36efd018e2 Merge pull request #5565 from dearblue/class.new
Improved `Class#new` method
2021-11-03 19:38:11 +09:00
Yukihiro "Matz" Matsumoto 59b7846ab0 Merge pull request #5568 from dearblue/nan+cxx_abi
Fix failed build with `MRB_NAN_BOXING` and `enable_cxx_abi`
2021-11-01 13:54:15 +09:00
Yukihiro "Matz" Matsumoto a0dd466840 object.c: fast implementation of mrb_obj_eq.
For `MRB_NAN_BOXING` and `MRB_WORD_BOXING`.
2021-11-01 13:35:10 +09:00
dearblue 7bb4a57e56 Added Random.#bytes method
ref: https://docs.ruby-lang.org/ja/3.0.0/method/Random/i/bytes.html
2021-10-31 23:36:10 +09:00
dearblue 5ea26260fa Added Array#product method
Ruby-1.9.0 feature.

ref: https://docs.ruby-lang.org/ja/3.0.0/method/Array/i/product.html
2021-10-31 23:02:37 +09:00
dearblue 1de662cb8b Fix failed build with MRB_NAN_BOXING and enable_cxx_abi
```console
% c++ -xc++ -std=c++03 -S -Iinclude -DMRB_NAN_BOXING -DMRB_NO_PRESYM -o- src/array.c > /dev/null
In file included from src/array.c:7:
In file included from include/mruby.h:115:
In file included from include/mruby/value.h:201:
include/mruby/boxing_nan.h:95:12: error: cannot initialize return object of type 'enum mrb_vtype' with an rvalue of type 'int'
    return (enum mrb_vtype)(o.u >> 8) & 0x1f;
           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
```
2021-10-31 22:17:15 +09:00
Yukihiro "Matz" Matsumoto d8204d51af Merge pull request #5566 from dearblue/no_float_truncate
Avoid redefining `MRB_WORDBOX_NO_FLOAT_TRUNCATE`
2021-10-31 17:29:20 +09:00
Yukihiro "Matz" Matsumoto f0b0f9d69d Merge pull request #5567 from dearblue/mrb_static_assert.1
Avoid violations of the `mrb_static_assert()` standard
2021-10-30 17:46:40 +09:00
Yukihiro "Matz" Matsumoto 9f0410789d boxing_nan.h: allow MRB_INT64 with MRB_NAN_BOXING.
Integers out of 32 bit range will be allocated in the heap.
2021-10-30 17:44:46 +09:00
Yukihiro "Matz" Matsumoto 85fcd2dc6f boxing_nan.h: implement Favor pointer NaN Boxing.
Favor pointer means encode NaN boxed values to keep pointer values
unmodified, to reduce the cost of far frequent pointer value retrievals.
2021-10-30 17:43:35 +09:00
dearblue 61ee857178 Avoid violations of the mrb_static_assert() standard
ref: #5564

```console
% cc -pedantic -S -Iinclude -DMRB_NO_PRESYM -o- src/array.c > /dev/null
In file included from src/array.c:7:
In file included from include/mruby.h:115:
In file included from include/mruby/value.h:204:
include/mruby/boxing_word.h:133:1: warning: must specify at least one argument for '...' parameter of variadic macro [-Wgnu-zero-variadic-macro-arguments]
mrb_static_assert(sizeof(mrb_value) == sizeof(union mrb_value_));
^
include/mruby.h:109:108: note: expanded from macro 'mrb_static_assert'
    mrb_static_assert_expand(mrb_static_assert_selector(__VA_ARGS__, mrb_static_assert2, mrb_static_assert1)(__VA_ARGS__))
                                                                                                           ^
include/mruby.h:100:10: note: macro 'mrb_static_assert_selector' defined here
# define mrb_static_assert_selector(a, b, name, ...) name
         ^
1 warning generated.
```
2021-10-30 13:22:35 +09:00
dearblue fa8bd00b57 Avoid redefining MRB_WORDBOX_NO_FLOAT_TRUNCATE
Adding `MRB_WORDBOX_NO_FLOAT_TRUNCATE` to the build configuration in 32-bit CPU mode had a double definition.

```console
% cat myconf.rb
MRuby::Build.new do
  toolchain "clang"
  defines << "MRB_WORDBOX_NO_FLOAT_TRUNCATE"
  cc.flags << "-m32"
  linker.flags << "-m32"
  enable_debug
end

% rake CONFIG=myconf.rb
CPP   src/array.c -> build/host/src/array.pi
In file included from /var/tmp/mruby/src/array.c:7:
In file included from /var/tmp/mruby/include/mruby.h:115:
In file included from /var/tmp/mruby/include/mruby/value.h:203:
/var/tmp/mruby/include/mruby/boxing_word.h:11:10: warning:
      'MRB_WORDBOX_NO_FLOAT_TRUNCATE' macro redefined [-Wmacro-redefined]
# define MRB_WORDBOX_NO_FLOAT_TRUNCATE
         ^
<command line>:3:9: note: previous definition is here
#define MRB_WORDBOX_NO_FLOAT_TRUNCATE 1
        ^
1 warning generated.
...SNIP...
```
2021-10-30 09:55:35 +09:00
dearblue 33792c2a02 Improved Class#new method
The number of registers used is reduced.

Also, previously `R6` and` R7` were used, which exceeded the limit of `new_irep.nregs = 6`.
This could cause the VM stack to overrun.
2021-10-29 22:20:20 +09:00
Yukihiro "Matz" Matsumoto 0069e6738a boxing_nan.h: refactor NaN Boxing.
Preparation for:

* 64 bit integer with NaN Boxing
* Favor pointer NaN Boxing
2021-10-28 12:22:21 +09:00
Yukihiro "Matz" Matsumoto fca63c6060 boxing_nan.h: revert part of dccd66f
WIP code was mistakenly committed.
2021-10-26 17:33:49 +09:00
Yukihiro "Matz" Matsumoto abf2d653d7 Merge pull request #5564 from dearblue/static_assert
Make `mrb_static_assert()` a variable argument
2021-10-25 07:59:01 +09:00
dearblue b774832ee1 Make mrb_static_assert() a variable argument
`mrb_static_assert()` extends the macro function to take one or two arguments.
If the argument is other than that, an error will occur.

References:
- static_assert のメッセージ省略を許可 - cpprefjp C++日本語リファレンス
  https://cpprefjp.github.io/lang/cpp17/extending_static_assert.html
- c - Overloading Macro on Number of Arguments - Stack Overflow
  https://stackoverflow.com/a/11763277
2021-10-24 23:11:52 +09:00
Yukihiro "Matz" Matsumoto 5c6e8b32a3 doc/mruby3.1.h: separate mruby3.0 changes and mruby3.1 changes. 2021-10-24 13:21:54 +09:00
Yukihiro "Matz" Matsumoto 7850549a5e string.c: use FNV1a algorithm for the string hash function. 2021-10-23 09:31:01 +09:00
Yukihiro "Matz" Matsumoto 74b02fba81 Merge pull request #5563 from suetanvil-misc/project-bintest-emulator-4-flat
Added testing support for cross-MinGW builds.
2021-10-22 13:41:50 +09:00
Chris Reuter 5c4273f944 Added testing support for cross-MinGW builds.
This adds a build_config that will cross-build a Windows executable
using the MinGW cross-compiler and will also run the unit (i.e.
'rake test') using Wine.

For this to work, I made some modifications to the underlying test
scripts as well as some minor changes to a couple of the tests
themselves.
2021-10-21 21:58:45 -04:00
Yukihiro "Matz" Matsumoto fabe8212fe codedump.c: add indentation for OP_MOVE. 2021-10-21 15:35:25 +09:00
Yukihiro "Matz" Matsumoto dc0d5db699 doc/mruby3.md: updated to the most recent mruby3.1 (to be). 2021-10-20 09:40:17 +09:00
Yukihiro "Matz" Matsumoto f653556731 dump.h: bump RITE_BINARY_MAJOR_VER to 03.
Since we have added several new instructions.
2021-10-19 15:27:29 +09:00
Yukihiro "Matz" Matsumoto d965d90edf codedump.c: remove OP_ prefix from disasm output. 2021-10-19 12:29:06 +09:00
Yukihiro "Matz" Matsumoto 90484cac63 codegen.c: skip OP_LOADSELF using OP_SSEND. 2021-10-19 12:13:05 +09:00
Yukihiro "Matz" Matsumoto 5d5e4f5214 ops.h: add new instructions OP_SSEND and OP_SSENDB.
These instructions call methods of the receiver.
2021-10-19 12:03:12 +09:00
Yukihiro "Matz" Matsumoto 45491cdd8c ops.h: update descriptions for array-like accesses.
* `R(a)` -> `R[a]`
* `Pool(a)` -> `Pool[a]`
* `Syms(a)` -> `Syms[a]`
* `Irep(a)` -> `Irep[a]`
2021-10-19 11:49:02 +09:00
Yukihiro "Matz" Matsumoto ab986ff108 ops.h: update OP_SEND description. 2021-10-19 11:37:59 +09:00
Yukihiro "Matz" Matsumoto b6b4ac8270 Merge pull request #5560 from mruby/dependabot/github_actions/actions/checkout-2.3.5
build(deps): bump actions/checkout from 2.3.4 to 2.3.5
2021-10-19 08:06:28 +09:00
dependabot[bot] cdccb5ea13 build(deps): bump actions/checkout from 2.3.4 to 2.3.5
Bumps [actions/checkout](https://github.com/actions/checkout) from 2.3.4 to 2.3.5.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v2.3.4...v2.3.5)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-10-18 14:05:53 +00:00
Yukihiro "Matz" Matsumoto 10edda9698 Merge pull request #5559 from igrep/fix-commented-out-example
Fix a syntax error in commented-out code
2021-10-18 13:07:32 +09:00
YAMAMOTO Yuji 66e61c5ab8 Fix a syntax error in commented-out code
By uncommenting the line changed by this commit, `ruby -c build_config/default.rb` complains of a syntax error due to the illegally nested double quotes
2021-10-18 12:45:55 +09:00
Yukihiro "Matz" Matsumoto 0d08f89159 codegen.c: Reduce MRB_CODEGEN_LEVEL_MAX from 1024 to 256.
1024 was too big.  Some deep recursion could not be detected before
actual stack overflow.
2021-10-18 12:01:07 +09:00
Yukihiro "Matz" Matsumoto de2b4bd0dc codegen.c: fixed a bug regarding attribute assignment with kargs. 2021-10-18 08:01:26 +09:00
Yukihiro "Matz" Matsumoto be189ae9f9 codegen.c: forgot to check s2 extensively in super codegen. 2021-10-17 08:03:24 +09:00
Yukihiro "Matz" Matsumoto 2b19a6c1b4 AUTHORS: update. 2021-10-17 08:02:36 +09:00
Yukihiro "Matz" Matsumoto 36bca25e58 codegen.c: s2 may be NULL.
Since `s2` is `NULL` on top-level, it will be an error. No need to
generate strict bytecode.
2021-10-16 11:09:52 +09:00
Yukihiro "Matz" Matsumoto 0dc5fcec7b parse.y: check car part of return node. 2021-10-16 10:33:35 +09:00
Yukihiro "Matz" Matsumoto 0b095406bf Merge pull request #5558 from jbampton/fix-grammar
Fix grammar in doc/guides/mrbgems.md
2021-10-15 09:47:23 +09:00
Yukihiro "Matz" Matsumoto a9a2dcd3cc rational.c: avoid recursion between rational_eq and complex_eq. 2021-10-14 22:48:54 +09:00
Yukihiro "Matz" Matsumoto 7010ed0f0a vm.c: need to ensure the stack size is sufficient.
Need to add `n` because the stack will be shifted in the `mrb_funcall`.
2021-10-14 22:47:19 +09:00
John Bampton a3da482683 Fix grammar in doc/guides/mrbgems.md 2021-10-14 19:55:57 +10:00
Yukihiro "Matz" Matsumoto 6b3b1012ca codegen.c: skip OP_ARGARY before super if the method has no arguments. 2021-10-13 07:06:17 +09:00
Yukihiro "Matz" Matsumoto a1027812bd error.c: small refactoring regarding #2485 2021-10-12 22:38:59 +09:00
Yukihiro "Matz" Matsumoto 3c8f0ac14b Merge branch 'take-cheeze-exc_mesg' 2021-10-12 22:16:21 +09:00
Yukihiro "Matz" Matsumoto 291234c7aa Merge branch 'exc_mesg' of https://github.com/take-cheeze/mruby into take-cheeze-exc_mesg 2021-10-12 22:14:11 +09:00
Yukihiro "Matz" Matsumoto 5004d9a282 codegen.c: should not assign negative number to ainfo (size_t). 2021-10-12 20:16:36 +09:00
Yukihiro "Matz" Matsumoto dccd66f9ef Support Ruby3.0 keyword arguments.
The Difference

Since Ruby1.9, the keyword arguments were emulated by Ruby using the hash
object at the bottom of the arguments. But we have gradually moved toward
keyword arguments separated from normal (positinal) arguments.

At the same time, we value compatibility, so that Ruby3.0 keyword
arguments are somewhat compromise. Basically, keyword arguments are
separated from positional arguments, except when the method does not
take any formal keyword arguments, given keyword arguments (packed
in the hash object) are considered as the last argument.

And we also allow non symbol keys in the keyword arguments. In that
case, those keys are just passed in the `**` hash (or raise
`ArgumentError` for unknown keys).

The Instruction Changes

We have changed `OP_SEND` instruction. `OP_SEND` instruction used to
take 3 operands, the register, the symbol, the number of (positional)
arguments. The meaning of the third operand has been changed. It is now
considered as `n|(nk<<4)`, where `n` is the number of positional
arguments, and `nk` is the number of keyword arguments, both occupies
4 bits in the operand.

The number `15` in both `n` and `nk` means variable sized arguments are
packed in the object. Positional arguments will be packed in the array,
and keyword arguments will be packed in the hash object. That means
arguments more than 14 values are always packed in the object.

Arguments information for other instructions (`OP_SENDB` and `OP_SUPER`)
are also changed. It works as the third operand of `OP_SEND`. the
difference between `OP_SEND` and `OP_SENDB` is just trivial. It assigns
`nil` to the block hidden arguments (right after arguments).

The instruction `OP_SENDV` and `OP_SENDVB` are removed. Those
instructions are replaced by `OP_SEND` and `OP_SENDB` respectively with
the `15` (variable sized) argument information.

Calling Convention

When calling a method, the stack elements shall be in the order of the
receiver of the method, positional arguments, keyword arguments and the
block argument. If the number of positional or keyword arugument (`n` or
`nk`) is zero, corresponding arguments will be empty. So when `n=0` and
`nk=0` the stack layout (from bottom to top) will be:

+-----------------------+
| recv | block (or nil) |
+-----------------------+

The last elements `block` should be explicitly filled before `OP_SEND`
or assigned to `nil` by `OP_SENDB` internally. In other words, the
following have exactly same behavior:

OP_SENDB clears `block` implicitly:

```
OP_SENDB reg sym 0
```

OP_SEND clears `block` implicitly:

```
OP_LOADNIL  R2
OP_SEND     R2 sym 0
```

When calling a method with only positional arguments (n=0..14) without
keyword arguments, the stack layout will be like following:

+--------------------------------------------+
| recv | arg1 | ... | arg_n | block (or nil) |
+--------------------------------------------+

When calling a method with arguments packed in the array (n=15) which
means argument splat (*) is used in the actual arguments, or more than
14 arguments are passed the stack layout will be like following:

+-------------------------------+
| recv | array | block (or nil) |
+-------------------------------+

The number of the actual arguments is determined by the length of the
argument array.

When keyword arguments are given (nk>0), keyword arguments are passed
between positional arguments and the block argument. For example, when
we pass one positional argument `1` and one keyword argument `a: 2`,
the stack layout will be like:

+------------------------------------+
| recv | 1 | :a | 2 | block (or nil) |
+------------------------------------+

Note that keyword arguments consume `2*nk` elements in the stack when
`nk=0..14` (unpacked).

When calling a method with keyword arguments packed in the hash object
(nk=15) which means keyword argument splat (**) is used or more than
14 keyword arguments in the actual arguments, the stack layout will
be like:

+------------------------------+
| recv | hash | block (or nil) |
+------------------------------+

Note for mruby/c

When mruby/c authors try to support new keyword arguments, they need
to handle the new meaning of the argument information operand. If they
choose not to support keyword arguments in mruby/c, it just raise
error when `nk` (taken by `(c>>4)&0xf`) is not zero. And combine
`OP_SENDV` behavior with `OP_SEND` when `n` is `15`.

If they want to support keyword arguments seriously, contact me at
<matz@ruby.or.jp> or `@yukihiro_matz`. I can help you.
2021-10-12 20:16:36 +09:00
Yukihiro "Matz" Matsumoto c6df4bf9a8 Merge pull request #5557 from jbampton/pre-commit-autoupdate
pre-commit autoupdate
2021-10-12 20:16:18 +09:00
John Bampton 843d3d4e41 pre-commit autoupdate
https://pre-commit.com/index.html#pre-commit-autoupdate
2021-10-12 19:03:35 +10:00
Yukihiro "Matz" Matsumoto 8e5d89df7f vm.c: unify mrb_gc_arena_restore and mrb_gc_arena_shrink. 2021-10-10 20:12:11 +09:00
Yukihiro "Matz" Matsumoto 5cdf1eabdd Merge pull request #5555 from dearblue/str-ref-regexp
Partially allow overriding of `String#[]` methods
2021-10-09 14:15:06 +09:00
Yukihiro "Matz" Matsumoto 07f805aa88 Merge pull request #5556 from dearblue/setidx
Fix typo for `OP_SETIDX`
2021-10-09 14:00:09 +09:00
dearblue e8205ec906 Fix typo for OP_SETIDX 2021-10-09 13:36:19 +09:00
Yukihiro "Matz" Matsumoto 87b673fc9a codegen.c: peephole optimization OP_MOVE after OP_AREF. 2021-10-09 13:31:07 +09:00
dearblue 8c355ec7e3 Partially allow overriding of String#[] methods
This is for the purpose of supporting `Regexp`.

- configuration and build

  ```console
  % cat regexp_config.rb
  MRuby::Lockfile.disable
  MRuby::Build.new do
    toolchain "clang"
    enable_debug
    gem core: "mruby-bin-mruby"
    gem core: "mruby-print"
    gem mgem: "mruby-onig-regexp"
    #gem mgem: "mruby-regexp-pcre"
  end

  % rake MRUBY_CONFIG=regexp_config.rb
  ```

- mruby HEAD (bec074e)

  ```console
  % build/host/bin/mruby -e 'p "abcdefg"[/.(?=...$)/]'
  -e:1: can't convert OnigRegexp into Integer (TypeError)
  ```

- with this patch

  ```console
  % build/host/bin/mruby -e 'p "abcdefg"[/.(?=...$)/]'
  "d"
  ```
2021-10-09 13:28:10 +09:00
Yukihiro "Matz" Matsumoto bec074e6a3 vm.c: check call stack depth before pushing the frame.
Existing call stack depth checks are unified into this check in
`cipush()`. The maximum depth is now specified by `MRB_CALL_LEVEL_MAX`
(the default is 512).  The older `MRB_FUNCALL_DEPTH_MAX` is no longer
used.
2021-10-08 15:35:33 +09:00
Yukihiro "Matz" Matsumoto fd6d911b53 codegen.c: peephole optimize OP_MOVE after OP_ARRAY or OP_HASH.
When the length operand is zero, we don't need `OP_MOVE` but adjust the
destination operand instead.
2021-10-08 12:09:05 +09:00
Yukihiro "Matz" Matsumoto 7018286453 Merge pull request #5554 from mruby/dependabot/github_actions/github/super-linter-4.8.1
build(deps): bump github/super-linter from 4.8.0 to 4.8.1
2021-10-07 10:30:12 +09:00
Yukihiro "Matz" Matsumoto 376e84c9d7 codedump.c: remove trailing extra newline.
The bug was introduced in 8be78bd.
2021-10-06 07:36:44 +09:00
Yukihiro "Matz" Matsumoto 9aa3c26221 io.c: hide internal method names in backtrace. 2021-10-05 07:11:59 +09:00
dependabot[bot] 4ef612a586 build(deps): bump github/super-linter from 4.8.0 to 4.8.1
Bumps [github/super-linter](https://github.com/github/super-linter) from 4.8.0 to 4.8.1.
- [Release notes](https://github.com/github/super-linter/releases)
- [Changelog](https://github.com/github/super-linter/blob/main/docs/release-process.md)
- [Commits](https://github.com/github/super-linter/compare/v4.8.0...v4.8.1)

---
updated-dependencies:
- dependency-name: github/super-linter
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-10-04 14:08:09 +00:00
Yukihiro "Matz" Matsumoto ab1047b445 codegen.c: no OP_ARGARY is needed here. 2021-10-04 07:45:46 +09:00
Yukihiro "Matz" Matsumoto 09336c5d49 mruby/ops.h: add new instructions OP_GETIDX and OP_SETIDX.
Which represent `obj[int]` and `obj[int]=val` respectively where `obj`
is either `string`, `array` or `hash`, so that index access could be
faster. When `obj` is not assumed type or `R(a+1)` is not integer, the
instructions fallback to method calls.
2021-10-03 17:14:00 +09:00
Yukihiro "Matz" Matsumoto d64d8ca8e4 Merge branch 'dearblue-inline-struct-gem' 2021-10-02 20:11:32 +09:00
Yukihiro "Matz" Matsumoto 31e3dbc5a8 Merge branch 'inline-struct-gem' of https://github.com/dearblue/mruby into dearblue-inline-struct-gem 2021-10-02 20:09:20 +09:00
Yukihiro "Matz" Matsumoto 4e504eaca1 SECURITY.md: add scope description. 2021-10-01 19:13:07 +09:00
Yukihiro "Matz" Matsumoto d96f53f8f8 TODO.md: update. 2021-09-30 17:15:29 +09:00
Yukihiro "Matz" Matsumoto eea605bfc5 dreamcast_shelf.rb: remove unnecessary gem lines.
- `mruby-binding-core` should be handle through dependency
- `mruby-inline-struct` is only for tests
2021-09-30 12:46:45 +09:00
Yukihiro "Matz" Matsumoto bb3cd69aff value.h: introduce MRB_TT_STRUCT for mruby-struct. 2021-09-30 12:46:45 +09:00
Yukihiro "Matz" Matsumoto f1a5c050f4 Merge pull request #5553 from mruby/dependabot/github_actions/github/super-linter-4.8.0
build(deps): bump github/super-linter from 4.7.3 to 4.8.0
2021-09-28 23:14:39 +09:00
dependabot[bot] 1b53b973e5 build(deps): bump github/super-linter from 4.7.3 to 4.8.0
Bumps [github/super-linter](https://github.com/github/super-linter) from 4.7.3 to 4.8.0.
- [Release notes](https://github.com/github/super-linter/releases)
- [Changelog](https://github.com/github/super-linter/blob/master/docs/release-process.md)
- [Commits](https://github.com/github/super-linter/compare/v4.7.3...v4.8.0)

---
updated-dependencies:
- dependency-name: github/super-linter
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-09-28 14:07:15 +00:00
Yukihiro "Matz" Matsumoto 906f9f2ba7 parse.y: __ENCODING__ should be determined in run-time; fix #5552
It used to be compiled to the static string in the compiler. But the
encoding status actually depends on the runtime configuration. A new
method `Kernel#__ENCODING__` is introduced to implement the feature.
2021-09-27 10:10:35 +09:00
Yukihiro "Matz" Matsumoto 368e8ce3d5 codegen.c: should not loop_push() before constant folding.
Otherwise, the following code will crash:

```ruby
1.times{{}until 1; break}
```
2021-09-26 16:58:40 +09:00
Yukihiro "Matz" Matsumoto 89ea41f15e mrbconf.h: rename a configuration macro for no truncate floats.
Rename `MRB_WORDBOX_USE_HEAP_FLOAT` to `MRB_WORDBOX_NO_FLOAT_TRUNCATE'.
2021-09-25 14:44:43 +09:00
Yukihiro "Matz" Matsumoto c70159b356 Revert "vm.c: add assertions instead of mrb_ensure_hash_type()."
This reverts commit 913a0a5a03.
In some cases, `OP_HASHADD` operand may not be `Hash`. We should check
explicitly in those cases.
2021-09-24 17:10:11 +09:00
Yukihiro "Matz" Matsumoto ab54ca272a codegen.c: refactor NODE_WHILE and NODE_UNTIL. 2021-09-24 11:39:00 +09:00
Yukihiro "Matz" Matsumoto 7c6c4ebb56 codegen.c: add short circuit constant folding for NODE_AND, NODE_OR. 2021-09-24 11:38:02 +09:00
Yukihiro "Matz" Matsumoto 863671c89f codegen.c: refactor NODE_IF generation for boolean constants.
In addition, add `NODE_SYM` for always true expression.
2021-09-24 11:36:27 +09:00
Yukihiro "Matz" Matsumoto a844f89655 codegen.c: need to check no_peephole() before constant folding. 2021-09-23 21:19:36 +09:00
Yukihiro "Matz" Matsumoto 4c196dbba5 codegen.c: separate maximum stack size from GEN_LIT_ARY_MAX. 2021-09-23 20:11:30 +09:00
Yukihiro "Matz" Matsumoto fd7896e579 error.c: stop calling initialize from VM exceptions.
The invocation of `initialize` hook can cause infinite recursion too
easily. We stop invoking the method for safety, at the cost of less
flexibility.

The `initialize` methods (e.g. ones defined in `mrblib/10error.rb`) are
called only from `NoMethodError.new(args..)` forms.
2021-09-22 11:41:38 +09:00
Yukihiro "Matz" Matsumoto 913a0a5a03 vm.c: add assertions instead of mrb_ensure_hash_type(). 2021-09-21 16:47:55 +09:00
Yukihiro "Matz" Matsumoto dd0caf8728 Create SECURITY.md 2021-09-20 19:44:41 +09:00
Yukihiro "Matz" Matsumoto d6dd6f0e7b Update struct initializer to work with relatively older C++. 2021-09-20 19:13:17 +09:00
Yukihiro "Matz" Matsumoto 8be78dbf9d codedump.c: add cosmetic tabs before variable labels. 2021-09-20 17:33:07 +09:00
Yukihiro "Matz" Matsumoto c29822f80c codegen.c (gen_addsub): use mrb_int_sub_overflow(). 2021-09-20 17:32:38 +09:00
Yukihiro "Matz" Matsumoto 0455313a9b codegen.c: avoid constant folding OP_LOADI16 across branch target. 2021-09-20 17:30:14 +09:00
Yukihiro "Matz" Matsumoto ca7228ad42 codegen.c: gen_move should generate proper OP_LOADI16. 2021-09-20 16:58:27 +09:00
Yukihiro "Matz" Matsumoto 1baf08f174 codegen.c: rename loopinfo->acc to reg.
`acc` meant `accumulator` but it is not an accumulator but just a
register position.
2021-09-20 10:40:30 +09:00
Yukihiro "Matz" Matsumoto 2083d99392 codegen.c: check no_peephole(s) before mrb_last_insn(s). 2021-09-20 10:37:11 +09:00
Yukihiro "Matz" Matsumoto f85c50543b codegen.c (mrb_last_insn): no previous instruction on top. 2021-09-20 10:35:01 +09:00
Yukihiro "Matz" Matsumoto 938af8a8ff vm.c: add array assertions. 2021-09-19 23:17:19 +09:00
Yukihiro "Matz" Matsumoto 8bfa99975c codegen.c: unify OP_ARYPUSH and OP_ARYPUSH_N.
- `OP_ARYPUSH` now takes operand for the number of pushing elements
- the code generator consume the stack no more than `64` for `mruby/c`
2021-09-19 09:07:20 +09:00
Yukihiro "Matz" Matsumoto 7c99df8416 ops.h: add OP_ARYPUSH_N instruction.
Add n elements at once. Reduces instructions for huge array
initialization. In addition, `gen_value` function in `codegen.c` was
refactored and clarified.
2021-09-17 07:49:47 +09:00
Yukihiro "Matz" Matsumoto 6f044de578 AUTHORS: update. [ci skip] 2021-09-17 07:47:45 +09:00
Yukihiro "Matz" Matsumoto f7063ccd1b AUTHORS: update. [ci skip] 2021-09-16 20:24:29 +09:00
Yukihiro "Matz" Matsumoto 8619ba6a38 Use struct initializer instead of memset. 2021-09-15 13:02:15 +09:00
Yukihiro "Matz" Matsumoto e5e7bd29ef sprintf.c: width may have been INT_MAX.
Now `width` is limited to `INT16_MIN..INT16_MAX`.
2021-09-14 14:12:56 +09:00
Yukihiro "Matz" Matsumoto 6dbf49fdb4 parse.y: cons_free unused node (empty string node). 2021-09-13 12:20:11 +09:00
Yukihiro "Matz" Matsumoto 100eac3fec parse.y: allow non-local variable access from hash value omission.
For example, `{p:}` (means `{p:p}`) and `{String:}` (`{String:String}`)
should be allowed like CRuby.
2021-09-13 12:15:10 +09:00
Yukihiro "Matz" Matsumoto 6c76926d05 parse.y: allow value omission in Hash literals introduced in Ruby3.1.
`{x:, y:}` now is a syntax sugar of `{x: x, y: y}`.

This fix also includes the update of #4815 fix.
2021-09-13 11:04:27 +09:00
Yukihiro "Matz" Matsumoto 31fc74f5a8 parse.y: fix nint (int to node) and intn (node to int). 2021-09-12 23:14:43 +09:00
Yukihiro "Matz" Matsumoto 9e86d204e5 parse.y: avoid adding zero length strings. 2021-09-12 07:58:57 +09:00
Yukihiro "Matz" Matsumoto e1a865f272 codedump.c: avoid printing OP_EXT? prefix. 2021-09-11 11:00:11 +09:00
Yukihiro "Matz" Matsumoto 648a774ef6 ops.h: update OP_HASHADD description. 2021-09-10 19:11:56 +09:00
Yukihiro "Matz" Matsumoto da749d870f array.c: forgot to adjust tail position in mrb_ary_splice. 2021-09-10 17:34:40 +09:00
Yukihiro "Matz" Matsumoto cd0ffd6f1c codegen.c: fixed gen_setxv bug with taking assignment value; fix #5550 2021-09-10 15:39:24 +09:00
Yukihiro "Matz" Matsumoto 69da192eec codegen.c: gen_move refactoring. 2021-09-10 15:38:51 +09:00
Yukihiro "Matz" Matsumoto 7df31d9451 mruby.h: remove acc from callinfo; add cci instead.
`acc` was used as an index of the receiver (if positive), or a flag for
methods implemented in C. We replace `regs[ci->acc]` by `ci[1].stack[0]`.
And renamed `acc` (originally meant accumulator position) to `cci`
(means callinfo for C implemented method).
2021-09-10 12:39:51 +09:00
Yukihiro "Matz" Matsumoto 3050630b69 vm.c, codedump.c: add IREP_TT_NFLAG assertions.
The pool specified by `OP_STRING` (and `OP_SYMBOL`) should represent a
string, so that `IREP_TT_NFLAG` should be zero.
2021-09-10 10:25:07 +09:00
Yukihiro "Matz" Matsumoto 28b5c30b96 ops.h: add OP_SYMBOL instruction.
It generates a symbol by interning from the pool string.
2021-09-10 10:23:28 +09:00
Yukihiro "Matz" Matsumoto b34713304a fixup! codegen.c: resurrect s->lastpc to reduce iseq scans. 2021-09-10 10:22:49 +09:00
Yukihiro "Matz" Matsumoto 5fbea87fe5 codegen.c: resurrect s->lastpc to reduce iseq scans.
When parsing scripts frequent scans could cost too much.
2021-09-10 10:15:55 +09:00
Yukihiro "Matz" Matsumoto 3693187beb vm.c: ci->acc (int16_t) may overflow. 2021-09-10 10:15:32 +09:00
Yukihiro "Matz" Matsumoto c0f39bcaaf Merge pull request #5549 from mruby/dependabot/github_actions/github/super-linter-4.7.3
build(deps): bump github/super-linter from 4.7.2 to 4.7.3
2021-09-10 10:15:20 +09:00
dependabot[bot] a7e85bb7e9 build(deps): bump github/super-linter from 4.7.2 to 4.7.3
Bumps [github/super-linter](https://github.com/github/super-linter) from 4.7.2 to 4.7.3.
- [Release notes](https://github.com/github/super-linter/releases)
- [Changelog](https://github.com/github/super-linter/blob/master/docs/release-process.md)
- [Commits](https://github.com/github/super-linter/compare/v4.7.2...v4.7.3)

---
updated-dependencies:
- dependency-name: github/super-linter
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-09-09 14:04:06 +00:00
Yukihiro "Matz" Matsumoto 7e612b1c89 string.c: check integer overflow in str_replace_partial. 2021-09-09 19:12:59 +09:00
Yukihiro "Matz" Matsumoto 8a41d2b876 string.c: check integer overflow in mrb_str_aset(). 2021-09-09 19:12:36 +09:00
Yukihiro "Matz" Matsumoto 5777e33c2a doc/guides/mrbconf.rb: add RO_DATA configuration description; #5547 2021-09-09 16:20:29 +09:00
Yukihiro "Matz" Matsumoto 49602f636d value.h: add configuration macros around mrb_ro_data_p(); close #5547
- `MRB_USE_ETEXT_RO_DATA_P`: use `etext` and `edata`
- `MRB_NO_DEFAULT_RO_DATA_P`: not use the default `mrb_ro_data_p()`
2021-09-09 16:15:25 +09:00
Yukihiro "Matz" Matsumoto 5dd8b04d91 load.c: no need for conditional compilation; #5547
`mrb_ro_data_p()` is available anyway.
2021-09-09 11:07:19 +09:00
Yukihiro "Matz" Matsumoto a503484cb3 value.h: use etext and edata which are more widely available; #5547 2021-09-09 10:12:50 +09:00
Yukihiro "Matz" Matsumoto a3fe04eda2 Merge pull request #5548 from mruby/dependabot/github_actions/github/super-linter-4.7.2
build(deps): bump github/super-linter from 4.7.1 to 4.7.2
2021-09-09 07:34:02 +09:00
dependabot[bot] ddf2a49622 build(deps): bump github/super-linter from 4.7.1 to 4.7.2
Bumps [github/super-linter](https://github.com/github/super-linter) from 4.7.1 to 4.7.2.
- [Release notes](https://github.com/github/super-linter/releases)
- [Changelog](https://github.com/github/super-linter/blob/master/docs/release-process.md)
- [Commits](https://github.com/github/super-linter/compare/v4.7.1...v4.7.2)

---
updated-dependencies:
- dependency-name: github/super-linter
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-09-08 14:04:32 +00:00
Yukihiro "Matz" Matsumoto e4a0728b24 array.c: refactor mrb_ary_splice. 2021-09-08 07:33:08 +09:00
Yukihiro "Matz" Matsumoto 1d1a89874f value.h: fixed address comparison on macOS. 2021-09-07 18:51:04 +09:00
Yukihiro "Matz" Matsumoto cbfaa5e20f object.c: rename mrb_to_int to mrb_to_integer.
Consistent naming: `integer` to represent integer packed in `mrb_value`
instead of `int`.
2021-09-07 14:31:56 +09:00
Yukihiro "Matz" Matsumoto 79bc8e2539 string.h: rename mrb_str_to_inum to mrb_str_to_integer.
Consistent naming: `integer` to represent integer packed in `mrb_value`
instead of `inum`.
2021-09-07 14:31:56 +09:00
Yukihiro "Matz" Matsumoto 674d841ead eval.c: if the parser raises an exception without an error message
`eval` would have crashed in formatting.
2021-09-07 07:37:19 +09:00
Yukihiro "Matz" Matsumoto 711f06a562 eval.c: check length of the file name.
It should be lexx than `UINT16_MAX`. If you don't check here, the parser
would raise an exception.
2021-09-07 07:35:35 +09:00
Yukihiro "Matz" Matsumoto 6fc6880f1f codegen.c: improve exception handling in generate_code.
- remove `mrb_jmpbuf` from `codegen_scope`
- unify exception handling of `mrb_state` and `codegen_scope`
2021-09-07 07:33:28 +09:00
Yukihiro "Matz" Matsumoto 2fb06aabe6 parse.y: refactor mrb_parser_parse().
- remove `mrb_jmpbuf` from `truct mrb_parser_state`
- unify exception handling of `mrb_state` and `mrb_parser_state`.
2021-09-07 07:31:21 +09:00
Yukihiro "Matz" Matsumoto ad3404229f parse.y: refactoring mrb_parser_parser(). 2021-09-06 13:58:01 +09:00
Yukihiro "Matz" Matsumoto fc1f7c4bf0 numeric.c: shortcut overflowing operation when ndigit is too small. 2021-09-06 10:21:42 +09:00
Yukihiro "Matz" Matsumoto ab3db07752 boxing_word.h: avoid mrb_float_p() when MRB_NO_FLOAT is on; fix #5546 2021-09-05 20:59:49 +09:00
Yukihiro "Matz" Matsumoto 43abf36f00 array.c: check integer overflow before addition. 2021-09-05 16:41:08 +09:00
Yukihiro "Matz" Matsumoto 7552b9322a codegen.c: avoid integer overflow. 2021-09-05 09:25:44 +09:00
Yukihiro "Matz" Matsumoto 28c4f2f683 kernel.c: add __method__; ref #4468 2021-09-04 17:57:35 +09:00
Yukihiro "Matz" Matsumoto 09f686cd7b Merge branch 'shuujii-rename-Kernel-__method__-to-Kernel-__callee__' 2021-09-04 16:18:20 +09:00
KOBAYASHI Shuji 8a9f891fd3 Rename Kernel#__method__ to Kernel#__callee__
Because the current behavior of `__method__` is equivalent to `__callee__`.

Example:

  # example.rb
  def src
    __send__(ARGV[0])
  end
  alias dst src
  %w[src dst].each {|n| puts "call #{n} => #{__send__(n).inspect}"}

  Ruby:

    $ ruby example.rb __method__
    call src => :src
    call dst => :src

    $ ruby example.rb __callee__
    call src => :src
    call dst => :dst

  mruby:

    $ mruby example.rb __method__
    call src => :src
    call dst => :dst
2021-09-04 16:17:06 +09:00
Yukihiro "Matz" Matsumoto 2d8f4fa92f proc.c: need to preserve target_class in callinfo.
Otherwise `target_class` can be lost when it differs from `proc`'s
`target_class`, e.g. when called from `instance_eval`.

Also we should not pass `target_class` to `MRB_OBJ_ALLOC` since it
checks instance type from the class, and `target_class` may not have
proper information. ref #5272
2021-09-04 13:50:32 +09:00
Yukihiro "Matz" Matsumoto 5acf7e7cf7 vm.c: remove duplicated calls of mrb_vm_ci_target_class(). 2021-09-04 12:54:04 +09:00
Yukihiro "Matz" Matsumoto e02350dd02 range.c: len = b - a may overflow. 2021-09-03 16:30:42 +09:00
Yukihiro "Matz" Matsumoto dc4b60291a range.c: hide internal `__num_to_a' method from backtrace. 2021-09-03 16:30:42 +09:00
Yukihiro "Matz" Matsumoto 161f2403b3 Merge pull request #5545 from mruby/dependabot/github_actions/github/super-linter-4.7.1
build(deps): bump github/super-linter from 4.6.3 to 4.7.1
2021-09-02 07:26:25 +09:00
dependabot[bot] a6bb53f65a build(deps): bump github/super-linter from 4.6.3 to 4.7.1
Bumps [github/super-linter](https://github.com/github/super-linter) from 4.6.3 to 4.7.1.
- [Release notes](https://github.com/github/super-linter/releases)
- [Changelog](https://github.com/github/super-linter/blob/master/docs/release-process.md)
- [Commits](https://github.com/github/super-linter/compare/v4.6.3...v4.7.1)

---
updated-dependencies:
- dependency-name: github/super-linter
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-09-01 14:06:39 +00:00
Yukihiro "Matz" Matsumoto de9bf86432 Merge pull request #5544 from stuarth/change-language
Use gender-neutral pronouns
2021-09-01 13:59:04 +09:00
Stuart Hinson 2c167361d5 use gender-neutral pronouns 2021-08-31 19:17:49 -07:00
Yukihiro "Matz" Matsumoto 5211a3f209 Merge pull request #5543 from mruby/dependabot/github_actions/github/super-linter-4.6.3
build(deps): bump github/super-linter from 4.6.2 to 4.6.3
2021-09-01 07:03:01 +09:00
Yukihiro "Matz" Matsumoto 41d0b343e6 string.c: need to adjust index for UTF-8. 2021-09-01 07:00:56 +09:00
Yukihiro "Matz" Matsumoto 7ffffbfe01 build_config/ci/gcc-clang.rb: enable MRB_UTF8_STRING. 2021-09-01 07:00:55 +09:00
Yukihiro "Matz" Matsumoto 3622f2c4b5 string.c: implement __sub_replace() in C.
To reduce number of string allocation.
2021-09-01 07:00:55 +09:00
Yukihiro "Matz" Matsumoto 2c41739b66 mruby.h: obsolete mrb_to_str().
Replace them by `mrb_ensure_string_type()`.
2021-09-01 07:00:55 +09:00
Yukihiro "Matz" Matsumoto 082882da69 string.rb: avoid internal __to_str calls.
`__to_str` was a mere type check method despite its name.
2021-09-01 07:00:55 +09:00
Yukihiro "Matz" Matsumoto 8c296a3818 object.c: remove `mrb_convert_to_integer()' function.
And merged to `mrb_f_integer()` which is only usage of the function.
2021-09-01 07:00:54 +09:00
Yukihiro "Matz" Matsumoto 37a7ff228b string-ext/string.c: implement casecmp in C.
* should not raise error for non-string arguments
* avoid allocating case converted string internally
2021-09-01 07:00:54 +09:00
Yukihiro "Matz" Matsumoto f6e5c902f0 string.h: obsolete mrb_str_to_str(), even from examples. 2021-09-01 07:00:54 +09:00
Yukihiro "Matz" Matsumoto e86c9cb57c Do no use return values from mrb_ensure_ functions.
They return the checking argument without modification, so the values
are already there. Maybe we should change the return type to `void` but
keep them unchanged for compatibility.
2021-09-01 07:00:54 +09:00
Yukihiro "Matz" Matsumoto 572a43de84 mruby.h: reorganize mrb_ensure/check functions in headers. 2021-09-01 07:00:53 +09:00
dependabot[bot] ad5c90e556 build(deps): bump github/super-linter from 4.6.2 to 4.6.3
Bumps [github/super-linter](https://github.com/github/super-linter) from 4.6.2 to 4.6.3.
- [Release notes](https://github.com/github/super-linter/releases)
- [Commits](https://github.com/github/super-linter/compare/v4.6.2...v4.6.3)

---
updated-dependencies:
- dependency-name: github/super-linter
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-08-31 14:07:23 +00:00
Yukihiro "Matz" Matsumoto 64d5a40cde Merge pull request #5542 from dearblue/mrb_get_args-cI
Allow `nil` for `c!` and `I!` specifiers of `mrb_get_args()`
2021-08-30 07:38:45 +09:00
Yukihiro "Matz" Matsumoto 84e36d748c Merge pull request #5541 from dearblue/mrb_get_args-oCSAH
Integrate the processing of similar specifiers of `mrb_get_args()`
2021-08-29 08:32:05 +09:00
dearblue f99620436d Allow nil for c! and I! specifiers of mrb_get_args() 2021-08-28 15:54:30 +09:00
dearblue c9f7bcc0cf Integrate the processing of similar specifiers of mrb_get_args()
It is `o`, `C`, `S`, `A` and `H` specifiers that are integrated.
As a side effect, the `C!` Specifier can now be used.
2021-08-28 15:52:37 +09:00
Yukihiro "Matz" Matsumoto 07f12fe890 Merge pull request #5540 from dearblue/mrb_get_args
Refactor the `mrb_get_args()` function
2021-08-28 12:50:47 +09:00
dearblue 6ac8d14b7b Refactor the mrb_get_args() function
- Removed the `ARGV` macro.
  The current path doesn't go into the mruby VM and there's also no need to separate variables.
- Use common functions to check object types.
  - Use `mrb_ensure_string_type()` to check the string instead of `mrb_to_str()`.
    This is for consistency with array and hash.
  - Use `mrb_ensure_array_type()` to check the array instead of `to_ary()`.
  - Use `mrb_ensure_hash_type()` to check the hash instead of `to_hash()`.
  - Add and use `ensure_class_type()` to check class and module.
- Changed the argument index type from `mrb_int` to `int`.
  Even if it is `int16_t`, it is enough.
  `mrb_int` is overkill, especially if `MRB_32BIT` and `MRB_INT64` are defined.
2021-08-27 22:43:25 +09:00
Yukihiro "Matz" Matsumoto 12a483c1bc Merge pull request #5539 from mruby/dependabot/github_actions/github/super-linter-4.6.2
build(deps): bump github/super-linter from 4.6.1 to 4.6.2
2021-08-27 07:43:48 +09:00
dependabot[bot] 86c5414dc1 build(deps): bump github/super-linter from 4.6.1 to 4.6.2
Bumps [github/super-linter](https://github.com/github/super-linter) from 4.6.1 to 4.6.2.
- [Release notes](https://github.com/github/super-linter/releases)
- [Commits](https://github.com/github/super-linter/compare/v4.6.1...v4.6.2)

---
updated-dependencies:
- dependency-name: github/super-linter
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-08-26 14:05:40 +00:00
Yukihiro "Matz" Matsumoto 4654de9074 etc.c: keep full float32 with MRB_64BIT and MRB_USE_FLOAT32. 2021-08-26 16:06:02 +09:00
Yukihiro "Matz" Matsumoto ba6e121537 boxing_nan.h: rename prefix BOXNAN to NANBOX. 2021-08-26 16:06:02 +09:00
Yukihiro "Matz" Matsumoto 9d6755569e boxing_word.h: rename prefix BOXWORD to WORDBOX. 2021-08-26 16:06:01 +09:00
Yukihiro "Matz" Matsumoto fdfa0caa46 boxing_word.h: rename configuration macro name.
`MRB_WORDBOX_USE_HEAP_FLOAT` instead of `MRB_USE_FLOAT_FULL_PRECISION`.
2021-08-26 16:06:01 +09:00
Yukihiro "Matz" Matsumoto e9c6e52f5b value.h: reconstruct mrb_ro_data_p().
* use predefined `mrb_ro_data_p()` for user-mode Linux and macOS
* define `MRB_LINK_TIME_RO_DATA_P` if predefined one is used
* configure macro `MRB_USE_LINK_TIME_RO_DATA_P` is no longer used
* contributions for new platforms are welcome
2021-08-26 16:06:01 +09:00
Yukihiro "Matz" Matsumoto d00ae8d166 Merge pull request #5538 from jbampton/pre-commit-autoupdate
pre-commit autoupdate
2021-08-26 11:11:04 +09:00
John Bampton db884a05e8 pre-commit autoupdate
https://pre-commit.com/#pre-commit-autoupdate
2021-08-25 18:24:02 +10:00
Yukihiro "Matz" Matsumoto b8b86d1976 Merge pull request #5535 from dearblue/get-args-frozen
Checks the frozen object with `mrb_get_args()`
2021-08-24 16:33:15 +09:00
dearblue 66aa184a82 Checks the frozen object with mrb_get_args()
This now works with the `+` modifier that can be added after each specifier.

- `nil` is bypassed.
- The `s` and `z` specifiers are received in C as a `const char *`, so adding a `+` modifier will raise an exception.
- The `a` specifier is received in C as `const mrb_value *`, so adding a `+` modifier will raise an exception.
- The `|`, `*`, `&`, `?` and `:` specifiers with `+` modifier raises an exception.

If `!`/`+` exceeds one for each specifier, an exception will occur in the subsequent processing.
This is the same behavior as before.
2021-08-23 21:58:57 +09:00
dearblue 6415faabaa Integrate each element expansion process of the argument
The previously used `given` variable will be merged into the `pickarg` pointer variable, which points to the argument currently being processed for each loop.
2021-08-23 21:58:51 +09:00
Yukihiro "Matz" Matsumoto 6f46f88873 numeric.c: fix: -0.0.abs returned -0.0. 2021-08-23 10:53:23 +09:00
Yukihiro "Matz" Matsumoto 11cfe77eb1 Merge pull request #5537 from dearblue/header-files
Organize the include of header files
2021-08-23 07:34:37 +09:00
Yukihiro "Matz" Matsumoto 0f36710445 Merge pull request #5536 from dearblue/random-seed
Stirs internal state when `seed` is set in `Random`
2021-08-22 12:37:34 +09:00
dearblue 5a57602860 Organize the include of header files
- `#include <math.h>` is done in `mruby.h`.
  Eliminate the need to worry about the `MRB_NO_FLOAT` macro.

- Include mruby header files before standard header files.
  If the standard header file is already placed before `mruby.h`, the standard header file added in the future tends to be placed before `mruby.h`.

This change should some reduce the chances of macros that must be defined becoming undefined in C++ or including problematic header files in a particular mruby build configuration.
2021-08-21 15:42:57 +09:00
dearblue 2121b6e689 Stirs internal state when seed is set in Random
This is to avoid the approximation of `Random#rand` when `seed`s are close together.

For example, the first `#rand` values after doing `Random#srand(0)` and `Random#srand(1)` are very similar.

Below is the sequence of mruby before this patch was given a `seed` of `0...20`:

```console
% bin/mruby -e 'r = Random.new; 20.times { |i| r.srand(i); puts "seed=%2d  %s" % [i, 10.times.map { "%0.3f" % r.rand }.join(" ")] }'
seed= 0  0.643 0.585 0.198 0.732 0.087 0.605 0.548 0.468 0.573 0.966
seed= 1  0.643 0.585 0.198 0.607 0.370 0.605 0.633 0.593 0.395 0.439
seed= 2  0.643 0.585 0.197 0.981 0.652 0.730 0.875 0.713 0.529 0.269
seed= 3  0.643 0.585 0.198 0.857 0.934 0.730 0.960 0.216 0.286 0.523
seed= 4  0.643 0.585 0.197 0.231 0.217 0.605 0.959 0.958 0.478 0.482
seed= 5  0.643 0.585 0.197 0.106 0.249 0.605 0.044 0.330 0.925 0.047
seed= 6  0.643 0.585 0.197 0.481 0.781 0.731 0.285 0.960 0.804 0.725
seed= 7  0.643 0.585 0.197 0.356 0.813 0.731 0.370 0.711 0.937 0.448
seed= 8  0.643 0.585 0.198 0.732 0.329 0.108 0.243 0.974 0.766 0.936
seed= 9  0.643 0.585 0.198 0.607 0.611 0.108 0.827 0.102 0.962 0.597
seed=10  0.643 0.585 0.198 0.981 0.393 0.233 0.569 0.723 0.472 0.805
seed=11  0.643 0.585 0.198 0.857 0.676 0.233 0.154 0.222 0.603 0.371
seed=12  0.643 0.585 0.198 0.231 0.458 0.108 0.654 0.979 0.928 0.577
seed=13  0.643 0.585 0.198 0.106 0.490 0.108 0.239 0.355 0.749 0.831
seed=14  0.643 0.585 0.198 0.481 0.523 0.233 0.981 0.486 0.505 0.131
seed=15  0.643 0.585 0.198 0.356 0.555 0.234 0.565 0.233 0.011 0.666
seed=16  0.643 0.585 0.197 0.730 0.573 0.611 0.904 0.512 0.971 0.153
seed=17  0.643 0.585 0.197 0.605 0.855 0.611 0.240 0.636 0.041 0.509
seed=18  0.643 0.585 0.196 0.979 0.137 0.736 0.229 0.765 0.674 0.832
seed=19  0.643 0.585 0.197 0.855 0.420 0.736 0.566 0.268 0.183 0.219
```
2021-08-21 15:37:12 +09:00
Yukihiro "Matz" Matsumoto 886055b3fb etc.c: clear mrb_value if sizeof(void*) is bigger than sizeof(mrb_float). 2021-08-21 15:25:59 +09:00
Yukihiro "Matz" Matsumoto 8ca40da3fe test/float.rb: avoid 1.0e16 in tests without precision specified. 2021-08-21 15:25:59 +09:00
Yukihiro "Matz" Matsumoto 3b4c4caddc mruby-test/driver.c: change FLOAT_TOLERANCE bigger for inline floats. 2021-08-21 15:25:59 +09:00
Yukihiro "Matz" Matsumoto 36632f55f4 boxing_word.h: embed mrb_float in mrb_value if possible.
Embedding reduce memory consumption, sacrificing precision. It clips least
significant 2 bits from `mrb_float`, so if you need to keep float precision,
define `MRB_USE_FLOAT_FULL_PRECISION`.

`MRB_WORD_BOXING` and `MRB_INT64`:

`mrb_float` (`double`) is embedded in `mrb_value` clipped last 2 bits.

`MRB_WORD_BOXING` and `MRB_INT64` and `MRB_USE_FLOAT_FULL_PRECISION`:

`mrb_float` is allocated in the heaps wrapped by `struct RFloat`.

`MRB_WORD_BOXING` and `MRB_INT32` and `MRB_USE_FLOAT32`:

`mrb_float` (`float`) is embedded in `mrb_value` clipped last 2 bits.
In addition, to reserve bit space in the `mrb_value`, maximum inline
symbol length become 4 (instead of 5) in the configuration.

`MRB_WORD_BOXING` and `MRB_INT32`:

Assume `MRB_USE_FLOAT_FULL_PRECISION` and allocate Float values in heap.
2021-08-21 15:25:58 +09:00
Yukihiro "Matz" Matsumoto 4ea80913c2 Merge pull request #5533 from dantecatalfamo/serenity-32bit-crossbuild
Add SerenityOS crossbuild
2021-08-21 15:25:46 +09:00
Dante Catalfamo 7f290bebaf Specify potential values for SERENITY_ARCH 2021-08-20 22:27:50 -04:00
Dante Catalfamo 5e030491e7 Replace 32-bit serenity config with 64-bit compatible version. 2021-08-20 14:48:49 -04:00
Dante Catalfamo 124c4d617f Add serenity-32bit crossbuild
Cross compile mruby for SerenityOS (https://github.com/SerenityOS/serenity)
2021-08-19 23:34:30 -04:00
Yukihiro "Matz" Matsumoto ca295a2c23 symbol.c: reduce memory by avoiding alignment gaps.
In additions:

* use bitmap for flags
* BER integer compression for length
2021-08-19 20:39:34 +09:00
Yukihiro "Matz" Matsumoto 7f8b30261f gc.c: remove unused structs from RVALUE. 2021-08-19 16:06:17 +09:00
Yukihiro "Matz" Matsumoto 6f305c01a2 value.h: fixed warnings on __APPLE__. 2021-08-19 13:08:39 +09:00
Yukihiro "Matz" Matsumoto 959383df75 value.h: enable mrb_ro_data_p() on __linux__ and __APPLE__.
Probably we should add conditions for FreeBSD, etc.
2021-08-19 12:52:10 +09:00
Yukihiro "Matz" Matsumoto ef66406c50 string.c: mrb_str_to_cstr() should always return a mutable string. 2021-08-18 21:40:10 +09:00
Yukihiro "Matz" Matsumoto 20635e6bdc debug.c: export integer compressing functions.
- mrb_packed_int_len()
- mrb_packed_int_encode()
- mrb_packed_int_decode()
2021-08-18 17:18:04 +09:00
Yukihiro "Matz" Matsumoto 96a8703ca8 boxing_word.h: simplifies inline symbols on MRB_64BIT. 2021-08-17 16:03:42 +09:00
Yukihiro "Matz" Matsumoto 80cf293bf6 pack.c: rename pack/unpack functions for readability. 2021-08-17 13:04:11 +09:00
Yukihiro "Matz" Matsumoto 57b347088d fixup! pack.c: reduce dispatch in pack_unpack(). 2021-08-17 13:04:06 +09:00
Yukihiro "Matz" Matsumoto 4385590d31 pack.c: reduce dispatch in pack_unpack(). 2021-08-17 12:52:56 +09:00
Yukihiro "Matz" Matsumoto bfe2bd4960 pack.c: fix M packing bug. 2021-08-16 10:56:44 +09:00
Yukihiro "Matz" Matsumoto 8d85d4ac9b AUTHORS: update. [ci skip] 2021-08-15 07:07:08 +09:00
Yukihiro "Matz" Matsumoto 40c4c5d344 random.c: use I specifier for mrb_get_args(); ref #5530 2021-08-14 15:28:38 +09:00
Yukihiro "Matz" Matsumoto 8e5e96239c pack.c: fixed a overwriting bug in pack_w and pack_M. 2021-08-14 14:58:09 +09:00
Yukihiro "Matz" Matsumoto ad194bd46b error.c: the error message may contain NUL character. 2021-08-14 13:01:47 +09:00
Yukihiro "Matz" Matsumoto 73798bff65 Merge pull request #5532 from dantecatalfamo/rhel-doxygen
Add instructions for installing doxygen on RHEL/Fedora/CentOS
2021-08-14 08:18:11 +09:00
Dante Catalfamo 89ea8fa34a Add instructions for installing doxygen on RHEL/Fedora/CentOS 2021-08-13 14:53:20 -04:00
Yukihiro "Matz" Matsumoto 32c30c35b2 Merge pull request #5530 from dearblue/mrb_get_args-I
Check the class with `I` specifier of `mrb_get_args()`
2021-08-13 18:11:26 +09:00
dearblue 01da5e1392 Check the class with I specifier of mrb_get_args()
Previously, the `I` specifier only checked if the object was `MRB_TT_ISTRUCT`.
So it was at risk of getting pointers to different C structs if multiple classes were to use the `MRB_TT_ISTRUCT` instance.

Change this behavior and change the C argument corresponding to the `I` specifier to `(void *, struct RClass)`.

This change is not compatible with the previous mruby.
Please note that if the user uses the previous specifications, `SIGSEGV` may occur or the machine stack may be destroyed.

resolve #5527
2021-08-13 15:04:19 +09:00
Yukihiro "Matz" Matsumoto 9e74aad43c codegen.c: fixed a bug in mrb_decode_insn(). 2021-08-13 12:38:10 +09:00
Yukihiro "Matz" Matsumoto 7907c184be codegen.c: add a comment that notice rewind_pc calling convention.
`rewind_pc` should not be called when `s->pc` is `0` (top).
2021-08-13 10:11:36 +09:00
Yukihiro "Matz" Matsumoto 9c3d305530 codegen.c: refactor mrb_last_insn().
Last commit made `mrb_decode_insn()` to take `NULL` as `pc`.
2021-08-13 10:10:17 +09:00
Yukihiro "Matz" Matsumoto cbdc4f2c5c codegen.c: mrb_prev_pc can return NULL at the top of iseq. 2021-08-13 10:02:01 +09:00
Yukihiro "Matz" Matsumoto 013365498d test/eval.c: add test for #5528 2021-08-12 11:57:56 +09:00
Yukihiro "Matz" Matsumoto 43f9901ec2 Revert "Drop unnecessary upper procs linked from class/module/def syntax"
Fix #5528
This reverts commit 59201b59046b9e73c309508350cd3c0fafd20e4d; #5497
2021-08-12 11:42:27 +09:00
Yukihiro "Matz" Matsumoto 80893811c0 class.c: const_missing do not have to be in the backtrace; ref #5528 2021-08-12 08:10:09 +09:00
Yukihiro "Matz" Matsumoto e1b170160b codegen.c: avoid signedness warning of int comparison. 2021-08-11 16:10:32 +09:00
Yukihiro "Matz" Matsumoto a85f2299c0 codegen.c: avoid cross initialization of mrb_insn_data. 2021-08-11 16:09:51 +09:00
Yukihiro "Matz" Matsumoto fd597d2655 codedump.c: print local variable name for `ADDI/SUBI/ instructions.
Recent peephole optimization made `ADDI/SUBI` destinations possibly
local variables.
2021-08-11 10:48:18 +09:00
Yukihiro "Matz" Matsumoto b1b9b157f8 codegen.c: more peephole optimization.
`a=10; a+=1` to generate:

```
    1 000 OP_LOADI      R1      11              ; R1:a
```

instead of:

```
    1 000 OP_LOADI      R1      10              ; R1:a
    1 003 OP_MOVE       R2      R1              ; R1:a
    1 006 OP_ADDI       R2      1
    1 009 OP_MOVE       R1      R2              ; R1:a
```
2021-08-11 10:48:18 +09:00
Yukihiro "Matz" Matsumoto 52eb2af7d0 Merge pull request #5526 from mruby/dependabot/github_actions/github/super-linter-4.6.1
build(deps): bump github/super-linter from 4.6.0 to 4.6.1
2021-08-11 06:27:53 +09:00
dependabot[bot] b83eb8dcff build(deps): bump github/super-linter from 4.6.0 to 4.6.1
Bumps [github/super-linter](https://github.com/github/super-linter) from 4.6.0 to 4.6.1.
- [Release notes](https://github.com/github/super-linter/releases)
- [Commits](https://github.com/github/super-linter/compare/v4.6.0...v4.6.1)

---
updated-dependencies:
- dependency-name: github/super-linter
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-08-10 14:06:15 +00:00
Yukihiro "Matz" Matsumoto 3909281126 Merge pull request #5524 from dearblue/gem-headers
Expose all header files of the gems for small compilation
2021-08-10 06:21:18 +09:00
dearblue 4c25ace8b3 Expose all header files of the gems for small compilation
After building mruby, if the user compiles and links to `libmruby.a`, expose the included directory of the captured gems.
This is a change to the `<build-dir> /lib/libmruby.flags.mak` file and will result in being added to `bin/mruby-config --cflags`.
This eliminates the need for the user to look up the path and add the compiler flag if the user wants to take advantage of her gems publishing features.

In the main build with `rake CONFIG=...`, there is no problem because it can only be seen from the gems that depends directly and indirectly as before.
However, when compiling independently by the user using `bin/mruby-config`, a header file name collision may occur if a unique header directory is added.
2021-08-09 21:16:45 +09:00
Yukihiro "Matz" Matsumoto e8dbf1db9a Merge pull request #5525 from jbampton/pre-commit-autoupdate
pre-commit autoupdate
2021-08-09 11:38:31 +09:00
John 530a91752f pre-commit autoupdate
https://pre-commit.com/#pre-commit-autoupdate
2021-08-09 10:10:09 +10:00
Yukihiro "Matz" Matsumoto 0b2ebf4868 Merge pull request #5522 from dearblue/pack-EOF
Fixed compilation error of "mruby-pack" with `MRB_NO_STDIO`
2021-08-09 08:39:12 +09:00
Yukihiro "Matz" Matsumoto 1e1d296497 Merge pull request #5523 from jbampton/patch-1
docs: fix case of mruby
2021-08-08 09:25:23 +09:00
John Bampton 0516d94c83 docs: fix case of mruby 2021-08-07 16:51:04 +10:00
dearblue 18ef4e35f3 Fixed compilation error of "mruby-pack" with MRB_NO_STDIO 2021-08-07 14:29:55 +09:00
Yukihiro "Matz" Matsumoto 35d230a669 codedump.c: print two operands R(x) and R(x+1) for clarity. 2021-08-07 12:12:24 +09:00
Yukihiro "Matz" Matsumoto 06f49b3f84 codegen.c: need to push the value when the loop was eliminated. 2021-08-07 12:11:38 +09:00
Yukihiro "Matz" Matsumoto cd02cef465 array.h: avoid duplicated defined of MRB_ARY_NO_EMBED; fix #5520 2021-08-07 06:48:03 +09:00
Yukihiro "Matz" Matsumoto ce0b38fb72 Merge pull request #5521 from mruby/dependabot/github_actions/github/super-linter-4.6.0
build(deps): bump github/super-linter from 4.5.1 to 4.6.0
2021-08-07 06:46:35 +09:00
dependabot[bot] d0b214c269 build(deps): bump github/super-linter from 4.5.1 to 4.6.0
Bumps [github/super-linter](https://github.com/github/super-linter) from 4.5.1 to 4.6.0.
- [Release notes](https://github.com/github/super-linter/releases)
- [Commits](https://github.com/github/super-linter/compare/v4.5.1...v4.6.0)

---
updated-dependencies:
- dependency-name: github/super-linter
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-08-06 14:05:46 +00:00
Yukihiro "Matz" Matsumoto 46a1c40fe3 numeric_ext.c: fix a bug regarding MRB_INT_MIN. 2021-08-06 11:16:12 +09:00
Yukihiro "Matz" Matsumoto ff2da0b66e numeric.c: fix a bug regarding MRB_INT_MIN. 2021-08-06 11:15:46 +09:00
Yukihiro "Matz" Matsumoto 37dbb91b96 codegen.c: -9223372036854775808 % -1 overflows 64 bit integer. 2021-08-06 10:35:06 +09:00
Yukihiro "Matz" Matsumoto 7ecc16f97a codegen.c: remove code duplication from NODE_ARRAY. 2021-08-05 16:59:32 +09:00
Yukihiro "Matz" Matsumoto 9cb44f5ae3 codegen.c: detect integer overflow in division.
`MRB_INT_MIN / -1` overflows.
2021-08-04 12:25:14 +09:00
Yukihiro "Matz" Matsumoto 9f37733382 numeric.c: fix a bug in left shift of negative integer.
`-1 * (1<<63)` causes overflow, but `-1<<63` is a valid value.
2021-08-04 12:05:09 +09:00
Yukihiro "Matz" Matsumoto 9b3b2a4c95 numeric.c: check zero division before modulo. 2021-08-03 16:45:08 +09:00
Yukihiro "Matz" Matsumoto caaa07f2da codegen.c: check zero division before constant folding. 2021-08-03 16:43:50 +09:00
Yukihiro "Matz" Matsumoto c480ac4457 numeric_ext.c: modulo and remainder should handle infinite argument. 2021-08-03 16:35:31 +09:00
Yukihiro "Matz" Matsumoto e75572af6a numeric_ext.c: add Float#modulo and #remainder methods. 2021-08-03 16:30:47 +09:00
Yukihiro "Matz" Matsumoto f4afcbef67 numeric_ext.c: update Integer#remainder method.
- need to detect zero division error
- support floating point number argument (as `%`)
2021-08-03 16:28:11 +09:00
Yukihiro "Matz" Matsumoto b70fd09f47 Revert "numeric.c: simplifies int_mod definition."
This reverts commit 3738d62a86.
The change changed the behavior with floating point numbers.
2021-08-03 16:11:02 +09:00
Yukihiro "Matz" Matsumoto 2092bc7fe8 codegen.c: avoid division by zero in constant folding. 2021-08-03 15:57:01 +09:00
Yukihiro "Matz" Matsumoto fad47a98a7 numeric_ext.c: use mrb_integer instead of mrb_as_int.
`mrb_as_int` implicitly converts the value into the integer, but those
methods are defined for Integer class so that the value should always be
integers.
2021-08-03 13:15:34 +09:00
Yukihiro "Matz" Matsumoto 3738d62a86 numeric.c: simplifies int_mod definition. 2021-08-03 13:14:23 +09:00
Yukihiro "Matz" Matsumoto df6ef39d1c numeric_ext.c: define modulo and remainder methods for Integer. 2021-08-03 13:13:42 +09:00
Yukihiro "Matz" Matsumoto b9d2b47f16 Replace mrb_fixnum_value() with mrb_int_value().
Use `mrb_fixnum_value()` only when you are absolutely sure that the
value is within `Fixnum` range, i.e. 31 bits signed integer at least.
2021-08-03 13:00:11 +09:00
Yukihiro "Matz" Matsumoto 23e7cb41e5 Replace fixnum references with int.
The `Fixnum` class is no longer provided by `mruby`.
2021-08-03 13:00:10 +09:00
Yukihiro "Matz" Matsumoto 019b006ee5 numeric_ext.c: remove unnecessary prefix mrb_ from static functions. 2021-08-03 10:33:04 +09:00
Yukihiro "Matz" Matsumoto 1f0238a928 numeric.c: rename fixdivmod to intdivmod. 2021-08-03 07:30:59 +09:00
Yukihiro "Matz" Matsumoto 4fa24e4ff9 codegen.c: allow constant folding for negative integer modulo. 2021-08-02 16:48:16 +09:00
Yukihiro "Matz" Matsumoto 81d56477f2 numeric.c: simpler integer modulo calculation. 2021-08-02 16:47:50 +09:00
Yukihiro "Matz" Matsumoto 504d05232d mrdb.c: do not skip OP_JMP on step execution. 2021-08-02 16:19:08 +09:00
Yukihiro "Matz" Matsumoto e93642d53f codegen.c: refactor readint() to read MRB_INT_MIN. 2021-08-02 14:10:38 +09:00
Yukihiro "Matz" Matsumoto 6ea0c04c06 numeric.c: use C's modulo operator if both operands are positive. 2021-08-02 14:09:38 +09:00
Yukihiro "Matz" Matsumoto a5ac9c8790 test/driver.c: remove unused constants related to FIXNUM. 2021-08-02 08:56:38 +09:00
Yukihiro "Matz" Matsumoto 9902ab50fc codegen.c: fix a bug in bit shift constant folding. 2021-08-02 08:53:50 +09:00
Yukihiro "Matz" Matsumoto a9d721ea8f numeric.c: refactor integer bit shift operations. 2021-08-02 08:53:14 +09:00
Yukihiro "Matz" Matsumoto 907df715ef codegen.c: refactor unary operator optimization. 2021-08-02 08:51:39 +09:00
Yukihiro "Matz" Matsumoto 188c150f44 codegen.c: constant folding binary operators, <<, >>, %, &, |, ^. 2021-08-02 07:34:54 +09:00
Yukihiro "Matz" Matsumoto 1315e8751e codegen.c: eliminate loop if condition is constant.
For example, `while false; ...; end` should be removed.
2021-08-01 20:33:41 +09:00
Yukihiro "Matz" Matsumoto 9dc801a798 codegen.c: peephole optimize OP_JMPxxx. 2021-08-01 20:31:19 +09:00
Yukihiro "Matz" Matsumoto b1cb6c3c69 codegen.c: allow constant folding for mul / div. 2021-07-31 21:14:54 +09:00
Yukihiro "Matz" Matsumoto 43999492a7 codegen.c: mrb_prev_pc() to take previous instruction position.
It rescans `s->iseq` so that peephole optimizer can take multiple
previous instructions for constant folding, etc.
2021-07-31 21:11:36 +09:00
Yukihiro "Matz" Matsumoto 4306893971 codedump.c: instruction length should be ilen, not iseq. 2021-07-30 17:50:24 +09:00
Yukihiro "Matz" Matsumoto 517071e3fa codegen.c: order instructions in natural order for loops.
`while` and `until` generates in `cond` `jmpif` `body` `jmp` order.
It used to be in `jmp` `body` `cond` `jmpif` order.
2021-07-29 17:38:18 +09:00
Yukihiro "Matz" Matsumoto 5cde5983d9 debug.c: uses most space efficient packed map for line information. 2021-07-28 23:08:58 +09:00
Yukihiro "Matz" Matsumoto 64358c09d9 codegen.c: labels should be uint32_t. 2021-07-28 23:08:58 +09:00
Yukihiro "Matz" Matsumoto adfd29c1b0 codegen.c: fix loopinfo structure members.
- `pc0`: `next` destination
- `pc1`: `redo` destination (renamed from `pc2`)
- `pc3`: `break` destination (renamed from `pc3`)

old `pc1` was unused so removed.
2021-07-28 23:08:58 +09:00
Yukihiro "Matz" Matsumoto e81d497155 codegen.c: removed bytecode when the value of while is not used. 2021-07-28 23:08:58 +09:00
Yukihiro "Matz" Matsumoto 2910af0010 codegen.c: fixed a bug when value is taken from while and until.
```ruby
p ((while true; p 1; break; end))
```

should print `1 nil` but was `1`.
2021-07-28 23:08:57 +09:00
Yukihiro "Matz" Matsumoto 9dd3e23fc9 Merge pull request #5518 from jbampton/pre-commit-autoupdate
pre-commit autoupdate
2021-07-28 23:08:10 +09:00
John Bampton cbd54782c6 pre-commit autoupdate
https://pre-commit.com/#pre-commit-autoupdate
2021-07-28 21:21:57 +10:00
Yukihiro "Matz" Matsumoto 1f1dca1746 parse.y: fix an integer cast warning. 2021-07-26 11:46:22 +09:00
Yukihiro "Matz" Matsumoto 984161e6bb parse.y: mrb_int_read() returns mrb_int not unsigned long.
Also, now too big capture group index just gives `nil`, not error.
2021-07-26 11:20:59 +09:00
Yukihiro "Matz" Matsumoto 4803718b14 parse.y: unify redundant functions yywarn() and yywarning(). 2021-07-26 11:12:10 +09:00
Yukihiro "Matz" Matsumoto f6b37ff44d debug.c: small refactoring. 2021-07-26 11:10:20 +09:00
Yukihiro "Matz" Matsumoto b4696c3935 debug.c: remove type cast warnings. 2021-07-26 11:09:42 +09:00
Yukihiro "Matz" Matsumoto 642497fe19 fmt_fp.c: add implicit cast from mrb_float to int8_t. 2021-07-26 10:57:42 +09:00
Yukihiro "Matz" Matsumoto 966aa476d1 vm.c: fix integer type error in mrb_protect_error. 2021-07-26 10:49:12 +09:00
Yukihiro "Matz" Matsumoto 6175db2746 irep.h: operand c should be fit in uint8_t. 2021-07-26 10:47:40 +09:00
Yukihiro "Matz" Matsumoto 22b24d5d76 test/binding.rb: remove a duplicated test. 2021-07-26 10:46:36 +09:00
Yukihiro "Matz" Matsumoto 26340a8818 time.c: fixed a potential buffer overflow in time_zonename. 2021-07-25 16:43:00 +09:00
Yukihiro "Matz" Matsumoto c2c0250063 time.c: fixed time_zonename buffer size bug. 2021-07-25 16:38:37 +09:00
Yukihiro "Matz" Matsumoto 368b75d81b time.c: stop returning LOCAL for the zone name from Time.zone. 2021-07-25 13:07:11 +09:00
Yukihiro "Matz" Matsumoto 2bed2fabae time.c: update the document for Time#usec; close #5515 2021-07-25 13:07:11 +09:00
Yukihiro "Matz" Matsumoto 47eca476e8 pack.c: fixed sign comparison warning. 2021-07-25 13:07:11 +09:00
Yukihiro "Matz" Matsumoto 8de8521cb6 parse.y: replace strtoul() by mrb_int_read(). 2021-07-25 13:07:10 +09:00
Yukihiro "Matz" Matsumoto 5c804cf68f Remove redundant include headers.
- stdlib.h
- stddef.h
- stdint.h
- stdarg.h
- limits.h
- float.h
2021-07-25 13:07:10 +09:00
Yukihiro "Matz" Matsumoto 1f90a39799 Merge pull request #5514 from mruby/dependabot/github_actions/github/super-linter-4.5.1
build(deps): bump github/super-linter from 4.5.0 to 4.5.1
2021-07-24 13:21:08 +09:00
dependabot[bot] 5b3a4b36c7 build(deps): bump github/super-linter from 4.5.0 to 4.5.1
Bumps [github/super-linter](https://github.com/github/super-linter) from 4.5.0 to 4.5.1.
- [Release notes](https://github.com/github/super-linter/releases)
- [Commits](https://github.com/github/super-linter/compare/v4.5.0...v4.5.1)

---
updated-dependencies:
- dependency-name: github/super-linter
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-07-23 14:06:33 +00:00
Yukihiro "Matz" Matsumoto 9c43276eb5 codegen.c: fixed a bug in OP_LOADI32 peephole optimization. 2021-07-23 11:20:18 +09:00
Yukihiro "Matz" Matsumoto 598c97ef76 codegen.c: get_int_operand() to support OP_LOADL (int in pool). 2021-07-22 11:49:47 +09:00
Yukihiro "Matz" Matsumoto d0fed63414 codegen.c: add constant folding for unary numeric operators (+, -, ~). 2021-07-22 11:39:52 +09:00
Yukihiro "Matz" Matsumoto 3e9ed1cca2 codegen.c: compare symbol names directly avoiding string conversion. 2021-07-22 11:21:00 +09:00
Yukihiro "Matz" Matsumoto e42f192827 codegen.c: skip -@ call if the argument is a literal integer. 2021-07-21 13:20:34 +09:00
Yukihiro "Matz" Matsumoto 2ef6e94489 codegen.c: move gen_setxv() after new_sym(). 2021-07-21 13:15:27 +09:00
Yukihiro "Matz" Matsumoto 81b384e3fb codegen.c: introduce gen_int() to generate integer instructions. 2021-07-21 13:15:27 +09:00
Yukihiro "Matz" Matsumoto 47fca90069 codegen.c: add peephole optimization for OP_LOADI32 before OP_MOVE. 2021-07-21 08:00:02 +09:00
Yukihiro "Matz" Matsumoto 28bf950e01 codegen.c: add peephole optimization for OP_LOADI16 before OP_MOVE. 2021-07-21 07:54:08 +09:00
Yukihiro "Matz" Matsumoto 275fe8c94b codegen.c: a new function get_int_operand. 2021-07-21 07:52:39 +09:00
Yukihiro "Matz" Matsumoto 5066e2370d codegen.c: negative zero equals to positive zero.
`OP_LOADI Rn -0` should be `OP_LOADI_0`.
2021-07-20 18:24:33 +09:00
Yukihiro "Matz" Matsumoto cdf54f3159 codegen.c: allow OP_EXT before OP_ADDI and OP_SUBI.
This is preparation for integer constant folding.
2021-07-20 11:07:37 +09:00
Yukihiro "Matz" Matsumoto 43f6f765b0 Remove unused prototypes for mrb_proc_merge_lvar(); ref #5511 2021-07-19 07:42:49 +09:00
Yukihiro "Matz" Matsumoto ed2a6a160e Merge pull request #5511 from dearblue/binding.3
Explicit write barrier for binding
2021-07-19 07:40:22 +09:00
Yukihiro "Matz" Matsumoto 71c778dbfc Merge pull request #5510 from dearblue/check-stdint
Output an error if the `INTPTR_MAX` macro is undefined in C++
2021-07-18 14:34:48 +09:00
Yukihiro "Matz" Matsumoto 86f8edca64 Merge pull request #5509 from dearblue/cast-c++
Avoid implicit casting from void pointers for C++
2021-07-17 20:55:18 +09:00
dearblue de4523f793 Explicit write barrier for binding 2021-07-17 20:43:19 +09:00
dearblue dbd249cace Output an error if the INTPTR_MAX macro is undefined in C++
When doing `conf.enable_cxx_abi` and compiling with FreeBSD + clang or MinGW, such as `INTPTR_MAX` constant macro is not defined if `#include <stdint.h>` precedes `#include <mruby.h>`.
Currently I get a warning when I use an undefined macro, but if I don't notice it I get confused in a link error.
It can be expected that the problem will be easier to understand by making a clear error.

Adding `-Werror=undef` as a compiler flag can also result in an error, but this can be a problem if the system header file itself uses undefined macros, for example.
This patch does minimal confirmation only, but has no side effects.
2021-07-17 20:32:38 +09:00
dearblue c8750048be Avoid implicit casting from void pointers for C++ 2021-07-17 20:21:30 +09:00
Yukihiro "Matz" Matsumoto d4e22c2cec codedump.c: update some instructions.
- OP_GETGV
- OP_SETGV
- OP_GETSV
- OP_SETSV
- OP_GETIV
- OP_SETIV
- OP_GETCV
- OP_SETCV
- OP_GETCONST
- OP_SETCONST
- OP_GETMCNST
- OP_SETMCNST
- OP_GETUPVAR
- OP_SETUPVAR
2021-07-17 19:51:25 +09:00
Yukihiro "Matz" Matsumoto 887df090cb codegen.c: optimize variable assignments after OP_MOVE.
- `OP_SETGV`
- `OP_SETIV`
- `OP_SETCV`
- `OP_SETCONST`
2021-07-17 19:51:25 +09:00
Yukihiro "Matz" Matsumoto 4dda97502b codegen.c: optimize OP_SETUPVAR after OP_MOVE. 2021-07-17 19:51:24 +09:00
Yukihiro "Matz" Matsumoto 3401396a16 Merge pull request #5508 from mruby/dependabot/github_actions/github/super-linter-4.5.0
build(deps): bump github/super-linter from 4.4.1 to 4.5.0
2021-07-16 07:57:58 +09:00
Yukihiro "Matz" Matsumoto 70f31d4bb4 codegen.c: add new peephole optimization for OP_MOVE.
If `OP_MOVE` comes after `OP_GETUPVAR`, you can skip move and redirect
the destination register of `OP_GETUPVAR`.
2021-07-16 07:55:25 +09:00
Yukihiro "Matz" Matsumoto 1a3564f2f1 codegen.c: add new peephole optimization for OP_GETUPVAR.
When `OP_GETUPVAR` is generated right after `OP_SETUPVAR`, there is no
need to read the upvar back to the register, e.g.

    3 008 OP_ADDI       R2      1
    3 011 OP_SETUPVAR   R2      1       0
    4 015 OP_GETUPVAR   R2      1       0
    4 019 OP_LOADI_2    R3

`OP_GETUPVAR` at the address `015` is useless. We can skip it like:

    3 008 OP_ADDI       R2      1
    3 011 OP_SETUPVAR   R2      1      0
    4 015 OP_LOADI_2    R3
2021-07-16 07:52:21 +09:00
dependabot[bot] 1284c0615e build(deps): bump github/super-linter from 4.4.1 to 4.5.0
Bumps [github/super-linter](https://github.com/github/super-linter) from 4.4.1 to 4.5.0.
- [Release notes](https://github.com/github/super-linter/releases)
- [Commits](https://github.com/github/super-linter/compare/v4.4.1...v4.5.0)

---
updated-dependencies:
- dependency-name: github/super-linter
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-07-15 14:06:05 +00:00
Yukihiro "Matz" Matsumoto d4abbf1b77 test/syntax.rb: add tests for break and redo. 2021-07-15 15:22:23 +09:00
Yukihiro "Matz" Matsumoto b7d75591f3 codegen.c: gen_jmpdst always needs to generate relative address. 2021-07-15 14:08:17 +09:00
Yukihiro "Matz" Matsumoto b8863c69dc Merge pull request #4141 from udzura/add-test-for-attr-nil-guard
Add a testcase of #4137 fix
2021-07-15 07:27:48 +09:00
Yukihiro "Matz" Matsumoto f5eeb76a85 Merge pull request #5507 from mruby/dependabot/github_actions/github/super-linter-4.4.1
build(deps): bump github/super-linter from 4.3.0 to 4.4.1
2021-07-15 07:25:53 +09:00
dependabot[bot] b2f3327ade build(deps): bump github/super-linter from 4.3.0 to 4.4.1
Bumps [github/super-linter](https://github.com/github/super-linter) from 4.3.0 to 4.4.1.
- [Release notes](https://github.com/github/super-linter/releases)
- [Commits](https://github.com/github/super-linter/compare/v4.3.0...v4.4.1)

---
updated-dependencies:
- dependency-name: github/super-linter
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-07-14 14:05:53 +00:00
Yukihiro "Matz" Matsumoto 70aee96050 Merge pull request #5506 from mruby/dependabot/github_actions/github/super-linter-4.3.0
build(deps): bump github/super-linter from 4.2.2 to 4.3.0
2021-07-14 08:11:56 +09:00
dependabot[bot] b89678b30d build(deps): bump github/super-linter from 4.2.2 to 4.3.0
Bumps [github/super-linter](https://github.com/github/super-linter) from 4.2.2 to 4.3.0.
- [Release notes](https://github.com/github/super-linter/releases)
- [Commits](https://github.com/github/super-linter/compare/v4.2.2...v4.3.0)

---
updated-dependencies:
- dependency-name: github/super-linter
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-07-13 14:06:38 +00:00
Yukihiro "Matz" Matsumoto 0712a5406a load.c: call mrb_top_run() from mrb_load_proc(); fix #5504
So that the function behave consistently with `mrb_load_proc()`.
2021-07-12 08:17:43 +09:00
Yukihiro "Matz" Matsumoto bb94082fa5 TODO.md: update. 2021-07-11 18:16:17 +09:00
Yukihiro "Matz" Matsumoto ce2d7c2e01 numeric.c: self should always be an integer in __coerce_step_counter. 2021-07-10 17:04:57 +09:00
Yukihiro "Matz" Matsumoto be6d559853 Update internal methods not to be listed in backtraces.
- String#__lines
- Array#__ary_eq
- Array#__ary_cmp
- Hash#__delete
- Kernel#__case_eqq
- Integer#__coerce_step_counter
2021-07-10 14:15:43 +09:00
Yukihiro "Matz" Matsumoto ce6319af61 Merge pull request #5503 from ntl/correct-header-files-when-cdump-disabled
Mrbgem gem_init.c: add headers for irep loading when cdump is disabled, but presym is enabled
2021-07-10 07:53:53 +09:00
Yukihiro "Matz" Matsumoto 13c0dc98f7 Merge pull request #5505 from dearblue/stdint
Do not include `stdint.h` before `mruby.h`
2021-07-10 07:42:25 +09:00
dearblue a7e41c74de Do not include stdint.h before mruby.h 2021-07-09 23:20:30 +09:00
Nathan Ladd 6598607fea Mrbgem gem_init.c compilation correction
When `disable_cdump` is declared on a Mrbgem spec, the procedure for
loading MRuby code from the gem's `mrblib` directory is slightly
different; instead of loading the mrblib code as a Proc built from the
compiled irep, the compiled irep is loaded directly. The header files
`mruby.h` and `mruby/proc.h` are needed only when the irep is loaded
directly. They are currently included only when presym is disabled, they
should be included whenever either presym is disabled *or* when
`disable_cdump` is called. The `cdump?` predicate method happens to
return true in either case (presym disabled *or* cdump disabled), so
this change should be safe.
2021-07-09 08:16:12 -05:00
Yukihiro "Matz" Matsumoto 93cce94e06 debug.h: use uint8_t instead of char for BER compressed binary.
A change in `load.c` is left uncommitted.
2021-07-09 21:11:28 +09:00
Yukihiro "Matz" Matsumoto b5039fdb6c debug.h: use uint8_t instead of char for BER compressed binary. 2021-07-09 14:10:48 +09:00
Yukihiro "Matz" Matsumoto 29556a49a0 cdump.c: avoid uninitialized local variable. 2021-07-09 14:10:17 +09:00
Yukihiro "Matz" Matsumoto b5aa08fc9e range.c: avoid implicit conversion from mrb_float to mrb_int. 2021-07-09 09:10:06 +09:00
Yukihiro "Matz" Matsumoto a1ba6cb728 codegen.c: avoid uninitialized local variable. 2021-07-09 09:09:11 +09:00
Yukihiro "Matz" Matsumoto b3fe9da329 range.c: should not include internal __num_to_a in the backtrace. 2021-07-08 10:07:18 +09:00
Yukihiro "Matz" Matsumoto 38c9c5c627 backtrace.c: skip C method without mid set.
That means it's a method not to be included in the backtrace, for
example `raise`.
2021-07-08 10:06:01 +09:00
Yukihiro "Matz" Matsumoto f9303699d1 pack.c: fix integer signedness mixture. 2021-07-08 09:59:14 +09:00
Yukihiro "Matz" Matsumoto 06b1662807 mruby-bin-debugger: remove unused local variables. 2021-07-08 09:58:44 +09:00
Yukihiro "Matz" Matsumoto c572165292 mruby-bin-debugger: support mrb_debug_line_packed_map. 2021-07-08 09:54:11 +09:00
Yukihiro "Matz" Matsumoto f16ea05a17 debug.c: new debug line information format mrb_debug_line_packed_map.
It uses BER number compression of delta of instruction positions and line
numbers. BER compression is a variable length number representation.

* `mrb_debug_line_ary`: array of line numbers represented in `uint16_t`.
  `[lineno, lineno, ...]`

* `mrb_debug_line_flat_map`: array of `mrb_irep_debug_info_line`, which
  is `struct {uint32_t pos; uint16_t lineno}`, for each line.

* `mrb_debug_line_packed_map` [new]: sequence of BER compressed 2
  numbers, `pos_delta, lineno_delta`. Deltas are differences from
  previous values (starting `0`). `line_entry_counts` represents total
  length of a packed map string for this type.
2021-07-08 07:24:12 +09:00
Yukihiro "Matz" Matsumoto fb1d4ff682 mruby-bin-debugger: rename prefix 'mrb_debug_' to mrdb_. 2021-07-08 07:24:12 +09:00
Yukihiro "Matz" Matsumoto 5f61b36a21 Merge pull request #5502 from jbampton/add-docs-yamllint
Add information on yamllint as comments
2021-07-08 07:24:00 +09:00
John Bampton 6b892e652b Add information on yamllint as comments 2021-07-07 23:18:00 +10:00
Yukihiro "Matz" Matsumoto 9079082b88 Merge pull request #5501 from jbampton/update-contributing-guide
Style the CONTRIBUTING guide
2021-07-07 22:05:50 +09:00
John Bampton c9db3ec7c3 Style the CONTRIBUTING guide 2021-07-07 22:26:19 +10:00
Yukihiro "Matz" Matsumoto 17748ecd1a Merge branch 'cremno-mrb_debug_strdup-and-strndup' 2021-07-06 17:02:31 +09:00
Yukihiro "Matz" Matsumoto 7c362ee723 Merge branch 'mrb_debug_strdup-and-strndup' of https://github.com/cremno/mruby into cremno-mrb_debug_strdup-and-strndup 2021-07-06 17:01:37 +09:00
Yukihiro "Matz" Matsumoto 7fa0a704e0 Make LocalJumpError a direct subclass of StandardError.
To be compatible with CRuby.
2021-07-05 11:57:04 +09:00
Yukihiro "Matz" Matsumoto a6657afab9 codegen.c: jump address should be generated by gen_jmpdst(). 2021-07-04 00:08:17 +09:00
Yukihiro "Matz" Matsumoto 39aed39139 ops.h: made terms consistent.
- `Lit` -> `Pool`
- `SEQ` -> `Irep`
2021-07-03 12:06:44 +09:00
Yukihiro "Matz" Matsumoto 2519659100 Update .git-blame-ignore-revs to skip a reformatting commit. 2021-07-03 06:51:35 +09:00
Yukihiro "Matz" Matsumoto 61e8a54086 doc/opcode.md: table reformatted. 2021-07-03 06:42:26 +09:00
Yukihiro "Matz" Matsumoto d9a8981c26 vm.c: OP_DEF to push a symbol to a register.
The code generator no longer need to emit `OP_LOADSYM` after `OP_DEF`.
`doc/opcode.md` is also updated.
2021-07-03 06:40:05 +09:00
Yukihiro "Matz" Matsumoto a624da6fdb vm.c: need to adjust pc for OP_EXT[123]. 2021-07-02 21:57:52 +09:00
Yukihiro "Matz" Matsumoto 040d1799ec error.c: mrb_obj_as_string and mrb_inspect may return non-object (undef). 2021-07-02 14:24:20 +09:00
Yukihiro "Matz" Matsumoto e60ddc431d AUTHORS: update. 2021-07-01 07:35:11 +09:00
Yukihiro "Matz" Matsumoto 99dbcec89c Revert "Remove OP_EXT[123] from operands."
This reverts commit fd10c72319.

I thought it was OK to restrict index value within 1 byte, but in some
cases index value could be 16 bits (2 bytes). I had several ideas to
address the issue, but reverting `fd10c72` is the easiest way. The
biggest reason is `mruby/c` still supports `OP_EXT[123]`, so that they
don't need any additional work.
2021-06-30 22:41:13 +09:00
Yukihiro "Matz" Matsumoto b2b0329d29 string.rb: upto to break when the string length is longer than end. 2021-06-29 16:49:16 +09:00
Yukihiro "Matz" Matsumoto f09eb196da Merge pull request #5497 from dearblue/drop-upper
Drop unnecessary upper procs linked from class/module/def syntax
2021-06-29 09:49:59 +09:00
Yukihiro "Matz" Matsumoto f05f6963f8 Merge pull request #5498 from dearblue/ruby-warns
Avoid warnings with `ruby -cw`
2021-06-29 09:48:32 +09:00
dearblue 2d0b50f6f3 Avoid warnings with ruby -cw
```console
% for rb in `git ls-files '*/mrblib/*.rb' 'mrblib'`; do ruby30 -cw $rb > /dev/null; done
mrbgems/mruby-array-ext/mrblib/array.rb:389: warning: assigned but unused variable - ary
mrbgems/mruby-array-ext/mrblib/array.rb:663: warning: assigned but unused variable - len
mrbgems/mruby-hash-ext/mrblib/hash.rb:119: warning: possibly useless use of a variable in void context
mrbgems/mruby-hash-ext/mrblib/hash.rb:259: warning: assigned but unused variable - keys
mrbgems/mruby-io/mrblib/io.rb:229: warning: literal in condition
mrbgems/mruby-io/mrblib/io.rb:280: warning: literal in condition
mrbgems/mruby-string-ext/mrblib/string.rb:347: warning: assigned but unused variable - len
mrbgems/mruby-toplevel-ext/mrblib/toplevel.rb:2: warning: parentheses after method name is interpreted as an argument list, not a decomposed argument
```
2021-06-28 23:21:47 +09:00
dearblue 59201b5904 Drop unnecessary upper procs linked from class/module/def syntax
It does not need to hold an anonymous proc for constant search.
Also, this change can be expected to cause an anonymous proc to be GC'd.

This is useful for metaprogramming that makes heavy use of the `class`/`module`/`def` syntax in the `class_eval`/`eval` method.

Example:

- code

  ```ruby
  p ObjectSpace.count_objects

  String.class_eval do
    def a
    end
  end

  p ObjectSpace.count_objects

  String.class_eval do
    eval <<~CODE
      def b
      end
    CODE
  end

  p ObjectSpace.count_objects
  ```

- result of building mruby-head (d63c0df6b) with `build_config/default.rb`

  ```
  {:TOTAL=>1024, :FREE=>262, :T_PROC=>495, :T_ENV=>61, ...}
  {:TOTAL=>1024, :FREE=>259, :T_PROC=>497, :T_ENV=>62, ...}
  {:TOTAL=>1024, :FREE=>255, :T_PROC=>500, :T_ENV=>63, ...}
  ```

- result of building mruby with this patch and `build_config/default.rb`

  ```
  {:TOTAL=>1024, :FREE=>264, :T_PROC=>494, :T_ENV=>60, ...}
  {:TOTAL=>1024, :FREE=>262, :T_PROC=>495, :T_ENV=>61, ...}
  {:TOTAL=>1024, :FREE=>261, :T_PROC=>496, :T_ENV=>61, ...}
  ```
2021-06-28 23:04:43 +09:00
Yukihiro "Matz" Matsumoto d63c0df6bc Merge pull request #5493 from dearblue/binding.2
Fixed finding variables from `proc` in `binding.eval` failed
2021-06-28 09:13:54 +09:00
Yukihiro "Matz" Matsumoto e462b42ff0 Merge pull request #5495 from dearblue/eval.2
Fixed finding variables defined in the upper proc failed
2021-06-27 14:32:43 +09:00
dearblue c182903ea0 Fixed finding variables from proc in binding.eval failed
Previously the following code did not produce the expected results:
```ruby
bx = binding
block = bx.eval("a = 1; proc { a }")
bx.eval("a = 2")
p block.call  # Expect 2 but return 1 due to a bug
```

The previous implementation of `Binding#eval` evaluated the code and then merged the top layer variables.
This patch will parse and expand the variable space before making a call to `eval`.
This means that the call to `Binding#eval` will do the parsing twice.

In addition, the following changes will be made:
- Make `mrb_parser_foreach_top_variable()`, `mrb_binding_extract_proc()` and `mrb_binding_extract_env()` functions private global functions.
- Remove the `posthook` argument from `mrb_exec_irep()`.
  The `posthook` argument was introduced to implement the `binding` method.
  This patch is unnecessary because it uses a different implementation method.

ref #5362
fixed #5491
2021-06-26 13:43:36 +09:00
Yukihiro "Matz" Matsumoto 912b2f8df3 Merge pull request #5494 from dearblue/eval.1
Fix memory leak in `Kernel#eval`
2021-06-26 12:17:14 +09:00
dearblue 52b29f41a3 Fixed finding variables defined in the upper proc failed
If no new variable was defined in the `eval` method, the variable was hidden from the nested `eval` method.

```ruby
a = 1
p eval %(b = 2; eval %(a)) # => 1 (good)
p eval %(eval %(a)) # => undefined method 'a' (NoMethodError)
```

This issue has occurred since mruby 3.0.0.
2021-06-26 11:00:32 +09:00
dearblue cf38fc2f9e Fix memory leak in Kernel#eval
The `mrbc_context` remained unreleased when the `mrb_parse_nstring()` function returned `NULL`.
2021-06-26 10:59:39 +09:00
Yukihiro "Matz" Matsumoto 5fc301f07d class.c: call method_added hooks on alias definitions; #2339 2021-06-25 10:10:34 +09:00
Yukihiro "Matz" Matsumoto 888be9611b class.c: call hook methods on method definitions; close #2339
- `Module#method_added`
- `BasicObject#singleton_method_added`
2021-06-24 13:13:59 +09:00
Yukihiro "Matz" Matsumoto f314a5132e Remove unused build configuration file benchmark/build_config_cc.rb. 2021-06-24 13:13:59 +09:00
Yukihiro "Matz" Matsumoto d0e07b5fdb Merge pull request #5492 from jbampton/add-file-contents-sorter-pre-commit
Add official pre-commit file-contents-sorter
2021-06-23 10:54:51 +09:00
John Bampton 7d2a2e10b3 Add official pre-commit file-contents-sorter
Remove unneeded bash script sort-codespell-wordlist.sh

https://github.com/pre-commit/pre-commit-hooks#file-contents-sorter
2021-06-23 10:55:26 +10:00
Yukihiro "Matz" Matsumoto 388bcb15e8 Rename two files for consistency; close #5488
* android_arm64-v8a.rb -> android_arm64_v8a.rb
* no-float.rb -> host-nofloat.rb
2021-06-22 16:36:26 +09:00
Yukihiro "Matz" Matsumoto fc6210763c Merge pull request #5487 from jbampton/lint-markdown
Enable markdownlint rules MD003,MD005,MD007
2021-06-22 13:14:34 +09:00
Yukihiro "Matz" Matsumoto 40ca240c4c Merge pull request #5489 from jbampton/pre-commit-autoupdate
pre-commit autoupdate
2021-06-22 13:13:13 +09:00
John Bampton 34b8dc211d pre-commit autoupdate
https://pre-commit.com/#pre-commit-autoupdate
2021-06-22 13:17:40 +10:00
John Bampton 188e9b6fb0 Enable markdownlint rules MD003,MD005,MD007
Lint Markdown

https://github.com/DavidAnson/markdownlint#rules--aliases
2021-06-22 06:57:03 +10:00
Yukihiro "Matz" Matsumoto 8416e706ba numeric.c: add optional ndigits argument to rounding methods.
- `truncate`
- `floor`
- `ceil`

`round` already takes `ndigits`.
2021-06-21 10:24:55 +09:00
Yukihiro "Matz" Matsumoto e893f805b1 Merge pull request #5486 from dearblue/alloc-castfree
Added `MRB_OBJ_ALLOC()` macro that does not require a cast
2021-06-21 10:24:44 +09:00
dearblue 0c5c04d7c8 Use MRB_VTYPE_FOREACH() in src/object.c 2021-06-20 11:11:37 +09:00
dearblue cc95e346fd Added MRB_OBJ_ALLOC() macro that does not require a cast
The `MRB_OBJ_ALLOC()` macro function returns a pointer of the type corresponding to the constant literal defined in `enum mrb_vtype`.
2021-06-20 11:08:28 +09:00
Yukihiro "Matz" Matsumoto f678620a43 Merge branch 'dearblue-block_given' 2021-06-19 21:19:42 +09:00
Yukihiro "Matz" Matsumoto 1fca58f7ca codegen.c: stop uninitialized warning. 2021-06-19 21:18:27 +09:00
dearblue c40802865a Added MRB_API function to get block arguments info.
- ` mrb_block_given_p()` -- The name comes from CRuby's `rb_block_given_p ()`

At the same time, it applies to `f_instance_eval()` and `f_class_eval()` of `mruby-eval`.
2021-06-19 21:15:02 +09:00
Yukihiro "Matz" Matsumoto 43eddfd4d5 Merge pull request #5484 from jbampton/enable-markdownlint-rule
Enable markdownlint rule MD046 code-block-style
2021-06-19 11:06:03 +09:00
John Bampton 625210f67c Enable markdownlint rule MD046 code-block-style
Fix C Markdown code block style
2021-06-19 08:38:58 +10:00
Yukihiro "Matz" Matsumoto e1637e716a Merge pull request #5434 from jbampton/add-markdownlint-rules-as-comments
Add the rules to the markdownlint config file as comments
2021-06-18 10:55:04 +09:00
Yukihiro "Matz" Matsumoto e812b1ccb3 Merge pull request #5483 from mruby/dependabot/github_actions/actions/upload-artifact-2.2.4
build(deps): bump actions/upload-artifact from 2.2.3 to 2.2.4
2021-06-18 07:26:35 +09:00
dependabot[bot] d3be93129e build(deps): bump actions/upload-artifact from 2.2.3 to 2.2.4
Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 2.2.3 to 2.2.4.
- [Release notes](https://github.com/actions/upload-artifact/releases)
- [Commits](https://github.com/actions/upload-artifact/compare/v2.2.3...v2.2.4)

---
updated-dependencies:
- dependency-name: actions/upload-artifact
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-06-17 14:05:11 +00:00
Yukihiro "Matz" Matsumoto 4fcb5e8e4f variable.c: add skip argument to skip base class in lookup.
`mrb_vm_const_get` function looks up the constant first in the base
class, so that fallback `const_get` need not to search from the base.
2021-06-17 16:53:54 +09:00
Yukihiro "Matz" Matsumoto 63bafca7f5 variable.c: refactor mrb_vm_const_get function. 2021-06-17 16:53:21 +09:00
Yukihiro "Matz" Matsumoto 090356ec3b variable.c: skip prepended module for constant lookup.
```ruby
module M
  FOO = 'm'
end
class A
  FOO = 'a'
  prepend M
end
class B < A
  def foo
    p FOO
  end
end
B.new.foo  # should print `m` not `a`
```
2021-06-17 16:35:39 +09:00
Yukihiro "Matz" Matsumoto 62754a4739 class.c: use MRB_FLAG_TEST() macro. 2021-06-17 16:34:51 +09:00
Yukihiro "Matz" Matsumoto 02aed7af10 Merge pull request #5480 from jbampton/add-more-pre-commit-hooks
Add two more pre-commit hooks
2021-06-17 11:44:21 +09:00
Yukihiro "Matz" Matsumoto dee895ae79 Merge pull request #5482 from jbampton/standardize-backtick-commands
Standardize commands inside backticks
2021-06-17 11:43:07 +09:00
John Bampton d08ea8a92c Standardize commands inside backticks
Remove whitespace
2021-06-17 12:02:21 +10:00
Yukihiro "Matz" Matsumoto 7b0eb1f9b3 Merge pull request #5481 from jbampton/fix-shebang
Fix shebang by removing whitespace
2021-06-17 10:26:47 +09:00
John Bampton 233366a00c Fix shebang by removing whitespace 2021-06-17 10:26:38 +10:00
John Bampton f1aaa5ee2b Add two more pre-commit hooks 2021-06-17 10:13:56 +10:00
John Bampton 96bc39e527 Add the rules to the markdownlint config file as comments
Enable MD011 no-reversed-links - Reversed link syntax
2021-06-17 09:46:52 +10:00
Yukihiro "Matz" Matsumoto a528834df7 Revert "instance_eval for classes and modules should behave as class_eval."
This reverts commit ee3017496b.

I misunderstood something and the new behavior was different from CRuby.
The issue was reported by @dearblue, regarding #5478
2021-06-17 07:54:54 +09:00
Yukihiro "Matz" Matsumoto 7893cbb523 Merge pull request #5444 from jbampton/add-misspell-docs
Add documentation on spell checking with misspell
2021-06-16 09:17:36 +09:00
Yukihiro "Matz" Matsumoto 2341e4f5e5 Merge pull request #5445 from jbampton/add-codespell-pre-commit-hook
Run pre-commit with GitHub Actions
2021-06-16 09:15:07 +09:00
Yukihiro "Matz" Matsumoto 651c234f9c eval.c: implement class_eval with string; close #5478 2021-06-16 09:12:03 +09:00
John Bampton dab5502e8a Run pre-commit with GitHub Actions
Running pre-commit with GitHub Actions now gives us more tests and coverage

Remove duplicate GitHub Actions for merge conflicts and trailing whitespace

Remove duplicate checks for markdownlint and yamllint from the GitHub Super-Linter

Add new custom pre-commit hook running with a shell script to sort alphabetically and uniquify codespell.txt

Add new pre-commit hook to check spelling with codespell

https://github.com/codespell-project/codespell

Fix spelling
2021-06-16 08:34:54 +10:00
Yukihiro "Matz" Matsumoto 7c8a91ff5a numeric.c: restore fmt argument for backward compatibility.
`mrb_float_to_str()` used to take `fmt` argument. We thought no one used
the function, and OK to remove the argument. But at least `mruby-redis`
gem used the function.
2021-06-15 16:19:16 +09:00
Yukihiro "Matz" Matsumoto 50b6fafddf pack.c: support `w' directive (BER integer compression). 2021-06-14 11:20:52 +09:00
Yukihiro "Matz" Matsumoto 1ed01a8d47 pack.c: count should not be negative for directives xX@. 2021-06-13 20:13:50 +09:00
Yukihiro "Matz" Matsumoto bf2b06ced7 pack.c: raise error for unsupported w directive. 2021-06-13 14:21:51 +09:00
Yukihiro "Matz" Matsumoto eaaa9148b5 readint.c: fixed typo. 2021-06-12 16:18:45 +09:00
Yukihiro "Matz" Matsumoto 96ad60b9aa pack.c: support `@' directive (absolute position). 2021-06-12 16:18:45 +09:00
Yukihiro "Matz" Matsumoto 952e7efdd7 pack.c: refactor pack/unpack 'X'. 2021-06-12 16:18:45 +09:00
Yukihiro "Matz" Matsumoto 3ddc57ed6e pack.c: add X directive (back up byte). 2021-06-12 16:18:44 +09:00
Yukihiro "Matz" Matsumoto fb013595ed pack.c: count should be always positive. no check needed. 2021-06-12 16:18:44 +09:00
Yukihiro "Matz" Matsumoto 203495ccea pack.c: fix long/int mixtures. 2021-06-12 16:18:44 +09:00
Yukihiro "Matz" Matsumoto 72ea85c8da pack.c: remove unused arguments from static functions. 2021-06-12 16:18:44 +09:00
Yukihiro "Matz" Matsumoto f764467c19 pack.c: wrong position after count read. 2021-06-12 16:18:43 +09:00
Yukihiro "Matz" Matsumoto 56593764c8 Merge pull request #5476 from dearblue/eval+super
Raise `TypeError` with `super` inside `instance_eval` / `class_eval`
2021-06-12 16:18:35 +09:00
dearblue b45d95fa9e Raise TypeError with super inside instance_eval / class_eval
Commit d0f60182af introduced an exception as a limitation of mruby.

Subsequent CRuby-2.7 has changed its behavior to raise an exception.
ref: https://github.com/ruby/ruby/commit/55b7ba368696033f2e89b77cbcd4a05dec97b139
2021-06-12 16:08:21 +09:00
Yukihiro "Matz" Matsumoto f7777f64e6 codegen.c: refactor readint()
* renamed from redundant `readint_mrb_int()`
* supports only base upto 16
* no base validation (already done in parser)
* no negative read (negate after read)
* overflow detection using `mrb_int_{mul,add}_overflow()`
2021-06-11 16:44:47 +09:00
Yukihiro "Matz" Matsumoto 49af1fca03 readint.c: add new function mrb_int_read.
Difference from `strtoul(3)`:

* reads `mrb_int` based on configuration
* specifies the end of the string
* no sign interpretation
* base 10 only
2021-06-11 15:14:17 +09:00
Yukihiro "Matz" Matsumoto 14a69c6ffd Merge pull request #5475 from mruby/dependabot/github_actions/github/super-linter-4.2.2
build(deps): bump github/super-linter from 4.2.1 to 4.2.2
2021-06-11 15:14:00 +09:00
dependabot[bot] 0271972e0f build(deps): bump github/super-linter from 4.2.1 to 4.2.2
Bumps [github/super-linter](https://github.com/github/super-linter) from 4.2.1 to 4.2.2.
- [Release notes](https://github.com/github/super-linter/releases)
- [Commits](https://github.com/github/super-linter/compare/v4.2.1...v4.2.2)

---
updated-dependencies:
- dependency-name: github/super-linter
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-06-11 05:50:49 +00:00
Yukihiro "Matz" Matsumoto 62f4cc8cd1 sprintf.c: check value range before type casting. 2021-06-10 18:42:51 +09:00
Yukihiro "Matz" Matsumoto df549c12e5 readflt.c: renamed from strtod.c
The file provides `mrb_read_float()` renamed from `vim_strtod()`.
2021-06-10 15:04:35 +09:00
Yukihiro "Matz" Matsumoto f2f6f2179b Merge pull request #5474 from mruby/dependabot/github_actions/github/super-linter-4.2.1
build(deps): bump github/super-linter from 4.2.0 to 4.2.1
2021-06-10 15:04:10 +09:00
dependabot[bot] d46e7c759f build(deps): bump github/super-linter from 4.2.0 to 4.2.1
Bumps [github/super-linter](https://github.com/github/super-linter) from 4.2.0 to 4.2.1.
- [Release notes](https://github.com/github/super-linter/releases)
- [Commits](https://github.com/github/super-linter/compare/v4.2.0...v4.2.1)

---
updated-dependencies:
- dependency-name: github/super-linter
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-06-10 05:55:58 +00:00
Yukihiro "Matz" Matsumoto 82428de5f9 Merge pull request #5473 from mruby/dependabot/github_actions/github/super-linter-4.2.0
build(deps): bump github/super-linter from 4.1.0 to 4.2.0
2021-06-09 17:11:23 +09:00
dependabot[bot] 670fa8607b build(deps): bump github/super-linter from 4.1.0 to 4.2.0
Bumps [github/super-linter](https://github.com/github/super-linter) from 4.1.0 to 4.2.0.
- [Release notes](https://github.com/github/super-linter/releases)
- [Commits](https://github.com/github/super-linter/compare/v4.1.0...v4.2.0)

---
updated-dependencies:
- dependency-name: github/super-linter
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-06-09 06:03:03 +00:00
Yukihiro "Matz" Matsumoto 3acc09ae61 string.c: make mrb_str_len_{inum,dbl}() static. 2021-06-08 17:19:31 +09:00
Yukihiro "Matz" Matsumoto d8ec544564 string.c: remove two unused functions.
* `mrb_cstr_to_inum()`
* `mrb_cstr_to_dbl()`
2021-06-08 17:00:54 +09:00
Yukihiro "Matz" Matsumoto a5f323835e string.c: add base>36 check to String#to_i. 2021-06-08 16:59:57 +09:00
Yukihiro "Matz" Matsumoto 972cc8b5a8 sprintf.c: fix mrb_int and int mixture errors. 2021-06-07 23:26:06 +09:00
Yukihiro "Matz" Matsumoto b10a6fd472 pack.c: fix 'void* to char*` assignment. 2021-06-07 22:42:31 +09:00
Yukihiro "Matz" Matsumoto 32e96a1d4a pack.c: add default to switch statement to silence warnings. 2021-06-07 09:06:37 +09:00
Yukihiro "Matz" Matsumoto 0afa651363 pack.c: support M specifier (quoted-printable). 2021-06-07 09:03:25 +09:00
Yukihiro "Matz" Matsumoto bba044cfc8 test/pack.c: reorganize test suits. 2021-06-07 08:54:54 +09:00
Yukihiro "Matz" Matsumoto cd64ddf372 pack.c: raise exception for unsupported specifiers. 2021-06-07 07:18:17 +09:00
Yukihiro "Matz" Matsumoto e112c46281 pack.c: check overflow before calling pack_x. 2021-06-06 08:01:58 +09:00
Yukihiro "Matz" Matsumoto d518294f20 pack.c: check overflow before reading count. 2021-06-06 08:01:01 +09:00
Yukihiro "Matz" Matsumoto af3e0ddfc0 pack.c: failed to detect overflow when ch is zero in read_tmpl. 2021-06-06 08:00:24 +09:00
Yukihiro "Matz" Matsumoto f01c29b0ec pack.c: hold enum values in enum variables not int. 2021-06-05 20:04:59 +09:00
Yukihiro "Matz" Matsumoto abb288f5cb codedump.c: fix a compiler condition bug with MRB_NO_FLOAT. 2021-06-05 08:09:04 +09:00
Yukihiro "Matz" Matsumoto cb7d351bfb ops.h: fix term consistency. Lit -> Pool. 2021-06-05 08:08:25 +09:00
Yukihiro "Matz" Matsumoto c2d3718b6e Merge branch 'mirichi-test' 2021-06-04 22:26:57 +09:00
mirichi a997e41d17 add block argument test #2144 2021-06-04 22:25:33 +09:00
Yukihiro "Matz" Matsumoto 001fb58698 Merge branch 'test' of https://github.com/mirichi/mruby into mirichi-test 2021-06-04 22:22:16 +09:00
Yukihiro "Matz" Matsumoto 45dd6b140a Merge pull request #5469 from mruby/dependabot/github_actions/github/super-linter-4.1.0
build(deps): bump github/super-linter from 4.0.2 to 4.1.0
2021-06-04 16:41:18 +09:00
dependabot[bot] 8d6f3595c3 build(deps): bump github/super-linter from 4.0.2 to 4.1.0
Bumps [github/super-linter](https://github.com/github/super-linter) from 4.0.2 to 4.1.0.
- [Release notes](https://github.com/github/super-linter/releases)
- [Commits](https://github.com/github/super-linter/compare/v4.0.2...v4.1.0)

---
updated-dependencies:
- dependency-name: github/super-linter
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-06-04 06:54:20 +00:00
Yukihiro "Matz" Matsumoto 01a21085f6 add a few regressions test from #2313
The code was contributed from Carson McDonald (@carsonmcdonald)
2021-06-03 16:47:04 +09:00
Yukihiro "Matz" Matsumoto 9775315240 vm.c: unify JUMP instructions in OP_SEND. 2021-06-02 18:53:22 +09:00
Yukihiro "Matz" Matsumoto 843abc5c7b cdump.c: rename dump_ prefix to cdump for static functions. 2021-06-01 22:21:04 +09:00
Yukihiro "Matz" Matsumoto ff93854c4a cdump.c: separate irep dump in C feature. 2021-06-01 16:47:06 +09:00
Yukihiro "Matz" Matsumoto a41174aa86 Merge pull request #5464 from shuujii/fix-typo-in-lib-mruby-presym.rb
Fix typo in `lib/mruby/presym.rb`
2021-05-31 09:16:34 +09:00
KOBAYASHI Shuji 2a4d340ce4 Fix typo in lib/mruby/presym.rb 2021-05-31 08:25:42 +09:00
Yukihiro "Matz" Matsumoto cf2e78de44 numeric.c: fixed a silly bug related to pointer decrement. 2021-05-31 02:59:33 +09:00
Yukihiro "Matz" Matsumoto be647acd3e sprintf.c: avoid object allocation in integer formatting. 2021-05-30 19:57:56 +09:00
Yukihiro "Matz" Matsumoto 8a4bcc58c9 numeric.c: introduce mrb_int_to_cstr() to dump mrb_int.
* refactor `mrb_integer_to_str()`
* refactor `mrb_str_format()`
2021-05-30 08:15:51 +09:00
Yukihiro "Matz" Matsumoto 60aa2192a8 codegen.c: just raise the exception on broken node for assignments. 2021-05-29 15:46:30 +09:00
Yukihiro "Matz" Matsumoto 8aa15b0096 Merge pull request #5463 from mruby/dependabot/github_actions/actions/cache-2.1.6
build(deps): bump actions/cache from 2.1.5 to 2.1.6
2021-05-28 16:33:09 +09:00
dependabot[bot] fc7a00f12f build(deps): bump actions/cache from 2.1.5 to 2.1.6
Bumps [actions/cache](https://github.com/actions/cache) from 2.1.5 to 2.1.6.
- [Release notes](https://github.com/actions/cache/releases)
- [Commits](https://github.com/actions/cache/compare/v2.1.5...v2.1.6)

Signed-off-by: dependabot[bot] <support@github.com>
2021-05-28 06:02:32 +00:00
Yukihiro "Matz" Matsumoto 269470babc kernel.c: avoid recursive VM call in mrb_f_caller. 2021-05-28 07:39:34 +09:00
Yukihiro "Matz" Matsumoto 4e683c20a2 kernel.c: caller should not include the frame for itself. 2021-05-28 07:38:21 +09:00
Yukihiro "Matz" Matsumoto 2a717cf2aa backtrace.c: do not skip frames for C function calls. 2021-05-28 07:36:20 +09:00
Yukihiro "Matz" Matsumoto cefbc21e67 vm.c: skip actual method_missing call unless it's overridden.
So that `mruby -e 'a'` does not print backtrace history, i.e.

```
% mruby -e 'a'
-e:1: undefined method 'a' (NoMethodError)
```

Instead of

```
% mruby -e 'a'
trace (most recent call last):
        [1] -e:1
-e:1: undefined method 'a' (NoMethodError)
```
2021-05-28 07:30:43 +09:00
Yukihiro "Matz" Matsumoto d9c8626bb1 kernel.c: clear mid for raise and method_missing
Method names need not to be printed in backtrace history.
2021-05-27 21:48:26 +09:00
Yukihiro "Matz" Matsumoto cb92f9ce0b backtrace.c: do not print trace line if there's no backtrace history 2021-05-27 21:44:55 +09:00
Yukihiro "Matz" Matsumoto 48b08fecba array.c: unify mrb_ary_ref and mrb_ary_entry
Use only `mrb_ary_entry` hereafter.
2021-05-27 21:43:43 +09:00
Yukihiro "Matz" Matsumoto 9a72869043 array.c: check for negative shift size. 2021-05-27 08:13:49 +09:00
Yukihiro "Matz" Matsumoto c019d8d34d fmt_fp.c: move mruby specific mrb_float_to_str to numeric.c 2021-05-26 17:29:18 +09:00
Yukihiro "Matz" Matsumoto 05cc3a8d99 Merge pull request #5461 from mruby/dependabot/github_actions/github/super-linter-4.0.2
build(deps): bump github/super-linter from 3.17.1 to 4.0.2
2021-05-26 15:09:52 +09:00
dependabot[bot] 705632c99d build(deps): bump github/super-linter from 3.17.1 to 4.0.2
Bumps [github/super-linter](https://github.com/github/super-linter) from 3.17.1 to 4.0.2.
- [Release notes](https://github.com/github/super-linter/releases)
- [Commits](https://github.com/github/super-linter/compare/v3.17.1...v4.0.2)

Signed-off-by: dependabot[bot] <support@github.com>
2021-05-26 05:58:37 +00:00
Yukihiro "Matz" Matsumoto 063b49ab8e fmt_fp.c: truncate precision to prevent buffer overflow. 2021-05-25 13:32:29 +09:00
Yukihiro "Matz" Matsumoto afbc199ed3 fmt_fp.c: use constant that depends on mrb_float size. 2021-05-25 13:31:41 +09:00
Yukihiro "Matz" Matsumoto 5ed3a3475e fmt_fp.c: use a const int instead of a macro constant. 2021-05-25 13:30:17 +09:00
Yukihiro "Matz" Matsumoto bf523b71d1 strtod.c: new public domain implementation of strtod; ref #5448
Instead of using copyrighted `strtod`, now use the public domain
implementation of `strtod` by Yasuhiro Matsumoto (@mattn). The function
has been renamed to `mrb_float_read()`; ref #5460 as well.
2021-05-24 12:10:14 +09:00
Yukihiro "Matz" Matsumoto a44ca2e9be fmt_fp.c: exponential may be bigger than 100. 2021-05-24 11:50:30 +09:00
Yukihiro "Matz" Matsumoto d121075e49 class.c: no need to create aliases if both symbols are same. 2021-05-24 11:50:30 +09:00
Yukihiro "Matz" Matsumoto e323cd0c6e class.c: add write barrier for aliases. 2021-05-24 11:50:29 +09:00
Yukihiro "Matz" Matsumoto a3f779c5b6 Merge pull request #5459 from shuujii/fix-typo-in-src-fmt_fp.c
Fix typo in `src/fmt_fp.c` [ci skip]
2021-05-23 00:02:55 +09:00
KOBAYASHI Shuji 6cfe184d39 Fix typo in src/fmt_fp.c [ci skip] 2021-05-22 17:00:14 +09:00
Yukihiro "Matz" Matsumoto b9bde0c918 mruby-sprintf: reduce float digits to avoid test failure.
Too many digits to fit in single precision float numbers, so that tests
fail when `MRB_USE_FLOAT32` defined.
2021-05-22 14:46:37 +09:00
Yukihiro "Matz" Matsumoto 5c7fe225a6 fp_fmt.c: remove mrb_float_to_cstr().
The function was intended to be a utility function for `mruby-sprintf`.
The functionality was integrated into `sprintf.c`.
2021-05-22 14:16:55 +09:00
Yukihiro "Matz" Matsumoto 328563995f fmt_fp.c: replace with public domain float format routine; ref #5448
The original code can be found in `https://github.com/dhylands/format-float`.

Changes:
- support `double`
- support `#` (alt_form) modifier
- small refactoring
2021-05-22 09:35:27 +09:00
Yukihiro "Matz" Matsumoto fa29bb3bb4 fmt_fp.c: remove fmt argument from mrb_float_to_str().
With major refactoring to prepare removing `snprintf(3) calls.
2021-05-21 08:13:38 +09:00
Yukihiro "Matz" Matsumoto beaf365dd4 numeric.h: remove 2 functions from MRB_API
- `mrb_float_to_str()`
- `mrb_float_to_cstr()`

Both functions will be replaced to support new coming `format-float.c`.
2021-05-21 08:13:38 +09:00
Yukihiro "Matz" Matsumoto 03c4e114a9 test/syntax.rb: fix endless def warning (no assertion). 2021-05-21 08:13:37 +09:00
Yukihiro "Matz" Matsumoto f0e1d575f2 sprintf.c: remove specifiers %a and %A.
`fmt_fp.c` does not support those specifiers. In addition, I believe no
one uses hexadecimal representation of float values.
2021-05-21 08:13:37 +09:00
Yukihiro "Matz" Matsumoto 8f73ee2e82 Merge pull request #5456 from shuujii/support-load-64-bit-integer-from-mrb-format-with-MRB_32BIT-and-MRB_INT64
Support load 64-bit integer from mrb format with MRB_32BIT and MRB_INT64
2021-05-21 08:12:54 +09:00
KOBAYASHI Shuji e9e720eab9 Support load 64-bit integer from mrb format with MRB_32BIT and MRB_INT64 2021-05-20 19:39:08 +09:00
Yukihiro "Matz" Matsumoto 07c8470278 parse.y: allow "command" syntax in endless method definition.
This change allows `def hello = puts "Hello"` without parentheses.
This syntax has been introduced since Ruby3.1.
2021-05-18 16:26:36 +09:00
Yukihiro "Matz" Matsumoto d50c83cca7 parse.y: endless singleton method definition can omit parens. 2021-05-18 16:25:53 +09:00
Yukihiro "Matz" Matsumoto 5eebbd7df2 Global renaming regarding integer and float.
Consistent number conversion function names:
* `mrb_value` to immediate (C) value
  * `mrb_int()` -> `mrb_as_int()`
  * `mrb_to_flo()` -> `mrb_as_float()`
* `mrb_value` to `mrb_value` (converted)
  * `mrb_to_int()'
  * `mrb_Integer()` - removed
  * `mrb_Float()` -> `mrb_to_float`

Consistent function name (avoid `_flo` suffix):
* `mrb_div_flo()` -> `mrb_div_float`
2021-05-17 15:07:05 +09:00
Yukihiro "Matz" Matsumoto ea7f1953c3 Rename mrb_fixnum_to_str to mrb_integer_to_str. 2021-05-17 13:59:01 +09:00
Yukihiro "Matz" Matsumoto 080fdbf9e8 Rename mrb_flo_to_fixnum to mrb_float_to_integer. 2021-05-17 13:58:54 +09:00
Yukihiro "Matz" Matsumoto fbbcee835f rational.c: update function prefixes.
To be consistent, functions with `rational_` prefix implements methods,
functions with `rat_` prefix are utility functions.
2021-05-17 13:39:51 +09:00
Yukihiro "Matz" Matsumoto e7db158321 numeric.h: reduce conditional compilation branch on MRB_NO_FLOAT. 2021-05-16 18:21:08 +09:00
Yukihiro "Matz" Matsumoto 361b380eaf AUTHORS: update authors information as of 2021-05-15. 2021-05-15 17:27:23 +09:00
Yukihiro "Matz" Matsumoto ae4c952d2e mruby-array-ext/array.c: implement Array#rotate in C.
The Ruby version of `Array#rotate!` generated a rotated array and
replaced the receiver, but the C version rotates the receiver array
in-place. So the performance is improved a lot both in speed and memory
consumption. Look for the comments in `array.c` for the in-place rotating
algorithm, if you are interested.
2021-05-15 17:26:36 +09:00
Yukihiro "Matz" Matsumoto 9422fdbc87 mruby-array-ext/array.c: implement Array#compact in C. 2021-05-14 10:39:41 +09:00
Yukihiro "Matz" Matsumoto bdb5d85adc array.rb: replace can't with cannot.
To avoid editor coloring failures.
2021-05-14 10:34:11 +09:00
Yukihiro "Matz" Matsumoto 364f275997 range.c: implement (part of) Range#to_a in C.
Mostly for performance reason.
2021-05-14 08:39:14 +09:00
Yukihiro "Matz" Matsumoto 99f0adc3f4 range.c: refactor conditional compilation code.
So that auto indentation works.
2021-05-14 08:28:27 +09:00
Yukihiro "Matz" Matsumoto dfac706ac2 range.c: rename RANGE_INITIALIZED_MASK to RANGE_INITIALIZED_FLAG. 2021-05-14 08:27:21 +09:00
Yukihiro "Matz" Matsumoto 1d0cfb359c Update mrb_bool definition; close #2385
- move `TRUE/FALSE` definition from `mrbconf.h` (not configurable)
- use C/C++ definition of boolean type for `mrb_bool`

The fix is originally written by @take-cheeze.
2021-05-13 19:30:41 +09:00
Yukihiro "Matz" Matsumoto 3a3761ec69 string.c: remove unnecessary branch in the internal method. 2021-05-13 16:08:25 +09:00
Yukihiro "Matz" Matsumoto 5c7aa4f299 Simplify module inclusion for Array, Hash and Range. 2021-05-13 16:07:09 +09:00
Yukihiro "Matz" Matsumoto 2597e5192f Merge pull request #5451 from mruby/dependabot/github_actions/github/super-linter-3.17.1
build(deps): bump github/super-linter from 3.17.0 to 3.17.1
2021-05-13 15:55:34 +09:00
Yukihiro "Matz" Matsumoto 2bed750eb0 range.c: avoid use of mrb_fixnum_p.
`mrb_int` may not fit in `fixnum` (inline integer).
2021-05-13 15:35:34 +09:00
Yukihiro "Matz" Matsumoto 4d6f5be1df mruby-test: MRB_INT_MAX etc. may not fit in Fixnum (inline int). 2021-05-13 15:34:20 +09:00
dependabot[bot] 649600ba9f build(deps): bump github/super-linter from 3.17.0 to 3.17.1
Bumps [github/super-linter](https://github.com/github/super-linter) from 3.17.0 to 3.17.1.
- [Release notes](https://github.com/github/super-linter/releases)
- [Commits](https://github.com/github/super-linter/compare/v3.17.0...v3.17.1)

Signed-off-by: dependabot[bot] <support@github.com>
2021-05-13 06:24:44 +00:00
Yukihiro "Matz" Matsumoto 5f9f26f6e6 backtrace.c: stop skipping frame with file/line information.
Instead, copy them from the outer frame as CRuby does.
2021-05-13 08:00:05 +09:00
Yukihiro "Matz" Matsumoto bd04630710 Merge pull request #5450 from mruby/dependabot/github_actions/actions/checkout-2.3.4
build(deps): bump actions/checkout from 2 to 2.3.4
2021-05-12 16:49:02 +09:00
dependabot[bot] 800b534a35 build(deps): bump actions/checkout from 2 to 2.3.4
Bumps [actions/checkout](https://github.com/actions/checkout) from 2 to 2.3.4.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v2...v2.3.4)

Signed-off-by: dependabot[bot] <support@github.com>
2021-05-12 05:53:03 +00:00
Yukihiro "Matz" Matsumoto 032d11de1b range.rb: add Range#entries as an alias to Range#to_a. 2021-05-12 11:09:03 +09:00
Yukihiro "Matz" Matsumoto 955c7f703e array.rb: add Array#entries as an alias to Array#to_a.
The performance of `Enumerable#entries` are significantly slower than
`Array#to_a`.
2021-05-12 07:17:49 +09:00
Yukihiro "Matz" Matsumoto 2a280a8f70 Remove the obsolete term Fixnum.
Except for compatibility code.
2021-05-11 07:36:34 +09:00
Yukihiro "Matz" Matsumoto 23019213b7 doc/limitation.md: update the limitation.
- `puts` behavior changed as CRuby
- fix wrong behavior in re-raising in `rescue`
2021-05-10 17:39:50 +09:00
Yukihiro "Matz" Matsumoto 033aa98cf4 time.c: Windows API provides clock_gettime.
`gettimeofday` emulation needed no longer.
2021-05-08 10:34:38 +09:00
Yukihiro "Matz" Matsumoto f8345dbc44 Add .git-blame-ignore-revs file to ignore whitespace fixes. 2021-05-07 17:28:52 +09:00
Yukihiro "Matz" Matsumoto 6eedb6173b Merge pull request #5447 from dearblue/tab
Extend the tab with 8 whitespace
2021-05-07 17:25:44 +09:00
Yukihiro "Matz" Matsumoto bc620824be Merge pull request #5443 from jbampton/order-editorconfig-properties
Order the EditorConfig properties
2021-05-07 17:25:05 +09:00
Yukihiro "Matz" Matsumoto 4458000404 symbol.c: add Symbol#name method
`Symbol#name` is similar to `#to_s` but returns a frozen string.
2021-05-06 16:45:54 +09:00
Yukihiro "Matz" Matsumoto a93d9d8585 symbol.c: rename sym_name to sym_cstr. 2021-05-06 16:45:27 +09:00
dearblue 6fc5dc986a Extend the tab with 8 whitespace
This work was done as follows:
- check:   `git grep $'\011' -- :^oss-fuzz`
- convert: `ruby -pi -e 'nil while $_.sub!(/^(.*?)\t/) { $1 + " " * (8 - $1.size % 8) }'`

The `doc/guide/{compile,mrbgems}.md` file adds and removes whitespace to make the directory tree look the same.
In `mrbgems/mruby-socket/src/socket.c`, there is a part where the indent is changed from 4 to 2 at the same time as the tab is changed.
2021-05-05 22:16:03 +09:00
Yukihiro "Matz" Matsumoto 1c9260db6b Merge pull request #5446 from mruby/dependabot/github_actions/github/super-linter-v3.17.0
build(deps): bump github/super-linter from v3 to v3.17.0
2021-05-05 19:05:39 +09:00
dependabot[bot] 7460e165dc build(deps): bump github/super-linter from v3 to v3.17.0
Bumps [github/super-linter](https://github.com/github/super-linter) from v3 to v3.17.0.
- [Release notes](https://github.com/github/super-linter/releases)
- [Commits](https://github.com/github/super-linter/compare/v3...28cfebb84fd6dd9e8773b5efe5ac0f8f3714f228)

Signed-off-by: dependabot[bot] <support@github.com>
2021-05-05 07:11:09 +00:00
Yukihiro "Matz" Matsumoto 35a6dfe905 Merge pull request #5442 from dearblue/mruby-pack
Fix documents for `mruby-io`
2021-05-05 09:38:45 +09:00
Yukihiro "Matz" Matsumoto b50be31d2b Merge pull request #5441 from dearblue/mruby-sleep
Update gem spec for `mruby-sleep`
2021-05-05 09:38:18 +09:00
John Bampton f4d9a9beec Add documentation on spell checking with misspell 2021-05-04 09:16:22 +10:00
Yukihiro "Matz" Matsumoto b517274921 Merge pull request #5440 from jbampton/fix-whitespace-in-src-symbol-c
Fix whitespace in `src/symbol.c`
2021-05-04 07:59:55 +09:00
John Bampton 1d5d912148 Order the EditorConfig properties 2021-05-04 08:14:12 +10:00
dearblue 8eb5a8867b Fix documents for mruby-io 2021-05-03 23:27:40 +09:00
dearblue eca990b2ec Update gem spec for mruby-sleep
To align the spec like any other core mrbgems:
- Delete `spec.version`
- Set `spec.summary`
2021-05-03 23:17:04 +09:00
John Bampton 356e1740f2 Fix whitespace in src/symbol.c 2021-05-03 21:15:29 +10:00
Yukihiro "Matz" Matsumoto 0c8cd60097 symbol.c: remove id2name reference from documents. 2021-05-03 15:33:39 +09:00
Yukihiro "Matz" Matsumoto ce054bd078 symbol.c: remove Symbol#id2sym.
In the ancient Ruby, symbols are represented by integers. In that era,
to get string representation from integers, we used `Integer#id2sym`
method. Later, `Symbol` was introduced, and `id2sym` was used for
compatibility. Today, no one uses `id2sym` any longer. It is described
in ISO 30170:2012 standard but I consider it as a mistake.
2021-05-03 15:30:59 +09:00
Yukihiro "Matz" Matsumoto 24dcd252f8 Merge pull request #5439 from dearblue/opcode.md
Enclose the table contents of `opcode.md` as code
2021-05-02 20:41:43 +09:00
Yukihiro "Matz" Matsumoto 4626348e47 array.c: mrb_ary_shift_m should be static. 2021-05-02 20:30:41 +09:00
dearblue 3e5ff7543a Enclose the table contents of opcode.md as code 2021-05-02 20:06:16 +09:00
dearblue ce973685d0 Rename mrbgems/mruby-inline-struct with mrbgems/mruby-test-inline-struct
This gem contains only tests.
2021-05-02 18:25:00 +09:00
Yukihiro "Matz" Matsumoto 14c13bb4d2 symbol.c: remove mrb_sym_static_p() function that no one use. 2021-05-02 17:57:34 +09:00
dearblue 66a55fb4df Run the task only once when parse.y is updated
Previously, the task was executed as many times as there were targets, including `mruby-compiler`.

```console
% rm mrbgems/mruby-compiler/core/y.tab.c
% rake `pwd`/mrbgems/mruby-compiler/core/y.tab.c
YACC  mrbgems/mruby-compiler/core/parse.y -> mrbgems/mruby-compiler/core/y.tab.c
YACC  mrbgems/mruby-compiler/core/parse.y -> mrbgems/mruby-compiler/core/y.tab.c
```
2021-05-02 16:52:50 +09:00
Yukihiro "Matz" Matsumoto 8f362eaf8a io.rb,print.rb: puts to expand array arguments.
As CRuby behaves.
2021-05-01 00:00:14 +09:00
Yukihiro "Matz" Matsumoto 519dc3d19c Merge pull request #5432 from shuujii/fix-typo-in-mrbgems-mruby-io-mrblib-io.rb
Fix typo in `mrbgems/mruby-io/mrblib/io.rb`; ref cb55e7eca
2021-04-29 11:17:41 +09:00
KOBAYASHI Shuji a633f0f9f6 Fix typo in mrbgems/mruby-io/mrblib/io.rb; ref cb55e7eca 2021-04-29 09:27:12 +09:00
Yukihiro "Matz" Matsumoto 2ad5d4f53d string.c: add a new method String#center. 2021-04-28 21:44:19 +09:00
Yukihiro "Matz" Matsumoto e5e5acefaf string.{c,rb}: fix type of return values from some methods as Ruby3.0
When the receiver is the instance of subclass of `String`.

- `String#each_char`
- `String#each_line`
- `String#partition`
2021-04-28 21:41:01 +09:00
Yukihiro "Matz" Matsumoto 6666b4fa62 doc/opcode.md: stop reversed link syntax check from markdownlint. 2021-04-28 21:37:06 +09:00
Yukihiro "Matz" Matsumoto cb55e7eca9 io.rb: reimplement IO#each_char.
It used to be an alias to `IO#each_byte` but those methods should have
behave differently.
2021-04-28 21:37:05 +09:00
Yukihiro "Matz" Matsumoto aff3743c12 array.rb: Array#uniq to return always Array.
Even called for subclass of `Array`, according to new Ruby3.0 behavior.
Other methods of `Array` behave as Ruby3.0 from the first hand.
2021-04-28 17:45:19 +09:00
Yukihiro "Matz" Matsumoto 9f77232b71 array.c: update Array#shift to take optional argument; close #5428 2021-04-27 16:37:24 +09:00
Yukihiro "Matz" Matsumoto 2e165b9e20 Merge pull request #5425 from dearblue/exc_to_s
Fix symbol leak in `exc_to_s()`
2021-04-26 23:13:22 +09:00
Yukihiro "Matz" Matsumoto f22535045a mruby.c: specify file names for libraries set by -r; fix #5427 2021-04-26 19:00:49 +09:00
Yukihiro "Matz" Matsumoto 14bd07f831 backtrace.c: skip innermost frame only when the method is in C; #5394 2021-04-26 16:46:44 +09:00
Yukihiro "Matz" Matsumoto b937463706 Merge pull request #5424 from dearblue/new_iseq
Fix annotations for inline iseq of `Class.new` [ci skip]
2021-04-26 14:29:46 +09:00
Yukihiro "Matz" Matsumoto 2ead8a0520 Merge pull request #5423 from dearblue/gc-red
Introduce `MRB_GC_RED`
2021-04-26 07:29:08 +09:00
Yukihiro "Matz" Matsumoto 8cd51578fb build_config/no-float.rb: unify two build configurations; #5421
- stop cross building
- add more gems for tests
- add `bintest`
2021-04-26 07:25:21 +09:00
Yukihiro "Matz" Matsumoto 767577efb1 Merge pull request #5422 from dearblue/binding1
Avoid ill-advised `goto`
2021-04-25 14:36:17 +09:00
dearblue c0cd004b21 Fix symbol leak in exc_to_s() 2021-04-25 10:49:33 +09:00
dearblue 8f66dd278b Fix annotations for inline iseq of Class.new [ci skip] 2021-04-24 21:31:50 +09:00
Yukihiro "Matz" Matsumoto 4d249c28d9 Skip tests that use Float inside; ref #5421 2021-04-24 12:04:08 +09:00
Yukihiro "Matz" Matsumoto f46b4056f8 numeric.c: remove duplicated definitions; #5421
Following functions are defined in `mrblib/numeric.c`:

- `Integer#ceil`
- `Integer#floor`
- `Integer#round`
- `Integer#truncate`
2021-04-24 11:56:50 +09:00
Yukihiro "Matz" Matsumoto 4b4622f711 time.c: fixable_time_t_p is not used with MRB_NO_FLOAT; #5421 2021-04-24 11:38:56 +09:00
Yukihiro "Matz" Matsumoto 237f3339bf random.c: refactoring; #5421
- `Random.rand` with `MRB_NO_FLOAT` behaves as `Random.rand(100)`
- `Random.rand(i)` where `i<0` raises `ArgumentError`
2021-04-24 11:15:53 +09:00
Yukihiro "Matz" Matsumoto 2e49a25740 build_config/nofloat.rb: build configuration with MRB_NO_FLOAT; #5421 2021-04-24 10:54:42 +09:00
dearblue 94c5c8f44c Introduce MRB_GC_RED
Replaces the magic number `7` except in `src/gc.c`.
2021-04-24 10:31:21 +09:00
Yukihiro "Matz" Matsumoto 90a59efbec numeric.c: fix errors from MRB_NO_FLOAT; close #5421 2021-04-24 10:23:40 +09:00
dearblue b18fd23cef Avoid ill-advised goto
ref #5362
2021-04-23 22:54:12 +09:00
Yukihiro "Matz" Matsumoto 39dc7b7901 vm.c: fix errors with MRB_NO_FLOAT; fix #5421 2021-04-23 11:28:17 +09:00
Yukihiro "Matz" Matsumoto dc88a87f9b time.c: time_t may be unsigned on some platforms. 2021-04-23 07:53:17 +09:00
Yukihiro "Matz" Matsumoto 1a82bab1b0 error.h: rename mrb_protect_raw to mrb_protect_error; #5415
- `_raw` does not describe the nature of the function
- the function protect errors during C function execution
2021-04-22 17:01:33 +09:00
Yukihiro "Matz" Matsumoto 91c4ac8d66 numeric.c: update error messages in int_pow; ref #5420 2021-04-21 22:08:07 +09:00
Yukihiro "Matz" Matsumoto 5cf1de5b31 numeric.c: fix int_pow to detect integer overflow; fix #5420 2021-04-21 22:05:52 +09:00
Yukihiro "Matz" Matsumoto 2268405fe6 test/math.rb: 10**30 could cause integer overflow; ref #5420 2021-04-21 22:04:20 +09:00
Yukihiro "Matz" Matsumoto bf11f87599 Merge pull request #5419 from shuujii/remove-unused-struct-in-include-mruby-variable.h
Remove unused struct in `include/mruby/variable.h`
2021-04-20 17:41:26 +09:00
Yukihiro "Matz" Matsumoto bd66115257 Merge pull request #5418 from shuujii/remove-unused--include-in-complex.c-and-rational.c
Remove unused `#include` in `complex.c` and `rational.c`
2021-04-20 17:41:01 +09:00
Yukihiro "Matz" Matsumoto ca744e77c4 Merge pull request #5417 from shuujii/remove-MRB_API-from-mrb_get_backtrace-definition
Remove `MRB_API` from `mrb_get_backtrace` definition
2021-04-20 17:40:33 +09:00
KOBAYASHI Shuji 903fbd767a Remove unused struct in include/mruby/variable.h 2021-04-20 16:53:11 +09:00
KOBAYASHI Shuji c6911c54e5 Remove unused #include in complex.c and rational.c 2021-04-20 16:42:40 +09:00
KOBAYASHI Shuji 0d8b025d9b Remove MRB_API from mrb_get_backtrace definition 2021-04-20 16:07:48 +09:00
Yukihiro "Matz" Matsumoto ff366b65eb Merge pull request #5415 from dearblue/unwind-mrb_protect
Introducing the `mrb_protect_raw()` API function
2021-04-19 22:34:20 +09:00
dearblue 891e852286 Introducing the mrb_protect_raw() API function
The purpose is two-fold:

 1. to be able to specify a pointer directly when user data is used

    When using `mrb_protect()`, it is necessary to allocate objects by `mrb_obj_cptr()` function when using user data.

    Adding `mrb_protect_raw()` will make it simpler to reimplement `mrbgems/mruby-error`.

 2. to correctly unwind callinfo when an exception is raised from a C function defined as a method (the main topic)

    If a method call is made directly under `mrb_protect()` and a C function is called, control is returned from `mrb_protect()` if an exception occurs there.
    In this case, callinfo is not restored, so it is out of sync.
    Moreover, returning to mruby VM (`mrb_vm_exec()` function) in this state will indicate `ci->pc` of C function which is equal to `NULL`, and subsequent `JUMP` will cause `SIGSEGV`.

    Following is an example that actually causes `SIGSEGV`:

    - `crash.c`

      ```c
      #include <mruby.h>
      #include <mruby/compile.h>
      #include <mruby/error.h>

      static mrb_value
      level1_body(mrb_state *mrb, mrb_value self)
      {
        return mrb_funcall(mrb, self, "level2", 0);
      }

      static mrb_value
      level1(mrb_state *mrb, mrb_value self)
      {
        return mrb_protect(mrb, level1_body, self, NULL);
      }

      static mrb_value
      level2(mrb_state *mrb, mrb_value self)
      {
        mrb_raise(mrb, E_RUNTIME_ERROR, "error!");
        return mrb_nil_value();
      }

      int
      main(int argc, char *argv[])
      {
        mrb_state *mrb = mrb_open();
        mrb_define_method(mrb, mrb->object_class, "level1", level1, MRB_ARGS_NONE());
        mrb_define_method(mrb, mrb->object_class, "level2", level2, MRB_ARGS_NONE());
        mrb_p(mrb, mrb_load_string(mrb, "p level1"));
        mrb_close(mrb);
        return 0;
      }
      ```

    - compile & run

      ```console
      % `bin/mruby-config --cc --cflags --ldflags` crash.c `bin/mruby-config --libs`

      % ./a.out
      zsh: segmentation fault (core dumped)  ./a.out
      ```

    After applying this patch, it will print exception object and exit normally.

The `mrb_protect()`, `mrb_ensure()` and `mrb_rescue_exceptions()` in `mrbgems/mruby-error` have been rewritten using `mrb_protect_raw()`.
2021-04-19 22:11:57 +09:00
Yukihiro "Matz" Matsumoto 9d362f2c27 backtrace.c: remove MRB_API from internal functions.
- `mrb_exc_backtrace` to implement `Exception#backtrace`
- `mrb_get_backtrace` to implement `#caller`
2021-04-19 15:49:51 +09:00
Yukihiro "Matz" Matsumoto 13eba43100 backtrace.c: small refactoring in mrb_exc_backtrace(); ref #5394
- add comment for unpacking
- avoid saving the symbol in a local variable
2021-04-19 15:49:51 +09:00
Yukihiro "Matz" Matsumoto 2275e76262 backtrace.c: pedantic check for empty backtrace; ref #5394 2021-04-19 15:49:50 +09:00
Yukihiro "Matz" Matsumoto 85808e50b0 backtrace.c: should skip first (innermost) frame w/out position; #5394
Otherwise we suffer `(unknown):0:` errors.
2021-04-19 15:49:50 +09:00
Yukihiro "Matz" Matsumoto 049ec9056e time.c: add integer boundary check for year.
On configurations where `sizeof(mrb_int) > sizeof(int)`.
2021-04-19 15:49:50 +09:00
Yukihiro "Matz" Matsumoto 713fb53bbf Merge pull request #5414 from shuujii/mRubyPresym-no-longer-needs-RakeDSL
`MRuby::Presym` no longer needs `Rake::DSL`
2021-04-18 08:24:15 +09:00
Yukihiro "Matz" Matsumoto 737254588b array.rb: add Array#intersect? from Ruby3.0.1. 2021-04-17 17:38:44 +09:00
KOBAYASHI Shuji f0318aca23 MRuby::Presym no longer needs Rake::DSL 2021-04-17 16:42:08 +09:00
John Bampton 9d32d440eb feat(CI): add the GitHub Super Linter
The GitHub Super Linter is a more robust and better supported
tool than the current GitHub Actions we are using.

Running these checks:

ERROR_ON_MISSING_EXEC_BIT: true
VALIDATE_BASH: true
VALIDATE_BASH_EXEC: true
VALIDATE_EDITORCONFIG: true
VALIDATE_MARKDOWN: true
VALIDATE_SHELL_SHFMT: true
VALIDATE_YAML: true

https://github.com/marketplace/actions/super-linter
https://github.com/github/super-linter

Added the GitHub Super Linter badge to the README.

Also updated the pre-commit framework and added
more documentation on pre-commit.

Added one more pre-commit check: check-executables-have-shebangs

Added one extra check for merge conflicts to our
GitHub Actions.

EditorConfig and Markdown linting.

Minor grammar and spelling fixes.

Update linter.yml
2021-04-16 16:37:52 +09:00
Yukihiro "Matz" Matsumoto ac9038121b Merge pull request #5413 from shuujii/fix-enable_debug_info-in-mrbgems-mruby-proc-ext-test-proc.rb
Fix `enable_debug_info?` in `mrbgems/mruby-proc-ext/test/proc.rb`
2021-04-15 16:55:43 +09:00
KOBAYASHI Shuji 35b2798a5d Fix enable_debug_info? in mrbgems/mruby-proc-ext/test/proc.rb 2021-04-15 15:49:23 +09:00
Yukihiro "Matz" Matsumoto 3c5467af63 Merge pull request #5411 from artichoke/mrb_protect_atexit_prototype_mismatch
Fix incorrect prototype on declaration of mrb_protect_atexit
2021-04-14 07:27:12 +09:00
Yukihiro "Matz" Matsumoto 5a8f0bdaf2 Merge pull request #5410 from mruby/dependabot/github_actions/actions/cache-v2.1.5
build(deps): bump actions/cache from v2.1.4 to v2.1.5
2021-04-14 07:25:07 +09:00
Ryan Lopopolo 7fe6f3976e Fix incorrect prototype on declaration of mrb_protect_atexit
`state.c` makes a prototype declaration for the private
`mrb_protect_atexit` which is defined in `error.c`. `error.c` defines
this function with a void return type, but `state.c` defines the
prototype with an `int` return type.

This mismatch prevents mruby from compiling on stricter compilers like
emscripten.
2021-04-13 07:57:09 -07:00
dependabot[bot] 99bd84e76b build(deps): bump actions/cache from v2.1.4 to v2.1.5
Bumps [actions/cache](https://github.com/actions/cache) from v2.1.4 to v2.1.5.
- [Release notes](https://github.com/actions/cache/releases)
- [Commits](https://github.com/actions/cache/compare/v2.1.4...1a9e2138d905efd099035b49d8b7a3888c653ca8)

Signed-off-by: dependabot[bot] <support@github.com>
2021-04-13 07:16:35 +00:00
Yukihiro "Matz" Matsumoto 1a3846b492 mrbgem.rake: avoid implicit receivers in mrbgem.rake. 2021-04-13 07:35:39 +09:00
Yukihiro "Matz" Matsumoto dd89a618b3 mruby-io: fix IO#ungetbyte; ref #5389
- remove `Integer#chr` (thus `mruby-sting-ext`) dependency
- fix the behavior when `c.is_a? String`
- fix the behavior when `c > 255`
2021-04-13 07:24:56 +09:00
Yukihiro "Matz" Matsumoto 9a9c842cb0 Rakefile: remove GitLab configuration; close #5409
This CI could consume too much CPU time on GitLab. Maybe we should add
resource concious CI configuration on GitLab.
2021-04-13 07:16:21 +09:00
Yukihiro "Matz" Matsumoto 475fc6ed26 AUTHORS: update authors information as of 2021-04-12. 2021-04-12 19:04:57 +09:00
Yukihiro "Matz" Matsumoto ff2ffe3b07 proc.h: add type cast to silence warning; ref #5402 2021-04-12 15:21:54 +09:00
Yukihiro "Matz" Matsumoto 2cb9a0653a Merge branch 'io_getbyte' close #5389 2021-04-10 19:08:51 +09:00
Yukihiro "Matz" Matsumoto 5cac9c8478 io.rb: fix IO#getbyte to work with UTF-8 characters; ref #5389 2021-04-10 19:08:15 +09:00
Yukihiro "Matz" Matsumoto 8fa1ff9a03 io.rb: add IO#readbyte; ref #5389 2021-04-10 19:08:15 +09:00
Yukihiro "Matz" Matsumoto 167e0b3f4f io.c: add assertions to mrb_io_bufread(); ref #5389 2021-04-10 19:08:14 +09:00
Yukihiro "Matz" Matsumoto 5342b5cfef io.rb: @buf should be empty on EOF; #4983, #5389 2021-04-10 19:08:14 +09:00
take-cheeze bf455fd582 Add IO#getbyte 2021-04-10 19:08:14 +09:00
Yukihiro "Matz" Matsumoto 44d5e214cc Rename some internal functions; ref #5401 2021-04-10 17:33:50 +09:00
Yukihiro "Matz" Matsumoto f7493b73cb Merge pull request #5400 from jbampton/fix-spelling
chore: fix spelling
2021-04-09 22:07:50 +09:00
Yukihiro "Matz" Matsumoto c2c37e1451 Merge pull request #5401 from dearblue/mcall
Reorganize `mcall()` in `mruby-method`
2021-04-09 21:46:09 +09:00
Yukihiro "Matz" Matsumoto 6d3c022749 mruby-config.bat: update as the shell version. [ci skip] 2021-04-08 07:32:35 +09:00
Yukihiro "Matz" Matsumoto cbe061c2f4 codeql-analysis.yml: remove git checkout HEAD^2.
According to CodeQL instruction, `HEAD^2` is no longer needed.
2021-04-08 07:32:34 +09:00
Yukihiro "Matz" Matsumoto 77405e11b6 Merge pull request #5407 from mruby/dependabot/github_actions/actions/upload-artifact-v2.2.3
build(deps): bump actions/upload-artifact from v2.2.2 to v2.2.3
2021-04-07 16:22:08 +09:00
dependabot[bot] 2544e7f0d1 build(deps): bump actions/upload-artifact from v2.2.2 to v2.2.3
Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from v2.2.2 to v2.2.3.
- [Release notes](https://github.com/actions/upload-artifact/releases)
- [Commits](https://github.com/actions/upload-artifact/compare/v2.2.2...ee69f02b3dfdecd58bb31b4d133da38ba6fe3700)

Signed-off-by: dependabot[bot] <support@github.com>
2021-04-07 07:12:15 +00:00
Yukihiro "Matz" Matsumoto fa2ad34792 Removing trailing white spaces; ref #5406 [ci skip] 2021-04-07 11:02:47 +09:00
Yukihiro "Matz" Matsumoto 32ae96af1f Merge pull request #5406 from sizious/dreamcast-shelf-build-config-update
Updating dreamcast_shelf build configuration.
2021-04-07 11:00:51 +09:00
SiZiOUS 03f7e88ee9 dreamcast_shelf: typo fix. 2021-04-06 20:49:03 +02:00
SiZiOUS 7ad2827900 Updating dreamcast_shelf build configuration. 2021-04-06 17:30:02 +02:00
Yukihiro "Matz" Matsumoto 71bf362a5b doc/link.md: update mruby-config description. 2021-04-06 17:25:54 +09:00
Yukihiro "Matz" Matsumoto 58ab97e300 mruby-config: add --cc and --ld options.
* `--cc` print compiler name
* `--ld` print linker name
2021-04-06 17:25:53 +09:00
Yukihiro "Matz" Matsumoto e19346fd8b Merge pull request #5405 from shuujii/fix-heading-level-in-doc-guides-link.md
Fix heading level in `doc/guides/link.md` [ci skip]
2021-04-06 13:14:34 +09:00
Yukihiro "Matz" Matsumoto 339216b5ec Merge pull request #5404 from shuujii/fix-typo-in-doc-guides-link.md
Fix typo in `doc/guides/link.md` [ci skip]
2021-04-06 12:52:14 +09:00
KOBAYASHI Shuji 6844ef7131 Fix heading level in doc/guides/link.md [ci skip] 2021-04-06 12:52:07 +09:00
KOBAYASHI Shuji 516756d538 Fix typo in doc/guides/link.md [ci skip] 2021-04-06 12:44:58 +09:00
Yukihiro "Matz" Matsumoto 1f03d34fd7 link.md: add new document for linking libmruby; ref #5393 2021-04-05 22:26:15 +09:00
Yukihiro "Matz" Matsumoto 27d3747faa Merge pull request #5402 from dearblue/catch1
Making a proc object static for a method with static irep
2021-04-04 17:56:25 +09:00
dearblue caeacea86e Making a proc object static for a method with static irep
The following methods will be made static.

  - `Class#new`
  - `Proc#call`
  - `Kernel#catch`

Previously, static const RProc could not be registered as a method, but this has been changed to allow it.
2021-04-04 15:44:19 +09:00
dearblue 4c196dcdaa Reorganize mcall() in mruby-method.
Use `mrb_exec_irep()`. If possible, re-entry into the VM will be suppressed.

Note that due to the effect of being a tail-call, the backtrace of `Method#call` will be lost, and it will look as if the target method was called directly.

This change fixes the problem of infinite loops when redefining methods that make block calls using `mruby-method`.

```console
% bin/mruby -e 'mm = method(:proc); define_method(:proc, ->(*a, &b) { mm.call(*a, &b) }); p proc { 1 }'
trace (most recent call last):
        [257] -e:1
        [256] -e:1:in proc
        [255] -e:1:in proc
        ...SNIP...
        [1] -e:1:in proc
-e:1:in proc: stack level too deep (SystemStackError)
```
2021-04-03 21:20:59 +09:00
dearblue dd34ac647f Make mrb_exec_irep() allow non-VM to enter.
Change the old `mrb_exec_irep()` as-is to static `mrb_exec_irep_vm()`.
Extract the VM entry part from the old `exec_irep()` in `mruby-eval/src/eval.c` and make it the core of the new `mrb_exec_irep()`.
2021-04-03 21:17:48 +09:00
John Bampton d8622fc68b chore: fix spelling 2021-04-03 19:51:01 +10:00
Yukihiro "Matz" Matsumoto fb8e12f37c Merge pull request #5397 from dearblue/c++dump
Fix build failures with `enable_debug` and `enable_cxx_abi`
2021-04-03 18:44:17 +09:00
Yukihiro "Matz" Matsumoto 474ec3e5c6 Merge pull request #5398 from jbampton/fix-authors-link
Fix the Authors link in the README
2021-04-03 17:58:30 +09:00
Yukihiro "Matz" Matsumoto 7561bed32a Merge pull request #5399 from jbampton/fix-spelling
chore: fix spelling
2021-04-03 17:57:08 +09:00
John Bampton ce2b8aa05e chore: fix spelling 2021-04-03 18:14:25 +10:00
John Bampton 049c1d0a45 Fix the Authors link in the README 2021-04-03 17:43:04 +10:00
dearblue 3e48f4eebc Fix build failures with enable_debug and enable_cxx_abi
Under C++, there is no implicit conversion from `int` to `enum`, which caused a compilation error.
2021-04-03 16:22:40 +09:00
Yukihiro "Matz" Matsumoto aca59de88e Merge branch 'shuujii-define-MRB_NO_GEMS-if-disable_libmruby-is-specified' 2021-04-02 07:55:43 +09:00
Yukihiro "Matz" Matsumoto ade9368510 Merge branch 'define-MRB_NO_GEMS-if-disable_libmruby-is-specified' of https://github.com/shuujii/mruby into shuujii-define-MRB_NO_GEMS-if-disable_libmruby-is-specified 2021-04-02 07:53:27 +09:00
Yukihiro "Matz" Matsumoto f68c0d092c Merge pull request #5396 from shuujii/fix-build-with-MRB_USE_ALL_SYMBOLS
Fix build with `MRB_USE_ALL_SYMBOLS`
2021-04-02 07:44:14 +09:00
Yukihiro "Matz" Matsumoto bda242a135 vm.c: change the default error message for undefined super method.
- (old) `undefined method 'foo'`
- (new) `no superclass method 'foo'`
2021-04-01 08:42:30 +09:00
KOBAYASHI Shuji 4309a5b1f4 Fix build with MRB_USE_ALL_SYMBOLS 2021-03-31 19:10:39 +09:00
Yukihiro "Matz" Matsumoto d5a4d5e393 codegen.c: s->ainfo should be zero along with OP_ENTER(0). 2021-03-31 17:20:14 +09:00
Yukihiro "Matz" Matsumoto 9f85c5e483 codegen.c: yield outside of method is now SyntaxError. 2021-03-31 15:57:43 +09:00
Yukihiro "Matz" Matsumoto a7ca5a9b6e backtrace.c: change missing-lineno to 0 for cosmetic reason; #5394 2021-03-31 15:41:19 +09:00
Yukihiro "Matz" Matsumoto f2da051367 Merge pull request #5394 from fundamental/partial-backtrace
Add support for partial backtraces
2021-03-31 15:39:47 +09:00
Yukihiro "Matz" Matsumoto b7c23a4a14 vm.c: resolve int and mrb_int mixture. 2021-03-31 11:46:21 +09:00
Yukihiro "Matz" Matsumoto 9038a1ca40 rational.c: add explicit cast from mrb_int to mrb_float. 2021-03-31 11:39:59 +09:00
Yukihiro "Matz" Matsumoto 590c1073fc should have removed codegen error: prefix from the test. 2021-03-31 11:35:56 +09:00
Yukihiro "Matz" Matsumoto cb8dabeb8c codegen.c: remove codegen error: prefix from error messages. 2021-03-31 10:48:18 +09:00
Yukihiro "Matz" Matsumoto 4428ce6050 codegen.c: ainfo may be negative.
When argument information is not available. So it should not happen for
`yield` (error). In contrast, the error from `super` should be handled
in run time (ignored).
2021-03-31 10:48:17 +09:00
Yukihiro "Matz" Matsumoto 87f113e19d Merge pull request #5395 from fundamental/mrbc-debug-cstruct
mrbc: Dump debug info with -g option
2021-03-31 10:48:01 +09:00
fundamental c146e81c4a Disable tests on backtraces w/ unknown line numbers 2021-03-30 20:26:10 -04:00
fundamental 5266f76346 mrbc: Dump debug info with -g option
Adds debug source information (line/file) when mrbc uses -g.
This commit results in usable backtraces for all gems when build_config
is setup with enable_debug.
2021-03-30 19:26:12 -04:00
fundamental 49f0da6821 Add support for partial backtraces
When debug information is omitted within ireps, show that a stack
frame existed rather than silently hiding it.
2021-03-30 19:16:15 -04:00
Yukihiro "Matz" Matsumoto a963e29b67 src/vm.c: calling C function may raise global jumps; fix #5391 2021-03-29 17:28:32 +09:00
Yukihiro "Matz" Matsumoto 3c2186f050 Merge pull request #5392 from mruby/revert-5391-throw
Revert "Fix `SIGSEGV` with mruby-method + mruby-catch"
2021-03-29 17:27:17 +09:00
Yukihiro "Matz" Matsumoto 4d3a1198f8 Revert "Fix SIGSEGV with mruby-method + mruby-catch" 2021-03-29 17:26:42 +09:00
Yukihiro "Matz" Matsumoto 76e4de7486 Merge pull request #5391 from dearblue/throw
Fix `SIGSEGV` with mruby-method + mruby-catch
2021-03-29 17:11:21 +09:00
Yukihiro "Matz" Matsumoto a5244b02c5 numeric.c: function renaming.
- `mrb_num_div_int(mrb,x,y)` -> `mrb_div_int(mrb,x,y)`
- `mrb_num_div_flo(mrb,x,y)` -> `mrb_div_flo(x,y)`

They are internal function not supposed to be used outside of the core.
2021-03-28 08:35:29 +09:00
dearblue 6c097c7113 Fix SIGSEGV with mruby-method + mruby-catch
Previously, the following code would cause a `SIGSEGV`.

```ruby
mm = method(:throw)
define_method(:throw, ->(*args) { mm.call(*args) })
catch { |tag| throw tag }
```

I think the reason is in the `mrb_yield_with_class()` function:
- Even if a C function is called, `CI_ACC_SKIP` is used
- `cipop()` is not done if globally jumping from a C function
2021-03-27 17:35:02 +09:00
Yukihiro "Matz" Matsumoto c2f929ad0f Move default Integer#/ from rational.c to complex.c. 2021-03-27 12:38:16 +09:00
Yukihiro "Matz" Matsumoto 01a8edea35 complex.rb: add test for arithmetic operators. [ci skip]
Tests for (`Float` or `Integer`) `op` `Complex`. Also added test
dependency to `mruby-rational` since `int_div` definition relies on
`Rational` when `MRB_USE_RATIONAL` is defined.
2021-03-26 17:20:25 +09:00
Yukihiro "Matz" Matsumoto 9492e389b8 rational.rb: add test for arithmetic operators.
Tests for (`Float` or `Integer`) `op` `Rational`.
2021-03-26 07:37:50 +09:00
Yukihiro "Matz" Matsumoto 6d89047637 rational.c: fix wrong funcall method in rational_mul. 2021-03-25 22:31:32 +09:00
Yukihiro "Matz" Matsumoto 0aff83dcdc rational.c: inline mrb_rational_eq().
It removes non-static function, so that strictly saying, it's
an incompatible change. But the function was added recently and I am
sure no one uses it yet.
2021-03-25 08:28:41 +09:00
Yukihiro "Matz" Matsumoto 4a0c14e3bd rational.c: implement Rational#<=> in C. 2021-03-24 19:49:20 +09:00
Yukihiro "Matz" Matsumoto 3a2075343c rational.c: implement Rational#/ and #quo in C. 2021-03-24 19:21:38 +09:00
Yukihiro "Matz" Matsumoto f05f6f4d11 rational.c: implement Rational#* in C. 2021-03-24 19:11:02 +09:00
Yukihiro "Matz" Matsumoto 9d058342a5 rational.c: implement Rational#- in C. 2021-03-24 19:01:58 +09:00
Yukihiro "Matz" Matsumoto 7a35b64251 fixup! rational.c: prepare utility function rat_to_flo(). 2021-03-24 19:01:38 +09:00
Yukihiro "Matz" Matsumoto ac4fe26fbb rational.c: prepare utility function rat_to_flo().
This function takes `struct mrb_rational*` and returns converted
`mrb_float` value.
2021-03-24 18:59:35 +09:00
Yukihiro "Matz" Matsumoto 7ca7bee9b3 rational.c: implement Rational#+ in C. 2021-03-24 13:57:49 +09:00
Yukihiro "Matz" Matsumoto 5a4958af26 complex.c: use mrb_num_div_flo to avoid copying function.
This change relies that `mrb_num_div_flo` does not use `mrb` inside.
2021-03-24 13:56:08 +09:00
Yukihiro "Matz" Matsumoto 092bba64e7 rational.c: check integer overflow in rational_minus. 2021-03-24 13:28:01 +09:00
Yukihiro "Matz" Matsumoto 49f75703cc complex.rb: unary plus (+@) to return self avoiding copying. 2021-03-24 11:06:48 +09:00
Yukihiro "Matz" Matsumoto 9ed212ef9e complex.c: implement Complex addition and subtraction in C. 2021-03-24 11:06:14 +09:00
Yukihiro "Matz" Matsumoto fa3ac351ff complex.c: override float division to support Complex. 2021-03-24 11:04:58 +09:00
Yukihiro "Matz" Matsumoto afb3c00e8c Use div_flo (copy of mrb_num_div_flo) for float division. 2021-03-24 10:56:01 +09:00
Yukihiro "Matz" Matsumoto ec456e5b18 Use mrb_num_div_flo for float division.
This function handles zero division properly. Also fixed bugs that multiply
numbers instead of division.
2021-03-24 10:54:24 +09:00
Yukihiro "Matz" Matsumoto 98799aa6b8 Fix infinite recursive call bugs in integer division. 2021-03-24 10:52:31 +09:00
Yukihiro "Matz" Matsumoto 3deb62d653 complex.c: implement Complex#/ and #quo in C. 2021-03-24 10:27:49 +09:00
Yukihiro "Matz" Matsumoto 5573707d7f complex.c: implement Complex#* in C. 2021-03-24 09:53:39 +09:00
Yukihiro "Matz" Matsumoto dc5d74dda8 rational.rb: avoid 'NaNi` representation.
Use `NaN*i` as CRuby does.
2021-03-24 09:52:15 +09:00
Yukihiro "Matz" Matsumoto 6e1a13360f Add `timeout-minutes' to GitHub workflow. [ci skip] 2021-03-23 15:02:48 +09:00
Yukihiro "Matz" Matsumoto 30576bf3c6 Merge pull request #5387 from shuujii/use-global-defines-for-mruby-bin-debugger
Use global defines for `mruby-bin-debugger`
2021-03-22 12:43:58 +09:00
Yukihiro "Matz" Matsumoto 2e87d83d8d Merge pull request #5388 from shuujii/reorganize-types-for-ObjectSpace.count_objects
Reorganize types for `ObjectSpace.count_objects`
2021-03-22 12:43:13 +09:00
Yukihiro "Matz" Matsumoto 7479ae307b nintendo_switch.rb: remove trailing white spaces; #5386 2021-03-22 12:39:48 +09:00
KOBAYASHI Shuji c0fb675526 Reorganize types for ObjectSpace.count_objects
#### Addition

- T_COMPLEX
- T_RATIONAL

#### Deletion

- T_FALSE
- T_FREE
- T_TRUE
- T_SYMBOL
- T_UNDEF
2021-03-22 12:24:42 +09:00
Yukihiro "Matz" Matsumoto dc6e7d5414 Merge pull request #5386 from LanzaSchneider/master
Add example for cross-compiling to Nintendo Switch
2021-03-22 12:06:59 +09:00
Yukihiro "Matz" Matsumoto cd047b2989 Merge pull request #5385 from shuujii/add-configuration-for-MinGW-cross-compilation
Add configuration for MinGW cross compilation [ci skip]
2021-03-22 12:05:03 +09:00
KOBAYASHI Shuji 00a13e22dd Use global defines for mruby-bin-debugger 2021-03-22 12:02:26 +09:00
Yukihiro "Matz" Matsumoto 68cf8346cd Use global defines for Rational and Complex. 2021-03-22 10:59:35 +09:00
Yukihiro "Matz" Matsumoto 384865997d build: provide global defines by build.defines. 2021-03-22 10:58:47 +09:00
Yukihiro "Matz" Matsumoto fbc629c56f codegen.c: fix integer size warnings.
along with repeated calls of `strlen()`.
2021-03-22 10:57:36 +09:00
Lanza ad09c39514 Add example for cross-compiling to Nintendo Switch
Cross Compiling configuration for the Nintendo Switch, it requires Nintendo SDK
2021-03-21 16:58:42 +08:00
KOBAYASHI Shuji b2c3ab8f3f Add configuration for MinGW cross compilation [ci skip]
With this cross compiler configuration, all tests for full-core gembox on
Windows on GitHub Actions were successful.
2021-03-21 16:43:04 +09:00
Yukihiro "Matz" Matsumoto 5764ff0740 command.rb: replace %w() to plain []. 2021-03-21 13:23:35 +09:00
Yukihiro "Matz" Matsumoto 73056aeb2b complex.c: define Complex#== in C.
This change also fixes the error caused by `rational.c` that calls
`mrb_complex_eq()`, which had been undefined.
2021-03-21 08:30:52 +09:00
Yukihiro "Matz" Matsumoto a6d4477a09 memsize.c: handle MRB_TT_RATIONAL and MRB_TT_COMPLEX. 2021-03-21 08:29:05 +09:00
Yukihiro "Matz" Matsumoto e21f293de5 rational.c: fix MRB_TT_RATIONAL and MRB_TT_COMPLEX confusion. 2021-03-20 18:03:11 +09:00
Yukihiro "Matz" Matsumoto 98821d2725 random.c: fixed seed underflow bug.
`MRB_INT_MIN` does not have a corresponding positive value.
2021-03-20 14:40:54 +09:00
Yukihiro "Matz" Matsumoto d3184e4a6d complex.c: overhaul complex operators.
- define `MRB_TT_COMPLEX`
- change object structure (`struct RComplex`)
- add memory management for `MRB_TT_COMPLEX`
- avoid operator overloading as much as possible
- as a result, performance improved a log
- should work with and without `Rational` defined
2021-03-19 10:37:10 +09:00
Yukihiro "Matz" Matsumoto 08f9d5bab5 rational.c: overhaul rational operators.
- define `MRB_TT_RATIONAL`
- change object structure (`struct RRational`)
- add memory management for `MRB_TT_RATIONAL`
- avoid operator overloading as much as possible
- implement division overloading in C
- as a result, performance improved a lot
2021-03-19 10:37:10 +09:00
Yukihiro "Matz" Matsumoto eb07030308 numeric.c: avoid integer overflow; close #5384
Since `mruby` does not have `Bignum`, `Float#divmod` could overflow, so
it will return `Float` values when the divided value does not fit in
`mrb_int`. This behavior will be changed when `Bignum` is introduced to
`mruby` in the future.
2021-03-19 07:15:05 +09:00
Yukihiro "Matz" Matsumoto 087e1719e4 Float#divmod with zero should cause ZeroDivisionError; #5384 2021-03-19 07:13:19 +09:00
Yukihiro "Matz" Matsumoto 0d96c1bb40 Merge branch 'dearblue-break-in-conf' 2021-03-18 22:48:11 +09:00
Yukihiro "Matz" Matsumoto 0e4f438eca lib/mruby/build.rb: refactoring ensure clause; ref #5381 2021-03-18 22:47:00 +09:00
Yukihiro "Matz" Matsumoto 99f00de040 Merge branch 'break-in-conf' of https://github.com/dearblue/mruby into dearblue-break-in-conf 2021-03-18 22:34:31 +09:00
Yukihiro "Matz" Matsumoto e5a3a37ae9 Merge pull request #5383 from shuujii/floatNAN-0-should-be-FloatNAN
`Float::NAN/0` should be `Float::NAN`; ref a0b3378b3
2021-03-18 20:54:56 +09:00
KOBAYASHI Shuji 6731f935cc Float::NAN/0 should be Float::NAN; ref a0b3378b3
#### Before this patch:

```console
$ bin/mruby -e 'p(Float::NAN/0)'
Infinity
```

#### After this patch (same as Ruby):

```console
$ bin/mruby -e 'p(Float::NAN/0)'
NaN
```
2021-03-18 17:10:51 +09:00
Yukihiro "Matz" Matsumoto a0b3378b36 numeric.c: float zero division should be infinity with sign kept; fix #5382 2021-03-18 15:24:31 +09:00
dearblue 199bbd73a3 Allow break in build_config.
If I break out of a block given to `MRuby::Build.new` with `break` or `throw`, I will get a seemingly inexplicable error because the `presym`-related initialization is not done.

```console
% cat build_config1.rb
MRuby::Build.new do
  toolchain
  break
end

% rake CONFIG=build_config1.rb
rake aborted!
external mrbc or mruby-bin-mrbc gem in current('host') or 'host' build is required
/var/tmp/mruby/lib/mruby/build.rb:332:in `mrbcfile'
/var/tmp/mruby/tasks/mrblib.rake:9:in `block in <top (required)>'
/var/tmp/mruby/lib/mruby/build.rb:18:in `instance_eval'
/var/tmp/mruby/lib/mruby/build.rb:18:in `block in each_target'
/var/tmp/mruby/lib/mruby/build.rb:17:in `each'
/var/tmp/mruby/lib/mruby/build.rb:17:in `each_target'
/var/tmp/mruby/tasks/mrblib.rake:1:in `<top (required)>'
/var/tmp/mruby/Rakefile:27:in `load'
/var/tmp/mruby/Rakefile:27:in `<top (required)>'
(See full trace by running task with --trace)
```

If a non-exceptional global jump occurs, it can be initialized by `ensure` to solve this problem.
2021-03-17 23:01:52 +09:00
Yukihiro "Matz" Matsumoto c0d63ea09f hash.c: Hash#shift to return nil when a hash is empty.
It used to be return the default value if available, but it should
ignore the default value for behavior consistency. CRuby will adopt
this behavior too in the future. [ruby-bugs:16908]
2021-03-17 15:14:23 +09:00
Yukihiro "Matz" Matsumoto 75ae3d3e23 range.c: fixed a begin-less ranges issue. 2021-03-17 09:48:27 +09:00
Yukihiro "Matz" Matsumoto 80f6b14ac1 AUTHORS: add the commit hash as of we counted. 2021-03-16 19:32:08 +09:00
Yukihiro "Matz" Matsumoto f576482082 Merge pull request #5379 from shuujii/fix-typo-in-AUTHORS
Fix typo in `AUTHORS` [ci skip]
2021-03-15 12:41:33 +09:00
KOBAYASHI Shuji def2ba56fd Fix typo in AUTHORS [ci skip] 2021-03-15 12:29:30 +09:00
Yukihiro "Matz" Matsumoto 266eccdf91 AUTHOR: fixed typos. 2021-03-15 11:57:49 +09:00
Yukihiro "Matz" Matsumoto d433a4e825 AUTHORS: add 2 new GitHub accounts. 2021-03-15 11:23:41 +09:00
Yukihiro "Matz" Matsumoto a3e73de2ba AUTHORS: re-renamed from AUTHOR.md. 2021-03-15 11:03:26 +09:00
Yukihiro "Matz" Matsumoto 5158b73ab4 AUTHORS.md: add GitHub accounts if available. 2021-03-15 10:32:55 +09:00
Yukihiro "Matz" Matsumoto be2bdce17d Remove mail addresses from AUTHORS.md. 2021-03-14 19:14:43 +09:00
Yukihiro "Matz" Matsumoto bf524e7002 time.c: calendar clock should use CLOCK_REALTIME; 5e95f11
The issue was reported by @shuujii
2021-03-14 14:54:53 +09:00
Yukihiro "Matz" Matsumoto f92a27f918 codegen.c: fix memory leak from new_litbn(). 2021-03-13 09:33:16 +09:00
Yukihiro "Matz" Matsumoto bf2110d206 codegen.c: need to preserve neg info. 2021-03-12 18:34:29 +09:00
Yukihiro "Matz" Matsumoto 01fdf03bce codegen.c: fixed a typo. 2021-03-12 18:34:09 +09:00
Yukihiro "Matz" Matsumoto b52078aa92 codegen.c: avoid integer comparison of different sign. 2021-03-12 16:26:51 +09:00
Yukihiro "Matz" Matsumoto 4ae5ae3535 codegen.c: no integer overflow error in codegen; close #5376
Add new pool value type `IREP_TT_BIGINT` and generate integer overflow
error in the VM. In the future, `mruby` will support `Bignum` for
integers bigger than `mrb_int` (probably using `mpz`).
2021-03-12 16:21:32 +09:00
Yukihiro "Matz" Matsumoto 84e27d3b51 Rename AUTHORS to AUTHORS.md. 2021-03-11 10:37:48 +09:00
Yukihiro "Matz" Matsumoto c45fc556f5 AUTHORS: update according to git log commit entries. 2021-03-11 10:34:10 +09:00
Yukihiro "Matz" Matsumoto 14f531355f Use relative path for files under doc directory [ci skip] 2021-03-10 18:39:21 +09:00
Yukihiro "Matz" Matsumoto a62a07f40e Merge pull request #5375 from artichoke/mrb_cmp-presym-op-maro
bug(presym): Fix mrb_cmp declaration of <=> symbol for funcall
2021-03-09 16:09:58 +09:00
Yukihiro "Matz" Matsumoto adbdbbb779 Merge pull request #5378 from jbampton/update-node-version
chore: upgrade markdownlint GitHub Action node version to 14
2021-03-09 15:29:21 +09:00
Yukihiro "Matz" Matsumoto 405b5225ae Merge pull request #5377 from jbampton/fix-grammar
chore: fix grammar
2021-03-09 15:03:35 +09:00
John Bampton 32261c96fa chore: upgrade markdownlint GitHub Action node version to 14
Upgrade to  markdownlint-cli version 0.27.1
2021-03-09 05:05:17 +10:00
John Bampton 3c1ce680a3 chore: fix grammar 2021-03-09 04:35:03 +10:00
Yukihiro "Matz" Matsumoto f2b3529441 time.c: fix errors on Windows and macOS; ref #5354
`gmtime_r` detection logic was too strict.
2021-03-08 15:23:29 +09:00
Ryan Lopopolo b199f6fc5a bug(presym): Fix mrb_cmp declaration of <=> symbol for funcall 2021-03-07 21:29:11 -08:00
Yukihiro "Matz" Matsumoto cb3a6dd168 ISO C99 doesn't support unnamed unions; fix #5354 2021-03-08 11:50:52 +09:00
Yukihiro "Matz" Matsumoto 833f556c70 Merge pull request #5374 from jbampton/fix-spelling
chore: fix spelling
2021-03-07 18:12:16 +09:00
John Bampton 15f7b0182d chore: fix spelling 2021-03-07 04:58:15 +10:00
Yukihiro "Matz" Matsumoto 111e4e1ba8 Merge pull request #5373 from mruby/stable
Merge mruby 3.0.0
2021-03-05 17:36:12 +09:00
mimaki 0f45836b59 Update version and release date. (mruby 3.0.0 (2021-03-05)) 2021-03-05 17:07:35 +09:00
Yukihiro "Matz" Matsumoto a712755036 Merge pull request #5372 from shuujii/fix-load-64-bit-integer-from-mrb-format
Fix load 64-bit integer from mrb format; fix #5369
2021-03-05 14:39:42 +09:00
KOBAYASHI Shuji cb10469dee Fix load 64-bit integer from mrb format; fix #5369 2021-03-05 13:41:13 +09:00
Yukihiro "Matz" Matsumoto 25f604635d Merge pull request #5371 from shuujii/update-minimal-build-configuration
Update minimal build configuration [ci skip]
2021-03-04 22:47:09 +09:00
Yukihiro "Matz" Matsumoto 32f66d4616 Merge pull request #5370 from shuujii/remove-unused-mrblib-init_mrblib.c
Remove unused `mrblib/init_mrblib.c`
2021-03-04 22:46:09 +09:00
KOBAYASHI Shuji 5296e0f5af Update minimal build configuration [ci skip] 2021-03-04 22:18:26 +09:00
KOBAYASHI Shuji c065002b51 Remove unused mrblib/init_mrblib.c 2021-03-04 21:54:00 +09:00
Yukihiro "Matz" Matsumoto 2f335e1a58 Fix mrb_pool_value to keep int64 on 32 bit platforms; fix #5366 2021-03-04 17:17:13 +09:00
Takashi Kokubun f5d3d89ac2 Skip --depth=1 when it's locked 2021-03-04 15:50:13 +09:00
Yukihiro "Matz" Matsumoto 2be1a9c3c7 time.c: timespec_get() never fails. 2021-03-03 12:01:49 +09:00
Yukihiro "Matz" Matsumoto 42afafbd23 time.c: fixed wrong condition to include unistd.h. 2021-03-03 10:15:50 +09:00
Yukihiro "Matz" Matsumoto 79e2ad9a44 time.c: Windows does not have unistd.h. 2021-03-03 10:01:32 +09:00
Yukihiro "Matz" Matsumoto 5e95f11756 time.c: use clock_gettime() if possible. 2021-03-03 09:53:11 +09:00
Yukihiro "Matz" Matsumoto 0c631a4c08 time.c: adjust buffer size in mrb_time_asctime(). 2021-03-03 09:52:26 +09:00
Yukihiro "Matz" Matsumoto 384209b8dd time.c: fix compile errors in mrb_time_asctime(). 2021-03-03 09:51:27 +09:00
Yukihiro "Matz" Matsumoto 187384124b Merge pull request #5368 from jbampton/add-pre-commit-framework
feat: add pre-commit framework
2021-03-02 16:53:33 +09:00
Yukihiro "Matz" Matsumoto 55ac5dba86 dump.c: remove operator_table if MRB_NO_STDIO is defined. 2021-03-01 14:57:58 +09:00
Yukihiro "Matz" Matsumoto 37e206472a minimal.rb: add minimal configuration; ref #1225 2021-03-01 14:54:29 +09:00
Yukihiro "Matz" Matsumoto f3507818e7 binding-core.c: add cast to remove warnings; ref #5362 2021-03-01 11:38:30 +09:00
Yukihiro "Matz" Matsumoto 935a135553 time.c: fixed a bug on no builtin overflow (e.g. VC). 2021-03-01 11:35:15 +09:00
John Bampton 1c9b1bfeb7 feat: add pre-commit framework 2021-03-01 10:06:17 +10:00
Yukihiro "Matz" Matsumoto 65add8c650 time.c: avoid using mrb_int_{add,sub}_overflow().
The size and signedness of `mrb_int` and `time_t` may differ.
2021-03-01 07:58:14 +09:00
Yukihiro "Matz" Matsumoto eb68adafa1 Merge pull request #5367 from dearblue/libedit
Support libedit on mirb for FreeBSD
2021-02-28 20:26:33 +09:00
Yukihiro "Matz" Matsumoto 03eb3b5e87 time.c: check overflow in addition and subtraction of Time. 2021-02-28 19:33:57 +09:00
Yukihiro "Matz" Matsumoto 8684abd697 Remove periods from error messages according to the convention. 2021-02-28 19:32:52 +09:00
Yukihiro "Matz" Matsumoto b61766473b time.c: change RuntimeError to ArgumentError. 2021-02-28 19:26:40 +09:00
dearblue 15a7d5be3d Support libedit on mirb for FreeBSD 2021-02-28 16:23:37 +09:00
Yukihiro "Matz" Matsumoto 4dbbe14117 state.c: remove stdint.h inclusion.
Fixes C++03 compilation.
2021-02-27 16:40:05 +09:00
Yukihiro "Matz" Matsumoto 3da372b30f pack.c: add more checks for pack_pack(). 2021-02-27 12:00:24 +09:00
Yukihiro "Matz" Matsumoto 30b1287df5 state.c: check irep reference count overflow. 2021-02-26 22:16:07 +09:00
Yukihiro "Matz" Matsumoto 5d37160455 Use MRB_SYM() more extensively. 2021-02-26 15:05:55 +09:00
Yukihiro "Matz" Matsumoto 192f3df9a1 Merge pull request #5362 from dearblue/binding
Binding
2021-02-25 21:15:24 +09:00
Yukihiro "Matz" Matsumoto f1c2096f8e parse.y: endless_method_name should allow ==.
e.g. `def ==(v) = true`. The issue is reported by @shuujii
2021-02-24 22:20:16 +09:00
Yukihiro "Matz" Matsumoto 386b53e6d9 parse.y: upgrade endless def syntax.
- prohibit defining setter method
- allow endless def without parentheses
2021-02-24 16:56:55 +09:00
Yukihiro "Matz" Matsumoto a9ebd4703f Merge pull request #5364 from mruby/dependabot/github_actions/actions/setup-node-v2.1.5
Bump actions/setup-node from v2.1.4 to v2.1.5
2021-02-23 16:43:37 +09:00
dependabot[bot] 09ebfc43a6 Bump actions/setup-node from v2.1.4 to v2.1.5
Bumps [actions/setup-node](https://github.com/actions/setup-node) from v2.1.4 to v2.1.5.
- [Release notes](https://github.com/actions/setup-node/releases)
- [Commits](https://github.com/actions/setup-node/compare/v2.1.4...46071b5c7a2e0c34e49c3cb8a0e792e86e18d5ea)

Signed-off-by: dependabot[bot] <support@github.com>
2021-02-23 07:17:23 +00:00
dearblue 927615e1f0 Added other methods for Binding
- Added to `mruby-binding-core`
  - `Binding#local_variable_defined?`
  - `Binding#local_variable_get`
  - `Binding#local_variable_set`
  - `Binding#local_variables`
  - `Binding#receiver`
  - `Binding#source_location`
  - `Binding#inspect`
- Added to `mruby-proc-binding`
  - `Proc#binding`

The reason for separating `Proc#binding` is that core-mrbgems has a method that returns a closure object to minimize possible problems with being able to manipulate internal variables.
By separating it as different mrbgem, each user can judge this problem and incorporate it arbitrarily.
2021-02-22 23:32:43 +09:00
dearblue 792f6ac670 Adjustment of the current HEAD and bindings, and separation
Make changes to make `Binding` work.
At the same time, it separates `Binding#eval`, which depends on `mruby-eval`, from `mruby-binding-core`.
2021-02-22 23:32:18 +09:00
dearblue 935ffa46a3 Change mruby-binding to mruby-binding-core 2021-02-22 22:15:46 +09:00
dearblue 297c5ac598 Merge branch 'binding' of https://github.com/ksss/mruby into HEAD 2021-02-22 22:14:46 +09:00
Yukihiro "Matz" Matsumoto d64c7330bc print.c: fix a compilation errors with MRB_NO_STDIO; fix #5361 2021-02-22 13:39:37 +09:00
Yukihiro "Matz" Matsumoto 60f9028612 Merge pull request #5360 from dearblue/opcode
Updated `doc/opcode.md` to match `include/mruby/ops.h` [ci skip]
2021-02-21 20:26:28 +09:00
dearblue 07874a3d29 Updated doc/opcode.md to match include/mruby/ops.h [ci skip] 2021-02-21 19:30:19 +09:00
Yukihiro "Matz" Matsumoto 6b8393081a Merge pull request #5359 from dearblue/warn
Comment out `warn` used in the `Array#fetch` method
2021-02-20 20:56:30 +09:00
dearblue 7ef4e54370 Comment out warn used in the Array#fetch method
I get an error because the current mruby does not have a `Kernel#warn` method.
But the warning itself is useful and I'll just comment it out in case it's implemented in the future.
2021-02-20 18:19:00 +09:00
Yukihiro "Matz" Matsumoto 0d7f5b8216 metaprog.c: fix a methods() bug with false argument; fix #5351 2021-02-20 14:56:55 +09:00
Yukihiro "Matz" Matsumoto 8ed15c078b metaprog.c: remove unused argument from a private function. 2021-02-20 13:20:14 +09:00
Yukihiro "Matz" Matsumoto 16fe040479 mruby/value.h: MRB_TT_CPTR is immediate with MRB_NO_BOXING.
The issue is reported by @shuujii.
2021-02-19 23:23:18 +09:00
Yukihiro "Matz" Matsumoto e5559184e0 Fix mrb_immediate_p() definition for MRB_NO_BOXING; ref #5352 2021-02-19 21:02:31 +09:00
Yukihiro "Matz" Matsumoto 787487b16d Check MRB_TT_* before object allocation; ref #5352 2021-02-19 15:36:41 +09:00
Yukihiro "Matz" Matsumoto ce0a381406 Merge pull request #5352 from shuujii/fix-type-tag-that-set-to-NilClass-and-FalseClass
Fix type tag that set to `NilClass` and `FalseClass`
2021-02-18 21:51:07 +09:00
Yukihiro "Matz" Matsumoto bdf2cf005e Merge pull request #5357 from k0kubun/lock-depth
Skip --depth=1 when it's locked
2021-02-17 15:23:24 +09:00
Takashi Kokubun 6ac79a2c44 Skip --depth=1 when it's locked 2021-02-16 20:56:13 -08:00
Yukihiro "Matz" Matsumoto cb43dda009 Merge pull request #5347 from shuujii/add--s-option-to-mrbc-for-make-variable-static
Add `-s` option to `mrbc` for make variable static
2021-02-17 12:43:45 +09:00
Yukihiro "Matz" Matsumoto dee9168882 Merge pull request #5356 from mruby/dependabot/github_actions/actions/upload-artifact-v2.2.2
Bump actions/upload-artifact from v1 to v2.2.2
2021-02-16 13:54:24 +09:00
Yukihiro "Matz" Matsumoto cb9225bcbf Merge pull request #5355 from mruby/dependabot/github_actions/actions/cache-v2.1.4
Bump actions/cache from v2 to v2.1.4
2021-02-16 13:54:00 +09:00
dependabot[bot] cf2fce93ec Bump actions/upload-artifact from v1 to v2.2.2
Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from v1 to v2.2.2.
- [Release notes](https://github.com/actions/upload-artifact/releases)
- [Commits](https://github.com/actions/upload-artifact/compare/v1...e448a9b857ee2131e752b06002bf0e093c65e571)

Signed-off-by: dependabot[bot] <support@github.com>
2021-02-16 04:23:03 +00:00
dependabot[bot] 1c8e1e20e4 Bump actions/cache from v2 to v2.1.4
Bumps [actions/cache](https://github.com/actions/cache) from v2 to v2.1.4.
- [Release notes](https://github.com/actions/cache/releases)
- [Commits](https://github.com/actions/cache/compare/v2...26968a09c0ea4f3e233fdddbafd1166051a095f6)

Signed-off-by: dependabot[bot] <support@github.com>
2021-02-16 04:23:03 +00:00
Yukihiro "Matz" Matsumoto e2d4bedb7b Merge pull request #5343 from jbampton/add-dependabot-config
feat: add Dependabot config file
2021-02-16 13:08:39 +09:00
Yukihiro "Matz" Matsumoto d6164817f5 Use full-core gembox for clang-asan configuration.
For better coverage.
2021-02-16 12:55:19 +09:00
Yukihiro "Matz" Matsumoto 7470337a82 Update URL explaining alignment issue; close #5344 2021-02-16 12:50:31 +09:00
Yukihiro "Matz" Matsumoto 61370ca98c Merge pull request #5350 from shuujii/refine-checking-for-trailing-whitespace
Refine checking for trailing whitespace [skip travis][skip appveyor]
2021-02-15 13:49:52 +09:00
Yukihiro "Matz" Matsumoto 2725755bc5 Merge pull request #5349 from shuujii/remove-trailing-tab-in-build_config-dreamcast_shelf.rb
Remove trailing tab in `build_config/dreamcast_shelf.rb` [ci skip]
2021-02-15 10:54:29 +09:00
Yukihiro "Matz" Matsumoto 330dd3f450 Merge pull request #5353 from dearblue/editorconfig
Introduce EditorConfig [skip ci]
2021-02-15 10:53:48 +09:00
dearblue 9b38dddc61 Introduce EditorConfig [skip ci] 2021-02-14 22:19:20 +09:00
KOBAYASHI Shuji 68daa3bf96 Fix type tag that set to NilClass and FalseClass 2021-02-14 20:55:46 +09:00
Yukihiro "Matz" Matsumoto 3217febfe9 Merge pull request #5348 from dearblue/optable
Place optable in ROM
2021-02-14 17:49:00 +09:00
KOBAYASHI Shuji 4203e574e3 Refine checking for trailing whitespace [skip travis][skip appveyor]
* Include tabs in checking.
* Use `git grep` to avoid including `.git` directory.
* Avoid running `grep` multiple times.
2021-02-14 16:07:04 +09:00
KOBAYASHI Shuji 29dfadf0de Remove trailing tab in build_config/dreamcast_shelf.rb [ci skip] 2021-02-14 16:02:02 +09:00
dearblue 297df70bc1 Place optable in ROM 2021-02-14 13:53:51 +09:00
KOBAYASHI Shuji a6a76d8fd2 Add -s option to mrbc for make variable static 2021-02-14 11:55:53 +09:00
Yukihiro "Matz" Matsumoto c3ec5861ac Merge pull request #5346 from jbampton/clean-up-linters
refactor: add the spell checker Action to the Lint Action file
2021-02-13 18:25:27 +09:00
John Bampton c263aec748 refactor: add the spell checker Action to the Lint Action file
Order jobs in workflow.
2021-02-13 18:58:48 +10:00
Yukihiro "Matz" Matsumoto da6c4ed169 Merge pull request #5345 from jbampton/fix-missing-https-on-links
chore: fix missing HTTPS on links
2021-02-13 17:21:12 +09:00
John Bampton 6204244b41 chore: fix missing HTTPS on links 2021-02-13 18:17:47 +10:00
Yukihiro "Matz" Matsumoto d04c651405 Merge pull request #5342 from jbampton/fix-spelling
chore: fix spelling
2021-02-13 16:38:02 +09:00
John Bampton d52da3fe77 feat: add Dependabot config file
Set for GitHub Actions to check for update everyday.

When you add or update the dependabot.yml file, this triggers an immediate check for version updates. Any options that also affect security updates are used the next time a security alert triggers a pull request for a security update.

https://docs.github.com/en/github/administering-a-repository/configuration-options-for-dependency-updates
2021-02-13 17:37:30 +10:00
John Bampton be40e9c783 chore: fix spelling
Normally a single spell checker can't find all the mistakes or check all types of code.

These mistakes were found by another spell checker inside my editor with a more manual sift / find.
2021-02-13 17:21:17 +10:00
Yukihiro "Matz" Matsumoto 9a9c95986a Merge pull request #5341 from jbampton/check-for-trailing-whitespace
feat(CI): check for trailing whitespace
2021-02-13 15:46:51 +09:00
John Bampton d55a74c418 feat(CI): check for trailing whitespace
Run on pull request only.
Use a shell script to check for trailing whitespace in all files.
Fail if trailing whitespace is found.
2021-02-13 16:37:46 +10:00
Yukihiro "Matz" Matsumoto 8e01fc8933 Merge pull request #5340 from jbampton/use-certified-actions
refactor: only use certified GitHub Actions to increase security
2021-02-13 15:19:34 +09:00
John Bampton 4c7ecbb8a6 refactor: only use certified GitHub Actions to increase security
Official -> "The individual jobs in a workflow can interact with (and compromise) other jobs. For example, a job querying the environment variables used by a later job, writing files to a shared directory that a later job processes, or even more directly by interacting with the Docker socket and inspecting other running containers and executing commands in them.

This means that a compromise of a single action within a workflow can be very significant, as that compromised action would have access to all secrets configured on your repository, and can use the GITHUB_TOKEN to write to the repository. Consequently, there is significant risk in sourcing actions from third-party repositories on GitHub. "

https://docs.github.com/en/actions/learn-github-actions/security-hardening-for-github-actions#using-third-party-actions
2021-02-13 16:13:30 +10:00
Yukihiro "Matz" Matsumoto acdd939d80 Merge pull request #5339 from shuujii/update-compile-prerequisites-in-doc-guides-compile.md
Update compile prerequisites in `doc/guides/compile.md` [ci skip]
2021-02-13 14:17:58 +09:00
Yukihiro "Matz" Matsumoto 94fb86f89b parse.y: string buffer (tokbuf) can overflow.
Check if `esclen` is smaller than `len` (original string length).
2021-02-13 14:06:37 +09:00
KOBAYASHI Shuji d470163b22 Update compile prerequisites in doc/guides/compile.md [ci skip]
Bison and gperf are optional.
2021-02-13 11:53:52 +09:00
Yukihiro "Matz" Matsumoto adb50df71a Update GitHub Actions.
- Remove Ubuntu-16.04
- Add Ubuntu-20.04 {gcc,clang}
2021-02-12 21:14:06 +09:00
Yukihiro "Matz" Matsumoto 5ba37db981 Merge pull request #5336 from shuujii/fix-build-mruby-catch-gem-without-presym
Fix build `mruby-catch` gem without presym
2021-02-12 21:11:59 +09:00
Yukihiro "Matz" Matsumoto d3fbac4d53 Merge pull request #5335 from shuujii/add-UncaughtThrowError-tagvalue-for-Ruby-compatibility
Add `UncaughtThrowError#{tag,value}` for Ruby compatibility
2021-02-12 21:10:53 +09:00
Yukihiro "Matz" Matsumoto 5f71e0e754 Merge pull request #5337 from shuujii/remove-skip-ci-hack-to-GitHub-Actions
Remove "skip ci" hack to GitHub Actions [skip travis][skip appveyor]
2021-02-12 21:09:07 +09:00
KOBAYASHI Shuji 28729deed6 Remove "skip ci" hack to GitHub Actions [skip travis][skip appveyor]
GitHub Actions now supports "skip ci" natively:
https://github.blog/changelog/2021-02-08-github-actions-skip-pull-request-and-push-workflows-with-skip-ci/
2021-02-12 19:44:41 +09:00
KOBAYASHI Shuji 8ba7be0999 Fix build mruby-catch gem without presym 2021-02-12 19:19:32 +09:00
KOBAYASHI Shuji 955464ca3c Add UncaughtThrowError#{tag,value} for Ruby compatibility 2021-02-12 19:09:18 +09:00
Yukihiro "Matz" Matsumoto 2af8e16cc6 include/mruby/array.h: ARY_LEN() should return mrb_int.
It used to return `mrb_ssize` but its size may differ from `mrb_int`,
e.g. `MRB_INT64` on `MRB_32BIT` architecture.
2021-02-12 16:57:33 +09:00
Yukihiro "Matz" Matsumoto 31051fd656 doc/mruby3.md: use relative path. 2021-02-12 15:39:19 +09:00
Yukihiro "Matz" Matsumoto ca7cac8b31 Merge pull request #5334 from shuujii/avoid-possibility-of-reading-uninitialized-areas-in-h_check_modified
Avoid possibility of reading uninitialized areas in `h_check_modified()`
2021-02-12 15:38:59 +09:00
KOBAYASHI Shuji 453296a729 Avoid possibility of reading uninitialized areas in h_check_modified()
In `h_check_modified()`, in the case of `MRB_NO_BOXING`, `ht_ea()` or
`ht_ea_capa()` for AR may read uninitialized area. Therefore, do not use
those macros for AR in `MRB_NO_BOXING` (but in the case of `MRB_64BIT`,
`ht_ea_capa()` is the same as `ar_ea_capa()`, so use it).

fix #5332
2021-02-12 15:00:06 +09:00
Yukihiro "Matz" Matsumoto 22ffc1108b src/print.c: stop warning with MRB_NO_STDIO. 2021-02-12 11:14:25 +09:00
Yukihiro "Matz" Matsumoto 793fbab7d5 Rename mrb_sleep.c to sleep.c in mruby-sleep gem. 2021-02-12 11:11:10 +09:00
Yukihiro "Matz" Matsumoto a96bd02127 Update docs/guides/mrbgems.md; ref #5210
Binary gems description added, along with a few cosmetic changes.
2021-02-12 11:07:45 +09:00
Yukihiro "Matz" Matsumoto 5c130e8e7b Do not collect linker options from binary gems; close #5210
Binary gems are mrbgems that set `spec.bins` in their `mrbgem.rake`,
and usually their names are prefixed with `mruby-bin-`.
2021-02-12 10:33:53 +09:00
Yukihiro "Matz" Matsumoto 69f8a52866 Update docs/guides/compile.md.
Especially description regarding the build process and `build` directory
structures, along with some typo fixes and cosmetic changes.
2021-02-12 10:27:10 +09:00
Yukihiro "Matz" Matsumoto 0db6e3eb6f Rename mruby-catch.c to catch.c; ref #5328 2021-02-12 10:09:19 +09:00
Yukihiro "Matz" Matsumoto d178e147f5 Merge pull request #5333 from shuujii/fix-heap-buffer-overflow-for-small-Hash-HT-in-Hash-rehash
Fix heap-buffer-overflow for small `Hash` (HT) in `Hash#rehash`
2021-02-11 08:26:33 +09:00
Yukihiro "Matz" Matsumoto 5735d7c2fd Merge branch 'dearblue-mruby-catch' 2021-02-10 20:11:40 +09:00
Yukihiro "Matz" Matsumoto c7809ca025 Refactor mruby-catch; ref #5328
- Move `#catch` definition to `mruby-catch.c` to avoid tweaking
- Remove `#__preserve_catch_method`
- Implement whole `#throw` method in C
2021-02-10 20:09:00 +09:00
KOBAYASHI Shuji 28eb6271ba Fix heap-buffer-overflow for small Hash (HT) in Hash#rehash
### Example

##### example.rb

```ruby
h = {}
(1..17).each{h[_1] = _1}
(1..16).each{h.delete(_1)}
h.rehash
```

##### ASAN report

```console
$ bin/mruby example.rb
==52587==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x602000006998 at pc 0x55a29cddf96b bp 0x7fff7b1b1720 sp 0x7fff7b1b1710
READ of size 4 at 0x602000006998 thread T0
    #0 0x55a29cddf96a in ib_it_next /mruby/src/hash.c:639
    #1 0x55a29cde2ca2 in ht_rehash /mruby/src/hash.c:900
    #2 0x55a29cde379f in h_rehash /mruby/src/hash.c:996
    #3 0x55a29cde7f3d in mrb_hash_rehash /mruby/src/hash.c:1735
    #4 0x55a29ce77b62 in mrb_vm_exec /mruby/src/vm.c:1451
    #5 0x55a29ce5fa88 in mrb_vm_run /mruby/src/vm.c:981
    #6 0x55a29ceb87e1 in mrb_top_run /mruby/src/vm.c:2874
    #7 0x55a29cf36bdf in mrb_load_exec mrbgems/mruby-compiler/core/parse.y:6805
    #8 0x55a29cf36f25 in mrb_load_detect_file_cxt mrbgems/mruby-compiler/core/parse.y:6848
    #9 0x55a29cdba0a2 in main /mruby/mrbgems/mruby-bin-mruby/tools/mruby/mruby.c:347
    #10 0x7f24ef43b0b2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x270b2)
    #11 0x55a29cdb4a6d in _start (/mruby/bin/mruby+0x2a3a6d)

0x602000006998 is located 0 bytes to the right of 8-byte region [0x602000006990,0x602000006998)
allocated by thread T0 here:
    #0 0x7f24f01cfffe in __interceptor_realloc (/lib/x86_64-linux-gnu/libasan.so.5+0x10dffe)
    #1 0x55a29ceb9440 in mrb_default_allocf /mruby/src/state.c:68
    #2 0x55a29cdba747 in mrb_realloc_simple /mruby/src/gc.c:228
    #3 0x55a29cdba928 in mrb_realloc /mruby/src/gc.c:242
    #4 0x55a29cde12e5 in ht_init /mruby/src/hash.c:749
    #5 0x55a29cde2b8e in ht_rehash /mruby/src/hash.c:897
    #6 0x55a29cde379f in h_rehash /mruby/src/hash.c:996
    #7 0x55a29cde7f3d in mrb_hash_rehash /mruby/src/hash.c:1735
    #8 0x55a29ce77b62 in mrb_vm_exec /mruby/src/vm.c:1451
    #9 0x55a29ce5fa88 in mrb_vm_run /mruby/src/vm.c:981
    #10 0x55a29ceb87e1 in mrb_top_run /mruby/src/vm.c:2874
    #11 0x55a29cf36bdf in mrb_load_exec mrbgems/mruby-compiler/core/parse.y:6805
    #12 0x55a29cf36f25 in mrb_load_detect_file_cxt mrbgems/mruby-compiler/core/parse.y:6848
    #13 0x55a29cdba0a2 in main /mruby/mrbgems/mruby-bin-mruby/tools/mruby/mruby.c:347
    #14 0x7f24ef43b0b2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x270b2)
```
2021-02-10 20:03:34 +09:00
Yukihiro "Matz" Matsumoto f0e25121fd Merge branch 'mruby-catch' of https://github.com/dearblue/mruby into dearblue-mruby-catch 2021-02-10 15:43:24 +09:00
Yukihiro "Matz" Matsumoto 20342714ea Upgrade supported Ruby version to 2.5.
Ruby 2.5 is the oldest maintained version.
2021-02-09 22:29:42 +09:00
Yukihiro "Matz" Matsumoto aa5b7fbd80 i_gcd() does not work for MRB_INT_MIN. 2021-02-08 21:18:50 +09:00
Yukihiro "Matz" Matsumoto db1172b48c Allow the case MRB_32BIT and MRB_NO_BOXING and MRB_USE_FLOAT32; #4382 2021-02-08 17:46:38 +09:00
Yukihiro "Matz" Matsumoto bc21278a7c Merge pull request #5331 from shuujii/explicit-top-level-task-to-clarify-in-tasks-test.rake
Explicit top level task to clarify in `tasks/test.rake`
2021-02-08 07:19:05 +09:00
KOBAYASHI Shuji 3cf0e85ed7 Explicit top level task to clarify in tasks/test.rake 2021-02-07 19:11:54 +09:00
Yukihiro "Matz" Matsumoto 530afca2d7 Move F(x) definition inside of #ifdef; fix #5330 2021-02-07 15:28:23 +09:00
Yukihiro "Matz" Matsumoto 1cc20978cf Enlarge tolerance limit for float32; close #5329
Along with some refactoring on `mruby-math` tests.
2021-02-07 14:56:34 +09:00
Yukihiro "Matz" Matsumoto 3252518a3c Fix tests to work with MRB_USE_FLOAT32; fix #5329 2021-02-07 14:55:45 +09:00
Yukihiro "Matz" Matsumoto 70b7ebd72f Add host-f32 config to test MRB_USE_FLOAT32; ref #5329 2021-02-07 14:54:01 +09:00
dearblue 232e07ad61 Reimplement mruby-catch; ref #5321
When there is a corresponding tag, the `RBreak` object is used to make a global jump.

Like CRuby, it can't be caught by `rescue`.
It is also the same as CRuby that it can be canceled in the middle by `ensure`.

 ### How to find the corresponding tag with `throw`

The called `catch` method remains in the call stack, and the tag also remains in the stack at that time.
So it is possible to find the called location by searching the two.

Note that no method can be given to the `proc` object specified in `RBreak`.
Therefore, inside the `catch` method, the argument block is called in a seemingly meaningless closure.

Also, as a countermeasure against `alias` etc., the `proc` object, which is the body of the `catch` method, is saved when mrbgem is initialized.
2021-02-06 21:41:08 +09:00
Yukihiro "Matz" Matsumoto ef8f475722 MinGW does not need MSVC hack.
Both MinGW and MSVC provide _WIN32 macro.
2021-02-06 19:30:59 +09:00
Yukihiro "Matz" Matsumoto c6c632cf97 Merge pull request #5325 from dearblue/c++-exc.2
`compile_as_cxx` should generate a path under` conf.build_dir`
2021-02-06 18:36:25 +09:00
Yukihiro "Matz" Matsumoto 94d8dfed66 Merge pull request #5327 from dearblue/notest
Ignore if `conf.enable_test` does not exist
2021-02-06 18:28:53 +09:00
Yukihiro "Matz" Matsumoto 6d0b5102cf Merge pull request #5326 from dearblue/struct
No need to check class definition
2021-02-06 18:25:49 +09:00
dearblue 9d1a659bc7 Ignore if conf.enable_test does not exist
Because if the configuration file didn't contain any `conf.enable_test`, `rake test` would report an exception and exit.

```console
% cat my_config.rb
MRuby::Build.new { toolchain }

% rake MRUBY_CONFIG=my_config.rb test

  ...SNIP...

rake aborted!
NoMethodError: undefined method `invoke' for nil:NilClass
/var/tmp/mruby/tasks/test.rake:24:in `block (3 levels) in <top (required)>'
Tasks: TOP => test => test:build => test:build:lib
(See full trace by running task with --trace)
```
2021-02-06 18:09:27 +09:00
dearblue 0f8d3d8777 No need to check class definition
Because now the `Struct` class is always defined when this file is included.
2021-02-06 18:05:05 +09:00
dearblue e0d2f4e0ae compile_as_cxx should generate a path under conf.build_dir
If the current directory is different from `MRUBY_ROOT` and it has` conf.build_dir` and `conf.enable_cxx_exception` set, it was generating a pathname outside of` build_dir`.
As a result, in some cases files unrelated to mruby could be linked.

```console
% pwd
/tmp/mruby/1/2/3/4/5/6

% mruby_dir=/tmp/mruby/a/b/c/d/mruby

% cat my_config.rb
MRuby::Build.new("host", "build/to/custom/directory") do
  toolchain
  enable_cxx_exception
end

% rake MRUBY_CONFIG=my_config.rb -f $mruby_dir/Rakefile > logs
% grep CXX logs
CXX   a/b/c/d/mruby/src/error-cxx.cxx -> a/b/c/d/mruby/src/error-cxx.o
CXX   a/b/c/d/mruby/src/gc-cxx.cxx -> a/b/c/d/mruby/src/gc-cxx.o
CXX   a/b/c/d/mruby/src/vm-cxx.cxx -> a/b/c/d/mruby/src/vm-cxx.o
CXX   a/b/c/d/mruby/mrbgems/mruby-compiler/core/codegen-cxx.cxx -> a/b/c/d/mruby/mrbgems/mruby-compiler/core/codegen-cxx.o
CXX   a/b/c/d/mruby/mrbgems/mruby-compiler/core/y.tab-cxx.cxx -> a/b/c/d/mruby/mrbgems/mruby-compiler/core/y.tab-cxx.o
CXX   ../a/b/c/d/mruby/src/error-cxx.cxx -> ../a/b/c/d/mruby/src/error-cxx.o
CXX   ../a/b/c/d/mruby/src/gc-cxx.cxx -> ../a/b/c/d/mruby/src/gc-cxx.o
CXX   ../a/b/c/d/mruby/src/vm-cxx.cxx -> ../a/b/c/d/mruby/src/vm-cxx.o
```
2021-02-06 17:27:23 +09:00
Yukihiro "Matz" Matsumoto 88113df098 Fixed compile errors in cmath.c in MinGW and macOS. 2021-02-06 17:00:03 +09:00
Yukihiro "Matz" Matsumoto 2a69f5105c Merge pull request #5324 from dearblue/c++-exc
Exclude `<build-dir>/mrbc/**/*` from rake target rules
2021-02-06 16:58:27 +09:00
Yukihiro "Matz" Matsumoto 0bd01c545f Merge pull request #5323 from shuujii/make-the-argument-of-Kernel-catch-optional-as-Ruby-does
Make the argument of `Kernel#catch` optional as Ruby does
2021-02-06 16:57:36 +09:00
dearblue 5c3b5f4221 Exclude <build-dir>/mrbc/**/* from rake target rules
Prevents the auto-generated mrbc target source code from being compiled under host conditions.

This is because a build error occurred when `conf.enable_cxx_exception` was set.
2021-02-06 16:37:15 +09:00
KOBAYASHI Shuji 1ea4c51245 Make the argument of Kernel#catch optional as Ruby does
Also implement the following changes.

* Add tests
* Use `Object#equal?` to compare tags for Ruby compatibility
* Use `attr_reader`
2021-02-06 13:28:47 +09:00
Yukihiro "Matz" Matsumoto 4bf4650321 Avoid implicit conversion from mrb_float to mrb_complex. 2021-02-06 00:50:13 +09:00
Yukihiro "Matz" Matsumoto 8945afe38e Merge pull request #5322 from shuujii/fix-message-of-ThrowCatchJump-in-mruby-catch-gem
Fix message of `ThrowCatchJump` in `mruby-catch` gem
2021-02-06 00:42:51 +09:00
Yukihiro "Matz" Matsumoto 8ecd38d648 Reimplement complex division. 2021-02-06 00:40:18 +09:00
Yukihiro "Matz" Matsumoto ea0737ecfd Define M_E for some platforms. 2021-02-06 00:39:53 +09:00
Yukihiro "Matz" Matsumoto a6994f51c8 Update mruby-cmath to support MSVC complex.
* Use `_Complex` instead of `complex` (MSYS2 do not support `complex`)
* Use `_Dcomplex` instead of `_Complex` on MSCV
* Avoid operator division and multiplication of complex
2021-02-06 00:08:25 +09:00
KOBAYASHI Shuji 80965fe2d7 Fix message of ThrowCatchJump in mruby-catch gem
### Example

```ruby
begin
  throw 1
rescue Exception => e
  puts e.message
end
```

#### Before this patch:

```console
$ bin/mruby example.rb
uncaught throw :1
```
#### After this patch (same as Ruby):

```console
$ bin/mruby example.rb
uncaught throw 1
```
2021-02-05 23:14:58 +09:00
Yukihiro "Matz" Matsumoto a0050541d1 Add mruby-cmath gem to the core.
This gem uses C99 `_Complex` features. You need a C compiler that
supports `_Complex` to enable this gem. All `gcc`, `clang`, `VC` support
`_Complex` so there should not be a big problem.
2021-02-05 22:27:27 +09:00
Yukihiro "Matz" Matsumoto d898002096 Add a few new API for complex access. 2021-02-05 21:54:49 +09:00
Yukihiro "Matz" Matsumoto c6149370b0 Refactor method overriding.
* Use `class_eval` instead of `instance_eval`.
* Reduce `class_eval` calls
* define `Numeric#i`
* undefine `Complex#i`
2021-02-05 21:54:11 +09:00
Yukihiro "Matz" Matsumoto 7ce03e32b7 Add Complex#to_c method. 2021-02-05 21:42:42 +09:00
Yukihiro "Matz" Matsumoto ee3017496b instance_eval for classes and modules should behave as class_eval. 2021-02-05 21:39:44 +09:00
KOBAYASHI Shuji 5e814ea912 Define MRB_NO_GEMS if disable_libmruby is specified 2021-02-05 18:52:00 +09:00
Yukihiro "Matz" Matsumoto 043fe9d9f5 Merge pull request #5319 from shuujii/check-if-.pi-build-rules-are-defined
Check if `.pi` build rules are defined
2021-02-04 22:19:19 +09:00
KOBAYASHI Shuji 67a28b56ab Check if .pi build rules are defined
`.pi` files are created for `.o` files that `build.products` depends on, but
an error will occur if the build rule is unknown, so add a check.

I don't think this situation would normally arise. However, in
`mattn/mruby-onig-regexp`, when using bundled onigmo, onigmo's `.o` files
are added to dependency of `libmruby.a` in the second and subsequent builds,
and mruby does not know the build rule, so the following error had occured.

```console
rake aborted!
Don't know how to build task '/mruby/build/host/mrbgems/mruby-onig-regexp/onigmo-6.2.0/libonig_objs/ascii.pi' (See the list of available tasks with `rake --tasks`)
```
2021-02-04 21:17:58 +09:00
Yukihiro "Matz" Matsumoto 6f354322a8 Merge pull request #5318 from shuujii/fix-breakage-where-builds-except-host-dont-refer-mrbc-in-host
Fix breakage where builds except `host` don't refer` mrbc` in `host`
2021-02-04 15:24:05 +09:00
KOBAYASHI Shuji f92c1f1b7f Fix breakage where builds except host don't refer mrbc in host
Build error occurred under the following conditions.

* `host` build is presym enabled and unspecified `mruby-bin-mrbc` gem.
* Build except `host` unspecified `mruby-bin-mrbc` gem and mrbcfile.

### Example

#### Build configuration

```ruby
MRuby::Build.new{|conf| conf.toolchain}
MRuby::Build.new("host2"){|conf| conf.toolchain}
```

#### Error

```console
rake aborted!
external mrbc or mruby-bin-mrbc gem in current('host2') or 'host' build is required
/mruby/lib/mruby/build.rb:326:in `mrbcfile'
/mruby/tasks/mrblib.rake:9:in `block in <top (required)>'
/mruby/lib/mruby/build.rb:18:in `instance_eval'
/mruby/lib/mruby/build.rb:18:in `block in each_target'
/mruby/lib/mruby/build.rb:17:in `each'
/mruby/lib/mruby/build.rb:17:in `each_target'
/mruby/tasks/mrblib.rake:1:in `<top (required)>'
/mruby/Rakefile:27:in `load'
/mruby/Rakefile:27:in `<top (required)>'
```
2021-02-04 14:57:37 +09:00
mimaki ea3874ed3c Update version to 3.0.0RC. 2021-02-03 16:45:11 +09:00
Yukihiro "Matz" Matsumoto c43dd75ea9 Avoid Heap Overflow in heredoc_remove_indent; fix #5316 2021-02-03 13:06:13 +09:00
Yukihiro "Matz" Matsumoto 810d13dacd Move MRB_TRY part of mrb_close to src/error.c; ref 6cc52b3
We don't want to increase number of files that should be compiled by C++
compiler when `enable_cxx_exception` is turned on.
2021-02-03 09:43:41 +09:00
Yukihiro "Matz" Matsumoto 6cc52b3210 Ignore errors from atexit finalizers. 2021-02-02 10:57:32 +09:00
Yukihiro "Matz" Matsumoto d759a73525 Allow more than 256 child irep; fix #5310
We have introduced following new instructions.

 * `OP_LAMBDA16`
 * `OP_BLOCK16`
 * `OP_METHOD16`
 * `OP_EXEC16`

Each instruction uses 16 bits operand for `reps` index. Since new
instructions are added, `mruby/c` VM should be updated.

Due to new instructions, dump format compatibility is lost, we have
increased `RITE_BINARY_MAJOR_VER`.

In addition, we have decreased the size of `refcnt` in `mrb_irep` from
`uint32_t` to `uint16_t`, which is reasonably big enough.
2021-02-01 16:20:58 +09:00
Yukihiro "Matz" Matsumoto bd6b48fa3b Copy iv table with #prepend; fix #5309
In addition, stop eager allocation of `mt` table.
2021-02-01 14:33:28 +09:00
Yukihiro "Matz" Matsumoto d0ba7b95a9 Merge pull request #5314 from dearblue/presym_init
Introduced `MRB_PRESYM_INIT_SYMBOLS()`
2021-02-01 11:19:13 +09:00
Yukihiro "Matz" Matsumoto 5cce4ad433 Merge pull request #5315 from shuujii/use-mrb_open_core-instead-of-mrb_open--in-mrbc
Use `mrb_open_core()` instead of `mrb_open()`  in `mrbc`
2021-02-01 10:12:29 +09:00
Yukihiro "Matz" Matsumoto 874f828a7a Merge pull request #5313 from dearblue/diet-5272
Remove unnecessary `ci0` variables; ref #5272
2021-02-01 09:36:11 +09:00
KOBAYASHI Shuji 1fc8e00e4a Use mrb_open_core() instead of mrb_open() in mrbc 2021-01-31 22:37:27 +09:00
Yukihiro "Matz" Matsumoto 406159d412 Merge pull request #5312 from dearblue/diet-5060
Remove unnecessary configuration macros; ref #5060
2021-01-31 19:57:31 +09:00
dearblue a9949f5da4 Introduced MRB_PRESYM_INIT_SYMBOLS()
The `init_SYMBOLS()` function implicitly defined in `MRB_PRESYM_DEFINE_VAR_AND_INITER()` requires some familiarity when trying to find it from the caller.
By introducing `MRB_PRESYM_INIT_SYMBOLS()`, it is possible to find directly from the identifier.
2021-01-31 18:13:28 +09:00
dearblue d824488915 Remove unnecessary ci0 variables; ref #5272 2021-01-31 17:24:16 +09:00
dearblue 5ede25c40f Remove unnecessary configuration macros; ref #5060
The following macros will be removed:
- `ENSURE_STACK_INIT_SIZE`
- `RESCUE_STACK_INIT_SIZE`
- `MRB_ECALL_DEPTH_MAX`
2021-01-31 17:22:27 +09:00
Yukihiro "Matz" Matsumoto cee916ab0f Merge pull request #5311 from shuujii/change-.o.d-back-to-.d-because-.pi.d-is-no-longer-created
Change `.o.d` back to `.d` because `.pi.d` is no longer created
2021-01-31 15:25:58 +09:00
KOBAYASHI Shuji d90abc648e Change .o.d back to .d because .pi.d is no longer created 2021-01-31 15:08:37 +09:00
Yukihiro "Matz" Matsumoto 02e336ee27 Merge pull request #5308 from dearblue/internal-mrbc
Build internal mrbc in an internal directory
2021-01-30 15:43:50 +09:00
Yukihiro "Matz" Matsumoto dd603d494d Merge pull request #5306 from dearblue/unpack
Fixed `String#unpack` to handle the highest range of integer values
2021-01-29 23:51:26 +09:00
dearblue 14e07f721a Build internal mrbc in an internal directory 2021-01-29 23:02:17 +09:00
dearblue b500e82950 Remove unnecessary range confirmation
This is a correction based on the review by @matz.
https://github.com/mruby/mruby/pull/5306#pullrequestreview-578378401
2021-01-29 22:33:03 +09:00
dearblue 9c36499e31 Fixed String#unpack to handle the highest range of integer values
Previously, problems occurred when the `fixnum` was exceeded.

- 32-bit cpu mode with `MRB_WORD_BOXING` and `MRB_INT32`:

  ```console
  % bin/mruby -e 'p [0x7fffffff].pack("N").unpack("N")'
  trace (most recent call last):
  -e:1: cannot unpack to Integer: 2147483647 (RangeError)
  ```

- 64-bit cpu mode with `MRB_WORD_BOXING` and `MRB_INT64`:

  ```console
  % bin/mruby -e 'p [0x7fffffff_ffffffff].pack("q").unpack("q")'
  trace (most recent call last):
  -e:1: cannot unpack to Integer: 9223372036854775807 (RangeError)
  ```
2021-01-29 22:27:36 +09:00
Yukihiro "Matz" Matsumoto 825241205f Replace mrb_intern_cstr to mrb_intern_lit. 2021-01-29 18:32:26 +09:00
Yukihiro "Matz" Matsumoto 4a7309d327 Merge pull request #5307 from dearblue/stackerr
Raise SystemStackError if mruby VM stack expansion fails
2021-01-28 23:01:40 +09:00
Yukihiro "Matz" Matsumoto 0030417ace Merge pull request #5305 from dearblue/symbol0
Check first `0` when converting symbols into strings
2021-01-28 22:56:27 +09:00
dearblue 0dbb9e6e41 Raise SystemStackError if mruby VM stack expansion fails 2021-01-28 22:04:47 +09:00
dearblue 3d8a8fb661 Check first 0 when converting symbols into strings
This was because it caused `SIGSEGV` when `mruby -v` displayed an unnamed variable.

```console
% bin/mruby -ve 'call { |(a, b)| }'

  ...SNIP...

irep 0x8007d0050 nregs=3 nlocals=1 pools=0 syms=1 reps=1 iseq=12
file: -e
    1 000 OP_LOADSELF   R1
    1 002 OP_BLOCK      R2      I(0:0x8007d00a0)
    1 005 OP_SENDB      R1      :call   0
    1 009 OP_RETURN     R1
    1 011 OP_STOP

irep 0x8007d00a0 nregs=6 nlocals=5 pools=0 syms=0 reps=0 iseq=29
local variable names:
zsh: segmentation fault (core dumped)  bin/mruby -ve 'call { |(a, b)| }'
```
2021-01-28 21:15:31 +09:00
Yukihiro "Matz" Matsumoto bb42c1b286 Merge pull request #5304 from shuujii/refine-preprocess_options
Refine `preprocess_options`; ref d95ffb036
2021-01-28 19:57:16 +09:00
Yukihiro "Matz" Matsumoto d42d308620 Remove duplicated --cflags; [ci skip] 2021-01-28 19:55:05 +09:00
KOBAYASHI Shuji c858cba3e9 Refine preprocess_options; ref d95ffb036
If we modify an option that may have been specified by users, we may
make unintended changes, so it is better not to modify it as much as
possible, IMO.
2021-01-28 18:42:19 +09:00
Yukihiro "Matz" Matsumoto 1c05764ba3 Update limitation.md for integer division change in 3.0. 2021-01-28 17:08:30 +09:00
Yukihiro "Matz" Matsumoto 56842628b9 Stop mentioning MRB_NO_PRESYM in the doc.
It's for internal use. Please use `conf.disable_presym`.
2021-01-28 16:47:02 +09:00
Yukihiro "Matz" Matsumoto 07d4498613 Silence VC warning. 2021-01-28 16:35:22 +09:00
Yukihiro "Matz" Matsumoto d95ffb0362 Stop generating build/<build>/src/*.pi.d. 2021-01-28 15:58:35 +09:00
Yukihiro "Matz" Matsumoto 1e009061f8 Describe disabling preallocated symbols in the doc. 2021-01-28 15:47:51 +09:00
Yukihiro "Matz" Matsumoto 4063af90e2 Update TODO after mruby3.0. 2021-01-28 15:06:22 +09:00
Yukihiro "Matz" Matsumoto 2e33c2d120 Remove unnecessary bit shift in rational_new_f. 2021-01-28 08:47:16 +09:00
Yukihiro "Matz" Matsumoto f5e10e294c Add symbol names as comments to presym_length_table; ref #5303 2021-01-27 23:47:32 +09:00
Yukihiro "Matz" Matsumoto 69f9460075 Add static modifiers to preallocated symbols tables; ref #5303 2021-01-27 23:44:04 +09:00
Yukihiro "Matz" Matsumoto f0eb50a55d Merge pull request #5303 from shuujii/split-presym_table-for-reduced-program-size
Split `presym_table` for reduced program size
2021-01-27 23:41:03 +09:00
KOBAYASHI Shuji 3104aed8c6 Split presym_table for reduced program size
Because a structure that is an element of `presym_table` has padding, split
it into individual arrays for name and length.

#### Result (64-bit CPU with full-core gembox)

|        |   mruby    | libmruby.a |
|--------|------------|------------|
| Before | 1,087,444B | 1,476,872B |
| After  | 1,079,340B | 1,469,784B |
2021-01-27 20:47:10 +09:00
Yukihiro "Matz" Matsumoto 251fd74315 Merge pull request #5302 from shuujii/rename-.i-created-for-presym-scan-to-.pi
Rename `.i` created for presym scan to `.pi`
2021-01-27 18:08:58 +09:00
KOBAYASHI Shuji d6a9ffa2b5 Rename .i created for presym scan to .pi
This is because compiler's `-save-temps=obj` option creates `.i` with the
same name.
2021-01-27 16:09:12 +09:00
Yukihiro "Matz" Matsumoto bf56ecd2bf Merge pull request #5301 from shuujii/fix-typos-in-mruby-presym-disableenable.h
Fix typos in `mruby/presym/{disable,enable}.h` [ci skip]
2021-01-27 12:32:42 +09:00
KOBAYASHI Shuji 826e0b108f Fix typos in mruby/presym/{disable,enable}.h [ci skip] 2021-01-27 12:18:41 +09:00
Yukihiro "Matz" Matsumoto 5e479c66d5 Merge pull request #5300 from shuujii/avoid-possible-loss-of-data-casting-in-binary-search
Avoid 'possible loss of data' casting in binary search
2021-01-27 12:15:58 +09:00
Yukihiro "Matz" Matsumoto 89cd742506 Merge pull request #5299 from shuujii/fix-Use-MRB_SYM-for-error-class-retrieval
Fix "Use `MRB_SYM()` for error class retrieval"; ref 2ddfd50df
2021-01-27 12:02:34 +09:00
KOBAYASHI Shuji 504788bf89 Avoid 'possible loss of data' casting in binary search
Because it may not be expected result.
example: https://wandbox.org/permlink/F5Mp7IEJ1VY3CFLp
2021-01-27 11:42:18 +09:00
KOBAYASHI Shuji dd07067067 Fix "Use MRB_SYM() for error class retrieval"; ref 2ddfd50df
The new macro (`MRB_E_SYM`) was not being used, so it is being used. Also
`MRB_E_SYM` is confusing with `MRB_SYM_E`, so change it to `MRB_ERROR_SYM`.
2021-01-27 11:23:08 +09:00
Yukihiro "Matz" Matsumoto efa0314731 Adjust spaces after list markers. 2021-01-26 21:21:26 +09:00
Yukihiro "Matz" Matsumoto d4101d0a08 Revert "Fix the wrong directory host-bin to host/bin."
This reverts commit 34f82f24e9.
Ref #5282
2021-01-26 21:17:28 +09:00
Yukihiro "Matz" Matsumoto f3d5deb981 Clarify that contributors agree with MIT license in CONTRIBUTING.md. 2021-01-26 18:21:49 +09:00
Yukihiro "Matz" Matsumoto 04d5e7da39 Update doc/mruby3.md. 2021-01-26 17:16:22 +09:00
Yukihiro "Matz" Matsumoto 73418a90fa Add doc/symbols.md. [ci skip]
To describe how to use symbols, especially preallocated symbols from C.
2021-01-26 12:42:36 +09:00
Yukihiro "Matz" Matsumoto 63b7439ddf Change mruby-config to print usage on invalid arguments.
Or no argument at all.
2021-01-26 11:37:01 +09:00
Yukihiro "Matz" Matsumoto 34f82f24e9 Fix the wrong directory host-bin to host/bin.
Where `mruby-config` command should be generated.
2021-01-26 11:35:59 +09:00
Yukihiro "Matz" Matsumoto 2ddfd50df3 Use MRB_SYM() for error class retrieval; ref #5277
Note that `MRB_SYM()` is only available when `mruby/presym.h` is
included. Use `mrb_intern_lit()` otherwise.
2021-01-26 11:13:06 +09:00
Yukihiro "Matz" Matsumoto 17ecf14511 Revert "Minimize the changes in #5277"
This reverts commit dc51d89ac2.
2021-01-26 10:57:07 +09:00
Yukihiro "Matz" Matsumoto 165f79c877 Silence 'loss of data' warnings in symbol.c. 2021-01-25 23:27:32 +09:00
Yukihiro "Matz" Matsumoto c68258f454 Merge pull request #5297 from hasumikin/fix-typo-in-rite-binary-header
Fix TYPO and checking minor version in RITE BINARY HEADER
2021-01-25 22:50:29 +09:00
HASUMI Hitoshi d5ed73379f fix comparison of minor version 2021-01-25 22:29:11 +09:00
HASUMI Hitoshi da65d35d7a fix TYPO in RITE BINARY HEADER 2021-01-25 22:11:54 +09:00
Yukihiro "Matz" Matsumoto 0903e2a72e Silence 'loss of data' warnings. 2021-01-25 15:45:32 +09:00
Yukihiro "Matz" Matsumoto efef4541aa Fix a bug for the case frexp() return Infinity. 2021-01-25 15:44:59 +09:00
Yukihiro "Matz" Matsumoto 23e5c08e31 Should use a limit for 32 bit platform; ref 05a8cc44 2021-01-25 15:44:59 +09:00
Yukihiro "Matz" Matsumoto 73ce5db170 Add description for mruby-config in compile.md. [ci skip]
For easier compiling and linking of the application embedding `mruby`
2021-01-25 10:45:57 +09:00
Yukihiro "Matz" Matsumoto 05a8cc44cc Define RAT_INT_LIMIT for 32 bit platforms. 2021-01-24 22:21:56 +09:00
Yukihiro "Matz" Matsumoto f20e10686c Prohibit r suffix after scientific notation (e.g. 1e10).
As CRuby does.
2021-01-24 21:43:20 +09:00
Yukihiro "Matz" Matsumoto cc59860e40 Detect integer overflow in rational_new_f(). 2021-01-24 21:42:34 +09:00
Yukihiro "Matz" Matsumoto 48b214f0b5 Remove test debug lines in fallback presym.inc
ref dc51d89ac2
2021-01-23 18:12:04 +09:00
Yukihiro "Matz" Matsumoto baa1ee1faa Fixed typo; ref #5296 2021-01-23 10:24:53 +09:00
Yukihiro "Matz" Matsumoto 8b590b5ec7 Merge pull request #5296 from yevgenko/patch-1
Fix typo
2021-01-23 10:20:21 +09:00
Yevhen Viktorov 2cab36c289 Fix typo 2021-01-23 00:25:23 +00:00
Yukihiro "Matz" Matsumoto dc51d89ac2 Minimize the changes in #5277
Instead of including `mruby/presym.h` everywhere, we provided the
fallback `mruby/presym.inc` under `include/mruby` directory, and specify
`-I<build-dir>/include` before `-I<top-dir>/include` in `presym.rake`.
So even when someone drops `-I<build-dir>/include` in compiler options,
it just compiles without failure.
2021-01-22 18:38:53 +09:00
Yukihiro "Matz" Matsumoto c5c156a6dd Reduce size of mrb_callinfo by rearranging members.
From 48 bytes to 40 bytes on 64 bit platforms (unchanged on 32 bit).
2021-01-21 21:11:32 +09:00
Yukihiro "Matz" Matsumoto 33deeae9eb Merge branch 'shuujii-avoid-including-presym.inc-in-existing-header-files' 2021-01-21 14:55:44 +09:00
Yukihiro "Matz" Matsumoto 6c5ccd5abe Merge branch 'avoid-including-presym.inc-in-existing-header-files' of https://github.com/shuujii/mruby into shuujii-avoid-including-presym.inc-in-existing-header-files 2021-01-21 14:53:18 +09:00
Yukihiro "Matz" Matsumoto 438d114917 Fix a bug that :_1 to cause syntax error; fix #5295 2021-01-21 14:45:06 +09:00
Yukihiro "Matz" Matsumoto 56fdc449eb Better error messages with yacc tokens. 2021-01-21 14:42:39 +09:00
Yukihiro "Matz" Matsumoto 5e0f51c906 Silence gcc warning from strncpy(). 2021-01-21 12:22:54 +09:00
Yukihiro "Matz" Matsumoto 47a68e89ff Remove CRC16 from dumped mruby binary.
`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-20 23:12:43 +09:00
Yukihiro "Matz" Matsumoto e91dfd07be Compile mruby-bin-debugger with ci/gcc-clang.rb. 2021-01-19 12:05:16 +09:00
Yukihiro "Matz" Matsumoto 0661ebb669 Merge pull request #5294 from shuujii/fix-that-Hash-may-not-contain-any-empty-buckets
Fix that Hash may not contain any empty buckets
2021-01-18 23:19:47 +09:00
KOBAYASHI Shuji dd81de49a6 Fix that Hash may not contain any empty buckets
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-18 21:32:10 +09:00
Yukihiro "Matz" Matsumoto e4fc42ea11 Merge pull request #5293 from dearblue/fix-5272.2
Fix build error for mruby-bin-debugger
2021-01-18 00:23:13 +09:00
dearblue 04a4e59c83 Fix build error for mruby-bin-debugger
This is a missing change in #5272.

This issue was reported by @shuujii.
https://github.com/mruby/mruby/pull/5272#issuecomment-761819737
2021-01-18 00:00:53 +09:00
Yukihiro "Matz" Matsumoto f4a3dc4f07 Add tests for Integer#quo and Float#quo; #5268 2021-01-17 23:02:36 +09:00
Yukihiro "Matz" Matsumoto 12ff88563d Fix int_quo to do float division; fix #5268 2021-01-17 23:02:36 +09:00
Yukihiro "Matz" Matsumoto c7452ff61f Define Rational#quo; fix #5268 2021-01-17 23:02:35 +09:00
Yukihiro "Matz" Matsumoto b4817a54f0 Make mrb_to_flo() to convert objects, not integer, not float; #5268
Thinking `Ratinal` and `Complex` in mind.
2021-01-17 23:02:35 +09:00
Yukihiro "Matz" Matsumoto 126f0f0563 Merge pull request #5292 from dearblue/objspace-memsize
Fix NULL pointer dereference with mruby-os-memsize and mruby-method
2021-01-16 17:55:43 +09:00
dearblue 0fdf5d9bb9 Fix NULL pointer dereference with mruby-os-memsize and mruby-method
If it gets an insubstantial method object with `obj.method`, it will raise a `SIGSEGV` with `ObjectSpace.memsize_of(method)`.
2021-01-16 15:52:52 +09:00
Yukihiro "Matz" Matsumoto 0aa8db9a06 Merge pull request #5291 from dearblue/fix-5272
Fixed stack position of return value; ref #5272
2021-01-16 13:56:26 +09:00
dearblue 414a61a9d2 Fixed stack position of return value; ref #5272
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-16 11:05:15 +09:00
Yukihiro "Matz" Matsumoto 4bba769b95 Avoid syntax error regarding colons in the expression; fix #5290
Reported and inspired by @hasumikin; based on CRuby's `parse.y`.
2021-01-15 22:49:40 +09:00
Yukihiro "Matz" Matsumoto 28d5dabacd Merge pull request #5273 from dearblue/fiber
Capture the return value of `Fiber.yield` via C; ref #5261
2021-01-14 23:47:25 +09:00
Yukihiro "Matz" Matsumoto a639a39883 Rational denominator should not be zero. 2021-01-13 09:17:20 +09:00
dearblue 0229446a30 Capture the return value of Fiber.yield via C; ref #5261 2021-01-12 23:04:36 +09:00
Yukihiro "Matz" Matsumoto c7d96dbf84 Merge pull request #5289 from dearblue/sockaddr_un
Initialize all area of `struct sockaddr_un`
2021-01-12 22:22:44 +09:00
Yukihiro "Matz" Matsumoto 9d950818ce Merge branch 'dearblue-reorganize-ci' 2021-01-12 22:14:53 +09:00
dearblue 8928bc2dce Initialize all area of struct sockaddr_un
Members of `struct sockaddr_un` are requesting the definitions of `sun_family` and `sun_path`.
https://pubs.opengroup.org/onlinepubs/009696699/basedefs/sys/un.h.html

But the other members are optional and environment dependent.

In fact, other members are defined in the BSD series.
from NetBSD-9.1 <https://github.com/NetBSD/src/blob/da504f75982b244b2288bc9970bbc203bd77a9c1/sys/sys/un.h#L49-L53>

```c
struct  sockaddr_un {
        unsigned char   sun_len;        /* sockaddr len excluding NUL */
        sa_family_t     sun_family;     /* AF_UNIX */
        char    sun_path[104];          /* path name (gag) */
};
```
2021-01-12 21:35:18 +09:00
Yukihiro "Matz" Matsumoto bec4d30dc6 Merge branch 'reorganize-ci' of https://github.com/dearblue/mruby into dearblue-reorganize-ci 2021-01-12 18:38:42 +09:00
Yukihiro "Matz" Matsumoto e13f34e308 Merge pull request #5288 from shuujii/fix-that-sometimes-parallel-build-of-test-code-fails
Fix that sometimes parallel build of test code fails; fix #5284
2021-01-12 16:29:02 +09:00
Yukihiro "Matz" Matsumoto b64ec814d6 Fix a signed shift bug on 32 bit platforms; ref e1c9e7e 2021-01-12 16:26:05 +09:00
Yukihiro "Matz" Matsumoto 1310368b3f Silence Windows warnings (cast and setmode). 2021-01-12 16:25:30 +09:00
KOBAYASHI Shuji 02121cbd65 Fix that sometimes parallel build of test code fails; fix #5284
The cause is that `mrbgem.rake` of` mruby-test` gem is loaded when test
code is requested to be built, but when `mrbgem.rake` is loaded,
`MRuby::Gem.current` is updated, which is not thread safe.

Address this by not loading `mrbgem.rake` in parallel.
2021-01-12 15:41:22 +09:00
Yukihiro "Matz" Matsumoto a8b8d316ab Save NOARG information in struct mt_elem; fix #5257 2021-01-12 14:51:34 +09:00
Yukihiro "Matz" Matsumoto e1c9e7efab Changed packing format of inline symbols.
To make inline symbols packed in 30 bits.
2021-01-12 14:51:33 +09:00
Yukihiro "Matz" Matsumoto 974e245ae0 Merge pull request #5285 from dearblue/io-unimps
Remove functions for unimplemented methods
2021-01-11 23:49:54 +09:00
Yukihiro "Matz" Matsumoto cdbcade041 Merge pull request #5286 from dearblue/io-popen
Integrate the argument parsing part of `IO.popen`
2021-01-11 23:48:41 +09:00
dearblue 0c96c4c34a Integrate the argument parsing part of IO.popen 2021-01-11 23:07:25 +09:00
dearblue 01897f8456 Remove functions for unimplemented methods
- Use `mrb_notimplement_m()` instead.
- Hide the unused `option_to_fd()` when `TARGET_OS_IPHONE` is enabled.
2021-01-11 23:01:53 +09:00
Yukihiro "Matz" Matsumoto d531636584 Merge pull request #5283 from shuujii/add-missing-cast-in-ea_next_capa_for
Add missing cast in `ea_next_capa_for`
2021-01-11 21:17:44 +09:00
Yukihiro "Matz" Matsumoto f8b938435c Merge pull request #5282 from dearblue/mruby-config-cross
Create a `mruby-config` that can be run on the host by cross-building
2021-01-11 20:34:38 +09:00
KOBAYASHI Shuji 87ba84b048 Add missing cast in ea_next_capa_for 2021-01-11 20:19:55 +09:00
dearblue 66df8c619a Create a mruby-config that can be run on the host by cross-building
The output directory will be `host-bin`, so it will be output as `<build-dir>/host-bin/mruby-config`.

It's still not available for target devices.
2021-01-11 17:07:05 +09:00
Yukihiro "Matz" Matsumoto 672e016b13 Merge pull request #5281 from shuujii/remove-the-definition-of-mrb_uint-in-numeric.h-that-is-no-longer-needed
Remove the definition of `mrb_uint` in `numeric.h` that is no longer needed
2021-01-11 16:35:42 +09:00
Yukihiro "Matz" Matsumoto 9577e6ca6a Merge pull request #5280 from shuujii/remove-unneeded-check-to-mrbtest-in-tasks-presym.rake
Remove unneeded check to `mrbtest` in `tasks/presym.rake`
2021-01-11 16:34:05 +09:00
KOBAYASHI Shuji 48feda0692 Remove the definition of mrb_uint in numeric.h that is no longer needed 2021-01-11 16:20:27 +09:00
KOBAYASHI Shuji 123d15c5ab Remove unneeded check to mrbtest in tasks/presym.rake
With the change in #5267, `build.products` no longer contains `mrbtest` when
`tasks/presym.rake` is loaded.
2021-01-11 16:15:12 +09:00
Yukihiro "Matz" Matsumoto 0290f06681 Merge pull request #5279 from shuujii/remove-unneeded-mruby-test-gem-in-build_config-no-float.rb
Remove unneeded `mruby-test` gem in `build_config/no-float.rb` [ci skip]
2021-01-11 12:53:17 +09:00
KOBAYASHI Shuji 2ddd66cc4b Remove unneeded mruby-test gem in build_config/no-float.rb [ci skip]
Use `enable_test` to enable the test.
2021-01-11 12:07:08 +09:00
Yukihiro "Matz" Matsumoto ffea200075 Merge pull request #5278 from dearblue/annotation
Fix annotations [ci skip]
2021-01-11 11:57:09 +09:00
dearblue a0662a16a3 Fix annotations [ci skip] 2021-01-11 11:33:39 +09:00
KOBAYASHI Shuji 90b53f4c29 Avoid including presym.inc in existing header files
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-11 09:21:07 +09:00
Yukihiro "Matz" Matsumoto 3deb3a7aac Fix CI failure on Windows environment.
`1L` on Windows means `32 bit int`.
2021-01-10 22:52:41 +09:00
Yukihiro "Matz" Matsumoto e66c6edaba Fix mixture of inline int declaration in for statement. 2021-01-10 22:52:40 +09:00
Yukihiro "Matz" Matsumoto 80a7655b10 Merge pull request #5271 from shuujii/fix-build-error-in-cross-build-with-presym
Fix build error in cross-build with presym
2021-01-10 22:15:52 +09:00
Yukihiro "Matz" Matsumoto dc5ade3729 Merge pull request #5275 from dearblue/read_irep
Replace `tempirep` with `RProc`
2021-01-10 22:13:51 +09:00
Yukihiro "Matz" Matsumoto 596b542720 Merge pull request #5274 from shuujii/fix-the-condition-to-remove-mrbtest-when-rake-clean
Fix the condition to remove `mrbtest` when `rake clean`
2021-01-10 22:07:22 +09:00
dearblue 3fc848b545 Replace tempirep with RProc
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: f1523d2404

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-10 21:41:51 +09:00
Yukihiro "Matz" Matsumoto e8e28eacc7 Revert "Revert "Simplify full-core.gembox""
This reverts commit 37d795dec7.
This reapplies e20d652 (#4202), which is reverted, but its issue was solved
by 1d8456f.
2021-01-10 20:29:49 +09:00
KOBAYASHI Shuji fe28e8617e Fix the condition to remove mrbtest when rake clean 2021-01-10 16:28:14 +09:00
dearblue 9877f4ca3c Revert "Save&restore execution point (pc) in c->cibase->pc; fix #5261"
This reverts commit a0c1e075e3.

This is because the `mrb_callinfo::pc` has been reorganized, resulting in over-correction.
2021-01-10 13:33:17 +09:00
dearblue ced89c25ff Unified pc and err of mrb_callinfo
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-10 13:23:43 +09:00
dearblue 16baea0677 Changes stackent to stack of mrb_callinfo
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-10 13:23:35 +09:00
dearblue 58e9442737 Unified target_class and env of mrb_callinfo
If there is `env`, `env->c` means `target_class`.
2021-01-10 13:23:28 +09:00
dearblue b210cfa34e Use uint16_t for argc and acc of mrb_callinfo
This is because it is enough to express the range up to (-1..255) or (-3..255).
2021-01-10 13:22:28 +09:00
KOBAYASHI Shuji f80d5ece27 Fix build error in cross-build with presym
Fix the following issues.

* https://github.com/mruby/mruby/pull/5220#issuecomment-757204258
* https://github.com/mruby/mruby/pull/5220#issuecomment-757205572
2021-01-10 10:21:45 +09:00
Yukihiro "Matz" Matsumoto 6f6eabf05a Fix wrong float to rational conversion in 32 bit mode. 2021-01-09 23:39:36 +09:00
Yukihiro "Matz" Matsumoto f81591ceb6 Detect invalid first byte of UTF-8 char; fix #5269
The first byte of UTF-8 character should not be `80..c1`.
2021-01-09 19:09:57 +09:00
Yukihiro "Matz" Matsumoto 62e5247300 Convert float number to rational by decoding mantissa. 2021-01-09 19:09:57 +09:00
Yukihiro "Matz" Matsumoto 92cc6b4996 Introduce mrb_uint which is unsigned integer with size of mrb_int. 2021-01-09 19:09:56 +09:00
Yukihiro "Matz" Matsumoto 12cc959998 Remove khash.h leftovers. 2021-01-09 19:09:56 +09:00
Yukihiro "Matz" Matsumoto fb4767a3b7 Merge pull request #5270 from shuujii/remove-unnecessary--include-in-generated-files
Remove unnecessary `#include` in generated files
2021-01-09 16:34:11 +09:00
KOBAYASHI Shuji 892bf15cd7 Remove unnecessary #include in generated files 2021-01-09 14:50:23 +09:00
Yukihiro "Matz" Matsumoto 69482dbc8e Merge pull request #5265 from shuujii/reapply-116e128b-because-it-is-back-at-456878ba
Reapply 116e128b because it is back at 456878ba
2021-01-08 23:10:49 +09:00
Yukihiro "Matz" Matsumoto 6587269af8 Merge pull request #5267 from shuujii/delay-test-code-build-until-rake-test
Delay test code build until `rake test`
2021-01-08 21:14:19 +09:00
Yukihiro "Matz" Matsumoto a0c1e075e3 Save&restore execution point (pc) in c->cibase->pc; fix #5261
`mrb_fiber_resume()` can be called from C; ref #3056
2021-01-08 21:03:41 +09:00
KOBAYASHI Shuji 3a8d7bdf82 Delay test code build until rake test
With this change, the test code will not be built unless `rake test` is
run, so there will be almost no side effects even if `enable_test` is
always set (but, gems specified by `add_test_dependency` are included
in `libmruby.a`).

Also added are `test: build` task, which only builds the test code
(including the main code), and `test: run` task, which only runs tests
independent of build. Therefore, the idiom for building in parallel and
not running tests in parallel is `rake -m test:build && rake test:run`.
2021-01-08 20:36:54 +09:00
Yukihiro "Matz" Matsumoto 04561cd999 Merge pull request #5266 from shuujii/stop-immediate-flush-to-stdout-stderr-when-running-in-parallel-on-CI
Stop immediate flush to stdout/stderr when running in parallel on CI
2021-01-08 16:37:50 +09:00
KOBAYASHI Shuji dbe387a9d8 Stop immediate flush to stdout/stderr when running in parallel on CI
During parallel execution (build), it is sometimes flushed before line
breaks, and lines are concatenated.
2021-01-08 15:59:08 +09:00
KOBAYASHI Shuji f7ff4810f0 Reapply 116e128b because it is back at 456878ba 2021-01-08 15:23:50 +09:00
Yukihiro "Matz" Matsumoto 1cc1ade610 Merge pull request #5263 from shuujii/use-namespaces-according-to-Rake-conventions
Use namespaces according to Rake conventions
2021-01-07 20:22:35 +09:00
Yukihiro "Matz" Matsumoto 76241a9630 Merge pull request #5264 from shuujii/immediately-flush-output-to-stdout-stderr-so-that-logs-are-not-mixed-on-CI
Immediately flush output to stdout/stderr so that logs are not mixed on CI
2021-01-07 20:21:13 +09:00
KOBAYASHI Shuji 35c85cb21f Immediately flush output to stdout/stderr so that logs are not mixed on CI
Set in build configuration to enable on all CI platforms.
2021-01-07 19:46:03 +09:00
KOBAYASHI Shuji 0dfcaaed63 Use namespaces according to Rake conventions
Change the Rake task to one that uses namespaces as follows (previous task
names can also be used for compatibility).

| Previous Task  |    New Task    |
|----------------|----------------|
| api_doc        | doc:api        |
| capi_doc       | doc:capi       |
| clean_doc      | doc:clean      |
| clean_api_doc  | doc:clean:api  |
| clean_capi_doc | doc:clean:capi |
| view_api       | doc:view:api   |
| view_capi      | doc:view:capi  |
| gitlab_config  | gitlab:config  |
| gitlab_dockers | gitlab:dockers |
2021-01-07 17:31:05 +09:00
Yukihiro "Matz" Matsumoto a435cc94ec Merge pull request #5262 from shuujii/add-scan-target-functions-for-presym
Add scan target functions for presym
2021-01-07 17:12:06 +09:00
KOBAYASHI Shuji d35cd42dc8 Add scan target functions for presym
Add the following functions:

- mrb_intern_cstr
- mrb_define_singleton_method
- mrb_define_class_under
- mrb_define_module_under
2021-01-07 16:38:46 +09:00
Yukihiro "Matz" Matsumoto ec6f46c05d Use nint() for implicit cast; ref #5260 2021-01-07 11:49:50 +09:00
Yukihiro "Matz" Matsumoto 7e116b5e8b Merge pull request #5260 from SeekingMeaning/squiggly-fix-5
Fix line continuations with mixed indentation in squiggly heredocs
2021-01-07 11:45:24 +09:00
Yukihiro "Matz" Matsumoto 5e752caf67 Merge pull request #5259 from shuujii/consider-the-case-a-local-variable-name-does-not-become-a-named-presym
Consider the case a local variable name does not become a named presym
2021-01-07 10:22:10 +09:00
Seeker d52c82d648 Add heredoc_push_indented helper function 2021-01-06 16:46:44 -08:00
Seeker e279528ff3 Fix line continuations with mixed indentation in squiggly heredocs 2021-01-06 16:35:46 -08:00
KOBAYASHI Shuji b8486d73e2 Consider the case a local variable name does not become a named presym
Non-ASCII characters are allowed to local variable names, so they are not
always named presym.
2021-01-06 23:29:45 +09:00
Yukihiro "Matz" Matsumoto 676054c8df Merge pull request #5258 from shuujii/fix-build-with-enable_cxx_exception
Fix build with `enable_cxx_exception`
2021-01-06 19:50:03 +09:00
KOBAYASHI Shuji 90283432a4 Fix build with enable_cxx_exception 2021-01-06 19:03:10 +09:00
Yukihiro "Matz" Matsumoto 01aa2a990f Specify receivers for gembox methods; ref #5241 2021-01-06 18:10:21 +09:00
Yukihiro "Matz" Matsumoto aecb3a33e6 Merge pull request #5241 from dearblue/gembox
Take advantage of gembox
2021-01-06 18:06:18 +09:00
Yukihiro "Matz" Matsumoto 0d76b90758 Use ~0U instead of ~0 to avoid sign comparison warnings. 2021-01-06 17:15:21 +09:00
Yukihiro "Matz" Matsumoto 8e048ae25d Merge branch 'shuujii-improve-source-scanning-for-presym' 2021-01-06 17:14:12 +09:00
Yukihiro "Matz" Matsumoto 74c9502bd4 Merge branch 'improve-source-scanning-for-presym' of https://github.com/shuujii/mruby into shuujii-improve-source-scanning-for-presym 2021-01-06 17:06:07 +09:00
Yukihiro "Matz" Matsumoto 1341e53961 Avoid comparing -1 with size_t (unsigned); Use ~0 instead. 2021-01-06 14:23:12 +09:00
Yukihiro "Matz" Matsumoto ca3a6156bf Allow context switch from C using mrb_fiber_resume().
But you still cannot cross C function boundary.
2021-01-06 14:16:56 +09:00
Yukihiro "Matz" Matsumoto 4585c360e4 Remove duplicated remove_sign_bits() call. 2021-01-05 21:09:46 +09:00
Yukihiro "Matz" Matsumoto bb5c451dd4 Fix mirb not to be terminated by codegen error. 2021-01-04 07:42:21 +09:00
Yukihiro "Matz" Matsumoto 7c9d9b1c89 Merge pull request #5255 from shuujii/avoid-64-bit-operations-in-src-hash.c
Avoid 64-bit operations in `src/hash.c`; close #5201
2021-01-03 20:28:00 +09:00
Yukihiro "Matz" Matsumoto 0d22e11b75 Merge pull request #5254 from SeekingMeaning/squiggly-fix-4
Fix for escaped newlines in squiggly heredocs
2021-01-03 20:25:34 +09:00
Yukihiro "Matz" Matsumoto 5798c03de6 Merge pull request #5256 from katsuyoshi/master
replace ; to : of OPT_SETGV in codedump.c
2021-01-03 20:25:02 +09:00
Katsuyoshi Ito f23918f61a replace ; to : of OPT_SETGV in codedump.c
Maybe it's a typo.
2021-01-03 19:47:30 +09:00
KOBAYASHI Shuji eb9d9e3425 Avoid 64-bit operations in src/hash.c; close #5201
The idea of using `size_t` in `ea_next_capa_for` is by @dearblue.
2021-01-03 18:42:22 +09:00
Seeker 8286e6052a Fix for escaped newlines in squiggly heredocs 2021-01-03 00:48:10 -08:00
Yukihiro "Matz" Matsumoto c52efe7be8 Avoid double inclusion on <mruby.h>. 2021-01-02 23:50:18 +09:00
Yukihiro "Matz" Matsumoto 17cb50f8d0 Avoid int64_t on 32 bit platforms. 2021-01-02 23:49:41 +09:00
Yukihiro "Matz" Matsumoto 757902c497 Check NaN and Infinity before converting Float to Rational. 2021-01-02 23:36:41 +09:00
Yukihiro "Matz" Matsumoto 392aff7099 Use Jenkins One At A Time Hash for mrb_str_hash(). 2021-01-02 20:28:29 +09:00
Yukihiro "Matz" Matsumoto d55367582c Allow negative integer value formatting in base 8 and 16. 2021-01-02 20:28:29 +09:00
Yukihiro "Matz" Matsumoto b151a697e0 Fixed wrong casting in OP_LOADI32.
Negative integer `>-65535` had wrong value, e,g, `p(-40550)` printed
`4294926746` since Nov. 2020, sigh.
2021-01-02 20:28:28 +09:00
Yukihiro "Matz" Matsumoto c1f05a7fb3 Avoid uint64_t in string-to-integer conversion; ref #5201 2021-01-02 20:28:27 +09:00
Yukihiro "Matz" Matsumoto 4ac73307fd Reduce strength of the hash function; ref #5201
Also avoid using `uint64_t`.
2021-01-02 20:28:27 +09:00
Yukihiro "Matz" Matsumoto 6323c995f3 Use type casting macros; ref #5246 #5247 2021-01-02 20:28:26 +09:00
Yukihiro "Matz" Matsumoto 15e7b3e8fe Merge pull request #5251 from SeekingMeaning/squiggly-fix-3
Fix regression for squiggly heredocs
2021-01-02 20:28:13 +09:00
Yukihiro "Matz" Matsumoto 12cb7207ec Merge pull request #5253 from shuujii/refine-wrong-number-of-arguments-message-in-mrb_get_args
Refine "wrong number of arguments" message in `mrb_get_args`
2021-01-02 19:45:09 +09:00
KOBAYASHI Shuji 1a9ac02d8d Refine "wrong number of arguments" message in mrb_get_args
#### 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)
```
2021-01-02 19:15:34 +09:00
Seeker 1099050377 Treat tabs as 8 spaces in squiggly heredocs 2020-12-31 19:09:38 -08:00
Seeker 4683a196d9 Fix regression for squiggly heredocs 2020-12-31 19:08:44 -08:00
Yukihiro "Matz" Matsumoto 1fbabe207d Merge pull request #5245 from jbampton/for-mruby-for-2021
Update copyright year for 2021
2021-01-01 00:24:53 +09:00
Yukihiro "Matz" Matsumoto db2a7a1e6e Merge pull request #5252 from dearblue/rm-gc_test
Removed unusable `GC.test`
2021-01-01 00:24:12 +09:00
dearblue ae72feb468 Removed unusable GC.test
The substance of the method was removed in commit 15ceb35e05.
2020-12-31 22:22:45 +09:00
Yukihiro "Matz" Matsumoto aabfe31d98 Merge pull request #5250 from shuujii/refine-error-message-from-mrb_get_arg1
Refine error message from `mrb_get_arg1`
2020-12-29 22:44:43 +09:00
KOBAYASHI Shuji 1fae7c0a69 Refine error message from mrb_get_arg1
#### 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-29 19:04:19 +09:00
Yukihiro "Matz" Matsumoto d44a1de8f4 Merge pull request #5249 from SeekingMeaning/squiggly-fix-2
Fix mixed indentation and escaped tabs in squiggly heredocs
2020-12-29 13:51:41 +09:00
Seeker 49b01f23a4 Fix mixed indentation and escaped tabs in squiggly heredocs 2020-12-28 18:22:13 -08:00
Yukihiro "Matz" Matsumoto 9b501ab507 Merge pull request #5247 from SeekingMeaning/squiggly-fix
Fix for empty lines in squiggly heredocs
2020-12-28 17:03:52 +09:00
Seeker 3a2ff9824e Fix for empty lines in squiggly heredocs 2020-12-27 23:10:08 -08:00
Yukihiro "Matz" Matsumoto 6d98ae57f2 Merge pull request #5248 from SeekingMeaning/hash-except
Add `Hash#except` [Ruby 3.0]
2020-12-28 15:19:13 +09:00
Seeker 14a92f9705 Add Hash#except [Ruby 3.0] 2020-12-27 16:33:12 -08:00
Yukihiro "Matz" Matsumoto d57d6e2b5b Merge pull request #5246 from SeekingMeaning/squiggly-heredocs
Add support for squiggly heredocs
2020-12-27 20:05:45 +09:00
Seeker 6312a50045 Fix operand types error 2020-12-27 00:20:02 -08:00
Seeker 6491d8dd28 Commit y.tab.c 2020-12-27 00:09:39 -08:00
Seeker 54bfcaf1ff Add support for squiggly heredocs 2020-12-26 23:48:20 -08:00
John Bampton 38de04c4f7 Update copyright year for 2021 2020-12-27 01:11:47 +10:00
Yukihiro "Matz" Matsumoto dad43359cb Merge pull request #5244 from dearblue/eval-nomem
Improves out of memory messages for `eval`
2020-12-26 08:44:08 +09:00
dearblue 88a11d81b0 Improves out of memory messages for eval
The comment says that if `mrb_parse_nstring()` returns `NULL`, it is only out of memory.
I'm worried about compatibility if I set the exception class to `NoMemoryError`, so it's still `RuntimeError`.
2020-12-25 23:24:20 +09:00
Yukihiro "Matz" Matsumoto 825c14a0c5 Reset paren_nest at tAREF and tASET. 2020-12-24 23:30:42 +09:00
Yukihiro "Matz" Matsumoto 2850b58dd9 Check integer overflow in float bit operations. 2020-12-24 23:17:18 +09:00
Yukihiro "Matz" Matsumoto 3419426dbf Avoid division by zero in rational_to_f(). 2020-12-24 23:16:49 +09:00
Yukihiro "Matz" Matsumoto 4e90d6938a Merge pull request #5242 from jbampton/add-codeowners
Create CODEOWNERS file
2020-12-23 15:59:30 +09:00
Yukihiro "Matz" Matsumoto 7f73af079a Merge pull request #5243 from boatrite/add-gba-build-config
Add example for cross-compiling to Nintendo GameBoyAdvance
2020-12-23 15:55:38 +09:00
Gwen Boatrite 3bfafd198c Add example for cross-compiling to Nintendo GameBoyAdvance 2020-12-23 00:26:49 -06:00
Yukihiro "Matz" Matsumoto 0bb4afe942 Fix the integer overflow in mrb_str_len_to_inum(). 2020-12-23 10:35:15 +09:00
John Bampton e96620cd23 Create CODEOWNERS file
- You can use a CODEOWNERS file to define individuals or teams that are responsible for code in a repository.
- Code owners are automatically requested for review when someone opens a pull request that modifies code that they own. Code owners are not automatically requested to review draft pull requests.
- https://docs.github.com/en/free-pro-team@latest/github/creating-cloning-and-archiving-repositories/about-code-owners
- This creates a bit more automation so that after you merge this PR, next time someone submits a PR @matz will be automatically assigned as the PR reviewer as CODEOWNER
- CODEOWNERS can even be assigned directories or file types
2020-12-22 16:09:41 +10:00
Yukihiro "Matz" Matsumoto 8b2fd45d46 Merge pull request #5239 from jbampton/fix-links
refactor: fix Rake link and fix missing HTTPS on links
2020-12-21 23:11:40 +09:00
dearblue 6c1c2041ef Take advantage of gembox
I think that it is easy to use if it is divided according to the type of library and the general purpose.
It is a subdivision from the previous `default.gembox`.

By type gembox:
- `stdlib`: Add some standard Ruby methods not provided by core.
- `stdlib-ext`: Add some standard Ruby methods that are not provided by `stdlib`.
- `stdlib-io`: Provides `IO`, `File`, `Socket`, `print`, etc. Conflict with `MRB_NO_STDIO`
- `math`: Add a class related to math. Conflict with `MRB_NO_FLOAT`
- `metaprog`: Adds features related to metaprogramming.

Purpose gembox:
- `default.gembox`: Import the same gems as before
- `default-no-stdio.gembox`: Import the` stdlib` and `math`
- `default-no-fpu.gembox`: Import the` stdlib` only
2020-12-21 21:48:50 +09:00
John Bampton 16cb81c727 refactor: fix Rake link and fix missing HTTPS on links 2020-12-21 18:46:38 +10:00
Yukihiro "Matz" Matsumoto 788ee38bdf Merge pull request #5238 from shuujii/fix-typo-in-.github-workflows-build.yml
Fix typo in `.github/workflows/build.yml` [skip travis][skip appveyor]
2020-12-21 17:07:20 +09:00
KOBAYASHI Shuji 366780f0bc Fix typo in .github/workflows/build.yml [skip travis][skip appveyor] 2020-12-21 16:12:02 +09:00
Yukihiro "Matz" Matsumoto 3069299200 Merge pull request #5237 from shuujii/use-git-ls-files-instead-of-find-to-avoid-including-.git
Use `git ls-files` instead of `find` in `spell-checker.yml` [ci skip]
2020-12-21 08:33:42 +09:00
KOBAYASHI Shuji 01a6cdb882 Use git ls-files instead of find in spell-checker.yml [ci skip]
To avoid including `.git` directory.
2020-12-20 22:52:33 +09:00
Yukihiro "Matz" Matsumoto a65c33c487 Merge pull request #5236 from shuujii/reorganize-GitHub-Actions-configuration
Reorganize GitHub Actions configuration [skip travis][skip appveyor]
2020-12-20 18:13:48 +09:00
Yukihiro "Matz" Matsumoto 5337e9375c Merge pull request #5235 from jbampton/fix-link-and-fix-word-case
refactor: fix case of GitHub and fix missing HTTPS on link
2020-12-20 18:12:23 +09:00
KOBAYASHI Shuji 74e1d1ea02 Reorganize GitHub Actions configuration [skip travis][skip appveyor]
* Skip if commit message contains `ci skip`, `skip ci`, or `skip gha`
  ENCLOSED WITH BRACKETS (excluding lint job).
* Separate build and test. This is because builds can be run in parallel,
  but running tests in parallel can cause logs to get mixed up or not
  finished.
* Don't use Chocolatey because it seems to take 1-2 minutes to start up.
* Use the cache better.
* Use `actions/checkout@v2` instead of `actions/checkout@v1`.
* Remove unnecessary package installation.
* Remove unnecessary flag settings.
* Remove `-j` for rake because it doesn't seem to have any effect.
* Rename `main.yml` to `oss-fuzz.yml` to clarify.
2020-12-20 15:31:15 +09:00
John Bampton 68af0cca65 refactor: fix case of GitHub and fix missing HTTPS on link
- changed `github` to `GitHub`
2020-12-19 23:55:10 +10:00
Yukihiro "Matz" Matsumoto a528312542 Merge pull request #5234 from jbampton/remove-whitespace
refactor: remove trailing whitespace
2020-12-19 22:44:23 +09:00
Yukihiro "Matz" Matsumoto c17f1be52a Merge pull request #5233 from jbampton/update-authors
Add my name to the AUTHORS file
2020-12-19 22:43:58 +09:00
John Bampton bc90635e83 refactor: remove trailing whitespace 2020-12-19 22:37:47 +10:00
John Bampton 2a42cc2d69 Add my name to the AUTHORS file 2020-12-19 20:28:17 +10:00
Yukihiro "Matz" Matsumoto 8f06789cb3 Merge pull request #5232 from jbampton/lint-markdown
feat(CI): add a GitHub Action to lint the Markdown
2020-12-19 17:31:54 +09:00
Yukihiro "Matz" Matsumoto fcc9b7fc2a Merge pull request #5230 from dearblue/mruby-config.2
Ignore `mruby-bin-config` in cross-building
2020-12-19 17:28:53 +09:00
John Bampton 97eed4493f feat(CI): add a GitHub Action to lint the Markdown
Run on pull request only
Using https://www.npmjs.com/package/markdownlint-cli
Lint Markdown for rules:
- MD009/no-trailing-spaces
- MD012/no-multiple-blanks
- MD022/blanks-around-headings
- MD031/blanks-around-fences
- MD032/blanks-around-lists
2020-12-19 18:22:08 +10:00
Yukihiro "Matz" Matsumoto 340f1f0094 Merge pull request #5231 from jbampton/fix-links
🔒 Fix missing HTTPS on links
2020-12-19 16:59:11 +09:00
John Bampton 6f6149509a 🔒 Fix missing HTTPS on links 2020-12-19 17:52:16 +10:00
Yukihiro "Matz" Matsumoto 563ebbf083 Merge pull request #5229 from jbampton/fix-links
🔒 Fix missing HTTPS on links
2020-12-19 16:42:40 +09:00
John Bampton f7c5c00d6e 🔒 Fix missing HTTPS on links 2020-12-19 17:36:39 +10:00
dearblue 36376eba5f Warn that it was ignored in crossbuild 2020-12-19 15:53:01 +09:00
dearblue db1b78820d Avoid using MRuby::CrossBuild.current
This is because `MRuby::Build.currrent` and `MRuby::CrossBuild.current` are assignments to different instance variables.
2020-12-19 15:53:01 +09:00
Yukihiro "Matz" Matsumoto 08d4365252 Merge pull request #5228 from jbampton/spell-checker
feat(CI): add a GitHub Action to check spelling
2020-12-18 23:43:11 +09:00
John Bampton d21d5993b9 feat(CI): add a GitHub Action to check spelling
- Fix spelling
- Run only on pull request
- Using https://github.com/client9/misspell
2020-12-17 16:22:31 +10:00
Yukihiro "Matz" Matsumoto fbe5033f80 Merge pull request #5224 from jbampton/lint-yaml
feat(CI): add a GitHub Action to lint the YAML
2020-12-16 22:26:21 +09:00
Yukihiro "Matz" Matsumoto 8f8e832767 Merge pull request #5227 from shuujii/rename-build-configuration-files-for-CI
Rename build configuration files for CI
2020-12-16 22:25:58 +09:00
KOBAYASHI Shuji d432688d9f Rename build configuration files for CI
Currently, there are build configuration files for CI, `travis.rb` and
`appveyor.rb`, but they are used for GCC/Clang and MSVC, not for Travis CI
and Appveyor, respectively.

Therefore, rename them to `gcc-clang.rb` and `msvc.rb`, respectively, and
move them under `build_config/ci/` to clarify that they are for CI.
2020-12-16 21:56:32 +09:00
Yukihiro "Matz" Matsumoto 1b7197622f Merge pull request #5226 from shuujii/guess-toolchain-when-MRubyBuild-toolchain-argument-is-omitted
Guess toolchain when `MRuby::Build#toolchain` argument is omitted
2020-12-16 20:25:35 +09:00
KOBAYASHI Shuji 0396f3f0fd Guess toolchain when MRuby::Build#toolchain argument is omitted 2020-12-16 19:17:44 +09:00
John Bampton aa6fc8c38e feat(CI): add a GitHub Action to lint the YAML
- Run only on pull request
- Add a `.yamllint` config file
- Lint YAML
2020-12-15 23:39:36 +10:00
Yukihiro "Matz" Matsumoto c1c8c25e70 Merge pull request #5223 from shuujii/ensure-initialization-of-RVALUE_zero-in-mrb_obj_alloc
Ensure initialization of `RVALUE_zero` in `mrb_obj_alloc`
2020-12-15 22:32:32 +09:00
Yukihiro "Matz" Matsumoto aec8eba076 Merge pull request #5225 from shuujii/output-build-log-at-the-time-of-installation
Output build log at the time of installation
2020-12-15 22:31:26 +09:00
Yukihiro "Matz" Matsumoto 2f177dcd72 Merge pull request #5222 from jbampton/remove-trailing-whitespace
refactor: remove trailing whitespace from C, Header, Ruby and YAML files
2020-12-15 22:30:38 +09:00
KOBAYASHI Shuji c6364edd96 Output build log at the time of installation 2020-12-15 21:54:19 +09:00
John Bampton 4fa3359d44 refactor: remove trailing whitespace from C, Header, Ruby and YAML files
Lint
2020-12-15 19:44:02 +10:00
KOBAYASHI Shuji d5cb54d4df Ensure initialization of RVALUE_zero in mrb_obj_alloc
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-15 17:48:06 +09:00
Yukihiro "Matz" Matsumoto e9fe337b95 Merge pull request #5221 from jbampton/fix-spelling
Fix spelling
2020-12-13 23:36:18 +09:00
John Bampton 940dec5e7d Fix spelling 2020-12-13 18:38:22 +10:00
KOBAYASHI Shuji 456878ba06 Improve source scanning for presym
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-13 15:27:53 +09:00
Yukihiro "Matz" Matsumoto 116e128b1a Remove positive check for unsigned integer; close #5218 2020-12-12 18:25:47 +09:00
Yukihiro "Matz" Matsumoto 092dd4a667 Argument forwarding with ... now supports leading arguments.
```ruby
def method_missing(meth, ...)
  send(:"do_#{meth}", ...)
end
```
2020-12-09 11:56:54 +09:00
Yukihiro "Matz" Matsumoto 2e9b8f0d9b Fix a bug caused by tBDOT3 (argument forwarding). 2020-12-08 22:01:47 +09:00
Yukihiro "Matz" Matsumoto ed29d74bfd Make type of pc arguments in debug.c consistent; close #5218
They used to be `size_t`, `uint32_t` and `ptrdiff_t`. Now all of them
made to be `uint32_t`.
2020-12-07 13:59:00 +09:00
Yukihiro "Matz" Matsumoto 8b52c67be9 Merge pull request #5217 from shuujii/call-super-before-creating-host-build-in-MRubyCrossBuild-initialize
Call `super` before creating `host` build in `MRuby::CrossBuild#initialize`
2020-12-06 17:30:34 +09:00
KOBAYASHI Shuji de03e97a50 Call super before creating host build in MRuby::CrossBuild#initialize
Call `super` (`block`) ahead so that creation of the `host` build can be
skipped if pre-built `mrbc` can be specified in the future.

close #5213.
2020-12-06 15:14:09 +09:00
Yukihiro "Matz" Matsumoto 9e41ae4909 Merge pull request #5214 from shuujii/allow-obsoluted-MRB_METHOD_T_STRUCT
Allow obsoluted `MRB_METHOD_T_STRUCT`
2020-12-05 22:22:18 +09:00
Yukihiro "Matz" Matsumoto 9cffacdf0d Merge pull request #5216 from shuujii/remove-unused-@endian-in-MRubyCrossBuild-initialize
Remove unused `@endian` in `MRuby::CrossBuild#initialize`
2020-12-05 22:20:11 +09:00
Yukihiro "Matz" Matsumoto 1b6efeef57 Merge pull request #5215 from shuujii/update-Configuration-Options-Changed-in-doc-mruby3.md
Update "Configuration Options Changed" in `doc/mruby3.md` [ci skip]
2020-12-05 22:19:41 +09:00
KOBAYASHI Shuji 07668b067b Remove unused @endian in MRuby::CrossBuild#initialize 2020-12-05 19:52:07 +09:00
KOBAYASHI Shuji f84668f8d5 Update "Configuration Options Changed" in doc/mruby3.md [ci skip] 2020-12-05 19:26:38 +09:00
KOBAYASHI Shuji 58ef897696 Allow obsoluted MRB_METHOD_T_STRUCT 2020-12-05 17:37:39 +09:00
Yukihiro "Matz" Matsumoto 6e5a0f623f Fixed a memory leak bug on codegen_error() when irep->rlen>255. 2020-12-05 15:28:58 +09:00
Yukihiro "Matz" Matsumoto 63d82142a8 Merge pull request #5212 from shuujii/make-it-possible-that-libmruby.a-is-not-created
Make it possible that `libmruby.a` is not created
2020-12-05 14:08:29 +09:00
KOBAYASHI Shuji 73b4152574 Make it possible that libmruby.a is not created
Previously, `libmruby.a` was created even if only `mruby-bin-mrbc` or`
mruby-compiler` was specified for gem, but by specifying `disable_libmruby`,
the creation of `libmruby.a` can be suppressed.

### Note

The https://github.com/mruby/mruby/pull/5084#issuecomment-723521971
incompatibility seems to be difficult for users to avoid, so the original
behavior has been restored. Therefore, if we need `mrbc` other than the
`host` build, we need to explicitly specify `mruby-bin-mrbc` gem.

Due to the above changes, `build_config/boxing.rb` etc. will not work, but I
have added` mruby-bin-mrbc` to `default.gembox` to fix it. I don't think
this change is a big deal because originally `mruby-compiler` was included.
2020-12-05 09:16:08 +09:00
Yukihiro "Matz" Matsumoto 00d1fd0e6f Fixed a bug with modules prepended many times.
Adjust insertion point in `fix_prepend_module()`.
2020-12-05 08:01:05 +09:00
Yukihiro "Matz" Matsumoto 3972df57fe Make Module#include and Module#prepend behave like Ruby3.0.
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-04 22:02:37 +09:00
Yukihiro "Matz" Matsumoto 4cd3493737 Merge pull request #5211 from shuujii/move-mrbc-test-to-mruby-bin-mrbc-gem-from-mruby-compiler-gem
Move `mrbc` test to `mruby-bin-mrbc` gem from `mruby-compiler` gem
2020-12-04 12:50:48 +09:00
KOBAYASHI Shuji 4452041ebb Move mrbc test to mruby-bin-mrbc gem from mruby-compiler gem 2020-12-04 09:22:13 +09:00
Yukihiro "Matz" Matsumoto f6ad163841 Merge pull request #5209 from shuujii/remove-build-presym.inc-by-rake-clean
Remove `build/presym{,.inc}` by `rake clean` [ci skip]
2020-12-03 07:17:37 +09:00
KOBAYASHI Shuji e1fa01b9c8 Remove build/presym{,.inc} by rake clean [ci skip]
Currently, adding gems to build configuration and rebuilding does not
regenerate `presym`, which can lead to build errors.

Therefore in this case we need to remove the `presym` file and then rebuild
mruby, but when the` presym` file is regenerated we will need to recompile
most of the files, so it seems useful to have the `presym` file deleted by
`rake clean`.
2020-12-02 23:15:29 +09:00
Yukihiro "Matz" Matsumoto 42f33fd51a Merge pull request #5208 from shuujii/fix-build-for-C++11-when-enable_cxx_exception
Fix build for C++ version >= C++11 when `enable_cxx_exception`; close #5199
2020-12-02 21:35:21 +09:00
KOBAYASHI Shuji 00df809609 Fix build for C++ version >= C++11 when enable_cxx_exception; close #5199 2020-12-02 19:15:42 +09:00
Yukihiro "Matz" Matsumoto 661081a072 Merge pull request #5198 from shuujii/remove-unused-Rake-rules
Remove unused Rake rules
2020-12-02 11:07:37 +09:00
Yukihiro "Matz" Matsumoto 504b731af6 Use JMPLINK_START instead of zero for a link start marker. 2020-12-02 09:48:08 +09:00
Yukihiro "Matz" Matsumoto affb18b85b Remove assertions to check catch handler offset to be in 16bits. 2020-12-02 09:47:13 +09:00
Yukihiro "Matz" Matsumoto 826fe1bc36 Fixed memory leaks from codegen_error. 2020-12-02 09:46:08 +09:00
Yukihiro "Matz" Matsumoto dd0715fd58 Print implicit operands for some instructions. 2020-12-02 09:44:34 +09:00
Yukihiro "Matz" Matsumoto 25985876b8 Remove a newline. 2020-12-02 09:44:07 +09:00
Yukihiro "Matz" Matsumoto 9ba0ebec0e Fix a `OP_JMP bug from 0 marker and address 0. 2020-12-01 16:48:24 +09:00
Yukihiro "Matz" Matsumoto a7d84382f8 Merge pull request #5207 from shuujii/revert-Create-presym-files-for-each-build-target
Revert "Create presym files for each build target" (58ba883e)
2020-12-01 16:46:19 +09:00
KOBAYASHI Shuji 5c205e6ea1 Revert "Create presym files for each build target" (58ba883e)
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-01 12:16:55 +09:00
Yukihiro "Matz" Matsumoto 98d5aa8d74 Fix OP_JMPUW address bug. 2020-12-01 00:25:09 +09:00
Yukihiro "Matz" Matsumoto 1c361f8a22 Merge pull request #5206 from dearblue/dumpirep
Improves dump irep
2020-11-30 23:21:19 +09:00
Yukihiro "Matz" Matsumoto d56db2296d Merge pull request #5205 from dearblue/codedump
Fixed print catch handler address in codedump; ref #5200
2020-11-30 23:19:59 +09:00
dearblue 3bc9453c9a Integrate the output of the catch handler table into iseq
Alleviates confusingness.

ref #5203
2020-11-30 22:56:59 +09:00
dearblue a56b601f56 Fixed irep size measurement by dump; ref #5203 2020-11-30 22:56:41 +09:00
dearblue 0ecb0fd97b Fixed print catch handler address in codedump; ref #5200
It became 32 bits in #5200, but only the upper 16 bits were printed.
2020-11-30 22:36:26 +09:00
Yukihiro "Matz" Matsumoto 9f5c0777f1 Merge pull request #5204 from shuujii/use-MRB_SYM-in-src-gc.c
Use `MRB_SYM` in `src/gc.c`
2020-11-29 20:15:48 +09:00
KOBAYASHI Shuji 82f3e4d31b Use MRB_SYM in src/gc.c 2020-11-29 19:01:48 +09:00
Yukihiro "Matz" Matsumoto d4439479cf Merge pull request #5203 from komainu8/fix-heap-buffer-overflow
Fix heap buffer overflow when dump irep
2020-11-29 16:24:30 +09:00
Horimoto Yasuhiro df13d418c3 Fix heap buffer overflow when dump irep
Currently, the size of writing in heap by write_irep_record() is
bigger than The size that is calculated by get_irep_record_size.

Therefore, irep is dumped over the size of allocating memory when we
execute dump_irep().
2020-11-29 15:57:44 +09:00
Yukihiro "Matz" Matsumoto c6071335a1 Merge pull request #5200 from dearblue/catchhandler32
Change the catch handler address to 32 bits
2020-11-29 14:50:22 +09:00
dearblue b0cea30f32 Change the catch handler address to 32 bits
Follow commit 7150c67539 .
2020-11-29 13:48:45 +09:00
KOBAYASHI Shuji 8da2c11243 Remove unused Rake rules
Currently, the source file language in the core is C only, and C++,
Objective-C, and Assembly are not used, so Rake rules for them are removed.
2020-11-28 12:38:46 +09:00
Yukihiro "Matz" Matsumoto 6d07d9b3d7 Merge pull request #5197 from shuujii/fix-incorrect-regexp-creation-in-tasks-presym.rake
Fix incorrect regexp creation in `tasks/presym.rake`
2020-11-27 22:08:25 +09:00
KOBAYASHI Shuji cb7eb202ce Fix incorrect regexp creation in tasks/presym.rake 2020-11-27 20:07:16 +09:00
Yukihiro "Matz" Matsumoto 6059834244 Merge pull request #5196 from shuujii/fix-build-failure
Fix build failure; ref #5194
2020-11-27 08:57:03 +09:00
KOBAYASHI Shuji fdce0e712b Fix build failure; ref #5194
Fix the following two issues:

1. Compile failure when external gem is specified.
   * https://github.com/mruby/mruby/pull/5194#issuecomment-734303442
2. When there are multiple build targets, presym parsing sometimes fails or
   output result of presym is broken.
   * https://github.com/mruby/mruby/pull/5194#issuecomment-734322142

The root cause of 2 is unknown, but it seems to occur when presym parsing is
performed in parallel, therefore I change them so that they are not run in
parallel.
2020-11-27 07:59:57 +09:00
Yukihiro "Matz" Matsumoto 13fc503434 Merge pull request #5195 from shuujii/add-tools-to-target-directory-for-presym-parsing
Add `tools/*` to target directory for presym parsing
2020-11-26 22:47:22 +09:00
KOBAYASHI Shuji 0cb3a7186c Add tools/* to target directory for presym parsing 2020-11-26 22:05:59 +09:00
Yukihiro "Matz" Matsumoto 521c16d738 Merge pull request #5194 from shuujii/create-presym-files-for-each-build-target
Create presym files for each build target
2020-11-26 21:17:47 +09:00
Yukihiro "Matz" Matsumoto 7f5e257f77 Use __builtin_setjmp(), __builtin_longjmp() on MinGW; fix #5133 2020-11-26 20:48:26 +09:00
Yukihiro "Matz" Matsumoto e0b8876640 Avoid integer overflow in rational_new. 2020-11-26 20:48:25 +09:00
KOBAYASHI Shuji 58ba883ee9 Create presym files for each build target
Previously, presym files were always created in `build/{presym,presym.inc}`.
However, this constraint is inconvenient because it is common to use
multiple build configurations and build targets in a single mruby tree.
Therefore, change to create presym file for each build target.
2020-11-26 19:05:07 +09:00
Yukihiro "Matz" Matsumoto 79af3f30b4 Merge pull request #5193 from shuujii/fix-loop-condition-in-mrb_sym_all_symbols
Fix loop condition in `mrb_sym_all_symbols`
2020-11-26 14:20:11 +09:00
KOBAYASHI Shuji 3c63d38058 Fix loop condition in mrb_sym_all_symbols 2020-11-26 13:47:45 +09:00
Yukihiro "Matz" Matsumoto 63d4e8eca2 Fix a bug in find_symbol(); fix #5192 2020-11-26 13:18:45 +09:00
Yukihiro "Matz" Matsumoto 7150c67539 Make OP_JMP* operand address to be relative.
Jump target address is `operand (16bit)` + `address of next instruction`.

In addition, `ilen` was made `uint32_t` so that `iseq` length limitation
of 65536 is removed. Only jump target address should be within signed
16bit (-32768 .. 32767).
2020-11-26 10:34:31 +09:00
Yukihiro "Matz" Matsumoto 6dedd6a940 Fix Symbol.all_symbols to include preallocated symbols; ref #5116 2020-11-26 10:33:15 +09:00
Yukihiro "Matz" Matsumoto 66f2e733e5 Symbols should work with MRB_USE_ALL_SYMBOLS; fix #5116 2020-11-26 10:32:19 +09:00
Yukihiro "Matz" Matsumoto a33f9d7b65 Small refactoring regarding symbols for clarity. 2020-11-26 09:42:08 +09:00
Yukihiro "Matz" Matsumoto 50b57f6ff1 Include mruby.h instead of mrbconf.h directly. 2020-11-26 09:14:12 +09:00
Yukihiro "Matz" Matsumoto 2daf1987f9 Avoid memory leak when mrb_read_irep() fails. 2020-11-26 09:04:30 +09:00
Yukihiro "Matz" Matsumoto 71f9add1c5 Move inline iseq in array.c to array.rb.
There's no efficiency difference since `cdump` is implemented.
2020-11-25 23:14:38 +09:00
Yukihiro "Matz" Matsumoto fba7874a68 Replace mere enable_debug by clearer conf.enable_debug [ci skip] 2020-11-25 21:42:10 +09:00
Yukihiro "Matz" Matsumoto 6e17122c6d Merge pull request #5190 from shuujii/allow-compiler-name-in-build-log-to-be-customized
Allow compiler name in build log to be customized
2020-11-25 15:31:39 +09:00
KOBAYASHI Shuji 038bad2f41 Allow compiler name in build log to be customized
For example, in the case of the C++ compiler, it is output as
`CXX  build/host/src/gc.cxx -> build/host/src/gc.cxx.o` (FYI, in the case
of `enable_cxx_abi`, it outputs `CC ...` because the option to compile as
C++ is added to C compiler).
2020-11-25 15:11:36 +09:00
Yukihiro "Matz" Matsumoto 6a284872ce Merge pull request #5189 from shuujii/fix-C-source-compilation-with-MRB_USE_ALL_SYMBOLS
Fix C source compilation with `MRB_USE_ALL_SYMBOLS`; ref #5187
2020-11-25 14:33:03 +09:00
KOBAYASHI Shuji a7b50be35b Fix C source compilation with MRB_USE_ALL_SYMBOLS; ref #5187
However, compiling by `mrbc` fails with another issue (#5116).
2020-11-25 10:17:52 +09:00
Yukihiro "Matz" Matsumoto fc98aa290f Remove no longer used `MRB_IV_SEGMENT_SIZE; close #5188 [ci skip] 2020-11-25 08:31:10 +09:00
Yukihiro "Matz" Matsumoto 40235f3050 Use more mrb_int_value() instead of mrb_fixnum_value(). 2020-11-24 20:52:25 +09:00
Yukihiro "Matz" Matsumoto 2e30c68562 Move MRB_NO_FLOAT detection in mruby-math; #5185 2020-11-24 20:43:56 +09:00
Yukihiro "Matz" Matsumoto 4d21a68d35 Add #include <mrbconf.h> at the head of fmt_fp.c; #5185 2020-11-24 20:01:24 +09:00
Yukihiro "Matz" Matsumoto 9e114fc913 Merge pull request #5186 from shuujii/optimize-presym_find
Optimize `presym_find`
2020-11-24 16:58:09 +09:00
Yukihiro "Matz" Matsumoto e55abd2390 Fix compiler errors from MRB_NO_FLOAT; #5185
Also added `no-float.rb` target in `build_config`.
2020-11-24 16:54:39 +09:00
KOBAYASHI Shuji db00fb238b Optimize presym_find
Chang to compare string length first.

### Benchmark

#### Code

* https://github.com/shuujii/mruby-presym_find-benchmark

#### Result

```console
Previous: 10.240772M i/s (25M times in 2.441222s)
     New: 16.412985M i/s (25M times in 1.523184s)
```
2020-11-24 16:30:52 +09:00
Yukihiro "Matz" Matsumoto 36e3c4404a Should not use mrb_float if MRB_NO_FLOAT is defined; fix #5185 2020-11-24 13:50:15 +09:00
Yukihiro "Matz" Matsumoto 67f3626b5c Merge pull request #5178 from abinoam/fix_mruby_config_setting
Fix #5177 by setting MRUBY_CONFIG early
2020-11-24 09:44:21 +09:00
Abinoam Praxedes Marques Junior 4803c872e2 Fix #5177 - set MRUBY_CONFIG early 2020-11-23 15:18:22 -03:00
Yukihiro "Matz" Matsumoto e4e4eeb0c3 Merge pull request #5184 from dearblue/embedded-directive
Avoid warnings from clang's "-Wembedded-directive"
2020-11-23 22:07:48 +09:00
dearblue 3a92a4e3d8 Avoid warnings from clang's "-Wembedded-directive"
If it gives clang-11.0 `-Wembedded-directive`, a warning will be reported in `include/mruby/boxing_nan.h`.

```
include/mruby/boxing_nan.h:48:2: warning: embedding a directive within macro arguments has undefined behavior [-Wembedded-directive]
include/mruby/boxing_nan.h:52:2: warning: embedding a directive within macro arguments has undefined behavior [-Wembedded-directive]
```

The cause of this is #5117.
ref. e993b83c50
2020-11-23 21:22:50 +09:00
Yukihiro "Matz" Matsumoto 6f53e2c059 Merge pull request #5180 from wataash/fix-unintended-variable-shadowing
Fix unintended variable shadowing
2020-11-23 17:05:27 +09:00
Yukihiro "Matz" Matsumoto c6c0b796e1 Merge pull request #5181 from shuujii/raise-an-exception-instead-of-exiting-when-mrbc-fails
Raise an exception instead of exiting when `mrbc` fails
2020-11-23 17:02:44 +09:00
Yukihiro "Matz" Matsumoto b1ee892818 Merge pull request #5183 from shuujii/change-output-condition-in-_pp
Change output condition in `_pp`
2020-11-23 17:01:59 +09:00
Yukihiro "Matz" Matsumoto e6b06eafb3 Merge pull request #5182 from shuujii/use-local-variables-instead-of-top-level-constants-in-boxing.rb
Use local variables instead of top level constants in `boxing.rb` [ci skip]
2020-11-23 17:01:01 +09:00
KOBAYASHI Shuji 2f85290065 Change output condition in _pp
* Output even with `rake -v` (to help debugging)
* Not output when `rake -s`
2020-11-23 16:50:15 +09:00
KOBAYASHI Shuji 0d8b1eaee5 Use local variables instead of top level constants in boxing.rb [ci skip] 2020-11-23 16:35:36 +09:00
KOBAYASHI Shuji 2b0f908017 Raise an exception instead of exiting when mrbc fails 2020-11-23 16:32:10 +09:00
Wataru Ashihara 01dc2265ff Fix unintended variable shadowing 2020-11-23 14:48:14 +09:00
Yukihiro "Matz" Matsumoto 39a11f323e Remove mrb_str_buf_new() and MRB_STR_BUF_MIN_SIZE; close #5171 2020-11-22 22:54:21 +09:00
Yukihiro "Matz" Matsumoto abdd006df3 Strictly speaking NULL + 0 is a undefined behavior; ref #5157 2020-11-22 22:44:22 +09:00
Yukihiro "Matz" Matsumoto 2d9bf22730 Merge pull request #5173 from shuujii/refine-build-log-for-generated-files
Refine build log for generated files
2020-11-22 22:38:33 +09:00
Yukihiro "Matz" Matsumoto 17532874a8 Merge pull request #5174 from dearblue/doc
Add brief explanation about `bin/mruby`; ref #5157 [ci skip]
2020-11-22 22:37:29 +09:00
dearblue a67b88e223 Add brief explanation about bin/mruby; ref #5157 [ci skip] 2020-11-22 20:49:59 +09:00
KOBAYASHI Shuji 2a97e97db4 Refine build log for generated files
* Output `GEN` log for generated files
* `MRBC` log is outputted one for each `mrbc` execution

#### Before this patch:

```console
CC    src/array.c -> build/host/src/array.o
(snip)
GEN   mrblib/*.rb -> build/host/mrblib/mrblib.c
      MRBC mrblib/00class.rb
      MRBC mrblib/10error.rb
(snip)
CC    mrbgems/mruby-time/src/time.c -> build/host/mrbgems/mruby-time/src/time.o
      MRBC mrbgems/mruby-time/mrblib/time.rb
(snip)
CC    mrbgems/mruby-socket/test/sockettest.c -> build/host/mrbgems/mruby-socket/test/sockettest.o
      MRBC mrbgems/mruby-socket/test/addrinfo.rb
      MRBC mrbgems/mruby-socket/test/basicsocket.rb
(snip)
```

#### After this patch:

```console
GEN   build/presym
GEN   build/presym.inc
CC    src/array.c -> build/host/src/array.o
(snip)
GEN   mrblib/*.rb -> build/host/mrblib/mrblib.c
      MRBC mrblib/00class.rb
           mrblib/10error.rb
(snip)
CC    mrbgems/mruby-time/src/time.c -> build/host/mrbgems/mruby-time/src/time.o
GEN   build/host/mrbgems/mruby-time/gem_init.c
      MRBC mrbgems/mruby-time/mrblib/time.rb
(snip)
CC    mrbgems/mruby-socket/test/sockettest.c -> build/host/mrbgems/mruby-socket/test/sockettest.o
GEN   build/host/mrbgems/mruby-socket/gem_test.c
      MRBC mrbgems/mruby-socket/test/addrinfo.rb
      MRBC mrbgems/mruby-socket/test/basicsocket.rb
(snip)
```
2020-11-22 20:31:01 +09:00
Yukihiro "Matz" Matsumoto 76b036a627 Merge pull request #5172 from shuujii/move-global-function-for-build-to-lib-mruby-core_ext.rb
Move global function for build to `lib/mruby/core_ext.rb`
2020-11-22 18:03:29 +09:00
Yukihiro "Matz" Matsumoto ac2dfa8c47 Merge pull request #5170 from dearblue/gcmark
Fix GC mark leaks for `MRB_TT_BREAK`; fix #5168
2020-11-22 18:00:53 +09:00
KOBAYASHI Shuji 1c7a1926a3 Move global function for build to lib/mruby/core_ext.rb
Because `_pp` is originally defined in `lib/mruby/core_ext.rb`, other global
functions are moved to the file.
2020-11-22 16:53:13 +09:00
dearblue fd3576e888 Fix GC mark leaks for MRB_TT_BREAK; fix #5168 2020-11-22 15:09:01 +09:00
Yukihiro "Matz" Matsumoto 1cd8b4c933 Merge pull request #5169 from shuujii/fix-size-of-local-variable-array-in-struct-dumped-file
Fix size of local variable array in struct dumped file
2020-11-22 14:41:48 +09:00
KOBAYASHI Shuji 1864816d1e Fix size of local variable array in struct dumped file 2020-11-22 13:32:45 +09:00
Yukihiro "Matz" Matsumoto e02d0ff78c Merge pull request #5167 from dearblue/singleton-method
Improved `Object#define_singleton_method`
2020-11-22 00:02:34 +09:00
Yukihiro "Matz" Matsumoto 049e749c8b Merge pull request #5166 from shuujii/rename-MRB_ENABLE-DISABLE_-to-MRB_USE-NO_
Rename `MRB_{ENABLE,DISABLE}_` to `MRB_{USE,NO}_`; close #5163
2020-11-21 23:59:32 +09:00
dearblue b2bfcabae2 Improved Object#define_singleton_method
Integrate the implementation with `Module#define_method`.

- Introduce the internal function `mrb_mod_define_method_m()` (no static)
- The `Object#define_singleton_method` method can now accept a second argument
2020-11-21 22:31:13 +09:00
KOBAYASHI Shuji 3d056d084a Rename MRB_{ENABLE,DISABLE}_ to MRB_{USE,NO}_; close #5163
|        Previous Name         |        New Name         |
|------------------------------|-------------------------|
| MRB_ENABLE_ALL_SYMBOLS       | MRB_USE_ALL_SYMBOLS     |
| MRB_ENABLE_SYMBOLL_ALL       | MRB_USE_ALL_SYMBOLS     |
| MRB_ENABLE_CXX_ABI           | MRB_USE_CXX_ABI         |
| MRB_ENABLE_CXX_EXCEPTION     | MRB_USE_CXX_EXCEPTION   |
| MRB_ENABLE_DEBUG_HOOK        | MRB_USE_DEBUG_HOOK      |
| MRB_DISABLE_DIRECT_THREADING | MRB_NO_DIRECT_THREADING |
| MRB_DISABLE_STDIO            | MRB_NO_STDIO            |
| ENABLE_LINENOISE             | MRB_USE_LINENOISE       |
| ENABLE_READLINE              | MRB_USE_READLINE        |
| DISABLE_MIRB_UNDERSCORE      | MRB_NO_MIRB_UNDERSCORE  |
| DISABLE_GEMS                 | MRB_NO_GEMS             |

* `MRB_ENABLE_SYMBOLL_ALL` seems to be a typo, so it is fixed.
* `MRB_` prefix is added to those without.
* The previous names can also be used for compatibility.
2020-11-21 21:14:40 +09:00
Yukihiro "Matz" Matsumoto 544784effd Merge pull request #5157 from dearblue/detect-rb-mrb
Allow to mixed and specify `*.rb` and `*.mrb` in `bin/mruby`
2020-11-21 19:22:49 +09:00
dearblue a045b6b8d9 Allow to mixed and specify *.rb and *.mrb in bin/mruby
It is not decides by the extension.
In order to be recognized as a `.mrb` file, the following three points must be satisfied:
- File starts with "RITE"
- At least `sizeof(struct rite_binary_header)` bytes can be read
- `NUL` is included in the first 64 bytes of the file
If these are not met, it is judged as a text file and it is processed as a Ruby script.

The `bin/mruby -b` switch is still available which treats the given file as a `.mrb` file.

New `MRB_API` function:
- `include/mruby/compile.h` and `mrbgems/mruby-compiler/core/parse.y`
  - `mrb_load_detect_file_cxt()` (remove with `MRB_DISABLE_STDIO`)

NOTE:
- Even script files now always open in binary mode for `bin/mruby`.
  The `\r\n` is handled by the `nextc()` function already, so there is no problem even on Windows.
- The `nextc0()` function in `mrbgems/mruby-compiler/core/parse.y` can now specify a string buffer and a file pointer at the same time.
  In this case, get it from the string buffer first.

This patch includes modifies by comment of https://github.com/mruby/mruby/pull/5157.
2020-11-21 19:05:46 +09:00
Yukihiro "Matz" Matsumoto e3b91b8d41 Merge pull request #5165 from shuujii/fix-incorrect-build-name-and-simplify-build_config-boxing.rb
Fix incorrect build name and simplify `build_config/boxing.rb` [ci skip]
2020-11-21 17:53:42 +09:00
KOBAYASHI Shuji a3685c4c04 Fix incorrect build name and simplify build_config/boxing.rb [ci skip]
`boxing-nan-m64` was duplicated.
2020-11-21 17:50:44 +09:00
Yukihiro "Matz" Matsumoto a3221bf8cd Merge pull request #5164 from shuujii/automatically-enable-MRB_ENABLE_DEBUG_HOOK-if-mruby-bin-debugger-is-used
Automatically enable `MRB_ENABLE_DEBUG_HOOK` if `mruby-bin-debugger` is used
2020-11-21 17:41:36 +09:00
KOBAYASHI Shuji 3179944e81 Automatically enable MRB_ENABLE_DEBUG_HOOK if mruby-bin-debugger is used 2020-11-21 17:15:47 +09:00
Yukihiro "Matz" Matsumoto 66d044ec3e Remove -Wdeclaration-after-statement from gcc options; #5159 2020-11-21 17:05:16 +09:00
Yukihiro "Matz" Matsumoto 734f6b1cc4 Remove 2 restrictions from CONTRIBUTING.md; close #5159
* Allow mixed declarations, especially loop variables
* Allow C++ style commends `//`
2020-11-21 16:55:40 +09:00
Yukihiro "Matz" Matsumoto 55e1275778 Merge pull request #5161 from dearblue/ary-splice
Fix documents for `mrb_ary_splice()` [ci skip]
2020-11-21 16:08:44 +09:00
Yukihiro "Matz" Matsumoto c6c18c32b0 Merge pull request #5162 from shuujii/move-some-.rake-files-to-tasks-directory-for-consistency
Move some `.rake` files to `tasks` directory for consistency
2020-11-21 16:07:03 +09:00
Yukihiro "Matz" Matsumoto 00751ccbcd Reserve OP_SENDVK for the future keyword arguments like Ruby3.0. 2020-11-21 15:50:17 +09:00
Yukihiro "Matz" Matsumoto 59e581ed78 Fix infinite loop bug from super when method is prepended. 2020-11-21 15:50:16 +09:00
Yukihiro "Matz" Matsumoto a7bcbd8bdc Fix module order of #include; ruby-bug:7844 2020-11-21 15:50:16 +09:00
Yukihiro "Matz" Matsumoto 33f1970df2 Merge pull request #5160 from dearblue/cptr-obj
Unable for the `MRB_TT_CPTR` object to have a singleton class
2020-11-21 15:50:03 +09:00
Yukihiro "Matz" Matsumoto 07053e5654 Merge pull request #5158 from dearblue/typo
Fix typo "overfow" to "overflow" [ci skip]
2020-11-21 15:49:29 +09:00
dearblue 3ac6c3f090 Fix documents for mrb_ary_splice() [ci skip] 2020-11-21 15:47:59 +09:00
dearblue 7f9b4e056d Unable for the MRB_TT_CPTR object to have a singleton class
This object is treated as an immediate value.
2020-11-21 15:36:56 +09:00
KOBAYASHI Shuji 551bf0c635 Move some .rake files to tasks directory for consistency 2020-11-21 15:36:46 +09:00
dearblue 1e340cf869 Fix typo "overfow" to "overflow" [ci skip] 2020-11-21 15:19:28 +09:00
Yukihiro "Matz" Matsumoto eb52c29b2d Test each combination of boxing, mrb_int size, and archtecture.
Boxing:

* `MRB_NO_BOXING`   (`mrb_value` packed in `struct`)
* `MRB_WORD_BOXING` (`mrb_value` packed in `struct`) default
* `MRB_NAN_BOXING`  (`mrb_value` packed in `double`)

`mrb_int` size

* `MRB_INT32`       (`int32_t` as `mrb_int`)
* `MRB_INT64`       (`int64` as `mrb_int`) conflict with `MRB_NAN_BOXING'

Architecture

* `MRB_64BIT`      (`sizeof(void*)` is 64 bits)
* `MRB_32BIT`      (`sizeof(void*)` is 32 bits)
2020-11-21 14:38:14 +09:00
Yukihiro "Matz" Matsumoto 8258b7b5b3 Specify conf explicitly for enable_debug. 2020-11-21 14:38:14 +09:00
Yukihiro "Matz" Matsumoto 1974aa0f72 Update Float#to_s to keep trailing zero as CRuby does; ref 68cebb6 2020-11-21 14:38:13 +09:00
Yukihiro "Matz" Matsumoto 5f7eb20256 Merge pull request #5156 from shuujii/improve-determining-C++-compiler-in-tasks-toolchains-gcc.rake
Improve determining C++ compiler in `tasks/toolchains/gcc.rake`
2020-11-21 14:38:00 +09:00
KOBAYASHI Shuji 98d0f1b98e Improve determining C++ compiler in tasks/toolchains/gcc.rake
* Consider CC envvar as C compiler on which to make the decision.
* Consider the case where C compiler is `ccache gcc`, etc.
2020-11-21 12:25:50 +09:00
Yukihiro "Matz" Matsumoto fb028b47aa Merge pull request #5155 from shuujii/refactor-mrblib-mrblib.rake
Refactor `mrblib/mrblib.rake`
2020-11-20 23:13:08 +09:00
KOBAYASHI Shuji 1088feb110 Refactor mrblib/mrblib.rake 2020-11-20 22:55:49 +09:00
Yukihiro "Matz" Matsumoto ebf380474c Merge pull request #5153 from shuujii/refactor-src-mruby_core.rake
Refactor `src/mruby_core.rake`
2020-11-20 22:23:29 +09:00
Yukihiro "Matz" Matsumoto 749ac0a021 Merge pull request #5152 from shuujii/move-lib-mruby-core-ext.rb-to-lib-mruby-core_ext.rb-for-consistency
Move `lib/mruby-core-ext.rb` to `lib/mruby/core_ext.rb` for consistency
2020-11-20 22:22:14 +09:00
KOBAYASHI Shuji aaa12911e2 Refactor src/mruby_core.rake 2020-11-20 17:55:26 +09:00
KOBAYASHI Shuji 56a60fa7b7 Move lib/mruby-core-ext.rb to lib/mruby/core_ext.rb for consistency 2020-11-20 16:58:08 +09:00
Yukihiro "Matz" Matsumoto 5dc9a8249f Merge pull request #5150 from shuujii/allow-bintest-even-if-build-name-is-not-host
Allow `bintest` even if build name is not `host`
2020-11-19 12:41:53 +09:00
KOBAYASHI Shuji fd113da3aa Allow bintest even if build name is not host 2020-11-19 11:37:00 +09:00
Yukihiro "Matz" Matsumoto 15d6e172e9 Merge pull request #5146 from shuujii/fix-integer-overflow-error-in-mrdb-test
Fix integer overflow error in mrdb test
2020-11-18 19:19:48 +09:00
KOBAYASHI Shuji f50cde9924 Fix integer overflow error in mrdb test 2020-11-18 18:54:00 +09:00
Yukihiro "Matz" Matsumoto 25e76ee5ce Merge pull request #5149 from mruby/revert-5147-patch1
Revert "Check if irep->reps is NULL in lv_defined_p"
2020-11-18 18:48:17 +09:00
Yukihiro "Matz" Matsumoto a211a326de Revert "Check if irep->reps is NULL in lv_defined_p" 2020-11-18 18:47:46 +09:00
Yukihiro "Matz" Matsumoto e7d0baaf3b Use mrb_int_value() instead of mrb_fixnum_value(); fix #5142 2020-11-18 18:38:53 +09:00
Yukihiro "Matz" Matsumoto b9c80a5357 Merge pull request #5147 from hifoolno/patch1
Check if irep->reps is NULL in lv_defined_p
2020-11-18 18:13:31 +09:00
Zhang Xiaohui d3e17eedee Check if irep->reps is NULL in lv_defined_p 2020-11-18 17:07:20 +08:00
Yukihiro "Matz" Matsumoto e0df303547 Merge pull request #5143 from shuujii/use-mrb_int_value-instead-of-mrb_fixnum_value-in-src-hash.c
Use `mrb_int_value` instead of `mrb_fixnum_value` in `src/hash.c`
2020-11-18 17:29:34 +09:00
Yukihiro "Matz" Matsumoto 557e0645bf Merge pull request #5145 from shuujii/remove-unused-MRubyBuild-enable_bintest=
Remove unused `MRuby::Build#enable_{bin,}test=`
2020-11-18 17:28:47 +09:00
Yukihiro "Matz" Matsumoto 26dd35be59 Merge pull request #5144 from hifoolno/master
Check if irep->reps is NULL
2020-11-18 17:27:49 +09:00
KOBAYASHI Shuji dbb6010d8e Remove unused MRuby::Build#enable_{bin,}test=
The writers seem to be unnecessary because `MRuby::Build#enable_{bin,}test`
are used from the beginning.
2020-11-18 15:41:56 +09:00
Zhang Xiaohui eca6266524 Check if irep->reps is NULL 2020-11-18 14:41:27 +08:00
KOBAYASHI Shuji 4cea788970 Use mrb_int_value instead of mrb_fixnum_value in src/hash.c 2020-11-18 15:13:42 +09:00
Yukihiro "Matz" Matsumoto 3d8350f920 Retrieve irep from proc after MRB_PROC_CFUNC_P check; ref #5140 2020-11-18 10:07:26 +09:00
Yukihiro "Matz" Matsumoto 7c80edb577 Revert half of 9fbf0ef8.
I misunderstand the meaning of #4483. Sorry.
2020-11-17 22:47:25 +09:00
Yukihiro "Matz" Matsumoto 5abb283dd7 Check division overflow (MRB_INT_MIN and -1). 2020-11-17 22:41:43 +09:00
Yukihiro "Matz" Matsumoto 1f12525154 Merge pull request #5141 from shuujii/fix-deprecated-set-env-command-error-on-GitHub-Actions
Fix deprecated `set-env` command error on GitHub Actions [ci skip]
2020-11-17 22:07:33 +09:00
KOBAYASHI Shuji bed04414d7 Fix deprecated set-env command error on GitHub Actions [ci skip]
I tried `$GITHUB_PATH` and `$GITHUB_ENV` instead of `set-env`, but
for some reason path was not recognized, so I changed to using
`ACTIONS_ALLOW_UNSECURE_COMMANDS`.
2020-11-17 18:40:59 +09:00
Yukihiro "Matz" Matsumoto 68cebb6331 Overflown integers should not be fall back to float values. 2020-11-17 16:20:54 +09:00
Yukihiro "Matz" Matsumoto a8cd364ece Detect overflow in flo_shift(). 2020-11-17 16:20:53 +09:00
Yukihiro "Matz" Matsumoto 9fbf0ef886 Refactoring integer ranges.
- Remove `mrb_ssize`
- Fix `MRB_FIXNUM_{MIN,MAX}` to 32 bits on `MRB_NAN_BOXING`
2020-11-17 12:41:10 +09:00
Yukihiro "Matz" Matsumoto aae8237335 Scan all active C source files; ref 600e333
In addition, `include/mruby.h` will be scanned for error class symbols.
2020-11-17 09:00:06 +09:00
Yukihiro "Matz" Matsumoto 354934d398 Refactor integer division. 2020-11-17 07:10:31 +09:00
Yukihiro "Matz" Matsumoto 37a1884749 Simplify mrb_num_div_int(). 2020-11-17 00:24:43 +09:00
Yukihiro "Matz" Matsumoto 3107d1caae Allow int size combinations for MRB_WORD_BOXING.
- `MRB_64BIT` and `MRB_INT32`
- `MRB_32BIT` and `MRB_INT64`
2020-11-16 22:49:55 +09:00
Yukihiro "Matz" Matsumoto 3bb419aeab Merge pull request #5137 from shuujii/use-uintptr_t-instead-of-unsigned-long-in-include-mruby-boxing_word.h
Use `uintptr_t` instead of `unsigned long` in `include/mruby/boxing_word.h`
2020-11-16 22:49:42 +09:00
Yukihiro "Matz" Matsumoto 2609f0a2b3 Merge pull request #5139 from shuujii/avoid-undefined-behavior
Avoid undefined behavior
2020-11-16 22:49:03 +09:00
Yukihiro "Matz" Matsumoto 5156ea997f Merge pull request #5138 from shuujii/simplify-obj_free
Simplify `obj_free`
2020-11-16 22:48:05 +09:00
KOBAYASHI Shuji 7c470e25b8 Avoid undefined behavior
### ASAN report (`MRB_INT32`)

  ```console
  $ bin/mruby -ve '-0x40000000'
  mruby 3.0.0preview (2020-10-16)
  00001 NODE_SCOPE:
  00001   NODE_BEGIN:
  00001     NODE_NEGATE:
  00001       NODE_INT 40000000 base 16
  irep 0x6070000001e0 nregs=2 nlocals=1 pools=0 syms=0 reps=0 iseq=9
  file: -e
  /mruby/src/codedump.c:173:49: runtime error: left shift of 49152 by 16 places cannot be represented in type 'int'
  SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /mruby/src/codedump.c:173:49 in
      1 000 OP_LOADI32	R1	-1073741824
      1 006 OP_RETURN	R1
      1 008 OP_STOP

  /mruby/src/vm.c:1138:7: runtime error: left shift of 49152 by 16 places cannot be represented in type 'mrb_int' (aka 'int')
  SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /mruby/src/vm.c:1138:7 in
  ```
2020-11-16 20:20:30 +09:00
KOBAYASHI Shuji cbc3dbedb4 Simplify obj_free 2020-11-16 16:40:37 +09:00
KOBAYASHI Shuji 8a019106c0 Use uintptr_t instead of unsigned long in include/mruby/boxing_word.h
`mrb_bool`  on LLP64 environment seems to become false if, for example,
`mrb_value` is a pointer whose lower 32 bits are 0.
2020-11-16 16:04:05 +09:00
Yukihiro "Matz" Matsumoto 8a6614d30e Merge pull request #5135 from shuujii/fix-paths-of-gem-files-to-be-scanned-for-presym
Fix paths of gem files to be scanned for presym
2020-11-15 23:15:34 +09:00
Yukihiro "Matz" Matsumoto 144cf6cd58 Merge pull request #5134 from shuujii/fix-that-large-integer-is-not-GCed-with-Word-boxing
Fix that large integer is not GCed with Word-boxing
2020-11-15 23:14:59 +09:00
KOBAYASHI Shuji e334c02a50 Fix paths of gem files to be scanned for presym
When building from outside `MRUBY_ROOT` (e.g. `rake -f`), gem files were not
scanned.
2020-11-15 20:16:12 +09:00
KOBAYASHI Shuji acc114003b Fix that large integer is not GCed with Word-boxing
### Example (32-bit Word-boxing)

  ```ruby
  # example.rb
  int_count = ObjectSpace.count_objects[:T_INTEGER]||0
  int = 1<<30
  p (ObjectSpace.count_objects[:T_INTEGER]||0) - int_count
  int = nil
  GC.start
  p (ObjectSpace.count_objects[:T_INTEGER]||0) - int_count
  ```

#### Before this patch:

  ```console
  $ bin/mruby example.rb
  1
  1
  ```

#### After this patch:

  ```console
  $ bin/mruby example.rb
  1
  0
  ```
2020-11-15 16:45:03 +09:00
Yukihiro "Matz" Matsumoto a6119b0077 Fixed further wrong condition in overflow detection. 2020-11-15 08:08:55 +09:00
Yukihiro "Matz" Matsumoto bb1fb2f43d Fixed wrong condition in mrb_int_mul_overflow(). 2020-11-14 23:34:43 +09:00
Yukihiro "Matz" Matsumoto 2c6a5d3a77 Change the fallback mrb_int_mul_overflow(). 2020-11-14 23:28:05 +09:00
Yukihiro "Matz" Matsumoto 10c1c9d6f8 Change the type of rlen to uint8_t in mrb_irep. 2020-11-14 23:27:28 +09:00
Yukihiro "Matz" Matsumoto 8a5dfa92ab Integer overflow in operations should cause RangeError. 2020-11-14 20:44:07 +09:00
Yukihiro "Matz" Matsumoto dd3ed8d99c Allow full mrb_int operations in overflow detection.
Fix overflow detection in integer operations with `MRB_WORD_BOXING`.
This bug made `1073741824 == 1073741824+0` to be `false` on 32bit
platforms.
2020-11-14 20:40:06 +09:00
Yukihiro "Matz" Matsumoto 19450df41e Integer operation should result in Integer.
Should raise `RangeError` if the operation overflows.
2020-11-14 19:38:27 +09:00
Yukihiro "Matz" Matsumoto 600e3330b3 Scan source files only from cdump enabled gems. 2020-11-14 18:52:57 +09:00
Yukihiro "Matz" Matsumoto 4dcd8dd7ce Merge pull request #5132 from shuujii/remove-redundant-command-execution-in-header_search_paths
Remove redundant command execution in `header_search_paths`
2020-11-14 18:52:48 +09:00
KOBAYASHI Shuji e941fb7866 Remove redundant command execution in header_search_paths
There is no need to execute command in duplicate for the same
reason as #5128.
2020-11-14 17:19:38 +09:00
Yukihiro "Matz" Matsumoto 8398020d0a Merge pull request #5131 from shuujii/remove-unused-constant-in-lib-mruby-build-command.rb
Remove unused constant in `lib/mruby/build/command.rb`
2020-11-14 17:01:37 +09:00
Yukihiro "Matz" Matsumoto 69dbe8cfa5 Merge pull request #5130 from shuujii/workaround-to-build-mirb-with-Homebrews-readline-on-Mac
Workaround to build `mirb` with Homebrew's readline on Mac; fix #4537
2020-11-14 16:53:23 +09:00
KOBAYASHI Shuji 08df172e91 Remove unused constant in lib/mruby/build/command.rb 2020-11-14 16:50:00 +09:00
KOBAYASHI Shuji 06a8e502fa Workaround to build mirb with Homebrew's readline on Mac; fix #4537 2020-11-14 16:30:45 +09:00
Yukihiro "Matz" Matsumoto fdbb1731ce Merge pull request #5128 from shuujii/simplify-MRubyCommand-_run-to-avoid-duplicated-compilation
Simplify `MRuby::Command#_run` to avoid duplicated compilation
2020-11-14 16:08:10 +09:00
Yukihiro "Matz" Matsumoto 5edac8b885 Merge pull request #5129 from dearblue/mrb_mt_foreach
Don't use private structs with `mrb_mt_foreach()`
2020-11-14 16:06:47 +09:00
dearblue 368f8a5da6 Don't use private structs with mrb_mt_foreach()
The `MRB_API` function `mrb_mt_foreach()` previously used the private structure `struct mt_elem`.
Therefore, use `mrb_method_t` instead.
2020-11-14 11:30:34 +09:00
KOBAYASHI Shuji 0c55b85fb0 Simplify MRuby::Command#_run to avoid duplicated compilation
ref: https://github.com/mruby/mruby/pull/4959#discussion_r402086196

Compiles twice because it falls back to `build.filename(command)` when
`command` fails. This process was added at 9968af4 to support `ccache gcc`
etc. At that time, it seems that it was necessary because
`build.filename(command)` quoted the whole `command`, but now it does not
quote, so we can just run `build.filename(command)`.

### Example

  ```console
  $ echo 1 > src/a.c
  $ rake -v
  ```

#### Before this patch:

  ```console
  (snip)
  gcc -std=gnu99 -g -O3 -Wall -Wundef -Wdeclaration-after-statement -Werror-implicit-function-declaration -Wwrite-strings -I"/mruby/mruby/include" -MMD -o "/mruby/mruby/build/host/src/a.o" -c "/mruby/mruby/src/a.c"
  /mruby/mruby/src/a.c:1:1: error: expected identifier or '('
  1
  ^
  1 error generated.
  gcc -std=gnu99 -g -O3 -Wall -Wundef -Wdeclaration-after-statement -Werror-implicit-function-declaration -Wwrite-strings -I"/mruby/mruby/include" -MMD -o "/mruby/mruby/build/host/src/a.o" -c "/mruby/mruby/src/a.c"
  /mruby/mruby/src/a.c:1:1: error: expected identifier or '('
  1
  ^
  1 error generated.
  rake aborted!
  (snip)
  ```

#### After this patch:

  ```console
  (snip)
  gcc -std=gnu99 -g -O3 -Wall -Wundef -Wdeclaration-after-statement -Werror-implicit-function-declaration -Wwrite-strings -I"/mruby/mruby/include" -MMD -o "/mruby/mruby/build/host/src/a.o" -c "/mruby/mruby/src/a.c"
  /mruby/mruby/src/a.c:1:1: error: expected identifier or '('
  1
  ^
  1 error generated.
  rake aborted!
  (snip)
  ```
2020-11-13 21:49:12 +09:00
Yukihiro "Matz" Matsumoto 7fb62670a9 Merge pull request #5127 from shuujii/include-size-of-iv-table-in-ObjectSpace.memsize_of-to-Hash-object
Include size of iv table in `ObjectSpace.memsize_of` to `Hash` object
2020-11-13 18:13:46 +09:00
KOBAYASHI Shuji 292a096118 Include size of iv table in ObjectSpace.memsize_of to Hash object 2020-11-13 16:59:45 +09:00
Yukihiro "Matz" Matsumoto 75beb55c2a Merge pull request #5126 from shuujii/use-enable_sanitizer-to-simplify-build_config-clang-asan.rb
Use `enable_sanitizer` to simplify `build_config/clang-asan.rb`
2020-11-13 16:47:20 +09:00
Yukihiro "Matz" Matsumoto f8ce3bec13 Merge pull request #5125 from shuujii/rename-mrb_os_memsize_of_hash_table-to-mrb_hash_memsize
Rename `mrb_os_memsize_of_hash_table` to `mrb_hash_memsize`
2020-11-13 16:45:52 +09:00
KOBAYASHI Shuji bad6223914 Use enable_sanitizer to simplify build_config/clang-asan.rb 2020-11-13 16:30:18 +09:00
KOBAYASHI Shuji ac4eb99629 Rename mrb_os_memsize_of_hash_table to mrb_hash_memsize
* The term `hash_table` can be misleading because the return value of this
  function includes memory usage of entire `Hash` object, including not only
  hash table part but also entry list part, etc.
* This function takes a `Hash` object as a receiver and is defined in
  `src/hash.c`, so it is natural to have a `mrb_hash_` prefix.
2020-11-13 16:18:32 +09:00
Yukihiro "Matz" Matsumoto af13cfb7d5 Merge pull request #5122 from shuujii/change-name-and-usage-of-presym-macros
Change name and usage of presym macros
2020-11-13 14:05:26 +09:00
KOBAYASHI Shuji 89f591485b Change name and usage of presym macros
To be also able to build mruby without presym in the future. However,
`MRB_QSYM` has been removed and changed as follows:

### Example

|       Type                | Symbol |  Previous Style  |   New Style    |
|---------------------------|--------|------------------|----------------|
| Operator                  | &      | MRB_QSYM(and)    | MRB_OPSYM(and) |
| Class Variable            | @@foo  | MRB_QSYM(00_foo) | MRB_CVSYM(foo) |
| Instance Variable         | @foo   | MRB_QSYM(0_foo)  | MRB_IVSYM(foo) |
| Method with Bang          | foo!   | MRB_QSYM(foo_b)  | MRB_SYM_B(foo) |
| Method with Question mark | foo?   | MRB_QSYM(foo_p)  | MRB_SYM_Q(foo) |
| Mmethod with Equal        | foo=   | MRB_QSYM(foo_e)  | MRB_SYM_E(foo) |

This change makes it possible to define, for example, `MRB_IVSYM(foo)` as
`mrb_intern_lit(mrb, "@" "foo")`, which is useful if we support building
without presym in the future.
2020-11-13 13:41:20 +09:00
Yukihiro "Matz" Matsumoto 280cb80a0d Merge pull request #5124 from shuujii/remove-unused-argument-of-mrb_obj_iv_tbl_memsize
Remove unused argument of `mrb_obj_iv_tbl_memsize`
2020-11-12 22:18:57 +09:00
KOBAYASHI Shuji ff2ef44c0e Remove unused argument of mrb_obj_iv_tbl_memsize 2020-11-12 20:19:41 +09:00
Yukihiro "Matz" Matsumoto 6a5e97b448 Merge pull request #5121 from shuujii/reduce-memory-usage-of-Hash-object
Reduce memory usage of Hash object
2020-11-10 21:56:42 +09:00
Yukihiro "Matz" Matsumoto cc20c5ca3a Merge pull request #5120 from kou/mrb-exe-new-str-lit-typo
Fix typo in backward compatible mrb_exc_new_str_lit() macro
2020-11-10 16:07:36 +09:00
Sutou Kouhei a00eabbf5d Fix typo in backward compatible mrb_exc_new_str_lit() macro 2020-11-10 16:03:05 +09:00
KOBAYASHI Shuji f2d8db39be Reduce memory usage of Hash object
## Implementation Summary

* Change entry list from segmented list to flat array.
* Change value of hash bucket from pointer to entry to index of entry list,
  and represent it by variable length bits according to capacity of hash
  buckets.
* Store management information about entry list and hash table to `struct
  RHash` as much as possible.

## Benchmark Summary

Only the results of typical situations on 64-bit Word-boxing are present
here. For more detailed information, including consideration, see below
(although most of the body is written in Japanese).

* https://shuujii.github.io/mruby-hash-benchmark

### Memory Usage

Lower value is better.

| Hash Size |   Baseline    |      New      |   Factor   |
|----------:|--------------:|--------------:|-----------:|
|        16 |          344B |          256B |   0.74419x |
|        40 |        1,464B |          840B |   0.57377x |
|       200 |        8,056B |        3,784B |   0.46971x |
|       500 |       17,169B |        9,944B |   0.57949x |

### Performance

Higher value is better.

#### `mrb_hash_set`

| Hash Size |   Baseline    |      New      |   Factor   |
|----------:|--------------:|--------------:|-----------:|
|        16 |  1.41847M i/s |  1.36004M i/s |   0.95881x |
|        40 |  0.39224M i/s |  0.31888M i/s |   0.81296x |
|       200 |  0.03780M i/s |  0.04290M i/s |   1.13494x |
|       500 |  0.01225M i/s |  0.01314M i/s |   1.07275x |

#### `mrb_hash_get`

| Hash Size |   Baseline    |      New      |   Factor   |
|----------:|--------------:|--------------:|-----------:|
|        16 | 26.05920M i/s | 30.19543M i/s |   1.15872x |
|        40 | 44.26420M i/s | 32.75781M i/s |   0.74005x |
|       200 | 44.55171M i/s | 31.56926M i/s |   0.70860x |
|       500 | 39.19250M i/s | 29.73806M i/s |   0.75877x |

#### `mrb_hash_each`

| Hash Size |   Baseline    |      New      |   Factor   |
|----------:|--------------:|--------------:|-----------:|
|        16 | 25.11964M i/s | 30.34167M i/s |   1.20789x |
|        40 | 11.74253M i/s | 13.25539M i/s |   1.12884x |
|       200 |  2.01133M i/s |  2.97214M i/s |   1.47770x |
|       500 |  0.87411M i/s |  1.21178M i/s |   1.38631x |

#### `Hash#[]=`

| Hash Size |   Baseline    |      New      |   Factor   |
|----------:|--------------:|--------------:|-----------:|
|        16 |  0.50095M i/s |  0.56490M i/s |   1.12764x |
|        40 |  0.19132M i/s |  0.18392M i/s |   0.96129x |
|       200 |  0.03624M i/s |  0.03256M i/s |   0.89860x |
|       500 |  0.01527M i/s |  0.01236M i/s |   0.80935x |
#### `Hash#[]`

| Hash Size |   Baseline    |      New      |   Factor   |
|----------:|--------------:|--------------:|-----------:|
|        16 | 11.53211M i/s | 12.78806M i/s |   1.10891x |
|        40 | 15.26920M i/s | 13.37529M i/s |   0.87596x |
|       200 | 15.28550M i/s | 13.36410M i/s |   0.87430x |
|       500 | 14.57695M i/s | 12.75388M i/s |   0.87494x |

#### `Hash#each`

| Hash Size |   Baseline    |      New      |   Factor   |
|----------:|--------------:|--------------:|-----------:|
|        16 |  0.30462M i/s |  0.27080M i/s |   0.88898x |
|        40 |  0.12912M i/s |  0.11704M i/s |   0.90642x |
|       200 |  0.02638M i/s |  0.02402M i/s |   0.91071x |
|       500 |  0.01066M i/s |  0.00959M i/s |   0.89953x |

#### `Hash#delete`

| Hash Size |   Baseline    |      New      |   Factor   |
|----------:|--------------:|--------------:|-----------:|
|        16 |  7.84167M i/s |  6.96419M i/s |   0.88810x |
|        40 |  6.91292M i/s |  7.41427M i/s |   1.07252x |
|       200 |  3.75952M i/s |  7.32080M i/s |   1.94727x |
|       500 |  2.10754M i/s |  7.05963M i/s |   3.34970x |

#### `Hash#shift`

| Hash Size |   Baseline    |      New      |   Factor   |
|----------:|--------------:|--------------:|-----------:|
|        16 | 14.66444M i/s | 13.18876M i/s |   0.89937x |
|        40 | 11.95124M i/s | 11.10420M i/s |   0.92913x |
|       200 |  5.53681M i/s |  7.88155M i/s |   1.42348x |
|       500 |  2.96728M i/s |  5.40405M i/s |   1.82121x |

#### `Hash#dup`

| Hash Size |   Baseline    |      New      |   Factor   |
|----------:|--------------:|--------------:|-----------:|
|        16 |  0.15063M i/s |  5.37889M i/s |  35.71024x |
|        40 |  0.06515M i/s |  3.38196M i/s |  51.91279x |
|       200 |  0.01359M i/s |  1.46538M i/s | 107.84056x |
|       500 |  0.00559M i/s |  0.75411M i/s | 134.88057x |

### Binary Size

Lower value is better.

|    File    |   Baseline    |      New      |  Factor   |
|:-----------|--------------:|--------------:|----------:|
| mruby      |      730,408B |      734,176B |  1.00519x |
| libmruby.a |    1,068,134B |    1,072,846B |  1.00441x |

## Other Fixes

The following issues have also been fixed in the parts where there was some
change this time.

* [Heap use-after-free in `Hash#value?`](https://gist.github.com/shuujii/30e4fcd5844a4112a0ecd4a5b3483101#file-heap-use-after-free-in-hash-value-md)
* [Heap use-after-free in `ht_hash_equal`](https://gist.github.com/shuujii/30e4fcd5844a4112a0ecd4a5b3483101#file-heap-use-after-free-in-ht_hash_equal-md)
* [Heap use-after-free in `ht_hash_func`](https://gist.github.com/shuujii/30e4fcd5844a4112a0ecd4a5b3483101#file-heap-use-after-free-in-ht_hash_func-md)
* [Heap use-after-free in `mrb_hash_merge`](https://gist.github.com/shuujii/30e4fcd5844a4112a0ecd4a5b3483101#file-heap-use-after-free-in-mrb_hash_merge-md)
* [Self-replacement does not work for `Hash#replace`](https://gist.github.com/shuujii/30e4fcd5844a4112a0ecd4a5b3483101#file-self-replacement-does-not-work-for-hash-replace-md)
* [Repeated deletes and inserts increase memory usage of `Hash`](https://gist.github.com/shuujii/30e4fcd5844a4112a0ecd4a5b3483101#file-repeated-deletes-and-inserts-increase-memory-usage-of-hash-md)
* [`Hash#rehash` does not reindex completely](https://gist.github.com/shuujii/30e4fcd5844a4112a0ecd4a5b3483101#file-hash-rehash-does-not-reindex-completely-md)
* `mrb_hash_delete_key` does not cause an error for frozen object
* `mrb_hash_new_capa` does not allocate required space first
* [`mrb_os_memsize_of_hash_table` result is incorrect](https://github.com/mruby/mruby/pull/5032#discussion_r457994075)
2020-11-10 15:21:49 +09:00
Yukihiro "Matz" Matsumoto 352c4755b2 Merge pull request #5118 from dearblue/mrb_value
Define `mrb_value` in struct for Word/NaN boxing
2020-11-10 11:50:59 +09:00
Yukihiro "Matz" Matsumoto 0df460892c Add range check before casting float to integer. 2020-11-09 11:35:54 +09:00
Yukihiro "Matz" Matsumoto 82249bb973 Merge pull request #5119 from kou/mruby-io-standard-io
Don't check FD for STDIN/STDOUT/STDERR; #5114
2020-11-09 11:19:21 +09:00
Sutou Kouhei 0cba422488 Don't check FD for STDIN/STDOUT/STDERR; #5114
We don't need to require valid STDIN/STDOUT/STDERR. If we require it,
we can't use mruby on an environment that doesn't have valid
STDIN/STDOUT/STDERR such as Windows service process. Windows service
process doesn't have valid STDIN.
2020-11-09 10:27:24 +09:00
Yukihiro "Matz" Matsumoto 9288805435 Merge pull request #5117 from dearblue/nan-32bit
Fixed build NaN boxing with 32-bit CPU mode
2020-11-08 14:38:18 +09:00
dearblue e993b83c50 Fixed build NaN boxing with 32-bit CPU mode
`SET_CPTR_VALUE()` requires the `p` field on 32-bit CPU mode.
2020-11-08 14:15:19 +09:00
dearblue 926ec1dc7e Define mrb_value in struct for Word/NaN boxing
This is to make it possible to distinguish between `mrb_value` and `mrb_sym` in C++ "Function overloading" and C11 "Generic selection".
2020-11-08 14:14:00 +09:00
Yukihiro "Matz" Matsumoto e2829bef0d Merge pull request #5115 from dearblue/nogems
Suppress `-Wunused-function`
2020-11-08 12:30:29 +09:00
dearblue 06d231d372 Suppress -Wunused-function
If no gem was specified, it was warning because `init_mrbgems()` was not used.

ref: #4250
2020-11-08 10:52:04 +09:00
Yukihiro "Matz" Matsumoto 8455344bf3 Skip too big left shift in flo_shift(). 2020-11-06 12:52:18 +09:00
Yukihiro "Matz" Matsumoto 2a52ebcc56 Avoid negating MRB_INT_MIN which is impossible. 2020-11-06 12:51:44 +09:00
Yukihiro "Matz" Matsumoto d93fc6593f Fix wrong integer casting. 2020-11-06 12:42:43 +09:00
Yukihiro "Matz" Matsumoto f77113e841 Fix a bug with printing (null) local variable name for a register. 2020-11-05 16:55:23 +09:00
Yukihiro "Matz" Matsumoto d9bd77b180 Fix A.new([[1,2],3]).flatten to return Array. 2020-11-05 14:29:26 +09:00
Yukihiro "Matz" Matsumoto 4e535080dc Use INT32_{MAX,MIN} to specify integer ranges. 2020-11-05 14:29:26 +09:00
Yukihiro "Matz" Matsumoto afba74ff50 Add Array.new([1,2,3]) initialization. 2020-11-05 14:29:25 +09:00
Yukihiro "Matz" Matsumoto aa4d8e9a2b Avoid integer overflow in comparison. 2020-11-04 14:27:34 +09:00
Yukihiro "Matz" Matsumoto 0113db6716 Add cast to silence int conversion warnings. 2020-11-04 14:18:47 +09:00
Yukihiro "Matz" Matsumoto b77a0f69a3 Fix a bug with big negative integers. 2020-11-04 14:15:51 +09:00
Yukihiro "Matz" Matsumoto 5d85045fcb Update mruby3.md about new instructions. 2020-11-04 14:01:56 +09:00
Yukihiro "Matz" Matsumoto d13df1536d Add a new instruction OP_LOADI32.
That loads 32 bit integer bypassing pool access.
2020-11-04 14:01:04 +09:00
Yukihiro "Matz" Matsumoto f8156ae175 Merge pull request #5113 from shuujii/reduce-recompilation-when-updating-presym-target-files
Reduce recompilation when updating presym target files
2020-11-03 18:13:56 +09:00
Yukihiro "Matz" Matsumoto b08da9c30b Merge pull request #5112 from shuujii/fix-dependencies-of-y.tab.o
Fix dependencies of `y.tab.o`
2020-11-03 18:12:50 +09:00
Yukihiro "Matz" Matsumoto 963b44286a Use C99 __func__ instead of __FUNCTION__; #5107 2020-11-03 18:03:23 +09:00
KOBAYASHI Shuji 82a2a5657c Reduce recompilation when updating presym target files
Fix that updating presym target files would recompile almost all files even
if symbols did not change.
2020-11-03 16:03:46 +09:00
KOBAYASHI Shuji ea5d0a593c Fix dependencies of y.tab.o
In the case of `y.tab.o`, `y.tab.d` was not read, so `y.tab.c` was not
recompiled by updating header files.

It seemed that the cause was overwriting the rake rule, so I deleted
unnecessary settings.
2020-11-03 15:56:08 +09:00
Yukihiro "Matz" Matsumoto b7e8406f6c Add new instructions to handle symbols/literals >255; fix #5109
New instructions:
  * OP_LOADL16
  * OP_LOADSYM16
  * OP_STRING16

Size of pools, symbols are `int16_t` but offset representation in the
bytecode was 8 bits. Size of child `irep` array is `int16_t`, too but
this change does not address it.
2020-11-03 14:58:44 +09:00
Yukihiro "Matz" Matsumoto 0be5b266b6 format '%p' expects argument of type 'void *'; #5107 2020-11-02 23:04:12 +09:00
Yukihiro "Matz" Matsumoto ac51a58683 ISO C does not allow extra ';' outside of a function; #5107 2020-11-02 23:04:12 +09:00
Yukihiro "Matz" Matsumoto 436765eb94 Revert "Remove long-time deprecated minirake."
`minirake` was still used in many occasions.
This reverts commit 3847c7eb64.
2020-11-02 15:14:36 +09:00
Yukihiro "Matz" Matsumoto ddfac9aba0 Search gem from MRUBY_ROOT if build config is in build_config. 2020-11-02 15:14:36 +09:00
Yukihiro "Matz" Matsumoto 9233d28ac7 Make Ranges frozen as Ruby3.0. 2020-11-02 15:14:36 +09:00
Yukihiro "Matz" Matsumoto dc886873bc Replace R-assignment by single-line pattern matching.
Since `R-assignment` in CRuby is abandoned.  Single-line pattern matching
in `mruby` only matches single local variable at the moment. Currently
it works as a right assignment to a local variable. It will be enhanced
in the future.
2020-11-02 15:14:36 +09:00
Yukihiro "Matz" Matsumoto 70ee936367 Update the build description in mruby3.md. 2020-11-02 15:14:35 +09:00
Yukihiro "Matz" Matsumoto c427776910 Merge pull request #5111 from shuujii/fix-parallel-build
Fix parallel build
2020-11-02 15:14:25 +09:00
KOBAYASHI Shuji 9a5c78dc26 Fix parallel build
When `rake -m` and so on are used to build in parallel, building may be
started before presym files are generated. Then, for example, the following
error occurs and this issue is fixed.

```console
In file included from /Users/shuujii/mruby/mruby/include/mruby.h:92:
/mruby/mruby/include/mruby/presym.h:16:10: fatal error: '../build/presym.inc' file not found
#include <../build/presym.inc>
         ^~~~~~~~~~~~~~~~~~~~~
```
2020-11-02 14:13:33 +09:00
Yukihiro "Matz" Matsumoto 331b119313 Merge pull request #5110 from bshastry/fix-mruby-ossfuzz-build
ossfuzz: Fix mruby include paths
2020-11-01 22:19:39 +09:00
Bhargava Shastry b5e4e283e8 ossfuzz: Fix mruby include paths 2020-11-01 13:24:03 +01:00
Yukihiro "Matz" Matsumoto f000856d68 Merge pull request #5108 from mimaki/display_preview_version
Add `preview` to version.
2020-11-01 17:19:01 +09:00
mimaki 943029954f Fix mruby -v option test. 2020-11-01 14:19:19 +09:00
mimaki bc9566eb64 Add preview to version. 2020-11-01 13:42:35 +09:00
Yukihiro "Matz" Matsumoto 6cc29ed377 Fix the condition to detect core mrbgems. 2020-10-30 07:15:11 +09:00
Yukihiro "Matz" Matsumoto e4d4192c3a Exclude symbols from mruby-test gem only used for tests. 2020-10-29 23:16:54 +09:00
Yukihiro "Matz" Matsumoto a5d05ea8b7 Use mrb dump format for non core mrbgems by default.
If you confirm the gem is cdump safe, add `spec.enable_cdump` in
`mrbgem.rake` file. Some external gems e.g. `mruby-mgem-template` do
not work with cdump.
2020-10-29 22:52:29 +09:00
Yukihiro "Matz" Matsumoto 86981dafb1 Use clear if instead of unless for condition. 2020-10-29 22:52:29 +09:00
Yukihiro "Matz" Matsumoto 5dff2194a2 Use instance variable @dir instead of access method dir. 2020-10-29 22:52:29 +09:00
Yukihiro "Matz" Matsumoto 78f7162508 Remove mrblib_dir and objs_dir configuration from gems.
Always use `mrblib` and 'src` for directory names.
2020-10-29 22:52:28 +09:00
Yukihiro "Matz" Matsumoto ccca5e521c Merge pull request #5105 from shuujii/fix-typo-in-Range-last
Fix typo in `Range#last`
2020-10-29 22:52:17 +09:00
Yukihiro "Matz" Matsumoto 212800a901 Merge pull request #5104 from shuujii/fix-typo-in-doc-guides-compile.md
Fix typo in `doc/guides/compile.md` [ci skip]
2020-10-29 22:51:43 +09:00
KOBAYASHI Shuji 353ecd7119 Fix typo in Range#last 2020-10-29 18:40:42 +09:00
KOBAYASHI Shuji 0736d7c99f Fix typo in doc/guides/compile.md [ci skip] 2020-10-29 18:27:11 +09:00
Yukihiro "Matz" Matsumoto 385cebe0b9 Use `default' gembox by default.
I changed to use `full-core` gembox for debugging. It should have been
reverted before `mruby3` branch was merged.
2020-10-29 11:53:10 +09:00
Yukihiro "Matz" Matsumoto 3847c7eb64 Remove long-time deprecated minirake. 2020-10-29 11:49:05 +09:00
Yukihiro "Matz" Matsumoto 24ffa4386a The path of the gem should be relative from MRUBY_ROOT.
It was relative from the directory of the build configuration file, but
the document says it's relative from `MRUBY_ROOT`. When the default
configuration file was `MRUBY_ROOT/build_config.rb`, it was OK for most
of the cases.
2020-10-29 11:49:05 +09:00
Yukihiro "Matz" Matsumoto 33742d941f Move build_config.rb -> build_config/default.rb; ref #5098
In addition, update the documents referring `build_config.rb` which is
no longer used. The new `build_config.rb` describes the new configuration
structure in the comment.
2020-10-29 11:49:05 +09:00
Yukihiro "Matz" Matsumoto c1ad4c4261 Restore original name for default build_config_name; ref #5098 2020-10-29 10:46:20 +09:00
Yukihiro "Matz" Matsumoto 41d5df03ed Use Dir.glob instead of map. 2020-10-29 10:43:09 +09:00
Yukihiro "Matz" Matsumoto 32ffd81011 Add beginless/endless ranges tests. 2020-10-29 10:43:09 +09:00
Yukihiro "Matz" Matsumoto cb636215bb Raise exception from Range#first with beginless ranges. 2020-10-29 10:43:08 +09:00
Yukihiro "Matz" Matsumoto d35677f213 Implement Range#last in mruby-range-ext in Ruby.
This reduce unnecessary calls of `mrb_funcall()`.
2020-10-29 10:43:08 +09:00
Yukihiro "Matz" Matsumoto 76eafa4608 Merge pull request #5098 from shuujii/revert-MRUBY_TARGET-mechanism
Revert `MRUBY_TARGET` mechanism; ref #5096
2020-10-29 10:42:56 +09:00
Yukihiro "Matz" Matsumoto 78d185efb9 Merge pull request #5102 from dearblue/c++-exc
Fixed build with `conf.enable_cxx_exception`
2020-10-29 10:41:56 +09:00
Yukihiro "Matz" Matsumoto f24658816c Merge pull request #5103 from shuujii/fix-mrb_obj_id-to-Float
Fix `mrb_obj_id` to `Float`
2020-10-29 07:01:09 +09:00
KOBAYASHI Shuji 43863d5f01 Fix mrb_obj_id to Float 2020-10-28 23:03:26 +09:00
dearblue 336f0de8bb Fixed build with conf.enable_cxx_exception
The problem was manifested by commit 5069fb15e4.
2020-10-28 21:10:33 +09:00
Yukihiro "Matz" Matsumoto 07224f8ed9 Merge pull request #5101 from dearblue/env-new
Reorganize `env_new()` as `mrb_env_new()`
2020-10-24 23:03:58 +09:00
dearblue 69a6bb1f12 Reorganize env_new() as mrb_env_new()
The `mrb_env_new()` function is a global function, but it is still treated as an internal function.
2020-10-24 22:29:31 +09:00
Yukihiro "Matz" Matsumoto 17247c51f2 Merge pull request #5099 from dearblue/getargs-array
Prohibit array changes by "a"/"*" specifier of `mrb_get_args()`
2020-10-23 15:43:18 +09:00
Yukihiro "Matz" Matsumoto fd38b9217d Merge pull request #5100 from dearblue/getargv-array
Prohibit array changes by `mrb_get_argv()`
2020-10-23 15:41:46 +09:00
dearblue edc49f9d26 Prohibit array changes by mrb_get_argv()
The `mrb_get_argv()` function will now return `const mrb_value *`.
This is because it is difficult for the caller to check if it is a splat argument (array object) and to write-barrier if necessary.
2020-10-22 23:22:29 +09:00
dearblue f0a64329b1 Prohibit array changes by "a"/"*" specifier of mrb_get_args()
The "a"/"*" specifier of the `mrb_get_args()` function will now return `const mrb_value *`.
This is because it is difficult for the caller to check if it is an array object and write-barrier if necessary.
And it requires calling `mrb_ary_modify()` on the unmodified array object, which is also difficult (this is similar to #5087).
2020-10-22 22:55:35 +09:00
KOBAYASHI Shuji 81c2108819 Revert MRUBY_TARGET mechanism; ref #5096
* In explanation of mruby, the expression `build_config.rb` is frequently
  used including official documents, so I think that it will not make sense
  if the file is no longer used.
* The `MRUBY_TARGET` mechanism seems to have little improvement, so I don't
  think it should be changed to avoid unnecessary confusion.
* `MRUBY_TARGET` and `MRuby.targets` represent somewhat different things,
  so using the same term "target" is a bit confusing.

The mechanism that can be written short when using a file under
`build_config` (renamed from `target`) directory remains
(`build_config/${MRUBY_CONFIG}.rb` is used if the path specified
in `MRUBY_CONFIG` doesn't exist).
2020-10-19 15:03:22 +09:00
Yukihiro "Matz" Matsumoto 27492e53a0 Add startless range (another part of #5085)
Ref #5093; close #5085
2020-10-16 17:29:23 +09:00
Yukihiro "Matz" Matsumoto 8d36393a5b Remove uninitialized local variable warning.
Fix for #5093
2020-10-16 16:47:04 +09:00
Yukihiro "Matz" Matsumoto 3c55cb0895 Turn of enable_debug by default; ref #5096
It was once turned off by #4045
2020-10-16 16:37:31 +09:00
Yukihiro "Matz" Matsumoto a373c48f3b Typo fixed; ref #5095
Thanks to @YunzheZJU
2020-10-16 13:34:32 +09:00
Yukihiro "Matz" Matsumoto c9db7d3531 Use conf.enable_debug; close #5095
According to `doc/guides/compile.md`; thanks to @YunzheZJU
2020-10-16 13:32:58 +09:00
Yukihiro "Matz" Matsumoto 045761390d Merge pull request #5094 from mruby-Forum/mruby3-preview
mruby 3.0.0-preview.
2020-10-16 10:56:54 +09:00
Hiroshi Mimaki 0589749952 mruby 3.0.0-preview. 2020-10-16 10:43:03 +09:00
Yukihiro "Matz" Matsumoto 4b5dd5683b Merge branch 'zubycz-work_for_merge' 2020-10-15 18:35:53 +09:00
Yukihiro "Matz" Matsumoto 6b457d2c00 Merge branch 'work_for_merge' of https://github.com/zubycz/mruby into zubycz-work_for_merge 2020-10-15 18:35:13 +09:00
Yukihiro "Matz" Matsumoto c779413df3 Fix out of bound access in parse.y. 2020-10-15 18:32:27 +09:00
Yukihiro "Matz" Matsumoto 9cebddf9fe Merge pull request #5084 from mruby/mruby3
Mruby3
2020-10-15 18:31:06 +09:00
Yukihiro "Matz" Matsumoto 21e07d6113 Add indent to lv in the C dump. 2020-10-14 20:26:06 +09:00
Yukihiro "Matz" Matsumoto 5b40bb8d15 Avoid using C struct dump for test Ruby code.
Files under `test/t` and `mrbgem/*/test` are for tests, not for actual
execution. So symbols in those files need not to be pre-allocated. This
change slightly reduce the memory consumption.
2020-10-14 15:52:14 +09:00
taiyoslime bec4d05340 Introduce endless range (a part of #5085)
Co-Authored-By: n4o847 <22975590+n4o847@users.noreply.github.com>
Co-Authored-By: smallkirby <ssmallkirby@gmail.com>
2020-10-13 14:09:36 +09:00
Yukihiro "Matz" Matsumoto 8c276f95be Merge pull request #5091 from zubycz/remove_unnecessary_assignment
Remove unnecessary assignment in String#upto
2020-10-12 18:23:22 +09:00
Yukihiro "Matz" Matsumoto 82046ff26e Revert "Add a new function mrb_exc_protect()."
This reverts commit 8746a6fe4e7bda8a0fbc0eaece9314ec51a0c255.

We already have `mrb_protect()`, `mrb_ensure()` and `mrb_rescue()`
functions. If you need to handle exceptions from C functions, use those
functions above.
2020-10-12 18:20:30 +09:00
Yukihiro "Matz" Matsumoto 3d6adccfbe Add a new function mrb_exc_protect().
`mrb_exc_protect()` takes two C functions, `body` to be executed first,
and `resc` to be executed when an error happens during `body` execution.
Since `mrb_exc_protect()` should be compiled with the proper compiler,
we will not see the problem like #5088 that was caused by `setjmp()` and
`throw` mixture.
2020-10-12 18:20:29 +09:00
Yukihiro "Matz" Matsumoto 5069fb15e4 Cause error explicitly from MRB_TRY() with cxx_exception; ref #5088
`MRB_TRY()` does not work when compiled by C compiler with `cxx_exception`
configuration. We should explicitly warn.
2020-10-12 18:20:29 +09:00
Yukihiro "Matz" Matsumoto 7ca59ecea2 Revert e2e6554b56 not to use MRB_TRY(); close #5088
`MRB_TRY()` does not work when compiled by C compiler with `cxx_exception`,
due to the mixture of `setjmp()` used by `mirb.c` and `throw` used by
the core.  The original intension of e2e6554b56 is to protect code from
signal interruption, but the signal interruption is not well-defined in
mruby anyway.
2020-10-12 18:20:29 +09:00
Yukihiro "Matz" Matsumoto 041351fb05 No need to get the irep record size twice. 2020-10-12 18:20:28 +09:00
Yukihiro "Matz" Matsumoto 34356974ee Update MRB_FLOAT_FMT to always use double precision. 2020-10-12 18:20:28 +09:00
Yukihiro "Matz" Matsumoto d2b548de60 Remove the length of `Float' pool from the binary dump.
Also fixed the size calculation of `irep` dump, that could cause memory
corruption.
2020-10-12 18:20:28 +09:00
Yukihiro "Matz" Matsumoto c80ece2149 Add bintest to host-m32 target. 2020-10-12 18:20:27 +09:00
Yukihiro "Matz" Matsumoto 356b719fef Remove DEBUG_ONLY_EXPR() from CHECKPOINT_* macros; ref #5060
To allow C++ compilation. Fix suggested by @dearblue.
2020-10-12 18:20:27 +09:00
Yukihiro "Matz" Matsumoto 896338e219 Unify mrb_str_to_str to mrb_obj_as_string.
Redirect `mrb_str_to_str` to `mrb_obj_as_string` via C macro.
Inspired by #5082
2020-10-12 18:20:26 +09:00
Yukihiro "Matz" Matsumoto bff79112a6 Dump/load 16 bits for ilen and slen in irep.
Those types are `uint16_t` in definition. Also we no longer need padding
for `iseq`.
2020-10-12 18:20:26 +09:00
Yukihiro "Matz" Matsumoto f1d02bfc15 Clarify the meaning of MRB_IREP_STATIC; ref #5084 2020-10-12 18:20:26 +09:00
Yukihiro "Matz" Matsumoto c1f5fdafb6 Remove duplicated constant IREP_TT_SFLAG; #5084 2020-10-12 18:20:25 +09:00
Yukihiro "Matz" Matsumoto 5d1d94d911 Use Markdown section marker #; ref #5084 [ci skip]
The fix was proposed by @dearblue
2020-10-12 18:20:25 +09:00
Yukihiro "Matz" Matsumoto 762556b6e8 Add const modifier to table in mrb_kwargs; #5084
The fix was proposed by @dearblue
2020-10-12 18:20:24 +09:00
Yukihiro "Matz" Matsumoto 618c589162 Should use PRId32 to dump .i32; ref #5084
The fix was proposed by @dearblue
2020-10-12 18:20:24 +09:00
Yukihiro "Matz" Matsumoto ab2b42d363 Update bintest of mruby-bin-debugger.
Need to support `int / int -> int` update.
2020-10-12 18:20:24 +09:00
Yukihiro "Matz" Matsumoto b9007244bd Add const before struct mrb_irep in mruby-bin-debugger gem. 2020-10-12 18:20:23 +09:00
Yukihiro "Matz" Matsumoto 7932523052 Remove host-debug internal target.
Target `host-debug` to use `host` internal target with debugging
configuration.
2020-10-12 18:20:23 +09:00
Yukihiro "Matz" Matsumoto 12881ccb05 Use NULL instead of 0; close #2467
The PR was from @cubicdaiya.
2020-10-12 18:20:23 +09:00
Yukihiro "Matz" Matsumoto 3ff2757bf7 Fix mrb_int_mul_overflow() to check either operand being zero. 2020-10-12 18:20:22 +09:00
Yukihiro "Matz" Matsumoto 4dcc1819c9 Embed debug information to resolve Windows VC's issue. 2020-10-12 18:20:22 +09:00
Yukihiro "Matz" Matsumoto 21ee56d82a Adjust backslash position in multi-line macros. 2020-10-12 18:20:21 +09:00
Yukihiro "Matz" Matsumoto 55a2ff5faf Use MRB_INT_MAX instead of INT_MAX according to variable type. 2020-10-12 18:20:21 +09:00
Kondo Uchio ed97c1779e Remove duplicated pattern 2020-10-12 18:20:21 +09:00
Uchio Kondo 0d8793047d Scan ruby files in directories 2020-10-12 18:20:20 +09:00
Kondo Uchio cbb46f6975 Exact match to allowed method/variable names 2020-10-12 18:20:20 +09:00
Uchio Kondo 0c242e278d Ensure exact match for symbols like foo!/foo?/foo=
e.g. symbols like "foo[]=" make invalid C codes
2020-10-12 18:20:20 +09:00
Yukihiro "Matz" Matsumoto 932b93fd12 Skip C comments from scan target; close #5072
The original PR was skipping Ruby comments as well, but caused some
issues in test suites.
2020-10-12 18:20:19 +09:00
Yukihiro "Matz" Matsumoto a4c5824e59 Restore old function names for compatibility; ref #5070
- `mrb_check_intern()` to return `mrb_value`
- `mrb_intern_check()` to return `mrb_sym` [NEW]

Other new functions:

- `mrb_intern_check_cstr()`
- `mrb_intern_check_str()`
2020-10-12 18:20:19 +09:00
Yukihiro "Matz" Matsumoto afcf19b727 Scan source code lines from downloaded mrbgems; fix #5071 2020-10-12 18:20:18 +09:00
Yukihiro "Matz" Matsumoto 30424dfa74 Restore old function names for compatibility; fix #5070
Rename new functions:

- `mrb_convert_type(mrb,val,type,tname,method)`
   => `mrb_type_convert(mrb,val,type,tname,method)`
- `mrb_check_convert_type(mrb,val,type,tname,method)`
   => `mrb_type_convert_check(mrb,val,type,tname,method)`

Old names are defined by macros (support `tname` drop and
`char*` => `mrb_sym` conversion).
2020-10-12 18:20:18 +09:00
Yukihiro "Matz" Matsumoto 9b8e5658ce Fix integer casting on 64 bit platforms.
On platforms where `sizeof(long)` is 4, casting `(long)` can lose data
or sign information.
2020-10-12 18:20:18 +09:00
Yukihiro "Matz" Matsumoto a127ded486 Fix warning from VC regarding implicit int conversion. 2020-10-12 18:20:17 +09:00
Yukihiro "Matz" Matsumoto fe3c3bb661 Made Rational overhaul.
- Implement `Rational()` in `C`.
- Use `float` to `rational` conversion function taken from:
  https://rosettacode.org/wiki/Convert_decimal_number_to_rational#C
2020-10-12 18:20:17 +09:00
Yukihiro "Matz" Matsumoto f9e781d83a Avoid unsigned int; Use mrb_int instead. 2020-10-12 18:20:16 +09:00
Yukihiro "Matz" Matsumoto fc8885f2f4 Use mrb_int extensively instead of int.
The mixture causes warnings on 64 bit Windows (VC).
2020-10-12 18:20:16 +09:00
Yukihiro "Matz" Matsumoto fe1ad37bfb Use goto to avoid problems with DIRECT_THREADED.
You can now use `NEXT` within `switch` statement like 7c087eb.
2020-10-12 18:20:16 +09:00
Yukihiro "Matz" Matsumoto 9e842b3a75 Extract div code in VM and make them shared by div methods. 2020-10-12 18:20:15 +09:00
Yukihiro "Matz" Matsumoto b81edb0035 Don't use NEXT within switch statement.
On non-`gcc` compatible environment, `NEXT` is translated to `break`.
2020-10-12 18:20:15 +09:00
Yukihiro "Matz" Matsumoto 86dee45f1d Remove meaningless IO.open(1<<32) test. 2020-10-12 18:20:15 +09:00
Yukihiro "Matz" Matsumoto 08f61db6ee Skip some Math.atan2() tests.
Linux `atan2(3)` man page says:

```
If  y is positive infinity (negative infinity) and x is positive infinity,
+pi/4 (-pi/4) is re‐ turned.
```

But on Microsoft VC/MinGW, `atan2()` returns `NaN` if either of
arguments is infinite. So we skip those tests on the platforms.
2020-10-12 18:20:14 +09:00
Yukihiro "Matz" Matsumoto 7f66e50ba2 Explain MRB_USE_MALLOC_TRIM; ref #5069 2020-10-12 18:20:14 +09:00
Rory OConnell 5592c7413a Remove compiler feature detection 2020-10-12 18:20:14 +09:00
Rory OConnell fff0f17b49 Better malloc_trim define name 2020-10-12 18:20:13 +09:00
Rory OConnell 2b05cf48d0 Work around removing tmp dir 2020-10-12 18:20:13 +09:00
Rory OConnell dae0de4461 Add call to malloc_trim on a full GC 2020-10-12 18:20:12 +09:00
Rory OConnell cfe8b0c81d Add methods for asking about compiler features 2020-10-12 18:20:12 +09:00
Yukihiro "Matz" Matsumoto 026726dd49 Remove obsolete MRB_WITHOUT_FLOAT macro from numeric.c. 2020-10-12 18:20:12 +09:00
Yukihiro "Matz" Matsumoto d7986b449d Change some int variables to mrb_int.
To silence some warnings. This change cancels part of 7ef3604134.
2020-10-12 18:20:11 +09:00
Yukihiro "Matz" Matsumoto 4970e24a1c Remove full-core from target/appveyor.rb. 2020-10-12 18:20:11 +09:00
Yukihiro "Matz" Matsumoto 950e60363a Update IO#popen to use keyword arguments instead of Hash args. 2020-10-12 18:20:11 +09:00
Yukihiro "Matz" Matsumoto 87c7064bad Update mrb_get_args() keyword argument support [incompatible]
* `mrb_kwargs` structure reordered (`values` and `rest` come last)
* take symbols instead of C `char*`
2020-10-12 18:20:10 +09:00
Yukihiro "Matz" Matsumoto 4cf1da9542 Separate jump destination check in OP_R_RETURN.
In the past code, the current `callinfo (ci)` was modified, thus it was
possible to pop `ci` beyond the `cibase`, that could cause out of memory
bound access for the code like the following:

```ruby
def m2
  lambda {
    Proc.new {
      return :return # return from the method
    }
  }.call.call
  :never_reached
end

p m2
```
2020-10-12 18:20:10 +09:00
Yukihiro "Matz" Matsumoto b01207ea94 Make the scope of const struct RProc *dst narrower. 2020-10-12 18:20:09 +09:00
Yukihiro "Matz" Matsumoto c2444b8424 Redefine CHECKPOINT_* macros.
By definition `mrb_assert()` called only when `MRB_DEBUG` is defined too.
But make I wanted to make clear that the local variable `current_checkpoint_tag`
is only accessed when `MRB_DEBUG` is set by wrapping with `DEBUG_ONLY_EXPR()`.
2020-10-12 18:20:09 +09:00
Yukihiro "Matz" Matsumoto 8461be11fc Include mruby/endian.h only when MRB_NO_FLOAT is undefined. 2020-10-12 18:20:09 +09:00
Yukihiro "Matz" Matsumoto 260db0f5fb Abandon packing all lower case symbols with 6 characters.
To make packed inline symbols within 31 bits, because the new method
hash tables allows only 31 bits of symbols. They use top 1 bit to maek
unused slots.
2020-10-12 18:20:08 +09:00
Yukihiro "Matz" Matsumoto 99ef00fe02 Add U prefix for mrb_sym dump.
Since `%u` of `mrb_sym` may be its MSB turned on.
2020-10-12 18:20:08 +09:00
Yukihiro "Matz" Matsumoto b9dfd0438f Don't compare int' with size_t (from sizeof()`). 2020-10-12 18:20:08 +09:00
Yukihiro "Matz" Matsumoto d0b5d720ac Use mrb_integer() instead of mrb_int().
`mrb_int()` includes implicit integer conversion, where `mrb_integer()`
does not. In this case, we know `obj` is an integer before hand.
2020-10-12 18:20:07 +09:00
Yukihiro "Matz" Matsumoto dd1ce5d53e Silence warnings from implicit integer conversions.
Caused from combination of `mrb_int`, `int` and `size_t`..
2020-10-12 18:20:07 +09:00
Yukihiro "Matz" Matsumoto 7eaaee5405 Add a new gem: mruby-catch.
Implements `catch`/`throw` non-local jump inherited from Lisp.

`catch([tag]) {|tag| block }  -> obj`

Example:
```
  catch(:foo) { 123 }               # => 123
  catch(:foo) { throw(:foo, 456) }  # => 456
  catch(:foo) { throw(:foo) }       # => nil
```
2020-10-12 18:20:07 +09:00
Yukihiro "Matz" Matsumoto 471479e723 Change float representation in mrb binary files.
From human readable (ASCII) string representation to binary dump of
IEEE754 in little endian.
2020-10-12 18:20:06 +09:00
Yukihiro "Matz" Matsumoto 397b005715 Replace the implementation of method tables in classes/modules.
They are basically the copy of instance variable tables. On my Linux
box, memory consumption of `mrbtest` measured by `valgrind` is:

- old: 17,683,830 bytes
- new: 14,283,749 bytes
2020-10-12 18:20:06 +09:00
Yukihiro "Matz" Matsumoto bf118b9006 Stop warning on 64 bit platforms. 2020-10-12 18:20:06 +09:00
Yukihiro "Matz" Matsumoto 7e3d22f095 Raname mrb_exc_new_str_lit() to mrb_exc_new_lit().
It uses `mrb_str_new_lit()` internally, but it doesn't need to express
it in the name of the function (macro).
2020-10-12 18:20:06 +09:00
Yukihiro "Matz" Matsumoto 01dbbcd553 Handle integer overflow in rational_s_new. 2020-10-12 18:20:05 +09:00
Yukihiro "Matz" Matsumoto e479a42757 Handle potential overflow in int_div and flo_idiv. 2020-10-12 18:20:05 +09:00
Yukihiro "Matz" Matsumoto 5134031e18 Use mrb_int_value() instead of mrb_fixnum_value().
Where fixnum overflow can happen.
2020-10-12 18:20:05 +09:00
Yukihiro "Matz" Matsumoto befcbd5607 Add MRB_NAN_BOXING for boxing target. 2020-10-12 18:20:04 +09:00
Yukihiro "Matz" Matsumoto 9d613159b5 Add mrb_integer() definition for MRB_NAN_BOXING. 2020-10-12 18:20:04 +09:00
Yukihiro "Matz" Matsumoto 3e71359d7a Update mruby-random gem to support 32 bit platforms.
`sizeof(rand_state)` had been bigger than `sizeof(void*)*3`. Changed
random number generator to `Xorshift96` on 32 bit platforms.
2020-10-12 18:20:04 +09:00
Yukihiro "Matz" Matsumoto 2b188ed8a1 Reorganize Integer system.
- Integrate `Fixnum` and `Integer`
- Remove `Integral`
- `int / int -> int`
- Replace `mrb_fixnum()` to `mrb_int()`
- Replace `mrb_fixnum_value()` to `mrb_int_value()`.
- Use `mrb_integer_p()` instead of `mrb_fixnum_p()`
2020-10-12 18:19:54 +09:00
n4o847 59af217779 Remove unnecessary assignment in String#upto
Co-authored-by: taiyoslime <t@iyosli.me>
Co-authored-by: smallkirby <ssmallkirby@gmail.com>
2020-10-12 16:50:22 +09:00
Yukihiro "Matz" Matsumoto 2bb84f1f1a Update build process for both host and cross compile. 2020-10-12 16:21:52 +09:00
Yukihiro "Matz" Matsumoto 850e200e84 Describe the need for -o option if multi files given. 2020-10-12 16:21:51 +09:00
Yukihiro "Matz" Matsumoto b978231bda Update usage description of mrbc. 2020-10-12 16:21:51 +09:00
Yukihiro "Matz" Matsumoto b7fe929232 Update Rakefile.
So that you can omit `host` target. Now `host-debug` works.
2020-10-12 16:21:51 +09:00
Yukihiro "Matz" Matsumoto 20ffc2206a "backport" CRuby r46756; ref #3500
Based on cremno/mruby@6bd0119
2020-10-12 16:21:50 +09:00
Yukihiro "Matz" Matsumoto caee1f68a2 Change the return type of mrb_check_intern() and friends.
They used to return `mrb_value` but now return `mrb_sym` for consistency
with other `intern` functions. If symbols are not defined, `check`
functions return `0`, instead of `nil` in the past.

It causes API incompatibility but I believe few people use those
functions out of the core, and those changes are very easy to handle,
hopefully.
2020-10-12 16:21:50 +09:00
Yukihiro "Matz" Matsumoto a4302524d0 Avoid using mrb_check_intern_str().
We call `mrb_intern_str()` later anyway, so there's no need to avoid
defining a new symbol here.
2020-10-12 16:21:49 +09:00
Yukihiro "Matz" Matsumoto 12d31c33af "backport" CRuby r46656; #2500
Based on cremno/mruby@d446192
2020-10-12 16:21:49 +09:00
Yukihiro "Matz" Matsumoto 5a7cbebc8a Remove MRB_NO_FLOAT_INLINE and MRB_WBOX_FLOAT_INLINE configuration.
They are not used from the beginning.
2020-10-12 16:21:49 +09:00
Yukihiro "Matz" Matsumoto 04fd7af23c Fixed ISO section numbers in test/t/superclass.rb. 2020-10-12 16:21:48 +09:00
Yukihiro "Matz" Matsumoto 2a92fb2516 Make division by zero cause ZeroDivisionError.
As described in ISO 15.2.30.
2020-10-12 16:21:48 +09:00
Yukihiro "Matz" Matsumoto 18e3d39ee2 Fixed wrong size calculation for memsize_of(). 2020-10-12 16:21:47 +09:00
Yukihiro "Matz" Matsumoto 55163a8a0a Rename MRB_TT_FIXNUM to MRB_TT_INTEGER.
We still have `#define MRB_TT_FIXNUM MRB_TT_INTEGER` for compatibility.
2020-10-12 16:21:47 +09:00
cremno 867268897a change linkage to internal 2020-10-12 16:21:47 +09:00
cremno 11317de468 define sprintf and format as global functions 2020-10-12 16:21:46 +09:00
cremno 857a1d9fc9 move mrbgem initialization into sprintf.c
Also remove some unnecessary code.
2020-10-12 16:21:46 +09:00
cremno b44326b561 Add tests for CRuby bug #9982
https://bugs.ruby-lang.org/issues/9982
2020-10-12 16:21:45 +09:00
KOBAYASHI Shuji 8bd1bc47b3 Always add trailing .0 in Float#inspect; ref #4225
Trailing `.0` is removed from `Float#to_s` and `Float#inspect` at
9d08025b. However, I think the more human-readable format is better
for `Float#inspect`.

For example, in the `Float#to_s` format, the failure message is not
well understood when testing values including types by `eql?` (e.g.
`Numeric#step` test).

  ```ruby
  assert "example" do
    exp = 1.0
    act = 1
    assert_operator(exp, :eql?, act)  #=> Expected 1 to be eql? 1.
  end
  ```
2020-10-12 16:21:45 +09:00
Yukihiro "Matz" Matsumoto c45674aff0 Rename mruby_version in the lockfile to mruby; close #4658 2020-10-12 16:21:44 +09:00
dearblue 80fe9838d2 Integrate Fixnum class into Integer class
* The `Fixnum` constant is now an alias for the `Integer` class.
* Remove `struct mrb_state::fixnum_class` member.
  If necessary, use `struct mrb_state::integer_class` instead.
2020-10-12 16:21:44 +09:00
KOBAYASHI Shuji 40d0d8fe0e Fix Fixnum and Float comparison in Hash lookup
```console
  $ bin/mruby -e 'p({1 => 2}.key?(1.0))'
  true
  ```

  ```console
  $ bin/mruby -e 'p({1 => 2}.key?(1.0))'
  false
  ```
2020-10-12 16:21:44 +09:00
Yukihiro "Matz" Matsumoto ee544dc881 Update the PR #4922 according to #3123.
close #3123
2020-10-12 16:21:43 +09:00
Yukihiro "Matz" Matsumoto ed32b6fcdc Update tests for integer division. 2020-10-12 16:21:43 +09:00
Yukihiro "Matz" Matsumoto c8cf9512cd Update the PR #4992 to enable integer division always. 2020-10-12 16:21:43 +09:00
Lanza 1835753f9f Update vm.c 2020-10-12 16:21:42 +09:00
Yukihiro "Matz" Matsumoto 424afa4446 Make Proc#parameters to support keyword arguments; fix #5066
TODO: Unlike CRuby, mruby's `Proc#parameters` does not distinguish
required keyword arguments and optional keyword arguments currently.
2020-10-12 16:21:42 +09:00
Yukihiro "Matz" Matsumoto 02e69d1c2c Update mruby3.md. 2020-10-12 16:21:41 +09:00
Yukihiro "Matz" Matsumoto 44a07393f4 Use xoshiro128++ instead of xorshift96/128. 2020-10-12 16:21:41 +09:00
Yukihiro "Matz" Matsumoto 0b22bf4a89 Fix rand_real to return random number [0,1) not [0,1]. 2020-10-12 16:21:41 +09:00
Yukihiro "Matz" Matsumoto 1520c97e17 Add default host target for cross compiling.
You don't have to define explicit `host` build target any more.
2020-10-12 16:21:40 +09:00
Yukihiro "Matz" Matsumoto 8a87549315 Rename float configuration option names.
- `MRB_WITHOUT_FLOAT` => `MRB_NO_FLOAT`
- `MRB_USE_FLOAT` => `MRB_USE_FLOAT32`

The former is to use `USE_XXX` naming convention. The latter is to make
sure `float` is 32bit float and not floating point number in general.
2020-10-12 16:21:40 +09:00
Yukihiro "Matz" Matsumoto ef9df5dc7d Allow MRUBY_CONFIG to specify target file out of source tree. 2020-10-12 16:21:39 +09:00
Yukihiro "Matz" Matsumoto 7dc595f98f Add a new document named mruby3.md.
That describes the changes in `mruby3`.
2020-10-12 16:21:39 +09:00
Yukihiro "Matz" Matsumoto d4b89ccc61 Add assertion we can pack function pointers in mrb_method_t.
If this assertion fails, you have to define `MRB_USE_METHOD_T_STRUCT`.
2020-10-12 16:21:39 +09:00
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
Yukihiro "Matz" Matsumoto 6e86e290e4 Rightward-assign by ASSOC.
[ruby-bugs:15921]
2020-10-12 16:21:18 +09:00
Yukihiro "Matz" Matsumoto b2398879fa Avoid including limits.h and stdint.h before mruby.h.
They are included from `mruby.h` anyway, and including it ahead can
cause some errors regarding `INT32_MAX` etc. with C++ compiler.
2020-10-12 16:21:18 +09:00
Yukihiro "Matz" Matsumoto e01648b86b Stop CXX_ABI test with VisualC++.
This combination is too hard to support. Difference between C and C++ is
too big with VisualC++. GCC and clang are OK.
2020-10-12 16:21:17 +09:00
Yukihiro "Matz" Matsumoto e0c9b53217 Run rake gensym on AppVeyor. 2020-10-12 16:21:17 +09:00
Yukihiro "Matz" Matsumoto ce30a4e04b Add const to irep structure to place data on ROM. 2020-10-12 16:21:16 +09:00
Yukihiro "Matz" Matsumoto 31877043c4 Invoke rake gensym for GitHub action build. 2020-10-12 16:21:16 +09:00
Yukihiro "Matz" Matsumoto 167a747a41 Constify irep struct for Class#new. 2020-10-12 16:21:16 +09:00
Yukihiro "Matz" Matsumoto cfc958b01a Add const qualifier to generated Proc structures. 2020-10-12 16:21:15 +09:00
Yukihiro "Matz" Matsumoto 015f06ed8e Should not mark red (i.e. ROM allocated) objects. 2020-10-12 16:21:15 +09:00
Yukihiro "Matz" Matsumoto 95169097fc Add /std:c++latest option to VC CXX_ABI build. 2020-10-12 16:21:14 +09:00
Yukihiro "Matz" Matsumoto 474545bba2 Do not define mrb_lstat unless S_ISLNK is defined. 2020-10-12 16:21:14 +09:00
Yukihiro "Matz" Matsumoto 925cd2ab8f Use int instead of mrb_int for arena index. 2020-10-12 16:21:14 +09:00
Yukihiro "Matz" Matsumoto 9debf63340 Specify the size of struct RStringEmbed array part. 2020-10-12 16:21:13 +09:00
Yukihiro "Matz" Matsumoto 0f978932e2 Use %u instead of %d to dump symbol IDs. 2020-10-12 16:21:13 +09:00
Yukihiro "Matz" Matsumoto 6488ae855f Avoid use of designated initializer for the sake of cxx_abi. 2020-10-12 16:21:13 +09:00
Yukihiro "Matz" Matsumoto d2f267a13d Add casts to silence warnings. 2020-10-12 16:21:12 +09:00
Yukihiro "Matz" Matsumoto a4a1e01e81 Add explicit gensym to GitHub Actions. 2020-10-12 16:21:12 +09:00
Yukihiro "Matz" Matsumoto ee111dd175 Clarify the use of MRB_64BIT and MRB_INT64 in dump.c and load.c.
- `MRB_64BIT`: the size of a pointer is 64 bits
- `MRB_INT64`: the size of `mrb_int` is 64 bits
2020-10-12 16:21:11 +09:00
Yukihiro "Matz" Matsumoto f0c1126997 Fix dump.c for MRB_INT32 env. 2020-10-12 16:21:11 +09:00
Yukihiro "Matz" Matsumoto b7031e8bc8 Enable NUL (\0) again. 2020-10-12 16:21:10 +09:00
Yukihiro "Matz" Matsumoto 52507b1083 Generate C struct from irep instead of binary dump. 2020-10-12 16:21:10 +09:00
Yukihiro "Matz" Matsumoto 7deb41b0e8 Generate C source file to represent mrb_irep structures.
Type `mrbc -S -B<init> -o<outfile> <rbfiles...>` to generate the C
source code that holds compiled `mrb_irep`.

Appending the following code to the bottom of the generated code,
`mruby` executes the compiled code:

```C
int
main()
{
  mrb_state *mrb = mrb_open();
  struct RProc *p = mrb_proc_new(mrb, &init_irep);
  mrb_vm_run(mrb, p, mrb_top_self(mrb), 0);
  mrb_close(mrb);
  return 0;
}
```

Eventually static compile should use this representation, instead
of `uint8_t` array that holds `mrb` data, so that we can skip
interpreting `mrb` data.
2020-10-12 16:21:09 +09:00
Yukihiro "Matz" Matsumoto f1c06eef7c Scan more symbols from Ruby files by rake gensym. 2020-10-12 16:21:09 +09:00
Yukihiro "Matz" Matsumoto 449317a251 Removed alignment pragma from -B output from mrbc.
We no longer need 4 bytes alignment after we moved to the byte oriented
instructions.
2020-10-12 16:21:09 +09:00
Yukihiro "Matz" Matsumoto d428fa0c4a Replace entire irep->pool.
Changes:
- `pool format is completely replaced
  - supported types: `STR`, `INT32`, `INT64`, `FLOAT`
  - `FLOAT` may be replaced by binary representation in the future
- insert `NUL` after string literals in `mrb` files
- `irep->pool` no longer store values in `mrb_value`
- instead it stores in `mrb_pool_value`
- less allocation
- `mrb_irep` can be stored in ROM
2020-10-12 16:21:08 +09:00
Yukihiro "Matz" Matsumoto daa37be549 Rename struct mrb_locals to struct mrb_lvinfo.
That stands for "local variable information".
2020-10-12 16:21:08 +09:00
Yukihiro "Matz" Matsumoto ad15e59cd9 Add irep C struct dump from mrbc with -S option.
But we need more work:
- recursive `irep` dump (`irep->reps`)
- pool values dump (`irep->pool`)
2020-10-12 16:21:07 +09:00
Yukihiro "Matz" Matsumoto 71eb4b2b22 Avoid use of designated initializers to generate irep struct.
Since it's not supported on VC without `/std:c++latest`. That means it
doesn't work for `cxx_api` build on Windows VC.
2020-10-12 16:21:07 +09:00
Yukihiro "Matz" Matsumoto d93b1a48d2 Make call_irep static. 2020-10-12 16:21:07 +09:00
Yukihiro "Matz" Matsumoto 3a64cde61d Add /std:c++latest to VC option in build.yml. 2020-10-12 16:21:06 +09:00
Yukihiro "Matz" Matsumoto 4684864f04 Specify new MRUBY_TARGET instead of MRUBY_CONFIG. 2020-10-12 16:21:06 +09:00
Yukihiro "Matz" Matsumoto dd8c178a73 Use static const struct mrb_irep each_irep to ininitalize each. 2020-10-12 16:21:06 +09:00
Yukihiro "Matz" Matsumoto 029c7c1116 Add const modifier to mrb_irep for code_fetch_hook. 2020-10-12 16:21:05 +09:00
Yukihiro "Matz" Matsumoto a68f005fd7 Remove remaining chomp:true option from Rakefile. 2020-10-12 16:21:05 +09:00
Yukihiro "Matz" Matsumoto 1adf93aa54 Stop Rake multitasking on Windows-VC for the time being. 2020-10-12 16:21:04 +09:00
Yukihiro "Matz" Matsumoto 26da07db15 Avoid using chomp:true option to File.readlines.
The option is not available in the old version of Ruby.
2020-10-12 16:21:04 +09:00
Yukihiro "Matz" Matsumoto 7ab7cadbbb Stringify non C identifier symbols to stop macro errors by old gcc. 2020-10-12 16:21:04 +09:00
Yukihiro "Matz" Matsumoto 2c1d209fd5 Remove rake -v option from GitHub Actions. 2020-10-12 16:21:03 +09:00
Yukihiro "Matz" Matsumoto 5a3e014e49 Constify irep members.
- `pool`
- `syms`
- `reps`
2020-10-12 16:21:03 +09:00
Yukihiro "Matz" Matsumoto 744ba80919 Add explicit cast to DROP_PRECISION macro in rational.c. 2020-10-12 16:21:02 +09:00
Yukihiro "Matz" Matsumoto 0d755e583c Build process updated:
You have to specify `TARGET` to specify a configuration, e.g.

```
rake TARGET=host-debug all test
```

When you port `mruby` to a new configuration:
1. copy an existing configuration under `target` directory
2. modify the new configuration file
3. build using the new configuration
4. send PR if you please
2020-10-12 16:21:02 +09:00
KOBAYASHI Shuji 92d8012b4e Refine .travis.yml
* Disable automatic update and clean up on `brew install` (install time
  160 sec -> 5 sec).
* Avoid using deprecated keys.
2020-10-12 16:21:02 +09:00
KOBAYASHI Shuji cc587e6535 Removed Bison related settings from .travis.yml and appveyor.yml 2020-10-12 16:21:01 +09:00
KOBAYASHI Shuji 1122124f97 Revert part of "Start GitHub Actions" (4ce3997c)
Because some changes have been overridden.
2020-10-12 16:21:01 +09:00
KOBAYASHI Shuji 5405977a6e Add y.tab.c to remove Bison from build dependencies; ref 4ce3997c
I sometimes see Bison related problems in setting up build environments.
Therefore to remove Bison from build time dependencies, add `y.tab.c`
generated by Bison to the repository.

The reduction of dependency at build time also reduces the labor and time
for setup and installation in CI.

In addition, a path in `#line` directive is converted to a relative path so
that its path is constant regardless of development environments.
2020-10-12 16:21:00 +09:00
Yukihiro "Matz" Matsumoto f6dcc6dcfc Use the newer bison on GitHub actions macOS; ref #4903
`Windows-MinGW` and `Windows-VC` also requires updates.
2020-10-12 16:21:00 +09:00
Takeshi Watanabe 9712379e0f Start GitHub Actions; close #4903 2020-10-12 16:21:00 +09:00
Yukihiro "Matz" Matsumoto b67955b8ca Change the arguments of following implicit conversion functions:
- `mrb_convert_type`
- `mrb_check_convert_type`

Those function no longer take `tname` string representation of desired
type, and take method symbols instead of `const char*` names. This is
incompatible change. I hope no third-party gems use those functions.
2020-10-12 16:20:59 +09:00
Yukihiro "Matz" Matsumoto 2a366ffba8 Use functions that take symbols to reduce string litrals in C. 2020-10-12 16:20:59 +09:00
Yukihiro "Matz" Matsumoto 8864c30d16 Provide functions that take symbols instead of const char*.
- mrb_define_class_id
- mrb_define_module_id
- mrb_define_method_id
- mrb_define_singleton_method_id
- mrb_define_module_function_id
- mrb_define_const_id
- mrb_undef_method_id
- mrb_undef_class_method_id
- mrb_class_defined_id
- mrb_class_get_id
- mrb_class_defined_under_id
- mrb_class_get_under_id
- mrb_module_get_id
- mrb_module_get_under_id
- mrb_define_class_under_id
- mrb_define_module_under_id
- mrb_exc_get_id
2020-10-12 16:20:59 +09:00
Yukihiro "Matz" Matsumoto 3516a3c012 Use mrb->eStandardError instead of mrb_exc_get(). 2020-10-12 16:20:58 +09:00
Yukihiro "Matz" Matsumoto fa6a9f6f13 Add functions that take symbols as arguments.
- :
2020-10-12 16:20:58 +09:00
Yukihiro "Matz" Matsumoto 00f5ddc9ae Use mrb_funcall_id() extensively.
Except for support files e.g. `mruby-test/driver.c`, which are not
target of symbol collection via `rake gensym`.
2020-10-12 16:20:58 +09:00
Yukihiro "Matz" Matsumoto dcd3e5907c Define a new function mrb_funcall_id().
`mrb_funcall_id()` takes `mrb_sym` instead of `char*` for a method name.
You can use `MRB_SYM()`/`MRB_QSYM()` to specify the method to call.
2020-10-12 16:20:57 +09:00
Yukihiro "Matz" Matsumoto 80c15ddd15 Update the build instruction. 2020-10-12 16:20:57 +09:00
Yukihiro "Matz" Matsumoto 7fde48b838 Remove unnecessary comments from host-shared target. 2020-10-12 16:20:56 +09:00
Yukihiro "Matz" Matsumoto 509f2bfd93 Add a new target clang-asan to use LLVM's address sanitizer. 2020-10-12 16:20:56 +09:00
Yukihiro "Matz" Matsumoto b941e91866 Use more MRB_QSYM(). 2020-10-12 16:20:56 +09:00
Yukihiro "Matz" Matsumoto 312f54b580 Add Rakefile to build/presym dependency. 2020-10-12 16:20:55 +09:00
Yukihiro "Matz" Matsumoto 3a162cc33f Run rake gensym before the build. 2020-10-12 16:20:55 +09:00
Yukihiro "Matz" Matsumoto b60809f117 Remove explicit rake gensym. 2020-10-12 16:20:55 +09:00
Yukihiro "Matz" Matsumoto 0881e34496 Add dependency from all to gensym.
You don't need to invoke `rake gensym` explicitly any longer.
2020-10-12 16:20:54 +09:00
Yukihiro "Matz" Matsumoto 24ad5f35b1 Removed unnecessary dependency from all.
`libmruby.flags.mak` is only required from `mruby-config` gem.
2020-10-12 16:20:54 +09:00
Yukihiro "Matz" Matsumoto 3c222e4e71 Add mruby-bin-config to default.gembox. 2020-10-12 16:20:54 +09:00
Yukihiro "Matz" Matsumoto e2063fc267 Add operators to presym from Rakefile. 2020-10-12 16:20:53 +09:00
Yukihiro "Matz" Matsumoto 68f8d73308 Use MRB_QSYM() instead of MRB_OPSYM(). 2020-10-12 16:20:53 +09:00
Yukihiro "Matz" Matsumoto 246c76e261 Rename MRB_OPSYM() to MRB_QSYM().
Where `QSYM` means quoted symbols, which cannot be represented C
symbols, so specify aliases instead.

- operators: name of the operation, e.g. add for `+`
- predicates: add `_p` suffix instead of `?`
- bang methods: add `_b` suffix instead of `!`
- instance variables: add `a_` prefix instead of `@`
- global variables: add `d_` prefix instead of `@`
- class variables: unsupported; don't use them
2020-10-12 16:20:53 +09:00
Yukihiro "Matz" Matsumoto 6128ae61a8 Simplified Rakefile. 2020-10-12 16:20:52 +09:00
Yukihiro "Matz" Matsumoto e3e5596960 Use MRB_OPSYM() instead of mrb_intern_lit(). 2020-10-12 16:20:52 +09:00
Yukihiro "Matz" Matsumoto 1bcf6d9f3c Create MRB_OPSYM() macro to refer symbols corresponding operators.
For example, `MRB_OPSYM(add)` refers a symbol for `+`.
2020-10-12 16:20:51 +09:00
Yukihiro "Matz" Matsumoto 97e3c3a5a3 Undefine internal macros in presym.h.
- MRB_PRESYM_CSYM
- MRB_PRESYM_SYM
2020-10-12 16:20:51 +09:00
Yukihiro "Matz" Matsumoto acd5317fb1 Create build directory first before gensym. 2020-10-12 16:20:50 +09:00
Yukihiro "Matz" Matsumoto 8d90c7c0fa Remove unused variable from Rakefile. 2020-10-12 16:20:50 +09:00
Yukihiro "Matz" Matsumoto 5a88904fe8 Use File.open instead of File.write shortcut. 2020-10-12 16:20:49 +09:00
Yukihiro "Matz" Matsumoto b3db34c2a8 Remove presym files before writing just to make sure. 2020-10-12 16:20:49 +09:00
Yukihiro "Matz" Matsumoto 6b7c12f523 Specify MRUBY_TARGET in CI configuration YAML. 2020-10-12 16:20:49 +09:00
Yukihiro "Matz" Matsumoto fa18ffa90c Add rake gensym to appveyor.yml too. 2020-10-12 16:20:48 +09:00
Yukihiro "Matz" Matsumoto 3ec61c0929 Update host* targets to use default.gembox.
And now `default.gembox` includes `mruby-socket` gem.
2020-10-12 16:20:48 +09:00
Yukihiro "Matz" Matsumoto 10b1a52bb8 Small updates on documents:
- README.md
- CONTRIBUTING.md
- doc/limitations.md
2020-10-12 16:20:48 +09:00
Yukihiro "Matz" Matsumoto dcfc2dbf14 Add host-shared.rb to create shared mruby library. 2020-10-12 16:20:47 +09:00
Yukihiro "Matz" Matsumoto d70536e0e8 Update host.rb build script. 2020-10-12 16:20:47 +09:00
Yukihiro "Matz" Matsumoto fdbfeaf533 Build process updated:
You have to specify `TARGET` to specify a configuration, e.g.

```
rake TARGET=host-debug all test
```

When you port `mruby` to a new configuration:
1. copy an existing configuration under `target` directory
2. modify the new configuration file
3. build using the new configuration
4. send PR if you please
2020-10-12 16:20:47 +09:00
KOBAYASHI Shuji ea31878b1f Avoid changing directory in mruby-io test 2020-10-12 16:20:46 +09:00
KOBAYASHI Shuji d33b9dc81f Refine .travis.yml
* Disable automatic update and clean up on `brew install` (install time
  160 sec -> 5 sec).
* Avoid using deprecated keys.
2020-10-12 16:20:46 +09:00
Yukihiro "Matz" Matsumoto d612344e48 Should not use assert with expressions with side-effect; ref #4981
`assert()` can be completely removed when `NDEBUG` is set.
2020-10-12 16:20:45 +09:00
Yukihiro "Matz" Matsumoto d7e183bfdf Fixed wrong condition in #4981. 2020-10-12 16:20:45 +09:00
Yukihiro "Matz" Matsumoto d5c010422a Run rake gensym before the build. 2020-10-12 16:20:45 +09:00
Yukihiro "Matz" Matsumoto 5738ed0474 Keep build/presym through rake clean. 2020-10-12 16:20:44 +09:00
Yukihiro "Matz" Matsumoto 3174061593 Prepend gensym rule to depfiles. 2020-10-12 16:20:44 +09:00
Yukihiro "Matz" Matsumoto 76d752c03b Fix presym_find for strings without NUL terminators. 2020-10-12 16:20:44 +09:00
Yukihiro "Matz" Matsumoto 33647b904e Avoid snprintf in mruby-io test; ref #4981 2020-10-12 16:20:43 +09:00
Yukihiro "Matz" Matsumoto 47f65a93c5 Remove the temporary file from the AF_UNIX socket test; #4981 2020-10-12 16:20:43 +09:00
Yukihiro "Matz" Matsumoto a2fbb98fa6 Remove build/presym and build/presym.inc on rake clean. 2020-10-12 16:20:42 +09:00
Yukihiro "Matz" Matsumoto 721f934b9b Scan .rb files as well to generate presym table. 2020-10-12 16:20:42 +09:00
Yukihiro "Matz" Matsumoto d2cab16301 Update presym_find to use more efficient binary search. 2020-10-12 16:20:42 +09:00
Yukihiro "Matz" Matsumoto eddd324979 Add MRB_SYM() for inline symbols. 2020-10-12 16:20:41 +09:00
Yukihiro "Matz" Matsumoto f221f4e0fa Update Rakefile to generate presym. 2020-10-12 16:20:41 +09:00
Yukihiro "Matz" Matsumoto a476d71143 Support presym in symbol.c. 2020-10-12 16:20:41 +09:00
Yukihiro "Matz" Matsumoto 1e156974d5 Generate a table for preallocated symbols (presym).
`presym` are symbols used in the C source files. `gensym` rake rule
scans the entire C source files and collect symbols referenced from
them.
2020-10-12 16:20:40 +09:00
Yukihiro "Matz" Matsumoto 8853b03591 Merge pull request #5090 from zubycz/fix_error_when_build_without_float
Fix argument error when built with MRB_WITHOUT_FLOAT flag
2020-10-12 16:19:04 +09:00
Yukihiro "Matz" Matsumoto f53781bdeb Merge pull request #5089 from zubycz/fix_test_of_range_min
fix improper test of Range#min
2020-10-12 14:29:39 +09:00
ssmallkirby afc0d7a6c3 Fix argument error when built with MRB_WITHOUT_FLOAT flag
Fixed inproper argument of mrb_fixnum_value() called in integral_div(),
when built with MRB_WITHOUT_FLOAT flag.

Co-authored-by: taiyoslime <t@iyosli.me>
Co-authored-by: n4o847 <22975590+n4o847@users.noreply.github.com>
2020-10-12 14:16:18 +09:00
taiyoslime c4f75c7de0 fix improper test of Range#min 2020-10-12 13:42:27 +09:00
Yukihiro "Matz" Matsumoto 9ea7b71868 Merge pull request #5087 from dearblue/get-args-string
Prohibit string changes by "s"/"z" specifier of `mrb_get_args()`
2020-09-25 22:54:25 +09:00
dearblue 57611240a9 Prohibit string changes by "s"/"z" specifier of mrb_get_args()
- The `s` specifier is a string pointer obtained without performing `mrb_str_modify()`, so it cannot be changed.
- The `z` specifier cannot be changed because it is a string pointer obtained by `RSTRING_CSTR()` which returns `const char *`.
2020-09-25 21:02:58 +09:00
Yukihiro "Matz" Matsumoto a97f085c52 Merge pull request #5083 from wataash/example-clarify-caller
examples/mrbgems: clarify the caller
2020-09-18 14:16:23 +09:00
Wataru Ashihara 2bf9fd06d2 examples/mrbgems: clarify the caller
Before this commit:

  mruby -e 'CRubyExtension.ruby_method' # => A Ruby Extension
  mruby -e 'CRubyExtension.c_method'    # => A C Extension
  mruby -e 'CExtension.c_method'        # => A C Extension
  mruby -e 'RubyExtension.ruby_method'  # => A Ruby Extension

After this commit:

  mruby -e 'CRubyExtension.ruby_method' # => CRubyExtension: A Ruby Extension
  mruby -e 'CRubyExtension.c_method'    # => CRubyExtension: A C Extension
  mruby -e 'CExtension.c_method'        # => CExtension: A C Extension
  mruby -e 'RubyExtension.ruby_method'  # => RubyExtension: A Ruby Extension
2020-09-18 14:10:20 +09:00
Yukihiro "Matz" Matsumoto dffe4bc8ba Merge pull request #5082 from wataash/remove-type-check
Remove redundant type-check
2020-09-18 13:42:02 +09:00
Wataru Ashihara 4375bffee5 Remove redundant type-check
since mrb_str_to_str() also does it.
2020-09-18 13:35:03 +09:00
Yukihiro "Matz" Matsumoto e440681a06 Merge pull request #5081 from wataash/d-format-comment
*.d format is version-independent
2020-09-17 21:05:42 +09:00
Yukihiro "Matz" Matsumoto 758f8f4baf Merge pull request #5080 from wataash/fix-dep-read
Fix skipping reading file
2020-09-17 21:05:30 +09:00
Wataru Ashihara ea3b02e387 *.d format is version-independent
As pointed out by @shuujii on https://github.com/mruby/mruby/pull/5079 ,
multi-path in single-line could be appear even with older-gcc or clang.
2020-09-17 21:04:45 +09:00
Wataru Ashihara 069d9bb4d7 Fix skipping reading file 2020-09-17 20:30:17 +09:00
Yukihiro "Matz" Matsumoto 9757616c57 Merge pull request #5079 from wataash/fix-dep-parse
Fix *.d parsing with gcc 9.3.0
2020-09-17 20:20:03 +09:00
Wataru Ashihara e8723a4f3f Fix *.d parsing with gcc 9.3.0
Before this commit:

  $ rake
  ...
  $ rm build/host/src/gc.o
  $ rake
  rake aborted!
  Don't know how to build task '/home/foo/mruby/build/host/src/gc.o' (See the list of available tasks with `rake --tasks`)
  ...

After this commit:

  $ rake
  ...
  $ rm build/host/src/gc.o
  $ rake
  CC    src/gc.c -> build/host/src/gc.o
  ...

With gcc 9.3.0 on Ubuntu 20.04, build/host/src/array.d looks like:

  /build/host/src/array.o: /src/array.c \
   /include/mruby.h /include/mrbconf.h \
   /include/mruby/common.h \
   ...
   /include/mruby/range.h \
   /src/value_array.h

and it has been parsed to:

  [
                                           # /src/array.c missing
    "/include/mruby.h /include/mrbconf.h", # incorrectly parsed
    "/include/mruby/common.h",
    ...
    "/src/value_array.h",
  ]

After this change, *.d will be parsed correctly.

  [
    "/src/array.c",
    "/include/mruby.h",
    "/include/mrbconf.h",
    "/include/mruby/common.h",
    ...
    "/src/value_array.h",
  ]
2020-09-17 20:02:55 +09:00
Yukihiro "Matz" Matsumoto 5bfb70e9db Fix File.extname bug; fix #5077 2020-09-13 11:38:31 +09:00
Yukihiro "Matz" Matsumoto 8b65e4b73c Add test to ensure #5077 2020-09-13 11:38:06 +09:00
Yukihiro "Matz" Matsumoto 4e15832000 Update y.tab.c; ref #4933 2020-09-10 21:17:38 +09:00
Yukihiro "Matz" Matsumoto c27e451931 Merge pull request #4933 from dearblue/variables
Fix take over file scope variables with `mruby` and `mirb` command
2020-09-10 18:12:38 +09:00
Yukihiro "Matz" Matsumoto c345fe4321 Merge pull request #5076 from dearblue/call_type
Remove `enum call_type`
2020-09-07 23:22:13 +09:00
dearblue f99c315400 Remove enum call_type
It seems to be unnecessary from mruby-1.0.0 or earlier.
2020-09-03 23:18:16 +09:00
Yukihiro "Matz" Matsumoto e2c628583e Fix mrb_ary_splat() to copy the array always. 2020-08-30 19:14:34 +09:00
Yukihiro "Matz" Matsumoto 705f95c983 Merge pull request #5068 from sizious/mingw32-legacy-fixes
mruby-io: Fixing compilation issue under the legacy MinGW environment
2020-08-29 23:04:02 +09:00
Yukihiro "Matz" Matsumoto 6b8664b951 Fix the bug caused by to_a returning a frozen array.
Reported by @shuujii.
2020-08-29 23:00:36 +09:00
Yukihiro "Matz" Matsumoto f08f3c34be Fix a bug introduced by the last commit.
Should have handled the case `to_a` returns `nil`.
2020-08-29 22:58:07 +09:00
SiZiOUS 510b9e7abc mruby-io: Fixing compilation issue under the legacy MinGW environment
Adding MRB_MINGW32_LEGACY in common.h in order to identify the legacy MinGW environment (i.e. NOT to be confused with MinGW-w64).
For more info about MinGW defined macros, see: https://sourceforge.net/p/predef/wiki/Compilers/
2020-08-29 13:58:00 +02:00
Yukihiro "Matz" Matsumoto 564372d7b9 Fix mrb_obj_ceqq to avoid array copying. 2020-08-29 18:43:47 +09:00
Yukihiro "Matz" Matsumoto a66d86cfc1 Fix mrb_ary_splat to copy the array; fix #5067 2020-08-29 18:43:26 +09:00
Yukihiro "Matz" Matsumoto 96bae1d508 Merge pull request #5065 from shuujii/simplify-MSVC-detection-to-mrb_static_assert
Simplify MSVC detection to `mrb_static_assert`
2020-08-12 21:51:45 +09:00
KOBAYASHI Shuji 77c35e7097 Simplify MSVC detection to mrb_static_assert 2020-08-12 20:05:31 +09:00
Yukihiro "Matz" Matsumoto 2aa70e9690 Merge pull request #5062 from shuujii/use-normal-static_assert-in-mrb_static_assert-as-much-as-possible
Use normal `static_assert` in `mrb_static_assert` as much as possible
2020-08-11 22:33:44 +09:00
Yukihiro "Matz" Matsumoto ae09a219d5 Merge pull request #5063 from dearblue/stat32
Use `struct _stat32` instead of `struct __stat32`
2020-08-11 22:31:09 +09:00
dearblue c5dc184a6d Use struct _stat32 instead of struct __stat32
It is described as `struct __stat32` in the MSVC reference manual.
https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/stat-functions?view=vs-2019
But it doesn't really exist, so it must use `struct _stat32`.

It also replaces `struct __stat64` with `struct _stat64` to make it look
nicer.
2020-08-11 22:09:28 +09:00
KOBAYASHI Shuji bab7e9f032 Use normal static_assert in mrb_static_assert as much as possible
* `_Static_assert` can also be used with `-std=gnu99` on GCC >= 4.6.
* `static_assert` can be used on MSVC.
* `static_assert` can be used even on old G++/Clang++ if
  `__GXX_EXPERIMENTAL_CXX0X__` is defined.
2020-08-11 20:47:20 +09:00
Yukihiro "Matz" Matsumoto 3b8df2c285 Fixed VC fstat issue. 2020-08-11 16:35:50 +09:00
Yukihiro "Matz" Matsumoto cfaaf7c6d4 Should use _fstat32() on 32bit Windows. 2020-08-11 16:02:05 +09:00
Yukihiro "Matz" Matsumoto 5210482c59 Add cast for mrb_fixnum_value() from time_t. 2020-08-11 16:01:23 +09:00
Yukihiro "Matz" Matsumoto 5e55b61c44 Fix mrb_int and size_t combination warnings. 2020-08-11 15:06:51 +09:00
Yukihiro "Matz" Matsumoto 4695dfdcb6 Avoid using mrb_funcall() from mruby-io gem. 2020-08-10 08:53:35 +09:00
Yukihiro "Matz" Matsumoto 55482063a7 Remove duplicated definition of E_EOF_ERROR. 2020-08-09 21:57:41 +09:00
Yukihiro "Matz" Matsumoto ab5726d4e4 Merge pull request #5061 from shuujii/allow-mrb_static_assert-to-be-used-outside-of-functions
Allow `mrb_static_assert()` to be used outside of functions
2020-08-09 21:57:30 +09:00
KOBAYASHI Shuji 0d54568b4d Allow mrb_static_assert() to be used outside of functions
The use of `struct` is an idea by @dearblue.
2020-08-09 20:39:36 +09:00
Yukihiro "Matz" Matsumoto df969b163a Return NaN for 0/0; d8e060d 2020-08-08 15:36:55 +09:00
Yukihiro "Matz" Matsumoto ad8b36daa1 Should not use mrb_float_value() with MRB_WITHOUT_FLOAT. 2020-08-08 14:14:17 +09:00
Yukihiro "Matz" Matsumoto c849b894ed Reintroduce mrb_static_assert; #5051
Note that the home brew version of `mrb_static_assert` only works within
the function body.  This reverts commit 8f99689.
2020-08-08 10:39:26 +09:00
Yukihiro "Matz" Matsumoto d8e060d2d3 Avoid division by zero undefined behavior. 2020-08-07 10:51:33 +09:00
Yukihiro "Matz" Matsumoto 9742bce198 Merge pull request #5059 from mruby/stable
Merge mruby 2.1.2
2020-08-06 17:47:36 +09:00
Hiroshi Mimaki 7f8d38bbbe Merge master. 2020-08-06 17:38:20 +09:00
Yukihiro "Matz" Matsumoto 0b95c8a1e8 Use memcpy to copy stack. 2020-08-06 17:02:15 +09:00
Yukihiro "Matz" Matsumoto 57a798e687 Use memset() to clear stack unless MRB_NAN_BOXING. 2020-08-06 17:01:59 +09:00
Yukihiro "Matz" Matsumoto 755233ef7d Remove block clear of callinfo. 2020-08-06 17:01:28 +09:00
Yukihiro "Matz" Matsumoto 8f99689ba3 Remove mrb_static_assert from the core; #5051 2020-08-06 16:01:45 +09:00
Hiroshi Mimaki 1a9bdfcde5 Update release date. 2020-08-06 12:45:59 +09:00
Yukihiro "Matz" Matsumoto 11cc7bed96 Merge pull request #5052 from dearblue/cistacks
Extend the `cipush()` and `cipop()` functions
2020-08-05 17:38:51 +09:00
Yukihiro "Matz" Matsumoto ef9c68795f Merge pull request #5058 from dearblue/benchmark
Improve `rake benchmark`
2020-08-05 06:51:54 +09:00
dearblue fde95a7db5 Improve rake benchmark
- Use POSIX format instead of GNU extension for `time` command.
  For example FreeBSD's `time(1)` does not have GNU extensions available.
- Sort `benchmark/bm_*.rb`.
  This is because the order of the bar graph cannot be uniquely
  determined depending on the result of `Dir.glob`.
2020-08-04 22:04:05 +09:00
Yukihiro "Matz" Matsumoto cfb799a18e Fix wrong condition for PACK_DIR_HEX; ref #5057 2020-08-04 17:50:09 +09:00
Yukihiro "Matz" Matsumoto 43443d9377 Should not decrement count when PACK_FLAG_COUNT2; fix #5057 2020-08-03 19:46:34 +09:00
Yukihiro "Matz" Matsumoto faed5054f8 Initialized local variables in mrb_hash_shift(). 2020-08-03 15:53:50 +09:00
Yukihiro "Matz" Matsumoto 0a505dcfd6 Simplify khash.h.
- Remove ` kh_put_prepare` function used only internally
- Remove `n_occupied` member from `kh_` struct
2020-07-31 18:14:02 +09:00
Yukihiro "Matz" Matsumoto 1517d77e93 Fix puts in mruby-print on no argument; 0e9bd24
`puts` should print newline when called without arguments.
2020-07-31 06:57:05 +09:00
KOBAYASHI Shuji 112120969d Use type tag for hash code in ht_hash_func()
The function corresponding to `ht_hash_func()` was as follows in the days of
khash implementation (before d78acc7a).

  ```c
  mrb_hash_ht_hash_func(mrb_state *mrb, mrb_value key)
  {
    enum mrb_vtype t = mrb_type(key);
    ...
    switch (t) {
    ...
    default:
      hv = mrb_funcall(mrb, key, "hash", 0);
      h = (khint_t)t ^ (khint_t)mrb_fixnum(hv);
      break;
    }
    ...
  }
  ```

When switched to the segmented list implementation (d78acc7a), this function
was changed as follows.

  ```c
  sg_hash_func(mrb_state *mrb, seglist *t, mrb_value key)
  {
    enum mrb_vtype tt = mrb_type(key);
    ...
    switch (tt) {
    ...
    default:
      hv = mrb_funcall(mrb, key, "hash", 0);
      h = (size_t)t ^ (size_t)mrb_fixnum(hv);
      break;
    }
    ...
  }
  ```

Since the argument `t` was added, the variable for type tag was changed from
`t` to `tt`, but the variable used in the expression of `h` remained `t`.

Probably this is an omission of change, so fixed it.
2020-07-29 09:17:32 +09:00
Yukihiro "Matz" Matsumoto 63956036e1 Fix the VM stack handling bug in 'mrb_yield_with_class()`; fix #5042 2020-07-29 09:09:37 +09:00
dearblue cdf45438f0 Fixed shift width for MRB_ENV_SET_BIDX()
ref c07f24cd1 and close #5035
2020-07-29 09:05:29 +09:00
Yukihiro "Matz" Matsumoto 9571a4c07e Merge pull request #5050 from dearblue/memsize_of2
Update document for `ObjectSpace.memsize_of` [ci skip]
2020-07-26 13:56:26 +09:00
dearblue d96be5c1b2 Extend the cipush() and cipop() functions
- Returns the updated call info.
- Unify the processing around `cipush()`.
- `cipop()` restores the stack.
2020-07-26 13:12:01 +09:00
dearblue 0983c723c5 Update document for ObjectSpace.memsize_of [ci skip]
The `recurse` keyword is removed by f00657ead7.
2020-07-26 13:12:01 +09:00
Yukihiro "Matz" Matsumoto 425b5f32d6 Merge pull request #5049 from shuujii/use-type-tag-for-hash-code-in-ht_hash_func
Use type tag for hash code in `ht_hash_func()`
2020-07-25 19:40:05 +09:00
KOBAYASHI Shuji 0c88c71786 Use type tag for hash code in ht_hash_func()
The function corresponding to `ht_hash_func()` was as follows in the days of
khash implementation (before d78acc7a).

  ```c
  mrb_hash_ht_hash_func(mrb_state *mrb, mrb_value key)
  {
    enum mrb_vtype t = mrb_type(key);
    ...
    switch (t) {
    ...
    default:
      hv = mrb_funcall(mrb, key, "hash", 0);
      h = (khint_t)t ^ (khint_t)mrb_fixnum(hv);
      break;
    }
    ...
  }
  ```

When switched to the segmented list implementation (d78acc7a), this function
was changed as follows.

  ```c
  sg_hash_func(mrb_state *mrb, seglist *t, mrb_value key)
  {
    enum mrb_vtype tt = mrb_type(key);
    ...
    switch (tt) {
    ...
    default:
      hv = mrb_funcall(mrb, key, "hash", 0);
      h = (size_t)t ^ (size_t)mrb_fixnum(hv);
      break;
    }
    ...
  }
  ```

Since the argument `t` was added, the variable for type tag was changed from
`t` to `tt`, but the variable used in the expression of `h` remained `t`.

Probably this is an omission of change, so fixed it.
2020-07-25 16:59:02 +09:00
Yukihiro "Matz" Matsumoto f868d7d357 Change the logic to calculate object (iv_tbl) size; #5045 2020-07-24 13:13:06 +09:00
Yukihiro "Matz" Matsumoto c69ca2c7f8 Merge pull request #5045 from dearblue/memsize_of
Improve `mruby-os-memsize`
2020-07-24 12:02:05 +09:00
dearblue ccd5f203bf Improve prototype for mrb_objspace_page_slot_size(); ref #5032
If it qualify a return type that is not a pointer with `const`, the
compiler ignores it.
2020-07-24 11:48:09 +09:00
dearblue 5c2b11d215 Avoid using FPU with mruby-os-memsize; ref #5032
And, in the calculation of the instance variable size, the fraction was
always rounded down because of division of integers, so fix it.

At the same time, test items that are no longer passed due to this
change are deleted.
2020-07-24 11:42:37 +09:00
dearblue c9ba761b9e Support without mruby-method for mruby-os-memsize; ref #5032 2020-07-24 11:42:26 +09:00
dearblue 2b588b8566 Add NUL terminator to string object size calculation; ref #5032 2020-07-24 11:42:16 +09:00
Yukihiro "Matz" Matsumoto b4f4f5968b ObjectSpace.count_objects to support MRB_TT_ISTRUCT; #5046 2020-07-23 07:10:35 +09:00
Yukihiro "Matz" Matsumoto e7599050dc Fix a bug with ht_index called with size==0; fix #5046
It happens when a hash made empty calls `rehash`.
2020-07-23 07:06:35 +09:00
Yukihiro "Matz" Matsumoto 0e9bd24827 Fix puts to print newline with empty strings; ref b184772 2020-07-22 17:50:01 +09:00
Yukihiro "Matz" Matsumoto b920270508 Use more mrb_field_write_barrier for instance variables. 2020-07-22 15:01:55 +09:00
Yukihiro "Matz" Matsumoto 491aa1bfe5 Use more local variables.
To make debugging easy, and to improve the performance little bit.
2020-07-22 15:01:54 +09:00
Yukihiro "Matz" Matsumoto c99bb756c4 Move gray_list update from gc_mark_children.
The responsibility moved to caller to avoid confusion. Currently the
function is called from only 2 places, so it is relatively easy to
ensure not to update `gray_list` in the caller.  But the assumption
may change in the future.
2020-07-22 15:01:54 +09:00
Yukihiro "Matz" Matsumoto 097f525817 Avoid using mrb_ary_modify from the internal function.
`mrb_ary_modify` calls `mrb_write_barrier`, so can cause the same
problem of the past `push`. It is provided for use-level API.
2020-07-22 15:01:54 +09:00
Yukihiro "Matz" Matsumoto 5533c29833 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-07-22 15:01:53 +09:00
Yukihiro "Matz" Matsumoto 0bb4d10ca7 Define Array#to_a to avoid unnecessary loops. 2020-07-22 14:56:56 +09:00
Yukihiro "Matz" Matsumoto 914da3d712 Small comment fix in mrblib/array.c. 2020-07-22 14:56:36 +09:00
Yukihiro "Matz" Matsumoto 670622f45d Skip unnecessary mark_context if mrb->c == mrb->root_c. 2020-07-22 14:56:03 +09:00
dearblue 97f71b5a67 Fixed garbled characters; ref #5041 2020-07-22 00:03:17 +09:00
dearblue 639703cf01 Remove unnecessory methods in mruby-objectspace; ref #5041
The `ObjectSpace#memsize_of` and `ObjectSpace#memsize_of_all` in `mruby-objectspace` ware
migrated to `mruby-os-memsize` mrbgem.
2020-07-21 23:32:30 +09:00
Yukihiro "Matz" Matsumoto 6334949ba6 Fix the VM stack handling bug in 'mrb_yield_with_class()`; fix #5042 2020-07-21 12:47:35 +09:00
Yukihiro "Matz" Matsumoto b1847721e8 Implement Kernel#print and Kernel#puts in C. 2020-07-20 23:35:17 +09:00
Yukihiro "Matz" Matsumoto f0afdf7496 Merge pull request #5041 from RoryO/extract-memsize-to-gem
Extract memsize to gem
2020-07-20 08:23:46 +09:00
Rory OConnell 0685784119 Adding to authors 2020-07-19 15:40:29 -07:00
Rory OConnell 5f4a27217e Separate memsize_of and memsize_of_all to a separate gem; #5040
Those methods are originally CRuby specific.

Co-authored-by: Yukihiro "Matz" Matsumoto <matz@ruby.or.jp>
2020-07-19 15:36:08 -07:00
Yukihiro "Matz" Matsumoto c9ea39843b Remove some tests from mruby-objectspace gem; #5040
Those tests succeeds only on some configuration.
2020-07-20 06:05:06 +09:00
Yukihiro "Matz" Matsumoto a6f31ad6ce Avoid accessing obj.tt of mrb_value; #5040
The old code compiles only on `MRB_NO_BOXING`.
2020-07-20 06:05:06 +09:00
Yukihiro "Matz" Matsumoto 07b75d927e Replace 0 by MRB_EACH_OBJ_OK; #5040 2020-07-20 06:04:54 +09:00
Yukihiro "Matz" Matsumoto 71254be076 Skip MRB_TT_FREE and MRB_TT_BREAK in each_object. 2020-07-19 13:11:53 +09:00
Yukihiro "Matz" Matsumoto 1d2c5c12d3 Reorder members of struct os_each_object_data to stop warnings.
`mrb_value` may or may not be struct according to configuration.
2020-07-19 13:10:08 +09:00
Yukihiro "Matz" Matsumoto 00337543a5 Should have updated the arg spec for memsize_of&memsize_of_all; #5040 2020-07-19 09:11:16 +09:00
Yukihiro "Matz" Matsumoto f76defd310 Use c specifier for mrb_get_args. 2020-07-19 07:47:07 +09:00
Yukihiro "Matz" Matsumoto d023adcb12 Add new specifier c to mrb_get_args.
`C` retrieves a `mrb_value` that refers a class/module.
`c` retrieves a `struct RClass*` pointer to a class/module.
2020-07-19 07:45:16 +09:00
Yukihiro "Matz" Matsumoto 5b2763821e Fix memsize_of_all to count all objects if no argument given; #5040 2020-07-19 07:42:35 +09:00
Yukihiro "Matz" Matsumoto 6d073f8d99 Fix memsize_of_all to count memory of subclass instances; #5040
`ObjectSpace.memsize_of_all` takes a class and count memory size of all
instances of the class and its subclasses (if any).
2020-07-19 06:57:34 +09:00
Yukihiro "Matz" Matsumoto 667ace2bfe Merge pull request #5040 from RoryO/add-memsize-of-all
Add ObjectSpace.memsize_of_all
2020-07-19 06:43:13 +09:00
Rory O'Connell ffe8bf6323 Avoid singleton classes with mrb_class_real 2020-07-18 13:55:45 -07:00
Rory OConnell a79d1ba9ff Adding memsize_of_all doc 2020-07-17 20:21:23 -07:00
Rory OConnell fe1ec9afdd Add ObjectSpace.memsize_of_all 2020-07-17 20:09:44 -07:00
Yukihiro "Matz" Matsumoto 1952004d5a Use proc->env to check block_given? if possible; fix #5039
This bug has been there since mruby 1.4.0 (2018-04).
2020-07-17 16:15:47 +09:00
Yukihiro "Matz" Matsumoto e41f1f5139 Fix indent of compiler conditions; #5032 2020-07-17 12:32:54 +09:00
Yukihiro "Matz" Matsumoto 495c1a377a Fix memsize_of to count method table size; #5032
Also avoid `mrb_funcall` to minimize VM recursion.
2020-07-17 12:31:00 +09:00
Yukihiro "Matz" Matsumoto 9f52bcfca9 Fix memsize_of Fibers; #5032
Memory size of a Fiber is calculated by stack size only in CRuby.
2020-07-17 11:50:12 +09:00
Yukihiro "Matz" Matsumoto a2b8c08a52 Add const to irep pointer in os_memsize_of_irep; #5032 2020-07-17 11:43:55 +09:00
Yukihiro "Matz" Matsumoto f00657ead7 Remove recursive memsize_of; #5032
This is enhancement from CRuby's `memsize_of`. We need to change the
CRuby first for the enhancement.
2020-07-17 11:15:07 +09:00
Yukihiro "Matz" Matsumoto 2e56da5a78 Remove MRB_TT_DATA calculation of memsize_of; #5032 2020-07-17 10:59:43 +09:00
Yukihiro "Matz" Matsumoto 60279b2a8e Use mrb_test instead of mrb_obj_eq; #5032 2020-07-17 10:53:24 +09:00
Yukihiro "Matz" Matsumoto c6b8b58e0e Fix memsize_of for fiber objects; #5032 2020-07-17 10:53:04 +09:00
Yukihiro "Matz" Matsumoto 7f66cf7d66 Fix memsize_of for string objects; #5032 2020-07-17 10:52:59 +09:00
Yukihiro "Matz" Matsumoto 9840d6a2e7 Merge pull request #5038 from dearblue/bidx
Fixed shift width for `MRB_ENV_SET_BIDX()`
2020-07-17 07:12:31 +09:00
Yukihiro "Matz" Matsumoto b5bf9510ee Merge pull request #5032 from RoryO/add-objspace-memsize-of
Add ObjectSpace.memsize_of
2020-07-17 07:10:58 +09:00
dearblue 5dc87f77d4 Fixed shift width for MRB_ENV_SET_BIDX()
ref c07f24cd1 and close #5035
2020-07-16 23:11:30 +09:00
Rory O'Connell f74d370c15 mrb_ prefix convention 2020-07-15 19:57:22 -07:00
Rory O'Connell 38b0759108 Clarify memsize_of documentation 2020-07-14 23:43:10 -07:00
Rory O'Connell 4d32c671a7 Finishing out memsize_of recursion 2020-07-14 23:30:35 -07:00
Yukihiro "Matz" Matsumoto bfd58a3fb3 Merge pull request #5036 from shuujii/fix-build_dir-mrbgems-gem_init.c-generation-condition
Fix `${build_dir}/mrbgems/gem_init.c` generation condition; ref #5010
2020-07-15 14:03:09 +09:00
Yukihiro "Matz" Matsumoto 1a4089803d Merge pull request #5037 from shuujii/set-STDOUT.sync=true-when-testing-on-AppVeyor
Set `STDOUT.sync=true` when testing on AppVeyor [skip travis]
2020-07-15 09:57:49 +09:00
KOBAYASHI Shuji 4bf050a192 Set STDOUT.sync=true when testing on AppVeyor [skip travis]
This issue is a correction error at 5a682bfc.
2020-07-14 21:30:36 +09:00
KOBAYASHI Shuji 49896a4d28 Fix ${build_dir}/mrbgems/gem_init.c generation condition; ref #5010
The `${build_dir}/mrbgems/gem_init.c` generation condition has been changed
at #5010, but it is somewhat insufficient, for example, there was a problem
with `rake && rake test`, which was also regenerated in `rake test`.
2020-07-14 19:55:23 +09:00
Rory OConnell 0e5394638b Validate ensure stack presense before calculating 2020-07-13 17:05:03 -07:00
Rory OConnell ad44021591 C89 compiler mode fixes 2020-07-13 16:43:59 -07:00
Rory OConnell 5759256ff8 Update tests for new calculations 2020-07-13 16:00:49 -07:00
Rory OConnell 5184263bdc Calculating sizes of VM components for a Fiber 2020-07-13 16:00:14 -07:00
Rory OConnell 6f945a09b4 Use object iv table size in calculation 2020-07-13 15:59:24 -07:00
Rory OConnell e7bd7d0eaf Use size of hash's table in calculation 2020-07-13 15:58:50 -07:00
Rory OConnell 41e3220539 All values use page slot size in calculation 2020-07-13 15:56:27 -07:00
Yukihiro "Matz" Matsumoto e3bb95bb6d Merge pull request #5034 from dearblue/ssize_t
Fix `ssize_t` for mingw; ref #5030
2020-07-13 08:47:02 +09:00
dearblue 5df95e8d7b Fix ssize_t for mingw; ref #5030
Legacy MinGW and MinGW-w64 had own `ssize_t`.
2020-07-12 17:10:57 +09:00
Yukihiro "Matz" Matsumoto 99bb2154ff Merge pull request #5033 from dearblue/mrb_free_backtrace
Remove the prototype declaration `mrb_free_backtrace()`
2020-07-11 16:43:34 +09:00
dearblue 28e39419a5 Remove the prototype declaration mrb_free_backtrace()
This function is removed by 9644ad5.
2020-07-11 16:15:17 +09:00
Yukihiro "Matz" Matsumoto 042f98912f Merge pull request #5030 from RoryO/fix-compile-msvc-io-utf8
Fix compiling mruby-io on msc with UTF8 enabled
2020-07-11 13:58:41 +09:00
Rory OConnell bb23faae65 downcase windows include file for mingw compatability 2020-07-10 21:18:31 -07:00
Rory OConnell 308c6c8311 Need typedef of ssize_t for msc compiler 2020-07-10 21:18:30 -07:00
Rory OConnell 37d6628688 fix case scopes and variable names 2020-07-10 00:57:45 -07:00
Rory OConnell 338c8538c9 Initial ObjectSpace.memsize_of implementation 2020-07-09 18:52:31 -07:00
Yukihiro "Matz" Matsumoto c5fd8cbbe1 Merge pull request #5031 from RoryO/update-ci
Update Windows CI settings
2020-07-08 10:09:44 +09:00
Rory OConnell 8a44903992 remove verbose test output 2020-07-07 17:34:26 -07:00
Rory OConnell 3a79d60515 fix rake -m for separating build and test steps 2020-07-07 11:18:44 -07:00
Yukihiro "Matz" Matsumoto 01a8d8498f Avoid infinite loop when converting objects to strings. 2020-07-06 23:11:51 +09:00
Rory OConnell b759746890 try not separating build and test steps 2020-07-05 21:37:20 -07:00
Rory OConnell b3dace6ae3 use verbose test output. use correct config file this time 2020-07-05 21:12:04 -07:00
Rory OConnell 4d393d5d09 use correct config file 2020-07-05 21:05:27 -07:00
Rory OConnell 5c7adf0534 separate build and test steps, remove MSC 2020-07-05 20:59:49 -07:00
Rory OConnell 4f189b2be9 remove vs2013, separate build and test commands 2020-07-05 20:55:56 -07:00
Yukihiro "Matz" Matsumoto 81fc5ff48a Merge pull request #5029 from RoryO/true-eq-false
object_id of true, false, and undef are all 0
2020-07-05 22:04:25 +09:00
Rory OConnell 5746958470 fix object_id of true, false, and undef all 0 2020-07-04 20:33:38 -07:00
Yukihiro "Matz" Matsumoto 97319697c8 Cancel 9cdf439
Should not free the pointer in `realloc` since it can cause
use-after-free problem.
2020-07-02 10:41:03 +09:00
Hiroshi Mimaki b6b9c57f24 Update version to 2.1.2. (mruby 2.1.2 RC) 2020-07-01 16:49:21 +09:00
Hiroshi Mimaki aa578c346d Revert "Free the original pointer if realloc failed."
This reverts commit 9cdf439db5.
2020-06-30 18:33:47 +09:00
Yukihiro "Matz" Matsumoto 612e5d6aad Merge pull request #5028 from RoryO/msvc-optimize-shuffle-bug
Work around MSC optimization generating non functional code with Array#shuffle
2020-06-30 10:41:26 +09:00
Rory OConnell ba9f81db8b VS2013 32-bit does not work 2020-06-29 16:16:55 -07:00
Rory OConnell 5b9f7c0b93 use 2015 image for 2013 builds, ruby 2 not on 2013 image 2020-06-29 15:59:13 -07:00
Rory OConnell ce167d70b7 fix quoting 2020-06-29 15:44:13 -07:00
Rory OConnell 0ed623c442 name appveyor jobs, fix <=2015 config 2020-06-29 15:38:11 -07:00
Rory OConnell 206f7ce272 simplify appveyor config 2020-06-29 15:21:15 -07:00
Rory OConnell b59283a03f per-machine appveyor os config 2020-06-29 15:05:02 -07:00
Rory OConnell 3cf48713a2 Work around more MSC optimzer bugs 2020-06-29 14:25:59 -07:00
Rory OConnell 6d5652114e update CI settings for Windows 2020-06-29 13:18:05 -07:00
Yukihiro "Matz" Matsumoto ac8360003e Fix the bug that mrbc generates a.rb.mrb instead of a.mrb.
The bug was introduced by 9dfe50f1d.
2020-06-29 07:25:03 +09:00
Rory OConnell b1017b2651 Reduce scope of volatile keyword for MSC bug 2020-06-26 21:44:31 -07:00
Rory OConnell b8d896e56a Narrower scope working around MSC bug 2020-06-26 21:16:17 -07:00
Rory OConnell db296e9593 work around MSC optimization generating non functional code 2020-06-26 15:13:04 -07:00
Yukihiro "Matz" Matsumoto 233cb49903 Remove unnecessary stack adjustment in OP_CALL. 2020-06-25 06:57:43 +09:00
Yukihiro "Matz" Matsumoto 9cdf439db5 Free the original pointer if realloc failed.
The POSIX `realloc` keep the original pointer untouched, so it can
easily leads to memory leakage. `mrb_realloc()` should handle those
bookkeeping, while `mrb_realloc_simple()` keeps the original `realloc`
behavior.
2020-06-25 06:57:43 +09:00
Yukihiro "Matz" Matsumoto 95360a17f2 Remove unnecessary break from numeric.c. 2020-06-25 06:57:42 +09:00
Yukihiro "Matz" Matsumoto 9dfe50f1d9 Use snprintf instead of memcpy in mrbc.c. 2020-06-25 06:57:42 +09:00
Yukihiro "Matz" Matsumoto c07f24cd18 Change flag names in preparation of REnv refactoring. 2020-06-25 06:57:41 +09:00
Yukihiro "Matz" Matsumoto 03c2b8656b Use mrb_get_argc() to improve performance. 2020-06-25 06:57:41 +09:00
Yukihiro "Matz" Matsumoto ea6e1b003c Create codeql-analysis.yml 2020-06-23 12:36:20 +09:00
Yukihiro "Matz" Matsumoto c2b37e76b3 Skip mrb_get_args() in mrb_ary_{aget,aset} unless necessary.
Use simpler `mrb_get_argc()` and `mrb_get_arg1()` instead.
2020-06-22 21:47:23 +09:00
Yukihiro "Matz" Matsumoto d40b922c98 Fix potential buffer overflow in sprintf.c. 2020-06-20 18:56:33 +09:00
Yukihiro "Matz" Matsumoto 28e793496a Support integer and float combination in mrb_equal(). 2020-06-20 18:56:05 +09:00
Yukihiro "Matz" Matsumoto 33c8d6af1e Move definition of BasicObject#!= to mrblib.
C implementation used `mrb_funcall()` that bypassed many optimization.
2020-06-20 14:09:23 +09:00
Yukihiro "Matz" Matsumoto 49ae2a69f2 Add mrb_get_arg1() that retrieves single (and only) argument.
`mrb_get_arg1()` raises `ArgumentError` if the method does not receive one
argument.

And replaces all `mrb_get_args(mrb, "o", &arg)` by the new function.
2020-06-20 12:49:46 +09:00
Yukihiro "Matz" Matsumoto 2ffb77586a Symbolify saved alias name to improve performance. 2020-06-20 12:07:49 +09:00
Yukihiro "Matz" Matsumoto dad99afae8 Remove unnecessary comments from MRB_TT_* definitions. 2020-06-15 09:54:55 +09:00
Yukihiro "Matz" Matsumoto f93dffb5ee Remove unused MRB_TT_FILE. 2020-06-15 07:47:22 +09:00
Yukihiro "Matz" Matsumoto 742117e7a3 Reorganize gray mark functions in GC. 2020-06-11 16:18:52 +09:00
Yukihiro "Matz" Matsumoto 15ceb35e05 Remove GC test code from ancient. 2020-06-11 16:18:51 +09:00
Yukihiro "Matz" Matsumoto f0bad600e0 Remove endian configuration methods.
Since we made our opcode byte based, we need no endian option (`-e`
and `-E`) to `mrbc`.
2020-06-11 16:18:50 +09:00
Yukihiro "Matz" Matsumoto a8aeba89ef Merge pull request #5023 from dearblue/nesting
Remove `mrb_assert()` in `Module.nesting`
2020-06-11 12:21:26 +09:00
Yukihiro "Matz" Matsumoto 7f593893e8 Update OP_HASH generation to support big hash creation. 2020-06-09 22:42:38 +09:00
Yukihiro "Matz" Matsumoto 5d5b1d1f3c Merge pull request #5022 from dearblue/test-dir
Need `build/XXX/mrbgems/mruby-test` directory
2020-06-09 22:42:29 +09:00
Yukihiro "Matz" Matsumoto bb6846468a Merge pull request #5021 from dearblue/kernel-test
Update `test/t/kernel.rb`
2020-06-09 22:41:44 +09:00
dearblue 960c82e396 Remove mrb_assert() in Module.nesting
The following code was causing SIGSEGV:

```ruby
Module.method(:nesting).call
```
2020-06-09 21:54:13 +09:00
dearblue 5be33b82c7 Need build/XXX/mrbgems/mruby-test directory
An error may occur when performing `rake clean all` or `rake clean test`.

The directory is needed before writing to `mrbgems/mruby-test/assert.c`.
2020-06-09 21:24:53 +09:00
dearblue 4cd858f93d Update test/t/kernel.rb
- Remove unnecessoury assert
- Fix typo
2020-06-09 20:33:56 +09:00
Yukihiro "Matz" Matsumoto 2098acee7d Merge pull request #5020 from jethrodaniel/master
only use GEMNAME if defined in assert.rb
2020-06-08 15:51:03 +09:00
Mark Delk 3157efa57c only use GEMNAME if defined in assert.rb
Check if the constant GEMNAME is defined before use in `assert.rb`.

This is added to prevent an undefined constant error when using
`assert.rb` in other environments - for example, testing CRuby.
2020-06-08 00:30:46 -05:00
Yukihiro "Matz" Matsumoto 613e0bee5e Merge pull request #5013 from shuujii/print-exception-backtrace-if-possible-without--v-in-test
Print exception backtrace if possible without `-v` in test
2020-06-08 09:59:43 +09:00
Yukihiro "Matz" Matsumoto 78c9c71bdf Add proper cast. 2020-06-05 17:52:22 +09:00
Yukihiro "Matz" Matsumoto aa30b13b36 Change arena index from mrb_int to int. 2020-06-05 17:26:40 +09:00
Yukihiro "Matz" Matsumoto 6ba542cd53 Revert part of #5019 (mruby_io_test.c) to honor #4987
The issue was reported by @shuujii.
2020-06-05 17:20:41 +09:00
Yukihiro "Matz" Matsumoto 106f4c4e9d Add proper casts to silence VC warnings. 2020-06-05 16:04:30 +09:00
Yukihiro "Matz" Matsumoto f1523d2404 Squashed commit of the following:
commit 2d7d545c4c4bfce7fdcbcbe9baaeb437915742f0
Merge: 625a1249 b178914b
Author: Yukihiro "Matz" Matsumoto <matz@ruby.or.jp>
Date:   Fri Jun 5 14:35:13 2020 +0900

    Merge branch 'fix-mrb_open-with-nomem' of https://github.com/dearblue/mruby into dearblue-fix-mrb_open-with-nomem

commit b178914b11
Author: dearblue <dearblue@users.noreply.github.com>
Date:   Sat Jan 19 22:22:44 2019 +0900

    Fix invalid pointer free inside other heap's block

     1. `e = mrb_obj_alloc(...)`
     2. `e->stack = mrb->c->stack` (`mrb->c->stack` is anywhere in the range `stbase...stend`)
     3. And raised exception by `mrb_malloc()`!
     4. `mrb_free(e->stack)` by GC part (wrong free)

commit 52e3d5d858
Author: dearblue <dearblue@users.noreply.github.com>
Date:   Sat Jan 19 21:55:36 2019 +0900

    Fix memory leak for temporary symbols when out of memory

commit 4c5499b88e
Author: dearblue <dearblue@users.noreply.github.com>
Date:   Sun Jan 20 11:42:07 2019 +0900

    Fix uninitialized pointer dereference for debug section

commit 8e993167de
Author: dearblue <dearblue@users.noreply.github.com>
Date:   Sun Jan 20 11:41:09 2019 +0900

    Fix memory leak for temporary filenames when out of memory

commit 8b422577e6
Author: dearblue <dearblue@users.noreply.github.com>
Date:   Sun Jan 20 10:57:51 2019 +0900

    Fix memory leak for irep when out of memory

commit 6b35ebf49a
Author: dearblue <dearblue@users.noreply.github.com>
Date:   Sun Jan 20 10:55:50 2019 +0900

    Fix uninitialized pointer dereference when do not finished initializing irep

commit 2531f2631e
Author: dearblue <dearblue@users.noreply.github.com>
Date:   Sun Jan 20 10:48:15 2019 +0900

    Fix NULL pointer dereference when do not finished initializing irep

commit e2d6896eba
Author: dearblue <dearblue@users.noreply.github.com>
Date:   Sat Jan 19 12:54:19 2019 +0900

    Fix memory leak for irep when out of memory by `mrb_proc_new()`

commit b6214ff8a0
Author: dearblue <dearblue@users.noreply.github.com>
Date:   Sat Jan 19 12:53:07 2019 +0900

    Fix memory leak for `khash_t` in `kh_init_size()` when out of memory by `kh_alloc()`

commit 19162dd6c1
Author: dearblue <dearblue@users.noreply.github.com>
Date:   Sun Jan 20 02:15:07 2019 +0900

    Fix memory leak for symbol string when out of memory in `kh_put()`

commit 15e67297ff
Author: dearblue <dearblue@users.noreply.github.com>
Date:   Sun Jan 20 02:12:24 2019 +0900

    Fix keep wrong symbol index when out of memory

commit 3f8e2b3752
Author: dearblue <dearblue@users.noreply.github.com>
Date:   Sun Jan 20 02:08:13 2019 +0900

    Fix keep wrong symbol capacity when out of memory

commit a3cfe755ab
Author: dearblue <dearblue@users.noreply.github.com>
Date:   Sat Jan 19 10:11:37 2019 +0900

    Fix NULL pointer dereference `mrb->c` by `mark_context()`

commit d9c7b6be6e
Author: dearblue <dearblue@users.noreply.github.com>
Date:   Sun Jan 20 15:25:09 2019 +0900

    Fix protect exception for print error message

commit 100642750e
Author: dearblue <dearblue@users.noreply.github.com>
Date:   Sun Jan 20 11:59:02 2019 +0900

    Protect exception for mruby core initialization

commit 7a0418304e
Author: dearblue <dearblue@users.noreply.github.com>
Date:   Fri Jan 18 20:38:27 2019 +0900

    Fix memory leak for string object when out of memory

    The `mrb_str_pool()` function has a path to call `malloc()` twice.

    If occurs `NoMemoryError` exception in second `malloc()`,
    first `malloc()` pointer is not freed.

commit fef1c152ce
Author: dearblue <dearblue@users.noreply.github.com>
Date:   Sat Jan 19 13:05:09 2019 +0900

    Fix stack overflow when out of memory

    As a result of this change, no backtrace information is set
    for NoMemoryError (`mrb->nomem_err`).

    Detailes:

    When generating a backtrace, called `mrb_intern_lit()`,
    `mrb_str_new_cstr()` and `mrb_obj_iv_set()` function with
    `exc_debug_info()` function in `src/error.c`.

    If a `NoMemoryError` exception occurs at this time,
    the `exc_debug_info()` function will be called again,
    and in the same way `NoMemoryError` exception raised will result
    in an infinite loop to occurs stack overflow (and SIGSEGV).

commit da7d7f881b
Author: dearblue <dearblue@users.noreply.github.com>
Date:   Sun Jan 20 12:00:38 2019 +0900

    Fix NULL pointer dereference `mrb->nomem_err` when not initialized

    Add internal functions (not `static`):

      * `mrb_raise_nomemory()`
      * `mrb_core_init_abort()`
2020-06-05 14:40:07 +09:00
Yukihiro "Matz" Matsumoto 00f6271e3b Change arena index from mrb_int to int. 2020-06-05 14:40:07 +09:00
Yukihiro "Matz" Matsumoto b0e49ef79e Merge pull request #5019 from mruby/stable
Merge mruby 2.1.1
2020-06-05 13:04:36 +09:00
Hiroshi Mimaki 81d340e042 Merge master. 2020-06-05 12:42:56 +09:00
Yukihiro "Matz" Matsumoto 4e40169ed6 Remove rake -v option from GitHub Actions. 2020-06-04 18:24:58 +09:00
Yukihiro "Matz" Matsumoto 49f1c0e94d Ignore files for clangd.
- `compile_flags.txt'
- `compile_commands.json`
2020-06-04 18:09:03 +09:00
Yukihiro "Matz" Matsumoto dcfebc6eed Remove bison installation from GitHub Actions. 2020-06-04 18:08:08 +09:00
Hiroshi Mimaki f9d113f764 Update release date. 2020-06-04 17:20:46 +09:00
Yukihiro "Matz" Matsumoto 3d2d9f8a9b Add explicit cast to DROP_PRECISION macro in rtional.c. 2020-06-04 11:01:31 +09:00
Yukihiro "Matz" Matsumoto 07129c76d9 Add mruby-complex and mruby-rational to default.gembox. 2020-06-04 11:01:30 +09:00
Yukihiro "Matz" Matsumoto 6fe03f3b39 Add explicit cast to silence warnings on AppVeyor. 2020-06-04 11:01:30 +09:00
Yukihiro "Matz" Matsumoto 41f3456a28 Merge pull request #4865 from take-cheeze/istruct_align
Align RIStruct data for rational/complex
2020-06-04 11:01:04 +09:00
Yukihiro "Matz" Matsumoto 7a420d4bba Add .ccls* to .gitignore. 2020-06-04 10:05:42 +09:00
Yukihiro "Matz" Matsumoto d2b9c90f28 Merge branch 'dearblue-hide-func'; merge #4937 2020-06-03 14:16:11 +09:00
dearblue ce12ef7e5c Hiding method implementation C functions in mruby-io 2020-06-03 14:12:51 +09:00
Yukihiro "Matz" Matsumoto 8bca11a64e Merge pull request #4800 from shuujii/set-MRB_STR_ASCII-flag-to-some-stringize-methods
Set `MRB_STR_ASCII` flag to some stringize methods
2020-06-03 14:01:52 +09:00
Yukihiro "Matz" Matsumoto 14e325e45d Merge branch 'dearblue-eval-patchfree'; close #5016 2020-06-02 14:49:49 +09:00
dearblue f85906b679 Remove patch_irep() in mruby-eval
- It can now deal with operands in the range of `OP_EXT*`.
- It can now call the same method as the variable name without arguments.

  ```ruby
  def a
    "Safe!"
  end

  a = "Auto!"

  eval "a()" # call method `a`
  ```
2020-06-02 14:49:27 +09:00
Yukihiro "Matz" Matsumoto 1fc9345b45 Add mruby-eval to default.gembox. 2020-06-01 23:00:37 +09:00
Yukihiro "Matz" Matsumoto 0a5983dd5e Merge pull request #5014 from dearblue/local_variables
Get local variable names from orphan block; ref #3710
2020-06-01 22:58:17 +09:00
Yukihiro "Matz" Matsumoto aec40d10b8 Merge pull request #5017 from RoryO/master
Fix float constant redefinition warnings
2020-06-01 21:26:57 +09:00
Rory OConnell 89ceb3e7ba Fix float constant redefinition warnings 2020-05-31 20:11:38 -07:00
dearblue fc80e4b651 Get local variable names from orphan block; ref #3710 2020-05-31 15:56:04 +09:00
KOBAYASHI Shuji 52ab095ccf Print exception backtrace if possible without -v in test
Backtrace is useful for debugging.
2020-05-29 13:46:16 +09:00
Yukihiro "Matz" Matsumoto d5cca2bdb2 Check c->eidx before decrement in ecall(); close #4977 2020-05-28 18:53:27 +09:00
Yukihiro "Matz" Matsumoto ebbb4fd7fb Merge pull request #5011 from shuujii/respect-CFLAGS-CXXFLAGS-and-LDFLAGS-env-vars-in-appveyor_config.rb
Respect CFLAGS, CXXFLAGS, and LDFLAGS env vars in appveyor_config.rb
2020-05-27 22:15:44 +09:00
KOBAYASHI Shuji b717cc7830 Respect CFLAGS, CXXFLAGS, and LDFLAGS env vars in appveyor_config.rb
[skip travis]
2020-05-27 16:50:44 +09:00
Yukihiro "Matz" Matsumoto a476c83caf Move fmt_setup until absolutely necessary. 2020-05-27 14:09:36 +09:00
Yukihiro "Matz" Matsumoto 15c63688e3 Integer format can be bigger than 32 on 64bit platforms.
We made it `64` which should be big enough:
- Format modifier: 4 characters max
- Maximum width: 19 digits max
- Period between width and precision: 1 character
- Maximum precision: 19 digits max
- Format specifier: 1 character
- NUL terminator: 1 byte
- Total: 45 < 64
2020-05-26 23:53:16 +09:00
Yukihiro "Matz" Matsumoto 69c62415c0 Merge pull request #5010 from udzura/patch-1
Detect newly added mrbgems when re-creating gem_init.c
2020-05-26 23:37:22 +09:00
Kondo Uchio 690b2aa761 Detect newly added mrbgems when re-creating gem_init.c 2020-05-26 23:15:00 +09:00
Yukihiro "Matz" Matsumoto 69311fa4c9 Merge pull request #5009 from shuujii/removed-Bison-related-settings-from-.travis.yml-and-appveyor.yml
Removed Bison related settings from `.travis.yml` and `appveyor.yml`
2020-05-26 20:17:49 +09:00
Yukihiro "Matz" Matsumoto ab9be1b48a Merge pull request #5008 from shuujii/revert-part-of-Start-GitHub-Actions
Revert part of "Start GitHub Actions" (4ce3997c)
2020-05-26 12:43:38 +09:00
KOBAYASHI Shuji 5a682bfc7b Removed Bison related settings from .travis.yml and appveyor.yml 2020-05-26 11:56:35 +09:00
KOBAYASHI Shuji 53ea8abea6 Revert part of "Start GitHub Actions" (4ce3997c)
Because some changes have been overridden.
2020-05-26 11:48:42 +09:00
Yukihiro "Matz" Matsumoto 6445e4683f Specify the latest bison on macOS; ref #4903 2020-05-26 08:17:39 +09:00
Yukihiro "Matz" Matsumoto 6d49ec25a9 Merge pull request #5007 from shuujii/add-y.tab.c-to-remove-Bison-from-build-dependencies
Add `y.tab.c` to remove Bison from build dependencies; ref 4ce3997c
2020-05-26 08:17:23 +09:00
KOBAYASHI Shuji a3ec6ede76 Add y.tab.c to remove Bison from build dependencies; ref 4ce3997c
I sometimes see Bison related problems in setting up build environments.
Therefore to remove Bison from build time dependencies, add `y.tab.c`
generated by Bison to the repository.

The reduction of dependency at build time also reduces the labor and time
for setup and installation in CI.

In addition, a path in `#line` directive is converted to a relative path so
that its path is constant regardless of development environments.
2020-05-25 23:26:30 +09:00
Yukihiro "Matz" Matsumoto 6803ddb8e2 Use the newer bison on GitHub actions macOS; ref #4903
`Windows-MinGW` and `Windows-VC` also requires updates.
2020-05-24 23:12:27 +09:00
Takeshi Watanabe 4ce3997ca4 Start GitHub Actions; close #4903 2020-05-24 22:34:28 +09:00
Yukihiro "Matz" Matsumoto 93e78fcde1 Merge pull request #5006 from mame/fix-send-with-splat-args
Do not destruct rest arguments for __send__
2020-05-24 08:31:06 +09:00
Yusuke Endoh 6f4c585bd7 Do not destruct rest arguments for __send__
Formerly, `__send__(*args)` modified `args` with `Array#shift`.
This bug affects optcarrot.

This changeset avoids the array destruction by using
`args = args[1, len-1]`.
2020-05-24 01:25:03 +09:00
Yukihiro "Matz" Matsumoto 47ea60814b Merge pull request #5003 from shuujii/retry-rake--m-on-AppVeyor
Retry `rake -m` on AppVeyor [skip travis]
2020-05-20 13:49:10 +09:00
KOBAYASHI Shuji 86223b6eca Retry rake -m on AppVeyor [skip travis]
The following error occurs when using `rake -m` on AppVeyor:

  ```
  fatal error C1041: cannot open program database 'C:\projects\mruby\vc140.pdb'; if multiple CL.EXE write to the same .PDB file, please use /FS
  ```

Therefore, the issue is solved by not creating the PDB file. It is expected
to be somewhat faster by not generating debugging information (I don't think
debugging information is necessary for normal CI).
2020-05-20 13:32:23 +09:00
Yukihiro "Matz" Matsumoto d79147fe5d Revert "Use rake -m (multi-task) to appveyor.yml."
This reverts commit ac68c90800.
`rake -m` does not work for VisualC.
2020-05-19 22:42:19 +09:00
Yukihiro "Matz" Matsumoto ac68c90800 Use rake -m (multi-task) to appveyor.yml. 2020-05-19 17:37:17 +09:00
Yukihiro "Matz" Matsumoto 82194c01ca Merge pull request #5002 from RoryO/master
Adding warnings for mrb_load functions leaking RProc objects
2020-05-19 17:34:56 +09:00
Rory OConnell 69bc477b43 Adding warnings for mrb_load functions leaking RProc objects 2020-05-19 01:07:49 -07:00
Yukihiro "Matz" Matsumoto 3655d4e0f4 Merge pull request #5000 from shuujii/unify-eql-receiver-in-Hash-according-to-Ruby
Unify `eql?` receiver in `Hash` according to Ruby
2020-05-15 23:42:19 +09:00
KOBAYASHI Shuji bc929656fb Unify eql? receiver in Hash according to Ruby
### Example

  ```ruby
  # example.rb
  class A
    def eql?(o)
      p self.class
      super
    end
    def hash
      1
    end
  end

  class B < A; end

  h = {A.new => 1}
  h[B.new]
  ```

#### Before this patch:

  ```console
  $ bin/mruby example.rb
  A
  ```

#### After this patch (same as Ruby)

  ```console
  $ bin/mruby example.rb
  B
  ```
2020-05-15 21:17:24 +09:00
Yukihiro "Matz" Matsumoto 4aba93c969 Rename C function mrb_proc_lambda. 2020-05-15 15:55:35 +09:00
Yukihiro "Matz" Matsumoto 49d97d6051 Add pread/pwrite support on __MACH__ (MacOS) in addition to __unix__. 2020-05-15 12:31:18 +09:00
Yukihiro "Matz" Matsumoto 484577670f Remove YYERROR_VERBOSE which no longer supported since bison 3.6.
Instead we added `%define parse.error verbose`.
2020-05-15 12:30:13 +09:00
Yukihiro "Matz" Matsumoto d64c4d64e6 Make off_t handling simpler; #4872 #4939
The newer `clang` warns implicit float conversions.
2020-05-11 10:14:25 +09:00
Yukihiro "Matz" Matsumoto 846af371c0 Merge pull request #4998 from dearblue/special-vars
Get an irep symbol if it's `OP_GETSV` or `OP_SETSV`
2020-05-11 09:59:23 +09:00
Yukihiro "Matz" Matsumoto 38b4483f9d Merge pull request #4999 from dearblue/opcode-doc
Update `doc/opcode.md` [ci skip]
2020-05-11 09:58:11 +09:00
dearblue bb2512641f Update doc/opcode.md [ci skip]
The difference of `include/mruby/ops.h` is applied.

- OP_NOP - update semantics
- OP_GETSV - update semantics
- OP_SETSV - update semantics
- OP_GETUPVAR - update prefix
- OP_SETUPVAR - update prefix
- OP_JMPIF - update operands and semantics
- OP_JMPNOT - update operands and semantics
- OP_JMPNIL - add entry
- OP_ONERR - update semantics
- OP_POPERR - update prefix
- OP_EPOP - update prefix
- OP_SENDB - update semantics
- OP_ADD - update prefix and operands
- OP_ADDI - update operands and semantics
- OP_SUB - update prefix and operands
- OP_SUBI - update semantics
- OP_MUL - update prefix and operands
- OP_DIV - update prefix and operands
- OP_EQ - update prefix and operands
- OP_LT - update prefix and operands
- OP_LE - update prefix and operands
- OP_GT - update prefix and operands
- OP_GE - update prefix and operands
- OP_ARYDUP - add entry
- OP_INTERN - add entry
- OP_HASHCAT - add entry
- OP_ERR - update semantics
2020-05-10 20:34:10 +09:00
dearblue bd60ad98eb Get an irep symbol if it's OP_GETSV or OP_SETSV 2020-05-10 20:15:55 +09:00
Yukihiro "Matz" Matsumoto 7826af38ac Merge pull request #4997 from dearblue/byteorder
Remove byteorder constants; ref 87576b8
2020-05-09 23:01:02 +09:00
Yukihiro "Matz" Matsumoto 84d842ea5c Merge pull request #4996 from dearblue/loadi16
Fix boundary check for `OP_LOADI16`; ref fa8668c
2020-05-09 22:41:23 +09:00
dearblue f6c2662632 Remove byteorder constants; ref 87576b8
The `FLAG_BYTEORDER_NATIVE` and `FLAG_BYTEORDER_NONATIVE` are no longer
needed.
2020-05-09 22:30:05 +09:00
dearblue e2aecacaeb Fix boundary check for OP_LOADI16; ref fa8668c
It was making a negative integer if the highest-order bit of a 16-bit
integer was 1.

no patched:

```ruby
p 0x7fff  # => 32767
p 0x8000  # => -32768
p 0xffff  # => -1
p 0x10000 # => 65536
```
2020-05-09 21:12:31 +09:00
Yukihiro "Matz" Matsumoto 8cdf6a87ed Merge pull request #4995 from shuujii/fix-some-Hash-methods-are-inconsistent-with-values
Fix some `Hash` methods are inconsistent with `values`
2020-05-09 18:59:22 +09:00
KOBAYASHI Shuji 181f7b97d6 Fix some Hash methods are inconsistent with values
Inconsistent when hash has duplicate key.

### Example

  ```ruby
  # example.rb
  keys = (1..3).map{[_1]}
  h = keys.to_h{[_1, _1[0]]}
  keys[0][0] = 2
  p h.values
  p h.each_value.to_a
  p h
  ```

#### Before this patch:

  ```console
  $ bin/mruby example.rb
  [1, 2, 3]
  [1, 1, 3]
  {[2]=>1, [2]=>1, [3]=>3}
  ```

#### After this patch (same as Ruby)

  ```console
  $ bin/mruby example.rb
  [1, 2, 3]
  [1, 2, 3]
  {[2]=>1, [2]=>2, [3]=>3}
  ```
2020-05-09 15:27:42 +09:00
Yukihiro "Matz" Matsumoto 3491372a1d Update doc/opcode.md for operand signs. [ci skip] 2020-05-07 18:41:43 +09:00
Yukihiro "Matz" Matsumoto 03b0741994 Remove unnecessary sprintf test that fails since 91368c1. 2020-05-07 10:31:49 +09:00
Yukihiro "Matz" Matsumoto a87f0b158d Update README.md to address old bison problem on macOS. 2020-05-07 10:17:38 +09:00
Yukihiro "Matz" Matsumoto 5e01674b72 Should not use assert with expressions with side-effect; ref #4981
`assert()` can be completely removed when `NDEBUG` is set.
2020-05-07 09:37:02 +09:00
Yukihiro "Matz" Matsumoto b652a4ff14 Fixed wrong condition in #4981. 2020-05-07 09:36:43 +09:00
Yukihiro "Matz" Matsumoto 7dc0fe66c7 Add #include <string.h> on all platforms for strncpy; #4981 2020-05-07 09:36:21 +09:00
Yukihiro "Matz" Matsumoto 1cdcd00cc0 Remove unused local variable if MRB_UTF8_STRING is not set.
Ref #4982 #4983
2020-05-07 09:35:47 +09:00
Yukihiro "Matz" Matsumoto 9f4b5227fe Avoid snprintf in mruby-io test; ref #4981 2020-05-07 09:33:44 +09:00
Yukihiro "Matz" Matsumoto d464fe5003 Remove the temporary file from the AF_UNIX socket test; #4981 2020-05-07 09:33:08 +09:00
Yukihiro "Matz" Matsumoto 6b839b2319 Fix IO#readchar to return broken UTF-8 rather than EOF error.
The behavior is different from CRuby, but we believe this is a right
behavior for mruby, which only supports either ASCII or UTF-8
exclusively; fix #4983, ref #4982

```
$ printf '\xe3\x81' | ruby -e 'p STDIN.readchar'
"\xE3\x81"
```

```
$ printf '\xe3\x81' | mruby -e 'p STDIN.readchar'
"\xE3"
```
2020-05-07 09:32:46 +09:00
Yukihiro "Matz" Matsumoto 45bd372755 Fix IO#readchar to support UTF-8 char reading; fix #4712
This fix only effective when `MRB_UTF8_STRING` is set.
2020-05-07 09:31:38 +09:00
Yukihiro "Matz" Matsumoto f5ee7df7f3 Rename (and expose) UTF-8 related functions; ref #4712
- mrb_utf8len() - returns the size of a UTF-8 char (in bytes)
- mrb_utf8_strlen() - returns the length of a UTF-8 string (in char)
2020-05-07 09:31:07 +09:00
Yukihiro "Matz" Matsumoto e82b8b7bf8 Update cmpnum document.
`cmpnum` function may return `nil` on error.
2020-05-07 08:38:46 +09:00
Yukihiro "Matz" Matsumoto 91368c117c Avoid mrb_funcall if MRB_UFT8_STRING is not set. 2020-05-07 08:38:46 +09:00
Yukihiro "Matz" Matsumoto 87576b819e Remove endian information/flags from compiled binary format.
Since `mruby 2.0`, compiled bytecode no longer depends on the
endian of the machine.
2020-05-07 08:38:46 +09:00
Yukihiro "Matz" Matsumoto 48c473a0c4 Remove -e/-E options from mrbc.
You don't have to specify endian since `mruby 2.0`.
2020-05-07 08:38:46 +09:00
Yukihiro "Matz" Matsumoto 87d77c13f5 Update compiled binary format version for OP_LOADI16. 2020-05-07 08:38:46 +09:00
Yukihiro "Matz" Matsumoto 4188219620 Update doc/opcode.md to reflect the latest bytecode.
- Add `OP_LOADI16`
- Update keyword argument related ops (e.g. OP_KEY_P, etc.)
- Fix some wrong descriptions
2020-05-07 08:38:46 +09:00
Yukihiro "Matz" Matsumoto fa8668c77d Add a new instruction OP_LOADI16.
Which loads 16bit integer to the register. The instruction number should
be reorder on massive instruction refactoring. The instruction is added
for `mruby/c` which had performance issue with `OP_EXT`. With this
instruction, `mruby/c` VM can just raise errors on `OP_EXT` extension
instructions.
2020-05-07 08:38:46 +09:00
Yukihiro "Matz" Matsumoto 47f5f887e8 Fix wrong line number before comment line; fix #4993 2020-05-07 08:38:46 +09:00
Yukihiro "Matz" Matsumoto c143d87e7c Remove mrb_run from MRB_API; #4488
`mrb_run` requires to push callinfo stack before calling, which is very
hard from outside of `vm.c`. So there should be virtually no correct
usage of the function, hence the cause of #4488. We removed it.

You can use `mrb_top_run(mrb, proc, self, 0)` instead of
`mrb_run(mrb, proc self)`.
2020-05-07 08:38:46 +09:00
Yukihiro "Matz" Matsumoto 2fcdd3f8eb Add assertion as originally intended; ref #4986 2020-05-07 08:38:46 +09:00
Yukihiro "Matz" Matsumoto 8c0dc55af8 Update doc/guides/compile.md to note the bison failure on Mac. 2020-05-07 08:38:46 +09:00
Yukihiro "Matz" Matsumoto 8c04379a4c Merge pull request #4990 from komainu8/enable-method-t-struct-on-32bit-linux
Enable MRB_METHOD_T_STRUCT by default on 32bit GUN/Linux
2020-05-05 22:57:40 +09:00
Horimoto Yasuhiro a5bfe548d7 Enable MRB_METHOD_T_STRUCT by default on 32bit GUN/Linux
Because we can't use the highest 2 bits of function pointers.
2020-05-04 15:34:16 +09:00
Yukihiro "Matz" Matsumoto e77e6e9d12 Fix _read_buf to be more efficient; fix #4982
The bug was introduced by #4712. The `getc' problem resurrected.
It should be addressed soon.
2020-05-01 16:57:45 +09:00
Yukihiro "Matz" Matsumoto a2b87c033a Fix IO#sysread to update buffer string on EOF; ref #4982 2020-05-01 16:54:13 +09:00
Yukihiro "Matz" Matsumoto b3c5d94bd1 Update IO#ungetc to keep @buf string; ref #4982 2020-05-01 16:53:55 +09:00
Yukihiro "Matz" Matsumoto d029549c2f Fix UTF-8 boundary check; ref #4982 2020-05-01 16:53:25 +09:00
Uchio Kondo 6e13467ce8 Fix typo and include location 2020-05-01 16:52:11 +09:00
Uchio Kondo 508ac2030e Skip socket check on windows 2020-05-01 16:51:47 +09:00
Uchio Kondo 4b81bce48d Follow C90 style 2020-05-01 16:51:22 +09:00
Uchio Kondo 3486675e00 Test mruby-io in tmpdir when AF_UNIX cannot be created on cwd 2020-05-01 16:50:54 +09:00
Yukihiro "Matz" Matsumoto 84aad39940 Merge pull request #4987 from shuujii/avoid-changing-directory-in-mruby-io-test
Avoid changing directory in `mruby-io` test
2020-04-30 17:13:11 +09:00
Yukihiro "Matz" Matsumoto c89ca5ebb8 Merge pull request #4988 from shuujii/refine-.travis.yml
Refine `.travis.yml`
2020-04-30 17:12:36 +09:00
KOBAYASHI Shuji 1a4b86233f Refine .travis.yml
* Disable automatic update and clean up on `brew install` (install time
  160 sec -> 5 sec).
* Avoid using deprecated keys.
2020-04-30 13:42:24 +09:00
Yukihiro "Matz" Matsumoto 69a487c407 Merge pull request #4984 from dearblue/break-to_s
Sorting the list of gems at build time by name
2020-04-30 08:38:33 +09:00
Yukihiro "Matz" Matsumoto f32c73ad1f Merge pull request #4986 from dearblue/assert-io
Avoid comparing pointers and integers
2020-04-29 18:34:40 +09:00
Yukihiro "Matz" Matsumoto a343439973 Merge pull request #4985 from dearblue/print-gems
Makes `mrb_any_to_s()` accept an object whose class is `NULL`
2020-04-29 18:34:03 +09:00
KOBAYASHI Shuji aeb86d953e Avoid changing directory in mruby-io test 2020-04-29 17:48:01 +09:00
dearblue 49bba6c997 Avoid comparing pointers and integers 2020-04-29 17:18:09 +09:00
dearblue 49b2e8c3a9 Makes mrb_any_to_s() accept an object whose class is NULL
When using `mrb_any_to_s()` for debugging purposes, giving an object
whose class is `NULL` no longer causes a SIGSEGV and no crash.
This is achieved by making `mrb_class_name()` and `mrb_str_cat_cstr()`
null safe.
2020-04-29 16:59:16 +09:00
dearblue 9c1220e14d Sorting the list of gems at build time by name
Printing them in sorted order makes it easier to find the desired gem.
But it has come to completely ignore the dependency.
2020-04-29 16:55:18 +09:00
Yukihiro "Matz" Matsumoto e2ac2a82a5 Should not use assert with expressions with side-effect; ref #4981
`assert()` can be completely removed when `NDEBUG` is set.
2020-04-28 22:37:14 +09:00
Yukihiro "Matz" Matsumoto bb6290a5d5 Fixed wrong condition in #4981. 2020-04-28 22:34:33 +09:00
Yukihiro "Matz" Matsumoto 312411dea0 Add #include <string.h> on all platforms for strncpy; #4981 2020-04-28 22:34:33 +09:00
Yukihiro "Matz" Matsumoto 7277682cfb Remove unused local variable if MRB_UTF8_STRING is not set.
Ref #4982 #4983
2020-04-28 22:34:01 +09:00
Yukihiro "Matz" Matsumoto 0f229bfbbf Avoid snprintf in mruby-io test; ref #4981 2020-04-28 18:30:50 +09:00
Yukihiro "Matz" Matsumoto 28b23b44ec Remove the temporary file from the AF_UNIX socket test; #4981 2020-04-28 18:13:43 +09:00
Yukihiro "Matz" Matsumoto 8627157298 Fix IO#readchar to return broken UTF-8 rather than EOF error.
The behavior is different from CRuby, but we believe this is a right
behavior for mruby, which only supports either ASCII or UTF-8
exclusively; fix #4983, ref #4982

```
$ printf '\xe3\x81' | ruby -e 'p STDIN.readchar'
"\xE3\x81"
```

```
$ printf '\xe3\x81' | mruby -e 'p STDIN.readchar'
"\xE3"
```
2020-04-28 18:07:17 +09:00
Yukihiro "Matz" Matsumoto b87268f130 Fix IO#readchar to support UTF-8 char reading; fix #4712
This fix only effective when `MRB_UTF8_STRING` is set.
2020-04-28 13:57:46 +09:00
Yukihiro "Matz" Matsumoto a395f8e2c8 Rename (and expose) UTF-8 related functions; ref #4712
- mrb_utf8len() - returns the size of a UTF-8 char (in bytes)
- mrb_utf8_strlen() - returns the length of a UTF-8 string (in char)
2020-04-28 13:57:46 +09:00
Yukihiro "Matz" Matsumoto 3ce459f23a Fix _read_buf to be more efficient; fix #4982
The bug was introduced by #4712. The `getc' problem resurrected.
It should be addressed soon.
2020-04-28 13:57:46 +09:00
Yukihiro "Matz" Matsumoto e51923778f Fix IO#sysread to update buffer string on EOF; ref #4982 2020-04-28 13:57:46 +09:00
Yukihiro "Matz" Matsumoto 468578113a Update IO#ungetc to keep @buf string; ref #4982 2020-04-28 13:57:46 +09:00
Yukihiro "Matz" Matsumoto 2c32154115 Fix UTF-8 boundary check; ref #4982 2020-04-28 13:57:46 +09:00
Yukihiro "Matz" Matsumoto 47d99457d9 Merge pull request #4981 from udzura/fix-test-mruby-io-on-vboxsf
Test mruby-io in tmpdir when AF_UNIX cannot be created on cwd
2020-04-28 09:46:56 +09:00
Uchio Kondo 88b756b39f Fix typo and include location 2020-04-28 01:52:56 +09:00
Uchio Kondo 462ff4cc84 Skip socket check on windows 2020-04-28 01:49:39 +09:00
Uchio Kondo 18274e717a Follow C90 style 2020-04-28 01:45:46 +09:00
Uchio Kondo 7870f74c21 Test mruby-io in tmpdir when AF_UNIX cannot be created on cwd 2020-04-28 01:33:50 +09:00
Yukihiro "Matz" Matsumoto 8dee2e3984 Updating parse.y for recent bison` (retry). 2020-04-27 18:52:43 +09:00
Yukihiro "Matz" Matsumoto 8e86e64d78 Revert "Change obsolete %pure-parser to %define api.pure."
This reverts commit 682a31f92b.
Unfortunately, I couldn't run newer `bison` on TravisCI. Maybe next
time.
2020-04-27 12:27:56 +09:00
Yukihiro "Matz" Matsumoto e79e972255 Update .travis.yml to support newer bison on MacOS.
If it doesn't work, I will revert the last update to `parse.y`.
2020-04-27 12:21:35 +09:00
Yukihiro "Matz" Matsumoto 682a31f92b Change obsolete %pure-parser to %define api.pure.
Recent `bison` warns for `%pure-parser`. We kept it since MacOS only
provide ancient `bison`, but the warning is noisy and there's no hope
that Apple will upgrade `bison`. MacOS users must install the newer
version of `bison`, by typing `brew install bison` for example.

Note that `brew` does not overwrite the `bison` execution path
automatically, so you need to update your `.bash_profile` as instructed
by `brew`.
2020-04-27 09:00:22 +09:00
Yukihiro "Matz" Matsumoto 17974aa285 Merge pull request #4978 from dearblue/test-ensure
Integrate class `EnsureYieldBreak` under test
2020-04-27 09:00:13 +09:00
Yukihiro "Matz" Matsumoto 0a7fd86d59 Merge pull request #4980 from dearblue/context
Reduce `struct mrb_context`
2020-04-27 08:59:19 +09:00
Yukihiro "Matz" Matsumoto d95d46dee6 Merge pull request #4979 from dearblue/mruby-bin
Remove unused `mruby-error` in `mruby-bin-mruby`
2020-04-27 08:56:50 +09:00
dearblue 81c8352179 Integrate class EnsureYieldBreak under test 2020-04-26 21:16:44 +09:00
dearblue 6d80c9505d Remove unused mruby-error in mruby-bin-mruby 2020-04-26 21:16:22 +09:00
dearblue 1b0cf6a91b Reduce struct mrb_context 2020-04-26 21:15:24 +09:00
Yukihiro "Matz" Matsumoto 954ce5379c Implemented argument forwarding by ... 2020-04-25 00:00:22 +09:00
Yukihiro "Matz" Matsumoto 8b5c19218d Merge pull request #4976 from dearblue/splice-undef
Support `undef` for `mrb_ary_splice()` instead of `[]`
2020-04-24 23:36:12 +09:00
Yukihiro "Matz" Matsumoto f6408c7b11 Merge pull request #4975 from dearblue/io-comment
Removed comments mentioning `MRB_WITHOUT_FLOAT`; ref 2e661e8
2020-04-24 23:35:10 +09:00
dearblue 095aae5e2c Removed comments mentioning MRB_WITHOUT_FLOAT; ref 2e661e8
The comment is for messages when `MRB_INT16` and `MRB_WITHOUT_FLOAT` are
specified at the same time.
The comment itself is no longer needed now that `MRB_INT16` is gone.
2020-04-24 21:47:20 +09:00
dearblue 26eb29547b Support undef for mrb_ary_splice() instead of []
When removing elements from an array, it is possible to avoid creating
an empty array.

Before this patch:

```c
mrb_ary_splice(mrb, ary, head, len, mrb_ary_new(mrb));
```

After this patch:

```c
mrb_ary_splice(mrb, ary, head, len, mrb_undef_value());
```
2020-04-24 21:32:35 +09:00
Yukihiro "Matz" Matsumoto d3a02a297f Fix instance_exec and class_exec to avoid crash on indirect calls.
Thank you @shuujii to additional report on #4973
2020-04-22 16:48:33 +09:00
Yukihiro "Matz" Matsumoto ab508e1e7f Make mrb_obj_instance_eval to use mrb_singleton_class_ptr; #4973 2020-04-22 16:47:26 +09:00
Yukihiro "Matz" Matsumoto 87d1bbe947 Add new function mrb_singleton_class_ptr(); ref #4973
The difference between `mrb_singleton_class` and `mrb_singleton_class_ptr`:

- `mrb_singleton_class_ptr` returns `struct RClass*`.
- `mrb_singleton_class_ptr` returns `NULL` on immediate values where
  `mrb_singleton_class` raises exceptions.
2020-04-22 16:44:39 +09:00
Yukihiro "Matz" Matsumoto 2e661e82d1 Removed comments mentioning MRB_INT16. 2020-04-21 20:47:22 +09:00
Yukihiro "Matz" Matsumoto 61c6832b48 Fix the bug by #instance_eval called via a method object; fix #4973
The tranpoline code in 6a0b68f8b was wrong; reverted.
2020-04-21 15:44:21 +09:00
Yukihiro "Matz" Matsumoto ed0038fdf2 Simplified mrb_obj_instance_eval; ref #4973 2020-04-21 15:43:35 +09:00
Yukihiro "Matz" Matsumoto c181d89c9d Kernel#clone and Kernel#dup no longer raise TypeError; fix #4974
In ISO, those methods should raise `TypeError`, but the spec has been
changed.  The change was discussed in [Feature#12979].
2020-04-21 13:21:12 +09:00
Yukihiro "Matz" Matsumoto c91c9e2429 Merge pull request #4968 from dearblue/check-fd
Check the file descriptor with `IO#initialize`; resolve #4966
2020-04-15 09:58:20 +09:00
Yukihiro "Matz" Matsumoto 7add524041 Selecting fd should be less than FD_SETSIZE; close #4966 2020-04-14 14:51:22 +09:00
Yukihiro "Matz" Matsumoto 72928f201c Merge pull request #4972 from dearblue/boxnan-cptr
Fix `MRB_TT_CPTR` object with `MRB_NAN_BOXING`
2020-04-14 14:51:00 +09:00
Yukihiro "Matz" Matsumoto 81a9210091 Merge pull request #4969 from dearblue/nostdio-pack
Support `MRB_DISABLE_STDIO` for mruby-pack; ref #4954
2020-04-14 14:46:25 +09:00
Yukihiro "Matz" Matsumoto e9877bc72a Merge pull request #4970 from dearblue/nostdio-sprintf
Support `MRB_DISABLE_STDIO` for mruby-sprintf; ref #4954
2020-04-14 14:45:26 +09:00
Yukihiro "Matz" Matsumoto ea632ab8a4 Merge pull request #4971 from dearblue/mruby-config
Fixed a build error in mruby-config
2020-04-14 09:29:00 +09:00
dearblue d0501c69b0 Fix MRB_TT_CPTR object with MRB_NAN_BOXING
Previously, if `MRB_NAN_BOXING` is defined, for example,
`mrb_cptr_value()` could not keep an odd address.

If it is `MRB_32BIT`, it can be embedded in `NaN` as it is.

If it is `MRB_64BIT`, some operations are shared with `MRB_WORD_BOXING`.
In this case, the MRB_API function `mrb_nan_boxing_cptr_value()` is
defined.
2020-04-13 23:12:09 +09:00
dearblue 3c03385e2e Check the file descriptor with IO#initialize; resolve #4966 2020-04-12 14:18:36 +09:00
dearblue 191ccbf660 Support MRB_DISABLE_STDIO for mruby-sprintf; ref #4954 2020-04-11 22:11:24 +09:00
dearblue d983269908 Add mrb_float_to_cstr() MRB_API function
In order to share the same operation with `mrb_float_to_str()`,
the internal structure is modified.
2020-04-11 22:11:24 +09:00
dearblue 2ceab2d270 Supports some specifier flags with mrb_float_to_str()
Changed to understand `#`, `0`, `-`, ` ` and `+`.

Based on src/stdio/vfprintf.c in git://git.musl-libc.org/musl
2020-04-11 22:11:10 +09:00
dearblue 8ce3664305 Supports width specifier with mrb_float_to_str()
Based on src/stdio/vfprintf.c in git://git.musl-libc.org/musl
2020-04-11 22:10:57 +09:00
dearblue ccd8485111 Add missing MRB_API 2020-04-11 21:59:30 +09:00
dearblue 70caf4ed6d Fixed a build error in mruby-config
The build error occurred when the "build/XXX/bin" directory did not exist.
2020-04-11 15:43:24 +09:00
dearblue b7c8bf7781 Support MRB_DISABLE_STDIO for mruby-pack; ref #4954 2020-04-11 15:29:07 +09:00
Hiroshi Mimaki 3d46f1b620 Update version to 2.1.1. (mruby 2.1.1 RC) 2020-04-10 13:05:23 +09:00
Yukihiro "Matz" Matsumoto 63c7ff341a Merge pull request #4965 from mimaki/remove-cygwin_filename
Merged `cygwin_filename()` into `filename()`.
2020-04-08 22:40:49 +09:00
mimaki a8ab74a6dc Merged cygwin_filename() into filename() because Cygwin pathnames are in UNIX format. 2020-04-08 13:27:14 +09:00
Yukihiro "Matz" Matsumoto 7ab5353f80 Merge pull request #4960 from Reckordp/BuildAndroid
Validate windows by Dir testing
2020-04-05 14:17:09 +09:00
Reckordp d7df30bdd8 Unused library folder 2020-04-04 21:57:13 +07:00
Reckordp d317ee144b Correct naming file from Mingw 2020-04-04 21:56:40 +07:00
Yukihiro "Matz" Matsumoto 3cef380b20 Revert part of #4959
To prevent infinite loop on errors; reported by @shuujii
2020-04-04 11:50:59 +09:00
Reckordp 707933aa8e Helper for link window's library 2020-04-03 20:34:00 +07:00
Yukihiro "Matz" Matsumoto 068b16a352 Merge pull request #4959 from dsisnero/master
build when directories and files have spaces
2020-04-02 13:26:53 +09:00
dsisnero c7ab4cf616 fix for quoting visualcpp 2020-04-01 12:31:48 -06:00
Dominic Sisneros e3875ae8c5 build when directories and files have spaces
Modified the build to quote filenames so that it builds when files have spaces
2020-04-01 11:55:35 -06:00
Yukihiro "Matz" Matsumoto 226fcb4f2a Avoid unnecessary nextc() recursion. 2020-04-01 23:23:07 +09:00
Yukihiro "Matz" Matsumoto d22b72a7cc Merge pull request #4957 from dearblue/excessive-arena
Fix `mrb_funcall_with_block()` uses more GC arena
2020-04-01 15:40:25 +09:00
dearblue 15dec83832 Fix mrb_funcall_with_block() uses more GC arena
If `mrb->jmp` is `NULL` and the function `mrb_funcall_with_block()` is
called, GC Arena is returned from the function with over-used.

- A normal (no global exodus) return will consume two GC Arena's.
- In the event of an exception, five GC Arena are consumed.

This patch reduces consumption in both cases to one.
2020-03-31 23:24:53 +09:00
Yukihiro "Matz" Matsumoto 5acd802d2b Merge pull request #4956 from dearblue/null-local_variables
Fix NULL pointer dereferences in mrb_local_variables; fix #4955
2020-03-31 22:04:18 +09:00
dearblue 9b15860ddb Fix NULL pointer dereferences in mrb_local_variables; fix #4955
However, the behavior of `#call` on the method object of
`local_variables` is not corrected.
2020-03-30 23:52:59 +09:00
Yukihiro "Matz" Matsumoto 0dacc9a62a Merge pull request #4954 from dearblue/nostdio
Improve configuration guard
2020-03-08 22:37:22 +09:00
dearblue 67606170e3 Add configuration guard for MRB_DISABLE_STDIO
ref #4576 and ref #4947

* Need MRBAPI functions without `MRB_DISABLE_STDIO`:
  * mrbgems/mruby-bin-debugger
  * mrbgems/mruby-bin-mirb
  * mrbgems/mruby-bin-mrbc
  * mrbgems/mruby-bin-mruby
  * mrbgems/mruby-bin-strip
* Need `stdio.h`:
  * mrbgems/mruby-io
  * mrbgems/mruby-print
* Need `snprintf()` in `stdio.h`:
  * mrbgems/mruby-pack
  * mrbgems/mruby-sprintf
2020-03-08 21:57:17 +09:00
dearblue cc1db2d117 Remove unnecessary 'stdio.h'; ref #4947
'stdio.h' is included in 'mruby.h' ('mrbconf.h').

However, keep 'stdio.h' used by mruby-test.
2020-03-08 21:42:09 +09:00
dearblue b3d4ab0cd8 Improve conflict error message of mruby-bin-debugger; ref 87d1b2a91 2020-03-08 20:49:22 +09:00
Yukihiro "Matz" Matsumoto 5bf5a2cc6e Merge pull request #4953 from Reckordp/BuildAndroid
Some rule to CrossBuild Android
2020-03-08 19:07:32 +09:00
Yukihiro "Matz" Matsumoto e15e6e761e Merge branch 'master' into BuildAndroid 2020-03-08 19:01:29 +09:00
Yukihiro "Matz" Matsumoto 1cc270f0cc Small refactoring on #4952
Fix the argument of `mrb_file_is_absolute_path()`.
2020-03-08 18:57:49 +09:00
Yukihiro "Matz" Matsumoto 55f3202650 Merge pull request #4952 from Reckordp/master
Traditional, UNC, and Drive Path
2020-03-08 18:52:24 +09:00
Reckordp a8d508c567 Let me in Please 2020-03-08 14:41:38 +07:00
Reckordp 7c85a1ff07 Increase flexibility of CrossBuild 2020-03-08 14:23:55 +07:00
Reckordp dd6f5e4607 Let me in Please 2020-03-08 11:50:26 +07:00
Reckordp ab1465d9d5 Traditional, UNC, and Device Is Absolute? 2020-03-08 10:53:18 +07:00
Reckordp 66c44b8568 Commit from remote 2020-03-08 05:40:47 +07:00
Reckordp 6ee24fe1bc Evaluate all type path 2020-03-08 05:32:27 +07:00
Yukihiro "Matz" Matsumoto 4398bae56a Merge branch 'dearblue-io-pread-pwrite' 2020-03-07 19:07:13 +09:00
Yukihiro "Matz" Matsumoto 20f9128f73 Small refactoring on #4939 2020-03-07 19:06:46 +09:00
Yukihiro "Matz" Matsumoto 6901752723 Use in-house macro ISALPHA instead of isalpha; ref #4950 2020-03-07 19:03:45 +09:00
Yukihiro "Matz" Matsumoto 886355007c Merge branch 'io-pread-pwrite' of https://github.com/dearblue/mruby into dearblue-io-pread-pwrite 2020-03-07 19:00:30 +09:00
Yukihiro "Matz" Matsumoto f45549edbf Merge pull request #4951 from Reckordp/master
Fix unfinished changes
2020-03-07 17:58:26 +09:00
Reckordp 5a4b9fd877 Add absolute path for UNC 2020-03-07 15:50:14 +07:00
Reckordp f319c5fb26 Fix typo 2020-03-07 15:18:48 +07:00
Yukihiro "Matz" Matsumoto 4687f8790c Merge the update suggested by @mattn; ref #4950 2020-03-07 14:58:05 +09:00
Yukihiro "Matz" Matsumoto 30eaee30fa Merge pull request #4950 from Reckordp/master
Absolute path for windows
2020-03-07 14:53:37 +09:00
Reckordp 8df49ea955 Absolute path for windows 2020-03-07 09:09:28 +07:00
Yukihiro "Matz" Matsumoto 7905431fe9 Merge pull request #4948 from kou/32bit-windows-method-t-struct
Enable MRB_METHOD_T_STRUCT by default on 32bit Windows
2020-03-04 21:25:10 +09:00
Sutou Kouhei 96d727177e Enable MRB_METHOD_T_STRUCT by default on 32bit Windows
Because we can't use the highest 2 bits of function pointers.
2020-03-04 18:35:40 +09:00
Yukihiro "Matz" Matsumoto be86bd3c49 Merge pull request #4946 from sizious/sega-dreamcast-example
Improving comments in the cross-compiling sample for the Sega Dreamcast.
2020-02-23 18:01:05 +09:00
SiZiOUS 260dc6d741 Improving comments in the cross-compiling example for the Sega Dreamcast (sh-elf). 2020-02-22 23:44:13 +01:00
Yukihiro "Matz" Matsumoto 3ba32e80af Merge pull request #4945 from Leo-Neat/master
Add CIFuzz action
2020-02-22 14:09:23 +09:00
Yukihiro "Matz" Matsumoto ac5ec1a153 Merge pull request #4944 from sizious/sega-dreamcast-example
Added example for cross-compiling for Sega Dreamcast (sh-elf).
2020-02-22 14:07:46 +09:00
Yukihiro "Matz" Matsumoto 34be5acc99 Merge pull request #4942 from inobelar/patch-1
Updated README.md - Fixed link to github issues
2020-02-22 13:25:11 +09:00
Leo Neat 4713502083 CIFuzz action 2020-02-21 15:27:53 -08:00
SiZiOUS 2f6afb52a9 Added example for cross-compiling for Sega Dreamcast (sh-elf).
Thanks to @yujiyokoo for demonstrating mruby usage on Sega Dreamcast at RubyConf AU 2020!
See more here: https://youtu.be/ni-1x5Esa_o
2020-02-21 22:07:07 +01:00
Yurii Nakonechnyi 20597b6d36 Updated README.md - Fixed link to github issues 2020-02-21 16:57:19 +02:00
Yukihiro "Matz" Matsumoto 0301d8a89b Fix integer boundary check before float to time_t casting. 2020-02-12 11:54:32 +09:00
Yukihiro "Matz" Matsumoto 736ea1f5c7 Merge pull request #4941 from davidsiaw/mac-compat
Include time.h for ios
2020-02-05 23:11:45 +09:00
Yukihiro "Matz" Matsumoto ffb55e51f1 Add explicit type cast to return value from mrmchr; ref #4940
C++ is stricter in implicit type casting.
2020-02-03 12:59:29 +09:00
Yukihiro "Matz" Matsumoto 6d9109bf70 Use simple search for short strings in mrb_memsearch_qs; close #4940
Differences from the PR #4940:
* Use simple search for short strings only.
* "short" means `m+n` is shorter than `MRB_QS_SHORT_STRING_LENGTH`.
* The current default value for `MRB_QS_SHORT_STRING_LENGTH` is 2048.
2020-02-03 12:59:29 +09:00
dearblue 4c6d524c47 Implement IO#pread and IO#pwrite
It is available by default in environments where `__unix__` is defined.
Other environments are enabled by defining `MRB_WITH_IO_PREAD_PWRITE`
(requires an implementation of `pread()` and `pwrite()` functions).

In any case, you can disable it by defining
`MRB_WITHOUT_IO_PREAD_PWRITE`.
2020-02-02 21:20:25 +09:00
Yukihiro "Matz" Matsumoto 3c67d9b1c0 Merge pull request #4938 from dearblue/socket-mingw
Fix builds for old mingw in mruby-socket; ref #4914
2020-02-01 17:41:19 +09:00
dearblue 8020374d6b Fix builds for old mingw in mruby-socket; ref #4914 2020-02-01 15:58:32 +09:00
Yukihiro "Matz" Matsumoto db64bd42d3 Add explicit casting in file.c to silence warnings. 2020-01-31 09:26:45 +09:00
Yukihiro "Matz" Matsumoto 724c90f369 Avoid casting warning from mrb_int to int in io.c. 2020-01-31 09:26:05 +09:00
Yukihiro "Matz" Matsumoto c0a6439a69 Avoid implicit integer casting in backtrace.c and hash.c. 2020-01-31 09:25:10 +09:00
Yukihiro "Matz" Matsumoto 10c2b7ee1c Remove unnecessary use of uint16_t in symbol.c. 2020-01-31 09:22:27 +09:00
Yukihiro "Matz" Matsumoto f34623fb03 Fix arena index type from mrb_int to just int. 2020-01-30 17:35:50 +09:00
Yukihiro "Matz" Matsumoto c8f4d72302 Move fallback definitions of FLT_EPSILON etc. after #include <mruby/value.h>
that includes `float.h`. It allows definitions from native headers.
2020-01-30 17:16:12 +09:00
dearblue 9840e5352b Isolate top-level local variables by file scope; fix #4931 2020-01-29 23:30:13 +09:00
dearblue 0aa5aa1de2 Add test for top level local variables are in file scope; ref #4931 2020-01-29 23:29:48 +09:00
Yukihiro "Matz" Matsumoto 7771c215e4 Removed junk.
My cat stepped on the keyboard at the last moment before the commit.
2020-01-29 10:23:31 +09:00
Yukihiro "Matz" Matsumoto ff5d1914ab Remove unused local variable mid; ref #4936 2020-01-29 08:56:05 +09:00
Yukihiro "Matz" Matsumoto e7e999414c Merge pull request #4873 from dearblue/open-flags
Support bit flags for `IO.open`
2020-01-28 11:09:33 +09:00
David Siaw 36efc33650 include time.h for ios 2020-01-28 00:43:49 +08:00
Yukihiro "Matz" Matsumoto 364c47610f Fixed backtrace message for top-level blocks; fix #4936
In top-level, `mid` is `NULL`. We used to ignore 'mid` update for `NULL`.
2020-01-27 14:34:54 +09:00
Yukihiro "Matz" Matsumoto 59464f3528 Merge pull request #4935 from mimaki/delete-duplicated-Array-delete_if
Delete duplicated `Array#delete_if`.
2020-01-21 13:40:30 +09:00
Hiroshi Mimaki 7d9a49efab Delete duplicated Array#delete_if test. 2020-01-21 12:50:26 +09:00
Hiroshi Mimaki e24b4a1e19 Delete duplicated Array#delete_if. 2020-01-21 11:35:53 +09:00
dearblue 25d9370f97 Fix take over file scope variable names with mirb command
Ref #4931

With this change, the `_` variable is defined after the `-r` switch.
2020-01-19 21:59:47 +09:00
dearblue 2bab6e197d Fix take over file scope variables with mruby command
Resolve #4931
2020-01-19 21:52:37 +09:00
dearblue 893cc2780c Add mrbc_cleanup_local_variables() with mrbc_context; ref #4931
Clean up defined local variables.
2020-01-19 21:42:09 +09:00
Yukihiro "Matz" Matsumoto f7abda1437 Remove debug target from travis_config.rb. 2020-01-15 23:39:19 +09:00
Yukihiro "Matz" Matsumoto ff57c0278f Remove broken MRB_INT16 configuration option. 2020-01-15 21:32:00 +09:00
Yukihiro "Matz" Matsumoto 2742ded32f Fixed wrong condition in #4926 fix. 2020-01-10 23:05:27 +09:00
Yukihiro "Matz" Matsumoto 70e5746896 Fixed wrong condition for copying arguments on stack; fix #4926
This bug was introduced in 694089f to address #4832
2020-01-10 17:58:15 +09:00
Yukihiro "Matz" Matsumoto fc8fb41451 Small refactoring in hash_slice; ref #4926 2020-01-10 17:57:33 +09:00
Yukihiro "Matz" Matsumoto dc86e35cac Add MRB_WITHOUT_FLOAT guard to <math.h>. 2020-01-08 10:53:11 +09:00
Yukihiro "Matz" Matsumoto 2124b9b4c9 Fix buffer overflow in mrb_str_len_to_dbl.
Issue 19902: mruby:mruby_fuzzer: Stack-buffer-overflow in mrb_str_len_to_dbl
2020-01-08 10:52:24 +09:00
Yukihiro "Matz" Matsumoto dbba0ca517 p->locals may be NULL when error occurs before the point.
This is reported by oss-fuzz:
Issue 19886: mruby:mruby_fuzzer: Potential-null-reference in setup_numparams
2020-01-08 01:18:53 +09:00
Yukihiro "Matz" Matsumoto afad939173 Check memory boundary in mrb_str_len_to_dbl. 2020-01-07 08:58:06 +09:00
Yukihiro "Matz" Matsumoto 3e4e10ffb6 "0x10".to_f should be 0, not 16.0; fix #4924 2020-01-06 22:27:39 +09:00
Yukihiro "Matz" Matsumoto c60bccaa94 Check remaining string length before access to avoid OOB access. 2020-01-06 22:25:47 +09:00
Yukihiro "Matz" Matsumoto 59756aef14 Need to preserve the original input string in mrb_str_len_to_dbl. 2020-01-06 22:25:05 +09:00
Yukihiro "Matz" Matsumoto 874797f36f Merge branch 'dearblue-file-size-truncate' 2020-01-06 18:58:42 +09:00
Yukihiro "Matz" Matsumoto b545f62aeb Avoid Boxing/Unboxing of file descriptors; ref #4872 2020-01-06 18:57:43 +09:00
Yukihiro "Matz" Matsumoto ca71eb7eef Merge branch 'file-size-truncate' of https://github.com/dearblue/mruby into dearblue-file-size-truncate 2020-01-06 18:49:52 +09:00
Yukihiro "Matz" Matsumoto ccf28775b8 Fix mrb_str_len_to_dbl to support Hexadecimal like 0x10. 2020-01-06 15:52:39 +09:00
Yukihiro "Matz" Matsumoto 2532e625ed Refactor mrb_cstr_to_dbl; ref #4920 2020-01-06 15:52:39 +09:00
Yukihiro "Matz" Matsumoto 111045ecad Avoid creating temporary objects in read_irep_record_1; close #4920
The basic idea of this change is from @dearblue.

Note: the arguments of `mrb_str_pool()` have changed, but the function
is provided for internal use (No `MRB_API`). So basically you don't have
to worry about the change.
2020-01-06 15:52:39 +09:00
Yukihiro "Matz" Matsumoto 282f907f1b Merge pull request #4923 from dearblue/kwargs-block
Fix ainfo with keyword arguments; fix #4921
2020-01-05 20:59:18 +09:00
dearblue 541185ef14 Fix ainfo with keyword arguments; fix #4921 2020-01-05 16:48:34 +09:00
Yukihiro "Matz" Matsumoto d82e91898d Merge pull request #4917 from dearblue/va_end
Call `va_end()` before return
2020-01-02 09:26:15 +09:00
dearblue 00f5c92149 Call va_end() before return
The behavior when returning from a function without `va_end()` is
undefined.
2020-01-02 00:58:27 +09:00
Yukihiro "Matz" Matsumoto 9174b18f34 Rename mrb_num_args_error to mrb_argnum_error; ref #4863 2020-01-01 22:37:14 +09:00
Yukihiro "Matz" Matsumoto b9c78c3fcc Merge pull request #4863 from shuujii/add-mrb_num_args_error-for-wrong-number-of-arguments-error
Add `mrb_num_args_error()` for "wrong number of arguments" error
2020-01-01 22:34:22 +09:00
Yukihiro "Matz" Matsumoto 021f228f9d Merge pull request #4919 from shuujii/revert-SHARED-string-is-not-required-when-sharing-POOL-string
Revert "SHARED string is not required when sharing POOL string" (75949836)
2020-01-01 22:32:41 +09:00
KOBAYASHI Shuji 40b8490fa4 Revert "SHARED string is not required when sharing POOL string" (75949836)
Because literal pool may be released by GC.

#### Example:

  ```ruby
  s1 = eval('"abcdefghijklmnopqrstuvwxyz01"')
  GC.start
  p s1  #=> "\x00\x00\x00\x00\x00\x00\x00\x90\x00\x00\x00\x00\x00\x00\x00\x90\x03\x00stuvwxyz01"
  ```
2020-01-01 19:16:05 +09:00
Yukihiro "Matz" Matsumoto 7247e4cf1b Merge pull request #4918 from dearblue/sync-vars
Integrate `i` and `arg_i` in `mrb_get_args()`
2020-01-01 15:31:16 +09:00
Yukihiro "Matz" Matsumoto b49bc17f48 Merge pull request #4916 from dearblue/stdint
Do not include `stdint.h` before `mruby.h`; ref #4750
2020-01-01 15:30:29 +09:00
dearblue 7ed26ead9b Integrate i and arg_i in mrb_get_args()
The behavior of these two variables is the same.
2020-01-01 15:07:16 +09:00
dearblue 20d3882469 Do not include stdint.h before mruby.h; ref #4750 2020-01-01 14:17:11 +09:00
Yukihiro "Matz" Matsumoto fd1cff7735 Fixed wrong usages of mrb_get_args in vformat.c. 2020-01-01 12:34:30 +09:00
Yukihiro "Matz" Matsumoto 943fbb2bea Allow here-doc in the middle of Hash expressions; fix #4815 2020-01-01 12:21:17 +09:00
Yukihiro "Matz" Matsumoto 28c8e29c4d Merge pull request #4915 from shuujii/silence-GCC-warning-in-time.c-on-Travis-CI
Silence GCC warning in `time.c` on Travis CI
2019-12-31 22:36:41 +09:00
KOBAYASHI Shuji b493229a23 Silence GCC warning in time.c on Travis CI
Silence the following warnings:

  ```
  /mruby/mrbgems/mruby-time/src/time.c:260:55: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    if ((MRB_INT_MAX > MRB_TIME_MAX && i > 0 && i > MRB_TIME_MAX) ||
                                                  ^
  ```
2019-12-31 21:52:20 +09:00
Yukihiro "Matz" Matsumoto 83e502b847 Merge pull request #4914 from dearblue/fix-4869
Fix builds for modern mingw; fix #4869
2019-12-31 09:42:47 +09:00
dearblue 93d0e5d9fb Fix builds for modern mingw; fix #4869
What I intended to fix in #4869 was a patch for an old MinGW.
Recent MinGWs have their own `mkstemp()` function.
I knew this after checking the patch #4903.
2019-12-31 00:11:40 +09:00
Yukihiro "Matz" Matsumoto 5e519cdbb5 Merge pull request #4913 from shuujii/use-rake-instead-of-minirake-in-.gitlab-ci.yml
Use `rake` instead of `minirake` in `.gitlab-ci.yml`
2019-12-30 22:24:08 +09:00
KOBAYASHI Shuji b96fa664b0 Use rake instead of minirake in .gitlab-ci.yml
There was an error in the `.gitlab-ci.yml` generation script, so it was also
fixed.
2019-12-30 17:46:22 +09:00
Yukihiro "Matz" Matsumoto 4327f36940 Merge pull request #4912 from shuujii/avoid-unneeded-directory-creation-during-rake--T-etc
Avoid unneeded directory creation during `rake -T`, etc.
2019-12-29 21:08:49 +09:00
KOBAYASHI Shuji b97ebf2aeb Avoid unneeded directory creation during rake -T, etc. 2019-12-29 17:46:55 +09:00
Yukihiro "Matz" Matsumoto e9de5a7a5c Merge pull request #4911 from shuujii/use-Rake.verbose-instead-of-verbose-and-pp_show
Use `Rake.verbose` instead of `$verbose` and `$pp_show` in build scripts
2019-12-28 17:43:54 +09:00
KOBAYASHI Shuji bb98fd78c3 Use Rake.verbose instead of $verbose and $pp_show in build scripts
The incompatibility that the commands of `FileUtils` origin output verbose
by default due to the changes in d8a5163b and 26e6e75b is also fixed.
2019-12-28 17:03:37 +09:00
Yukihiro "Matz" Matsumoto d2f34a8455 Merge pull request #4910 from shuujii/use-Rake-DSL-instead-of-commands-of-FileUtils
Use Rake DSL instead of commands of `FileUtils`
2019-12-27 18:35:19 +09:00
KOBAYASHI Shuji 26e6e75ba6 Use Rake DSL instead of commands of FileUtils
- Respect `--verbose(-v)` and `--dry-run(-n)` options.
- Silence warnings to keyword arguments on Ruby 2.7.
2019-12-27 16:49:32 +09:00
Yukihiro "Matz" Matsumoto 03244b52a0 Revert "Enable sanitizer in travis test"; ref #4864
`gcc` sanitizer does not work on some environment (namely my localhost).
Although it works on Travis, it is not convenient that tests fail on the
local host. We keep sanitizer tests on the local (using `clang`).

This reverts commit 9cde967321.
2019-12-27 11:16:37 +09:00
Yukihiro "Matz" Matsumoto d15e56dab0 Prohibit assignment to numbered parameters.
It is stricter than CRuby but confusing anyway.
2019-12-27 11:05:56 +09:00
Yukihiro "Matz" Matsumoto ff16331754 Allow non numbered-parameter identifier like _1 outside of blocks.
But it causes warnings as CRuby does; fix #4892 fix #489
2019-12-27 11:05:56 +09:00
Yukihiro "Matz" Matsumoto d8a5163b24 Support -v flag of rake; close #4887
The patch was originally written by @take-cheese. I have fixed the
conflict caused by `minirake` deletion - @matz.
2019-12-27 11:05:56 +09:00
Yukihiro "Matz" Matsumoto ed8491cde6 Numbered parameters: usually linked list uses cdr for links. 2019-12-27 11:05:56 +09:00
Yukihiro "Matz" Matsumoto 7e6355975e Prohibit numbered parameters as method arguments; fix #4892
As of CRuby2.7 it is only warned. `mruby` prohibits explicitly to
implement the future Ruby3 behavior.
2019-12-27 11:05:56 +09:00
KOBAYASHI Shuji 716102fff3 Enable MRB_GC_STRESS test on CI
The `debug` build target (`MRB_GC_STRESS` is enabled) on CI have been
compiled but not tested so far. However, I think testing with
`MRB_GC_STRESS` is effective (in fact, I found #4907 bug).

Therefore, I integrated `debug` and `full-debug` build targets to enable
`MRB_GC_STRESS` testing. Testing with `MRB_GC_STRESS` takes a little time,
but compiling takes more time, so CI execution time does not increase due to
decrease of build target.
2019-12-27 11:05:56 +09:00
Yukihiro "Matz" Matsumoto ef6805f599 Merge pull request #4864 from take-cheeze/enable_sanitizer_travis
Enable sanitizer in travis test
2019-12-27 10:58:24 +09:00
Yukihiro "Matz" Matsumoto d6b898685f Merge pull request #4907 from shuujii/fix-poteltially-use-of-wrong-method-cache
Fix potentially use of wrong method cache
2019-12-25 23:23:00 +09:00
KOBAYASHI Shuji 0b2d54f4f1 Fix potentially use of wrong method cache
#### Example (with `MRB_METHOD_CACHE`)

  ```ruby
  GC.start
  c = Class.new
  p c            #=> #<Class:0x7fd6a180e790>
  c.new          #=> cache `c.new`
  c = nil
  GC.start       #=> `c` is GCed
  r = Range.dup
  p r            #=> #<Class:0x7fd6a180e790>
                 #   [same pointer as `c`]
  r.new(2, 3)    #=> ArgumentError: 'initialize':
                 #   wrong number of arguments (2 for 0)
                 #   [`c.new` is called instead of `r.new`]
  ```

#### Cause

  An entry of method cache is identified by class pointer and method
  id. However, reusing memory after GC may create a class with the same
  pointer as the cached class.

#### Treatment

  Cleared method caches of the class when the class is GCed.
2019-12-25 21:31:10 +09:00
Yukihiro "Matz" Matsumoto d4cbe6271c Merge pull request #4906 from shuujii/refine-the-assertion-failure-message-in-mrdb-print-tests
Refine the assertion failure message in mrdb print tests
2019-12-25 10:58:04 +09:00
KOBAYASHI Shuji f92867a59e Refine the assertion failure message in mrdb print tests
#### Before this patch:

  ```console
  Fail: mruby-bin-debugger(print) error (mrbgems: mruby-bin-debugger)
   - Assertion[2]
      Expected true to be false.
  ```

#### After this patch:

  ```console
  Fail: mruby-bin-debugger(print) error (mrbgems: mruby-bin-debugger)
   - Assertion[2]
      Expected "$2 = undefined method 'bar' (NoMethodError)\n" to be start_with? "$2 = (eval):2: undefined method".
  ```
2019-12-24 23:20:20 +09:00
Yukihiro "Matz" Matsumoto d062528653 Merge pull request #4905 from kishima/cygwin_compile
Add double quotes for cygwin filenames #4904
2019-12-24 14:23:24 +09:00
kishima b63f1912df add double quotes for cygwin filenames #4904 2019-12-23 23:36:59 +09:00
Yukihiro "Matz" Matsumoto 18248cfd00 Merge pull request #4901 from take-cheeze/gnu_cxx
Use GNU extension in C++ for cygwin
2019-12-23 21:32:26 +09:00
Yukihiro "Matz" Matsumoto 0f89a91607 Merge pull request #4902 from take-cheeze/native_crlf
Handle CR LF newline natively in lexer
2019-12-23 21:31:51 +09:00
take-cheeze bb0aec1d94 Use binary mode in mrbc source code reading 2019-12-23 21:01:42 +09:00
take-cheeze 10e9f193ca Handle CR LF newline natively in lexer 2019-12-23 21:01:11 +09:00
take-cheeze 38fdca82c6 Use GNU extension in C++ for cygwin 2019-12-23 20:58:43 +09:00
Yukihiro "Matz" Matsumoto 49301ed785 Merge pull request #4900 from shuujii/parallelize-compilation-only-on-Travis-CI
Parallelize compilation only on Travis CI
2019-12-23 20:37:25 +09:00
KOBAYASHI Shuji 212d12f269 Parallelize compilation only on Travis CI
Parallel execution of tests makes log difficult to see due to mixing.
2019-12-23 20:04:11 +09:00
Yukihiro "Matz" Matsumoto a562a9aa93 Merge pull request #4899 from dearblue/build-git
Use `git checkout` instead of `git reset`
2019-12-22 22:31:33 +09:00
dearblue f08d9b288d Use git checkout instead of git reset
With this change, if the checkout fails, it will stop with an error.

The purpose is to avoid deleting working branch history when
developing gem.
2019-12-22 15:09:29 +09:00
dearblue dc15c2838f Display directory with git command 2019-12-22 14:26:00 +09:00
Yukihiro "Matz" Matsumoto 0bd3a67dea Merge pull request #4898 from shuujii/refine-.travis.yml
Refine `.travis.yml`
2019-12-22 13:13:49 +09:00
Yukihiro "Matz" Matsumoto 572958ece3 Merge pull request #4896 from shuujii/fix-undefined-method-Pathname
Fix "undefined method `Pathname'"; fix #4895
2019-12-22 13:12:59 +09:00
Yukihiro "Matz" Matsumoto fa90bcb9ab Merge pull request #4897 from shuujii/use-exec-instead-of-system-in-minirake-for-exit-status
Use `exec` instead of `system` in `minirake` for exit status
2019-12-22 13:11:23 +09:00
KOBAYASHI Shuji 5974d53ab0 Refine .travis.yml
* Use `rake` instead of `minirake`.
* Remove `gperf` configuration.

Execution time seems to be reduced by about 15%.
2019-12-22 11:48:04 +09:00
KOBAYASHI Shuji 66349bcef1 Use exec instead of system in minirake for exit status
#### Before this patch:

  ```console
  $ ./minirake --foo; echo $?
  invalid option: --foo
  0
  ```

#### After this patch:

  ```console
  $ ./minirake --foo; echo $?
  invalid option: --foo
  1
  ```
2019-12-21 23:44:33 +09:00
KOBAYASHI Shuji 9f1167f7c9 Fix "undefined method `Pathname'"; fix #4895 2019-12-21 23:31:17 +09:00
Yukihiro "Matz" Matsumoto 089bb6acad Merge pull request #4888 from dearblue/shellquote
Perform `shellquote` on referenced string
2019-12-21 22:46:27 +09:00
Yukihiro "Matz" Matsumoto 06e09fc7a9 Numbered parameters should not be available in the lambda bodies.
`mruby` does not warn like `CRuby` for cases like #4893.
Fix #4890, fix #4891, fix #4893.
2019-12-21 22:41:32 +09:00
Yukihiro "Matz" Matsumoto 2fe78a0c7c Add emulating minirake that calls real rake. 2019-12-21 22:11:08 +09:00
Yukihiro "Matz" Matsumoto de17f63b45 Abandon minirake. Use rake for compilation; fix #4884 2019-12-21 22:11:08 +09:00
Yukihiro "Matz" Matsumoto fee3c1c242 Merge pull request #4889 from shuujii/_0-is-not-numbered-parameter
`_0` is not numbered parameter
2019-12-21 22:10:42 +09:00
KOBAYASHI Shuji 74f564b0bb _0 is not numbered parameter
#### Before this patch:

  ```console
  $ bin/mruby rb -e '_0=:l; p ->{_0}.()'
  -e:1:13: _0 is not available
  -e:1:13: syntax error, unexpected $end, expecting '}'
  ```

#### After this patch (same as Ruby):

  ```console
  $ bin/mruby rb -e '_0=:l; p ->{_0}.()'
  :l
  ```
2019-12-21 18:54:15 +09:00
dearblue acef52c35e Perform shellquote on referenced string 2019-12-21 17:25:22 +09:00
Yukihiro "Matz" Matsumoto 5cc595cb2a Fix SEGV from numbered parameters outside of blocks; fix #4862 2019-12-21 01:24:56 +09:00
Yukihiro "Matz" Matsumoto ef8621cb61 Merge pull request #4885 from shuujii/fix-potentially-crash-in-%n-of-mrb_vformat-with-64-bit-int
Fix potentially crash in `%n` of `mrb_vformat()` with 64-bit `int`
2019-12-21 01:18:09 +09:00
KOBAYASHI Shuji e8299a89da Fix potentially crash in %n of mrb_vformat() with 64-bit int
If `mrb_sym` is smaller than `int`, it is promoted to `int`.
2019-12-20 23:04:46 +09:00
Yukihiro "Matz" Matsumoto 19fa77ddbb Merge pull request #4871 from dearblue/method-in-method
Avoid method in method
2019-12-20 19:29:48 +09:00
Yukihiro "Matz" Matsumoto adf358363c Merge pull request #4870 from dearblue/unnessesary-branch
Remove unnessesary branches
2019-12-20 19:24:45 +09:00
Yukihiro "Matz" Matsumoto 64e9f278b3 Merge pull request #4874 from dearblue/method-list
Fix for `#methods` to include methods that were `undef`
2019-12-20 19:23:13 +09:00
take-cheeze 9cde967321 Enable sanitizer in travis test 2019-12-19 14:21:49 +09:00
Yukihiro "Matz" Matsumoto 87809742f5 Fix mixed declarations in 429f6de 2019-12-19 10:00:33 +09:00
Yukihiro "Matz" Matsumoto fcde80a4d0 Merge pull request #4881 from shuujii/fix-mruby-bin-debugger-tests
Fix `mruby-bin-debugger` tests; ref d2f2f9db
2019-12-19 09:51:31 +09:00
Yukihiro "Matz" Matsumoto 868ba8464e Merge pull request #4882 from shuujii/simplify-print_backtrace
Simplify `print_backtrace()`
2019-12-19 09:50:22 +09:00
Yukihiro "Matz" Matsumoto 429f6defdd Reimplement vformat tests; close #4868
Avoid creating `Data` object that refers `mruby` objects.
Also close #4622 ref #4613
2019-12-19 09:35:51 +09:00
Yukihiro "Matz" Matsumoto 7f0e1fc90b Revert "%C value need not to be saved in TestVFormat::Native; close #4868"
This reverts commit f507ff4842.
It makes AppVeyor tests fail.
2019-12-19 00:07:08 +09:00
KOBAYASHI Shuji 6df6bd4ac7 Simplify print_backtrace() 2019-12-18 19:35:24 +09:00
KOBAYASHI Shuji f0b8c9ec06 Fix mruby-bin-debugger tests; ref d2f2f9db 2019-12-18 19:34:11 +09:00
Yukihiro "Matz" Matsumoto 815e0c400a Merge pull request #4875 from shuujii/remove-location-info-from-Exception-inspect
Remove location info from `Exception#inspect`
2019-12-18 01:55:23 +09:00
Yukihiro "Matz" Matsumoto 4c1667a5f6 Merge pull request #4879 from shuujii/refine-output-of-mrb_print_error
Refine output of `mrb_print_error()`
2019-12-18 01:54:28 +09:00
Yukihiro "Matz" Matsumoto f507ff4842 %C value need not to be saved in TestVFormat::Native; close #4868 2019-12-18 01:40:11 +09:00
KOBAYASHI Shuji 29ecc3840a Refine output of mrb_print_error()
The following improvements are made according to Ruby's behavior:

- Match location number to index.
- Remove duplicate most recent call output.
- Fix that first call is not output when array (unpacked) backtrace.

### Example

  ```ruby
  def a; raise "error!" end
  def b; a end
  begin
    b
  rescue => e
    e.backtrace if ARGV[0] == "unpack"  # unpack backtrace
    raise e
  end
  ```

#### Before this patch:

  ```
  $ bin/mruby example.rb unpack
  trace (most recent call last):
    [0] example.rb:2:in b
    [1] example.rb:1:in a
  example.rb:1: error! (RuntimeError)
  ```

#### After this patch:

  ```
  $ bin/mruby example.rb unpack
  trace (most recent call last):
    [2] example.rb:4
    [1] example.rb:2:in b
  example.rb:1:in a: error! (RuntimeError)
  ```
2019-12-17 23:16:20 +09:00
Yukihiro "Matz" Matsumoto 8bc9a79e65 Merge pull request #4869 from dearblue/mingw32-io-test
Fix mruby-io test for mingw32
2019-12-17 00:49:01 +09:00
Yukihiro "Matz" Matsumoto 6a22fa7f47 Merge pull request #4878 from shuujii/remove-unneeded-null-checks-to-struct-backtrace_locationfilename
Remove unneeded null checks to `struct backtrace_location::filename`
2019-12-17 00:48:27 +09:00
KOBAYASHI Shuji 854c61c3ab Remove unneeded null checks to struct backtrace_location::filename
`struct backtrace_location` is created only in `each_backtrace()`, and
the `filename` field will never be null (it will be `(unknown)` if null).
2019-12-16 18:57:53 +09:00
Yukihiro "Matz" Matsumoto 85b4ed623e Merge pull request #4876 from dearblue/class-methods
Remove module only methods from class
2019-12-16 13:53:55 +09:00
Yukihiro "Matz" Matsumoto fc5a9c2be2 Merge pull request #4877 from shuujii/drop-dependencies-from-mruby-complex-to-some-gems
Drop dependencies from `mruby-complex` to some gems
2019-12-16 13:51:48 +09:00
Yukihiro "Matz" Matsumoto cc6d17423b Merge pull request #4859 from dearblue/authors
Add "mruby developers" into some gems; Resolve #4709
2019-12-16 13:50:33 +09:00
KOBAYASHI Shuji 4bdb1eb5aa Drop dependencies from mruby-complex to some gems 2019-12-15 22:51:07 +09:00
KOBAYASHI Shuji d2f2f9db51 Remove location info from Exception#inspect
Because location info (file name and line number) is kept in the backtrace,
it should not be kept in the result of `inspect` (and the exception object
itself), I think.

### Example

  ```ruby
  # example.rb
  begin
    raise "err"
  rescue => e
    p e
  end
  ```

#### Before this patch:

  ```
  $ bin/mruby example.rb
  example.rb:2: err (RuntimeError)
  ```

#### After this patch:

  ```
  $ bin/mruby example.rb
  err (RuntimeError)
  ```
2019-12-14 22:29:37 +09:00
dearblue cc52fa66e8 Remove module only methods from class
The `#prepend_features` and `#module_function` methods are not haves for
class objects.
2019-12-14 22:12:32 +09:00
dearblue 184ad732df Fix for #methods to include methods that were undef
If `#methods` traverse the super class, it includes the methods that
were does `undef` in the subclass.

Before patched:
```terminal
% bin/mruby -e 'p Module.instance_methods - Class.instance_methods'
[]
```

After patched:
```terminal
% bin/mruby -e 'p Module.instance_methods - Class.instance_methods'
[:append_features, :extend_object]
```
2019-12-14 21:30:44 +09:00
dearblue 69619aeeb1 Support bit flags for IO.open
Note that this bit flags are not compatible with the native flags
defined in `#include <fcntl.h>`.
2019-12-14 15:19:13 +09:00
dearblue 6d9ac89f92 Implement File#size and File#truncate 2019-12-14 15:10:57 +09:00
dearblue 5b30f789e5 Avoid method in method
And rename `File.concat_path` to `File._concat_path`.
2019-12-14 15:04:56 +09:00
dearblue c18a8c53e8 Remove unnessesary branches 2019-12-14 15:01:42 +09:00
dearblue ec1ef925a9 Fix mruby-io test for mingw32
Need `mkstemp()` implements.
2019-12-14 14:57:10 +09:00
Yukihiro "Matz" Matsumoto 6c5ee8f79e Merge pull request #4866 from shuujii/fix-arguments-check-to-Array-each
Fix arguments check to `Array#each`
2019-12-14 01:14:26 +09:00
KOBAYASHI Shuji e18aa4d893 Fix arguments check to Array#each
#### Before this patch:

  ```
  $ mruby -e '[].each(1){}'  #=> no error
  ```

#### After this patch:

  ```
  $ mruby -e '[].each(1){}'  #=> ArgumentError: wrong number of arguments
  ```
2019-12-13 17:30:34 +09:00
take-cheeze 6af555b394 Align RIStruct data for rational 2019-12-13 04:41:43 +09:00
KOBAYASHI Shuji 81de1f159c Add mrb_num_args_error() for "wrong number of arguments" error
To unify the style of messages.
2019-12-12 11:45:58 +09:00
Yukihiro "Matz" Matsumoto 9c4c82ed1c Merge pull request #4861 from shuujii/fix-behavior-of-Kernel-Integer-to-numbers-ending-with-_-and-spaces
Fix behavior of `Kernel#Integer` to numbers ending with `_` and spaces
2019-12-12 09:26:14 +09:00
KOBAYASHI Shuji 7192429e83 Fix behavior of Kernel#Integer to numbers ending with _ and spaces
#### Before this patch:

  ```ruby
  Integer("1_ ")  #=> 1
  ```

#### After this patch (same as Ruby):

  ```ruby
  Integer("1_ ")  #=> ArgumentError
  ```
2019-12-11 16:40:39 +09:00
Yukihiro "Matz" Matsumoto 994da0fd73 Merge pull request #4860 from shuujii/fix-behavior-of-String-to_i-Kernel-Integer-to-numbers-starting-with-_
Fix behavior of `String#to_i`/`Kernel#Integer` to numbers starting with `_`
2019-12-10 23:00:17 +09:00
KOBAYASHI Shuji bf431e77b8 Fix behavior of String#to_i/Kernel#Integer to numbers starting with _
#### Before this patch:

  ```ruby
  Integer("_1")  #=> 1
  "_1".to_i      #=> 1
  ```

#### After this patch (same as Ruby):

  ```ruby
  Integer("_1")  #=> ArgumentError
  "_1".to_i      #=> 0
  ```
2019-12-10 21:31:30 +09:00
Yukihiro "Matz" Matsumoto 543a9f84d1 Merge pull request #4858 from shuujii/fix-that-String-to_f-accepts-consecutive-_-as-a-numeric-expression
Fix that `String#to_f` accepts consecutive `_` as a numeric expression
2019-12-10 11:09:55 +09:00
dearblue 56de911b7a Add "mruby developers" into some gems; Resolve #4709
It is writing side by side with the original authors.
2019-12-09 23:49:03 +09:00
KOBAYASHI Shuji 0893ee492c Fix that String#to_f accepts consecutive _ as a numeric expression
Consecutive `_` is not allowed as a numeric expression:

  1_2__3             #=> SyntaxError
  Float("1_2__3")    #=> ArgumentError
  Integer("1_2__3")  #=> ArgumentError
  "1_2__3".to_i      #=> 12

But `String#to_f` accept it, so I fixed the issue.

Before this patch:

  "1_2__3".to_f      #=> 123

After this patch:

  "1_2__3".to_f      #=> 12
2019-12-09 21:47:59 +09:00
Yukihiro "Matz" Matsumoto 694089fafe Fix mrb_get_argv() to return array pointer every time; fix #4832 2019-12-09 20:50:41 +09:00
Yukihiro "Matz" Matsumoto fb9e92e828 Warnings for numbered parameters in nested blocks. 2019-12-09 20:50:41 +09:00
Yukihiro "Matz" Matsumoto f7a0f11c36 Parser refactoring on numbered parameters.
Now identifiers like `_1abc` are allowed.
2019-12-09 20:50:41 +09:00
Yukihiro "Matz" Matsumoto 0011652a28 Support new numbered parameter syntax _1 instead of @1. 2019-12-09 20:50:41 +09:00
Ukrainskiy Sergey 72d57ad094 Implement numbered parameters 2019-12-09 20:50:41 +09:00
Yukihiro "Matz" Matsumoto 8267993988 Merge pull request #4855 from dearblue/kwargs-uninit
Fix keyword arguments not be obtained with `mrb_get_args()`; Fix #4754
2019-12-09 17:31:53 +09:00
Yukihiro "Matz" Matsumoto ef644120e4 Merge pull request #4856 from shuujii/fix-the-error-message-of-Kernel-Float
Fix the error message of `Kernel#Float`
2019-12-08 21:31:14 +09:00
KOBAYASHI Shuji cf6ae0de6a Fix the error message of Kernel#Float
#### Before this patch:

  ```
  $ bin/mruby -e 'Float("1_a")'
  -e:1: invalid string for float(a) (ArgumentError)
  ```

#### After this patch:

  ```
  $ bin/mruby -e 'Float("1_a")'
  -e:1: invalid string for float("1_a") (ArgumentError)
  ```
2019-12-08 18:31:41 +09:00
Yukihiro "Matz" Matsumoto 2456d3abc0 Merge pull request #4854 from shuujii/add-tests-to-Math
Add tests to `Math`
2019-12-08 11:24:29 +09:00
dearblue 1ca4fdc4c7 Fix keyword arguments not be obtained with mrb_get_args(); Fix #4754
If ":" is after "|" and there is no "?" or "*", the keyword argument
could not be obtained and it was not initialized with `undef`.

For example: "|oo:"
2019-12-07 22:48:58 +09:00
KOBAYASHI Shuji d908a73b04 Add tests to Math 2019-12-07 20:50:56 +09:00
Yukihiro "Matz" Matsumoto 6e5c861fff Merge pull request #4852 from shuujii/auto-detect-MRB_TIME_T_UINT
Auto detect `MRB_TIME_T_UINT`
2019-12-06 08:00:53 +09:00
KOBAYASHI Shuji e6033e00fe Auto detect MRB_TIME_T_UINT 2019-12-05 21:40:15 +09:00
Yukihiro "Matz" Matsumoto 52318b3359 Merge pull request #4851 from shuujii/refine-mrb_alloca
Refine `mrb_alloca()`
2019-12-05 09:40:44 +09:00
KOBAYASHI Shuji a030446a94 Refine mrb_alloca()
* The allocated memory is guaranteed to be aligned for any data type (it was
  not guaranteed when string type is embed).
* Make allocation size exactly specified size (does not allocate space for a
  null byte).
2019-12-04 22:21:00 +09:00
Yukihiro "Matz" Matsumoto bc22991ac3 Merge pull request #4850 from shuujii/silence-Clang-warning-with-MRB_INT64-and-MRB_32BIT-in-time.c
Silence Clang warning with `MRB_INT64` and `MRB_32BIT` in `time.c`
2019-12-04 07:10:17 +09:00
KOBAYASHI Shuji ea1911d23f Silence Clang warning with MRB_INT64 and MRB_32BIT in time.c
Silence the following warnings:

  ```
  /mruby/mrbgems/mruby-time/src/time.c:871:15: warning: result of comparison of constant 9223372036854775807 with expression of type 'time_t' (aka 'long') is always false [-Wtautological-constant-out-of-range-compare]
    if (tm->sec > MRB_INT_MAX || tm->sec < MRB_INT_MIN) {
        ~~~~~~~ ^ ~~~~~~~~~~~
  /mruby/mrbgems/mruby-time/src/time.c:871:40: warning: result of comparison of constant -9223372036854775808 with expression of type 'time_t' (aka 'long') is always false [-Wtautological-constant-out-of-range-compare]
    if (tm->sec > MRB_INT_MAX || tm->sec < MRB_INT_MIN) {
                                 ~~~~~~~ ^ ~~~~~~~~~~~
  /mruby/mrbgems/mruby-time/src/time.c:887:16: warning: result of comparison of constant 9223372036854775807 with expression of type 'time_t' (aka 'long') is always false [-Wtautological-constant-out-of-range-compare]
    if (tm->usec > MRB_INT_MAX || tm->usec < MRB_INT_MIN) {
        ~~~~~~~~ ^ ~~~~~~~~~~~
  /mruby/mrbgems/mruby-time/src/time.c:887:42: warning: result of comparison of constant -9223372036854775808 with expression of type 'time_t' (aka 'long') is always false [-Wtautological-constant-out-of-range-compare]
    if (tm->usec > MRB_INT_MAX || tm->usec < MRB_INT_MIN) {
                                ~~~~~~~~ ^ ~~~~~~~~~~~
  ```
2019-12-03 22:50:50 +09:00
Yukihiro "Matz" Matsumoto 54f2ed6afd Merge pull request #4849 from shuujii/silence-Clang-warning-with-MRB_INT32-and-MRB_64BIT-in-time.c
Silence Clang warning with `MRB_INT32` and `MRB_64BIT` in `time.c`
2019-12-03 22:35:44 +09:00
KOBAYASHI Shuji 6973539005 Silence Clang warning with MRB_INT32 and MRB_64BIT in time.c
Silence the following warning:

  ```
  /mruby/mrbgems/mruby-time/src/time.c:258:60: warning: result of comparison of constant -9223372036854775808 with expression of type 'mrb_int' (aka 'int') is always false [-Wtautological-constant-out-of-range-compare]
        if ((mrb_time_int)i > MRB_TIME_MAX || MRB_TIME_MIN > i) {
                                              ~~~~~~~~~~~~ ^ ~
  ```
2019-12-02 20:00:36 +09:00
Yukihiro "Matz" Matsumoto 3c67872805 Merge pull request #4848 from shuujii/fix-MRB_FIXNUM_SHIFT-with-MRB_WORD_BOXING-MRB_INT32-and-MRB_64BIT
Fix `MRB_FIXNUM_SHIFT` with `MRB_WORD_BOXING`, `MRB_INT32` and `MRB_64BIT`
2019-12-02 13:42:16 +09:00
KOBAYASHI Shuji a53f28275e Fix MRB_FIXNUM_SHIFT with MRB_WORD_BOXING, MRB_INT32 and MRB_64BIT
### Example

  ```ruby
  # example.rb
  max32 = 2**30 - 1 + 2**30
  min32 = -max32-1
  [max32, max32+1, min32, min32-1].each{|n| p [n, n.class]}
  ```

#### Before this patch:

  ```
  $ bin/mruby example.rb
  [2147483647, Float]
  [2147483648, Float]
  [-2147483648, Float]
  [-2147483649, Float]
  ```

#### After this patch:

  ```
  $ bin/mruby example.rb
  [2147483647, Fixnum]
  [2147483648, Float]
  [-2147483648, Fixnum]
  [-2147483649, Float]
  ```
2019-12-01 22:09:38 +09:00
Yukihiro "Matz" Matsumoto ef95a9fa93 Use a string as a common regexp representation; ref #4847 2019-11-30 21:10:36 +09:00
Yukihiro "Matz" Matsumoto 25b5b79cc3 Merge pull request #4847 from shuujii/quit-mruby-v-immediately-if-no-program-is-given
Quit `mruby -v` immediately if no program is given for Ruby compatibility
2019-11-30 21:08:54 +09:00
KOBAYASHI Shuji 49653b81ea Quit mruby -v immediately if no program is given for Ruby compatibility 2019-11-30 19:52:22 +09:00
Yukihiro "Matz" Matsumoto 5eb08a0d1a Merge pull request #4846 from shuujii/fix-mruby---verbose-regression-by--4827
Fix `mruby --verbose` (regression by #4827)
2019-11-29 21:53:12 +09:00
KOBAYASHI Shuji df437eebcc Fix mruby --verbose (regression by #4827)
#### Before this patch:

  ```
  $ bin/mruby --verbose -e 'p 1'
  bin/mruby: Cannot open program file: --verbose
  ```

#### After this patch:

  ```
  $ bin/mruby --verbose -e 'p 1'
  00001 NODE_SCOPE:
  (snip)
  irep 0x7fe97041df30 nregs=4 nlocals=1 pools=0 syms=1 reps=0 iseq=11
  file: -e
      1 000 OP_LOADSELF R1
  (snip)

  1
  ```
2019-11-29 19:02:04 +09:00
Yukihiro "Matz" Matsumoto 75e96c6927 Merge pull request #4845 from shuujii/change-URL-of-mruby.org
Change the URL of `mruby.org` [ci skip]
2019-11-29 09:22:26 +09:00
KOBAYASHI Shuji 1680f2c95e Change the URL of mruby.org [ci skip]
- `http` -> `https`
- Remove `www.`
2019-11-28 17:54:52 +09:00
Yukihiro "Matz" Matsumoto 17ec885270 Merge pull request #4843 from shuujii/support-end-of-options-to-mruby-command
Support `--` (end of options) to `mruby` command
2019-11-27 22:41:36 +09:00
KOBAYASHI Shuji f4b528e07a Support -- (end of options) to mruby command
#### Before this patch:

  ```
  $ bin/mruby -e 'p ARGV' -- -x
  bin/mruby: invalid option -- (-h will show valid options)
  ```

#### After this patch:

  ```
  $ bin/mruby -e 'p ARGV' -- -x
  ["-x"]
  ```
2019-11-27 19:51:43 +09:00
Yukihiro "Matz" Matsumoto 190649e591 Merge pull request #4837 from shuujii/add-assertion-to-RVALUE-size
Add assertion to `RVALUE` size
2019-11-27 09:47:35 +09:00
Yukihiro "Matz" Matsumoto ec957ec5ee Merge pull request #4838 from shuujii/rename-BITSIZE-to-BIT-and-BIT-to-BIT_POS-for-consistency
Rename `BITSIZE` to `BIT` and `BIT` to `BIT_POS` for consistency
2019-11-26 06:31:48 +09:00
Yukihiro "Matz" Matsumoto ff15a586a0 Merge pull request #4841 from shuujii/fix-ARGV-value-in-mruby-command-regression-by-4827
Fix `ARGV` value in `mruby` command (regression by #4827)
2019-11-25 23:19:17 +09:00
KOBAYASHI Shuji f9bd414350 Fix ARGV value in mruby command (regression by #4827)
#### Before this patch:

  ```
  $ bin/mruby -e 'p ARGV' a b
  ["bin/mruby", "-e", "p ARGV", "a", "b"]
  ```

#### After this patch:

  ```
  $ bin/mruby -e 'p ARGV' a b
  ["a", "b"]
  ```
2019-11-25 21:56:27 +09:00
Yukihiro "Matz" Matsumoto a89d15cdde Merge pull request #4827 from shuujii/support-short-options-concatenation-to-mruby-command
Support short options concatenation to `mruby` command
2019-11-25 09:49:28 +09:00
Yukihiro "Matz" Matsumoto 1d1c81258e Merge pull request #4840 from shuujii/remove-unused-methods-of-MRubyIOTestUtil
Remove unused methods of `MRubyIOTestUtil`
2019-11-24 23:07:15 +09:00
KOBAYASHI Shuji ce553fa834 Remove unused methods of MRubyIOTestUtil 2019-11-24 21:40:22 +09:00
Yukihiro "Matz" Matsumoto b3e6a993a9 Merge pull request #4834 from shuujii/use-proper-PEEK-macro-for-OP_EPUSH-in-patch_irep
Use proper `PEEK` macro for `OP_EPUSH` in `patch_irep`; fix #4833
2019-11-24 07:52:17 +09:00
KOBAYASHI Shuji 375c1ebc41 Rename BITSIZE to BIT and BIT to BIT_POS for consistency
The bit width terminology is unified to `BIT` according to `MRB_INT_BIT`
and `CHAR_BIT`. Also the bit position terminology is unified to `BIT_POS`.
2019-11-23 20:40:23 +09:00
KOBAYASHI Shuji 6cf99d12ac Add assertion to RVALUE size 2019-11-23 17:36:46 +09:00
Yukihiro "Matz" Matsumoto 56f9106d94 Merge pull request #4836 from shuujii/allow-true-false-argument-to-Kernel-exit
Allow `true`/`false` argument to `Kernel#exit`
2019-11-23 06:25:02 +09:00
Yukihiro "Matz" Matsumoto 8bcf44669c Merge pull request #4835 from shuujii/introduce-mrb_ssize-type-for-buffer-size-on-memory
Introduce `mrb_ssize` type for buffer size on memory; ref #4483
2019-11-22 19:40:19 +09:00
KOBAYASHI Shuji d81e4d71c1 Allow true/false argument to Kernel#exit 2019-11-22 18:29:38 +09:00
KOBAYASHI Shuji a2df247063 Introduce mrb_ssize type for buffer size on memory; ref #4483
Previously, `mrb_int` was used as the type that represents the buffer size
on memory, but the sizes of `RString` and `RArray` exceed 6 words when
`MRB_INT64` is enabled on 32-bit CPU.

I don't think it is necessary to be able to represent the buffer size on
memory that exceeds the virtual address space. Therefore, for this purpose,
introduce `mrb_ssize` which doesn't exceed the sizes of `mrb_int` and
pointer.

I think all `mrb_int` used for this purpose should be changed to
`mrb_ssize`, but currently only the members of the structures (`RString`,
`mrb_shared_string`, `RArray` and `mrb_shared_array`) are changed.
2019-11-21 19:34:02 +09:00
KOBAYASHI Shuji 8596edba09 Use proper PEEK macro for OP_EPUSH in patch_irep; fix #4833 2019-11-20 16:00:58 +09:00
Yukihiro "Matz" Matsumoto 1bb1df19d8 Merge pull request #4831 from shuujii/always-enable-the-rational-and-complex-literals
Always enable the rational and complex literals
2019-11-19 23:32:16 +09:00
Yukihiro "Matz" Matsumoto 125c660974 Merge pull request #4830 from mruby/stable
Release `mruby 2.1.0`.
2019-11-19 23:30:37 +09:00
KOBAYASHI Shuji 351c9c80e7 Always enable the rational and complex literals
I think they can always be enabled because the regular expression literal is
always enabled.
2019-11-19 21:10:59 +09:00
Hiroshi Mimaki 57a56ddaa2 Release mruby 2.1.0. 2019-11-19 18:58:11 +09:00
Yukihiro "Matz" Matsumoto 79e73dd86a Merge pull request #4828 from shuujii/refactor-mrb_string_value_cstr
Refactor `mrb_string_value_cstr`
2019-11-19 02:52:39 +09:00
KOBAYASHI Shuji 3241a7e5a8 Refactor mrb_string_value_cstr
- Keep `MRB_STR_ASCII` flag.
- Avoid a string object creation.
2019-11-19 01:07:58 +09:00
Yukihiro "Matz" Matsumoto bd87799673 Merge pull request #4825 from shuujii/fix-argument-specs-to-Kernel
Fix argument specs to `Kernel`
2019-11-18 08:15:58 +09:00
KOBAYASHI Shuji 9de7130a9a Support short options concatenation to mruby command
#### Before this patch:

  ```
  $ bin/mruby -ce 1
  bin/mruby: Cannot open program file: 1
  ```

#### After this patch:

  ```
  $ bin/mruby -ce 1
  Syntax OK
  ```
2019-11-17 16:38:50 +09:00
Yukihiro "Matz" Matsumoto 74310f41d7 Merge pull request #4826 from shuujii/revert-Implement-Ruby2.7-frozen-strings-from-Symbol-to_s
Revert "Implement Ruby2.7's frozen strings from `Symbol#to_s`"
2019-11-17 04:38:46 +09:00
KOBAYASHI Shuji a367373fe3 Revert "Implement Ruby2.7's frozen strings from Symbol#to_s"
This feature was reverted from Ruby 2.7.
2019-11-16 19:47:31 +09:00
KOBAYASHI Shuji 04baaab311 Fix argument specs to Kernel 2019-11-15 19:07:42 +09:00
Yukihiro "Matz" Matsumoto c9f156ef0c Merge pull request #4823 from shuujii/fix-here-document-with-EOF
Fix here document with EOF
2019-11-15 08:16:33 +09:00
KOBAYASHI Shuji 455930fbc4 Fix here document with EOF
#### Before this patch:

  ```
  $ bin/mruby -e 'p <<EOS
1
EOS'
  -e:4:0: can't find heredoc delimiter "EOS" anywhere before EOF
  -e:4:0: syntax error, unexpected $end, expecting tHEREDOC_END or tHD_STRING_PART or tHD_STRING_MID
  ```

#### After this patch (same as Ruby):

  ```
  $ bin/mruby -e 'p <<EOS
1
EOS'
  "1\n"
  ```
2019-11-14 20:28:36 +09:00
Yukihiro "Matz" Matsumoto db43738397 Merge pull request #4821 from shuujii/use-mrb_intern_lit-if-possible-in-parse.y
Use `mrb_intern_lit` if possible in `parse.y`
2019-11-13 21:08:47 +09:00
Yukihiro "Matz" Matsumoto 079aff1779 Revert a76dc04 to resolve #4820 2019-11-13 21:06:26 +09:00
KOBAYASHI Shuji 29133b2fe2 Use mrb_intern_lit if possible in parse.y 2019-11-13 19:20:47 +09:00
Yukihiro "Matz" Matsumoto 37c8cbe76b Merge pull request #4819 from shuujii/use-intern-instead-of-intern_cstr-if-possible-in-parse.y
Use `intern` instead of `intern_cstr` if possible in `parse.y`
2019-11-13 08:10:50 +09:00
KOBAYASHI Shuji ac917983c5 Use intern instead of intern_cstr if possible in parse.y 2019-11-12 21:04:12 +09:00
Yukihiro "Matz" Matsumoto 1259564c01 Merge pull request #4818 from shuujii/fix-argument-specs-to-Integer
Fix argument specs to `Integer`
2019-11-12 08:33:21 +09:00
KOBAYASHI Shuji edbc6d8ab5 Fix argument specs to Integer 2019-11-11 20:48:52 +09:00
Yukihiro "Matz" Matsumoto c268e36e44 Require Regexp.escape before interpolating build_dir; fix #4817 2019-11-11 18:13:24 +09:00
Yukihiro "Matz" Matsumoto 067c11f65d Merge pull request #4816 from shuujii/defer-getting-caller_dir-until-needed-in-MRubyLoadGems-gem
Defer getting `caller_dir` until needed in `MRuby::LoadGems#gem`
2019-11-11 07:33:31 +09:00
KOBAYASHI Shuji b5946822af Defer getting caller_dir until needed in MRuby::LoadGems#gem 2019-11-10 19:40:07 +09:00
Yukihiro "Matz" Matsumoto cc54257de5 Merge pull request #4814 from shuujii/fix-argument-specs-to-IO
Fix argument specs to `IO`
2019-11-10 08:29:55 +09:00
KOBAYASHI Shuji a72917541f Fix argument specs to IO 2019-11-09 22:08:00 +09:00
Yukihiro "Matz" Matsumoto e50344b5da Avoid unnecessary Symbol#to_s call; fix #4812 2019-11-08 23:38:40 +09:00
Yukihiro "Matz" Matsumoto 1a0c799898 Merge pull request #4813 from shuujii/remove-unneeded-dependency-from-mruby-hash-ext
Remove unneeded dependency from `mruby-hash-ext`
2019-11-08 23:37:40 +09:00
KOBAYASHI Shuji ac213907d7 Remove unneeded dependency from mruby-hash-ext 2019-11-08 20:40:20 +09:00
Yukihiro "Matz" Matsumoto 7750c61e29 Fixed a bug in keyword arguments in block parameters; fix #4810
This is caused by incomplete fix in #4746
2019-11-08 14:06:46 +09:00
Yukihiro "Matz" Matsumoto 8ff001ef30 Avoid crashing of Array#unshift; fix #4808
On cases like `a.unshift(*a)`.
2019-11-08 10:57:18 +09:00
Yukihiro "Matz" Matsumoto 962776fe25 Allow here-doc before closing parentheses; ref #4796 2019-11-08 09:50:48 +09:00
Yukihiro "Matz" Matsumoto 0f64cb421e Merge pull request #4811 from shuujii/clear-MRB_STR_SHARED-flag-in-mrb_str_modify_keep_ascii
Clear `MRB_STR_SHARED` flag in `mrb_str_modify_keep_ascii`; close #4807
2019-11-08 08:12:23 +09:00
KOBAYASHI Shuji 45aa5081e4 Clear MRB_STR_SHARED flag in mrb_str_modify_keep_ascii; close #4807 2019-11-07 22:16:59 +09:00
Yukihiro "Matz" Matsumoto c10e191ac7 Merge pull request #4806 from shuujii/drop-test-dependency-from-mruby-hash-ext-to-mruby-enumerator
Drop test dependency from `mruby-hash-ext` to `mruby-enumerator`
2019-11-06 21:10:21 +09:00
KOBAYASHI Shuji ea2424d36d Drop test dependency from mruby-hash-ext to mruby-enumerator 2019-11-06 18:57:35 +09:00
Yukihiro "Matz" Matsumoto 1cc0180a81 Merge pull request #4805 from shuujii/remove-test-that-depend-on-mruby-enumerator-from-mruby-array-ext
Remove test that depend on `mruby-enumerator` from `mruby-array-ext`
2019-11-05 21:35:06 +09:00
KOBAYASHI Shuji b5bb981959 Remove test that depend on mruby-enumerator from mruby-array-ext
`Object.const_defined?(:Enumerator)` is always false because
`mruby-enumerator` is not specified in `test_dependency`. I don't
think this test is necessary.
2019-11-05 19:45:04 +09:00
Yukihiro "Matz" Matsumoto ee86721ef9 Merge pull request #4804 from shuujii/avoid-using-C++-style-comments-in-parse.y
Avoid using C++ style comments (`//`) in `parse.y` [ci skip]
2019-11-05 17:08:53 +09:00
KOBAYASHI Shuji 4841754aba Avoid using C++ style comments (//) in parse.y [ci skip] 2019-11-04 22:12:59 +09:00
Yukihiro "Matz" Matsumoto 2166cc2e80 Merge pull request #4803 from shuujii/remove-unused-enum-in-mrb_cstr_to_dbl
Remove unused enum in `mrb_cstr_to_dbl`
2019-11-03 22:31:35 +09:00
KOBAYASHI Shuji bf0b591b2f Remove unused enum in mrb_cstr_to_dbl 2019-11-03 19:39:25 +09:00
Yukihiro "Matz" Matsumoto 5812d05b71 Merge pull request #4802 from shuujii/fix-argument-specs-to-Hash
Fix argument specs to `Hash`
2019-11-02 19:40:48 +09:00
KOBAYASHI Shuji 7a06e49008 Fix argument specs to Hash 2019-11-02 17:37:43 +09:00
Yukihiro "Matz" Matsumoto 8cbee9695b Merge pull request #4801 from shuujii/fix-argument-specs-to-File
Fix argument specs to `File`
2019-11-02 08:40:22 +09:00
KOBAYASHI Shuji 7e03f47370 Fix argument specs to File 2019-11-01 22:02:18 +09:00
KOBAYASHI Shuji ad6c58972c Set MRB_STR_ASCII flag to some stringize methods
- `Fixnum#to_s`, `Fixnum#inspect`
- `Float#to_s`, `Float#inspect`
- `NilClass#to_s`, `NilClass#inspect`
- `FalseClass#to_s`, `FalseClass#inspect`
- `TrueClass#to_s`, `TrueClass#inspect`
- `Time#to_s`, `Time#inspect`
2019-10-31 22:04:56 +09:00
Yukihiro "Matz" Matsumoto ad7f9b3542 Merge pull request #4799 from shuujii/fix-argument-specs-to-Fiber
Fix argument specs to `Fiber`
2019-10-31 11:29:19 +09:00
KOBAYASHI Shuji e4d078b520 Fix argument specs to Fiber 2019-10-30 23:00:22 +09:00
Yukihiro "Matz" Matsumoto 1dc0da8218 Fix here-doc inside parens and brackets; fix #4796 2019-10-30 10:05:28 +09:00
mimaki a9e27933a9 Fix file/directory name parameter for git command. 2019-10-30 09:32:24 +09:00
Yukihiro "Matz" Matsumoto fdc0219db5 Merge pull request #4798 from mimaki/fix-git-params-for-windows
Fix `git` command parameter for Windows.
2019-10-30 00:40:58 +09:00
Yukihiro "Matz" Matsumoto ecdc6c6507 Merge pull request #4797 from shuujii/remove-unneeded-Array-creation-in-Struct-_inspect
Remove unneeded `Array` creation in `Struct#_inspect`
2019-10-30 00:39:44 +09:00
mimaki f68212cc7a Fix file/directory name parameter for git command. 2019-10-29 20:56:12 +09:00
KOBAYASHI Shuji e23840a3fc Remove unneeded Array creation in Struct#_inspect 2019-10-29 20:55:28 +09:00
Yukihiro "Matz" Matsumoto 34f68d0104 Merge pull request #4795 from shuujii/remove-documents-about-Regexp-argument-from-string
Remove documents about `Regexp` argument from `String#{[],[]=}` [ci skip]
2019-10-28 22:24:04 +09:00
KOBAYASHI Shuji 23cb78a0ff Remove documents about Regexp argument from String#{[],[]=} [ci skip] 2019-10-28 18:37:40 +09:00
Yukihiro "Matz" Matsumoto 552bd9daff Merge pull request #4792 from shuujii/refine-String-split-document
Refine `String#split` document
2019-10-27 22:52:50 +09:00
KOBAYASHI Shuji 799ad0e1c7 Refine String#split document 2019-10-27 19:14:12 +09:00
Yukihiro "Matz" Matsumoto 8710a22c31 Merge pull request #4791 from shuujii/optimize-chars2bytes-with-MRB_UTF8_STRING-to-ASCII-only-string
Optimize `chars2bytes` with `MRB_UTF8_STRING` to ASCII only string
2019-10-26 23:09:30 +09:00
KOBAYASHI Shuji db0a4d9045 Optimize chars2bytes with MRB_UTF8_STRING to ASCII only string
### Benchmark (with `MRB_UTF8_STRING`)

  ```
  $ mruby -e '
    COUNT = 150000
    SIZE = 10000
    strs = Array.new(COUNT) do
      s = "a" * SIZE
      s.size  # set `MRB_STR_ASCII` flag
      s
    end
    i = 0
    t = Time.now
    while i < COUNT
      strs[i][-2..-1] = ""
      i += 1
    end
    printf "%.2f sec\n", Time.now - t
  '

  1.10 sec  # before
  0.07 sec  # after
  ```
2019-10-26 22:19:04 +09:00
Yukihiro "Matz" Matsumoto 9c99451607 Merge pull request #4790 from shuujii/squeeze-redundant-spaces
Squeeze redundant spaces in `test/t/numeric.rb` [ci skip]
2019-10-25 22:14:18 +09:00
KOBAYASHI Shuji 4b14c4633a Squeeze redundant spaces in test/t/numeric.rb [ci skip] 2019-10-25 19:39:31 +09:00
Yukihiro "Matz" Matsumoto 39a0a25f20 Merge pull request #4788 from shuujii/fix-argument-specs-to-Exception
Fix argument specs to `Exception`
2019-10-25 08:21:53 +09:00
KOBAYASHI Shuji 85e34f1ca4 Fix argument specs to Exception 2019-10-24 22:24:40 +09:00
Yukihiro "Matz" Matsumoto b4262972dc Merge pull request #4787 from shuujii/optimize-str_subseq-with-MRB_UTF8_STRING-to-ASCII-only-string
Optimize `str_subseq` with `MRB_UTF8_STRING` to ASCII only string
2019-10-23 20:12:55 +09:00
KOBAYASHI Shuji 06bd4ffdaf Optimize str_subseq with MRB_UTF8_STRING to ASCII only string
### Benchmark (with `MRB_UTF8_STRING`)

  ```ruby
  # benchmark.rb
  COUNT = 300000
  SIZE = 10000
  s = "a" * SIZE
  s.size  # set `MRB_STR_ASCII` flag
  i = 0
  while i < COUNT
    s[-1]
    i += 1
  end
  ```

#### Before this patch:

  ```
  $ time mruby benchmark.rb
          2.06 real         2.05 user         0.00 sys
  ```

#### After this patch:

  ```
  $ time mruby benchmark.rb
          0.05 real         0.04 user         0.00 sys
  ```
2019-10-23 19:03:39 +09:00
Hiroshi Mimaki 4eb8fca140 Merge branch 'master' into stable 2019-10-23 15:44:21 +09:00
Yukihiro "Matz" Matsumoto fa85f91e0e Add type cast to avoid an error from int and enum mixture; fix #4786 2019-10-23 14:47:55 +09:00
Yukihiro "Matz" Matsumoto 9540a8309c Remove unnecessary mrb_funcall(). 2019-10-23 14:47:55 +09:00
Yukihiro "Matz" Matsumoto 11184e9186 Remove unnecessary mrb_string_p() check. 2019-10-23 14:47:55 +09:00
Yukihiro "Matz" Matsumoto 2f0bf1e110 Merge pull request #4785 from shuujii/fix-incorrect-MRB_STR_ASCII-flag-update-in-mrb_str_dump
Fix incorrect `MRB_STR_ASCII` flag update in `mrb_str_dump`
2019-10-23 09:55:47 +09:00
KOBAYASHI Shuji 41c43234a7 Fix incorrect MRB_STR_ASCII flag update in mrb_str_dump
### Example (with `MRB_UTF8_STRING`)

  ```ruby
  s = "\u3042"
  p s.size
  s.dump
  p s.size
  ```

#### Before this patch:

  ```
  1
  3
  ```

#### After this patch:

  ```
  1
  1
  ```
2019-10-22 21:56:40 +09:00
Yukihiro "Matz" Matsumoto 1aacde20fa Merge pull request #4784 from shuujii/remove-Kernel-getc
Remove `Kernel#getc`
2019-10-21 21:27:02 +09:00
KOBAYASHI Shuji 941b99955a Remove Kernel#getc
`Kernel#getc` has been removed since Ruby 1.9 and is not defined in ISO.
2019-10-21 18:50:52 +09:00
Yukihiro "Matz" Matsumoto 0701cc493c Merge pull request #4783 from shuujii/use-mrb_str_cat_str-instead-of-mrb_str_concat-if-possible
Use `mrb_str_cat_str` instead of `mrb_str_concat` if possible
2019-10-20 20:24:10 +09:00
KOBAYASHI Shuji 7047c52d7b Use mrb_str_cat_str instead of mrb_str_concat if possible 2019-10-20 16:26:10 +09:00
Yukihiro "Matz" Matsumoto fddefeb7ee Merge pull request #4781 from shuujii/fix-that-Module-to_s-may-return-frozen-string
Fix that `Module#to_s` may return frozen string; ref 08eafe2
2019-10-19 17:55:26 +09:00
KOBAYASHI Shuji 347729a7c0 Fix that Module#to_s may return frozen string; ref 08eafe2 2019-10-19 17:27:17 +09:00
Yukihiro "Matz" Matsumoto 7957f75bd8 Merge pull request #4779 from take-cheeze/print_mrbc_cmd
Print mrbc command on verbose mode
2019-10-19 11:12:03 +09:00
take-cheeze 4877dbf2a9 Print mrbc command on verbose mode 2019-10-19 01:42:34 +09:00
Hiroshi Mimaki 4c91adc4b2 Update version to 2.1.0. (mruby 2.1.0 RC) 2019-10-18 14:59:27 +09:00
Hiroshi Mimaki b654683545 Merge master. 2019-10-18 14:46:03 +09:00
Yukihiro "Matz" Matsumoto 20d01f118d Merge pull request #4778 from shuujii/move-methods-of-Kernel-to-kernel.rb-from-io.rb-in-mruby-io-gem
Move methods of `Kernel` to `kernel.rb` from `io.rb` in `mruby-io` gem
2019-10-18 12:23:28 +09:00
KOBAYASHI Shuji e5d767b149 Move methods of Kernel to kernel.rb from io.rb in mruby-io gem 2019-10-18 10:50:23 +09:00
Yukihiro "Matz" Matsumoto e5f7b1d262 Merge pull request #4777 from yurie/pr
Remove constant export declaration for MRBC output compiled as C
2019-10-18 06:58:08 +09:00
yuri d29178a9cd delete extern in C 2019-10-17 23:49:58 +09:00
Yukihiro "Matz" Matsumoto bc4799361e Merge pull request #4776 from shuujii/make-IO-each-family-without-block-to-return-Enumerator
Make `IO#each` family without block to return `Enumerator`
2019-10-17 20:50:22 +09:00
KOBAYASHI Shuji 14870a290d Make IO#each family without block to return Enumerator 2019-10-17 20:14:02 +09:00
Yukihiro "Matz" Matsumoto 84db8edade Merge pull request #4775 from shuujii/use-mrb_sym_name_len-instead-of-mrb_sym_name-in-assign_class_name
Use `mrb_sym_name_len` instead of `mrb_sym_name` in `assign_class_name`
2019-10-16 20:22:00 +09:00
KOBAYASHI Shuji 3827c4deb2 Use mrb_sym_name_len instead of mrb_sym_name in assign_class_name 2019-10-16 18:18:58 +09:00
Yukihiro "Matz" Matsumoto b7af9c47b3 Merge pull request #4774 from shuujii/adjust-buf-size-in-str_escape
Adjust `buf` size in `str_escape`
2019-10-16 07:36:33 +09:00
KOBAYASHI Shuji b0507e7678 Adjust buf size in str_escape 2019-10-15 19:23:30 +09:00
Yukihiro "Matz" Matsumoto dc474b625b Merge pull request #4773 from shuujii/fix-the-example-of-Array-intersection-in-the-document
Fix the example of `Array#intersection` in the document [ci skip]
2019-10-14 18:56:12 +09:00
KOBAYASHI Shuji ac29638a8a Fix the example of Array#intersection in the document [ci skip] 2019-10-14 18:22:00 +09:00
Yukihiro "Matz" Matsumoto bdacdfaea9 Add Array#intersection which is new in Ruby2.7. 2019-10-14 17:04:19 +09:00
Yukihiro "Matz" Matsumoto 682406a384 Move Array#difference just after Array#-. 2019-10-14 17:04:19 +09:00
Yukihiro "Matz" Matsumoto 67ea80b2bd Fixed a bug in Array#difference. 2019-10-14 17:04:19 +09:00
Yukihiro "Matz" Matsumoto 265034134a Merge pull request #4772 from shuujii/refactor-mrb_class_name_class
Refactor `mrb_class_name_class`
2019-10-13 17:20:46 +09:00
KOBAYASHI Shuji 6377c9bce5 Refactor mrb_class_name_class
- Use `mrb_sym_name_len` instead of `mrb_sym_name` (class name should not
  be escaped).
- Avoid `mrb_str_dup` (it is unnecessary to be shared string because it is
  changed).
2019-10-13 17:03:39 +09:00
Yukihiro "Matz" Matsumoto d128e2d09e Merge pull request #4770 from shuujii/sHARED-string-is-not-required-when-sharing-POOL-string
SHARED string is not required when sharing POOL string
2019-10-12 23:35:43 +09:00
Yukihiro "Matz" Matsumoto 9f3b6ebbde Merge pull request #4769 from shuujii/rename-str_make_shared-to-str_share
Rename `str_make_shared()` to `str_share()` in `src/string.c`
2019-10-12 23:33:20 +09:00
KOBAYASHI Shuji 7594983671 SHARED string is not required when sharing POOL string
The heap string buffer of POOL string always exists, does not need to be
released, and read only, so it can be shared as NOFREE string.
2019-10-12 21:32:56 +09:00
KOBAYASHI Shuji cdd36c979d Rename str_make_shared() to str_share() in src/string.c
Because it may not create `struct mrb_shared_string`.
2019-10-12 12:49:51 +09:00
Yukihiro "Matz" Matsumoto c310c8dc24 Move exception raising to scope_new.
Besides that fix bugs that mistakenly calls `raise_error` that emits
code to raise runtime error instead of `codegen_error` that terminates
code generation immediately.
2019-10-11 20:31:29 +09:00
Yukihiro "Matz" Matsumoto 20ceee794b Merge pull request #4767 from shuujii/remove-unused-exception-classes-in-mruby-io-gem
Remove unused exception classes in `mruby-io` gem
2019-10-11 19:54:44 +09:00
KOBAYASHI Shuji a7ae0d5b9e Remove unused exception classes in mruby-io gem 2019-10-11 11:32:14 +09:00
Yukihiro "Matz" Matsumoto 529a336966 Fixed a bug in mruby-time with NO_GETTIMEOFDAT. 2019-10-10 20:46:12 +09:00
Yukihiro "Matz" Matsumoto 78e54904b5 Silence double free warnings by mrb_local_free().
The warnings were detected by cppcheck.
2019-10-10 20:46:12 +09:00
Yukihiro "Matz" Matsumoto 8fe6a1904c Merge pull request #4764 from shuujii/integrate-mrb_str_inspect-and-mrb_str_dump
Integrate `mrb_str_inspect` and `mrb_str_dump`
2019-10-10 20:45:59 +09:00
KOBAYASHI Shuji 7ce5d33947 Integrate mrb_str_inspect and mrb_str_dump 2019-10-10 19:50:48 +09:00
Yukihiro "Matz" Matsumoto 20aab8a10b Merge pull request #4763 from shuujii/mrdb-Fix-that-print-command-raises-FrozenError
Fix that `print` command raises `FrozenError` in `mrdb`; ref 1f5a7f2f
2019-10-09 22:47:12 +09:00
KOBAYASHI Shuji 7f6e8e8ddc Fix that print command raises FrozenError in mrdb; ref 1f5a7f2f
#### Before this patch:

  ```
  $ echo 'p true' | bin/mrdb /dev/null
  (/dev/null:1) mruby application exited.
  FrozenError: can't modify frozen String
  (-:0)
  ```

#### After this patch:

  ```
  $ echo 'p true' | bin/mrdb /dev/null
  (/dev/null:1) $1 = true
  (/dev/null:1)
  ```
2019-10-09 20:00:17 +09:00
Yukihiro "Matz" Matsumoto 7624e23426 Revert part of #4758 to reduce number of tests.
More tests, more time.
2019-10-09 10:29:04 +09:00
Yukihiro "Matz" Matsumoto 3e9b501ff8 Merge pull request #4761 from take-cheeze/fix_4759
Add mrbgem version field to lock file
2019-10-09 08:01:52 +09:00
take-cheeze f7616c4287 Add mrbgem version field to lock file 2019-10-09 02:22:33 +09:00
Yukihiro "Matz" Matsumoto b68818a8a0 Merge pull request #4758 from shuujii/implement-Ruby2.7-frozen-strings-from-Module-name
Implement Ruby2.7's frozen strings from `Module#name`
2019-10-08 22:25:43 +09:00
Yukihiro "Matz" Matsumoto e348326fa7 Merge pull request #4760 from shuujii/use-mrb_str_concat-instead-of-mrb_str_to_str-plus-mrb_str_cat_str
Use `mrb_str_concat` instead of `mrb_str_to_str` + `mrb_str_cat_str`
2019-10-08 22:23:59 +09:00
KOBAYASHI Shuji 97c62408fb Use mrb_str_concat instead of mrb_str_to_str + mrb_str_cat_str 2019-10-08 18:55:45 +09:00
KOBAYASHI Shuji fb103c1319 Implement Ruby2.7's frozen strings from Module#name 2019-10-08 17:34:13 +09:00
Yukihiro "Matz" Matsumoto b7a8d538c1 Remove unnecessary function: mrb_str_freeze. 2019-10-06 22:18:11 +09:00
Yukihiro "Matz" Matsumoto ff1ac49a72 Merge pull request #4754 from dearblue/get-keyword-args
Get keyword arguments with `mrb_get_args()`
2019-10-06 22:08:15 +09:00
dearblue 5f929d6940 Get keyword arguments with mrb_get_args()
Keyword arguments can now be retrieved with the `:` specifier and
`mrb_kwargs` data.

For the interface, I referred to CRuby's `rb_get_kwargs()`.
For implementation, I referred to `OP_KARG` or etc.
2019-10-06 21:23:55 +09:00
Yukihiro "Matz" Matsumoto ffaa2968ed Merge pull request #4757 from shuujii/refine-the-usage-message-of-mirb-command
Refine the usage message of `mirb` command
2019-10-06 20:23:30 +09:00
Yukihiro "Matz" Matsumoto 028ab5a143 Merge pull request #4755 from shuujii/refine-the-usage-message-of-mruby-command
Refine the usage message of `mruby` command
2019-10-06 20:23:04 +09:00
KOBAYASHI Shuji ea14df2e3a Refine the usage message of mirb command 2019-10-06 20:12:28 +09:00
KOBAYASHI Shuji 0cdc984b1c Refine the usage message of mruby command 2019-10-06 19:35:41 +09:00
Yukihiro "Matz" Matsumoto c613813364 Merge pull request #4752 from shuujii/drop-initialization-dependency-from-mruby-print-to-mruby-sprintf
Drop initialization dependency from `mruby-print` to `mruby-sprintf`
2019-10-05 17:18:12 +09:00
KOBAYASHI Shuji 1d8456fe7d Drop initialization dependency from mruby-print to mruby-sprintf
In the old implementation, `Kernel#printf` raise error if `mruby-sprintf`
gem isn't specified before `mruby-print` gem. The new implementation
eliminates this ordering issue. This way is the same as `Kernel#printf` and
`IO#printf` in `mruby-io` gem.
2019-10-05 15:22:43 +09:00
Yukihiro "Matz" Matsumoto 1f5a7f2f49 Freeze strings from nil.to_s, true.to_s, false.to_s.
This is an experimental changes in Ruby 2.7.
2019-10-04 16:02:50 +09:00
Yukihiro "Matz" Matsumoto 08eafe21d3 Implement Ruby2.7's frozen strings from Symbol#to_s. 2019-10-04 14:42:01 +09:00
Yukihiro "Matz" Matsumoto 264239f78f Refactor local variables addition in optional/keyword arguments. 2019-10-04 14:39:53 +09:00
Yukihiro "Matz" Matsumoto d4e9de84c5 Merge pull request #4751 from shuujii/remove-unused-code-to-old-Visual-Studio
Remove unused code to old Visual Studio in `tasks/toolchains/visualcpp.rake`
2019-10-04 10:11:30 +09:00
KOBAYASHI Shuji edd412966e Remove unused code to old Visual Studio in tasks/toolchains/visualcpp.rake 2019-10-04 09:31:54 +09:00
Yukihiro "Matz" Matsumoto 4695542f37 Merge pull request #4750 from dearblue/c++-abi
Remove duplicates header files in `src/pool.c`
2019-10-04 08:03:38 +09:00
dearblue fab062f7b5 Remove duplicates header files in src/pool.c
These are included in `mruby.h`.

As a background, if `enable_cxx_abi` is specified, the macro that
defines the maximum value in `stdint.h` is undefined depending on the
environment.

- Confirmed with gcc on FreeBSD 12.0 and mingw32-gcc available on
  FreeBSD.
- `INTPTR_MAX`, `INT64_MAX` and `UINT64_MAX` are defined by `cstdint`
  added in C++11. But `toolchains :gcc` adds `-std=c++03`, so the macros
  are not defined.
- To have these defined in `C++03`, `__STDC_CONSTANT_MACROS` must be
  defined in advance. This is already done by `mruby.h`.
2019-10-03 23:32:24 +09:00
Yukihiro "Matz" Matsumoto de176d37e0 Merge pull request #4749 from shuujii/add-tests-for-4746
Add tests for #4746
2019-10-03 21:30:23 +09:00
KOBAYASHI Shuji 882bc80dd0 Add tests for #4746 2019-10-03 16:59:18 +09:00
Yukihiro "Matz" Matsumoto 3d2781311e Merge pull request #4748 from HirohitoHigashi/master
Fix opcode semantics comment miss.
2019-10-03 15:18:06 +09:00
Hirohito Higashi 63496a6730 Fix opcode semantics comment miss. (op_jmpnil) 2019-10-03 15:06:06 +09:00
Hirohito Higashi b4bf7a2282 Fix opcode semantics comment miss. 2019-10-03 14:44:47 +09:00
Yukihiro "Matz" Matsumoto ec6c8b2a3c Add local variable reordering to kwargs; ref #4746 2019-10-03 09:17:37 +09:00
Yukihiro "Matz" Matsumoto 47cdda370e Need to reorder local variables defined in opt; fix #4746
For example, local variables in the following def:
```ruby
def foo(a = (not_set = true), &block)
  ...
end
```
should be `a, block, not_set`, but were `a, not_set, block`.
2019-10-03 07:52:31 +09:00
Yukihiro "Matz" Matsumoto 306f02117b Refactor append_gen function. 2019-10-03 07:52:03 +09:00
Yukihiro "Matz" Matsumoto a406a35cf8 Merge pull request #4747 from shuujii/avoid-symhash-call-for-inline-symbol-in-sym_intern
Avoid `symhash()` call for inline symbol in `sym_intern()`
2019-10-02 23:36:32 +09:00
KOBAYASHI Shuji 855d996847 Avoid symhash() call for inline symbol in sym_intern() 2019-10-02 16:56:22 +09:00
Yukihiro "Matz" Matsumoto c33100c4f0 Merge pull request #4736 from dearblue/ast-strdump
Escape the AST string
2019-10-02 07:07:20 +09:00
Yukihiro "Matz" Matsumoto 97433c0263 Merge pull request #4745 from shuujii/dump-more-node-types
Dump more node types in `mrb_parser_dump`
2019-10-01 19:35:11 +09:00
KOBAYASHI Shuji 8df2763b56 Support NODE_LITERAL_DELIM in mrb_parser_dump
#### Before this patch:

  ```terminal
  $ bin/mruby -v -e '%w[1 2]'
  mruby 2.0.1 (2019-04-04)
  00001 NODE_SCOPE:
  00001   NODE_BEGIN:
  00001     NODE_WORDS:
  00001       NODE_STR "1" len 1
  00001       node type: 85 (0x55)
  00001       NODE_STR "2" len 1
  (snip)
  ```

#### After this patch:

  ```terminal
  $ bin/mruby -v -e '%w[1 2]'
  mruby 2.0.1 (2019-04-04)
  00001 NODE_SCOPE:
  00001   NODE_BEGIN:
  00001     NODE_WORDS:
  00001       NODE_STR "1" len 1
  00001       NODE_LITERAL_DELIM
  00001       NODE_STR "2" len 1
  (snip)
  ```
2019-10-01 17:20:39 +09:00
KOBAYASHI Shuji 42c7f2d6b0 Support NODE_SYMBOLS in mrb_parser_dump
#### Before this patch:

  ```terminal
  $ bin/mruby -v -e '%i[1]; %I[#{2}]'
  mruby 2.0.1 (2019-04-04)
  00001 NODE_SCOPE:
  00001   NODE_BEGIN:
  00001     node type: 87 (0x57)
  00001     node type: 87 (0x57)
  (snip)
  ```

#### After this patch:

  ```terminal
  $ bin/mruby -v -e '%i[1]; %I[#{2}]'
  mruby 2.0.1 (2019-04-04)
  00001 NODE_SCOPE:
  00001   NODE_BEGIN:
  00001     NODE_SYMBOLS:
  00001       NODE_STR "1" len 1
  00001     NODE_SYMBOLS:
  00001       NODE_STR "" len 0
  00001       NODE_BEGIN:
  00001         NODE_INT 2 base 10
  00001       NODE_STR "" len 0
  (snip)
  ```
2019-10-01 17:10:34 +09:00
KOBAYASHI Shuji 732ef6b10e Support NODE_WORDS in mrb_parser_dump
#### Before this patch:

  ```terminal
  $ bin/mruby -v -e '%w[1]; %W[#{2}]'
  mruby 2.0.1 (2019-04-04)
  00001 NODE_SCOPE:
  00001   NODE_BEGIN:
  00001     node type: 86 (0x56)
  00001     node type: 86 (0x56)
  (snip)
  ```

#### After this patch:

  ```terminal
  $ bin/mruby -v -e '%w[1]; %W[#{2}]'
  mruby 2.0.1 (2019-04-04)
  00001 NODE_SCOPE:
  00001   NODE_BEGIN:
  00001     NODE_WORDS:
  00001       NODE_STR "1" len 1
  00001     NODE_WORDS:
  00001       NODE_STR "" len 0
  00001       NODE_BEGIN:
  00001         NODE_INT 2 base 10
  00001       NODE_STR "" len 0
  (snip)
  ```
2019-10-01 17:07:30 +09:00
Yukihiro "Matz" Matsumoto cdb35a12fc Merge pull request #4744 from shuujii/remove-a-trailing-space-in-MRUBY_DESCRIPTION
Remove a trailing space in `MRUBY_DESCRIPTION`
2019-10-01 12:16:27 +09:00
KOBAYASHI Shuji 482d0626b8 Remove a trailing space in MRUBY_DESCRIPTION 2019-09-30 21:39:13 +09:00
KOBAYASHI Shuji 16745261e3 Support NODE_DSYM in mrb_parser_dump
#### Before this patch:

  ```terminal
  $ bin/mruby -v -e ':"#{1}"; ["#{2}": 0]'
  mruby 2.0.1 (2019-04-04)
  00001 NODE_SCOPE:
  00001   NODE_BEGIN:
  00001     node type: 83 (0x53)
  00001     NODE_ARRAY:
  00001       NODE_KW_HASH:
  00001         key:
  00001           node type: 83 (0x53)
  00001         value:
  00001           NODE_INT 0 base 10
  (snip)
  ```

#### After this patch:

  ```terminal
  $ bin/mruby -v -e ':"#{1}"; ["#{2}": 0]'
  mruby 2.0.1 (2019-04-04)
  00001 NODE_SCOPE:
  00001   NODE_BEGIN:
  00001     NODE_DSYM:
  00001       NODE_DSTR:
  00001         NODE_STR "" len 0
  00001         NODE_BEGIN:
  00001           NODE_INT 1 base 10
  00001         NODE_STR "" len 0
  00001     NODE_ARRAY:
  00001       NODE_KW_HASH:
  00001         key:
  00001           NODE_DSYM:
  00001             NODE_DSTR:
  00001               NODE_STR "" len 0
  00001               NODE_BEGIN:
  00001                 NODE_INT 2 base 10
  00001               NODE_STR "" len 0
  00001         value:
  00001           NODE_INT 0 base 10
  (snip)
  ```
2019-09-30 11:54:51 +09:00
Yukihiro "Matz" Matsumoto 9ddde3be39 Merge pull request #4742 from dearblue/mrb_hash_value
Remove unnecessary type `mrb_hash_value`
2019-09-30 03:06:56 +09:00
dearblue 40e8a90e89 Remove unnecessary type mrb_hash_value
The type `mrb_hash_value` is no longer used by the segmented list
implementation (ref e8dcfe1 and e65d426).
2019-09-29 23:55:38 +09:00
Yukihiro "Matz" Matsumoto 4621907fca Merge pull request #4741 from shuujii/print-missing-colon-before-newline-in-mrb_parser_dump
Print missing `:` before newline in `mrb_parser_dump`
2019-09-29 22:05:41 +09:00
KOBAYASHI Shuji a5d140ae42 Print missing : before newline in mrb_parser_dump 2019-09-29 17:14:52 +09:00
Yukihiro "Matz" Matsumoto e55f881bc2 Merge pull request #4740 from dearblue/rethrow-break
Allow rethrowing `MRB_TT_BREAK`
2019-09-29 15:38:16 +09:00
dearblue d8f1099419 Allow rethrowing MRB_TT_BREAK 2019-09-29 15:11:36 +09:00
Yukihiro "Matz" Matsumoto ccf7a8248f Merge pull request #4739 from dearblue/restore-arena
Restore GC arena frequently
2019-09-29 14:40:29 +09:00
Yukihiro "Matz" Matsumoto a1886942eb Further refactoring over #4738 2019-09-29 14:30:41 +09:00
Yukihiro "Matz" Matsumoto c5d500d51e Merge pull request #4738 from dearblue/unneed-assign
Remove unnecessary assignments
2019-09-29 14:29:07 +09:00
dearblue 39855a3304 Restore GC arena frequently 2019-09-29 13:57:22 +09:00
Yukihiro "Matz" Matsumoto 704c40bfa2 Merge pull request #4737 from dearblue/hash-delete
Add an annotation about the return value
2019-09-29 13:56:31 +09:00
Yukihiro "Matz" Matsumoto bbfd64d01b Add an annotation of the return value from mrb_delete_key; #4737
The return value from `mrb_delete_key` needs to be protected from GC in
some cases.
2019-09-29 13:53:45 +09:00
dearblue e48207cdb3 Remove unnecessary assignments 2019-09-29 13:45:16 +09:00
Yukihiro "Matz" Matsumoto acbea6affe Merge pull request #4735 from shuujii/remove-unused-node-type-in-codegen
Remove unused node type in `codegen()`
2019-09-29 12:47:16 +09:00
dearblue f6d3d675ab Add an annotation about the return value 2019-09-29 11:49:15 +09:00
dearblue e2f54ff594 Escape the AST string 2019-09-29 10:39:55 +09:00
KOBAYASHI Shuji ae530d89c4 Remove unused node type in codegen() 2019-09-28 15:15:31 +09:00
Yukihiro "Matz" Matsumoto 19e4f56c67 Merge pull request #4734 from shuujii/simplify-arguments-check-in-String-rindex
Simplify arguments check in `String#rindex`
2019-09-28 00:20:01 +09:00
Yukihiro "Matz" Matsumoto 2de757eef0 Replace mrb_sym_name with mrb_sym_dump; ref #4684 2019-09-28 00:06:01 +09:00
KOBAYASHI Shuji 198683e914 Simplify arguments check in String#rindex
Also fix document about type of the first argument.
2019-09-27 17:13:57 +09:00
Yukihiro "Matz" Matsumoto 5cd6ed4511 Merge pull request #4733 from shuujii/use-type-predicate-macros-instead-of-mrb_type-if-possible
Use type predicate macros instead of `mrb_type` if possible
2019-09-27 00:00:03 +09:00
Yukihiro "Matz" Matsumoto d4be545d54 Fixed codedump for human readable symbol format; ref #4684 2019-09-26 23:56:40 +09:00
KOBAYASHI Shuji feaf80d899 Use type predicate macros instead of mrb_type if possible
For efficiency with `MRB_WORD_BOXING` (implement type predicate macros for
all `enum mrb_vtype`).
2019-09-26 22:23:27 +09:00
Yukihiro "Matz" Matsumoto 60cc46a92c Use proper type specifier for mrb_raisef(); ref #4731
The following two may be different:
* `%d` for `int`
* `%i` for `mrb_int`
2019-09-26 09:48:01 +09:00
Yukihiro "Matz" Matsumoto 184aeb0694 Merge pull request #4732 from dearblue/inttypes
Use inttypes for `snprintf()`
2019-09-26 06:31:07 +09:00
Yukihiro "Matz" Matsumoto 0d661bcca6 Merge pull request #4731 from dearblue/consistent-type
Keep the type of `posarg` consistent
2019-09-26 06:30:55 +09:00
Yukihiro "Matz" Matsumoto 9bf193b49a Merge pull request #4728 from shuujii/remove-MRB_TT_HAS_BASIC-macro
Remove `MRB_TT_HAS_BASIC` macro
2019-09-25 23:55:55 +09:00
Yukihiro "Matz" Matsumoto 5c381032b0 Merge pull request #4729 from dearblue/fix-4598
Fix `MRB_WITHOUT_FLOAT` reversal; fix #4598
2019-09-25 23:55:36 +09:00
Yukihiro "Matz" Matsumoto b5fa2dadfc Merge pull request #4730 from dearblue/fall-through
Add "fall through"
2019-09-25 23:53:34 +09:00
Yukihiro "Matz" Matsumoto a365f9a67d Rename symbol-to-string functions; close #4684
* mrb_sym2name -> mrb_sym_name
* mrb_sym2name_len -> mrb_sym_name_len
* mrb_sym2str -> mrb_sym_str
2019-09-25 23:52:00 +09:00
dearblue 84d9296c05 Use inttypes for snprintf() 2019-09-25 23:28:05 +09:00
dearblue 9f6ba4bfa1 Keep the type of posarg consistent
Match the type with the caller and related functions.
2019-09-25 23:17:06 +09:00
dearblue 5ce1bec1bc Add "fall through" 2019-09-25 23:07:05 +09:00
dearblue eb2f34719d Fix MRB_WITHOUT_FLOAT reversal; fix #4598 2019-09-25 22:55:41 +09:00
KOBAYASHI Shuji 27e8ea4ea2 Remove MRB_TT_HAS_BASIC macro
The value of `MRB_TT_HAS_BASIC` is meaningless because `MRB_TT_HAS_BASIC` is
no longer used with `MRB_WORD_BOXING` at b2c3d88f.
2019-09-25 18:17:01 +09:00
Yukihiro "Matz" Matsumoto 3c1a2612e7 Merge pull request #4727 from shuujii/exception-initialize-should-not-allow-two-or-more-arguments
`Exception#initialize` should not allow two or more arguments
2019-09-24 23:01:13 +09:00
KOBAYASHI Shuji 07856a7e8f Exception#initialize should not allow two or more arguments 2019-09-24 21:43:46 +09:00
Yukihiro "Matz" Matsumoto 4f0f712b51 Merge pull request #4726 from shuujii/fix-Fixnum-overflow-test-in-Integer-lshift-test
Fix `Fixnum` overflow test in `Integer#<<` test
2019-09-23 23:27:15 +09:00
KOBAYASHI Shuji 549317a36b Fix Fixnum overflow test in Integer#<< test
- Skip when `MRB_WITHOUT_FLOAT` is defined.
- Make `Fixnum` overflow even when `MRB_INT64` is defined.
2019-09-23 21:59:35 +09:00
Yukihiro "Matz" Matsumoto a4f2e1276c Merge pull request #4725 from shuujii/implement-all-type-predicate-macros-for-MRB_WORD_BOXING
Implement all type predicate macros for `MRB_WORD_BOXING`
2019-09-23 03:30:24 +09:00
KOBAYASHI Shuji 5dda4f5da3 Implement all type predicate macros for MRB_WORD_BOXING
The default implementations of type predicate macros use `mrb_type`.
But `mrb_type` with `MRB_WORD_BOXING` isn't very efficient, so the new
implementations avoid `mrb_type`.
2019-09-22 22:36:12 +09:00
Yukihiro "Matz" Matsumoto 046b116c18 Merge pull request #4716 from MaskRay/rodata
Rename MRB_USE_ETEXT_EDATA to MRB_USE_LINK_TIME_RO_DATA_P and support lld linked programs
2019-09-22 17:00:49 +09:00
Fangrui Song 7f044341f9 Rename MRB_USE_ETEXT_EDATA to MRB_USE_LINK_TIME_RO_DATA_P and support lld linked programs
In lld linked programs, .rodata comes before .text, thus mrb_ro_data_p
will return false for strings in .rodata. Change the lower bound from
_etext to __ehdr_start to catch these cases. This works for ld.bfd, gold
and lld, and it does not have false positives even if .init_array does
not exist.

Remove the branch that uses _edata: strings in .data can be modified so
this is semantically incorrect. Delete the __APPLE__ branch (its
manpages say get_etext() and get_edata() are strongly discouraged).
.init_array has been adopted by most ELF platforms to supersede .ctors.

Neither _etext nor _edata is used, so rename MRB_USE_ETEXT_EDATA to
MRB_USE_EHDR_START.
2019-09-21 17:55:14 -07:00
Yukihiro "Matz" Matsumoto 8db7dfb5c4 Merge pull request #4724 from shuujii/use-mrb_define_method-instead-of-mrb_define_alias
Use `mrb_define_method` instead of `mrb_define_alias`
2019-09-21 17:50:21 +09:00
KOBAYASHI Shuji f252ab0770 Use mrb_define_method instead of mrb_define_alias 2019-09-21 16:51:10 +09:00
Yukihiro "Matz" Matsumoto 15701a32f5 Fix compatibility issue of class variables.
Singleton class definition do not introduce its own class variable scope
in CRuby/JRuby. So should mruby.

```
module Mod1
  class << Object.new

    C = 1
    @@cv = 1

    p Module.nesting,        # => [#<Class:#<Object:0x55cb16e60a50>>, Mod1]
      constants,             # => [:C]
      class_variables,       # => []
      Mod1.class_variables   # => [:@@cv]
  end
end
```
2019-09-20 13:07:58 +09:00
Yukihiro "Matz" Matsumoto 683baec4f0 Add optional argument to Module#class_variables. 2019-09-20 13:07:58 +09:00
Yukihiro "Matz" Matsumoto 01ce5824f0 Merge pull request #4723 from shuujii/fix-typo-in-Array-difference-document
Fix typo in `Array#difference` document [ci skip]
2019-09-20 09:46:19 +09:00
KOBAYASHI Shuji 1fb4e73981 Fix typo in Array#difference document [ci skip] 2019-09-20 09:28:56 +09:00
Yukihiro "Matz" Matsumoto 21c0c78d2e Merge pull request #4722 from shuujii/simplify-arguments-check-in-String-index
Simplify arguments check in `String#index`
2019-09-20 08:02:14 +09:00
KOBAYASHI Shuji e61095426b Simplify arguments check in String#index
Also fix document about type of the first argument.
2019-09-19 20:19:38 +09:00
Yukihiro "Matz" Matsumoto 77f00d5006 Merge pull request #4720 from shuujii/fix-Enumerable-filter_map-without-block
Fix `Enumerable#filter_map` without block; ref d380c7d2
2019-09-18 21:52:28 +09:00
KOBAYASHI Shuji c7c344dbc2 Fix Enumerable#filter_map without block; ref d380c7d2 2019-09-18 19:33:15 +09:00
Yukihiro "Matz" Matsumoto c20dda4f4c Merge pull request #4719 from shuujii/remove-unneeded-mrb_get_args
Remove `mrb_get_args(mrb, "")`; ref 30f37872
2019-09-18 17:14:00 +09:00
KOBAYASHI Shuji 0bedd900b9 Remove mrb_get_args(mrb, ""); ref 30f37872 2019-09-18 16:07:21 +09:00
Yukihiro "Matz" Matsumoto ca2d47c20f Fix super from aliased methods to work correctly; fix #4718
We needed to preserve the original method name somewhere. We kept it in
the `env` structure pointed from aliased methods. #1457 and #1531 tried
to address this issue. But this patch is more memory efficient.

Limitation: this fix does not support `super` from methods defined by
`define_method`. This limitation may be addressed in the future, but
it's low priority.
2019-09-18 10:31:28 +09:00
Yukihiro "Matz" Matsumoto 47add060cc Merge pull request #4717 from shuujii/fix-Fixnum-to_s-inspect-argument-specs
Fix `Fixnum#(to_s|inspect)` argument specs
2019-09-17 13:39:51 +09:00
KOBAYASHI Shuji 2f7175442f Fix Fixnum#(to_s|inspect) argument specs
Before this patch:

  $ bin/mruby -e 'p 3.to_s(2)'
  trace (most recent call last):
    [0] -e:1
  -e:1: 'to_s': wrong number of arguments (1 for 0) (ArgumentError)

After this patch:

  $ bin/mruby -e 'p 3.to_s(2)'
  "11"
2019-09-17 09:28:51 +09:00
Yukihiro "Matz" Matsumoto 88cd1d6593 Merge pull request #4714 from dearblue/shrink-mrb_get_args
Shrink `mrb_get_args()`
2019-09-17 08:41:51 +09:00
Yukihiro "Matz" Matsumoto cc636f334f Merge pull request #4715 from dearblue/need-block
Entrust "no block given" error to `mrb_get_args()`
2019-09-17 08:40:03 +09:00
Yukihiro "Matz" Matsumoto d45c94fe1c Merge pull request #4713 from shuujii/fix-argument-specs-to-Enumerable
Fix argument specs to `Enumerable`
2019-09-17 08:31:18 +09:00
dearblue 099a4f3969 Entrust "no block given" error to mrb_get_args()
Some error messages will be changed.
2019-09-16 20:29:58 +09:00
dearblue 62499c6250 Shrink mrb_get_args()
As a side effect, all specifiers now accept the `!` modifier.
2019-09-16 18:14:00 +09:00
dearblue f312638ecd Cache argv first in each specifiers for mrb_get_args(); ref #3090
In terms of specifiers, argv is never referenced after a method call as
shown in #3090.

Reduction of object code can be expected.

If you need to refer to argv after a method call in the same loop,
update argv after the method call.
2019-09-16 18:14:00 +09:00
Yukihiro "Matz" Matsumoto 2f9b1fdb0c Merge pull request #4255 from shuujii/enumerator-size-is-not-supported
`Enumerator#size` is not supported [ci skip]
2019-09-16 15:37:58 +09:00
KOBAYASHI Shuji b3b55132a9 Fix argument specs to Enumerable 2019-09-16 11:58:35 +09:00
Yukihiro "Matz" Matsumoto 2256bb07b0 Remove MRB_METHOD_TABLE_INLINE.
`MRB_METHOD_TABLE_INLINE` was fragile. It requires `-falign-functions=n`.
On platform that uses higher bits of function pointers, you can use new
`MRB_METHOD_T_STRUCT` configuration macro.
2019-09-16 11:14:13 +09:00
Yukihiro "Matz" Matsumoto 30f3787248 Raise ArgumentError by aspec check; ref #4688
This is partial `aspec` check that only checks `MRB_ARGS_NONE()`.
2019-09-16 10:50:31 +09:00
Yukihiro "Matz" Matsumoto 2764fdf9f0 Share common definition of MRB_METHOD_FUNC_FL. 2019-09-16 10:10:09 +09:00
Yukihiro "Matz" Matsumoto 0eb9355acd Use bit shifting to pack function pointers to mrb_method_t.
So you don't need `-falign-functions=2` anymore. Instead your platform
must not use higher bits of the pointer (true for most platforms).
If not, you have to use `struct mrb_method_t` version.
2019-09-16 10:10:09 +09:00
Yukihiro "Matz" Matsumoto 743d480fba Refactor mrb_method_t. 2019-09-16 10:10:09 +09:00
Yukihiro "Matz" Matsumoto a57b6f8ed0 Implement Enumerable tally from Ruby2.7. 2019-09-16 10:10:09 +09:00
Yukihiro "Matz" Matsumoto d380c7d26f Implement filter_map from Ruby2.6. 2019-09-16 10:10:09 +09:00
Yukihiro "Matz" Matsumoto 57a0132b41 Add filter aliases for Enumerable and Hash. 2019-09-16 10:10:09 +09:00
Yukihiro "Matz" Matsumoto f4117d81d2 Add Array#difference method from Ruby2.6. 2019-09-16 10:10:09 +09:00
Yukihiro "Matz" Matsumoto 3daa53ce63 Implement bind_call method from Ruby2.7. 2019-09-16 10:10:09 +09:00
Yukihiro "Matz" Matsumoto a016d1d0ff Merge branch 'dearblue-mruby-io' 2019-09-16 07:45:42 +09:00
Yukihiro "Matz" Matsumoto 6de1c64a9c Add small fix over #4712 2019-09-16 07:44:51 +09:00
dearblue 992ba476a9 Fix broken UTF-8 characters by IO#getc
Character (multi-byte UTF-8) is destroyed when character spanning
`IO::BUF_SIZE` (4096 bytes) exist.

- Prepare file:

  ```ruby
  File.open("sample", "wb") { |f| f << "●" * 1370 }
  ```

- Before patched:

  ```ruby
  File.open("sample") { |f| a = []; while ch = f.getc; a << ch; end; p a }
  # => ["●", "●", ..., "●", "\xe2", "\x97", "\x8f", "●", "●", "●", "●"]

- After patched:

  ```ruby
  File.open("sample") { |f| a = []; while ch = f.getc; a << ch; end; p a }
  # => ["●", "●", ..., "●", "●", "●", "●", "●", "●"]
2019-09-16 00:26:41 +09:00
dearblue 7cc8c7d2ff Small improvement for mruby-io 2019-09-16 00:11:43 +09:00
dearblue 52a0ad4108 Fix IO#pos 2019-09-16 00:11:43 +09:00
dearblue 77368ce762 Revert part of 8c90b5fc6
`IO#readline` and `IO#readchar` process in character units.
2019-09-16 00:11:43 +09:00
Yukihiro "Matz" Matsumoto 0734d9f314 Merge pull request #4512 from lopopolo/patch-1
Support parsing a Regexp literal with 'o' option
2019-09-15 18:19:59 +09:00
Yukihiro "Matz" Matsumoto e790fb5128 Merge pull request #4710 from shuujii/refactor-mrb_type-in-include-mruby-boxing_word.h
Refactor `mrb_type` in `include/mruby/boxing_word.h`
2019-09-15 18:19:27 +09:00
KOBAYASHI Shuji 7fcda585bc Refactor mrb_type in include/mruby/boxing_word.h 2019-09-15 18:11:16 +09:00
Yukihiro "Matz" Matsumoto 76355dee68 Add unavailability of declaration form of visibility methods; #4708 2019-09-14 23:21:44 +09:00
Yukihiro "Matz" Matsumoto 28bbd3e7d9 Add argument names to C function prototypes. 2019-09-14 23:21:44 +09:00
Yukihiro "Matz" Matsumoto 57d7fe94a9 Add a macro mrb_frozen_p that points to MRB_FROZEN_P. 2019-09-14 23:21:44 +09:00
Yukihiro "Matz" Matsumoto 6f1c08f7d8 Replace String#byteslice by custom IO._bufread.
`byteslice` creates 2 string objects. `_bufread` creates one, and
modifies the original buffer string, that is more efficient.
2019-09-14 23:21:44 +09:00
Yukihiro "Matz" Matsumoto dcc2d44d93 Merge pull request #4707 from shuujii/use-%C-to-mrb_name_error-in-mrb_method_search
Use `%C` to `mrb_name_error` in `mrb_method_search`; ref 5890c7d5
2019-09-14 14:35:36 +09:00
KOBAYASHI Shuji 2f74a97d04 Use %C to mrb_name_error in mrb_method_search; ref 5890c7d5 2019-09-14 11:28:02 +09:00
Yukihiro "Matz" Matsumoto 6620b1cdcb Revert "Update %pure-parser to %define api.pure for newer bison; fix #4706"
The `bison` on MacOS does not support `%define api.pure`.
This reverts commit f7c9f1f796.
2019-09-14 10:28:07 +09:00
Yukihiro "Matz" Matsumoto f7c9f1f796 Update %pure-parser to %define api.pure for newer bison; fix #4706 2019-09-14 09:05:32 +09:00
Yukihiro "Matz" Matsumoto 76f1aa7de5 Remove mrb_funcall from <=> operations. 2019-09-14 09:05:32 +09:00
Yukihiro "Matz" Matsumoto fcd3f8450d Raise an error from String#<=> with a non string operand. 2019-09-14 09:05:32 +09:00
Yukihiro "Matz" Matsumoto 34cdff5ee4 Use mrb_equal instead of mrb_funcall.
In the typical case, `mrb_funcall` invocation would be skipped.
2019-09-14 09:05:32 +09:00
Yukihiro "Matz" Matsumoto 5890c7d516 Remove mrb_funcall from mrb_method_search. 2019-09-14 09:05:32 +09:00
Yukihiro "Matz" Matsumoto 2fa4a55e80 Replace loop method with while true loop to gain performance. 2019-09-14 09:05:32 +09:00
Yukihiro "Matz" Matsumoto 5489fae8f2 Merge pull request #4705 from shuujii/revert-part-of-Refine-tasks-toolchains-gcc-clang.rake
Revert part of "Refine `tasks/toolchains/(gcc|clang).rake`" (07c6b7f0)
2019-09-13 22:55:50 +09:00
KOBAYASHI Shuji 895ab2342e Revert part of "Refine tasks/toolchains/(gcc|clang).rake" (07c6b7f0)
`-Wzero-length-array` is not a mandatory option, so the original is better.
2019-09-13 21:28:23 +09:00
Yukihiro "Matz" Matsumoto 1e82b1958b Merge pull request #4704 from shuujii/fix-warnings-for-invalid-C++-option-with-enable_cxx_abi
Fix warnings for invalid C++ option with `enable_cxx_abi`; ref #3618, #4703
2019-09-13 19:59:40 +09:00
KOBAYASHI Shuji be76cec342 Fix warnings for invalid C++ option with enable_cxx_abi; ref #3618, #4703 2019-09-13 17:14:37 +09:00
Yukihiro "Matz" Matsumoto ad4bdda074 Update assert_take for zero size take. 2019-09-13 02:28:56 +09:00
Yukihiro "Matz" Matsumoto f5542b9927 Add Enumerator.produce from Ruby2.7 2019-09-13 02:28:56 +09:00
Yukihiro "Matz" Matsumoto d4af765651 Remove -std=gnu99 when enable_cxx_abi; ref #4703
To stop warnings since C++ do not accept `-std=gnu99` option.
2019-09-13 02:23:16 +09:00
Yukihiro "Matz" Matsumoto 5a0204bb45 Remove unnecessary files from mruby-{io,pack,socket}. 2019-09-13 02:23:16 +09:00
Yukihiro "Matz" Matsumoto 915bb4e206 Merge pull request #4703 from shuujii/refine-tasks-toolchains-gcc-clang.rake
Refine `tasks/toolchains/(gcc|clang).rake`
2019-09-12 22:53:47 +09:00
KOBAYASHI Shuji 07c6b7f0ab Refine tasks/toolchains/(gcc|clang).rake
- Make sure to specify `-std=gnu99` for C compiler flag.
- Make sure to specify `-Wzero-length-array` for C/C++ compiler flag (Clang).
- Extract similar codes.
2019-09-12 21:45:47 +09:00
Yukihiro "Matz" Matsumoto 231a1d68b0 Remove $/ from mruby implementation.
1. `$/` and other Perl-ish global variables are not defined in ISO.
2. The current Ruby policy do not encourage those variables.
3. Those variables has global effect and can cause troubles.
2019-09-12 21:22:59 +09:00
Yukihiro "Matz" Matsumoto 6bbdb97e75 Merge pull request #4527 from lopopolo/string-each-line-paragraph-mode
Add paragraph mode to String#each_line in mrblib
2019-09-12 21:19:42 +09:00
Yukihiro "Matz" Matsumoto b98bf36a15 Use mrb_str_inspect instead of mrb_str_dup; fix #4678 2019-09-12 17:15:55 +09:00
Yukihiro "Matz" Matsumoto 9383e9d469 Removed unnecessary files from mruby-sleep; #4702 2019-09-12 06:54:09 +09:00
Yukihiro "Matz" Matsumoto 13c3802073 Remove Rakefile from mruby-sleep gem; fix #4702
The `Rakefile` was a leftover from the time it was an independent gem.
2019-09-11 20:28:52 +09:00
Yukihiro "Matz" Matsumoto 04b098d000 Move tests related to getbyte, setbyte, byteslice` to core. 2019-09-11 18:49:08 +09:00
Yukihiro "Matz" Matsumoto 8c90b5fc6a Fixed length for IO should be in bytes, not in characters; #4696
E.g. `io.read(5)` should read 5 byte string, not 5 characters.
2019-09-11 18:47:39 +09:00
Yukihiro "Matz" Matsumoto ec3aeede20 Move String#{getbyte,setbyte,byteslice} to the core; #4696
Unlike CRuby, there's no way to process strings byte-wise by core
methods because there's no per string encoding in mruby, so that
we moved 3 byte-wise operation methods from `mruby-string-ext` gem.
2019-09-11 18:47:39 +09:00
Yukihiro "Matz" Matsumoto 08d4e7c0c4 Merge pull request #4701 from shuujii/drop-test-dependency-from-mruby-string-ext-to-mruby-enumerator
Drop test dependency from `mruby-string-ext` to `mruby-enumerator`
2019-09-11 18:47:27 +09:00
KOBAYASHI Shuji fab781cf8b Drop test dependency from mruby-string-ext to mruby-enumerator 2019-09-11 10:35:52 +09:00
Yukihiro "Matz" Matsumoto 896f3fe703 Merge pull request #4700 from shuujii/refine-documentation-for-C99-compliance
Refine documentation for C99 compliance; ref #4685 [ci skip]
2019-09-10 17:00:29 +09:00
KOBAYASHI Shuji 1c1ebb1833 Refine documentation for C99 compliance; ref #4685 [ci skip]
The refinement was based on comment from @matz.
2019-09-10 16:49:14 +09:00
Yukihiro "Matz" Matsumoto 080f7baeaf Merge pull request #4699 from takkaw/mirb_lv_under_score
add special local variable _ in mirb
2019-09-10 09:24:27 +09:00
takkaw 3f70e3a81f change _ variable in mirb to be enable by default 2019-09-09 23:40:51 +09:00
Yukihiro "Matz" Matsumoto 9d9cb0ab6a Fix mod.constants not to have duplicate constant names; #4698
The fix was based on PR from @dearblue
2019-09-09 23:14:07 +09:00
Yukihiro "Matz" Matsumoto a1a838d966 Remove duplication of BasicObject constant; fix #4698 2019-09-09 23:14:07 +09:00
Yukihiro "Matz" Matsumoto 6b157397ba Merge pull request #4697 from shuujii/fix-Class.new-argument-specs
Fix `Class.new` argument specs
2019-09-09 22:51:15 +09:00
takkaw e28451585d add special local variable _ in mirb 2019-09-09 22:32:10 +09:00
KOBAYASHI Shuji b156aa2cf6 Fix Class.new argument specs 2019-09-09 21:37:35 +09:00
Yukihiro "Matz" Matsumoto 715afd6fdb Merge pull request #4695 from dearblue/promote-to-int
Fix `mrb_vformat()` crashes with `MRB_INT16`
2019-09-08 22:46:25 +09:00
Yukihiro "Matz" Matsumoto 801343b56b Merge pull request #4694 from shuujii/optimize-mrb_bool-with-MRB_WORD_BOXING
Optimize `mrb_bool()` with `MRB_WORD_BOXING`
2019-09-08 22:44:07 +09:00
dearblue 311d867deb Fix mrb_vformat() crashes with MRB_INT16
If `MRB_INT16` is specified, the variable length argument `mrb_int` is
converted to `int`.
2019-09-08 20:31:35 +09:00
KOBAYASHI Shuji d47bd0a2cd Optimize mrb_bool() with MRB_WORD_BOXING 2019-09-08 12:17:25 +09:00
Yukihiro "Matz" Matsumoto 9d08025b8b Revert part of #4225
Since in mruby, Integer and Float interchange frequently (mostly on
overflow), so adding explicit `.0` can cause problems sometimes.

For example:
https://github.com/mattn/mruby-json/pull/40
https://github.com/pepabo/mruby-msd/pull/13
https://github.com/mattn/mruby-json/pull/42
2019-09-07 22:27:30 +09:00
Yukihiro "Matz" Matsumoto 8f04d6561f Merge pull request #4693 from shuujii/increase-symbol-bit-size-on-32-bit-mode-with-MRB_WORD_BOXING
Increase symbol bit size on 32-bit mode with `MRB_WORD_BOXING`
2019-09-07 22:16:54 +09:00
KOBAYASHI Shuji 17c53040ab Increase symbol bit size on 32-bit mode with MRB_WORD_BOXING
This change increases the max length of lower inline symbols to 5 bytes.
2019-09-07 21:38:11 +09:00
Yukihiro "Matz" Matsumoto bb7eccc9c4 Merge pull request #4692 from shuujii/avoid-bit-fields-in-mrb_value
Avoid bit fields in `mrb_value`; ref b2c3d88f
2019-09-06 22:23:16 +09:00
KOBAYASHI Shuji 19e2cc187b Avoid bit fields in mrb_value; ref b2c3d88f
The changes at b2c3d88f were inappropriate because the memory layout of bit
fields are implementation defined. Therefor, I fixed it not to use bit
fields.
2019-09-06 13:24:35 +09:00
Yukihiro "Matz" Matsumoto c3b16c26a6 Merge pull request #4691 from shuujii/fix-Range-max-test-TypeError-is-raised-on-32-bit-mode-with-word-boxing
Fix `Range#max` test (`TypeError` is raised) on 32-bit mode with word boxing
2019-09-05 23:02:53 +09:00
Yukihiro "Matz" Matsumoto 968547d79b Merge pull request #4690 from takumakume/add_assert_not_nil
Add `assert_not_nil` method
2019-09-05 22:59:34 +09:00
takumakume 6c4278144a add assert_not_nil method 2019-09-05 19:51:54 +09:00
KOBAYASHI Shuji 6cfcff6f10 Fix Range#max test (TypeError is raised) on 32-bit mode with word boxing 2019-09-05 19:51:32 +09:00
Yukihiro "Matz" Matsumoto be8bb2be61 Merge pull request #4687 from shuujii/fix-argument-specs-to-BasicObject
Fix argument specs to `BasicObject`
2019-09-05 11:15:34 +09:00
KOBAYASHI Shuji 489f655d18 Fix argument specs to BasicObject 2019-09-04 22:49:57 +09:00
Yukihiro "Matz" Matsumoto 2df419e324 Merge pull request #4686 from shuujii/add-to-doc-limitations.md-about-nil-redefinition
Add to `doc/limitations.md` about `nil?` redefinition; ref 4996709 [ci skip]
2019-09-04 01:25:00 +09:00
KOBAYASHI Shuji 74e7c4aa0b Add to doc/limitations.md about nil? redefinition; ref 4996709 [ci skip] 2019-09-03 21:51:15 +09:00
Yukihiro "Matz" Matsumoto 148fffa21a Merge pull request #4683 from shuujii/enumeratorChain-rewind-shouldnt-rewind-elements-arent-iterated
`Enumerator::Chain#rewind` shouldn't rewind elements aren't iterated
2019-09-02 16:50:47 +09:00
KOBAYASHI Shuji 66211394e1 Enumerator::Chain#rewind shouldn't rewind elements aren't iterated
### Example:

  ```ruby
  # example.rb
  e = [1]
  def e.rewind; p :r end
  c = e.chain(e)
  c.each{break c}.rewind
  ```

#### Before this patch:

  ```terminal
  $ bin/mruby example.rb
  :r
  :r
  ```

#### After this patch (same as Ruby):

  ```terminal
  $ bin/mruby example.rb
  :r
  ```
2019-09-02 08:58:33 +09:00
Yukihiro "Matz" Matsumoto aea5880c10 Small refactoring in fiber.c. 2019-09-02 08:41:44 +09:00
Yukihiro "Matz" Matsumoto 5cd52d2d69 Fix an error in refactoring; fix #4682 2019-09-02 08:41:44 +09:00
Yukihiro "Matz" Matsumoto e8de7c6819 Merge pull request #4681 from shuujii/array-permutation-with-a-negative-argument-should-not-yield
`Array#permutation` with a negative argument should not yield
2019-09-01 13:01:59 +09:00
KOBAYASHI Shuji fe6cf851bf Array#permutation with a negative argument should not yield
Before this patch:

  $ bin/mruby -e '[1].permutation(-1){|v| p v}'  #=> [1]

After this patch (same as Ruby):

  $ bin/mruby -e '[1].permutation(-1){|v| p v}'  #=> no output
2019-09-01 09:28:11 +09:00
Yukihiro "Matz" Matsumoto 1a4ea94bc7 Fix mrb_immediate_p(MRB_TT_FREE) to return false; ref #4679 2019-08-31 23:19:08 +09:00
Yukihiro "Matz" Matsumoto d48a2190bf Refactor #4662 with different names. 2019-08-31 22:14:25 +09:00
Yukihiro "Matz" Matsumoto 49967097ed Skip nil? method call in if conditionals.
Compile `if expr.nil?` to use `OP_JMPNIL` instead of calls.
2019-08-31 22:14:25 +09:00
Yukihiro "Matz" Matsumoto 49896abe2b Merge pull request #4679 from shuujii/implement-mrb_immediate_p-macro-for-MRB_WORD_BOXING
Implement `mrb_immediate_p` macro for `MRB_WORD_BOXING`
2019-08-31 22:14:14 +09:00
KOBAYASHI Shuji b2c3d88fbf Implement mrb_immediate_p macro for MRB_WORD_BOXING
The default implementation of `mrb_immediate_p` uses `mrb_type`. However,
in `MRB_WORD_BOXING`, `mrb_type` has many branches and is inefficient, so
provide an implementation that does not use `mrb_type`.
2019-08-31 16:55:57 +09:00
Yukihiro "Matz" Matsumoto 55ef4e4bdd Merge pull request #4677 from shuujii/array-permutation-combination-without-block-should-return-self
`Array#(permutation|combination)` without block should return `self`
2019-08-30 22:38:15 +09:00
KOBAYASHI Shuji 28d1f6cdc4 Array#(permutation|combination) without block should return self 2019-08-30 17:04:25 +09:00
Yukihiro "Matz" Matsumoto 0ce1878aba Merge pull request #4674 from shuujii/remove-unneeded--src-y.tab.c-in-.gitignore
Remove unneeded `/src/y.tab.c` in `.gitignore`
2019-08-29 16:24:48 +09:00
KOBAYASHI Shuji d9614549bb Remove unneeded /src/y.tab.c in .gitignore
Currently, `y.tab.c` is generated to under the `build/` directory.
2019-08-29 14:05:53 +09:00
Yukihiro "Matz" Matsumoto aa97b8a4fe Merge pull request #4672 from shuujii/fix-build-of-mruby-random-on-32-bit-mode
Fix build of `mruby-random` on 32-bit mode
2019-08-27 15:03:47 +09:00
KOBAYASHI Shuji 7993b87235 Fix build of mruby-random on 32-bit mode 2019-08-27 10:48:25 +09:00
Yukihiro "Matz" Matsumoto c1cd2007b8 Merge pull request #4671 from shuujii/fix-Array-sample-with-MRB_INT32
Fix `Array#sample` with `MRB_INT32`
2019-08-26 22:18:36 +09:00
KOBAYASHI Shuji 7178a5e7d3 Fix Array#sample with MRB_INT32
Array index became potentially negative because `uint32_t` is cast to
`mrb_int`.
2019-08-26 20:23:46 +09:00
Yukihiro "Matz" Matsumoto 4aabf91ee2 Merge pull request #4635 from shuujii/fix-wrong-argument-for-fprintf-in-mruby-bin-mrbc
Fix wrong argument for `fprintf` in `mruby-bin-mrbc`
2019-08-26 19:18:49 +09:00
Yukihiro "Matz" Matsumoto cd96998372 Merge pull request #4670 from shuujii/remove-unused-random.h
Remove unused `random.h`
2019-08-26 19:17:38 +09:00
KOBAYASHI Shuji b9350f908f Remove unused random.h 2019-08-26 18:08:32 +09:00
Yukihiro "Matz" Matsumoto 2d09fd2135 Merge pull request #4669 from davidsiaw/doxygen
Fixes for Doxygen docs
2019-08-26 07:46:57 +09:00
David Siaw 6375639917 fix lots of warnings and make logo not so big 2019-08-26 02:08:33 +09:00
David Siaw e1e96c0cf4 change doc directory and reduce warnings 2019-08-26 00:23:28 +09:00
Yukihiro "Matz" Matsumoto a4870a579f Merge pull request #4668 from shuujii/defer-several-build-libraries-loading-until-needed
Defer several build libraries loading until needed
2019-08-25 17:56:03 +09:00
KOBAYASHI Shuji 3110d84ed8 Defer several build libraries loading until needed 2019-08-25 09:48:07 +09:00
Yukihiro "Matz" Matsumoto e3f7429173 Merge pull request #4667 from shuujii/fix-Range-max-test-TypeError-is-raised-on-32-bit-mode
Fix `Range#max` test (`TypeError` is raised) on 32-bit mode
2019-08-25 01:30:45 +09:00
Yukihiro "Matz" Matsumoto ee0806ad4b Merge pull request #4666 from dearblue/warn-str_new_capa
Suppress warning by gcc with `-Wmaybe-uninitialized`
2019-08-25 01:29:49 +09:00
Yukihiro "Matz" Matsumoto 17623fd0d3 Merge pull request #4665 from dearblue/fix-4642
Create a symbolic link in the temporary directory; fix #4642
2019-08-25 01:28:14 +09:00
Yukihiro "Matz" Matsumoto ce89974679 Merge pull request #4664 from shuujii/remove-unused-constant-in-Rakefile
Remove unused constant in `Rakefile`; ref e312842a
2019-08-25 01:25:32 +09:00
KOBAYASHI Shuji 13f58f9bc2 Fix Range#max test (TypeError is raised) on 32-bit mode 2019-08-24 14:22:10 +09:00
dearblue c9c27e9d69 Suppress warning by gcc with -Wmaybe-uninitialized 2019-08-24 11:44:51 +09:00
KOBAYASHI Shuji e7b49e3f09 Remove unused constant in Rakefile; ref e312842a 2019-08-24 11:30:03 +09:00
dearblue 6ad2442fb9 Create a symbolic link in the temporary directory; fix #4642
Because the linker gives a warning on FreeBSD 12.0.

```
warning: mktemp() possibly used unsafely; consider using mkstemp()
```
2019-08-24 11:11:00 +09:00
Yukihiro "Matz" Matsumoto 71242c0f2e Merge pull request #4662 from shuujii/fix-RBreak-exceeding-6-words-on-32-bit-mode-w-o-boxing-and-MRB_USE_FLOAT
Fix `RBreak` exceeding 6 words on 32-bit mode w/o boxing and `MRB_USE_FLOAT`
2019-08-23 22:35:28 +09:00
KOBAYASHI Shuji be78b5d8f7 Fix RBreak exceeding 6 words on 32-bit mode w/o boxing and MRB_USE_FLOAT
ref: https://github.com/mruby/mruby/pull/4483#issuecomment-498001736

In this configuration, `tt` of `RBreak::val` is set into `RBreak::flags`.
2019-08-23 22:15:42 +09:00
Yukihiro "Matz" Matsumoto 14d5a86b29 Merge pull request #4656 from shuujii/refine-processing-for-gem-lock-file
Refine processing for gem lock file
2019-08-23 05:46:20 +09:00
KOBAYASHI Shuji e312842a18 Refine processing for gem lock file
- Defer YAML library and lock file loading until needed.
- Don't write empty parts into lock file.
- Extract code to read/write lock file to `MRuby::Lockfile`.
- `MRuby::Lockfile.disable` disables the use of lock file.
2019-08-22 21:40:01 +09:00
Yukihiro "Matz" Matsumoto 246179518d Merge pull request #4655 from yamori813/master
make clean error workaround
2019-08-22 13:50:28 +09:00
yamori813 07b2d33347 workaround error 2019-08-22 10:59:46 +09:00
Yukihiro "Matz" Matsumoto 3ad58f4dae Add lock files to .gitignore; #4180 2019-08-22 08:16:51 +09:00
Yukihiro "Matz" Matsumoto ef46fb4840 Merge pull request #4654 from take-cheeze/mruby_version_lock
Take commit hash of mruby too
2019-08-22 08:07:30 +09:00
Yukihiro "Matz" Matsumoto 2aa22206be Merge pull request #4653 from take-cheeze/sep_repo_build
Separate repos directory and build directory
2019-08-22 08:06:47 +09:00
take-cheeze 8e7a3a4df1 Take commit hash of mruby too 2019-08-22 03:03:24 +09:00
take-cheeze a86f8f26a2 Separate repos directory and build directory
closes #4652
2019-08-22 02:43:00 +09:00
Yukihiro "Matz" Matsumoto 90bffaa2a6 Merge pull request #4180 from take-cheeze/lock_file
Support lock file for git.
2019-08-21 17:17:30 +09:00
Yukihiro "Matz" Matsumoto 4c8e6daab7 Merge pull request #4651 from shuujii/prioritize-embedded-string-over-nofree-or-normal-string
Prioritize embedded string over nofree (or normal) string
2019-08-21 12:39:59 +09:00
KOBAYASHI Shuji a84ab12735 Prioritize embedded string over nofree (or normal) string
Prioritize embedded string in the following functions:

- `str_new_static`
- `str_new`
- `mrb_str_new_capa`
- `mrb_str_pool`

The reasons are as follows:

- Consistency with `mrb_str_byte_subseq` and `str_replace`.
- Memory locality increases and may be slightly faster.
- No conversion cost to embedded string when modifying the string.
2019-08-21 12:06:03 +09:00
Yukihiro "Matz" Matsumoto def7925873 Merge pull request #4650 from take-cheeze/patch-5
Remove deprecated iij stuffs
2019-08-21 07:10:08 +09:00
Yukihiro "Matz" Matsumoto 55ac140c25 Merge pull request #4649 from take-cheeze/patch-4
Fix link of mruby-io
2019-08-21 07:09:32 +09:00
Yukihiro "Matz" Matsumoto 392f8f840d Merge pull request #4648 from take-cheeze/patch-3
Use mruby-onig-regexp instead in example
2019-08-21 07:08:56 +09:00
Yukihiro "Matz" Matsumoto f563cc227b Merge pull request #4647 from take-cheeze/patch-2
Add note about checksum_hash in mrbgem doc
2019-08-21 07:08:08 +09:00
Takeshi Watanabe fd4db7e6dd Remove deprecated iij stuffs 2019-08-20 23:56:10 +09:00
Takeshi Watanabe 2e172fd932 Fix link of mruby-io 2019-08-20 23:54:36 +09:00
Takeshi Watanabe c138b9ea30 Use mruby-onig-regexp instead in example 2019-08-20 23:52:21 +09:00
Takeshi Watanabe 3256fae147 Add note about checksum_hash in mrbgem doc 2019-08-20 23:50:16 +09:00
Yukihiro "Matz" Matsumoto 4c001673b6 Avoid C++ strict aliasing warning.
Based on code proposed by @dearblue to avoid the warning:
`dereferencing type-punned pointer will break strict-aliasing rules`.
2019-08-20 22:50:21 +09:00
Yukihiro "Matz" Matsumoto 183fb961b3 Fixed a bug in the OP_JMPNOT optimization (13eaff4); fix #4644 2019-08-20 22:01:50 +09:00
Yukihiro "Matz" Matsumoto 942c076938 Merge pull request #4646 from shuujii/use-RBasic-padding-for-embedded-string-on-64-bit-CPU
Use `RBasic` padding for embedded string on 64-bit CPU
2019-08-20 22:00:54 +09:00
KOBAYASHI Shuji 8157672a29 Use RBasic padding for embedded string on 64-bit CPU
On 64-bit CPU, there is padding in `RBasic`, so reorder the fields and use
it as buffer of embedded string. This change allows 4 more bytes to be
embedded on 64-bit CPU.

However, an incompatibility will occur if `RString::as::ary` is accessed
directly because `RString` structure has changed.
2019-08-20 18:49:55 +09:00
Yukihiro "Matz" Matsumoto b836fd05dd Merge pull request #4645 from shuujii/move-mrb_str_pool-to-src-string.c-to-use-str_init-family
Move `mrb_str_pool` to `src/string.c` to use `str_init` family
2019-08-19 21:29:38 +09:00
KOBAYASHI Shuji 507dbf984e Move mrb_str_pool to src/string.c to use str_init family 2019-08-19 19:18:52 +09:00
Yukihiro "Matz" Matsumoto 1961059330 Merge pull request #4643 from lopopolo/externally-define-MRB_API
Allow external definition of MRB_API macro
2019-08-19 13:18:41 +09:00
Ryan Lopopolo b5662c87c8 Allow external definition of MRB_API macro
When building WebAssembly targets with clang (e.g. wasm32-unknown-unknown), all
symbols are hidden by default. To export a symbol, it must be marked with

    __attribute__((visibility(default)))

Rather than detecting this exotic target in mruby, allow MRB_API to be defined
externally.
2019-08-18 19:40:12 -07:00
Yukihiro "Matz" Matsumoto 3fbd5f0029 Merge pull request #4639 from dearblue/suppress-Wstringop-truncation
Suppress warnings for `strncat()`
2019-08-19 07:31:26 +09:00
Yukihiro "Matz" Matsumoto f263088b0d Merge pull request #4638 from dearblue/simplify-get-args
Simplify get arguments
2019-08-19 07:30:48 +09:00
Yukihiro "Matz" Matsumoto b5e2d208b9 Merge pull request #4636 from davidsiaw/doxygen
Generate doxygen docs for mruby
2019-08-19 07:29:46 +09:00
Yukihiro "Matz" Matsumoto fe8428b33b Merge pull request #4642 from dearblue/unique-symlink
Make symbolic link names unique for test
2019-08-19 07:25:07 +09:00
Yukihiro "Matz" Matsumoto 1b9801a04b Merge pull request #4641 from shuujii/rename-mrb_shared_string-len-to-mrb_shared_string-capa
Rename `mrb_shared_string::len` to `mrb_shared_string::capa`
2019-08-19 07:24:06 +09:00
Yukihiro "Matz" Matsumoto feecb3321a Merge pull request #4640 from shuujii/also-use-str_init_shared-for-orig-in-str_make_shared
Also use `str_init_shared` for `orig` in `str_make_shared()`
2019-08-19 07:23:23 +09:00
Yukihiro "Matz" Matsumoto 6f61b35bcf Merge pull request #4637 from dearblue/immutable-iseq
Prohibit changes to iseq in principle
2019-08-18 23:25:40 +09:00
dearblue 734a7f52a7 Make symbolic link names unique for test 2019-08-18 22:10:41 +09:00
David Siaw b5299b1c58 fix up documentation for values 2019-08-18 20:12:44 +09:00
KOBAYASHI Shuji d2d201cc82 Rename mrb_shared_string::len to mrb_shared_string::capa
Because this field is used as capacity of string buffer.
2019-08-18 20:08:04 +09:00
KOBAYASHI Shuji aaa509dd07 Also use str_init_shared for orig in str_make_shared() 2019-08-18 19:44:00 +09:00
dearblue 74395d7577 Suppress warnings for strncat()
`strncat()` also needs `'\0'`.
2019-08-18 15:46:17 +09:00
dearblue 05a873c25c Simplify get arguments
- `mrb_str_index_m()` and `mrb_str_rindex()`
  Make `mrb_get_args()` called only once from called twice.
- `mrb_str_byteslice()`
  Replace `goto` with `if ~ else`.
2019-08-18 15:38:25 +09:00
dearblue 279c21b816 Prohibit changes to iseq in principle 2019-08-18 15:00:32 +09:00
David Siaw 2c86895468 fix up markdown display in doxygen 2019-08-18 13:59:29 +09:00
David Siaw 8d70a9b1b5 first bit of doc generation 2019-08-18 13:07:24 +09:00
Yukihiro "Matz" Matsumoto 83dab1ee0d Merge pull request #4634 from shuujii/refactor-set-unset-string-type-flags
Refactor set/unset string type flags
2019-08-17 23:41:52 +09:00
KOBAYASHI Shuji 5345731b1d Fix wrong argument for fprintf in mruby-bin-mrbc 2019-08-17 21:46:45 +09:00
KOBAYASHI Shuji caba5fef27 Refactor set/unset string type flags
Introduce `RSTR_SET_TYPE_FLAG` macro to set the specified string type flag and
clear the others.
2019-08-17 21:24:08 +09:00
Yukihiro "Matz" Matsumoto 277c91e94c Merge pull request #4625 from dearblue/rindex-broken-utf8
Fix `String#rindex` with invalid UTF-8 string
2019-08-17 15:52:34 +09:00
Yukihiro "Matz" Matsumoto b55e72b2d6 Resolve conflict between #4582 and C++ warning. 2019-08-17 15:47:14 +09:00
Yukihiro "Matz" Matsumoto 5b1f25a4e0 Implement Array#each using inline mruby bytecode. 2019-08-17 14:46:32 +09:00
Yukihiro "Matz" Matsumoto 13eaff4f9f Remove unnecessary OP_JMPNOT for unless statement. 2019-08-17 12:29:04 +09:00
dearblue bc27273087 Fix String#rindex with invalid UTF-8 string
Previously `String#rindex` returned the wrong index when given an
invalid UTF-8 string.

```terminal
% ruby26 -e 'str = "\xf0☀\xf1☁\xf2☂\xf3☃\xf0☀\xf1☁\xf2☂\xf3☃"; p str.rindex("☁")'
11
% ./mruby-head -e 'str = "\xf0☀\xf1☁\xf2☂\xf3☃\xf0☀\xf1☁\xf2☂\xf3☃"; p str.rindex("☁")'
nil
% ./mruby-patched -e 'str = "\xf0☀\xf1☁\xf2☂\xf3☃\xf0☀\xf1☁\xf2☂\xf3☃"; p str.rindex("☁")'
11
```
2019-08-17 12:05:03 +09:00
Yukihiro "Matz" Matsumoto e76c5aad36 Stop using mrb_to_str as a converter (it is not). 2019-08-17 11:49:00 +09:00
dearblue 414ab682f3 Add String#rindex test for invalid UTF-8 string 2019-08-17 11:44:27 +09:00
dearblue cf5f290fa0 Fix String#rindex test for UTF-8 string 2019-08-17 11:44:27 +09:00
Yukihiro "Matz" Matsumoto 0286a7f709 Avoid mrb_funcall from Class#new when no overloading. 2019-08-17 09:02:47 +09:00
Yukihiro "Matz" Matsumoto 99715a2e62 Merge pull request #4633 from shuujii/shared-fshared-string-is-not-required-when-sharing-nofree-string
SHARED/FSHARED string is not required when sharing NOFREE string
2019-08-16 23:20:44 +09:00
Yukihiro "Matz" Matsumoto c1a0a99309 Update struct RArray union to silence C++ warning. 2019-08-16 22:51:07 +09:00
Yukihiro "Matz" Matsumoto 0923ff6313 Optimize bytecode for Class#new. 2019-08-16 22:37:30 +09:00
Yukihiro "Matz" Matsumoto 61763129db Implement Class#new using inline mruby bytecode. 2019-08-16 22:30:03 +09:00
KOBAYASHI Shuji 9832e91304 SHARED/FSHARED string is not required when sharing NOFREE string
I think the string buffer of NOFREE string always exists and does not need
to be released, so it can be shared as another NOFREE string.

Also changed the `mrb_shared_string` field order so that eliminate padding if
`int` and `mrb_int` sizes are less than pointer size.
2019-08-16 22:05:58 +09:00
Yukihiro "Matz" Matsumoto 06c7ff0666 Avoid creating unnecessary empty arrays on splat.
But this changes requires `OP_ARYCAT` and `OP_ARYPUSH` to accept `nil`
as their first operand. Alternative VMs (e.g. `mruby/c`) that understand
mruby bytecode need to be updated.
2019-08-16 16:42:40 +09:00
Yukihiro "Matz" Matsumoto fa8515bc2c Stop raising exceptions from undef C API.
Some `undef' functions may be called before initialization, thus causes
infinite error recursion.
2019-08-16 16:42:40 +09:00
Yukihiro "Matz" Matsumoto 8fa9a7b965 Merge pull request #4632 from shuujii/remove-unneeded--include-in-src-string.c
Remove unneeded `#include` in `src/string.c`
2019-08-15 18:41:30 +09:00
KOBAYASHI Shuji 59844ddde0 Remove unneeded #include in src/string.c 2019-08-15 12:18:33 +09:00
Yukihiro "Matz" Matsumoto 0c5ebd75a3 Merge pull request #4631 from shuujii/extract-initialization-code-of-shared-and-fshared-string-to-function
Extract initialization code of shared and fshared string to function
2019-08-14 23:29:07 +09:00
KOBAYASHI Shuji af6724c2f6 Extract initialization code of shared and fshared string to function 2019-08-14 22:20:34 +09:00
Yukihiro "Matz" Matsumoto d986b9ff7b Avoid array copying in mrb_instance_new. 2019-08-14 15:08:48 +09:00
Yukihiro "Matz" Matsumoto 603005ba65 Integrate kazuho/mruby-class-new-fiber-safe in the master.
Avoid calling `initialize` via `mrb_funcall`, which cause `cross C
boundary` error from Fibers started in the method.
2019-08-14 14:09:56 +09:00
Yukihiro "Matz" Matsumoto 8ed15fd92e Small refactoring on #4630 2019-08-14 12:20:40 +09:00
Yukihiro "Matz" Matsumoto 9f6328d499 Remove MRB_API from functions only called from vm.c.
* `mrb_vm_define_class`
* `mrb_vm_define_module`

Only functions called from user code requires `MRB_API`.
2019-08-14 09:33:23 +09:00
Yukihiro "Matz" Matsumoto e2ab8cca82 Merge pull request #4630 from shuujii/extract-struct-RString-initialization-code-to-function
Extract `struct RString` initialization code to function
2019-08-14 08:16:45 +09:00
KOBAYASHI Shuji 7af0ee099d Extract struct RString initialization code to function 2019-08-13 22:40:30 +09:00
Yukihiro "Matz" Matsumoto 8a3457c330 Merge pull request #4629 from shuujii/mrb_str_pool-can-embed-one-more-byte
`mrb_str_pool` can embed one more byte; ref #4626
2019-08-12 22:41:51 +09:00
KOBAYASHI Shuji dfb297e3c4 mrb_str_pool can embed one more byte; ref #4626 2019-08-12 21:42:31 +09:00
Yukihiro "Matz" Matsumoto f113fa2a4f Remove unnecessary prototypes from 'keywords`; fix #4628 2019-08-12 18:22:31 +09:00
Yukihiro "Matz" Matsumoto ad0b546088 Merge pull request #4626 from shuujii/mrb_str_modify_keep_ascii-can-embed-one-more-byte
`mrb_str_modify_keep_ascii` can embed one more byte
2019-08-12 17:09:21 +09:00
Yukihiro "Matz" Matsumoto 285ce9d8aa Replacing region may overwrap with the target region; fix #4627 2019-08-12 16:51:01 +09:00
Yukihiro "Matz" Matsumoto 472dba19ea Revert "Should have cleared mrb->globals in mrb_gc_free_gv; fix #4618"
This reverts commit 3dc8d9d7b3.
2019-08-11 22:14:56 +09:00
Yukihiro "Matz" Matsumoto 0376383354 Reorder finalization to avoid potential crash; ref #4618
`mrb_gc_destroy` may call other mruby API functions from the finalizers.
So call that function first.
2019-08-11 22:14:56 +09:00
Yukihiro "Matz" Matsumoto 70b53f91c2 Add NUL always to short strings; ref 98fc887 2019-08-11 22:14:56 +09:00
KOBAYASHI Shuji 450684ab33 mrb_str_modify_keep_ascii can embed one more byte
The condition to make an embedded string was incorrect. Because there were
several similar codes, extracted into `RSTR_EMBEDDABLE_P` macro.
2019-08-11 20:48:37 +09:00
Yukihiro "Matz" Matsumoto ce7fd7e1a3 Merge pull request #4621 from shuujii/remove-monkey-patches-for-Ruby-1.9-or-earlier
Remove monkey patches for Ruby 1.9 or earlier
2019-08-11 03:23:51 +09:00
Yukihiro "Matz" Matsumoto 469dbeb42e Merge pull request #4624 from shuujii/enumerable-reject-etc.-should-return-Enumerable-without-block
`Enumerable#reject`, etc. should return `Enumerable` without block
2019-08-11 03:22:35 +09:00
KOBAYASHI Shuji 9f18aced9f Enumerable#reject, etc. should return Enumerable without block 2019-08-10 22:18:54 +09:00
Yukihiro "Matz" Matsumoto 496a2c3264 Merge pull request #4623 from chasonr/complex-fixes
Avoid premature overflow in Complex#abs and Complex#/
2019-08-09 21:47:00 +09:00
Ray Chason 1cd0ff0d42 Avoid overflow and underflow in Complex#/ 2019-08-09 00:08:36 -04:00
Ray Chason c181d1e7fa Implement Complex#abs in terms of Math.hypot
Math.hypot avoids premature overflow and underflow
2019-08-08 23:59:25 -04:00
KOBAYASHI Shuji 1868fd453d Remove monkey patches for Ruby 1.9 or earlier 2019-08-08 22:12:25 +09:00
Yukihiro "Matz" Matsumoto 438638b42e Merge pull request #4620 from shuujii/improve-MiniRake-rule-enhancement-for-Rake-compatibility
Improve MiniRake rule enhancement for Rake compatibility
2019-08-07 23:55:51 +09:00
KOBAYASHI Shuji 7e42b6ad3f Improve MiniRake rule enhancement for Rake compatibility
Support pathmap notation, recursive dependencies search, and so on.
2019-08-07 21:50:22 +09:00
Yukihiro "Matz" Matsumoto b377b7d580 Update mrb_to_str and related functions.
Contrary to the name, `mrb_to_str` just checks type, no conversion.
2019-08-07 16:20:40 +09:00
Yukihiro "Matz" Matsumoto 98fc887cb3 Reorganize mrb_string_value_cstr and related functions.
`mrb_string_value_cstr` and `mrb_string_value_len`: obsolete
`mrb_string_cstr`: new function to retrieve NULL terminated C string
`RSTRING_CSTR`: wrapper macro of `mrb_string_cstr`
2019-08-07 15:52:10 +09:00
Yukihiro "Matz" Matsumoto b8a87bd111 Update required Ruby version to 2.0 or later. 2019-08-07 15:03:16 +09:00
Yukihiro "Matz" Matsumoto 2e73fe5ea1 Replace i.e. (means "that is") with e.g. (means "for example"). 2019-08-07 15:02:38 +09:00
Yukihiro "Matz" Matsumoto eceaa80de7 RUBY_PLATFORM may not contain mswin or mingw; Add msys 2019-08-07 08:54:40 +09:00
Yukihiro "Matz" Matsumoto 97672b22e6 Merge pull request #4619 from shuujii/add-mrb_noreturn-to-cmperr-in-src-numeric.c
Add `mrb_noreturn` to `cmperr()` in `src/numeric.c`
2019-08-07 08:54:25 +09:00
KOBAYASHI Shuji 6e2edd8ed2 Add mrb_noreturn to cmperr() in src/numeric.c 2019-08-06 23:04:40 +09:00
Yukihiro "Matz" Matsumoto 2ba8399ac8 Removed an unused local variable; ref #4615 2019-08-06 20:50:26 +09:00
Yukihiro "Matz" Matsumoto 3dc8d9d7b3 Should have cleared mrb->globals in mrb_gc_free_gv; fix #4618 2019-08-06 20:47:35 +09:00
Yukihiro "Matz" Matsumoto 151d0c14ed Merge pull request #4615 from shuujii/use-new-specifiers-modifiers-of-mrb_vfromat
Use new specifiers/modifiers of `mrb_vfromat()`
2019-08-05 13:33:46 +09:00
KOBAYASHI Shuji 334afb167c Use new specifiers/modifiers of mrb_vfromat()
The binary sizes (gems are only `mruby-bin-mruby`) are reduced slightly in
my environment than before the introduction of new specifiers/modifiers
(5116789a) with this change.

  ------------+-------------------+-------------------+--------
   BINARY     | BEFORE (5116789a) |   AFTER (This PR) |  RATIO
  ------------+-------------------+-------------------+--------
   mruby      |      593416 bytes |      593208 bytes | -0.04%
   libmruby.a |      769048 bytes |      767264 bytes | -0.23%
  ------------+-------------------+-------------------+--------

BTW, I accidentally changed `tasks/toolchains/visualcpp.rake` at #4613,
so I put it back.
2019-08-05 13:18:50 +09:00
Yukihiro "Matz" Matsumoto 96ce4563bd Merge pull request #4614 from shuujii/use-mrb_int-instead-of-to_int-in-mruby-numeric-ext
Use `mrb_int()` instead of `to_int()` in `mruby-numeric-ext`
2019-08-05 12:33:59 +09:00
Yukihiro "Matz" Matsumoto 0e2e8b79d3 Merge pull request #4612 from dearblue/float-consts
Add constants for floating point number
2019-08-05 07:29:25 +09:00
Yukihiro "Matz" Matsumoto dc11e7f027 Merge pull request #4613 from shuujii/change-second-argument-to-%l-of-mrb_vformat-to-size_t-from-mrb_int
Change second argument to `%l` of `mrb_vformat()` to `size_t` from `mrb_int`
2019-08-05 07:26:20 +09:00
KOBAYASHI Shuji d599e35aa4 Use mrb_int() instead of to_int() in mruby-numeric-ext 2019-08-04 22:02:39 +09:00
dearblue eb86340139 Add constants for floating point number 2019-08-04 18:34:46 +09:00
KOBAYASHI Shuji 1e9cb74cc6 Change second argument to %l of mrb_vformat() to size_t from mrb_int
- `size_t` is more commonly used.
- `len` argument of `mrb_str_new()` is `size_t`.

NOTE:

The test for `%l` is temporarily disabled because adding a new type to
`mrbgems/mruby-test/vformat.c` causes an error (memory error?) on Visual
Studio 2017 in AppVeyor.
2019-08-03 19:42:22 +09:00
Yukihiro "Matz" Matsumoto f6c41c1862 Merge pull request #4611 from shuujii/fix-mrb_vformat%f-with-MRB_USE_FLOAT
Fix `mrb_vformat("%f")` with `MRB_USE_FLOAT`
2019-08-03 15:33:35 +09:00
Yukihiro "Matz" Matsumoto d5695a84df Merge pull request #4610 from dearblue/time-warnings
Suppress compiler warnings for mruby-time; fix #4600
2019-08-03 15:31:36 +09:00
KOBAYASHI Shuji a4243360a2 Fix mrb_vformat("%f") with MRB_USE_FLOAT
It potentially not work when `mrb_float` is `float` because `float` variable
in variable length arguments is promoted to `double`.

Also I fixed build with `MRB_WITHOUT_FLOAT`.
2019-08-03 11:54:45 +09:00
dearblue 07308a2fc9 Suppress compiler warnings for mruby-time; fix #4600
Warnings:

- If `MRB_TIME_T_UINT` is defined, the compiler issues a warning with an
  integer comparison of different signs.
- It is mentioned that the `usec` variable passed to the
  `mrb_to_time_t()` function may not be initialized
2019-08-03 10:35:39 +09:00
Yukihiro "Matz" Matsumoto c883f4e332 Merge pull request #4609 from shuujii/change-the-mrb_vformat-specifier-%d-for-int
Change the `mrb_vformat` specifier `%d` for `int`
2019-08-02 20:38:41 +09:00
KOBAYASHI Shuji d1817e7791 Change the mrb_vformat specifier %d for int
It potentially breaks, for example, in the case of `mrb_int` is 64-bit
and more smaller type is passed by `%d`. In fact, the problem could
become apparent when I used `%d` to `backtrace_location::lineno` in
`src/backtrace.c:mrb_unpack_backtrace()` on AppVeyor.

Therefore, change `%d` for `int` (not `mrb_int`) so that it can be
used mostly without casting.
2019-08-02 19:22:08 +09:00
Yukihiro "Matz" Matsumoto 3bacc302a3 Merge pull request #4608 from shuujii/add-new-specifiers-modifiers-to-format-string-of-mrb_vfromat
Add new specifiers/modifiers to format string of `mrb_vfromat()`
2019-08-01 22:10:53 +09:00
KOBAYASHI Shuji eea42e06af Add new specifiers/modifiers to format string of mrb_vfromat()
Format sequence syntax:

  %[modifier]specifier

Modifiers:

  ----------+------------------------------------------------------------
  Modifier  | Meaning
  ----------+------------------------------------------------------------
      !     | Convert to string by corresponding `inspect` instead of
            | corresponding `to_s`.
  ----------+------------------------------------------------------------

Specifiers:

  ----------+----------------+--------------------------------------------
  Specifier | Argument Type  | Note
  ----------+----------------+--------------------------------------------
      c     | char           |
     d,i    | mrb_int        |
      f     | mrb_float      |
      l     | char*, mrb_int | Arguments are string and length.
      n     | mrb_sym        |
      s     | char*          | Argument is NUL terminated string.
      t     | mrb_value      | Convert to type (class) of object.
     v,S    | mrb_value      |
      C     | struct RClass* |
      T     | mrb_value      | Convert to real type (class) of object.
      Y     | mrb_value      | Same as `!v` if argument is `true`, `false`
            |                | or `nil`, otherwise same as `T`.
      %     | -              | Convert to percent sign itself (no argument
            |                | taken).
  ----------+----------------+--------------------------------------------

This change will increase the binary size, but replacing all format strings
with new specifiers/modifiers will decrease the size because it reduces
inline expansion of `mrb_obj_value()`, etc. at the caller.
2019-08-01 13:24:52 +09:00
Yukihiro "Matz" Matsumoto 3d3a6da2ca Merge pull request #4607 from shuujii/fix-UTC-offset-representation-in-Time-to_s-on-some-environments
Fix UTC offset representation in `Time#to_s` on some environments; ref #4604
2019-07-31 22:07:31 +09:00
KOBAYASHI Shuji 5116789aa0 Fix UTC offset representation in Time#to_s on some environments; ref #4604
Use own implementation to calculate UTC offset on Visual Studio 2015 or
earlier or MinGW because `strftime("%z")` on these environments does not
conform C99.
2019-07-31 20:34:27 +09:00
Yukihiro "Matz" Matsumoto 96ac49b75b Avoid MRB_INT_MIN to apply fixdivmod.
`MRB_INT_MIN` is the only integer value that has no corresponding
positive integer value (i.e. `-MRB_INT_MIN` = `MRB_INT_MIN`).
2019-07-31 00:58:12 +09:00
Yukihiro "Matz" Matsumoto c31e1ea798 Normalize floating point negative zero to positive zero in `flodivmod'. 2019-07-31 00:57:00 +09:00
Yukihiro "Matz" Matsumoto 28405d26b0 Should return +/- infinity for float division by zero. 2019-07-31 00:55:31 +09:00
Yukihiro "Matz" Matsumoto 8175d92b4b Use NULL instead of 0 for null pointers. 2019-07-31 00:54:39 +09:00
Yukihiro "Matz" Matsumoto 5900b29fb4 Fixed integer overflow in lshift. 2019-07-30 23:16:34 +09:00
Yukihiro "Matz" Matsumoto 7dae0ec74c Merge pull request #4606 from shuujii/refine-message-to-skip-in-nested-assert
Refine message to `skip` in nested `assert`
2019-07-30 14:41:09 +09:00
KOBAYASHI Shuji 44381f0a0c Refine message to skip in nested assert
- I think "Info" is used only to `skip`, so change to "Skip".
- Changed the default value of `assert` and specify the argument explicitly
  at the caller of `assert` because it is unnatural "Assertion failed" is
  output even though the assertion doesn't fail.

== Example:

  def assert_foo(exp, act)
    assert do
      assert_equal exp[0], act[0]
      assert_equal exp[1], act[1]
    end
  end

  def assert_bar(exp, act)
    assert do
      skip
    end
  end

  def assert_baz(exp, act)
    assert do
      assert_equal exp, act
      assert_bar exp, act
    end
  end

  assert 'test#skip_in_nested_assert' do
    assert_baz 1, 1
  end

  === Before this patch:

    ?..
    Info: test#skip_in_nested_assert (core)
     - Assertion[1]
        Info: Assertion failed (core)
         - Assertion[1-2]
            Skip: Assertion failed (core)
      Total: 3
         OK: 2
         KO: 0
      Crash: 0
    Warning: 0
       Skip: 1

  === After this patch:

    ???
    Skip: test#skip_in_nested_assert (core)
     - Assertion[1]
        Skip: assert (core)
         - Assertion[1-2]
            Skip: assert (core)
      Total: 3
         OK: 0
         KO: 0
      Crash: 0
    Warning: 0
       Skip: 3
2019-07-30 13:05:01 +09:00
Yukihiro "Matz" Matsumoto 428e34abba Merge pull request #4605 from shuujii/fix-Warn-if-assertion-is-missing-inside-assert
Fix "Warn if assertion is missing inside `assert`"; ref ff43b2b9
2019-07-29 22:37:13 +09:00
KOBAYASHI Shuji 5091d047c0 Fix "Warn if assertion is missing inside assert"; ref ff43b2b9 2019-07-29 21:40:58 +09:00
Yukihiro "Matz" Matsumoto a8001d693a Merge pull request #4604 from kou/time-to-s-utf8
Fix Time#to_s encoding on Windows
2019-07-29 18:43:16 +09:00
Sutou Kouhei effae4ae55 Fix Time#to_s encoding on Windows
strftime() on Windows returns locale encoding time zone for "%z" even
if MSDN says "%z" is "The offset from UTC in ISO 8601 format; no
characters if time zone is unknown" in MSDN:

https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/strftime-wcsftime-strftime-l-wcsftime-l?view=vs-2019

So we need to convert encoding of string from strftime().
2019-07-29 18:16:21 +09:00
Yukihiro "Matz" Matsumoto ff43b2b97c Fixed a conflict between #4407 and #4540 2019-07-29 01:25:58 +09:00
Yukihiro "Matz" Matsumoto 2ebc6d5b6f Merge pull request #4407 from shuujii/add-assert_raise_with_message-and-assert_raise_with_message_pattern
Add `assert_raise_with_message` and `assert_raise_with_message_pattern`
2019-07-29 01:05:26 +09:00
Yukihiro "Matz" Matsumoto cd8fc9bcb8 Resolved conflicts in #4320 2019-07-29 01:02:03 +09:00
Yukihiro "Matz" Matsumoto 3ac98009d3 Merge pull request #4602 from shuujii/remove-EnumeratorChain-initialize_copy
Remove `Enumerator::Chain#initialize_copy`
2019-07-28 23:44:11 +09:00
Yukihiro "Matz" Matsumoto 34741d513f Merge pull request #4603 from shuujii/define-plus-to-Enumerator-and-Enumerator-Chain-instead-of-Enumerable
Define `#+` to `Enumerator` and `Enumerator#Chain` instead of `Enumerable`
2019-07-28 23:43:31 +09:00
KOBAYASHI Shuji 7f80a5f73c Define #+ to Enumerator and Enumerator#Chain instead of Enumerable 2019-07-28 22:52:24 +09:00
KOBAYASHI Shuji 27e3d92a30 Remove Enumerator::Chain#initialize_copy
I think `Enumerator::Chain#initialize_copy` is unnecessary because CRuby
doesn't clone elements.
2019-07-28 22:12:02 +09:00
Yukihiro "Matz" Matsumoto 04a422e499 Merge pull request #4601 from shuujii/drop-dependency-from-mruby-enumerator-to-mruby-enum-ext
Drop dependency from `mruby-enumerator` to `mruby-enum-ext`
2019-07-28 14:48:15 +09:00
KOBAYASHI Shuji a70107d725 Drop dependency from mruby-enumerator to mruby-enum-ext 2019-07-28 13:08:11 +09:00
Yukihiro "Matz" Matsumoto fa798f17ff Merge pull request #4600 from dearblue/time-precision
Fix the lack of precision for `Time`; ref d74355061
2019-07-28 10:38:07 +09:00
Yukihiro "Matz" Matsumoto 8c6cd2da76 Merge pull request #4599 from shuujii/drop-dependency-from-mruby-enum-chain-to-mruby-enum-ext
Drop dependency from `mruby-enum-chain` to `mruby-enum-ext`
2019-07-27 21:38:20 +09:00
dearblue fda5c0c073 Fix the lack of precision for Time; ref d74355061
- `Time.local` and `Time.utc` are able to use with `MRB_INT16 + MRB_WITHOUT_FLOAT`.

  - `time_t` is converted directly from the Ruby object.

  - `time + sec` and` time - sec` are not affected by the precision of `mrb_float`.

    Similarly, calculations are possible with `MRB_INT16 + MRB_WITHOUT_FLOAT`.
2019-07-27 21:25:18 +09:00
KOBAYASHI Shuji fe9a58c193 Drop dependency from mruby-enum-chain to mruby-enum-ext 2019-07-27 20:45:14 +09:00
Yukihiro "Matz" Matsumoto 2f0a95768b Merge pull request #4598 from dearblue/time-without-float
Fix mruby-time with `MRB_WITHOUT_FLOAT`; ref d74355061
2019-07-27 15:05:16 +09:00
Yukihiro "Matz" Matsumoto b58f769c96 Fix line number bug; fix #4513
Also fix the misfeature introduced in 23783a4, that ignores newlines
between method chains.
2019-07-27 15:00:46 +09:00
dearblue 1467c14adc Fix mruby-time with MRB_WITHOUT_FLOAT; ref d74355061 2019-07-27 14:42:37 +09:00
Yukihiro "Matz" Matsumoto 42fb251d0a Merge pull request #4597 from shuujii/drop-dependency-from-mruby-array-ext-to-mruby-enum-ext
Drop dependency from `mruby-array-ext` to `mruby-enum-ext`
2019-07-27 14:01:37 +09:00
Yukihiro "Matz" Matsumoto 3103da8570 Merge pull request #4594 from shuujii/move-NilClass-to_h-to-mruby-object-ext-from-mruby-enum-ext
Move `NilClass#to_h` to `mruby-object-ext` from `mruby-enum-ext`
2019-07-27 13:09:34 +09:00
KOBAYASHI Shuji 778310260c Drop dependency from mruby-array-ext to mruby-enum-ext 2019-07-26 11:48:53 +09:00
Yukihiro "Matz" Matsumoto 381a6ddddb Merge pull request #4595 from shuujii/refine-Array-permutation-combination-test
Refine `Array#(permutation|combination) test`
2019-07-26 00:04:52 +09:00
KOBAYASHI Shuji 87cc58ba3d Refine Array#(permutation|combination) test
- No guarantees about the order in which the permutations/combinations
  are yielded.

- Drop dependency on `Enumerator`.
2019-07-25 22:31:54 +09:00
KOBAYASHI Shuji 2d520eaf6f Move NilClass#to_h to mruby-object-ext from mruby-enum-ext 2019-07-24 20:13:26 +09:00
Yukihiro "Matz" Matsumoto 5779464ec3 Add return to silence a warning; ref #4593 2019-07-24 10:50:22 +09:00
Yukihiro "Matz" Matsumoto 866a9e6481 Use MRB_TT_ISTRUCT for Random to reduce memory.
When the size of Xorshift128 seed (`sizeof(uint32)*4`) is bigger than
ISTRUCT_DATA_SIZE, `Random` uses Xorshift96 instead.
2019-07-24 10:48:00 +09:00
Yukihiro "Matz" Matsumoto a57a9bce79 Call MRB_SET_INSTANCE_TT for Complex and Rational. 2019-07-24 10:48:00 +09:00
Yukihiro "Matz" Matsumoto e968bdf629 Merge pull request #4593 from shuujii/add-encoding-argument-to-Integral-chr
Add encoding argument to `Integral#chr`
2019-07-23 23:36:50 +09:00
KOBAYASHI Shuji e86aa61f20 Add encoding argument to Integral#chr
Currently, `Integral#chr` in mruby changes behavior by `MRB_UTF8_STRING`
setting.

before this patch:

  $ bin/mruby -e 'p 171.chr'  #=> "\xab"  (`MRB_UTF8_STRING` is disabled)
  $ bin/mruby -e 'p 171.chr'  #=> "«"     (`MRB_UTF8_STRING` is enabled)

This behavior is incompatible with Ruby, and a little inconvenient because
it can't be interpreted as ASCII-8BIT with `MRB_UTF8_STRING`, I think.

So add encoding argument according to Ruby.

after this patch:

  $ bin/mruby -e 'p 171.chr'                #=> "\xab"
  $ bin/mruby -e 'p 171.chr("ASCII-8BIT")'  #=> "\xab"
  $ bin/mruby -e 'p 171.chr("UTF-8")'       #=> "«"

Allow only `String` for encoding because mruby doesn't have `Encoding`
class, and `"ASCII-8BIT"` (`"BINARY"`) and `"UTF-8"` (only with
`MRB_UTF8_STRING`) are valid value (default is `"ASCII-8BIT"`).
2019-07-23 20:16:46 +09:00
Yukihiro "Matz" Matsumoto 5166e316ef Merge pull request #4591 from shuujii/integrate-Integral-chr-Fixnum-chr-to-mruby-string-ext
Integrate `Integral#chr` (`Fixnum#chr`) to `mruby-string-ext`
2019-07-22 21:40:02 +09:00
Yukihiro "Matz" Matsumoto d2dd2d0e48 Merge pull request #4590 from shuujii/fix-Module-dup-to-frozen-module
Fix `Module#dup` to frozen module
2019-07-22 21:38:56 +09:00
Yukihiro "Matz" Matsumoto 477be45244 Merge pull request #4592 from shuujii/set-MRB_STR_ASCII-flag-in-String-inspect
Set `MRB_STR_ASCII` flag in `String#inspect`
2019-07-22 21:38:08 +09:00
Yukihiro "Matz" Matsumoto d74355061b Fix mruby-time to work with MRB_WITHOUT_FLOAT; ref #4576
As a side effect, `mrb_time_at()` now takes `mrb_int` instead of
`double` as time arguments.
2019-07-22 21:34:37 +09:00
Yukihiro "Matz" Matsumoto 87d1b2a910 Improve conflict error message of Time and Math; ref #4576 2019-07-22 20:21:30 +09:00
Yukihiro "Matz" Matsumoto 949f6f5324 Check conflicts with Complex and MRB_WITHOUT_FLOAT; ref #4576
The Complex class needs `mrb_float` so that it does not work with
`MRB_WITHOUT_FLOAT` anyway.
2019-07-22 20:19:01 +09:00
KOBAYASHI Shuji fe8b463c4e Set MRB_STR_ASCII flag in String#inspect
`String#inspect` can set `MRB_STR_ASCII` flag to receiver and return value
because it checks character byte length.
2019-07-22 19:39:25 +09:00
Yukihiro "Matz" Matsumoto f99e9963b2 Switch random generator from Mersenne Twister to Xorshit128.
Now `rand` can be used with `MRB_WITHOUT_FLOAT`; ref #4576
2019-07-22 15:49:59 +09:00
Yukihiro "Matz" Matsumoto 277be410f3 No rounding needed if 'ndigits is bigger than DBL_DIG+2`; fix #4566 2019-07-22 13:23:53 +09:00
Yukihiro "Matz" Matsumoto 6f67fddb87 Fix FIXABLE_FLOAT() on MRB_INT64; ref #4566
Normal `TYPED_FIXABLE(f,mrb_float)` does not work on 64bit int from
casting problems. The new approach works well, but assumes two's
complement and IEEE-754 floating point numbers.
2019-07-22 13:23:53 +09:00
KOBAYASHI Shuji c980fe2792 Integrate Integral#chr (Fixnum#chr) to mruby-string-ext
Because they're defined in both `mruby-string-ext` and `mruby-numeric-ext`
(they seem more natural to define in N, but `mruby-string-ext` depends on
`Integral#chr`).
2019-07-21 22:59:41 +09:00
KOBAYASHI Shuji 7675fcb5d3 Fix Module#dup to frozen module
Before this patch:

  $ bin/mruby -e 'p Module.new.freeze.dup.frozen?'  #=> true

After this patch (same as Ruby):

  $ bin/mruby -e 'p Module.new.freeze.dup.frozen?'  #=> false
2019-07-20 22:41:57 +09:00
Yukihiro "Matz" Matsumoto cf4cddf7a1 Merge pull request #4589 from shuujii/refine-String-chr-test
Refine `String#chr` test and separate `Fixnum#chr` test
2019-07-20 08:15:02 +09:00
KOBAYASHI Shuji 8ab846b5b9 Refine String#chr test and separate Fixnum#chr test 2019-07-19 21:48:06 +09:00
Yukihiro "Matz" Matsumoto 7e229c470a Merge pull request #4575 from dearblue/attr-use-stack
Use stack memory for small name of attr accessors
2019-07-18 18:37:08 +09:00
Yukihiro "Matz" Matsumoto 317fba47a6 Merge pull request #4588 from shuujii/fix-String-times-test-with-MRB_WITHOUT_FLOAT
Fix `String#*` test with `MRB_WITHOUT_FLOAT`
2019-07-18 18:36:32 +09:00
KOBAYASHI Shuji 9873d5e0b9 Fix String#* test with MRB_WITHOUT_FLOAT 2019-07-18 17:51:02 +09:00
Yukihiro "Matz" Matsumoto 94a1f488a6 Clear env before top-level execution; fix #4581 2019-07-18 00:35:21 +09:00
Yukihiro "Matz" Matsumoto 2a410c0e1b Avoid making top-level env in initialization code; ref #4581 2019-07-18 00:34:08 +09:00
Yukihiro "Matz" Matsumoto 0b5e155016 Merge pull request #4587 from shuujii/fix-String-aref-test
Fix `String#[]` test
2019-07-17 22:35:16 +09:00
Yukihiro "Matz" Matsumoto 626c21466f Merge pull request #4585 from shuujii/fix-range-min-with-mruby-range-ext
Fix `(fixnum_value ... float_value).min` with `mruby-range-ext`
2019-07-17 22:34:29 +09:00
Yukihiro "Matz" Matsumoto cdf5e3963d Merge branch 'master' into fix-range-min-with-mruby-range-ext 2019-07-17 22:33:55 +09:00
Yukihiro "Matz" Matsumoto 7172231b8f Merge pull request #4586 from shuujii/revert-4300
Revert #4300
2019-07-17 22:29:35 +09:00
Yukihiro "Matz" Matsumoto 47ac318920 Merge pull request #4584 from shuujii/allow-mruby-range-ext-to-work-with-MRB_WITHOUT_FLOAT
Allow `mruby-range-ext` to work with `MRB_WITHOUT_FLOAT`; ref 2add8641
2019-07-17 20:42:25 +09:00
KOBAYASHI Shuji 9d2272ec2c Fix String#[] test 2019-07-17 20:09:37 +09:00
KOBAYASHI Shuji e38ba3d58c Revert #4300
Originally, it was not necessary to change. I made mistake.
2019-07-17 19:49:58 +09:00
KOBAYASHI Shuji 1b7516a4ae Fix (fixnum_value ... float_value).min with mruby-range-ext
Before this patch:

  $ bin/mruby -e 'p (2...4.0).min'  #=> TypeError

After this patch (same as CRuby and without `mruby-range-ext`):

  $ bin/mruby -e 'p (2...4.0).min'  #=> 2
2019-07-17 19:18:23 +09:00
KOBAYASHI Shuji 8cb37804c1 Allow mruby-range-ext to work with MRB_WITHOUT_FLOAT; ref 2add8641 2019-07-17 18:58:21 +09:00
Yukihiro "Matz" Matsumoto d5939879cc Fixed a bug in #4034 2019-07-17 10:39:17 +09:00
Yukihiro "Matz" Matsumoto b22bde6596 Avoid MRB_INLINE for mrb_str_modify(); ref #4579
Functions that are called infrequently need not to be inline.
2019-07-17 10:36:10 +09:00
Yukihiro "Matz" Matsumoto 2add864164 Allow mruby-range-ext to work with MRB_WITHOUT_FLOAT; ref #4576 2019-07-17 10:36:10 +09:00
Yukihiro "Matz" Matsumoto 5eef75b678 Merge pull request #4034 from i110/i110/inspect-recursion
Let inspect recursion do the right thing
2019-07-17 10:35:59 +09:00
Yukihiro "Matz" Matsumoto d605b72c1d Merge branch 'master' into i110/inspect-recursion 2019-07-17 10:35:41 +09:00
Yukihiro "Matz" Matsumoto 9af3b7c625 Merge pull request #4583 from shuujii/set-MRB_STR_ASCII-flag-in-some-methods-of-String
Copy receiver's `MRB_STR_ASCII` flag in some methods of `String`
2019-07-16 22:51:55 +09:00
KOBAYASHI Shuji 31492a177c Copy receiver's MRB_STR_ASCII flag in some methods of String 2019-07-16 21:56:58 +09:00
Yukihiro "Matz" Matsumoto d9a656756b Merge pull request #4576 from dearblue/error-configuration
Error needed/conflicts configuration
2019-07-16 12:12:58 +09:00
Yukihiro "Matz" Matsumoto 8e10a026e6 Merge pull request #4580 from shuujii/unify-type-of-line-number-to-uint16_t
Unify type of line number to `uint16_t`
2019-07-16 06:36:47 +09:00
Yukihiro "Matz" Matsumoto d7f9d71ea5 Merge pull request #4579 from shuujii/keep-MRB_STR_ASCII-flag-in-some-methods-of-String
Keep `MRB_STR_ASCII` flag in some methods of `String`
2019-07-16 06:35:12 +09:00
KOBAYASHI Shuji acad9567c1 Unify type of line number to uint16_t 2019-07-15 23:03:41 +09:00
KOBAYASHI Shuji 9093f3403f Add MRB_API to mrb_str_modify_keep_ascii() 2019-07-15 07:43:46 +09:00
Yukihiro "Matz" Matsumoto df293c7be1 Merge pull request #4578 from dearblue/improve-utf8len
Improve `utf8len()` performance with UTF-8
2019-07-15 05:34:12 +09:00
KOBAYASHI Shuji 380805ece2 Keep MRB_STR_ASCII flag in some methods of String 2019-07-14 19:13:19 +09:00
Yukihiro "Matz" Matsumoto 38624074e9 Merge pull request #4577 from dearblue/pack-unpack
Fix pack/unpack for base64; ref #4556
2019-07-14 18:59:41 +09:00
dearblue 7b260d9c2d Improve utf8len() performance with UTF-8 2019-07-14 18:55:38 +09:00
dearblue fd89948164 Fix empty array refers; ref #4556
For example, `"".unpack("")` evaluates to `[]`.
2019-07-14 12:03:44 +09:00
dearblue 4861be1171 Fix pack/unpack for base64; ref #4556
The pack/unpack "m" directive should be treated as a length rather than
an element count.
2019-07-14 12:03:00 +09:00
dearblue 109d926e9c Add pack/unpack test for base64 2019-07-15 10:41:32 +09:00
dearblue c96b517ea2 Error needed/conflicts configuration
The purpose is to clarify the error if there is a needed/conflicts
configuration at compile time.
2019-07-14 00:29:17 +09:00
dearblue c417c16788 Use stack memory for small name of attr accessors
Also integrated the common parts of `mrb_mod_attr_reader()` and
`mrb_mod_attr_writer()` functions.
2019-07-13 23:04:12 +09:00
Yukihiro "Matz" Matsumoto a7be9f1cab Merge pull request #4574 from shuujii/add-mruby-method-gem-to-default.gembox
Add `mruby-method` gem to `default.gembox` [ci skip]
2019-07-13 21:11:45 +09:00
KOBAYASHI Shuji e8a84d663f Add mruby-method gem to default.gembox [ci skip] 2019-07-13 20:42:32 +09:00
Yukihiro "Matz" Matsumoto b4cdced22f Enumerable#detect {and #find} should call ifnone; fix #4484
It's an error in ISO specification; 15.3.2.2.4 and 15.3.2.2.7
2019-07-13 18:05:01 +09:00
Yukihiro "Matz" Matsumoto a9fd2e6464 Resolve ambiguous argument warning. 2019-07-13 13:16:30 +09:00
Yukihiro "Matz" Matsumoto 9741df100b Change type of a variable for signedness mismatch; ref #4573 2019-07-13 13:13:21 +09:00
Yukihiro "Matz" Matsumoto 6b1cc6e2fe Avoid mrb_funcall() if possible using mrb_Float(); ref #4555 2019-07-13 12:54:02 +09:00
Yukihiro "Matz" Matsumoto c902e30494 Merge pull request #4571 from shuujii/consider--MP-flag-specified-when-parsing-.d-file
Consider `-MP` flag specified when parsing `.d` file
2019-07-12 21:46:35 +09:00
Yukihiro "Matz" Matsumoto 1556371370 Merge pull request #4573 from dearblue/fix-4569
Fix heap buffer overflow; fix #4569
2019-07-12 21:46:02 +09:00
dearblue bde2f35a9f Fix heap buffer overflow; fix #4569 2019-07-12 21:23:55 +09:00
Yukihiro "Matz" Matsumoto 54712c0624 Merge pull request #4572 from shuujii/lazy-load-tasks-toolchains
Lazy load `tasks/toolchains/*.rake`
2019-07-12 19:01:58 +09:00
KOBAYASHI Shuji 16e4657acd Lazy load tasks/toolchains/*.rake 2019-07-12 18:35:20 +09:00
KOBAYASHI Shuji 66909dfe86 Consider -MP flag specified when parsing .d file
`-MP` flag is used in `tasks/toolchains/android.rake`.
2019-07-12 14:23:35 +09:00
Yukihiro "Matz" Matsumoto c5f0a0256b Merge pull request #4569 from dearblue/improve-string-index
Improve performance `String#index` with UTF-8
2019-07-12 01:47:50 +09:00
dearblue e4249b1b9e Add UTF-8 test for String#index 2019-07-11 22:09:16 +09:00
dearblue 8c0d9ba1a3 Improve performance String#index with UTF-8
Based on Boyer-Moore-Horspool algorithm (Quick Search algorithm).

As a side effect, the correct position is returned even if an invalid UTF-8
string is given.

```console
% ./mruby@master -e 'p ("\xd1" * 100 + "#").index("#")'
50
% ./mruby@improve-index -e 'p ("\xd1" * 100 + "#").index("#")'
100
```

The other behavior should be the same as the current implementation.
2019-07-11 22:09:15 +09:00
Yukihiro "Matz" Matsumoto 5420895bcb Merge pull request #4568 from shuujii/remove-an-unused-argument-of-str_with_class
Remove an unused argument of `str_with_class()`
2019-07-10 22:33:38 +09:00
KOBAYASHI Shuji 80f78ca196 Remove an unused argument of str_with_class() 2019-07-10 21:53:17 +09:00
Yukihiro "Matz" Matsumoto bc7c5d376a Merge pull request #4562 from shuujii/set-MRB_STR_ASCII-flag-when-an-inline-symbol-is-stringized
Set `MRB_STR_ASCII` flag when an inline symbol is stringized
2019-07-09 21:22:15 +09:00
KOBAYASHI Shuji 23fc3339ee Set MRB_STR_ASCII flag when an inline symbol is stringized 2019-07-09 18:59:00 +09:00
Yukihiro "Matz" Matsumoto 59a76d48f8 Merge pull request #4560 from lopopolo/range-max-min-hang
Specialize Enumerable#max and Enumerable#min for Range
2019-07-09 18:44:53 +09:00
Ryan Lopopolo 3b77b5fd39 Revert Float dependency in Range#each 2019-07-09 02:08:14 -07:00
Ryan Lopopolo 56929362f5 Fix Range#min fast path with exclusive range 2019-07-09 01:48:15 -07:00
Ryan Lopopolo 0ad5ba7a0f Add a fast path for Float and Fixnum ranges for Range#max and Range#min
If no block is given and the Range has Fixnum or Float endpoints, do not iterate with
each and instead compare the endpoints directly. This implementation passes all of
the applicable specs from Ruby Spec.
2019-07-09 01:42:40 -07:00
Ryan Lopopolo eab07daf92 Add Range#max and Range#min tests from Ruby Spec 2019-07-09 01:41:10 -07:00
Ryan Lopopolo d9c5303793 Remove attempt at spec-compliant Range#max and Range#min from core 2019-07-09 01:40:44 -07:00
Yukihiro "Matz" Matsumoto 9add4a66c0 Merge pull request #4561 from shuujii/fix-the-order-of-expected-and-actual-in-test-t-range.rb
Fix the order of "expected" and "actual" in `test/t/range.rb`
2019-07-09 16:41:32 +09:00
Ryan Lopopolo 4085709ae1 Specialize Enumerable#max and Enumerable#min for Range
This patch prevents a hang for pathalogical (large) Ranges when
computing max and min.

Range inherits its implementation of max and min from Enumerable.
Enumerable implements max and min by calling each. For Range objects,
this is unnecessary since we know the max and the min by the end and
begin attributes.

It is also very slow. This code hangs unnecessarily:

    (0..2**32).max
    # ... hang
    (0..2**32).min
    # ... hang

This patch overrides max and min after including enumerable to yield
based on the begin and end methods.
2019-07-08 22:36:24 -07:00
Ryan Lopopolo 469c6261c6 Add tests for String Ranges
Range#each depends on String#upto which is implemented in mruby-string-ext
which is why these tests live there.
2019-07-08 22:36:24 -07:00
Ryan Lopopolo f7d59dfe23 Add tests for Range#max and Range#min 2019-07-08 22:36:24 -07:00
KOBAYASHI Shuji c8a7d0ab95 Fix the order of "expected" and "actual" in test/t/range.rb 2019-07-09 13:13:13 +09:00
Yukihiro "Matz" Matsumoto 0484bf133b Merge pull request #4559 from shuujii/add-macros-for-inline-symbol-for-readability
Add macros for inline symbol for readability
2019-07-09 09:25:54 +09:00
KOBAYASHI Shuji 0a79486380 Add macros for inline symbol for readability 2019-07-08 22:14:23 +09:00
Yukihiro "Matz" Matsumoto fd4e37404b Merge pull request #4557 from shuujii/fix-Numeric-step-to-infinity
Fix `Numeric#step` to infinity; ref. #4555
2019-07-08 18:50:28 +09:00
KOBAYASHI Shuji 32c2aa10c7 Fix Numeric#step to infinity; ref. #4555 2019-07-07 22:10:32 +09:00
Yukihiro "Matz" Matsumoto 519f396365 Merge pull request #4554 from shuujii/fix-missing--ifndef-MRB_ENABLE_ALL_SYMBOLS
Fix missing `#ifndef MRB_ENABLE_ALL_SYMBOLS`
2019-07-06 21:09:13 +09:00
KOBAYASHI Shuji df1f1002d9 Fix missing #ifndef MRB_ENABLE_ALL_SYMBOLS 2019-07-06 19:55:37 +09:00
Yukihiro "Matz" Matsumoto 280a83f029 Merge pull request #4553 from shuujii/read-write-MRB_STR_ASCII-flag-only-when-MRB_UTF8_STRING-is-defined
Read/write `MRB_STR_ASCII` flag only when `MRB_UTF8_STRING` is defined
2019-07-06 07:30:06 +09:00
KOBAYASHI Shuji f9bf2d9d8e Read/write MRB_STR_ASCII flag only when MRB_UTF8_STRING is defined 2019-07-05 22:19:31 +09:00
Yukihiro "Matz" Matsumoto 8294ce9fd4 It was too early to check key for undef; ref #4534 2019-07-04 23:11:57 +09:00
Yukihiro "Matz" Matsumoto 991bdd4ed7 Rename MRB_STR_NO_UTF to 'MRB_STR_ASCII`; close #4550
In #4550, @shuuji proposed the name name `MRB_STR_NO_MULTI_BYTE` for
more precise description. Although I agree that the name name is
correct, but the flag means the string does not contain multi byte UTF-8
characters, i.e. all characters fit in the range of ASCII.
2019-07-04 23:07:18 +09:00
Yukihiro "Matz" Matsumoto f4f3ced955 Merge pull request #4551 from dearblue/fix-4549
Fix heap buffer overflow; ref #4549
2019-07-04 22:50:06 +09:00
dearblue 2bb30481b6 Fix heap buffer overflow; ref #4549
This patch is showed in #4549.
2019-07-04 21:49:07 +09:00
Yukihiro "Matz" Matsumoto 93b3b83cc4 Merge pull request #4548 from shuujii/refine-document-to-mrb_get_args
Refine document to mrb_get_args()` [ci skip]
2019-07-04 01:49:00 +09:00
KOBAYASHI Shuji d915261590 Refine document to mrb_get_args()` [ci skip] 2019-07-03 20:41:30 +09:00
Yukihiro "Matz" Matsumoto 8c29b5998f Merge pull request #4546 from shuujii/fix-and-refine-error-message-in-mrb_obj_to_sym
Fix and refine error message in `mrb_obj_to_sym()`
2019-07-02 19:55:42 +09:00
KOBAYASHI Shuji 0d54dbb264 Fix and refine error message in mrb_obj_to_sym()
Before this patch:

  $ bin/mruby -e '1.respond_to?(2)'  #=> nil is not a symbol

After this patch (same as Ruby):

  $ bin/mruby -e '1.respond_to?(2)'  #=> 2 is not a symbol nor a string
2019-07-02 19:41:40 +09:00
Yukihiro "Matz" Matsumoto 38a10e8a98 Merge pull request #4545 from shuujii/remove-unused-C-header-file-from-src-etc.c
Remove unused C header file from `src/etc.c`
2019-07-02 00:20:37 +09:00
KOBAYASHI Shuji 7e3a8b7a75 Remove unused C header file from src/etc.c 2019-07-01 12:29:02 +09:00
Yukihiro "Matz" Matsumoto 8f19d516f9 Merge pull request #4544 from shuujii/fix-include-prepend-and-extend-to-frozen-object
Fix `include`, `prepend` and `extend` to frozen object
2019-06-30 16:29:55 +09:00
KOBAYASHI Shuji 97c9e6b000 Fix include, prepend and extend to frozen object 2019-06-30 15:06:39 +09:00
Yukihiro "Matz" Matsumoto cf69724083 Merge pull request #4540 from dearblue/assert-nesting
Nested `assert` for mrbtest
2019-06-29 21:38:32 +09:00
Yukihiro "Matz" Matsumoto ff5ec824fd Merge pull request #4541 from dearblue/replace-string-aset
Replace `String#[]=` method by C implements
2019-06-29 21:36:48 +09:00
dearblue 0ad1cacff3 Simplify mrb_str_aref_m() and mrb_str_aref()
It is integration with part of argument parsing used in `mrb_str_aset_m()`.
2019-06-29 14:41:43 +09:00
dearblue 0d452073f4 Replace String#[]= method by C implements
The purpose is to eliminate string objects that are temporarily created during processing.
2019-06-29 14:41:43 +09:00
dearblue 40030a5dbc Add test for String#[]= 2019-06-29 14:41:43 +09:00
dearblue a215292b6a Use nested assert 2019-06-29 11:54:17 +09:00
dearblue 1b9f949f36 Use a normal method instead of a lambda
Ref commit 35319bed01
2019-06-29 11:54:17 +09:00
dearblue 5f9034e428 Nested assert for mrbtest
When nesting `assert` used in test, it is indented and displayed.
Assertion numbers are concatenated by `"-"` at this time.

The purpose is to match the apparent numbers when failing with `assert_mruby`
which is defined by `mrbgems/mruby-bin-mruby/bintest/mruby.rb` for example.

Child assertions "skip" and "info" are reported as parent assertions "info"
and `$ok_test += 1`. The child assertions "ko" and "crash" are reported as the
parent assertion "ko" and `$ko_test += 1`.

When child assertions are mixed, "ko" takes precedence.

Incompatibility:

- `$mrbtest_assert_idx` takes `nil` or an integer array object.
  So far it was `nil` or an integer.
- `$asserts` points to the top of the internal stack in the `assert`.
- `$mrbtest_assert` points to the top of the internal stack in `assert`.
2019-06-29 11:54:10 +09:00
Yukihiro "Matz" Matsumoto 4f4e240024 Merge pull request #4538 from shuujii/use-__ENCODING__-in-tests
Use `__ENCODING__` in tests
2019-06-28 20:08:52 +09:00
Yukihiro "Matz" Matsumoto cf7a2292f3 Merge pull request #4539 from shuujii/remove-unnecessary-backticks-in-src-range.c
Remove unnecessary backticks in `src/range.c`; ref #2858
2019-06-28 20:07:34 +09:00
KOBAYASHI Shuji c9a3867ff2 Remove unnecessary backticks in src/range.c; ref #2858 2019-06-28 19:27:58 +09:00
KOBAYASHI Shuji bc3176da63 Use __ENCODING__ in tests
It cannot be used for `String#size` test if judging whether or not `MRB_UTF8_STRING` is defined by result of `String#size`.
2019-06-28 19:26:29 +09:00
Yukihiro "Matz" Matsumoto dc03bea854 Merge pull request #4535 from shuujii/add-modification-tests-for-immediate-value
Add modification tests for immediate value
2019-06-28 08:32:23 +09:00
Yukihiro "Matz" Matsumoto 051cb9ca37 Merge pull request #4536 from komainu8/fix_broken_links
Fix broken links for mruby.org
2019-06-28 08:23:50 +09:00
Yasuhiro Horimoto 5727d3a30c Fix broken links for mruby.org
A part of a fix for issue mruby/mruby.github.io#50
2019-06-27 22:31:25 +09:00
KOBAYASHI Shuji ad8473bd66 Add modification tests for immediate value 2019-06-27 18:47:48 +09:00
Yukihiro "Matz" Matsumoto 23783a4430 Skip copying delete keys in a hash; fix #4534 2019-06-27 09:35:58 +09:00
Yukihiro "Matz" Matsumoto 9bc7edd673 Merge pull request #4533 from shuujii/silence-unused-label-warnings
Silence unused label warnings from gcc; ref #4524
2019-06-26 15:57:44 +09:00
KOBAYASHI Shuji 28c510cf41 Silence unused label warnings from gcc; ref #4524
mruby/mruby/src/string.c:1722:4: warning: label 'bytes' defined but not used [-Wunused-label]
      bytes:
      ^~~~~
2019-06-26 15:38:20 +09:00
Yukihiro "Matz" Matsumoto 014f928229 Merge pull request #4524 from dearblue/reverse-utf8
Change to UTF-8 string reversing with in place
2019-06-26 13:22:42 +09:00
Yukihiro "Matz" Matsumoto 84779f0170 Merge pull request #4532 from shuujii/fix-String-byteslice-with-MRB_UTF8_STRING-and-some-edge-cases
Fix `String#byteslice` with `MRB_UTF8_STRING` and some edge cases
2019-06-26 12:41:56 +09:00
Yukihiro "Matz" Matsumoto a5b005b57c Merge pull request #4493 from dearblue/fix-rational-new
Fix rational new on 32 bits mode
2019-06-26 08:06:06 +09:00
Yukihiro "Matz" Matsumoto 45c99155d8 Merge pull request #4492 from dearblue/fix-complex-new
Fix complex new on 32 bits mode
2019-06-26 07:40:38 +09:00
KOBAYASHI Shuji 75df13a973 Fix String#byteslice with MRB_UTF8_STRING and some edge cases
Example:

  $ bin/mruby -e '
    p "あa".byteslice(1)
    p "bar".byteslice(3)
    p "bar".byteslice(4..0)
  '

  Before this patch:

    "a"
    ""
    RangeError (4..0 out of range)

  After this patch (same as Ruby):

    "\x81"
    nil
    nil
2019-06-25 23:09:23 +09:00
Yukihiro "Matz" Matsumoto f268ecaf0d Merge pull request #4516 from shuujii/fix-struct-RRange-overflow-on-32-bit-CPU-with-MRB_NAN_BOXING
Fix `struct RRange` overflow on 32-bit CPU with `MRB_NAN_BOXING`
2019-06-25 22:44:31 +09:00
Yukihiro "Matz" Matsumoto a4124a3113 Merge pull request #4517 from shuujii/remove-unneeded-statement-in-SET_OBJ_VALUE-with-boxing_word.h
Remove unneeded statement in `SET_OBJ_VALUE` with `boxing_word.h`
2019-06-25 20:32:39 +09:00
Yukihiro "Matz" Matsumoto e59a80c787 Merge pull request #4528 from shuujii/fix-argument-specs-to-Array
Fix argument specs to `Array`
2019-06-25 20:27:26 +09:00
Yukihiro "Matz" Matsumoto d4c9eff67b Merge pull request #4530 from shuujii/compare-obj-pointer-directly-instead-of-using-mrb_obj_eq-in-mrb_gc_unregister
Compare obj pointer directly instead of using mrb_obj_eq in mrb_gc_unregister
2019-06-25 18:50:46 +09:00
Yukihiro "Matz" Matsumoto 63d8b5e1e3 Fixed mrb_iv_remove with immediate objects; fix #4519
The #4520 tried to address the issue, but it changes the type of
`mrb_check_frozen` argument; close #4520
2019-06-25 18:41:17 +09:00
Yukihiro "Matz" Matsumoto 6724416d5c Fixed a bug caused by to_s that returns nil; fix 4504 2019-06-25 18:07:48 +09:00
Yukihiro "Matz" Matsumoto dc21024ec7 Fix mrb_str_to_str() to handle symbols. 2019-06-25 18:07:48 +09:00
Yukihiro "Matz" Matsumoto ace0c76a69 Renamed stacked to onstack; ref #4523 2019-06-25 18:07:48 +09:00
Ryan Lopopolo 46c972f746 Unify loops to minimize bytecode size 2019-06-25 00:01:51 +02:00
KOBAYASHI Shuji f71270df77 Compare obj pointer directly instead of using mrb_obj_eq in mrb_gc_unregister
Because immediate values are not registered.
2019-06-24 18:55:05 +09:00
KOBAYASHI Shuji 1fd08aee15 Fix argument specs to Array 2019-06-23 20:01:33 +09:00
Ryan Lopopolo 6b92acf361 Use explicit block parameter 2019-06-23 03:40:39 +01:00
Ryan Lopopolo 8ea45b862a Optimize String#each_line 2019-06-23 03:29:47 +01:00
Yukihiro "Matz" Matsumoto cb3ee2d050 Merge pull request #4526 from shuujii/refine-Hash-rehash-example
Refine `Hash#rehash` example [ci skip]
2019-06-23 10:56:41 +09:00
Yukihiro "Matz" Matsumoto af9637e545 Merge pull request #4523 from dearblue/use-stack
Use stack memory for small name of Struct members
2019-06-23 10:51:34 +09:00
Yukihiro "Matz" Matsumoto 36f1c26d9d Merge pull request #4525 from dearblue/utf8len-overflow
Fix potential overflow in `utf8len()`
2019-06-23 10:50:19 +09:00
dearblue 11e09dc5db Fix the unnecessary mrb_str_modify() call
Now to be calls `mrb_str_modify()` only once when 2 or more characters.
2019-06-22 23:09:36 +09:00
dearblue ec03e3f54a Delete the unnecessary block brace in mrb_str_reverse_bang 2019-06-22 23:02:29 +09:00
dearblue 567075aab9 Fix string brakes for one UTF-8 charactor 2019-06-22 22:58:18 +09:00
dearblue 5af8a9777b Add test for one UTF-8 charactor 2019-06-22 22:58:08 +09:00
dearblue bd2c93c2df Change to UTF-8 string reversing with in place
Reverses UTF-8 strings without allocated heap for working memory.

 1. String before reversing:
    ```
    "!yburmの界世"
    # byte unit
    [33, 121, 98, 117, 114, 109, 227, 129, 174, 231, 149, 140, 228, 184, 150]
    ```
 2. Reverse the byte order of each character:
    ```
    [33, 121, 98, 117, 114, 109, 174, 129, 227, 140, 149, 231, 150, 184, 228]
    ```
 3. Reverse the whole byte order and complete:
    ```
    [228, 184, 150, 231, 149, 140, 227, 129, 174, 109, 114, 117, 98, 121, 33]
    # string
    "世界のmruby!"
    ```
2019-06-22 22:36:58 +09:00
dearblue 7c6d6effae Replacement to function for string reversing 2019-06-22 22:36:58 +09:00
Ryan Lopopolo a932b8c96a Speed up base case by 2x
Make non-paragraph mode twice as fast. Performance is within a factor of 2
of the original implementation.
2019-06-22 12:55:02 +01:00
Ryan Lopopolo 0f516bbe1d Add paragraph mode to String#each_line in mrblib
mruby/mruby#4511 demonstrated an infinite loop in `String#each_line` when
given an empty string separator. In MRI, an empty separator places
String#each_line in paragraph mode, where the String is separated on
successive runs of newlines. In paragraph mode, the String
`"abc\n\n\ndef\nxyz"` is split into `["abc\n\n\n", "def\nxyz"]`.

This commit makes the String#each_line implementation as close to
ruby/spec compliant as possible given the limitations of mruby core.
With this patch, the following specs fail for `String#each_line`:

- uses `$/` as the separator when none is given (can be fixed by
  aliasing and redefining the method to use $/ as the default value
  of separator in mruby-io)
- when no block is given returned Enumerator size should return nil
  (`Enumerator#size` is not supported on mruby)
- tries to convert the separator to a string using to_str (`String#to_str`
  is not implemented on mruby)

This patch has similar memory consumption compared to the prior
implementation and is takes 4x the time the prior implementation takes to
execute:

```console
/usr/bin/time -l ./bin/mruby -e '("aaa\n\nbbbbb\n\n\n\n\ncccc" * 100000).each_line("\n") { }';
```
2019-06-22 12:31:01 +01:00
KOBAYASHI Shuji 28de6b0da1 Refine Hash#rehash example [ci skip]
Previous example doesn't work because string key (frozen) can't be modified.
2019-06-22 19:07:01 +09:00
dearblue 7583539029 Fix potential overflow in utf8len()
For example on 32 bit mode, when `p = 0xfffffffd`, `e = 0xfffffffe`
and `len = 4`, the sum of `p` and `len` can be to `1`, and comparison
with `e` will to be false.

As a result, a segmentation fault occurs by referring to address 0.
2019-06-22 18:16:38 +09:00
Yukihiro "Matz" Matsumoto f94551ad40 Merge pull request #4518 from shuujii/add-ISO-section-number-to-Kernel-local_variables
Add ISO section number to `Kernel.#local_variables` [ci skip]
2019-06-22 17:52:32 +09:00
dearblue a76da32567 Use stack memory for small name of Struct members 2019-06-22 17:49:07 +09:00
Yukihiro "Matz" Matsumoto f13c5969eb Merge pull request #4521 from shuujii/move-Kernel-__send__-test-to-core-from-mruby-metaprog
Move `Kernel#__send__` test to core from `mruby-metaprog`
2019-06-22 16:14:44 +09:00
KOBAYASHI Shuji c43ff6fa40 Move Kernel#__send__ test to core from mruby-metaprog 2019-06-21 22:02:29 +09:00
KOBAYASHI Shuji 77996e6adc Add ISO section number to Kernel.#local_variables [ci skip] 2019-06-20 19:59:56 +09:00
KOBAYASHI Shuji 4d9d6faf0d Remove unneeded statement in SET_OBJ_VALUE with boxing_word.h
`(r).value.bp` and `v` have the same value due to assignment of the line
preceding the removed line.
2019-06-19 17:50:20 +09:00
Yukihiro "Matz" Matsumoto c53b7cedcc Merge pull request #4510 from shuujii/remove-unneeded-mrb_str_dup-in-Module-name
Remove unneeded `mrb_str_dup()` in `Module#name`
2019-06-19 08:50:14 +09:00
Yukihiro "Matz" Matsumoto 791391cf5b Merge pull request #4514 from mimaki/fix-error.h
Fix path of `error.h`.
2019-06-19 07:58:57 +09:00
KOBAYASHI Shuji 81828f8b08 Fix struct RRange overflow on 32-bit CPU with MRB_NAN_BOXING 2019-06-18 18:17:03 +09:00
Hiroshi Mimaki b630bf59ef Fix path of error.h. 2019-06-18 13:27:16 +09:00
Ryan Lopopolo eeb7d3a04f Support parsing a Regexp literal with 'o' option
CRuby supports a 'o' `Regexp` option for `Regexp` literals, e.g. `/foo/o` that disables multiple interpolation passes.

This commit adds support for parsing such literals. Nothing is done with the option, it is consumed and ignored by the parser.
2019-06-17 21:42:19 +01:00
KOBAYASHI Shuji faec8331b7 Remove unneeded mrb_str_dup() in Module#name
`mrb_class_path()` always returns a new string or `nil`.
2019-06-17 21:46:30 +09:00
Yukihiro "Matz" Matsumoto 1685c459dd Merge pull request #4508 from shuujii/fix-cvar-ivar-const-and-method-can-be-removed-to-frozen-object
Fix cvar, ivar, const and method can be removed to frozen object
2019-06-17 12:22:33 +09:00
Yukihiro "Matz" Matsumoto e514264b53 Merge pull request #4507 from shuujii/fix-index-in-error-message-of-Struct-aref
Fix index in error message of `Struct#[]`
2019-06-17 12:21:48 +09:00
Yukihiro "Matz" Matsumoto 0fba500826 Fixed indentation in parse.y 2019-06-17 12:18:57 +09:00
Yukihiro "Matz" Matsumoto 4296c77e29 Allow newlines and comments between method calls. 2019-06-17 12:18:57 +09:00
Yukihiro "Matz" Matsumoto 4124047cce Support &. at the beginning of the line. 2019-06-17 12:18:57 +09:00
Yukihiro "Matz" Matsumoto d895c5fe5a Fixed wrong behavior on .. at the beginning of the line. 2019-06-17 12:18:57 +09:00
Yukihiro "Matz" Matsumoto c1901539a8 Merge pull request #4502 from shuujii/adjust-allocation-size-in-mrb_id_attrset-mruby-struct
Adjust allocation size in `mrb_id_attrset()` (`mruby-struct`)
2019-06-17 12:18:48 +09:00
KOBAYASHI Shuji 030dd6655e Fix cvar, ivar, const and method can be removed to frozen object 2019-06-16 20:43:23 +09:00
KOBAYASHI Shuji 9e378b451f Fix index in error message of Struct#[]
Before this patch:

  $ bin/mruby -e 'Struct.new(:a,:b).new[-3]'
  #=> offset -1 too small for struct(size:2) (IndexError)

After this patch (same as Ruby):

  $ bin/mruby -e 'Struct.new(:a,:b).new[-3]'
  #=> offset -3 too small for struct(size:2) (IndexError)
2019-06-15 19:41:04 +09:00
Yukihiro "Matz" Matsumoto ab5ffb308b Merge pull request #4506 from shuujii/remove-a-meaningless-branch-condition-in-mruby-struct
Remove a meaningless branch condition in `mruby-struct`
2019-06-14 13:42:58 +09:00
KOBAYASHI Shuji 6084048b28 Remove a meaningless branch condition in mruby-struct
The following branch condition is always true:

  // mrbgems/mruby-struct/src/struct.c:187 in make_struct_define_accessors()
  if (is_local_id(mrb, name) || is_const_id(mrb, name)) {
2019-06-14 10:26:19 +09:00
Yukihiro "Matz" Matsumoto 27109d1ae0 Merge pull request #4505 from shuujii/fix-class-name-validation-in-Struct.new
Fix class name validation in `Struct.new`
2019-06-14 06:22:57 +09:00
KOBAYASHI Shuji 9bd692bc67 Fix class name validation in Struct.new
Before this patch:

  $ bin/mruby -e 'p Struct.new("A-")'
  #=> Struct::"A-"

After this patch:

  $ bin/mruby -e 'p Struct.new("A-")'
  #=> NameError: identifier A- needs to be constant
2019-06-13 21:24:48 +09:00
Yukihiro "Matz" Matsumoto 1a98b94100 Merge pull request #4500 from shuujii/kernel-global_variables-should-not-include-undefined-gvar
`Kernel#global_variables` should not include undefined `$1`-`$9`
2019-06-13 10:24:45 +09:00
Yukihiro "Matz" Matsumoto e2e312dbfc Merge pull request #4503 from shuujii/fix-typo-in-String-setbyte-error-message
Fix typo in `String#setbyte` error message
2019-06-13 10:24:11 +09:00
KOBAYASHI Shuji db3e6f6ac6 Fix typo in String#setbyte error message 2019-06-12 20:45:27 +09:00
KOBAYASHI Shuji ee955b58f7 Adjust allocation size in mrb_id_attrset() (mruby-struct) 2019-06-12 18:52:58 +09:00
Yukihiro "Matz" Matsumoto b8d8f8fdae Merge pull request #4501 from shuujii/remove-redundant-colon-in-Proc-inspect-mruby-proc-ext
Remove redundant colon in `Proc#inspect` (`mruby-proc-ext`)
2019-06-11 20:53:39 +09:00
KOBAYASHI Shuji 3b9b326d3c Remove redundant colon in Proc#inspect (mruby-proc-ext)
Before this patch:

  $ bin/mruby -e 'p proc{}'  #=> #<Proc:0x7fd5eb8206d0@-e::1>

After this patch:

  $ bin/mruby -e 'p proc{}'  #=> #<Proc:0x7fd5eb8206d0@-e:1>
2019-06-11 20:33:07 +09:00
Yukihiro "Matz" Matsumoto 313059d08c Merge pull request #4496 from dearblue/replace-obsolete
Replace obsolete macros
2019-06-11 09:36:15 +09:00
KOBAYASHI Shuji 38f1da6f26 Kernel#global_variables should not include undefined $1-$9
- They are not include in Ruby.
- Appear in duplicate when `$1`-`$9` are defined.
2019-06-10 18:46:57 +09:00
Yukihiro "Matz" Matsumoto 04999e969f Merge pull request #4495 from shuujii/remove-Kernel-global_variables-from-core
Remove `Kernel#global_variables` from core
2019-06-10 15:42:33 +09:00
Yukihiro "Matz" Matsumoto 7cfa4d6011 Merge pull request #4494 from shuujii/clarify-mruby-kernel-object-ext-gem-summary
Clarify `mruby-(kernel|object)-ext` gem summary; ref 8e637bdd [ci skip]
2019-06-10 15:40:41 +09:00
Yukihiro "Matz" Matsumoto a9e94d43b3 Merge pull request #4499 from shuujii/fix-missing-assertions-in-test-t-syntax.rb
Fix missing assertions in `test/t/syntax.rb`
2019-06-10 15:39:56 +09:00
KOBAYASHI Shuji ffb700dea0 Fix missing assertions in test/t/syntax.rb 2019-06-09 18:27:28 +09:00
Yukihiro "Matz" Matsumoto a7ae278d1a Merge pull request #4497 from shuujii/remove-Check-the-usage-of-a-NUL-character-test
Remove "Check the usage of a NUL character" test
2019-06-09 07:57:51 +09:00
KOBAYASHI Shuji 2e160f53db Remove "Check the usage of a NUL character" test
Because there is not assertion in this test and NUL character literal is
used in other tests.
2019-06-08 22:32:19 +09:00
dearblue f8f75fc9c6 Replace obsolete macros 2019-06-07 22:54:03 +09:00
KOBAYASHI Shuji 4b83fe8b04 Remove Kernel#global_variables from core
This method is defined in `mruby-metaprog` gem.
2019-06-07 22:02:43 +09:00
KOBAYASHI Shuji 05493e651d Clarify mruby-(kernel|object)-ext gem summary; ref 8e637bdd [ci skip] 2019-06-06 20:21:40 +09:00
dearblue 64b3d452ec Drop precisions for rational when big numbers 2019-06-05 23:25:28 +09:00
dearblue 5e69760d91 Fix build error if struct mrb_rational is bigger than RIStruct
In that case, to be switched implementation with `RData`.

It is based to "complex".
2019-06-05 23:25:23 +09:00
dearblue 82831c6acd Fix not frozen in Complex method by RData
Object allocation was separated, and initialization was made common.
2019-06-05 23:19:16 +09:00
dearblue 97e999c409 Fix memory leak in Complex method by RData
If `Data_Wrap_Struct()` raises a `NoMemoryError` exception,
it will leak memory if it does `mrb_malloc()` first.
2019-06-05 23:19:16 +09:00
Yukihiro "Matz" Matsumoto 2847692d59 Merge pull request #4491 from shuujii/fix-missing-assertions-in-test-t-module.rb
Fix missing assertions in `test/t/module.rb`
2019-06-05 23:10:36 +09:00
KOBAYASHI Shuji dc1905e1bd Fix missing assertions in test/t/module.rb 2019-06-05 19:13:36 +09:00
Yukihiro "Matz" Matsumoto 913a148ddc Merge pull request #4489 from shuujii/fIx-typo-in-mrblib-range.rb
Fix typo in `mrblib/range.rb` [ci skip]
2019-06-05 01:46:58 +09:00
Yukihiro "Matz" Matsumoto d47d561da3 Merge pull request #4490 from dearblue/explicit-cast
Need explicit cast for C++
2019-06-05 01:45:37 +09:00
dearblue 81ea89f10e Need explicit cast for C++ 2019-06-04 21:41:40 +09:00
KOBAYASHI Shuji c75402a57b Fix typo in mrblib/range.rb [ci skip] 2019-06-04 10:45:13 +09:00
Yukihiro "Matz" Matsumoto 3b061a90fe Merge pull request #4485 from shuujii/fix-missing-assertions-in-mruby-objectspace-test
Fix missing assertions in `mruby-objectspace` test
2019-06-02 22:11:43 +09:00
KOBAYASHI Shuji 92f00d3e58 Fix missing assertions in mruby-objectspace test 2019-06-02 19:15:20 +09:00
Yukihiro "Matz" Matsumoto 366617dbc1 Merge pull request #4482 from shuujii/comment-out-the-empty-Array-bsearch_index-test
Comment out the empty `Array#bsearch_index` test
2019-06-01 11:02:07 +09:00
KOBAYASHI Shuji c1e6f324c2 Comment out the empty Array#bsearch_index test 2019-05-31 20:50:54 +09:00
Yukihiro "Matz" Matsumoto 4677918676 Merge pull request #4481 from shuujii/fix-missing-assertions-in-mruby-fiber-test
Fix missing assertions in `mruby-fiber` test
2019-05-30 22:34:54 +09:00
KOBAYASHI Shuji 05056ddac4 Fix missing assertions in mruby-fiber test 2019-05-30 21:42:01 +09:00
Yukihiro "Matz" Matsumoto 729931a06c Fix inverted compilation condition; fix #4478 2019-05-30 12:34:31 +09:00
Yukihiro "Matz" Matsumoto 53f93158a2 Merge pull request #4477 from shuujii/kernel-itself-should-not-be-a-module-function
`Kernel#itself` should not be a module function
2019-05-29 20:16:56 +09:00
KOBAYASHI Shuji 03fce2e206 Kernel#itself should not be a module function 2019-05-29 15:57:18 +09:00
Yukihiro "Matz" Matsumoto 855f2cdeea Slightly simplify Rational#==; ref #4475 2019-05-29 11:49:21 +09:00
Yukihiro "Matz" Matsumoto 2b81ea7ec1 Add mrb_alloca again; ref #4470
This time, the allocated memory comes from the string object, which is
referenced from GC arena. The memory region will be reclaimed when the C
function called from VM is terminated, or the GC arena is restored.
2019-05-29 11:47:12 +09:00
Yukihiro "Matz" Matsumoto a1e1af44d2 Merge pull request #4475 from shuujii/fix-Rational-eq-Complex
Fix `Rational#==(Complex)`
2019-05-29 11:46:42 +09:00
Yukihiro "Matz" Matsumoto 4b82fdb637 Merge pull request #4476 from shuujii/fix-missing-assertions-in-mruby-pack-test
Fix missing assertions in `mruby-pack` test
2019-05-29 10:35:45 +09:00
KOBAYASHI Shuji ffc915fdee Fix missing assertions in mruby-pack test 2019-05-28 18:26:01 +09:00
Yukihiro "Matz" Matsumoto 1727f0b7ff Merge pull request #4474 from shuujii/use-undefined.equal-obj2-instead-of-obj2-eq-undefined-in-assert.rb
Use `$undefined.equal?(obj2)` instead of `obj2 == $undefined` in `ass…
2019-05-28 10:50:30 +09:00
Yukihiro "Matz" Matsumoto 6c5cb109ee Merge pull request #4473 from shuujii/make-some-functions-static-in-mrbgems-mruby-metaprog-src-metaprog.c
Make some functions static in `mrbgems/mruby-metaprog/src/metaprog.c`
2019-05-27 23:32:55 +09:00
KOBAYASHI Shuji a97a455c03 Use $undefined.equal?(obj2) instead of obj2 == $undefined in assert.rb
In case `obj2.==` is broken.
2019-05-27 21:43:55 +09:00
KOBAYASHI Shuji 902b2ce3c6 Fix Rational#==(Complex)
Consider a Numreic class like `Complex` that does not have `<=>` but `==`
works (`0i == 0r` is `true`).
2019-05-27 21:29:49 +09:00
KOBAYASHI Shuji 534b578da7 Make some functions static in mrbgems/mruby-metaprog/src/metaprog.c 2019-05-27 18:26:54 +09:00
Yukihiro "Matz" Matsumoto 8ad777c702 Merge pull request #4470 from dearblue/remove-mrb_alloca
Remove `mrb_alloca()` function
2019-05-27 14:45:10 +09:00
Yukihiro "Matz" Matsumoto 459c439243 Merge pull request #4472 from shuujii/move-mrb_mod_s_nesting-to-mruby-metaprog-gem-from-the-core
Move `mrb_mod_s_nesting()` to `mruby-metaprog` gem from the core
2019-05-27 08:17:06 +09:00
Yukihiro "Matz" Matsumoto 879f1586ab Merge pull request #4471 from shuujii/add-Complex.rect
Add `Complex.rect`
2019-05-26 23:07:11 +09:00
KOBAYASHI Shuji 779251de64 Move mrb_mod_s_nesting() to mruby-metaprog gem from the core 2019-05-26 20:32:04 +09:00
KOBAYASHI Shuji 0bdb185a6f Add Complex.rect 2019-05-26 20:17:03 +09:00
Yukihiro "Matz" Matsumoto 4261ba9443 Remove some overhead from methods defined in Ruby in Complex. 2019-05-26 09:19:29 +09:00
Yukihiro "Matz" Matsumoto c33ab7c0bb Merge pull request #4469 from dearblue/double-rounds
Fix double rounded by negative index for `String#[]`
2019-05-26 09:17:40 +09:00
dearblue d1e1bb0d5b Remove mrb_alloca() function
When I found this function, I expected it to behave the same as the
`alloca(3)` function, but it is accually the `mrb_alloca()` function
does not free the heap until the `mrb_close()` function is called.

Also, even if it is deleted, it can be replaced with the combination
of the `MRB_TT_DATA` object and the `mrb_gv_set()` function if it is
sure necessary.
2019-05-25 23:59:43 +09:00
dearblue ecfca8def7 Fix double rounded by negative index
- Before patched:
  ```
  $ mruby -e 'p (-12..-1).map { |i| "Hello"[i] }.join'
  "HelloHello"
  ```
- After patched:
  ```
  $ mruby -e 'p (-12..-1).map { |i| "Hello"[i] }.join'
  "Hello"
  ```
2019-05-25 22:43:07 +09:00
Yukihiro "Matz" Matsumoto f455cb6c40 Merge pull request #4467 from dearblue/naming-mrb_range_beg_len
Name the return value of `mrb_range_beg_len()`
2019-05-25 22:25:58 +09:00
dearblue 56e0e1934d Name the return value of mrb_range_beg_len() 2019-05-25 12:12:21 +09:00
Yukihiro "Matz" Matsumoto c6f30e8f17 Merge pull request #4466 from shuujii/fix-the-order-of-expected-and-actual-in-mruby-time-test
Fix the order of "expected" and "actual" in `mruby-time` test
2019-05-25 00:12:53 +09:00
KOBAYASHI Shuji 240bbc39e1 Fix the order of "expected" and "actual" in mruby-time test 2019-05-24 21:02:22 +09:00
Yukihiro "Matz" Matsumoto 43a26aa958 Merge pull request #4463 from shuujii/freeze-Rational-and-Complex-objects
Freeze `Rational` and `Complex` objects
2019-05-23 19:54:45 +09:00
KOBAYASHI Shuji 48903850e9 Freeze Rational and Complex objects 2019-05-23 13:40:49 +09:00
Yukihiro "Matz" Matsumoto 5f4eb87735 Merge pull request #4462 from shuujii/kernel-Rational-requires-numerator
`Kernel#Rational` requires numerator
2019-05-22 20:17:11 +09:00
KOBAYASHI Shuji 8513abd404 Kernel#Rational requires numerator 2019-05-22 19:57:35 +09:00
Yukihiro "Matz" Matsumoto 85a2dfc841 Merge pull request #4403 from dearblue/read-irep-from-buf
Read irep from buffers
2019-05-22 08:58:50 +09:00
Yukihiro "Matz" Matsumoto 38f8edbdd7 Update ISO section number for some Numeric methods. 2019-05-21 21:12:33 +09:00
Yukihiro "Matz" Matsumoto c02e63eb77 Use MRB_TT_ISTRUCT for Complex numbers if possible. 2019-05-21 21:08:26 +09:00
Yukihiro "Matz" Matsumoto fccec8964a Implements part of Complex class in C. 2019-05-21 21:08:26 +09:00
Yukihiro "Matz" Matsumoto e941cf06a3 Export mrb_int_value that converts mrb_float to Fixnum.
Or `Float` if `mrb_float` value is too big (or too small) to fit in
`mrb_int`. The `_int_` in `mrb_int_value` means `Integral` module, which
represents integer-like values in mruby.
2019-05-21 21:08:26 +09:00
Yukihiro "Matz" Matsumoto f6e4145ad9 Remove Complex(string) complex generation.
It should raise an error.
2019-05-21 21:08:26 +09:00
Yukihiro "Matz" Matsumoto b7f85b9df9 Should not refer Float class in case of MRB_WITHOUT_FLOAT.
This commit removes `Float` from `rational.c`.
2019-05-21 21:08:26 +09:00
Yukihiro "Matz" Matsumoto 5d30309e98 Silence the return value warnings from gcc; ref 237a57b 2019-05-21 21:08:26 +09:00
Yukihiro "Matz" Matsumoto eca20a16bd Merge pull request #4461 from shuujii/move-comparision-methods-to-Integral-from-Numeric
Move `**`,`/`,`quo`,`div` and comparison methods to Integral from Numeric
2019-05-21 21:07:39 +09:00
KOBAYASHI Shuji 3b46831da8 Move **,/,quo,div and comparison methods to Integral from Numeric
Having these methods in Numeric can get in the way of creating subclasses of
Numeric because they only support Fixnum and Float.
2019-05-21 20:43:42 +09:00
Yukihiro "Matz" Matsumoto 24525fd1ae Merge pull request #4459 from shuujii/revert-part-of-4457
Revert part of #4457
2019-05-21 09:34:42 +09:00
KOBAYASHI Shuji 5d6c1794ad Revert part of #4457 2019-05-21 09:31:06 +09:00
Yukihiro "Matz" Matsumoto 70e754e6da Merge pull request #4457 from shuujii/change-the-order-of-expected-and-actual-in-mruby-rational-test
Change the order of "expected" and "actual" in `mruby-rational` test
2019-05-21 07:56:21 +09:00
Yukihiro "Matz" Matsumoto a642f73b44 Merge pull request #4458 from shuujii/drop-dependency-from-mruby-rational-to-mruby-object-ext
Drop dependency from `mruby-rational` to `mruby-object-ext`
2019-05-21 06:38:04 +09:00
KOBAYASHI Shuji 3db5d7fe3d Drop dependency from mruby-rational to mruby-object-ext 2019-05-20 18:36:13 +09:00
KOBAYASHI Shuji 97600ded8d Change the order of "expected" and "actual" in mruby-rational test 2019-05-20 18:24:18 +09:00
Yukihiro "Matz" Matsumoto 8b8bf9f3f6 Add new functions for numerical operation; ref 237a57b
New functions:
* mrb_num_plus(mrb, x, y)
* mrb_num_minus(mrb, x, y)
* num_num_mul(mrb, x, y)
2019-05-20 14:59:25 +09:00
Yukihiro "Matz" Matsumoto 05e7544583 Merge pull request #4455 from dearblue/remove-LINE-section
Remove "LINE" section reader
2019-05-19 22:29:25 +09:00
Yukihiro "Matz" Matsumoto e60891e453 Merge pull request #4454 from shuujii/fix-Rational-cmp-Numeric
Fix `Rational#<=>(Numeric)`
2019-05-19 22:24:49 +09:00
Yukihiro "Matz" Matsumoto 3e8b19b00e Merge pull request #4453 from shuujii/move-Kernel-instance_eval-to-BasicObject
Move `Kernel#instance_eval` to `BasicObject`
2019-05-19 22:23:57 +09:00
Yukihiro "Matz" Matsumoto aafaf79fdd Merge pull request #4452 from shuujii/move-Kernel-equal-to-BasicObject
Move `Kernel#equal? to `BasicObject`
2019-05-19 22:23:14 +09:00
Yukihiro "Matz" Matsumoto 8170f6899c Merge pull request #4450 from shuujii/move-Kernel-instance_exec-to-BasicObject
Move `Kernel#instance_exec` to `BasicObject`
2019-05-19 22:21:31 +09:00
Yukihiro "Matz" Matsumoto 8e637bdd83 Should clarify the role of mruby-kernel-ext and mruby-object-ext; close #4449
The former should contain function like methods, and the latter should
contain methods shared by all objects.
2019-05-19 22:17:56 +09:00
KOBAYASHI Shuji a6eb01837b Fix Rational#<=>(Numeric)
Reported by Sergey Ukrainskiy: https://github.com/mruby/mruby/commit/f5fb1307b017fb972c12b4ec4b1866d789b0ca09#r33590698
2019-05-19 13:52:18 +09:00
dearblue 67fc3428cb Remove "LINE" section reader
Because it is not currently output by `mrbc`.
2019-05-19 11:09:25 +09:00
KOBAYASHI Shuji 9c79c28604 Move Kernel#instance_eval to BasicObject 2019-05-18 21:17:47 +09:00
KOBAYASHI Shuji 6fb5979d29 Move Kernel#equal? to BasicObject` 2019-05-18 20:57:54 +09:00
KOBAYASHI Shuji ef5dd5d31d Move Kernel#instance_exec to BasicObject 2019-05-18 19:19:52 +09:00
Yukihiro "Matz" Matsumoto 1cdb3ec93c Merge pull request #4448 from shuujii/move-Object-Rational-Complex-to-Kernel
Move `Object#(Rational|Complex)` to `Kernel`
2019-05-18 18:57:47 +09:00
Yukihiro "Matz" Matsumoto ed70e81264 Merge pull request #4447 from shuujii/move-Numeric-__coerce_step_counter-to-Integral
Move `Numeric#__coerce_step_counter` to `Integral`
2019-05-18 18:56:39 +09:00
KOBAYASHI Shuji 6c9c189e4b Move Object#(Rational|Complex) to Kernel 2019-05-18 18:31:55 +09:00
KOBAYASHI Shuji 4f71e9eebe Move Numeric#__coerce_step_counter to Integral
This method is only used in `Integral#step`
2019-05-18 18:22:56 +09:00
Yukihiro "Matz" Matsumoto 89d2926415 Add ISO section number to Module#===. 2019-05-18 11:48:59 +09:00
Yukihiro "Matz" Matsumoto bd7328f5e6 Implement Rational._new in C. 2019-05-18 11:23:59 +09:00
Yukihiro "Matz" Matsumoto e41f15747e Rename struct RIstruct to struct RIStruct. 2019-05-18 11:10:20 +09:00
Yukihiro "Matz" Matsumoto ace0d3949b Support MRB_WITHOUT_FLOAT.
I assume there's no realistic usage of `Rational` with
`MRB_WITHOUT_FLOAT`. But just for consistency.
2019-05-18 08:38:45 +09:00
Yukihiro "Matz" Matsumoto d2a2af2481 Merge pull request #4446 from dearblue/PoC-tuning-profiles
(Proof of Concept) mruby tuning profiles [ci skip]
2019-05-17 22:45:45 +09:00
Yukihiro "Matz" Matsumoto b7bc03aa18 Stop wrapping the filename by double quotes; ref #4440 2019-05-17 22:39:41 +09:00
Yukihiro "Matz" Matsumoto 8d37a3575b Revert "Add support for CC="gcc --option ..." again"
This reverts commit d5c8868346.
2019-05-17 22:37:45 +09:00
dearblue a14ae80102 (Proof of Concept) mruby tuning profiles [ci skip]
Not only mruby, it is one of the difficult things to adjust the performance vs. memory efficiency of the software.
If the approximate target device is divided and the adjustment value for it is prepared by default, it is a good indicator to do fine adjustment.

This PR divides into four profiles.

***Caution: There is no basis for the definitions in the patch.***

- `MRB_CONSTRAINED_BASELINE_PROFILE` - for microprocessors. Reduce memory consumption.
- `MRB_BASELINE_PROFILE` - Default value of mruby.
- `MRB_MAIN_PROFILE` - For desktop computers. Assume that a huge amount of RAM, 10 MiB or more, is on board.
- `MRB_HIGH_PROFILE` - for servers. Assume that mruby VM has a long life.

As you can see the profile name has been ~~stolen~~ imitated from H.264.
2019-05-17 22:32:01 +09:00
Yukihiro "Matz" Matsumoto a46da9e44d Merge pull request #4445 from bshastry/modifiy-ossfuzz-fork-config
Add/Edit ossfuzz config options
2019-05-17 21:31:09 +09:00
Yukihiro "Matz" Matsumoto 132c04bcc8 Merge pull request #4443 from shuujii/move-Integral-zero-nonzero-positive-negative-to-Numeric
Move `Integral#(zero|nonzero|positive|negative)?` to `Numeric`
2019-05-17 21:30:39 +09:00
Yukihiro "Matz" Matsumoto 4572d42d07 Merge pull request #4444 from bshastry/mruby-proto
proto fuzzer: Add source files necessary to compile proto fuzzer
2019-05-17 21:30:20 +09:00
Bhargava Shastry 1f3ece9631 proto fuzzer: Add source files necessary to compile proto fuzzer 2019-05-17 14:28:20 +02:00
Yukihiro "Matz" Matsumoto eecac4f18b Merge pull request #4442 from shuujii/drop-dependency-from-mruby-rational-to-mruby-numeric-ext
Drop dependency from `mruby-rational` to `mruby-numeric-ext`
2019-05-17 21:27:47 +09:00
Yukihiro "Matz" Matsumoto 6558d51b50 Merge pull request #4441 from shuujii/fix-Numeric-to_r
Fix `Numeric#to_r`
2019-05-17 21:26:48 +09:00
Bhargava Shastry 647569bfe8 Add/Edit ossfuzz config options 2019-05-17 14:26:41 +02:00
Yukihiro "Matz" Matsumoto ed0a5f9e16 Merge pull request #4440 from kou/cc-with-option
Add support for CC="gcc --option ..." again
2019-05-17 21:26:00 +09:00
KOBAYASHI Shuji c5c39f585b Move Integral#(zero|nonzero|positive|negative)? to Numeric
Because these methods work if object is `Comparable`, and `Numeric` is
`Comparable`.
2019-05-17 21:13:31 +09:00
KOBAYASHI Shuji aa41a5c9af Drop dependency from mruby-rational to mruby-numeric-ext 2019-05-17 20:44:48 +09:00
KOBAYASHI Shuji eeb95e058a Fix Numeric#to_r 2019-05-17 19:53:31 +09:00
Kouhei Sutou d5c8868346 Add support for CC="gcc --option ..." again
If $rake_root_fiber is used, sh runs command in another Fiber. If
command is ran in another Fiber, "rescue RuntimEerror" can't rescue
exception for system(...) failure.

How to reproduce:

    $ CC="gcc -std=gnu99" ./minirake
    (in /home/kou/work/ruby/mruby.kou)
    CC    mrbgems/mruby-compiler/core/codegen.c -> build/test/mrbgems/mruby-compiler/core/codegen.o
    sh: 1: gcc -std=gnu99: not found
    rake aborted!
    Command Failed: ["gcc -std=gnu99" -g -std=gnu99 ...]
2019-05-17 17:59:24 +09:00
Yukihiro "Matz" Matsumoto b6e9fab649 Implement part of Rational in C. 2019-05-17 16:37:34 +09:00
Yukihiro "Matz" Matsumoto cec92673ae Avoid direct access to instance variables in rational.rb. 2019-05-17 16:22:23 +09:00
Yukihiro "Matz" Matsumoto 912d23634d Fixed wrong overloading.
`float op rational` should return `float`, since float is an inexact
value.
2019-05-17 16:18:46 +09:00
Yukihiro "Matz" Matsumoto 237a57bbe8 Make unused functions private.
* mrb_fixnum_plus()
* mrb_fixnum_minus()
* mrb_fixnum_mul()
2019-05-17 11:30:38 +09:00
Yukihiro "Matz" Matsumoto 0d61bcd823 Use div (integer divition) instead of / for rational numbers. 2019-05-17 11:27:52 +09:00
Yukihiro "Matz" Matsumoto 0c91da257b Remove unused mrb_num_div() function. 2019-05-17 11:27:21 +09:00
Yukihiro "Matz" Matsumoto 223defd62a Move Numeric#div to the core. 2019-05-17 11:26:16 +09:00
Yukihiro "Matz" Matsumoto 3734c53eb8 Make flo_rount to return Integeral. 2019-05-17 11:13:12 +09:00
Yukihiro "Matz" Matsumoto bc18060149 Change the num.divmod(float) to return [int,num]. 2019-05-17 10:58:17 +09:00
Yukihiro "Matz" Matsumoto 8a9f984eb8 Add a new function mrb_int_value.
This function returns `Fixnum` if the value fits in `mrb_int`,
otherwise it returns `Float` value (mruby behavior of handling integers).
2019-05-17 10:42:16 +09:00
Yukihiro "Matz" Matsumoto 80c789b394 Use int64_t instead of mrb_int in int64_value. 2019-05-17 10:40:19 +09:00
Yukihiro "Matz" Matsumoto 283530b19b Use mrb_float instead of double in FIXABLE_FLOAT. 2019-05-17 10:37:49 +09:00
Yukihiro "Matz" Matsumoto 4bc48d0b76 Refactor time.c regarding memory allocation. 2019-05-16 22:49:27 +09:00
Yukihiro "Matz" Matsumoto 83071843da Merge pull request #4439 from shuujii/fix-Rational-eq
Fix `Rational#==`
2019-05-16 22:49:15 +09:00
KOBAYASHI Shuji f5fb1307b0 Fix Rational#== 2019-05-16 22:09:56 +09:00
Yukihiro "Matz" Matsumoto 9b604abc83 Enable YYSTACK_USE_ALLOCA.
It used heap allocated memory for the parser stack, but there's
possibility of parser termination by exceptions. In that case, the
parser stack memory is leaked.

We were afraid of stack consumption, but parser stack size is only 4KB,
so we don't have to worry about it (at least for the parser).
2019-05-16 11:46:37 +09:00
Yukihiro "Matz" Matsumoto 304b52fabe Set maximum string (and symbol) size to 65534 (UINT16_MAX-1).
The previous value (`UINT16_MAX`) was too long for symbols, so it raises
an exception after the length check.
2019-05-16 11:44:51 +09:00
Yukihiro "Matz" Matsumoto 7aff5507dd Avoid potential type mismatch warnings in pack.c. 2019-05-16 10:15:11 +09:00
Yukihiro "Matz" Matsumoto 2f14254142 Avoid potential integer overflow. 2019-05-16 10:13:52 +09:00
Yukihiro "Matz" Matsumoto 752edf413f Terminate float right shift if shift value is too big. 2019-05-16 09:51:27 +09:00
Yukihiro "Matz" Matsumoto 6af0effda1 Merge pull request #4435 from shuujii/fix-typo-in-mrbgems-mruby-io-src-file_test.c
Fix typo in `mrbgems/mruby-io/src/file_test.c` [ci skip]
2019-05-15 17:00:46 +09:00
Yukihiro "Matz" Matsumoto 936f72fdd2 Do not overwrite conf.cc.defines. 2019-05-15 16:58:35 +09:00
Ukrainskiy Sergey 31bfc55866 Fix 2019-05-15 16:57:21 +09:00
Ukrainskiy Sergey fa45cc4272 Fix dependencies 2019-05-15 16:57:21 +09:00
Ukrainskiy Sergey d67d2ae8e8 Basic implementation of Complex and Rational classes 2019-05-15 16:57:21 +09:00
Ukrainskiy Sergey 79c3335e8d Small refactoring 2019-05-15 16:57:21 +09:00
Ukrainskiy Sergey 8808219e6d Initial suffix support 2019-05-15 16:57:21 +09:00
KOBAYASHI Shuji 5f664fb6f8 Fix typo in mrbgems/mruby-io/src/file_test.c [ci skip] 2019-05-15 16:27:08 +09:00
Yukihiro "Matz" Matsumoto 7f1f499b22 Merge pull request #4400 from shuujii/fix-name-assignment-to-frozen-anonymous-class-module
Fix name assignment to frozen anonymous class/module
2019-05-15 15:47:02 +09:00
Yukihiro "Matz" Matsumoto 780342eddb Add Enumerator support to String#each_byte.
`String#each_byte` is not defined in ISO Ruby but it is implemented in
the core mruby because it's useful.
2019-05-15 14:59:48 +09:00
Yukihiro "Matz" Matsumoto 138845a519 Merge pull request #4434 from shuujii/refine-Time-to_s-inspect
Refine `Time#(to_s|inspect)`
2019-05-15 14:22:47 +09:00
Yukihiro "Matz" Matsumoto fd37bc53de Remove String#=~ and String#match that requires Regexp. 2019-05-15 09:55:21 +09:00
KOBAYASHI Shuji edf4b33c61 Refine Time#(to_s|inspect)
For the following reasons:

- Ruby compatibility.
- Add UTC offset (time zone informations was not included by #4433).
- More readable.

Example:

  Before this patch:

    p Time.gm(2003,4,5,6,7,8,9)        #=> Sat Apr  5 06:07:08 2003
    p Time.local(2013,10,28,16,27,48)  #=> Mon Oct 28 16:27:48 2013

  After this patch:

    p Time.gm(2003,4,5,6,7,8,9)        #=> 2003-04-05 06:07:08 UTC
    p Time.local(2013,10,28,16,27,48)  #=> 2013-10-28 16:27:48 +0900

Implementation:

I use `strftime(3)` because UTC offset can be added and program size become
smaller than the other implementations (using `sprintf(3)`, self conversion
etc) in my environment.
2019-05-14 22:50:36 +09:00
Yukihiro "Matz" Matsumoto d8eff635fd Merge pull request #4433 from shuujii/fix-Time-asctime-ctime-according-to-ISO-Ruby
Fix `Time#(asctime|ctime)` according to ISO Ruby
2019-05-14 18:36:55 +09:00
KOBAYASHI Shuji a2616db4dc Fix Time#(asctime|ctime) according to ISO Ruby
- A leading charactor for day is space.
- Time zone does not included.

Before this patch:

  Time.gm(1982,3,4,5,6,7).asctime  #=> "Thu Mar 04 05:06:07 UTC 1982"

After this patch:

  Time.gm(1982,3,4,5,6,7).asctime  #=> "Thu Mar  4 05:06:07 1982"
2019-05-13 19:46:26 +09:00
Yukihiro "Matz" Matsumoto b145ed9de5 Merge pull request #4432 from shuujii/fix-missing-assertions-in-mruby-time-test
Fix missing assertions in `mruby-time` test
2019-05-13 08:33:55 +09:00
KOBAYASHI Shuji 2c2584138a Fix missing assertions in mruby-time test 2019-05-12 20:25:11 +09:00
Yukihiro "Matz" Matsumoto e28ebed661 Merge pull request #4431 from shuujii/use-mrb_ensure_string_type-in-mrb_to_str
Use `mrb_ensure_string_type` in `mrb_to_str`
2019-05-12 14:33:10 +09:00
KOBAYASHI Shuji fa317fabbd Use mrb_ensure_string_type in mrb_to_str 2019-05-11 18:40:33 +09:00
Yukihiro "Matz" Matsumoto 4cce39cab7 Merge pull request #4430 from bshastry/ossfuzz
Update ossfuzz options
2019-05-11 09:26:19 +09:00
Yukihiro "Matz" Matsumoto 4601ac7f13 Merge pull request #4429 from shuujii/move-mrb_gc_arena_restore-into-loop-in-mrb_file_s_chmod
Move `mrb_gc_arena_restore` to inside the loop in `mrb_file_s_chmod`
2019-05-11 09:24:35 +09:00
Bhargava Shastry 1e2983bd04 Update ossfuzz options 2019-05-10 16:13:05 +02:00
KOBAYASHI Shuji f2719e903a Move mrb_gc_arena_restore to inside the loop in mrb_file_s_chmod 2019-05-10 21:10:44 +09:00
Yukihiro "Matz" Matsumoto 2e99f34fe3 Merge pull request #4428 from shuujii/raise-TypeError-if-the-argument-type-is-unsupported-in-mrb_stat0
Raise `TypeError` if the argument type is unsupported in `mrb_stat0`
2019-05-10 12:25:10 +09:00
KOBAYASHI Shuji 0d94a2e3a9 Raise TypeError if the argument type is unsupported in mrb_stat0 2019-05-10 00:31:30 +09:00
Yukihiro "Matz" Matsumoto 9a4f3029d9 Update README.md; mruby is now Ruby 2.x compatible. 2019-05-08 21:32:25 +09:00
Yukihiro "Matz" Matsumoto ecc6eb81b5 Merge pull request #4426 from shuujii/use-mrb_string_value_cstr-in-mrb_str_to_dbl
Use `mrb_string_value_cstr` in `mrb_str_to_dbl`
2019-05-08 21:32:11 +09:00
KOBAYASHI Shuji 1975dedb21 Use mrb_string_value_cstr in mrb_str_to_dbl 2019-05-08 20:35:03 +09:00
Yukihiro "Matz" Matsumoto f405d35dac Merge pull request #4425 from shuujii/refactor-mrb_str_to_cstr-and-mrb_string_value_cstr
Refactor `mrb_str_to_cstr` and `mrb_string_value_cstr`
2019-05-08 06:23:50 +09:00
KOBAYASHI Shuji 35943e7beb Refactor mrb_str_to_cstr and mrb_string_value_cstr
- Extract null byte check to function.
- Avoid string allocation if null byte is included.
- Use `str_new` instead of `mrb_str_dup` + `mrb_str_modify`
2019-05-07 23:01:13 +09:00
Yukihiro "Matz" Matsumoto c778c234b0 Merge pull request #4424 from shuujii/avoid-using-mrb_str_to_cstr-if-possible
Avoid using `mrb_str_to_cstr` if possible
2019-05-07 06:21:10 +09:00
KOBAYASHI Shuji e2604c1550 Avoid using mrb_str_to_cstr if possible
Because it always allocate new string. Replace with the followings:

- Use `RSRING_PTR` if string is guaranteed to be null-terminated.
- Use `mrb_string_value_cstr` or `mrb_get_args("z")` if return value isn't
  modified.
2019-05-06 23:32:53 +09:00
Yukihiro "Matz" Matsumoto 31cc8573f0 Merge pull request #4423 from shuujii/use-mrb_fixnum_to_str-instead-of-Fixnum-to_s
Use `mrb_fixnum_to_str()` instead of `Fixnum#to_s`
2019-05-05 21:57:35 +09:00
KOBAYASHI Shuji 0ccb058b90 Use mrb_fixnum_to_str() instead of Fixnum#to_s 2019-05-05 20:31:12 +09:00
Yukihiro "Matz" Matsumoto 2b1c4e9acd Merge pull request #4179 from bshastry/ossfuzz
ossfuzz: Add simple mruby compile test harness
2019-05-04 18:32:40 +09:00
Yukihiro "Matz" Matsumoto 82b04f927e Merge pull request #4422 from shuujii/check-whether-object-is-immediate-in-mrb_gc_register-unregister
Check whether object is immediate in `mrb_gc_(register|unregister)`
2019-05-04 18:28:06 +09:00
KOBAYASHI Shuji a5bda13fb7 Check whether object is immediate in mrb_gc_(register|unregister) 2019-05-04 16:38:07 +09:00
Yukihiro "Matz" Matsumoto 181d14668a Merge pull request #4420 from shuujii/simplify-conversion-process-for-i-in-mrb_get_args
Simplify conversion process for `i` in `mrb_get_args()`
2019-05-04 00:19:14 +09:00
Yukihiro "Matz" Matsumoto 187b4c819f Merge pull request #4419 from dearblue/fix-always-static
Fix `FLAG_SRC_STATIC` always set in `mrb_read_irep()` with `MRB_USE_CUSTOM_RO_DATA_P`
2019-05-04 00:17:10 +09:00
Yukihiro "Matz" Matsumoto a277a6e47d Merge pull request #4418 from dearblue/clean-duplicate
Clean duplicate code
2019-05-04 00:15:56 +09:00
KOBAYASHI Shuji 0692f7916c Simplify conversion process for i in mrb_get_args() 2019-05-03 13:39:19 +09:00
dearblue e86e360b36 Fix FLAG_SRC_STATIC always set in mrb_read_irep() with MRB_USE_CUSTOM_RO_DATA_P 2019-05-03 11:42:14 +09:00
dearblue f5d5caaf82 Clean duplicate code
Removed duplicates in the code entered for "Concatenate string literal".
2019-05-03 11:36:31 +09:00
Yukihiro "Matz" Matsumoto 8c8e6e25ad Merge pull request #4417 from shuujii/unify-overflow-error-class-for-conversion-to-integer-to-RangeError
Unify overflow error class for conversion to integer to `RangeError`
2019-05-02 23:05:13 +09:00
Yukihiro "Matz" Matsumoto 35319bed01 Use a normal method instead of a lambda in bintest/mruby; ref #4416 2019-05-02 23:03:38 +09:00
Yukihiro "Matz" Matsumoto f83112cea2 Fixed include specifier format for mruby/common.h. 2019-05-02 22:55:19 +09:00
Yukihiro "Matz" Matsumoto 335602e85c Merge pull request #4416 from shuujii/small-fix-in-mruby-bin-mruby
Small fix in `mruby-bin-mruby`
2019-05-02 22:52:38 +09:00
Yukihiro "Matz" Matsumoto a7871ce77e Merge pull request #4415 from shuujii/remove-unneeded-argc-check-in-mrb_str_aref_m
Remove unneeded `argc` check in `mrb_str_aref_m()`
2019-05-02 22:31:58 +09:00
KOBAYASHI Shuji 95a92d35c8 Unify overflow error class for conversion to integer to RangeError 2019-05-02 20:45:31 +09:00
KOBAYASHI Shuji 2a94bf8fbd Small fix in mruby-bin-mruby
- Modify some error messages for consistency.
- Add test for codegen error.
- Use regular expression for error message matching in test.
2019-05-01 16:49:56 +09:00
KOBAYASHI Shuji 1a8f6e70b5 Remove unneeded argc check in mrb_str_aref_m() 2019-05-01 15:04:08 +09:00
Yukihiro "Matz" Matsumoto eeb78a7259 Merge pull request #4414 from shuujii/refine-error-message-output-for-mruby-command
Refine error message output for `mruby` command
2019-04-30 19:37:00 +09:00
KOBAYASHI Shuji 9bd17226d5 Refine error message output for mruby command
- Write message to stderr instead of stdout.
- Avoid duplicate message output (`SyntaxError`, `ScriptError` etc).
- Refine invalid option message.
- Suppress redundant usage output.
- Fix some incorrect exit code.
2019-04-30 16:58:01 +09:00
Yukihiro "Matz" Matsumoto 0615970877 Merge pull request #4413 from shuujii/fix-missing-assertions-in-mruby-io-test
Fix missing assertions in `mruby-io` test
2019-04-29 11:54:51 +09:00
Yukihiro "Matz" Matsumoto b7ff23d235 Merge pull request #4412 from shuujii/refine-the-default-values-of-flunk
Refine the default values of `flunk`
2019-04-29 11:53:58 +09:00
KOBAYASHI Shuji 4bf6b8c136 Refine the default values of flunk
The default message for the second argument should be set to the first
argument because only one argument is normally specified.
2019-04-29 11:34:41 +09:00
KOBAYASHI Shuji 8cc2ad3348 Fix missing assertions in mruby-io test 2019-04-29 11:09:35 +09:00
Yukihiro "Matz" Matsumoto e4992cdd03 Merge pull request #4411 from shuujii/commented-out-Struct.new-removes-existing-constant-test
Commented out "Struct.new removes existing constant" test
2019-04-28 23:44:37 +09:00
KOBAYASHI Shuji 5969ed1afb Commented out "Struct.new removes existing constant" test
Because this test is always skipped.
2019-04-28 18:42:23 +09:00
Yukihiro "Matz" Matsumoto b15293e709 Merge pull request #4410 from dearblue/update-docs
Update document for `MRB_USE_CUSTOM_RO_DATA_P` and some configurations
2019-04-27 23:18:18 +09:00
dearblue 828a998941 Update document for MRB_USE_CUSTOM_RO_DATA_P 2019-04-27 22:29:20 +09:00
dearblue b57f61ac95 Update document for any configurations
- (Modify) `MRB_INT16`
- (Add)    `MRB_INT32`
- (Modify) `MRB_INT64`
- (Add)    `MRB_USE_ETEXT_EDATA`
- (Add)    `MRB_NO_INIT_ARRAY_START
- (Add)    `MRB_WITHOUT_FLOAT`
- (Add)    `MRB_METHOD_CACHE`
- (Add)    `MRB_METHOD_CACHE_SIZE`
- (Add)    `MRB_METHOD_TABLE_INLINE
- (Add)    `MRB_ENABLE_ALL_SYMBOLS`
2019-04-27 22:28:54 +09:00
Yukihiro "Matz" Matsumoto 6f779ceac2 Merge pull request #4409 from shuujii/remove-duplicated-String-each_char
Remove duplicated `String#each_char`
2019-04-27 14:02:38 +09:00
KOBAYASHI Shuji 270131253f Remove duplicated String#each_char 2019-04-27 12:50:02 +09:00
Yukihiro "Matz" Matsumoto 2b0135e869 Merge pull request #4408 from dearblue/my-ro_data_p
Add customized `mrb_ro_data_p()`
2019-04-26 23:36:50 +09:00
KOBAYASHI Shuji 1fb635ac03 Add assert_raise_with_message and assert_raise_with_message_pattern 2019-04-26 21:48:40 +09:00
dearblue 302ad847a3 Add customized mrb_ro_data_p()
User definable `mrb_ro_data_p()` functions are available
by defining `MRB_USE_CUSTOM_RO_DATA_P`.

(Limitation) It can not be defined as an inline function.
2019-04-26 21:28:57 +09:00
Yukihiro "Matz" Matsumoto c078758644 Merge pull request #4405 from shuujii/singleton-class-of-frozen-object-should-be-frozen
Singleton class of frozen object should be frozen
2019-04-26 01:14:11 +09:00
KOBAYASHI Shuji 8fa3995a1a Singleton class of frozen object should be frozen
Before this patch:

  p (class << Object.new.freeze; self end).frozen?                #=> false
  sc = class << (o=Object.new); self end; o.freeze; p sc.frozen?  #=> false

After this patch / Ruby:

  p (class << Object.new.freeze; self end).frozen?                #=> true
  sc = class << (o=Object.new); self end; o.freeze; p sc.frozen?  #=> true
2019-04-25 19:48:40 +09:00
Yukihiro "Matz" Matsumoto e5799b5d40 Merge pull request #4402 from shuujii/fix-modiying-class-variable-to-frozen-class
Fix modiying class variable to frozen class/module
2019-04-25 07:17:10 +09:00
dearblue 8f6f36f654 Add mruby binary loader functions from buffer memory
Add new functions (with `MRB_API`):
- `mrb_read_irep_buf()`
- `mrb_load_irep_buf()`
- `mrb_load_irep_buf_cxt()`
2019-04-24 22:56:39 +09:00
dearblue 58d525c9fa Check mruby binary size 2019-04-24 22:56:39 +09:00
dearblue 4d85019e4c Check mruby binary version 2019-04-24 22:56:38 +09:00
KOBAYASHI Shuji 4720648137 Fix modiying class variable to frozen class/module 2019-04-24 21:05:44 +09:00
Yukihiro "Matz" Matsumoto 163a6d01e0 Reorganize defines related to MRB_INLINE; ref #4391 2019-04-24 12:09:16 +09:00
Yukihiro "Matz" Matsumoto 0c5f26e0ff Remove unnecessary mrb_regexp_check() and related functions. 2019-04-24 11:43:05 +09:00
Yukihiro "Matz" Matsumoto 9ca9af60f2 Merge pull request #4401 from shuujii/fix-ambiguous-first-argument-warning-in-test-t-float.rb
Fix "ambiguous first argument" warning in `test/t/float.rb`
2019-04-24 00:30:30 +09:00
KOBAYASHI Shuji 9f4147f28e Fix "ambiguous first argument" warning in test/t/float.rb 2019-04-23 21:02:42 +09:00
KOBAYASHI Shuji cc7f9190ba Fix name assignment to frozen anonymous class/module
Fix the following issues:

  A = Class.new.freeze              #=> FrozenError
  Module.new::B = Class.new.freeze  #=> FrozenError
  String::B = Module.new.freeze     #=> FrozenError
2019-04-23 20:45:38 +09:00
Yukihiro "Matz" Matsumoto e9f3902ab5 Fixed the condition in mrb_funcall_with_block; fix #4389 2019-04-23 15:30:10 +09:00
Yukihiro "Matz" Matsumoto 7cf1bc39a7 Merge pull request #4356 from shuujii/add-assert_match-and-assert_not_match
Add `assert_match` and `assert_not_match`
2019-04-22 22:29:15 +09:00
Yukihiro "Matz" Matsumoto 5ab8ca41a5 Merge branch 'shuujii-add-assert_predicate-and-assert_operator' 2019-04-22 22:26:46 +09:00
KOBAYASHI Shuji 0debf154ee Add assert_predicate and assert_operator 2019-04-22 22:26:11 +09:00
Yukihiro "Matz" Matsumoto 49cb149033 Merge pull request #4391 from dearblue/inlines
Change modifier to `MRB_INLINE` from `static inline`
2019-04-22 21:17:27 +09:00
Yukihiro "Matz" Matsumoto 9985d0aaca Merge pull request #4399 from shuujii/use-MRB_ASPEC_XXX-macro-in-codedump
Use `MRB_ASPEC_XXX()` macro in `codedump()`
2019-04-22 21:15:02 +09:00
KOBAYASHI Shuji 0e6a93a9ca Use MRB_ASPEC_XXX() macro in codedump() 2019-04-22 19:09:29 +09:00
Yukihiro "Matz" Matsumoto 0e704d195f Merge pull request #4396 from shuujii/commented-out-String-scan
Commented out `String#scan` because it is not implemented yet
2019-04-22 08:57:55 +09:00
Yukihiro "Matz" Matsumoto a025cd2268 Merge pull request #4395 from shuujii/expand-BOXWORD_SET_VALUE-macro-in-include-mruby-boxing_word.h
Expand `BOXWORD_SET_VALUE()` macro in `include/mruby/boxing_word.h`
2019-04-22 08:56:47 +09:00
KOBAYASHI Shuji cdb458ed4e Commented out String#scan because it is not implemented yet 2019-04-21 20:34:39 +09:00
KOBAYASHI Shuji b212050026 Expand BOXWORD_SET_VALUE() macro in include/mruby/boxing_word.h
In `SET_OBJ_VALUE()`, branch isn't removed because `switch` condition isn't
constant expression.
2019-04-20 21:23:58 +09:00
Yukihiro "Matz" Matsumoto 88c3595db3 Merge pull request #4393 from robfors/twiddle_wakka
Fixes the twiddle wakka comparison algorithm
2019-04-20 07:31:11 +09:00
Yukihiro "Matz" Matsumoto ff765c814d Merge pull request #4390 from shuujii/add-type-check-in-String-aset
Add type check (conversion) in `String#[]=`
2019-04-20 07:30:12 +09:00
Rob 73bb144ef0 Fixes the twiddle wakka comparison algorithm to support passing only a major number 2019-04-19 17:18:30 -04:00
Yukihiro "Matz" Matsumoto 2f9ebc6f32 Merge pull request #4392 from dearblue/true-false-p
Add `mrb_true_p()` and `mrb_false_p()` macro functions
2019-04-20 04:09:34 +09:00
dearblue 125c3bef19 Add mrb_true_p() and mrb_false_p() macro functions 2019-04-19 22:50:05 +09:00
dearblue 6907e97fa1 Change modifier to MRB_INLINE from static inline 2019-04-19 22:24:22 +09:00
KOBAYASHI Shuji 4a8b88f775 Add type check (conversion) in String#[]=
Before this patch:

  'a'[0] = 1        #=> 1
  'a'[:a] = '1'     #=> ArgumentError
  'a'[:a, 0] = '1'  #=> ArgumentError
  'a'[0, :a] = '1'  #=> ArgumentError
  'a'[0, 1] = 1     #=> 1

After this patch / Ruby:

  'a'[0] = 1        #=> TypeError
  'a'[:a] = '1'     #=> TypeError
  'a'[:a, 0] = '1'  #=> TypeError
  'a'[0, :a] = '1'  #=> TypeError
  'a'[0, 1] = 1     #=> TypeError
2019-04-19 20:14:23 +09:00
Yukihiro "Matz" Matsumoto 05f65d2d42 Merge pull request #4388 from shuujii/remove-duplicated-include-Comparable-in-mrblib-string.rb
Remove duplicated `include Comparable` in `mrblib/string.rb`
2019-04-19 10:44:14 +09:00
KOBAYASHI Shuji 916045921e Remove duplicated include Comparable in mrblib/string.rb 2019-04-18 19:58:05 +09:00
Yukihiro "Matz" Matsumoto 2f6baf60e9 Merge pull request #4387 from shuujii/add-Array-sample-test
Add `Array#sample` test
2019-04-18 08:10:45 +09:00
KOBAYASHI Shuji 2ae727ac3a Add Array#sample test
And simplify tests for `Array#shuffle` and `Array#shuffle!`.
2019-04-17 21:04:46 +09:00
Yukihiro "Matz" Matsumoto 8ee516436b Merge pull request #4386 from tomas/stable
Fix compilation on gcc 4.9.x
2019-04-17 08:03:15 +09:00
Tomás Pollak ef3b539125 Prevent 'mixed declarations and code' C90 warning 2019-04-16 18:02:30 -04:00
Tomas Pollak bcb8e297fc Fix compilation on gcc 4.9.x 2019-04-16 12:34:09 -04:00
Yukihiro "Matz" Matsumoto 77c42988c8 Merge pull request #4385 from shuujii/avoid-potential-zero-size-array-declaration
Avoid potential zero size array declaration; fix #4382
2019-04-16 21:53:28 +09:00
KOBAYASHI Shuji 79a7f18150 Avoid potential zero size array declaration; fix #4382 2019-04-16 19:56:11 +09:00
Yukihiro "Matz" Matsumoto 4e45e320b0 Fixed a bug in recursive mrb_top_run calls; fix #4384 2019-04-16 18:47:46 +09:00
Yukihiro "Matz" Matsumoto 3760f58d53 Merge pull request #4383 from Shokuji/fix_mruby-io_test
Fix test in mruby-io
2019-04-16 17:34:50 +09:00
Shokuji cdfeb53887 Merge branch 'master' into fix_mruby-io_test 2019-04-16 09:47:32 +09:00
Yukihiro "Matz" Matsumoto 4e3e4260c3 Merge pull request #4381 from shuujii/fix-missing-assertions-in-mruby-random-test
Fix missing assertions in `mruby-random` test
2019-04-16 08:39:08 +09:00
KOBAYASHI Shuji d53eb8a377 Fix missing assertions in mruby-random test 2019-04-15 19:03:39 +09:00
Shouji Kuboyama 164985881b Fix test, popen and cmd in mruby-io 2019-04-15 17:16:08 +09:00
Yukihiro "Matz" Matsumoto 6b8d3c7070 Fixed wrong function names; fix #4380 2019-04-15 07:15:38 +09:00
Yukihiro "Matz" Matsumoto 7a62efae63 Merge pull request #4379 from shuujii/extract-similar-codes-to-macros-for-math-opcode-in-mrb_vm_exec
Extract similar codes to macros for math opcode in `mrb_vm_exec()`
2019-04-15 07:08:27 +09:00
KOBAYASHI Shuji 30c880bea9 Extract similar codes to macros for math opcode in mrb_vm_exec 2019-04-14 22:40:17 +09:00
Yukihiro "Matz" Matsumoto ea6aab20e8 Merge pull request #4378 from dearblue/memleak-hashtable
Fix memory leak for hash table index if occur out of memory
2019-04-14 20:36:29 +09:00
Yukihiro "Matz" Matsumoto 6ad89d30d2 Merge pull request #4377 from dearblue/wrong-iv-size
Fix wrong size of instance variable if occur out of memory
2019-04-14 20:36:05 +09:00
Yukihiro "Matz" Matsumoto e74a8a7360 Merge pull request #4376 from dearblue/leak-symbols
Fix leaked function symbols
2019-04-14 20:35:19 +09:00
Yukihiro "Matz" Matsumoto 4a1d29cbb8 Merge pull request #4375 from dearblue/forgotten-structs
Include `RFiber` and `RIstruct` as a part of `RVALUE`
2019-04-14 20:34:45 +09:00
Yukihiro "Matz" Matsumoto ec41262e22 Merge pull request #4374 from dearblue/hexdump
Fix hexdigits convertion
2019-04-14 20:34:14 +09:00
KOBAYASHI Shuji 716a99b069 Add assert_match and assert_not_match 2019-04-14 19:06:28 +09:00
dearblue d328808892 Fix memory leak for hash table index if occur out of memory 2019-04-14 17:55:20 +09:00
dearblue d8527d17ea Fix wrong size of instance variable if occur out of memory 2019-04-14 17:42:35 +09:00
dearblue d557f97732 Remove pointer check after mrb_malloc() 2019-04-14 17:39:50 +09:00
dearblue 3f3e4754d9 Fix leaked function symbols
- `free_heap()` in src/gc.c
- `symhash()` in src/symbol.c
- `no_optimize()` in mrbgems/mruby-compiler/core/codegen.c
2019-04-14 17:23:16 +09:00
dearblue dac0f3f5e8 Fix string index for appending
`sizeof(string-literal)` is included `'\0'` character
2019-04-14 16:16:05 +09:00
dearblue c2fa935fee Fix hexdigits convertion 2019-04-14 16:11:21 +09:00
dearblue 0ebbc491a1 Include RFiber and RIstruct as a part of RVALUE 2019-04-14 15:35:51 +09:00
Yukihiro "Matz" Matsumoto 4d8ff2fba4 Merge pull request #4373 from shuujii/fix-broken-NaN-with-MRB_NAN_BOXING
Fix broken NaN with `MRB_NAN_BOXING`
2019-04-14 12:25:54 +09:00
KOBAYASHI Shuji f639da0f1c Fix broken NaN with MRB_NAN_BOXING
Example:

  $ bin/mruby -e '(Float::INFINITY - Float::INFINITY).nan?'
  zsh: segmentation fault

Cause:

  `SET_FLOAT_VALUE` is not used. It is needed for normalizing NaN.

Treatment:

  In my environment, this issue could be reproduced only when
  `infinity - infinity`, however `SET_FLOAT_VALUE` should be used in all
  arithmetic operations (regardless of boxing setting), I think.

  So I fixed all similar codes by extracting to macro.
2019-04-13 19:27:17 +09:00
Yukihiro "Matz" Matsumoto 79fd986bcb Small refactoring in mrb_funcall_with_block. 2019-04-12 23:04:10 +09:00
Yukihiro "Matz" Matsumoto 7f1984a01e Merge pull request #4372 from shuujii/refine-assert_float
Refine `assert_float`
2019-04-12 22:58:57 +09:00
Yukihiro "Matz" Matsumoto befdf59e61 Deallocate s->lines in codegen_error; ref #4370 2019-04-12 22:54:25 +09:00
Yukihiro "Matz" Matsumoto 00545fc51d The number of local variables should be less than 1024; fix #4370
The `env` stores stack length in a 10 bit field.
See `MRB_ENV_STACK_LEN()` macro.
2019-04-12 22:52:26 +09:00
KOBAYASHI Shuji 6626fbc500 Refine assert_float
Avoid arithmetic operations when `exp` and/or `act` are infinity or NaN.
2019-04-12 22:27:07 +09:00
Yukihiro "Matz" Matsumoto 6da10f643a Merge pull request #4369 from shuujii/remove-incorrect-flags-updating-in-mrb_regexp_p
Remove incorrect flags updating in `mrb_regexp_p()`
2019-04-12 21:01:49 +09:00
Yukihiro "Matz" Matsumoto 9b9c41d699 Merge pull request #4371 from clayton-shopify/fix-buffer-overflows
Fix buffer overflows in parser.
2019-04-12 19:56:35 +09:00
Clayton Smith 57e617620a Fix buffer overflows in parser. 2019-04-11 20:07:43 -04:00
KOBAYASHI Shuji 0c9c3f08ee Remove incorrect flags updating in mrb_regexp_p() 2019-04-11 21:42:18 +09:00
Yukihiro "Matz" Matsumoto 9c252410cf Merge pull request #4368 from shuujii/use-mrb_immediate_p-in-mrb_obj_freeze-and-mrb_obj_frozen
Use `mrb_immediate_p()` in `mrb_obj_freeze()` and `mrb_obj_frozen()`
2019-04-10 19:34:58 +09:00
KOBAYASHI Shuji 7b0ebed033 Use mrb_immediate_p() in mrb_obj_freeze() and mrb_obj_frozen() 2019-04-10 19:19:53 +09:00
Yukihiro "Matz" Matsumoto 4776ac50ed Remove too aggressive initialize call in mrb_instance_new. 2019-04-10 19:11:35 +09:00
Yukihiro "Matz" Matsumoto 88ac7549c0 Remove MRB_API from mrb_instance_new. 2019-04-10 19:11:35 +09:00
Yukihiro "Matz" Matsumoto d0b30f4ce2 Merge pull request #4367 from shuujii/extract-frozen-checking-to-function
Extract frozen checking to function
2019-04-10 06:03:32 +09:00
Yukihiro "Matz" Matsumoto b433001a1b Merge pull request #4366 from shuujii/remove-unneeded-function-prototypes
Remove unneeded function prototypes
2019-04-10 06:02:16 +09:00
Yukihiro "Matz" Matsumoto b351bdb8d5 Fixed old style declaration; ref #4365 2019-04-10 06:00:38 +09:00
Yukihiro "Matz" Matsumoto d529501cbf Rename itoa to dump_int to avoid name crash; ref #4173 2019-04-10 05:55:40 +09:00
Yukihiro "Matz" Matsumoto 16f86f8ede Use the old style declaration; ref #4365 2019-04-10 05:42:36 +09:00
KOBAYASHI Shuji e3beef065c Extract frozen checking to function 2019-04-09 18:23:11 +09:00
KOBAYASHI Shuji f89fe04d54 Remove unneeded function prototypes 2019-04-08 22:34:49 +09:00
Yukihiro "Matz" Matsumoto 292bffb32e Avoid infinite loop when no Regexp class is available; fix #4363 2019-04-08 20:27:28 +09:00
Yukihiro "Matz" Matsumoto ec1688807e Avoid using snprintf when MRB_DISABLE_STDIO is set; fix #4173 2019-04-08 19:06:36 +09:00
Yukihiro "Matz" Matsumoto 6cec0c9f62 Fix C99 style inline declaration; fix #4365 2019-04-08 19:06:36 +09:00
Yukihiro "Matz" Matsumoto 2595d5f6c8 Merge pull request #4364 from shuujii/fix-test-for-Array-slice
Fix test for `Array#slice`
2019-04-07 22:12:33 +09:00
KOBAYASHI Shuji f65b35dc9f Fix test for Array#slice 2019-04-07 21:31:12 +09:00
Yukihiro "Matz" Matsumoto 6865826aff Merge pull request #4362 from shuujii/move-Array-append-prepend-from-core-to-mruby-ary-ext
Move `Array#(append|prepend)` from core to `mruby-ary-ext`
2019-04-06 22:25:55 +09:00
Yukihiro "Matz" Matsumoto 64c2ea3f02 Merge pull request #4361 from shuujii/remove-unused-mrb_proc_cfunc_p
Remove unused `mrb_proc_cfunc_p()`
2019-04-06 22:22:38 +09:00
KOBAYASHI Shuji 5adef8ba44 Move Array#(append|prepend) from core to mruby-ary-ext
They are not included in ISO standard.
2019-04-06 17:40:51 +09:00
KOBAYASHI Shuji 271a91c648 Remove unused mrb_proc_cfunc_p() 2019-04-06 16:32:27 +09:00
Yukihiro "Matz" Matsumoto 293a7b2a6e Merge pull request #4360 from shuujii/use-Module-alias_method-should-return-self-in-ISO-standard
`Module#alias_method` should return `self` in ISO standard
2019-04-05 22:17:34 +09:00
KOBAYASHI Shuji 623e15936a Module#alias_method should return self in ISO standard 2019-04-05 19:03:46 +09:00
Yukihiro "Matz" Matsumoto f882b6908e Merge pull request #4357 from mruby/stable
Update version and release date. `mruby 2.0.1 (2019-4-4)`
2019-04-05 17:06:21 +09:00
Yukihiro "Matz" Matsumoto d26f03b446 Merge pull request #4358 from shuujii/use-mrb_proc_arity-instead-of-Proc-arity-call-in-Method-arity
Use `mrb_proc_arity` instead of `Proc#arity` call in `Method#arity`
2019-04-05 13:58:20 +09:00
Yukihiro "Matz" Matsumoto dd1c100b84 Merge pull request #4355 from shuujii/modify-else-and-endif-annotations-in-src-fmt_fp.c
Modify `#else` and `#endif` annotations in `src/fmt_fp.c` [ci skip]
2019-04-05 13:41:26 +09:00
KOBAYASHI Shuji ed41bbb199 Use mrb_proc_arity instead of Proc#arity call in Method#arity 2019-04-04 22:17:26 +09:00
Hiroshi Mimaki 7c91efc1ff Update version and release date.
`mruby 2.0.1 (2019-4-4)`
2019-04-04 09:26:40 +09:00
Yukihiro "Matz" Matsumoto 50a223f21f Merge pull request #4354 from shuujii/remove-unnecessary-_set_output_format-call
Remove unnecessary `_set_output_format` call
2019-04-04 05:10:32 +09:00
KOBAYASHI Shuji 5e0caefa58 Modify #else and #endif annotations in src/fmt_fp.c [ci skip] 2019-04-03 19:25:06 +09:00
KOBAYASHI Shuji abc6c990a6 Remove unnecessary _set_output_format call
Three-digit exponent issue was fixed via another workaround (63b8f5c).
2019-04-03 18:54:25 +09:00
Yukihiro "Matz" Matsumoto 73feef9766 Merge pull request #4353 from shuujii/pad-leading-zero-to-month-and-day-in-MRUBY_RELEASE_DATE
Pad leading zero to month and day in `MRUBY_RELEASE_DATE`
2019-04-02 21:14:21 +09:00
KOBAYASHI Shuji 9b7e9addcd Pad leading zero to month and day in MRUBY_RELEASE_DATE
For Ruby compatibility.
2019-04-02 16:24:07 +09:00
Yukihiro "Matz" Matsumoto c274e1ae5a Merge pull request #4352 from shuujii/fix-modifiable-class-name
Fix modifiable class name
2019-04-02 10:27:21 +09:00
KOBAYASHI Shuji 55cb625808 Fix modifiable class name
Fix the following example:

    Object.const_set :A, Module.new{const_set :B, Class.new}
    ab = A::B.to_s
    p ab         #=> "A::B" # Good
    ab[0] = "x"
    p A::B.to_s  #=> "x::B" # Bad
2019-04-01 20:12:43 +09:00
Yukihiro "Matz" Matsumoto 2871d0cdc5 Avoid keeping pointers from mrb_sym2name_len(); fix #4342
The addresses for packed inline symbols reference `mrb->symbuf` that
could be overridden by the later call of `mrb_sym2name_len`. Since
file names in call stack information are kept as symbols, keeping the
address in the C structures could cause problems like #4342.

This changes small incompatible changes in function prototypes:
* `mrb_parser_get_filename`: return value changed to `mrb_sym`.
* `mrb_debug_get_filename`: add `mrb_state*` as a first argument.
* `mrb_debug_get_line`: ditto.

I believe above functions are almost internal, and no third-party
mrbgem use them.
2019-04-01 14:13:06 +09:00
Yukihiro "Matz" Matsumoto 6ec855a38e Merge pull request #4351 from shuujii/fix-warning-interpreted-as-argument-prefix
Fix warning: '*' interpreted as argument prefix
2019-03-31 17:39:10 +09:00
KOBAYASHI Shuji 9b024dcf7a Fix warning: '*' interpreted as argument prefix 2019-03-31 14:52:18 +09:00
Yukihiro "Matz" Matsumoto 19537b103c Merge pull request #4349 from shuujii/add-pass-and-flunk-to-test-assert.rb
Add `pass` and `flunk` to `test/assert.rb`
2019-03-30 22:07:29 +09:00
KOBAYASHI Shuji 4e9c90ed47 Add pass and flunk to test/assert.rb 2019-03-30 13:19:31 +09:00
Yukihiro "Matz" Matsumoto 3c732cd28c Merge pull request #4348 from shuujii/fix-missing-assertions-in-mruby-math-test
Fix missing assertions in `mruby-math` test
2019-03-29 15:51:20 +09:00
Yukihiro "Matz" Matsumoto 85f816528c Merge pull request #4347 from iij/include-stdarg-in-mruby-h
fixes build on OpenBSD.
2019-03-29 15:49:41 +09:00
Tomoyuki Sahara d8d59f70c1 va_list is defined in stdarg.h.
fixes build on OpenBSD.
2019-03-29 11:55:04 +09:00
KOBAYASHI Shuji d1f937e1f4 Fix missing assertions in mruby-math test 2019-03-29 09:40:13 +09:00
Yukihiro "Matz" Matsumoto 42f240796f Use Mrbtest::FLOAT_TOLERANCE instead of Math::TORELANCE; ref #4345 2019-03-28 23:22:32 +09:00
Yukihiro "Matz" Matsumoto 3b92b642eb Break loop whem sum==0 to avoid zero division; ref #4345 2019-03-28 23:22:32 +09:00
Yukihiro "Matz" Matsumoto a26856f883 Use DBL_EPSILON instead of 1E-12; ref #4345 2019-03-28 23:22:32 +09:00
Yukihiro "Matz" Matsumoto 6023180848 Merge pull request #4346 from shuujii/use-mrb_sym2str-in-implementation-of-symbol-to_s
Use `mrb_sym2str` in implementation of `Symbol#to_s`
2019-03-28 23:22:23 +09:00
KOBAYASHI Shuji da2bc9e678 Use mrb_sym2str in implementation of Symbol#to_s 2019-03-28 19:56:51 +09:00
Yukihiro "Matz" Matsumoto 21b8d20d7e Fixed mistakes in 92dce05
* rename `sym2name` to `sym2name_len`.
* `MRB_API` -> `static`
2019-03-28 07:06:44 +09:00
Yukihiro "Matz" Matsumoto 5fe00c46ba Merge pull request #4344 from shuujii/remove-unused-variable-in-each_backtrace
Remove unused variable in `each_backtrace()`
2019-03-27 20:24:31 +09:00
KOBAYASHI Shuji 58ca4061b5 Remove unused variable in each_backtrace() 2019-03-27 19:27:00 +09:00
Yukihiro "Matz" Matsumoto 92dce053ad Fix another bug related to #4342
For short symbols with alpha numeric characters, `mrb_sym2name_len()`
returns the same buffer `mrb->symbuf`. Some occasion, we forget the fact
that the second call could overwrite the result of first call of the
function.

We have prepared the static function `sym2name()` which specifies the
buffer region for inline packed symbols and use the function in
`mrb_sym_to_s`.
2019-03-27 17:38:06 +09:00
Yukihiro "Matz" Matsumoto b8f00e439d Avoid using 'mrb_str_new_static` if a symbol is packed; fix #4342 2019-03-27 12:53:24 +09:00
Yukihiro "Matz" Matsumoto 5598612336 Merge pull request #4343 from shuujii/fix-dealing-with-infinity-and-NaN-in-assert_float
Fix dealing with infinity and NaN in `test/assert.rb:assert_float`
2019-03-27 06:53:30 +09:00
KOBAYASHI Shuji 0b6696cc28 Fix dealing with infinity and NaN in test/assert.rb:assert_float
`assert_float` is always passed when expected value and/or actual value are
infinity or NaN. This behavior seems unintentional.

Before this patch:

    assert_float(Float::INFINITY, 1.0)  #=> pass
    assert_float(-Float::INFINITY, 1)   #=> pass
    assert_float(1, 1/0)                #=> pass
    assert_float(1, -1/0)               #=> pass
    assert_float(1.0, Float::NAN)       #=> pass
    assert_float(Float::NAN, 1)         #=> pass

After this patch:

    assert_float(Float::INFINITY, 1.0)  #=> fail: Expected 1.0 to be Infinity.
    assert_float(-Float::INFINITY, 1)   #=> fail: Expected 1 to be -Infinity.
    assert_float(1, 1/0)                #=> fail: Expected Infinity to be 1.
    assert_float(1, -1/0)               #=> fail: Expected -Infinity to be 1.
    assert_float(1.0, Float::NAN)       #=> fail: Expected NaN to be 1.0.
    assert_float(Float::NAN, 1)         #=> fail: Expected 1 to be NaN.
2019-03-26 22:12:09 +09:00
Yukihiro "Matz" Matsumoto c2660b8111 Fix missing MRB_API prefix for functions below; clse #4267
Functions to add prototypes to headers:
* mrb_ary_splice()
* mrb_notimplement()
* mrb_vformat()
* mrb_cstr_to_dbl()
* mrb_cstr_to_inum()

Functions to be made `static` (`MRB_API` was not needed):
* mrb_mod_module_function()
* mrb_obj_hash()
* mrb_str_len_to_inum()

Functions to remove `MRB_API` from definitions (referenced from within `libmruby`):
* mrb_mod_cv_defined()
* mrb_mod_cv_get()
* mrb_f_send()
2019-03-26 10:23:52 +09:00
Yukihiro "Matz" Matsumoto a5a6b51126 Use uppercase version of ctype macros e.g. ISSPACE; fix #4338 2019-03-25 22:05:31 +09:00
Yukihiro "Matz" Matsumoto 1e14afa4e4 Merge pull request #4341 from shuujii/remove-implementation-of-Symbol-eqq
Remove implementation of `Symbol#===`
2019-03-25 22:05:18 +09:00
KOBAYASHI Shuji b489ddcbd1 Remove implementation of Symbol#===
For reducing program size.
2019-03-25 21:39:11 +09:00
Yukihiro "Matz" Matsumoto 33a9840e4a Need to check length before packing a symbol; fix #4340 2019-03-25 20:28:21 +09:00
Yukihiro "Matz" Matsumoto f7e05c7d22 Update float test values to avoid precision errors. 2019-03-25 16:54:34 +09:00
Yukihiro "Matz" Matsumoto ce67561511 Avoid infinite binary floating numbers in float. 2019-03-25 16:21:50 +09:00
Yukihiro "Matz" Matsumoto 3e5dd40a5c Merge pull request #4339 from shuujii/fix-arguments-spec-in-src-proc.c
Fix arguments spec in `src/proc.c`
2019-03-24 22:26:37 +09:00
Yukihiro "Matz" Matsumoto e36db51bea Merge pull request #4337 from shuujii/refactor-t_print-for-test
Refactor `t_print` for test
2019-03-24 21:29:00 +09:00
KOBAYASHI Shuji 10a8e0f105 Fix arguments spec in src/proc.c 2019-03-24 20:55:04 +09:00
KOBAYASHI Shuji df4b081392 Refactor t_print for test 2019-03-23 19:27:21 +09:00
Yukihiro "Matz" Matsumoto 36c9416bff Merge pull request #4336 from shuujii/simplify-assert_step
Simplify `assert_step` in `test/t/numeric.rb`
2019-03-22 22:38:05 +09:00
KOBAYASHI Shuji 04fc265858 Simplify assert_step in test/t/numeric.rb 2019-03-22 18:37:37 +09:00
Yukihiro "Matz" Matsumoto 84241d3dba Merge pull request #4334 from shuujii/remove-redundant-content-in-assertion-failure-message-and-diff
Remove redundant content in assertion failure message and diff
2019-03-22 14:40:19 +09:00
Yukihiro "Matz" Matsumoto 19191a5476 Merge pull request #4335 from shuujii/fix-Float-eql
Fix `Float#eql?`
2019-03-22 14:38:23 +09:00
KOBAYASHI Shuji a41b02ab91 Fix Float#eql? 2019-03-21 21:36:54 +09:00
KOBAYASHI Shuji 2b72baccf3 Remove redundant content in assertion failure message and diff
Based on minitest RubyGem.

Example of before this patch:

    - Assertion[1] Failed: Expected 1 to be 2
       Expected: 2
         Actual: 1
    - Assertion[2] Failed: Expected [1, 3] to include 2
       Collection: [1, 3]
           Object: 2

Example of after this patch:

    - Assertion[1]
       Expected: 2
         Actual: 1
    - Assertion[2]
       Expected [1, 3] to include 2.
2019-03-21 20:53:52 +09:00
Yukihiro "Matz" Matsumoto 3f7cd4687f Merge pull request #4333 from shuujii/use-FrozenError-instead-of-RuntimeError-in-frozen-obj-mod-test
Use `FrozenError` instead of `RuntimeError` in frozen object modification test
2019-03-20 18:43:41 +09:00
Yukihiro "Matz" Matsumoto cd3bf55b3e Merge pull request #4332 from shuujii/use-Rake-instead-of-MiniRake-on-AppVeyor
Use Rake instead of MiniRake on AppVeyor
2019-03-20 18:42:54 +09:00
KOBAYASHI Shuji fbad7a1595 Use FrozenError instead of RuntimeError in frozen object modification test 2019-03-19 20:48:32 +09:00
KOBAYASHI Shuji bc321ece4c Use Rake instead of MiniRake on AppVeyor
1. Reduce build time

Build time becomes less than half. In MiniRake, a way of using fiber may not be good.

2. Synchronize standard output

No synchronized:

    mrbtest - Embeddable Ruby Test
    ...........................
    Total: 1165
    (snip)
     Time: 1.19 seconds
    bintest - Command Binary Test

    .....................
    Total: 21
    (snip)
     Time: 0.39 seconds
    mrbtest - Embeddable Ruby Test

    ...........................
    Total: 1165
    (snip)
     Skip: 23
     Time: 1.15 seconds
    (snip)

    >>> Test cxx_abi <<<

    >>> Bintest host <<<
    >>> Test host <<<

    >>> Test full-debug <<<

    >>> Bintest cxx_abi <<<

Synchronized:

    >>> Test full-debug <<<
    mrbtest - Embeddable Ruby Test
    ...........................
    Total: 1165
    (snip)
     Time: 1.25 seconds

    >>> Test host <<<
    mrbtest - Embeddable Ruby Test
    ...........................
    Total: 1165
    (snip)
     Time: 1.16 seconds

    >>> Bintest host <<<
    bintest - Command Binary Test
    .....................
    Total: 21
    (snip)
     Time: 0.41 seconds

    >>> Test cxx_abi <<<
    mrbtest - Embeddable Ruby Test
    (snip)
2019-03-18 14:25:24 +09:00
Yukihiro "Matz" Matsumoto f8b17d1ec4 Merge pull request #4331 from shuujii/fix-class-instance-variable-name-validation
Fix class/instance variable name validation
2019-03-17 18:38:06 +09:00
KOBAYASHI Shuji b588e5a5b7 Fix class/instance variable name validation
- `@@?` etc are invalid class variable name.
- `@1` etc are invalid instance variable name.
2019-03-17 16:58:31 +09:00
Yukihiro "Matz" Matsumoto 15b6499c8b Merge pull request #4330 from shuujii/refine-appveyor.yml
Refine `appveyor.yml`
2019-03-16 20:30:07 +09:00
KOBAYASHI Shuji 1809fb755a Refine appveyor.yml
- Add Visual Studio 2017.
- Enable `shallow_clone` for saving build time.
- Cache extracted WinFlexBison.
2019-03-16 13:37:52 +09:00
Yukihiro "Matz" Matsumoto e9b1f14cdc Merge pull request #4329 from shuujii/use-FrozenError-instead-of-RuntimeError
Use `FrozenError` instead of `RuntimeError` in `String#rstrip!`
2019-03-15 23:18:19 +09:00
KOBAYASHI Shuji cd4daf78ec Use FrozenError instead of RuntimeError in String#rstrip! 2019-03-15 22:49:40 +09:00
Yukihiro "Matz" Matsumoto a1e1201148 Merge pull request #4328 from shuujii/fix-constant-name-validation
Fix constant name validation
2019-03-15 21:19:48 +09:00
Yukihiro "Matz" Matsumoto 298807fa4e Avoid using infinite binary floating point numbers in tests. 2019-03-15 15:25:43 +09:00
Yukihiro "Matz" Matsumoto 63b8f5cf57 Use fmt_fp() for portable float representation. 2019-03-15 15:25:43 +09:00
KOBAYASHI Shuji 16b1b2978e Fix constant name validation
`X!` etc are invalid constant name.
2019-03-14 23:09:05 +09:00
Yukihiro "Matz" Matsumoto 63124bf633 Merge pull request #4327 from shuujii/do-not-raise-an-exception-when-bintest-fail
Do not raise an exception when bintest fail
2019-03-13 22:30:08 +09:00
KOBAYASHI Shuji c3122c887a Do not raise an exception when bintest fail
- An exception do not raise when mrbtest fail.
- There are no useful informations in exception message and backtrace.
2019-03-13 22:04:14 +09:00
Yukihiro "Matz" Matsumoto ad0a8888f3 Merge pull request #4326 from shuujii/fix-typo-in-AUTHORS
Fix typo in `AUTHORS` [ci skip]
2019-03-13 09:06:18 +09:00
KOBAYASHI Shuji 29951a6d07 Fix typo in AUTHORS [ci skip] 2019-03-13 07:56:32 +09:00
Yukihiro "Matz" Matsumoto 1d38c1f307 Merge pull request #4322 from shuujii/reduce-String-creation-in-checking-name
Reduce `String` creation in `check_(cv|const)_name_sym`
2019-03-12 23:48:48 +09:00
Yukihiro "Matz" Matsumoto d2c325d08a Merge pull request #4325 from shuujii/fix-missing-assertions-in-mruby-string-ext-test
Fix missing assertions in `mruby-string-ext` test
2019-03-12 23:48:03 +09:00
Yukihiro "Matz" Matsumoto 07b9a10c06 Update the description at the head of AUTHORS; ref #4324 2019-03-12 23:36:26 +09:00
KOBAYASHI Shuji e3b339bec6 Fix missing assertions in mruby-string-ext test 2019-03-12 21:47:33 +09:00
Yukihiro "Matz" Matsumoto adfb25ab13 Merge pull request #4324 from shuujii/update-AUTHORS
Update `AUTHORS` [ci skip]
2019-03-12 21:21:25 +09:00
KOBAYASHI Shuji fc96dbcac6 Update AUTHORS [ci skip] 2019-03-12 09:46:29 +09:00
Yukihiro "Matz" Matsumoto 46e4524566 Merge pull request #4323 from shuujii/rename-MITL-to-LICENSE
Rename `MITL` to `LICENSE` in `.yardopts`; ref 67728c1 [ci skip]
2019-03-12 09:27:04 +09:00
KOBAYASHI Shuji e2976172c5 Rename MITL to LICENSE in .yardopts; ref 67728c1 [ci skip] 2019-03-12 09:21:43 +09:00
Yukihiro "Matz" Matsumoto 67728c1576 Rename MITL to LICENSE to conform GitHub convention. 2019-03-12 07:54:38 +09:00
KOBAYASHI Shuji 425e6e0ffb Reduce String creation in check_(cv|const)_name_sym 2019-03-11 17:26:19 +09:00
Yukihiro "Matz" Matsumoto fba8ecf55c Merge pull request #4321 from shuujii/add-bintest-header
Add bintest header
2019-03-10 23:51:03 +09:00
KOBAYASHI Shuji 7d1a8d3f8e Add bintest header 2019-03-10 21:46:24 +09:00
Yukihiro "Matz" Matsumoto 6a0ae792df Merge pull request #4316 from shuujii/add-a-missing-file-for-4314
Add a missing file for #4314
2019-03-09 10:19:32 +09:00
Yukihiro "Matz" Matsumoto d27808ef82 Merge pull request #4319 from shuujii/allow-enable_bintest-without-enable_test
Allow `enable_bintest` without `enable_test` in build config
2019-03-08 23:05:05 +09:00
KOBAYASHI Shuji 441c964716 Allow enable_bintest without enable_test in build config 2019-03-08 22:00:06 +09:00
Yukihiro "Matz" Matsumoto 4fb3edce11 Merge pull request #4318 from shuujii/set-GEMNAME-on-bintest
Set `GEMNAME` on bintest
2019-03-08 12:22:24 +09:00
KOBAYASHI Shuji 968e3b9400 Set GEMNAME on bintest 2019-03-07 22:16:47 +09:00
KOBAYASHI Shuji f6326803c7 Add a missing file for #4314 2019-03-07 21:36:54 +09:00
Yukihiro "Matz" Matsumoto bf922c9f7a Merge pull request #4315 from shuujii/refer-also-CXX-and-CC-env-vars-as-linker-command
Refer also CXX and CC env vars as linker command in gcc and clang toolchain
2019-03-06 22:26:34 +09:00
KOBAYASHI Shuji e2bb5ce079 Refer also CXX and CC env vars as linker command in gcc and clang toolchain
ref #4292
2019-03-06 20:42:31 +09:00
Yukihiro "Matz" Matsumoto 06e07cbcd8 Merge pull request #4314 from shuujii/count-skip-test
Count skip tests
2019-03-06 19:54:37 +09:00
KOBAYASHI Shuji 650ca7da17 Count skip tests 2019-03-05 19:53:25 +09:00
Yukihiro "Matz" Matsumoto 06dae1a9b6 Merge pull request #4313 from shuujii/extract-similar-code-fragment-to-method-in-src-class.c
Extract similar code fragment to method in `src/class.c`
2019-03-04 21:57:37 +09:00
Yukihiro "Matz" Matsumoto f82e11a7ed Merge pull request #4312 from shuujii/GEMNAME-is-undefined-in-bintest
`GEMNAME` is undefined in bintest
2019-03-04 06:48:31 +09:00
KOBAYASHI Shuji ee537eceee GEMNAME is undefined in bintest
ref: https://github.com/mruby/mruby/pull/4296#discussion_r261868710
2019-03-04 00:18:54 +09:00
Yukihiro "Matz" Matsumoto d1cdb9ef75 Merge pull request #4311 from shuujii/simplify-MRubyTestSkip-in-test-assert.rb
Simplify `MRubyTestSkip` in `test/assert.rb`
2019-03-03 23:22:23 +09:00
KOBAYASHI Shuji 376dd992f1 Extract similar code fragment to method in src/class.c 2019-03-03 20:45:44 +09:00
KOBAYASHI Shuji c6b8106924 Simplify MRubyTestSkip in test/assert.rb 2019-03-03 18:58:11 +09:00
Yukihiro "Matz" Matsumoto 83a1df3785 Merge pull request #4309 from shuujii/fix-missing-assertion-in-test-t-class.rb
Fix missing assertion in `test/t/class.rb`
2019-03-02 21:14:41 +09:00
KOBAYASHI Shuji 729ab86d49 Fix missing assertion in test/t/class.rb 2019-03-02 18:55:02 +09:00
Yukihiro "Matz" Matsumoto ad45f51caf Remove unused gem.bin= method; close #4271 2019-03-02 15:57:39 +09:00
Yukihiro "Matz" Matsumoto af51119d3a Raise error on failed comparison in sort; ref #4307 2019-03-02 15:46:50 +09:00
Yukihiro "Matz" Matsumoto 73091ab202 Do not apply mrb_ptr() to immediate objects; fix #4307 2019-03-02 15:45:15 +09:00
Yukihiro "Matz" Matsumoto ca0dcbb226 Free struct mrb_time before error; fix #4308
To avoid memory leak from `time_update_datetime`.
2019-03-02 14:13:06 +09:00
Yukihiro "Matz" Matsumoto e5649eba70 Remove useless regression tests; ref #4306 2019-03-02 14:01:52 +09:00
Yukihiro "Matz" Matsumoto 997cc8238d Remove useless regression tests; fix #4306 2019-03-02 14:00:25 +09:00
Yukihiro "Matz" Matsumoto 13e0a48e3c Print length of the iseq in code dump header; fix #4304 2019-03-02 13:51:46 +09:00
Yukihiro "Matz" Matsumoto 48fb239efb Merge pull request #4305 from shuujii/add-warning-prefix-to-parser-warning-message
Add `warning: ` prefix to parser warning message
2019-03-01 06:58:33 +09:00
KOBAYASHI Shuji 8c04ba2222 Add warning: prefix to parser warning message 2019-02-28 19:54:45 +09:00
Yukihiro "Matz" Matsumoto d25b9c9d0e Remove unnecessary backticks; ref #4301 2019-02-28 12:59:16 +09:00
Yukihiro "Matz" Matsumoto f1fb2bf29e Remove ?A style string literals from string tests; #4303
We have a plan to obsolete this style in the future.
2019-02-28 12:55:44 +09:00
Yukihiro "Matz" Matsumoto 4f3067fe2f Merge pull request #4301 from shuujii/remove-unnecessary-backticks
Remove unnecessary backticks; ref #2858
2019-02-28 12:55:26 +09:00
Yukihiro "Matz" Matsumoto 5424640f6f Merge pull request #4303 from dearblue/string-literal-concatenation
String literal concatenation
2019-02-28 07:05:08 +09:00
dearblue f9a568adcb Add test for string literal concatenation 2019-02-27 22:58:13 +09:00
dearblue e871a1538d Compositing NODE_DSTR and NODE_DSTR 2019-02-27 22:58:13 +09:00
dearblue 4d2bb3cb47 Compositing NODE_DSTR and NODE_STR 2019-02-27 22:58:13 +09:00
dearblue 8ead6da913 Compositing NODE_STR and NODE_DSTR 2019-02-27 22:58:13 +09:00
dearblue 25957421bc Replacement to function for composite two string nodes 2019-02-27 22:58:13 +09:00
dearblue 477e5285e8 Replacement to function for NODE_STR cheking 2019-02-27 22:58:09 +09:00
dearblue 9913643ed8 Compositing NODE_STR and NODE_STR 2019-02-27 22:57:45 +09:00
dearblue cece016389 Concatenate string literals 2019-02-27 22:35:53 +09:00
Yukihiro "Matz" Matsumoto 6962d0ddde Merge pull request #4302 from shuujii/add-newline-to-warning-by-mrb_warn
Add newline to warning by `mrb_warn()`
2019-02-27 22:33:22 +09:00
Yukihiro "Matz" Matsumoto 759b57d22a Merge pull request #4300 from shuujii/use-yywarning-instead-of-yywarning_s-for-MRB_WITHOUT_FLOAT
Use `yywarning()` instead of `yywarning_s()` for `MRB_WITHOUT_FLOAT`
2019-02-27 22:32:31 +09:00
KOBAYASHI Shuji 62bb9c6436 Add newline to warning by mrb_warn() 2019-02-27 20:58:20 +09:00
KOBAYASHI Shuji c11bd075f7 Remove unnecessary backticks; ref #2858 2019-02-27 20:27:29 +09:00
KOBAYASHI Shuji 2894625089 Use yywarning() instead of yywarning_s() for MRB_WITHOUT_FLOAT 2019-02-27 20:21:40 +09:00
Yukihiro "Matz" Matsumoto 018f4bd32e Merge pull request #4299 from shuujii/remove-unneeded-separator-in-test-skip-error-messages
Remove unneeded `=>` in test skip/error messages
2019-02-27 07:29:17 +09:00
Yukihiro "Matz" Matsumoto d544401f1f Merge pull request #4298 from shuujii/remove-unneeded-const_defined-Time-in-mruby-io-test
Remove unneeded `const_defined?(:Time)` in `mruby-io` test
2019-02-26 21:49:32 +09:00
KOBAYASHI Shuji fdb7f9dad3 Remove unneeded => in test skip/error messages 2019-02-26 21:32:34 +09:00
KOBAYASHI Shuji c6cd69970b Remove unneeded const_defined?(:Time) in mruby-io test
`mruby-time` is included in test dependencies.
2019-02-26 21:12:41 +09:00
Yukihiro "Matz" Matsumoto 68f421c859 Merge pull request #4294 from shuujii/remove-explicit-set-of-DISABLE_GEMS
Remove explicit set of `DISABLE_GEMS`
2019-02-25 23:49:16 +09:00
Yukihiro "Matz" Matsumoto 6337bde8a5 Merge pull request #4296 from shuujii/refine-mrbgem-name-in-assertion-failure-message-for-core-test
Refine mrbgem name in assertion failure/skip message for core test
2019-02-25 23:48:04 +09:00
Yukihiro "Matz" Matsumoto 96b12b9813 Merge pull request #4297 from shuujii/refactor-src-backtrace.c
Refactor `src/backtrace.c`
2019-02-25 23:46:24 +09:00
KOBAYASHI Shuji c49a10f9a0 Refactor src/backtrace.c
- Move calling `mrb_debug_get_filename()` to after `lineno` check.
- Remove unneeded array check in `print_backtrace()`.
- Add a few `const` qualifier.
2019-02-25 20:39:20 +09:00
KOBAYASHI Shuji 5c40203930 Refine mrbgem name in assertion failure/skip message for core test 2019-02-24 19:21:40 +09:00
Yukihiro "Matz" Matsumoto ad87fd2287 Merge pull request #4295 from wataash/struct-dig
Move `Object#dig` to `Struct#dig`
2019-02-24 18:13:56 +09:00
Wataru Ashihara e91f3ec770 Move Object#dig to Struct#dig
This method seems to be mistakenly put into `Object` instead of `Struct`
since it's in `struct.rb` and daf83946b says:

  add #dig to Array,Hash and Struct
2019-02-24 16:59:02 +09:00
KOBAYASHI Shuji 31f1b4a553 Remove explicit set of DISABLE_GEMS
`DISABLE_GEMS` is automatically set (or unset); ref #790
2019-02-23 18:29:37 +09:00
Yukihiro "Matz" Matsumoto f5cfb77078 Merge pull request #4293 from shuujii/integrate-init_mrbtest.c-to-driver.c-in-mruby-test-mrbgem
Integrate `init_mrbtest.c` to `driver.c` in `mruby-test` mrbgem
2019-02-23 10:31:40 +09:00
KOBAYASHI Shuji f209f781ac Integrate init_mrbtest.c to driver.c in mruby-test mrbgem
- `mrbgemtest_init()` is needed if `DISABLE_GEMS` is enabled because core
  tests are run as part of `mruby-test` mrbgem (moreover, `DISABLE_GEMS` is
  disabled when `enable_test` is used in build config).
- For the same reason `mrb_open_core()` etc for core tests is unneeded.
2019-02-22 20:41:20 +09:00
Yukihiro "Matz" Matsumoto 5cc277340f Merge pull request #4291 from shuujii/fix-typo-in-lib-mruby-build-command.rb
Fix typo in `lib/mruby/build/command.rb`
2019-02-21 22:40:17 +09:00
Yukihiro "Matz" Matsumoto 769b56c3ae Merge pull request #4290 from shuujii/refactor-exception-handling-in-assert
Refactor exception handling in `assert`
2019-02-21 22:37:09 +09:00
KOBAYASHI Shuji 37fb5f929f Fix typo in lib/mruby/build/command.rb 2019-02-21 19:47:00 +09:00
KOBAYASHI Shuji ad789944db Refactor exception handling in assert 2019-02-21 17:44:45 +09:00
Yukihiro "Matz" Matsumoto 76262b8e28 Merge pull request #4288 from shuujii/assert_true-should-pass-when-actual-is-only-true
`assert_true`/`assert_false` should pass when actual is only `true`/`false`
2019-02-20 19:42:01 +09:00
KOBAYASHI Shuji 244abdae09 assert_true/assert_false should pass when actual is only true/false
For the following reasons:

- Previous behavior is confusable because it's different from test/unit rubygem's `assert_true`
- Tests may pass unintentionally in an inappropriate way; ref #4285 #4287
2019-02-20 18:49:38 +09:00
Yukihiro "Matz" Matsumoto baf8fbe6ed Merge pull request #4286 from kimushu/mrdb-local-variables
mrdb: add "info locals" command
2019-02-19 20:44:16 +09:00
Yukihiro "Matz" Matsumoto 8781596c35 Merge pull request #4287 from shuujii/use-more-appropriate-assertion-methods
Use more appropriate assertion methods
2019-02-19 20:31:10 +09:00
KOBAYASHI Shuji 8a7298e069 Use more appropriate assertion methods 2019-02-19 20:02:50 +09:00
kimu_shu 477ffc7473 Add "info locals" command to mrdb 2019-02-19 18:10:05 +09:00
Yukihiro "Matz" Matsumoto 971bfd13c1 Merge pull request #4284 from shuujii/use-assert_same-instead-of-assert_equal-in-enum-reverse_each-test
Use `assert_same` instead of `assert_equal` in `Enumerable#reverse_each` test
2019-02-18 21:50:08 +09:00
Yukihiro "Matz" Matsumoto 4164d4efdf Merge pull request #4285 from shuujii/fix-wrong-assertin-method-in-some-tests
Fix wrong assertion method in some tests
2019-02-18 21:47:41 +09:00
KOBAYASHI Shuji d68eb3d043 Fix wrong assertion method in some tests 2019-02-18 21:24:20 +09:00
KOBAYASHI Shuji f86e4a5d93 Use assert_same instead of assert_equal in Enumerable#reverse_each test 2019-02-18 21:06:18 +09:00
Yukihiro "Matz" Matsumoto 9215c85450 Parenthesize expression to suppress warning; ref #4278 2019-02-18 17:25:01 +09:00
Yukihiro "Matz" Matsumoto 4ccc3f1525 Use key argument register for OP_KEY_P to reduce register use. 2019-02-18 17:25:01 +09:00
Yukihiro "Matz" Matsumoto e986dfa8aa Merge pull request #4283 from shuujii/reorder-members-in-struct-backtrace_location
Reorder members in `struct backtrace_location`
2019-02-18 17:24:48 +09:00
Yukihiro "Matz" Matsumoto 93e25f4aaa Merge pull request #4282 from shuujii/remove-unneeded-memset-in-backtrace.c
Remove unneeded `memset()` in `src/backtrace.c`
2019-02-18 17:24:16 +09:00
KOBAYASHI Shuji a28d714398 Reorder members in struct backtrace_location
`sizeof(struct backtrace_location)` is 24 bytes -> 16 bytes in LP64
data model etc.
2019-02-18 16:38:56 +09:00
KOBAYASHI Shuji 15344dfd0b Remove unneeded memset() in src/backtrace.c 2019-02-18 16:12:12 +09:00
Yukihiro "Matz" Matsumoto 3e0d29b7be Merge pull request #4279 from dearblue/fix-inline-packed-symbols
Fix destroyed "inline packed symbols" on 32 bit mode with `MRB_WORD_BOXING`
2019-02-17 22:13:22 +09:00
Yukihiro "Matz" Matsumoto a3e8b750ef Merge pull request #4280 from shuujii/refine-deps-for-mruby-config
Refine dependencies for `mruby-config`
2019-02-17 22:12:19 +09:00
Yukihiro "Matz" Matsumoto 391b5aa0d8 Merge pull request #4281 from yui-knk/typos [ci skip
Fix typos
2019-02-17 22:11:32 +09:00
yui-knk f614eed13a Fix typos 2019-02-17 21:34:33 +09:00
KOBAYASHI Shuji b3e0a13989 Refine dependencies for mruby-config 2019-02-17 15:52:16 +09:00
dearblue 5067a5cd58 Use const int instead of enum 2019-02-16 22:13:16 +09:00
Yukihiro "Matz" Matsumoto 21933b7790 Merge pull request #4278 from shuujii/add-length-argument-for-sym_inline_unpack
Add length argument for `sym_inline_unpack()`
2019-02-16 21:52:39 +09:00
dearblue 81cbc92513 Fix inline packed symbols on 32 bit mode with MRB_WORD_BOXING 2019-02-16 21:26:45 +09:00
dearblue d1db959cab Fix to defined MRB_SYMBOL_BITSIZE and MRB_SYMBOL_MAX always; ref #4077 2019-02-16 21:24:05 +09:00
KOBAYASHI Shuji 2c8af128f4 Add length argument for sym_inline_unpack()
`sym_inline_unpack_with_bit()` is moved inside of `sym_inline_unpack()`
because this is used only one place.
2019-02-16 20:48:33 +09:00
Yukihiro "Matz" Matsumoto c769013f9b Merge pull request #4277 from shuujii/extract-code-fragment-for-unpacking-in-sym_inline_unpack
Extract code fragment for unpacking into method in `sym_inline_unpack()`
2019-02-15 20:12:49 +09:00
KOBAYASHI Shuji 5b10439f6f Extract code fragment for unpacking into method in sym_inline_unpack() 2019-02-15 19:48:00 +09:00
Yukihiro "Matz" Matsumoto cc94c8bf9d Merge pull request #4276 from shuujii/use-assert-for-checking-sym-in-sym_inline_unpack
Use `mrb_assert()` for checking `sym` in `sym_inline_unpack()`
2019-02-15 16:34:18 +09:00
Yukihiro "Matz" Matsumoto 702a868b86 Merge pull request #4275 from shuujii/add-const-to-pack_table-in-symbol.c
Add `const` to `pack_table` in `src/symbol.c`
2019-02-14 20:12:03 +09:00
KOBAYASHI Shuji 921af6923d Use mrb_assert() for checking sym in sym_inline_unpack() 2019-02-14 18:48:41 +09:00
KOBAYASHI Shuji bedd672571 Add const to pack_table to src/symbol.c 2019-02-14 18:44:00 +09:00
Yukihiro "Matz" Matsumoto 01c908117d Merge pull request #4274 from shuujii/lazy-message-diff-creation-for-assertion
Lazy message/diff creation for assertion in `test/assert.rb`
2019-02-14 13:10:48 +09:00
KOBAYASHI Shuji 6cdac5efb6 Lazy message/diff creation for assertion in test/assert.rb
Include the following changes too:

- Extract part of logic with block to a method
- Use `var ||= ...` instead of `var = ... unless var`
- Unify using parentheses for `t_print`
- Change methods order
2019-02-14 09:04:42 +09:00
Yukihiro "Matz" Matsumoto a6c0aa8306 Merge pull request #4269 from shuujii/always-through-assert_true-for-assertion
Always through `assert_true` for assertion methods in `test/assert.rb`
2019-02-13 07:10:13 +09:00
Yukihiro "Matz" Matsumoto ae5ff737e0 Merge pull request #4273 from shuujii/refine-mruby-bin-config-mrbgem.rake
Refine `mrbgems/mruby-bin-config/mrbgem.rake`
2019-02-13 07:09:07 +09:00
KOBAYASHI Shuji c592c093aa Refine mrbgems/mruby-bin-config/mrbgem.rake
- Use `MRuby::Gem::Specification`
- Fix a binary name is added to `MRuby::Build#bins` multiple times
- Close file immediately (avoid using `open(...).read`)
- Simplify
2019-02-12 21:45:38 +09:00
Yukihiro "Matz" Matsumoto 37bc343e0a Disable Symbol.all_symbols. 2019-02-12 17:30:34 +09:00
Yukihiro "Matz" Matsumoto 06ba5905f0 Implement inline packed symbols.
Small symbols with all alphanumeric characters (<5) are packed in 32bit
symbol integer a la base64. This means those small symbols are not
listed in `Symbol.all_symbols`.
2019-02-12 17:30:34 +09:00
Yukihiro "Matz" Matsumoto 3a95bf0ddb Merge pull request #4272 from shuujii/refactor-for-node_back_ref-in-codegen
Small refactoring in `codegen.c`
2019-02-11 22:47:43 +09:00
KOBAYASHI Shuji c6e2d91536 Small refactoring in codegen.c 2019-02-11 21:09:40 +09:00
Yukihiro "Matz" Matsumoto ef93ff6405 Should not copy keys&values when a hash table is empty; fix #4270 2019-02-11 15:20:34 +09:00
Yukihiro "Matz" Matsumoto 639f6e2799 No strict argument check for blocks when keyword arguments exist; ref #4270 2019-02-11 15:20:34 +09:00
Yukihiro "Matz" Matsumoto 55e58d8512 Merge pull request #4268 from dearblue/null-safe-mrb_open_core
NULL safed `mrb_open_core()`
2019-02-10 08:58:10 +09:00
KOBAYASHI Shuji e60f5f5cee Always through assert_true for assertion methods in test/assert.rb 2019-02-09 21:48:12 +09:00
dearblue eb6aee117b mrb_default_allocf() is default allocator for NULL safe 2019-02-09 20:22:08 +09:00
Yukihiro "Matz" Matsumoto fc883de458 Merge pull request #4266 from shuujii/add-no_method_error-tests-to-enumerator
Add `NoMethodError` tests to `mruby-enumerator`
2019-02-08 23:28:38 +09:00
KOBAYASHI Shuji 19740d45a1 Add NoMethodError tests to mruby-enumerator 2019-02-08 17:40:12 +09:00
Yukihiro "Matz" Matsumoto 3d73a29783 Merge branch 'shuujii-fix-enumerator-initialize-for-nil-or-false' 2019-02-08 09:35:34 +09:00
Yukihiro "Matz" Matsumoto e0bc87297e Update mruby-enumerator test to conform the last update. 2019-02-08 09:35:28 +09:00
Yukihiro "Matz" Matsumoto 9ab7c1111b Update #4265 patch.
* Update doc comment to clarify `Enumerator.new` without a block is
  deprecated and left only for internal use.

* Fixed some cases `mruby` raise `ArgumentError` too eagerly compared
  with `CRuby`.
2019-02-08 09:35:28 +09:00
KOBAYASHI Shuji 2650999092 Fix Enumerator#(initialize|inspect) for nil/false 2019-02-08 09:35:28 +09:00
Yukihiro "Matz" Matsumoto c32e3158f5 Update mruby-enumerator test to conform the last update. 2019-02-08 09:34:31 +09:00
Yukihiro "Matz" Matsumoto 32f3ffa2c9 Update #4265 patch.
* Update doc comment to clarify `Enumerator.new` without a block is
  deprecated and left only for internal use.

* Fixed some cases `mruby` raise `ArgumentError` too eagerly compared
  with `CRuby`.
2019-02-08 09:31:55 +09:00
Yukihiro "Matz" Matsumoto 60529fdeeb Merge branch 'fix-enumerator-initialize-for-nil-or-false' of https://github.com/shuujii/mruby into shuujii-fix-enumerator-initialize-for-nil-or-false 2019-02-08 09:13:39 +09:00
Yukihiro "Matz" Matsumoto 687a4d961f Merge pull request #4251 from shuujii/remove-no-meaning-statements-in-mruby-io-tests
Remove no meaning statements in `mruby-io` tests
2019-02-08 07:19:40 +09:00
KOBAYASHI Shuji e846db709f Fix Enumerator#(initialize|inspect) for nil/false 2019-02-07 23:52:08 +09:00
Yukihiro "Matz" Matsumoto bdc9de875f Add OP_ENTER to blocks without parameters; fix #4175
So that `lambda{}.call(1)` raises `ArgumentError` as CRuby does.
Also, fixed junk assignment for `lambda{|;a|p a}.call{}`.
2019-02-07 22:44:36 +09:00
Yukihiro "Matz" Matsumoto 156641515c Merge branch 'shuujii-rename-bin-mruby-config-to-bin-config' 2019-02-07 15:54:08 +09:00
Yukihiro "Matz" Matsumoto e199df032d Merge branch 'rename-bin-mruby-config-to-bin-config' of https://github.com/shuujii/mruby into shuujii-rename-bin-mruby-config-to-bin-config 2019-02-07 15:52:58 +09:00
Yukihiro "Matz" Matsumoto 6397ec727f Raise NameError for symbol struct access. 2019-02-07 15:52:33 +09:00
Yukihiro "Matz" Matsumoto 215906dc83 Merge pull request #4264 from shuujii/integrate-definition-of-exefile
Integrate definition of `MRuby::Build#exefile`
2019-02-07 07:05:05 +09:00
Yukihiro "Matz" Matsumoto d52f46da45 Implement symbol hash table to boost find_symbol.
In 4174e02, we removed the symbol hash table from `mrb_state` but
`find_symbol` was too slow with linear search. My performance estimation
was wrong. So we implemented a new compact hash table for symbols.
2019-02-06 22:07:11 +09:00
Yukihiro "Matz" Matsumoto 905fef2669 Reduce invocation of mrb_convert_type() from mrb_str_to_str(). 2019-02-06 22:07:11 +09:00
Yukihiro "Matz" Matsumoto 02fbb2c211 Remove symbol hash table from mrb_state structure.
Use linear search instead. Number of symbols is usually small (<1K), so
we don't need performance boost from hash tables. In our benchmark
measurement, hash tables consumes 790KB for `build/full-debug/mrbtest`.
2019-02-06 22:07:11 +09:00
KOBAYASHI Shuji c8628f7ca4 Integrate definition of MRuby::Build#exefile 2019-02-06 22:05:10 +09:00
Yukihiro "Matz" Matsumoto 1076bebde7 Merge pull request #4256 from shuujii/move-none-to-mrblib-enum
Move `NONE` to `mrblib/enum.rb`
2019-02-06 20:18:45 +09:00
Yukihiro "Matz" Matsumoto cb8bbd9e12 Merge pull request #4262 from shuujii/remove-old-comment-in-symbol
Remove old comment for `mrb_sym2name_len()` [ci skip]
2019-02-05 22:51:26 +09:00
Yukihiro "Matz" Matsumoto f51c0f5a59 Merge pull request #4261 from shuujii/fix-doc-markup-in-string
Fix markup and remove unneeded comment for doc in `src/string.c` [ci skip]
2019-02-05 22:50:56 +09:00
KOBAYASHI Shuji 5ef1e479da Remove old comment for mrb_sym2name_len() [ci skip] 2019-02-05 19:16:23 +09:00
KOBAYASHI Shuji 7a2865cfef Fix markup and remove unneeded comment for doc in src/string.c [ci skip] 2019-02-05 19:11:59 +09:00
Yukihiro "Matz" Matsumoto db2545cb3c Merge pull request #4260 from shuujii/fix-symbol-size-with-mrb_utf8_string
Fix `Symbol#size` for multi-byte characters with `MRB_UTF8_STRING`
2019-02-04 21:11:06 +09:00
KOBAYASHI Shuji 69fd1a5925 Fix Symbol#size for multi-byte characters with MRB_UTF8_STRING
Before:

  p :あ.size  #=> 3

After:

  p :あ.size  #=> 1
2019-02-04 18:11:22 +09:00
Yukihiro "Matz" Matsumoto 5fd9f68b27 Merge pull request #4259 from shuujii/use-eException_class-instead-of-mrb_class_get
Use `mrb->eException_class` instead of `mrb_class_get()`
2019-02-04 07:35:00 +09:00
KOBAYASHI Shuji c86861bddf Use mrb->eException_class instead of mrb_class_get() 2019-02-03 22:00:55 +09:00
Yukihiro "Matz" Matsumoto 3f7137feae Merge pull request #4258 from shuujii/extend-only-when-necessary
Extend only when necessary in `lib/mruby-core-ext.rb`
2019-02-02 21:14:55 +09:00
KOBAYASHI Shuji 668ed60521 Extend only when necessary in lib/mruby-core-ext.rb 2019-02-02 18:53:49 +09:00
KOBAYASHI Shuji 6da3cd5d22 Move NONE to mrblib/enum.rb 2019-02-01 16:02:01 +09:00
KOBAYASHI Shuji 465fdde52d Enumerator#size is not supported [ci skip] 2019-01-31 21:25:35 +09:00
Yukihiro "Matz" Matsumoto 32067b5005 Merge pull request #4254 from shuujii/remove-unneeded-dup-in-enumerator-initialize
Remove unneeded `dup` in `Enumerator#initialize`
2019-01-31 16:20:11 +09:00
KOBAYASHI Shuji 6218585968 Remove unneeded dup in Enumerator#initialize 2019-01-30 19:41:32 +09:00
Yukihiro "Matz" Matsumoto cc32cc50f8 Merge pull request #4253 from shuujii/remove-unused-macro-in-string
Remove unused macro in `src/string.c`
2019-01-29 23:10:27 +09:00
KOBAYASHI Shuji 486154ce34 Remove unused macro in src/string.c 2019-01-29 20:21:25 +09:00
Yukihiro "Matz" Matsumoto c02c4047f8 Merge pull request #4252 from shuujii/class-expr-with-empty-body-should-return-nil
`class`/`module` expression  with empty body should return `nil`
2019-01-28 23:14:22 +09:00
KOBAYASHI Shuji abbc501433 class/module expression with empty body should return nil
Before:

  p(class A end)          #=> A
  p(class << self; end)   #=> #<Class:#<Object:0x7fdc3880e420>>
  p(module B end)         #=> B

After/Ruby:

  p(class A end)          #=> nil
  p(class << self; end)   #=> nil
  p(module B end)         #=> nil
2019-01-28 21:29:55 +09:00
KOBAYASHI Shuji 12ba571a13 Use assertion methods in FileTest tests 2019-01-28 12:17:41 +09:00
KOBAYASHI Shuji e85cb9799c Remove no meaning statements in mruby-io tests 2019-01-27 20:35:41 +09:00
Yukihiro "Matz" Matsumoto 1b597f9da4 Merge pull request #4249 from takkaw/fix_time_carry_up_and_down
fix Time about carry-up and carry-down
2019-01-27 11:41:31 +09:00
takkaw 995a329bf4 fix Time about carry-up and carry-down 2019-01-26 23:19:53 +09:00
Yukihiro "Matz" Matsumoto 8a988643e8 Merge pull request #4241 from shuujii/fix-tests-for-string-reverse-with-mrb-utf8-string
Fix tests for `String#reverse` with `MRB_UTF8_STRING`
2019-01-26 22:34:05 +09:00
Yukihiro "Matz" Matsumoto a03e721408 Merge pull request #4237 from dearblue/fix-memleak-Data_Wrap_Struct
Fix memory leak `sval` when out of memory in `Data_Wrap_Struct()`
2019-01-26 22:33:23 +09:00
Yukihiro "Matz" Matsumoto 2f62178dda Merge pull request #4235 from shuujii/avoid-side-effect-when-run-rake
Avoid a side effect when run Rake without execution of tasks
2019-01-26 22:19:00 +09:00
Yukihiro "Matz" Matsumoto 1e67c98c85 Merge pull request #4248 from shuujii/refine-error-message-for-time-interval
Refine error message for time interval
2019-01-26 22:17:31 +09:00
KOBAYASHI Shuji 1cd57006f3 Refine error message for time interval
Time interval value can be zero, and float (in `Kernel#sleep`)
2019-01-26 18:37:53 +09:00
Yukihiro "Matz" Matsumoto aee67eaf62 Merge pull request #4240 from shuujii/refactor-sleep-test
Use `assert_raise` and `assert_nothing_raised` in `mruby-sleep` tests
2019-01-25 22:47:56 +09:00
Yukihiro "Matz" Matsumoto fc5dc5270c Merge pull request #4245 from shuujii/remove-assert_nothing_raised-in-io-test
Remove definition of `assert_nothing_raised` in `IO` test
2019-01-25 22:47:15 +09:00
Yukihiro "Matz" Matsumoto a2615900c0 Merge pull request #4246 from shuujii/use-assertion-methods-in-file-test
Use assertion methods in `File` test
2019-01-25 22:46:12 +09:00
Yukihiro "Matz" Matsumoto 89a76f4a49 Merge pull request #4247 from shuujii/remove-unused-file-for-mruby-io-test
Remove unused file for `mruby-io` test
2019-01-25 22:45:08 +09:00
KOBAYASHI Shuji b91a17b33b Remove unused file for mruby-io test 2019-01-25 20:35:55 +09:00
KOBAYASHI Shuji e9a6ec05b6 Use assertion methods in File test 2019-01-25 20:12:24 +09:00
KOBAYASHI Shuji bdbbac999f Remove definition of assert_nothing_raised in IO test 2019-01-25 20:02:45 +09:00
Yukihiro "Matz" Matsumoto 671447964f Merge pull request #4243 from shuujii/remove-definition-of-sprintf-in-mruby-print
Remove definition of `Kernel#sprintf` in `mruby-print`
2019-01-25 08:15:27 +09:00
Yukihiro "Matz" Matsumoto 8eddcbf53d Merge pull request #4244 from shuujii/remove-redundant-null-check-for-mrb_malloc
Remove redundant `NULL` check for `mrb_malloc`
2019-01-24 22:20:56 +09:00
KOBAYASHI Shuji a4c5fcc038 Remove redundant NULL check for mrb_malloc 2019-01-24 20:53:40 +09:00
KOBAYASHI Shuji 1d6679e9d1 Remove definition of Kernel#sprintf in mruby-print 2019-01-24 20:44:55 +09:00
Yukihiro "Matz" Matsumoto 5956f5b4e8 Merge pull request #4242 from shuujii/remove-no-meaning-statement
[ci skip] Remove no meaning statement in `bm_app_lc_fizzbuzz.rb`
2019-01-23 21:50:09 +09:00
KOBAYASHI Shuji f54262776e [ci skip] Remove no meaning statement in bm_app_lc_fizzbuzz.rb 2019-01-23 21:19:39 +09:00
KOBAYASHI Shuji 6d5a62cf5f Fix tests for String#reverse with MRB_UTF8_STRING 2019-01-22 19:37:14 +09:00
KOBAYASHI Shuji 3707ef3d1c Use assert_raise and assert_nothing_raised in mruby-sleep tests 2019-01-21 19:37:20 +09:00
KOBAYASHI Shuji 8c22911c86 Rename mruby-bin-mruby-config mrbgem to mruby-bin-config
For brevity and consistency (e.g. `mruby-bin-strip` doesn't have `mruby-`
after `bin-`).
2019-01-20 19:47:58 +09:00
dearblue d6d02774c5 Fix memory leak sval when out of memory in Data_Wrap_Struct() 2019-01-20 14:23:22 +09:00
Yukihiro "Matz" Matsumoto b83e4df43d Merge pull request #4236 from shuujii/remove-gitkeep
Remove `.gitkeep` files
2019-01-20 10:30:12 +09:00
KOBAYASHI Shuji dff0f2ee10 Remove .gitkeep files 2019-01-19 20:40:21 +09:00
KOBAYASHI Shuji 107dc0c778 Avoid a side effect when run Rake without execution of tasks
Avoid directory creation when run `rake -T` etc.
2019-01-18 23:29:35 +09:00
Yukihiro "Matz" Matsumoto cb1946f26c Merge pull request #4233 from shuujii/remove-special-treatments-for-without-float-in-build-scripts
Remove special treatments for `MRB_WITHOUT_FLOAT` in build scripts
2019-01-18 16:17:58 +09:00
Yukihiro "Matz" Matsumoto 3d32be6f3e Merge pull request #4231 from shuujii/avoid-runtime-eval-for-without-float
Avoid runtime evaluation for `MRB_WITHOUT_FLOAT`
2019-01-18 16:16:48 +09:00
Yukihiro "Matz" Matsumoto 9a2366ded6 Merge pull request #4234 from shuujii/fix-assertion-name-for-numeric-test
Fix assertion name for `Numeric#**` test
2019-01-18 16:16:19 +09:00
KOBAYASHI Shuji cfe3654fd1 Fix assertion name for Numeric#** test 2019-01-17 21:16:02 +09:00
KOBAYASHI Shuji 366a14f297 Remove special treatments for MRB_WITHOUT_FLOAT in build scripts 2019-01-16 23:48:59 +09:00
KOBAYASHI Shuji 8969edf03b Avoid runtime evaluation for MRB_WITHOUT_FLOAT 2019-01-16 19:32:29 +09:00
Yukihiro "Matz" Matsumoto fa34a8b5be Merge pull request #4230 from shuujii/fix-coercing-for-step-counter-in-numeric-step
Fix coercing for first step counter in `Numeric#step`
2019-01-15 22:27:40 +09:00
KOBAYASHI Shuji de5da4b7f6 Fix coercing for first step counter in Numeric#step
Before:

  a=[]; 7.step(4, -3.0) { |c| a << c }; p a  #=> [7, 4.0]

After / Ruby:

  a=[]; 7.step(4, -3.0) { |c| a << c }; p a  #=> [7.0, 4.0]
2019-01-15 21:41:54 +09:00
Yukihiro "Matz" Matsumoto 348442dd5e Merge pull request #4228 from shuujii/sort-gitignore
[ci skip] Sort `.gitignore`
2019-01-15 20:09:00 +09:00
KOBAYASHI Shuji adfc2d08c9 [ci skip] Sort .gitignore 2019-01-15 19:30:15 +09:00
Yukihiro "Matz" Matsumoto 127d355bf8 Merge pull request #4226 from dearblue/fix-build-cxx-exc
Build fails when set `conf.build_dir=<rel path>` and `conf.enable_cxx_exception`
2019-01-15 11:00:05 +09:00
Yukihiro "Matz" Matsumoto 4797542b71 Merge pull request #4227 from shuujii/ignore-compiler-tmp-files
Ignore compiler temporary files (for `-save-temps` flag)
2019-01-15 10:57:44 +09:00
KOBAYASHI Shuji bb52efd0fc Ignore compiler temporary files (for -save-temps flag) 2019-01-14 21:45:57 +09:00
Yukihiro "Matz" Matsumoto 17333bde3a Merge pull request #4222 from shuujii/use-g-instead-of-e
Use `%g` instead of `%e` for float representation in dump format
2019-01-14 19:13:48 +09:00
Yukihiro "Matz" Matsumoto 348526e1ad Merge pull request #4225 from shuujii/improve-compatibility-to-cruby-for-float-to_s
Improve compatibility to CRuby for `Float#to_s`
2019-01-14 19:13:09 +09:00
dearblue a7c2ef9dab Fix build failed when set conf.build_dir=<rel path> and conf.enable_cxx_exception 2019-01-14 15:21:21 +09:00
KOBAYASHI Shuji 0e04c46261 Use 2 digits exponent format for printf family on old MSVC
For conforming C standard.
2019-01-13 23:24:57 +09:00
KOBAYASHI Shuji 9f081183d2 Improve compatibility to CRuby for Float#to_s
Bfore:

  Float::INFINITY.to_s  #=> "inf"
  50.0.to_s             #=> "50"
  1e20.to_s             #=> "1e+20"

After / CRuby:

  Float::INFINITY.to_s  #=> "Infinity"
  50.0.to_s             #=> "50.0"
  1e20.to_s             #=> "1.0e+20"
2019-01-13 19:59:22 +09:00
Yukihiro "Matz" Matsumoto c1b92f88a2 Merge pull request #4224 from shuujii/use-__send__-instead-of-send
Use `__send__` instead of `send`; ref #4207
2019-01-13 08:03:14 +09:00
KOBAYASHI Shuji 8b951710fe Use __send__ instead of send; ref #4207 2019-01-12 22:21:34 +09:00
KOBAYASHI Shuji 2d8aec2b88 Use %g instead of %e for float representation in dump format
`%g` use shorter representation than `%e`.
2019-01-11 19:54:46 +09:00
Yukihiro "Matz" Matsumoto 980b7b5c50 Merge pull request #4221 from shuujii/remove-duplicate-code-in-numeric
Remove duplicate code in numeric.c
2019-01-11 08:47:02 +09:00
KOBAYASHI Shuji 856b8d9610 Remove duplicate code in numeric.c 2019-01-10 23:22:23 +09:00
Yukihiro "Matz" Matsumoto 8dcd66cc27 Merge pull request #4220 from shuujii/change-order-for-assertion-args
Change the order of "expected" and "actual" in test
2019-01-10 09:19:17 +09:00
KOBAYASHI Shuji 0740595f85 Change the order of "expected" and "actual" in test 2019-01-09 20:00:17 +09:00
Yukihiro "Matz" Matsumoto d88d7aaf4b Use $mrbtest_io_wfname for chmod test. 2019-01-09 13:04:23 +09:00
Yukihiro "Matz" Matsumoto 81862fd689 Update compiled binary format version; ref #4219 2019-01-08 21:44:40 +09:00
Yukihiro "Matz" Matsumoto d38a8e8807 Update OP_APOST description (typo fixed). 2019-01-08 21:43:04 +09:00
Yukihiro "Matz" Matsumoto 712a8bb1b2 Merge pull request #4219 from shuujii/fix-dump-load-float-literal-evaluate-to-infinity
Fix dump/load float leteral evaluate to infinity
2019-01-08 21:42:50 +09:00
Yukihiro "Matz" Matsumoto b575d0c45e Merge pull request #4218 from take-cheeze/export_time_api
Add `Time` object creation API
2019-01-08 21:35:51 +09:00
KOBAYASHI Shuji 68735d1261 Fix dump/load float leteral evaluate to infinity
Example:

  # example.rb
  p(2e308)
  p(-2e308)

  Good:

    $ bin/mruby example.rb
    inf
    -inf

  Bad:

    $ bin/mrbc example.rb
    $ bin/mruby -b example.mrb
    0
    -0

Cause:

  Float infinity representation is `inf` on dump and it is converted by
  corresponding `String#to_f` on load.

Treatment:

  - Introduce new representations (`i`: +infinity, `I`: -infinity)
  - Allow old representations (`inf`, `-inf`, `infinity`, `-infinity`) too
  - Raise error for unknown representations (use corresponding `Kernel#Float`)
2019-01-08 20:43:23 +09:00
take-cheeze 3e7a3a0a15 Export Time creation API 2019-01-08 20:26:39 +09:00
Yukihiro "Matz" Matsumoto 817436c33b Merge pull request #4217 from shuujii/fix-0.0-handling
Fix `0.0` and `-0.0` handling.
2019-01-07 18:16:27 +09:00
KOBAYASHI Shuji c8f904b7f5 Fix 0.0 and -0.0 handling.
Fix the following issue:

    Good:
    $ bin/mruby -e 'p(-0.0)' #=> "-0"

    Bad:
    $ bin/mruby -e 'a=0.0; p(-0.0)' #=> "0"
2019-01-06 23:05:13 +09:00
Yukihiro "Matz" Matsumoto 89c79e56c5 Merge pull request #4216 from shuujii/add-assert_same
Add `assert_same` and `assert_not_same`
2019-01-06 20:59:22 +09:00
KOBAYASHI Shuji 6f395a58d2 Add assert_same and assert_not_same 2019-01-05 20:41:09 +09:00
Yukihiro "Matz" Matsumoto d45a6d8363 Merge pull request #4215 from shuujii/integrate-float.rb-into-numeric.c
Integrate mrblib/float.rb into src/numeric.c
2019-01-04 20:49:42 +09:00
KOBAYASHI Shuji b30ca87bd0 Integrate mrblib/float.rb into src/numeric.c
- Avoid hack for `MRB_WITHOUT_FLOAT` in build scripts
- Avoid runtime dispatch for `MRB_WITHOUT_FLOAT`
2019-01-04 20:31:05 +09:00
Yukihiro "Matz" Matsumoto 1c574b065d Remove mrb_ prefix from static functions in mruby-range-ext; #4213 2019-01-04 14:46:17 +09:00
Yukihiro "Matz" Matsumoto 53d87c59c0 Remove unused local variable n in range_initialize; #4213 2019-01-04 14:42:47 +09:00
Yukihiro "Matz" Matsumoto 1e7d6890a5 Merge pull request #4210 from dearblue/enum-chain
Add enumerator chain feature (CRuby-2.6 compatible)
2019-01-04 14:39:20 +09:00
Yukihiro "Matz" Matsumoto 1bf6c84682 Merge pull request #4213 from shuujii/range-rafactor
range: Refactor range.h/range.c
2019-01-04 14:39:04 +09:00
Yukihiro "Matz" Matsumoto 2a9ccf2449 Merge pull request #4211 from dearblue/proc-composition
Add proc composition feature (CRuby-2.6 compatible)
2019-01-04 14:32:19 +09:00
Yukihiro "Matz" Matsumoto acb1fdc79f Merge pull request #4212 from shuujii/pack-remove-float-check
pack: Remove redundant float check in pack_utf8()
2019-01-04 14:27:58 +09:00
KOBAYASHI Shuji eb216fc858 range: Refactor range.h/range.c
Functions order, name, linkage and so on.
2019-01-03 20:09:41 +09:00
KOBAYASHI Shuji 668d632c6e pack: Remove redundant float check in pack_utf8()
The argument is converted to fixnum before calling.
2019-01-03 19:11:30 +09:00
dearblue f392337e10 Add test for Enumerator::Chain 2019-01-03 18:16:26 +09:00
dearblue fc20d0186d Add test for #<< and #>> for Proc and Method class 2019-01-03 18:16:26 +09:00
dearblue a98359faa7 Add enumerator chain feature (CRuby-2.6 compatible)
- Enumerator::Chain
  - Enumerable#chain
  - Enumerable#+
2019-01-03 18:16:26 +09:00
dearblue 9a9e12a129 Add proc composition feature (CRuby-2.6 compatible)
- Proc#<< and Proc#>>
  - Method#<< and Method#>>
2019-01-03 18:16:26 +09:00
Yukihiro "Matz" Matsumoto cca19532c5 Remove Kernel#class_defined? which is not available in CRuby; #3829 2019-01-03 11:34:35 +09:00
Yukihiro "Matz" Matsumoto f9d89e3fa5 mruby-inline-struct to support MRB_WITHOUT_FLOAT. 2019-01-03 11:29:10 +09:00
Yukihiro "Matz" Matsumoto 3e59f25eef Merge pull request #4208 from shuujii/io-skip-tty-test
io: Skip TTY test for environments that TTY device is unavailable.
2019-01-02 11:41:57 +09:00
Yukihiro "Matz" Matsumoto 4ffc280372 Merge pull request #4209 from shuujii/range-embed-edges-in-rrange
range: Embed edges in RRange on boxing environment.
2019-01-02 11:40:32 +09:00
KOBAYASHI Shuji ff0ab552d0 io: Skip TTY test for environments that TTY device is unavailable.
e.g. GitLab CI
2019-01-01 19:25:12 +09:00
KOBAYASHI Shuji 648b57620a range: Embed edges in RRange on boxing environment.
[Breaking changes]

Developers must use following APIs for accessing attributes of RRange
because RRange structure depends on boxing setting.

- mrb_range_beg
- mrb_range_end
- mrb_range_excl_p
2019-01-01 15:35:56 +09:00
Yukihiro "Matz" Matsumoto c6f9a09e39 Merge pull request #4207 from shuujii/use-__send__-instead-of-send
Use `__send__` instead of `send` in a Range test.
2019-01-01 11:24:54 +09:00
KOBAYASHI Shuji 4da687a6c3 Use __send__ instead of send in a Range test.
This assertion is accidentaly passed because `send` was removed from mruby
core so `NoMethodError` is raised and `NoMethodError` is subclass of
`NameError`.
2019-01-01 09:38:58 +09:00
Yukihiro "Matz" Matsumoto b04506cdcc Should not check non-node value to void_expr_error; fix #4203
This is also a reason for #4192 as well.
2018-12-31 12:52:27 +09:00
Yukihiro "Matz" Matsumoto 23ca1dcb4e Merge pull request #4206 from shuujii/enumerator-refine-accessor
mruby-enumerator: Refine accessors (obj/meth/args/fib).
2018-12-31 11:22:11 +09:00
Yukihiro "Matz" Matsumoto a5ad768cac Merge pull request #4204 from shuujii/fix-yacc-running-multiple-times
Fix Yacc running multiple times.
2018-12-31 11:21:11 +09:00
KOBAYASHI Shuji bc03650c6a mruby-enumerator: Refine accessors (obj/meth/args/fib).
- `fib=` writer is not used.
- All accessors are used as public (e.g. in `initialized_copy`).
2018-12-30 11:30:14 +09:00
KOBAYASHI Shuji 482b2ea01e Use each_with_object instead of reduce.
For fix Codacy issue.
2018-12-30 11:16:00 +09:00
KOBAYASHI Shuji ce5e45443e Fix Yacc running multiple times.
Example:

  $ MRUBY_CONFIG=<(echo 'MRuby::Build.new{toolchain(:gcc);gem(core:"mruby-bin-mruby");enable_test}') ./minirake

  Before:

    ...
    CC    build/host/mrbgems/gem_init.c -> build/host/mrbgems/gem_init.o
    YACC  mrbgems/mruby-compiler/core/parse.y -> build/host/mrbgems/mruby-compiler/core/y.tab.c
    YACC  mrbgems/mruby-compiler/core/parse.y -> build/host/mrbgems/mruby-compiler/core/y.tab.c
    YACC  mrbgems/mruby-compiler/core/parse.y -> build/host/mrbgems/mruby-compiler/core/y.tab.c
    YACC  mrbgems/mruby-compiler/core/parse.y -> build/host/mrbgems/mruby-compiler/core/y.tab.c
    CC    build/host/mrbgems/mruby-compiler/core/y.tab.c -> build/host/mrbgems/mruby-compiler/core/y.tab.o
    CC    build/host/mrbgems/mruby-compiler/core/y.tab.c -> build/host/mrbgems/mruby-compiler/core/y.tab.o
    CC    build/host/mrbgems/mruby-compiler/core/y.tab.c -> build/host/mrbgems/mruby-compiler/core/y.tab.o
    CC    build/host/mrbgems/mruby-compiler/core/y.tab.c -> build/host/mrbgems/mruby-compiler/core/y.tab.o
    AR    build/host/lib/libmruby_core.a
    ...

  After:

    ...
    CC    build/host/mrbgems/gem_init.c -> build/host/mrbgems/gem_init.o
    YACC  mrbgems/mruby-compiler/core/parse.y -> build/host/mrbgems/mruby-compiler/core/y.tab.c
    CC    build/host/mrbgems/mruby-compiler/core/y.tab.c -> build/host/mrbgems/mruby-compiler/core/y.tab.o
    AR    build/host/lib/libmruby_core.a
    ...
2018-12-29 10:40:06 +09:00
Yukihiro "Matz" Matsumoto 37d795dec7 Revert "Simplify full-core.gembox"
This reverts commit e20d652f22.
This change cannot handle hidden dependency between `mruby-print` and
`mruby-sprintf`; ref #4202
2018-12-25 23:17:10 +09:00
Yukihiro "Matz" Matsumoto f2b48875a4 Merge pull request #4201 from take-cheeze/patch-2
Fix `$rake_root_fiber` checking
2018-12-25 18:44:15 +09:00
Yukihiro "Matz" Matsumoto 2216fb2895 Merge pull request #4202 from shuujii/simplify-full-core-gembox
Simplify full-core.gembox
2018-12-25 18:43:45 +09:00
KOBAYASHI Shuji e20d652f22 Simplify full-core.gembox
Dependencies order is auto detected.
2018-12-25 15:23:05 +09:00
Takeshi Watanabe 5b5e54d38e Fix $rake_root_fiber checking.
https://github.com/mruby/mruby/pull/4101#pullrequestreview-187752352
2018-12-25 14:37:32 +09:00
Yukihiro "Matz" Matsumoto 45e8cb47ea Merge pull request #4200 from shuujii/add-test-dependency-for-mruby
mruby-bin-mruby: Add test dependency.
2018-12-25 09:55:32 +09:00
KOBAYASHI Shuji 1f91482585 mruby-bin-mruby: Add test dependency.
`Kernel#p` etc are used.
2018-12-25 09:47:28 +09:00
Yukihiro "Matz" Matsumoto ecd2bcc9ae Merge pull request #4199 from shuujii/refine-desc-for-rake-test
Refine description for rake test tasks.
2018-12-24 16:02:57 +09:00
KOBAYASHI Shuji 96bea076ec Refine description for rake test tasks.
Before:
    $ rake -T test
    rake test_test  # run all mruby tests

After:
    $ rake -T test
    rake test  # run all mruby tests
2018-12-24 12:12:10 +09:00
Yukihiro "Matz" Matsumoto c34aa8a63e Merge pull request #4197 from shuujii/suppress-struct-initializer-warn
Suppress a struct initializer warning
2018-12-23 22:26:55 +09:00
Yukihiro "Matz" Matsumoto 2fbea74de5 Merge pull request #4198 from dearblue/missing-macros
Suppress missing macro warns
2018-12-23 22:18:07 +09:00
dearblue 0bfeefad2a Suppress _MSC_VER warns for mingw32 2018-12-23 17:36:06 +09:00
dearblue 027f4ded34 Suppress TARGET_OS_IPHONE warns 2018-12-23 17:24:16 +09:00
dearblue be980e9a7a Suppress __FreeBSD_version warns for FreeBSD 2018-12-23 17:23:51 +09:00
dearblue 49cce74c1a Suppress __STDC_VERSION__ warns for C++ 2018-12-23 17:22:59 +09:00
KOBAYASHI Shuji b0dc163b5d Suppress a struct initializer warning
Suppress a compiler (clang) warning bellow:

    src/vm.c:104:38: warning: suggest braces around initialization of
        subobject [-Wmissing-braces]
      const mrb_value mrb_value_zero = { 0 };
                                         ^
                                         {}
2018-12-23 14:23:44 +09:00
Yukihiro "Matz" Matsumoto f6c07b8835 Merge pull request #4196 from dearblue/add-Wundef-cflags
Append cflags for undefined macro
2018-12-22 22:49:14 +09:00
Yukihiro "Matz" Matsumoto a154d657ae Merge pull request #4194 from shuujii/mirb-drop-dependency-on-mruby-print
mirb: drop dependency on mruby-print in a test
2018-12-22 22:47:27 +09:00
Yukihiro "Matz" Matsumoto 30dae4742b Merge pull request #4195 from dearblue/fix-byteorder
Fix byte order
2018-12-22 22:47:03 +09:00
dearblue 129a804136 Append cflags for undefined macro 2018-12-22 21:58:58 +09:00
dearblue b7a832bf4f Define byte order macros, if not defined it and there are alternatives 2018-12-22 21:05:27 +09:00
dearblue e9ceb865b6 Fix MRB_ENDIAN_BIG is always defined, if byte order macro is not defined 2018-12-22 20:37:51 +09:00
KOBAYASHI Shuji 6578fec779 mirb: drop dependency on mruby-print in a test 2018-12-22 17:26:11 +09:00
Yukihiro "Matz" Matsumoto 281d0ff4ea Merge pull request #4193 from dearblue/fix-assert-variable
Fix undefined variable is using
2018-12-22 13:31:06 +09:00
dearblue 9377da9775 Fix undefined variable is using 2018-12-21 23:44:38 +09:00
Yukihiro "Matz" Matsumoto aeafce23e4 Merge branch 'cubicdaiya-feature/optimize_proc_parameters' 2018-12-21 13:00:27 +09:00
Tatsuhiko Kubo d2fb4752e2 Add test for Proc#parameters 2018-12-21 12:59:38 +09:00
Tatsuhiko Kubo cc71bd51f1 optimize Proc#parameters 2018-12-21 12:59:38 +09:00
Yukihiro "Matz" Matsumoto 94b73b1440 Add NULL pointer check before void_expr_error(); fix #4192 2018-12-21 09:35:10 +09:00
Yukihiro "Matz" Matsumoto ed2bc5d4ed Simplify MRB_ENDIAN_BIG macro definition; ref #4190
`cpp` does not raise error on undefined macro access in condition.
2018-12-21 09:28:19 +09:00
Yukihiro "Matz" Matsumoto 445c64d0ad Fixed a bug on platforms without BYTE_ORDER; ref #4190 2018-12-21 09:26:48 +09:00
Yukihiro "Matz" Matsumoto f5537912ab Define MRB_ENDIAN_BIG automatically; ref #4190
You had to define this macro on big endian platforms, but it is very
error-prone. So define the macro automatically if possible.
2018-12-21 08:57:17 +09:00
Yukihiro "Matz" Matsumoto 2fdb309e55 mruby-pack should not rely on MRB_ENDIAN_BIG macro; fix #4190
The `MRB_ENDIAN_BIG` macro is originally used for `NaN` boxing.
We cannot assume it is defined on every big endian platform (#4190
is the case). So instead of relying on untrusted `MRB_ENDIAN_BIG`, we
use `BYTE_ORDER` macro with a fallback function to check endian in
runtime.
2018-12-21 08:52:31 +09:00
Yukihiro "Matz" Matsumoto 7e35c659aa Remove things we've done in TODO file. 2018-12-21 00:47:56 +09:00
Yukihiro "Matz" Matsumoto e588e9df23 Merge pull request #4191 from dearblue/parenthesis
Fix parenthesis for macros
2018-12-19 20:40:34 +09:00
Yukihiro "Matz" Matsumoto 624b126fb6 Added Android Hack to time.c.
Android bionic defines `TIME_UTC` but does not provide `timespec_get`.
2018-12-19 13:12:30 +09:00
dearblue e19353be25 Fix macro expressions with paren 2018-12-18 23:14:26 +09:00
dearblue 14133f4057 Fix macro arguments with paren 2018-12-18 23:05:36 +09:00
Yukihiro "Matz" Matsumoto 11071b9ab1 Merge pull request #4189 from sdottaka/fix-mrb_ary_clear
Make mrb_ary_clear() function callable from C again
2018-12-17 16:29:00 +09:00
Yukihiro "Matz" Matsumoto ccc5edc60d Small refactoring of #4188 2018-12-17 16:00:22 +09:00
Yukihiro "Matz" Matsumoto e65d42644a Remove #include <mruby/khash.h> from mruby/hash.h. 2018-12-17 15:59:42 +09:00
Yukihiro "Matz" Matsumoto e690314525 Recover #to_int; ref #4177
We have removed implicit conversion to strings using `to_int`. But some
users still using `to_int` as a typical integer method, i.e. they do
string check by code like: `obj.respond_to?(:to_int)`. So we have
recovered the method.
2018-12-17 15:59:42 +09:00
Yukihiro "Matz" Matsumoto c03fa0e1b3 Recover String#to_str; ref #4177
We have removed implicit conversion to strings using `to_str`. But some
people still using `to_str` as a typical string method, i.e. they do
string check by code like: `obj.respond_to?(:to_str)`. So we have
recovered the method.
2018-12-17 15:59:42 +09:00
Yukihiro "Matz" Matsumoto ea71f1165b Merge pull request #4188 from dearblue/mrb_hash_size
Add `mrb_hash_size()` function
2018-12-17 15:59:31 +09:00
Takashi Sawanaka d8c70167f7 Make mrb_ary_clear() function callable from C again 2018-12-15 05:17:38 +09:00
dearblue 62dd4d89fc Add mrb_hash_size() function. 2018-12-14 21:41:07 +09:00
Yukihiro "Matz" Matsumoto ec812c646f Merge pull request #4185 from icm7216/fix-sleep-example
Fix sleep example
2018-12-12 13:48:58 +09:00
icm7216 59651f43ad Specify the core library instead of the external library. 2018-12-12 00:54:15 +09:00
icm7216 74c5402211 Sleep module is undefined. Remove module name. 2018-12-12 00:52:07 +09:00
Yukihiro "Matz" Matsumoto 730b925332 Merge pull request #4184 from mruby/stable
Release mruby 2.0.0
2018-12-11 11:52:33 +09:00
Yukihiro "Matz" Matsumoto 60da293d5c Avoid using floating point number for HT_SEG_INCREASE_RATIO; ref #4182 2018-12-11 10:54:47 +09:00
Yukihiro "Matz" Matsumoto 265171a28c Rename ht_foreach_func to mrb_hash_foreach_func. 2018-12-11 10:41:26 +09:00
Yukihiro "Matz" Matsumoto e935d20ab5 Add mrb_ prefix to iv_foreach_func. 2018-12-11 10:39:53 +09:00
Yukihiro "Matz" Matsumoto a0df27d8e0 Add new API mrb_iv_foreach() to iterate over instance variables. 2018-12-11 09:48:15 +09:00
Yukihiro "Matz" Matsumoto f6b2e6231a Update iv_foreach() function.
* return `void` instead of `mrb_bool'.
* non zero return value from `func` breaks the loop.
* no longer remove items on negative return value from `func`.
2018-12-11 09:47:06 +09:00
Yukihiro "Matz" Matsumoto 378c728338 Update comments. 2018-12-11 09:04:08 +09:00
Yukihiro "Matz" Matsumoto c0d91a14e7 Add API function mrb_hash_foreach() to iterate over items in a hash. 2018-12-11 09:01:05 +09:00
Yukihiro "Matz" Matsumoto c23e68d32b Need to clear stack before invoking a block; fix #4181 2018-12-10 10:23:01 +09:00
take-cheeze b6850f88a1 Support lock file for git. 2018-12-06 11:47:17 +09:00
Bhargava Shastry 05b4eaac4b ossfuzz: Moved config related files to a namesake directory under ossfuzz 2018-12-05 18:06:30 +01:00
Bhargava Shastry bccf9e4a3f ossfuzz: Add fuzzing dictionary for mruby. 2018-12-05 18:00:47 +01:00
Bhargava Shastry 1d1b47044c ossfuzz: Add simple mruby compile test harness 2018-12-05 17:45:27 +01:00
Yukihiro "Matz" Matsumoto e6bad6766a Add new methods Module#{>,>=,<=>}; ref #4174 2018-12-04 08:41:09 +09:00
Yukihiro "Matz" Matsumoto d5d9cc8b62 Remove unnecessary check in Module#<; ref #4174 2018-12-04 08:40:23 +09:00
Yukihiro "Matz" Matsumoto 6ef4a5fd6b Replace RDoc <i></i> to Markdown back quotes; ref #4174 2018-12-04 08:39:44 +09:00
Yukihiro "Matz" Matsumoto 20c655dc45 Merge pull request #4174 from robfors/module_operators
Adds Module#< and Module#<=
2018-12-04 08:09:18 +09:00
Rob e300ac8e3a Adds Module#< and Module#<= 2018-12-02 20:56:47 -05:00
Uchio KONDO 7c52734243 Add a testcase of #4137 fix 2018-10-15 14:46:24 +09:00
Ichito Nagata 2af92d0ebc Let inspect recursion do the right thing 2018-06-04 11:25:10 +09:00
ksss e8988197f2 Try Binding class 2017-02-24 11:06:47 +09:00
cremno f31733045f use mrb_debug_strdup() and mrb_debug_strndup()
As they are safer to use than mrb_malloc()+strlen()+strncpy() (see #2652).
2014-12-02 00:00:55 +01:00
cremno ce5a3dbcba add mrb_debug_strdup() and mrb_debug_strndup()
They behave similar to their POSIX equivalents, except
mrb_malloc_simple() is used for memory allocation and
errno might not be set since ISO C99 doesn't have ENOMEM.
2014-12-02 00:00:54 +01:00
take_cheeze f77fb11f4e Use RString in mesg instead. 2014-07-28 20:30:02 +09:00
take_cheeze e926b532ee Store exception message to mesg field of struct RException. 2014-07-28 16:34:01 +09:00
mirichi 670a457e06 add block argument test #2144 2014-04-28 13:49:50 +09:00
448 changed files with 50928 additions and 22178 deletions
+43
View File
@@ -0,0 +1,43 @@
# About this file, see:
# Website: https://editorconfig.org/
# For Emacs users: https://github.com/editorconfig/editorconfig-emacs
# For Vim users: https://github.com/editorconfig/editorconfig-vim
root = true
[*]
charset = utf-8
end_of_line = lf
indent_size = 8
indent_style = tab
insert_final_newline = true
tab_width = 8
[{Makefile,Makefile.*,makefile,*.mk}]
trim_trailing_whitespace = true
#max_line_length = 80
[*.{c,cc,C,cxx,cpp,h,hh,H,hxx,hpp,inc,y}]
indent_size = 2
indent_style = space
trim_trailing_whitespace = true
#max_line_length = 120
[{*.rb,Rakefile,rakefile,*.rake,*.gemspec,*.gembox}]
indent_size = 2
indent_style = space
trim_trailing_whitespace = true
#max_line_length = 120
[*.bat]
charset = latin1
end_of_line = crlf
#max_line_length = 80
[*.{yaml,yml}]
indent_size = 2
indent_style = space
[*.md]
indent_size = 2
indent_style = space
+4
View File
@@ -0,0 +1,4 @@
# Extend the tab with 8 whitespace
6fc5dc986a5ffc1a74c63ad0617ea1dcc10d3cdd
# reformatted doc/opcode.md
61e8a540869c57ebddac53cf9d243db407d57fff
+10
View File
@@ -0,0 +1,10 @@
# Basic set up
version: 2
updates:
# Maintain dependencies for GitHub Actions
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"
+12
View File
@@ -0,0 +1,12 @@
{
"verbose": false,
"ignore_defaults": false,
"exclude": ["oss-fuzz/", "src/"],
"disable": {
"end_of_line": false,
"trim_trailing_whitespace": false,
"insert_final_newline": false,
"indent_size": true,
"indent_style": true
}
}
+26
View File
@@ -0,0 +1,26 @@
# https://github.com/DavidAnson/markdownlint#rules--aliases
# markdownlint -c .github/linters/.markdown-lint.yml .
# MD001 heading-increment/header-increment - Heading levels should only increment by one level at a time
MD001: false
# MD010 no-hard-tabs - Hard tabs
MD010: false
# MD013 line-length - Line length
MD013: false
# MD014 commands-show-output - Dollar signs used before commands without showing output
MD014: false
# MD024 no-duplicate-heading/no-duplicate-header - Multiple headings with the same content
MD024: false
# MD025 single-title/single-h1 - Multiple top-level headings in the same document
MD025: false
# MD026 no-trailing-punctuation - Trailing punctuation in heading
MD026: false
# MD040 fenced-code-language - Fenced code blocks should have a language specified
MD040: false
+9
View File
@@ -0,0 +1,9 @@
---
# https://yamllint.readthedocs.io/en/stable/
# yamllint --strict -c .github/linters/.yaml-lint.yml .
extends: default
rules:
document-start: disable
line-length: disable
truthy: false
+155
View File
@@ -0,0 +1,155 @@
name: Build & Test
on: [push, pull_request]
jobs:
Ubuntu-1804-gcc:
runs-on: ubuntu-18.04
timeout-minutes: 10
env:
MRUBY_CONFIG: ci/gcc-clang
CC: gcc
steps:
- uses: actions/checkout@v2.4.0
- name: Ruby version
run: ruby -v
- name: Compiler version
run: ${{ env.CC }} --version
- name: Build and test
run: rake -m test:build && rake test:run
Ubuntu-1804-clang:
runs-on: ubuntu-18.04
timeout-minutes: 10
env:
MRUBY_CONFIG: ci/gcc-clang
CC: clang
steps:
- uses: actions/checkout@v2.4.0
- name: Ruby version
run: ruby -v
- name: Compiler version
run: ${{ env.CC }} --version
- name: Build and test
run: rake -m test:build && rake test:run
Ubuntu-2004-gcc:
runs-on: ubuntu-20.04
timeout-minutes: 10
env:
MRUBY_CONFIG: ci/gcc-clang
CC: gcc
steps:
- uses: actions/checkout@v2.4.0
- name: Ruby version
run: ruby -v
- name: Compiler version
run: ${{ env.CC }} --version
- name: Build and test
run: rake -m test:build && rake test:run
Ubuntu-2004-clang:
runs-on: ubuntu-20.04
timeout-minutes: 10
env:
MRUBY_CONFIG: ci/gcc-clang
CC: clang
steps:
- uses: actions/checkout@v2.4.0
- name: Ruby version
run: ruby -v
- name: Compiler version
run: ${{ env.CC }} --version
- name: Build and test
run: rake -m test:build && rake test:run
macOS:
runs-on: macos-latest
timeout-minutes: 10
env:
MRUBY_CONFIG: ci/gcc-clang
CC: clang
steps:
- uses: actions/checkout@v2.4.0
- name: Ruby version
run: ruby -v
- name: Compiler version
run: ${{ env.CC }} --version
- name: Build and test
run: rake -m test:build && rake test:run
Windows-MinGW:
runs-on: windows-latest
timeout-minutes: 10
env:
MRUBY_CONFIG: ci/gcc-clang
CC: gcc
steps:
- uses: actions/checkout@v2.4.0
- name: Ruby version
run: ruby -v
- name: Compiler version
run: ${{ env.CC }} --version
- name: Build and test
run: rake -m test:build && rake test:run
Windows-Cygwin:
runs-on: windows-latest
timeout-minutes: 15
env:
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
MRUBY_CONFIG: ci/gcc-clang
CC: gcc
installer-path: '%TMP%\cygwin-setup.exe'
cygwin-root: C:\cygwin
package-dir: C:\cygwin-package
cache-version: v1
steps:
- uses: actions/checkout@v2.4.0
- uses: actions/cache@v2.1.7
with:
path: ${{ env.package-dir }}
key: ${{ runner.os }}-cygwin-${{ env.cache-version }}
- name: Download Cygwin installer
shell: cmd
run: >
bitsadmin /transfer download /priority foreground
https://cygwin.com/setup-x86_64.exe ${{ env.installer-path }}
- name: Install Cygwin
shell: cmd
run: >
${{ env.installer-path }}
--quiet-mode --no-shortcuts --no-startmenu --no-desktop --no-admin
--only-site --site http://mirrors.kernel.org/sourceware/cygwin/
--root ${{ env.cygwin-root }}
--local-package-dir ${{ env.package-dir }}
--packages gcc-core,gcc-g++,ruby
- name: Set PATH for Cygwin
run: |
echo '::set-env name=PATH::${{ env.cygwin-root }}\bin;${{ env.cygwin-root }}\usr\bin'
- name: Ruby version
shell: cmd
run: ruby -v
- name: Compiler version
run: ${{ env.CC }} --version
- name: Build and test
shell: cmd
run: ruby /usr/bin/rake -m test:build && ruby /usr/bin/rake test:run
- name: Set PATH for cache archiving (tar)
# set Windows path so that Cygwin tar is not used for cache archiving
run: echo '::set-env name=PATH::C:\windows\System32'
Windows-VC:
runs-on: windows-latest
timeout-minutes: 10
env:
MRUBY_CONFIG: ci/msvc
steps:
- uses: actions/checkout@v2.4.0
- name: Ruby version
run: ruby -v
- name: Build and test
shell: cmd
run: |
call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\Build\vcvars64.bat"
rake -m test:build && rake test:run
+46
View File
@@ -0,0 +1,46 @@
name: "Code scanning - action"
on:
push:
pull_request:
schedule:
- cron: '0 19 * * 4'
jobs:
CodeQL-Build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2.4.0
with:
# We must fetch at least the immediate parents so that if this is
# a pull request then we can checkout the head.
fetch-depth: 2
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
# Override language selection by uncommenting this and choosing your languages
# with:
# languages: go, javascript, csharp, python, cpp, java
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v1
# ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
# and modify them (or add more) to build your code if your project
# uses a compiled language
# - run: |
# make bootstrap
# make release
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
+32
View File
@@ -0,0 +1,32 @@
name: Lint
on: [pull_request]
jobs:
misspell:
name: Check spelling with misspell
runs-on: ubuntu-latest
steps:
- name: Check Out
uses: actions/checkout@v2.4.0
- name: Install
run: wget -O - -q https://git.io/misspell | sh -s -- -b .
- name: Misspell
run: git ls-files --empty-directory | xargs ./misspell -error
pre-commit:
name: Run pre-commit
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2.4.0
- name: Check merge conflict
run: |
python -m pip install --upgrade pip
pip install pre-commit
- name: Set PY
run: echo "PY=$(python -VV | sha256sum | cut -d' ' -f1)" >> $GITHUB_ENV
- uses: actions/cache@v2.1.7
with:
path: ~/.cache/pre-commit
key: pre-commit|${{ env.PY }}|${{ hashFiles('.pre-commit-config.yaml') }}
- name: Run pre-commit
run: pre-commit run --all-files
+23
View File
@@ -0,0 +1,23 @@
name: CIFuzz
on: [pull_request]
jobs:
Fuzzing:
runs-on: ubuntu-latest
steps:
- name: Build Fuzzers
uses: google/oss-fuzz/infra/cifuzz/actions/build_fuzzers@master
with:
oss-fuzz-project-name: 'mruby'
dry-run: false
- name: Run Fuzzers
uses: google/oss-fuzz/infra/cifuzz/actions/run_fuzzers@master
with:
oss-fuzz-project-name: 'mruby'
fuzz-seconds: 600
dry-run: false
- name: Upload Crash
uses: actions/upload-artifact@v2.3.1
if: failure()
with:
name: artifacts
path: ./out/artifacts
+23
View File
@@ -0,0 +1,23 @@
name: Super Linter
on:
push:
branches-ignore: [master]
# Remove the line above to run when pushing to master
pull_request:
branches: [master]
jobs:
build:
name: Lint Code Base
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2.4.0
- uses: github/super-linter@v4.8.5
env:
ERROR_ON_MISSING_EXEC_BIT: true
VALIDATE_BASH: true
# VALIDATE_BASH_EXEC: true
# VALIDATE_EDITORCONFIG: true
# VALIDATE_SHELL_SHFMT: true
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+17 -8
View File
@@ -1,13 +1,13 @@
# /
*.lock
*.bak
*.bc
*.d
*.i
*.o
/benchmark/**/*.dat
/benchmark/*.pdf
/benchmark/*.png
*.orig
*.pdb
*.rej
*.s
*.sav
*.swp
*.tmp
@@ -16,13 +16,22 @@
.ccmalloc
.svn
.vscode
/.git
.yardoc
.ccls*
compile_flags.txt
compile_commands.json
cscope.files
cscope.out
tags
/src/y.tab.c
/.git
/bin
/build
/mruby-source-*.gem
doc/api
.yardoc
/benchmark/**/*.dat
/benchmark/*.pdf
/benchmark/*.png
/doc/api
/doc/capi
-3214
View File
File diff suppressed because it is too large Load Diff
+58
View File
@@ -0,0 +1,58 @@
---
default_stages: [commit, push]
default_language_version:
# force all unspecified Python hooks to run python3
python: python3
minimum_pre_commit_version: "1.20.0"
repos:
- repo: meta
hooks:
- id: identity
- id: check-hooks-apply
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.1.0
hooks:
- id: check-added-large-files
- id: check-case-conflict
- id: check-executables-have-shebangs
exclude: ^test/t/lang\.rb$
- id: check-merge-conflict
- id: check-vcs-permalinks
- id: check-yaml
- id: detect-private-key
- id: end-of-file-fixer
- id: file-contents-sorter
files: ^codespell\.txt$
- id: fix-byte-order-marker
- id: mixed-line-ending
- id: trailing-whitespace
# - repo: git://github.com/Lucas-C/pre-commit-hooks
# rev: v1.1.9
# hooks:
# - id: forbid-tabs
# - id: remove-tabs
- repo: https://github.com/codespell-project/codespell
rev: v2.1.0
hooks:
- id: codespell
name: Run codespell
description: Check spelling with codespell
entry: codespell --ignore-words=codespell.txt
- repo: https://github.com/igorshubovych/markdownlint-cli
rev: v0.30.0
hooks:
- id: markdownlint
name: Run markdownlint
description: Checks the style of Markdown files
entry: markdownlint -c .github/linters/.markdown-lint.yml .
types: [markdown]
files: \.(md|mdown|markdown)$
- repo: https://github.com/adrienverge/yamllint
rev: v1.26.3
hooks:
- id: yamllint
name: Run yamllint
description: Check YAML files with yamllint
entry: yamllint --strict -c .github/linters/.yaml-lint.yml
types: [yaml]
files: \.(yaml|yml)$
+7 -15
View File
@@ -1,19 +1,11 @@
language: c
sudo: false
matrix:
include:
- os: linux
sudo: false
- os: osx
osx_image: xcode7.1
addons:
apt:
packages:
- gperf
jobs:
- os: linux
- os: osx
env:
- MRUBY_CONFIG=travis_config.rb
script: "./minirake -j4 all test"
- MRUBY_CONFIG=ci/gcc-clang
script:
- rake -m test:build && rake test:run
+1 -1
View File
@@ -12,6 +12,6 @@ mrbgems/*/mrblib/**/*.rb
mrbgems/*/include/**/*.h
-
AUTHORS
MITL
LICENSE
CONTRIBUTING.md
doc/guides/*.md
+304 -34
View File
@@ -1,40 +1,310 @@
Original Authors "mruby developers" are:
Yukihiro Matsumoto
# Authors of mruby (mruby developers)
## The List of Contributors sorted by number of commits (as of 2022-01-10 69b1667)
7956 Yukihiro "Matz" Matsumoto (@matz)*
586 KOBAYASHI Shuji (@shuujii)
376 Daniel Bovensiepen (@bovi)
346 Takeshi Watanabe (@take-cheeze)*
342 dearblue (@dearblue)*
334 Masaki Muranaka (@monaka)
298 Tomoyuki Sahara (@tsahara)*
234 Jun Hiroe (@suzukaze)
219 Cremno (@cremno)*
208 Yuki Kurihara (@ksss)+
148 Yasuhiro Matsumoto (@mattn)*
113 Carson McDonald (@carsonmcdonald)
103 Tomasz Dąbrowski (@dabroz)*
84 skandhas (@skandhas)
80 Masamitsu MURASE (@masamitsu-murase)
74 Yuichiro MASUI (@masuidrive)
71 Tatsuhiko Kubo (@cubicdaiya)*
68 Hiroshi Mimaki (@mimaki)*
63 Akira Yumiyama (@akiray03)*
62 Paolo Bosetti (@pbosetti)*
59 Kurebayashi, Takahiro (@crimsonwoods)*
56 h2so5 (@h2so5)
52 Ralph Desir (@Mav7)*
49 John Bampton (@jbampton)
45 Rory O'Connell (@RoryO)*
43 Yuichiro Kaneko (@yui-knk)+
42 fleuria (@flaneur2020)
40 Christopher Aue (@christopheraue)
40 Seba Gamboa (@sagmor)
38 Koji Yoshioka (@kyab)*+
38 Kouhei Sutou (@kou)*
31 MATSUMOTO Ryosuke (@matsumotory)*
30 Nobuyoshi Nakada (@nobu)
28 Masayoshi Takahashi (@takahashim)+
24 Julian Aron Prenner (@furunkel)*
24 Ryan Scott (@ryan-scott-dev)*
22 Clayton Smith (@clayton-shopify)
22 Zachary Scott (@zzak)*
22 mirichi (@mirichi)
21 Jared Breeden (@jbreeden)*
20 Uchio Kondo (@udzura)*
19 Bouke van der Bijl (@bouk)
19 Felix Jones (@felixjones)*
19 Hidetaka Takano (@TJ-Hidetaka-Takano)
19 go kikuta (@gkta)*
18 Corey Powell (@IceDragon200)
18 Jon Maken (@jonforums)+
18 Mitchell Blank Jr (@mitchblank)*
17 Ryan Lopopolo (@lopopolo)
16 bggd (@bggd)
16 kano4 (@kano4)
14 Blaž Hrastnik (@archseer)*
14 Jose Narvaez (@goyox86)
14 Kazuki Tsujimoto (@k-tsj)
14 Tadashi FUKUZAWA (@FUKUZAWA-Tadashi)+
13 Patrick Hogan (@pbhogan)
12 Akira Kuroda (@akuroda)
12 Kouki Ooyatsu (kaishuu0123)*
12 NAKAMURA Usaku (@unak)*
12 RIZAL Reckordp (@Reckordp)+
12 Takashi Sawanaka (@sdottaka)*
12 Ukrainskiy Sergey (@ukrainskiysergey)
12 Xuejie "Rafael" Xiao (@xxuejie)*
11 Julien Ammous (@schmurfy)
11 Seeker (@SeekingMeaning)
11 YAMAMOTO Masaya (pandax381)
11 takkaw (@takkaw)
10 Kazuho Oku (@kazuho)
10 Miura Hideki (@miura1729)
10 Narihiro Nakamura (@authorNari)
10 Ray Chason (@chasonr)*
10 Yuichi Nishiwaki (@nyuichi)
9 Akira Mitsui (@murasesyuka)*
9 Frank Celler (@fceller)
9 Tatsuya Matsumoto (@tmash06)*
8 Takashi Sogabe (@sogabe)
7 Bhargava Shastry (@bshastry)*
7 Kouichi Nakanishi (@keizo042)
7 Rubyist (@expeditiousRubyist)
7 Simon Génier (@simon-shopify)
7 Terence Lee (@hone)
7 Wataru Ashihara (@wataash)*
7 roco (@rystyle)*
6 Akito Mochizuki (@ak-mochi)
6 Beoran (@beoran)
6 David Siaw (@davidsiaw)*
6 Frederick John Milens III (@fjmilens3)
6 Hiro Asari (@BanzaiMan)
6 INOUE Yasuyuki (@yasuyuki)
6 Junji Sawada (@junjis0203)
6 Kenji Okimoto (@okkez)+
6 Selman ULUG (@selman)
6 Yusuke Endoh (@mame)*
5 Davide D'Agostino (@DAddYE)
5 Eric Hodel (@drbrain)
5 Hendrik (@Asmod4n)
5 Ichito Nagata (@i110)
5 Keita Obo (@ktaobo)*
5 Max Anselm (@silverhammermba)
5 SiZiOUS (@sizious)
5 Syohei YOSHIDA (@syohex)
5 TOMITA Masahiro (@tmtm)
5 Yurie Yamane (@yurie)+
5 dreamedge (@dreamedge)
5 nkshigeru (@nkshigeru)
4 Dante Catalfamo (@dantecatalfamo)
4 Goro Kikuchi (@gorogit)
4 Herwin Weststrate (@herwinw)
4 Jon Moss (@maclover7)
4 Ken Muramatsu (@ken-mu)+
4 Kohei Suzuki (@eagletmt)
4 Li Yazhou (@flaneur2020)
4 Marcus Stollsteimer (@stomar)
4 NARUSE, Yui (@nurse)
4 Ravil Bayramgalin (@brainopia)*+
4 Satoshi Odawara (@SatoshiOdawara)
4 Yuhei Okazaki (@Yuuhei-Okazaki)*
4 Yuji Yamano (@yyamano)
4 kurodash (@kurodash)*
4 masahino (@masahino)
4 wanabe (@wanabe)*
4 xuejianqing (@joans321)
3 Anton Davydov (@davydovanton)
3 Carlo Prelz (@asfluido)*
3 David Turnbull (@AE9RB)
3 Franck Verrot (@franckverrot)
3 Horimoto Yasuhiro (@komainu8)
3 J. Mutua (@katmutua)+
3 Jan Berdajs (@mrbrdo)
3 Joseph McCullough (@joequery)
3 Mark McCurry (@fundamental)
3 Nobuhiro Iwamatsu (@iwamatsu)
3 Per Lundberg (@perlun)*
3 Rob Fors (@robfors)*
3 Rodrigo Malizia (@rmalizia44)+
3 Sebastián Katzer (@katzer)*
3 Shouji Kuboyama (@Shokuji)*
3 Shuta Kimura (@kimushu)+
3 TERAJIMA, Motoyuki (@trmmy)
3 Takashi Kokubun (@k0kubun)
3 Tatsuhiro Tsujikawa (@tatsuhiro-t)
3 Thiago Scalone (@scalone)
3 Vladimir Dementyev (@palkan)*
3 William Light (@wrl)
3 bamchoh (@bamchoh)
3 sasaki takeru (@takeru)
2 Akira Moroo (@retrage)
2 Artur K (@nemerle)
2 Christian Mauceri (@mauceri)
2 Craig Lehmann (@craiglrock)*
2 Dominic Sisneros (@dsisnero)*
2 Dusan D. Majkic (@dmajkic)
2 Emiliano Lesende (@3miliano)
2 Francois Chagnon (@EiNSTeiN-)*
2 Gilad Zohari (@gzohari)
2 Go Saito (@govm)
2 HASUMI Hitoshi (@hasumikin)
2 Hirohito Higashi (@HirohitoHigashi)
2 Hiroyuki Iwatsuki (@iwadon)
2 Huei-Horng Yo (@hiroshiyui)
2 Jonas Kulla (@Ancurio)
2 Jun Takeda (@takjn)
2 Kazuaki Tanaka (@kaz0505)
2 Kazuhiko Yamashita (@pyama86)+
2 Kazuhiro Sera (@seratch)
2 Kuroda Daisuke (@dycoon)+
2 Lanza (@LanzaSchneider)
2 Lothar Scholz (@llothar)
2 Lukas Joeressen (@kext)
2 Masahiro Wakame (@vvkame)+
2 Minao Yamamoto (@tarosay)+
2 Nihad Abbasov (@NARKOZ)
2 Robert Mosolgo (@rmosolgo)
2 Russel Hunter Yukawa (@rhykw)+
2 Ryunosuke SATO (@tricknotes)
2 Santa Zhang (@santazhang)
2 Satoru Naba (@snaba)+
2 Serg Podtynnyi (@shtirlic)
2 Shannen Saez (@shancat)
2 SouthWolf (@southwolf)
2 TJ Singleton (@tjsingleton)
2 Taiyo Mizuhashi (@taiyoslime)+
2 Tomás Pollak (@tomas)*
2 Yutaka HARA (@yhara)*+
2 Zhang Xiaohui (@hifoolno)
2 icm7216 (@icm7216)
2 windwiny (@windwiny)
1 A-Sat (@asatou)+
1 Abinoam Praxedes Marques Junior (@abinoam)
1 Alex Wang (@nanamiwang)+
1 Andrew Nordman (@cadwallion)
1 Atsushi Morimoto (@mynz)
1 Ben A Morgan (@BenMorganIO)
1 Benoit Daloze (@eregon)
1 Chris Reuter (@suetanvil)
1 Daehyub Kim (@lateau)
1 Daniel Varga (@vargad)
1 Edgar Boda-Majer (@eboda)
1 Fangrui Song (@MaskRay)
1 Flavio Medeiros (@flaviommedeiros)
1 Francis Bogsanyi (@fbogsany)
1 Guo Xiao (@guoxiao)
1 Gwen Boatrite (@boatrit)
1 HAYASHI Kentaro (@kenhys)
1 Hiroki Mori (@yamori813)+
1 Hiromasa Ishii (@Hir0)+
1 Hiroyuki Matsuzaki (@Hiroyuki-Matsuzaki)
1 Hugo Logmans (@hlogmans)
1 Jack Danger Canty (@JackDanger)
1 Jeff Federman (@jefffederman)
1 Jeffrey Crowell (@crowell)
1 Jeremy Ong (@jeremyong)
1 Jiro Nishiguchi (@spiritloose)
1 Joachim Baran (@indiedotkim)
1 Joe Kutner (@jkutner)
1 Jun Aruga (@junaruga)
1 Junichi Kajiwara (@kjunichi)
1 Jurriaan Pruis (@jurriaan)
1 Katsuhiko Kageyama (@kishima)+
1 Katsuyoshi Ito (@katsuyoshi)
1 Kazuhiro NISHIYAMA (@znz)
1 Kei Sawada (@remore)
1 Kim H Madsen (@kimhmadsen)
1 Konstantin Haase (@rkh)
1 Leo Neat (@Leo-Neat)
1 Lian Cheng (@liancheng)
1 Luis Lavena (@luislavena)
1 Lukas Elmer (@lukaselmer)
1 Lukas Stabe (@Ahti)
1 M.Naruoka (@fenrir-naru)
1 Mark Delk (@jethrodaniel)
1 Martin Bosslet (@emboss)+
1 Masahiko Sawada (@MasahikoSawada)
1 Matt Aimonetti (@mattetti)
1 Maxim Abramchuk (@MaximAbramchuck)
1 Megumi Tomita (@tomykaira)+
1 Mitchell Hashimoto (@mitchellh)
1 Mitsutaka Mimura (@takkanm)
1 Nathan Ladd (@ntl)
1 Nicholas (@knf)
1 Nozomi SATO (@nozomiS)
1 Okumura Takahiro (@hfm)
1 Patrick Ellis (@pje)
1 Patrick Pokatilo (@SHyx0rmZ)
1 Pavel Evstigneev (@Paxa)+
1 Prayag Verma (@pra85)
1 Ranmocy (@ranmocy)
1 Robert McNally (@wolfmcnally)
1 Robert Rowe (@CaptainJet)
1 Ryan Scott Lewis (@RyanScottLewis)
1 Ryo Okubo (@syucream)
1 Santiago Rodriguez (@sanrodari)
1 Satoh, Hiroh (@cho45)+
1 Sayed Abdelhaleem (@visualsayed)
1 Shugo Maeda (@shugo)
1 Sorah Fukumori (@sorah)
1 Stuart Hinson (@stuarth)
1 Takuma Kume (@takumakume)+
1 Thomas Schmidt (@digitaltom)
1 Timo Schilling (@timoschilling)
1 Tom Black (@blacktm)
1 Utkarsh Kukreti (@utkarshkukreti)
1 W (@graywolf)
1 Wuffers Lightwolf (@w-x-l)
1 YAMAMOTO Yuji (@igrep)
1 Yevhen Viktorov (@yevgenko)
1 Yoji SHIDARA (@darashi)
1 Yoshiori SHOJI (@yoshiori)
1 Yukang (@chenyukang)
1 Yurii Nakonechnyi (@inobelar)
1 Yusuke Suzuki (@Constellation)+
1 Yusuke Tanaka (@csouls)
1 arton (@arton)
1 duangsuse (@duangsuse)
1 fl0l0u (@fl0l0u)
1 hhc0null (@hhc0null)
1 iTitou (@titouanc)
1 javier ramírez (@javier)
1 liyuray (@liyuray)
1 lucas dicioccio (@lucasdicioccio)
1 n4o847 (@n4o847)
1 robert (@R-obert)
1 sbsoftware (@sbsoftware)
1 ssmallkirby (@smallkirby)
1 taku toyama (@tsuichu)
`*` - Entries unified according to names and addresses
`+` - Entries with names different from commits
## Contributors without named commits
Yuichi Osawa (Mitsubishi Electric Micro-Computer Application Software)
Shota Nakano (Manycolors)
Bjorn De Meyer
## Corporate contributors
Ministry of Economy, Trade and Industry, Japan
Kyushu Bureau of Economy, Trade and Industry
SCSK KYUSHU CORPORATION
Kyushu Institute of Technology
Network Applied Communication Laboratory, Inc.
Daniel Bovensiepen
Jon Maken
Bjorn De Meyer
Yuichiro MASUI
Masamitsu MURASE
Masaki Muranaka
Internet Initiative Japan Inc.
Tadashi FUKUZAWA
MATSUMOTO Ryosuke
Yasuhiro Matsumoto
Koji Yoshioka
Jun Hiroe
Narihiro Nakamura
Yuichi Nishiwaki
Tatsuhiko Kubo
Takeshi Watanabe
Yuki Kurihara
specified non-profit corporation mruby Forum
Kazuaki Tanaka
Hiromasa Ishii
Hiroshi Mimaki
Satoshi Odawara
Specified non-profit organization mruby Forum
Mitsubishi Electric Micro-Computer Application Software Co.,Ltd.
Ralph Desir(Mav7)
Hiroyuki Matsuzaki
Yuhei Okazaki
Manycolors, Inc.
Shota Nakano
Yuichi Osawa
Terence Lee
Zachary Scott
Tomasz Dąbrowski
Christopher Aue
Masahiro Wakame
YAMAMOTO Masaya
+1
View File
@@ -0,0 +1 @@
* @matz
+53 -18
View File
@@ -1,6 +1,7 @@
# How to contribute
mruby is an open-source project which is looking forward to each contribution.
Contributors agree to license their contribution(s) under MIT license.
## Your Pull Request
@@ -9,7 +10,7 @@ things in mind before submitting your pull request:
* Work on the latest possible state of **mruby/master**
* Create a branch which is dedicated to your change
* Test your changes before creating a pull request (```./minirake test```)
* Test your changes before creating a pull request (`rake test`)
* If possible write a test case which confirms your change
* Don't mix several features or bug-fixes in one pull request
* Create a meaningful commit message
@@ -17,6 +18,41 @@ things in mind before submitting your pull request:
* Use mrbgem to provide non ISO features (classes, modules and methods) unless
you have a special reason to implement them in the core
## pre-commit
A framework for managing and maintaining multi-language `pre-commit` hooks.
`pre-commit` can be [installed](https://pre-commit.com/#installation) with `pip`, `curl`, `brew` or `conda`.
You need to first install `pre-commit` and then install the `pre-commit` hooks with `pre-commit install`.
Now `pre-commit` will run automatically on git commit!
It's usually a good idea to run the hooks against all the files when adding new hooks (usually `pre-commit` will only run on the changed files during git hooks).
Use `pre-commit run --all-files` to check all files.
To run a single hook use `pre-commit run --all-files <hook_id>`
To update use `pre-commit autoupdate`
* [Quick start](https://pre-commit.com/#quick-start)
* [Usage](https://pre-commit.com/#usage)
* [pre-commit-autoupdate](https://pre-commit.com/#pre-commit-autoupdate)
## Spell Checking
We are running [misspell](https://github.com/client9/misspell) which is mainly written in
[Golang](https://golang.org/) to check spelling with [GitHub Actions](.github/workflows/lint.yml).
Correct commonly misspelled English words quickly with `misspell`. You can run `misspell` locally
against all files with:
```bash
find . -type f | xargs ./misspell -error
```
Notable `misspell` help options or flags are:
* `-i` string: ignore the following corrections, comma separated
* `-w`: Overwrite file with corrections (default is just to display)
## Coding conventions
How to style your C and Ruby code which you want to submit.
@@ -31,11 +67,13 @@ C code:
mruby should be highly portable to other systems and compilers. For this it is
recommended to keep your code as close as possible to the C99 standard
(http://www.open-std.org/jtc1/sc22/WG14/www/docs/n1256.pdf).
(<http://www.open-std.org/jtc1/sc22/WG14/www/docs/n1256.pdf>).
Although we target C99, Visual C++ is also an important target for mruby. For
this reason a declaration of a local variable has to be at the beginning of a
scope block.
Visual C++ is also an important target for mruby (supported version is 2013 or
later). For this reason features that are not supported by Visual C++ may not
be used (e.g. `%z` of `strftime()`).
NOTE: Old GCC requires `-std=gnu99` option to enable C99 support.
#### Reduce library dependencies to a minimum
@@ -43,19 +81,15 @@ The dependencies to libraries should be kept to an absolute minimum. This
increases the portability but makes it also easier to cut away parts of mruby
on-demand.
#### Don't use C++ style comments
#### Insert a break after the function return value:
/* This is the preferred comment style */
Use C++ style comments only for temporary comment e.g. commenting out some code lines.
#### Insert a break after the method return value:
int
main(void)
{
...
}
```c
int
main(void)
{
...
}
```
### Ruby code
@@ -65,4 +99,5 @@ language itself. Please note the following hints for your Ruby code:
#### Comply with the Ruby standard (ISO/IEC 30170:2012)
mruby is currently targeting to execute Ruby code which complies to ISO/IEC
30170:2012 (http://www.iso.org/iso/iso_catalogue/catalogue_tc/catalogue_detail.htm?csnumber=59579).
30170:2012 (<https://www.iso.org/iso/iso_catalogue/catalogue_tc/catalogue_detail.htm?csnumber=59579>),
unless there's a clear reason, e.g. the latest Ruby has changed behavior from ISO.
+2408
View File
File diff suppressed because it is too large Load Diff
+1 -2
View File
@@ -2,5 +2,4 @@ LEGAL NOTICE INFORMATION
------------------------
All the files in this distribution are covered under the MIT license
(see the file MITL) except some files mentioned below:
(see the file LICENSE) except some files mentioned below:
+1 -2
View File
@@ -1,4 +1,4 @@
Copyright (c) 2018 mruby developers
Copyright (c) 2010-2021 mruby developers
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
@@ -17,4 +17,3 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
+2 -4
View File
@@ -1,8 +1,6 @@
# mruby is using Rake (http://rake.rubyforge.org) as a build tool.
# We provide a minimalistic version called minirake inside of our
# codebase.
# mruby is using Rake (https://ruby.github.io/rake/) as a build tool.
RAKE = ruby ./minirake
RAKE = rake
all :
$(RAKE)
-2
View File
@@ -9,5 +9,3 @@ with all sufficient information, see the ChangeLog file.
** Information about first release v1.0.0
+33 -23
View File
@@ -1,12 +1,15 @@
# mruby
[![Build Status][build-status-img]][travis-ci]
[![GitHub Super-Linter](https://github.com/mruby/mruby/workflows/Lint%20Code%20Base/badge.svg)](https://github.com/marketplace/actions/super-linter)
## What is mruby
mruby is the lightweight implementation of the Ruby language complying to (part
of) the [ISO standard][ISO-standard]. Its syntax is Ruby 1.9 compatible.
of) the [ISO standard][ISO-standard]. Its syntax is Ruby 2.x compatible.
mruby can be linked and embedded within your application. We provide the
interpreter program "mruby" and the interactive mruby shell "mirb" as examples.
interpreter program "mruby", and the interactive mruby shell "mirb" as examples.
You can also compile Ruby programs into compiled byte code using the mruby
compiler "mrbc". All those tools reside in the "bin" directory. "mrbc" is
also able to generate compiled byte code in a C source file, see the "mrbtest"
@@ -17,49 +20,58 @@ of the Ministry of Economy, Trade and Industry of Japan.
## How to get mruby
The stable version 2.0.0 of mruby can be downloaded via the following URL: [https://github.com/mruby/mruby/archive/2.0.0.zip](https://github.com/mruby/mruby/archive/2.0.0.zip)
The release candidate version 3.1.0 of mruby can be downloaded via the following URL: [https://github.com/mruby/mruby/archive/3.1.0-rc2.zip](https://github.com/mruby/mruby/archive/3.1.0-rc2.zip)
The latest development version of mruby can be downloaded via the following URL: [https://github.com/mruby/mruby/zipball/master](https://github.com/mruby/mruby/zipball/master)
The trunk of the mruby source tree can be checked out with the
following command:
$ git clone https://github.com/mruby/mruby.git
```
$ git clone https://github.com/mruby/mruby.git
```
You can also install and compile mruby using [ruby-install](https://github.com/postmodern/ruby-install), [ruby-build](https://github.com/rbenv/ruby-build) or [rvm](https://github.com/rvm/rvm).
## mruby home-page
The URL of the mruby home-page is: [http://www.mruby.org](http://www.mruby.org).
The URL of the mruby home-page is: <https://mruby.org>.
## Mailing list
We don't have a mailing list, but you can use [GitHub issues](https://github.com/mruby/mruby).
We don't have a mailing list, but you can use [GitHub issues](https://github.com/mruby/mruby/issues).
## How to compile and install (mruby and gems)
## How to compile, test, and install (mruby and gems)
See the [doc/guides/compile.md](doc/guides/compile.md) file.
See the [compile.md](doc/guides/compile.md) file.
## Running Tests
## Building documentation
To run the tests, execute the following from the project's root directory.
There are two sets of documentation in mruby: the mruby API (generated by yard) and C API (Doxygen)
$ make test
To build both of them, simply go
Or
```
rake doc
```
$ ruby ./minirake test
You can also view them in your browser
```
rake view_api
rake view_capi
```
## How to customize mruby (mrbgems)
mruby contains a package manager called *mrbgems*. To create extensions
in C and/or Ruby you should create a *GEM*. For a documentation of how to
use mrbgems consult the file [doc/guides/mrbgems.md](doc/guides/mrbgems.md). For example code of
how to use mrbgems look into the folder *examples/mrbgems/*.
use mrbgems consult the file [mrbgems.md](doc/guides/mrbgems.md).
For example code of how to use mrbgems look into the folder *examples/mrbgems/*.
## License
mruby is released under the [MIT License](MITL).
mruby is released under the [MIT License](LICENSE).
## Note for License
@@ -73,7 +85,7 @@ In the future, mruby might ask you to distribute your new code
(that you will commit,) under the MIT License as a member of
"mruby developers" but contributors will keep their copyright.
(We did not intend for contributors to transfer or waive their copyrights,
Actual copyright holder name (contributors) will be listed in the AUTHORS
actual copyright holder name (contributors) will be listed in the [AUTHORS](AUTHORS)
file.)
Please ask us if you want to distribute your code under another license.
@@ -81,12 +93,10 @@ Please ask us if you want to distribute your code under another license.
## How to Contribute
See the [contribution guidelines][contribution-guidelines], and then send a pull
request to <http://github.com/mruby/mruby>. We consider you have granted
non-exclusive right to your contributed code under MIT license. If you want to
be named as one of mruby developers, please include an update to the AUTHORS
file in your pull request.
request to <https://github.com/mruby/mruby>. We consider you have granted
non-exclusive right to your contributed code under MIT license.
[ISO-standard]: http://www.iso.org/iso/iso_catalogue/catalogue_tc/catalogue_detail.htm?csnumber=59579
[ISO-standard]: https://www.iso.org/iso/iso_catalogue/catalogue_tc/catalogue_detail.htm?csnumber=59579
[build-status-img]: https://travis-ci.org/mruby/mruby.svg?branch=master
[contribution-guidelines]: CONTRIBUTING.md
[contribution-guidelines]: https://github.com/mruby/mruby/blob/master/CONTRIBUTING.md
[travis-ci]: https://travis-ci.org/mruby/mruby
+22 -116
View File
@@ -5,15 +5,16 @@ MRUBY_ROOT = File.dirname(File.expand_path(__FILE__))
MRUBY_BUILD_HOST_IS_CYGWIN = RUBY_PLATFORM.include?('cygwin')
MRUBY_BUILD_HOST_IS_OPENBSD = RUBY_PLATFORM.include?('openbsd')
Rake.verbose(false) if Rake.verbose == Rake::DSL::DEFAULT
$LOAD_PATH << File.join(MRUBY_ROOT, "lib")
# load build systems
require "mruby-core-ext"
require "mruby/core_ext"
require "mruby/build"
require "mruby/gem"
# load configuration file
MRUBY_CONFIG = (ENV['MRUBY_CONFIG'] && ENV['MRUBY_CONFIG'] != '') ? ENV['MRUBY_CONFIG'] : "#{MRUBY_ROOT}/build_config.rb"
MRUBY_CONFIG = MRuby::Build.mruby_config_path
load MRUBY_CONFIG
# load basic rules
@@ -22,142 +23,47 @@ MRuby.each_target do |build|
end
# load custom rules
load "#{MRUBY_ROOT}/src/mruby_core.rake"
load "#{MRUBY_ROOT}/mrblib/mrblib.rake"
load "#{MRUBY_ROOT}/tasks/core.rake"
load "#{MRUBY_ROOT}/tasks/mrblib.rake"
load "#{MRUBY_ROOT}/tasks/mrbgems.rake"
load "#{MRUBY_ROOT}/tasks/libmruby.rake"
load "#{MRUBY_ROOT}/tasks/bin.rake"
load "#{MRUBY_ROOT}/tasks/presym.rake"
load "#{MRUBY_ROOT}/tasks/test.rake"
load "#{MRUBY_ROOT}/tasks/benchmark.rake"
load "#{MRUBY_ROOT}/tasks/gitlab.rake"
load "#{MRUBY_ROOT}/tasks/doc.rake"
##############################
# generic build targets, rules
task :default => :all
bin_path = ENV['INSTALL_DIR'] || "#{MRUBY_ROOT}/bin"
FileUtils.mkdir_p bin_path, { :verbose => $verbose }
depfiles = MRuby.targets['host'].bins.map do |bin|
install_path = MRuby.targets['host'].exefile("#{bin_path}/#{bin}")
source_path = MRuby.targets['host'].exefile("#{MRuby.targets['host'].build_dir}/bin/#{bin}")
file install_path => source_path do |t|
FileUtils.rm_f t.name, { :verbose => $verbose }
FileUtils.cp t.prerequisites.first, t.name, { :verbose => $verbose }
end
install_path
end
MRuby.each_target do |target|
gems.map do |gem|
current_dir = gem.dir.relative_path_from(Dir.pwd)
relative_from_root = gem.dir.relative_path_from(MRUBY_ROOT)
current_build_dir = File.expand_path "#{build_dir}/#{relative_from_root}"
if current_build_dir !~ /^#{build_dir}/
current_build_dir = "#{build_dir}/mrbgems/#{gem.name}"
end
gem.bins.each do |bin|
exec = exefile("#{build_dir}/bin/#{bin}")
objs = Dir.glob("#{current_dir}/tools/#{bin}/*.{c,cpp,cxx,cc}").map { |f| objfile(f.pathmap("#{current_build_dir}/tools/#{bin}/%n")) }
file exec => objs + target.libraries do |t|
gem_flags = gems.map { |g| g.linker.flags }
gem_flags_before_libraries = gems.map { |g| g.linker.flags_before_libraries }
gem_flags_after_libraries = gems.map { |g| g.linker.flags_after_libraries }
gem_libraries = gems.map { |g| g.linker.libraries }
gem_library_paths = gems.map { |g| g.linker.library_paths }
linker.run t.name, t.prerequisites, gem_libraries, gem_library_paths, gem_flags, gem_flags_before_libraries, gem_flags_after_libraries
end
if target == MRuby.targets['host']
install_path = MRuby.targets['host'].exefile("#{bin_path}/#{bin}")
file install_path => exec do |t|
FileUtils.rm_f t.name, { :verbose => $verbose }
FileUtils.cp t.prerequisites.first, t.name, { :verbose => $verbose }
end
depfiles += [ install_path ]
elsif target == MRuby.targets['host-debug']
unless MRuby.targets['host'].gems.map {|g| g.bins}.include?([bin])
install_path = MRuby.targets['host-debug'].exefile("#{bin_path}/#{bin}")
file install_path => exec do |t|
FileUtils.rm_f t.name, { :verbose => $verbose }
FileUtils.cp t.prerequisites.first, t.name, { :verbose => $verbose }
end
depfiles += [ install_path ]
end
else
depfiles += [ exec ]
end
end
end
end
depfiles += MRuby.targets.map { |n, t|
t.libraries
}.flatten
depfiles += MRuby.targets.reject { |n, t| n == 'host' }.map { |n, t|
t.bins.map { |bin| t.exefile("#{t.build_dir}/bin/#{bin}") }
}.flatten
desc "build all targets, install (locally) in-repo"
task :all => depfiles do
task :all => :gensym do
Rake::Task[:build].invoke
puts
puts "Build summary:"
puts
MRuby.each_target do
print_build_summary
MRuby.each_target do |build|
build.print_build_summary
end
MRuby::Lockfile.write
end
desc "run all mruby tests"
MRuby.each_target do
next unless test_enabled?
t = :"test_#{self.name}"
task t => ["all"] do
run_test
end
task :test => t
next unless bintest_enabled?
t = :"bintest_#{self.name}"
task t => ["all"] do
run_bintest
end
task :test => t
end
task :build => MRuby.targets.flat_map{|_, build| build.products}
desc "clean all built and in-repo installed artifacts"
task :clean do
MRuby.each_target do |t|
FileUtils.rm_rf t.build_dir, { :verbose => $verbose }
MRuby.each_target do |build|
rm_rf build.build_dir
rm_f build.products
end
FileUtils.rm_f depfiles, { :verbose => $verbose }
puts "Cleaned up target build folder"
end
desc "clean everything!"
task :deep_clean => ["clean"] do
MRuby.each_target do |t|
FileUtils.rm_rf t.gem_clone_dir, { :verbose => $verbose }
task :deep_clean => %w[clean doc:clean] do
MRuby.each_target do |build|
rm_rf build.gem_clone_dir
end
puts "Cleaned up mrbgems build folder"
end
desc 'generate document'
task :doc do
begin
sh "mrbdoc"
rescue
puts "ERROR: To generate documents, you should install yard-mruby gem."
puts " $ gem install yard-mruby"
end
end
+18
View File
@@ -0,0 +1,18 @@
# Security Policy
## Reporting a Vulnerability
If you have any security concern, contact <matz@ruby.or.jp>.
## Scope
We consider following issues as vulnerabilities:
* Remote code execution
* Crash caused by a valid Ruby script
We *don't* consider following issues as vulnerabilities:
* Runtime C undefined behavior (including integer overflow)
* Crash caused by misused API
* Crash caused by tweaked compiled binary
-10
View File
@@ -1,10 +0,0 @@
Things to do (Things that are not done yet)
* special variables ($1,$2..)
* super in aliased methods
* multi-assignment decomposing
* keyword arguments in def statement
Things to improve (Done but things to fix)
* Make additions as they are noticed.
+14
View File
@@ -0,0 +1,14 @@
# Thing to Do in the future
# After mruby 3.1
* multi-precision integer
* parser and code generator independent from `mrb_state` (picoruby?)
* variable sized AST node
* iv/hash entry cache
* more peephole optimization (if possible)
# Things to do (Things we need to consider)
* `begin ... end while cond` to behave as CRuby
* special variables ($1,$2..)
+31 -24
View File
@@ -1,38 +1,45 @@
version: "{build}"
os: Visual Studio 2015
clone_depth: 50
cache:
- win_flex_bison-2.5.10.zip
shallow_clone: true
environment:
matrix:
# Visual Studio 2015 64bit
- visualcpp: C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat
machine: amd64
- job_name: Visual Studio 2019 64bit
visualcpp: C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars64.bat
appveyor_build_worker_image: Visual Studio 2019
# Visual Studio 2013 64bit
- visualcpp: C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\vcvarsall.bat
machine: amd64
- job_name: Visual Studio 2019 32bit
visualcpp: C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars32.bat
appveyor_build_worker_image: Visual Studio 2019
- job_name: Visual Studio 2017 64bit
visualcpp: C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars64.bat
appveyor_build_worker_image: Visual Studio 2017
- job_name: Visual Studio 2017 32bit
visualcpp: C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars32.bat
appveyor_build_worker_image: Visual Studio 2017
- job_name: Visual Studio 2015 64bit
visualcpp: C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat
appveyor_build_worker_image: Visual Studio 2015
machine: x86_amd64
- job_name: Visual Studio 2015 32bit
visualcpp: C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat
appveyor_build_worker_image: Visual Studio 2015
machine: x86
init:
- call "%visualcpp%" %machine%
# For using Rubyinstaller's Ruby 2.4 64bit
- set PATH=C:\Ruby24-x64\bin;%PATH%
# For using RubyInstaller's Ruby 2.6 64bit
# 2.6 is the highest supported Ruby version across all historical
# Visual Studio AppVeyor images. Ruby 2.7 is only on the 2019 image.
- set PATH=C:\Ruby26-x64\bin;%PATH%
- ruby --version
install:
- if not exist win_flex_bison-2.5.10.zip appveyor DownloadFile "https://github.com/lexxmark/winflexbison/releases/download/v.2.5.10/win_flex_bison-2.5.10.zip"
- 7z x -y -owin_flex_bison win_flex_bison-2.5.10.zip > nul
build_script:
- set YACC=.\win_flex_bison\win_bison.exe
- set MRUBY_CONFIG=appveyor_config.rb
- ruby .\minirake test all
- set MRUBY_CONFIG=ci/msvc
- rake -m test:build
- rake test:run
-50
View File
@@ -1,50 +0,0 @@
MRuby::Build.new('debug') do |conf|
toolchain :visualcpp
enable_debug
# include all core GEMs
conf.gembox 'full-core'
conf.compilers.each do |c|
c.defines += %w(MRB_GC_STRESS MRB_GC_FIXED_ARENA MRB_METHOD_CACHE)
end
build_mrbc_exec
end
MRuby::Build.new('full-debug') do |conf|
toolchain :visualcpp
enable_debug
# include all core GEMs
conf.gembox 'full-core'
conf.cc.defines = %w(MRB_ENABLE_DEBUG_HOOK)
conf.enable_test
end
MRuby::Build.new do |conf|
toolchain :visualcpp
# include all core GEMs
conf.gembox 'full-core'
conf.compilers.each do |c|
c.defines += %w(MRB_GC_FIXED_ARENA)
end
conf.enable_bintest
conf.enable_test
end
MRuby::Build.new('cxx_abi') do |conf|
toolchain :visualcpp
conf.gembox 'full-core'
conf.compilers.each do |c|
c.defines += %w(MRB_GC_FIXED_ARENA)
end
conf.enable_bintest
conf.enable_test
enable_cxx_abi
build_mrbc_exec
end
+12 -12
View File
@@ -1,29 +1,29 @@
# AO render benchmark
# Original program (C) Syoyo Fujita in Javascript (and other languages)
# Original program (C) Syoyo Fujita in JavaScript (and other languages)
# https://code.google.com/p/aobench/
# Ruby(yarv2llvm) version by Hideki Miura
# mruby version by Hideki Miura
#
IMAGE_WIDTH = 64
IMAGE_HEIGHT = 64
IMAGE_WIDTH = Integer(ARGV[0] || 64)
IMAGE_HEIGHT = IMAGE_WIDTH
NSUBSAMPLES = 2
NAO_SAMPLES = 8
module Rand
# Use xorshift
@@x = 123456789
@@y = 362436069
@@z = 521288629
@@w = 88675123
@x = 123456789
@y = 362436069
@z = 521288629
@w = 88675123
BNUM = 1 << 29
BNUMF = BNUM.to_f
def self.rand
x = @@x
x = @x
t = x ^ ((x & 0xfffff) << 11)
w = @@w
@@x, @@y, @@z = @@y, @@z, w
w = @@w = (w ^ (w >> 19) ^ (t ^ (t >> 8)))
w = @w
@x, @y, @z = @y, @z, w
w = @w = (w ^ (w >> 19) ^ (t ^ (t >> 8)))
(w % BNUM) / BNUMF
end
end
@@ -260,7 +260,7 @@ class Scene
w.times do |x|
rad = Vec.new(0.0, 0.0, 0.0)
# Subsmpling
# Subsampling
nsubsamples.times do |v|
nsubsamples.times do |u|
cnt = cnt + 1
+1 -2
View File
@@ -48,5 +48,4 @@ answer = to_array(solution).map do |p|
to_string(p)
end
answer_str = answer.to_a
# puts answer_str
# puts answer
+1 -1
View File
@@ -1,4 +1,4 @@
#from http://www.bagley.org/~doug/shootout/bench/lists/lists.ruby
# from http://www.bagley.org/~doug/shootout/bench/lists/lists.ruby
NUM = 300
SIZE = 10000
-28
View File
@@ -1,28 +0,0 @@
MRuby::Build.new do |conf|
toolchain :gcc
end
MRuby::Build.new('no_boxing') do |conf|
toolchain :gcc
conf.gembox 'default'
end
MRuby::Build.new('word_boxing') do |conf|
toolchain :gcc
conf.gembox 'default'
conf.compilers.each do |c|
c.defines += %w(MRB_WORD_BOXING)
end
end
MRuby::Build.new('nan_boxing') do |conf|
toolchain :gcc
conf.gembox 'default'
conf.compilers.each do |c|
c.defines += %w(MRB_NAN_BOXING)
end
end
-13
View File
@@ -1,13 +0,0 @@
MRuby::Build.new do |conf|
toolchain :gcc
end
MRuby::Build.new('gcc') do |conf|
toolchain :gcc
conf.gembox 'default'
end
MRuby::Build.new('clang') do |conf|
toolchain :clang
conf.gembox 'default'
end
+8 -151
View File
@@ -1,152 +1,9 @@
MRuby::Build.new do |conf|
# load specific toolchain settings
# Gets set by the VS command prompts.
if ENV['VisualStudioVersion'] || ENV['VSINSTALLDIR']
toolchain :visualcpp
else
toolchain :gcc
end
# Turn on `enable_debug` for better debugging
# enable_debug
# Use mrbgems
# conf.gem 'examples/mrbgems/ruby_extension_example'
# conf.gem 'examples/mrbgems/c_extension_example' do |g|
# g.cc.flags << '-g' # append cflags in this gem
# end
# conf.gem 'examples/mrbgems/c_and_ruby_extension_example'
# conf.gem :core => 'mruby-eval'
# conf.gem :mgem => 'mruby-io'
# conf.gem :github => 'iij/mruby-io'
# conf.gem :git => 'git@github.com:iij/mruby-io.git', :branch => 'master', :options => '-v'
# include the default GEMs
conf.gembox 'default'
# C compiler settings
# conf.cc do |cc|
# cc.command = ENV['CC'] || 'gcc'
# cc.flags = [ENV['CFLAGS'] || %w()]
# cc.include_paths = ["#{root}/include"]
# cc.defines = %w(DISABLE_GEMS)
# cc.option_include_path = '-I%s'
# cc.option_define = '-D%s'
# cc.compile_options = "%{flags} -MMD -o %{outfile} -c %{infile}"
# end
# mrbc settings
# conf.mrbc do |mrbc|
# mrbc.compile_options = "-g -B%{funcname} -o-" # The -g option is required for line numbers
# end
# Linker settings
# conf.linker do |linker|
# linker.command = ENV['LD'] || 'gcc'
# linker.flags = [ENV['LDFLAGS'] || []]
# linker.flags_before_libraries = []
# linker.libraries = %w()
# linker.flags_after_libraries = []
# linker.library_paths = []
# linker.option_library = '-l%s'
# linker.option_library_path = '-L%s'
# linker.link_options = "%{flags} -o %{outfile} %{objs} %{libs}"
# end
# Archiver settings
# conf.archiver do |archiver|
# archiver.command = ENV['AR'] || 'ar'
# archiver.archive_options = 'rs %{outfile} %{objs}'
# end
# Parser generator settings
# conf.yacc do |yacc|
# yacc.command = ENV['YACC'] || 'bison'
# yacc.compile_options = '-o %{outfile} %{infile}'
# end
# gperf settings
# conf.gperf do |gperf|
# gperf.command = 'gperf'
# gperf.compile_options = '-L ANSI-C -C -p -j1 -i 1 -g -o -t -N mrb_reserved_word -k"1,3,$" %{infile} > %{outfile}'
# end
# file extensions
# conf.exts do |exts|
# exts.object = '.o'
# exts.executable = '' # '.exe' if Windows
# exts.library = '.a'
# end
# file separetor
# conf.file_separator = '/'
# bintest
# conf.enable_bintest
end
MRuby::Build.new('host-debug') do |conf|
# load specific toolchain settings
# Gets set by the VS command prompts.
if ENV['VisualStudioVersion'] || ENV['VSINSTALLDIR']
toolchain :visualcpp
else
toolchain :gcc
end
enable_debug
# include the default GEMs
conf.gembox 'default'
# C compiler settings
conf.cc.defines = %w(MRB_ENABLE_DEBUG_HOOK)
# Generate mruby debugger command (require mruby-eval)
conf.gem :core => "mruby-bin-debugger"
# bintest
# conf.enable_bintest
end
MRuby::Build.new('test') do |conf|
# Gets set by the VS command prompts.
if ENV['VisualStudioVersion'] || ENV['VSINSTALLDIR']
toolchain :visualcpp
else
toolchain :gcc
end
enable_debug
conf.enable_bintest
conf.enable_test
conf.gembox 'default'
end
#MRuby::Build.new('bench') do |conf|
# # Gets set by the VS command prompts.
# if ENV['VisualStudioVersion'] || ENV['VSINSTALLDIR']
# toolchain :visualcpp
# else
# toolchain :gcc
# conf.cc.flags << '-O3'
# end
# The default build configuration file was moved to `build_config/default.rb`.
#
# conf.gembox 'default'
#end
# Define cross build settings
# MRuby::CrossBuild.new('32bit') do |conf|
# toolchain :gcc
#
# conf.cc.flags << "-m32"
# conf.linker.flags << "-m32"
#
# conf.build_mrbtest_lib_only
#
# conf.gem 'examples/mrbgems/c_and_ruby_extension_example'
#
# conf.test_runner.command = 'env'
# end
# Recommended way to customize the build configuration is:
# * copy `default.rb` (or any config file) to a new file (e.g. `myconfig.rb`)
# * edit `myconfig.rb`.
# * `rake MRUBY_CONFIG=/path/to/myconfig.rb` to compile and test.
# * or `rake MRUBY_CONFIG=myconfig` if your configuration file is in the `build_config` directory.
# * (optional) submit your configuration as a pull-request if it's useful for others
raise "The default configuration was moved to `build_config/default.rb`"
@@ -1,21 +1,5 @@
MRuby::Build.new do |conf|
# Gets set by the VS command prompts.
if ENV['VisualStudioVersion'] || ENV['VSINSTALLDIR']
toolchain :visualcpp
else
toolchain :gcc
end
enable_debug
# include the default GEMs
conf.gembox 'default'
end
# Cross Compiling configuration for Arduino Due
# http://arduino.cc/en/Main/ArduinoBoardDue
# https://arduino.cc/en/Main/ArduinoBoardDue
#
# Requires Arduino IDE >= 1.5
MRuby::CrossBuild.new("ArduinoDue") do |conf|
@@ -27,7 +11,7 @@ MRuby::CrossBuild.new("ArduinoDue") do |conf|
# ARDUINO_PATH = '/Applications/Arduino.app/Contents/Java'
# GNU Linux
ARDUINO_PATH = '/opt/arduino'
# Arduino IDE <= 1.5.6
# Arduino IDE <= 1.5.6
BIN_PATH = "#{ARDUINO_PATH}/hardware/tools/g++_arm_none_eabi/bin"
# Arduino IDE >= 1.5.7
# BIN_PATH = "#{ARDUINO_PATH}/hardware/tools/gcc-arm-none-eabi-4.8.3-2014q1/bin"
@@ -42,14 +26,13 @@ MRuby::CrossBuild.new("ArduinoDue") do |conf|
cc.flags = %w(-g -Os -w -ffunction-sections -fdata-sections -nostdlib --param max-inline-insns-single=500
-Dprintf=iprintf -mcpu=cortex-m3 -DF_CPU=84000000L -DARDUINO=156 -DARDUINO_SAM_DUE -DARDUINO_ARCH_SAM
-D__SAM3X8E__ -mthumb -DUSB_PID=0x003e -DUSB_VID=0x2341 -DUSBCON -DUSB_MANUFACTURER="Unknown" -DUSB_PRODUCT="Arduino Due")
cc.compile_options = "%{flags} -o %{outfile} -c %{infile}"
cc.compile_options = %Q[%{flags} -o "%{outfile}" -c "%{infile}"]
#configuration for low memory environment
cc.defines << %w(MRB_HEAP_PAGE_SIZE=64)
cc.defines << %w(KHASH_DEFAULT_SIZE=8)
cc.defines << %w(MRB_STR_BUF_MIN_SIZE=20)
cc.defines << %w(MRB_GC_STRESS)
#cc.defines << %w(MRB_DISABLE_STDIO) #if you dont need stdio.
#cc.defines << %w(MRB_NO_STDIO) #if you don't need stdio.
#cc.defines << %w(POOL_PAGE_SIZE=1000) #effective only for use with mruby-eval
end
@@ -64,7 +47,7 @@ MRuby::CrossBuild.new("ArduinoDue") do |conf|
conf.archiver do |archiver|
archiver.command = "#{BIN_PATH}/arm-none-eabi-ar"
archiver.archive_options = 'rcs %{outfile} %{objs}'
archiver.archive_options = 'rcs "%{outfile}" %{objs}'
end
#no executables
@@ -5,7 +5,7 @@
MRuby::Build.new do |conf|
toolchain :gcc
conf.gembox 'default'
conf.cc.defines = %w(ENABLE_READLINE)
conf.cc.defines = %w(MRB_USE_READLINE)
conf.gembox 'default'
#lightweight regular expression
@@ -21,7 +21,7 @@ MRuby::CrossBuild.new('core2-32-poky-linux') do |conf|
#
POKY_EDISON_PATH = '/opt/poky-edison/1.7.2'
POKY_EDISON_SYSROOT = "#{POKY_EDISON_PATH}/sysroots/core2-32-poky-linux"
POKY_EDISON_SYSROOT = "#{POKY_EDISON_PATH}/sysroots/core2-32-poky-linux"
POKY_EDISON_X86_PATH = "#{POKY_EDISON_PATH}/sysroots/i386-pokysdk-darwin"
POKY_EDISON_BIN_PATH = "#{POKY_EDISON_X86_PATH}/usr/bin/i586-poky-linux"
@@ -32,8 +32,8 @@ MRuby::CrossBuild.new('core2-32-poky-linux') do |conf|
cc.flags = %w(-m32 -march=core2 -mtune=core2 -msse3 -mfpmath=sse -mstackrealign -fno-omit-frame-pointer)
cc.flags << %w(-O2 -pipe -g -feliminate-unused-debug-types)
cc.flags << "--sysroot=#{POKY_EDISON_SYSROOT}"
cc.compile_options = "%{flags} -o %{outfile} -c %{infile}"
cc.defines = %w(ENABLE_READLINE)
cc.compile_options = %Q[%{flags} -o "%{outfile}" -c "%{infile}"]
cc.defines = %w(MRB_USE_READLINE)
end
conf.cxx do |cxx|
@@ -47,7 +47,7 @@ MRuby::CrossBuild.new('core2-32-poky-linux') do |conf|
conf.archiver do |archiver|
archiver.command = "#{POKY_EDISON_BIN_PATH}/i586-poky-linux-ar"
archiver.archive_options = 'rcs %{outfile} %{objs}'
archiver.archive_options = 'rcs "%{outfile}" %{objs}'
end
conf.linker do |linker|
@@ -1,22 +1,5 @@
MRuby::Build.new do |conf|
# Gets set by the VS command prompts.
if ENV['VisualStudioVersion'] || ENV['VSINSTALLDIR']
toolchain :visualcpp
else
toolchain :gcc
end
enable_debug
# include the default GEMs
conf.gembox 'default'
end
# Cross Compiling configuration for Intel Galileo on Arduino environment
# http://arduino.cc/en/ArduinoCertified/IntelGalileo
# https://arduino.cc/en/ArduinoCertified/IntelGalileo
#
# Requires Arduino IDE for Intel Galileo
MRuby::CrossBuild.new("Galileo") do |conf|
@@ -39,7 +22,7 @@ MRuby::CrossBuild.new("Galileo") do |conf|
cc.flags = %w(-m32 -march=i586 -c -g -Os -w
-ffunction-sections -fdata-sections -MMD -DARDUINO=153)
cc.flags << "--sysroot=#{GALILEO_SYSROOT}"
cc.compile_options = "%{flags} -o %{outfile} -c %{infile}"
cc.compile_options = %Q[%{flags} -o "%{outfile}" -c "%{infile}"]
end
conf.cxx do |cxx|
@@ -54,7 +37,7 @@ MRuby::CrossBuild.new("Galileo") do |conf|
conf.archiver do |archiver|
archiver.command = "#{GALILEO_BIN_PATH}/i586-poky-linux-uclibc-ar"
archiver.archive_options = 'rcs %{outfile} %{objs}'
archiver.archive_options = 'rcs "%{outfile}" %{objs}'
end
conf.linker do |linker|
@@ -91,7 +74,7 @@ MRuby::CrossBuild.new("Galileo") do |conf|
conf.gem :core => "mruby-fiber"
conf.gem :core => "mruby-toplevel-ext"
#lightweigh regular expression
#lightweight regular expression
conf.gem :github => "masamitsu-murase/mruby-hs-regexp", :branch => "master"
#Arduino API
@@ -1,19 +1,3 @@
MRuby::Build.new do |conf|
# Gets set by the VS command prompts.
if ENV['VisualStudioVersion'] || ENV['VSINSTALLDIR']
toolchain :visualcpp
else
toolchain :gcc
end
enable_debug
# include the default GEMs
conf.gembox 'default'
end
# Cross Compiling configuration for RX630
# http://gadget.renesas.com/
#
@@ -27,15 +11,14 @@ MRuby::CrossBuild.new("RX630") do |conf|
conf.cc do |cc|
cc.command = "#{BIN_PATH}/rx-elf-gcc"
cc.flags = "-Wall -g -O2 -flto -mcpu=rx600 -m64bit-doubles"
cc.compile_options = "%{flags} -o %{outfile} -c %{infile}"
cc.compile_options = %Q[%{flags} -o "%{outfile}" -c "%{infile}"]
#configuration for low memory environment
cc.defines << %w(MRB_USE_FLOAT)
cc.defines << %w(MRB_USE_FLOAT32)
cc.defines << %w(MRB_HEAP_PAGE_SIZE=64)
cc.defines << %w(KHASH_DEFAULT_SIZE=8)
cc.defines << %w(MRB_STR_BUF_MIN_SIZE=20)
cc.defines << %w(MRB_GC_STRESS)
cc.defines << %w(MRB_DISABLE_STDIO) #if you dont need stdio.
cc.defines << %w(MRB_NO_STDIO) #if you don't need stdio.
#cc.defines << %w(POOL_PAGE_SIZE=1000) #effective only for use with mruby-eval
end
@@ -53,7 +36,7 @@ MRuby::CrossBuild.new("RX630") do |conf|
conf.archiver do |archiver|
archiver.command = "#{BIN_PATH}/rx-elf-ar"
archiver.archive_options = 'rcs %{outfile} %{objs}'
archiver.archive_options = 'rcs "%{outfile}" %{objs}'
end
#no executables
+11
View File
@@ -0,0 +1,11 @@
# Requires Android NDK r13 or later.
MRuby::CrossBuild.new('android-arm64-v8a') do |conf|
params = {
:arch => 'arm64-v8a',
:platform => 'android-24',
:toolchain => :clang,
}
toolchain :android, params
conf.gembox 'default'
end
+11
View File
@@ -0,0 +1,11 @@
# Requires Android NDK r13 or later.
MRuby::CrossBuild.new('android-armeabi') do |conf|
params = {
:arch => 'armeabi',
:platform => 'android-24',
:toolchain => :clang,
}
toolchain :android, params
conf.gembox 'default'
end
@@ -1,18 +1,3 @@
MRuby::Build.new do |conf|
# Gets set by the VS command prompts.
if ENV['VisualStudioVersion'] || ENV['VSINSTALLDIR']
toolchain :visualcpp
else
toolchain :gcc
end
enable_debug
# include the default GEMs
conf.gembox 'default'
end
# Requires Android NDK r13 or later.
MRuby::CrossBuild.new('android-armeabi-v7a-neon-hard') do |conf|
params = {
+11
View File
@@ -0,0 +1,11 @@
MRuby::Build.new('bench') do |conf|
# Gets set by the VS command prompts.
if ENV['VisualStudioVersion'] || ENV['VSINSTALLDIR']
toolchain :visualcpp
else
toolchain :gcc
conf.cc.flags << '-O3'
end
conf.gembox 'default'
end
+19
View File
@@ -0,0 +1,19 @@
boxings = %w[no word nan]
bits = [64, 32]
ints = [64, 32]
boxings.product(bits, ints) do |boxing, bit, int|
MRuby::Build.new("boxing-#{boxing}-m#{bit}-i#{int}") do |conf|
conf.toolchain :gcc
conf.gembox 'default'
conf.compilers.each do |c|
c.defines << "MRB_#{boxing.upcase}_BOXING"
c.defines << "MRB_INT#{int}"
c.flags << "-m#{bit}"
end
conf.linker.flags << "-m#{bit}"
conf.enable_debug
conf.enable_test
conf.enable_bintest
end
end
@@ -1,21 +1,5 @@
MRuby::Build.new do |conf|
# Gets set by the VS command prompts.
if ENV['VisualStudioVersion'] || ENV['VSINSTALLDIR']
toolchain :visualcpp
else
toolchain :gcc
end
enable_debug
# include the default GEMs
conf.gembox 'default'
end
# Cross Compiling configuration for Digilent chipKIT Max32
# http://www.digilentinc.com/Products/Detail.cfm?Prod=CHIPKIT-MAX32
# https://www.digilentinc.com/Products/Detail.cfm?Prod=CHIPKIT-MAX32
#
# Requires MPIDE (https://github.com/chipKIT32/chipKIT32-MAX)
#
@@ -39,14 +23,13 @@ MRuby::CrossBuild.new("chipKITMax32") do |conf|
cc.flags = %w(-O2 -mno-smart-io -w -ffunction-sections -fdata-sections -g -mdebugger -Wcast-align
-fno-short-double -mprocessor=32MX795F512L -DF_CPU=80000000L -DARDUINO=23 -D_BOARD_MEGA_
-DMPIDEVER=0x01000202 -DMPIDE=23)
cc.compile_options = "%{flags} -o %{outfile} -c %{infile}"
cc.compile_options = %Q[%{flags} -o "%{outfile}" -c "%{infile}"]
#configuration for low memory environment
cc.defines << %w(MRB_HEAP_PAGE_SIZE=64)
cc.defines << %w(KHASH_DEFAULT_SIZE=8)
cc.defines << %w(MRB_STR_BUF_MIN_SIZE=20)
cc.defines << %w(MRB_GC_STRESS)
#cc.defines << %w(MRB_DISABLE_STDIO) #if you dont need stdio.
#cc.defines << %w(MRB_NO_STDIO) #if you don't need stdio.
#cc.defines << %w(POOL_PAGE_SIZE=1000) #effective only for use with mruby-eval
end
@@ -60,7 +43,7 @@ MRuby::CrossBuild.new("chipKITMax32") do |conf|
conf.archiver do |archiver|
archiver.command = "#{PIC32_PATH}/compiler/pic32-tools/bin/pic32-ar"
archiver.archive_options = 'rcs %{outfile} %{objs}'
archiver.archive_options = 'rcs "%{outfile}" %{objs}'
end
#no executables
+40
View File
@@ -0,0 +1,40 @@
STDOUT.sync = STDERR.sync = true unless Rake.application.options.always_multitask
MRuby::Build.new('full-debug') do |conf|
conf.toolchain
conf.enable_debug
# include all core GEMs
conf.gembox 'full-core'
conf.cc.defines += %w(MRB_GC_STRESS MRB_USE_DEBUG_HOOK MRB_UTF8_STRING)
conf.enable_test
end
MRuby::Build.new do |conf|
conf.toolchain
# include all core GEMs
conf.gembox 'full-core'
conf.gem :core => 'mruby-bin-debugger'
conf.compilers.each do |c|
c.defines += %w(MRB_GC_FIXED_ARENA MRB_UTF8_STRING)
end
conf.enable_bintest
conf.enable_test
end
MRuby::Build.new('cxx_abi') do |conf|
conf.toolchain
conf.gembox 'full-core'
conf.cc.flags += %w(-fpermissive -std=gnu++03)
conf.compilers.each do |c|
c.defines += %w(MRB_GC_FIXED_ARENA MRB_UTF8_STRING)
end
conf.enable_test
conf.enable_cxx_abi
conf.build_mrbc_exec
end
+20
View File
@@ -0,0 +1,20 @@
STDOUT.sync = STDERR.sync = true unless Rake.application.options.always_multitask
def setup_option(conf)
conf.cc.compile_options.sub!(%r{/Zi }, "") unless ENV['CFLAGS']
conf.cxx.compile_options.sub!(%r{/Zi }, "") unless ENV['CFLAGS'] || ENV['CXXFLAGS']
conf.linker.flags << "/DEBUG:NONE" unless ENV['LDFLAGS']
end
MRuby::Build.new do |conf|
conf.toolchain :visualcpp
# include all core GEMs
conf.gembox 'full-core'
conf.compilers.each do |c|
c.defines += %w(MRB_GC_FIXED_ARENA)
end
setup_option(conf)
conf.enable_bintest
conf.enable_test
end
+11
View File
@@ -0,0 +1,11 @@
MRuby::Build.new do |conf|
conf.toolchain :clang
# include the GEM box
conf.gembox 'full-core'
# Turn on `enable_debug` for better debugging
conf.enable_sanitizer "address,undefined"
conf.enable_debug
conf.enable_bintest
conf.enable_test
end
+14
View File
@@ -0,0 +1,14 @@
# Define cross build settings
MRuby::CrossBuild.new('cross-32bit') do |conf|
conf.toolchain :gcc
conf.cc.flags << "-m32"
conf.linker.flags << "-m32"
# conf.build_mrbtest_lib_only
conf.gem :core => "mruby-bin-mruby"
conf.gem "#{MRUBY_ROOT}/examples/mrbgems/c_and_ruby_extension_example"
conf.test_runner.command = 'env'
end
+91
View File
@@ -0,0 +1,91 @@
# Cross-compile using MinGW and test using Wine.
#
# Steps:
#
# 1. Install MinGW; 64-bit target seems to work best.
#
# 2. Install Wine.
#
# 3. Run command:
#
# wine cmd /c echo "Hello world"'
#
# This will confirm that Wine works and will trigger standard
# Wine setup, which is slow.
#
# 4. Confirm that drive 'z:' is mapped to your root filesystem.
# (This is supposed to be a default but it helps to
# double-check.) To confirm, run:
#
# wine cmd /c dir 'z:\\'
#
# This should give you a DOS-style equivalent of 'ls /'. If not,
# you'll need to fix that with winecfg or by adding a symlink to
# '~/.wine/dosdevices'.
#
# 5. You will likely need to tweak the settings below to work with
# your configuration unless it is exactly like one of the platforms
# I've tested on (Ubuntu 20.04 or macOS using brew.)
#
# 6. Run the build command:
#
# MRUBY_CONFIG=build_config/cross-mingw-winetest.rb rake test
#
# If all goes well, you should now have Windows executables and a
# set of passing tests.
#
#
# Caveats:
#
# 1. This works by using a helper script that rewrites test output
# to make it look *nix-like and then handing it back to the test
# cases. Some of the existing tests were (slightly) modified to
# make this easier but only for the 'full-core' gembox. Other
# gems' bintests may or may not work with the helper script and
# may or may not be fixable by extending the script.
#
# 2. MinGW and Wine are both complex and not very consistent so you
# will likely need to do some fiddling to get things to work.
#
# 3. This script assumes you are running it on a *nix-style OS.
#
# 4. I recommend building 64-bit targets only. Building a 32-bit
# Windows binary with i686-w64-mingw32 seems to work (at least,
# it did for me) but the resulting executable failed a number of
# unit tests due to small errors in some floating point
# operations. It's unclear if this indicates more serious problems.
#
MRuby::CrossBuild.new("cross-mingw-winetest") do |conf|
conf.toolchain :gcc
conf.host_target = "x86_64-w64-mingw32"
# Ubuntu 20
conf.cc.command = "#{conf.host_target}-gcc-posix"
# macOS+Wine from brew
#conf.cc.command = "#{conf.host_target}-gcc"
conf.linker.command = conf.cc.command
conf.archiver.command = "#{conf.host_target}-gcc-ar"
conf.exts.executable = ".exe"
# By default, we compile as static as possible to remove runtime
# MinGW dependencies; they are probably fixable but it gets
# complicated.
conf.cc.flags = ['-static']
conf.linker.flags += ['-static']
conf.test_runner do |t|
thisdir = File.absolute_path( File.dirname(__FILE__) )
t.command = File.join(thisdir, * %w{ helpers wine_runner.rb})
end
conf.gembox "full-core"
conf.enable_bintest
conf.enable_test
end
+14
View File
@@ -0,0 +1,14 @@
#
# Ubuntu 20.04 requires at least `gcc-mingw-w64-x86-64` package as a
# cross compiler.
#
MRuby::CrossBuild.new("cross-mingw") do |conf|
conf.toolchain :gcc
conf.host_target = "x86_64-w64-mingw32" # required for `for_windows?` used by `mruby-socket` gem
conf.cc.command = "#{conf.host_target}-gcc-posix"
conf.linker.command = conf.cc.command
conf.archiver.command = "#{conf.host_target}-gcc-ar"
conf.exts.executable = ".exe"
conf.gembox "default"
end
+80
View File
@@ -0,0 +1,80 @@
MRuby::Build.new do |conf|
# load specific toolchain settings
conf.toolchain
# Use mrbgems
# conf.gem 'examples/mrbgems/ruby_extension_example'
# conf.gem 'examples/mrbgems/c_extension_example' do |g|
# g.cc.flags << '-g' # append cflags in this gem
# end
# conf.gem 'examples/mrbgems/c_and_ruby_extension_example'
# conf.gem :core => 'mruby-eval'
# conf.gem :mgem => 'mruby-onig-regexp'
# conf.gem :github => 'mattn/mruby-onig-regexp'
# conf.gem :git => 'git@github.com:mattn/mruby-onig-regexp.git', :branch => 'master', :options => '-v'
# include the GEM box
conf.gembox 'default'
# C compiler settings
# conf.cc do |cc|
# cc.command = ENV['CC'] || 'gcc'
# cc.flags = [ENV['CFLAGS'] || %w()]
# cc.include_paths = ["#{root}/include"]
# cc.defines = %w()
# cc.option_include_path = %q[-I"%s"]
# cc.option_define = '-D%s'
# cc.compile_options = %Q[%{flags} -MMD -o "%{outfile}" -c "%{infile}"]
# end
# mrbc settings
# conf.mrbc do |mrbc|
# mrbc.compile_options = "-g -B%{funcname} -o-" # The -g option is required for line numbers
# end
# Linker settings
# conf.linker do |linker|
# linker.command = ENV['LD'] || 'gcc'
# linker.flags = [ENV['LDFLAGS'] || []]
# linker.flags_before_libraries = []
# linker.libraries = %w()
# linker.flags_after_libraries = []
# linker.library_paths = []
# linker.option_library = '-l%s'
# linker.option_library_path = '-L%s'
# linker.link_options = %Q[%{flags} -o "%{outfile}" %{objs} %{libs}]
# end
# Archiver settings
# conf.archiver do |archiver|
# archiver.command = ENV['AR'] || 'ar'
# archiver.archive_options = 'rs "%{outfile}" %{objs}'
# end
# Parser generator settings
# conf.yacc do |yacc|
# yacc.command = ENV['YACC'] || 'bison'
# yacc.compile_options = %q[-o "%{outfile}" "%{infile}"]
# end
# gperf settings
# conf.gperf do |gperf|
# gperf.command = 'gperf'
# gperf.compile_options = %q[-L ANSI-C -C -p -j1 -i 1 -g -o -t -N mrb_reserved_word -k"1,3,$" "%{infile}" > "%{outfile}"]
# end
# file extensions
# conf.exts do |exts|
# exts.object = '.o'
# exts.executable = '' # '.exe' if Windows
# exts.library = '.a'
# end
# file separator
# conf.file_separator = '/'
# Turn on `enable_debug` for better debugging
# conf.enable_debug
conf.enable_bintest
conf.enable_test
end
+117
View File
@@ -0,0 +1,117 @@
# Cross Compiling configuration for the Sega Dreamcast
# https://dreamcast.wiki/Using_Ruby_for_Sega_Dreamcast_development
#
# Requires KallistiOS (KOS)
# http://gamedev.allusion.net/softprj/kos/
#
# Tested on GNU/Linux, macOS and Windows (through MinGW-w64/MSYS2, Cygwin and DreamSDK).
# DreamSDK is based on MinGW/MSYS: https://dreamsdk.org/
#
# Input this command on the directory where mruby is installed:
# make MRUBY_CONFIG=dreamcast_shelf
#
MRuby::CrossBuild.new("dreamcast") do |conf|
toolchain :gcc
# Support for DreamSDK (based on MinGW/MSYS)
# To compile mruby with DreamSDK, RubyInstaller for Windows should be installed
DREAMSDK_HOME = ENV["DREAMSDK_HOME"]
MSYS_ROOT = !(DREAMSDK_HOME.nil? || DREAMSDK_HOME.empty?) ? "#{DREAMSDK_HOME}/msys/1.0" : ""
# Setting paths
DREAMCAST_PATH = "#{MSYS_ROOT}/opt/toolchains/dc"
KOS_PATH = "#{DREAMCAST_PATH}/kos"
BIN_PATH = "#{DREAMCAST_PATH}/sh-elf/bin"
# C compiler
# Flags were extracted from KallistiOS environment files
conf.cc do |cc|
cc.command = "#{BIN_PATH}/sh-elf-gcc"
cc.include_paths << ["#{KOS_PATH}/include", "#{KOS_PATH}/kernel/arch/dreamcast/include", "#{KOS_PATH}/addons/include", "#{KOS_PATH}/../kos-ports/include"]
cc.flags << ["-O2", "-fomit-frame-pointer", "-ml", "-m4-single-only", "-ffunction-sections", "-fdata-sections", "-Wall", "-g", "-fno-builtin", "-ml", "-m4-single-only", "-Wl,-Ttext=0x8c010000", "-Wl,--gc-sections", "-T#{KOS_PATH}/utils/ldscripts/shlelf.xc", "-nodefaultlibs"]
cc.compile_options = %Q[%{flags} -o "%{outfile}" -c "%{infile}"]
cc.defines << %w(_arch_dreamcast)
cc.defines << %w(_arch_sub_pristine)
end
# C++ compiler
conf.cxx do |cxx|
cxx.command = conf.cc.command.dup
cxx.include_paths = conf.cc.include_paths.dup
cxx.flags = conf.cc.flags.dup
cxx.flags << %w(-fno-rtti -fno-exceptions)
cxx.defines = conf.cc.defines.dup
cxx.compile_options = conf.cc.compile_options.dup
end
# Linker
# There is an issue when making the mruby library with KallistiOS:
# 'newlib_kill.o' and 'newlib_getpid.o' aren't found so they are explicitly
# specified here at least for now.
conf.linker do |linker|
linker.command="#{BIN_PATH}/sh-elf-gcc"
linker.flags << ["#{MSYS_ROOT}/opt/toolchains/dc/kos/kernel/build/newlib_kill.o", "#{MSYS_ROOT}/opt/toolchains/dc/kos/kernel/build/newlib_getpid.o", "-Wl,--start-group -lkallisti -lc -lgcc -Wl,--end-group"]
linker.library_paths << ["#{KOS_PATH}/lib/dreamcast", "#{KOS_PATH}/addons/lib/dreamcast", "#{KOS_PATH}/../kos-ports/lib"]
end
# Archiver
conf.archiver do |archiver|
archiver.command = "#{BIN_PATH}/sh-elf-ar"
archiver.archive_options = 'rcs "%{outfile}" %{objs}'
end
# No executables
conf.bins = []
# Do not build executable test
conf.build_mrbtest_lib_only
# Disable C++ exception
conf.disable_cxx_exception
# Gems from core
# Some Gems are incompatible and were disabled.
conf.gem :core => "mruby-array-ext"
conf.gem :core => "mruby-binding"
conf.gem :core => "mruby-catch"
conf.gem :core => "mruby-class-ext"
conf.gem :core => "mruby-cmath"
conf.gem :core => "mruby-compar-ext"
conf.gem :core => "mruby-compiler"
conf.gem :core => "mruby-complex"
conf.gem :core => "mruby-enum-chain"
conf.gem :core => "mruby-enum-ext"
conf.gem :core => "mruby-enum-lazy"
conf.gem :core => "mruby-enumerator"
conf.gem :core => "mruby-error"
conf.gem :core => "mruby-eval"
conf.gem :core => "mruby-exit"
conf.gem :core => "mruby-fiber"
conf.gem :core => "mruby-hash-ext"
# conf.gem :core => "mruby-io"
conf.gem :core => "mruby-kernel-ext"
conf.gem :core => "mruby-math"
conf.gem :core => "mruby-metaprog"
conf.gem :core => "mruby-method"
conf.gem :core => "mruby-numeric-ext"
conf.gem :core => "mruby-object-ext"
conf.gem :core => "mruby-objectspace"
conf.gem :core => "mruby-os-memsize"
conf.gem :core => "mruby-pack"
conf.gem :core => "mruby-print"
conf.gem :core => "mruby-proc-binding"
conf.gem :core => "mruby-proc-ext"
conf.gem :core => "mruby-random"
conf.gem :core => "mruby-range-ext"
conf.gem :core => "mruby-rational"
conf.gem :core => "mruby-sleep"
# conf.gem :core => "mruby-socket"
conf.gem :core => "mruby-sprintf"
conf.gem :core => "mruby-string-ext"
conf.gem :core => "mruby-struct"
conf.gem :core => "mruby-symbol-ext"
# conf.gem :core => "mruby-test"
# conf.gem :core => "mruby-time"
conf.gem :core => "mruby-toplevel-ext"
end
+73
View File
@@ -0,0 +1,73 @@
# Cross Compiling configuration for the Nintendo GameBoyAdvance.
# This configuration requires devkitARM
# https://devkitpro.org/wiki/Getting_Started/devkitARM
#
# Tested only on GNU/Linux
#
MRuby::CrossBuild.new("gameboyadvance") do |conf|
toolchain :gcc
DEVKITPRO_PATH = "/opt/devkitpro"
BIN_PATH = "#{DEVKITPRO_PATH}/devkitARM/bin"
# C compiler
conf.cc do |cc|
cc.command = "#{BIN_PATH}/arm-none-eabi-gcc"
cc.flags << ["-mthumb-interwork", "-mthumb", "-O2"]
cc.compile_options = %(%{flags} -o "%{outfile}" -c "%{infile}")
end
# C++ compiler
conf.cxx do |cxx|
cxx.command = "#{BIN_PATH}/arm-none-eabi-g++"
cxx.include_paths = conf.cc.include_paths.dup
cxx.flags = conf.cc.flags.dup
cxx.flags << %w[-fno-rtti -fno-exceptions]
cxx.defines = conf.cc.defines.dup
cxx.compile_options = conf.cc.compile_options.dup
end
# Linker
conf.linker do |linker|
linker.command = "#{BIN_PATH}/arm-none-eabi-gcc"
linker.flags << ["-mthumb-interwork", "-mthumb", "-specs=gba.specs"]
end
# No executables
conf.bins = []
# Do not build executable test
conf.build_mrbtest_lib_only
# Disable C++ exception
conf.disable_cxx_exception
# Gems from core
# removing mruby-io
conf.gem core: "mruby-metaprog"
conf.gem core: "mruby-pack"
conf.gem core: "mruby-sprintf"
conf.gem core: "mruby-print"
conf.gem core: "mruby-math"
conf.gem core: "mruby-time"
conf.gem core: "mruby-struct"
conf.gem core: "mruby-compar-ext"
conf.gem core: "mruby-enum-ext"
conf.gem core: "mruby-string-ext"
conf.gem core: "mruby-numeric-ext"
conf.gem core: "mruby-array-ext"
conf.gem core: "mruby-hash-ext"
conf.gem core: "mruby-range-ext"
conf.gem core: "mruby-proc-ext"
conf.gem core: "mruby-symbol-ext"
conf.gem core: "mruby-random"
conf.gem core: "mruby-object-ext"
conf.gem core: "mruby-objectspace"
conf.gem core: "mruby-fiber"
conf.gem core: "mruby-enumerator"
conf.gem core: "mruby-enum-lazy"
conf.gem core: "mruby-toplevel-ext"
conf.gem core: "mruby-kernel-ext"
conf.gem core: "mruby-class-ext"
conf.gem core: "mruby-compiler"
end
+71
View File
@@ -0,0 +1,71 @@
#!/usr/bin/env ruby
# Wrapper for running tests for cross-compiled Windows builds in Wine.
require 'open3'
DOSROOT = 'z:'
# Rewrite test output to replace DOS-isms with Unix-isms.
def clean(output, stderr = false)
ends_with_newline = !!(output =~ /\n$/)
executable = ARGV[0].gsub(/\.exe\z/i, '')
# Fix line-ends
output = output.gsub(/\r\n/, "\n")
# Strip out Wine messages
results = output.split(/\n/).map do |line|
# Fix file paths
if line =~ /#{DOSROOT}\\/i
line.gsub!(/#{DOSROOT}([^:]*)/i) { |path|
path.gsub!(/^#{DOSROOT}/i, '')
path.gsub!(%r{\\}, '/')
path
}
end
# strip '.exe' off the end of the executable's name if needed
line.gsub!(/(#{Regexp.escape executable})\.exe/i, '\1')
line
end
result_text = results.join("\n")
result_text += "\n" if ends_with_newline
return result_text
end
def main
if ARGV.empty? || ARGV[0] =~ /^- (-?) (\?|help|h) $/x
puts "#{$0} <command-line>"
exit 0
end
# For simplicity, just read all of stdin into memory and pass that
# as an argument when invoking wine. (Skipped if STDIN was not
# redirected.)
if !STDIN.tty?
input = STDIN.read
else
input = ""
end
# Disable all Wine messages so they don't interfere with the output
ENV['WINEDEBUG'] = 'err-all,warn-all,fixme-all,trace-all'
# Run the program in wine and capture the output
output, errormsg, status = Open3.capture3('wine', *ARGV, :stdin_data => input)
# Clean and print the results.
STDOUT.write clean(output)
STDERR.write clean(errormsg)
exit(status.exitstatus)
end
main()
+12
View File
@@ -0,0 +1,12 @@
MRuby::Build.new do |conf|
conf.toolchain
# include the default GEMs
conf.gembox 'default'
# C compiler settings
conf.cc.defines = %w(MRB_USE_DEBUG_HOOK)
conf.enable_debug
conf.enable_cxx_abi
conf.enable_test
end
+20
View File
@@ -0,0 +1,20 @@
MRuby::Build.new('host') do |conf|
# load specific toolchain settings
conf.toolchain
conf.enable_debug
# include the default GEMs
conf.gembox 'full-core'
# C compiler settings
conf.cc.defines = %w(MRB_USE_DEBUG_HOOK MRB_NO_BOXING)
# Generate mruby debugger command (require mruby-eval)
conf.gem :core => "mruby-bin-debugger"
# test
conf.enable_test
# bintest
conf.enable_bintest
end
+14
View File
@@ -0,0 +1,14 @@
MRuby::Build.new do |conf|
# load specific toolchain settings
toolchain :gcc
# include the GEM box
conf.gembox 'default'
conf.cc.defines << 'MRB_USE_FLOAT32'
# Turn on `enable_debug` for better debugging
conf.enable_debug
conf.enable_test
conf.enable_bintest
end
+14
View File
@@ -0,0 +1,14 @@
MRuby::Build.new do |conf|
# load specific toolchain settings
toolchain :gcc
# include the GEM box
conf.gembox 'default'
conf.cc.flags << '-pg'
conf.linker.flags << '-pg'
# Turn on `enable_debug` for better debugging
conf.enable_debug
conf.enable_test
end
+15
View File
@@ -0,0 +1,15 @@
MRuby::Build.new do |conf|
# load specific toolchain settings
toolchain :gcc
# include the GEM box
conf.gembox 'default'
conf.cc.flags << '-m32'
conf.linker.flags << '-m32'
# Turn on `enable_debug` for better debugging
conf.enable_debug
conf.enable_test
conf.enable_bintest
end
+22
View File
@@ -0,0 +1,22 @@
MRuby::Build.new do |conf|
# load specific toolchain settings
toolchain :gcc
# include the GEM box
conf.gembox "stdlib"
conf.gembox "stdlib-ext"
conf.gembox "stdlib-io"
conf.gembox "metaprog"
conf.gem :core => 'mruby-bin-mruby'
conf.gem :core => 'mruby-bin-mirb'
# Add configuration
conf.compilers.each do |c|
c.defines << "MRB_NO_FLOAT"
end
conf.enable_debug
conf.enable_test
conf.enable_bintest
end
+36
View File
@@ -0,0 +1,36 @@
MRuby::Build.new do |conf|
# load specific toolchain settings
# Gets set by the VS command prompts.
if ENV['VisualStudioVersion'] || ENV['VSINSTALLDIR']
toolchain :visualcpp
else
toolchain :gcc
end
# include the GEM box
conf.gembox 'default'
# C compiler settings
conf.cc do |cc|
cc.flags = '-fPIC'
end
conf.archiver do |archiver|
archiver.command = 'gcc'
archiver.archive_options = '-shared -o %{outfile} %{objs}'
end
# file extensions
conf.exts do |exts|
exts.library = '.so'
end
# file separator
# conf.file_separator = '/'
# Turn on `enable_debug` for better debugging
conf.enable_debug
conf.enable_bintest
conf.enable_test
end
+4
View File
@@ -0,0 +1,4 @@
MRuby::CrossBuild.new('minimal') do |conf|
conf.toolchain :gcc
conf.cc.defines << 'MRB_NO_STDIO'
end
+11
View File
@@ -0,0 +1,11 @@
MRuby::Build.new do |conf|
if ENV['VisualStudioVersion'] || ENV['VSINSTALLDIR']
conf.toolchain :visualcpp
else
conf.toolchain :gcc
end
conf.build_mrbc_exec
conf.disable_libmruby
conf.disable_presym
end
+73
View File
@@ -0,0 +1,73 @@
# Cross Compiling configuration for the Nintendo Switch, it requires Nintendo SDK
# Tested on windows
MRuby::CrossBuild.new('nintendo_switch_32bit') do |conf|
conf.toolchain :clang
NINTENDO_SDK_PATH = ENV['NINTENDO_SDK_ROOT']
include_paths = [
"#{NINTENDO_SDK_PATH}/Include",
"#{NINTENDO_SDK_PATH}/Common/Configs/Targets/NX-NXFP2-a32/Include"
]
conf.cc do |cc|
cc.command = "#{NINTENDO_SDK_PATH}/Compilers/NX/bin/nx-clang++"
cc.include_paths += include_paths
cc.flags += ['-fpic -fno-short-enums -ffunction-sections -fdata-sections -fno-common -fno-strict-aliasing -fomit-frame-pointer -fno-vectorize -funsigned-char -O2 -g -mno-implicit-float']
cc.defines += 'NN_SDK_BUILD_RELEASE'
end
conf.cxx do |cxx|
cxx.command = "#{NINTENDO_SDK_PATH}/Compilers/NX/bin/nx-clang++"
cxx.include_paths += include_paths
cxx.flags += ['-fpic -fno-short-enums -ffunction-sections -fdata-sections -fno-common -fno-strict-aliasing -fomit-frame-pointer -fno-vectorize -funsigned-char -O2 -g -mno-implicit-float']
cxx.defines += 'NN_SDK_BUILD_RELEASE'
end
conf.archiver do |archiver|
archiver.command = "#{NINTENDO_SDK_PATH}/Compilers/NX/nx/armv7l/bin/llvm-ar"
end
conf.linker do |linker|
linker.command = "#{NINTENDO_SDK_PATH}/Compilers/NX/nx/armv7l/bin/clang++"
linker.libraries = []
end
# Add your mrbgems
end
MRuby::CrossBuild.new('nintendo_switch_64bit') do |conf|
conf.toolchain :clang
NINTENDO_SDK_PATH = ENV['NINTENDO_SDK_ROOT']
include_paths = [
"#{NINTENDO_SDK_PATH}/Include",
"#{NINTENDO_SDK_PATH}/Common/Configs/Targets/NX-NXFP2-a64/Include"
]
conf.cc do |cc|
cc.command = "#{NINTENDO_SDK_PATH}/Compilers/NX/bin/nx-clang++"
cc.include_paths += include_paths
cc.flags += ['-fpic -fno-short-enums -ffunction-sections -fdata-sections -fno-common -fno-strict-aliasing -fomit-frame-pointer -fno-vectorize -funsigned-char -O2 -g -mno-implicit-float']
cc.flags << '--target=aarch64-nintendo-nx-elf'
cc.defines += 'NN_SDK_BUILD_RELEASE'
end
conf.cxx do |cxx|
cxx.command = "#{NINTENDO_SDK_PATH}/Compilers/NX/bin/nx-clang++"
cxx.include_paths += include_paths
cxx.flags += ['-fpic -fno-short-enums -ffunction-sections -fdata-sections -fno-common -fno-strict-aliasing -fomit-frame-pointer -fno-vectorize -funsigned-char -O2 -g -mno-implicit-float']
cxx.flags << '--target=aarch64-nintendo-nx-elf'
cxx.defines += 'NN_SDK_BUILD_RELEASE'
end
conf.archiver do |archiver|
archiver.command = "#{NINTENDO_SDK_PATH}/Compilers/NX/nx/aarch64/bin/llvm-ar"
end
conf.linker do |linker|
linker.command = "#{NINTENDO_SDK_PATH}/Compilers/NX/nx/aarch64/bin/clang++"
linker.libraries = []
end
# Add your mrbgems
end
+26
View File
@@ -0,0 +1,26 @@
# Cross compiling configuration for SerenityOS
# Graphical Unix-like operating system for x86 computers.
# https://github.com/SerenityOS/serenity
#
# Should be built using the SerenityOS Ports system
# https://github.com/SerenityOS/serenity/tree/master/Ports
#
# As of 2021/08/20, SERENITY_ARCH is defined in the SerenityOS Ports
# build script to always be either "i686" or "x86_64"
MRuby::CrossBuild.new('serenity') do |conf|
conf.toolchain :gcc
conf.archiver.command = "#{ENV['SERENITY_ARCH']}-pc-serenity-ar"
conf.linker.command = "#{ENV['SERENITY_ARCH']}-pc-serenity-g++"
conf.cxx.command = "#{ENV['SERENITY_ARCH']}-pc-serenity-g++"
conf.cxx.defines << (ENV['SERENITY_ARCH'].include?('64') ? 'MRB_64BIT' : 'MRB_32BIT')
conf.cc.command = "#{ENV['SERENITY_ARCH']}-pc-serenity-gcc"
conf.cc.defines << (ENV['SERENITY_ARCH'].include?('64') ? 'MRB_64BIT' : 'MRB_32BIT')
conf.gembox 'full-core'
conf.test_runner.command = 'env'
end
+17
View File
@@ -0,0 +1,17 @@
ans
ba
creat
delet
disabl
filetest
fo
hel
hist
ist
methid
nd
quitt
remore
runn
sting
upto
+256 -186
View File
@@ -6,41 +6,54 @@ binaries.
## Prerequisites
To compile mruby out of the source code you need the following tools:
* C Compiler (i.e. ```gcc```)
* Linker (i.e. ```gcc```)
* Archive utility (i.e. ```ar```)
* Parser generator (i.e. ```bison```)
* Ruby 1.8 or 1.9 (i.e. ```ruby``` or ```jruby```)
* C Compiler (e.g. `gcc` or `clang`)
* Linker (e.g. `gcc` or `clang`)
* Archive utility (e.g. `ar`)
* Ruby 2.5 or later (e.g. `ruby` or `jruby`)
Optional:
* GIT (to update mruby source and integrate mrbgems easier)
* C++ compiler (to use GEMs which include \*.cpp, \*.cxx, \*.cc)
* Assembler (to use GEMs which include \*.asm)
## Usage
* Git (to update mruby source and integrate mrbgems easier)
* C++ compiler (to use mrbgems which include `*.cpp`, `*.cxx`, `*.cc`)
* Bison (to compile `mrbgems/mruby-compiler/core/parse.y`)
* gperf (to compile `mrbgems/mruby-compiler/core/keywords`)
Note that `bison` bundled with macOS is too old to compile `mruby`.
Try `brew install bison` and follow the instruction shown to update
the `$PATH` to compile `mruby`. We also encourage you to upgrade `ruby`
on macOS in similar manner.
## Build
To compile `mruby` with the default build configuration, just invoke `rake`
inside of the mruby source root. To generate and execute the test tools call
`rake test`. To clean all build files call `rake clean`. To see full command
line on build, call `rake -v`.
You can specify your own configuration file by the `MRUBY_CONFIG` environment
variable (you can use `CONFIG` for shorthand for `MRUBY_CONFIG`). If the path
doesn't exist, `build_config/${MRUBY_CONFIG}.rb` is used. The default
configuration is defined in the `build_config/default.rb` file.
Those build configuration files contain the build configuration of mruby, for
example:
Inside of the root directory of the mruby source a file exists
called *build_config.rb*. This file contains the build configuration
of mruby and looks like this for example:
```ruby
MRuby::Build.new do |conf|
toolchain :gcc
conf.toolchain :gcc
end
```
All tools necessary to compile mruby can be set or modified here. In case
you want to maintain an additional *build_config.rb* you can define a
customized path using the *$MRUBY_CONFIG* environment variable.
To compile just call ```./minirake``` inside of the mruby source root. To
generate and execute the test tools call ```./minirake test```. To clean
all build files call ```./minirake clean```. To see full command line on
build, call ```./minirake -v```.
All tools necessary to compile mruby can be set or modified here.
## Build Configuration
Inside of the *build_config.rb* the following options can be configured
based on your environment.
We wish you submit a pull-request to `build_config/PLATFORM.rb`, once you
created a new configuration for a new platform.
Inside the configuration file, the following options can be
configured based on your environment.
### Toolchains
@@ -50,54 +63,56 @@ configure the build environment for specific compiler infrastructures.
#### GCC
Toolchain configuration for the GNU C Compiler.
```ruby
toolchain :gcc
conf.toolchain :gcc
```
#### clang
Toolchain configuration for the LLVM C Compiler clang. Mainly equal to the
GCC toolchain.
```ruby
toolchain :clang
conf.toolchain :clang
```
#### Visual Studio 2010, 2012 and 2013
Toolchain configuration for Visual Studio on Windows. If you use the
[Visual Studio Command Prompt](http://msdn.microsoft.com/en-us/library/ms229859\(v=vs.110\).aspx),
[Visual Studio Command Prompt](https://msdn.microsoft.com/en-us/library/ms229859\(v=vs.110\).aspx),
you normally do not have to specify this manually, since it gets automatically detected by our build process.
```ruby
toolchain :visualcpp
conf.toolchain :visualcpp
```
#### Android
Toolchain configuration for Android.
```ruby
toolchain :android
conf.toolchain :android
```
Requires the custom standalone Android NDK and the toolchain path
in ```ANDROID_STANDALONE_TOOLCHAIN```.
in `ANDROID_STANDALONE_TOOLCHAIN`.
### Binaries
It is possible to select which tools should be compiled during the compilation
process. The following tools can be selected:
* mruby (mruby interpreter)
* mirb (mruby interactive shell)
process. For example,
To select them declare conf.gem as follows:
```ruby
conf.gem "#{root}/mrbgems/mruby-bin-mruby"
conf.gem "#{root}/mrbgems/mruby-bin-mirb"
```
* `mruby`
* `mirb`
The configuration are done via `mrbgems`. See `Mrbgems` section.
### File Separator
Some environments require a different file separator character. It is possible to
set the character via ```conf.file_separator```.
set the character via `conf.file_separator`.
```ruby
conf.file_separator = '/'
```
@@ -105,6 +120,7 @@ conf.file_separator = '/'
### C Compiler
Configuration of the C compiler binary, flags and include paths.
```ruby
conf.cc do |cc|
cc.command = ...
@@ -119,28 +135,31 @@ end
C Compiler has header searcher to detect installed library.
If you need a include path of header file use ```search_header_path```:
If you need an include path of header file use `search_header_path`:
```ruby
# Searches ```iconv.h```.
# Searches `iconv.h`.
# If found it will return include path of the header file.
# Otherwise it will return nil .
# Otherwise it will return nil.
fail 'iconv.h not found' unless conf.cc.search_header_path 'iconv.h'
```
If you need a full file name of header file use ```search_header```:
If you need a full file name of header file use `search_header`:
```ruby
# Searches ```iconv.h```.
# Searches `iconv.h`.
# If found it will return full path of the header file.
# Otherwise it will return nil .
# Otherwise it will return nil.
iconv_h = conf.cc.search_header 'iconv.h'
print "iconv.h found: #{iconv_h}\n"
```
Header searcher uses compiler's ```include_paths``` by default.
Header searcher uses compiler's `include_paths` by default.
When you are using GCC toolchain (including clang toolchain since its base is gcc toolchain)
it will use compiler specific include paths too. (For example ```/usr/local/include```, ```/usr/include```)
it will use compiler specific include paths too. (For example `/usr/local/include`, `/usr/include`)
If you need a special header search paths define a singleton method `header_search_paths` to C compiler:
If you need a special header search paths define a singleton method ```header_search_paths``` to C compiler:
```ruby
def conf.cc.header_search_paths
['/opt/local/include'] + include_paths
@@ -150,6 +169,7 @@ end
### Linker
Configuration of the Linker binary, flags and library paths.
```ruby
conf.linker do |linker|
linker.command = ...
@@ -167,6 +187,7 @@ end
### Archiver
Configuration of the Archiver binary and flags.
```ruby
conf.archiver do |archiver|
archiver.command = ...
@@ -177,6 +198,7 @@ end
### Parser Generator
Configuration of the Parser Generator binary and flags.
```ruby
conf.yacc do |yacc|
yacc.command = ...
@@ -187,6 +209,7 @@ end
### GPerf
Configuration of the GPerf binary and flags.
```ruby
conf.gperf do |gperf|
gperf.command = ...
@@ -195,6 +218,7 @@ end
```
### File Extensions
```ruby
conf.exts do |exts|
exts.object = ...
@@ -203,26 +227,52 @@ conf.exts do |exts|
end
```
### Preallocated Symbols
By far, preallocated symbols are highly compatible with the previous versions, so
we expect you won't see any problem with them. But just in case you face any
issue, you can disable preallocated symbols by specifying `conf.disable_presym`.
In the build process, `mrbc` under cross compiling environment will be compiled
with this configuration.
### Mrbgems
Integrate GEMs in the build process.
```ruby
# Integrate GEM with additional configuration
conf.gem 'path/to/gem' do |g|
g.cc.flags << ...
end
`mruby` comes with the (sort of) packaging system named `mrbgems`. To
specify `gem`, you can use `conf.gem` in the configuration file.
# Integrate GEM without additional configuration
conf.gem 'path/to/another/gem'
```ruby
# Integrate a bundled Gem you see in `mrbgems` directory
conf.gem :core => 'mruby-something'
# Integrate a Gem from GitHub
conf.gem :github => 'someone/mruby-another'
# Integrate a mruby binary Gem
conf.gem :core => 'mruby-bin-mruby'
# Integrate a interactive mruby binary Gem
conf.gem :core => 'mruby-bin-mirb'
# Integrate GemBox (set of Gems)
conf.gembox "default"
```
A GemBox is a set of Gems defined in `mrbgems/default.gembox` for example.
It's just a set of `mrbgem` configurations.
There is a `RubyGem` (gem for CRuby) named `mgem` that help you to
manage `mrbgems`. Try `gem install mgem`. `mgem` can show you the list
of registered `mrbgems`.
See doc/mrbgems/README.md for more option about mrbgems.
### Mrbtest
Configuration Mrbtest build process.
If you want mrbtest.a only, You should set ```conf.build_mrbtest_lib_only```
If you want `mrbtest.a` only, You should set `conf.build_mrbtest_lib_only`
```ruby
conf.build_mrbtest_lib_only
```
@@ -230,11 +280,12 @@ conf.build_mrbtest_lib_only
### Bintest
Tests for mrbgem tools using CRuby.
To have bintests place \*.rb scripts to ```bintest/``` directory of mrbgems.
See ```mruby-bin-*/bintest/*.rb``` if you need examples.
If you want a temporary files use `tempfile` module of CRuby instead of ```/tmp/```.
To have bintests place `*.rb` scripts to `bintest/` directory of mrbgems.
See `mruby-bin-*/bintest/*.rb` if you need examples.
If you want a temporary files use `tempfile` module of CRuby instead of `/tmp/`.
You can enable it with following:
```ruby
conf.enable_bintest
```
@@ -247,64 +298,71 @@ correctly. To support mrbgems written in C++, mruby can be
configured to use C++ exception.
There are two levels of C++ exception handling. The one is
```enable_cxx_exception``` that enables C++ exception, but
uses C ABI. The other is ```enable_cxx_abi``` where all
`enable_cxx_exception` that enables C++ exception, but
uses C ABI. The other is `enable_cxx_abi` where all
files are compiled by C++ compiler.
When you mix C++ code, C++ exception would be enabled automatically.
If you need to enable C++ exception explicitly add the following:
```ruby
conf.enable_cxx_exception
```
#### C++ exception disabling.
#### C++ exception disabling
If your compiler does not support C++ and you want to ensure
If your compiler does not support C++, and you want to ensure
you don't use mrbgem written in C++, you can explicitly disable
C++ exception, add following:
```ruby
conf.disable_cxx_exception
```
and you will get an error when you try to use C++ gem.
Note that it must be called before ```enable_cxx_exception``` or ```gem``` method.
Note that it must be called before `enable_cxx_exception` or `gem` method.
### Debugging mode
To enable debugging mode add the following:
```ruby
conf.enable_debug
```
When debugging mode is enabled
* Macro ```MRB_DEBUG``` would be defined.
* Which means ```mrb_assert()``` macro is enabled.
* Debug information of irep would be generated by ```mrbc```.
* Because ```-g``` flag would be added to ```mrbc``` runner.
* Macro `MRB_DEBUG` would be defined.
* Which means `mrb_assert()` macro is enabled.
* Debug information of irep would be generated by `mrbc`.
* Because `-g` flag would be added to `mrbc` runner.
* You can have better backtrace of mruby scripts with this.
## Cross-Compilation
mruby can also be cross-compiled from one platform to another. To
achieve this the *build_config.rb* needs to contain an instance of
```MRuby::CrossBuild```. This instance defines the compilation
tools and flags for the target platform. An example could look
like this:
mruby can also be cross-compiled from one platform to another. To achieve
cross-compilation, the build configuration needs to contain an instance of
`MRuby::CrossBuild`. This instance defines the compilation tools and flags
for the target platform. An example could look like this:
```ruby
MRuby::CrossBuild.new('32bit') do |conf|
toolchain :gcc
conf.toolchain :gcc
conf.cc.flags << "-m32"
conf.linker.flags << "-m32"
end
```
All configuration options of ```MRuby::Build``` can also be used
in ```MRuby::CrossBuild```.
All configuration options of `MRuby::Build` can also be used in
`MRuby::CrossBuild`. You can find examples under the `build_config`
directory.
### Mrbtest in Cross-Compilation
In cross compilation, you can run ```mrbtest``` on emulator if
In cross compilation, you can run `mrbtest` on an emulator if
you have it by changing configuration of test runner.
```ruby
conf.test_runner do |t|
t.command = ... # set emulator. this value must be non nil or false
@@ -318,48 +376,44 @@ end
## Build process
During the build process the directory *build* will be created in the
During the build process the directory `build` will be created in the
root directory. The structure of this directory will look like this:
+- build
|
+- host
|
+- bin <- Binaries (mirb, mrbc and mruby)
|
+- lib <- Libraries (libmruby.a and libmruby_core.a)
|
+- mrblib
|
+- src
|
+- test <- mrbtest tool
|
+- tools
|
+- mirb
|
+- mrbc
|
+- mruby
```
+- build
|
+- host
|
+- LEGAL <- License description
|
+- bin <- Binaries (mirb, mrbc and mruby)
|
+- lib <- Libraries (libmruby.a and libmruby_core.a)
|
+- mrbc <- Minimal mrbc place
|
+- mrbgems <- Compilation result from mrbgems
|
+- mrblib <- Compilation result from mrblib
|
+- src <- Compilation result from C sources
```
The compilation workflow will look like this:
* compile all files under *src* (object files will be stored
in *build/host/src*)
* generate parser grammar out of *src/parse.y* (generated
result will be stored in *build/host/src/y.tab.c*)
* compile *build/host/src/y.tab.c* to *build/host/src/y.tab.o*
* create *build/host/lib/libmruby_core.a* out of all object files (C only)
* create ```build/host/bin/mrbc``` by compiling *tools/mrbc/mrbc.c* and
linking with *build/host/lib/libmruby_core.a*
* create *build/host/mrblib/mrblib.c* by compiling all \*.rb files
under *mrblib* with ```build/host/bin/mrbc```
* compile *build/host/mrblib/mrblib.c* to *build/host/mrblib/mrblib.o*
* create *build/host/lib/libmruby.a* out of all object files (C and Ruby)
* create ```build/host/bin/mruby``` by compiling *mrbgems/mruby-bin-mruby/tools/mruby/mruby.c* and
linking with *build/host/lib/libmruby.a*
* create ```build/host/bin/mirb``` by compiling *mrbgems/mruby-bin-mirb/tools/mirb/mirb.c* and
linking with *build/host/lib/libmruby.a*
* compile minimal `mrbc` from `src` and `mrblib` sources
* compile all files under `src` (object files will be stored in `build/host/mrbc/src`)
* compile `mruby-compiler` gem
* create `build/host/mrbc/lib/libmruby_core.a` out of all object files (C only)
* create `build/host/mrbc/bin/mrbc` via `mruby-bin-mrbc` gem
* compile all files under `src` and store result in `build/host/src`
* create `build/host/mrblib/mrblib.c` by compiling all `*.rb` files under `mrblib` with `build/host/mrbc/bin/mrbc`
* compile `build/host/mrblib/mrblib.c` to `build/host/mrblib/mrblib.o`
* create `build/host/lib/libmruby.a` out of all object files (C and Ruby)
* compile (normal) mrbgems specified in the configuration file
* create `build/host/lib/libmruby.a` from object files from gems and `libmruby_core.a`
* create binary commands according to binary gems (e.g. `mirb` and `mruby`)
* copy binaries under `build/host/bin` to `bin` directory
```
_____ _____ ______ ____ ____ _____ _____ ____
@@ -370,73 +424,54 @@ linking with *build/host/lib/libmruby.a*
### Cross-Compilation
In case of a cross-compilation to *i386* the *build* directory structure looks
In case of a cross-compilation to `i386` the `build` directory structure looks
like this:
+- build
|
+- host
| |
| +- bin <- Native Binaries
| |
| +- lib <- Native Libraries
| |
| +- mrblib
| |
| +- src
| |
| +- test <- Native mrbtest tool
| |
| +- tools
| |
| +- mirb
| |
| +- mrbc
| |
| +- mruby
+- i386
|
+- bin <- Cross-compiled Binaries
|
+- lib <- Cross-compiled Libraries
|
+- mrblib
|
+- src
|
+- test <- Cross-compiled mrbtest tool
|
+- tools
|
+- mirb
|
+- mrbc
|
+- mruby
```
+- build
|
+- host
| |
| +- bin <- Native Binaries
| |
| +- lib <- Native Libraries
| |
| +- mrbgems
| |
| +- src
|
+- i386
|
+- bin <- Cross-compiled Binaries
|
+- include <- Header Directory
|
+- lib <- Cross-compiled Libraries
|
+- mrbgems
|
+- mrblib
|
+- src
```
An extra directory is created for the target platform. In case you
compile for *i386* a directory called *i386* is created under the
compile for `i386` a directory called `i386` is created under the
build directory.
The cross compilation workflow starts in the same way as the normal
compilation by compiling all *native* libraries and binaries.
Afterwards the cross compilation process proceeds like this:
* cross-compile all files under *src* (object files will be stored
in *build/i386/src*)
* generate parser grammar out of *src/parse.y* (generated
result will be stored in *build/i386/src/y.tab.c*)
* cross-compile *build/i386/src/y.tab.c* to *build/i386/src/y.tab.o*
* create *build/i386/mrblib/mrblib.c* by compiling all \*.rb files
under *mrblib* with the native ```build/host/bin/mrbc```
* cross-compile *build/host/mrblib/mrblib.c* to *build/host/mrblib/mrblib.o*
* create *build/i386/lib/libmruby.a* out of all object files (C and Ruby)
* create ```build/i386/bin/mruby``` by cross-compiling *mrbgems/mruby-bin-mruby/tools/mruby/mruby.c* and
linking with *build/i386/lib/libmruby.a*
* create ```build/i386/bin/mirb``` by cross-compiling *mrbgems/mruby-bin-mirb/tools/mirb/mirb.c* and
linking with *build/i386/lib/libmruby.a*
* create *build/i386/lib/libmruby_core.a* out of all object files (C only)
* create ```build/i386/bin/mrbc``` by cross-compiling *tools/mrbc/mrbc.c* and
linking with *build/i386/lib/libmruby_core.a*
compilation by compiling all *native* libraries and binaries, except
for we don't have `host/mrbc` directory (`host` directory itself works
as placeholder for `mrbc`). Afterwards the cross compilation process
proceeds like this:
* cross-compile all files under `src` and store result in `build/i386/src`
* create `build/i386/lib/libmruby_core.a` out of C object files
* create `build/i386/mrblib/mrblib.c` by compiling all `*.rb` files under `mrblib` with native `build/host/bin/mrbc`
* cross-compile `build/i386/mrblib/mrblib.c` to `build/i386/mrblib/mrblib.o`
* create `build/i386/lib/libmruby.a` from object files from gems and `libmruby_core.a`
* create binary commands according to binary gems (e.g. `mirb` and `mruby`)
* copy binaries under `build/host/bin` to `bin` directory
```
_______________________________________________________________
@@ -463,26 +498,61 @@ linking with *build/i386/lib/libmruby_core.a*
### Minimal Library
To build a minimal mruby library you need to use the Cross Compiling
feature due to the reason that there are functions (i.e. stdio) which
feature due to the reason that there are functions (e.g. stdio) which
can't be disabled for the main build.
```ruby
MRuby::CrossBuild.new('Minimal') do |conf|
toolchain :gcc
conf.cc.defines = %w(MRB_DISABLE_STDIO)
conf.bins = []
MRuby::CrossBuild.new('minimal') do |conf|
conf.toolchain :gcc
conf.cc.defines << 'MRB_NO_STDIO'
end
```
This configuration defines a cross compile build called 'Minimal' which
This configuration defines a cross compile build called 'minimal' which
is using the GCC and compiles for the host machine. It also disables
all usages of stdio and doesn't compile any binaries (i.e. mrbc).
all usages of stdio and doesn't compile any binaries (e.g. `mrbc`).
## Test Environment
mruby's build process includes a test environment. In case you start the testing
of mruby, a native binary called ```mrbtest``` will be generated and executed.
This binary contains all test cases which are defined under *test/t*. In case
of a cross-compilation an additional cross-compiled *mrbtest* binary is
of mruby, a native binary called `mrbtest` will be generated and executed.
This binary contains all test cases which are defined under `test/t`. In case
of a cross-compilation an additional cross-compiled `mrbtest` binary is
generated. You can copy this binary and run on your target system.
## Embedding `mruby` in Your Application
After the build, you will get `libmruby.a`. You can link it to your application.
For compiler options and library path, you can use `mruby-config` command for
convenience. `mruby-config` command prints the configuration used for `libmruby.a`.
```
$ mruby-config --help
Usage: mruby-config [switches]
switches:
--cc print compiler name
--cflags print flags passed to compiler
--ld print linker name
--ldflags print flags passed to linker
--ldflags-before-libs print flags passed to linker before linked libraries
--libs print linked libraries
--libmruby-path print libmruby path
--help print this help
```
For example, when you have a C source file (`c.c`) and try to
compile and link it with `libmruby.a`, you can run the following command,
```
gcc `mruby-config --cflags` c.c `mruby-config --ldflags` `mruby-config --libs`
```
When you use `make`, add following lines in `Makefile`
```
MRB_CONFIG = <path-to-mruby-config>
CFLAGS = `$(MRB_CONFIG) --cflags`
LDFLAGS = `$(MRB_CONFIG) --ldflags`
LIBS = `$(MRB_CONFIG) --libs`
```
+11 -10
View File
@@ -38,7 +38,7 @@ To confirm mrdb was installed properly, run mrdb with the `--version` option:
```bash
$ mrdb --version
mruby 2.0.0 (2018-12-11)
mruby 3.0.0 (2021-03-05)
```
## 2.2 Basic Operation
@@ -114,8 +114,8 @@ b [class:]method
The breakpoint will be ordered in serial from 1.
The number, which was given to the deleted breakpoint, will never be given to another breakpoint again.
You can give multiple breakpoints to specified the line number and method.
Be ware that breakpoint command will not check the validity of the class name and method name.
You can give multiple breakpoints to the specified the line number and method.
Be aware that the breakpoint command will not check the validity of the class name and method name.
You can get the current breakpoint information by the following options.
@@ -165,7 +165,7 @@ Example:
(foo.rb:1) delete
```
This will delete all of the breakpoints.
This will delete all the breakpoints.
```
(foo.rb:1) delete 1 3
@@ -192,7 +192,7 @@ Example:
(foo.rb:1) disable
```
Use `disable` if you would like to disable all of the breakpoints.
Use `disable` if you would like to disable all the breakpoints.
```
(foo.rb:1) disable 1 3
@@ -220,6 +220,7 @@ Example:
```
Enabling all breakpoints
```
(foo.rb:1) enable 1 3
```
@@ -263,7 +264,7 @@ Example:
```
(sample.rb:1) info breakpoints
Num Type Enb What
Num Type Enb What
1 breakpoint y at sample.rb:3 -> file name,line number
2 breakpoint n in Sample_class:sample_class_method -> [class:]method name
3 breakpoint y in sample_global_method
@@ -273,8 +274,8 @@ Displaying the specified breakpoint number:
```
(foo.rb:1) info breakpoints 1 3
Num Type Enb What
1 breakpoint y at sample.rb:3
Num Type Enb What
1 breakpoint y at sample.rb:3
3 breakpoint y in sample_global_method
```
@@ -323,7 +324,7 @@ expr: expression
The expression is mandatory.
The displayed expressions will be serially ordered from 1.
If an exception occurs, the exception information will be displayed and the debugging will be continued.
If an exception occurs, the exception information will be displayed, and the debugging will be continued.
Example:
@@ -366,5 +367,5 @@ r
#### Step Command
This will run the program step by step.
When the method and the block are invoked, the program will be stop at the first row.
When the method and the block are invoked, the program will stop at the first row.
The program, which is developed in C, will be ignored.
+7 -7
View File
@@ -3,7 +3,7 @@
_This is an English translation of [Matz's blog post][matz blog post]
written in Japanese._
_Some parts are updated to reflect recent changes._
[matz blog post]: http://www.rubyist.net/~matz/20130731.html
[matz blog post]: <https://www.rubyist.net/~matz/20130731.html>
When you are extending mruby using C language, you may encounter
mysterious "arena overflow error" or memory leak or very slow
@@ -11,13 +11,13 @@ execution speed. This is an error indicating overflow of "GC arena"
implementing "conservative GC".
GC (garbage collector) must ensure that object is "alive", in other
words, that it is referenced by somewhere from program. This can be
words, that it is referenced by somewhere from the program. This can be
determined by checking if the object can be directly or indirectly
referenced by root. The local variables, global variables and
constants etc are root.
If program execution is performed inside mruby VM, there is nothing to
worry about because GC can access all roots owned by VM.
worry about because GC can access all roots owned by the VM.
The problem arises when executing C functions. The object referenced
by C variable is also "alive", but mruby GC cannot aware of this, so
@@ -38,7 +38,7 @@ The biggest problem is we have no way to access to the stack area in
portable way. Therefore, we cannot use this method if we'd like to
implement highly portable runtime, like mruby.
So we came up with an another plan to implement "conservative GC" in mruby.
So we came up with another plan to implement "conservative GC" in mruby.
Again, the problem is when an object which was created in C function, becomes
no longer referenced in the Ruby world, and cannot be treated as garbage.
@@ -46,7 +46,7 @@ no longer referenced in the Ruby world, and cannot be treated as garbage.
In mruby, we recognize all objects created in C function are alive.
Then we have no problem such as confusing a live object as dead.
This means that because we cannot collect truly dead object, we may
This means that because we cannot collect a truly dead object, we may
lose efficiency, but as a trade-off the GC itself is highly portable.
We can say goodbye to the problem that GC deletes live objects due to
optimization which sometimes occurs in CRuby.
@@ -140,7 +140,7 @@ inspect_ary(mrb_state *mrb, mrb_value ary, mrb_value list)
}
```
This is a real example, so a little bit complicated, but bear with me.
This is a real example, so slightly complicated, but bear with me.
The essence of `Array#inspect` is that after stringifying each element
of array using `inspect` method, we join them together so that we can
get `inspect` representation of the entire array.
@@ -161,7 +161,7 @@ Please note that the final `inspect` representation of entire array
was created before the call of `mrb_gc_arena_restore()`. Otherwise,
required temporal object may be deleted by GC.
We may have a usecase where after creating many temporal objects, we'd
We may have an usecase where after creating many temporal objects, we'd
like to keep some of them. In this case, we cannot use the same idea
in `ary_inspect()` like appending objects to existing one.
Instead, after `mrb_gc_arena_restore()`, we must re-register the objects we
+83
View File
@@ -0,0 +1,83 @@
# Linking `libmruby` to your application
You have two ways to link `libmruby` to your application.
* using executable gem.
* using normal compilation process
## Executable Gems
If your application is relatively small, `mrbgem` is an easier way to
create the executable. By tradition, the gem name start with
`mruby-bin-`, e.g. `mruby-bin-debugger`.
### `mrbgem.rake` file
The executable name is specified in `mrbgem.rake` file at the top of
your `mrbgem` directory.
```ruby
MRuby::Gem::Specification.new('mruby-bin-example') do |spec|
spec.license = 'MIT'
spec.author = 'mruby developers'
spec.summary = 'Example for executable command gem'
spec.bins = %w(mruby-example) # <- this is binary name
end
```
### Source tree structure
The source file for the gem executable should be in
`<gem-name>/tools/<bin-name>`. Currently, we support C or C++ source code
(`.c`, `.cpp`, `.cxx`, `.cc`) for the executable. Ruby source files are not
supported. Put the functionality in the different gem and specify dependency to
it in `mrbgem.rake`.
## Normal compilation process
The `libmruby` is a normal library so that you can just link it to your
application. Specify proper compiler options (`-I` etc.) and linker options
(`-Lmruby` etc.) to compile and link your application. Specify those options in
your build script (e.g. `Makefile`).
### Compiler options
You need to specify compiler options that are compatible to mruby configuration,
for example:
* `-I` to specify the place for mruby header files
* `-D` to specify mruby configuration macros
To retrieve compiler options used to build `mruby`, you can use `mruby-config`
command with following options:
* `--cc` compiler name
* `--cflags` options passed to compiler
```
$ mruby-config --cflags
-std=gnu99 -g -O3 -Wall -DMRB_GC_FIXED_ARENA -I/home/matz/work/mruby/include -I/home/matz/work/mruby/build/host/include
```
### Linker options
Just like compiler options, you need to specify linker options that are
compatible to mruby configuration.
To retrieve linker options, you can use `mruby-config` with following options:
* `--ld` linker name
* `--ldflags` options passed to linker
* `--ldflags-before-libs` options passed to linker before linked libraries
* `--libs` linked libraries
```
$ mruby-config --ldflags
-L/home/matz/work/mruby/build/host/lib
$ mruby-config --ldflags-before-libs
# <nothing in this case>
$ mruby-config --libs
-lmruby -lm
```
+100 -37
View File
@@ -1,146 +1,209 @@
# mruby configuration macros.
# mruby configuration macros
## How to use these macros
## How to use these macros.
You can use mrbconfs with following ways:
* Write them in `mrbconf.h`.
* Using compiler flags is preferred when building a cross binaries or multiple mruby binaries
since it's easier to use different mrbconf per each `MRuby::Build`.
* Most flags can be enabled by just commenting in.
* Pass them as compiler flags.
* Make sure you pass the same flags to all compilers since some mrbconf(e.g., `MRB_GC_FIXED_ARENA`)
changes `struct` layout and cause memory access error when C and other language(e.g., C++) is mixed.
## stdio setting.
`MRB_DISABLE_STDIO`
* Write them in `mrbconf.h`.
* Using compiler flags is preferred when building a cross binaries or multiple mruby binaries
since it's easier to use different mrbconf per each `MRuby::Build`.
* Most flags can be enabled by just commenting in.
* Pass them as compiler flags.
* Make sure you pass the same flags to all compilers since some mrbconf(e.g., `MRB_GC_FIXED_ARENA`)
changes `struct` layout and cause memory access error when C and other language(e.g., C++) is mixed.
## stdio setting
`MRB_NO_STDIO`
* When defined `<stdio.h>` functions won't be used.
* Some features will be disabled when this is enabled:
* `mrb_irep` load/dump from/to file.
* Compiling mruby script from file.
* Compiling mruby script from a file.
* Printing features in **src/print.c**.
## Debug macros.
`MRB_ENABLE_DEBUG_HOOK`
## Debug macros
`MRB_USE_DEBUG_HOOK`
* When defined code fetch hook and debug OP hook will be enabled.
* When using any of the hook set function pointer `code_fetch_hook` and/or `debug_op_hook` of `mrb_state`.
* Fetch hook will be called before any OP.
* Debug OP hook will be called when dispatching `OP_DEBUG`.
`MRB_DEBUG`
* When defined `mrb_assert*` macro will be defined with macros from `<assert.h>`.
* Could be enabled via `enable_debug` method of `MRuby::Build`.
## Stack configuration
`MRB_STACK_EXTEND_DOUBLING`
* If defined doubles the stack size when extending it.
* Else extends stack with `MRB_STACK_GROWTH`.
`MRB_STACK_GROWTH`
* Default value is `128`.
* Used in stack extending.
* Ignored when `MRB_STACK_EXTEND_DOUBLING` is defined.
`MRB_STACK_MAX`
* Default value is `0x40000 - MRB_STACK_GROWTH`.
* Raises `RuntimeError` when stack size exceeds this value.
## Primitive type configuration.
## Primitive type configuration
`MRB_USE_FLOAT`
* When defined single precision floating point type(C type `float`) is used as `mrb_float`.
* Else double precision floating point type(C type `double`) is used as `mrb_float`.
`MRB_USE_FLOAT32`
`MRB_INT16`
* When defined `int16_t` will be defined as `mrb_int`.
* When defined single precision floating-point type(C type `float`) is used as `mrb_float`.
* Otherwise, double precision floating-point type(C type `double`) is used as `mrb_float`.
`MRB_NO_FLOAT`
* When defined removes floating-point numbers from mruby.
* It makes mruby easier to handle in "Microcontroller without FPU" and "Kernel Space".
`MRB_INT32`
* When defined, or `MRB_INT64` are not defined on 32-bit CPU mode, `mrb_int` will be defined as `int32_t`.
* Conflicts with `MRB_INT64`.
`MRB_INT64`
* When defined `int64_t` will be defined as `mrb_int`.
* Conflicts with `MRB_INT16`.
* When `MRB_INT16` or `MRB_INT64` isn't defined `int`(most of the times 32-bit integer)
will be defined as `mrb_int`.
## Garbage collector configuration.
* When defined, or `MRB_INT32` are not defined on 64-bit CPU mode, `mrb_int` will be defined as `int64_t`.
* Conflicts with `MRB_INT32`.
## Garbage collector configuration
`MRB_GC_STRESS`
* When defined full GC is emitted per each `RBasic` allocation.
* Mainly used in memory manager debugging.
`MRB_GC_TURN_OFF_GENERATIONAL`
* When defined turns generational GC by default.
`MRB_GC_FIXED_ARENA`
* When defined used fixed size GC arena.
* Raises `RuntimeError` when this is defined and GC arena size exceeds `MRB_GC_ARENA_SIZE`.
* Useful tracking unnecessary mruby object allocation.
`MRB_GC_ARENA_SIZE`
* Default value is `100`.
* Ignored when `MRB_GC_FIXED_ARENA` isn't defined.
* Defines fixed GC arena size.
`MRB_HEAP_PAGE_SIZE`
* Defines value is `1024`.
* Specifies number of `RBasic` per each heap page.
## Memory pool configuration.
## Memory pool configuration
`POOL_ALIGNMENT`
* Default value is `4`.
* If you're allocating data types that requires alignment more than default value define the
largest value of required alignment.
`POOL_PAGE_SIZE`
* Default value is `16000`.
* Specifies page size of pool page.
* Smaller the value is increases memory overhead.
## State atexit configuration.
## State atexit configuration
`MRB_FIXED_STATE_ATEXIT_STACK`
* If defined enables fixed size `mrb_state` atexit stack.
* Raises `RuntimeError` when `mrb_state_atexit` call count to same `mrb_state` exceeds
`MRB_FIXED_STATE_ATEXIT_STACK_SIZE`'s value.
`MRB_FIXED_STATE_ATEXIT_STACK_SIZE`
* Default value is `5`.
* If `MRB_FIXED_STATE_ATEXIT_STACK` isn't defined this macro is ignored.
## `mrb_value` configuration.
## `mrb_value` configuration
`MRB_ENDIAN_BIG`
* If defined compiles mruby for big endian machines.
* Used in `MRB_NAN_BOXING`.
* Some mrbgem use this mrbconf.
`MRB_NAN_BOXING`
* If defined represent `mrb_value` in boxed `double`.
* Conflicts with `MRB_USE_FLOAT`.
* Conflicts with `MRB_USE_FLOAT32` and `MRB_NO_FLOAT`.
`MRB_WORD_BOXING`
* If defined represent `mrb_value` as a word.
* If defined `Float` will be a mruby object with `RBasic`.
## Instance variable configuration.
`MRB_IV_SEGMENT_SIZE`
* Default value is `4`.
* Specifies size of each segment in segment list.
## Reduce heap memory configuration
`MRB_USE_ETEXT_RO_DATA_P`
* Use `etext` and `edata` section addresses defined by the linker to detect read-only data.
* Those addresses are widely available, but not portable, nor standardized.
* This macro is defined by default on User-mode Linux.
`MRB_NO_DEFAULT_RO_DATA_P`
* Define this macro when the default `mrb_ro_data_p()` does not work for any reason.
`MRB_USE_CUSTOM_RO_DATA_P`
* Please try if `MRB_USE_LINK_TIME_RO_DATA_P` is not available.
* The `mrb_ro_data_p()` function is implemented by the user in an arbitrary file.
* The prototype declaration is `mrb_bool mrb_ro_data_p(const char *ptr)`.
* Return `TRUE` if `ptr` is in the read-only section, otherwise return `FALSE`.
## Other configuration
## Other configuration.
`MRB_UTF8_STRING`
* Adds UTF-8 encoding support to character-oriented String instance methods.
* If it isn't defined, they only support the US-ASCII encoding.
`MRB_FUNCALL_ARGC_MAX`
* Default value is `16`.
* Specifies 4th argument(`argc`) max value of `mrb_funcall`.
* Raises `ArgumentError` when the `argc` argument is bigger then this value `mrb_funcall`.
`KHASH_DEFAULT_SIZE`
* Default value is `32`.
* Specifies default size of khash table bucket.
* Used in `kh_init_ ## name` function.
`MRB_STR_BUF_MIN_SIZE`
* Default value is `128`.
* Specifies initial capacity of `RString` created by `mrb_str_buf_new` function..
`MRB_NO_METHOD_CACHE`
* Disable method cache to save memory.
`MRB_METHOD_CACHE_SIZE`
* Default value is `256`.
* Ignored if `MRB_NO_METHOD_CACHE` is defined.
* Need to be the power of 2.
`MRB_USE_METHOD_T_STRUCT`
* Use C struct to represent `mrb_method_t`
* No `MRB_USE_METHOD_T_STRUCT` requires highest 2 bits of function pointers to be zero
* Define this macro on machines that use higher bits of pointers
`MRB_USE_ALL_SYMBOLS`
* Make it available `Symbol.all_symbols` in `mrbgems/mruby-symbol-ext`
* Increase heap memory usage.
+176 -104
View File
@@ -1,47 +1,62 @@
# mrbgems
mrbgems is a library manager to integrate C and Ruby extension in an easy and
standardised way into mruby.
standardised way into mruby. Conventionally, each mrbgem name is prefixed by
`mruby-`, e.g. `mruby-time` for a gem that provides `Time` class functionality.
## Usage
By default mrbgems is currently deactivated. As soon as you add a GEM to your
build configuration (i.e. *build_config.rb*), mrbgems will be activated and the
extension integrated.
You have to activate mrbgems explicitly in your build configuration. To add
a gem, add the following line to your build configuration file, for example:
To add a GEM into the *build_config.rb* add the following line for example:
```ruby
conf.gem '/path/to/your/gem/dir'
```
You can also use a relative path which would be relative from the mruby root:
You can also use a relative path to specify a gem.
```ruby
conf.gem 'examples/mrbgems/ruby_extension_example'
```
In that case,
* if your build configuration file is in the `build_config` directory, it's
relative from `MRUBY_ROOT`.
* otherwise, it is relative from the directory where your build configuration is.
A remote GIT repository location for a GEM is also supported:
```ruby
conf.gem :git => 'https://github.com/masuidrive/mrbgems-example.git', :branch => 'master'
conf.gem :github => 'masuidrive/mrbgems-example', :branch => 'master'
conf.gem :bitbucket => 'mruby/mrbgems-example', :branch => 'master'
```
You can specify the sub directory of the repository with `:path` option:
You can specify the subdirectory of the repository with `:path` option:
```ruby
conf.gem github: 'mruby/mruby', path: 'mrbgems/mruby-socket'
```
To use mrbgem from [mgem-list](https://github.com/mruby/mgem-list) use `:mgem` option:
```ruby
conf.gem :mgem => 'mruby-yaml'
conf.gem :mgem => 'yaml' # 'mruby-' prefix could be omitted
```
If there is missing dependencies, mrbgem dependencies solver will reference
mrbgem from core or mgem-list.
For specifying the commit hash to checkout use `:checksum_hash` option:
To pull all gems from remote GIT repository on build, call ```./minirake -p```,
or ```./minirake --pull-gems```.
```ruby
conf.gem mgem: 'mruby-redis', checksum_hash: '3446d19fc4a3f9697b5ddbf2a904f301c42f2f4e'
```
If there are missing dependencies, mrbgem dependencies solver will reference
mrbgem from the core or mgem-list.
To pull all gems from remote GIT repository on build, call `rake -p`,
or `rake --pull-gems`.
NOTE: `:bitbucket` option supports only git. Hg is unsupported in this version.
@@ -49,13 +64,14 @@ NOTE: `:bitbucket` option supports only git. Hg is unsupported in this version.
There are instances when you wish to add a collection of mrbgems into mruby at
once, or be able to substitute mrbgems based on configuration, without having to
add each gem to the *build_config.rb* file. A packaged collection of mrbgems
add each gem to your build configuration file. A packaged collection of mrbgems
is called a GemBox. A GemBox is a file that contains a list of mrbgems to load
into mruby, in the same format as if you were adding them to *build_config.rb*
into mruby, in the same format as if you were adding them to the build config
via `config.gem`, but wrapped in an `MRuby::GemBox` object. GemBoxes are
loaded into mruby via `config.gembox 'boxname'`.
Below we have created a GemBox containing *mruby-time* and *mrbgems-example*:
Below we have created a GemBox containing `mruby-time` and `mrbgems-example`:
```ruby
MRuby::GemBox.new do |conf|
conf.gem "#{root}/mrbgems/mruby-time"
@@ -64,20 +80,23 @@ end
```
As mentioned, the GemBox uses the same conventions as `MRuby::Build`. The GemBox
must be saved with a *.gembox* extension inside the *mrbgems* directory to to be
must be saved with a `.gembox` extension inside the `mrbgems` directory to be
picked up by mruby.
To use this example GemBox, we save it as `custom.gembox` inside the *mrbgems*
directory in mruby, and add the following to our *build_config.rb* file inside
To use this example GemBox, we save it as `custom.gembox` inside the `mrbgems`
directory in mruby, and add the following to your build configuration file inside
the build block:
```ruby
conf.gembox 'custom'
```
This will cause the *custom* GemBox to be read in during the build process,
adding *mruby-time* and *mrbgems-example* to the build.
This will cause the `custom` GemBox to be read in during the build process,
adding `mruby-time` and `mrbgems-example` to the build.
If you want, you can put GemBox outside of mruby directory. In that case you must
specify an absolute path like below.
```ruby
conf.gembox "#{ENV["HOME"]}/mygemboxes/custom"
```
@@ -85,36 +104,41 @@ conf.gembox "#{ENV["HOME"]}/mygemboxes/custom"
There are two GemBoxes that ship with mruby: [default](../../mrbgems/default.gembox)
and [full-core](../../mrbgems/full-core.gembox). The [default](../../mrbgems/default.gembox) GemBox
contains several core components of mruby, and [full-core](../../mrbgems/full-core.gembox)
contains every gem found in the *mrbgems* directory.
contains every gem found in the `mrbgems` directory.
## GEM Structure
The maximal GEM structure looks like this:
+- GEM_NAME <- Name of GEM
|
+- include/ <- Header for Ruby extension (will exported)
|
+- mrblib/ <- Source for Ruby extension
|
+- src/ <- Source for C extension
|
+- test/ <- Test code (Ruby)
|
+- mrbgem.rake <- GEM Specification
|
+- README.md <- Readme for GEM
```
+- GEM_NAME <- Name of GEM
|
+- README.md <- Readme for GEM
|
+- mrbgem.rake <- GEM Specification
|
+- include/ <- Header for Ruby extension (will exported)
|
+- mrblib/ <- Source for Ruby extension
|
+- src/ <- Source for C extension
|
+- tools/ <- Source for Executable (in C)
|
+- test/ <- Test code (Ruby)
```
The folder *mrblib* contains pure Ruby files to extend mruby. The folder *src*
contains C/C++ files to extend mruby. The folder *include* contains C/C++ header
files. The folder *test* contains C/C++ and pure Ruby files for testing purposes
which will be used by `mrbtest`. *mrbgem.rake* contains the specification
to compile C and Ruby files. *README.md* is a short description of your GEM.
The folder `mrblib` contains pure Ruby files to extend mruby. The folder `src`
contains C/C++ files to extend mruby. The folder `include` contains C/C++ header
files. The folder `test` contains C/C++ and pure Ruby files for testing purposes
which will be used by `mrbtest`. `mrbgem.rake` contains the specification
to compile C and Ruby files. `README.md` is a short description of your GEM.
## Build process
mrbgems expects a specification file called *mrbgem.rake* inside of your
mrbgems expects a specification file called `mrbgem.rake` inside of your
GEM directory. A typical GEM specification could look like this for example:
```ruby
MRuby::Gem::Specification.new('c_and_ruby_extension_example') do |spec|
spec.license = 'MIT'
@@ -124,10 +148,10 @@ end
```
The mrbgems build process will use this specification to compile Object and Ruby
files. The compilation results will be added to *lib/libmruby.a*. This file exposes
files. The compilation results will be added to `lib/libmruby.a`. This file exposes
the GEM functionality to tools like `mruby` and `mirb`.
The following properties can be set inside of your `MRuby::Gem::Specification` for
The following properties can be set inside your `MRuby::Gem::Specification` for
information purpose:
* `spec.license` or `spec.licenses` (A single license or a list of them under which this GEM is licensed)
@@ -144,6 +168,7 @@ The `license` and `author` properties are required in every GEM!
In case your GEM is depending on other GEMs please use
`spec.add_dependency(gem, *requirements[, default_get_info])` like:
```ruby
MRuby::Gem::Specification.new('c_and_ruby_extension_example') do |spec|
spec.license = 'MIT'
@@ -153,10 +178,10 @@ MRuby::Gem::Specification.new('c_and_ruby_extension_example') do |spec|
# The version must be between 1.0.0 and 1.5.2 .
spec.add_dependency('mruby-parser', '>= 1.0.0', '<= 1.5.2')
# Use any version of mruby-uv from github.
# Use any version of mruby-uv from GitHub.
spec.add_dependency('mruby-uv', '>= 0.0.0', :github => 'mattn/mruby-uv')
# Use latest mruby-onig-regexp from github. (version requirements can be omitted)
# Use latest mruby-onig-regexp from GitHub. (version requirements can be omitted)
spec.add_dependency('mruby-onig-regexp', :github => 'mattn/mruby-onig-regexp')
# You can add extra mgems active only on test
@@ -167,6 +192,7 @@ end
The version requirements and default gem information are optional.
Version requirement supports following operators:
* '=': is equal
* '!=': is not equal
* '>': is greater
@@ -174,23 +200,25 @@ Version requirement supports following operators:
* '>=': is equal or greater
* '<=': is equal or lesser
* '~>': is equal or greater and is lesser than the next major version
* example 1: '~> 2.2.2' means '>= 2.2.2' and '< 2.3.0'
* example 2: '~> 2.2' means '>= 2.2.0' and '< 3.0.0'
* example 1: '~> 2.2.2' means '>= 2.2.2' and '< 2.3.0'
* example 2: '~> 2.2' means '>= 2.2.0' and '< 3.0.0'
When more than one version requirements is passed, the dependency must satisfy all of it.
You can have default gem to use as dependency when it's not defined in *build_config.rb*.
You can have default gem to use as dependency when it's not defined in your build configuration.
When the last argument of `add_dependency` call is `Hash`, it will be treated as default gem information.
Its format is same as argument of method `MRuby::Build#gem`, expect that it can't be treated as path gem location.
When a special version of dependency is required,
use `MRuby::Build#gem` in *build_config.rb* to override default gem.
use `MRuby::Build#gem` in the build configuration to override default gem.
If you have conflicting GEMs use the following method:
* `spec.add_conflict(gem, *requirements)`
* The `requirements` argument is same as in `add_dependency` method.
* The `requirements` argument is same as in `add_dependency` method.
like following code:
```ruby
MRuby::Gem::Specification.new 'some-regexp-binding' do |spec|
spec.license = 'BSD'
@@ -204,7 +232,7 @@ end
```
In case your GEM has more complex build requirements you can use
the following options additionally inside of your GEM specification:
the following options additionally inside your GEM specification:
* `spec.cc.flags` (C compiler flags)
* `spec.cc.defines` (C compiler defines)
@@ -219,7 +247,7 @@ the following options additionally inside of your GEM specification:
* `spec.test_objs` (Object test files for integration into mrbtest)
* `spec.test_preload` (Initialization files for mrbtest)
You also can use `spec.mruby.cc` and `spec.mruby.linker` to add extra global parameters for compiler and linker.
You also can use `spec.mruby.cc` and `spec.mruby.linker` to add extra global parameters for the compiler and linker.
### include_paths and dependency
@@ -228,12 +256,11 @@ By default, `/...absolute path.../{GEM_NAME}/include` will be exported.
So it is recommended not to put GEM's local header files on include/.
These exports are retroactive.
For example: when B depends to C and A depends to B, A will get include paths exported by C.
For example: when B depends on C and A depends on B, A will get include paths exported by C.
Exported include_paths are automatically appended to GEM local include_paths by Minirake.
Exported include_paths are automatically appended to GEM local include_paths by rake.
You can use `spec.export_include_paths` accessor if you want more complex build.
## C Extension
mruby can be extended with C. This is possible by using the C API to
@@ -243,9 +270,10 @@ integrate C libraries into mruby.
mrbgems expects that you have implemented a C method called
`mrb_YOURGEMNAME_gem_init(mrb_state)`. `YOURGEMNAME` will be replaced
by the name of your GEM. If you call your GEM *c_extension_example*, your
by the name of your GEM. If you call your GEM `c_extension_example`, your
initialisation method could look like this:
```C
```c
void
mrb_c_extension_example_gem_init(mrb_state* mrb) {
struct RClass *class_cextension = mrb_define_module(mrb, "CExtension");
@@ -257,10 +285,10 @@ mrb_c_extension_example_gem_init(mrb_state* mrb) {
mrbgems expects that you have implemented a C method called
`mrb_YOURGEMNAME_gem_final(mrb_state)`. `YOURGEMNAME` will be replaced
by the name of your GEM. If you call your GEM *c_extension_example*, your
by the name of your GEM. If you call your GEM `c_extension_example`, your
finalizer method could look like this:
```C
```c
void
mrb_c_extension_example_gem_final(mrb_state* mrb) {
free(someone);
@@ -269,54 +297,57 @@ mrb_c_extension_example_gem_final(mrb_state* mrb) {
### Example
+- c_extension_example/
|
+- src/
| |
| +- example.c <- C extension source
|
+- test/
| |
| +- example.rb <- Test code for C extension
|
+- mrbgem.rake <- GEM specification
|
+- README.md
```
+- c_extension_example/
|
+- README.md (Optional)
|
+- src/
| |
| +- example.c <- C extension source
|
+- test/
| |
| +- example.rb <- Test code for C extension
|
+- mrbgem.rake <- GEM specification
```
## Ruby Extension
mruby can be extended with pure Ruby. It is possible to override existing
classes or add new ones in this way. Put all Ruby files into the *mrblib*
classes or add new ones in this way. Put all Ruby files into the `mrblib`
folder.
### Pre-Conditions
none
### Example
+- ruby_extension_example/
|
+- mrblib/
| |
| +- example.rb <- Ruby extension source
|
+- test/
| |
| +- example.rb <- Test code for Ruby extension
|
+- mrbgem.rake <- GEM specification
|
+- README.md
```
+- ruby_extension_example/
|
+- README.md (Optional)
|
+- mrblib/
| |
| +- example.rb <- Ruby extension source
|
+- test/
| |
| +- example.rb <- Test code for Ruby extension
|
+- mrbgem.rake <- GEM specification
```
## C and Ruby Extension
mruby can be extended with C and Ruby at the same time. It is possible to
override existing classes or add new ones in this way. Put all Ruby files
into the *mrblib* folder and all C files into the *src* folder.
into the `mrblib` folder and all C files into the `src` folder.
mruby codes under *mrblib* directory would be executed after gem init C
mruby codes under `mrblib` directory would be executed after gem init C
function is called. Make sure *mruby script* depends on *C code* and
*C code* doesn't depend on *mruby script*.
@@ -326,20 +357,61 @@ See C and Ruby example.
### Example
+- c_and_ruby_extension_example/
|
+- mrblib/
| |
| +- example.rb <- Ruby extension source
|
+- src/
| |
| +- example.c <- C extension source
|
+- test/
| |
| +- example.rb <- Test code for C and Ruby extension
|
+- mrbgem.rake <- GEM specification
|
+- README.md
```
+- c_and_ruby_extension_example/
|
+- README.md (Optional)
|
+- mrblib/
| |
| +- example.rb <- Ruby extension source
|
+- src/
| |
| +- example.c <- C extension source
|
+- test/
| |
| +- example.rb <- Test code for C and Ruby extension
|
+- mrbgem.rake <- GEM specification
```
## Binary gems
Some gems can generate executables under `bin` directory. Those gems are called
binary gems. Names of binary gems are conventionally prefixed by `mruby-bin`,
e.g. `mruby-bin-mirb` and `mruby-bin-strip`.
To specify the name of executable, you need to specify `spec.bins` in the
`mrbgem.rake`. The entry point `main()` should be in the C source file under
`tools/<bin>/*.c` where `<bin>` is a name of the executable. C files under the
`<bin>` directory are compiled and linked to the executable, but not included in
`libmruby.a`, whereas files under `mrblib` and `src` are.
It is strongly recommended not to include `mrblib` and `src` directories in the
binary gems, to separate normal gems and binary gems.
### Example
```
+- mruby-bin-example/
|
+- README.md (Optional)
|
+- bintest/
| |
| +- example.rb <- Test code for binary gem
|
+- mrbgem.rake <- Gem specification
|
+- mrblib/ <- Source for Ruby extension (Optional)
|
+- src/ <- Source for C extension (Optional)
|
+- tools/
|
+- example/ <- Executable name directory
|
+- example.c <- Source for Executable (includes main)
```
+83
View File
@@ -0,0 +1,83 @@
# Symbols
Symbols in `mruby` C source code is represented by `mrb_sym` which is alias of
`uint32_t`. Lower 30 bits are used for symbols so that higher 2 bits can be
used as flags, e.g. `struct mt_elem` in `class.c`.
```c
struct mt_elem {
union mt_ptr ptr;
size_t func_p:1;
size_t noarg_p:1;
mrb_sym key:sizeof(mrb_sym)*8-2;
};
```
## C API
We provide following C API for symbols.
### Generate Symbols
#### `mrb_sym mrb_intern(mrb_state*,const char*,size_t)`
Get a symbol from a string.
#### `mrb_sym mrb_intern_check_cstr(mrb_state*,const char*)`
Get a symbol from a NULL terminated (C) string.
#### `mrb_sym mrb_intern_str(mrb_state*,mrb_value)`
Get a symbol from a Ruby string object.
#### `mrb_intern_lit(mrb_state*,const char*)`
Get a symbol from a C string literal. The second argument should be a C string
literal, otherwise you will get a compilation error. It does not copy C string
given the fact it's a literal.
#### `mrb_sym mrb_intern_check(mrb_state*,const char*,size_t)`
Get a symbol from a string if the string has been already registered as a
symbol, otherwise return `0`. We also provide variants `mrb_intern_check_str()`
(from Ruby string) and `mrb_intern_check_cstr()` (from C string).
#### `const char *mrb_sym_name(mrb_state*,mrb_sym)`
Get a string representation of a symbol as a C string.
#### `const char *mrb_sym_name_len(mrb_state*,mrb_sym,mrb_int*)`
Get a string representation of a symbol, and its length.
## Preallocate Symbols
To save RAM, `mruby` can use compile-time allocation of some symbols. You can
use following macros to get preallocated symbols by including `mruby/presym.h`
header.
* `MRB_SYM(xor)` //=> xor (Word characters)
* `MRB_SYM_B(xor)` //=> xor! (Method with Bang)
* `MRB_SYM_Q(xor)` //=> xor? (Method with Question mark)
* `MRB_SYM_E(xor)` //=> xor= (Method with Equal)
* `MRB_CVSYM(xor)` //=> @@xor (Class Variable)
* `MRB_IVSYM(xor)` //=> @xor (Instance Variable)
* `MRB_OPSYM(xor)` //=> ^ (Operator)
For `MRB_OPSYM()`, specify the names corresponding to operators (see
`MRuby::Presym::OPERATORS` in `lib/mruby/presym.rb` for the names that
can be specified for it). Other than that, describe only word characters
excluding leading and ending punctuations.
These macros are converted to static symbol IDs at compile time, unless
preallocate symbols are disabled by `conf.disable_presym`. In that case,
these macros are expanded to `mrb_intern_lit` calls, therefore the mruby state
variable is required. The above macros assume the variable name is `mrb`. If
its name is not `mrb`, you need to use macros with `_2` suffix, such as
`MRB_SYM_2` to specify `mrb_state*` variable.
### Disabling Preallocated Symbols
You can disable preallocated symbols by specifying `conf.disable_presym` in the
configuration file.
+52
View File
@@ -0,0 +1,52 @@
# Boxing
The mruby objects and data are represented by C data type `mrb_value`. There are three options how to pack the data values in the `mrb_value`.
* Word Boxing
* NaN Boxing
* No Boxing
## Word Boxing
Word boxing packs the Ruby data in a word, which is a natural integer size that equals to the size of pointers (`intptr_t`). Word boxing can be specified by `MRB_WORD_BOXING`, and it's default configuration for most platforms.
Some values (called immediate values, e.g. integers, booleans, symbols, etc.) are directly packed in the word. The other data types are represented by pointers to the heap allocated structures.
The Word boxing packing bit patterns are like following:
| Types | Bit Pattern |
|--------|-------------------------------------|
| object | xxxxxxxx xxxxxxxx xxxxxxxx xxxxx000 |
| fixnum | xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxx1 |
| nil | 00000000 00000000 00000000 00000000 |
| true | 00000000 00000000 00000000 00001100 |
| false | 00000000 00000000 00000000 00000100 |
| undef | 00000000 00000000 00000000 00010100 |
| symbol | xxxxxxxx xxxxxxxx xxxxxxxx xxxxxx10 |
On 64 bit platform (unless `MRB_WORDBOX_NO_FLOAT_TRUNCATE`), float values are also packed in the `mrb_value`. In that case, we drop least significant 2 bits from mantissa.
If you need full precision for floating point numbers, define `MRB_WORDBOX_NO_FLOAT_TRUNCATE`.
## NaN Boxing
NaN boxing packs the Ruby data in a floating point numbers, which represent NaN (Not a Number) values. Under IEEE753 definitions every value that exponent is all set are considered as NaN. That means NaN can represent `2^51` values. NaN boxing is a teaching to pack the values in those NaN representation. In theory, 64 bits pointers are too big to fit in NaN, but practically most OS uses only 48 bits at most for pointers (except for some OS e.g. Solaris).
The NaN boxing packing bit patterns are like following:
| Types | Bit Pattern |
|--------|-------------------------------------------------------------------------|
| float | SEEEEEEE EEEEFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF |
| +/-inf | S1111111 11110000 00000000 00000000 00000000 00000000 00000000 00000000 |
| nan | 01111111 11111000 00000000 00000000 00000000 00000000 00000000 00000000 |
| fixnum | 01111111 11111001 00000000 00000000 IIIIIIII IIIIIIII IIIIIIII IIIIIIII |
| symbol | 01111111 11111110 00000000 00000000 SSSSSSSS SSSSSSSS SSSSSSSS SSSSSSSS |
| misc | 01111111 11111111 00000000 00000000 00000000 00000000 00TTTTTT 0000MMMM |
| object | 01111111 11111100 PPPPPPPP PPPPPPPP PPPPPPPP PPPPPPPP PPPPPPPP PPPPPP00 |
| ptr | 01111111 11111100 PPPPPPPP PPPPPPPP PPPPPPPP PPPPPPPP PPPPPPPP PPPPPP01 |
| nil | 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 |
The object values appear far more frequently than floating point numbers, so we offset the value so that object pointers are unchanged. This technique is called "favor pointer"".
## No Boxing
No boxing represents `mrb_value` by the C struct with `type` and the value union. This is the most portable (but inefficient) representation. No boxing can be specified by `MRB_NO_BOXING`, and it's default for debugging configuration (e.g. `host-debug`).
+128
View File
@@ -0,0 +1,128 @@
# The new bytecode
We will reimplement the VM to use 8bit instruction code. By
bytecode, we mean real byte code. The whole purpose is
reducing the memory consumption of mruby VM.
# Instructions
Instructions are bytes. There can be 256 instructions. Currently, we
have 94 instructions. Instructions can take 0 to 3 operands.
## operands
The size of operands can be either 8bits, 16bits or 24bits.
In the table.1 below, the second field describes the size (and
sign) of operands.
* B: 8bit
* S: 16bit
* sS: signed 16bit
* W: 24bit
## table.1 Instruction Table
| Instruction Name | Operand type | Semantics |
|------------------|--------------|----------------------------------------------------------|
| `OP_NOP` | `-` | `no operation` |
| `OP_MOVE` | `BB` | `R(a) = R(b)` |
| `OP_LOADL` | `BB` | `R(a) = Pool(b)` |
| `OP_LOADI` | `BB` | `R(a) = mrb_int(b)` |
| `OP_LOADINEG` | `BB` | `R(a) = mrb_int(-b)` |
| `OP_LOADI__1` | `B` | `R(a) = mrb_int(-1)` |
| `OP_LOADI_0` | `B` | `R(a) = mrb_int(0)` |
| `OP_LOADI_1` | `B` | `R(a) = mrb_int(1)` |
| `OP_LOADI_2` | `B` | `R(a) = mrb_int(2)` |
| `OP_LOADI_3` | `B` | `R(a) = mrb_int(3)` |
| `OP_LOADI_4` | `B` | `R(a) = mrb_int(4)` |
| `OP_LOADI_5` | `B` | `R(a) = mrb_int(5)` |
| `OP_LOADI_6` | `B` | `R(a) = mrb_int(6)` |
| `OP_LOADI_7` | `B` | `R(a) = mrb_int(7)` |
| `OP_LOADI16` | `BS` | `R(a) = mrb_int(b)` |
| `OP_LOADI32` | `BSS` | `R(a) = mrb_int((b<<16)+c)` |
| `OP_LOADSYM` | `BB` | `R(a) = Syms(b)` |
| `OP_LOADNIL` | `B` | `R(a) = nil` |
| `OP_LOADSELF` | `B` | `R(a) = self` |
| `OP_LOADT` | `B` | `R(a) = true` |
| `OP_LOADF` | `B` | `R(a) = false` |
| `OP_GETGV` | `BB` | `R(a) = getglobal(Syms(b))` |
| `OP_SETGV` | `BB` | `setglobal(Syms(b), R(a))` |
| `OP_GETSV` | `BB` | `R(a) = Special[Syms(b)]` |
| `OP_SETSV` | `BB` | `Special[Syms(b)] = R(a)` |
| `OP_GETIV` | `BB` | `R(a) = ivget(Syms(b))` |
| `OP_SETIV` | `BB` | `ivset(Syms(b),R(a))` |
| `OP_GETCV` | `BB` | `R(a) = cvget(Syms(b))` |
| `OP_SETCV` | `BB` | `cvset(Syms(b),R(a))` |
| `OP_GETCONST` | `BB` | `R(a) = constget(Syms(b))` |
| `OP_SETCONST` | `BB` | `constset(Syms(b),R(a))` |
| `OP_GETMCNST` | `BB` | `R(a) = R(a)::Syms(b)` |
| `OP_SETMCNST` | `BB` | `R(a+1)::Syms(b) = R(a)` |
| `OP_GETUPVAR` | `BBB` | `R(a) = uvget(b,c)` |
| `OP_SETUPVAR` | `BBB` | `uvset(b,c,R(a))` |
| `OP_JMP` | `S` | `pc+=a` |
| `OP_JMPIF` | `BS` | `if R(a) pc+=b` |
| `OP_JMPNOT` | `BS` | `if !R(a) pc+=b` |
| `OP_JMPNIL` | `BS` | `if R(a)==nil pc+=b` |
| `OP_JMPUW` | `S` | `unwind_and_jump_to(a)` |
| `OP_EXCEPT` | `B` | `R(a) = exc` |
| `OP_RESCUE` | `BB` | `R(b) = R(a).isa?(R(b))` |
| `OP_RAISEIF` | `B` | `raise(R(a)) if R(a)` |
| `OP_SEND` | `BBB` | `R(a) = call(R(a),Syms(b),R(a+1),...,R(a+c))` |
| `OP_SENDB` | `BBB` | `R(a) = call(R(a),Syms(b),R(a+1),...,R(a+c),&R(a+c+1))` |
| `OP_CALL` | `-` | `R(0) = self.call(frame.argc, frame.argv)` |
| `OP_SUPER` | `BB` | `R(a) = super(R(a+1),... ,R(a+b+1))` |
| `OP_ARGARY` | `BS` | `R(a) = argument array (16=m5:r1:m5:d1:lv4)` |
| `OP_ENTER` | `W` | `arg setup according to flags (23=m5:o5:r1:m5:k5:d1:b1)` |
| `OP_KEY_P` | `BB` | `R(a) = kdict.key?(Syms(b))` |
| `OP_KEYEND` | `-` | `raise unless kdict.empty?` |
| `OP_KARG` | `BB` | `R(a) = kdict[Syms(b)]; kdict.delete(Syms(b))` |
| `OP_RETURN` | `B` | `return R(a) (normal)` |
| `OP_RETURN_BLK` | `B` | `return R(a) (in-block return)` |
| `OP_BREAK` | `B` | `break R(a)` |
| `OP_BLKPUSH` | `BS` | `R(a) = block (16=m5:r1:m5:d1:lv4)` |
| `OP_ADD` | `B` | `R(a) = R(a)+R(a+1)` |
| `OP_ADDI` | `BB` | `R(a) = R(a)+mrb_int(b)` |
| `OP_SUB` | `B` | `R(a) = R(a)-R(a+1)` |
| `OP_SUBI` | `BB` | `R(a) = R(a)-mrb_int(b)` |
| `OP_MUL` | `B` | `R(a) = R(a)*R(a+1)` |
| `OP_DIV` | `B` | `R(a) = R(a)/R(a+1)` |
| `OP_EQ` | `B` | `R(a) = R(a)==R(a+1)` |
| `OP_LT` | `B` | `R(a) = R(a)<R(a+1)` |
| `OP_LE` | `B` | `R(a) = R(a)<=R(a+1)` |
| `OP_GT` | `B` | `R(a) = R(a)>R(a+1)` |
| `OP_GE` | `B` | `R(a) = R(a)>=R(a+1)` |
| `OP_ARRAY` | `BB` | `R(a) = ary_new(R(a),R(a+1)..R(a+b))` |
| `OP_ARRAY2` | `BBB` | `R(a) = ary_new(R(b),R(b+1)..R(b+c))` |
| `OP_ARYCAT` | `B` | `ary_cat(R(a),R(a+1))` |
| `OP_ARYPUSH` | `BB` | `ary_push(R(a),R(a+1)..R(a+b))` |
| `OP_ARYDUP` | `B` | `R(a) = ary_dup(R(a))` |
| `OP_AREF` | `BBB` | `R(a) = R(b)[c]` |
| `OP_ASET` | `BBB` | `R(b)[c] = R(a)` |
| `OP_APOST` | `BBB` | `*R(a),R(a+1)..R(a+c) = R(a)[b..]` |
| `OP_INTERN` | `B` | `R(a) = intern(R(a))` |
| `OP_STRING` | `BB` | `R(a) = str_dup(Pool(b))` |
| `OP_STRCAT` | `B` | `str_cat(R(a),R(a+1))` |
| `OP_HASH` | `BB` | `R(a) = hash_new(R(a),R(a+1)..R(a+b*2-1))` |
| `OP_HASHADD` | `BB` | `hash_push(R(a),R(a+1)..R(a+b*2))` |
| `OP_HASHCAT` | `B` | `R(a) = hash_cat(R(a),R(a+1))` |
| `OP_LAMBDA` | `BB` | `R(a) = lambda(Irep(b),OP_L_LAMBDA)` |
| `OP_BLOCK` | `BB` | `R(a) = lambda(Irep(b),OP_L_BLOCK)` |
| `OP_METHOD` | `BB` | `R(a) = lambda(Irep(b),OP_L_METHOD)` |
| `OP_RANGE_INC` | `B` | `R(a) = range_new(R(a),R(a+1),FALSE)` |
| `OP_RANGE_EXC` | `B` | `R(a) = range_new(R(a),R(a+1),TRUE)` |
| `OP_OCLASS` | `B` | `R(a) = ::Object` |
| `OP_CLASS` | `BB` | `R(a) = newclass(R(a),Syms(b),R(a+1))` |
| `OP_MODULE` | `BB` | `R(a) = newmodule(R(a),Syms(b))` |
| `OP_EXEC` | `BB` | `R(a) = blockexec(R(a),Irep[b])` |
| `OP_DEF` | `BB` | `R(a).newmethod(Syms(b),R(a+1)); R(a) = Syms(b)` |
| `OP_ALIAS` | `BB` | `alias_method(target_class,Syms(a),Syms(b))` |
| `OP_UNDEF` | `B` | `undef_method(target_class,Syms(a))` |
| `OP_SCLASS` | `B` | `R(a) = R(a).singleton_class` |
| `OP_TCLASS` | `B` | `R(a) = target_class` |
| `OP_DEBUG` | `BBB` | `print a,b,c` |
| `OP_ERR` | `B` | `raise(LocalJumpError, Pool(a))` |
| `OP_EXT1` | `-` | `make 1st operand 16bit` |
| `OP_EXT2` | `-` | `make 2nd operand 16bit` |
| `OP_EXT3` | `-` | `make 1st and 2nd operands 16bit` |
| `OP_STOP` | `-` | `stop VM` |
|------------------|--------------|----------------------------------------------------------|
+84 -78
View File
@@ -13,40 +13,9 @@ This document is collecting these limitations.
This document does not contain a complete list of limitations.
Please help to improve it by submitting your findings.
## `Kernel.raise` in rescue clause
## ```1/2``` gives ```0.5```
Since mruby does not have ```Bignum```, bigger integers are represented
by ```Float``` numbers. To enhance interoperability between ```Fixnum```
and ```Float```, mruby provides ```Float#upto``` and other iterating
methods for the ```Float``` class. As a side effect, ```1/2``` gives ```0.5```
not ```0```.
## ```Array``` passed to ```puts```
Passing an Array to ```puts``` results in different output.
```ruby
puts [1,2,3]
```
#### Ruby [ruby 2.0.0p645 (2015-04-13 revision 50299)]
```
1
2
3
```
#### mruby [2.0.0 (2018-12-11)]
```
[1, 2, 3]
```
## ```Kernel.raise``` in rescue clause
```Kernel.raise``` without arguments does not raise the current exception within
`Kernel.raise` without arguments does not raise the current exception within
a rescue clause.
```ruby
@@ -59,26 +28,34 @@ end
#### Ruby [ruby 2.0.0p645 (2015-04-13 revision 50299)]
```ZeroDivisionError``` is raised.
`ZeroDivisionError` is raised.
#### mruby [2.0.0 (2018-12-11)]
#### mruby [3.0.0 (2021-03-05)]
No exception is raised.
`RuntimeError` is raised instead of `ZeroDivisionError`. To re-raise the exception, you have to do:
```ruby
begin
1 / 0
rescue => e
raise e
end
```
## Fiber execution can't cross C function boundary
mruby's ```Fiber``` is implemented in a similar way to Lua's co-routine. This
mruby's `Fiber` is implemented similarly to Lua's co-routine. This
results in the consequence that you can't switch context within C functions.
Only exception is ```mrb_fiber_yield``` at return.
Only exception is `mrb_fiber_yield` at return.
## ```Array``` does not support instance variables
## `Array` does not support instance variables
To reduce memory consumption ```Array``` does not support instance variables.
To reduce memory consumption `Array` does not support instance variables.
```ruby
class Liste < Array
def initialize(str = nil)
@feld = str
@field = str
end
end
@@ -87,16 +64,16 @@ p Liste.new "foobar"
#### Ruby [ruby 2.0.0p645 (2015-04-13 revision 50299)]
``` [] ```
` [] `
#### mruby [1.4.1 (2018-4-27)]
#### mruby [3.0.0 (2021-03-05)]
```ArgumentError``` is raised.
`ArgumentError` is raised.
## Method visibility
For simplicity reasons no method visibility (public/private/protected) is
supported.
supported. Those methods are defined, but they are dummy methods.
```ruby
class VisibleTest
@@ -119,17 +96,53 @@ false
true
```
#### mruby [2.0.0 (2018-12-11)]
#### mruby [3.0.0 (2021-03-05)]
```
true
true
```
## defined?
### Visibility Declaration
The ```defined?``` keyword is considered too complex to be fully
implemented. It is recommended to use ```const_defined?``` and
The declaration form of following visibility methods are not implemented.
* `public`
* `private`
* `protected`
* `module_function`
Especially, `module_function` method is not dummy, but no declaration form.
```
module TestModule
module_function
def test_func
p 'test_func called'
end
test_func
end
p 'ok'
```
#### Ruby [ruby 2.5.5p157 (2019-03-15 revision 67260)]
```
ok
```
#### mruby [3.0.0 (2021-03-05)]
```
test.rb:8: undefined method 'test_func' (NoMethodError)
```
## `defined?`
The `defined?` keyword is considered too complex to be fully
implemented. It is recommended to use `const_defined?` and
other reflection methods instead.
```ruby
@@ -142,11 +155,11 @@ defined?(Foo)
nil
```
#### mruby [2.0.0 (2018-12-11)]
#### mruby [3.0.0 (2021-03-05)]
```NameError``` is raised.
`NameError` is raised.
## ```alias``` on global variables
## `alias` on global variables
Aliasing a global variable works in CRuby but is not part
of the ISO standard.
@@ -157,9 +170,9 @@ alias $a $__a__
#### Ruby [ruby 2.0.0p645 (2015-04-13 revision 50299)]
``` nil ```
` nil `
#### mruby [2.0.0 (2018-12-11)]
#### mruby [3.0.0 (2021-03-05)]
Syntax error
@@ -178,15 +191,15 @@ end
#### Ruby [ruby 2.0.0p645 (2015-04-13 revision 50299)]
```ArgumentError``` is raised.
The re-defined ```+``` operator does not accept any arguments.
`ArgumentError` is raised.
The re-defined `+` operator does not accept any arguments.
#### mruby [2.0.0 (2018-12-11)]
#### mruby [3.0.0 (2021-03-05)]
``` 'ab' ```
` 'ab' `
Behavior of the operator wasn't changed.
## Kernel#binding is not supported
## `Kernel#binding` is not supported
`Kernel#binding` method is not supported.
@@ -197,7 +210,7 @@ $ ruby -e 'puts Proc.new {}.binding'
#<Binding:0x00000e9deabb9950>
```
#### mruby [2.0.0 (2018-12-11)]
#### mruby [3.0.0 (2021-03-05)]
```
$ ./bin/mruby -e 'puts Proc.new {}.binding'
@@ -206,27 +219,19 @@ trace (most recent call last):
-e:1: undefined method 'binding' (NoMethodError)
```
## Keyword arguments
## `nil?` redefinition in conditional expressions
mruby keyword arguments behave slightly different from CRuby 2.5
to make the behavior simpler and less confusing. Maybe in the
future, the simpler behavior will be adopted to CRuby as well.
Redefinition of `nil?` is ignored in conditional expressions.
#### Ruby [ruby 2.5.1p57 (2018-03-29 revision 63029)]
```
$ ruby -e 'def m(*r,**k) p [r,k] end; m("a"=>1,:b=>2)'
[[{"a"=>1}], {:b=>2}]
```ruby
a = "a"
def a.nil?
true
end
puts(a.nil? ? "truthy" : "falsy")
```
#### mruby [mruby 2.0.0]
```
$ ./bin/mruby -e 'def m(*r,**k) p [r,k] end; m("a"=>1,:b=>2)'
trace (most recent call last):
[0] -e:1
-e:1: keyword argument hash with non symbol keys (ArgumentError)
```
Ruby outputs `falsy`. mruby outputs `truthy`.
## Argument Destructuring
@@ -234,11 +239,12 @@ trace (most recent call last):
def m(a,(b,c),d); p [a,b,c,d]; end
m(1,[2,3],4) # => [1,2,3,4]
```
Destructured arguments (`b` and `c` in above example) cannot be accessed
from the default expression of optional arguments and keyword arguments,
since actual assignment is done after the evaluation of those default
expressions. Thus:
```ruby
def f(a,(b,c),d=b)
p [a,b,c,d]
+162
View File
@@ -0,0 +1,162 @@
# User visible changes in `mruby3.0`
# Build System
## `build_config` directory
Typical build configuration files are located in `build_config`
directory. For examples:
* `default`: the default configuration
* `host-gprof`: compiles with `gprof` for performance tuning
* `host-m32`: compiles in gcc 32bit mode on 64bit platforms
* `boxing`: compiles all three boxing options
* `clang-asan`: compiles with `clang`'s Address Sanitizer
You can specify the build configuration file with the
`MRUBY_CONFIG` environment variable (or `CONFIG` in short).
If the value specified by `MRUBY_CONFIG` is not the path to
the configuration file, `build_config/${MRUBY_CONFIG}.rb` is
used. So you can specify it as `rake MRUBY_CONFIG=boxing`,
for example.
# Build Configuration Contribution
When you write a new build configuration description, please
contribute. We welcome your contribution as a GitHub
pull-request.
# Language Changes
## New Syntax
We have ported some new syntax from CRuby.
* Single line pattern matching (`12 => x`);
mruby matches only with local variables at the moment
* Numbered block parameter (`x.map{_1 * 2}`)
* End-less `def` (`def double(x) = x*2`)
# Configuration Options Changed
## Renamed for consistency
Some configuration macro names are changed for consistency (use `MRB_USE_XXX`
or `MRB_NO_XXX`).
| mruby2 | mruby3 |
|--------------------------------|---------------------------|
| `MRB_ENABLE_ALL_SYMBOLS` | `MRB_USE_ALL_SYMBOLS` |
| `MRB_ENABLE_CXX_ABI` | `MRB_USE_CXX_ABI` |
| `MRB_ENABLE_CXX_EXCEPTION` | `MRB_USE_CXX_EXCEPTION` |
| `MRB_ENABLE_DEBUG_HOOK` | `MRB_USE_DEBUG_HOOK` |
| `MRB_DISABLE_DIRECT_THREADING` | `MRB_NO_DIRECT_THREADING` |
| `MRB_DISABLE_STDIO` | `MRB_NO_STDIO` |
| `MRB_METHOD_T_STRUCT` | `MRB_USE_METHOD_T_STRUCT` |
| `MRB_USE_FLOAT` | `MRB_USE_FLOAT32` |
| `MRB_WITHOUT_FLOAT` | `MRB_NO_FLOAT` |
| `ENABLE_LINENOISE` | `MRB_USE_LINENOISE` |
| `ENABLE_READLINE` | `MRB_USE_READLINE` |
| `DISABLE_MIRB_UNDERSCORE` | `MRB_NO_MIRB_UNDERSCORE` |
* `MRB_USE_FLOAT32` is changed from `MRB_USE_FLOAT` to make sure `float` here
means using single precision float, and not the opposite of `MRB_NO_FLOAT`.
* `MRB_USE_METHOD_T_STRUCT` uses `struct` version of `mrb_method_t`. More
portable but consumes more memory. Turned on by default on 32bit platforms.
* `MRB_` prefix is added to those without.
## `MRB_NO_BOXING`
Uses `struct` to represent `mrb_value`. Consumes more memory
but easier to investigate the internal and to debug. It used
to be default `mrb_value` representation. Now the default is
`MRB_WORD_BOXING`.
## `MRB_WORD_BOXING`
Pack `mrb_value` in an `intptr_t` integer. Consumes less
memory compared to `MRB_NO_BOXING` especially on 32 bit
platforms. `Fixnum` size is 31 bits so some integer values
does not fit in `Fixnum` integers.
## `MRB_NAN_BOXING`
Pack `mrb_value` in a floating pointer number. Nothing
changed from previous versions.
## `MRB_USE_MALLOC_TRIM`
Call `malloc_trim(0)` from mrb_full_gc() if this macro is defined.
If you are using glibc malloc, this macro could reduce memory consumption.
# Command Line Program
## `bin/mruby` (by mrbgems/mruby-bin-mruby)
The mruby3 now automatically detects `*.mrb` files without the `-b`
switch. Therefore, it can be mixed with the `*.rb` file in combination
with the `-r` switch and specified at the same time.
Here's an example that works fine:
```console
$ bin/mruby app.mrb
$ bin/mruby -r lib1.mrb -r lib2.rb app.rb
$ bin/mruby -r lib1.rb -r lib2.rb < app.mrb
```
# Internal Changes
## New Instructions
`mruby3` introduces a few new instructions.
Instructions that access pool[i]/syms[i] where i>255.
* `OP_LOADL16`
* `OP_STRING16`
* `OP_LOADSYM16`
Instructions that load a 32 bit integer.
* `OP_LOADI32`
Instruction that unwinds jump table for rescue/ensure.
* `OP_JMPUW`
Renamed from `OP_RAISE`
* `OP_RAISEIF`
Instruction that is reserved for the future keyword argument support.
* OP_SENDVK
## Removed Instructions
Instructions for old exception handling
* `OP_ONERR`
* `OP_POPERR`
* `OP_EPUSH`
* `OP_EPOP`
No more operand extension
* `OP_EXT1`
* `OP_EXT2`
* `OP_EXT3`
## Changed Instructions
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.
## `Random` now use `xoshiro128++`.
For better and faster random number generation.
## Preallocated Symbol
Preallocated symbols are interned at compile-time. They can be accessed via symbols macros (e.g. `MRB_SYM()`).
See [Symbols](https://github.com/mruby/mruby/blob/master/doc/guides/symbol.md).
+148
View File
@@ -0,0 +1,148 @@
# 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.
# 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
# Language Changes
## Keyword Arguments
CRuby3.0 compatible keyword arguments are introduced.
Keyword arguments are basically separated from ordinal arguments
## New Methods
* `Array#product`
* `Array#repeated_combination`
* `Array#repeated_permutation`
* `Random.bytes`
* `Random#bytes`
# 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] = R[a].call(Syms[b],R[a+1..n],R[a+n+1],R[a+n+2]..nk) c=n|nk<<4` |
|`OP_SENDB` | BBB | `R[a] = R[a].call(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` |
Operand C specifies the number of arguments. Lower 4 bits (`n`) represents the number of ordinal arguments, and higher 4 bits (`nk`) represents the number of keyword arguments.
When `n == 15`, the method takes arguments packed in an array. When `nk == 15`, the method takes keyword arguments are packed in a hash.
### `OP_ARYPUSH`
Now takes 2 operands and pushes multiple entries to an array.
## Boxing Updated
### Word Boxing
`MRB_WORD_BOXING` now packs floating point numbers in the word, if the size of `mrb_float` is equal or smaller than the size of `mrb_int` by default.
If the size of `mrb_float` and `mrb_int` are same, the last 2 bits in the `mrb_float` are trimmed and used as flags. If you need full precision, you need to define `MRB_WORDBOX_NO_FLOAT_TRUNCATE` as described above.
### NaN Boxing
Previous NaN boxing packs values in NaN representation, but pointer retrievals are far more frequent than floating point number references. So we add constant offset to NaN representation to clear higher bits of pointer representation. This representation is called "Favor Pointer" NaN Boxing.
Also, previous NaN boxing limit the size of `mrb_int` to 4 bytes (32 bits) to fit in NaN values. Now we allocates integer values in the heap, if the value does not fit in the 32 bit range, just like we did in Word Boxing.
## Constant Folding
The code generator was updated to reduce the number of instructions, e.g.
```
a = 2 * 5
```
will be interpreted as
```
a = 10
```
In addition, we have improved peephole optimizations, for example:
```
GETIV R4 :@foo
MOVE R1 R4
```
to
```
GETIV R1 :@foo
```
## `String#hash` now use `FNV1a` algorithm
For better and faster hash values.
Binary file not shown.

After

Width:  |  Height:  |  Size: 8.4 KiB

-127
View File
@@ -1,127 +0,0 @@
# The new bytecode
We will reimplement VM to use 8bit instruction code. By
bytecode, we mean real byte code. The whole purpose is
reducing the memory consumption of mruby VM.
# Instructions
Instructions are bytes. There can be 256 instructions. Currently we
have 94 instructions. Instructions can take 0 to 3 operands.
## operands
The size of operands can be either 8bits, 16bits or 24bits.
In the table.1 below, the second field describes the size (and
sign) of operands.
* B: 8bit
* sB: signed 8bit
* S: 16bit
* sS: signed 16bit
* W: 24bit
First two byte operands may be extended to 16bit. When those byte
operands are bigger than 256, the instruction will be prefixed by
`OP_EXT1` (means 1st operand is 16bit) or `OP_EXT2` (means 2nd operand
is 16bit) or `OP_EXT3` (means 1st and 2nd operands are 16bit).
For instructions marked by `'`, `OP_EXT1` can be prefixed. For those
with `"`, either `OP_EXT1` or `OP_EXT2` or `OP_EXT2` can be prefixed.
## table.1 Instruction Table
|Instruction Name |Operand type |Semantics
|-----------------|-------------|-----------------
|OP_NOP | - |
|OP_MOVE" |BB |R(a) = R(b)
|OP_LOADL" |BB |R(a) = Pool(b)
|OP_LOADI" |BsB |R(a) = mrb_int(b)
|OP_LOADI_0' |B |R(a) = 0
|OP_LOADI_1' |B |R(a) = 1
|OP_LOADI_2' |B |R(a) = 2
|OP_LOADI_3' |B |R(a) = 3
|OP_LOADSYM" |BB |R(a) = Syms(b)
|OP_LOADNIL' |B |R(a) = nil
|OP_LOADSELF' |B |R(a) = self
|OP_LOADT' |B |R(a) = true
|OP_LOADF' |B |R(a) = false
|OP_GETGV" |BB |R(a) = getglobal(Syms(b))
|OP_SETGV" |BB |setglobal(Syms(b), R(a))
|OP_GETSV" |BB |R(a) = Special[b]
|OP_SETSV" |BB |Special[b] = R(a)
|OP_GETIV" |BB |R(a) = ivget(Syms(b))
|OP_SETIV" |BB |ivset(Syms(b),R(a))
|OP_GETCV" |BB |R(a) = cvget(Syms(b))
|OP_SETCV" |BB |cvset(Syms(b),R(a))
|OP_GETCONST" |BB |R(a) = constget(Syms(b))
|OP_SETCONST" |BB |constset(Syms(b),R(a))
|OP_GETMCNST" |BB |R(a) = R(a)::Syms(b)
|OP_SETMCNST" |BB |R(a+1)::Syms(b) = R(a)
|OP_GETUPVAR' |BBB |R(a) = uvget(b,c)
|OP_SETUPVAR' |BBB |uvset(b,c,R(a))
|OP_JMP |S |pc+=a
|OP_JMPIF' |SB |if R(b) pc+=a
|OP_JMPNOT' |SB |if !R(b) pc+=a
|OP_ONERR |sS |rescue_push(pc+a)
|OP_EXCEPT' |B |R(a) = exc
|OP_RESCUE" |BB |R(b) = R(a).isa?(R(b))
|OP_POPERR |B |a.times{rescue_pop()}
|OP_RAISE' |B |raise(R(a))
|OP_EPUSH' |B |ensure_push(SEQ[a])
|OP_EPOP |B |A.times{ensure_pop().call}
|OP_SENDV" |BB |R(a) = call(R(a),Syms(b),*R(a+1))
|OP_SENDVB" |BB |R(a) = call(R(a),Syms(b),*R(a+1),&R(a+2))
|OP_SEND" |BBB |R(a) = call(R(a),Syms(b),R(a+1),...,R(a+c))
|OP_SENDB" |BBB |R(a) = call(R(a),Syms(Bx),R(a+1),...,R(a+c),&R(a+c+1))
|OP_CALL' |B |R(a) = self.call(frame.argc, frame.argv)
|OP_SUPER' |BB |R(a) = super(R(a+1),... ,R(a+b+1))
|OP_ARGARY' |BS |R(a) = argument array (16=5:1:5:1:4)
|OP_ENTER |W |arg setup according to flags (23=5:5:1:5:5:1:1)
|OP_KARG" |BB |R(a) = kdict[Syms(Bx)] # todo
|OP_KARG2" |BB |R(a) = kdict[Syms(Bx)]; kdict.rm(Syms(b)) # todo
|OP_RETURN' |B |return R(a) (normal)
|OP_RETURN_BLK' |B |return R(a) (in-block return)
|OP_BREAK' |B |break R(a)
|OP_BLKPUSH' |BS |R(a) = block (16=5:1:5:1:4)
|OP_ADD" |BB |R(a) = R(a)+R(a+1)
|OP_ADDI" |BBB |R(a) = R(a)+mrb_int(c)
|OP_SUB" |BB |R(a) = R(a)-R(a+1)
|OP_SUBI" |BB |R(a) = R(a)-C
|OP_MUL" |BB |R(a) = R(a)*R(a+1)
|OP_DIV" |BB |R(a) = R(a)/R(a+1)
|OP_EQ" |BB |R(a) = R(a)==R(a+1)
|OP_LT" |BB |R(a) = R(a)<R(a+1)
|OP_LE" |BB |R(a) = R(a)<=R(a+1)
|OP_GT" |BB |R(a) = R(a)>R(a+1)
|OP_GE" |BB |R(a) = R(a)>=R(a+1)
|OP_ARRAY' |BB |R(a) = ary_new(R(a),R(a+1)..R(a+b))
|OP_ARRAY2" |BB |R(a) = ary_new(R(b),R(b+1)..R(b+c))
|OP_ARYCAT' |B |ary_cat(R(a),R(a+1))
|OP_ARYPUSH' |B |ary_push(R(a),R(a+1))
|OP_AREF' |BB |R(a) = R(a)[b]
|OP_ASET' |BB |R(a)[b] = R(a+1)
|OP_APOST' |BB |*R(a),R(A+1)..R(A+C) = R(a)[B..]
|OP_STRING" |BB |R(a) = str_dup(Lit(b))
|OP_STRCAT' |B |str_cat(R(a),R(a+1))
|OP_HASH' |BB |R(a) = hash_new(R(a),R(a+1)..R(a+b))
|OP_HASHADD' |BB |R(a) = hash_push(R(a),R(a+1)..R(a+b))
|OP_LAMBDA" |BB |R(a) = lambda(SEQ[b],OP_L_LAMBDA)
|OP_BLOCK" |BB |R(a) = lambda(SEQ[b],OP_L_BLOCK)
|OP_METHOD" |BB |R(a) = lambda(SEQ[b],OP_L_METHOD)
|OP_RANGE_INC' |B |R(a) = range_new(R(a),R(a+1),FALSE)
|OP_RANGE_EXC' |B |R(a) = range_new(R(a),R(a+1),TRUE)
|OP_OCLASS' |B |R(a) = ::Object
|OP_CLASS" |BB |R(a) = newclass(R(a),Syms(b),R(a+1))
|OP_MODULE" |BB |R(a) = newmodule(R(a),Syms(b))
|OP_EXEC" |BB |R(a) = blockexec(R(a),SEQ[b])
|OP_DEF" |BB |R(a).newmethod(Syms(b),R(a+1))
|OP_ALIAS' |B |alias_method(R(a),R(a+1),R(a+2))
|OP_UNDEF" |BB |undef_method(R(a),Syms(b))
|OP_SCLASS' |B |R(a) = R(a).singleton_class
|OP_TCLASS' |B |R(a) = target_class
|OP_ERR' |B |raise(RuntimeError, Lit(Bx))
|OP_EXT1 |- |make 1st operand 16bit
|OP_EXT2 |- |make 2nd operand 16bit
|OP_EXT3 |- |make 1st and 2nd operands 16bit
|OP_STOP |- |stop VM
@@ -1,5 +1,5 @@
module CRubyExtension
def CRubyExtension.ruby_method
puts "A Ruby Extension"
puts "#{self}: A Ruby Extension"
end
end
@@ -1,10 +1,13 @@
#include <mruby.h>
#include <mruby/string.h>
#include <stdio.h>
static mrb_value
mrb_c_method(mrb_state *mrb, mrb_value self)
{
puts("A C Extension");
mrb_ensure_string_type(mrb, self);
printf("%s: A C Extension\n", mrb_str_to_cstr(mrb, self));
return self;
}
@@ -1,10 +1,13 @@
#include <mruby.h>
#include <mruby/string.h>
#include <stdio.h>
static mrb_value
mrb_c_method(mrb_state *mrb, mrb_value self)
{
puts("A C Extension");
mrb_ensure_string_type(mrb, self);
printf("%s: A C Extension\n", mrb_str_to_cstr(mrb, self));
return self;
}
@@ -1,5 +1,5 @@
class RubyExtension
def RubyExtension.ruby_method
puts "A Ruby Extension"
puts "#{self}: A Ruby Extension"
end
end
@@ -1,26 +0,0 @@
MRuby::Build.new do |conf|
# Gets set by the VS command prompts.
if ENV['VisualStudioVersion'] || ENV['VSINSTALLDIR']
toolchain :visualcpp
else
toolchain :gcc
end
enable_debug
# include the default GEMs
conf.gembox 'default'
end
# Requires Android NDK r13 or later.
MRuby::CrossBuild.new('android-arm64-v8a') do |conf|
params = {
:arch => 'arm64-v8a',
:platform => 'android-24',
:toolchain => :clang,
}
toolchain :android, params
conf.gembox 'default'
end
@@ -1,26 +0,0 @@
MRuby::Build.new do |conf|
# Gets set by the VS command prompts.
if ENV['VisualStudioVersion'] || ENV['VSINSTALLDIR']
toolchain :visualcpp
else
toolchain :gcc
end
enable_debug
# include the default GEMs
conf.gembox 'default'
end
# Requires Android NDK r13 or later.
MRuby::CrossBuild.new('android-armeabi') do |conf|
params = {
:arch => 'armeabi',
:platform => 'android-24',
:toolchain => :clang,
}
toolchain :android, params
conf.gembox 'default'
end
+143 -54
View File
@@ -7,9 +7,6 @@
#ifndef MRUBYCONF_H
#define MRUBYCONF_H
#include <limits.h>
#include <stdint.h>
/* architecture selection: */
/* specify -DMRB_32BIT or -DMRB_64BIT to override */
#if !defined(MRB_32BIT) && !defined(MRB_64BIT)
@@ -25,30 +22,76 @@
#endif
/* configuration options: */
/* add -DMRB_USE_FLOAT to use float instead of double for floating point numbers */
//#define MRB_USE_FLOAT
/* add -DMRB_USE_FLOAT32 to use float instead of double for floating-point numbers */
//#define MRB_USE_FLOAT32
/* exclude floating point numbers */
//#define MRB_WITHOUT_FLOAT
/* exclude floating-point numbers */
//#define MRB_NO_FLOAT
/* add -DMRB_METHOD_CACHE to use method cache to improve performance */
//#define MRB_METHOD_CACHE
/* obsolete configuration */
#if defined(MRB_USE_FLOAT)
# define MRB_USE_FLOAT32
#endif
/* obsolete configuration */
#if defined(MRB_WITHOUT_FLOAT)
# define MRB_NO_FLOAT
#endif
#if defined(MRB_USE_FLOAT32) && defined(MRB_NO_FLOAT)
#error Cannot define MRB_USE_FLOAT32 and MRB_NO_FLOAT at the same time
#endif
/* add -DMRB_NO_METHOD_CACHE to disable method cache to save memory */
//#define MRB_NO_METHOD_CACHE
/* size of the method cache (need to be the power of 2) */
//#define MRB_METHOD_CACHE_SIZE (1<<7)
//#define MRB_METHOD_CACHE_SIZE (1<<8)
/* add -DMRB_METHOD_TABLE_INLINE to reduce the size of method table */
/* MRB_METHOD_TABLE_INLINE requires LSB of function pointers to be zero */
/* you might need to specify --falign-functions=n (where n>1) */
//#define MRB_METHOD_TABLE_INLINE
/* add -DMRB_USE_METHOD_T_STRUCT on machines that use higher bits of function pointers */
/* no MRB_USE_METHOD_T_STRUCT requires highest 2 bits of function pointers to be zero */
#ifndef MRB_USE_METHOD_T_STRUCT
// can't use highest 2 bits of function pointers at least on 32bit
// Windows and 32bit Linux.
# ifdef MRB_32BIT
# define MRB_USE_METHOD_T_STRUCT
# endif
#endif
/* add -DMRB_INT16 to use 16bit integer for mrb_int; conflict with MRB_INT64 */
//#define MRB_INT16
/* define on big endian machines; used by MRB_NAN_BOXING, etc. */
#ifndef MRB_ENDIAN_BIG
# if (defined(BYTE_ORDER) && defined(BIG_ENDIAN) && BYTE_ORDER == BIG_ENDIAN) || \
(defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
# define MRB_ENDIAN_BIG
# endif
#endif
/* add -DMRB_INT64 to use 64bit integer for mrb_int; conflict with MRB_INT16 */
/* represent mrb_value in boxed double; conflict with MRB_USE_FLOAT32 and MRB_NO_FLOAT */
//#define MRB_NAN_BOXING
/* represent mrb_value as a word (natural unit of data for the processor) */
//#define MRB_WORD_BOXING
/* represent mrb_value as a struct; occupies 2 words */
//#define MRB_NO_BOXING
/* if no specific boxing type is chosen */
#if !defined(MRB_NAN_BOXING) && !defined(MRB_WORD_BOXING) && !defined(MRB_NO_BOXING)
# define MRB_WORD_BOXING
#endif
/* if defined mruby allocates Float objects in the heap to keep full precision if needed */
//#define MRB_WORDBOX_NO_FLOAT_TRUNCATE
/* add -DMRB_INT32 to use 32bit integer for mrb_int; conflict with MRB_INT64;
Default for 32-bit CPU mode. */
//#define MRB_INT32
/* add -DMRB_INT64 to use 64bit integer for mrb_int; conflict with MRB_INT32;
Default for 64-bit CPU mode (unless using MRB_NAN_BOXING). */
//#define MRB_INT64
/* if no specific integer type is chosen */
#if !defined(MRB_INT16) && !defined(MRB_INT32) && !defined(MRB_INT64)
#if !defined(MRB_INT32) && !defined(MRB_INT64)
# if defined(MRB_64BIT) && !defined(MRB_NAN_BOXING)
/* Use 64bit integers on 64bit architecture (without MRB_NAN_BOXING) */
# define MRB_INT64
@@ -58,14 +101,8 @@
# endif
#endif
/* represent mrb_value in boxed double; conflict with MRB_USE_FLOAT and MRB_WITHOUT_FLOAT */
//#define MRB_NAN_BOXING
/* define on big endian machines; used by MRB_NAN_BOXING */
//#define MRB_ENDIAN_BIG
/* represent mrb_value as a word (natural unit of data for the processor) */
//#define MRB_WORD_BOXING
/* call malloc_trim(0) from mrb_full_gc() */
//#define MRB_USE_MALLOC_TRIM
/* string class to handle UTF-8 encoding */
//#define MRB_UTF8_STRING
@@ -76,12 +113,19 @@
/* number of object per heap page */
//#define MRB_HEAP_PAGE_SIZE 1024
/* if _etext and _edata available, mruby can reduce memory used by symbols */
//#define MRB_USE_ETEXT_EDATA
/* define if your platform does not support etext, edata */
//#define MRB_NO_DEFAULT_RO_DATA_P
/* do not use __init_array_start to determine readonly data section;
effective only when MRB_USE_ETEXT_EDATA is defined */
//#define MRB_NO_INIT_ARRAY_START
/* define if your platform supports etext, edata */
//#define MRB_USE_RO_DATA_P_ETEXT
/* use MRB_USE_ETEXT_RO_DATA_P by default on Linux */
#if (defined(__linux__) && !defined(__KERNEL__))
#define MRB_USE_ETEXT_RO_DATA_P
#endif
/* you can provide and use mrb_ro_data_p() for your platform.
prototype is `mrb_bool mrb_ro_data_p(const char *ptr)` */
//#define MRB_USE_CUSTOM_RO_DATA_P
/* turn off generational GC by default */
//#define MRB_GC_TURN_OFF_GENERATIONAL
@@ -95,9 +139,6 @@
/* page size of memory pool */
//#define POOL_PAGE_SIZE 16000
/* initial minimum size for string buffer */
//#define MRB_STR_BUF_MIN_SIZE 128
/* arena size */
//#define MRB_GC_ARENA_SIZE 100
@@ -110,34 +151,82 @@
/* fixed size state atexit stack */
//#define MRB_FIXED_STATE_ATEXIT_STACK
/* -DMRB_DISABLE_XXXX to drop following features */
//#define MRB_DISABLE_STDIO /* use of stdio */
/* -DMRB_NO_XXXX to drop following features */
//#define MRB_NO_STDIO /* use of stdio */
/* -DMRB_ENABLE_XXXX to enable following features */
//#define MRB_ENABLE_DEBUG_HOOK /* hooks for debugger */
/* -DMRB_USE_XXXX to enable following features */
//#define MRB_USE_DEBUG_HOOK /* hooks for debugger */
//#define MRB_USE_ALL_SYMBOLS /* Symbol.all_symbols */
/* obsolete configurations */
#ifdef MRB_METHOD_T_STRUCT
# define MRB_USE_METHOD_T_STRUCT
#endif
#if defined(DISABLE_STDIO) || defined(MRB_DISABLE_STDIO)
# define MRB_NO_STDIO
#endif
#ifdef MRB_DISABLE_DIRECT_THREADING
# define MRB_NO_DIRECT_THREADING
#endif
#if defined(ENABLE_DEBUG) || defined(MRB_ENABLE_DEBUG_HOOK)
# define MRB_USE_DEBUG_HOOK
#endif
#ifdef MRB_ENABLE_ALL_SYMBOLS
# define MRB_USE_ALL_SYMBOLS
#endif
#ifdef MRB_ENABLE_CXX_ABI
# define MRB_USE_CXX_ABI
#endif
#ifdef MRB_ENABLE_CXX_EXCEPTION
# define MRB_USE_CXX_EXCEPTION
#endif
/* end of configuration */
/* define MRB_DISABLE_XXXX from DISABLE_XXX (for compatibility) */
#ifdef DISABLE_STDIO
#define MRB_DISABLE_STDIO
#endif
/* define MRB_ENABLE_XXXX from ENABLE_XXX (for compatibility) */
#ifdef ENABLE_DEBUG
#define MRB_ENABLE_DEBUG_HOOK
#endif
#ifndef MRB_DISABLE_STDIO
#ifndef MRB_NO_STDIO
# include <stdio.h>
#endif
#ifndef FALSE
# define FALSE 0
#endif
/*
** mruby tuning profiles
**/
#ifndef TRUE
# define TRUE 1
/* A profile for micro controllers */
#if defined(MRB_CONSTRAINED_BASELINE_PROFILE)
# ifndef MRB_NO_METHOD_CACHE
# define MRB_NO_METHOD_CACHE
# endif
# ifndef KHASH_DEFAULT_SIZE
# define KHASH_DEFAULT_SIZE 16
# endif
# ifndef MRB_HEAP_PAGE_SIZE
# define MRB_HEAP_PAGE_SIZE 256
# endif
/* A profile for default mruby */
#elif defined(MRB_BASELINE_PROFILE)
/* A profile for desktop computers or workstations; rich memory! */
#elif defined(MRB_MAIN_PROFILE)
# ifndef MRB_METHOD_CACHE_SIZE
# define MRB_METHOD_CACHE_SIZE (1<<10)
# endif
# ifndef MRB_HEAP_PAGE_SIZE
# define MRB_HEAP_PAGE_SIZE 4096
# endif
/* A profile for server; mruby vm is long life */
#elif defined(MRB_HIGH_PROFILE)
# ifndef MRB_METHOD_CACHE_SIZE
# define MRB_METHOD_CACHE_SIZE (1<<12)
# endif
# ifndef MRB_HEAP_PAGE_SIZE
# define MRB_HEAP_PAGE_SIZE 4096
# endif
#endif
#endif /* MRUBYCONF_H */
+468 -236
View File
File diff suppressed because it is too large Load Diff
+53 -29
View File
@@ -1,5 +1,5 @@
/*
** mruby/array.h - Array class
/**
** @file mruby/array.h - Array class
**
** See Copyright Notice in mruby.h
*/
@@ -14,26 +14,37 @@
*/
MRB_BEGIN_DECL
typedef struct mrb_shared_array {
int refcnt;
mrb_int len;
mrb_ssize len;
mrb_value *ptr;
} mrb_shared_array;
#define MRB_ARY_EMBED_LEN_MAX ((mrb_int)(sizeof(void*)*3/sizeof(mrb_value)))
#if defined(MRB_32BIT) && defined(MRB_NO_BOXING) && !defined(MRB_USE_FLOAT32) && !defined(MRB_ARY_NO_EMBED)
# define MRB_ARY_NO_EMBED
#endif
#ifdef MRB_ARY_NO_EMBED
# define MRB_ARY_EMBED_LEN_MAX 0
#else
# define MRB_ARY_EMBED_LEN_MAX ((mrb_int)(sizeof(void*)*3/sizeof(mrb_value)))
mrb_static_assert(MRB_ARY_EMBED_LEN_MAX > 0, "MRB_ARY_EMBED_LEN_MAX > 0");
#endif
struct RArray {
MRB_OBJECT_HEADER;
union {
struct {
mrb_int len;
mrb_ssize len;
union {
mrb_int capa;
mrb_ssize capa;
mrb_shared_array *shared;
} aux;
mrb_value *ptr;
} heap;
mrb_value embed[MRB_ARY_EMBED_LEN_MAX];
#ifndef MRB_ARY_NO_EMBED
mrb_value ary[MRB_ARY_EMBED_LEN_MAX];
#endif
} as;
};
@@ -41,14 +52,22 @@ struct RArray {
#define mrb_ary_value(p) mrb_obj_value((void*)(p))
#define RARRAY(v) ((struct RArray*)(mrb_ptr(v)))
#ifdef MRB_ARY_NO_EMBED
#define ARY_EMBED_P(a) 0
#define ARY_UNSET_EMBED_FLAG(a) (void)0
#define ARY_EMBED_LEN(a) 0
#define ARY_SET_EMBED_LEN(a,len) (void)0
#define ARY_EMBED_PTR(a) 0
#else
#define MRB_ARY_EMBED_MASK 7
#define ARY_EMBED_P(a) ((a)->flags & MRB_ARY_EMBED_MASK)
#define ARY_UNSET_EMBED_FLAG(a) ((a)->flags &= ~(MRB_ARY_EMBED_MASK))
#define ARY_EMBED_LEN(a) ((mrb_int)(((a)->flags & MRB_ARY_EMBED_MASK) - 1))
#define ARY_SET_EMBED_LEN(a,len) ((a)->flags = ((a)->flags&~MRB_ARY_EMBED_MASK) | ((uint32_t)(len) + 1))
#define ARY_EMBED_PTR(a) (&((a)->as.embed[0]))
#define ARY_EMBED_PTR(a) ((a)->as.ary)
#endif
#define ARY_LEN(a) (ARY_EMBED_P(a)?ARY_EMBED_LEN(a):(a)->as.heap.len)
#define ARY_LEN(a) (ARY_EMBED_P(a)?ARY_EMBED_LEN(a):(mrb_int)(a)->as.heap.len)
#define ARY_PTR(a) (ARY_EMBED_P(a)?ARY_EMBED_PTR(a):(a)->as.heap.ptr)
#define RARRAY_LEN(a) ARY_LEN(RARRAY(a))
#define RARRAY_PTR(a) ARY_PTR(RARRAY(a))
@@ -90,7 +109,7 @@ MRB_API mrb_value mrb_ary_new(mrb_state *mrb);
* Array[value1, value2, ...]
*
* @param mrb The mruby state reference.
* @param size The numer of values.
* @param size The number of values.
* @param vals The actual values.
* @return The initialized array.
*/
@@ -159,20 +178,6 @@ MRB_API void mrb_ary_push(mrb_state *mrb, mrb_value array, mrb_value value);
*/
MRB_API mrb_value mrb_ary_pop(mrb_state *mrb, mrb_value ary);
/*
* Returns a reference to an element of the array on the given index.
*
* Equivalent to:
*
* ary[n]
*
* @param mrb The mruby state reference.
* @param ary The target array.
* @param n The array index being referenced
* @return The referenced value.
*/
MRB_API mrb_value mrb_ary_ref(mrb_state *mrb, mrb_value ary, mrb_int n);
/*
* Sets a value on an array at the given index
*
@@ -183,7 +188,7 @@ MRB_API mrb_value mrb_ary_ref(mrb_state *mrb, mrb_value ary, mrb_int n);
* @param mrb The mruby state reference.
* @param ary The target array.
* @param n The array index being referenced.
* @param val The value being setted.
* @param val The value being set.
*/
MRB_API void mrb_ary_set(mrb_state *mrb, mrb_value ary, mrb_int n, mrb_value val);
@@ -199,8 +204,6 @@ MRB_API void mrb_ary_set(mrb_state *mrb, mrb_value ary, mrb_int n, mrb_value val
* @param other The array to replace it with.
*/
MRB_API void mrb_ary_replace(mrb_state *mrb, mrb_value self, mrb_value other);
MRB_API mrb_value mrb_ensure_array_type(mrb_state *mrb, mrb_value self);
MRB_API mrb_value mrb_check_array_type(mrb_state *mrb, mrb_value self);
/*
* Unshift an element into the array
@@ -226,6 +229,24 @@ MRB_API mrb_value mrb_ary_unshift(mrb_state *mrb, mrb_value self, mrb_value item
* @param offset The element position (negative counts from the tail).
*/
MRB_API mrb_value mrb_ary_entry(mrb_value ary, mrb_int offset);
#define mrb_ary_ref(mrb, ary, n) mrb_ary_entry(ary, n)
/*
* Replace subsequence of an array.
*
* Equivalent to:
*
* ary[head, len] = rpl
*
* @param mrb The mruby state reference.
* @param self The array from which the value will be partiality replaced.
* @param head Beginning position of a replacement subsequence.
* @param len Length of a replacement subsequence.
* @param rpl The array of replacement elements.
* It is possible to pass `mrb_undef_value()` instead of an empty array.
* @return The receiver array.
*/
MRB_API mrb_value mrb_ary_splice(mrb_state *mrb, mrb_value self, mrb_int head, mrb_int len, mrb_value rpl);
/*
* Shifts the first element from the array.
@@ -262,7 +283,7 @@ MRB_API mrb_value mrb_ary_clear(mrb_state *mrb, mrb_value self);
*
* @param mrb The mruby state reference.
* @param ary The target array
* @param sep The separater, can be NULL
* @param sep The separator, can be NULL
*/
MRB_API mrb_value mrb_ary_join(mrb_state *mrb, mrb_value ary, mrb_value sep);
@@ -275,6 +296,9 @@ MRB_API mrb_value mrb_ary_join(mrb_state *mrb, mrb_value ary, mrb_value sep);
*/
MRB_API mrb_value mrb_ary_resize(mrb_state *mrb, mrb_value ary, mrb_int new_len);
/* helper functions */
mrb_value mrb_ary_subseq(mrb_state *mrb, mrb_value ary, mrb_int beg, mrb_int len);
MRB_END_DECL
#endif /* MRUBY_ARRAY_H */
+135 -78
View File
@@ -1,5 +1,5 @@
/*
** mruby/boxing_nan.h - nan boxing mrb_value definition
/**
** @file mruby/boxing_nan.h - nan boxing mrb_value definition
**
** See Copyright Notice in mruby.h
*/
@@ -7,96 +7,153 @@
#ifndef MRUBY_BOXING_NAN_H
#define MRUBY_BOXING_NAN_H
#ifdef MRB_USE_FLOAT
# error ---->> MRB_NAN_BOXING and MRB_USE_FLOAT conflict <<----
#ifdef MRB_USE_FLOAT32
# error ---->> MRB_NAN_BOXING and MRB_USE_FLOAT32 conflict <<----
#endif
#ifdef MRB_WITHOUT_FLOAT
# error ---->> MRB_NAN_BOXING and MRB_WITHOUT_FLOAT conflict <<----
#ifdef MRB_NO_FLOAT
# error ---->> MRB_NAN_BOXING and MRB_NO_FLOAT conflict <<----
#endif
#ifdef MRB_INT64
# error ---->> MRB_NAN_BOXING and MRB_INT64 conflict <<----
#endif
#define MRB_FIXNUM_MIN INT32_MIN
#define MRB_FIXNUM_MAX INT32_MAX
#define MRB_FIXNUM_SHIFT 0
#define MRB_TT_HAS_BASIC MRB_TT_OBJECT
#ifdef MRB_ENDIAN_BIG
#define MRB_ENDIAN_LOHI(a,b) a b
#else
#define MRB_ENDIAN_LOHI(a,b) b a
#endif
enum mrb_nanbox_tt_inline {
MRB_NANBOX_TT_OBJECT = 0,
MRB_NANBOX_TT_INTEGER = 1,
MRB_NANBOX_TT_MISC = 2,
MRB_NANBOX_TT_CPTR = 3,
};
/* value representation by nan-boxing:
* float : FFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFF
* object: 111111111111TTTT TTPPPPPPPPPPPPPP PPPPPPPPPPPPPPPP PPPPPPPPPPPPPPPP
* int : 1111111111110001 0000000000000000 IIIIIIIIIIIIIIII IIIIIIIIIIIIIIII
* sym : 1111111111110001 0100000000000000 SSSSSSSSSSSSSSSS SSSSSSSSSSSSSSSS
* In order to get enough bit size to save TT, all pointers are shifted 2 bits
* in the right direction. Also, TTTTTT is the mrb_vtype + 1;
* float : SEEEEEEE EEEEFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF
* +/-inf: S1111111 11110000 00000000 00000000 00000000 00000000 00000000 00000000
* nan : 01111111 11111000 00000000 00000000 00000000 00000000 00000000 00000000
* int : 01111111 11111001 00000000 00000000 IIIIIIII IIIIIIII IIIIIIII IIIIIIII
* sym : 01111111 11111110 00000000 00TTTTTT SSSSSSSS SSSSSSSS SSSSSSSS SSSSSSSS
* misc : 01111111 11111110 00000000 00TTTTTT 00000000 00000000 00000000 0000MMMM
* object: 01111111 11111100 PPPPPPPP PPPPPPPP PPPPPPPP PPPPPPPP PPPPPPPP PPPPPP00
* cptr : 01111111 11111111 PPPPPPPP PPPPPPPP PPPPPPPP PPPPPPPP PPPPPPPP PPPPPPPP
* Stored as O = R + 0x8004000000000000, retrieved as R = O - 0x8004000000000000.
* This makes pointers have all zeros in the top 32 bits.
*/
typedef struct mrb_value {
union {
mrb_float f;
union {
void *p;
struct {
MRB_ENDIAN_LOHI(
uint32_t ttt;
,union {
mrb_int i;
mrb_sym sym;
};
)
};
} value;
};
uint64_t u;
} mrb_value;
#define mrb_float_pool(mrb,f) mrb_float_value(mrb,f)
static inline mrb_float
mrb_nan_boxing_value_float(mrb_value v)
{
union {
mrb_float f;
uint64_t u;
} x;
x.u = v.u - 0x8004000000000000;
return x.f;
}
#define mrb_tt(o) ((enum mrb_vtype)(((o).value.ttt & 0xfc000)>>14)-1)
#define mrb_type(o) (enum mrb_vtype)((uint32_t)0xfff00000 < (o).value.ttt ? mrb_tt(o) : MRB_TT_FLOAT)
#define mrb_ptr(o) ((void*)((((uintptr_t)0x3fffffffffff)&((uintptr_t)((o).value.p)))<<2))
#define mrb_float(o) (o).f
#define mrb_cptr(o) mrb_ptr(o)
#define mrb_fixnum(o) (o).value.i
#define mrb_symbol(o) (o).value.sym
#ifdef MRB_64BIT
#define BOXNAN_SHIFT_LONG_POINTER(v) (((uintptr_t)(v)>>34)&0x3fff)
#else
#define BOXNAN_SHIFT_LONG_POINTER(v) 0
#endif
#define BOXNAN_SET_VALUE(o, tt, attr, v) do {\
(o).attr = (v);\
(o).value.ttt = 0xfff00000 | (((tt)+1)<<14);\
} while (0)
#define BOXNAN_SET_OBJ_VALUE(o, tt, v) do {\
(o).value.p = (void*)((uintptr_t)(v)>>2);\
(o).value.ttt = (0xfff00000|(((tt)+1)<<14)|BOXNAN_SHIFT_LONG_POINTER(v));\
} while (0)
#define SET_FLOAT_VALUE(mrb,r,v) do { \
if (v != v) { \
(r).value.ttt = 0x7ff80000; \
(r).value.i = 0; \
#define SET_FLOAT_VALUE(mrb,r,f) do { \
union { \
mrb_float f; \
uint64_t u; \
} float_uint_union; \
if ((f) != (f)) { /* NaN */ \
float_uint_union.u = 0x7ff8000000000000UL; \
} \
else { \
(r).f = v; \
}} while(0)
float_uint_union.f = (f); \
} \
r.u = float_uint_union.u + 0x8004000000000000; \
} while(0)
#define SET_NIL_VALUE(r) BOXNAN_SET_VALUE(r, MRB_TT_FALSE, value.i, 0)
#define SET_FALSE_VALUE(r) BOXNAN_SET_VALUE(r, MRB_TT_FALSE, value.i, 1)
#define SET_TRUE_VALUE(r) BOXNAN_SET_VALUE(r, MRB_TT_TRUE, value.i, 1)
#define SET_BOOL_VALUE(r,b) BOXNAN_SET_VALUE(r, b ? MRB_TT_TRUE : MRB_TT_FALSE, value.i, 1)
#define SET_INT_VALUE(r,n) BOXNAN_SET_VALUE(r, MRB_TT_FIXNUM, value.i, (n))
#define SET_SYM_VALUE(r,v) BOXNAN_SET_VALUE(r, MRB_TT_SYMBOL, value.sym, (v))
#define SET_OBJ_VALUE(r,v) BOXNAN_SET_OBJ_VALUE(r, (((struct RObject*)(v))->tt), (v))
#define SET_CPTR_VALUE(mrb,r,v) BOXNAN_SET_OBJ_VALUE(r, MRB_TT_CPTR, v)
#define SET_UNDEF_VALUE(r) BOXNAN_SET_VALUE(r, MRB_TT_UNDEF, value.i, 0)
#define mrb_float_p(o) (((uint64_t)((o).u)&0xfffc000000000000) != 0)
struct RInteger {
MRB_OBJECT_HEADER;
mrb_int i;
};
#define mrb_nb_tt(o) ((enum mrb_nanbox_tt_inline)((uint32_t)((o).u>>48)&3))
MRB_INLINE enum mrb_vtype
mrb_type(mrb_value o)
{
if (mrb_float_p(o)) return MRB_TT_FLOAT;
int64_t u = o.u;
switch (mrb_nb_tt(o)) {
case MRB_NANBOX_TT_OBJECT: {
if (u == 0) return MRB_TT_FALSE;
return ((struct RBasic*)(uintptr_t)u)->tt;
}
case MRB_NANBOX_TT_INTEGER:
return MRB_TT_INTEGER;
case MRB_NANBOX_TT_MISC:
return (enum mrb_vtype)((uint32_t)(o.u >> 32) & 0x1f);
case MRB_NANBOX_TT_CPTR:
return MRB_TT_CPTR;
default:
/* never happen */
return MRB_TT_FLOAT;
}
}
#define NANBOX_SET_MISC_VALUE(r,t,i) NANBOX_SET_VALUE(r, MRB_NANBOX_TT_MISC, ((uint64_t)(t)<<32) | (i))
#define mrb_float(o) mrb_nan_boxing_value_float(o)
#ifdef MRB_INT64
/*
#ifdef MRB_32BIT
#define mrb_fixnum(o) ((mrb_int)((intptr_t)0xffffffffffff&((o).u))|(((o).u & 0x800000000000)?0xffff000000000000:0))
#else
#define mrb_fixnum(o) ((mrb_int)(int32_t)((o).u))
#endif
*/
#define mrb_fixnum(o) ((mrb_int)(int32_t)((o).u))
static inline mrb_int
mrb_nan_boxing_value_int(mrb_value v)
{
uint64_t u = v.u;
if (mrb_nb_tt(v)==MRB_NANBOX_TT_OBJECT) {
struct RInteger *p = (struct RInteger*)(uintptr_t)u;
return p->i;
}
return mrb_fixnum(v);
}
#define mrb_integer(o) mrb_nan_boxing_value_int(o)
#else
#define mrb_fixnum(o) ((mrb_int)(((uintptr_t)0xffffffff)&((o).u)))
#define mrb_integer(o) mrb_fixnum(o)
#endif
#define mrb_symbol(o) ((mrb_sym)((uintptr_t)0xffffffff)&((o).u))
#define mrb_ptr(o) ((void*)(uintptr_t)(o).u)
#define mrb_cptr(o) ((void*)(uintptr_t)(0xffffffffffffULL&(o).u))
#define NANBOX_SET_VALUE(o, tt, v) do { \
(o).u = ((uint64_t)(tt)<<48) | ((uint64_t)(v)); \
} while (0)
#define SET_NIL_VALUE(r) ((r).u = 0)
#define SET_FALSE_VALUE(r) NANBOX_SET_MISC_VALUE(r, MRB_TT_FALSE, 1)
#define SET_TRUE_VALUE(r) NANBOX_SET_MISC_VALUE(r, MRB_TT_TRUE, 1)
#define SET_BOOL_VALUE(r,b) NANBOX_SET_MISC_VALUE(r, (b) ? MRB_TT_TRUE : MRB_TT_FALSE, 1)
#ifdef MRB_INT64
MRB_API mrb_value mrb_boxing_int_value(struct mrb_state*, mrb_int);
#define SET_INT_VALUE(mrb, r, n) ((r) = mrb_boxing_int_value(mrb, n))
#else
#define SET_INT_VALUE(mrb, r, n) SET_FIXNUM_VALUE(r, n)
#endif
#define SET_FIXNUM_VALUE(r,n) NANBOX_SET_VALUE(r, MRB_NANBOX_TT_INTEGER, (uint32_t)(n))
#define SET_SYM_VALUE(r,v) NANBOX_SET_MISC_VALUE(r, MRB_TT_SYMBOL, (uint32_t)(v))
#define SET_OBJ_VALUE(r,v) do {(r).u = (uint64_t)(uintptr_t)(v);} while (0)
#define SET_CPTR_VALUE(mrb,r,v) NANBOX_SET_VALUE(r, MRB_NANBOX_TT_CPTR, (uint64_t)(uintptr_t)(v) & 0x0000ffffffffffffULL)
#define SET_UNDEF_VALUE(r) NANBOX_SET_MISC_VALUE(r, MRB_TT_UNDEF, 4)
#define mrb_immediate_p(o) ((mrb_float_p(o) || mrb_nb_tt(o) != MRB_NANBOX_TT_OBJECT) || (o).u == 0)
#define mrb_nil_p(o) ((o).u == 0)
#define mrb_false_p(o) (mrb_type(o) == MRB_TT_FALSE || (o).u == 0)
#define mrb_fixnum_p(o) (!mrb_float_p(o) && mrb_nb_tt(o)==MRB_NANBOX_TT_INTEGER)
#endif /* MRUBY_BOXING_NAN_H */
+20 -18
View File
@@ -1,5 +1,5 @@
/*
** mruby/boxing_no.h - unboxed mrb_value definition
/**
** @file mruby/boxing_no.h - unboxed mrb_value definition
**
** See Copyright Notice in mruby.h
*/
@@ -8,30 +8,31 @@
#define MRUBY_BOXING_NO_H
#define MRB_FIXNUM_SHIFT 0
#define MRB_TT_HAS_BASIC MRB_TT_OBJECT
#define MRB_SYMBOL_SHIFT 0
#define MRB_FIXNUM_MIN MRB_INT_MIN
#define MRB_FIXNUM_MAX MRB_INT_MAX
union mrb_value_union {
#ifndef MRB_NO_FLOAT
mrb_float f;
#endif
void *p;
mrb_int i;
mrb_sym sym;
};
typedef struct mrb_value {
union {
#ifndef MRB_WITHOUT_FLOAT
mrb_float f;
#endif
void *p;
mrb_int i;
mrb_sym sym;
} value;
union mrb_value_union value;
enum mrb_vtype tt;
} mrb_value;
#ifndef MRB_WITHOUT_FLOAT
#define mrb_float_pool(mrb,f) mrb_float_value(mrb,f)
#endif
#define mrb_ptr(o) (o).value.p
#define mrb_cptr(o) mrb_ptr(o)
#ifndef MRB_WITHOUT_FLOAT
#ifndef MRB_NO_FLOAT
#define mrb_float(o) (o).value.f
#endif
#define mrb_fixnum(o) (o).value.i
#define mrb_integer(o) mrb_fixnum(o)
#define mrb_symbol(o) (o).value.sym
#define mrb_type(o) (o).tt
@@ -44,8 +45,9 @@ typedef struct mrb_value {
#define SET_FALSE_VALUE(r) BOXNIX_SET_VALUE(r, MRB_TT_FALSE, value.i, 1)
#define SET_TRUE_VALUE(r) BOXNIX_SET_VALUE(r, MRB_TT_TRUE, value.i, 1)
#define SET_BOOL_VALUE(r,b) BOXNIX_SET_VALUE(r, b ? MRB_TT_TRUE : MRB_TT_FALSE, value.i, 1)
#define SET_INT_VALUE(r,n) BOXNIX_SET_VALUE(r, MRB_TT_FIXNUM, value.i, (n))
#ifndef MRB_WITHOUT_FLOAT
#define SET_INT_VALUE(mrb,r,n) BOXNIX_SET_VALUE(r, MRB_TT_INTEGER, value.i, (n))
#define SET_FIXNUM_VALUE(r,n) BOXNIX_SET_VALUE(r, MRB_TT_INTEGER, value.i, (n))
#ifndef MRB_NO_FLOAT
#define SET_FLOAT_VALUE(mrb,r,v) BOXNIX_SET_VALUE(r, MRB_TT_FLOAT, value.f, (v))
#endif
#define SET_SYM_VALUE(r,v) BOXNIX_SET_VALUE(r, MRB_TT_SYMBOL, value.sym, (v))
+192 -105
View File
@@ -1,5 +1,5 @@
/*
** mruby/boxing_word.h - word boxing mrb_value definition
/**
** @file mruby/boxing_word.h - word boxing mrb_value definition
**
** See Copyright Notice in mruby.h
*/
@@ -7,138 +7,225 @@
#ifndef MRUBY_BOXING_WORD_H
#define MRUBY_BOXING_WORD_H
#if defined(MRB_INT16)
# error MRB_INT16 is too small for MRB_WORD_BOXING.
#if defined(MRB_32BIT) && !defined(MRB_USE_FLOAT32) && !defined(MRB_WORDBOX_NO_FLOAT_TRUNCATE)
# define MRB_WORDBOX_NO_FLOAT_TRUNCATE
#endif
#if defined(MRB_INT64) && !defined(MRB_64BIT)
#error MRB_INT64 cannot be used with MRB_WORD_BOXING in 32-bit mode.
#endif
#ifndef MRB_WITHOUT_FLOAT
#if !defined(MRB_NO_FLOAT) && defined(MRB_WORDBOX_NO_FLOAT_TRUNCATE)
struct RFloat {
MRB_OBJECT_HEADER;
mrb_float f;
};
#endif
struct RCptr {
struct RInteger {
MRB_OBJECT_HEADER;
void *p;
mrb_int i;
};
#define MRB_FIXNUM_SHIFT 1
#ifdef MRB_WITHOUT_FLOAT
#define MRB_TT_HAS_BASIC MRB_TT_CPTR
#else
#define MRB_TT_HAS_BASIC MRB_TT_FLOAT
#endif
enum mrb_special_consts {
MRB_Qnil = 0,
MRB_Qfalse = 2,
MRB_Qtrue = 4,
MRB_Qundef = 6,
MRB_Qnil = 0,
MRB_Qfalse = 4,
MRB_Qtrue = 12,
MRB_Qundef = 20,
};
#define MRB_FIXNUM_FLAG 0x01
#define MRB_SYMBOL_FLAG 0x0e
#define MRB_SPECIAL_SHIFT 8
#if defined(MRB_64BIT)
#define MRB_SYMBOL_BITSIZE (sizeof(mrb_sym) * CHAR_BIT)
#define MRB_SYMBOL_MAX UINT32_MAX
#if defined(MRB_64BIT) && defined(MRB_INT32)
#define MRB_FIXNUM_SHIFT 0
#else
#define MRB_SYMBOL_BITSIZE (sizeof(mrb_sym) * CHAR_BIT - MRB_SPECIAL_SHIFT)
#define MRB_SYMBOL_MAX (UINT32_MAX >> MRB_SPECIAL_SHIFT)
#define MRB_FIXNUM_SHIFT WORDBOX_FIXNUM_SHIFT
#endif
#define MRB_SYMBOL_SHIFT WORDBOX_SYMBOL_SHIFT
#if defined(MRB_64BIT) && defined(MRB_INT64)
# define MRB_FIXNUM_MIN (INT64_MIN>>MRB_FIXNUM_SHIFT)
# define MRB_FIXNUM_MAX (INT64_MAX>>MRB_FIXNUM_SHIFT)
#else
# define MRB_FIXNUM_MIN (INT32_MIN>>MRB_FIXNUM_SHIFT)
# define MRB_FIXNUM_MAX (INT32_MAX>>MRB_FIXNUM_SHIFT)
#endif
typedef union mrb_value {
union {
void *p;
struct {
unsigned int i_flag : MRB_FIXNUM_SHIFT;
mrb_int i : (MRB_INT_BIT - MRB_FIXNUM_SHIFT);
};
struct {
unsigned int sym_flag : MRB_SPECIAL_SHIFT;
mrb_sym sym : MRB_SYMBOL_BITSIZE;
};
struct RBasic *bp;
#ifndef MRB_WITHOUT_FLOAT
struct RFloat *fp;
#define WORDBOX_FIXNUM_BIT_POS 1
#define WORDBOX_FIXNUM_SHIFT WORDBOX_FIXNUM_BIT_POS
#define WORDBOX_FIXNUM_FLAG (1 << (WORDBOX_FIXNUM_BIT_POS - 1))
#define WORDBOX_FIXNUM_MASK ((1 << WORDBOX_FIXNUM_BIT_POS) - 1)
#if defined(MRB_WORDBOX_NO_FLOAT_TRUNCATE)
/* floats are allocated in heaps */
#define WORDBOX_SYMBOL_BIT_POS 2
#define WORDBOX_SYMBOL_SHIFT WORDBOX_SYMBOL_BIT_POS
#define WORDBOX_SYMBOL_FLAG (1 << (WORDBOX_SYMBOL_BIT_POS - 1))
#define WORDBOX_SYMBOL_MASK ((1 << WORDBOX_SYMBOL_BIT_POS) - 1)
#else
#define WORDBOX_FLOAT_FLAG 2
#define WORDBOX_FLOAT_MASK 3
#if defined(MRB_64BIT)
#define WORDBOX_SYMBOL_SHIFT 32
#else /* MRB_32BIT */
#define WORDBOX_SYMBOL_SHIFT 5
#endif
struct RCptr *vp;
} value;
unsigned long w;
#define WORDBOX_SYMBOL_FLAG 0x1c
#define WORDBOX_SYMBOL_MASK 0x1f
#endif
#define WORDBOX_IMMEDIATE_MASK 0x07
#define WORDBOX_SET_SHIFT_VALUE(o,n,v) \
((o).w = (((uintptr_t)(v)) << WORDBOX_##n##_SHIFT) | WORDBOX_##n##_FLAG)
#define WORDBOX_SHIFT_VALUE_P(o,n) \
(((o).w & WORDBOX_##n##_MASK) == WORDBOX_##n##_FLAG)
#define WORDBOX_OBJ_TYPE_P(o,n) \
(!mrb_immediate_p(o) && mrb_val_union(o).bp->tt == MRB_TT_##n)
/*
* mrb_value representation:
*
* 64bit word with inline float:
* nil : ...0000 0000 (all bits are 0)
* false : ...0000 0100 (mrb_fixnum(v) != 0)
* true : ...0000 1100
* undef : ...0001 0100
* symbol: ...0001 1100 (use only upper 32-bit as symbol value with MRB_64BIT)
* fixnum: ...IIII III1
* float : ...FFFF FF10 (51 bit significands; require MRB_64BIT)
* object: ...PPPP P000
*
* 32bit word with inline float:
* nil : ...0000 0000 (all bits are 0)
* false : ...0000 0100 (mrb_fixnum(v) != 0)
* true : ...0000 1100
* undef : ...0001 0100
* symbol: ...SSS1 0100 (symbol occupies 20bits)
* fixnum: ...IIII III1
* float : ...FFFF FF10 (22 bit significands; require MRB_64BIT)
* object: ...PPPP P000
*
* and word boxing without inline float (MRB_WORDBOX_NO_FLOAT_TRUNCATE):
* nil : ...0000 0000 (all bits are 0)
* false : ...0000 0100 (mrb_fixnum(v) != 0)
* true : ...0000 1100
* undef : ...0001 0100
* fixnum: ...IIII III1
* symbol: ...SSSS SS10
* object: ...PPPP P000 (any bits are 1)
*/
typedef struct mrb_value {
uintptr_t w;
} mrb_value;
MRB_API mrb_value mrb_word_boxing_cptr_value(struct mrb_state*, void*);
#ifndef MRB_WITHOUT_FLOAT
MRB_API mrb_value mrb_word_boxing_float_value(struct mrb_state*, mrb_float);
MRB_API mrb_value mrb_word_boxing_float_pool(struct mrb_state*, mrb_float);
union mrb_value_ {
void *p;
struct RBasic *bp;
#ifndef MRB_NO_FLOAT
#ifndef MRB_WORDBOX_NO_FLOAT_TRUNCATE
mrb_float f;
#else
struct RFloat *fp;
#endif
#ifndef MRB_WITHOUT_FLOAT
#define mrb_float_pool(mrb,f) mrb_word_boxing_float_pool(mrb,f)
#endif
struct RInteger *ip;
struct RCptr *vp;
uintptr_t w;
mrb_value value;
};
#define mrb_ptr(o) (o).value.p
#define mrb_cptr(o) (o).value.vp->p
#ifndef MRB_WITHOUT_FLOAT
#define mrb_float(o) (o).value.fp->f
#endif
#define mrb_fixnum(o) ((mrb_int)(o).value.i)
#define mrb_symbol(o) (o).value.sym
mrb_static_assert(sizeof(mrb_value) == sizeof(union mrb_value_));
static inline enum mrb_vtype
mrb_type(mrb_value o)
static inline union mrb_value_
mrb_val_union(mrb_value v)
{
switch (o.w) {
case MRB_Qfalse:
case MRB_Qnil:
return MRB_TT_FALSE;
case MRB_Qtrue:
return MRB_TT_TRUE;
case MRB_Qundef:
return MRB_TT_UNDEF;
}
if (o.value.i_flag == MRB_FIXNUM_FLAG) {
return MRB_TT_FIXNUM;
}
if (o.value.sym_flag == MRB_SYMBOL_FLAG) {
return MRB_TT_SYMBOL;
}
return o.value.bp->tt;
union mrb_value_ x;
x.value = v;
return x;
}
#define mrb_bool(o) ((o).w != MRB_Qnil && (o).w != MRB_Qfalse)
#define mrb_fixnum_p(o) ((o).value.i_flag == MRB_FIXNUM_FLAG)
MRB_API mrb_value mrb_word_boxing_cptr_value(struct mrb_state*, void*);
#ifndef MRB_NO_FLOAT
MRB_API mrb_value mrb_word_boxing_float_value(struct mrb_state*, mrb_float);
#endif
MRB_API mrb_value mrb_boxing_int_value(struct mrb_state*, mrb_int);
#define mrb_immediate_p(o) ((o).w & WORDBOX_IMMEDIATE_MASK || (o).w == MRB_Qnil)
#define mrb_ptr(o) mrb_val_union(o).p
#define mrb_cptr(o) mrb_val_union(o).vp->p
#ifndef MRB_NO_FLOAT
#ifndef MRB_WORDBOX_NO_FLOAT_TRUNCATE
MRB_API mrb_float mrb_word_boxing_value_float(mrb_value v);
#define mrb_float(o) mrb_word_boxing_value_float(o)
#else
#define mrb_float(o) mrb_val_union(o).fp->f
#endif
#endif
#define mrb_fixnum(o) (mrb_int)(((intptr_t)(o).w) >> WORDBOX_FIXNUM_SHIFT)
MRB_INLINE mrb_int
mrb_integer_func(mrb_value o) {
if (mrb_immediate_p(o)) return mrb_fixnum(o);
return mrb_val_union(o).ip->i;
}
#define mrb_integer(o) mrb_integer_func(o)
#define mrb_symbol(o) (mrb_sym)(((o).w) >> WORDBOX_SYMBOL_SHIFT)
#define mrb_bool(o) (((o).w & ~(uintptr_t)MRB_Qfalse) != 0)
#define mrb_fixnum_p(o) WORDBOX_SHIFT_VALUE_P(o, FIXNUM)
#define mrb_integer_p(o) (WORDBOX_SHIFT_VALUE_P(o, FIXNUM)||WORDBOX_OBJ_TYPE_P(o, INTEGER))
#define mrb_symbol_p(o) WORDBOX_SHIFT_VALUE_P(o, SYMBOL)
#define mrb_undef_p(o) ((o).w == MRB_Qundef)
#define mrb_nil_p(o) ((o).w == MRB_Qnil)
#define BOXWORD_SET_VALUE(o, ttt, attr, v) do { \
switch (ttt) {\
case MRB_TT_FALSE: (o).w = (v) ? MRB_Qfalse : MRB_Qnil; break;\
case MRB_TT_TRUE: (o).w = MRB_Qtrue; break;\
case MRB_TT_UNDEF: (o).w = MRB_Qundef; break;\
case MRB_TT_FIXNUM: (o).w = 0;(o).value.i_flag = MRB_FIXNUM_FLAG; (o).attr = (v); break;\
case MRB_TT_SYMBOL: (o).w = 0;(o).value.sym_flag = MRB_SYMBOL_FLAG; (o).attr = (v); break;\
default: (o).w = 0; (o).attr = (v); if ((o).value.bp) (o).value.bp->tt = ttt; break;\
}\
} while (0)
#ifndef MRB_WITHOUT_FLOAT
#define SET_FLOAT_VALUE(mrb,r,v) r = mrb_word_boxing_float_value(mrb, v)
#define mrb_false_p(o) ((o).w == MRB_Qfalse)
#define mrb_true_p(o) ((o).w == MRB_Qtrue)
#ifndef MRB_NO_FLOAT
#ifndef MRB_WORDBOX_NO_FLOAT_TRUNCATE
#define mrb_float_p(o) WORDBOX_SHIFT_VALUE_P(o, FLOAT)
#else
#define mrb_float_p(o) WORDBOX_OBJ_TYPE_P(o, FLOAT)
#endif
#define SET_CPTR_VALUE(mrb,r,v) r = mrb_word_boxing_cptr_value(mrb, v)
#define SET_NIL_VALUE(r) BOXWORD_SET_VALUE(r, MRB_TT_FALSE, value.i, 0)
#define SET_FALSE_VALUE(r) BOXWORD_SET_VALUE(r, MRB_TT_FALSE, value.i, 1)
#define SET_TRUE_VALUE(r) BOXWORD_SET_VALUE(r, MRB_TT_TRUE, value.i, 1)
#define SET_BOOL_VALUE(r,b) BOXWORD_SET_VALUE(r, b ? MRB_TT_TRUE : MRB_TT_FALSE, value.i, 1)
#define SET_INT_VALUE(r,n) BOXWORD_SET_VALUE(r, MRB_TT_FIXNUM, value.i, (n))
#define SET_SYM_VALUE(r,v) BOXWORD_SET_VALUE(r, MRB_TT_SYMBOL, value.sym, (v))
#define SET_OBJ_VALUE(r,v) BOXWORD_SET_VALUE(r, (((struct RObject*)(v))->tt), value.p, (v))
#define SET_UNDEF_VALUE(r) BOXWORD_SET_VALUE(r, MRB_TT_UNDEF, value.i, 0)
#endif
#define mrb_array_p(o) WORDBOX_OBJ_TYPE_P(o, ARRAY)
#define mrb_string_p(o) WORDBOX_OBJ_TYPE_P(o, STRING)
#define mrb_hash_p(o) WORDBOX_OBJ_TYPE_P(o, HASH)
#define mrb_cptr_p(o) WORDBOX_OBJ_TYPE_P(o, CPTR)
#define mrb_exception_p(o) WORDBOX_OBJ_TYPE_P(o, EXCEPTION)
#define mrb_free_p(o) WORDBOX_OBJ_TYPE_P(o, FREE)
#define mrb_object_p(o) WORDBOX_OBJ_TYPE_P(o, OBJECT)
#define mrb_class_p(o) WORDBOX_OBJ_TYPE_P(o, CLASS)
#define mrb_module_p(o) WORDBOX_OBJ_TYPE_P(o, MODULE)
#define mrb_iclass_p(o) WORDBOX_OBJ_TYPE_P(o, ICLASS)
#define mrb_sclass_p(o) WORDBOX_OBJ_TYPE_P(o, SCLASS)
#define mrb_proc_p(o) WORDBOX_OBJ_TYPE_P(o, PROC)
#define mrb_range_p(o) WORDBOX_OBJ_TYPE_P(o, RANGE)
#define mrb_env_p(o) WORDBOX_OBJ_TYPE_P(o, ENV)
#define mrb_data_p(o) WORDBOX_OBJ_TYPE_P(o, DATA)
#define mrb_fiber_p(o) WORDBOX_OBJ_TYPE_P(o, FIBER)
#define mrb_istruct_p(o) WORDBOX_OBJ_TYPE_P(o, ISTRUCT)
#define mrb_break_p(o) WORDBOX_OBJ_TYPE_P(o, BREAK)
#ifndef MRB_NO_FLOAT
#define SET_FLOAT_VALUE(mrb,r,v) ((r) = mrb_word_boxing_float_value(mrb, v))
#endif
#define SET_CPTR_VALUE(mrb,r,v) ((r) = mrb_word_boxing_cptr_value(mrb, v))
#define SET_UNDEF_VALUE(r) ((r).w = MRB_Qundef)
#define SET_NIL_VALUE(r) ((r).w = MRB_Qnil)
#define SET_FALSE_VALUE(r) ((r).w = MRB_Qfalse)
#define SET_TRUE_VALUE(r) ((r).w = MRB_Qtrue)
#define SET_BOOL_VALUE(r,b) ((b) ? SET_TRUE_VALUE(r) : SET_FALSE_VALUE(r))
#define SET_INT_VALUE(mrb,r,n) ((r) = mrb_boxing_int_value(mrb, n))
#define SET_FIXNUM_VALUE(r,n) WORDBOX_SET_SHIFT_VALUE(r, FIXNUM, n)
#define SET_SYM_VALUE(r,n) WORDBOX_SET_SHIFT_VALUE(r, SYMBOL, n)
#define SET_OBJ_VALUE(r,v) ((r).w = (uintptr_t)(v))
MRB_INLINE enum mrb_vtype
mrb_type(mrb_value o)
{
return !mrb_bool(o) ? MRB_TT_FALSE :
mrb_true_p(o) ? MRB_TT_TRUE :
mrb_fixnum_p(o) ? MRB_TT_INTEGER :
mrb_symbol_p(o) ? MRB_TT_SYMBOL :
mrb_undef_p(o) ? MRB_TT_UNDEF :
#ifndef MRB_NO_FLOAT
mrb_float_p(o) ? MRB_TT_FLOAT :
#endif
mrb_val_union(o).bp->tt;
}
#endif /* MRUBY_BOXING_WORD_H */
+29 -18
View File
@@ -1,5 +1,5 @@
/*
** mruby/class.h - Class class
/**
** @file mruby/class.h - Class class
**
** See Copyright Notice in mruby.h
*/
@@ -17,13 +17,13 @@ MRB_BEGIN_DECL
struct RClass {
MRB_OBJECT_HEADER;
struct iv_tbl *iv;
struct kh_mt *mt;
struct mt_tbl *mt;
struct RClass *super;
};
#define mrb_class_ptr(v) ((struct RClass*)(mrb_ptr(v)))
static inline struct RClass*
MRB_INLINE struct RClass*
mrb_class(mrb_state *mrb, mrb_value v)
{
switch (mrb_type(v)) {
@@ -35,9 +35,9 @@ mrb_class(mrb_state *mrb, mrb_value v)
return mrb->true_class;
case MRB_TT_SYMBOL:
return mrb->symbol_class;
case MRB_TT_FIXNUM:
return mrb->fixnum_class;
#ifndef MRB_WITHOUT_FLOAT
case MRB_TT_INTEGER:
return mrb->integer_class;
#ifndef MRB_NO_FLOAT
case MRB_TT_FLOAT:
return mrb->float_class;
#endif
@@ -61,37 +61,48 @@ mrb_class(mrb_state *mrb, mrb_value v)
#define MRB_FL_CLASS_IS_PREPENDED (1 << 19)
#define MRB_FL_CLASS_IS_ORIGIN (1 << 18)
#define MRB_CLASS_ORIGIN(c) do {\
if (c->flags & MRB_FL_CLASS_IS_PREPENDED) {\
c = c->super;\
while (!(c->flags & MRB_FL_CLASS_IS_ORIGIN)) {\
c = c->super;\
if ((c)->flags & MRB_FL_CLASS_IS_PREPENDED) {\
(c) = (c)->super;\
while (!((c)->flags & MRB_FL_CLASS_IS_ORIGIN)) {\
(c) = (c)->super;\
}\
}\
} while (0)
#define MRB_FL_CLASS_IS_INHERITED (1 << 17)
#define MRB_INSTANCE_TT_MASK (0xFF)
#define MRB_SET_INSTANCE_TT(c, tt) c->flags = ((c->flags & ~MRB_INSTANCE_TT_MASK) | (char)tt)
#define MRB_INSTANCE_TT(c) (enum mrb_vtype)(c->flags & MRB_INSTANCE_TT_MASK)
#define MRB_SET_INSTANCE_TT(c, tt) ((c)->flags = (((c)->flags & ~MRB_INSTANCE_TT_MASK) | (char)(tt)))
#define MRB_INSTANCE_TT(c) (enum mrb_vtype)((c)->flags & MRB_INSTANCE_TT_MASK)
MRB_API struct RClass* mrb_define_class_id(mrb_state*, mrb_sym, struct RClass*);
MRB_API struct RClass* mrb_define_module_id(mrb_state*, mrb_sym);
MRB_API struct RClass *mrb_vm_define_class(mrb_state*, mrb_value, mrb_value, mrb_sym);
MRB_API struct RClass *mrb_vm_define_module(mrb_state*, mrb_value, mrb_sym);
struct RClass *mrb_vm_define_class(mrb_state*, mrb_value, mrb_value, mrb_sym);
struct RClass *mrb_vm_define_module(mrb_state*, mrb_value, mrb_sym);
MRB_API void mrb_define_method_raw(mrb_state*, struct RClass*, mrb_sym, mrb_method_t);
MRB_API void mrb_define_method_id(mrb_state *mrb, struct RClass *c, mrb_sym mid, mrb_func_t func, mrb_aspec aspec);
MRB_API void mrb_alias_method(mrb_state*, struct RClass *c, mrb_sym a, mrb_sym b);
MRB_API void mrb_remove_method(mrb_state *mrb, struct RClass *c, mrb_sym sym);
MRB_API mrb_method_t mrb_method_search_vm(mrb_state*, struct RClass**, mrb_sym);
MRB_API mrb_method_t mrb_method_search(mrb_state*, struct RClass*, mrb_sym);
MRB_API struct RClass* mrb_class_real(struct RClass* cl);
mrb_value mrb_instance_new(mrb_state *mrb, mrb_value cv);
void mrb_class_name_class(mrb_state*, struct RClass*, struct RClass*, mrb_sym);
mrb_bool mrb_const_name_p(mrb_state*, const char*, mrb_int);
mrb_value mrb_class_find_path(mrb_state*, struct RClass*);
mrb_value mrb_mod_to_s(mrb_state*, mrb_value);
void mrb_gc_mark_mt(mrb_state*, struct RClass*);
size_t mrb_gc_mark_mt_size(mrb_state*, struct RClass*);
void mrb_gc_free_mt(mrb_state*, struct RClass*);
#ifndef MRB_NO_METHOD_CACHE
void mrb_mc_clear_by_class(mrb_state *mrb, struct RClass* c);
#else
#define mrb_mc_clear_by_class(mrb,c)
#endif
/* return non zero to break the loop */
typedef int (mrb_mt_foreach_func)(mrb_state*,mrb_sym,mrb_method_t,void*);
MRB_API void mrb_mt_foreach(mrb_state*, struct RClass*, mrb_mt_foreach_func*, void*);
MRB_END_DECL
#endif /* MRUBY_CLASS_H */
+30 -9
View File
@@ -1,5 +1,5 @@
/*
**"common.h - mruby common platform definition"
/**
** @file common.h - mruby common platform definition"
**
** See Copyright Notice in mruby.h
*/
@@ -14,7 +14,7 @@
#endif
#ifdef __cplusplus
#ifdef MRB_ENABLE_CXX_ABI
#ifdef MRB_USE_CXX_ABI
#define MRB_BEGIN_DECL
#define MRB_END_DECL
#else
@@ -28,13 +28,19 @@
# define MRB_END_DECL
#endif
#include <sys/types.h>
#if defined _MSC_VER
#include <BaseTsd.h>
typedef SSIZE_T ssize_t;
#endif
/**
* Shared compiler macros
*/
MRB_BEGIN_DECL
/** Declare a function that never returns. */
#if __STDC_VERSION__ >= 201112L
#if defined __STDC_VERSION__ && __STDC_VERSION__ >= 201112L
# define mrb_noreturn _Noreturn
#elif defined __GNUC__ && !defined __STRICT_ANSI__
# define mrb_noreturn __attribute__((noreturn))
@@ -54,14 +60,15 @@ MRB_BEGIN_DECL
#endif
/** Declare a function as always inlined. */
#if defined(_MSC_VER)
# define MRB_INLINE static __inline
#else
# define MRB_INLINE static inline
#if defined _MSC_VER && _MSC_VER < 1900
# ifndef __cplusplus
# define inline __inline
# endif
#endif
#define MRB_INLINE static inline
/** Declare a public MRuby API function. */
#ifndef MRB_API
#if defined(MRB_BUILD_AS_DLL)
#if defined(MRB_CORE) || defined(MRB_LIB)
# define MRB_API __declspec(dllexport)
@@ -71,6 +78,20 @@ MRB_BEGIN_DECL
#else
# define MRB_API extern
#endif
#endif
/** Declare mingw versions */
#if defined(__MINGW32__) || defined(__MINGW64__)
# include <_mingw.h>
# if defined(__MINGW64_VERSION_MAJOR)
# define MRB_MINGW64_VERSION (__MINGW64_VERSION_MAJOR * 1000 + __MINGW64_VERSION_MINOR)
# elif defined(__MINGW32_MAJOR_VERSION)
# define MRB_MINGW32_VERSION (__MINGW32_MAJOR_VERSION * 1000 + __MINGW32_MINOR_VERSION)
# endif
# if defined(__MINGW32__) && !defined(__MINGW64__)
# define MRB_MINGW32_LEGACY
# endif
#endif
MRB_END_DECL
+32 -18
View File
@@ -1,5 +1,5 @@
/*
** mruby/compile.h - mruby parser
/**
** @file mruby/compile.h - mruby parser
**
** See Copyright Notice in mruby.h
*/
@@ -16,15 +16,13 @@ MRB_BEGIN_DECL
#include <mruby.h>
struct mrb_jmpbuf;
struct mrb_parser_state;
/* load context */
typedef struct mrbc_context {
mrb_sym *syms;
int slen;
char *filename;
short lineno;
uint16_t lineno;
int (*partial_hook)(struct mrb_parser_state*);
void *partial_data;
struct RClass *target_class;
@@ -33,7 +31,8 @@ typedef struct mrbc_context {
mrb_bool no_exec:1;
mrb_bool keep_lv:1;
mrb_bool no_optimize:1;
mrb_bool on_eval:1;
mrb_bool no_ext_ops:1;
const struct RProc *upper;
size_t parser_nerr;
} mrbc_context;
@@ -42,6 +41,7 @@ MRB_API mrbc_context* mrbc_context_new(mrb_state *mrb);
MRB_API void mrbc_context_free(mrb_state *mrb, mrbc_context *cxt);
MRB_API const char *mrbc_filename(mrb_state *mrb, mrbc_context *c, const char *s);
MRB_API void mrbc_partial_hook(mrb_state *mrb, mrbc_context *c, int (*partial_hook)(struct mrb_parser_state*), void*data);
MRB_API void mrbc_cleanup_local_variables(mrb_state *mrb, mrbc_context *c);
/* AST node structure */
typedef struct mrb_ast_node {
@@ -57,7 +57,7 @@ enum mrb_lex_state_enum {
EXPR_ENDFN, /* ditto, and unbound braces. */
EXPR_ARG, /* newline significant, +/- is an operator. */
EXPR_CMDARG, /* newline significant, +/- is an operator. */
EXPR_MID, /* newline significant, +/- is an operator. */
EXPR_MID, /* newline significant, +/- is a sign. */
EXPR_FNAME, /* ignore newline, no reserved words. */
EXPR_DOT, /* right after '.' or '::', no reserved words. */
EXPR_CLASS, /* immediate after 'class', no here document. */
@@ -67,7 +67,7 @@ enum mrb_lex_state_enum {
/* saved error message */
struct mrb_parser_message {
int lineno;
uint16_t lineno;
int column;
char* message;
};
@@ -98,6 +98,9 @@ enum mrb_string_type {
/* heredoc structure */
struct mrb_parser_heredoc_info {
mrb_bool allow_indent:1;
mrb_bool remove_indent:1;
size_t indent;
mrb_ast_node *indented;
mrb_bool line_head:1;
enum mrb_string_type type;
const char *term;
@@ -105,7 +108,7 @@ struct mrb_parser_heredoc_info {
mrb_ast_node *doc;
};
#define MRB_PARSER_TOKBUF_MAX 65536
#define MRB_PARSER_TOKBUF_MAX (UINT16_MAX-1)
#define MRB_PARSER_TOKBUF_SIZE 256
/* parser structure */
@@ -114,12 +117,13 @@ struct mrb_parser_state {
struct mrb_pool *pool;
mrb_ast_node *cells;
const char *s, *send;
#ifndef MRB_DISABLE_STDIO
#ifndef MRB_NO_STDIO
/* If both f and s are non-null, it will be taken preferentially from s until s < send. */
FILE *f;
#endif
mrbc_context *cxt;
char const *filename;
int lineno;
mrb_sym filename_sym;
uint16_t lineno;
int column;
enum mrb_lex_state_enum lstate;
@@ -151,8 +155,9 @@ struct mrb_parser_state {
mrb_ast_node *tree;
mrb_bool no_optimize:1;
mrb_bool on_eval:1;
mrb_bool capture_errors:1;
mrb_bool no_ext_ops:1;
const struct RProc *upper;
struct mrb_parser_message error_buffer[10];
struct mrb_parser_message warn_buffer[10];
@@ -160,7 +165,7 @@ struct mrb_parser_state {
uint16_t filename_table_length;
uint16_t current_filename_index;
struct mrb_jmpbuf* jmp;
mrb_ast_node *nvars;
};
MRB_API struct mrb_parser_state* mrb_parser_new(mrb_state*);
@@ -168,10 +173,10 @@ MRB_API void mrb_parser_free(struct mrb_parser_state*);
MRB_API void mrb_parser_parse(struct mrb_parser_state*,mrbc_context*);
MRB_API void mrb_parser_set_filename(struct mrb_parser_state*, char const*);
MRB_API char const* mrb_parser_get_filename(struct mrb_parser_state*, uint16_t idx);
MRB_API mrb_sym mrb_parser_get_filename(struct mrb_parser_state*, uint16_t idx);
/* utility functions */
#ifndef MRB_DISABLE_STDIO
#ifndef MRB_NO_STDIO
MRB_API struct mrb_parser_state* mrb_parse_file(mrb_state*,FILE*,mrbc_context*);
#endif
MRB_API struct mrb_parser_state* mrb_parse_string(mrb_state*,const char*,mrbc_context*);
@@ -179,10 +184,19 @@ MRB_API struct mrb_parser_state* mrb_parse_nstring(mrb_state*,const char*,size_t
MRB_API struct RProc* mrb_generate_code(mrb_state*, struct mrb_parser_state*);
MRB_API mrb_value mrb_load_exec(mrb_state *mrb, struct mrb_parser_state *p, mrbc_context *c);
/* program load functions */
#ifndef MRB_DISABLE_STDIO
/** program load functions
* Please note! Currently due to interactions with the GC calling these functions will
* leak one RProc object per function call.
* To prevent this save the current memory arena before calling and restore the arena
* right after, like so
* int ai = mrb_gc_arena_save(mrb);
* mrb_value status = mrb_load_string(mrb, buffer);
* mrb_gc_arena_restore(mrb, ai);
*/
#ifndef MRB_NO_STDIO
MRB_API mrb_value mrb_load_file(mrb_state*,FILE*);
MRB_API mrb_value mrb_load_file_cxt(mrb_state*,FILE*, mrbc_context *cxt);
MRB_API mrb_value mrb_load_detect_file_cxt(mrb_state *mrb, FILE *fp, mrbc_context *c);
#endif
MRB_API mrb_value mrb_load_string(mrb_state *mrb, const char *s);
MRB_API mrb_value mrb_load_nstring(mrb_state *mrb, const char *s, size_t len);
+9 -8
View File
@@ -1,5 +1,5 @@
/*
** mruby/data.h - Data class
/**
** @file mruby/data.h - Data class
**
** See Copyright Notice in mruby.h
*/
@@ -39,10 +39,11 @@ MRB_API struct RData *mrb_data_object_alloc(mrb_state *mrb, struct RClass* klass
#define Data_Wrap_Struct(mrb,klass,type,ptr)\
mrb_data_object_alloc(mrb,klass,ptr,type)
#define Data_Make_Struct(mrb,klass,strct,type,sval,data) do { \
sval = mrb_malloc(mrb, sizeof(strct)); \
{ static const strct zero = { 0 }; *sval = zero; };\
data = Data_Wrap_Struct(mrb,klass,type,sval);\
#define Data_Make_Struct(mrb,klass,strct,type,sval,data_obj) do { \
(data_obj) = Data_Wrap_Struct(mrb,klass,type,NULL);\
(sval) = (strct *)mrb_malloc(mrb, sizeof(strct)); \
{ static const strct zero = { 0 }; *(sval) = zero; };\
(data_obj)->data = (sval);\
} while (0)
#define RDATA(obj) ((struct RData *)(mrb_ptr(obj)))
@@ -62,10 +63,10 @@ MRB_API void *mrb_data_check_get_ptr(mrb_state *mrb, mrb_value, const mrb_data_t
*(void**)&sval = mrb_data_get_ptr(mrb, obj, type); \
} while (0)
static inline void
MRB_INLINE void
mrb_data_init(mrb_value v, void *ptr, const mrb_data_type *type)
{
mrb_assert(mrb_type(v) == MRB_TT_DATA);
mrb_assert(mrb_data_p(v));
DATA_PTR(v) = ptr;
DATA_TYPE(v) = type;
}
+8 -7
View File
@@ -1,5 +1,5 @@
/*
** mruby/debug.h - mruby debug info
/**
** @file mruby/debug.h - mruby debug info
**
** See Copyright Notice in mruby.h
*/
@@ -16,7 +16,8 @@ MRB_BEGIN_DECL
typedef enum mrb_debug_line_type {
mrb_debug_line_ary = 0,
mrb_debug_line_flat_map = 1
mrb_debug_line_flat_map,
mrb_debug_line_packed_map
} mrb_debug_line_type;
typedef struct mrb_irep_debug_info_line {
@@ -26,14 +27,14 @@ typedef struct mrb_irep_debug_info_line {
typedef struct mrb_irep_debug_info_file {
uint32_t start_pos;
const char *filename;
mrb_sym filename_sym;
uint32_t line_entry_count;
mrb_debug_line_type line_type;
union {
void *ptr;
mrb_irep_debug_info_line *flat_map;
uint16_t *ary;
mrb_irep_debug_info_line *flat_map;
uint8_t *packed_map;
} lines;
} mrb_irep_debug_info_file;
@@ -47,13 +48,13 @@ typedef struct mrb_irep_debug_info {
* get line from irep's debug info and program counter
* @return returns NULL if not found
*/
MRB_API const char *mrb_debug_get_filename(mrb_irep *irep, ptrdiff_t pc);
MRB_API const char *mrb_debug_get_filename(mrb_state *mrb, const mrb_irep *irep, uint32_t pc);
/*
* get line from irep's debug info and program counter
* @return returns -1 if not found
*/
MRB_API int32_t mrb_debug_get_line(mrb_irep *irep, ptrdiff_t pc);
MRB_API int32_t mrb_debug_get_line(mrb_state *mrb, const mrb_irep *irep, uint32_t pc);
MRB_API mrb_irep_debug_info *mrb_debug_info_alloc(mrb_state *mrb, mrb_irep *irep);
MRB_API mrb_irep_debug_info_file *mrb_debug_info_append_file(

Some files were not shown because too many files have changed in this diff Show More