Compare commits

..

1057 Commits

Author SHA1 Message Date
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
Uchio KONDO 7c52734243 Add a testcase of #4137 fix 2018-10-15 14:46:24 +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
288 changed files with 18459 additions and 16998 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
+43 -37
View File
@@ -3,38 +3,14 @@ name: Build & Test
on: [push, pull_request]
jobs:
Check-Skip:
if: |
!contains(github.event.head_commit.message, '[ci skip]') &&
!contains(github.event.head_commit.message, '[skip ci]') &&
!contains(github.event.head_commit.message, '[skip gha]')
runs-on: ubuntu-latest
steps:
- run: echo not skip
Ubuntu-1604:
needs: Check-Skip
runs-on: ubuntu-16.04
env:
MRUBY_CONFIG: ci/gcc-clang
CC: gcc
steps:
- uses: actions/checkout@v2
- 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-gcc:
needs: Check-Skip
runs-on: ubuntu-18.04
timeout-minutes: 10
env:
MRUBY_CONFIG: ci/gcc-clang
CC: gcc
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v2.4.0
- name: Ruby version
run: ruby -v
- name: Compiler version
@@ -43,13 +19,43 @@ jobs:
run: rake -m test:build && rake test:run
Ubuntu-1804-clang:
needs: Check-Skip
runs-on: ubuntu-18.04
timeout-minutes: 10
env:
MRUBY_CONFIG: ci/gcc-clang
CC: clang
steps:
- uses: actions/checkout@v2
- 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
@@ -58,13 +64,13 @@ jobs:
run: rake -m test:build && rake test:run
macOS:
needs: Check-Skip
runs-on: macos-latest
timeout-minutes: 10
env:
MRUBY_CONFIG: ci/gcc-clang
CC: clang
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v2.4.0
- name: Ruby version
run: ruby -v
- name: Compiler version
@@ -73,13 +79,13 @@ jobs:
run: rake -m test:build && rake test:run
Windows-MinGW:
needs: Check-Skip
runs-on: windows-latest
timeout-minutes: 10
env:
MRUBY_CONFIG: ci/gcc-clang
CC: gcc
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v2.4.0
- name: Ruby version
run: ruby -v
- name: Compiler version
@@ -88,8 +94,8 @@ jobs:
run: rake -m test:build && rake test:run
Windows-Cygwin:
needs: Check-Skip
runs-on: windows-latest
timeout-minutes: 15
env:
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
MRUBY_CONFIG: ci/gcc-clang
@@ -99,8 +105,8 @@ jobs:
package-dir: C:\cygwin-package
cache-version: v1
steps:
- uses: actions/checkout@v2
- uses: actions/cache@v2
- uses: actions/checkout@v2.4.0
- uses: actions/cache@v2.1.7
with:
path: ${{ env.package-dir }}
key: ${{ runner.os }}-cygwin-${{ env.cache-version }}
@@ -134,12 +140,12 @@ jobs:
run: echo '::set-env name=PATH::C:\windows\System32'
Windows-VC:
needs: Check-Skip
runs-on: windows-latest
timeout-minutes: 10
env:
MRUBY_CONFIG: ci/msvc
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v2.4.0
- name: Ruby version
run: ruby -v
- name: Build and test
+1 -10
View File
@@ -8,26 +8,17 @@ on:
jobs:
CodeQL-Build:
if: |
!contains(github.event.head_commit.message, '[ci skip]') &&
!contains(github.event.head_commit.message, '[skip ci]') &&
!contains(github.event.head_commit.message, '[skip gha]')
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
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
# If this run was triggered by a pull request event, then checkout
# the head of the pull request instead of the merge commit.
- run: git checkout HEAD^2
if: ${{ github.event_name == 'pull_request' }}
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
+23 -14
View File
@@ -1,23 +1,32 @@
name: ❄️ Lint
name: Lint
on: [pull_request]
jobs:
yamllint:
name: 🍶 YAML
misspell:
name: Check spelling with misspell
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: 🧹 YAML Lint
uses: ibiqlik/action-yamllint@v3
markdownlint:
name: 🍸 Markdown
- 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
- name: 🚀 Use Node.js
uses: actions/setup-node@v2.1.4
- 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:
node-version: '12.x'
- run: npm install -g markdownlint-cli@0.25.0
- run: markdownlint '**/*.md'
path: ~/.cache/pre-commit
key: pre-commit|${{ env.PY }}|${{ hashFiles('.pre-commit-config.yaml') }}
- name: Run pre-commit
run: pre-commit run --all-files
+1 -5
View File
@@ -2,10 +2,6 @@ name: CIFuzz
on: [pull_request]
jobs:
Fuzzing:
if: |
!contains(github.event.head_commit.message, '[ci skip]') &&
!contains(github.event.head_commit.message, '[skip ci]') &&
!contains(github.event.head_commit.message, '[skip gha]')
runs-on: ubuntu-latest
steps:
- name: Build Fuzzers
@@ -20,7 +16,7 @@ jobs:
fuzz-seconds: 600
dry-run: false
- name: Upload Crash
uses: actions/upload-artifact@v1
uses: actions/upload-artifact@v2.3.1
if: failure()
with:
name: artifacts
-17
View File
@@ -1,17 +0,0 @@
name: 💎 Spellchecker
on: [pull_request]
jobs:
misspell:
name: 🧹 Check Spelling
runs-on: ubuntu-latest
steps:
- name: 🍒 Check Out
uses: actions/checkout@v2
- name: 🍅 Install
run: |
wget -O - -q https://git.io/misspell | sh -s -- -b .
- name: 🌶️ Misspell
run: |
git ls-files --empty-directory | xargs ./misspell -error
+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 }}
-4414
View File
File diff suppressed because it is too large Load Diff
-16
View File
@@ -1,16 +0,0 @@
MD001: false
MD003: false
MD004: false
MD005: false
MD007: false
MD010: false
MD011: false
MD013: false
MD014: false
MD024: false
MD025: false
MD026: false
MD034: false
MD040: false
MD041: false
MD046: false
+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)$
-8
View File
@@ -1,8 +0,0 @@
---
extends: default
rules:
document-start: disable
line-length: disable
truthy: false
+303 -41
View File
@@ -1,48 +1,310 @@
This is the (likely incomplete) list of "mruby developers".
If you submit a patch to mruby, please add your name to the end
of this list.
# Authors of mruby (mruby developers)
Yukihiro Matsumoto (Matz)
## 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
KOBAYASHI Shuji
RIZAL Reckordp
Rory O'Connell
John Bampton
Seeker
+45 -10
View File
@@ -10,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 (```rake 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
@@ -18,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.
@@ -32,7 +67,7 @@ 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>).
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
@@ -48,13 +83,13 @@ on-demand.
#### Insert a break after the function return value:
```C
int
main(void)
{
...
}
```
```c
int
main(void)
{
...
}
```
### Ruby code
@@ -64,5 +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 (https://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.
+1 -1
View File
@@ -6,7 +6,7 @@
DOXYFILE_ENCODING = UTF-8
PROJECT_NAME = "mruby"
PROJECT_NUMBER = 2.1.2
PROJECT_NUMBER = 3.0.0
PROJECT_BRIEF = "mruby is the lightweight implementation of the Ruby language"
-1
View File
@@ -3,4 +3,3 @@ LEGAL NOTICE INFORMATION
All the files in this distribution are covered under the MIT license
(see the file LICENSE) except some files mentioned below:
-1
View File
@@ -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
View File
@@ -9,5 +9,3 @@ with all sufficient information, see the ChangeLog file.
** Information about first release v1.0.0
+21 -16
View File
@@ -1,4 +1,7 @@
# 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
@@ -6,7 +9,7 @@ mruby is the lightweight implementation of the Ruby language complying to (part
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,22 +20,22 @@ of the Ministry of Economy, Trade and Industry of Japan.
## How to get mruby
The releace candidate version 3.0.0 of mruby can be downloaded via the following URL: [https://github.com/mruby/mruby/archive/3.0.0-rc.zip](https://github.com/mruby/mruby/archive/3.0.0-rc.zip)
The stable version 2.1.2 of mruby can be downloaded via the following URL: [https://github.com/mruby/mruby/archive/2.1.2.zip](https://github.com/mruby/mruby/archive/2.1.2.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-rc.zip](https://github.com/mruby/mruby/archive/3.1.0-rc.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: https://mruby.org.
The URL of the mruby home-page is: <https://mruby.org>.
## Mailing list
@@ -40,7 +43,7 @@ We don't have a mailing list, but you can use [GitHub issues](https://github.com
## How to compile, test, and install (mruby and gems)
See the [compile.md](https://github.com/mruby/mruby/blob/master/doc/guides/compile.md) file.
See the [compile.md](doc/guides/compile.md) file.
## Building documentation
@@ -48,23 +51,27 @@ There are two sets of documentation in mruby: the mruby API (generated by yard)
To build both of them, simply go
rake doc
```
rake doc
```
You can also view them in your browser
rake view_api
rake view_capi
```
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 [mrbgems.md](https://github.com/mruby/mruby/blob/master/doc/guides/mrbgems.md).
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](https://github.com/mruby/mruby/blob/master/LICENSE).
mruby is released under the [MIT License](LICENSE).
## Note for License
@@ -78,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.
@@ -87,9 +94,7 @@ Please ask us if you want to distribute your code under another license.
See the [contribution guidelines][contribution-guidelines], and then send a pull
request to <https://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.
non-exclusive right to your contributed code under MIT license.
[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
-1
View File
@@ -31,7 +31,6 @@ 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"
##############################
+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
+7 -10
View File
@@ -1,17 +1,14 @@
Thing to Do in the future
===
# Thing to Do in the future
# After mruby 3.0
# After mruby 3.1
* replace `fp_fmt.c` by `float_format` (https://github.com/dhylands/format-float.git)
* multi-precision integer
* WORD_BOXING: Pack some floats in `mrb_value`
* NAN_BOXING: Allow `MRB_INT64` along with NaN boxing
* keyword arguments a la Ruby3.0 (using `OP_SENDVK`)
* parser and code generator independent from `mrb_state` (mmruby?)
* 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 that are not done yet)
# Things to do (Things we need to consider)
* `begin ... end while cond` to behave as CRuby
* special variables ($1,$2..)
* super in aliased methods
+1 -1
View File
@@ -32,7 +32,7 @@ environment:
init:
- call "%visualcpp%" %machine%
# For using Rubyins4aller's Ruby 2.6 64bit
# 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%
+11 -11
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
+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
-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
+2 -2
View File
@@ -11,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"
@@ -32,7 +32,7 @@ MRuby::CrossBuild.new("ArduinoDue") do |conf|
cc.defines << %w(MRB_HEAP_PAGE_SIZE=64)
cc.defines << %w(KHASH_DEFAULT_SIZE=8)
cc.defines << %w(MRB_GC_STRESS)
#cc.defines << %w(MRB_NO_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
+1 -1
View File
@@ -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"
+1 -1
View File
@@ -74,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 -1
View File
@@ -18,7 +18,7 @@ MRuby::CrossBuild.new("RX630") do |conf|
cc.defines << %w(MRB_HEAP_PAGE_SIZE=64)
cc.defines << %w(KHASH_DEFAULT_SIZE=8)
cc.defines << %w(MRB_GC_STRESS)
cc.defines << %w(MRB_NO_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
-2
View File
@@ -3,8 +3,6 @@ bits = [64, 32]
ints = [64, 32]
boxings.product(bits, ints) do |boxing, bit, int|
next if boxing == "nan" && int == 64
MRuby::Build.new("boxing-#{boxing}-m#{bit}-i#{int}") do |conf|
conf.toolchain :gcc
conf.gembox 'default'
+1 -1
View File
@@ -29,7 +29,7 @@ MRuby::CrossBuild.new("chipKITMax32") do |conf|
cc.defines << %w(MRB_HEAP_PAGE_SIZE=64)
cc.defines << %w(KHASH_DEFAULT_SIZE=8)
cc.defines << %w(MRB_GC_STRESS)
#cc.defines << %w(MRB_NO_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
+4 -4
View File
@@ -6,7 +6,7 @@ MRuby::Build.new('full-debug') do |conf|
# include all core GEMs
conf.gembox 'full-core'
conf.cc.defines += %w(MRB_GC_STRESS MRB_USE_DEBUG_HOOK)
conf.cc.defines += %w(MRB_GC_STRESS MRB_USE_DEBUG_HOOK MRB_UTF8_STRING)
conf.enable_test
end
@@ -18,7 +18,7 @@ MRuby::Build.new do |conf|
conf.gembox 'full-core'
conf.gem :core => 'mruby-bin-debugger'
conf.compilers.each do |c|
c.defines += %w(MRB_GC_FIXED_ARENA)
c.defines += %w(MRB_GC_FIXED_ARENA MRB_UTF8_STRING)
end
conf.enable_bintest
conf.enable_test
@@ -28,9 +28,9 @@ MRuby::Build.new('cxx_abi') do |conf|
conf.toolchain
conf.gembox 'full-core'
conf.cc.flags += %w(-fpermissive)
conf.cc.flags += %w(-fpermissive -std=gnu++03)
conf.compilers.each do |c|
c.defines += %w(MRB_GC_FIXED_ARENA)
c.defines += %w(MRB_GC_FIXED_ARENA MRB_UTF8_STRING)
end
conf.enable_test
+1 -1
View File
@@ -1,7 +1,7 @@
MRuby::Build.new do |conf|
conf.toolchain :clang
# include the GEM box
conf.gembox 'default'
conf.gembox 'full-core'
# Turn on `enable_debug` for better debugging
conf.enable_sanitizer "address,undefined"
+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
+1 -1
View File
@@ -42,7 +42,7 @@ MRuby::Build.new do |conf|
# linker.library_paths = []
# linker.option_library = '-l%s'
# linker.option_library_path = '-L%s'
# linker.link_options = "%{flags} -o "%{outfile}" %{objs} %{libs}"
# linker.link_options = %Q[%{flags} -o "%{outfile}" %{objs} %{libs}]
# end
# Archiver settings
+49 -26
View File
@@ -1,8 +1,14 @@
# Cross Compiling configuration for the Sega Dreamcast
# This configuration requires KallistiOS (KOS)
# https://dreamcast.wiki
# https://dreamcast.wiki/Using_Ruby_for_Sega_Dreamcast_development
#
# Tested on GNU/Linux, MinGW-w64/MSYS2, Cygwin, macOS and MinGW/MSYS (see below)
# 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
@@ -20,7 +26,7 @@ MRuby::CrossBuild.new("dreamcast") do |conf|
# C compiler
# Flags were extracted from KallistiOS environment files
conf.cc do |cc|
cc.command = "#{BIN_PATH}/sh-elf-gcc"
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}"]
@@ -64,31 +70,48 @@ MRuby::CrossBuild.new("dreamcast") do |conf|
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"
# 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-range-ext"
conf.gem :core => "mruby-proc-ext"
conf.gem :core => "mruby-symbol-ext"
conf.gem :core => "mruby-random"
# 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-fiber"
conf.gem :core => "mruby-enumerator"
conf.gem :core => "mruby-enum-lazy"
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"
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()
+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
+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
+1 -1
View File
@@ -23,7 +23,7 @@ MRuby::Build.new do |conf|
# file extensions
conf.exts do |exts|
exts.library = '.so'
exts.library = '.so'
end
# file separator
+4
View File
@@ -0,0 +1,4 @@
MRuby::CrossBuild.new('minimal') do |conf|
conf.toolchain :gcc
conf.cc.defines << 'MRB_NO_STDIO'
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
-17
View File
@@ -1,17 +0,0 @@
# Define cross build settings
MRuby::CrossBuild.new('no-float') do |conf|
conf.toolchain
# Add configuration
conf.compilers.each do |c|
c.defines << "MRB_NO_FLOAT"
end
conf.gem :core => "mruby-bin-mruby"
conf.test_runner.command = 'env'
conf.enable_debug
# conf.enable_bintest
conf.enable_test
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
+110 -133
View File
@@ -10,18 +10,19 @@ To compile mruby out of the source code you need the following tools:
* C Compiler (e.g. `gcc` or `clang`)
* Linker (e.g. `gcc` or `clang`)
* Archive utility (e.g. `ar`)
* Parser generator (`bison`)
* Ruby 2.0 or later (e.g. `ruby` or `jruby`)
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 to upgrade `ruby`
on MacOS in similar manner.
* 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)
* 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
@@ -32,7 +33,7 @@ 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
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
@@ -48,10 +49,10 @@ All tools necessary to compile mruby can be set or modified here.
## Build Configuration
We wish you submit a pull-request to *build_config/**PLATFORM**.rb*, once you
We wish you submit a pull-request to `build_config/PLATFORM.rb`, once you
created a new configuration for a new platform.
Inside of the configuration file, the following options can be
Inside the configuration file, the following options can be
configured based on your environment.
### Toolchains
@@ -134,21 +135,21 @@ 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`:
```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"
```
@@ -228,7 +229,7 @@ end
### Preallocated Symbols
By far, preallocate symbols are highly compatible with the previous versions, so
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`.
@@ -270,7 +271,7 @@ See doc/mrbgems/README.md for more option about mrbgems.
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
@@ -279,7 +280,7 @@ conf.build_mrbtest_lib_only
### Bintest
Tests for mrbgem tools using CRuby.
To have bintests place \*.rb scripts to `bintest/` directory of mrbgems.
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/`.
@@ -308,9 +309,9 @@ If you need to enable C++ exception explicitly add the following:
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:
@@ -332,9 +333,9 @@ conf.enable_debug
When debugging mode is enabled
* Macro `MRB_DEBUG` would be defined.
* Which means `mrb_assert()` macro is enabled.
* 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.
* Because `-g` flag would be added to `mrbc` runner.
* You can have better backtrace of mruby scripts with this.
## Cross-Compilation
@@ -354,12 +355,12 @@ end
```
All configuration options of `MRuby::Build` can also be used in
`MRuby::CrossBuild`. You can find examples under the *build_config*
`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
@@ -375,49 +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
```
_____ _____ ______ ____ ____ _____ _____ ____
@@ -428,74 +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:
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* (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*
* 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
```
_______________________________________________________________
@@ -526,24 +502,22 @@ 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_NO_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 (e.g. 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
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
@@ -557,11 +531,14 @@ convenience. `mruby-config` command prints the configuration used for `libmruby.
$ 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
+7 -7
View File
@@ -38,7 +38,7 @@ To confirm mrdb was installed properly, run mrdb with the `--version` option:
```bash
$ mrdb --version
mruby 2.1.2 (2020-08-06)
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
@@ -324,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:
@@ -367,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]: https://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
```
+29 -28
View File
@@ -1,28 +1,28 @@
# 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.
* 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.
* 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.
## 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.
## Debug macros
`MRB_USE_DEBUG_HOOK`
@@ -54,16 +54,16 @@ You can use mrbconfs with following ways:
* Default value is `0x40000 - MRB_STACK_GROWTH`.
* Raises `RuntimeError` when stack size exceeds this value.
## Primitive type configuration.
## Primitive type configuration
`MRB_USE_FLOAT32`
* 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`.
* 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.
* When defined removes floating-point numbers from mruby.
* It makes mruby easier to handle in "Microcontroller without FPU" and "Kernel Space".
`MRB_INT32`
@@ -76,7 +76,7 @@ You can use mrbconfs with following ways:
* 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.
## Garbage collector configuration
`MRB_GC_STRESS`
@@ -104,7 +104,7 @@ You can use mrbconfs with following ways:
* Defines value is `1024`.
* Specifies number of `RBasic` per each heap page.
## Memory pool configuration.
## Memory pool configuration
`POOL_ALIGNMENT`
@@ -118,7 +118,7 @@ largest value of required alignment.
* Specifies page size of pool page.
* Smaller the value is increases memory overhead.
## State atexit configuration.
## State atexit configuration
`MRB_FIXED_STATE_ATEXIT_STACK`
@@ -131,7 +131,7 @@ largest value of required alignment.
* 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`
@@ -149,25 +149,26 @@ largest value of required alignment.
* If defined represent `mrb_value` as a word.
* If defined `Float` will be a mruby object with `RBasic`.
## Reduce heap memory configuration.
## Reduce heap memory configuration
`MRB_USE_LINK_TIME_RO_DATA_P`
`MRB_USE_ETEXT_RO_DATA_P`
* Only available on ELF platforms.
* If you specify the address of a read-only section when creating a symbol or string, that string will be used as it is.
* Heap memory can be saved.
* Uses `__ehdr_start` and `__init_array_start`.
* It must be `__ehdr_start < data_addr < __init_array_start`.
* 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`
* Takes precedence over `MRB_USE_LINK_TIME_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 read-only section, otherwise return `FALSE`.
* Return `TRUE` if `ptr` is in the read-only section, otherwise return `FALSE`.
## Other configuration.
## Other configuration
`MRB_UTF8_STRING`
+141 -91
View File
@@ -1,12 +1,13 @@
# 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
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:
a gem, add the following line to your build configuration file, for example:
```ruby
conf.gem '/path/to/your/gem/dir'
@@ -32,7 +33,7 @@ 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'
@@ -45,17 +46,17 @@ conf.gem :mgem => 'mruby-yaml'
conf.gem :mgem => 'yaml' # 'mruby-' prefix could be omitted
```
For specifying commit hash to checkout use `:checksum_hash` option:
For specifying the commit hash to checkout use `:checksum_hash` option:
```ruby
conf.gem mgem: 'mruby-redis', checksum_hash: '3446d19fc4a3f9697b5ddbf2a904f301c42f2f4e'
```
If there is missing dependencies, mrbgem dependencies solver will reference
mrbgem from core or mgem-list.
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```.
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.
@@ -69,7 +70,7 @@ 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|
@@ -79,10 +80,10 @@ 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*
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:
@@ -90,8 +91,8 @@ the build block:
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.
@@ -103,35 +104,39 @@ 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
@@ -143,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)
@@ -195,8 +200,8 @@ 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.
@@ -210,7 +215,7 @@ 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:
@@ -227,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)
@@ -242,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
@@ -251,7 +256,7 @@ 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 rake.
You can use `spec.export_include_paths` accessor if you want more complex build.
@@ -265,10 +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");
@@ -280,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);
@@ -292,24 +297,26 @@ 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
@@ -318,27 +325,29 @@ 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*.
@@ -348,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)
```
+8 -8
View File
@@ -4,7 +4,7 @@ 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
```c
struct mt_elem {
union mt_ptr ptr;
size_t func_p:1;
@@ -57,13 +57,13 @@ 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)
* `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
+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` |
|------------------|--------------|----------------------------------------------------------|
+12 -55
View File
@@ -13,28 +13,6 @@ 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.
## `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.1.2 (2020-08-06)]
```
[1, 2, 3]
```
## `Kernel.raise` in rescue clause
`Kernel.raise` without arguments does not raise the current exception within
@@ -52,9 +30,9 @@ end
`ZeroDivisionError` is raised.
#### mruby [2.1.2 (2020-08-06)]
#### mruby [3.0.0 (2021-03-05)]
No exception is raised. Instead you have to do:
`RuntimeError` is raised instead of `ZeroDivisionError`. To re-raise the exception, you have to do:
```ruby
begin
@@ -66,7 +44,7 @@ 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.
@@ -77,7 +55,7 @@ To reduce memory consumption `Array` does not support instance variables.
```ruby
class Liste < Array
def initialize(str = nil)
@feld = str
@field = str
end
end
@@ -88,14 +66,14 @@ p Liste.new "foobar"
` [] `
#### mruby [2.1.2 (2020-08-06)]
#### mruby [3.0.0 (2021-03-05)]
`ArgumentError` is raised.
## Method visibility
For simplicity reasons no method visibility (public/private/protected) is
supported. Those methods are defined but they are dummy methods.
supported. Those methods are defined, but they are dummy methods.
```ruby
class VisibleTest
@@ -118,7 +96,7 @@ false
true
```
#### mruby [2.1.2 (2020-08-06)]
#### mruby [3.0.0 (2021-03-05)]
```
true
@@ -155,7 +133,7 @@ p 'ok'
ok
```
#### mruby [2.1.2 (2020-08-06)]
#### mruby [3.0.0 (2021-03-05)]
```
test.rb:8: undefined method 'test_func' (NoMethodError)
@@ -177,7 +155,7 @@ defined?(Foo)
nil
```
#### mruby [2.1.2 (2020-08-06)]
#### mruby [3.0.0 (2021-03-05)]
`NameError` is raised.
@@ -194,7 +172,7 @@ alias $a $__a__
` nil `
#### mruby [2.1.2 (2020-08-06)]
#### mruby [3.0.0 (2021-03-05)]
Syntax error
@@ -216,7 +194,7 @@ end
`ArgumentError` is raised.
The re-defined `+` operator does not accept any arguments.
#### mruby [2.1.2 (2020-08-06)]
#### mruby [3.0.0 (2021-03-05)]
` 'ab' `
Behavior of the operator wasn't changed.
@@ -232,7 +210,7 @@ $ ruby -e 'puts Proc.new {}.binding'
#<Binding:0x00000e9deabb9950>
```
#### mruby [2.1.2 (2020-08-06)]
#### mruby [3.0.0 (2021-03-05)]
```
$ ./bin/mruby -e 'puts Proc.new {}.binding'
@@ -241,27 +219,6 @@ trace (most recent call last):
-e:1: undefined method 'binding' (NoMethodError)
```
## Keyword arguments
mruby keyword arguments behave slightly different from CRuby 2.5
to make the behavior simpler and less confusing.
#### 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}]
```
#### mruby [mruby 2.1.2]
```
$ ./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)
```
## `nil?` redefinition in conditional expressions
Redefinition of `nil?` is ignored in conditional expressions.
+1 -2
View File
@@ -1,5 +1,4 @@
User visible changes in `mruby3`
===
# User visible changes in `mruby3.0`
# Build System
+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.
-126
View File
@@ -1,126 +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
* 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 | BsS | R(a) = mrb_int(b) |
| 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_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(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=5:1:5:1:4) |
| OP_ENTER | W | arg setup according to flags (23=5:5:1:5:5:1:1) |
| 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=5:1:5:1:4) |
| 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 | B | ary_push(R(a),R(a+1)) |
| OP_ARYDUP | B | R(a) = ary_dup(R(a)) |
| OP_AREF | BBB | R(a) = R(b)[c] |
| OP_ASET | BBB | R(a)[c] = R(b) |
| 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(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_HASHCAT | B | R(a) = hash_cat(R(a),R(a+1)) |
| 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 | 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, Lit(a)) |
| OP_STOP | - | stop VM |
|------------------|--------------|--------------------------------------------------------|
@@ -5,9 +5,8 @@
static mrb_value
mrb_c_method(mrb_state *mrb, mrb_value self)
{
mrb_value self_str = mrb_str_to_str(mrb, self);
printf("%s: A C Extension\n", mrb_str_to_cstr(mrb, self_str));
mrb_ensure_string_type(mrb, self);
printf("%s: A C Extension\n", mrb_str_to_cstr(mrb, self));
return self;
}
@@ -5,9 +5,8 @@
static mrb_value
mrb_c_method(mrb_state *mrb, mrb_value self)
{
mrb_value self_str = mrb_str_to_str(mrb, self);
printf("%s: A C Extension\n", mrb_str_to_cstr(mrb, self_str));
mrb_ensure_string_type(mrb, self);
printf("%s: A C Extension\n", mrb_str_to_cstr(mrb, self));
return self;
}
+15 -17
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,10 +22,10 @@
#endif
/* configuration options: */
/* add -DMRB_USE_FLOAT32 to use float instead of double for floating point numbers */
/* add -DMRB_USE_FLOAT32 to use float instead of double for floating-point numbers */
//#define MRB_USE_FLOAT32
/* exclude floating point numbers */
/* exclude floating-point numbers */
//#define MRB_NO_FLOAT
/* obsolete configuration */
@@ -82,6 +79,9 @@
# 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
@@ -113,11 +113,17 @@
/* number of object per heap page */
//#define MRB_HEAP_PAGE_SIZE 1024
/* if __ehdr_start is available, mruby can reduce memory used by symbols */
//#define MRB_USE_LINK_TIME_RO_DATA_P
/* define if your platform does not support etext, edata */
//#define MRB_NO_DEFAULT_RO_DATA_P
/* if MRB_USE_LINK_TIME_RO_DATA_P does not work,
you can try mrb_ro_data_p() that you have implemented yourself in any file;
/* 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
@@ -181,14 +187,6 @@
# include <stdio.h>
#endif
#ifndef FALSE
# define FALSE 0
#endif
#ifndef TRUE
# define TRUE 1
#endif
/*
** mruby tuning profiles
**/
+86 -16
View File
@@ -44,6 +44,9 @@
#include <limits.h>
#ifdef __cplusplus
#ifndef UINTPTR_MAX
#error Must be placed `#include <mruby.h>` before `#include <stdint.h>`
#endif
#ifndef SIZE_MAX
#ifdef __SIZE_MAX__
#define SIZE_MAX __SIZE_MAX__
@@ -66,14 +69,18 @@
#define mrb_assert_int_fit(t1,n,t2,max) ((void)0)
#endif
#if (defined __cplusplus && __cplusplus >= 201103L) || \
#if (defined __cplusplus && __cplusplus >= 201703L)
# define mrb_static_assert(...) static_assert(__VA_ARGS__)
# define mrb_static_assert1(exp) static_assert(exp)
# define mrb_static_assert2(exp, str) static_assert(exp, str)
#elif (defined __cplusplus && __cplusplus >= 201103L) || \
(defined _MSC_VER) || \
(defined __GXX_EXPERIMENTAL_CXX0X__) /* for old G++/Clang++ */
# define mrb_static_assert(exp, str) static_assert(exp, str)
# define mrb_static_assert2(exp, str) static_assert(exp, str)
#elif defined __STDC_VERSION__ && \
((__STDC_VERSION__ >= 201112L) || \
(defined __GNUC__ && __GNUC__ * 100 + __GNUC_MINOR__ >= 406))
# define mrb_static_assert(exp, str) _Static_assert(exp, str)
# define mrb_static_assert2(exp, str) _Static_assert(exp, str)
#else
# /* alternative implementation of static_assert() */
# define _mrb_static_assert_cat0(a, b) a##b
@@ -83,10 +90,26 @@
# else
# define _mrb_static_assert_id(prefix) _mrb_static_assert_cat(prefix, __LINE__)
# endif
# define mrb_static_assert(exp, str) \
# define mrb_static_assert2(exp, str) \
struct _mrb_static_assert_id(_mrb_static_assert_) { char x[(exp) ? 1 : -1]; }
#endif
#define mrb_static_assert1(exp) mrb_static_assert(exp, #exp)
#ifndef mrb_static_assert
# define mrb_static_assert1(exp) mrb_static_assert2(exp, #exp)
# define mrb_static_assert_expand(...) __VA_ARGS__ /* for MSVC behaviour - https://stackoverflow.com/q/5530505 */
# define mrb_static_assert_selector(a, b, name, ...) name
/**
* The `mrb_static_assert()` macro function takes one or two arguments.
*
* !!!c
* mrb_static_assert(expect_condition);
* mrb_static_assert(expect_condition, error_message);
*/
# define mrb_static_assert(...) \
mrb_static_assert_expand(mrb_static_assert_selector(__VA_ARGS__, mrb_static_assert2, mrb_static_assert1, _)(__VA_ARGS__))
#endif
#define mrb_static_assert_powerof2(num) mrb_static_assert((num) > 0 && (num) == ((num) & -(num)), "need power of 2 for " #num)
#include "mrbconf.h"
@@ -96,6 +119,7 @@
#include <mruby/version.h>
#ifndef MRB_NO_FLOAT
#include <math.h>
#include <float.h>
#ifndef FLT_EPSILON
#define FLT_EPSILON (1.19209290e-07f)
@@ -149,9 +173,10 @@ typedef void* (*mrb_allocf) (struct mrb_state *mrb, void*, size_t, void *ud);
#endif
typedef struct {
uint8_t n:4; /* (15=*) c=n|nk<<4 */
uint8_t nk:4; /* (15=*) */
uint8_t cci; /* called from C function */
mrb_sym mid;
int16_t argc;
int16_t acc;
const struct RProc *proc;
mrb_value *stack;
const mrb_code *pc; /* current address on iseq of this proc */
@@ -185,6 +210,7 @@ struct mrb_context {
#ifdef MRB_METHOD_CACHE_SIZE
# undef MRB_NO_METHOD_CACHE
mrb_static_assert_powerof2(MRB_METHOD_CACHE_SIZE);
#else
/* default method cache size: 256 */
/* cache size needs to be power of 2 */
@@ -265,7 +291,9 @@ typedef struct mrb_state {
#endif
mrb_sym symidx;
struct symbol_name *symtbl; /* symbol table */
const char **symtbl;
uint8_t *symlink;
uint8_t *symflags;
mrb_sym symhash[256];
size_t symcapa;
#ifndef MRB_USE_ALL_SYMBOLS
@@ -886,19 +914,20 @@ MRB_API struct RClass* mrb_define_module_under_id(mrb_state *mrb, struct RClass
* | char | Ruby type | C types | Notes |
* |:----:|----------------|-------------------|----------------------------------------------------|
* | `o` | {Object} | {mrb_value} | Could be used to retrieve any type of argument |
* | `C` | {Class}/{Module} | {mrb_value} | |
* | `C` | {Class}/{Module} | {mrb_value} | when `!` follows, the value may be `nil` |
* | `S` | {String} | {mrb_value} | when `!` follows, the value may be `nil` |
* | `A` | {Array} | {mrb_value} | when `!` follows, the value may be `nil` |
* | `H` | {Hash} | {mrb_value} | when `!` follows, the value may be `nil` |
* | `s` | {String} | const char *, {mrb_int} | Receive two arguments; `s!` gives (`NULL`,`0`) for `nil` |
* | `z` | {String} | const char * | `NULL` terminated string; `z!` gives `NULL` for `nil` |
* | `a` | {Array} | const {mrb_value} *, {mrb_int} | Receive two arguments; `a!` gives (`NULL`,`0`) for `nil` |
* | `c` | {Class}/{Module} | strcut RClass * | `c!` gives `NULL` for `nil` |
* | `f` | {Integer}/{Float} | {mrb_float} | |
* | `i` | {Integer}/{Float} | {mrb_int} | |
* | `b` | boolean | {mrb_bool} | |
* | `n` | {String}/{Symbol} | {mrb_sym} | |
* | `d` | data | void *, {mrb_data_type} const | 2nd argument will be used to check data type so it won't be modified; when `!` follows, the value may be `nil` |
* | `I` | inline struct | void * | |
* | `I` | inline struct | void *, struct RClass | `I!` gives `NULL` for `nil` |
* | `&` | block | {mrb_value} | &! raises exception if no block given. |
* | `*` | rest arguments | const {mrb_value} *, {mrb_int} | Receive the rest of arguments as an array; `*!` avoid copy of the stack. |
* | <code>\|</code> | optional | | After this spec following specs would be optional. |
@@ -906,6 +935,13 @@ MRB_API struct RClass* mrb_define_module_under_id(mrb_state *mrb, struct RClass
* | `:` | keyword args | {mrb_kwargs} const | Get keyword arguments. @see mrb_kwargs |
*
* @see mrb_get_args
*
* Immediately after format specifiers it can add format modifiers:
*
* | char | Notes |
* |:----:|-----------------------------------------------------------------------------------------|
* | `!` | Switch to the alternate mode; The behaviour changes depending on the format specifier |
* | `+` | Request a not frozen object; However, except nil value |
*/
typedef const char *mrb_args_format;
@@ -1004,6 +1040,11 @@ MRB_API const mrb_value *mrb_get_argv(mrb_state *mrb);
*/
MRB_API mrb_value mrb_get_arg1(mrb_state *mrb);
/**
* Check if a block argument is given from mrb_state.
*/
MRB_API mrb_bool mrb_block_given_p(mrb_state *mrb);
/* `strlen` for character string literals (use with caution or `strlen` instead)
Adjacent string literals are concatenated in C/C++ in translation phase 6.
If `lit` is not one, the compiler will report a syntax error:
@@ -1126,6 +1167,17 @@ MRB_API void *mrb_malloc_simple(mrb_state*, size_t); /* return NULL if no memor
MRB_API struct RBasic *mrb_obj_alloc(mrb_state*, enum mrb_vtype, struct RClass*);
MRB_API void mrb_free(mrb_state*, void*);
/**
* Allocates a Ruby object that matches the constant literal defined in
* `enum mrb_vtype` and returns a pointer to the corresponding C type.
*
* @param mrb The current mruby state
* @param tt The constant literal of `enum mrb_vtype`
* @param klass A Class object
* @return Reference to the newly created object
*/
#define MRB_OBJ_ALLOC(mrb, tt, klass) ((MRB_VTYPE_TYPEOF(tt)*)mrb_obj_alloc(mrb, tt, klass))
MRB_API mrb_value mrb_str_new(mrb_state *mrb, const char *p, size_t len);
/**
@@ -1219,10 +1271,11 @@ MRB_API mrb_sym mrb_obj_to_sym(mrb_state *mrb, mrb_value name);
MRB_API mrb_bool mrb_obj_eq(mrb_state *mrb, mrb_value a, mrb_value b);
MRB_API mrb_bool mrb_obj_equal(mrb_state *mrb, mrb_value a, mrb_value b);
MRB_API mrb_bool mrb_equal(mrb_state *mrb, mrb_value obj1, mrb_value obj2);
MRB_API mrb_value mrb_convert_to_integer(mrb_state *mrb, mrb_value val, mrb_int base);
MRB_API mrb_value mrb_Integer(mrb_state *mrb, mrb_value val);
#ifndef MRB_NO_FLOAT
MRB_API mrb_value mrb_Float(mrb_state *mrb, mrb_value val);
MRB_API mrb_value mrb_ensure_float_type(mrb_state *mrb, mrb_value val);
#define mrb_as_float(mrb, x) mrb_float(mrb_ensure_float_type(mrb, x))
/* obsolete: use mrb_ensure_float_type() instead */
#define mrb_to_float(mrb, val) mrb_ensure_float_type(mrb, val)
#endif
MRB_API mrb_value mrb_inspect(mrb_state *mrb, mrb_value obj);
MRB_API mrb_bool mrb_eql(mrb_state *mrb, mrb_value obj1, mrb_value obj2);
@@ -1339,10 +1392,25 @@ MRB_API void mrb_gc_register(mrb_state *mrb, mrb_value obj);
/* mrb_gc_unregister() removes the object from GC root. */
MRB_API void mrb_gc_unregister(mrb_state *mrb, mrb_value obj);
MRB_API mrb_value mrb_to_int(mrb_state *mrb, mrb_value val);
#define mrb_int(mrb, val) mrb_integer(mrb_to_int(mrb, val))
/* type conversion/check functions */
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);
MRB_API mrb_value mrb_ensure_hash_type(mrb_state *mrb, mrb_value hash);
MRB_API mrb_value mrb_check_hash_type(mrb_state *mrb, mrb_value hash);
MRB_API mrb_value mrb_ensure_string_type(mrb_state *mrb, mrb_value str);
MRB_API mrb_value mrb_check_string_type(mrb_state *mrb, mrb_value str);
/* obsolete: use mrb_ensure_string_type() instead */
#define mrb_string_type(mrb, str) mrb_ensure_string_type(mrb,str)
#define mrb_to_str(mrb, str) mrb_ensure_string_type(mrb,str)
/* obsolete: use mrb_obj_as_string() instead */
#define mrb_str_to_str(mrb, str) mrb_obj_as_string(mrb, str)
MRB_API mrb_value mrb_ensure_int_type(mrb_state *mrb, mrb_value val);
#define mrb_as_int(mrb, val) mrb_integer(mrb_ensure_int_type(mrb, val))
/* obsolete: use mrb_ensure_int_type() instead */
#define mrb_to_integer(mrb, val) mrb_ensure_int_type(mrb, val)
#define mrb_to_int(mrb, val) mrb_ensure_int_type(mrb, val)
/* string type checking (contrary to the name, it doesn't convert) */
MRB_API mrb_value mrb_to_str(mrb_state *mrb, mrb_value val);
MRB_API void mrb_check_type(mrb_state *mrb, mrb_value x, enum mrb_vtype t);
MRB_INLINE void mrb_check_frozen(mrb_state *mrb, void *o)
@@ -1361,6 +1429,8 @@ MRB_API mrb_bool mrb_respond_to(mrb_state *mrb, mrb_value obj, mrb_sym mid);
MRB_API mrb_bool mrb_obj_is_instance_of(mrb_state *mrb, mrb_value obj, struct RClass* c);
MRB_API mrb_bool mrb_func_basic_p(mrb_state *mrb, mrb_value obj, mrb_sym mid, mrb_func_t func);
/* obsolete function(s); will be removed */
#define mrb_int(mrb, val) mrb_as_int(mrb, val)
/**
* Resume a Fiber
+8 -21
View File
@@ -14,15 +14,17 @@
*/
MRB_BEGIN_DECL
typedef struct mrb_shared_array {
int refcnt;
mrb_ssize len;
mrb_value *ptr;
} mrb_shared_array;
#if defined(MRB_32BIT) && defined(MRB_NO_BOXING)
#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)))
@@ -65,7 +67,7 @@ struct RArray {
#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))
@@ -107,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.
*/
@@ -176,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
*
@@ -200,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);
@@ -216,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
@@ -243,6 +229,7 @@ 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.
+121 -92
View File
@@ -15,116 +15,145 @@
# 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_SHIFT 0
#define MRB_SYMBOL_SHIFT 0
#define MRB_FIXNUM_MIN INT32_MIN
#define MRB_FIXNUM_MAX INT32_MAX
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 {
uint64_t u;
} mrb_value;
union mrb_value_ {
mrb_float f;
uint64_t u;
#ifdef MRB_64BIT
void *p;
# define BOXNAN_IMMEDIATE_VALUE uint32_t i
#else
# define BOXNAN_IMMEDIATE_VALUE union { uint32_t i; void *p; }
#endif
struct {
MRB_ENDIAN_LOHI(
uint32_t ttt;
,BOXNAN_IMMEDIATE_VALUE;
)
};
mrb_value value;
};
mrb_static_assert1(sizeof(mrb_value) == sizeof(union mrb_value_));
static inline union mrb_value_
mrb_val_union(mrb_value v)
static inline mrb_float
mrb_nan_boxing_value_float(mrb_value v)
{
union mrb_value_ x;
x.value = v;
return x;
union {
mrb_float f;
uint64_t u;
} x;
x.u = v.u - 0x8004000000000000;
return x.f;
}
#define mrb_tt(o) ((enum mrb_vtype)((mrb_val_union(o).ttt & 0xfc000)>>14)-1)
#define mrb_type(o) (enum mrb_vtype)((uint32_t)0xfff00000 < mrb_val_union(o).ttt ? mrb_tt(o) : MRB_TT_FLOAT)
#define mrb_float(o) mrb_val_union(o).f
#define mrb_fixnum(o) ((mrb_int)mrb_val_union(o).i)
#define mrb_integer(o) mrb_fixnum(o)
#define mrb_symbol(o) ((mrb_sym)mrb_val_union(o).i)
#ifdef MRB_64BIT
#define mrb_ptr(o) ((void*)((((uintptr_t)0x3fffffffffff)&((uintptr_t)(mrb_val_union(o).p)))<<2))
#define mrb_cptr(o) (((struct RCptr*)mrb_ptr(o))->p)
#define BOXNAN_SHIFT_LONG_POINTER(v) (((uintptr_t)(v)>>34)&0x3fff)
#else
#define mrb_ptr(o) ((void*)mrb_val_union(o).i)
#define mrb_cptr(o) mrb_ptr(o)
#define BOXNAN_SHIFT_LONG_POINTER(v) 0
#endif
#define BOXNAN_SET_VALUE(o, tt, attr, v) do { \
union mrb_value_ mrb_value_union_variable; \
mrb_value_union_variable.attr = (v);\
mrb_value_union_variable.ttt = 0xfff00000 | (((tt)+1)<<14);\
o = mrb_value_union_variable.value;\
} while (0)
#ifdef MRB_64BIT
#define BOXNAN_SET_OBJ_VALUE(o, tt, v) do {\
union mrb_value_ mrb_value_union_variable;\
mrb_value_union_variable.p = (void*)((uintptr_t)(v)>>2);\
mrb_value_union_variable.ttt = (0xfff00000|(((tt)+1)<<14)|BOXNAN_SHIFT_LONG_POINTER(v));\
o = mrb_value_union_variable.value;\
} while (0)
#else
#define BOXNAN_SET_OBJ_VALUE(o, tt, v) BOXNAN_SET_VALUE(o, tt, i, (uint32_t)v)
#endif
#define SET_FLOAT_VALUE(mrb,r,v) do { \
union mrb_value_ mrb_value_union_variable; \
if ((v) != (v)) { /* NaN */ \
mrb_value_union_variable.ttt = 0x7ff80000; \
mrb_value_union_variable.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 { \
mrb_value_union_variable.f = (v); \
float_uint_union.f = (f); \
} \
r = mrb_value_union_variable.value; \
r.u = float_uint_union.u + 0x8004000000000000; \
} while(0)
#define SET_NIL_VALUE(r) BOXNAN_SET_VALUE(r, MRB_TT_FALSE, i, 0)
#define SET_FALSE_VALUE(r) BOXNAN_SET_VALUE(r, MRB_TT_FALSE, i, 1)
#define SET_TRUE_VALUE(r) BOXNAN_SET_VALUE(r, MRB_TT_TRUE, i, 1)
#define SET_BOOL_VALUE(r,b) BOXNAN_SET_VALUE(r, b ? MRB_TT_TRUE : MRB_TT_FALSE, i, 1)
#define SET_INT_VALUE(mrb, r,n) BOXNAN_SET_VALUE(r, MRB_TT_INTEGER, i, (uint32_t)(n))
#define SET_FIXNUM_VALUE(r,n) BOXNAN_SET_VALUE(r, MRB_TT_INTEGER, i, (uint32_t)(n))
#define SET_SYM_VALUE(r,v) BOXNAN_SET_VALUE(r, MRB_TT_SYMBOL, i, (uint32_t)(v))
#define SET_OBJ_VALUE(r,v) BOXNAN_SET_OBJ_VALUE(r, (((struct RObject*)(v))->tt), (v))
#ifdef MRB_64BIT
MRB_API mrb_value mrb_nan_boxing_cptr_value(struct mrb_state*, void*);
#define SET_CPTR_VALUE(mrb,r,v) ((r) = mrb_nan_boxing_cptr_value(mrb, v))
#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 SET_CPTR_VALUE(mrb,r,v) BOXNAN_SET_VALUE(r, MRB_TT_CPTR, p, v)
#define mrb_fixnum(o) ((mrb_int)(int32_t)((o).u))
#endif
#define SET_UNDEF_VALUE(r) BOXNAN_SET_VALUE(r, MRB_TT_UNDEF, i, 0)
*/
#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 */
+105 -79
View File
@@ -7,7 +7,11 @@
#ifndef MRUBY_BOXING_WORD_H
#define MRUBY_BOXING_WORD_H
#ifndef MRB_NO_FLOAT
#if defined(MRB_32BIT) && !defined(MRB_USE_FLOAT32) && !defined(MRB_WORDBOX_NO_FLOAT_TRUNCATE)
# define MRB_WORDBOX_NO_FLOAT_TRUNCATE
#endif
#if !defined(MRB_NO_FLOAT) && defined(MRB_WORDBOX_NO_FLOAT_TRUNCATE)
struct RFloat {
MRB_OBJECT_HEADER;
mrb_float f;
@@ -29,9 +33,9 @@ enum mrb_special_consts {
#if defined(MRB_64BIT) && defined(MRB_INT32)
#define MRB_FIXNUM_SHIFT 0
#else
#define MRB_FIXNUM_SHIFT BOXWORD_FIXNUM_SHIFT
#define MRB_FIXNUM_SHIFT WORDBOX_FIXNUM_SHIFT
#endif
#define MRB_SYMBOL_SHIFT BOXWORD_SYMBOL_SHIFT
#define MRB_SYMBOL_SHIFT WORDBOX_SYMBOL_SHIFT
#if defined(MRB_64BIT) && defined(MRB_INT64)
# define MRB_FIXNUM_MIN (INT64_MIN>>MRB_FIXNUM_SHIFT)
@@ -41,36 +45,68 @@ enum mrb_special_consts {
# define MRB_FIXNUM_MAX (INT32_MAX>>MRB_FIXNUM_SHIFT)
#endif
#define BOXWORD_FIXNUM_BIT_POS 1
#define BOXWORD_SYMBOL_BIT_POS 2
#define BOXWORD_FIXNUM_SHIFT BOXWORD_FIXNUM_BIT_POS
#ifdef MRB_64BIT
#define BOXWORD_SYMBOL_SHIFT 0
#else
#define BOXWORD_SYMBOL_SHIFT BOXWORD_SYMBOL_BIT_POS
#endif
#define BOXWORD_FIXNUM_FLAG (1 << (BOXWORD_FIXNUM_BIT_POS - 1))
#define BOXWORD_SYMBOL_FLAG (1 << (BOXWORD_SYMBOL_BIT_POS - 1))
#define BOXWORD_FIXNUM_MASK ((1 << BOXWORD_FIXNUM_BIT_POS) - 1)
#define BOXWORD_SYMBOL_MASK ((1 << BOXWORD_SYMBOL_BIT_POS) - 1)
#define BOXWORD_IMMEDIATE_MASK 0x07
#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)
#define BOXWORD_SET_SHIFT_VALUE(o,n,v) \
((o).w = (((uintptr_t)(v)) << BOXWORD_##n##_SHIFT) | BOXWORD_##n##_FLAG)
#define BOXWORD_SHIFT_VALUE_P(o,n) \
(((o).w & BOXWORD_##n##_MASK) == BOXWORD_##n##_FLAG)
#define BOXWORD_OBJ_TYPE_P(o,n) \
#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
#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 (use only upper 32-bit as symbol value on 64-bit CPU)
* symbol: ...SSSS SS10
* object: ...PPPP P000 (any bits are 1)
*/
typedef struct mrb_value {
@@ -79,18 +115,13 @@ typedef struct mrb_value {
union mrb_value_ {
void *p;
#ifdef MRB_64BIT
/* use struct to avoid bit shift. */
struct {
MRB_ENDIAN_LOHI(
mrb_sym sym;
,uint32_t sym_flag;
)
};
#endif
struct RBasic *bp;
#ifndef MRB_NO_FLOAT
#ifndef MRB_WORDBOX_NO_FLOAT_TRUNCATE
mrb_float f;
#else
struct RFloat *fp;
#endif
#endif
struct RInteger *ip;
struct RCptr *vp;
@@ -98,7 +129,7 @@ union mrb_value_ {
mrb_value value;
};
mrb_static_assert1(sizeof(mrb_value) == sizeof(union mrb_value_));
mrb_static_assert(sizeof(mrb_value) == sizeof(union mrb_value_));
static inline union mrb_value_
mrb_val_union(mrb_value v)
@@ -112,61 +143,62 @@ 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_word_boxing_int_value(struct mrb_state*, mrb_int);
MRB_API mrb_value mrb_boxing_int_value(struct mrb_state*, mrb_int);
#define mrb_immediate_p(o) ((o).w & BOXWORD_IMMEDIATE_MASK || (o).w == MRB_Qnil)
#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
#define mrb_float(o) mrb_val_union(o).fp->f
#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
#define mrb_fixnum(o) (mrb_int)(((intptr_t)(o).w) >> BOXWORD_FIXNUM_SHIFT)
#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)
#ifdef MRB_64BIT
#define mrb_symbol(o) mrb_val_union(o).sym
#else
#define mrb_symbol(o) (mrb_sym)(((o).w) >> BOXWORD_SYMBOL_SHIFT)
#endif
#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) BOXWORD_SHIFT_VALUE_P(o, FIXNUM)
#define mrb_integer_p(o) (BOXWORD_SHIFT_VALUE_P(o, FIXNUM)||BOXWORD_OBJ_TYPE_P(o, INTEGER))
#ifdef MRB_64BIT
#define mrb_symbol_p(o) (mrb_val_union(o).sym_flag == BOXWORD_SYMBOL_FLAG)
#else
#define mrb_symbol_p(o) BOXWORD_SHIFT_VALUE_P(o, SYMBOL)
#endif
#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 mrb_false_p(o) ((o).w == MRB_Qfalse)
#define mrb_true_p(o) ((o).w == MRB_Qtrue)
#ifndef MRB_NO_FLOAT
#define mrb_float_p(o) BOXWORD_OBJ_TYPE_P(o, 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 mrb_array_p(o) BOXWORD_OBJ_TYPE_P(o, ARRAY)
#define mrb_string_p(o) BOXWORD_OBJ_TYPE_P(o, STRING)
#define mrb_hash_p(o) BOXWORD_OBJ_TYPE_P(o, HASH)
#define mrb_cptr_p(o) BOXWORD_OBJ_TYPE_P(o, CPTR)
#define mrb_exception_p(o) BOXWORD_OBJ_TYPE_P(o, EXCEPTION)
#define mrb_free_p(o) BOXWORD_OBJ_TYPE_P(o, FREE)
#define mrb_object_p(o) BOXWORD_OBJ_TYPE_P(o, OBJECT)
#define mrb_class_p(o) BOXWORD_OBJ_TYPE_P(o, CLASS)
#define mrb_module_p(o) BOXWORD_OBJ_TYPE_P(o, MODULE)
#define mrb_iclass_p(o) BOXWORD_OBJ_TYPE_P(o, ICLASS)
#define mrb_sclass_p(o) BOXWORD_OBJ_TYPE_P(o, SCLASS)
#define mrb_proc_p(o) BOXWORD_OBJ_TYPE_P(o, PROC)
#define mrb_range_p(o) BOXWORD_OBJ_TYPE_P(o, RANGE)
#define mrb_env_p(o) BOXWORD_OBJ_TYPE_P(o, ENV)
#define mrb_data_p(o) BOXWORD_OBJ_TYPE_P(o, DATA)
#define mrb_fiber_p(o) BOXWORD_OBJ_TYPE_P(o, FIBER)
#define mrb_istruct_p(o) BOXWORD_OBJ_TYPE_P(o, ISTRUCT)
#define mrb_break_p(o) BOXWORD_OBJ_TYPE_P(o, BREAK)
#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))
@@ -177,18 +209,9 @@ mrb_integer_func(mrb_value o) {
#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_word_boxing_int_value(mrb, n))
#define SET_FIXNUM_VALUE(r,n) BOXWORD_SET_SHIFT_VALUE(r, FIXNUM, n)
#ifdef MRB_64BIT
#define SET_SYM_VALUE(r,v) do {\
union mrb_value_ mrb_value_union_variable;\
mrb_value_union_variable.sym = v;\
mrb_value_union_variable.sym_flag = BOXWORD_SYMBOL_FLAG;\
(r) = mrb_value_union_variable.value;\
} while (0)
#else
#define SET_SYM_VALUE(r,n) BOXWORD_SET_SHIFT_VALUE(r, SYMBOL, n)
#endif
#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
@@ -199,6 +222,9 @@ mrb_type(mrb_value o)
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;
}
+6
View File
@@ -28,6 +28,12 @@
# 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
*/
+3 -4
View File
@@ -16,8 +16,6 @@ MRB_BEGIN_DECL
#include <mruby.h>
struct mrb_jmpbuf;
struct mrb_parser_state;
/* load context */
typedef struct mrbc_context {
@@ -33,6 +31,7 @@ typedef struct mrbc_context {
mrb_bool no_exec:1;
mrb_bool keep_lv:1;
mrb_bool no_optimize:1;
mrb_bool no_ext_ops:1;
const struct RProc *upper;
size_t parser_nerr;
@@ -58,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. */
@@ -157,6 +156,7 @@ struct mrb_parser_state {
mrb_bool no_optimize: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];
@@ -165,7 +165,6 @@ struct mrb_parser_state {
uint16_t filename_table_length;
uint16_t current_filename_index;
struct mrb_jmpbuf* jmp;
mrb_ast_node *nvars;
};
+4 -2
View File
@@ -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 {
@@ -31,8 +32,9 @@ typedef struct mrb_irep_debug_info_file {
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;
+5 -2
View File
@@ -16,7 +16,10 @@
*/
MRB_BEGIN_DECL
#define DUMP_DEBUG_INFO 1
/* flags for mrb_dump_irep{,_binary,_cfunc,_cstruct} */
#define MRB_DUMP_DEBUG_INFO 1
#define MRB_DUMP_STATIC 2
#define DUMP_DEBUG_INFO MRB_DUMP_DEBUG_INFO /* deprecated */
int mrb_dump_irep(mrb_state *mrb, const mrb_irep *irep, uint8_t flags, uint8_t **bin, size_t *bin_size);
#ifndef MRB_NO_STDIO
@@ -51,7 +54,7 @@ MRB_API mrb_irep *mrb_read_irep_buf(mrb_state*, const void*, size_t);
/* Binary Format Version Major:Minor */
/* Major: Incompatible to prior versions */
/* Minor: Upper-compatible to prior versions */
#define RITE_BINARY_MAJOR_VER "02"
#define RITE_BINARY_MAJOR_VER "03"
#define RITE_BINARY_MINOR_VER "00"
#define RITE_BINARY_FORMAT_VER RITE_BINARY_MAJOR_VER RITE_BINARY_MINOR_VER
#define RITE_COMPILER_NAME "MATZ"
+12 -2
View File
@@ -17,17 +17,20 @@ MRB_BEGIN_DECL
struct RException {
MRB_OBJECT_HEADER;
struct iv_tbl *iv;
struct RString *mesg;
};
#define mrb_exc_ptr(v) ((struct RException*)mrb_ptr(v))
#define MRB_EXC_MESG_STRING_FLAG 0x100
MRB_API void mrb_sys_fail(mrb_state *mrb, const char *mesg);
MRB_API mrb_value mrb_exc_new_str(mrb_state *mrb, struct RClass* c, mrb_value str);
#define mrb_exc_new_lit(mrb, c, lit) mrb_exc_new_str(mrb, c, mrb_str_new_lit(mrb, lit))
#define mrb_exc_new_str_lit(mrb, c, lit) mrb_exc_new_lit(mrb, c, lit)
MRB_API mrb_value mrb_make_exception(mrb_state *mrb, mrb_int argc, const mrb_value *argv);
MRB_API mrb_value mrb_exc_backtrace(mrb_state *mrb, mrb_value exc);
MRB_API mrb_value mrb_get_backtrace(mrb_state *mrb);
mrb_value mrb_exc_backtrace(mrb_state *mrb, mrb_value exc);
mrb_value mrb_get_backtrace(mrb_state *mrb);
MRB_API mrb_noreturn void mrb_no_method_error(mrb_state *mrb, mrb_sym id, mrb_value args, const char *fmt, ...);
/* declaration for `fail` method */
@@ -103,6 +106,13 @@ mrb_break_tag_set(struct RBreak *brk, uint32_t tag)
/**
* Protect
*
*/
typedef mrb_value mrb_protect_error_func(mrb_state *mrb, void *userdata);
MRB_API mrb_value mrb_protect_error(mrb_state *mrb, mrb_protect_error_func *body, void *userdata, mrb_bool *error);
/**
* Protect (takes mrb_value for body argument)
*
* Implemented in the mruby-error mrbgem
*/
MRB_API mrb_value mrb_protect(mrb_state *mrb, mrb_func_t body, mrb_value data, mrb_bool *state);
+2
View File
@@ -87,6 +87,8 @@ typedef struct mrb_gc {
MRB_API mrb_bool
mrb_object_dead_p(struct mrb_state *mrb, struct RBasic *object);
#define MRB_GC_RED 7
MRB_END_DECL
#endif /* MRUBY_GC_H */
+1 -3
View File
@@ -29,7 +29,7 @@ struct RHash {
union {
struct hash_entry *ea;
struct hash_table *ht;
};
} hsh;
};
#define mrb_hash_ptr(v) ((struct RHash*)(mrb_ptr(v)))
@@ -37,8 +37,6 @@ struct RHash {
size_t mrb_hash_memsize(mrb_value obj);
MRB_API mrb_value mrb_hash_new_capa(mrb_state *mrb, mrb_int capa);
MRB_API mrb_value mrb_ensure_hash_type(mrb_state *mrb, mrb_value hash);
MRB_API mrb_value mrb_check_hash_type(mrb_state *mrb, mrb_value hash);
/*
* Initializes a new hash.
+4 -4
View File
@@ -20,6 +20,7 @@ enum irep_pool_type {
IREP_TT_SSTR = 2, /* string (static) */
IREP_TT_INT32 = 1, /* 32bit integer */
IREP_TT_INT64 = 3, /* 64bit integer */
IREP_TT_BIGINT = 7, /* big integer (not yet supported) */
IREP_TT_FLOAT = 5, /* float (double/float) */
};
@@ -31,9 +32,7 @@ typedef struct mrb_pool_value {
union {
const char *str;
int32_t i32;
#if defined(MRB_64BIT) || defined(MRB_INT64)
int64_t i64;
#endif
#ifndef MRB_NO_FLOAT
mrb_float f;
#endif
@@ -47,8 +46,8 @@ enum mrb_catch_type {
struct mrb_irep_catch_handler {
uint8_t type; /* enum mrb_catch_type */
uint8_t begin[4]; /* The starting address to match the hander. Includes this. */
uint8_t end[4]; /* The endpoint address that matches the hander. Not Includes this. */
uint8_t begin[4]; /* The starting address to match the handler. Includes this. */
uint8_t end[4]; /* The endpoint address that matches the handler. Not Includes this. */
uint8_t target[4]; /* The address to jump to if a match is made. */
};
@@ -124,6 +123,7 @@ struct mrb_insn_data {
uint16_t a;
uint16_t b;
uint16_t c;
const mrb_code *addr;
};
struct mrb_insn_data mrb_decode_insn(const mrb_code *pc);
+21 -13
View File
@@ -30,21 +30,19 @@ MRB_BEGIN_DECL
#endif
#endif
#ifndef MRB_NO_FLOAT
MRB_API mrb_value mrb_flo_to_fixnum(mrb_state *mrb, mrb_value val);
#endif
MRB_API mrb_value mrb_fixnum_to_str(mrb_state *mrb, mrb_value x, mrb_int base);
/* ArgumentError if format string doesn't match /%(\.[0-9]+)?[aAeEfFgG]/ */
#ifndef MRB_NO_FLOAT
MRB_API mrb_value mrb_float_to_str(mrb_state *mrb, mrb_value x, const char *fmt);
MRB_API int mrb_float_to_cstr(mrb_state *mrb, char *buf, size_t len, const char *fmt, mrb_float f);
MRB_API mrb_float mrb_to_flo(mrb_state *mrb, mrb_value x);
#endif
MRB_API mrb_value mrb_num_plus(mrb_state *mrb, mrb_value x, mrb_value y);
MRB_API mrb_value mrb_num_minus(mrb_state *mrb, mrb_value x, mrb_value y);
MRB_API mrb_value mrb_num_mul(mrb_state *mrb, mrb_value x, mrb_value y);
MRB_API mrb_value mrb_integer_to_str(mrb_state *mrb, mrb_value x, mrb_int base);
MRB_API char *mrb_int_to_cstr(char *buf, size_t len, mrb_int n, mrb_int base);
/* internal function(s) */
mrb_int mrb_div_int(mrb_state *mrb, mrb_int x, mrb_int y);
/* obsolete function(s); will be removed */
#define mrb_fixnum_to_str(mrb, x, base) mrb_integer_to_str(mrb, x, base)
#ifndef __has_builtin
#define __has_builtin(x) 0
#endif
@@ -135,8 +133,6 @@ mrb_int_mul_overflow(mrb_int a, mrb_int b, mrb_int *c)
#endif
#ifndef MRB_NO_FLOAT
# include <stdint.h>
# include <float.h>
# define MRB_FLT_RADIX FLT_RADIX
@@ -162,6 +158,18 @@ mrb_int_mul_overflow(mrb_int a, mrb_int b, mrb_int *c)
# define MRB_FLT_MAX DBL_MAX
# define MRB_FLT_MAX_10_EXP DBL_MAX_10_EXP
# endif /* MRB_USE_FLOAT32 */
MRB_API mrb_value mrb_float_to_integer(mrb_state *mrb, mrb_value val);
/* internal functions */
mrb_float mrb_div_float(mrb_float x, mrb_float y);
mrb_value mrb_float_to_str(mrb_state *mrb, mrb_value x, const char *fmt);
int mrb_format_float(mrb_float f, char *buf, size_t buf_size, char fmt, int prec, char sign);
/* obsolete functions; will be removed */
#define mrb_flo_to_fixnum(mrb, val) mrb_float_to_integer(mrb, val)
#define mrb_to_flo(mrb, x) mrb_as_float(mrb, x)
#endif /* MRB_NO_FLOAT */
MRB_END_DECL
+30
View File
@@ -40,4 +40,34 @@ enum mrb_insn {
#define FETCH_S() do {a=READ_S();} while (0)
#define FETCH_W() do {a=READ_W();} while (0)
/* with OP_EXT1 (1st 16bit) */
#define FETCH_Z_1() FETCH_Z()
#define FETCH_B_1() FETCH_S()
#define FETCH_BB_1() do {a=READ_S(); b=READ_B();} while (0)
#define FETCH_BBB_1() do {a=READ_S(); b=READ_B(); c=READ_B();} while (0)
#define FETCH_BS_1() do {a=READ_S(); b=READ_S();} while (0)
#define FETCH_BSS_1() do {a=READ_S(); b=READ_S();c=READ_S();} while (0)
#define FETCH_S_1() FETCH_S()
#define FETCH_W_1() FETCH_W()
/* with OP_EXT2 (2nd 16bit) */
#define FETCH_Z_2() FETCH_Z()
#define FETCH_B_2() FETCH_B()
#define FETCH_BB_2() do {a=READ_B(); b=READ_S();} while (0)
#define FETCH_BBB_2() do {a=READ_B(); b=READ_S(); c=READ_B();} while (0)
#define FETCH_BS_2() FETCH_BS()
#define FETCH_BSS_2() FETCH_BSS()
#define FETCH_S_2() FETCH_S()
#define FETCH_W_2() FETCH_W()
/* with OP_EXT3 (1st & 2nd 16bit) */
#define FETCH_Z_3() FETCH_Z()
#define FETCH_B_3() FETCH_B()
#define FETCH_BB_3() do {a=READ_S(); b=READ_S();} while (0)
#define FETCH_BBB_3() do {a=READ_S(); b=READ_S(); c=READ_B();} while (0)
#define FETCH_BS_3() do {a=READ_S(); b=READ_S();} while (0)
#define FETCH_BSS_3() FETCH_BSS_1()
#define FETCH_S_3() FETCH_S()
#define FETCH_W_3() FETCH_W()
#endif /* MRUBY_OPCODE_H */
+99 -101
View File
@@ -13,110 +13,108 @@
operation code operands semantics
------------------------------------------------------------------------*/
OPCODE(NOP, Z) /* no operation */
OPCODE(MOVE, BB) /* R(a) = R(b) */
OPCODE(LOADL, BB) /* R(a) = Pool(b) */
OPCODE(LOADL16, BS) /* R(a) = Pool(b) */
OPCODE(LOADI, BB) /* R(a) = mrb_int(b) */
OPCODE(LOADINEG, BB) /* R(a) = mrb_int(-b) */
OPCODE(LOADI__1, B) /* R(a) = mrb_int(-1) */
OPCODE(LOADI_0, B) /* R(a) = mrb_int(0) */
OPCODE(LOADI_1, B) /* R(a) = mrb_int(1) */
OPCODE(LOADI_2, B) /* R(a) = mrb_int(2) */
OPCODE(LOADI_3, B) /* R(a) = mrb_int(3) */
OPCODE(LOADI_4, B) /* R(a) = mrb_int(4) */
OPCODE(LOADI_5, B) /* R(a) = mrb_int(5) */
OPCODE(LOADI_6, B) /* R(a) = mrb_int(6) */
OPCODE(LOADI_7, B) /* R(a) = mrb_int(7) */
OPCODE(LOADI16, BS) /* R(a) = mrb_int(b) */
OPCODE(LOADI32, BSS) /* R(a) = mrb_int((b<<16)+c) */
OPCODE(LOADSYM, BB) /* R(a) = Syms(b) */
OPCODE(LOADSYM16, BS) /* R(a) = Syms(b) */
OPCODE(LOADNIL, B) /* R(a) = nil */
OPCODE(LOADSELF, B) /* R(a) = self */
OPCODE(LOADT, B) /* R(a) = true */
OPCODE(LOADF, B) /* R(a) = false */
OPCODE(GETGV, BB) /* R(a) = getglobal(Syms(b)) */
OPCODE(SETGV, BB) /* setglobal(Syms(b), R(a)) */
OPCODE(GETSV, BB) /* R(a) = Special[Syms(b)] */
OPCODE(SETSV, BB) /* Special[Syms(b)] = R(a) */
OPCODE(GETIV, BB) /* R(a) = ivget(Syms(b)) */
OPCODE(SETIV, BB) /* ivset(Syms(b),R(a)) */
OPCODE(GETCV, BB) /* R(a) = cvget(Syms(b)) */
OPCODE(SETCV, BB) /* cvset(Syms(b),R(a)) */
OPCODE(GETCONST, BB) /* R(a) = constget(Syms(b)) */
OPCODE(SETCONST, BB) /* constset(Syms(b),R(a)) */
OPCODE(GETMCNST, BB) /* R(a) = R(a)::Syms(b) */
OPCODE(SETMCNST, BB) /* R(a+1)::Syms(b) = R(a) */
OPCODE(GETUPVAR, BBB) /* R(a) = uvget(b,c) */
OPCODE(SETUPVAR, BBB) /* uvset(b,c,R(a)) */
OPCODE(MOVE, BB) /* R[a] = R[b] */
OPCODE(LOADL, BB) /* R[a] = Pool[b] */
OPCODE(LOADI, BB) /* R[a] = mrb_int(b) */
OPCODE(LOADINEG, BB) /* R[a] = mrb_int(-b) */
OPCODE(LOADI__1, B) /* R[a] = mrb_int(-1) */
OPCODE(LOADI_0, B) /* R[a] = mrb_int(0) */
OPCODE(LOADI_1, B) /* R[a] = mrb_int(1) */
OPCODE(LOADI_2, B) /* R[a] = mrb_int(2) */
OPCODE(LOADI_3, B) /* R[a] = mrb_int(3) */
OPCODE(LOADI_4, B) /* R[a] = mrb_int(4) */
OPCODE(LOADI_5, B) /* R[a] = mrb_int(5) */
OPCODE(LOADI_6, B) /* R[a] = mrb_int(6) */
OPCODE(LOADI_7, B) /* R[a] = mrb_int(7) */
OPCODE(LOADI16, BS) /* R[a] = mrb_int(b) */
OPCODE(LOADI32, BSS) /* R[a] = mrb_int((b<<16)+c) */
OPCODE(LOADSYM, BB) /* R[a] = Syms[b] */
OPCODE(LOADNIL, B) /* R[a] = nil */
OPCODE(LOADSELF, B) /* R[a] = self */
OPCODE(LOADT, B) /* R[a] = true */
OPCODE(LOADF, B) /* R[a] = false */
OPCODE(GETGV, BB) /* R[a] = getglobal(Syms[b]) */
OPCODE(SETGV, BB) /* setglobal(Syms[b], R[a]) */
OPCODE(GETSV, BB) /* R[a] = Special[Syms[b]] */
OPCODE(SETSV, BB) /* Special[Syms[b]] = R[a] */
OPCODE(GETIV, BB) /* R[a] = ivget(Syms[b]) */
OPCODE(SETIV, BB) /* ivset(Syms[b],R[a]) */
OPCODE(GETCV, BB) /* R[a] = cvget(Syms[b]) */
OPCODE(SETCV, BB) /* cvset(Syms[b],R[a]) */
OPCODE(GETCONST, BB) /* R[a] = constget(Syms[b]) */
OPCODE(SETCONST, BB) /* constset(Syms[b],R[a]) */
OPCODE(GETMCNST, BB) /* R[a] = R[a]::Syms[b] */
OPCODE(SETMCNST, BB) /* R[a+1]::Syms[b] = R[a] */
OPCODE(GETUPVAR, BBB) /* R[a] = uvget(b,c) */
OPCODE(SETUPVAR, BBB) /* uvset(b,c,R[a]) */
OPCODE(GETIDX, B) /* R[a] = R[a][R[a+1]] */
OPCODE(SETIDX, B) /* R[a][R[a+1]] = R[a+2] */
OPCODE(JMP, S) /* pc+=a */
OPCODE(JMPIF, BS) /* if R(a) pc+=b */
OPCODE(JMPNOT, BS) /* if !R(a) pc+=b */
OPCODE(JMPNIL, BS) /* if R(a)==nil pc+=b */
OPCODE(JMPIF, BS) /* if R[a] pc+=b */
OPCODE(JMPNOT, BS) /* if !R[a] pc+=b */
OPCODE(JMPNIL, BS) /* if R[a]==nil pc+=b */
OPCODE(JMPUW, S) /* unwind_and_jump_to(a) */
OPCODE(EXCEPT, B) /* R(a) = exc */
OPCODE(RESCUE, BB) /* R(b) = R(a).isa?(R(b)) */
OPCODE(RAISEIF, B) /* raise(R(a)) if R(a) */
OPCODE(SENDV, BB) /* R(a) = call(R(a),Syms(b),*R(a+1)) */
OPCODE(SENDVB, BB) /* R(a) = call(R(a),Syms(b),*R(a+1),&R(a+2)) */
OPCODE(SEND, BBB) /* R(a) = call(R(a),Syms(b),R(a+1),...,R(a+c)) */
OPCODE(SENDB, BBB) /* R(a) = call(R(a),Syms(b),R(a+1),...,R(a+c),&R(a+c+1)) */
OPCODE(SENDVK, BB) /* R(a) = call(R(a),Syms(b),*R(a+1),**(a+2),&R(a+3)) # todo */
OPCODE(CALL, Z) /* R(0) = self.call(frame.argc, frame.argv) */
OPCODE(SUPER, BB) /* R(a) = super(R(a+1),... ,R(a+b+1)) */
OPCODE(ARGARY, BS) /* R(a) = argument array (16=m5:r1:m5:d1:lv4) */
OPCODE(EXCEPT, B) /* R[a] = exc */
OPCODE(RESCUE, BB) /* R[b] = R[a].isa?(R[b]) */
OPCODE(RAISEIF, B) /* raise(R[a]) if R[a] */
OPCODE(SSEND, BBB) /* R[a] = self.send(Syms[b],R[a+1]..,R[a+n+1]:R[a+n+2]..) (c=n|k<<4) */
OPCODE(SSENDB, BBB) /* R[a] = self.send(Syms[b],R[a+1]..,R[a+n+1]:R[a+n+2]..,&R[a+n+2k+1]) */
OPCODE(SEND, BBB) /* R[a] = R[a].send(Syms[b],R[a+1]..,R[a+n+1]:R[a+n+2]..) (c=n|k<<4) */
OPCODE(SENDB, BBB) /* R[a] = R[a].send(Syms[b],R[a+1]..,R[a+n+1]:R[a+n+2]..,&R[a+n+2k+1]) */
OPCODE(CALL, Z) /* R[0] = self.call(frame.argc, frame.argv) */
OPCODE(SUPER, BB) /* R[a] = super(R[a+1],... ,R[a+b+1]) */
OPCODE(ARGARY, BS) /* R[a] = argument array (16=m5:r1:m5:d1:lv4) */
OPCODE(ENTER, W) /* arg setup according to flags (23=m5:o5:r1:m5:k5:d1:b1) */
OPCODE(KEY_P, BB) /* R(a) = kdict.key?(Syms(b)) */
OPCODE(KEY_P, BB) /* R[a] = kdict.key?(Syms[b]) */
OPCODE(KEYEND, Z) /* raise unless kdict.empty? */
OPCODE(KARG, BB) /* R(a) = kdict[Syms(b)]; kdict.delete(Syms(b)) */
OPCODE(RETURN, B) /* return R(a) (normal) */
OPCODE(RETURN_BLK, B) /* return R(a) (in-block return) */
OPCODE(BREAK, B) /* break R(a) */
OPCODE(BLKPUSH, BS) /* R(a) = block (16=m5:r1:m5:d1:lv4) */
OPCODE(ADD, B) /* R(a) = R(a)+R(a+1) */
OPCODE(ADDI, BB) /* R(a) = R(a)+mrb_int(b) */
OPCODE(SUB, B) /* R(a) = R(a)-R(a+1) */
OPCODE(SUBI, BB) /* R(a) = R(a)-mrb_int(b) */
OPCODE(MUL, B) /* R(a) = R(a)*R(a+1) */
OPCODE(DIV, B) /* R(a) = R(a)/R(a+1) */
OPCODE(EQ, B) /* R(a) = R(a)==R(a+1) */
OPCODE(LT, B) /* R(a) = R(a)<R(a+1) */
OPCODE(LE, B) /* R(a) = R(a)<=R(a+1) */
OPCODE(GT, B) /* R(a) = R(a)>R(a+1) */
OPCODE(GE, B) /* R(a) = R(a)>=R(a+1) */
OPCODE(ARRAY, BB) /* R(a) = ary_new(R(a),R(a+1)..R(a+b)) */
OPCODE(ARRAY2, BBB) /* R(a) = ary_new(R(b),R(b+1)..R(b+c)) */
OPCODE(ARYCAT, B) /* ary_cat(R(a),R(a+1)) */
OPCODE(ARYPUSH, B) /* ary_push(R(a),R(a+1)) */
OPCODE(ARYDUP, B) /* R(a) = ary_dup(R(a)) */
OPCODE(AREF, BBB) /* R(a) = R(b)[c] */
OPCODE(ASET, BBB) /* R(a)[c] = R(b) */
OPCODE(APOST, BBB) /* *R(a),R(a+1)..R(a+c) = R(a)[b..] */
OPCODE(INTERN, B) /* R(a) = intern(R(a)) */
OPCODE(STRING, BB) /* R(a) = str_dup(Lit(b)) */
OPCODE(STRING16, BS) /* R(a) = str_dup(Lit(b)) */
OPCODE(STRCAT, B) /* str_cat(R(a),R(a+1)) */
OPCODE(HASH, BB) /* R(a) = hash_new(R(a),R(a+1)..R(a+b*2-1)) */
OPCODE(HASHADD, BB) /* R(a) = hash_push(R(a),R(a+1)..R(a+b*2)) */
OPCODE(HASHCAT, B) /* R(a) = hash_cat(R(a),R(a+1)) */
OPCODE(LAMBDA, BB) /* R(a) = lambda(SEQ[b],L_LAMBDA) */
OPCODE(LAMBDA16, BS) /* R(a) = lambda(SEQ[b],L_LAMBDA) */
OPCODE(BLOCK, BB) /* R(a) = lambda(SEQ[b],L_BLOCK) */
OPCODE(BLOCK16, BS) /* R(a) = lambda(SEQ[b],L_BLOCK) */
OPCODE(METHOD, BB) /* R(a) = lambda(SEQ[b],L_METHOD) */
OPCODE(METHOD16, BS) /* R(a) = lambda(SEQ[b],L_METHOD) */
OPCODE(RANGE_INC, B) /* R(a) = range_new(R(a),R(a+1),FALSE) */
OPCODE(RANGE_EXC, B) /* R(a) = range_new(R(a),R(a+1),TRUE) */
OPCODE(OCLASS, B) /* R(a) = ::Object */
OPCODE(CLASS, BB) /* R(a) = newclass(R(a),Syms(b),R(a+1)) */
OPCODE(MODULE, BB) /* R(a) = newmodule(R(a),Syms(b)) */
OPCODE(EXEC, BB) /* R(a) = blockexec(R(a),SEQ[b]) */
OPCODE(EXEC16, BS) /* R(a) = blockexec(R(a),SEQ[b]) */
OPCODE(DEF, BB) /* R(a).newmethod(Syms(b),R(a+1)) */
OPCODE(ALIAS, BB) /* alias_method(target_class,Syms(a),Syms(b)) */
OPCODE(UNDEF, B) /* undef_method(target_class,Syms(a)) */
OPCODE(SCLASS, B) /* R(a) = R(a).singleton_class */
OPCODE(TCLASS, B) /* R(a) = target_class */
OPCODE(KARG, BB) /* R[a] = kdict[Syms[b]]; kdict.delete(Syms[b]) */
OPCODE(RETURN, B) /* return R[a] (normal) */
OPCODE(RETURN_BLK, B) /* return R[a] (in-block return) */
OPCODE(BREAK, B) /* break R[a] */
OPCODE(BLKPUSH, BS) /* R[a] = block (16=m5:r1:m5:d1:lv4) */
OPCODE(ADD, B) /* R[a] = R[a]+R[a+1] */
OPCODE(ADDI, BB) /* R[a] = R[a]+mrb_int(b) */
OPCODE(SUB, B) /* R[a] = R[a]-R[a+1] */
OPCODE(SUBI, BB) /* R[a] = R[a]-mrb_int(b) */
OPCODE(MUL, B) /* R[a] = R[a]*R[a+1] */
OPCODE(DIV, B) /* R[a] = R[a]/R[a+1] */
OPCODE(EQ, B) /* R[a] = R[a]==R[a+1] */
OPCODE(LT, B) /* R[a] = R[a]<R[a+1] */
OPCODE(LE, B) /* R[a] = R[a]<=R[a+1] */
OPCODE(GT, B) /* R[a] = R[a]>R[a+1] */
OPCODE(GE, B) /* R[a] = R[a]>=R[a+1] */
OPCODE(ARRAY, BB) /* R[a] = ary_new(R[a],R[a+1]..R[a+b]) */
OPCODE(ARRAY2, BBB) /* R[a] = ary_new(R[b],R[b+1]..R[b+c]) */
OPCODE(ARYCAT, B) /* ary_cat(R[a],R[a+1]) */
OPCODE(ARYPUSH, BB) /* ary_push(R[a],R[a+1]..R[a+b]) */
OPCODE(ARYDUP, B) /* R[a] = ary_dup(R[a]) */
OPCODE(AREF, BBB) /* R[a] = R[b][c] */
OPCODE(ASET, BBB) /* R[b][c] = R[a] */
OPCODE(APOST, BBB) /* *R[a],R[a+1]..R[a+c] = R[a][b..] */
OPCODE(INTERN, B) /* R[a] = intern(R[a]) */
OPCODE(SYMBOL, BB) /* R[a] = intern(Pool[b]) */
OPCODE(STRING, BB) /* R[a] = str_dup(Pool[b]) */
OPCODE(STRCAT, B) /* str_cat(R[a],R[a+1]) */
OPCODE(HASH, BB) /* R[a] = hash_new(R[a],R[a+1]..R[a+b*2-1]) */
OPCODE(HASHADD, BB) /* hash_push(R[a],R[a+1]..R[a+b*2]) */
OPCODE(HASHCAT, B) /* R[a] = hash_cat(R[a],R[a+1]) */
OPCODE(LAMBDA, BB) /* R[a] = lambda(Irep[b],L_LAMBDA) */
OPCODE(BLOCK, BB) /* R[a] = lambda(Irep[b],L_BLOCK) */
OPCODE(METHOD, BB) /* R[a] = lambda(Irep[b],L_METHOD) */
OPCODE(RANGE_INC, B) /* R[a] = range_new(R[a],R[a+1],FALSE) */
OPCODE(RANGE_EXC, B) /* R[a] = range_new(R[a],R[a+1],TRUE) */
OPCODE(OCLASS, B) /* R[a] = ::Object */
OPCODE(CLASS, BB) /* R[a] = newclass(R[a],Syms[b],R[a+1]) */
OPCODE(MODULE, BB) /* R[a] = newmodule(R[a],Syms[b]) */
OPCODE(EXEC, BB) /* R[a] = blockexec(R[a],Irep[b]) */
OPCODE(DEF, BB) /* R[a].newmethod(Syms[b],R[a+1]); R[a] = Syms[b] */
OPCODE(ALIAS, BB) /* alias_method(target_class,Syms[a],Syms[b]) */
OPCODE(UNDEF, B) /* undef_method(target_class,Syms[a]) */
OPCODE(SCLASS, B) /* R[a] = R[a].singleton_class */
OPCODE(TCLASS, B) /* R[a] = target_class */
OPCODE(DEBUG, BBB) /* print a,b,c */
OPCODE(ERR, B) /* raise(LocalJumpError, Lit(a)) */
OPCODE(ERR, B) /* raise(LocalJumpError, Pool[a]) */
OPCODE(EXT1, Z) /* make 1st operand (a) 16bit */
OPCODE(EXT2, Z) /* make 2nd operand (b) 16bit */
OPCODE(EXT3, Z) /* make 1st and 2nd operands 16bit */
OPCODE(STOP, Z) /* stop VM */
+15 -9
View File
@@ -12,16 +12,22 @@
#undef mrb_intern_lit
#define mrb_intern_lit(mrb, name) MRB_PRESYM_SCANNING_TAGGED(name)
#define mrb_intern_cstr(mrb, name) MRB_PRESYM_SCANNING_TAGGED(name)
#define mrb_define_method(mrb, c, name, f, a) MRB_PRESYM_SCANNING_TAGGED(name)
#define mrb_define_class_method(mrb, c, name, f, a) MRB_PRESYM_SCANNING_TAGGED(name)
#define mrb_define_singleton_method(mrb, c, name, f, a) MRB_PRESYM_SCANNING_TAGGED(name)
#define mrb_define_class(mrb, name, s) MRB_PRESYM_SCANNING_TAGGED(name)
#define mrb_define_class_under(mrb, o, name, s) MRB_PRESYM_SCANNING_TAGGED(name)
#define mrb_define_method(mrb, c, name, ...) MRB_PRESYM_SCANNING_TAGGED(name) (c) (__VA_ARGS__)
#define mrb_define_class_method(mrb, c, name, ...) MRB_PRESYM_SCANNING_TAGGED(name) (c) (__VA_ARGS__)
#define mrb_define_singleton_method(mrb, c, name, ...) MRB_PRESYM_SCANNING_TAGGED(name) (c) (__VA_ARGS__)
#define mrb_define_class(mrb, name, s) MRB_PRESYM_SCANNING_TAGGED(name) (s)
#define mrb_define_class_under(mrb, o, name, s) MRB_PRESYM_SCANNING_TAGGED(name) (o) (s)
#define mrb_define_module(mrb, name) MRB_PRESYM_SCANNING_TAGGED(name)
#define mrb_define_module_under(mrb, o, name) MRB_PRESYM_SCANNING_TAGGED(name)
#define mrb_define_module_function(mrb, c, name, f, s) MRB_PRESYM_SCANNING_TAGGED(name)
#define mrb_define_const(mrb, c, name, v) MRB_PRESYM_SCANNING_TAGGED(name)
#define mrb_define_global_const(mrb, name, v) MRB_PRESYM_SCANNING_TAGGED(name)
#define mrb_define_module_under(mrb, o, name) MRB_PRESYM_SCANNING_TAGGED(name) (o)
#define mrb_define_module_function(mrb, c, name, ...) MRB_PRESYM_SCANNING_TAGGED(name) (c) (__VA_ARGS__)
#define mrb_define_const(mrb, c, name, v) MRB_PRESYM_SCANNING_TAGGED(name) (c) (v)
#define mrb_define_global_const(mrb, name, v) MRB_PRESYM_SCANNING_TAGGED(name) (v)
#define mrb_define_alias(mrb, c, a, b) MRB_PRESYM_SCANNING_TAGGED(a) MRB_PRESYM_SCANNING_TAGGED(b) (c)
#define mrb_class_get(mrb, name) MRB_PRESYM_SCANNING_TAGGED(name)
#define mrb_class_get_under(mrb, outer, name) MRB_PRESYM_SCANNING_TAGGED(name) (outer)
#define mrb_module_get(mrb, name) MRB_PRESYM_SCANNING_TAGGED(name)
#define mrb_module_get_under(mrb, outer, name) MRB_PRESYM_SCANNING_TAGGED(name) (outer)
#define mrb_funcall(mrb, v, name, ...) MRB_PRESYM_SCANNING_TAGGED(name) (v) (__VA_ARGS__)
#define MRB_OPSYM(name) MRB_OPSYM__##name(mrb)
#define MRB_CVSYM(name) MRB_PRESYM_SCANNING_TAGGED("@@" #name)
+4 -2
View File
@@ -83,6 +83,8 @@ struct RProc {
} while (0)
#define MRB_PROC_SCOPE 2048
#define MRB_PROC_SCOPE_P(p) (((p)->flags & MRB_PROC_SCOPE) != 0)
#define MRB_PROC_NOARG 4096 /* for MRB_PROC_CFUNC_FL, it would be something like MRB_ARGS_NONE() or MRB_METHOD_NOARG_FL */
#define MRB_PROC_NOARG_P(p) (((p)->flags & MRB_PROC_NOARG) != 0)
#define mrb_proc_ptr(v) ((struct RProc*)(mrb_ptr(v)))
@@ -90,7 +92,7 @@ struct RProc *mrb_proc_new(mrb_state*, const mrb_irep*);
struct RProc *mrb_closure_new(mrb_state*, const mrb_irep*);
MRB_API struct RProc *mrb_proc_new_cfunc(mrb_state*, mrb_func_t);
MRB_API struct RProc *mrb_closure_new_cfunc(mrb_state *mrb, mrb_func_t func, int nlocals);
void mrb_proc_copy(struct RProc *a, struct RProc *b);
void mrb_proc_copy(mrb_state *mrb, struct RProc *a, struct RProc *b);
mrb_int mrb_proc_arity(const struct RProc *p);
/* following functions are defined in mruby-proc-ext so please include it when using */
@@ -121,7 +123,7 @@ MRB_API mrb_value mrb_proc_cfunc_env_get(mrb_state *mrb, mrb_int idx);
#define MRB_METHOD_FUNC(m) ((m).func)
#define MRB_METHOD_NOARG_SET(m) do{(m).flags|=MRB_METHOD_NOARG_FL;}while(0)
#define MRB_METHOD_FROM_FUNC(m,fn) do{(m).flags=MRB_METHOD_FUNC_FL;(m).func=(fn);}while(0)
#define MRB_METHOD_FROM_PROC(m,pr) do{(m).flags=0;(m).proc=(pr);}while(0)
#define MRB_METHOD_FROM_PROC(m,pr) do{(m).flags=0;(m).proc=(struct RProc*)(pr);}while(0)
#define MRB_METHOD_PROC_P(m) (!MRB_METHOD_FUNC_P(m))
#define MRB_METHOD_PROC(m) ((m).proc)
#define MRB_METHOD_UNDEF_P(m) ((m).proc==NULL)
+3 -24
View File
@@ -324,20 +324,6 @@ MRB_API mrb_value mrb_str_resize(mrb_state *mrb, mrb_value str, mrb_int len);
*/
MRB_API mrb_value mrb_str_substr(mrb_state *mrb, mrb_value str, mrb_int beg, mrb_int len);
/**
* Returns a Ruby string type.
*
*
* @param mrb The current mruby state.
* @param str Ruby string.
* @return [mrb_value] A Ruby string.
*/
MRB_API mrb_value mrb_ensure_string_type(mrb_state *mrb, mrb_value str);
MRB_API mrb_value mrb_check_string_type(mrb_state *mrb, mrb_value str);
/* obsolete: use mrb_ensure_string_type() instead */
MRB_API mrb_value mrb_string_type(mrb_state *mrb, mrb_value str);
MRB_API mrb_value mrb_str_new_capa(mrb_state *mrb, size_t capa);
#define mrb_str_buf_new(mrb, capa) mrb_str_new_capa(mrb, (capa))
@@ -369,17 +355,10 @@ MRB_API mrb_value mrb_str_dup(mrb_state *mrb, mrb_value str);
*/
MRB_API mrb_value mrb_str_intern(mrb_state *mrb, mrb_value self);
MRB_API mrb_value mrb_str_to_inum(mrb_state *mrb, mrb_value str, mrb_int base, mrb_bool badcheck);
MRB_API mrb_value mrb_cstr_to_inum(mrb_state *mrb, const char *s, mrb_int base, mrb_bool badcheck);
MRB_API mrb_value mrb_str_to_integer(mrb_state *mrb, mrb_value str, mrb_int base, mrb_bool badcheck);
/* obsolete: use mrb_str_to_integer() */
#define mrb_str_to_inum(mrb, str, base, badcheck) mrb_str_to_integer(mrb, str, base, badcheck)
MRB_API double mrb_str_to_dbl(mrb_state *mrb, mrb_value str, mrb_bool badcheck);
MRB_API double mrb_cstr_to_dbl(mrb_state *mrb, const char *s, mrb_bool badcheck);
/**
* Returns a converted string type.
* For type checking, non converting `mrb_to_str` is recommended.
* obsolete: use `mrb_obj_as_string()` instead.
*/
#define mrb_str_to_str(mrb, str) mrb_obj_as_string(mrb, str)
/**
* Returns true if the strings match and false if the strings don't match.
+80 -40
View File
@@ -31,7 +31,30 @@ typedef uint32_t mrb_sym;
* Not to be confused with Ruby's boolean classes, which can be
* obtained using mrb_false_value() and mrb_true_value()
*/
#if defined(__cplusplus) || (defined(__bool_true_false_are_defined) && __bool_true_false_are_defined)
typedef bool mrb_bool;
# ifndef FALSE
# define FALSE false
# endif
# ifndef TRUE
# define TRUE true
# endif
#else
# if __STDC_VERSION__ >= 199901L
typedef _Bool mrb_bool;
# else
typedef uint8_t mrb_bool;
# endif
# ifndef FALSE
# define FALSE 0
# endif
# ifndef TRUE
# define TRUE 1
# endif
#endif
struct mrb_state;
#if defined _MSC_VER && _MSC_VER < 1800
@@ -77,6 +100,7 @@ struct mrb_state;
# define MRB_ENDIAN_LOHI(a,b) b a
#endif
MRB_API mrb_int mrb_int_read(const char *p, const char *e, char **endp);
#ifndef MRB_NO_FLOAT
MRB_API double mrb_float_read(const char*, char**);
#ifdef MRB_USE_FLOAT32
@@ -87,13 +111,11 @@ MRB_API double mrb_float_read(const char*, char**);
#endif
#if defined _MSC_VER && _MSC_VER < 1900
# include <stdarg.h>
MRB_API int mrb_msvc_vsnprintf(char *s, size_t n, const char *format, va_list arg);
MRB_API int mrb_msvc_snprintf(char *s, size_t n, const char *format, ...);
# define vsnprintf(s, n, format, arg) mrb_msvc_vsnprintf(s, n, format, arg)
# define snprintf(s, n, format, ...) mrb_msvc_snprintf(s, n, format, __VA_ARGS__)
# if _MSC_VER < 1800 && !defined MRB_NO_FLOAT
# include <float.h>
# define isfinite(n) _finite(n)
# define isnan _isnan
# define isinf(n) (!_finite(n) && !_isnan(n))
@@ -104,34 +126,49 @@ static const unsigned int IEEE754_INFINITY_BITS_SINGLE = 0x7F800000;
# endif
#endif
#define MRB_VTYPE_FOREACH(f) \
/* mrb_vtype */ /* c type */ /* ruby class */ \
f(MRB_TT_FALSE, void, "false") \
f(MRB_TT_TRUE, void, "true") \
f(MRB_TT_SYMBOL, void, "Symbol") \
f(MRB_TT_UNDEF, void, "undefined") \
f(MRB_TT_FREE, void, "free") \
f(MRB_TT_FLOAT, struct RFloat, "Float") \
f(MRB_TT_INTEGER, struct RInteger, "Integer") \
f(MRB_TT_CPTR, struct RCptr, "cptr") \
f(MRB_TT_OBJECT, struct RObject, "Object") \
f(MRB_TT_CLASS, struct RClass, "Class") \
f(MRB_TT_MODULE, struct RClass, "Module") \
f(MRB_TT_ICLASS, struct RClass, "iClass") \
f(MRB_TT_SCLASS, struct RClass, "SClass") \
f(MRB_TT_PROC, struct RProc, "Proc") \
f(MRB_TT_ARRAY, struct RArray, "Array") \
f(MRB_TT_HASH, struct RHash, "Hash") \
f(MRB_TT_STRING, struct RString, "String") \
f(MRB_TT_RANGE, struct RRange, "Range") \
f(MRB_TT_EXCEPTION, struct RException, "Exception") \
f(MRB_TT_ENV, struct REnv, "env") \
f(MRB_TT_DATA, struct RData, "Data") \
f(MRB_TT_FIBER, struct RFiber, "Fiber") \
f(MRB_TT_STRUCT, struct RArray, "Struct") \
f(MRB_TT_ISTRUCT, struct RIStruct, "istruct") \
f(MRB_TT_BREAK, struct RBreak, "break") \
f(MRB_TT_COMPLEX, struct RComplex, "Complex") \
f(MRB_TT_RATIONAL, struct RRational, "Rational")
enum mrb_vtype {
MRB_TT_FALSE = 0,
MRB_TT_TRUE,
MRB_TT_FLOAT,
MRB_TT_INTEGER,
MRB_TT_SYMBOL,
MRB_TT_UNDEF,
MRB_TT_CPTR,
MRB_TT_FREE,
MRB_TT_OBJECT,
MRB_TT_CLASS,
MRB_TT_MODULE,
MRB_TT_ICLASS,
MRB_TT_SCLASS,
MRB_TT_PROC,
MRB_TT_ARRAY,
MRB_TT_HASH,
MRB_TT_STRING,
MRB_TT_RANGE,
MRB_TT_EXCEPTION,
MRB_TT_ENV,
MRB_TT_DATA,
MRB_TT_FIBER,
MRB_TT_ISTRUCT,
MRB_TT_BREAK,
#define MRB_VTYPE_DEFINE(tt, type, name) tt,
MRB_VTYPE_FOREACH(MRB_VTYPE_DEFINE)
#undef MRB_VTYPE_DEFINE
MRB_TT_MAXDEFINE
};
#define MRB_VTYPE_TYPEOF(tt) MRB_TYPEOF_##tt
#define MRB_VTYPE_TYPEDEF(tt, type, name) typedef type MRB_VTYPE_TYPEOF(tt);
MRB_VTYPE_FOREACH(MRB_VTYPE_TYPEDEF)
#undef MRB_VTYPE_TYPEDEF
/* for compatibility */
#define MRB_TT_FIXNUM MRB_TT_INTEGER
@@ -177,7 +214,7 @@ struct RCptr {
#endif
#ifndef mrb_immediate_p
#define mrb_immediate_p(o) (mrb_type(o) < MRB_TT_FREE)
#define mrb_immediate_p(o) (mrb_type(o) <= MRB_TT_CPTR)
#endif
#ifndef mrb_integer_p
#define mrb_integer_p(o) (mrb_type(o) == MRB_TT_INTEGER)
@@ -372,26 +409,29 @@ mrb_undef_value(void)
return v;
}
#if defined(MRB_USE_ETEXT_EDATA) && !defined(MRB_USE_LINK_TIME_RO_DATA_P)
# ifdef __GNUC__
# warning MRB_USE_ETEXT_EDATA is deprecated. Define MRB_USE_LINK_TIME_RO_DATA_P instead.
# endif
# define MRB_USE_LINK_TIME_RO_DATA_P
#endif
#if defined(MRB_USE_CUSTOM_RO_DATA_P)
/* If you define `MRB_USE_CUSTOM_RO_DATA_P`, you must implement `mrb_ro_data_p()`. */
mrb_bool mrb_ro_data_p(const char *p);
#elif defined(MRB_USE_LINK_TIME_RO_DATA_P)
extern char __ehdr_start[];
extern char __init_array_start[];
#elif !defined(MRB_NO_DEFAULT_RO_DATA_P)
#if defined(MRB_USE_ETEXT_RO_DATA_P)
#define MRB_LINK_TIME_RO_DATA_P
extern char etext, edata;
static inline mrb_bool
mrb_ro_data_p(const char *p)
{
return __ehdr_start < p && p < __init_array_start;
return &etext < p && p < &edata;
}
#else
#elif defined(__APPLE__)
#define MRB_LINK_TIME_RO_DATA_P
#include <mach-o/getsect.h>
static inline mrb_bool
mrb_ro_data_p(const char *p)
{
return (char*)get_etext() < p && p < (char*)get_edata();
}
#endif /* Linux or macOS */
#endif /* MRB_NO_DEFAULT_RO_DATA_P */
#ifndef MRB_LINK_TIME_RO_DATA_P
# define mrb_ro_data_p(p) FALSE
#endif
-15
View File
@@ -14,21 +14,6 @@
*/
MRB_BEGIN_DECL
typedef struct global_variable {
int counter;
mrb_value *data;
mrb_value (*getter)(void);
void (*setter)(void);
/* void (*marker)(); */
/* int block_trace; */
/* struct trace_var *trace; */
} global_variable;
struct global_entry {
global_variable *var;
mrb_sym id;
};
mrb_value mrb_vm_special_get(mrb_state*, mrb_sym);
void mrb_vm_special_set(mrb_state*, mrb_sym, mrb_value);
mrb_value mrb_vm_cv_get(mrb_state*, mrb_sym);
+5 -5
View File
@@ -27,7 +27,7 @@ MRB_BEGIN_DECL
/*
* The version of Ruby used by mruby.
*/
#define MRUBY_RUBY_VERSION "3.0"
#define MRUBY_RUBY_VERSION "3.1"
/*
* Ruby engine.
@@ -42,7 +42,7 @@ MRB_BEGIN_DECL
/*
* Minor release version number.
*/
#define MRUBY_RELEASE_MINOR 0
#define MRUBY_RELEASE_MINOR 1
/*
* Tiny release version number.
@@ -80,17 +80,17 @@ MRB_BEGIN_DECL
/*
* Release year.
*/
#define MRUBY_RELEASE_YEAR 2021
#define MRUBY_RELEASE_YEAR 2022
/*
* Release month.
*/
#define MRUBY_RELEASE_MONTH 2
#define MRUBY_RELEASE_MONTH 1
/*
* Release day.
*/
#define MRUBY_RELEASE_DAY 3
#define MRUBY_RELEASE_DAY 7
/*
* Release date as a string.
+40 -21
View File
@@ -71,7 +71,7 @@ module MRuby
include Rake::DSL
include LoadGems
attr_accessor :name, :bins, :exts, :file_separator, :build_dir, :gem_clone_dir
attr_accessor :name, :bins, :exts, :file_separator, :build_dir, :gem_clone_dir, :defines
attr_reader :products, :libmruby_core_objs, :libmruby_objs, :gems, :toolchains, :presym, :mrbc_build, :gem_dir_to_repo_url
alias libmruby libmruby_objs
@@ -97,6 +97,7 @@ module MRuby
@file_separator = '/'
@build_dir = "#{build_dir}/#{@name}"
@gem_clone_dir = "#{build_dir}/repos/#{@name}"
@defines = []
@cc = Command::Compiler.new(self, %w(.c), label: "CC")
@cxx = Command::Compiler.new(self, %w(.cc .cxx .cpp), label: "CXX")
@objc = Command::Compiler.new(self, %w(.m), label: "OBJC")
@@ -131,15 +132,18 @@ module MRuby
end
MRuby::Build.current = current
current.instance_eval(&block)
if current.libmruby_enabled? && !current.mrbcfile_external?
if current.presym_enabled?
current.create_mrbc_build if current.host? || current.gems["mruby-bin-mrbc"]
elsif current.host?
current.build_mrbc_exec
begin
current.instance_eval(&block)
ensure
if current.libmruby_enabled? && !current.mrbcfile_external?
if current.presym_enabled?
current.create_mrbc_build if current.host? || current.gems["mruby-bin-mrbc"]
elsif current.host?
current.build_mrbc_exec
end
end
current.presym = Presym.new(current) if current.presym_enabled?
end
current.presym = Presym.new(current) if current.presym_enabled?
end
def libmruby_enabled?
@@ -248,7 +252,7 @@ module MRuby
end
end
else
cxx_src = "#{build_dir}/#{src.relative_path})".ext << "-cxx.cxx"
cxx_src = "#{build_dir}/#{src.relative_path.to_s.remove_leading_parents}".ext << "-cxx.cxx"
obj = cxx_src.ext(@exts.object)
end
@@ -320,12 +324,16 @@ EOS
return @mrbcfile if @mrbcfile
gem_name = "mruby-bin-mrbc"
gem = @gems[gem_name]
gem ||= (host = MRuby.targets["host"]) && host.gems[gem_name]
unless gem
fail "external mrbc or mruby-bin-mrbc gem in current('#{@name}') or 'host' build is required"
if (gem = @gems[gem_name])
@mrbcfile = exefile("#{gem.build.build_dir}/bin/mrbc")
elsif !host? && (host = MRuby.targets["host"])
if (gem = host.gems[gem_name])
@mrbcfile = exefile("#{gem.build.build_dir}/bin/mrbc")
elsif host.mrbcfile_external?
@mrbcfile = host.mrbcfile
end
end
@mrbcfile = exefile("#{gem.build.build_dir}/bin/mrbc")
@mrbcfile || fail("external mrbc or mruby-bin-mrbc gem in current('#{@name}') or 'host' build is required")
end
def mrbcfile=(path)
@@ -344,14 +352,8 @@ EOS
end
def define_rules
use_mrdb = @gems["mruby-bin-debugger"]
compilers.each do |compiler|
if respond_to?(:enable_gems?) && enable_gems?
compiler.defines -= %w(MRB_NO_GEMS)
else
compiler.defines += %w(MRB_NO_GEMS)
end
compiler.defines |= %w(MRB_USE_DEBUG_HOOK) if use_mrdb
compiler.defines << "MRB_NO_GEMS" unless enable_gems? && libmruby_enabled?
end
[@cc, *(@cxx if cxx_exception_enabled?)].each do |compiler|
compiler.define_rules(@build_dir, MRUBY_ROOT, @exts.object)
@@ -539,6 +541,23 @@ EOS
end
end
def run_bintest
puts ">>> Bintest #{name} <<<"
targets = @gems.select { |v| File.directory? "#{v.dir}/bintest" }.map { |v| filename v.dir }
targets << filename(".") if File.directory? "./bintest"
mrbc = @gems["mruby-bin-mrbc"] ? exefile("#{@build_dir}/bin/mrbc") : mrbcfile
emulator = @test_runner.command
emulator = @test_runner.shellquote(emulator) if emulator
env = {
"BUILD_DIR" => @build_dir,
"MRBCFILE" => mrbc,
"EMULATOR" => @test_runner.emulator,
}
sh env, "ruby test/bintest.rb#{verbose_flag} #{targets.join ' '}"
end
protected
def create_mrbc_build; end
+15 -7
View File
@@ -51,7 +51,7 @@ module MRuby
@flags = [ENV['CFLAGS'] || []]
@source_exts = source_exts
@include_paths = ["#{MRUBY_ROOT}/include"]
@defines = %w()
@defines = []
@option_include_path = %q[-I"%s"]
@option_define = %q[-D"%s"]
@compile_options = %q[%{flags} -o "%{outfile}" -c "%{infile}"]
@@ -77,7 +77,7 @@ module MRuby
end
def all_flags(_defines=[], _include_paths=[], _flags=[])
define_flags = [defines, _defines].flatten.map{ |d| option_define % d }
define_flags = [defines, _defines, build.defines].flatten.map{ |d| option_define % d }
include_path_flags = [include_paths, _include_paths].flatten.map do |f|
option_include_path % filename(f)
end
@@ -104,9 +104,9 @@ module MRuby
rakedep = File.exist?(gemrake) ? [ gemrake ] : []
if build_dir.include? "mrbgems/"
generated_file_matcher = Regexp.new("^#{Regexp.escape build_dir}/(.*)#{Regexp.escape out_ext}$")
generated_file_matcher = Regexp.new("^#{Regexp.escape build_dir}/(?!mrbc/)(.*)#{Regexp.escape out_ext}$")
else
generated_file_matcher = Regexp.new("^#{Regexp.escape build_dir}/(?!mrbgems/.+/)(.*)#{Regexp.escape out_ext}$")
generated_file_matcher = Regexp.new("^#{Regexp.escape build_dir}/(?!mrbc/|mrbgems/.+/)(.*)#{Regexp.escape out_ext}$")
end
source_exts.each do |ext, compile|
rule generated_file_matcher => [
@@ -277,7 +277,7 @@ module MRuby
def initialize(build)
super
@command = 'git'
@flags = %w[]
@flags = []
@clone_options = "clone %{flags} %{url} %{dir}"
@pull_options = "--git-dir %{repo_dir}/.git --work-tree %{repo_dir} pull"
@checkout_options = "--git-dir %{repo_dir}/.git --work-tree %{repo_dir} checkout %{checksum_hash}"
@@ -328,13 +328,16 @@ module MRuby
@compile_options = "-B%{funcname} -o-"
end
def run(out, infiles, funcname, cdump = true)
def run(out, infiles, funcname, cdump: true, static: false)
@command ||= @build.mrbcfile
infiles = [infiles].flatten
infiles.each_with_index do |f, i|
_pp i == 0 ? "MRBC" : "", f.relative_path, indent: 2
end
cmd = %Q["#{filename @command}" #{cdump ? "-S" : ""} #{@compile_options % {:funcname => funcname}} #{filename(infiles).map{|f| %Q["#{f}"]}.join(' ')}]
opt = @compile_options % {funcname: funcname}
opt << " -S" if cdump
opt << " -s" if static
cmd = %["#{filename @command}" #{opt} #{filename(infiles).map{|f| %["#{f}"]}.join(' ')}]
puts cmd if Rake.verbose
IO.popen(cmd, 'r+') do |io|
out.puts io.read
@@ -360,6 +363,11 @@ module MRuby
@flags = []
end
def emulator
return "" unless @command
return [@command, *@flags].map{|c| shellquote(c)}.join(' ')
end
def run(testbinfile)
puts "TEST for " + @build.name
_run runner_options, { :flags => [flags, verbose_flag].flatten.join(' '), :infile => testbinfile }
+1 -1
View File
@@ -100,7 +100,7 @@ module MRuby
options = [params[:options]] || []
options << "--recursive"
options << "--branch \"#{branch}\""
options << "--depth 1" unless params[:checksum_hash]
options << "--depth 1" unless params[:checksum_hash] || lock
mkdir_p "#{gem_clone_dir}"
git.run_clone gemdir, url, options
+4
View File
@@ -18,6 +18,10 @@ class String
def relative_path
relative_path_from(Dir.pwd)
end
def remove_leading_parents
Pathname.new(".#{Pathname.new("/#{self}").cleanpath}").cleanpath.to_s
end
end
def install_D(src, dst)
+12 -5
View File
@@ -119,6 +119,10 @@ module MRuby
@dir.start_with?("#{MRUBY_ROOT}/mrbgems/")
end
def bin?
@bins.size > 0
end
def add_dependency(name, *requirements)
default_gem = requirements.last.kind_of?(Hash) ? requirements.pop : nil
requirements = ['>= 0.0.0'] if requirements.empty?
@@ -194,10 +198,11 @@ module MRuby
open(fname, 'w') do |f|
print_gem_init_header f
unless rbfiles.empty?
opts = {cdump: cdump?, static: true}
if cdump?
build.mrbc.run f, rbfiles, "gem_mrblib_#{funcname}_proc"
build.mrbc.run f, rbfiles, "gem_mrblib_#{funcname}_proc", **opts
else
build.mrbc.run f, rbfiles, "gem_mrblib_irep_#{funcname}", false
build.mrbc.run f, rbfiles, "gem_mrblib_irep_#{funcname}", **opts
end
end
f.puts %Q[void mrb_#{funcname}_gem_init(mrb_state *mrb);]
@@ -248,7 +253,7 @@ module MRuby
f.puts %Q[#include <mruby.h>]
else
f.puts %Q[#include <stdlib.h>]
unless build.presym_enabled?
unless cdump?
f.puts %Q[#include <mruby.h>]
f.puts %Q[#include <mruby/proc.h>]
end
@@ -496,8 +501,10 @@ module MRuby
end
end
def linker_attrs
map{|g| g.linker.run_attrs}.transpose
def linker_attrs(gem=nil)
gems = self.reject{|g| g.bin?} # library gems
gems << gem unless gem.nil?
gems.map{|g| g.linker.run_attrs}.transpose
end
end # List
end # Gem
+1 -3
View File
@@ -1,7 +1,5 @@
module MRuby
class Presym
include Rake::DSL
OPERATORS = {
"!" => "not",
"%" => "mod",
@@ -101,7 +99,7 @@ module MRuby
end
def list_path
@list_pat ||= "#{@build.build_dir}/presym".freeze
@list_path ||= "#{@build.build_dir}/presym".freeze
end
def header_dir;
+1 -1
View File
@@ -2,7 +2,7 @@ require "pathname"
module MRuby
module Source
# MRuby's source root directory
# mruby's source root directory
ROOT = Pathname.new(File.expand_path('../../../',__FILE__))
# Reads a constant defined at version.h
+1 -1
View File
@@ -1,2 +1,2 @@
#! /usr/bin/env ruby
#!/usr/bin/env ruby
exec "rake", *ARGV
+166 -93
View File
@@ -51,7 +51,7 @@ class Array
# b.uniq { |s| s.first } # => [["student", "sam"], ["teacher", "matz"]]
#
def uniq(&block)
ary = self.dup
ary = self[0..-1]
ary.uniq!(&block)
ary
end
@@ -150,7 +150,7 @@ class Array
# [ 1, 1, 3, 5 ] & [ 1, 2, 3 ] #=> [ 1, 3 ]
#
def &(elem)
raise TypeError, "can't convert #{elem.class} into Array" unless elem.class == Array
raise TypeError, "cannot convert #{elem.class} into Array" unless elem.class == Array
hash = {}
array = []
@@ -191,6 +191,47 @@ class Array
ary
end
##
# call-seq:
# ary.intersect?(other_ary) -> true or false
#
# Returns +true+ if the array and +other_ary+ have at least one element in
# common, otherwise returns +false+.
#
# a = [ 1, 2, 3 ]
# b = [ 3, 4, 5 ]
# c = [ 5, 6, 7 ]
# a.intersect?(b) #=> true
# a.intersect?(c) #=> false
def intersect?(ary)
raise TypeError, "cannot convert #{ary.class} into Array" unless ary.class == Array
hash = {}
if self.length > ary.length
shorter = ary
longer = self
else
shorter = self
longer = ary
end
idx = 0
len = shorter.size
while idx < len
hash[shorter[idx]] = true
idx += 1
end
idx = 0
len = size
while idx < len
v = longer[idx]
if hash[v]
return true
end
idx += 1
end
false
end
##
# call-seq:
# ary.flatten -> new_ary
@@ -253,41 +294,6 @@ class Array
end
end
##
# call-seq:
# ary.compact -> new_ary
#
# Returns a copy of +self+ with all +nil+ elements removed.
#
# [ "a", nil, "b", nil, "c", nil ].compact
# #=> [ "a", "b", "c" ]
#
def compact
result = self.dup
result.compact!
result
end
##
# call-seq:
# ary.compact! -> ary or nil
#
# Removes +nil+ elements from the array.
# Returns +nil+ if no changes were made, otherwise returns
# <i>ary</i>.
#
# [ "a", nil, "b", nil, "c" ].compact! #=> [ "a", "b", "c" ]
# [ "a", "b", "c" ].compact! #=> nil
#
def compact!
result = self.select { |e| !e.nil? }
if result.size == self.size
nil
else
self.replace(result)
end
end
# for efficiency
def reverse_each(&block)
return to_enum :reverse_each unless block
@@ -325,7 +331,7 @@ class Array
#
def fetch(n, ifnone=NONE, &block)
warn "block supersedes default value argument" if !n.nil? && ifnone != NONE && block
#warn "block supersedes default value argument" if !n.nil? && ifnone != NONE && block
idx = n
if idx < 0
@@ -376,11 +382,10 @@ class Array
def fill(arg0=nil, arg1=nil, arg2=nil, &block)
if arg0.nil? && arg1.nil? && arg2.nil? && !block
raise ArgumentError, "wrong number of arguments (0 for 1..3)"
raise ArgumentError, "wrong number of arguments (given 0, expected 1..3)"
end
beg = len = 0
ary = []
if block
if arg0.nil? && arg1.nil? && arg2.nil?
# ary.fill { |index| block } -> ary
@@ -442,57 +447,6 @@ class Array
self
end
##
# call-seq:
# ary.rotate(count=1) -> new_ary
#
# Returns a new array by rotating +self+ so that the element at +count+ is
# the first element of the new array.
#
# If +count+ is negative then it rotates in the opposite direction, starting
# from the end of +self+ where +-1+ is the last element.
#
# a = [ "a", "b", "c", "d" ]
# a.rotate #=> ["b", "c", "d", "a"]
# a #=> ["a", "b", "c", "d"]
# a.rotate(2) #=> ["c", "d", "a", "b"]
# a.rotate(-3) #=> ["b", "c", "d", "a"]
def rotate(count=1)
ary = []
len = self.length
if len > 0
idx = (count < 0) ? (len - (~count % len) - 1) : (count % len) # rotate count
len.times do
ary << self[idx]
idx += 1
idx = 0 if idx > len-1
end
end
ary
end
##
# call-seq:
# ary.rotate!(count=1) -> ary
#
# Rotates +self+ in place so that the element at +count+ comes first, and
# returns +self+.
#
# If +count+ is negative then it rotates in the opposite direction, starting
# from the end of the array where +-1+ is the last element.
#
# a = [ "a", "b", "c", "d" ]
# a.rotate! #=> ["b", "c", "d", "a"]
# a #=> ["b", "c", "d", "a"]
# a.rotate!(2) #=> ["d", "a", "b", "c"]
# a.rotate!(-3) #=> ["a", "b", "c", "d"]
def rotate!(count=1)
self.replace(self.rotate(count))
end
##
# call-seq:
# ary.delete_if { |item| block } -> ary
@@ -705,7 +659,6 @@ class Array
return to_enum :keep_if unless block
idx = 0
len = self.size
while idx < self.size do
if block.call(self[idx])
idx += 1
@@ -920,7 +873,7 @@ class Array
# ary.to_h -> Hash
# ary.to_h{|item| ... } -> Hash
#
# Returns the result of interpreting <i>aray</i> as an array of
# Returns the result of interpreting <i>array</i> as an array of
# <tt>[key, value]</tt> pairs. If a block is given, it should
# return <tt>[key, value]</tt> pairs to construct a hash.
#
@@ -943,4 +896,124 @@ class Array
alias append push
alias prepend unshift
alias filter! select!
##
# call-seq:
# ary.product(*arys) -> array
# ary.product(*arys) { |item| ... } -> self
def product(*arys, &block)
size = arys.size
i = size
while i > 0
i -= 1
unless arys[i].kind_of?(Array)
raise TypeError, "no implicit conversion into Array"
end
end
i = size
total = self.size
total *= arys[i -= 1].size while i > 0
if block
result = self
list = ->(*, e) { block.call e }
class << list; alias []= call; end
else
result = [nil] * total
list = result
end
i = 0
while i < total
group = [nil] * (size + 1)
j = size
n = i
while j > 0
j -= 1
a = arys[j]
b = a.size
group[j + 1] = a[n % b]
n /= b
end
group[0] = self[n]
list[i] = group
i += 1
end
result
end
##
# call-seq:
# ary.repeated_combination(n) { |combination| ... } -> self
# ary.repeated_combination(n) -> enumerator
#
# A +combination+ method that contains the same elements.
def repeated_combination(n, &block)
raise TypeError, "no implicit conversion into Integer" unless 0 <=> n
return to_enum(:repeated_combination, n) unless block
__repeated_combination(n, false, &block)
end
##
# call-seq:
# ary.repeated_permutation(n) { |permutation| ... } -> self
# ary.repeated_permutation(n) -> enumerator
#
# A +permutation+ method that contains the same elements.
def repeated_permutation(n, &block)
raise TypeError, "no implicit conversion into Integer" unless 0 <=> n
return to_enum(:repeated_permutation, n) unless block
__repeated_combination(n, true, &block)
end
def __repeated_combination(n, permutation, &block)
case n
when 0
yield []
when 1
i = 0
while i < self.size
yield [self[i]]
i += 1
end
else
if n > 0
v = [0] * n
while true
tmp = [nil] * n
i = 0
while i < n
tmp[i] = self[v[i]]
i += 1
end
yield tmp
tmp = self.size
i = n - 1
while i >= 0
v[i] += 1
break if v[i] < tmp
i -= 1
end
break unless v[0] < tmp
i = 1
while i < n
unless v[i] < tmp
if permutation
v[i] = 0
else
v[i] = v[i - 1]
end
end
i += 1
end
end
end
end
self
end
end
+178 -3
View File
@@ -94,6 +94,12 @@ mrb_ary_at(mrb_state *mrb, mrb_value ary)
return mrb_ary_entry(ary, pos);
}
static mrb_value
ary_ref(mrb_state *mrb, mrb_value ary, mrb_int n)
{
return mrb_ary_entry(ary, n);
}
static mrb_value
mrb_ary_values_at(mrb_state *mrb, mrb_value self)
{
@@ -102,10 +108,9 @@ mrb_ary_values_at(mrb_state *mrb, mrb_value self)
mrb_get_args(mrb, "*", &argv, &argc);
return mrb_get_values_at(mrb, self, RARRAY_LEN(self), argc, argv, mrb_ary_ref);
return mrb_get_values_at(mrb, self, RARRAY_LEN(self), argc, argv, ary_ref);
}
/*
* call-seq:
* ary.slice!(index) -> obj or nil
@@ -183,6 +188,172 @@ mrb_ary_slice_bang(mrb_state *mrb, mrb_value self)
return ary;
}
/*
* call-seq:
* ary.compact -> new_ary
*
* Returns a copy of +self+ with all +nil+ elements removed.
*
* [ "a", nil, "b", nil, "c", nil ].compact
* #=> [ "a", "b", "c" ]
*/
static mrb_value
mrb_ary_compact(mrb_state *mrb, mrb_value self)
{
mrb_value ary = mrb_ary_new(mrb);
mrb_int len = RARRAY_LEN(self);
mrb_value *p = RARRAY_PTR(self);
for (mrb_int i = 0; i < len; ++i) {
if (!mrb_nil_p(p[i])) {
mrb_ary_push(mrb, ary, p[i]);
}
}
return ary;
}
/*
* call-seq:
* ary.compact! -> ary or nil
*
* Removes +nil+ elements from the array.
* Returns +nil+ if no changes were made, otherwise returns
* <i>ary</i>.
*
* [ "a", nil, "b", nil, "c" ].compact! #=> [ "a", "b", "c" ]
* [ "a", "b", "c" ].compact! #=> nil
*/
static mrb_value
mrb_ary_compact_bang(mrb_state *mrb, mrb_value self)
{
struct RArray *a = mrb_ary_ptr(self);
mrb_int i, j = 0;
mrb_int len = ARY_LEN(a);
mrb_value *p = ARY_PTR(a);
mrb_ary_modify(mrb, a);
for (i = 0; i < len; ++i) {
if (!mrb_nil_p(p[i])) {
if (i != j) p[j] = p[i];
j++;
}
}
if (i == j) return mrb_nil_value();
if (j < len) ARY_SET_LEN(RARRAY(self), j);
return self;
}
/*
* call-seq:
* ary.rotate(count=1) -> new_ary
*
* Returns a new array by rotating +self+ so that the element at +count+ is
* the first element of the new array.
*
* If +count+ is negative then it rotates in the opposite direction, starting
* from the end of +self+ where +-1+ is the last element.
*
* a = [ "a", "b", "c", "d" ]
* a.rotate #=> ["b", "c", "d", "a"]
* a #=> ["a", "b", "c", "d"]
* a.rotate(2) #=> ["c", "d", "a", "b"]
* a.rotate(-3) #=> ["b", "c", "d", "a"]
*/
static mrb_value
mrb_ary_rotate(mrb_state *mrb, mrb_value self)
{
mrb_int count=1;
mrb_get_args(mrb, "|i", &count);
mrb_value ary = mrb_ary_new(mrb);
mrb_int len = RARRAY_LEN(self);
mrb_value *p = RARRAY_PTR(self);
mrb_int idx;
if (len <= 0) return ary;
if (count < 0) {
idx = len - (~count % len) - 1;
}
else {
idx = count % len;
}
for (mrb_int i = 0; i<len; i++) {
mrb_ary_push(mrb, ary, p[idx++]);
if (idx == len) idx = 0;
}
return ary;
}
static void
rev(mrb_value *p, mrb_int beg, mrb_int end)
{
for (mrb_int i=beg,j=end-1; i<j; i++,j--) {
mrb_value v = p[i];
p[i] = p[j];
p[j] = v;
}
}
/*
* call-seq:
* ary.rotate!(count=1) -> ary
*
* Rotates +self+ in place so that the element at +count+ comes first, and
* returns +self+.
*
* If +count+ is negative then it rotates in the opposite direction, starting
* from the end of the array where +-1+ is the last element.
*
* a = [ "a", "b", "c", "d" ]
* a.rotate! #=> ["b", "c", "d", "a"]
* a #=> ["b", "c", "d", "a"]
* a.rotate!(2) #=> ["d", "a", "b", "c"]
* a.rotate!(-3) #=> ["a", "b", "c", "d"]
*/
static mrb_value
mrb_ary_rotate_bang(mrb_state *mrb, mrb_value self)
{
mrb_int count=1;
mrb_get_args(mrb, "|i", &count);
struct RArray *a = mrb_ary_ptr(self);
mrb_int len = ARY_LEN(a);
mrb_value *p = ARY_PTR(a);
mrb_int idx;
mrb_ary_modify(mrb, a);
if (len == 0 || count == 0) return self;
if (count == 1) {
mrb_value v = p[0];
for (mrb_int i=1; i<len; i++) {
p[i-1] = p[i];
}
p[len-1] = v;
return self;
}
if (count < 0) {
idx = len - (~count % len) - 1;
}
else {
idx = count % len;
}
/* e.g. [1,2,3,4,5].rotate!(2) -> [3,4,5,1,2] */
/* first, reverse the whole array */
/* [1,2,3,4,5] -> [5,4,3,2,1] */
rev(p, 0, len);
/* then, re-reverse part before idx */
/* [5,4,3,2,1] -> [3,4,5,2,1] */
/* ^idx ~~~~~ */
rev(p, 0, len-idx);
/* finally, re-reverse part after idx */
/* [3,4,5,2,1] -> [3,4,5,1,2] */
/* ^idx ~~~ */
rev(p, len-idx, len);
return self;
}
void
mrb_mruby_array_ext_gem_init(mrb_state* mrb)
{
@@ -192,7 +363,11 @@ mrb_mruby_array_ext_gem_init(mrb_state* mrb)
mrb_define_method(mrb, a, "at", mrb_ary_at, MRB_ARGS_REQ(1));
mrb_define_method(mrb, a, "rassoc", mrb_ary_rassoc, MRB_ARGS_REQ(1));
mrb_define_method(mrb, a, "values_at", mrb_ary_values_at, MRB_ARGS_ANY());
mrb_define_method(mrb, a, "slice!", mrb_ary_slice_bang, MRB_ARGS_ARG(1,1));
mrb_define_method(mrb, a, "slice!", mrb_ary_slice_bang, MRB_ARGS_ARG(1,1));
mrb_define_method(mrb, a, "compact", mrb_ary_compact, MRB_ARGS_NONE());
mrb_define_method(mrb, a, "compact!", mrb_ary_compact_bang, MRB_ARGS_NONE());
mrb_define_method(mrb, a, "rotate", mrb_ary_rotate, MRB_ARGS_OPT(1));
mrb_define_method(mrb, a, "rotate!", mrb_ary_rotate_bang, MRB_ARGS_OPT(1));
}
void
+86
View File
@@ -18,6 +18,14 @@ def assert_combination(exp, receiver, *args)
assert_permutation_combination(exp, receiver, :combination, *args)
end
def assert_repeated_permutation(exp, receiver, *args)
assert_permutation_combination(exp, receiver, :repeated_permutation, *args)
end
def assert_repeated_combination(exp, receiver, *args)
assert_permutation_combination(exp, receiver, :repeated_combination, *args)
end
assert("Array#assoc") do
s1 = [ "colors", "red", "blue", "green" ]
s2 = [ "letters", "a", "b", "c" ]
@@ -119,6 +127,14 @@ assert("Array#intersection") do
assert_equal [1, 8], a.intersection(b,c)
end
assert("Array#intersect?") do
a = [ 1, 2, 3 ]
b = [ 3, 4, 5 ]
c = [ 5, 6, 7 ]
assert_true(a.intersect?(b))
assert_false(a.intersect?(c))
end
assert("Array#flatten") do
assert_equal [1, 2, "3", {4=>5}, :'6'], [1, 2, "3", {4=>5}, :'6'].flatten
assert_equal [1, 2, 3, 4, 5, 6], [1, 2, [3, 4, 5], 6].flatten
@@ -413,3 +429,73 @@ assert('Array#transpose') do
assert_raise(TypeError) { [1].transpose }
assert_raise(IndexError) { [[1], [2,3,4]].transpose }
end
assert "Array#product" do
assert_equal [[1], [2], [3]], [1, 2, 3].product
assert_equal [], [1, 2, 3].product([])
assert_equal [], [1, 2, 3].product([4, 5, 6], [])
expect = [[1, 5, 8], [1, 5, 9], [1, 6, 8], [1, 6, 9], [1, 7, 8], [1, 7, 9],
[2, 5, 8], [2, 5, 9], [2, 6, 8], [2, 6, 9], [2, 7, 8], [2, 7, 9],
[3, 5, 8], [3, 5, 9], [3, 6, 8], [3, 6, 9], [3, 7, 8], [3, 7, 9],
[4, 5, 8], [4, 5, 9], [4, 6, 8], [4, 6, 9], [4, 7, 8], [4, 7, 9]]
assert_equal expect, [1, 2, 3, 4].product([5, 6, 7], [8, 9])
expect = [[1, 4, 7], [1, 4, 8], [1, 4, 9], [1, 5, 7], [1, 5, 8], [1, 5, 9], [1, 6, 7], [1, 6, 8], [1, 6, 9],
[2, 4, 7], [2, 4, 8], [2, 4, 9], [2, 5, 7], [2, 5, 8], [2, 5, 9], [2, 6, 7], [2, 6, 8], [2, 6, 9],
[3, 4, 7], [3, 4, 8], [3, 4, 9], [3, 5, 7], [3, 5, 8], [3, 5, 9], [3, 6, 7], [3, 6, 8], [3, 6, 9]]
assert_equal expect, [1, 2, 3].product([4, 5, 6], [7, 8, 9])
base = [1, 2, 3]
x = []
assert_equal base, base.product([4, 5, 6], [7, 8, 9]) { |e| x << e }
assert_equal expect, x
end
assert("Array#repeated_combination") do
a = [1, 2, 3]
assert_raise(ArgumentError) { a.repeated_combination }
#assert_kind_of(Enumerator, a.repeated_combination(1))
assert_repeated_combination([[1],[2],[3]], a, 1)
assert_repeated_combination([[1,1],[1,2],[1,3],[2,2],[2,3],[3,3]], a, 2)
assert_repeated_combination([[1,1,1],[1,1,2],[1,1,3],[1,2,2],[1,2,3],[1,3,3],[2,2,2],
[2,2,3],[2,3,3],[3,3,3]], a, 3)
assert_repeated_combination([[1,1,1,1],[1,1,1,2],[1,1,1,3],[1,1,2,2],[1,1,2,3],[1,1,3,3],
[1,2,2,2],[1,2,2,3],[1,2,3,3],[1,3,3,3],[2,2,2,2],[2,2,2,3],
[2,2,3,3],[2,3,3,3],[3,3,3,3]], a, 4)
assert_repeated_combination([[1,1,1,1,1],[1,1,1,1,2],[1,1,1,1,3],[1,1,1,2,2],[1,1,1,2,3],
[1,1,1,3,3],[1,1,2,2,2],[1,1,2,2,3],[1,1,2,3,3],[1,1,3,3,3],
[1,2,2,2,2],[1,2,2,2,3],[1,2,2,3,3],[1,2,3,3,3],[1,3,3,3,3],
[2,2,2,2,2],[2,2,2,2,3],[2,2,2,3,3],[2,2,3,3,3],[2,3,3,3,3],
[3,3,3,3,3]], a, 5)
assert_repeated_combination([[]], a, 0)
assert_repeated_combination([], a, -1)
end
assert("Array#repeated_permutation") do
a = [1, 2, 3]
assert_raise(ArgumentError) { a.repeated_permutation }
#assert_kind_of(Enumerator, a.repeated_permutation(1))
assert_repeated_permutation([[1],[2],[3]], a, 1)
assert_repeated_permutation([[1,1],[1,2],[1,3],[2,1],[2,2],[2,3],[3,1],[3,2],[3,3]], a, 2)
assert_repeated_permutation([[1,1,1],[1,1,2],[1,1,3],[1,2,1],[1,2,2],[1,2,3],[1,3,1],[1,3,2],[1,3,3],
[2,1,1],[2,1,2],[2,1,3],[2,2,1],[2,2,2],[2,2,3],[2,3,1],[2,3,2],[2,3,3],
[3,1,1],[3,1,2],[3,1,3],[3,2,1],[3,2,2],[3,2,3],[3,3,1],[3,3,2],[3,3,3]],
a, 3)
assert_repeated_permutation([[1,1,1,1],[1,1,1,2],[1,1,1,3],[1,1,2,1],[1,1,2,2],[1,1,2,3],
[1,1,3,1],[1,1,3,2],[1,1,3,3],[1,2,1,1],[1,2,1,2],[1,2,1,3],
[1,2,2,1],[1,2,2,2],[1,2,2,3],[1,2,3,1],[1,2,3,2],[1,2,3,3],
[1,3,1,1],[1,3,1,2],[1,3,1,3],[1,3,2,1],[1,3,2,2],[1,3,2,3],
[1,3,3,1],[1,3,3,2],[1,3,3,3],[2,1,1,1],[2,1,1,2],[2,1,1,3],
[2,1,2,1],[2,1,2,2],[2,1,2,3],[2,1,3,1],[2,1,3,2],[2,1,3,3],
[2,2,1,1],[2,2,1,2],[2,2,1,3],[2,2,2,1],[2,2,2,2],[2,2,2,3],
[2,2,3,1],[2,2,3,2],[2,2,3,3],[2,3,1,1],[2,3,1,2],[2,3,1,3],
[2,3,2,1],[2,3,2,2],[2,3,2,3],[2,3,3,1],[2,3,3,2],[2,3,3,3],
[3,1,1,1],[3,1,1,2],[3,1,1,3],[3,1,2,1],[3,1,2,2],[3,1,2,3],
[3,1,3,1],[3,1,3,2],[3,1,3,3],[3,2,1,1],[3,2,1,2],[3,2,1,3],
[3,2,2,1],[3,2,2,2],[3,2,2,3],[3,2,3,1],[3,2,3,2],[3,2,3,3],
[3,3,1,1],[3,3,1,2],[3,3,1,3],[3,3,2,1],[3,3,2,2],[3,3,2,3],
[3,3,3,1],[3,3,3,2],[3,3,3,3]], a, 4)
assert_repeated_permutation([[]], a, 0)
assert_repeated_permutation([], a, -1)
end

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