Compare commits

...

1857 Commits

Author SHA1 Message Date
Hiroshi Mimaki 7c91efc1ff Update version and release date.
`mruby 2.0.1 (2019-4-4)`
2019-04-04 09:26:40 +09:00
Yukihiro "Matz" Matsumoto 2871d0cdc5 Avoid keeping pointers from mrb_sym2name_len(); fix #4342
The addresses for packed inline symbols reference `mrb->symbuf` that
could be overridden by the later call of `mrb_sym2name_len`. Since
file names in call stack information are kept as symbols, keeping the
address in the C structures could cause problems like #4342.

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

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

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

Before this patch:

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

After this patch:

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

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

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

Example of before this patch:

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

Example of after this patch:

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

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

2. Synchronize standard output

No synchronized:

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

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

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

    >>> Test cxx_abi <<<

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

    >>> Test full-debug <<<

    >>> Bintest cxx_abi <<<

Synchronized:

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

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

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

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

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

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

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

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

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

  p :あ.size  #=> 3

After:

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

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

After/Ruby:

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

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

After / Ruby:

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

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

After / CRuby:

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

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

  Good:

    $ bin/mruby example.rb
    inf
    -inf

  Bad:

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

Cause:

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

Treatment:

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

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

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

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

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

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

  Before:

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

  After:

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

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

    src/vm.c:104:38: warning: suggest braces around initialization of
        subobject [-Wmissing-braces]
      const mrb_value mrb_value_zero = { 0 };
                                         ^
                                         {}
2018-12-23 14:23:44 +09:00
Yukihiro "Matz" Matsumoto f6c07b8835 Merge pull request #4196 from dearblue/add-Wundef-cflags
Append cflags for undefined macro
2018-12-22 22:49:14 +09:00
Yukihiro "Matz" Matsumoto a154d657ae Merge pull request #4194 from shuujii/mirb-drop-dependency-on-mruby-print
mirb: drop dependency on mruby-print in a test
2018-12-22 22:47:27 +09:00
Yukihiro "Matz" Matsumoto 30dae4742b Merge pull request #4195 from dearblue/fix-byteorder
Fix byte order
2018-12-22 22:47:03 +09:00
dearblue 129a804136 Append cflags for undefined macro 2018-12-22 21:58:58 +09:00
dearblue b7a832bf4f Define byte order macros, if not defined it and there are alternatives 2018-12-22 21:05:27 +09:00
dearblue e9ceb865b6 Fix MRB_ENDIAN_BIG is always defined, if byte order macro is not defined 2018-12-22 20:37:51 +09:00
KOBAYASHI Shuji 6578fec779 mirb: drop dependency on mruby-print in a test 2018-12-22 17:26:11 +09:00
Yukihiro "Matz" Matsumoto 281d0ff4ea Merge pull request #4193 from dearblue/fix-assert-variable
Fix undefined variable is using
2018-12-22 13:31:06 +09:00
dearblue 9377da9775 Fix undefined variable is using 2018-12-21 23:44:38 +09:00
Yukihiro "Matz" Matsumoto aeafce23e4 Merge branch 'cubicdaiya-feature/optimize_proc_parameters' 2018-12-21 13:00:27 +09:00
Tatsuhiko Kubo d2fb4752e2 Add test for Proc#parameters 2018-12-21 12:59:38 +09:00
Tatsuhiko Kubo cc71bd51f1 optimize Proc#parameters 2018-12-21 12:59:38 +09:00
Yukihiro "Matz" Matsumoto 94b73b1440 Add NULL pointer check before void_expr_error(); fix #4192 2018-12-21 09:35:10 +09:00
Yukihiro "Matz" Matsumoto ed2bc5d4ed Simplify MRB_ENDIAN_BIG macro definition; ref #4190
`cpp` does not raise error on undefined macro access in condition.
2018-12-21 09:28:19 +09:00
Yukihiro "Matz" Matsumoto 445c64d0ad Fixed a bug on platforms without BYTE_ORDER; ref #4190 2018-12-21 09:26:48 +09:00
Yukihiro "Matz" Matsumoto f5537912ab Define MRB_ENDIAN_BIG automatically; ref #4190
You had to define this macro on big endian platforms, but it is very
error-prone. So define the macro automatically if possible.
2018-12-21 08:57:17 +09:00
Yukihiro "Matz" Matsumoto 2fdb309e55 mruby-pack should not rely on MRB_ENDIAN_BIG macro; fix #4190
The `MRB_ENDIAN_BIG` macro is originally used for `NaN` boxing.
We cannot assume it is defined on every big endian platform (#4190
is the case). So instead of relying on untrusted `MRB_ENDIAN_BIG`, we
use `BYTE_ORDER` macro with a fallback function to check endian in
runtime.
2018-12-21 08:52:31 +09:00
Yukihiro "Matz" Matsumoto 7e35c659aa Remove things we've done in TODO file. 2018-12-21 00:47:56 +09:00
Yukihiro "Matz" Matsumoto e588e9df23 Merge pull request #4191 from dearblue/parenthesis
Fix parenthesis for macros
2018-12-19 20:40:34 +09:00
Yukihiro "Matz" Matsumoto 624b126fb6 Added Android Hack to time.c.
Android bionic defines `TIME_UTC` but does not provide `timespec_get`.
2018-12-19 13:12:30 +09:00
dearblue e19353be25 Fix macro expressions with paren 2018-12-18 23:14:26 +09:00
dearblue 14133f4057 Fix macro arguments with paren 2018-12-18 23:05:36 +09:00
Yukihiro "Matz" Matsumoto 11071b9ab1 Merge pull request #4189 from sdottaka/fix-mrb_ary_clear
Make mrb_ary_clear() function callable from C again
2018-12-17 16:29:00 +09:00
Yukihiro "Matz" Matsumoto ccc5edc60d Small refactoring of #4188 2018-12-17 16:00:22 +09:00
Yukihiro "Matz" Matsumoto e65d42644a Remove #include <mruby/khash.h> from mruby/hash.h. 2018-12-17 15:59:42 +09:00
Yukihiro "Matz" Matsumoto e690314525 Recover #to_int; ref #4177
We have removed implicit conversion to strings using `to_int`. But some
users still using `to_int` as a typical integer method, i.e. they do
string check by code like: `obj.respond_to?(:to_int)`. So we have
recovered the method.
2018-12-17 15:59:42 +09:00
Yukihiro "Matz" Matsumoto c03fa0e1b3 Recover String#to_str; ref #4177
We have removed implicit conversion to strings using `to_str`. But some
people still using `to_str` as a typical string method, i.e. they do
string check by code like: `obj.respond_to?(:to_str)`. So we have
recovered the method.
2018-12-17 15:59:42 +09:00
Yukihiro "Matz" Matsumoto ea71f1165b Merge pull request #4188 from dearblue/mrb_hash_size
Add `mrb_hash_size()` function
2018-12-17 15:59:31 +09:00
Takashi Sawanaka d8c70167f7 Make mrb_ary_clear() function callable from C again 2018-12-15 05:17:38 +09:00
dearblue 62dd4d89fc Add mrb_hash_size() function. 2018-12-14 21:41:07 +09:00
Yukihiro "Matz" Matsumoto ec812c646f Merge pull request #4185 from icm7216/fix-sleep-example
Fix sleep example
2018-12-12 13:48:58 +09:00
icm7216 59651f43ad Specify the core library instead of the external library. 2018-12-12 00:54:15 +09:00
icm7216 74c5402211 Sleep module is undefined. Remove module name. 2018-12-12 00:52:07 +09:00
Yukihiro "Matz" Matsumoto 730b925332 Merge pull request #4184 from mruby/stable
Release mruby 2.0.0
2018-12-11 11:52:33 +09:00
Yukihiro "Matz" Matsumoto 60da293d5c Avoid using floating point number for HT_SEG_INCREASE_RATIO; ref #4182 2018-12-11 10:54:47 +09:00
Hiroshi Mimaki 1c09046c13 Update release date. 2018-12-11 10:52:20 +09:00
Yukihiro "Matz" Matsumoto 265171a28c Rename ht_foreach_func to mrb_hash_foreach_func. 2018-12-11 10:41:26 +09:00
Yukihiro "Matz" Matsumoto e935d20ab5 Add mrb_ prefix to iv_foreach_func. 2018-12-11 10:39:53 +09:00
Yukihiro "Matz" Matsumoto a0df27d8e0 Add new API mrb_iv_foreach() to iterate over instance variables. 2018-12-11 09:48:15 +09:00
Yukihiro "Matz" Matsumoto f6b2e6231a Update iv_foreach() function.
* return `void` instead of `mrb_bool'.
* non zero return value from `func` breaks the loop.
* no longer remove items on negative return value from `func`.
2018-12-11 09:47:06 +09:00
Hiroshi Mimaki 716e7b815f Fixed missing comma in mruby/mirb usage. 2018-12-11 09:37:23 +09:00
Yukihiro "Matz" Matsumoto 378c728338 Update comments. 2018-12-11 09:04:08 +09:00
Yukihiro "Matz" Matsumoto c0d91a14e7 Add API function mrb_hash_foreach() to iterate over items in a hash. 2018-12-11 09:01:05 +09:00
Yukihiro "Matz" Matsumoto c23e68d32b Need to clear stack before invoking a block; fix #4181 2018-12-10 10:23:01 +09:00
Yukihiro "Matz" Matsumoto e6bad6766a Add new methods Module#{>,>=,<=>}; ref #4174 2018-12-04 08:41:09 +09:00
Yukihiro "Matz" Matsumoto d5d9cc8b62 Remove unnecessary check in Module#<; ref #4174 2018-12-04 08:40:23 +09:00
Yukihiro "Matz" Matsumoto 6ef4a5fd6b Replace RDoc <i></i> to Markdown back quotes; ref #4174 2018-12-04 08:39:44 +09:00
Yukihiro "Matz" Matsumoto 20c655dc45 Merge pull request #4174 from robfors/module_operators
Adds Module#< and Module#<=
2018-12-04 08:09:18 +09:00
Rob e300ac8e3a Adds Module#< and Module#<= 2018-12-02 20:56:47 -05:00
Hiroshi Mimaki e3ae0e4f29 Merge branch 'master' into stable 2018-11-27 09:09:20 +09:00
Yukihiro "Matz" Matsumoto 26475d0a78 Update doc/limitations.md for argument destructuring. 2018-11-25 18:03:27 +09:00
Yukihiro "Matz" Matsumoto 762f682b80 Allow destructuring in formal arguments.
e.g.
```
def m(a,(b,c),d); p [a,b,c,d]; end
m(1,[2,3],4)  # => [1,2,3,4]
```

mruby limitation:
Destructured arguments (`b` and `c` in above example) cannot be accessed
from the default expression of optional arguments and keyword arguments,
since actual assignment is done after the evaluation of those default
expressions. Thus:

```
def f(a,(b,c),d=b)
  p [a,b,c,d]
end
f(1,[2,3])
```

raises `NoMethodError` for `b` in mruby.
2018-11-25 09:07:49 +09:00
Yukihiro "Matz" Matsumoto e6b72b2121 Remove redundant rules from parse.y. 2018-11-25 07:30:32 +09:00
Yukihiro "Matz" Matsumoto 7ed9bb3bd3 Fix wrong number of arguments in Array#fetch; fix #4170 2018-11-25 06:05:07 +09:00
Yukihiro "Matz" Matsumoto e2e6554b56 Protect from exceptions raised outside of mrb_vm_run().
It can happen if signals are used (e.g. from `mruby-alarm` gem).
2018-11-25 06:05:07 +09:00
Yukihiro "Matz" Matsumoto 91bf55bbe5 Remove do { ... } while(0) hacks from MRB_TRY macros.
Because it can swallow `break` etc. if they are used in loops.
2018-11-25 06:05:07 +09:00
Hiroshi Mimaki 0711c861ca Fix mruby-socket test failure on MinGW. 2018-11-22 09:49:00 +09:00
Yukihiro "Matz" Matsumoto b158f26f0c Merge pull request #4168 from robfors/doc
Add documentation to mrb_load_irep
2018-11-21 12:16:07 +09:00
Rob Fors c9a66d4c41 Update documentation to mrb_load_irep 2018-11-20 21:27:03 -05:00
Yukihiro "Matz" Matsumoto 68c5384830 Update version number; fix #4165 2018-11-20 10:43:34 +09:00
Yukihiro "Matz" Matsumoto ec19c34a20 Fixed a bug in mirb heredoc handling; fix #3989 2018-11-20 10:39:34 +09:00
Yukihiro "Matz" Matsumoto f1eeaad84a Stop special treating of \r in the lexer; fix #4132 2018-11-20 09:35:38 +09:00
Yukihiro "Matz" Matsumoto 86d102350b Restrict total recursion number of ecall(); fix #3789 2018-11-20 09:14:34 +09:00
Yukihiro "Matz" Matsumoto afd46eccd1 Add -fpermissive to C++ compiler flags. 2018-11-19 17:11:59 +09:00
Yukihiro "Matz" Matsumoto 65a2c2082d Call mrb_str_to_str from mrb_string_value_ptr for compatibility. 2018-11-19 17:11:19 +09:00
Yukihiro "Matz" Matsumoto 53e2df3e93 Restore mrb_string_type function for compatibility. 2018-11-19 16:13:26 +09:00
Yukihiro "Matz" Matsumoto c308a149f0 Add Hash type check for OP_KARG and OP_KEY_P; ref #4166 2018-11-19 15:35:59 +09:00
Yukihiro "Matz" Matsumoto 423f872c84 Need to keep rooms for empty splat; fix #4166 2018-11-19 15:26:19 +09:00
Yukihiro "Matz" Matsumoto 87ffab5713 Adjust codedump output format; ref #4166 2018-11-19 15:25:42 +09:00
Yukihiro "Matz" Matsumoto 9516731329 Use type checking mrb_to_str instead of converting mrb_str_to_str. 2018-11-19 12:08:28 +09:00
Yukihiro "Matz" Matsumoto c022e4643f Avoid assignments from type checking String#__to_str. 2018-11-19 12:08:28 +09:00
Yukihiro "Matz" Matsumoto 610bcc88c2 Removed to_hash conversion method. 2018-11-19 12:08:28 +09:00
Yukihiro "Matz" Matsumoto 698f5f707c Removed to_ary conversion method. 2018-11-19 12:08:28 +09:00
Yukihiro "Matz" Matsumoto 5bbcea9b3b Removed try_convert method from Array and Hash. 2018-11-19 12:08:28 +09:00
Yukihiro "Matz" Matsumoto b5d43a16a3 Removed String#try_convert method from mruby-string-ext gem.
Because `try_convert` method rarely used in production. For mruby users,
we have `__to_str` utility method to check string type.
2018-11-19 12:08:28 +09:00
Yukihiro "Matz" Matsumoto ff08856fe3 Remove implicit conversion using to_str method; fix #3854
We have added internal convenience method `__to_str` which
does string type check.

The issue #3854 was fixed but fundamental flaw of lack of stack
depth check along with fibers still remains. Use `MRB_GC_FIXED_ARENA`
for workaround.
2018-11-19 12:05:46 +09:00
Yukihiro "Matz" Matsumoto afca99a40b Remove implicit conversion using to_int method.
The ISO standard does not include implicit type conversion using
`to_int`. This implicit conversion often causes vulnerability.
There will be no more attacks like #4120.

In addition, we have added internal convenience method `__to_int` which
does type check and conversion (from floats).
2018-11-19 11:28:51 +09:00
Yukihiro "Matz" Matsumoto 426c1f9e0b fix non-ASCII comment. 2018-11-19 11:28:03 +09:00
Yukihiro "Matz" Matsumoto 0a0cc5a217 Check method existence for Enumerators; fix #3920
The issue #3920 was fixed but the fundamental flaw of lack of stack
depth check along with fibers still remains, even though it's not
easy to cause the issue.  Use `MRB_GC_FIXED_ARENA` to avoid the issue
for workaround.

After this patch, `obj.to_enum` raises `ArgumentError` if the object
does not respond to the enumerating method. This is incompatible to
CRuby but I think this behavior is better and CRuby should be updated
to behave like this.
2018-11-19 10:57:07 +09:00
Yukihiro "Matz" Matsumoto 31a961acf1 The current context may be changed in mrb_vm_exec; ref #3668 #4104 2018-11-19 09:50:31 +09:00
Yukihiro "Matz" Matsumoto cab6b0f39b Protect Fiber from GC in ecall(); fix #4104 2018-11-19 09:49:20 +09:00
Yukihiro "Matz" Matsumoto 25d390d6cc Improve Hash table using variable sized segments. 2018-11-19 09:30:15 +09:00
Yukihiro "Matz" Matsumoto 180b73fec4 The key or value object could be reclaimed by GC; fix #4164
The GC may occur between `sg_shift` and `mrb_assoc_new`, in which
case `key` and `value` could be freed even tough they are still alive.

The issue is found and fixed by https://hackerone.com/hexodus
2018-11-16 01:04:57 +09:00
Yukihiro "Matz" Matsumoto 0a022f7b8d The saved pc from ERR_PC_SET was wrong; fix #4138
The saving `pc` position should be beginning of the instruction.
But after `mruby 2.0` byte code modification, the `pc` variable
points the beginning of the next instruction. We save the previous
position in a local variable `pc0`.
2018-11-15 23:34:32 +09:00
Yukihiro "Matz" Matsumoto 418ad65db4 Fixed a bug in continuous read of target files; ref #4138
Line number information in a compiled file was wrong.
2018-11-15 23:34:32 +09:00
Yukihiro "Matz" Matsumoto 7e3e8d8ed5 Shrink file name table size to uint16_t; ref #4138 2018-11-15 23:34:32 +09:00
Yukihiro "Matz" Matsumoto faf51f82c7 Rename local variables in mrb_debug_info_append_file 2018-11-15 23:34:32 +09:00
Yukihiro "Matz" Matsumoto 56db3cf3eb Simplify argument parsing; ref #4161 2018-11-15 21:01:56 +09:00
Yukihiro "Matz" Matsumoto f39f428ed4 Silence -fsanitize=undefined warning in src/enum.c; fix #4161 2018-11-15 21:01:56 +09:00
Yukihiro "Matz" Matsumoto 61f49690e4 Remove filename&lines from mrb_irep struct.
This patch slightly reduce memory consumption (2% for my test).
2018-11-15 21:01:56 +09:00
Yukihiro "Matz" Matsumoto 1bea1e2050 Small renaming refactor in dump.c 2018-11-15 19:24:45 +09:00
Yukihiro "Matz" Matsumoto 485955eccc String#{squeeze,delete,count} to use bitmap for matching; ref #4163 2018-11-15 04:51:27 +09:00
Yukihiro "Matz" Matsumoto 4550f4e381 Pattern length may overflow uint16_t; fixed #4163
The issue is reported by `https://hackerone.com/dgaletic`.
2018-11-15 02:03:54 +09:00
Yukihiro "Matz" Matsumoto c3188cac43 Merge pull request #4160 from mimaki/wrong-negative-float-in-mrb
Wrong pool data length for negative floating value in a mrb file.
2018-11-07 18:22:13 +09:00
Hiroshi Mimaki 7d7f9feee7 Wrong pool data length for negative floating value in a mrb file. 2018-11-07 17:20:18 +09:00
Yukihiro "Matz" Matsumoto d25ebec988 Fixed wrong ArgumentError with keyword arguments; fix #4159 2018-11-05 21:52:17 +09:00
Yukihiro "Matz" Matsumoto d47003aea4 Fixed a bug in argument number check with kwargs; fix #4159 2018-11-05 07:44:25 +09:00
Yukihiro "Matz" Matsumoto d9e2532552 Remove reserved symbols for now.
It should be done by planned embedded symbols.
2018-11-02 22:58:12 +09:00
Yukihiro "Matz" Matsumoto 9c5e28646b Merge pull request #4151 from take-cheeze/remove_op_symidx
Reduce instruction size
2018-11-02 22:37:47 +09:00
Yukihiro "Matz" Matsumoto 788e4388f8 Merge branch 'take-cheeze-fix_dump_load'
Since our new VM instruction is byte based, there's no need to endian
conversion of instruction sequences.
2018-11-02 20:58:15 +09:00
take-cheeze 57a435aa1d Suppress warning 2018-11-02 15:49:34 +09:00
take-cheeze 659c680a5b Fix dump and load with endianess 2018-11-02 15:47:28 +09:00
Yukihiro "Matz" Matsumoto 0419f07915 Add NULL checks for mrb->ci and proc->upeer; #4024 2018-11-02 14:57:03 +09:00
Yukihiro "Matz" Matsumoto f2084f300b Add tests for empty patterns for tr and count; #4156 #4157 2018-11-02 08:58:21 +09:00
Yukihiro "Matz" Matsumoto 8e59695625 Empty pattern string for String#tr should remove characters; fix #4157 2018-11-02 08:55:17 +09:00
Yukihiro "Matz" Matsumoto 65b04066a2 Empty pattern string can generate TR_UNINITIALIZED pattern; fix #4156 2018-11-02 08:54:24 +09:00
Yukihiro "Matz" Matsumoto 7ad53273a2 Silence Appveyor's VC compilation warnings. 2018-11-01 22:52:12 +09:00
Yukihiro "Matz" Matsumoto d68da042b3 The env object referenced from fibers may be freed; fix #4154
By dffa203 that reclaim `env` objects from heaps, there's more chance
for `env` objects referenced from fibers may be freed from heap pages.
2018-11-01 22:36:06 +09:00
Yukihiro "Matz" Matsumoto 830321fed5 Merge pull request #4155 from mimaki/fix-4153
Fixed a bug in INIT_DISPATCH for non direct threading; fix #4153
2018-11-01 22:31:31 +09:00
Hiroshi Mimaki 73727aeb50 Fixed a bug in INIT_DISPATCH for non direct threading; fix #4153 2018-11-01 11:10:47 +09:00
Yukihiro "Matz" Matsumoto 31eb5f4e1b Merge pull request #4152 from take-cheeze/build_debug_flag
Add debug flag to `MRuby::Build`
2018-10-30 09:04:35 +09:00
Yukihiro "Matz" Matsumoto cca5e0977c VS 2017 C does not understand inline struct initialization; ref #4153 2018-10-30 09:01:12 +09:00
take-cheeze 08bd095446 Add debug flag to MRuby::Build 2018-10-29 20:10:03 +09:00
take-cheeze 6a6586ca84 Reduce unnecessary symbol table entry 2018-10-29 19:40:33 +09:00
take-cheeze 486c9d902d Fix codedumper 2018-10-29 19:35:31 +09:00
take-cheeze 7d51a7bbf5 Fix document 2018-10-29 19:34:56 +09:00
take-cheeze 557805da07 Fix operator 2018-10-29 19:29:43 +09:00
take-cheeze 68714ab648 Fix SEGV 2018-10-29 19:26:00 +09:00
take-cheeze e022080390 Define null symbol 2018-10-29 19:22:53 +09:00
take-cheeze 3248de83b6 Reduce instruction size 2018-10-29 19:17:05 +09:00
Yukihiro "Matz" Matsumoto eebb56713e Merge pull request #4149 from take-cheeze/static_tr_pattern
Keep `tr_pattern` static if possible
2018-10-29 15:34:07 +09:00
Yukihiro "Matz" Matsumoto ae5463c9e4 Merge pull request #4148 from take-cheeze/rename_libmruby_stuff
Rename `MRuby::Build#libmruby` stuff to avoid confusion
2018-10-29 15:13:24 +09:00
Yukihiro "Matz" Matsumoto 63fade1396 Merge pull request #4147 from take-cheeze/add_missing_dep
Add missing dependency of source code generator
2018-10-29 15:12:07 +09:00
Yukihiro "Matz" Matsumoto a7e42a2024 Merge pull request #4146 from take-cheeze/sup_sleep_warn
Suppress sleep test script warning
2018-10-29 15:11:07 +09:00
Yukihiro "Matz" Matsumoto c7327c84dc Merge pull request #4145 from take-cheeze/sort_test_rbfiles
Sort test script list too
2018-10-29 15:10:36 +09:00
take-cheeze b37b312081 Rename libmruby stuff to avoid confusion 2018-10-29 14:07:16 +09:00
take-cheeze c240aeada9 Add missing dependency of source code generator 2018-10-29 13:58:57 +09:00
take-cheeze 1b185f08e7 Suppress sleep test script warning 2018-10-29 13:58:25 +09:00
take-cheeze ac512e9d9f Sort test script list too 2018-10-29 13:57:41 +09:00
take-cheeze 52d55e6069 Keep tr_pattern static 2018-10-29 13:21:36 +09:00
Yukihiro "Matz" Matsumoto fa33a4d75a We need no write barrier here; ref #4143 2018-10-29 12:01:27 +09:00
Yukihiro "Matz" Matsumoto 3dc3643e34 Marking from terminated fibers are not needed; ref #4143
The old condition marks the top-level callinfo even after the
fiber is terminated.
2018-10-29 11:58:10 +09:00
Yukihiro "Matz" Matsumoto 34872e90d4 Re-implement Array#_inspect and Hash#_inspect without blocks.
To reduce the env object allocation; ref #4143
2018-10-29 11:55:49 +09:00
Yukihiro "Matz" Matsumoto dffa203d07 Need to mark shared env objects as MRB_TT_FREE; fix #4143
The following code mistakenly exits from the function without marking
the env object as `MRB_TT_FREE`.

``` ruby
      if (MRB_ENV_STACK_SHARED_P(e)) {
        /* cannot be freed */
        return; // <- should be `break`
      }
```
2018-10-29 11:51:04 +09:00
Yukihiro "Matz" Matsumoto 7ff84789c3 Add argument check to Array#clear; fix #4144 2018-10-29 10:12:10 +09:00
Yukihiro "Matz" Matsumoto b3a181aaa1 Fixed a bug in processing OP_EXT? instructions.
fix haconiwa/haconiwa#171
2018-10-23 21:10:03 +09:00
Yukihiro "Matz" Matsumoto 80b5a56f51 Need to freeze string keys. 2018-10-20 19:02:12 +09:00
Yukihiro "Matz" Matsumoto e89676a6ec Merge pull request #4142 from iij/mergesort
replace quicksort with mergesort.
2018-10-18 13:02:11 +08:00
Tomoyuki Sahara 91444c4747 replace quicksort with mergesort. 2018-10-18 13:07:47 +09:00
Yukihiro "Matz" Matsumoto fdd5ce8fac Fixed a bug caused by too much optimization; fix #4137 2018-10-13 00:31:13 +09:00
Yukihiro "Matz" Matsumoto d2313aebd6 Fixed broken stack consistency; fix #4135 2018-10-12 23:26:14 +09:00
Yukihiro "Matz" Matsumoto e5f160dc7e Should not compare undef (deleted) key in hashes; fix #4136 2018-10-12 19:00:45 +09:00
Yukihiro "Matz" Matsumoto ab0f4db688 Call uniq! for each union processing in Array#union. 2018-10-12 19:00:14 +09:00
Yukihiro "Matz" Matsumoto 249fef7dc4 Add NULL check in sg_compact(); fix #4139 2018-10-12 08:30:57 +09:00
Yukihiro "Matz" Matsumoto 82e00ce60f Hash#delete should return the deleted value; fix #4133 2018-10-12 08:25:54 +09:00
Yukihiro "Matz" Matsumoto a690aef8d3 Merge pull request #4131 from junaruga/feature/ci-refactoring
Refactor .travis.yml to remove duplicated env: MRUBY_CONFIG.
2018-10-05 22:10:51 +09:00
Jun Aruga f38e6c63e9 Refactor .travis.yml to remove duplicated env: MRUBY_CONFIG. 2018-10-05 14:15:33 +02:00
Yukihiro "Matz" Matsumoto 8392578216 Fixed SEGV from eval called form top-level mrb_funcall(); fix #4028 2018-10-02 17:26:43 +09:00
Yukihiro "Matz" Matsumoto e6841abad6 Fixed a String#squeeze bug in handling iso-8859-1 strings; ref #4127 2018-09-27 21:43:35 +09:00
Yukihiro "Matz" Matsumoto 54ec08c7f1 Implement Hash#rehash in C using sg_compact(). 2018-09-26 23:09:48 +09:00
Yukihiro "Matz" Matsumoto d78acc7afe Add index to larger segment lists for performance 2018-09-26 23:09:48 +09:00
Yukihiro "Matz" Matsumoto 8ffd4e47fb Use mrb_undef_value for delete mark instead of shifting Hash entry table.
That means entry table should be compacted periodically by `sg_compact()`.
2018-09-26 23:09:48 +09:00
Yukihiro "Matz" Matsumoto e8dcfe1745 Use segmented list to implement Hash [Experimental]
I know it's not hash at all, but reduce memory consumption.
2018-09-26 12:55:22 +09:00
Yukihiro "Matz" Matsumoto 01c2f59e14 Revert "Fix comparisons in str_squeeze."
This reverts commit 7b04fcd092.
The issue was addressed by 9e3cbaa. No longer needed.
2018-09-26 12:35:25 +09:00
Yukihiro "Matz" Matsumoto 9e3cbaaacd Avoid using memmove() for performance; fix #4130 2018-09-26 12:20:37 +09:00
Yukihiro "Matz" Matsumoto 87ce740168 Disambiguate block braces. 2018-09-26 12:17:38 +09:00
Yukihiro "Matz" Matsumoto fb49a94314 Rename tr_pattern_free() to tr_free_pattern(). 2018-09-26 12:17:38 +09:00
Yukihiro "Matz" Matsumoto 78195eb2ae Small refactoring in vm.c 2018-09-26 12:17:38 +09:00
Yukihiro "Matz" Matsumoto 09a99154c0 Merge pull request #4128 from take-cheeze/patch-1
Fix memory leak in `mrb_str_count`
2018-09-25 12:03:26 +09:00
Takeshi Watanabe 67897195de Fix leak in mrb_str_count 2018-09-25 11:48:59 +09:00
Yukihiro "Matz" Matsumoto 152e8c5bb2 Merge pull request #4127 from clayton-shopify/fix-str-squeeze-comparisons
Fix comparisons in str_squeeze.
2018-09-25 11:43:41 +09:00
Daniel Varga 4d5e3e1e63 Fix minor typos (#4126) 2018-09-25 09:14:01 +09:00
Clayton Smith 7b04fcd092 Fix comparisons in str_squeeze. 2018-09-24 18:16:12 -04:00
sbsoftware 8fc56f062e Add compiler flag to disable direct threading (#4075)
* Add option to disable direct threading

* Prepend MRB_ to option name
2018-09-21 11:22:53 +09:00
Yukihiro "Matz" Matsumoto 9bd2a3b5d9 Fixed a top-level local variable bug in mirb.
`OP_STOP` returned a wrong value.
2018-09-21 00:51:29 +09:00
Yukihiro "Matz" Matsumoto 346f154ece Implement String#delete and #delete!; ref #4086
mruby restriction:
In mruby, `String#delete` only takes single pattern argument.
2018-09-21 00:03:07 +09:00
Yukihiro "Matz" Matsumoto 58f7f2361a Implement String#count; ref #4086
mruby restriction:
In mruby, `String#count` does not take multiple pattern arguments,
but only one pattern.
2018-09-21 00:03:07 +09:00
Yukihiro "Matz" Matsumoto 68523b4ec4 Add String#squeeze and #squeeze!; ref #4086
mruby restriction:
`String#squeeze` can take more than 1 pattern arguments in CRuby,
in that case, the intersection of patterns will be used to match.
But in mruby, it doesn't take multiple patterns.
2018-09-21 00:03:07 +09:00
Yukihiro "Matz" Matsumoto c0ae8a96a1 Add String#tr_s and String#tr_s!; ref #4086 2018-09-21 00:03:07 +09:00
Yukihiro "Matz" Matsumoto 58ba38fe1e Add String#tr and #tr! to mruby-string-ext gem; fix #4086
This patch is based on `mruby/c` implementation by Hirohito Higashi.

We might need to add `#tr_s`, `#squeeze` and `#delete` as well.
Adding them should not be too hard using functions we implemented here.
2018-09-21 00:03:07 +09:00
Yukihiro "Matz" Matsumoto f23f2bbdad Implement Array#union which is introduced in Ruby2.6. 2018-09-21 00:01:48 +09:00
Yukihiro "Matz" Matsumoto dd346be99a Improve performance of Array#uniq!. 2018-09-20 23:56:53 +09:00
Yukihiro "Matz" Matsumoto 5ec5a41fd2 Merge branch 'dearblue-assign-anon-class-name' 2018-09-20 13:58:36 +09:00
Yukihiro "Matz" Matsumoto 159575f630 Renamed is_namespace() to namespace_p(). 2018-09-20 13:57:43 +09:00
Yukihiro "Matz" Matsumoto 505e601730 Revert "Add MRB_IMPROVE_META_PROGRAMMING configuration"
This reverts commit 1997fcf98f.
It became the default behavior.
2018-09-20 13:53:55 +09:00
Yukihiro "Matz" Matsumoto d192a52edb Merge branch 'assign-anon-class-name' of https://github.com/dearblue/mruby into dearblue-assign-anon-class-name 2018-09-20 13:50:16 +09:00
Yukihiro "Matz" Matsumoto 3a9caad8eb Move Symbol#to_proc to the core from mruby-symbol-ext gem.
Even though `Symbol#to_proc` is not included in ISO standard, the
`some_method(&:method_name)` is used very widely and convenient.
So we moved it to the core.
2018-09-20 13:47:29 +09:00
Yukihiro "Matz" Matsumoto 19d3bb2d90 Make #to_h to take a block; [ruby-core:89088] 2018-09-20 13:47:29 +09:00
Yukihiro "Matz" Matsumoto fa5f5954da Merge pull request #4112 from dearblue/fix-outer-module-name
Fix outer module name
2018-09-20 13:47:16 +09:00
Yukihiro "Matz" Matsumoto b7e5c86612 Allow nested gemboxes; fix #4124 2018-09-20 11:10:34 +09:00
Yukihiro "Matz" Matsumoto 3820ef791f Small refactoring in mruby-hash-ext. 2018-09-20 09:07:24 +09:00
Yukihiro "Matz" Matsumoto 8b43754644 Use mrb_to_flo() to check return value from to_f; fix #4115
The ISO standard does not include implicit type conversion using
`to_int`, `to_str` and sometimes `to_f`. For the compactness of the
mruby implementation, maybe we should remove those implicit conversion
from mruby.
2018-09-18 09:35:09 +09:00
Yukihiro "Matz" Matsumoto e9b1d9dc2f Array size may be changed in mrb_get_args() reentry.
fix #4116; fix #4117; fix #4118; fix #4119; fix #4120
2018-09-18 07:07:43 +09:00
Yukihiro "Matz" Matsumoto 0ff1540e8b Merge pull request #4122 from blacktm/iphone-exclude-pipe-exec
Exclude pipe and exec on iOS/tvOS
2018-09-17 13:26:04 +09:00
Tom Black 82053dd945 Exclude pipe and exec on iOS/tvOS
Use of `execl()` is prohibited on these platforms
2018-09-15 13:55:11 -07:00
Yukihiro "Matz" Matsumoto ed4dbce052 fixup! Add support for iOS platforms that does not support fork; fix #4113 2018-09-16 00:58:52 +09:00
Yukihiro "Matz" Matsumoto 05595c1284 Merge pull request #4121 from clayton-shopify/fix-sprintf-overflow
Prevent signed integer overflow.
2018-09-16 00:45:55 +09:00
Yukihiro "Matz" Matsumoto 2661ac7049 Add support for iOS platforms that does not support fork; fix #4113 2018-09-16 00:41:48 +09:00
Clayton Smith 2760cea451 Prevent signed integer overflow. 2018-09-14 16:53:26 -04:00
Yukihiro "Matz" Matsumoto f93734f622 Merge pull request #4110 from dearblue/fix-typo1
Fix typo
2018-09-08 11:20:11 +09:00
dearblue 292ea06d4d Fix outer module name
example:
  a = Module.new
  a::B = Module.new
  p [a, a::B] # => [#<Module:0x801825890>, #<Class:0x801825890>::B]
              # => [#<Module:0x801825890>, #<Module:0x801825890>::B] (Fixed)
2018-09-08 10:25:30 +09:00
dearblue 5e6cd86f6e Fix to not define outer when outer is itself.
example:
  a = Class.new
  a::A = a
2018-09-07 23:56:06 +09:00
dearblue 366848996a Clear terminated space 2018-09-07 22:32:34 +09:00
dearblue 1997fcf98f Add MRB_IMPROVE_META_PROGRAMMING configuration 2018-09-07 22:32:34 +09:00
dearblue 1595e8368a Fix indent 2018-09-07 22:32:34 +09:00
dearblue 9b0ef58a48 A class/module name is now defined for meta programing 2018-09-07 22:32:34 +09:00
dearblue fd57af3ea4 Undesirable line split 2018-09-07 22:32:34 +09:00
dearblue 2a24b40d30 Not set a class/module name into anonymous class/module 2018-09-07 22:32:34 +09:00
dearblue 9da9e5eb4e Fix typo for concatenate 2018-09-07 22:32:34 +09:00
Yukihiro "Matz" Matsumoto 625976d793 Fix integer overflow issue; fix #4108
I misunderstood the return value from `snprintf()`, which is NOT number
of characters written in buffer, but the number of character the buffer
has to have to write the complete output.
2018-09-07 03:20:57 +09:00
Yukihiro "Matz" Matsumoto 3447162a4c Add a new method unpack1 to mruby-pack gem. 2018-09-07 02:16:56 +09:00
Yukihiro "Matz" Matsumoto 04f8b0431c Fix heap buffer overflow in unpack_a; fix #4103 2018-09-07 02:15:55 +09:00
Yukihiro "Matz" Matsumoto fdaec90780 Make Kernel#sleep to accept float as a duration time.
But when `MRB_WITHOUT_FLOAT` is set, there's no way to sleep for
sub seconds. So mruby specific `usleep` is provided.
2018-09-06 23:42:05 +09:00
Yukihiro "Matz" Matsumoto 72522f8e0e Remove Sleep module that does not exist in CRuby. 2018-09-06 23:35:32 +09:00
Yukihiro "Matz" Matsumoto 0b44e802a9 Need to check if merging hash is empty; fix #4107 2018-09-06 23:30:32 +09:00
Yukihiro "Matz" Matsumoto 4cd4c64266 Need to support multiple ** splats in argument list; fix #4106 2018-09-06 14:40:21 +09:00
Yukihiro "Matz" Matsumoto a170c1dd70 Refactored mruby-sleep gem.
* Method implementation functions made `static`.
 * Function declaration style has been changed.
 * Unnecessary header file `mrb_sleep.h` removed.
 * Used `mrb_get_args()` instead of self parsing.
 * Indentation kept untouched.
2018-09-05 14:55:49 +09:00
Yukihiro "Matz" Matsumoto 44fdd53f2e Add mruby-sleep gem to the core. 2018-09-05 13:30:14 +09:00
Yukihiro "Matz" Matsumoto b01b0d242b Free mrbc_context on exit from mruby. 2018-09-05 07:58:36 +09:00
Yukihiro "Matz" Matsumoto ade7185a2b Merge pull request #4055 from take-cheeze/verbose_bintest
Support verbose mode in bintest.
2018-09-05 07:11:23 +09:00
Yukihiro "Matz" Matsumoto 2a9525caab Add argv and argc check in OP_ENTER; fix #4102
`argv` may be retrieved from an array whose `ptr` is `NULL` when it`s
empty.
2018-09-05 07:06:25 +09:00
Yukihiro "Matz" Matsumoto 9b5910bd0f Revert "Remove top-level constant lookup; CRuby2.5"; fix #4070
This reverts commit c96def7c96.
This change was from my misunderstanding.
2018-09-04 21:19:07 +09:00
Yukihiro "Matz" Matsumoto 7592dfcf7d Need more precise constant name check.
This change was inspired by [ruby-bugs#7573]
2018-09-04 20:50:54 +09:00
Yukihiro "Matz" Matsumoto c2634e18b6 Add type casts to silence MSVC warnings. 2018-09-04 16:22:50 +09:00
Yukihiro "Matz" Matsumoto 28c50b3e90 Merge pull request #4101 from take-cheeze/fix_4085
Avoid root fiber initialization for CRuby.
2018-09-04 16:22:40 +09:00
take-cheeze 901dccb2df Avoid root fiber initialization for CRuby workaround.
closes #4085.
2018-09-04 16:18:01 +09:00
take-cheeze e6357f3baa Fix indent. 2018-09-04 16:18:01 +09:00
Yukihiro "Matz" Matsumoto 02adae167f Merge pull request #4098 from dearblue/reverse-gems-final
Reversing gems final
2018-09-04 07:26:25 +09:00
dearblue cbf2738861 Reverse gems final 2018-09-02 14:13:09 +09:00
Yukihiro "Matz" Matsumoto a657117e4e Avoid warning in MSVC compilation. 2018-09-01 17:36:35 +09:00
Yukihiro "Matz" Matsumoto 20c0c6330f Too much peephole optimization in gen_call; fix #4091
It causes trouble for safe navigation operator.
2018-09-01 17:14:54 +09:00
Yukihiro "Matz" Matsumoto b80e0ef742 Move Kernel#send to mruby-metaprog gem.
But `BasicObject#__send__` is still available from the core.
2018-09-01 11:20:30 +09:00
Yukihiro "Matz" Matsumoto 593c12a5cd Avoid NoMethodError exception from mrb_func_basic_p. 2018-09-01 11:18:12 +09:00
Yukihiro "Matz" Matsumoto 05f377dee4 Use __send__ instead of send. 2018-09-01 11:02:59 +09:00
Yukihiro "Matz" Matsumoto 0c6353aa2c Remove MRB_API from mrb_f_send which is not API. 2018-09-01 11:01:50 +09:00
Yukihiro "Matz" Matsumoto 2be42aef0f Fix ISO/JIS section numbers. 2018-09-01 09:35:46 +09:00
Yukihiro "Matz" Matsumoto 1bc1fed534 Update RITE_BINARY_FORMAT_VER and RITE_VM_VER.
The bytecode format was updated so the header version constants must be
updated as well.
2018-08-30 22:48:05 +09:00
Yukihiro "Matz" Matsumoto 50b840c9de Use mrb_ensure_hash_type() to check if an operand is a Hash; fix #4097 2018-08-30 22:30:36 +09:00
Yukihiro "Matz" Matsumoto f6564dd83e Add new function mrb_ensure_hash_type(); ref #4097
Unlike `mrb_check_hash_type()` that returns `nil` if the argument is
not a `Hash`, `mrb_ensure_hash_type()` raises a `TypeError` exception.
2018-08-30 22:30:36 +09:00
Yukihiro "Matz" Matsumoto e471d37ca5 Separate meta-programming features to mruby-metaprog gem.
We assume meta-programming is less used in embedded environments.
We have moved following methods:

 * Kernel module
   global_variables, local_variables, singleton_class,
   instance_variables, instance_variables_defined?, instance_variable_get,
   instance_variable_set, methods, private_methods, public_methods,
   protected_methods, singleton_methods, define_singleton_methods

 * Module class
   class_variables, class_variables_defined?, class_variable_get,
   class_variable_set, remove_class_variable, included_modules,
   instance_methods, remove_method, method_removed, constants

 * Module class methods
   constants, nesting

Note:
Following meta-programming methods are kept in the core:

 * Module class
   alias_method, undef_method, ancestors, const_defined?, const_get,
   const_set, remove_const, method_defined?, define_method

 * Toplevel object
   define_method

`mruby-metaprog` gem is linked by default (specified in default.gembox).
When it is removed, it will save 40KB (stripped:8KB) on x86-64
environment last time I measured.
2018-08-30 22:30:36 +09:00
Yukihiro "Matz" Matsumoto 75a01af710 Remove consequent OP_RETURN by peephole optimization. 2018-08-30 01:23:17 +09:00
Yukihiro "Matz" Matsumoto 5addd5db4a Need to clear mrb->c->cibase->ridx (toplevel ridx) at L_STOP; fix #4092
This problem only appears when `mrb` executed multiple times (i.e. `mirb`)
2018-08-30 01:20:59 +09:00
Yukihiro "Matz" Matsumoto 500bd38dfe uint16_t is too small for reference count; fix #4093
Use `uint32_t` instead. Theoretically `uint32_t` can overflow as well,
but I think it is sufficient size for embeddable Ruby VM.
2018-08-30 00:29:35 +09:00
Yukihiro "Matz" Matsumoto 2c93e4a0a8 The operand of OP_ARYDUP may not be an array; fix #4094
This commit also fix #4096.
2018-08-30 00:29:35 +09:00
Yukihiro "Matz" Matsumoto f76cc483d5 Fix off-by-one error in OP_EPUSH and OP_ONERR; fix #4095 2018-08-29 23:59:20 +09:00
Yukihiro "Matz" Matsumoto e91b6a0378 Merge pull request #4080 from 'ukrainskiysergey-node_negate_fix' 2018-08-29 13:34:02 +09:00
Yukihiro "Matz" Matsumoto 441ff45a51 Merge branch 'node_negate_fix' of https://github.com/ukrainskiysergey/mruby into ukrainskiysergey-node_negate_fix 2018-08-29 13:29:54 +09:00
Yukihiro "Matz" Matsumoto 98c759e86a Check the size of rescue&ensure stacks; ref #4088
Those small stack indexes can cause integer overflow.
2018-08-29 13:17:18 +09:00
Yukihiro "Matz" Matsumoto 2a88a546b2 Fix type of eidx and ridx from uint8_t to uint16_t; fix #4088
A byte was too small to hold ensure&rescue stacks indexes.
2018-08-29 13:15:24 +09:00
Yukihiro "Matz" Matsumoto 6aa091e5aa Simplified #ifdef nesting in codedump.c; fix #4089
`printf()` and related functions should not be called when
`MRB_DISABLE_STDIO` is defined.
2018-08-29 12:37:07 +09:00
Yukihiro "Matz" Matsumoto bc88fc6ed1 Check iseq buffer size before code emission; fix #4090
The type of `s->pc` is now `uint16_t` that can be overflowed easily.
Need more checks.
2018-08-29 12:31:48 +09:00
Yukihiro "Matz" Matsumoto 814b7b5ef8 Move back mrb_define_alias to mruby.h to avoid breakage. 2018-08-29 07:00:13 +09:00
Yukihiro "Matz" Matsumoto 93bab387a7 Merge branch 'mruby2-draft' 2018-08-28 22:13:52 +09:00
Yukihiro "Matz" Matsumoto 471288f37d Reduce integer casting warnings. 2018-08-25 16:58:01 +09:00
Yukihiro "Matz" Matsumoto d79dbd92f9 fixup! New bytecode implementation of mruby VM. 2018-08-25 09:49:20 +09:00
Yukihiro "Matz" Matsumoto 49d1b16822 Hash splat ** should not be ignored.
Implemented by adding `OP_HASHCAT` that merges hashes.
2018-08-25 09:41:21 +09:00
Yukihiro "Matz" Matsumoto 306732e02d Fixed a bug in OP_HASHADD. 2018-08-25 09:41:21 +09:00
Yukihiro "Matz" Matsumoto a3fb80904d Remove unused Hash#__update method. 2018-08-25 09:41:21 +09:00
Yukihiro "Matz" Matsumoto 3554fc54de Add a new function mrb_hash_merge(). 2018-08-25 09:41:21 +09:00
Yukihiro "Matz" Matsumoto b06dad43fa Remove unused NODE_* constants from node.h. 2018-08-25 09:41:21 +09:00
Yukihiro "Matz" Matsumoto e5eb7ef046 Add NODE_KW_HASH support in mrb_parser_dump(). 2018-08-25 09:41:21 +09:00
Yukihiro "Matz" Matsumoto 162243d95c Remove arg_value from parse.y. 2018-08-25 09:41:21 +09:00
Yukihiro "Matz" Matsumoto b7e56e9d20 Add bytecode support for MRB_WORD_BOXING. 2018-08-25 09:41:21 +09:00
Yukihiro "Matz" Matsumoto eeb6d5658d New bytecode implementation of mruby VM. 2018-08-25 09:41:21 +09:00
Yukihiro "Matz" Matsumoto a16885efe5 Try to fix a fragile File#mtime test. 2018-08-25 09:19:17 +09:00
Yukihiro "Matz" Matsumoto 31827189ab Remove potential path to avoid uninitialized variable access. 2018-08-25 09:19:17 +09:00
Yukihiro "Matz" Matsumoto fbfe519be7 Simplify mruby-inline-struct tests.
`gcc -O3` raises error on truncation using `snprintf`.
2018-08-25 09:19:17 +09:00
Yukihiro "Matz" Matsumoto b3a1d37926 Make Array.new to accept both integers and floats.
This time we used `Integral` module which is mruby specific.
2018-08-25 09:19:17 +09:00
Kazuhiro Sera 2b2ff844a1 Fix misspelling words in comments 2018-08-25 09:19:17 +09:00
Yukihiro "Matz" Matsumoto b083c1351f Fixed the corner case bug in String#{gsub!,sub!}.
`"a".sub!("a", "a")` should not return `nil`.
2018-08-25 09:17:46 +09:00
pyama86 821135e2df irep is released when Fiber is terminated 2018-08-25 09:17:46 +09:00
Yukihiro "Matz" Matsumoto 49d9fb8f41 Reimplement Hash#compact! to conform the standard behavior.
`Hash#compact!` should return `nil` if the receiver does not change.
2018-08-25 09:17:46 +09:00
Yukihiro "Matz" Matsumoto 9409a2ff6d Rename ambiguous function names.
`mrb_iv_p` -> `mrb_iv_name_sym_p`
`mrb_iv_check` -> `mrb_iv_name_sym_check`
2018-08-25 09:17:46 +09:00
Yukihiro "Matz" Matsumoto 5e469d2b92 Remove utility functions: mrb_vm_iv_{get,set}. 2018-08-25 09:17:46 +09:00
Yukihiro "Matz" Matsumoto c88fd32713 Revert 04dbbff.
Use segment list for instance variable again to reduce memory.
2018-08-25 09:16:01 +09:00
Yukihiro "Matz" Matsumoto 4c974b9523 Small refactoring.
The macro `RCLASS_SUPER`, `RCLASS_IV_TBL` and `RCLASS_M_TBL` are
removed from `include/mruby/class.h`.
2018-08-25 09:16:01 +09:00
Yukihiro "Matz" Matsumoto f3564a405e Small refactoring of flodivmod(). 2018-08-25 09:16:01 +09:00
dearblue 322eb2328a Fix mrb_value size with MRB_WORD_BOXING on 32-bit mode 2018-08-25 09:16:01 +09:00
Yukihiro "Matz" Matsumoto 6681e22c71 Simply use snprintf instead of custom fmt_fp,
Unless `MRB_DISABLE_STDIO` is set. `snprintf` is used anyway
if mruby is configured to use `stdio`. This change reduces 8KB
of program size on the Linux box.
2018-08-25 09:16:01 +09:00
Yukihiro "Matz" Matsumoto 91c08d7631 Remove nregs member from mrb_callinfo.
This means reducing one word per a call frame.
2018-08-25 09:16:01 +09:00
Yukihiro "Matz" Matsumoto 8a18d1539b Should update ci->env to share the environment; fix #4073 2018-08-25 09:13:09 +09:00
Yukihiro "Matz" Matsumoto fd086833ff Reorganize flags values for classes; fix #3975
Renamed flag macro names as well:
`MRB_FLAG_IS_FROZEN` -> `MRB_FL_OBJ_FROZEN`
`MRB_FLAG_IS_PREPENDED` -> `MRB_FL_CLASS_IS_PREPENDED`
`MRB_FLAG_IS_ORIGIN` -> `MRB_FL_CLASS_IS_ORIGIN`
`MRB_FLAG_IS_INHERITED` -> `MRB_FL_CLASS_IS_INHERITED`
2018-08-25 09:13:09 +09:00
Yukihiro "Matz" Matsumoto bfd11aab35 Check size of the integer multiply before actual overflow; fix #4062 2018-08-25 09:13:09 +09:00
Yukihiro "Matz" Matsumoto fe77272c25 Kernel#p should return an array of arguments; fix #4083
Although the return value is not defined in ISO, it is better to behave
as CRuby does.
2018-08-18 22:40:44 +09:00
Yukihiro "Matz" Matsumoto c095736002 Try to fix a fragile File#mtime test. 2018-08-13 23:15:52 +09:00
Yukihiro "Matz" Matsumoto 14206a75a3 Remove potential path to avoid uninitialized variable access. 2018-08-13 23:15:52 +09:00
Yukihiro "Matz" Matsumoto 1e52d47bc3 Simplify mruby-inline-struct tests.
`gcc -O3` raises error on truncation using `snprintf`.
2018-08-13 23:15:52 +09:00
Yukihiro "Matz" Matsumoto fee9ec61bb Make Array.new to accept both integers and floats.
This time we used `Integral` module which is mruby specific.
2018-08-13 23:15:52 +09:00
Yukihiro "Matz" Matsumoto 11d5782687 Merge pull request #4081 from seratch/fix-typo
Fix misspelling words in comments, docs
2018-08-11 10:35:13 +09:00
Kazuhiro Sera b03f1f78e3 Fix misspelling words in comments 2018-08-11 00:28:32 +09:00
Ukrainskiy Sergey fbe876b871 Added push() after OP_SEND 2018-08-10 06:44:19 +09:00
Ukrainskiy Sergey 672110dbe8 Small fix 2018-08-09 17:57:18 +09:00
Ukrainskiy Sergey e3b181586c Fix weird behavior of the NODE_NEGATE 2018-08-09 17:31:57 +09:00
Yukihiro "Matz" Matsumoto 35be8b2524 Fixed the corner case bug in String#{gsub!,sub!}.
`"a".sub!("a", "a")` should not return `nil`.
2018-08-07 23:03:17 +09:00
pyama86 54246db00a irep is released when Fiber is terminated 2018-08-06 19:13:19 +09:00
Yukihiro "Matz" Matsumoto 62e8e910b2 Reimplement Hash#compact! to conform the standard behavior.
`Hash#compact!` should return `nil` if the receiver does not change.
2018-08-06 16:40:19 +09:00
Yukihiro "Matz" Matsumoto 0dca6206c1 Rename ambiguous function names.
`mrb_iv_p` -> `mrb_iv_name_sym_p`
`mrb_iv_check` -> `mrb_iv_name_sym_check`
2018-08-06 10:15:55 +09:00
Yukihiro "Matz" Matsumoto 8f386f7663 Remove utility functions: mrb_vm_iv_{get,set}. 2018-08-06 10:15:55 +09:00
Yukihiro "Matz" Matsumoto 14c7a9c548 Revert 04dbbff.
Use segment list for instance variable again to reduce memory.
2018-08-06 10:15:55 +09:00
Yukihiro "Matz" Matsumoto afbbc0a2cb Small refactoring.
The macro `RCLASS_SUPER`, `RCLASS_IV_TBL` and `RCLASS_M_TBL` are
removed from `include/mruby/class.h`.
2018-08-06 10:15:55 +09:00
Yukihiro "Matz" Matsumoto 005ccd9c7e Small refactoring of flodivmod(). 2018-08-06 10:15:55 +09:00
Yukihiro "Matz" Matsumoto 708d6a4964 Merge pull request #4077 from dearblue/fix-wordboxing-symbol
Fix to sizeof(mrb_value) is 4 bytes with MRB_WORD_BOXING on 32-bit mode
2018-08-06 10:15:34 +09:00
dearblue ca01c8792d Fix mrb_value size with MRB_WORD_BOXING on 32-bit mode 2018-08-05 20:33:44 +09:00
Yukihiro "Matz" Matsumoto 4713cd9eb7 Simply use snprintf instead of custom fmt_fp,
Unless `MRB_DISABLE_STDIO` is set. `snprintf` is used anyway
if mruby is configured to use `stdio`. This change reduces 8KB
of program size on the Linux box.
2018-08-01 16:50:44 +09:00
Yukihiro "Matz" Matsumoto b9817b00a4 Remove nregs member from mrb_callinfo.
This means reducing one word per a call frame.
2018-08-01 13:18:32 +09:00
Yukihiro "Matz" Matsumoto e89cc9b9fa Should update ci->env to share the environment; fix #4073 2018-08-01 10:08:40 +09:00
Yukihiro "Matz" Matsumoto d886676690 Merge pull request #4074 from znz/patch-1
Remove unmatched quotation mark
2018-08-01 09:26:23 +09:00
Kazuhiro NISHIYAMA 64748691de Remove unmatched quotation mark 2018-07-31 22:09:45 +09:00
Yukihiro "Matz" Matsumoto beb6e5c299 Bytecode support for mrdb. 2018-07-31 17:28:42 +09:00
Yukihiro "Matz" Matsumoto 889f0f5f36 Add test case corresponding to 53e2723. 2018-07-31 17:27:59 +09:00
Yukihiro "Matz" Matsumoto 8558627b9b Reorganize flags values for classes; fix #3975
Renamed flag macro names as well:
`MRB_FLAG_IS_FROZEN` -> `MRB_FL_OBJ_FROZEN`
`MRB_FLAG_IS_PREPENDED` -> `MRB_FL_CLASS_IS_PREPENDED`
`MRB_FLAG_IS_ORIGIN` -> `MRB_FL_CLASS_IS_ORIGIN`
`MRB_FLAG_IS_INHERITED` -> `MRB_FL_CLASS_IS_INHERITED`
2018-07-31 16:48:50 +09:00
Yukihiro "Matz" Matsumoto 180f39bf4c Check size of the integer multiply before actual overflow; fix #4062 2018-07-31 16:14:18 +09:00
Yukihiro "Matz" Matsumoto 4ce9058f64 Describe the difference of the keyword argument behavior.
The implementation of keyword arguments is heavily rely on the prototype
made by @take-cheeze in #3629.
2018-07-31 03:26:53 +09:00
Yukihiro "Matz" Matsumoto e27565152f Removed merge hiccups in doc/opcode.md. 2018-07-31 03:20:27 +09:00
Yukihiro "Matz" Matsumoto 43173e1299 Removed unused instruction: OP_KDICT. 2018-07-31 03:20:00 +09:00
Yukihiro "Matz" Matsumoto 53e2723fae Fixed a small bug in keyword argument parsing.
def m(a=1,**k) p [a,k] end
m(a: 1)
2018-07-31 03:14:42 +09:00
Yukihiro "Matz" Matsumoto 8c9e712784 Keyword argument implemented. 2018-07-30 22:58:01 +09:00
Yukihiro "Matz" Matsumoto 891839b976 New bytecode implementation of mruby VM. 2018-07-30 22:57:54 +09:00
Yukihiro "Matz" Matsumoto b09d2eb900 Kernel#instance_eval should define singleton methods; fix #4069 2018-07-23 18:26:24 +09:00
Tomoyuki Sahara cb42c98757 Merge pull request #4072 from katzer/fix/unsupported_servname
[mruby-socket] Network services might not be available
2018-07-21 20:07:37 +09:00
Sebastián Katzer 0bc8d1979c Network services might not be available 2018-07-21 10:18:22 +02:00
Yukihiro "Matz" Matsumoto e3bc680d98 Merge pull request #4068 from yurie/mrbc
add mrbc option `--remove-lv`
2018-07-11 15:09:57 +09:00
yuri a921b936d6 move declaration of mrb_irep_remove_lv from dump.h to irep.h 2018-07-11 14:14:12 +09:00
yuri 5fef38e4c7 move mrb_irep_remove_lv to codegen.c in mruby-compiler 2018-07-10 15:44:25 +09:00
yuri dabb20ddbb add mrbc option --remove-lv
* refactor: move `irep_remove_lv` from `mruby-bin-strip` gem to src/dump and rename to `mrb_irep_remove_lv`
* add: mrbc option `--remove-lv` to remove LVAR section
2018-07-10 01:42:33 +09:00
Yukihiro "Matz" Matsumoto ea435f99da Merge pull request #4067 from katzer/patch-1
[mruby-test] Fix task name is not necessarily a valid path
2018-07-09 08:19:12 +09:00
Sebastián Katzer b1f1fe2f81 Fix task name is not necessarily a valid path
Errno::ENOENT: No such file or directory @ dir_s_mkdir - mruby:Z:/Documents
2018-07-08 13:51:00 +02:00
Yukihiro "Matz" Matsumoto 17c9e65603 Merge pull request #4066 from duangsuse/master
Added ~/Android/Sdk/ndk-bundle as default NDK home
2018-07-04 22:12:41 +09:00
duangsuse 06428059f6 Add ~/Android/Sdk/ndk-bundle as default NDK home 2018-07-04 19:33:11 +08:00
Yukihiro "Matz" Matsumoto 5bb3f60e49 Merge pull request #4064 from mame/mrb_without_float-for-mruby-io
Support MRB_WITHOUT_FLOAT to mruby-io
2018-07-02 11:00:35 +09:00
Yusuke Endoh 7917b7f8bf Support MRB_WITHOUT_FLOAT to mruby-io 2018-07-02 10:47:56 +09:00
Yukihiro "Matz" Matsumoto adb1eae912 Use mrb_raise() instead of mrb_raisef(); ref #4062 2018-06-28 22:40:24 +09:00
Yukihiro "Matz" Matsumoto e60829405c Merge pull request #4063 from graywolf/patch-1
Add information about Kernel#binding
2018-06-28 08:43:25 +09:00
W 3116d06003 Add information about Kernel#binding 2018-06-27 12:20:24 +00:00
Yukihiro "Matz" Matsumoto 695f29cd60 Add negative check in mrb_str_resize; fix #4062 2018-06-27 16:32:24 +09:00
Yukihiro "Matz" Matsumoto 7e79840587 initialize a local variable to avoid warning 2018-06-22 12:03:52 +09:00
Yukihiro "Matz" Matsumoto 351614bbdd Merge pull request #4059 from take-cheeze/parallel_tests
Run tests parallelly for each target.
2018-06-22 12:02:09 +09:00
Yukihiro "Matz" Matsumoto 864a998c24 Merge pull request #4058 from take-cheeze/exp_sleep
Increase sleep duration exponentially instead of `Thread.pass`.
2018-06-22 12:01:33 +09:00
take-cheeze eaf463ada3 Run tests parallelly for each target. 2018-06-22 11:43:14 +09:00
take-cheeze 48ba7c7bb0 Increase sleep duration exponentially instead of Thread.pass. 2018-06-22 11:41:12 +09:00
Yukihiro "Matz" Matsumoto 3671404391 Merge pull request #4053 from take-cheeze/use_transfer
Use Fiber#transfer instead in minirake.
2018-06-22 10:26:37 +09:00
Yukihiro "Matz" Matsumoto 410a5031fc Merge pull request #4057 from take-cheeze/use_thread_pass
Use `Thread.pass` instead of sleeping.
2018-06-22 10:19:16 +09:00
take-cheeze 61e8f831dd Use Thread.pass instead of sleeping. 2018-06-22 09:29:59 +09:00
Yukihiro "Matz" Matsumoto 36e1796e41 Merge branch 'master' into use_transfer 2018-06-22 07:23:50 +09:00
Yukihiro "Matz" Matsumoto 640fca3276 Merge pull request #4056 from take-cheeze/fix_rake_jobs
Fix job waiter of minirake.
2018-06-22 07:18:01 +09:00
Yukihiro "Matz" Matsumoto 485efd9253 Merge pull request #4054 from take-cheeze/show_rake_bt
Show minirake backtrace in verbose mode.
2018-06-22 07:16:48 +09:00
take-cheeze 7c246cb9db Fix job waiter. 2018-06-21 12:45:55 +09:00
take-cheeze acd04ad519 Support verbose mode in bintest. 2018-06-21 11:33:34 +09:00
take-cheeze c90dbd12ef Show minirake backtrace in verbose mode. 2018-06-21 11:29:50 +09:00
take-cheeze 6f35b07fab Use Fiber#transfer instead in minirake. 2018-06-21 11:26:55 +09:00
Yukihiro "Matz" Matsumoto fd9617cad0 Merge pull request #4052 from take-cheeze/fix_mtime_test
Use temporary file name for `File#mtime` test to avoid conflicts.
2018-06-20 23:19:52 +09:00
Yukihiro "Matz" Matsumoto 1829b76929 Merge pull request #4051 from take-cheeze/para_rake
Make minirake parallel.
2018-06-20 22:09:54 +09:00
take-cheeze 7bb2fc70f2 Set jobs to 4 since it have 2 CPUs. 2018-06-20 21:44:23 +09:00
take-cheeze 8f808cc9b1 Use temporary name for File#mtime test to avoid conflicts. 2018-06-20 21:42:48 +09:00
take-cheeze 33f72bb038 disable sudo. 2018-06-20 21:34:03 +09:00
take-cheeze c3ac33d9cd Make minirake parallel. 2018-06-20 20:51:24 +09:00
Yukihiro "Matz" Matsumoto cfed6e3a4b Merge pull request #4050 from take-cheeze/fix_build_script
Fix build scripts.
2018-06-20 20:42:53 +09:00
Yukihiro "Matz" Matsumoto 1a9195285c Merge pull request #4049 from take-cheeze/fix_mirb_leak
Fix memory leaks in mirb.
2018-06-20 19:13:43 +09:00
take-cheeze b8fec13cab Make codacy happy. 2018-06-20 18:29:11 +09:00
take-cheeze 1d7c69a7cb Fix dependencies. 2018-06-20 18:23:08 +09:00
take-cheeze a212428fed Comment out unused variable. 2018-06-20 18:22:50 +09:00
take-cheeze 633599a2cb Fix forgotten argument passing. 2018-06-20 18:21:57 +09:00
take-cheeze dfddc6a09f Fix dependencies. 2018-06-20 18:21:33 +09:00
take-cheeze e050cfb349 Add forgotten mkdir_ps. 2018-06-20 18:20:26 +09:00
take-cheeze 26d143bda8 Fix memory leaks in mirb. 2018-06-20 18:16:25 +09:00
Yukihiro "Matz" Matsumoto f29bc4607a Add test_dependency from mruby-io to mruby-time. 2018-06-20 15:24:46 +09:00
Yukihiro "Matz" Matsumoto 54cd2623b3 Turn off enable_debug flag in build_config.rb by default.
This will improve the default performance of mruby; fix #4045
2018-06-20 15:24:46 +09:00
Yukihiro "Matz" Matsumoto 58d819f317 Merge pull request #4048 from kou/export-mrb-utf8-locale
Export mrb_utf8_from_locale() and mrb_locale_from_utf8()
2018-06-20 13:39:59 +09:00
Kouhei Sutou e38d1d278b Export mrb_utf8_from_locale() and mrb_locale_from_utf8() 2018-06-20 11:45:15 +09:00
Yukihiro "Matz" Matsumoto 5e7ced0785 Merge pull request #4047 from kou/stop-to-use-freed-value
Stop to use freed value
2018-06-19 19:33:37 +09:00
Yukihiro "Matz" Matsumoto 47413d0507 Merge pull request #4046 from kou/fix-wrong-free-function
Fix wrong free function
2018-06-19 19:32:18 +09:00
Kouhei Sutou 33c8c8f8a6 Stop to use freed value 2018-06-19 17:27:34 +09:00
Kouhei Sutou fb9358206e Fix wrong free function
mrb_locale_free() should be used for the return value of
mrb_locale_from_utf8().
2018-06-19 17:25:38 +09:00
Yukihiro "Matz" Matsumoto a9abf65f03 Fixed wrong usages of mrb_raisef(); ref #4043
`mrb_raisef()` only takes `%S` specifier. If you don't have extra
arguments, use `mrb_raise()`.
2018-06-15 07:47:18 +09:00
Yukihiro "Matz" Matsumoto 70600c3ba8 Resolve sign comparison warning; ref #4044 2018-06-14 14:16:04 +09:00
Tomoyuki Sahara 5340d39ed4 Merge pull request #4044 from iij/fixes-from-iij-socket
incorporate fixes from iij/socket
2018-06-14 13:58:48 +09:00
Tomoyuki Sahara af8020e7fd sa_family_t is not defined on windows. 2018-06-14 13:52:37 +09:00
Tomoyuki Sahara 2eeac91098 set sockaddr_un.sun_len on the systems that have sockaddr.sa_len.
If your system has sa_len but is not BSD-derived, define HAVE_SA_LEN=1
on mrbgem.rake or build_config.rb.
2018-06-14 13:36:01 +09:00
Tomoyuki Sahara 5013d2b20f struct sockaddr_un can be truncated.
When we have "struct sockaddr_un *s_un", we could not assume *s_un
points to a memory region which size is at least sizeof(*s_un).
Even worse, it may be shorter than sizeof(struct sockaddr) on some
systems.
2018-06-14 13:28:32 +09:00
Tomoyuki Sahara 3618556a95 struct sockaddr_un can be shorter than struct sockaddr.
ref: https://github.com/iij/mruby-socket/issues/45
2018-06-14 13:25:57 +09:00
Yukihiro "Matz" Matsumoto 97933665b6 Restore GC arena after raised exceptions; ref #4042 2018-06-14 11:42:34 +09:00
Yukihiro "Matz" Matsumoto ba090a46af Need to add a write barrier for ranges; fix #4042
Ranges are almost immutable but `initialize` and `initialize_copy`
modify the receiver so that we need to add a write barrier.
2018-06-14 11:25:12 +09:00
Yukihiro "Matz" Matsumoto a7f77fefa9 Check for switching to uninitialized fiber; fix #4041
The problem was caused by `Fiber.current.resume'.
2018-06-14 11:15:49 +09:00
Yukihiro "Matz" Matsumoto 896de5532b Merge pull request #4043 from take-cheeze/fix_test_dep
Fix unnecessary rebuild of tests.
2018-06-14 10:13:35 +09:00
take-cheeze f715f2ddea Fix unnecessary rebuild of tests. 2018-06-13 23:32:08 +09:00
Yukihiro "Matz" Matsumoto 23a4e7149d Revert "No longer need to insert write barriers for fibers."
This reverts commit c6736357a7.
The assumption was wrong and caused the issue; fix #4020
2018-06-11 14:50:42 +09:00
Yukihiro "Matz" Matsumoto a9b740b36b Retrieve b operand from the instruction (for debugging); ref #4020 2018-06-11 14:50:03 +09:00
Yukihiro "Matz" Matsumoto faa4eaf680 mrb_class_real() did not work for BasicObject; fix #4037 2018-06-08 14:13:06 +09:00
Yukihiro "Matz" Matsumoto 55edae0226 Allow Object#clone to copy frozen status only; fix #4036
Copying all flags from the original object may overwrite the clone's
flags e.g. the embedded flag.
2018-06-07 16:17:00 +09:00
Yukihiro "Matz" Matsumoto cfd0c93d7d Merge pull request #4035 from katzer/patch-1
[mruby-socket] Declare inet_ntop and inet_pton as static
2018-06-07 16:03:14 +09:00
Yukihiro "Matz" Matsumoto 55dcdd26cc Merge pull request #4039 from i110/i110/fix-broken-lexical-variables
fix broken lexical variables
2018-06-07 16:02:30 +09:00
Yukihiro "Matz" Matsumoto 778500563a Extend stack when pushing arguments that does not fit in; fix #4038 2018-06-07 15:59:00 +09:00
Yukihiro "Matz" Matsumoto ff0a4f7867 Export stack_extend function (renamed mrb_stack_extend); fix #3219
This change is required to support #4038.
2018-06-07 15:55:20 +09:00
Ichito Nagata 1dbeda5c9c add test for eval 2018-06-06 15:35:41 +09:00
Ichito Nagata c2b2bec9e2 Revert "Fix heap use after free on mruby-aws-sigv4."
This reverts commit b8869498b7.
2018-06-06 15:04:58 +09:00
Sebastián Katzer e7a4699135 Declare inet_ntop and inet_pton as static
To avoid conflicts with multiple definitions of inet_ntop and inet_pton if compiled with # define _WIN32_WINNT _WIN32_WINNT_VISTA

C:/mingw-w64/x86_64-7.2.0-posix-seh-rt_v5-rev1/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/7.2.0/../../../../x86_64-w64-mingw32/lib/../lib/libWs2_32.a(dghfs00169.o):(.text+0x0): multiple definition of `inet_pton'
722C:/projects/iss/mruby/build/host/lib/libmruby.a(socket.o):C:/projects/iss/mruby/mrbgems/mruby-socket/src/socket.c:80: first defined here

define _WIN32_WINNT _WIN32_WINNT_VISTA
2018-06-05 15:59:12 +02:00
Yukihiro "Matz" Matsumoto aa5c5de4fd Merge pull request #4033 from i110/i110/fix-envadjust
fix env->stack misadjusting: fix #4029
2018-06-03 20:54:12 +09:00
Ichito Nagata edaa7a1ba1 fix env->stack misadjusting 2018-06-03 19:40:33 +09:00
Yukihiro "Matz" Matsumoto 395260747a Instead of defining Hash#dup, we should define Hash#initialize_copy.
`Hash#clone` did not work properly; fix #4030
2018-06-01 22:40:42 +09:00
Yukihiro "Matz" Matsumoto f408143c28 The clone method should copy object status (e.g. frozen) too; #4030 2018-06-01 22:39:40 +09:00
Yukihiro "Matz" Matsumoto 7ed164ba89 Merge pull request #4031 from i110/i110/hash_default
let Hash#merge keep ifnone value
2018-06-01 20:29:45 +09:00
Ichito Nagata 4a2b055cdd let Hash#merge keep ifnone value 2018-06-01 12:48:17 +09:00
Yukihiro "Matz" Matsumoto b64ce17852 Should not call initialize_copy for TT_ICLASS; fix #4027
Since `TT_ICLASS` is a internal object that should never be revealed
to Ruby world.
2018-05-30 17:05:40 +09:00
Yukihiro "Matz" Matsumoto 1dddc2f712 Clear __classname__ of duped class/module; ref #4027 2018-05-30 17:05:05 +09:00
Yukihiro "Matz" Matsumoto 14c21793a0 Check if the exception is frozen; fix #4025
`exc_debug_info()` and `mrb_keep_backtrace()` raise `FrozenError`
if the exception is frozen and lead to infinite loop.
2018-05-23 08:30:50 +09:00
Yukihiro "Matz" Matsumoto c8fb7453fc Add then alias to yield_self.
`then' was added in CRuby 2.6.
2018-05-23 08:30:50 +09:00
Yukihiro "Matz" Matsumoto a7c8575fe3 Merge pull request #4023 from iwamatsu/fix-upstream
Fix test of mruby-pack with big-endian CPUs
2018-05-11 10:34:01 +09:00
Nobuhiro Iwamatsu 0759647f06 Fix test of mruby-pack with big-endian CPUs
When running the mruby-pack test with big endian, test data is incorrect,
so it will fail with "i" and "I".

------
Fail: pack/unpack "i" (mrbgems: mruby-pack)
 - Assertion[1] Failed: Expected to be equal
    Expected: "\xff\xff\xc7\xcf"
      Actual: "\xff\xff\xcf\xc7"
 - Assertion[2] Failed: Expected to be equal
    Expected: [-12345]
      Actual: [-14385]
Fail: pack/unpack "I" (mrbgems: mruby-pack)
 - Assertion[1] Failed: Expected to be equal
    Expected: "\x00\x0090"
      Actual: "\x00\x0009"
 - Assertion[2] Failed: Expected to be equal
    Expected: [12345]
      Actual: [14640]
------

This will fix the test data at big-endian.

Signed-off-by: Nobuhiro Iwamatsu <iwamatsu@nigauri.org>
2018-05-10 12:54:08 +09:00
Yukihiro "Matz" Matsumoto bda88bdbea Merge pull request #4022 from mimaki/mruby-r-option
Add `-r` option for `mruby` and `mirb`. (mrbgem is not supported)
2018-05-09 18:31:34 +08:00
Hiroshi Mimaki e76492c776 Fix CI build errors and warnings. 2018-05-08 09:55:09 +09:00
Hiroshi Mimaki d973a8ebc4 Add -r option for mruby and mirb. 2018-05-07 18:17:50 +09:00
Yukihiro "Matz" Matsumoto fc247449e2 Merge pull request #4017 from mimaki/mruby-d-option
Add `-d` option for `mruby` and `mirb`.
2018-05-07 14:31:19 +08:00
Hiroshi Mimaki 0c01afc3c9 Fix CI build errors and warnings. 2018-05-07 12:23:32 +09:00
Yukihiro "Matz" Matsumoto 72581696d3 env referred from top-level callinfo should not be unshared; fix #4019
Because `mirb` keeps top-level environment across each iteration.
2018-05-03 15:15:30 +09:00
Yukihiro "Matz" Matsumoto 2d4c092de7 Need to call mrb_str_modify() in mrb_str_cat_str(); fix #4018
If `str` and `str2` are the same string object `str->ptr` may be
rewritten by `mrb_str_modify()`.
2018-05-02 22:50:55 +09:00
Hiroshi Mimaki 1d16646506 Add -d option for mruby and mirb. 2018-05-02 20:52:02 +09:00
Yukihiro "Matz" Matsumoto 028e34d345 Update MRB_FLO_TO_STR_FMT to "%.16g"; fix #4016 2018-05-01 17:21:01 +09:00
Yukihiro "Matz" Matsumoto 2a38eb9325 Check the return value from mrb_get_datatype(); fix #4009
The return value (void*) may be NULL. Avoid using `mrb_get_datatype()`
directly and use `io_get_open_fptr()` instead.
2018-05-01 13:29:08 +09:00
Yukihiro "Matz" Matsumoto a8122a9d56 Fix stack position in multiple assignment; fix #4008
This was caused by a patch from #2684.
2018-05-01 12:25:04 +09:00
Yukihiro "Matz" Matsumoto 59c8fdd651 Update OP_APOST description; ref #4008 2018-04-28 15:36:23 +09:00
Yukihiro "Matz" Matsumoto 0fee6e1ee9 Fix broken support of MRB_WITHOUT_FLOAT; fix #4015 2018-04-28 15:15:28 +09:00
Yukihiro "Matz" Matsumoto 50a9c5d7c7 Update the patch to not use funcall in C; ref #4013 2018-04-28 11:26:23 +09:00
kimu_shu 4b29abc565 Fix Enumerable#hash on non 32-bit integer conf. 2018-04-28 11:26:23 +09:00
Yukihiro "Matz" Matsumoto 84b499d02b Merge pull request #4014 from mruby/stable
Set the mruby-1.4.1 release date to `2018-4-27`.
2018-04-28 10:08:56 +09:00
Yukihiro "Matz" Matsumoto b956c0f43c Merge pull request #4012 from take-cheeze/fix_heap_use_after_free
Fix heap use after free on mruby-aws-sigv4.
2018-04-28 10:08:20 +09:00
Hiroshi Mimaki 023070a639 Set the mruby-1.4.1 release date to 2018-4-27. 2018-04-27 11:30:30 +09:00
Takeshi Watanabe b8869498b7 Fix heap use after free on mruby-aws-sigv4. 2018-04-27 10:45:59 +09:00
Yukihiro "Matz" Matsumoto 1b261382a0 Merge pull request #4011 from kou/fix-gc-env-children
Fix wrong the number of marked objects of MRB_TT_ENV in gray mark phase
2018-04-26 23:00:25 +09:00
Kouhei Sutou 4194fe9d65 Fix wrong the number of marked objects of MRB_TT_ENV in gray mark phase
If MRB_TT_ENV has stack shared flag or bidx flag, flags is too large
than the real stack size.
2018-04-26 15:25:36 +09:00
Yukihiro "Matz" Matsumoto 1c66d42e47 Merge pull request #4010 from take-cheeze/fix_ary_replace_leak
Fix array replace leak error in mruby-uri.
2018-04-25 15:59:56 +09:00
Takeshi Watanabe e66c990234 Fix array replace leak error in mruby-uri. 2018-04-25 13:27:00 +09:00
Yukihiro "Matz" Matsumoto 8bfad558f8 Merge pull request #4007 from iij/sort-should-not-consume-system-stack
sort method should not consume system stack.
2018-04-23 13:15:10 +09:00
Yukihiro "Matz" Matsumoto 1ca06f407b Merge pull request #4006 from take-cheeze/fix_ub_check
Fix undefined error of pointer dereference.
2018-04-23 13:13:36 +09:00
Tomoyuki Sahara f0e54df4fe sort method should not consume system stack. 2018-04-23 12:28:15 +09:00
Takeshi Watanabe 25c40c2f12 Fix undefined error of pointer dereference. 2018-04-23 12:06:13 +09:00
Yukihiro "Matz" Matsumoto 2213deeeaa Implement String#upto in Ruby.
Avoid using `mrb_yield` in C code. The function is not recommended.
Because it doesn't work well with fibers.
2018-04-21 22:30:54 +09:00
Yukihiro "Matz" Matsumoto 8b92ab5c7b CRuby2.6 stops deprecating String#lines with a block.
`String#lines` (with a block) is now implemented in Ruby.
2018-04-19 17:33:00 +09:00
Yukihiro "Matz" Matsumoto c79e81ebc3 String#lines with a block is deprecated style. 2018-04-19 09:07:11 +09:00
Yukihiro "Matz" Matsumoto 54905e98cf ary_dup() should not use `ary_replace(); fix #4004
Otherwise the duplicated object may have shared entities that
should not be modified in-line.
2018-04-18 17:30:33 +09:00
Yukihiro "Matz" Matsumoto 391e24210f A new function ary_from_values(); ref #4004 2018-04-18 17:29:45 +09:00
Yukihiro "Matz" Matsumoto c9275bbbed mrb_io_initialize_copy should not free existing fptr; fix #4005
When arguments `copy` and `orig` are the same object.
2018-04-18 17:27:41 +09:00
Yukihiro "Matz" Matsumoto 05db341ef5 mrb_dup() should fail if fd is a negative integer; ref #4005 2018-04-18 17:25:52 +09:00
Yukihiro "Matz" Matsumoto 135b4773e3 Turn off major GC mode before full GC; fix #4000 2018-04-18 00:18:03 +09:00
Yukihiro "Matz" Matsumoto 0866fa38b0 Avoid unnecessary object allocation (addrinfo) in _accept; ref #3999 2018-04-18 00:18:03 +09:00
Yukihiro "Matz" Matsumoto f7cf5812b1 Merge pull request #4003 from take-cheeze/int32_overflow
Fallback to float when compiled binary with 64bit compiler.
2018-04-17 23:08:36 +09:00
Takeshi Watanabe 87ef6aeb02 Fallback to float when caompiled binary with 64bit compiler.
closes #3997.
2018-04-17 22:59:07 +09:00
Yukihiro "Matz" Matsumoto 4880f6dc89 Socket.accept should have returned [fd, addr]; fix #3999 2018-04-17 17:21:49 +09:00
Yukihiro "Matz" Matsumoto 0e76faed8c Make ary_replace() to share entry buffers if possible. 2018-04-17 17:21:45 +09:00
Yukihiro "Matz" Matsumoto 5c15aa2f3b Make ary_concat() to replace the receiver when it is empty. 2018-04-17 12:34:30 +09:00
Yukihiro "Matz" Matsumoto c078783a5a Make ary_replace() to take struct RArray* argument. 2018-04-17 12:33:01 +09:00
Yukihiro "Matz" Matsumoto 66b1695ba9 Define SOL_IP and SOL_TCP; ref #3999 2018-04-17 12:01:32 +09:00
Yukihiro "Matz" Matsumoto d88191e7e7 Implement Array#__svalue in C. 2018-04-17 11:32:31 +09:00
Yukihiro "Matz" Matsumoto b51b21fc63 Fix use after free in File#initilialize_copy; fix #4001
The bug and the fix were reported by https://hackerone.com/pnoltof
2018-04-17 09:57:41 +09:00
Yukihiro "Matz" Matsumoto fabc460880 Invoke full GC when too many objects allocated during GC; fix #3998
When object allocation rate during incremental GC is too high, the
`gc->majorgc_old_threshold` becomes too big. This means major GC
start slower and old objects stay longer (and consume too much memory).
2018-04-14 06:18:49 +09:00
Yukihiro "Matz" Matsumoto 3b273243e6 Change MAJOR_GC_INC_RATIO to 120; ref #3998
Because 200% is consumes too much memory for some cases.
2018-04-14 06:13:00 +09:00
Yukihiro "Matz" Matsumoto fc85016a32 Remove DEFAULT_ from DEFAULT_MAJOR_GC_INC_RATIO; ref #3998
Because unlike other GC ratio constants, it's not a default value.
2018-04-14 06:12:12 +09:00
Yukihiro "Matz" Matsumoto c6736357a7 No longer need to insert write barriers for fibers.
Those barriers are inserted to fix #3699 but all living fibers are
marked from `mark_context()` anyway now.
2018-04-13 23:46:40 +09:00
Yukihiro "Matz" Matsumoto e3e87ee26a The #3871 fix caused wrong break from proc-closure error; fix #3996 2018-04-13 21:56:45 +09:00
Yukihiro "Matz" Matsumoto 4df0380f1e Add fallthrough comment to silence gcc warning. 2018-04-13 11:23:27 +09:00
Yukihiro "Matz" Matsumoto 4b09c7364e Silence gcc initializer warning. 2018-04-13 11:22:54 +09:00
Yukihiro "Matz" Matsumoto 1905091634 Check length of env stack before accessing upvar; fix #3995 2018-04-11 10:24:44 +09:00
Yukihiro "Matz" Matsumoto e340b17252 Merge pull request #3994 from kou/fix-windows-build-error-on-dll-build
Fix build error on Windows with MRB_BUILD_AS_DLL
2018-04-10 16:35:48 +09:00
Kouhei Sutou 0bc6c17490 Fix build error on Windows with MRB_BUILD_AS_DLL
Error message:

    C:\projects\groonga\vendor\mruby-source\include\mruby.h(1098): error C2375: 'mrb_gc_arena_save' : redefinition; different linkage [C:\projects\groonga\vendor\mruby\mruby.vcxproj]
              C:\projects\groonga\vendor\mruby-source\include\mruby.h(1083) : see declaration of 'mrb_gc_arena_save'
    C:\projects\groonga\vendor\mruby-source\include\mruby.h(1099): error C2375: 'mrb_gc_arena_restore' : redefinition; different linkage [C:\projects\groonga\vendor\mruby\mruby.vcxproj]
              C:\projects\groonga\vendor\mruby-source\include\mruby.h(1084) : see declaration of 'mrb_gc_arena_restore'
2018-04-10 15:24:41 +09:00
Yukihiro "Matz" Matsumoto e9ddb593f3 Merge pull request #3991 from take-cheeze/fix_eval_env_gc
Fix possible heap use after free in `mrb_exec_irep` and stack expanding.
2018-04-05 15:44:24 +09:00
Takeshi Watanabe 26e436e247 Adjust environment when mrb_exec_irep happened. 2018-04-05 11:53:30 +09:00
Yukihiro "Matz" Matsumoto f23c3cddc8 Merge pull request #3990 from mimaki/fix-mrdb-illegal-free
Fixed memory failure on mruby debugger.
2018-04-04 15:44:49 +09:00
mimaki e57d9e6047 Fixed test case for mruby ddebugger. 2018-04-04 14:07:59 +09:00
mimaki c1b9ec0c30 Fixed illegal memory operation on mruby debugger. 2018-04-04 13:20:40 +09:00
Yukihiro "Matz" Matsumoto 951ebbafdc Merge pull request #3988 from ksss/each_with_object
Refactoring for `Enumerable#each_with_object`
2018-03-28 14:50:41 +09:00
ksss e683c95e90 Refactoring for Enumerable#each_with_object
`each_with_object` arity should be 1
2018-03-27 23:09:10 +09:00
Yukihiro "Matz" Matsumoto a072015c4e Merge pull request #3987 from ksss/enum-lazy-zip
Reimplement `Enumerable#zip` with Enumerator
2018-03-27 13:53:37 +09:00
Yukihiro "Matz" Matsumoto 211d417b02 Merge pull request #3986 from ksss/enum-zip
Support block yielding for Enumerable#zip
2018-03-27 13:52:13 +09:00
ksss 3a22d113ee Reimplement Enumerable#zip with Enumerator
for fix some specs
- [passes each element of the result array to a block and return nil if a block is given](https://github.com/ruby/spec/blob/a585ec35d185435e5c11f371ba4ed2a29d8817bd/core/enumerable/zip_spec.rb#L11-L17)
- [converts arguments to arrays using #to_ary](https://github.com/ruby/spec/blob/a585ec35d185435e5c11f371ba4ed2a29d8817bd/core/enumerable/zip_spec.rb#L23-L27)
- [converts arguments to enums using #to_enum](https://github.com/ruby/spec/blob/a585ec35d185435e5c11f371ba4ed2a29d8817bd/core/enumerable/zip_spec.rb#L29-L34)
- [gathers whole arrays as elements when each yields multiple](https://github.com/ruby/spec/blob/a585ec35d185435e5c11f371ba4ed2a29d8817bd/core/enumerable/zip_spec.rb#L36-L39)
2018-03-27 10:53:33 +09:00
ksss b1c8fad94a Should raise TypeError instead of NoMethodError 2018-03-27 10:52:32 +09:00
ksss 5a7ce01f12 Support block yielding for Enumerable#zip 2018-03-27 10:51:59 +09:00
Yukihiro "Matz" Matsumoto 203b071ca2 Merge pull request #3985 from take-cheeze/revert_ai_protocol
Revert #3984 .
2018-03-26 11:07:50 +09:00
Takeshi Watanabe baff7c63ee Revert #3984 . 2018-03-26 11:02:05 +09:00
Yukihiro "Matz" Matsumoto 0da7b4454f Merge pull request #3984 from take-cheeze/merge_socket
Catch up with latest mruby-socket.
2018-03-25 22:25:15 +09:00
Takeshi Watanabe 306cb99b10 Merge commit '36d016afd663d34607c843d03371bedb71efa34e' 2018-03-25 21:10:11 +09:00
Yukihiro "Matz" Matsumoto 4b5c21cf3b Merge pull request #3982 from take-cheeze/fix_str_cmp
Return nil if type differ in `String#<=>`.
2018-03-24 16:27:22 +09:00
Takeshi Watanabe 77a3863a3d Return nil if type differ in String#<=>. 2018-03-24 16:18:44 +09:00
Yukihiro "Matz" Matsumoto 8e8bc9e40b Merge pull request #3974 from take-cheeze/repo_path
Add `:path` option for git repository.
2018-03-22 17:06:31 +09:00
Takeshi Watanabe 4940ddb9fc Add :path option for git repository. 2018-03-22 12:42:41 +09:00
Yukihiro "Matz" Matsumoto fb78f10893 Need to keep block argument in mrb_exec_irep; fix #3973 2018-03-22 01:01:18 +09:00
Yukihiro "Matz" Matsumoto c8538be471 Needed to set ci->proc in OP_SUPER; fix #3966 2018-03-20 23:16:38 +09:00
Yukihiro "Matz" Matsumoto a85bc19f35 Merge pull request #3972 from take-cheeze/fix_ary_set_len_assert
Set array length after expanding capacity.
2018-03-20 23:15:37 +09:00
Takeshi Watanabe 1218ff5d47 Set array length after expanding capacity. 2018-03-19 21:40:17 +09:00
Tomoyuki Sahara 36d016afd6 Set protocol of AddrInfo
backport https://github.com/mruby/mruby/pull/3891
2018-03-16 17:05:37 +09:00
Yukihiro "Matz" Matsumoto 1a8483f17e __sort_sub__ is a method defined in Array; fix #3970
Reorganize `__sort_sub__` arguments.
2018-03-16 14:49:51 +09:00
Yukihiro "Matz" Matsumoto 1abff3f2ab Merge pull request #3957 from take-cheeze/fix_io_read
Pass same mode parameter to `IO.sysopen` and `IO.open` in `IO.read`.
2018-03-16 14:34:44 +09:00
Yukihiro "Matz" Matsumoto ceeb8c05df Needed to pass sort block. 2018-03-16 08:20:43 +09:00
Yukihiro "Matz" Matsumoto ec390e8f1b Update mrb_get_args reference comment; ref #3963 2018-03-16 08:18:52 +09:00
Yukihiro "Matz" Matsumoto 6c84e6e4a5 Merge pull request #3969 from hfm/patch-1
Fix tinytypo
2018-03-16 08:18:38 +09:00
Okumura Takahiro 0664c452ee Fix tinytypo 2018-03-16 00:19:09 +09:00
Yukihiro "Matz" Matsumoto 59dabb38ab Merge pull request #3963 from dearblue/forced-block-arguments
Give me block by mrb_get_args() (forced block arguments)
2018-03-12 22:14:08 +09:00
Yukihiro "Matz" Matsumoto 843053c97c Merge pull request #3965 from take-cheeze/patch-1
Add same fix as #3964 to lib/mruby/gem.rb .
2018-03-05 10:51:32 +09:00
Takeshi Watanabe e8cea2accf Add same fix as #3964 to lib/mruby/gem.rb . 2018-03-05 10:38:44 +09:00
Yukihiro "Matz" Matsumoto e924501693 Merge pull request #3964 from take-cheeze/patch-1
Close `mrb_state` before error exit.
2018-03-05 10:26:02 +09:00
Takeshi Watanabe 0f5cf385b8 Close mrb_state before exit. 2018-03-05 10:13:55 +09:00
Takeshi Watanabe 94aebe3137 Close on exception too. 2018-03-05 10:12:33 +09:00
dearblue a5ac49de30 fix && to &! in mrb_get_args() 2018-03-04 23:48:45 +09:00
dearblue 2ce6d23db6 add forced block arguments feature to mrb_get_args 2018-03-04 22:23:47 +09:00
Yukihiro "Matz" Matsumoto 10f28fc82d Add mrb_fiber_alive_p to C API. 2018-03-02 10:14:36 +09:00
Yukihiro "Matz" Matsumoto a95b6d34aa Round up the dstlen value; fix #3949
The fix was proposed by https://hackerone.com/aerodudrizzt
2018-03-02 10:14:36 +09:00
Takeshi Watanabe 92641248fa Pass same mode parameter to IO.sysopen and IO.open in IO.read. 2018-02-23 20:42:13 +09:00
Yukihiro "Matz" Matsumoto 097bfdcac5 Merge pull request #3953 from take-cheeze/fix_cross_test_runner_verbose
Add verbose flag to cross test runner too. [experimental]
2018-02-17 18:34:46 +09:00
Takeshi Watanabe 5d43a93046 Add verbose flag to cross test runner too. 2018-02-16 23:44:58 +09:00
Yukihiro "Matz" Matsumoto 75c1fccd08 Check if to_int returns fixnum value; fix #3946 2018-02-13 09:12:39 +09:00
Yukihiro "Matz" Matsumoto ef1a0e6358 Check sizeof(base64_dec_tab) in base64 encoding; fix #3947
The issue (and the fix) reported by https://hackerone.com/aerodudrizzt
2018-02-13 08:55:24 +09:00
Yukihiro "Matz" Matsumoto 7483753094 Check negative offset in pack method; fix #3944 2018-02-13 08:48:23 +09:00
Yukihiro "Matz" Matsumoto c5ec37a8ab Fixed wrong offset in pack_x function; ref #3944 2018-02-13 08:47:33 +09:00
Yukihiro "Matz" Matsumoto 00845ea908 Use 'mrb_raise instead of mrb_raisef` when no argument given. 2018-02-13 08:35:01 +09:00
Yukihiro "Matz" Matsumoto 1d55260423 String#inspect to use hexadecimal, not octal to print unprintable. 2018-02-12 22:56:24 +09:00
Yukihiro "Matz" Matsumoto b9523d0e06 Merge pull request #3945 from take-cheeze/fix_dep_core_gems
Fix core dependencies resolving in dependencies gems.
2018-02-12 22:41:31 +09:00
Yukihiro "Matz" Matsumoto 2c84d94854 Merge pull request #3915 from llothar/master
Uncommented the Visual Studio version check
2018-02-12 09:32:35 +09:00
Yukihiro "Matz" Matsumoto 4790f28d62 Resolve conflicts between labels and conditional ternary; fix #3931 2018-02-12 09:28:09 +09:00
Takeshi Watanabe 3dc8634d86 Fix core dependencies resolving in dependencies gems. 2018-02-10 23:23:57 +09:00
Yukihiro "Matz" Matsumoto 7a116f27e4 Need to determine IS_LABEL_POSSIBLE() properly.
Otherwise, `{"a": 1}` will cause `SyntaxError`.
2018-02-10 17:17:36 +09:00
Yukihiro "Matz" Matsumoto 79cfa377e1 Check negative count in pack_x and unpack_x; fix #3944 2018-02-10 16:59:14 +09:00
Yukihiro "Matz" Matsumoto 4f31bcbc84 Add mruby-io and mruby-pack to default.gembox 2018-02-10 16:58:59 +09:00
Yukihiro "Matz" Matsumoto 4c1494d58f Check if mruby-pack template count overflow; fix #3942 2018-02-09 12:55:13 +09:00
Yukihiro "Matz" Matsumoto b43c146455 Check ensure proc is NULL before calling; fix #3943 2018-02-09 12:34:54 +09:00
Yukihiro "Matz" Matsumoto 4c18e37f71 Merge pull request #3941 from matsumotory/patch-1
Depend mruby-io and mruby-pack in mruby core
2018-02-04 00:01:03 +09:00
MATSUMOTO, Ryosuke 6ae4fb707a Depend mruby-io and mruby-pack in mruby core 2018-02-03 14:57:12 +09:00
Yukihiro "Matz" Matsumoto e02cbb4426 Need fcntl.h and sys/stat.h as well for _open; ref #3938 2018-02-02 14:58:09 +09:00
Yukihiro "Matz" Matsumoto c9fa7b1919 Need to include io.h anyway for _WIN32/64; ref #3938 2018-02-02 14:18:25 +09:00
Yukihiro "Matz" Matsumoto cafe6ce4f4 Merge pull request #3940 from take-cheeze/fix_proc_ctx_access
Fix possible memory access error.
2018-02-02 14:16:10 +09:00
Takeshi Watanabe 3c18ec27e9 Fix possible memory access error. 2018-02-02 13:30:32 +09:00
Yukihiro "Matz" Matsumoto 6f1e1777cb Merge pull request #3938 from mattn/include-io
include io.h on mingw
2018-01-31 12:32:23 +09:00
Yasuhiro Matsumoto 0e0dad7697 include io.h on mingw 2018-01-31 12:18:35 +09:00
Yukihiro "Matz" Matsumoto f7ff2d0ee3 Define compatibility only for _MSC_VER; ref #3923
Suggested by @mattn.
2018-01-31 12:10:51 +09:00
Yukihiro "Matz" Matsumoto 1ad2dd6187 Merge pull request #3923 from ksss/tempnam
Shouldn't use tempnam
2018-01-31 11:58:49 +09:00
ksss e422ba0bff Use mkstemp instead of tempnam 2018-01-31 11:34:29 +09:00
Yukihiro "Matz" Matsumoto 55431b4cef Need not to pop callinfo on OP_STOP. 2018-01-30 22:55:58 +09:00
Yukihiro "Matz" Matsumoto 43594843d7 Merge pull request #3937 from mattn/file-mtime
add File#mtime
2018-01-30 21:39:08 +09:00
Yasuhiro Matsumoto f4f006ba40 add File#mtime 2018-01-30 16:02:00 +09:00
Yukihiro "Matz" Matsumoto 3498a787ba Merge pull request #3936 from ken-mu/uint
mruby-time: support time_t is uint
2018-01-30 12:42:49 +09:00
ken-mu a1b71b64b3 mruby-time: remove ifdef for mktime error handling 2018-01-29 09:43:43 +00:00
ken-mu 6a2c0c6e2a mruby-time: support time_t is uint 2018-01-28 03:03:20 +00:00
Yukihiro "Matz" Matsumoto 83f2654bac Do not use MRB_METHOD_TABLE_INLINE by default; fix #3924
It was default on Linux. Abandoned for 2 reasons:

* some cross-platform compiler defines `__linux__` even on bare metal
  environment (RTL8196 (MIPS big endian soc) for example).

* some compilers do not align functions pointers so that we need to
  specify `-falign-functions=n` (where n>1). It's not suitable for
  default configuration.

By our measurement, `mrbtest` consumes 400KB less memory. So if your
target machine is memory tight, add the following command-line options
to `GCC` (unfortunately `clang` does not support `-falign-functions`).

`-falign-functions=2 -DMRB_METHOD_TABLE_INLINE`
2018-01-25 14:22:01 +09:00
Yukihiro "Matz" Matsumoto ec1a5af719 Use LSB not MSB for MRB_METHOD_TABLE_INLINE; ref #3924 2018-01-25 14:02:38 +09:00
Yukihiro "Matz" Matsumoto d895861a30 Check arena_idx before accessing; fix #3934 2018-01-25 12:30:10 +09:00
Yukihiro "Matz" Matsumoto 0e93f1ff12 Merge pull request #3921 from ksss/cloexec
Should be true for close_on_exec flag
2018-01-24 22:04:05 +09:00
Yukihiro "Matz" Matsumoto dfb56074d6 Add big_endian and little_endian methods to CrossBuild; ref #3922
When your target machine is big endian, specify as following in the
`build_config.rb`:

```ruby
MRuby::CrossBuild.new('32bit') do |conf|
  toolchain :gcc

  conf.big_endian
end
```
2018-01-24 21:42:25 +09:00
Yukihiro "Matz" Matsumoto 3ff56a8e55 Time.new(1969,12,31,23,59,59) may or may not faile; ref #3932
On some platform and timezone it is a valid time spec.
2018-01-24 21:42:25 +09:00
Yukihiro "Matz" Matsumoto f8ab3c1eeb Merge pull request #3932 from ken-mu/timegm
mruby-time: Fix mruby specific timegm() cannot return minus
2018-01-21 21:10:01 +09:00
ken-mu d398cd47d7 mruby-time: remove test case less than Dec 31 23:59:58 1969 2018-01-21 02:47:17 +00:00
ken-mu a1f36316d2 mruby-time: Fix mruby specific timegm() cannot return minus 2018-01-20 13:09:58 +00:00
Yukihiro "Matz" Matsumoto e5fb21b6d2 Detect cyclic link of class path references; fix #3926 2018-01-17 09:41:26 +09:00
Yukihiro "Matz" Matsumoto 3ae621fcb3 Typo fixed. 2018-01-17 09:38:41 +09:00
Yukihiro "Matz" Matsumoto ec63b1a0e0 Limit size of iseq buffer; fix #3927 2018-01-16 15:17:56 +09:00
Yukihiro "Matz" Matsumoto ca837b1a24 Allow -> do rescue; end as well as proc do rescue; end [Ruby2.6] 2018-01-16 15:08:51 +09:00
Yukihiro "Matz" Matsumoto 03e88b9ae0 Merge pull request #3930 from mruby/stable
Set the mruby-1.4.0 release date to `2018-1-16`.
2018-01-16 15:07:53 +09:00
Hiroshi Mimaki 58fb6f421a Set the mruby-1.4.0 release date to 2018-1-16. 2018-01-16 10:15:19 +09:00
ksss dc9c40f72d Remove trailing space 2018-01-14 22:40:46 +09:00
ksss 540efd3730 IO#close_on_exec? is not supported on MinGW 2018-01-14 22:40:46 +09:00
ksss e5e9d03482 Should be true for close_on_exec flag 2018-01-14 22:40:45 +09:00
Yukihiro "Matz" Matsumoto 623436276e Merge pull request #3916 from mimaki/mruby-socket-cygwin-test
Passed mruby-test on Cygwin.
2017-12-26 15:51:18 +09:00
Hiroshi Mimaki f55df0da7b addrinfo.ai_protocol was not set on Cygwin. 2017-12-26 11:12:49 +09:00
Hiroshi Mimaki bce811a53a Disabled UNIXSocket test on Cygwin 2017-12-26 11:05:28 +09:00
Yukihiro "Matz" Matsumoto 6b09692684 Add `Integer#{allbits?,anybits?,nobits?}. [Ruby2.5]
In mruby, those methods are defined in `Integral` module.
2017-12-26 09:44:39 +09:00
Yukihiro "Matz" Matsumoto 3d7141b7fe Move Intefer#chr to Integral#chr.
Since mruby mixes `Integer` and `Float`, integer operations have
been moved to `Integral` module.
2017-12-26 09:42:34 +09:00
Yukihiro "Matz" Matsumoto ad17ba0e11 KeyError from Hash#fetch should inspect key.
To distinguish string keys and symbol keys.
2017-12-25 23:52:40 +09:00
Yukihiro "Matz" Matsumoto e4a9b4a3ad `Enumerable#{one?,none?,all?,any?} to take pattern argument [Ruby2.5] 2017-12-25 23:43:43 +09:00
Yukihiro "Matz" Matsumoto 421819dc2c Add Hash#slice [Ruby 2.5] 2017-12-25 23:43:37 +09:00
Yukihiro "Matz" Matsumoto df68a3345d assert_equal() takes result as the first argument 2017-12-25 15:39:45 +09:00
Lothar Scholz a9d0d90f74 Removed the Visual Studio Version Check because it does not
work with internationalized versions of Visual Studio. It will capture
the returned string in the local codepage encoding and make ruby exits
with an invalid UTF8 error message.

Also "Version" might be translated and not appear in the output.
2017-12-24 06:28:38 +01:00
Yukihiro "Matz" Matsumoto 2a5545cc25 Update Kernel#method_missing tests for new NoMethodError message.
Also removed tests that depends on implementation details of the default
`method_missing` behavior.
2017-12-23 15:18:13 +09:00
Yukihiro "Matz" Matsumoto 6999e45742 Do not include object string representation in NoMethodError message.
This information is not mandatory but causes a lot of problems in the
past due to infinite recursion by redefining `to_str`, `inspect` etc.
2017-12-23 15:15:03 +09:00
Yukihiro "Matz" Matsumoto ca0f32a208 super should raise TypeError when the receiver is switched; fix #3911
The receiver can be switched using `#instance_eval` etc.
2017-12-23 11:14:12 +09:00
Yukihiro "Matz" Matsumoto aa8786f79c Do not initialize a local variable soon to be assigned. 2017-12-23 11:14:12 +09:00
Yukihiro "Matz" Matsumoto 7e520838b3 Avoid infinite recursion in method_missing; ref #3908 2017-12-23 11:13:27 +09:00
Yukihiro "Matz" Matsumoto 44b4f69fce May need more stack space in mrb_funcall_with_block; fix #3908 2017-12-23 10:01:30 +09:00
Yukihiro "Matz" Matsumoto 8d7e95282c Add #module_exec and #class_exec in mruby-class-ext gem. 2017-12-23 10:01:30 +09:00
Yukihiro "Matz" Matsumoto 7fbbd7ab9f Should not overwrite ci->target_class in mrb_exec_irep().
For example, the following code behaved wrong:

```ruby
Object.instance_exec(1,2,3){|*a|
  def foo
    42
  end
}
p foo()
```
2017-12-23 10:01:30 +09:00
Yukihiro "Matz" Matsumoto 7990bb7fa7 Merge pull request #3913 from llothar/master
Make source compilable with C++17
2017-12-23 09:44:00 +09:00
Lothar Scholz 06f90a3b45 Make source compilable with C++17
Changes applied:

- Removing "register" keyword
- Fixing const pointer to pointer assignments
- Adding type casts to rb_malloc calls
2017-12-23 01:10:43 +01:00
Yukihiro "Matz" Matsumoto 100f0e6759 Do not need to take target_class from the upper proc.
Since it is already set in `mrb_proc_new()`.
2017-12-20 19:37:26 +09:00
Yukihiro "Matz" Matsumoto 73b05f0130 Should not overwrite MRB_PROC_TARGET_CLASS(p) if p has env; fix #3905 2017-12-20 19:37:26 +09:00
Yukihiro "Matz" Matsumoto 165e7b181b Fixed method look-up for method_missing in OP_SUPER; ref #3905
Method look-up for `OP_SUPER` should start from the superclass of
the `target_class` but if it fails, the look-up for `method_missing`
should start from the class of the receiver.

The following code explains the case:
```ruby
class Bar
  def foo
    super
  end
end

class Foo<Bar
  def method_missing(mid, *)
    p mid
  end
end
```
Foo.new.foo
2017-12-20 19:37:26 +09:00
Yukihiro "Matz" Matsumoto d0f60182af The superclass info should be taken from `TARGET_CLASS(ci->proc).
Not from `ci->target_class` that may be switched using `class_eval` etc.
fix #3899, fix #3906

We found out there is a mruby specific limitation that `super` may be
screwed up when a method is defined in a module and `super` is called
in the block with the target class switched (for example, `super` in
`class_eval` block).  Now we raise `RuntimeError` for such cases.

The following code works in CRuby but not in mruby.
```
module M
  def foo
    "aaa".singleton_class.class_eval{super 2}
  end
end
class Foo
  def foo(*); end
end
class Bar<Foo
  include M
end
Bar.new.foo
```
2017-12-20 10:34:54 +09:00
Yukihiro "Matz" Matsumoto d9049c10fa Merge pull request #3904 from ksss/mruby-method
Add mruby-method
2017-12-18 11:59:36 +09:00
Yukihiro "Matz" Matsumoto bba6c9a1ce Fix descriptor leakage; ref #3903 2017-12-18 11:55:12 +09:00
Yukihiro "Matz" Matsumoto e5056d058a Fix fptr leakage; ref #3903 2017-12-18 11:55:12 +09:00
Yukihiro "Matz" Matsumoto 83d02bcd5a Use _dup2 instead of dup2 on Windows; ref #3903 2017-12-18 11:55:12 +09:00
Yukihiro "Matz" Matsumoto 5e22e8e350 open on Windows takes int 3rd argument instead of mode_t. 2017-12-18 11:15:27 +09:00
ksss c0914dbb65 mruby/data.h doesn't need 2017-12-18 11:11:44 +09:00
Yukihiro "Matz" Matsumoto b4dcb8f286 Use _dup instead of dup on Windows; ref #3903 2017-12-18 11:10:49 +09:00
ksss 615f296fcf Clean up some files and docs 2017-12-18 11:10:10 +09:00
ksss ae786b18d5 Shouldn't use alloca 2017-12-18 11:05:55 +09:00
Yukihiro "Matz" Matsumoto a510564d6d Merge pull request #3903 from ksss/io-dup
Implement IO#initialize_copy
2017-12-18 10:58:12 +09:00
ksss b83ff8ccd8 Add mrbgems/mruby-method
from https://github.com/ksss/mruby-method/commit/0837a0b507a5b4cdf8a1f1039ee371cee4e3b7fb
2017-12-18 10:54:37 +09:00
ksss 35185e69bf Implement IO#initialize_copy 2017-12-17 18:02:37 +09:00
Yukihiro "Matz" Matsumoto ddb1aae41d Need to set ci->proc before calling methods; fix #3902 2017-12-16 09:33:37 +09:00
Yukihiro "Matz" Matsumoto 03614ed918 Need to clear exception handler on return; fix #3898 2017-12-16 09:17:07 +09:00
Yukihiro "Matz" Matsumoto 05129ab9b3 Check if destinations are too distant; fix #3900 fix #3901 2017-12-15 17:57:45 +09:00
Yukihiro "Matz" Matsumoto 7ecb96a00a Merge pull request #3897 from mimaki/initialize-is_socket
Initialized mrb_io.is_socket
2017-12-14 13:58:27 +09:00
Hiroshi Mimaki 41039524a9 Initialized mrb_io.is_socket 2017-12-14 12:36:25 +09:00
Yukihiro "Matz" Matsumoto 5b304c156c On Windows, _S_IREAD and _S_IWRITE is defined in sys/stat.h. 2017-12-14 01:19:44 +09:00
Yukihiro "Matz" Matsumoto 7ac39333b5 Use _open and _close on Windows. 2017-12-14 01:19:21 +09:00
Yukihiro "Matz" Matsumoto ebf49932c7 Merge pull request #3895 from mattn/fix-mkstemp
fix mkstemp implementation for MSVC
2017-12-14 00:46:19 +09:00
Yasuhiro Matsumoto e7e5db51de fix mkstemp implementation for MSVC 2017-12-14 00:43:38 +09:00
Yukihiro "Matz" Matsumoto f0379c8c45 Merge pull request #3892 from mimaki/ipproto-winsock
Use IPPROTO enum values on WinSock.
2017-12-14 00:09:45 +09:00
Yukihiro "Matz" Matsumoto 16e473caad Rename BasicSocket#is_socket= to #_is_socket; ref #3878 2017-12-14 00:07:42 +09:00
Yukihiro "Matz" Matsumoto 69ad12de06 Exclude UNIXSocket tests again; ref #3878 2017-12-14 00:05:23 +09:00
Takeshi Watanabe d2163d13a8 Declare super class in socket.rb. 2017-12-14 00:05:23 +09:00
Takeshi Watanabe 949bf6ca43 Fix socket closing by using closesocket API in windows instead. 2017-12-14 00:05:23 +09:00
Yukihiro "Matz" Matsumoto 2300c9f737 Merge pull request #3893 from mimaki/add-mrbgem-summary
Added mrbgem's summary.
2017-12-14 00:00:10 +09:00
Yukihiro "Matz" Matsumoto dc5de38414 Merge pull request #3894 from mattn/mirb-locale
fix locale message in mirb
2017-12-13 23:11:49 +09:00
Yukihiro "Matz" Matsumoto 1a150a6e48 Merge pull request #3891 from mimaki/set-addrinfo-protocol
Set protocol of AddrInfo
2017-12-13 23:00:25 +09:00
Yasuhiro Matsumoto 0ab9ac6b22 fix locale in mirb 2017-12-13 22:28:18 +09:00
Hiroshi Mimaki 584e4e413a Added mrbgem's summary. 2017-12-13 16:05:06 +09:00
Hiroshi Mimaki 9fac1a3f8b Use IPPROTO enum values on WinSock. 2017-12-13 15:58:23 +09:00
Hiroshi Mimaki 398da99d05 Set protocol of AddrInfo 2017-12-13 14:44:13 +09:00
Yukihiro "Matz" Matsumoto 55fced30cd Use _tempnam instead of tempnam on Windows. 2017-12-13 14:17:49 +09:00
Yukihiro "Matz" Matsumoto a3925f3dec Merge pull request #3889 from mattn/fix-crash
fix crash bug on Windows
2017-12-13 14:10:44 +09:00
Yukihiro "Matz" Matsumoto aec65f2605 Merge pull request #3890 from mimaki/mruby-socket-windows-test
Skip tests on Windows platform
2017-12-13 13:59:28 +09:00
Hiroshi Mimaki 4353623b72 Skip tests on Windows platform 2017-12-13 13:02:59 +09:00
Yasuhiro Matsumoto 6123d653b7 fix crash bug on Windows 2017-12-13 12:48:26 +09:00
Yukihiro "Matz" Matsumoto fa33bd86a8 Remove VC++ compiler warnings. 2017-12-13 11:39:32 +09:00
Yukihiro "Matz" Matsumoto 7d940e3682 Merge pull request #3888 from mattn/fix-locale
fix path locales
2017-12-13 10:24:52 +09:00
Yasuhiro Matsumoto 16c2ac2588 fix path locales 2017-12-13 10:12:59 +09:00
Yukihiro "Matz" Matsumoto e14387440e Skip test/t/float.rb tests; ref #3827 2017-12-13 08:45:46 +09:00
Yukihiro "Matz" Matsumoto 11b6696ce2 Retrieve operands at the beginning of OP_SCLASS. 2017-12-13 08:43:15 +09:00
Yukihiro "Matz" Matsumoto e647b16d1d Should not define Float class in mrblib/00class.rb; ref #3828
Unless it is defined in `numeric.c`.
2017-12-13 08:42:07 +09:00
Yukihiro "Matz" Matsumoto ad06781107 Fixed wrong MRB_WITHOUT_FLOAT condition; ref #3827 2017-12-13 08:38:34 +09:00
Yukihiro "Matz" Matsumoto c66978521d Reduce VC++ type mismatch warnings. 2017-12-13 08:10:35 +09:00
Yukihiro "Matz" Matsumoto 5a5adafabf Merge pull request #3886 from mattn/io-windows
implement popen/flock on Windows
2017-12-13 07:56:24 +09:00
Yasuhiro Matsumoto b07269584c fix build for MSVC 2017-12-13 00:21:30 +09:00
Yasuhiro Matsumoto e0e23b1765 close file descriptors 2017-12-13 00:18:02 +09:00
Yasuhiro Matsumoto 7c8c9f9532 mingw have mkstemp 2017-12-13 00:08:10 +09:00
Yasuhiro Matsumoto 7ff907f680 fix test 2017-12-13 00:07:51 +09:00
Yasuhiro Matsumoto f1ea7a31c0 implement flock on Windows 2017-12-12 23:21:41 +09:00
Yasuhiro Matsumoto df2c3771f8 fix compilation error 2017-12-12 22:39:21 +09:00
Yasuhiro Matsumoto f6f8bb2416 fix compilation error 2017-12-12 22:39:20 +09:00
Yasuhiro Matsumoto 06ec17de60 add definition for pid_t on MSVC 2017-12-12 22:39:19 +09:00
Yasuhiro Matsumoto d549603a8a close handle 2017-12-12 22:39:18 +09:00
Yasuhiro Matsumoto b8ca0b7cd8 implement popen on Windows 2017-12-12 22:39:17 +09:00
Yukihiro "Matz" Matsumoto c863e0dac8 Merge pull request #3885 from Shokuji/cygwin_mruby_io_test
fixed mruby-io so that the test passes on cygwin
2017-12-12 22:34:10 +09:00
Yukihiro "Matz" Matsumoto c6ea948030 Revert "Update .travis.yml to use gcc-6"
This change caused Travis CI errors on OSX.  This reverts
commit c76631d445.
2017-12-12 22:31:14 +09:00
Yukihiro "Matz" Matsumoto 346ebfb0ea Merge pull request #3882 from mattn/fix-filename
use filename in locale
2017-12-12 22:27:25 +09:00
Yukihiro "Matz" Matsumoto 25bee356b1 Merge pull request #3884 from mimaki/mruby-io-test-on-windows
Fixed mruby-io test failure on Windows platform.
2017-12-12 22:21:08 +09:00
Yasuhiro Matsumoto 17cd7a65e7 fix wrong variable name 2017-12-12 18:52:41 +09:00
Yasuhiro Matsumoto bceb6640fa fix compilation error 2017-12-12 18:52:41 +09:00
Yasuhiro Matsumoto 977f79478f use filename in locale 2017-12-12 18:52:40 +09:00
Yukihiro "Matz" Matsumoto bbb0882343 Modifying frozen objects will raise FrozenError.
`FrozenError` is a subclass of `RuntimeError` which used to be
raised.  [Ruby2.5]
2017-12-12 18:41:18 +09:00
Yukihiro "Matz" Matsumoto d4ff92bcf6 Do not use FIXABLE when mrb_int is big enough. 2017-12-12 17:45:15 +09:00
Yukihiro "Matz" Matsumoto 3d98fa2e46 Reduce type mismatch warnings in pack.c. 2017-12-12 17:45:15 +09:00
Yukihiro "Matz" Matsumoto a5b8603aa2 Winsock uses int where UNIX uses size_t. 2017-12-12 17:45:15 +09:00
Yukihiro "Matz" Matsumoto a9e434e69a Merge pull request #3883 from mattn/fix-ssize_t
fix build on mingw
2017-12-12 17:31:26 +09:00
窪山 翔士 e71a6a7b2c fixed mruby-io so that the test passes on cygwin 2017-12-12 17:29:05 +09:00
Hiroshi Mimaki 5ef8f18e9b Fixed mruby-io test failure on Windows platform. 2017-12-12 16:57:13 +09:00
Yasuhiro Matsumoto 99328695e3 fix build on mingw 2017-12-12 16:47:34 +09:00
Yukihiro "Matz" Matsumoto 9c0426c990 Winsock does not provide ssize_t; Use int instead. 2017-12-12 09:52:39 +09:00
Yukihiro "Matz" Matsumoto 2db06c471e Revert "Update .travis.yml"
This reverts commit f73ac4112f.
This change caused Travis errors.
2017-12-12 09:49:26 +09:00
Yukihiro "Matz" Matsumoto 08a508cbee Fixed the mixture of int and long in mruby-pack. 2017-12-12 09:48:53 +09:00
Yukihiro "Matz" Matsumoto 5bf60b4837 Merge pull request #3881 from mame/mrb_without_float-for-mruby-io-and-mruby-pack
Support MRB_WITHOUT_FLOAT to mruby-io and mruby-pack
2017-12-12 07:49:30 +09:00
Yusuke Endoh d96b2c9a76 Support MRB_WITHOUT_FLOAT to mruby-io and mruby-pack 2017-12-12 00:47:56 +09:00
Yukihiro "Matz" Matsumoto 85fc9b88d0 Merge pull request #3880 from mruby/matz-patch-1
Update .travis.yml
2017-12-11 23:23:10 +09:00
Yukihiro "Matz" Matsumoto f73ac4112f Update .travis.yml 2017-12-11 22:17:30 +09:00
Yukihiro "Matz" Matsumoto 0e452a75ac Update .travis.yml 2017-12-11 19:36:52 +09:00
Yukihiro "Matz" Matsumoto b763759972 Reduce VC++ compiler warnings. 2017-12-11 17:22:46 +09:00
Yukihiro "Matz" Matsumoto c76631d445 Update .travis.yml to use gcc-6
The patch is created by @take_cheese in #3872
2017-12-11 17:19:49 +09:00
Yukihiro "Matz" Matsumoto 6d42195fb2 Add enable_sanitizer method for clang and gcc.
The patch is created by @take_cheese in #3872
2017-12-11 17:14:50 +09:00
Yukihiro "Matz" Matsumoto 274884abe5 Reduce VC++ compiler warnings. 2017-12-09 16:14:12 +09:00
Yukihiro "Matz" Matsumoto 761218e70b Skip socket tests on Windows platform.
Some test may be OK but we skip everything as a starting point.
2017-12-09 14:22:53 +09:00
Yukihiro "Matz" Matsumoto b103fa229d File.symlink may not be implemented on some platforms; ref #3877 2017-12-09 14:22:03 +09:00
Yukihiro "Matz" Matsumoto bda273f35d Merge pull request #3877 from bamchoh/patch-3
Skip "File.readlink fails" test on MSVC
2017-12-09 14:16:20 +09:00
Yukihiro "Matz" Matsumoto 6bc38f4637 Merge pull request #3876 from bamchoh/patch-2
Use same format between Fail and Skip
2017-12-09 13:15:10 +09:00
bamchoh 0ded91c806 Skip "File.readlink fails" test on MSVC
When MSVC, "File.readlink fails with non-symlink" test was failed even if raising NotImplementedError
2017-12-09 03:27:05 +09:00
bamchoh 81dc383291 Use same format between Fail and Skip
We can see gem name in skip message by this fix
2017-12-09 02:12:37 +09:00
Yukihiro "Matz" Matsumoto 550c878216 Use RL_READLINE_VERSION to determine rl_free existence; fix #3875 2017-12-08 21:49:12 +09:00
Yukihiro "Matz" Matsumoto e17092debd Merge pull request #3874 from mimaki/fix-mingw-compile-error
Fixed compile error of `mruby-io` gem on MinGW.
2017-12-08 14:34:10 +09:00
Yukihiro "Matz" Matsumoto c47a1984b4 Merge pull request #3873 from take-cheeze/fix_socket_test_leak
Fix memory leak found by leak sanitizer.
2017-12-08 14:33:49 +09:00
Hiroshi Mimaki 7f3bda5653 Fixed compile error of mruby-io gem on MinGW. 2017-12-08 12:58:26 +09:00
Takeshi Watanabe 5de7dc2948 Fix memory leak found by leak sanitizer. 2017-12-08 12:10:28 +09:00
Yukihiro "Matz" Matsumoto 83065df67a Reduce compiler warnings from mruby-io gem. 2017-12-08 10:07:41 +09:00
Yukihiro "Matz" Matsumoto f9d1d72217 Avoid VC++ reserved word template. 2017-12-08 09:55:55 +09:00
Yukihiro "Matz" Matsumoto 36a0b864ba Reduce VC++ compiler warnings. 2017-12-08 09:50:02 +09:00
Yukihiro "Matz" Matsumoto f1207573bd Uninitialized value returned. 2017-12-08 09:50:02 +09:00
Yukihiro "Matz" Matsumoto 6ebcb7417a AppVeyor compile errors resolution. 2017-12-08 09:37:50 +09:00
Yukihiro "Matz" Matsumoto 9df7bceb15 AppVeyor compiler does not proved some POSIX functions.
- `mode_t` by `int`
- `umask` by `_umask`
- `rmdir` by `_rmdir`
- `mkstemp` and `mkdtemp` by using `_mktemp`
2017-12-08 09:19:59 +09:00
Yukihiro "Matz" Matsumoto b724e06cf2 Avoid uninitialized local variables in mruby-pack. 2017-12-07 20:28:30 +09:00
Yukihiro "Matz" Matsumoto bc9e3e6fd0 Add type cast to readline(2) return value. 2017-12-07 20:26:34 +09:00
Yukihiro "Matz" Matsumoto 764a568aa4 Remove unused variable usock from mruby-socket/src/socket.c. 2017-12-07 20:25:40 +09:00
Yukihiro "Matz" Matsumoto ff1194c134 fixup! Fix type casting errors when mruby-socket compiled by C++. 2017-12-07 20:24:13 +09:00
Yukihiro "Matz" Matsumoto a5412d48fd Add 'mrbgems/mruby-pack/' from commit '383a9c79e191d524a9a2b4107cc5043ecbf6190b'
git-subtree-dir: mrbgems/mruby-pack
git-subtree-mainline: 842e6945f2
git-subtree-split: 383a9c79e1
2017-12-07 18:35:09 +09:00
Yukihiro "Matz" Matsumoto 842e6945f2 Fix type casting errors when mruby-socket compiled by C++.
Also `bool` is a reserved word in C++.
2017-12-07 18:23:01 +09:00
Yukihiro "Matz" Matsumoto 73ef548c63 Add 'mrbgems/mruby-socket/' from commit 'ab54185005ec87fe4f5b10df95ad29659884141b'
git-subtree-dir: mrbgems/mruby-socket
git-subtree-mainline: d75266dd1b
git-subtree-split: ab54185005
2017-12-07 18:11:13 +09:00
Yukihiro "Matz" Matsumoto d75266dd1b Add 'mrbgems/mruby-io/' from commit '3c8e1f94c44252c836f79a48bb17726da28e2756'
git-subtree-dir: mrbgems/mruby-io
git-subtree-mainline: 10ed730e4b
git-subtree-split: 3c8e1f94c4
2017-12-07 18:11:06 +09:00
Yukihiro "Matz" Matsumoto 10ed730e4b Cancel df3507660 that does not do any good. 2017-12-07 15:18:41 +09:00
Yukihiro "Matz" Matsumoto cdf173d32c Avoid updating to reallocated stack in OP_RETURN; fix #3870
The code was introduced to address #3175 but it's no longer needed.
2017-12-07 15:05:14 +09:00
Yukihiro "Matz" Matsumoto 0e46b14b9e The ci should not be equal to cibase with OP_R_BREAK; #3871 2017-12-06 17:28:20 +09:00
Yukihiro "Matz" Matsumoto 6975258efd The proc with top-level env must be 'proc-closure'; fix #3871 2017-12-06 17:28:20 +09:00
Yukihiro "Matz" Matsumoto ae44e80668 Limit ecall() depth to 32 (default). 2017-12-06 17:28:20 +09:00
Yukihiro "Matz" Matsumoto b00d45b095 mrb_method_search_vm() should gives the defined class.
Otherwise `super` may call a wrong method.
2017-12-06 17:28:20 +09:00
Yukihiro "Matz" Matsumoto 4a99f4949e Need to set ci->proc when we have RProc structure.
Mentioned in https://qiita.com/bamchoh/items/eabebbbb330cb0e0470a
2017-12-05 11:43:12 +09:00
Yukihiro "Matz" Matsumoto cbb6f29875 Merge pull request #3868 from bamchoh/patch-1
Revise MRB_METHOD_PROC macro's argument
2017-12-05 06:47:22 +09:00
bamchoh 940133b627 Revise MRB_METHOD_PROC macro's argument
I revised MRB_METHOD_PROC macro's argument fn to m.
2017-12-05 01:22:43 +09:00
Yukihiro "Matz" Matsumoto 1fea63429e Some OS uses libedit that does not provide rl_free().
`libedit` is a `readline` compatible library with BSD license.
2017-12-04 11:53:19 +09:00
Yukihiro "Matz" Matsumoto 0b5d97ec42 Need to unshare env stack on break; fix #3866 2017-12-04 10:15:12 +09:00
Yukihiro "Matz" Matsumoto 6f4d4bbcc7 Remove temporary objects from GC arena in `mrb_vformat()'; #3863 2017-12-04 08:56:11 +09:00
Yukihiro "Matz" Matsumoto 5d04e3316b Check if ci->proc is not NULL and MRB_PROC_CFUNC_P(); fix #3867 2017-12-04 08:56:11 +09:00
Yukihiro "Matz" Matsumoto ff8b608c52 Free read lines using the deallocation function from the library.
To avoid potential `malloc/free` mismatch.
2017-12-04 08:56:11 +09:00
Yukihiro "Matz" Matsumoto cd9f53d42e Pop exception objects from the bottom of GC arena; fix #3863 2017-12-04 08:56:11 +09:00
Yukihiro "Matz" Matsumoto c35a402676 The stack shift width should be determined by p->upper; fix #3864
And check required register number from `ci->proc` as well.
The fixes for #3859 and #3862 were incomplete.
2017-12-01 10:01:46 +09:00
Yukihiro "Matz" Matsumoto 86ef9a2806 Avoid calling mrb_env_unshare() when env is NULL.
Small performance improvement by reducing function invocations.
2017-11-30 08:19:38 +09:00
Yukihiro "Matz" Matsumoto 2b9f762ba1 Avoid double free() of env stack; fix #3860
Should turn on `MRB_ENV_STACK_UNSHARED` flag only after env stack
reallocation.  `malloc()` may fail.
2017-11-30 08:17:14 +09:00
Yukihiro "Matz" Matsumoto d3e273ba4e Wrong stack adjustment in ecall() (f35f975 #3859); fix #3862 2017-11-30 08:04:27 +09:00
Yukihiro "Matz" Matsumoto f3279b41e6 Stop infinite recursion in Class#to_s; fix #3861 2017-11-30 07:58:11 +09:00
Yukihiro "Matz" Matsumoto 5f7cdecdc9 Clear c->prev on fiber termination. 2017-11-29 20:25:55 +09:00
Yukihiro "Matz" Matsumoto b746a0f0d2 Need to free contexts when freeing fibers.
Memory leak fixed; ref #3711
2017-11-29 20:24:03 +09:00
Yukihiro "Matz" Matsumoto 9c78a9bfa2 Set MRB_FIBER_TERMINATED flag on exception termination of a fiber. 2017-11-29 20:17:33 +09:00
Yukihiro "Matz" Matsumoto b7c3a876f1 Add most recent call last message to the backtrace. 2017-11-29 16:56:10 +09:00
Yukihiro "Matz" Matsumoto 3e67a116d1 Call all ensure clauses pushed at OP_STOP. 2017-11-29 12:16:16 +09:00
Yukihiro "Matz" Matsumoto afa53809e2 No need to use ecall_adjust(). 2017-11-29 12:15:24 +09:00
Yukihiro "Matz" Matsumoto f35f975d26 Fixed stack address adjustment in ecall(); fix #3859 2017-11-29 12:14:05 +09:00
Yukihiro "Matz" Matsumoto d4fc980527 Need to evaluate ensure clauses at fiber termination. 2017-11-29 11:57:33 +09:00
Yukihiro "Matz" Matsumoto 6bb5ad786c Remove unnecessary code; ref #3711 2017-11-29 11:44:07 +09:00
Yukihiro "Matz" Matsumoto 597149ae23 Change newline style of test/t/lang.rb (from DOS) 2017-11-22 16:10:28 +09:00
Yukihiro "Matz" Matsumoto b4f9b031de Some cosmetic changes 2017-11-22 16:09:50 +09:00
Yukihiro "Matz" Matsumoto 284a1d12ee Provide shortcut comparison methods for numbers for performance. 2017-11-22 15:43:48 +09:00
Yukihiro "Matz" Matsumoto 0ab21a9a5e Stack adjustment should be based on p->upper; fix #3857
It used to be based on `ci->proc` but the callinfo position may be
wrong when `ecall()` is called during stack rewinding from `OP_RETURN`.
2017-11-22 14:05:11 +09:00
Yukihiro "Matz" Matsumoto fbafa78098 Clear ensure stack after calling in OP_EPOP; #3855 3856 2017-11-22 12:22:45 +09:00
Yukihiro "Matz" Matsumoto 4665b07f7b No need to pop ensure stack if eidx is smaller than epos; #3855 #3856 2017-11-22 12:21:24 +09:00
Yukihiro "Matz" Matsumoto fe3ac50845 fixup! Remove fixed argument of ecall(); ref #3855 #3856 2017-11-22 12:20:56 +09:00
Yukihiro "Matz" Matsumoto cb4b042777 Remove fixed argument of ecall(); ref #3855 #3856 2017-11-22 12:19:40 +09:00
Yukihiro "Matz" Matsumoto 393133e741 Should have marked all ensure stack entries; fix #3855 fix #3856 2017-11-22 12:18:20 +09:00
Yukihiro "Matz" Matsumoto 8b7a8978e2 Reduce the size of struct RBreak to reduce memory usage.
The old size of `struct RBreak` was 56 bytes (`MRB_NO_BOXING`)
and it's bigger than other object structures. That increase the
size of `RVALUE` thus increase the total amount of memory consumption.
2017-11-20 18:33:41 +09:00
Yukihiro "Matz" Matsumoto 8f2c62407c Add MRB_METHOD_TABLE_INLINE option.
Now the method tables (in classes/modules and caches) keeps C function
pointers without wrapping in `struct RProc` objects. For the sake of
portability, `mrb_method_t` is represented by the struct and union, but
if the most significant bit of the pointer is not used by the platform,
`mrb_method_t` should be packed in `uintptr_t` to reduce memory usage.

`MRB_METHOD_TABLE_INLINE` is turned on by default for linux.
2017-11-20 18:33:41 +09:00
Yukihiro "Matz" Matsumoto 6c06e77446 Add MRB_METHOD_CACHE description to include/mrbconf.h 2017-11-20 06:04:27 +09:00
Yukihiro "Matz" Matsumoto 6a9efd6849 Invoke mrb_full_gc() before ObjectSpace.count_objects. 2017-11-19 12:19:46 +09:00
Yukihiro "Matz" Matsumoto 9b2454c94d Leave hash->ht to be NULL if initial capacity is zero. 2017-11-19 03:46:58 +09:00
Yukihiro "Matz" Matsumoto 7405821f5a doc/limitaions.md: Remove infinite recursion entry.
It's fixed since 1.3.0
2017-11-18 21:16:22 +09:00
Yukihiro "Matz" Matsumoto 86f9254df0 doc/limitaions.md: Remove Kernel.binding entry.
Since no ISO classes/methods are not provided by mruby, there's
no use mentioning `Kernel.binding` here.
2017-11-18 21:14:19 +09:00
Yukihiro "Matz" Matsumoto 825e93eba4 Assign operands to local variables. 2017-11-18 00:03:59 +09:00
Yukihiro "Matz" Matsumoto 31ce73ddc3 Merge pull request #3853 from ukrainskiysergey/variable_c_cosmetic_changes
Removed useless condition
2017-11-18 00:03:50 +09:00
Ukrainskiy Sergey a2d0ee59c6 Removed useless condition 2017-11-17 22:30:22 +09:00
Yukihiro "Matz" Matsumoto 269f9f2125 Merge pull request #3852 from dabroz/feature-array-transpose
implement Array.transpose
2017-11-17 21:50:34 +09:00
Tomasz Dąbrowski e65fa4d7a2 implement Array.transpose 2017-11-17 12:39:34 +01:00
Yukihiro "Matz" Matsumoto d01003ce3a Merge pull request #3851 from ukrainskiysergey/variable_c_cosmetic_changes
Cosmetic changes in variable.c
2017-11-17 20:04:37 +09:00
Ukrainskiy Sergey ddd32d74e1 Changed the assignment of a variable in variable.c 2017-11-17 19:43:57 +09:00
Ukrainskiy Sergey 74714c8fee Changed numbers to TRUE and FALSE for mrb_bool in variable.c 2017-11-17 19:16:29 +09:00
Yukihiro "Matz" Matsumoto c8da602752 Need to save stack space by number of registers from the current proc,
Not from the execution ensure proc; fix #3849
2017-11-17 01:08:46 +09:00
Yukihiro "Matz" Matsumoto 03a3bd9178 The number of argument should be retrieved by mrb_get_argc; fix #3848
You should not access `mrb->c->ci->argc` directly.
2017-11-13 16:16:38 +09:00
Yukihiro "Matz" Matsumoto c210a8adf9 Fixed wrong stack extend size; fix #3847 2017-11-11 17:55:32 +09:00
Yukihiro "Matz" Matsumoto 181f980b6c Need to clear stack region for local variables in eval; fix #3844 2017-11-10 21:53:12 +09:00
Yukihiro "Matz" Matsumoto 41c8c419cf Use proper target_class to define class/module; fix #3843
The outer class of the class/module definition should be taken from
`MRB_TARGET_CLASS(mrb->c->ci->proc)` not `mrb->c->ci->target_class`
which is the target of constant lookups.
2017-11-09 00:14:21 +09:00
Yukihiro "Matz" Matsumoto f723832ebc Should allocate memory region before updating len; fix #3842
Otherwise half-baked string object will be allocated.
2017-11-08 08:46:55 +09:00
Yukihiro "Matz" Matsumoto 7ae20e0785 Simplify MRB_WITHOUT_FLOAT condtion 2017-11-08 08:45:59 +09:00
Yukihiro "Matz" Matsumoto 37f6e42293 Removed redundant function prototype. 2017-11-04 17:59:00 +09:00
Yukihiro "Matz" Matsumoto d6cb4f9cf2 Merge branch 'pandax381-mrb_without_float' 2017-11-04 12:33:07 +09:00
Yukihiro "Matz" Matsumoto a751f7f196 Make mirb to print warnings; ref #3827 2017-11-04 12:32:34 +09:00
Yukihiro "Matz" Matsumoto fef4b394a7 Avoid compiling fmt_fp.c if MRB_WITHOUT_FLOAT is set; #3827 2017-11-04 12:12:52 +09:00
Yukihiro "Matz" Matsumoto de2363a9f0 Merge branch 'mrb_without_float' of https://github.com/pandax381/mruby into pandax381-mrb_without_float 2017-11-04 11:49:25 +09:00
Yukihiro "Matz" Matsumoto 388d26d770 Reimplement block_given?; ref #3841
Make `block_given?` to search for the top of the scope first.
The top of the scope means either:

* the top method body
* the enclosing class body
* the top-level

The special case is the method defined by `define_method` with a
block as in #3841. In cases like this, the method body (given by
a block) is not considered as the top of the scope. You need to use
`&block` in the block parameter if you want to know if a block is
given to the method.

This commit also changes the behavior of `MRB_PROC_SCOPE` flag.
Now it is only set if the `proc` is either a class body or a method
body defined in Ruby. It is no longer set for a block that given to
`define_method`.
2017-11-04 11:20:04 +09:00
Yukihiro "Matz" Matsumoto ab27abe083 The bidx saved in env may be useless; fix #3841
When `block_given?` is called from a block given to `define_method`
as a method body, the `bidx` may not be within `env` saved closure.
In this case, it causes heap buffer overflow.
2017-11-04 03:01:37 +09:00
YAMAMOTO Masaya 625f9f6fa3 Merge branch 'master' of github.com:mruby/mruby 2017-11-04 01:23:12 +09:00
Yukihiro "Matz" Matsumoto e7fe6ee263 Avoid pointer arithmetic in backtrace.c; #3816 2017-11-04 00:35:50 +09:00
Yukihiro "Matz" Matsumoto 12e38597c8 Always check division-by-zero to avoid undefined behavior; fix #3816
Also removed the code to normalize NaN value for `MRB_NAN_BOXING`.
Tha code was added to fix #1712 but no longer required after 249f05e7d.
2017-11-03 09:35:55 +09:00
Yukihiro "Matz" Matsumoto d489b41c31 Reduce memory leaks from mirb. 2017-11-03 08:24:47 +09:00
Yukihiro "Matz" Matsumoto e4662d77e7 Should not use FSHARED state for string from irep pools; fix #3829
This strings in `irep` pools may be freed forcefully in `mrb_irep_free`.
This commit probably fixes #3817 as well.
2017-11-03 08:24:47 +09:00
Yukihiro "Matz" Matsumoto 13a318b0c7 Merge pull request #3840 from iij/keep-backtrace-rethrown-exc
don't strip away backtrace info when an exception is re-thrown
2017-11-02 21:36:26 +09:00
Tomoyuki Sahara f6896751b4 don't overwrite backtrace info. 2017-11-02 15:44:05 +09:00
Yukihiro "Matz" Matsumoto ddfb24908c Fixed constant (and class variable) reference bug; fix #3839
Unlike method definition, constant reference should start from
`MRB_PROC_TARGET_CLASS(ci->proc)`, not `ci->target_class`.
In addition, `MRB_PROC_TARGET_CLASS(ci->proc)` is always set.
2017-10-31 09:10:08 +09:00
Yukihiro "Matz" Matsumoto 022570ab8d Call stack may not reference the destination proc; fix #3838
The destination `proc` may be an orphan.
2017-10-31 09:10:08 +09:00
Yukihiro "Matz" Matsumoto b6598e052f Need to mark fibers referenced from env; fix #3837
The issue #3837 is a regression of #3819. I was mistakenly removed
a important code to mark fibers from `env`.
2017-10-31 09:10:08 +09:00
Yukihiro "Matz" Matsumoto 77edafb04c Need to check number of argument of Struct#new; fix #3823 2017-10-29 00:25:45 +09:00
Yukihiro "Matz" Matsumoto 59dc7d0763 Removed a debug printf; fix #3834 2017-10-28 23:39:21 +09:00
Yukihiro "Matz" Matsumoto 1b45e034ba Remove one of the lines that did the same thing; fix #3836
The change is suggested by `ukrainskiysergey` in #3836.
I deleted the other line for clarity. I also updated comment lines.
2017-10-28 23:35:01 +09:00
Yukihiro "Matz" Matsumoto 6316e0c75d Should clear ensure stack at OP_RETURN break; #3715
This is a resurrection of d0a7e01, which is accidentally
removed by 93f5f22; Fix #3715
2017-10-28 23:27:07 +09:00
Yukihiro "Matz" Matsumoto 92e24f809b Should check if callinfo stack is popped before updating the stack.
This is a resurrection of 75c374c, which is accidentally removed by
93f5f22; Fix #3507 #3512 #3518 #3521
2017-10-28 23:10:28 +09:00
Yukihiro "Matz" Matsumoto c7c9543bed Fixed UPVAR gotchas; fix #3835
Both `uvenv` function and `env` generation in `create_proc_from_string`
function have bugs to handling enclosed environment objects.
2017-10-28 23:08:31 +09:00
Yukihiro "Matz" Matsumoto 57dad6e3fd Remove a debug variable 2017-10-28 01:37:51 +09:00
Yukihiro "Matz" Matsumoto 23d18bbd62 Add parentheses to pacify a warning. 2017-10-28 01:32:25 +09:00
Yukihiro "Matz" Matsumoto 93f5f22577 Heavily refactored how lexical scope links are implemented; fix #3821
Instead of `irep` links, we added a `upper` link to `struct RProc`.
To make a space for the `upper` link, we moved `target_class` reference.
If a `Proc` does not have `env`, `target_class` is saved in an `union`
shared with `env` (if a `Proc` has env, you can tell it by `MRB_PROC_ENV_P()).
Otherwise `target_class` is referenced from `env->c`. We removed links
in `env` as well.

This change removes 2 members from `mrb_irep` struct, thus saving 2
words per method/proc/block. This also fixes potential memory leaks
due to the circular references caused by a link from `mrb_irep`.
2017-10-28 00:29:30 +09:00
Yukihiro "Matz" Matsumoto 3f9d00ded3 comment out bench build from standard build_config.rb 2017-10-28 00:29:30 +09:00
Yukihiro "Matz" Matsumoto 4614b9d632 remove inline from replacement memcpy&memset 2017-10-28 00:29:30 +09:00
Yukihiro "Matz" Matsumoto 5405b47f41 Update test for Kernel#local_variables 2017-10-28 00:29:30 +09:00
Yukihiro "Matz" Matsumoto 14877469d1 Remove MRB_API from mrb_env_unshare() 2017-10-28 00:29:30 +09:00
Yukihiro "Matz" Matsumoto 07cf7b16f3 Add some peephole optimizations 2017-10-28 00:29:30 +09:00
Yukihiro "Matz" Matsumoto 6c966a1f86 Change the order of "expected" and "actual" in test 2017-10-28 00:29:30 +09:00
Yukihiro "Matz" Matsumoto 0cf5a0ee37 Use alias to implement attr method 2017-10-28 00:29:30 +09:00
Yukihiro "Matz" Matsumoto fda64be996 Flush stdout after every print from tests 2017-10-28 00:29:30 +09:00
Yukihiro "Matz" Matsumoto 71eeb86a99 Format codedump for OP_{LE,LT,GE,GT}. 2017-10-28 00:29:30 +09:00
Yukihiro "Matz" Matsumoto d08205b40d Merge pull request #3833 from bggd/appveyor_winbison_ruby24
Appveyor Improvements
2017-10-25 00:31:44 +09:00
bggd 7f4cc0de51 Turn on method cache for AppVeyor CI 2017-10-24 21:39:05 +09:00
bggd 7a13e89509 Use Ruby 2.4 instead of AppVeyor's Default(Ruby 1.9) 2017-10-24 21:37:36 +09:00
bggd 8a9b6c4352 Use win_bison instead of Cygwin's bison. Use YACC environment variable instead of global PATH 2017-10-24 21:31:37 +09:00
Yukihiro "Matz" Matsumoto 0c3ee0ba66 Add `Array#{permutation,combination}. 2017-10-20 10:38:58 +09:00
Yukihiro "Matz" Matsumoto f2394859e3 Add main.define_method 2017-10-19 10:39:06 +09:00
Tomoyuki Sahara 3c8e1f94c4 Merge pull request #94 from kazuho/kazuho/rename-compatibility
make `rename` behavior consistent with MRI
2017-10-18 13:22:22 +09:00
Yukihiro "Matz" Matsumoto fc930700b7 Add Kernel#itself; CRuby2.2 2017-10-18 10:21:54 +09:00
Yukihiro "Matz" Matsumoto ce916b99b8 Add Hash#to_proc; CRuby2.3 2017-10-18 10:18:43 +09:00
Yukihiro "Matz" Matsumoto b5dfbce767 Add Numeric#{positive?,negative?}; CRuby2.3 2017-10-18 10:10:37 +09:00
Yukihiro "Matz" Matsumoto 44f07045d1 Add Hash#fetch_values; CRuby2.3 2017-10-18 10:05:39 +09:00
Yukihiro "Matz" Matsumoto 913b83d579 Merge branch 'dabroz-fix-get-argc' 2017-10-17 15:24:00 +09:00
Yukihiro "Matz" Matsumoto 3c20c96f84 Use a new function: mrb_get_argc(); ref #3826 2017-10-17 15:23:32 +09:00
Yukihiro "Matz" Matsumoto b890528a18 Remove mrb_vm_get_argc; ref #3826 2017-10-17 15:22:45 +09:00
Yukihiro "Matz" Matsumoto 344a7ce20c Merge branch 'fix-get-argc' of https://github.com/dabroz/mruby into dabroz-fix-get-argc 2017-10-17 15:07:05 +09:00
Yukihiro "Matz" Matsumoto 4122c320bb Add {String,Symbol}#casecmp?; CRuby2.4 2017-10-17 13:26:37 +09:00
Yukihiro "Matz" Matsumoto db8265f428 Add Comparable#uniq; CRuby2.4 2017-10-17 12:46:51 +09:00
Yukihiro "Matz" Matsumoto 4e365156d1 Add Comparable#clamp; CRuby2.4 2017-10-17 11:19:12 +09:00
Yukihiro "Matz" Matsumoto 061d804a59 Add Numeric#{finite?,infinite?}; CRuby2.4 2017-10-17 11:19:12 +09:00
Yukihiro "Matz" Matsumoto 332d8d2a1c Add String#delete_{prefix,suffix}; CRuby2.5 2017-10-17 11:19:12 +09:00
Yukihiro "Matz" Matsumoto 1519616ecb Add Kernel#yield_self; CRuby2.5 2017-10-17 09:10:13 +09:00
Yukihiro "Matz" Matsumoto c96def7c96 Remove top-level constant lookup; CRuby2.5 2017-10-17 08:45:06 +09:00
Yukihiro "Matz" Matsumoto e59ad60327 do/end blocks to work with rescue/ensure/else; CRuby2.5 2017-10-17 08:17:31 +09:00
Yukihiro "Matz" Matsumoto fb85855fa1 Add more checks before accessing struct pointer; ref #3831 2017-10-17 07:43:35 +09:00
Yukihiro "Matz" Matsumoto be2c1592ed Check struct-array pointer before accessing; fix #3831 2017-10-16 22:53:36 +09:00
Yukihiro "Matz" Matsumoto 1988bec23e Need to adjust the stack length of the top-level environment; fix #3819 2017-10-16 22:35:25 +09:00
Yukihiro "Matz" Matsumoto c3710dbb96 Fix a compile error on zero mrbgem case. 2017-10-16 18:46:15 +09:00
Yukihiro "Matz" Matsumoto 6b0c22e395 Merge pull request #3830 from dearblue/fix-alias-for-struct-accessors
fix alias for Struct accessors
2017-10-16 18:45:52 +09:00
YAMAMOTO Masaya b70d69de09 Support MRB_WIHTOUT_FLOAT to mruby-kernel-ext 2017-10-16 18:15:47 +09:00
YAMAMOTO Masaya 9afd376fa4 Support MRB_WIHTOUT_FLOAT to mruby-object-ext 2017-10-16 18:15:25 +09:00
YAMAMOTO Masaya b0cdb93a3a Support MRB_WIHTOUT_FLOAT to mruby-numeric-ext (test only) 2017-10-16 18:14:34 +09:00
YAMAMOTO Masaya 9c1f21aaa1 Support MRB_WIHTOUT_FLOAT to mruby-string-ext 2017-10-16 18:09:56 +09:00
dearblue 44e2c97152 fix alias for Struct accessors 2017-10-15 23:43:55 +09:00
YAMAMOTO Masaya 5d781312ca Support MRB_WIHTOUT_FLOAT to mruby-sprintf 2017-10-13 16:42:35 +09:00
Yukihiro "Matz" Matsumoto fa974a1f6a Merge pull request #3828 from asfluido/master
Correct a small error in parse.y
2017-10-12 20:19:24 +09:00
Carlo Prelz af3d5d6c8a Correct a small error in parse.y, which causes the reading of unassigned memory (triggers an error when address sanitizer is active) 2017-10-12 09:54:02 +02:00
Kazuho Oku 0d92431061 make the behavior consistent with MRI 2017-10-12 15:23:52 +09:00
YAMAMOTO Masaya 81ea81e05c Fix typo 2017-10-11 19:52:21 +09:00
YAMAMOTO Masaya 3eebe81b35 Upadte AUTHORS 2017-10-11 19:44:34 +09:00
YAMAMOTO Masaya dcd5d0ffec Test for MRB_WITHOUT_FLOAT 2017-10-11 17:58:11 +09:00
YAMAMOTO Masaya acdc2d1f24 Add MRB_WITHOUT_FLOAT 2017-10-11 17:58:11 +09:00
YAMAMOTO Masaya 679dfd75a8 Use division expression instead of some floating point literals 2017-10-11 17:58:11 +09:00
Tomasz Dąbrowski be86d8b45f correctly handle *splat arguments in mrb_get_argc, also add mrb_vm_get_argc and mrb_get_argv
Fixes #3825
2017-10-10 18:40:38 +02:00
Yukihiro "Matz" Matsumoto 80e03f3ffb Merge pull request #3824 from nobu/bug/paren_arg
Bug/paren arg
2017-10-09 12:39:13 +09:00
Nobuyoshi Nakada 82983330a3 Fix parse error on TRICK2013/yhara 2017-10-09 08:56:46 +09:00
Nobuyoshi Nakada 1c2a2827b3 Replace lvar_defined with local_var_p 2017-10-09 08:54:25 +09:00
Tomoyuki Sahara f8121953e7 Merge pull request #92 from palkan/master
Handle shared/frozen strings in IO#sysread
2017-10-05 21:27:58 +09:00
Vladimir Dementyev 43795cb1f1 Remove useless mrb_str_modify 2017-10-05 15:22:57 +03:00
Vladimir Dementyev 4c255c7739 Handle shared/frozen strings in IO#sysread
See https://github.com/mruby/mruby/commit/7edbe428caca6814841195a3f2720745cf04353e
2017-10-05 14:40:43 +03:00
Yukihiro "Matz" Matsumoto c3c882f681 Use uint32_t to avoid signed integer overflow warning; #3816 2017-10-01 17:53:10 +09:00
Yukihiro "Matz" Matsumoto 8c408379aa Add cscope.files to .gitignore. 2017-10-01 16:24:43 +09:00
Yukihiro "Matz" Matsumoto 7edbe428ca Add new type of shared string: RSTR_FSHARED.
`RSTR_FSHARED` use frozen strings as shared body instead of
`struct mrb_shared_string`. This reduces allocation from
literal strings.
2017-10-01 16:24:43 +09:00
Yukihiro "Matz" Matsumoto 473b7d0efd Cut links from irep in heaps finalization. 2017-09-29 00:18:55 +09:00
Yukihiro "Matz" Matsumoto 7b01b969f5 codedump to display OP_CALL. 2017-09-29 00:18:55 +09:00
Yukihiro "Matz" Matsumoto 29a9e698e3 Merge pull request #3815 from dabroz/fix-warnings
Fix MSVC 14.0 warnings
2017-09-29 00:18:39 +09:00
Tomasz Dąbrowski 999ce87129 fix: src\vm.c(2631): warning C4244: '=': conversion from 'mrb_int' to 'int', possible loss of data 2017-09-27 22:22:05 +02:00
Tomasz Dąbrowski 77d6a953ff fix: src\vm.c(1757): warning C4244: '=': conversion from 'mrb_int' to 'int', possible loss of data 2017-09-27 22:22:05 +02:00
Tomasz Dąbrowski ebd45b1072 fix: src\vm.c(1744): warning C4244: '=': conversion from 'mrb_int' to 'int', possible loss of data 2017-09-27 22:22:05 +02:00
Tomasz Dąbrowski 0bff4b6a09 fix: src\vm.c(1702): warning C4244: '=': conversion from 'mrb_int' to 'int', possible loss of data 2017-09-27 22:22:05 +02:00
Tomasz Dąbrowski 885916c84b fix: src\vm.c(708): warning C4244: '=': conversion from 'mrb_int' to 'int', possible loss of data 2017-09-27 22:22:05 +02:00
Tomasz Dąbrowski e88fc10679 fix: src\vm.c(704): warning C4244: '=': conversion from 'mrb_int' to 'int', possible loss of data 2017-09-27 22:22:05 +02:00
Tomasz Dąbrowski ec7f478eda fix: src\vm.c(457): warning C4244: '=': conversion from 'mrb_int' to 'int', possible loss of data 2017-09-27 22:22:05 +02:00
Tomasz Dąbrowski 67ab8406b8 fix: src\vm.c(445): warning C4244: '=': conversion from 'mrb_int' to 'int', possible loss of data 2017-09-27 22:22:05 +02:00
Tomasz Dąbrowski 23cc698134 fix: src\vm.c(438): warning C4244: '=': conversion from 'mrb_int' to 'int', possible loss of data 2017-09-27 22:22:05 +02:00
Tomasz Dąbrowski 5ede90cdf4 fix: src\vm.c(438): warning C4244: '=': conversion from 'mrb_int' to 'int', possible loss of data 2017-09-27 22:22:05 +02:00
Tomasz Dąbrowski 53f934a7ee fix: src\string.c(2219): warning C4244: 'function': conversion from 'mrb_int' to 'int', possible loss of data 2017-09-27 22:22:05 +02:00
Tomasz Dąbrowski ef8df492e9 fix: src\string.c(1924): warning C4244: '=': conversion from 'mrb_int' to 'int', possible loss of data 2017-09-27 22:22:05 +02:00
Tomasz Dąbrowski 027b8d8377 fix: src\string.c(1130): warning C4244: '=': conversion from 'mrb_int' to 'int', possible loss of data 2017-09-27 22:22:05 +02:00
Tomasz Dąbrowski 46ccabacf0 fix: src\string.c(497): warning C4244: '=': conversion from 'mrb_int' to 'long', possible loss of data 2017-09-27 22:22:05 +02:00
Tomasz Dąbrowski 6cde950017 fix: src\state.c(66): warning C4200: nonstandard extension used: zero-sized array in struct/union 2017-09-27 22:22:05 +02:00
Tomasz Dąbrowski 0e2976bf93 fix: src\range.c(136): warning C4244: '=': conversion from 'mrb_int' to 'int', possible loss of data 2017-09-27 22:22:05 +02:00
Tomasz Dąbrowski b7e71e4cef fix: src\proc.c(96): warning C4244: 'function': conversion from 'mrb_int' to 'int', possible loss of data 2017-09-27 22:22:05 +02:00
Tomasz Dąbrowski 490de9dbe1 fix: src\print.c(22): warning C4244: 'initializing': conversion from 'mrb_int' to 'int', possible loss of data 2017-09-27 22:22:05 +02:00
Tomasz Dąbrowski 220c628210 fix: src\pool.c(33): warning C4200: nonstandard extension used: zero-sized array in struct/union 2017-09-27 22:22:05 +02:00
Tomasz Dąbrowski f0c1074b07 fix: src\numeric.c(1215): warning C4244: 'function': conversion from 'mrb_int' to 'int', possible loss of data 2017-09-27 22:22:05 +02:00
Tomasz Dąbrowski 4a0c9c9e31 fix: src\numeric.c(954): warning C4334: '<<': result of 32-bit shift implicitly converted to 64 bits (was 64-bit shift intended?) 2017-09-27 22:22:05 +02:00
Tomasz Dąbrowski 332a04af73 fix: src\numeric.c(897): warning C4244: 'function': conversion from 'mrb_int' to 'mrb_float', possible loss of data 2017-09-27 22:22:05 +02:00
Tomasz Dąbrowski 971a4f9122 fix: src\kernel.c(874): warning C4244: 'function': conversion from 'mrb_int' to 'int', possible loss of data 2017-09-27 22:22:05 +02:00
Tomasz Dąbrowski 0e0c96096d fix: src\kernel.c(861): warning C4244: '=': conversion from 'mrb_int' to 'int', possible loss of data 2017-09-27 22:22:05 +02:00
Tomasz Dąbrowski 7d98055862 fix: src\hash.c(139): warning C4244: 'function': conversion from 'mrb_int' to 'khint_t', possible loss of data 2017-09-27 22:22:05 +02:00
Tomasz Dąbrowski 8cef3f946c fix: src\hash.c(40): warning C4244: '=': conversion from 'mrb_int' to 'khint_t', possible loss of data 2017-09-27 22:22:05 +02:00
Tomasz Dąbrowski 3e1d60ae0b fix: src\hash.c(27): warning C4244: '=': conversion from 'mrb_int' to 'khint_t', possible loss of data 2017-09-27 22:22:05 +02:00
Tomasz Dąbrowski c7b663f2cf fix: src\gc.c(1425): warning C4244: '=': conversion from 'mrb_int' to 'int', possible loss of data 2017-09-27 22:22:04 +02:00
Tomasz Dąbrowski b406e9f795 fix: src\gc.c(1392): warning C4244: '=': conversion from 'mrb_int' to 'int', possible loss of data 2017-09-27 22:22:04 +02:00
Tomasz Dąbrowski 1dcf8ba488 fix: src\gc.c(559): warning C4244: '=': conversion from 'mrb_int' to 'int', possible loss of data 2017-09-27 22:22:04 +02:00
Tomasz Dąbrowski 7a2391b120 fix: src\error.c(76): warning C4244: '=': conversion from 'mrb_int' to 'int', possible loss of data 2017-09-27 22:22:04 +02:00
Tomasz Dąbrowski 4d6b8dbcb9 fix: src\dump.c(710): warning C4244: 'function': conversion from 'mrb_int' to 'uint16_t', possible loss of data 2017-09-27 22:22:04 +02:00
Tomasz Dąbrowski f4a17dd7b5 fix: src\dump.c(657): warning C4244: 'function': conversion from 'mrb_int' to 'uint16_t', possible loss of data 2017-09-27 22:22:04 +02:00
Tomasz Dąbrowski 5ed76e381c fix: src\class.c(949): warning C4244: '=': conversion from 'mrb_int' to 'int', possible loss of data 2017-09-27 22:22:04 +02:00
Tomasz Dąbrowski 9c5db48d1f fix: src\class.c(949): warning C4244: '=': conversion from 'mrb_int' to 'int', possible loss of data 2017-09-27 22:22:04 +02:00
Tomasz Dąbrowski d8b37d0381 fix: src\class.c(583): warning C4244: '=': conversion from 'mrb_int' to 'int', possible loss of data 2017-09-27 22:22:04 +02:00
Tomasz Dąbrowski 4146b5c2b5 fix: src\backtrace.c(83): warning C4244: '=': conversion from 'mrb_int' to 'int', possible loss of data 2017-09-27 22:22:04 +02:00
Tomasz Dąbrowski 7507d46992 fix: src\array.c(86): warning C4244: '=': conversion from 'mrb_int' to 'uint32_t', possible loss of data 2017-09-27 22:22:04 +02:00
Tomasz Dąbrowski be81504770 fix: mrbgems\mruby-time\src\time.c(641): warning C4244: '=': conversion from 'mrb_int' to 'int', possible loss of data 2017-09-27 22:22:04 +02:00
Tomasz Dąbrowski 0848407ee5 fix: mrbgems\mruby-time\src\time.c(372): warning C4244: 'function': conversion from 'mrb_int' to 'double', possible loss of data 2017-09-27 22:22:04 +02:00
Tomasz Dąbrowski d713f8d761 fix: mrbgems\mruby-test\driver.c(67): warning C4244: '=': conversion from 'mrb_int' to 'int', possible loss of data 2017-09-27 22:22:04 +02:00
Tomasz Dąbrowski 2640896911 fix: mrbgems\mruby-string-ext\src\string.c(49): warning C4244: '=': conversion from 'mrb_int' to 'int', possible loss of data 2017-09-27 22:22:04 +02:00
Tomasz Dąbrowski 8d816fa142 fix: mrbgems\mruby-string-ext\src\string.c(30): warning C4244: '=': conversion from 'mrb_int' to 'long', possible loss of data 2017-09-27 22:22:04 +02:00
Tomasz Dąbrowski d3819620ce fix: mrbgems\mruby-string-ext\src\string.c(38): warning C4244: '=': conversion from 'mrb_int' to 'char', possible loss of data 2017-09-27 22:22:04 +02:00
Tomasz Dąbrowski a94525d4ea fix: mrbgems\mruby-sprintf\src\sprintf.c(1052): warning C4244: '+=': conversion from 'mrb_int' to 'int', possible loss of data 2017-09-27 22:22:04 +02:00
Tomasz Dąbrowski 1e2c962fa5 fix: mrbgems\mruby-sprintf\src\sprintf.c(623): warning C4244: 'function': conversion from 'mrb_int' to 'int', possible loss of data 2017-09-27 22:22:04 +02:00
Tomasz Dąbrowski 897eabb1bb fix: mrbgems\mruby-sprintf\src\sprintf.c(646): warning C4244: 'function': conversion from 'mrb_int' to 'int', possible loss of data 2017-09-27 22:22:04 +02:00
Tomasz Dąbrowski e10b329fa3 fix: mrbgems\mruby-sprintf\src\sprintf.c(618): warning C4244: 'initializing': conversion from 'mrb_int' to 'int', possible loss of data 2017-09-27 22:22:04 +02:00
Tomasz Dąbrowski 861077f779 fix: mrbgems\mruby-sprintf\src\sprintf.c(516): warning C4244: 'function': conversion from 'mrb_int' to 'int', possible loss of data 2017-09-27 22:22:04 +02:00
Tomasz Dąbrowski 553dbad2c6 fix: mrbgems\mruby-math\src\math.c(660): warning C4244: 'function': conversion from 'mrb_int' to 'int', possible loss of data 2017-09-27 22:22:04 +02:00
Tomasz Dąbrowski 49e96a2e19 fix: mrbgems\mruby-math\src\math.c(491): warning C4244: '=': conversion from 'mrb_int' to 'int', possible loss of data 2017-09-27 22:22:04 +02:00
Tomasz Dąbrowski 536b95eb48 fix: mrbgems\mruby-kernel-ext\src\kernel.c(114): warning C4244: 'function': conversion from 'mrb_int' to 'int', possible loss of data 2017-09-27 22:22:04 +02:00
Tomasz Dąbrowski 9d89f8c00b fix: mrbgems\mruby-fiber\src\fiber.c(215): warning C4244: '=': conversion from 'mrb_int' to 'int', possible loss of data 2017-09-27 22:22:04 +02:00
Tomasz Dąbrowski 377d6a47ac fix: mrbgems\mruby-exit\src\mruby-exit.c(10): warning C4244: 'function': conversion from 'mrb_int' to 'int', possible loss of data 2017-09-27 22:22:04 +02:00
Tomasz Dąbrowski f632baddb1 fix: mrbgems\mruby-eval\src\eval.c(301): warning C4244: 'function': conversion from 'mrb_int' to 'int', possible loss of data 2017-09-27 14:42:27 +02:00
Tomasz Dąbrowski 49db1db81f fix: mrbgems\mruby-eval\src\eval.c(214): warning C4244: '=': conversion from 'mrb_int' to 'short', possible loss of data 2017-09-27 14:42:27 +02:00
Tomasz Dąbrowski 2e239a296e fix: mrbgems\mruby-compiler\core\parse.y(3455): warning C4244: 'function': conversion from 'intptr_t' to 'int', possible loss of data 2017-09-27 14:42:27 +02:00
Tomasz Dąbrowski f1a02dff58 fix: include\mruby/gc.h(43): warning C4200: nonstandard extension used: zero-sized array in struct/union 2017-09-27 14:42:27 +02:00
Yukihiro "Matz" Matsumoto 381850280c The [] special method call should be able to take a block. 2017-09-25 20:44:50 +09:00
Yukihiro "Matz" Matsumoto e98823f189 The lex_state after literals should be EXPR_ENDARG. 2017-09-25 20:44:04 +09:00
Yukihiro "Matz" Matsumoto e01d35ef79 The symbols should not take brace blocks. 2017-09-25 20:22:36 +09:00
Yukihiro "Matz" Matsumoto 298177fd6a Merge pull request #3813 from dabroz/feature-fix-date
Change DISABLE_STDIO to MRB_DISABLE_STDIO in mruby-time/time.c
2017-09-25 20:19:13 +09:00
Tomasz Dabrowski e00b48be4a change DISABLE_STDIO to MRB_DISABLE_STDIO in mruby-time/time.c 2017-09-25 13:11:20 +02:00
Yukihiro "Matz" Matsumoto 7450a774a5 The first instruction was skipped mistakenly in ensure clause; fix #3811 2017-09-23 10:12:04 +09:00
Yukihiro "Matz" Matsumoto 0ceaa0960a OP_EPOP operand may be bigger than mrb->c->eidx; fix #3810 2017-09-22 13:00:58 +09:00
Yukihiro "Matz" Matsumoto 5760226e71 Remove temporary limitation of OP_EPOP.
After f68f5f6, the operand of `OP_EPOP` should have been `1`.
Now we have removed the limitation.
2017-09-12 12:41:02 +09:00
Tomoyuki Sahara ab54185005 receiver variables must be "mrb_int" for mrb_get_args("i").
Otherwise, it can cause a segfault on the platforms where the
size of "int" and "mrb_int" differs.
2017-09-12 12:32:12 +09:00
Tomoyuki Sahara a809d42f5a remove whitespaces at the end of line. 2017-09-12 11:43:21 +09:00
Yukihiro "Matz" Matsumoto d6e41c3e51 The callinfo stack may be reallocated in cipush; fix rest of #3809
fix #3809
2017-09-11 23:13:47 +09:00
Yukihiro "Matz" Matsumoto 3d8c1a7e97 The ensure stack may be empty at OP_EPOP; fix 1st part of #3809 2017-09-11 22:46:34 +09:00
Yukihiro "Matz" Matsumoto 2a1e616e4d Avoid calling mrb_funcall to invoke #initialize from Class.new.
If `#initialize` is implemented in C, we don't need stack consuming
`mrb_funcall`.
2017-09-06 14:35:24 +09:00
Yukihiro "Matz" Matsumoto cbfa2b3588 Avoid recursion from mark_context(). 2017-09-05 21:13:16 +09:00
Yukihiro "Matz" Matsumoto f68f5f6b97 Avoid crossing C function boundary from OP_EPOP; ref #3789 2017-09-05 21:12:36 +09:00
Yukihiro "Matz" Matsumoto 7f4b57bb20 Restrict OP_EPOP operand to 1; ref #3789 2017-09-05 21:11:41 +09:00
Tomoyuki Sahara 15f4bdb529 Merge pull request #37 from udzura/fix-types
Fix type int to mrb_int
2017-09-04 23:55:37 +09:00
Uchio KONDO 5b6e4eda2a Fix type int to mrb_int
- mruby's default int size is changed after: https://github.com/mruby/mruby/commit/f0f4a1088a270e339407a24ffe8be748f4764fc2
- implicit cast causes some errors
2017-09-04 16:33:57 +09:00
Yukihiro "Matz" Matsumoto 3acaa44a70 Restructure irep->outer chain; fix #3804
Instead of `irep -> proc` chain, we use `irep -> irep` chain to
avoid GC bugs like #3804. We added `target_class` reference to
`mrb_irep` struct. That means one more word consumption per `irep`.
2017-09-04 06:51:31 +09:00
Yukihiro "Matz" Matsumoto 8a5d783f2e Call initialize only when it's not empty. 2017-09-04 06:49:05 +09:00
Yukihiro "Matz" Matsumoto 5d7e4957e0 Merge pull request #3806 from flaviommedeiros/master
Trying to make the code more readable
2017-09-03 07:51:12 +09:00
Yukihiro "Matz" Matsumoto da97715e11 Merge pull request #3805 from fl0l0u/patch-1
Update print.c
2017-09-03 07:48:33 +09:00
fl0l0u e03042ec19 Update print.c
Strings not containing a newline are not printed synchronously
ex. bin/mruby -e '["a", "b", "c", "\n", "d", "e", "f", "\n"].each {|e| print e ; usleep 200000}'
2017-09-02 18:26:50 +02:00
Flavio Medeiros 9f677b72db Trying to make the source code more understandable by removing mixing of ternary if statements with attributions. 2017-09-02 13:25:09 -03:00
Yukihiro "Matz" Matsumoto 476af3c647 Merge pull request #3802 from christopheraue/proc_break_tests
Tested local jump errors caused by break in a proc
2017-09-02 22:19:15 +09:00
Yukihiro "Matz" Matsumoto ab99e2c293 Avoid copying over initialized procs using initialize_copy; fix #3803
It may be better to raise exceptions, but CRuby doesn't.
2017-09-01 06:51:59 +09:00
Yukihiro "Matz" Matsumoto 57610091ce Update method cache clearing. 2017-09-01 06:51:59 +09:00
Yukihiro "Matz" Matsumoto f0f4a1088a Make the default integer size to be MRB_INT64 on 64bit systems; close #3800
Unless `MRB_NAN_BOXING` is specified.
2017-09-01 06:51:59 +09:00
Christopher Aue 35deaae776 Tested LocalJumpErrors caused by break in a proc 2017-08-30 12:25:55 +02:00
Yukihiro "Matz" Matsumoto 71357ff1d8 Merge pull request #3801 from christopheraue/assert_raise_refactoring
Allowed to pass multiple exceptions to assert_raise
2017-08-30 18:56:59 +09:00
Christopher Aue bf32265743 Allowed to pass multiple exceptions to assert_raise 2017-08-30 11:03:51 +02:00
Yukihiro "Matz" Matsumoto fe3227cd5c Set the ORPHAN flag in Proc.new; fix #3798 2017-08-30 16:51:40 +09:00
Yukihiro "Matz" Matsumoto 483a038d39 Fixed a critical typo; ref #3798 2017-08-30 16:51:17 +09:00
Yukihiro "Matz" Matsumoto 2c85213298 Need to mark mrb->range_class; fix #3797 2017-08-30 16:12:12 +09:00
Yukihiro "Matz" Matsumoto 79b4f61b02 Merge pull request #3799 from christopheraue/assert_raise_refactoring
Refactored #assert_raise and #assert_nothing_raised
2017-08-30 14:47:12 +09:00
Christopher Aue 4b0b8f7e1a Refactored #assert_raise and #assert_nothing_raised 2017-08-29 23:25:53 +02:00
Yukihiro "Matz" Matsumoto 8976f47e0a Need to update ci after callinfo stack reallocation; fix #3796 2017-08-29 11:06:34 +09:00
Yukihiro "Matz" Matsumoto c082249838 Exclude the top-level closure from each_object; fix #3793 2017-08-29 09:29:14 +09:00
Yukihiro "Matz" Matsumoto 786cbf06c3 Revert "Clear irep->outer when no Proc reference the irep; fix #3793"
This reverts commit 15d48efa4b.
2017-08-29 09:27:45 +09:00
Yukihiro "Matz" Matsumoto 1260d3b68a Add `__ENCODING__' support.
`__ENCODING__' returns the current encoding name (string), unlike
CRuby that returns the encoding object.
2017-08-28 22:42:06 +09:00
Yukihiro "Matz" Matsumoto f1fa5bf1c6 Remove integer type mismatch warnings from parse.y. 2017-08-28 22:31:02 +09:00
Yukihiro "Matz" Matsumoto 15d48efa4b Clear irep->outer when no Proc reference the irep; fix #3793 2017-08-28 10:06:04 +09:00
Yukihiro "Matz" Matsumoto fd927d786e Merge pull request #3795 from christopheraue/array_refactoring
Array refactorings and speed improvements
2017-08-27 08:56:41 +09:00
Christopher Aue c956e17c02 Replaced Array#each with while loop for performance reasons
Example benchmark:
$ time build/bench/bin/mruby -e "Array.new(2_000_000){ |i| i }.index{ |i| i == 1_999_999 }"

Before:
real    0m0.934s
user    0m0.922s
sys     0m0.003s

After:
real    0m0.590s
user    0m0.583s
sys     0m0.007s
2017-08-26 15:57:25 +02:00
Christopher Aue 6c9013e22b Removed unneeded block check in Array#uniq 2017-08-26 15:57:25 +02:00
Christopher Aue f3fb43c729 Reimplemented Array#flatten with #flatten! 2017-08-26 15:57:25 +02:00
Yukihiro "Matz" Matsumoto ccd555421a Merge pull request #3794 from dabroz/fix-flt-epsilon
Fix building with MRB_USE_FLOAT=1
2017-08-26 22:29:00 +09:00
Tomasz Dąbrowski 01b9b71902 fix mrbgems/mruby-range-ext/src/range.c:142:71: error: use of undeclared identifier 'FLT_EPSILON' 2017-08-26 12:11:57 +02:00
Yukihiro "Matz" Matsumoto 85a400e43d Reimplement Array#shift to be faster. 2017-08-26 02:03:21 +09:00
Yukihiro "Matz" Matsumoto cec53ff77e Array#first to treat 1 argument case specially to improve performance. 2017-08-26 02:03:21 +09:00
Yukihiro "Matz" Matsumoto 1b545a6b63 Check for ability to skip optional argument parsing. 2017-08-26 02:03:21 +09:00
Yukihiro "Matz" Matsumoto 60104ce41d Silence compiler warning regarding float condition; fix #3790 2017-08-26 02:02:45 +09:00
Yukihiro "Matz" Matsumoto 43ec918be1 Remove unused mrb_obj_iv_ifnone() from API. 2017-08-26 02:01:50 +09:00
Yukihiro "Matz" Matsumoto 0e10a23d7a Add checks if iv_tbl is NULL. 2017-08-26 02:01:50 +09:00
Yukihiro "Matz" Matsumoto 0c52112dd4 Keep Range class in mrb_state structure for performance. 2017-08-26 02:01:50 +09:00
Yukihiro "Matz" Matsumoto 04dbbff3c1 Use khash for instance variables tables instead of segment list.
For performance reason. Segmented list consumes slightly less memory
but takes a lot of time especially when there are many slots in the
segment lists (e.g. class constants).
2017-08-26 02:01:50 +09:00
Yukihiro "Matz" Matsumoto f2cc1239a5 Turn on method cache for Travis CI. 2017-08-26 02:01:50 +09:00
Yukihiro "Matz" Matsumoto f7f1aca8b5 Merge pull request #3792 from dabroz/fix-test-int16
Fix string test with 16-bit integers
2017-08-26 02:00:30 +09:00
Yukihiro "Matz" Matsumoto 5f2c7e47bb Merge pull request #3791 from dabroz/fix-msvc-warning
Fix MSVC warnings in fmt_fp.c
2017-08-26 01:54:59 +09:00
Tomasz Dąbrowski 17c249780f fix String#% %d test with MRB_INT16 set 2017-08-25 14:36:05 +02:00
Tomasz Dąbrowski 5d9b84ef40 fix fmt_fp.c(329) : warning C4244: 'return' : conversion from 'ptrdiff_t' to 'int', possible loss of data 2017-08-25 14:18:31 +02:00
Tomasz Dąbrowski 78b13b3955 fix fmt_fp.c(251) : warning C4244: '=' : conversion from '__int64' to 'int', possible loss of data 2017-08-25 14:18:05 +02:00
Tomasz Dąbrowski ef6a762d41 fix fmt_fp.c(224) : warning C4244: '=' : conversion from 'ptrdiff_t' to 'int', possible loss of data 2017-08-25 14:14:17 +02:00
Tomasz Dąbrowski bac37a9f1a fix fmt_fp.c(220) : warning C4244: '=' : conversion from '__int64' to 'int', possible loss of data 2017-08-25 14:13:06 +02:00
Tomasz Dąbrowski b2a16d6bf7 fix fmt_fp.c(206) : warning C4244: 'initializing' : conversion from 'ptrdiff_t' to 'int', possible loss of data 2017-08-25 14:12:08 +02:00
Tomasz Dąbrowski c8341dbf7c fix fmt_fp.c(178) : warning C4244: 'return' : conversion from 'ptrdiff_t' to 'int', possible loss of data 2017-08-25 14:10:43 +02:00
Tomasz Dąbrowski 5d099e40e6 fix fmt_fp.c(123) : warning C4244: 'return' : conversion from 'ptrdiff_t' to 'int', possible loss of data 2017-08-25 14:10:24 +02:00
Yukihiro "Matz" Matsumoto 63f10a1ee5 Merge pull request #3788 from christopheraue/fix_codegen_op_send_nregs
Fixed register windows of OP_SENDs generated during codegen
2017-08-24 14:38:03 +09:00
Christopher Aue 3366894a40 Fixed register windows of OP_SENDs generated by NODE_{DREGX,REGX}; ref #3783 2017-08-23 18:16:05 +02:00
Christopher Aue 499498a6a7 Tested register windows of OP_SENDs generated by NODE_{DXSTR,XSTR}; ref #3783 2017-08-23 18:15:54 +02:00
Christopher Aue 84d8ecc1d7 Fixed register windows of OP_SENDs generated by NODE_OP_ASGN; ref #3783 2017-08-23 18:15:44 +02:00
Christopher Aue 4aca9ef98e Refactored code around generation of OP_SEND in NODE_OP_ASGN 2017-08-23 18:15:38 +02:00
Christopher Aue 1221f7676e Fixed register windows of OP_SENDs generated by NODE_{FOR,SYMBOLS}; ref #3783 2017-08-23 18:15:27 +02:00
Christopher Aue c040c8d92b Tested register windows of OP_SENDs generated by NODE_{RESCUE,HASH,ALIAS}; ref #3783 2017-08-23 18:15:08 +02:00
Christopher Aue c6596cf26a Fixed register windows of OP_SENDs generated by NODE_{SCALL,CASE,YIELD,UNDEF}; ref #3783 2017-08-23 18:12:35 +02:00
Christopher Aue 64e5208404 Asserted bidx < ci->nregs for OP_SEND and OP_SUPER 2017-08-23 15:18:06 +02:00
Yukihiro "Matz" Matsumoto 4c9a604877 Added method cache.
To enable method cache, define `MRB_METHOD_CACHE` or
`MRB_METHOD_CACHE_SIZE`. The cache size must be power of 2.
The default cache size is 128.

The measurement:
I measured simple benchmarks found in benchmark/ directory. With
method cache enabled, we gained 6-8% performance improvement, with
97-99% cache hit rate.
2017-08-22 22:17:01 +09:00
Yukihiro "Matz" Matsumoto a65f4dbb32 Remove possible path that leaves a local variable uninitialized. 2017-08-22 15:50:08 +09:00
Yukihiro "Matz" Matsumoto db437b04a4 mrb_obj_respond_to to use mrb_method_search_vm. 2017-08-22 14:23:46 +09:00
Yukihiro "Matz" Matsumoto 0d865a77d5 c (mrbc_context) may be NULL; fix #3787 2017-08-22 09:47:10 +09:00
Yukihiro "Matz" Matsumoto ab3b6dbd2a strlen returns size_t; need to cast before assigning to int. 2017-08-22 08:14:09 +09:00
Yukihiro "Matz" Matsumoto 3f90af6b42 (Try to) fix mixture of int and size_t in UTF-8 conversion.
This only effects VC.
2017-08-22 07:35:51 +09:00
Yukihiro "Matz" Matsumoto a7d611fb23 Reduce signed/unsigned warnings in dump.c 2017-08-19 21:50:36 +09:00
Yukihiro "Matz" Matsumoto 5d0fc7e57a Reduce signed/unsigned warnings in fmt_fp.c 2017-08-19 17:09:30 +09:00
Yukihiro "Matz" Matsumoto 8cea1f8907 Use ptrdiff_t instead of int. 2017-08-19 15:51:08 +09:00
Yukihiro "Matz" Matsumoto a117ec771b Remove mixed signed/unsigned comparison in debug.c. 2017-08-19 14:42:30 +09:00
Yukihiro "Matz" Matsumoto 834523945e Replace stack pop() by push_n(2); pop_n(3); fix #3783
To calculate correct register windows size. The fix was suggested
by Christopher Aue.
2017-08-19 11:56:04 +09:00
Yukihiro "Matz" Matsumoto db098d3e0e Type check before traversing irep->outer; fix #3782 2017-08-19 11:39:42 +09:00
Yukihiro "Matz" Matsumoto 2294ebdd44 Call mrb_full_gc before gc_each_objects; ref #3782
Otherwise dead object may be seen from `#each_object`.
2017-08-19 11:38:11 +09:00
Yukihiro "Matz" Matsumoto 9146d5c34f Zero width unshift should not touch memory; ref #3780 2017-08-19 11:11:26 +09:00
Yukihiro "Matz" Matsumoto 8b3298b2d6 Unshift pointer move size was wrong (not len but alen); fix #3780 2017-08-19 11:08:46 +09:00
Yukihiro "Matz" Matsumoto 29ad0a7964 capacify' for mrb_str_new_capa should not be 0`. 2017-08-18 23:42:34 +09:00
Yukihiro "Matz" Matsumoto a8bd06904d mrb_str_cat: capa should not be zero to avoid infinite loops. 2017-08-18 23:42:34 +09:00
Yukihiro "Matz" Matsumoto a06adb176f mrb_str_cat: capa should be bigger than total. 2017-08-18 23:42:33 +09:00
Yukihiro "Matz" Matsumoto 8b5be554c7 ARY_CAPA handles capacity for embedded arrays by itself. 2017-08-18 23:42:33 +09:00
Yukihiro "Matz" Matsumoto 8fbc4bef55 Reduce signed/unsigned comparison warnings; ref #3785 2017-08-18 22:54:59 +09:00
Yukihiro "Matz" Matsumoto f1767fd079 Separate mrb_str_buf_new and mrb_str_new_capa.
`mrb_str_buf_new` is an old function that ensures capacity size of
`MRB_STR_BUF_MIN_SIZE` minimum. Usually one need to use
`mrb_str_new_capa` instead.
2017-08-18 22:17:48 +09:00
Yukihiro "Matz" Matsumoto 722d123b87 Remove code duplication in mrb_str_concat. 2017-08-18 22:17:48 +09:00
Yukihiro "Matz" Matsumoto 198c898817 Rename mrb_str_concat2 to mrb_str_concat_m.
According to the naming convention a function that implements
a method should be suffixed by `_m`.
2017-08-18 22:17:47 +09:00
Yukihiro "Matz" Matsumoto 4c25738ac7 Merge str_buf_cat and mrb_str_cat. 2017-08-18 22:17:47 +09:00
Yukihiro "Matz" Matsumoto 2adb0c201e Merge pull request #3786 from christopheraue/3784_fix
Reset ci in OP_SUPER after potential realloc
2017-08-18 22:17:33 +09:00
Yukihiro "Matz" Matsumoto 11c3ad999e Merge pull request #3781 from clayton-shopify/fix-hash-compact-bang
Check whether internal khash is initialized in Hash#compact!
2017-08-18 22:13:33 +09:00
Yukihiro "Matz" Matsumoto f229ed917e Merge pull request #3785 from miura1729/original
Improve Array structure
2017-08-18 20:37:31 +09:00
Miura Hideki 75ec86ed00 Improve Array structure 2017-08-18 20:12:00 +09:00
Christopher Aue 6b0860ce61 Reset ci in OP_SUPER after potential realloc 2017-08-18 13:11:08 +02:00
Clayton Smith 5dc688fb12 Check whether internal khash is initialized in Hash#compact! 2017-08-17 12:13:41 -04:00
Yukihiro "Matz" Matsumoto 0789ec71e0 Merge pull request #3779 from christopheraue/vm_refactoring
Some more vm refactorings
2017-08-13 07:11:21 +09:00
Christopher Aue d5ac785b31 Reintroduced not storing converted proc directly in the stack 2017-08-12 23:59:40 +02:00
Christopher Aue 198df61039 Removed unneeded ci->nregs checks in OP_SEND and OP_SUPER
Because of #3504 `ci->nregs = bidx+1` was introduced in b64f08784c.
This led to the follow up error #3551 whose fix introduced the `if (bidx >= ci->nregs)`
check in 071164b799 and the `stack_extend(mrb, ci->nregs)`
in 93d802987e.

Then, the code causing #3504 reappeared again in #3590. The fix for it moved the code
dealing with the block in OP_SUPER from below the `cipush`  to above the `cipush`
in d9fb8b69b0. The `if (bidx >= ci->nregs) { ... }` from
then on works with the original callinfo and not the pushed one. `ci->nregs` needed to
be modified for the pushed one because it is initialized to 0. But for the original ci
it is propertly set and a check is not needed.
2017-08-12 23:27:17 +02:00
Christopher Aue f2d4640998 Extended stack always based on ci->nregs 2017-08-12 14:47:22 +02:00
Christopher Aue 3f591d71c6 Refactored variable usage in OP_SEND and OP_SUPER 2017-08-12 14:31:18 +02:00
Yukihiro "Matz" Matsumoto 8bf492f127 Reduce integer type mismatch warnings in VC. 2017-08-12 09:35:35 +09:00
Yukihiro "Matz" Matsumoto baa5d2e3f7 Remove some empty lines; ref #3778 2017-08-11 22:39:31 +09:00
Yukihiro "Matz" Matsumoto 0828a962c0 Merge pull request #3778 from christopheraue/vm_refactoring
Refactored OP_SEND and OP_SUPER and calculate argc right at the top
2017-08-11 22:38:32 +09:00
Yukihiro "Matz" Matsumoto 42f9af41fb Merge pull request #3777 from christopheraue/super_method_missing_test
Added basic test for calling a missing method through super
2017-08-11 22:35:40 +09:00
Christopher Aue 731dd78aa0 Added basic test for calling a missing method through super 2017-08-11 14:09:22 +02:00
Christopher Aue 58f5115b22 Refactored OP_SEND and OP_SUPER and calculate argc right at the top 2017-08-11 13:42:06 +02:00
Yukihiro "Matz" Matsumoto d077a5f0a6 scan_hex may be used to parse both unicode and hex escape.
The error checks for both usage should be separated; ref #3774
2017-08-11 14:25:02 +09:00
Yukihiro "Matz" Matsumoto 56d4e41d76 Fixed a wrong condition in scan_hex; fix #3774 2017-08-11 14:14:30 +09:00
Yukihiro "Matz" Matsumoto 96d4c2d385 Remove an unused argument from each_backtrace_func. 2017-08-11 13:52:24 +09:00
Yukihiro "Matz" Matsumoto 1d781da8a6 Should not include float.h here. 2017-08-11 13:52:01 +09:00
Yukihiro "Matz" Matsumoto db72cdae28 Merge branch 'christopheraue-super_method_missing_fix' 2017-08-11 13:16:40 +09:00
Yukihiro "Matz" Matsumoto ab39ed4f82 Defer mid update after unshift; ref #3776 2017-08-11 13:15:50 +09:00
Yukihiro "Matz" Matsumoto 9feb069124 Merge branch 'super_method_missing_fix' of https://github.com/christopheraue/mruby into christopheraue-super_method_missing_fix 2017-08-11 13:14:32 +09:00
Yukihiro "Matz" Matsumoto 0ff28c9e60 Silence integer type conversion warnings. 2017-08-11 13:10:31 +09:00
Yukihiro "Matz" Matsumoto ef0b239704 Remove unnecessary inline function ary_elt.
And the function does not conform the naming convention anyway.
2017-08-11 12:57:37 +09:00
Yukihiro "Matz" Matsumoto 67e2dddb82 Remove mrb_ary_len function. Use RARRAY_LEN instead. 2017-08-11 12:52:36 +09:00
Yukihiro "Matz" Matsumoto 8f6b2121d9 Update document comment of array C API functions. 2017-08-11 12:51:45 +09:00
Yukihiro "Matz" Matsumoto 4e2f4f4280 Avoid possible data loss by using ptrdiff_t. 2017-08-11 12:12:11 +09:00
Yukihiro "Matz" Matsumoto ae04005092 The type of ARY_EMBED_LEN should be mrb_int. 2017-08-11 12:09:37 +09:00
Yukihiro "Matz" Matsumoto 3e075a7b6c Should not call to_str in mrb_vformat; fix #3773 2017-08-11 09:21:47 +09:00
Yukihiro "Matz" Matsumoto 68470bef86 Check method existence in `to_enum'; ref #3773 2017-08-11 09:21:09 +09:00
Christopher Aue 2249551c63 Fixed calling missing method through super with 126 args 2017-08-10 23:26:39 +02:00
Yukihiro "Matz" Matsumoto ac42ccc1fc Merge pull request #3772 from vvakame/add2authors
Updated AUTHORS
2017-08-10 09:50:08 +09:00
vvakame a8658b0f2c Updated AUTHORS 2017-08-10 09:21:40 +09:00
Yukihiro "Matz" Matsumoto a7462a7f42 Remove redundant flo_hash function.
`flo_hash` implemented `15.2.8.3.18` but `Kernel#hash` (15.3.1.3.15)
now works for numbers.
2017-08-10 08:47:01 +09:00
Yukihiro "Matz" Matsumoto 3d288ef0d8 Use standard hash functions in mrb_hash_ht_hash_func. 2017-08-10 08:47:01 +09:00
Yukihiro "Matz" Matsumoto 78be0172f7 Normalize float numbers before calculating a hash value. 2017-08-10 08:36:09 +09:00
Yukihiro "Matz" Matsumoto 9826ca54f2 VM stack may be reallocated during mrb_hash_get; fix #3771 2017-08-10 08:21:43 +09:00
Yukihiro "Matz" Matsumoto 9e0c48ddc6 Merge pull request #3770 from christopheraue/tabs_to_spaces
Replaced tabs with spaces
2017-08-10 07:59:49 +09:00
Christopher Aue 2fadddcd20 Replaced tabs with spaces 2017-08-09 21:56:27 +02:00
Yukihiro "Matz" Matsumoto 24c345fe5c Merge branch 'vvakame-add-hash-compact' 2017-08-09 21:21:31 +09:00
Yukihiro "Matz" Matsumoto 6c61a60609 Implement Hash#compact! in C; ref #3769 2017-08-09 21:20:50 +09:00
vvakame 4d46f366ac add method(compact, compact!) and test of Hash to mruby-hash-ext 2017-08-09 19:18:02 +09:00
Yukihiro "Matz" Matsumoto f9c3ebd29d Wrong blkargs pos for vararg; ref #3768 2017-08-09 15:23:20 +09:00
Yukihiro "Matz" Matsumoto 0a61df1c34 The block argument offset saved in the env was wrong; fix #3768
When the method takes variable number of argument (`argc = -1`),
the block argument offset should be `-1` not `0`.
2017-08-09 12:57:55 +09:00
Yukihiro "Matz" Matsumoto 8f62957888 Support break within rescue clauses; fix #3767 ref #3721 2017-08-09 12:25:20 +09:00
Yukihiro "Matz" Matsumoto 66e2928bd4 Float values divided by zero should honor signs; fix #3766
It also fixes unexpected resurrection of #3745 by #3752
2017-08-08 02:13:11 +09:00
Yukihiro "Matz" Matsumoto 8494557006 Set the current pc as the error position in OP_ERR; ref #3765 2017-08-08 01:55:46 +09:00
Yukihiro "Matz" Matsumoto e910cf6169 Check if ptr is NULL before calling memset; fix #3765 2017-08-08 01:54:43 +09:00
Yukihiro "Matz" Matsumoto 1358725738 Merge pull request #3764 from christopheraue/new_hash_perf
Improved speed of creating new hash tables
2017-08-07 01:48:39 +09:00
Christopher Aue ec7475d88b Prevented resizing just created hashes in specific size ranges 2017-08-05 20:59:26 +02:00
Christopher Aue 0e5c3c4ebd Improved speed of creating new hash tables 2017-08-04 22:08:29 +02:00
Yukihiro "Matz" Matsumoto 1b9c4855a3 proc->body.irep may be NULL; fix #3761 2017-08-05 01:28:11 +09:00
Yukihiro "Matz" Matsumoto 006661394d Fixed heap buffer overflow in mrb_ary_unshift_m; fix #3760 2017-08-05 01:18:52 +09:00
Yukihiro "Matz" Matsumoto 36dbfd9bda Change return type of scan_oct from int to int32_t. 2017-08-05 01:06:36 +09:00
Yukihiro "Matz" Matsumoto e86c252a99 Left shift of signed integers is undefined behavior in C; fix #3762 2017-08-05 01:06:36 +09:00
Yukihiro "Matz" Matsumoto 8095754e28 Merge pull request #3763 from mimaki/fix-mrdb-source-path
Fixed a invalid source path name on mruby debugger.
2017-08-04 23:41:14 +09:00
Hiroshi Mimaki 7bdc709da0 Fixed a invalid source path name on mruby debugger. 2017-08-04 17:25:03 +09:00
Yukihiro "Matz" Matsumoto 7b88c1a8e5 Now local_variables works when for closures; fix #3710 2017-08-02 07:44:58 +09:00
Yukihiro "Matz" Matsumoto da24af34b9 Better class name management.
The change removes several internal instance variables used by
class name management. The variables `__classid__` and `__classpath__`
are no longer available. `__outer__` is used only for unnamed outer
classes/modules (and will be removed after they are named).

[Important note]
Along with this change we removed several public functions.

 - mrb_class_outer_module()
 - mrb_class_sym()

We believe no one have used those functions, but if you do, please
ask us for the workaround.
2017-08-01 22:25:49 +09:00
Yukihiro "Matz" Matsumoto 2170fad406 Cosmetic changes (removing spaces before * in return types). 2017-08-01 16:31:18 +09:00
Yukihiro "Matz" Matsumoto 648e9ea51b Move naming unnamed classes/modules
From `mrb_mod_const_set` to `mrb_const_set`.
2017-08-01 16:25:09 +09:00
Yukihiro "Matz" Matsumoto 3f6a098626 Reimplement constant look-up rule to follow lexical scoping.
This update fix CRuby scoping incompatibility; close #600; close #3200
2017-08-01 15:57:32 +09:00
Yukihiro "Matz" Matsumoto 9e10afe1d0 Implements `Module::nesting' (15.2.2.3.2); ref #600, #3200 2017-08-01 15:37:21 +09:00
Yukihiro "Matz" Matsumoto 16aafdd866 Merge pull request #3759 from christopheraue/authors_update
Updated AUTHORS
2017-07-31 07:27:04 +09:00
Yukihiro "Matz" Matsumoto facf5f99d4 Merge pull request #3758 from christopheraue/enumeration_perf
Improved speed of enumeration methods
2017-07-31 07:26:46 +09:00
Christopher Aue a4ff31eaf6 Updated AUTHORS 2017-07-30 16:19:24 +02:00
Christopher Aue 3359b86ec7 Improved speed of enumeration methods 2017-07-30 13:19:31 +02:00
Yukihiro "Matz" Matsumoto c8fdab8725 Merge branch 'udzura-move-task-class-definitions' 2017-07-29 07:15:10 +09:00
Yukihiro "Matz" Matsumoto e821c25d38 Merge branch 'move-task-class-definitions' of https://github.com/udzura/mruby into udzura-move-task-class-definitions 2017-07-29 07:09:53 +09:00
Yukihiro "Matz" Matsumoto b290e98f3b Merge pull request #3757 from christopheraue/module_const_get_class_path
Extended Module#const_get to support class paths
2017-07-29 07:05:37 +09:00
Yukihiro "Matz" Matsumoto cf23a85333 Merge pull request #3755 from christopheraue/array_bsearch_index
Added Array#bsearch_index
2017-07-29 07:01:53 +09:00
Yukihiro "Matz" Matsumoto dda73da640 Merge pull request #3756 from christopheraue/fix_mod_include_ret_val
Fixed return value of Module#include and #prepend
2017-07-29 06:53:06 +09:00
Christopher Aue a3bfd735a0 Added Array#bsearch_index 2017-07-28 23:51:49 +02:00
Christopher Aue 451574f142 Refactored Array#bsearch 2017-07-28 23:51:40 +02:00
Christopher Aue f937af5745 Extended Module#const_get to support class paths 2017-07-28 23:19:49 +02:00
Christopher Aue c7018ea962 Added mrb_str_index to the mrb API 2017-07-28 21:07:20 +02:00
Christopher Aue b499ad6749 Fixed return value of Module#include and #prepend 2017-07-28 17:38:40 +02:00
Christopher Aue 8a6ce74b4d Tested Array#bsearch more thoroughly 2017-07-28 17:15:35 +02:00
Yukihiro "Matz" Matsumoto 4696093673 Rename MRB_SEGMENT_SIZE to MRB_IV_SEGMENT_SIZE. 2017-07-27 16:14:03 +09:00
Yukihiro "Matz" Matsumoto 1e41026b28 Always use MRB_USE_IV_SEGLIST. 2017-07-27 16:14:03 +09:00
Yukihiro "Matz" Matsumoto f26d00d9e8 Embed small size array elements in the heap.
It reduces the memory consumption and sometimes improve the
performance as well.  For example, the consumed memory size
of `bench/bm_ao_render.rb` is reduced from 1.2GB to 1GB, and
its total execution time become 18.795 sec from 22.229 sec.
2017-07-27 16:13:06 +09:00
Yukihiro "Matz" Matsumoto 5d44f8582e Remove loop from OP_POPERR. 2017-07-27 10:30:43 +09:00
Yukihiro "Matz" Matsumoto 7d5cf8749a (0).div(0.0) should be NaN; fix #3754 2017-07-26 15:48:50 +09:00
Yukihiro "Matz" Matsumoto 46ab8fdf07 (0.0).div(0) should not be infinity; fix #3753 2017-07-25 15:28:41 +09:00
Yukihiro "Matz" Matsumoto 9fa3d77114 0/0 should not be infinity; fix #3752 2017-07-25 15:11:31 +09:00
Yukihiro "Matz" Matsumoto 7b8d784040 Reimplement sort method to reduce array copying. 2017-07-25 14:42:38 +09:00
Yukihiro "Matz" Matsumoto 7f9e333647 Should not update @objs from mruby-bin-mruby mrbgem.rake; fix #3751 2017-07-24 16:53:20 +09:00
Yukihiro "Matz" Matsumoto 308341b990 Clear mrb_callinfo struct by zero initializer. 2017-07-24 16:47:11 +09:00
Yukihiro "Matz" Matsumoto 1fc9a3019d Initialize potentially uninitialized local variable. 2017-07-24 16:46:27 +09:00
Yukihiro "Matz" Matsumoto 1c360965e7 Need to unshare env on OP_R_BREAK too. 2017-07-21 10:57:21 +09:00
Yukihiro "Matz" Matsumoto 5fee3f5869 Move NULL check to mrb_env_unshare(); ref #3750 2017-07-21 10:14:15 +09:00
Yukihiro "Matz" Matsumoto e2c9a30571 Should not raise LocalJumpError on funcall'ed frame; fix #3750 2017-07-21 07:17:21 +09:00
Yukihiro "Matz" Matsumoto 04c21d9d6b Merge pull request #3749 from christopheraue/fix_spec_rbfiles
Fixed setting custom rbfiles in gemspec
2017-07-20 23:14:34 +09:00
Yukihiro "Matz" Matsumoto 25a0a6b038 Need to patch OP_GETUPVAR and OP_SETUPVAR; fix #3732 2017-07-20 22:47:20 +09:00
Christopher Aue 5a9eedf541 Fixed setting custom rbfiles in gemspec 2017-07-19 19:46:36 +02:00
Yukihiro "Matz" Matsumoto aa3cb0466e Avoid C undefined behavior of division by zero; close #3745 2017-07-19 09:49:41 +09:00
Yukihiro "Matz" Matsumoto ca2cfc6fe9 Merge pull request #3746 from christopheraue/mod_singleton_class_p
Implemented Module#singleton_class?
2017-07-19 09:08:11 +09:00
Yukihiro "Matz" Matsumoto 645b0fb58c Merge branch 'christopheraue-const_set_mod_to_s' 2017-07-19 09:03:51 +09:00
Yukihiro "Matz" Matsumoto 14a72b0800 Avoid constant-set duplication; ref #3747 2017-07-19 09:03:07 +09:00
Yukihiro "Matz" Matsumoto a8bffdae50 Merge branch 'const_set_mod_to_s' of https://github.com/christopheraue/mruby into christopheraue-const_set_mod_to_s 2017-07-19 08:58:06 +09:00
Christopher Aue 468cc34c93 Fixed Module#to_s and #name for #const_set modules 2017-07-18 22:55:37 +02:00
Christopher Aue dd52b88101 implemented Module#singleton_class? 2017-07-18 20:47:05 +02:00
Yukihiro "Matz" Matsumoto 329938ef15 Simplify mrb_gc_arena_restore() to reduce overhead.
It will no longer shrink arena region. Instead `vm.c` uses
a static function `mrb_gc_arena_shrink()` to shrink.
2017-07-18 23:26:36 +09:00
Yukihiro "Matz" Matsumoto 52aafcd001 Merge pull request #3743 from christopheraue/sprintf_d_tests
added tests for #3736
2017-07-17 09:17:24 +09:00
Yukihiro "Matz" Matsumoto 59eaad9d78 Merge pull request #3742 from christopheraue/iter_exp_tests
added basic tests for while/until/break/next
2017-07-17 09:16:25 +09:00
Christopher Aue 2730231e50 added tests for #3736 2017-07-16 22:34:23 +02:00
Christopher Aue 8fe2a6ce0f added basic tests for while/until/break/next 2017-07-16 22:25:48 +02:00
Yukihiro "Matz" Matsumoto 515a093213 Add Hash#transform_keys! and Hash#transform_values. 2017-07-15 08:51:35 +09:00
Yukihiro "Matz" Matsumoto d7fef24a95 Use keys.each instead of unstable each_keys. 2017-07-15 08:50:52 +09:00
Yukihiro "Matz" Matsumoto 460d628490 Remove duplication in mruby-hash-ext test. 2017-07-14 16:10:26 +09:00
Yukihiro "Matz" Matsumoto 1c02b8558f Avoid duplicated width filling for sprintf %d specifier; fix #3736 2017-07-14 15:21:11 +09:00
Yukihiro "Matz" Matsumoto de3edcc170 Add Hash#transform_{keys,values} to mruby-hash-ext. 2017-07-14 15:13:41 +09:00
Yukihiro "Matz" Matsumoto bad807e7f0 Use floor() to implement round() on WIN32 platform.
This change was suggested by Akira Kakuto.
2017-07-13 20:32:34 +09:00
Yukihiro "Matz" Matsumoto 70e99d6b57 Define round() only on WIN32 platform; fix #3741 2017-07-13 00:09:31 +09:00
Yukihiro "Matz" Matsumoto 7fa9321c18 while|until should have the value from break; fix #3735 2017-07-12 14:56:48 +09:00
Yukihiro "Matz" Matsumoto e5fbe350b3 Avoid float operation to shrink arena buffer size. 2017-07-12 14:52:03 +09:00
Yukihiro "Matz" Matsumoto 9501b18362 Add inline modifier to cipush() and cipop() functions. 2017-07-12 14:50:44 +09:00
Yukihiro "Matz" Matsumoto a18904a4c2 Use "$!" specifier of mrb_get_args. 2017-07-12 14:49:55 +09:00
Yukihiro "Matz" Matsumoto e9b57124a0 Update mrb_get_args() document. 2017-07-12 14:49:06 +09:00
Yukihiro "Matz" Matsumoto adf453a584 Add "*!" argument specifier to avoid stack copying. 2017-07-12 14:48:23 +09:00
Yukihiro "Matz" Matsumoto 059d707e3a Add ary_modify_check() to Array#unshift; ref #3737 2017-07-12 14:44:36 +09:00
Yukihiro "Matz" Matsumoto e1de86134d Merge pull request #3740 from christopheraue/fix_test_output
fixed printing failed assertions
2017-07-12 08:24:02 +09:00
Christopher Aue 495a2e605d fixed printing failed assertions 2017-07-11 12:53:48 +02:00
Yukihiro "Matz" Matsumoto fc666bfe20 POSFIXABLE and NEGFIXABLE should take one argument. 2017-07-11 09:02:24 +09:00
Yukihiro "Matz" Matsumoto 46dee5716f Resurrect POSFIXABLE and NEGFIXABLE; ref 9186828 2017-07-10 09:42:48 +09:00
Yukihiro "Matz" Matsumoto 01fce3dc35 Merge pull request #3739 from ksss/array-shift
Should only check frozen fix #3737
2017-07-09 19:58:11 +09:00
ksss bf48473cf6 Should only check frozen for Array#pop 2017-07-09 18:05:21 +09:00
ksss c76dc33116 Add frozen test for Array#shift 2017-07-09 17:53:12 +09:00
ksss e581f2ed97 Should only check frozen fix #3737 2017-07-09 17:47:10 +09:00
Yukihiro "Matz" Matsumoto ce6c05600a Add fallback definitions of DBL_EPSILPN and LDBL_EPSILON; fix #3733
This is a workaround for mingw-w64 (5.3.1) bug.
2017-07-07 22:47:49 +09:00
Yukihiro "Matz" Matsumoto 718a9ceb6e Reduce allocation size of backtrace arrays. 2017-07-06 09:33:53 +09:00
Yukihiro "Matz" Matsumoto 542f0f7b16 Avoid out-of-bounds access of the backtrace array. 2017-07-06 09:32:28 +09:00
Yukihiro "Matz" Matsumoto 91868286be FIXABLE_FLOAT() fails sometimes in MRB_INT64 environment. 2017-07-06 09:05:46 +09:00
Yukihiro "Matz" Matsumoto cc04f03393 print("%d", 0) should not print -0; fix #3731 2017-07-05 23:31:50 +09:00
Yukihiro "Matz" Matsumoto 2ef5d22b60 Put a space between error position and error message.
For readability's sake.
2017-07-05 18:34:27 +09:00
Yukihiro "Matz" Matsumoto b68e7a605c Negation was not a good way to handle negative integers; fix #3729
There's a number that negation does not work (-2147483648 in 32bit
environment).
2017-07-05 18:13:37 +09:00
Yukihiro "Matz" Matsumoto b643a1a8bc In Ruby, sprintf specifier %u should behave as %d; fix #3730
Since there's no unsigned integer in Ruby. Binary, octal and
hexadecimal negative numbers can be represented by using 2's
compliment. But decimal (not being power of 2) cannot be use
that kind of format.
2017-07-05 17:48:40 +09:00
Yukihiro "Matz" Matsumoto bd66c5d716 Check stack size before accessing env stack; fix #3727 2017-07-05 09:19:06 +09:00
Yukihiro "Matz" Matsumoto cc01dedc65 Avoid undefined behavior of left shifting negative integer; #3728 2017-07-05 03:11:39 +09:00
Yukihiro "Matz" Matsumoto c377d504f6 Avoid undefined behavior of signed integer overflow; fix #3728 2017-07-05 03:11:39 +09:00
Yukihiro "Matz" Matsumoto c6bd8ceab7 Merge pull request #3726 from mruby/stable
mruby-1.3.0
2017-07-04 15:46:38 +09:00
Yukihiro "Matz" Matsumoto e9cdc88008 Refactor sprintf() code. 2017-07-04 08:50:39 +09:00
Yukihiro "Matz" Matsumoto 31bc2b0009 Initialize flags for each loop. 2017-07-04 08:46:33 +09:00
Yukihiro "Matz" Matsumoto 9b8956cdd0 break should not cross fiber-context boundary; fix #3724 2017-07-01 12:45:27 +09:00
Yukihiro "Matz" Matsumoto 7d99830211 super may be called from a block; fix #3723 2017-07-01 12:45:27 +09:00
Yukihiro "Matz" Matsumoto 466a18b0d3 Remove redundant use of Object#to_s in interpolation. 2017-06-28 23:28:24 +09:00
Yukihiro "Matz" Matsumoto aee1476ebd Provide better way to check compile errors.
Now you can just call `mrb_load_*` functions then check
`context->parser_nerr > 0` if the return value is `undef`,
instead of calling `mrb_parse_*` functions independently.
ref #3248 #3331
2017-06-28 16:04:40 +09:00
Yukihiro "Matz" Matsumoto 15945e14b9 Revert "Make mrb_load_exec a static function."
This reverts commit 7944d9a6d4.
Because it voids #3248 and #3331. But we should add better way
to check whether compile errors occur without duplicated callings.
2017-06-28 16:00:59 +09:00
Yukihiro "Matz" Matsumoto f0abd4241f Avoid mrb_funcall() unless absolutely necessary; ref #3722
As a result, `#chr` is not called for ch < 0x80, so we need to
update the "invalid chr" test.
2017-06-28 12:03:53 +09:00
Yukihiro "Matz" Matsumoto 3554a41a54 Remove unnecessary initialization of a local variable. 2017-06-27 22:48:06 +09:00
Yukihiro "Matz" Matsumoto 877e16501c No longer need to copy argv from mrb_get_args; ref #3722 2017-06-27 22:47:26 +09:00
Yukihiro "Matz" Matsumoto 1a3b32343e Copy argv from VM stack to avoid use-after-free; fix #3722 2017-06-27 22:43:37 +09:00
Yukihiro "Matz" Matsumoto b30eba6a13 Make LocalJumpError a subclass of ScriptError.
It's incompatible with CRuby, but it is required for mruby because
it cannot detect `break` outside of loops in the parsing time, but
in the code generation time where it cannot raise `SyntaxError`.
2017-06-23 18:08:38 +09:00
Yukihiro "Matz" Matsumoto d0717efda6 Should raise an exception if break called in ensure; fix #3721 2017-06-23 18:08:04 +09:00
Yukihiro "Matz" Matsumoto 7944d9a6d4 Make mrb_load_exec a static function. 2017-06-23 17:56:12 +09:00
Yukihiro "Matz" Matsumoto 9a59cd7af8 Silence mrbmemcpy and mrbmemset warnings. 2017-06-23 17:54:02 +09:00
Yukihiro "Matz" Matsumoto b200c7475a No need to mark stacks of terminated fibers; fix #3720 2017-06-22 02:05:14 +09:00
Yukihiro "Matz" Matsumoto c41e262667 Add write barrier to protect singleton class from GC; fix #3717 2017-06-22 01:20:22 +09:00
Yukihiro "Matz" Matsumoto af0bef6dd8 Silence rubocop warnings. 2017-06-22 00:27:17 +09:00
Yukihiro "Matz" Matsumoto e8a4e4262a Add write barrier to protect proc reference from fiber; fix #3719 2017-06-21 17:59:14 +09:00
Yukihiro "Matz" Matsumoto 464d3fc0a3 Use alias enum_for to_enum instead of alias :enum_for :to_enum. 2017-06-21 11:13:43 +09:00
Yukihiro "Matz" Matsumoto 057be5ffb5 use unless instead of if not. 2017-06-21 11:13:33 +09:00
Yukihiro "Matz" Matsumoto d0a7e01d9c Should call ecall() before callinfo adjustment; fix #3715 2017-06-21 02:51:55 +09:00
Yukihiro "Matz" Matsumoto bf1cb87b34 Array size can be cause integer overflow; fix #3710 2017-06-20 20:19:37 +09:00
Yukihiro "Matz" Matsumoto 39779b339e Merge pull request #3718 from miura1729/original
#3711 fix
2017-06-20 16:18:07 +09:00
Miura Hideki 0fa94f9ead #3711 fix 2017-06-20 12:50:00 +09:00
Yukihiro "Matz" Matsumoto 615e7e44e3 Avoid using snprintf(3) in case MRB_DISABLE_STDIO; fix #3714 2017-06-20 09:39:33 +09:00
Yukihiro "Matz" Matsumoto 455f3954dc Merge pull request #3713 from Asmod4n/patch-2
Save gc_arena after buffer got allocated
2017-06-20 09:16:38 +09:00
Asmod4n abca63c73b Save gc_arena after buffer got allocated
Latest fix was freeing the buffer while it was still in use.
Fixes #3712
2017-06-19 20:27:38 +02:00
Tomoyuki Sahara 04774e5bf2 remove unused exception variables. 2017-06-15 11:00:26 +09:00
Tomoyuki Sahara 7c62d89348 Merge pull request #88 from christopheraue/master
Fix for IO#read(n) with n > IO::BUF_SIZE
2017-06-15 10:53:01 +09:00
Christopher Aue 3642fe4013 fixed #87: IO#read(n) with n > IO::BUF_SIZE 2017-06-13 21:40:36 +02:00
Tomoyuki Sahara 81a0dcdb7a sizeof(optval) must be 1 for IP_MULTICAST_TTL & IP_MULTICAST_LOOP. fixes #34. 2017-06-13 12:13:04 +09:00
Tomoyuki Sahara fe99819bc9 Merge pull request #85 from ksss/read
Support outbuf argument for IO#read
2017-06-12 16:17:53 +09:00
Tomoyuki Sahara c279f00109 Merge pull request #86 from ksss/write
Reseek when write
2017-06-12 16:15:31 +09:00
Tomoyuki Sahara 0b41066e83 Merge pull request #84 from ksss/pos
To accurate `pos`
2017-06-12 15:43:44 +09:00
ksss 051d7bc8db Reseek when write 2017-06-12 09:57:18 +09:00
ksss 1ebe1c8b1f Support outbuf argument for IO#read 2017-06-12 09:43:02 +09:00
ksss 27f422880f To accurate pos
pos shouldn't cache because it's not controllable
2017-06-11 23:22:04 +09:00
Tomoyuki Sahara 3a73a58493 mruby 1.2.0 assumes test blocks return their results. master does not. 2017-06-07 11:36:37 +09:00
Tomoyuki Sahara 383a9c79e1 Merge pull request #13 from ksss/unpack-utf8
Support unpack template "U"
2017-06-07 11:09:43 +09:00
Tomoyuki Sahara dab87cf960 Merge pull request #80 from ksss/sysread
IO#sysread Check for readable
2017-06-05 16:21:30 +09:00
ksss a3a4f4d061 IO#sysread Check for readable 2017-05-27 13:34:11 +09:00
Tomoyuki Sahara 0c0b34136e Merge pull request #78 from ksss/syswrite
Should raise SyscallError on IO#syswrite
2017-05-23 15:09:04 +09:00
Tomoyuki Sahara 87771ecf92 Merge pull request #79 from ksss/ioerror
Fix some spec for IO#sysread
2017-05-23 15:06:15 +09:00
ksss 0bbd60b523 IO#sysread should raise error when invalid pos 2017-05-22 11:47:45 +09:00
ksss 86edc9ab85 IO#sysread should raise IOError when closed 2017-05-21 22:54:46 +09:00
ksss 844b2c368f IO#sysread with 0 always return empty string 2017-05-21 22:54:12 +09:00
ksss c43795c664 Should raise SyscallError on IO#syswrite
instead of IOError
2017-05-21 17:10:15 +09:00
Tomoyuki Sahara 6836f424c5 "open" error message should include pathname. fixes #77. 2017-05-19 17:14:43 +09:00
Tomoyuki Sahara 728d313b2c Merge pull request #76 from yyamano/issue-75
Make backquote work with the latest mruby. Fixed #75
2017-04-25 11:19:07 +09:00
Yuji Yamano 311f4a230f Make backquote work with the latest mruby. Fixed #75 2017-04-24 02:40:01 -04:00
Tomoyuki Sahara 7e014efe45 Merge pull request #14 from ksss/to_int
Should use `to_int` instead of `to_i`
2017-04-06 10:25:06 +09:00
Uchio KONDO 38db5e550f Some adjustments 2017-04-04 12:16:53 +09:00
Uchio KONDO 9c2db2e134 Move class/module definitions to normal .rb files 2017-04-04 12:03:43 +09:00
Uchio KONDO 86b69d7c5d Initial skelton for class/module def 2017-04-04 11:57:17 +09:00
ksss d83e15e866 Should use to_int instead of to_i
For CRuby compatibility
2017-04-04 11:19:43 +09:00
ksss 0dbd1d5992 Add "U" template to doc 2017-04-04 11:07:15 +09:00
ksss f691a73c26 Should raise RangeError 2017-04-04 11:07:14 +09:00
ksss a80a745b69 Support unpack template "U" 2017-04-04 10:06:30 +09:00
Tomoyuki Sahara f8a3af8086 Merge pull request #74 from iij/run-test-outside-source-tree
run mrbtest outside of source tree.
2017-02-28 12:34:15 +09:00
Tomoyuki Sahara 3ae5fea2b8 run mrbtest outside of source tree. 2017-02-28 12:10:51 +09:00
Tomoyuki Sahara 74fe87c289 Add a travis-ci badge. 2017-02-17 10:33:11 +09:00
Tomoyuki Sahara 86d58a2d37 File class does not have to include Enumerable.
Because IO class, which is the superclass of File class, includes it.
2017-02-10 11:22:52 +09:00
Tomoyuki Sahara 88a7fedea4 support "x". 2017-02-09 11:07:55 +09:00
Tomoyuki Sahara 3dad125a1c TCPSocket.new supports "local_host" and "local_service". 2017-02-08 19:04:11 +09:00
Tomoyuki Sahara caab1c203c define IO#hash to override Enumerable#hash. fixes #73.
Current implementation of Enumerable#hash calls #each to collect
hash values of enumerated objects (then calculates the hash value
of the Enumerable object).  But IO#each is a method to read lines.
It is not expected that IO#hash reads all lines from the IO object.
Or even worse, program waits for the IO object to be readable if
it is a socket or something cannot be read immediately.
2017-02-08 18:31:50 +09:00
Tomoyuki Sahara 69623078a8 Merge pull request #72 from masahino/add_pointer_casting
Add pointer casting
2016-12-26 09:12:19 +09:00
masahino 1fac605e3f Add pointer casting 2016-12-24 23:32:44 +09:00
Tomoyuki Sahara 458b517c6f Merge pull request #71 from eagletmt/readlink
Add File.readlink
2016-12-19 09:03:13 +09:00
Kohei Suzuki b31b8022db Fix memory leak in error case 2016-12-17 16:48:02 +09:00
Kohei Suzuki d1c48192cb Add File.readlink 2016-12-17 15:03:52 +09:00
Tomoyuki Sahara 7e89736291 Merge pull request #70 from eagletmt/chmod
Add File.chmod
2016-12-16 22:54:20 +09:00
Kohei Suzuki 698378f076 Add File.chmod 2016-12-16 01:20:08 +09:00
Tomoyuki Sahara f2d4880098 Merge pull request #11 from masahino/add_casting
Add pointer casting
2016-12-12 06:51:03 +09:00
masahino 906b516cfa Add pointer casting 2016-12-09 21:57:06 +09:00
Tomoyuki Sahara 0eafb089c9 Merge pull request #69 from eagletmt/explicit-cast
Add explicit cast from void* to struct mrb_io*
2016-11-27 13:53:50 +09:00
Kohei Suzuki 905203ef5e Add explicit cast from void* to struct mrb_io*
For compatibility with C++.
2016-11-26 14:18:28 +09:00
Tomoyuki Sahara b5e2dc9097 raise an exception when we cannot close "fd" but can close "fd2". 2016-10-13 16:57:38 +09:00
Tomoyuki Sahara f6a82772e6 eof? should raise an IOError if it is not opened for reading. 2016-09-30 17:10:55 +09:00
Tomoyuki Sahara 2229a2aa0f reimplement #eof. fixes #66. 2016-09-30 16:27:11 +09:00
Tomoyuki Sahara 51cf6b6048 Merge pull request #65 from ksss/join
Support Array argument
2016-09-13 09:57:05 +09:00
ksss ff845be72c Support Array argument 2016-09-11 22:01:45 +09:00
ksss 7c9d941003 Show value of expect and actual each assertion 2016-09-11 17:00:19 +09:00
Tomoyuki Sahara d8189c2b19 Merge pull request #64 from asfluido/master
Apparently, in mruby-process gem, Process is now a Module, not a Class
2016-08-10 09:12:44 +09:00
Carlo - PERI 024b09de0c Apparently, in mruby-process gem, Process is now a Module, not a Class 2016-08-09 11:23:49 +02:00
Tomoyuki Sahara b341ee7c12 Merge pull request #63 from ksss/opt
Enable option :in, :out, :err to IO.popen
2016-08-08 10:12:20 +09:00
Tomoyuki Sahara 9ccf03e5ae Merge pull request #62 from ksss/global
Should use global variable
2016-08-08 09:38:22 +09:00
ksss d2c1f4d10b Enable Fixnum option 2016-08-07 22:19:21 +09:00
ksss b462ef4506 Enable option :in, :out, :err 2016-08-07 21:21:01 +09:00
ksss 4cac5e9c70 Should use global variable 2016-08-06 23:11:31 +09:00
Tomoyuki Sahara cc66bf94d1 Merge pull request #9 from ksss/pointer-sign
Suppress compiler warning [-Wpointer-sign]
2016-07-19 09:45:32 +09:00
Tomoyuki Sahara 13650747e7 Merge pull request #10 from dabroz/master
Added 'U' pack support.
2016-07-19 09:44:14 +09:00
Tomasz Dąbrowski 26c1dedcab Added 'U' pack support. 2016-07-18 16:06:01 +02:00
ksss b9f7daf5b6 Suppress compiler warning [-Wpointer-sign] 2016-07-01 22:27:02 +09:00
Tomoyuki Sahara 93d481d4b4 update $? when IO object is closed. closes #58. 2016-06-22 10:29:49 +09:00
Tomoyuki Sahara e90ecff671 Merge pull request #60 from drbrain/test_io_setup_failure
Test io setup failure
2016-06-21 09:52:30 +09:00
Tomoyuki Sahara 2af2a4fff8 add IO#isatty and IO#tty? 2016-06-21 09:49:34 +09:00
Tomoyuki Sahara b2a0c9c6bf Merge pull request #30 from rhykw/tcpserver-reuseaddr
Use TCPServer SO_REUSEADDR
2016-05-30 10:42:30 +09:00
rhykw 4f6703203b TCPServer use SO_REUSEADDR if possible 2016-05-28 09:33:53 +09:00
rhykw 2a80cccf30 TCPServer use SO_REUSEADDR 2016-05-23 21:44:34 +09:00
Eric Hodel 11961b42ac Create socket in /tmp for security
Some systems do not allow UNIX sockets from arbitrary directories.
Instead of trying to `#define SOCKET_PATH` correctly I assume the /tmp/
directory is accessible and use it.
2016-05-12 17:55:14 -07:00
Eric Hodel 777cf70cc5 Include reason in test failure message
I am seeing this test fail in some environments but can't determine why.
The extra information will help me determine the reason bind(2) is
failing.
2016-05-12 16:02:09 -07:00
Tomoyuki Sahara 18f7b45ad1 Merge pull request #29 from rmalizia44/patch-1
Add _WIN32_WINNT definition to Avoid Windows Compilation Errors
2016-01-30 22:39:20 +09:00
rmalizia44 be2ec608e2 Add _WIN32_WINNT definition to Avoid Windows Compilation Errors
the line #define _WIN32_WINNT 0x0501 will cause ws2tcpip.h to implement the missing functions freeaddrinfo, getaddrinfo and getnameinfo on windows
2016-01-28 03:28:05 -02:00
Tomoyuki Sahara 1c4428880b Merge pull request #57 from MaximAbramchuck/patch-1
Add installation instructions
2016-01-21 22:09:17 +09:00
Maxim Abramchuk 7d6f2beaaa Add installation instructions 2016-01-20 13:40:30 +03:00
Tomoyuki Sahara c165e50193 Merge pull request #28 from zzak/port-ntop-pton-win32
Port inet_ntop and inet_pton for WIN32
2016-01-18 16:12:35 +09:00
Tomoyuki Sahara a25ec0a749 Merge pull request #27 from zzak/fix-udpsock-warning
Fix warning: variable 'udpsock' set but not used
2016-01-18 16:09:55 +09:00
Zachary Scott bdc118304c Port inet_ntop and inet_pton for WIN32
Without these functions, compilation fails on MinGW
2016-01-18 15:34:26 +09:00
Zachary Scott c8a2c636e0 Fix warning: variable 'udpsock' set but not used 2016-01-18 15:27:32 +09:00
Tomoyuki Sahara 99e10b8dc4 File::ALT_SEPARATOR is always defined (some string or nil). 2015-12-08 16:44:13 +09:00
Tomoyuki Sahara 4acfd1c7d2 Merge pull request #56 from takahashim/fix-flock
Fix for windows(mingw)
2015-12-08 12:55:38 +09:00
takahashim dd754220ce Fix for windows(mingw)
* File.expand_path: support drive letter and ALT_SEPARATOR

* File.dirname: support ALT_SEPARATOR
* File.basename: ditto.

* IO.popen: raise NotImplementedError
* IO.pipe: ditto.
* `cmd`:  ditto.
* File#flock: ditto.
* FileTest.pipe?: ditto.
* FileTest.symlink?: ditto.
* FileTest.socket?: ditto.
2015-12-08 00:29:42 +09:00
Tomoyuki Sahara 68de1e4fc5 Merge pull request #55 from takahashim/separator
fix file separator
2015-12-07 16:00:46 +09:00
takahashim 0f5b8b66b0 fix file separator
* File::SEPARATOR should be "/"
* File::ALT_SEPARATOR should be "\\" or nil.
2015-12-04 15:36:41 +09:00
Tomoyuki Sahara 6c67120ed4 Merge pull request #54 from takahashim/win-crlf
fix tests for Win: use binary mode
2015-12-03 12:22:59 +09:00
takahashim b19c315148 fix tests for Win: use binary mode 2015-12-02 21:47:46 +09:00
Tomoyuki Sahara 7337bfa497 Merge pull request #53 from takahashim/build-win32
build on Win32
2015-12-02 10:13:15 +09:00
takahashim 07ceb138fa build on Win32 2015-12-02 00:10:43 +09:00
Tomoyuki Sahara 07f1ebd26d symlink(2) returns -1 when it fails. 2015-11-24 17:09:00 +09:00
Tomoyuki Sahara 11ffb93852 assert_nothing_raised is not available on mruby 1.0.0. 2015-11-24 17:00:12 +09:00
Tomoyuki Sahara ca495944b6 Merge pull request #51 from ksss/io-pipe
Implement IO.pipe
2015-11-24 16:49:34 +09:00
ksss a55accd736 Implement IO.pipe 2015-11-24 14:24:24 +09:00
Tomoyuki Sahara c9a4091b83 arguments can be shared strings. 2015-11-24 09:54:03 +09:00
Tomoyuki Sahara 1f4bd9fd9f Merge pull request #50 from takahashim/file-symlink
add File.symlink
2015-11-24 09:47:09 +09:00
takahashim 2cc674e58e add File.symlink 2015-11-22 13:13:52 +09:00
Tomoyuki Sahara 14cdff075d Merge pull request #48 from takahashim/file-path
add File.path
2015-11-22 07:12:23 +09:00
takahashim 44473fecdd add File.path 2015-11-21 22:03:40 +09:00
Tomoyuki Sahara 828551f86c off_t can be larger than mrb_int. 2015-10-20 16:03:02 +09:00
Tomoyuki Sahara db7d829679 raise a SystemCallError when lseek(2) fails. 2015-10-20 15:40:25 +09:00
Tomoyuki Sahara 21963f8fa1 UT for IO#sysseek. 2015-10-20 15:37:05 +09:00
Tomoyuki Sahara cac0035348 fix typo. 2015-10-20 15:16:46 +09:00
Tomoyuki Sahara 78fe65aec4 Merge branch 'master' of github.com:iij/mruby-io 2015-10-20 15:13:28 +09:00
Tomoyuki Sahara 71197d2737 Merge pull request #47 from matsumoto-r/patch-1
Fix buffer overflow of `pos` when file-size is too big
2015-10-19 19:33:09 +09:00
MATSUMOTO, Ryosuke 238704592a Fix buffer overflow of pos when file-size is too big 2015-10-19 19:24:39 +09:00
Tomoyuki Sahara e724c5af98 Merge pull request #45 from takahashim/enable-test
enable test
2015-09-28 12:25:33 +09:00
Tomoyuki Sahara 1f217ea82e Merge pull request #46 from takahashim/add-rewind
support IO#rewind
2015-09-28 12:24:51 +09:00
takahashim 9bbfc38bb4 add IO#rewind 2015-09-27 21:25:06 +09:00
Tomoyuki Sahara 1d6b7f9bba Merge pull request #44 from takahashim/io-addstr
support IO#<<
2015-09-27 21:15:54 +09:00
takahashim f5560e8f17 enable test 2015-09-27 01:39:11 +09:00
takahashim c26f998ed5 support IO#<< 2015-09-27 00:29:17 +09:00
Tomoyuki Sahara 625995424c To run test, we need "conf.enable_test" in build_config.rb. 2015-09-08 13:25:05 +09:00
Tomoyuki Sahara f3016752bd build in container-based environment. 2015-09-08 13:23:46 +09:00
Tomoyuki Sahara ecd7ef5924 Revert "try to fix failure on travis."
This reverts commit 02daa2509d.
2015-09-08 11:57:08 +09:00
Tomoyuki Sahara 02daa2509d try to fix failure on travis. 2015-09-08 10:44:08 +09:00
Tomoyuki Sahara 5fa3c39145 variables are not used on the platforms lack FD_CLOEXEC. 2015-08-27 09:56:17 +09:00
Tomoyuki Sahara 6c4d39412f Merge pull request #30 from ksss/cloexec
Opened fd should be set FD_CLOEXEC by default
2015-08-26 17:37:21 +09:00
Tomoyuki Sahara 042e4a4313 Merge pull request #43 from jkutner/master
Made FILE_SEPERATOR platform dependent
2015-08-21 09:20:32 +09:00
Joe Kutner 2467332c93 Made FILE_SEPERATOR platform dependent 2015-08-20 07:22:48 -05:00
Tomoyuki Sahara efaf74672e Merge pull request #42 from hone/path_separator
define PATH_SEPARATOR
2015-08-12 09:06:34 +09:00
Tomoyuki Sahara 5323498033 Merge pull request #23 from expeditiousRubyist/master
Changed Windows IO overrides to use sysread and syswrite instead
2015-08-10 10:36:14 +09:00
Tomoyuki Sahara e8efd10bd9 make pack_l simpler. 2015-08-07 11:51:01 +09:00
Tomoyuki Sahara 4603047eb1 update installation procedure. 2015-08-07 11:49:56 +09:00
Tomoyuki Sahara 359d2ae6fd support "q" and "Q". closes #7. 2015-08-07 11:48:45 +09:00
Tomoyuki Sahara d34db58797 implicit type conversion caused unexpected result. fixes #8. 2015-08-06 15:38:35 +09:00
unknown c43a08314e Changed IO overrides to use sysread and syswrite instead of read and write 2015-08-03 04:12:10 -07:00
Terence Lee ec4982b2d3 define PATH_SEPARATOR 2015-08-02 17:35:07 +02:00
Tomoyuki Sahara 8527c78fb5 Merge pull request #22 from Asmod4n/master
added SO_NOSIGPIPE
2015-07-28 09:00:31 +09:00
Asmod4n 2929c629d4 added SO_NOSIGPIPE 2015-07-27 18:42:22 +02:00
Tomoyuki Sahara de60400c64 Merge pull request #21 from expeditiousRubyist/master
Added functioning read for Win32
2015-07-25 20:09:20 +09:00
Rubyist f80a4fd0e8 Added functioning read for Win32 2015-07-25 00:24:31 -07:00
Tomoyuki Sahara 2d1134e9ea Merge pull request #41 from hone/cross_compile_windows
support for crossbuild for windows (32 bit and 64 bit) using mingw
2015-07-24 09:19:56 +09:00
Terence Lee fe7784efb0 support for crossbuild for windows (32 bit and 64 bit) using mingw 2015-07-23 12:39:05 -05:00
Tomoyuki Sahara bfb9cf7922 Merge pull request #20 from expeditiousRubyist/master
Win32 Port
2015-07-22 09:35:39 +09:00
Rubyist 4ab922044d Removed unnecessary/incorrect use of sizeof(int) and corrected more
improper usages of mrb_sys_fail
2015-07-21 15:56:27 -07:00
Rubyist 7ee9ab89f9 Changed some uses of mrb_sys_fail to instead use mrb_raise where
appropriate
2015-07-21 03:37:28 -07:00
Rubyist a426f0e2b5 Overrided close and write to work on Win32 platforms 2015-07-18 23:22:57 -07:00
Rubyist 752f7c1526 Minimal semi-working compile on Windows platforms. 2015-07-17 23:45:02 -07:00
Rubyist 7d8cbf1a9c Added Winsock 2 to list of libraries to use when building for Windows
targets
2015-07-17 23:03:34 -07:00
Tomoyuki Sahara 1b5c68567e Merge pull request #40 from archSeer/patch-1
Remove mrb_io_s_select typo.
2015-07-03 09:36:49 +09:00
Blaž Hrastnik 8da787be72 Remove mrb_io_s_select typo.
Uncovered with a Coverity scan of our project using mruby-io. https://scan8.coverity.com/reports.htm#v26153/p11375/fileInstanceId=6844382&defectInstanceId=2515905&mergedDefectId=121921
2015-07-02 21:02:56 +02:00
Tomoyuki Sahara b913e7eefd test suite for pack/unpack. 2015-05-22 11:38:56 +09:00
Tomoyuki Sahara 2ba4933158 refactor "AaZ". fixes #6. 2015-05-22 11:38:39 +09:00
Tomoyuki Sahara 15de80a7cd style. 2015-05-22 09:41:39 +09:00
Tomoyuki Sahara dacb8b626b failed to remove temporary files! 2015-05-20 11:38:03 +09:00
Tomoyuki Sahara ae4fc77675 Merge pull request #39 from jbreeden/master
Correct File::NULL for Windows
2015-04-18 06:50:32 +09:00
Jared Breeden 6d6be18d4e Removing redundant platform check 2015-04-17 15:45:14 -04:00
Jared Breeden 7f8324a2ed Merge branch 'master' of https://github.com/iij/mruby-io 2015-04-17 15:40:35 -04:00
Jared Breeden 36343cf098 Correct File::NULL for Windows 2015-04-17 15:39:11 -04:00
Jared Breeden c0738a74c6 Excluding wait call for windows 2015-04-05 17:21:02 -04:00
Tomoyuki Sahara cfbc8a8995 Merge pull request #38 from jbreeden/master
Excluding wait call for windows
2015-04-05 09:23:29 +09:00
Tomoyuki Sahara e92fd76248 wait for child processes when we close pipes. fixes #37. 2015-04-03 10:05:09 +09:00
Tomoyuki Sahara 1629e86063 add IPv6 constants defined in RFC3493. 2015-02-13 11:35:36 +09:00
Tomoyuki Sahara e4006cb53a Socket::Option requires iij/mruby-pack. 2014-12-26 16:12:41 +09:00
Tomoyuki Sahara 0d05a22602 don't call undefined method. fixes #15. 2014-12-26 16:00:50 +09:00
Tomoyuki Sahara 7b17158f88 remove unused variables. 2014-12-26 13:36:11 +09:00
Tomoyuki Sahara a09858af61 syscalls may return sockaddr shorter than sizeof(struct sockaddr) on Linux. 2014-12-26 13:27:39 +09:00
Tomoyuki Sahara a960a6f931 failed to add... 2014-12-26 11:19:53 +09:00
Tomoyuki Sahara 3a22166c67 debug UNIXSocket and UNIXServer. 2014-12-26 11:16:03 +09:00
Tomoyuki Sahara 3a97a453c4 rewrite IO.for_fd.
IO.for_fd should call IO#initialize to initialize the created object
properly.  It cannot be implemented in Ruby.
2014-12-26 11:09:07 +09:00
Tomoyuki Sahara c455544ee2 better error message. 2014-12-26 11:08:18 +09:00
Tomoyuki Sahara 1d1f273ca9 Merge pull request #35 from tmtm/fix-read-create-many-objects
FIX: IO#read create a large number of objects.
2014-12-18 11:33:06 +09:00
TOMITA Masahiro 42752bffce FIX: IO#read create a large number of objects. 2014-12-18 00:41:59 +09:00
Tomoyuki Sahara e7dbe6e87a Merge pull request #33 from iij/revert-32-fix-read-create-many-objects
Revert "FIX: IO#read create a large number of objects."
2014-12-17 13:39:59 +09:00
Tomoyuki Sahara e82c1d3f38 Revert "FIX: IO#read create a large number of objects." 2014-12-17 13:37:15 +09:00
Tomoyuki Sahara 50721e9bf8 Merge pull request #32 from tmtm/fix-read-create-many-objects
FIX: IO#read create a large number of objects.
2014-12-17 13:35:34 +09:00
TOMITA Masahiro 9b13a59a55 FIX: IO#read create a large number of objects. 2014-12-17 01:46:23 +09:00
Tomoyuki Sahara ee347f3417 Merge pull request #31 from tmtm/fix-sysread-segv
FIX: IO#sysread occurs SEGV
2014-12-16 09:07:45 +09:00
TOMITA Masahiro be9e203563 FIX: IO#sysread occurs SEGV 2014-12-15 20:24:01 +09:00
Tomoyuki Sahara 723db886e1 add Socket::Option#inspect
without this, mirb dies.
https://github.com/mruby/mruby/pull/2666
2014-12-12 12:38:43 +09:00
Tomoyuki Sahara 121475638d add "I" and "i". 2014-12-12 12:12:41 +09:00
Tomoyuki Sahara 2103bc99ba style 2014-12-12 12:12:19 +09:00
Tomoyuki Sahara 669fe705cc "i" and "I". 2014-12-12 12:01:58 +09:00
ksss e61c469724 IO.popen fd set close_on_exec flag by default 2014-12-04 10:25:03 +09:00
ksss 9439b981d8 Opened fd should be set FD_CLOEXEC by default 2014-12-04 10:25:03 +09:00
Tomoyuki Sahara d1fee5892a IO.sysopen does retry. closes #26. 2014-11-25 16:26:34 +09:00
Tomoyuki Sahara e7cd024498 Merge pull request #29 from sdottaka/fix-for-msvc
Fix broken build for Visual C++
2014-11-25 10:29:07 +09:00
sdottaka 24007b80b4 Fix broken build for Visual C++ 2014-11-22 17:48:59 +09:00
Tomoyuki Sahara a2f45bf8d1 Merge pull request #28 from ksss/file-size
Implement FileTest.size
2014-11-18 10:35:12 +09:00
ksss a44ada616e Implement FileTest.size
- File.size delegate to FileTest.size
- File.size more faster by reading i-node value
2014-11-16 14:55:45 +09:00
Tomoyuki Sahara 379c5a6d88 Merge pull request #25 from matz/gc_on_enfile
garbage collect when open(2) fails with ENFILE or EMFILE
2014-11-13 09:27:11 +09:00
Yukihiro "Matz" Matsumoto b50093ad28 garbage collect when open(2) fails with ENFILE or EMFILE 2014-11-13 01:50:46 +09:00
Tomoyuki Sahara 190264b3c8 Merge pull request #23 from jbreeden/master
Correcting E_NOTIMP_ERROR reference
2014-08-08 21:34:15 +09:00
Akito Mochizuki 0761b17245 update implemented methods table 2014-08-05 11:51:05 +09:00
jbreeden 9a2cbc4122 Correcting E_NOTIMP_ERROR reference 2014-08-03 16:45:46 -04:00
Tomoyuki Sahara e60951a305 add IO#sync and IO#sync= 2014-07-29 10:55:02 +09:00
Tomoyuki Sahara 1768ee02e5 remove extra ';'. 2014-07-22 23:55:25 +09:00
Tomoyuki Sahara 8c34a8d561 Merge pull request #22 from take-cheeze/fix_arg
Fix type of argument passed to mrb_get_args.
2014-07-22 15:30:57 +09:00
take_cheeze 689541d0fb Fix type of argument passed to mrb_get_args. 2014-07-19 21:37:13 +09:00
Tomoyuki Sahara 093f4e2cff mrb_voidp (and other macros) has gone. 2014-07-09 12:24:50 +09:00
Tomoyuki Sahara fa39825b1b refactor. 2014-07-09 10:01:33 +09:00
Tomoyuki Sahara 66a92240de Merge pull request #21 from dreamedge/add_close_on_exec
Add close on exec
2014-07-09 09:34:12 +09:00
dreamedge 78f5f98710 delete debug messages 2014-07-09 05:29:20 +09:00
dreamedge 7e689e8680 Add IO#close_on_exec=
and a test on test/io.rb
2014-07-08 15:56:56 +09:00
dreamedge 59b7c4eaf0 add IO.close_on_exec? 2014-07-07 12:47:53 +09:00
Tomoyuki Sahara 91c285fcfe regen. 2014-07-02 09:12:27 +09:00
Tomoyuki Sahara 04097348e8 more TCP options (for NetBSD). 2014-07-02 09:12:04 +09:00
Tomoyuki Sahara baa40ef2b1 sort. 2014-07-02 09:09:58 +09:00
Tomoyuki Sahara 9c3c267bef Merge pull request #14 from dreamedge/add_tcp_constants
Add TCP_* constants included in "netinet/tcp.h".
2014-07-02 09:08:47 +09:00
dreamedge f3c71cf5da Add TCP_* constants included in "netinet/tcp.h".
ex: TCP_NODELAY, TCP_CORK, ...
2014-07-02 00:30:10 +09:00
Tomoyuki Sahara ddfc4eb5ef IO#read(0) should return "" immediately. fixes iij/mruby-socket#13. 2014-06-19 09:57:08 +09:00
Tomoyuki Sahara 376af5bac3 re-implement TCPServer.accept. fixes #12. 2014-06-17 15:41:42 +09:00
Tomoyuki Sahara 5b65ca3ebb Merge pull request #5 from take-cheeze/float
Add full support of float templates.
2014-06-15 19:54:08 +09:00
take_cheeze 7b2611ea28 Update supported template list. 2014-06-14 13:25:00 +09:00
take_cheeze 8f4b7ac15c Support float/double unpacking. 2014-06-14 13:25:00 +09:00
take_cheeze 514450e891 Use PACK_FLAG_LITTLEENDIAN. 2014-06-14 13:25:00 +09:00
take_cheeze 7dc2b4f59f Implement g/f/F/G/d/D packing. 2014-06-14 13:24:59 +09:00
take_cheeze f4f968241b Add support of little endian float. 2014-06-14 13:24:49 +09:00
Tomoyuki Sahara a0c4ca2406 Merge pull request #4 from take-cheeze/raise_fix
Fix invalid raise format found with mruby-clang-plugin.
2014-06-14 07:51:42 +09:00
take_cheeze 1997420a7f Fix raise format found with mruby-clang-plugin. 2014-06-13 17:42:43 +09:00
Tomoyuki Sahara d894de86f4 fd2 is valid if fd2 >= 0. fixes #18. 2014-06-10 10:22:50 +09:00
Tomoyuki Sahara cb84ce30e7 no longer used. 2014-06-10 09:54:23 +09:00
Tomoyuki Sahara 9ee9c271d1 Merge pull request #20 from windwiny/patch-1
compatible 32 bit windows
2014-05-09 02:33:00 +09:00
windwiny dc61ef1c65 compatible 32 bit windows 2014-05-07 20:33:12 +08:00
Tomoyuki Sahara 077f39bd38 Merge pull request #19 from schmurfy/solaris_flock
raise an error for flock on solaris
2014-04-29 00:45:08 +09:00
Julien Ammous 9a1b25bdd8 raise an error for flock on solaris 2014-04-28 15:40:04 +02:00
Tomoyuki Sahara 5aeb99ad49 fix mrb_raisef usage. 2014-04-21 11:14:40 +09:00
Tomoyuki Sahara 9c00de59ce IO.for_fd can be written in Ruby. 2014-04-21 10:24:59 +09:00
Tomoyuki Sahara c46cb1b5eb more tests. 2014-04-21 10:02:25 +09:00
Tomoyuki Sahara e5f30f83ce IO#flush should raise an exception if it is closed. 2014-04-21 10:01:49 +09:00
Tomoyuki Sahara 99c67749ff remove return statements after mrb_raise(). 2014-04-21 09:06:46 +09:00
Tomoyuki Sahara 7d7a549a4f remove io_open(). 2014-04-18 11:32:38 +09:00
Tomoyuki Sahara 36045ea96f IO#syswrite should raise an error if it's not opened for writing. 2014-04-18 11:20:55 +09:00
Tomoyuki Sahara 1c4f46f324 remove standard header files from io.h. 2014-04-17 16:29:27 +09:00
Tomoyuki Sahara a11780f4f1 file.c depends on mruby/ext/io.h now. 2014-04-17 16:18:26 +09:00
Tomoyuki Sahara a3e1e535dc function declarations should be in a header file. 2014-04-17 16:13:18 +09:00
Tomoyuki Sahara 9f5ff9ddec remove unused constants. 2014-04-17 16:12:51 +09:00
Tomoyuki Sahara ba9cb1f757 "struct mrb_io_type" is not used at all. 2014-04-17 16:07:12 +09:00
Tomoyuki Sahara 10be4cbb2c file.c does not depend on mruby/ext/io.h. 2014-04-17 15:56:11 +09:00
Tomoyuki Sahara 87ce12dfe3 io.write("") -> 0 2014-04-17 15:53:51 +09:00
Tomoyuki Sahara 810e37b1c3 return value of syswrite may be less than length of given string. 2014-04-17 15:45:31 +09:00
Tomoyuki Sahara d5cf1de1ae Merge pull request #16 from schmurfy/solaris
solaris does not have flock
2014-04-11 06:53:34 +09:00
Tomoyuki Sahara 1d987d2fcd Merge pull request #9 from schmurfy/solaris
OpenSolaris/Illumos defines a "sun" constant...
2014-04-11 05:50:18 +09:00
Julien Ammous 9850e6a9d0 OpenSolaris/Illumos defines a "sun" constant... 2014-04-10 19:32:05 +02:00
Julien Ammous cd168c6f32 solaris does not have flock 2014-04-10 19:26:55 +02:00
Tomoyuki Sahara 28e00d82fb suppress compiler warnings. 2014-04-07 13:15:54 +09:00
Tomoyuki Sahara a6ab2c54f3 Merge pull request #15 from monami-ya-mrb/pr-add-error-check-in-test
Don't ignore the return value of symlink().
2014-04-05 11:55:51 +09:00
Masaki Muranaka 706ef1337a Don't ignore the return value of symlink(). 2014-04-05 10:44:47 +09:00
Akira Yumiyama 572b404935 Update .travis.yml 2014-04-04 11:32:42 +09:00
Akira Yumiyama 2bf49c9232 Update .travis.yml 2014-04-04 11:31:45 +09:00
Akira Yumiyama 083cd9ca8c Update .travis.yml 2014-04-04 11:31:33 +09:00
Akira Yumiyama 355723ebca Create .travis.yml 2014-04-04 11:27:56 +09:00
Akira Yumiyama 80e01e3659 Create .travis.yml 2014-04-04 11:27:14 +09:00
Akira Yumiyama 1094bbfff8 Create .travis.yml 2014-04-04 11:25:04 +09:00
Akira Yumiyama eda9d1a8fc nonexistent test fixes (for travis-ci) 2014-03-26 22:09:10 +09:00
Tomoyuki Sahara ab9dcc766e IO.close should be IO._sysclose. closes #13. 2014-03-26 17:22:57 +09:00
Tomoyuki Sahara 719452b8d2 remove unsed. 2014-03-14 10:47:54 +09:00
Tomoyuki Sahara 14031bdf44 Merge pull request #11 from pbosetti/master
Can build on VisualStudio, revised.
2014-03-14 10:41:56 +09:00
Tomoyuki Sahara 279587c138 split. 2014-03-12 09:44:34 +09:00
Tomoyuki Sahara a8558512ec mruby-mtest is not required to build (but to test). 2014-03-12 09:41:23 +09:00
Tomoyuki Sahara e345d4c68f Merge pull request #7 from monami-ya-mrb/pr-fix-connect-failed
Call Socket._connect() in Socket.connect() .
2014-03-11 23:25:29 +09:00
Masaki Muranaka 11b47459e7 Call Socket._connect() in Socket.connect() . 2014-03-11 21:18:05 +09:00
Paolo Bosetti 39bd240116 Fixed bug in File.expand_path() on Windows (forever recursive loop) 2014-03-07 16:47:18 +01:00
Paolo Bosetti 7ff049457f Added File.foreach method.
Improved error management in File.new (Errno can be undefined)
2014-03-04 10:43:46 +01:00
Paolo Bosetti d9f3fd868a Merge branch 'master' of https://github.com/iij/mruby-io into test
Conflicts:
	src/io.c
2014-03-03 13:15:57 +01:00
Tomoyuki Sahara f7c054bd39 quiet compiler. 2014-02-25 12:28:34 +09:00
Tomoyuki Sahara e8706d4ee7 remove unused. 2014-02-25 12:23:15 +09:00
Tomoyuki Sahara b9dff44582 Merge branch 'master' of github.com:iij/mruby-io 2014-02-25 12:20:52 +09:00
Tomoyuki Sahara 56a8c592dd add IO.read 2014-02-25 12:19:52 +09:00
Tomoyuki Sahara a90d8b8a73 add Socket.getaddrinfo. 2014-02-24 11:21:49 +09:00
Akira Yumiyama d28f042118 compatibility support (mruby/mruby, iij/mruby and 1.0.0)
- refs https://github.com/mruby/mruby/commit/36e234aa377d50d8ee425c7868e0651cf78e85cf
2014-02-22 20:45:07 +09:00
Tomoyuki Sahara 7fd585bae1 support older version. 2014-02-14 10:36:37 +09:00
Tomoyuki Sahara daa65c15de add dummy IO#flush for better compatibility with CRuby. 2014-02-12 16:33:34 +09:00
Tomoyuki Sahara 40c52f58d0 Merge pull request #9 from matsumoto-r/support_mrb_get_module
Support mrb_module_get
2014-02-12 10:57:58 +09:00
Paolo Bosetti ee2859de6e Updated mrb_include_module call after mruby 1.0.0 2014-02-11 14:54:30 +01:00
Tomoyuki Sahara b3c6075dc5 IO._bless has gone.
https://github.com/iij/mruby-io/commit/b74458a486042f4863fa6362057e25f0997694f5
2014-02-10 09:51:24 +09:00
Tomoyuki Sahara b74458a486 remove _bless trick. closes #8. 2014-02-10 09:49:37 +09:00
MATSUMOTO Ryosuke 526608c8a2 Support mrb_module_ge 2014-02-08 17:38:41 +09:00
Tomoyuki Sahara f10b73efa7 move license terms to the bottom. 2014-02-03 12:35:02 +09:00
Paolo Bosetti a2af349959 Now the drive letter is returned as leading path element by File#dirname on Windows 2014-01-13 17:29:57 +01:00
Tomoyuki Sahara b744097511 Merge pull request #6 from schmurfy/testless
removed mtest dependency
2014-01-09 16:09:50 -08:00
Paolo Bosetti a613bce3f2 Merge branch 'master' of https://github.com/iij/mruby-io 2014-01-07 13:51:38 +01:00
Tomoyuki Sahara 8cee36b1b5 Catch Errno::ENFILE too.
When system file descriptor table is full, errno is set to
ENFILE instead of EMFILE.  They are similar but different.
2013-12-13 15:49:32 +09:00
Paolo Bosetti 23afaf02dc Made compatible with VisualStudio 2013-12-10 14:34:26 +01:00
Julien Ammous a26ce35c64 removed mtest dependency 2013-12-04 20:51:27 +01:00
Tomoyuki Sahara d12f436bdb mrb_intern API change. 2013-12-03 10:07:29 +09:00
Paolo Bosetti 5a59fd3a5c Fix for compilation under Win/MinGW 2013-12-02 12:14:04 +01:00
Tomoyuki Sahara e641e9a380 suppress a compiler warning. 2013-11-20 12:14:54 +09:00
Tomoyuki Sahara 2245818f91 make it more portable. 2013-11-20 12:13:34 +09:00
Tomoyuki Sahara 78d2d909cf style 2013-11-20 10:26:13 +09:00
Tomoyuki Sahara 87d878292d Try GC when Too many open files (revert a part of 1e8097a). 2013-11-16 16:04:31 +09:00
Tomoyuki Sahara e44da8a6cc test for #6. 2013-11-16 05:44:04 +09:00
Tomoyuki Sahara 1e8097a4b8 IO.sysopen raises an exception when open(2) fails. closes #6. 2013-11-16 05:14:07 +09:00
Tomoyuki Sahara e96cdeb2af Merge pull request #3 from h2so5/patch-1
avoid declaration error on VC++
2013-11-05 18:31:15 -08:00
h2so5 db14b8e7d4 avoid declaration error on VC++ 2013-11-06 11:25:33 +09:00
Tomoyuki Sahara d8e5e7df3f Merge pull request #3 from murasesyuka/feature/add_dependencies_gem
add mruby-socket dependency gems
2013-11-03 00:41:21 -07:00
murase_syuka 78ebe1b427 add mruby-socket dependency gems 2013-11-02 14:30:42 +09:00
Tomoyuki Sahara 823df14ff4 remove unused code and irrelevant comment. 2013-10-15 10:43:48 +09:00
Tomoyuki Sahara ec443d45db more IPPROTO_* related to IPv6. 2013-10-10 10:24:02 +09:00
Tomoyuki Sahara 93edd26b3e fix typo... 2013-10-09 00:35:22 +09:00
Tomoyuki Sahara 005f01f2fc fix RSTRING_PTR usage. 2013-10-03 12:18:39 +09:00
Tomoyuki Sahara bf4c226232 Merge pull request #4 from pbosetti/master
Truncate the file to zero length on opening when "w" mode is set
2013-10-02 17:08:24 -07:00
Paolo Bosetti c608c26ab4 Merge branch 'master' of https://github.com/iij/mruby-io 2013-10-02 13:05:12 +02:00
Paolo Bosetti 49494a7367 Truncate file on File.open(file, "w") 2013-10-02 13:01:56 +02:00
Tomoyuki Sahara 8b48e2b4a4 syswrite must write to fd2 if it is properly set.
closes #3.
2013-09-30 11:56:15 +09:00
Tomoyuki Sahara 97899a6922 style 2013-09-30 11:18:22 +09:00
Tomoyuki Sahara adb3bd6698 don't retry when we cannot fork(2).
EAGAIN indicates the system is under heavy load.
Retrying make things worse.
2013-09-30 10:55:09 +09:00
Tomoyuki Sahara d75d23294d fix descriptor leakage. 2013-09-30 10:36:29 +09:00
Tomoyuki Sahara b4f0a68fba add File#flock. 2013-09-30 10:17:21 +09:00
Tomoyuki Sahara 140da1c6ca remove duplicated white spaces. 2013-09-26 18:31:02 +09:00
Tomoyuki Sahara e27fb544df suppress a warning and fix a possible segv. 2013-09-26 10:59:40 +09:00
Tomoyuki Sahara e2b0606752 Merge pull request #2 from pbosetti/master
Catch up with API changes on mrb_intern() -> mrb_intern_cstr()
2013-09-25 18:21:27 -07:00
Paolo Bosetti c4e3c46e86 Catch up with API changes on mrb_intern() -> mrb_intern_cstr() 2013-09-25 13:26:49 +02:00
Tomoyuki Sahara 47a610e688 use array parameter on IO.open. 2013-08-30 19:09:36 +09:00
Tomoyuki Sahara 713aa48cf9 STDERR's file descriptor is 2.
closes #1
2013-08-30 17:04:40 +09:00
Tomoyuki Sahara 9dc875f246 add cmd (command output expression). 2013-08-23 16:00:08 +09:00
Tomoyuki Sahara 40adffc676 ARGS_XXX -> MRB_ARGS_XXX 2013-08-21 09:29:38 +09:00
Tomoyuki Sahara 0345215465 fix a possible address family mismatch. 2013-08-14 11:51:53 +09:00
Tomoyuki Sahara a9593e1f57 v4/v6 fallback for TCP. 2013-08-14 09:34:22 +09:00
Tomoyuki Sahara 5e8021bedb tests for File.socket? and File.symlink? 2013-08-08 14:00:02 +09:00
Tomoyuki Sahara c49541058c use lstat(2) to check if it's a symlink 2013-08-08 13:58:47 +09:00
Tomoyuki Sahara 76e1017f48 hints.ai_socktype must be set if servname is not NULL on NetBSD3.
Closes #1
2013-07-25 15:04:59 +09:00
Tomoyuki Sahara a341b8e0ff more socket options (for multicast). 2013-07-25 11:58:05 +09:00
Tomoyuki Sahara cf827ab0e7 fix Addrinfo.getaddrinfo("127.0.0.1", nil).
Closes #2
2013-07-25 11:54:53 +09:00
Takashi Sogabe 4f3a749da1 Fix incorrect condition for pendig-IO 2013-06-26 15:24:23 +09:00
Tomoyuki Sahara 216e32751e Socket.gethostname always fails. 2013-06-21 09:14:53 +09:00
Akira Yumiyama 5625e44371 add method: IO#select 2013-06-02 15:25:14 +09:00
Akira Yumiyama 1272df7cb6 fix IO#eof? method (consider the read buffer) 2013-06-02 13:24:34 +09:00
Akito Mochizuki 35defaf1c9 fix mrb_voidp_value function call 2013-05-28 10:15:25 +09:00
Tomoyuki Sahara f4aa3e7ae7 getaddrinfo("localhost") returns "fe80::1%lo0" on MacOS! 2013-05-21 14:48:42 +09:00
Tomoyuki Sahara 1411d5b974 using mruby-mtest on test/socket.rb. 2013-05-21 14:23:35 +09:00
Tomoyuki Sahara 12144b9ad2 getaddrinfo("localhost") may return 2 or more. 2013-05-21 14:23:07 +09:00
Tomoyuki Sahara 0f2d7e8a99 fix reading wrong variable. 2013-05-21 14:15:15 +09:00
Tomoyuki Sahara b8912c3508 Linux does not have getpeereid(2). 2013-05-21 14:13:15 +09:00
Tomoyuki Sahara 4bebd4d70f mrb_sys_fail() is declared in src/error.h 2013-05-21 14:03:10 +09:00
Tomoyuki Sahara cfe18142cb test runner. 2013-05-21 13:53:27 +09:00
Tomoyuki Sahara 89147066f8 mruby-socket depends on mruby-io. 2013-05-21 13:48:33 +09:00
Tomoyuki Sahara bc5feb39a1 short description, example, requirement, todo, license. 2013-05-21 13:40:14 +09:00
Tomoyuki Sahara e459ecc934 Merge branch 'master' of github.com:iij/mruby-socket 2013-05-21 13:19:32 +09:00
Tomoyuki Sahara 49e53bca5d Socket library for mruby. 2013-05-21 13:17:34 +09:00
Tomoyuki Sahara 06f1c82f64 Initial commit 2013-05-20 21:15:50 -07:00
Akira Yumiyama 0a21d9ec92 bufix of mrb_file__gethome() 2013-05-12 14:58:12 +09:00
Akira Yumiyama e277079616 update run_test.rb 2013-05-12 14:50:31 +09:00
Akira Yumiyama 55b6ef43c5 add return value check of fseek 2013-05-12 14:23:48 +09:00
Akira Yumiyama 14e1992ed0 add null check 2013-05-12 14:15:00 +09:00
Akira Yumiyama d39a05e68e remove unused variable. 2013-05-12 14:14:48 +09:00
Akira Yumiyama 49cc9c7cfa Use strncpy instead of strcpy. 2013-05-12 14:01:53 +09:00
Akira Yumiyama c25d386c41 Use mkstemp instead of mktemp. 2013-05-12 13:15:11 +09:00
Akira Yumiyama acc8995060 update run_test.rb 2013-05-12 12:54:35 +09:00
Akira Yumiyama df529a83d6 add $stdin $stdout $stderr STDIN STDOUT STDERR 2013-05-08 20:22:29 +09:00
Akira Yumiyama 7a94d02e8d add IO#print 2013-05-08 20:22:14 +09:00
Tomoyuki Sahara 38f4086a52 Merge pull request #2 from schmurfy/double
added support for E in pack
2013-05-08 01:53:56 -07:00
Julien Ammous dce09fb7fd removed unused variables 2013-05-08 10:26:15 +02:00
Julien Ammous c869bdedc0 added support for E in pack (double) 2013-05-08 10:26:15 +02:00
Tomoyuki Sahara 8c5cb5e782 cannot pack objects other than the first one. closes #1. 2013-05-08 09:40:24 +09:00
Akira Yumiyama f89ee88a6c rename mrb_class_obj_get -> mrb_class_get 2013-05-02 23:52:57 +09:00
Akira Yumiyama 7618ca6bb3 remove unused Makefile 2013-05-02 23:45:47 +09:00
Akira Yumiyama 8bfbca234f update run_test.rb 2013-05-02 23:44:40 +09:00
Akira Yumiyama 62e1823187 update run_test.rb 2013-05-02 23:36:20 +09:00
Akira Yumiyama 814f3305ca put MRB_ prefix before ARGS_XXX macros 2013-04-27 10:09:05 +09:00
Akira Yumiyama d5982b43c5 put MRB_ prefix before ARGS_XXX macros 2013-04-27 09:47:05 +09:00
Akira Yumiyama da557fbc82 add File.expand_path 2013-04-07 01:55:18 +09:00
Akira Yumiyama cc40f93ac8 Kernel#open block support 2013-04-02 15:51:36 +09:00
Akira Yumiyama 911003987b add Kernel#open 2013-04-02 15:32:01 +09:00
Akira Yumiyama 5a425f598b Update README.md 2013-04-01 10:17:18 +09:00
Akira Yumiyama b8a23e6be8 update README.md 2013-04-01 09:21:12 +09:00
Akira Yumiyama e8ca5e5169 initial commit 2013-04-01 09:12:01 +09:00
Tomoyuki Sahara 858d67c154 add "v" and "V". 2013-02-15 10:54:36 +09:00
Tomoyuki Sahara fc43022c95 support "V" and "v". 2013-02-15 10:52:37 +09:00
Tomoyuki Sahara abe9ccfe4b Merge branch 'master' of https://github.com/iij/mruby-pack 2013-02-15 10:46:21 +09:00
Tomoyuki Sahara 88fa5851f4 fix an issue large/negative integer may not be packed/unpacked correctly. 2013-02-15 10:45:30 +09:00
Tomoyuki Sahara a0c62dd4b8 fix an issue negative integer may not be packed/unpacked correctly. 2013-02-15 10:39:04 +09:00
Akira Yumiyama 53ff8bab17 update README.md 2013-01-30 17:03:42 +09:00
Akira Yumiyama aadcbb1690 add mrbgem test runner 2013-01-30 15:20:41 +09:00
Akira Yumiyama 0786e37ed6 update mrbgem.rake 2013-01-30 15:20:10 +09:00
Akira Yumiyama a0161d69a8 typo fix on mrbgem.rake 2013-01-24 10:12:02 +09:00
Akira Yumiyama f70a45ad3a update mrbgem.rake 2013-01-24 10:09:15 +09:00
Akira Yumiyama 558f6fc090 update mrbgem.rake 2013-01-24 09:00:55 +09:00
Akira Yumiyama e734ab3f95 add mrb_mruby_pack_gem_final 2013-01-24 09:00:40 +09:00
Akira Yumiyama 209ad3171d add mrbgem.rake 2013-01-04 00:04:02 +09:00
Akira Yumiyama fb79282a5b add README.md 2012-12-31 13:15:30 +09:00
Akira Yumiyama e205905d02 mruby-pack 2012-12-31 11:38:22 +09:00
290 changed files with 24198 additions and 8682 deletions
+16 -8
View File
@@ -1,13 +1,12 @@
# /
*.bak
*.bc
*.d
*.i
*.o
/benchmark/**/*.dat
/benchmark/*.pdf
/benchmark/*.png
*.orig
*.pdb
*.rej
*.s
*.sav
*.swp
*.tmp
@@ -15,12 +14,21 @@
.DS_Store
.ccmalloc
.svn
/.git
.vscode
.yardoc
cscope.files
cscope.out
tags
/src/y.tab.c
/.git
/bin
/build
/mruby-source-*.gem
doc/api
.yardoc
/benchmark/**/*.dat
/benchmark/*.pdf
/benchmark/*.png
/doc/api
/src/y.tab.c
+4 -3
View File
@@ -5,7 +5,7 @@ sudo: false
matrix:
include:
- os: linux
sudo: 9000
sudo: false
- os: osx
osx_image: xcode7.1
@@ -14,5 +14,6 @@ addons:
packages:
- gperf
env: MRUBY_CONFIG=travis_config.rb
script: "./minirake all test"
env:
- MRUBY_CONFIG=travis_config.rb
script: "./minirake -j4 all test"
+1 -1
View File
@@ -12,6 +12,6 @@ mrbgems/*/mrblib/**/*.rb
mrbgems/*/include/**/*.h
-
AUTHORS
MITL
LICENSE
CONTRIBUTING.md
doc/guides/*.md
+9 -2
View File
@@ -1,5 +1,8 @@
Original Authors "mruby developers" are:
Yukihiro Matsumoto
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.
Yukihiro Matsumoto (Matz)
SCSK KYUSHU CORPORATION
Kyushu Institute of Technology
Network Applied Communication Laboratory, Inc.
@@ -35,3 +38,7 @@ Original Authors "mruby developers" are:
Terence Lee
Zachary Scott
Tomasz Dąbrowski
Christopher Aue
Masahiro Wakame
YAMAMOTO Masaya
KOBAYASHI Shuji
+1 -1
View File
@@ -2,5 +2,5 @@ LEGAL NOTICE INFORMATION
------------------------
All the files in this distribution are covered under the MIT license
(see the file MITL) except some files mentioned below:
(see the file LICENSE) except some files mentioned below:
+1 -1
View File
@@ -1,4 +1,4 @@
Copyright (c) 2017 mruby developers
Copyright (c) 2019 mruby developers
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
+2 -2
View File
@@ -17,7 +17,7 @@ of the Ministry of Economy, Trade and Industry of Japan.
## How to get mruby
The stable version 1.3.0 of mruby can be downloaded via the following URL: [https://github.com/mruby/mruby/archive/1.3.0.zip](https://github.com/mruby/mruby/archive/1.3.0.zip)
The stable version 2.0.1 of mruby can be downloaded via the following URL: [https://github.com/mruby/mruby/archive/2.0.1.zip](https://github.com/mruby/mruby/archive/2.0.1.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)
@@ -59,7 +59,7 @@ how to use mrbgems look into the folder *examples/mrbgems/*.
## License
mruby is released under the [MIT License](MITL).
mruby is released under the [MIT License](LICENSE).
## Note for License
+33 -15
View File
@@ -5,10 +5,12 @@ MRUBY_ROOT = File.dirname(File.expand_path(__FILE__))
MRUBY_BUILD_HOST_IS_CYGWIN = RUBY_PLATFORM.include?('cygwin')
MRUBY_BUILD_HOST_IS_OPENBSD = RUBY_PLATFORM.include?('openbsd')
$LOAD_PATH << File.join(MRUBY_ROOT, "lib")
# load build systems
load "#{MRUBY_ROOT}/tasks/ruby_ext.rake"
load "#{MRUBY_ROOT}/tasks/mruby_build.rake"
load "#{MRUBY_ROOT}/tasks/mrbgem_spec.rake"
require "mruby-core-ext"
require "mruby/build"
require "mruby/gem"
# load configuration file
MRUBY_CONFIG = (ENV['MRUBY_CONFIG'] && ENV['MRUBY_CONFIG'] != '') ? ENV['MRUBY_CONFIG'] : "#{MRUBY_ROOT}/build_config.rb"
@@ -30,20 +32,25 @@ load "#{MRUBY_ROOT}/tasks/benchmark.rake"
load "#{MRUBY_ROOT}/tasks/gitlab.rake"
def install_D(src, dst)
opts = { :verbose => $verbose }
FileUtils.rm_f dst, opts
FileUtils.mkdir_p File.dirname(dst), opts
FileUtils.cp src, dst, opts
end
##############################
# generic build targets, rules
task :default => :all
bin_path = ENV['INSTALL_DIR'] || "#{MRUBY_ROOT}/bin"
FileUtils.mkdir_p bin_path, { :verbose => $verbose }
depfiles = MRuby.targets['host'].bins.map do |bin|
install_path = MRuby.targets['host'].exefile("#{bin_path}/#{bin}")
source_path = MRuby.targets['host'].exefile("#{MRuby.targets['host'].build_dir}/bin/#{bin}")
file install_path => source_path do |t|
FileUtils.rm_f t.name, { :verbose => $verbose }
FileUtils.cp t.prerequisites.first, t.name, { :verbose => $verbose }
install_D t.prerequisites.first, t.name
end
install_path
@@ -63,7 +70,7 @@ MRuby.each_target do |target|
exec = exefile("#{build_dir}/bin/#{bin}")
objs = Dir.glob("#{current_dir}/tools/#{bin}/*.{c,cpp,cxx,cc}").map { |f| objfile(f.pathmap("#{current_build_dir}/tools/#{bin}/%n")) }
file exec => objs + [libfile("#{build_dir}/lib/libmruby")] do |t|
file exec => objs + target.libraries do |t|
gem_flags = gems.map { |g| g.linker.flags }
gem_flags_before_libraries = gems.map { |g| g.linker.flags_before_libraries }
gem_flags_after_libraries = gems.map { |g| g.linker.flags_after_libraries }
@@ -76,8 +83,7 @@ MRuby.each_target do |target|
install_path = MRuby.targets['host'].exefile("#{bin_path}/#{bin}")
file install_path => exec do |t|
FileUtils.rm_f t.name, { :verbose => $verbose }
FileUtils.cp t.prerequisites.first, t.name, { :verbose => $verbose }
install_D t.prerequisites.first, t.name
end
depfiles += [ install_path ]
elsif target == MRuby.targets['host-debug']
@@ -85,8 +91,7 @@ MRuby.each_target do |target|
install_path = MRuby.targets['host-debug'].exefile("#{bin_path}/#{bin}")
file install_path => exec do |t|
FileUtils.rm_f t.name, { :verbose => $verbose }
FileUtils.cp t.prerequisites.first, t.name, { :verbose => $verbose }
install_D t.prerequisites.first, t.name
end
depfiles += [ install_path ]
end
@@ -98,7 +103,7 @@ MRuby.each_target do |target|
end
depfiles += MRuby.targets.map { |n, t|
[t.libfile("#{t.build_dir}/lib/libmruby")]
t.libraries
}.flatten
depfiles += MRuby.targets.reject { |n, t| n == 'host' }.map { |n, t|
@@ -116,9 +121,22 @@ task :all => depfiles do
end
desc "run all mruby tests"
task :test => ["all"] do
MRuby.each_target do
run_test if test_enabled?
task :test
MRuby.each_target do
if test_enabled?
t = :"test_#{self.name}"
task t => ["all"] do
run_test
end
task :test => t
end
if bintest_enabled?
t = :"bintest_#{self.name}"
task t => ["all"] do
run_bintest
end
task :test => t
end
end
-2
View File
@@ -2,8 +2,6 @@ Things to do (Things that are not done yet)
* special variables ($1,$2..)
* super in aliased methods
* multi-assignment decomposing
* keyword arguments in def statement
Things to improve (Done but things to fix)
+20 -5
View File
@@ -1,12 +1,19 @@
version: "{build}"
os: Visual Studio 2015
os: Visual Studio 2017
clone_depth: 50
shallow_clone: true
cache:
- win_flex_bison
environment:
matrix:
# Visual Studio 2017 64bit
- visualcpp: C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars64.bat
# Visual Studio 2015 64bit
- visualcpp: C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat
machine: amd64
@@ -18,10 +25,18 @@ environment:
init:
- call "%visualcpp%" %machine%
# For using bison.exe
- set PATH=%PATH%;C:\cygwin\bin;
# For using Rubyinstaller's Ruby 2.4 64bit
- set PATH=C:\Ruby24-x64\bin;%PATH%
- ruby --version
install:
- if not exist win_flex_bison (
appveyor DownloadFile "https://github.com/lexxmark/winflexbison/releases/download/v.2.5.10/win_flex_bison-2.5.10.zip" &
7z x -y -owin_flex_bison win_flex_bison-2.5.10.zip
)
build_script:
- set YACC=.\win_flex_bison\win_bison.exe
- set MRUBY_CONFIG=appveyor_config.rb
- ruby .\minirake test
- rake -E $stdout.sync=true test
+1 -1
View File
@@ -5,7 +5,7 @@ MRuby::Build.new('debug') do |conf|
# include all core GEMs
conf.gembox 'full-core'
conf.compilers.each do |c|
c.defines += %w(MRB_GC_STRESS MRB_GC_FIXED_ARENA)
c.defines += %w(MRB_GC_STRESS MRB_GC_FIXED_ARENA MRB_METHOD_CACHE)
end
build_mrbc_exec
+15 -15
View File
@@ -68,7 +68,7 @@ class Vec
def vnormalize
len = vlength
v = Vec.new(@x, @y, @z)
if len > 1.0e-17 then
if len > 1.0e-17
v.x = v.x / len
v.y = v.y / len
v.z = v.z / len
@@ -92,10 +92,10 @@ class Sphere
b = rs.vdot(ray.dir)
c = rs.vdot(rs) - (@radius * @radius)
d = b * b - c
if d > 0.0 then
if d > 0.0
t = - b - Math.sqrt(d)
if t > 0.0 and t < isect.t then
if t > 0.0 and t < isect.t
isect.t = t
isect.hit = true
isect.pl = Vec.new(ray.org.x + ray.dir.x * t,
@@ -118,16 +118,16 @@ class Plane
d = -@p.vdot(@n)
v = ray.dir.vdot(@n)
v0 = v
if v < 0.0 then
if v < 0.0
v0 = -v
end
if v0 < 1.0e-17 then
if v0 < 1.0e-17
return
end
t = -(ray.org.vdot(@n) + d) / v
if t > 0.0 and t < isect.t then
if t > 0.0 and t < isect.t
isect.hit = true
isect.t = t
isect.n = @n
@@ -170,10 +170,10 @@ end
def clamp(f)
i = f * 255.5
if i > 255.0 then
if i > 255.0
i = 255.0
end
if i < 0.0 then
if i < 0.0
i = 0.0
end
i.to_i
@@ -183,11 +183,11 @@ def otherBasis(basis, n)
basis[2] = Vec.new(n.x, n.y, n.z)
basis[1] = Vec.new(0.0, 0.0, 0.0)
if n.x < 0.6 and n.x > -0.6 then
if n.x < 0.6 and n.x > -0.6
basis[1].x = 1.0
elsif n.y < 0.6 and n.y > -0.6 then
elsif n.y < 0.6 and n.y > -0.6
basis[1].y = 1.0
elsif n.z < 0.6 and n.z > -0.6 then
elsif n.z < 0.6 and n.z > -0.6
basis[1].z = 1.0
else
basis[1].x = 1.0
@@ -221,8 +221,8 @@ class Scene
p0 = Vec.new(isect.pl.x + eps * isect.n.x,
isect.pl.y + eps * isect.n.y,
isect.pl.z + eps * isect.n.z)
nphi.times do |j|
ntheta.times do |i|
nphi.times do
ntheta.times do
r = Rand::rand
phi = 2.0 * 3.14159265 * Rand::rand
x = Math.cos(phi) * Math.sqrt(1.0 - r)
@@ -241,7 +241,7 @@ class Scene
@spheres[1].intersect(ray, occisect)
@spheres[2].intersect(ray, occisect)
@plane.intersect(ray, occisect)
if occisect.hit then
if occisect.hit
occlusion = occlusion + 1.0
else
0.0
@@ -283,7 +283,7 @@ class Scene
@spheres[1].intersect(ray, isect)
@spheres[2].intersect(ray, isect)
@plane.intersect(ray, isect)
if isect.hit then
if isect.hit
col = ambient_occlusion(isect)
rad.x = rad.x + col.x
rad.y = rad.y + col.y
+1 -2
View File
@@ -48,5 +48,4 @@ answer = to_array(solution).map do |p|
to_string(p)
end
answer_str = answer.to_a
# puts answer_str
# puts answer
+3 -3
View File
@@ -17,19 +17,19 @@ def test_lists()
# li2 must now be empty
# remove each individual item from right side of li3 and
# append to right side of li2 (reversing list)
while (not li3.empty?)
until li3.empty?
li2.push(li3.pop)
end
# li3 must now be empty
# reverse li1 in place
li1.reverse!
# check that first item is now SIZE
if li1[0] != SIZE then
if li1[0] != SIZE
p "not SIZE"
0
else
# compare li1 and li2 for equality
if li1 != li2 then
if li1 != li2
return(0)
else
# return the length of the list
View File
+14 -14
View File
@@ -8,7 +8,8 @@ MRuby::Build.new do |conf|
toolchain :gcc
end
enable_debug
# Turn on `enable_debug` for better debugging
# enable_debug
# Use mrbgems
# conf.gem 'examples/mrbgems/ruby_extension_example'
@@ -28,7 +29,7 @@ MRuby::Build.new do |conf|
# cc.command = ENV['CC'] || 'gcc'
# cc.flags = [ENV['CFLAGS'] || %w()]
# cc.include_paths = ["#{root}/include"]
# cc.defines = %w(DISABLE_GEMS)
# cc.defines = %w()
# cc.option_include_path = '-I%s'
# cc.option_define = '-D%s'
# cc.compile_options = "%{flags} -MMD -o %{outfile} -c %{infile}"
@@ -124,17 +125,17 @@ MRuby::Build.new('test') do |conf|
conf.gembox 'default'
end
MRuby::Build.new('bench') do |conf|
# Gets set by the VS command prompts.
if ENV['VisualStudioVersion'] || ENV['VSINSTALLDIR']
toolchain :visualcpp
else
toolchain :gcc
conf.cc.flags << '-O3'
end
conf.gembox 'default'
end
#MRuby::Build.new('bench') do |conf|
# # Gets set by the VS command prompts.
# if ENV['VisualStudioVersion'] || ENV['VSINSTALLDIR']
# toolchain :visualcpp
# else
# toolchain :gcc
# conf.cc.flags << '-O3'
# end
#
# conf.gembox 'default'
#end
# Define cross build settings
# MRuby::CrossBuild.new('32bit') do |conf|
@@ -148,5 +149,4 @@ end
# conf.gem 'examples/mrbgems/c_and_ruby_extension_example'
#
# conf.test_runner.command = 'env'
#
# end
+1 -1
View File
@@ -38,7 +38,7 @@ To confirm mrdb was installed properly, run mrdb with the `--version` option:
```bash
$ mrdb --version
mruby 1.3.0 (2017-7-4)
mruby 2.0.1 (2019-4-4)
```
## 2.2 Basic Operation
+5 -5
View File
@@ -114,14 +114,14 @@ inspect_ary(mrb_state *mrb, mrb_value ary, mrb_value list)
mrb_ary_push(mrb, list, ary);
arystr = mrb_str_buf_new(mrb, 64);
mrb_str_buf_cat(mrb, arystr, head, sizeof(head));
arystr = mrb_str_new_capa(mrb, 64);
mrb_str_cat(mrb, arystr, head, sizeof(head));
for(i=0; i<RARRAY_LEN(ary); i++) {
int ai = mrb_gc_arena_save(mrb);
if (i > 0) {
mrb_str_buf_cat(mrb, arystr, sep, sizeof(sep));
mrb_str_cat(mrb, arystr, sep, sizeof(sep));
}
if (mrb_array_p(RARRAY_PTR(ary)[i])) {
s = inspect_ary(mrb, RARRAY_PTR(ary)[i], list);
@@ -129,11 +129,11 @@ inspect_ary(mrb_state *mrb, mrb_value ary, mrb_value list)
else {
s = mrb_inspect(mrb, RARRAY_PTR(ary)[i]);
}
mrb_str_buf_cat(mrb, arystr, RSTRING_PTR(s), RSTRING_LEN(s));
mrb_str_cat(mrb, arystr, RSTRING_PTR(s), RSTRING_LEN(s));
mrb_gc_arena_restore(mrb, ai);
}
mrb_str_buf_cat(mrb, arystr, tail, sizeof(tail));
mrb_str_cat(mrb, arystr, tail, sizeof(tail));
mrb_ary_pop(mrb, list);
return arystr;
+1 -12
View File
@@ -122,20 +122,9 @@ largest value of required alignment.
* If defined `Float` will be a mruby object with `RBasic`.
## Instance variable configuration.
`MRB_USE_IV_SEGLIST`
* If defined enable segmented list in instance variable table instead of khash.
* Segmented list is a linked list of key and value segments.
* It will linear search instead of hash search.
`MRB_SEGMENT_SIZE`
`MRB_IV_SEGMENT_SIZE`
* Default value is `4`.
* Specifies size of each segment in segment list.
* Ignored when `MRB_USE_IV_SEGLIST` isn't defined.
`MRB_IVHASH_INIT_SIZE`
* Default value is `8`.
* Specifies initial size for instance variable table.
* Ignored when `MRB_USE_IV_SEGLIST` is defined.
## Other configuration.
`MRB_UTF8_STRING`
+7 -2
View File
@@ -26,6 +26,11 @@ 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:
```ruby
conf.gem github: 'mruby/mruby', path: 'mrbgems/mruby-socket'
```
To use mrbgem from [mgem-list](https://github.com/mruby/mgem-list) use `:mgem` option:
```ruby
conf.gem :mgem => 'mruby-yaml'
@@ -174,11 +179,11 @@ Version requirement supports following operators:
When more than one version requirements is passed, the dependency must satisfy all of it.
You can have default gem to use as depedency when it's not defined in *build_config.rb*.
You can have default gem to use as dependency when it's not defined in *build_config.rb*.
When the last argument of `add_dependency` call is `Hash`, it will be treated as default gem information.
Its format is same as argument of method `MRuby::Build#gem`, expect that it can't be treated as path gem location.
When a special version of depedency is required,
When a special version of dependency is required,
use `MRuby::Build#gem` in *build_config.rb* to override default gem.
If you have conflicting GEMs use the following method:
+67 -26
View File
@@ -38,7 +38,7 @@ puts [1,2,3]
3
```
#### mruby [1.3.0 (2017-7-4)]
#### mruby [2.0.1 (2019-4-4)]
```
[1, 2, 3]
@@ -61,26 +61,10 @@ end
```ZeroDivisionError``` is raised.
#### mruby [1.3.0 (2017-7-4)]
#### mruby [2.0.1 (2019-4-4)]
No exception is raised.
## Check of infinite recursion
mruby does not check infinite recursion across C extensions.
```ruby
def test; eval 'test'; end; test
```
#### Ruby [ruby 2.0.0p645 (2015-04-13 revision 50299)]
```SystemStackError``` is raised.
#### mruby [1.3.0 (2017-7-4)]
Segmentation fault.
## Fiber execution can't cross C function boundary
mruby's ```Fiber``` is implemented in a similar way to Lua's co-routine. This
@@ -105,7 +89,7 @@ p Liste.new "foobar"
``` [] ```
#### mruby [1.3.0 (2017-7-4)]
#### mruby [2.0.1 (2019-4-4)]
```ArgumentError``` is raised.
@@ -135,7 +119,7 @@ false
true
```
#### mruby [1.3.0 (2017-7-4)]
#### mruby [2.0.1 (2019-4-4)]
```
true
@@ -158,7 +142,7 @@ defined?(Foo)
nil
```
#### mruby [1.3.0 (2017-7-4)]
#### mruby [2.0.1 (2019-4-4)]
```NameError``` is raised.
@@ -175,7 +159,7 @@ alias $a $__a__
``` nil ```
#### mruby [1.3.0 (2017-7-4)]
#### mruby [2.0.1 (2019-4-4)]
Syntax error
@@ -197,12 +181,69 @@ end
```ArgumentError``` is raised.
The re-defined ```+``` operator does not accept any arguments.
#### mruby [1.3.0 (2017-7-4)]
#### mruby [2.0.1 (2019-4-4)]
``` 'ab' ```
Behavior of the operator wasn't changed.
## ```Kernel.binding``` missing
## Kernel#binding is not supported
```Kernel.binding``` is not implemented as it is not in the
ISO standard.
`Kernel#binding` method is not supported.
#### Ruby [ruby 2.5.1p57 (2018-03-29 revision 63029)]
```
$ ruby -e 'puts Proc.new {}.binding'
#<Binding:0x00000e9deabb9950>
```
#### mruby [2.0.1 (2019-4-4)]
```
$ ./bin/mruby -e 'puts Proc.new {}.binding'
trace (most recent call last):
[0] -e:1
-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. Maybe in the
future, the simpler behavior will be adopted to CRuby as well.
#### 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.0.1]
```
$ ./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)
```
## Argument Destructuring
```ruby
def m(a,(b,c),d); p [a,b,c,d]; end
m(1,[2,3],4) # => [1,2,3,4]
```
Destructured arguments (`b` and `c` in above example) cannot be accessed
from the default expression of optional arguments and keyword arguments,
since actual assignment is done after the evaluation of those default
expressions. Thus:
```ruby
def f(a,(b,c),d=b)
p [a,b,c,d]
end
f(1,[2,3])
```
CRuby gives `[1,2,3,nil]`. mruby raises `NoMethodError` for `b`.
+127
View File
@@ -0,0 +1,127 @@
# The new bytecode
We will reimplement VM to use 8bit instruction code. By
bytecode, we mean real byte code. The whole purpose is
reducing the memory consumption of mruby VM.
# Instructions
Instructions are bytes. There can be 256 instructions. Currently we
have 94 instructions. Instructions can take 0 to 3 operands.
## operands
The size of operands can be either 8bits, 16bits or 24bits.
In the table.1 below, the second field describes the size (and
sign) of operands.
* B: 8bit
* sB: signed 8bit
* S: 16bit
* sS: signed 16bit
* W: 24bit
First two byte operands may be extended to 16bit. When those byte
operands are bigger than 256, the instruction will be prefixed by
`OP_EXT1` (means 1st operand is 16bit) or `OP_EXT2` (means 2nd operand
is 16bit) or `OP_EXT3` (means 1st and 2nd operands are 16bit).
For instructions marked by `'`, `OP_EXT1` can be prefixed. For those
with `"`, either `OP_EXT1` or `OP_EXT2` or `OP_EXT2` can be prefixed.
## table.1 Instruction Table
|Instruction Name |Operand type |Semantics
|-----------------|-------------|-----------------
|OP_NOP | - |
|OP_MOVE" |BB |R(a) = R(b)
|OP_LOADL" |BB |R(a) = Pool(b)
|OP_LOADI" |BsB |R(a) = mrb_int(b)
|OP_LOADI_0' |B |R(a) = 0
|OP_LOADI_1' |B |R(a) = 1
|OP_LOADI_2' |B |R(a) = 2
|OP_LOADI_3' |B |R(a) = 3
|OP_LOADSYM" |BB |R(a) = Syms(b)
|OP_LOADNIL' |B |R(a) = nil
|OP_LOADSELF' |B |R(a) = self
|OP_LOADT' |B |R(a) = true
|OP_LOADF' |B |R(a) = false
|OP_GETGV" |BB |R(a) = getglobal(Syms(b))
|OP_SETGV" |BB |setglobal(Syms(b), R(a))
|OP_GETSV" |BB |R(a) = Special[b]
|OP_SETSV" |BB |Special[b] = R(a)
|OP_GETIV" |BB |R(a) = ivget(Syms(b))
|OP_SETIV" |BB |ivset(Syms(b),R(a))
|OP_GETCV" |BB |R(a) = cvget(Syms(b))
|OP_SETCV" |BB |cvset(Syms(b),R(a))
|OP_GETCONST" |BB |R(a) = constget(Syms(b))
|OP_SETCONST" |BB |constset(Syms(b),R(a))
|OP_GETMCNST" |BB |R(a) = R(a)::Syms(b)
|OP_SETMCNST" |BB |R(a+1)::Syms(b) = R(a)
|OP_GETUPVAR' |BBB |R(a) = uvget(b,c)
|OP_SETUPVAR' |BBB |uvset(b,c,R(a))
|OP_JMP |S |pc+=a
|OP_JMPIF' |SB |if R(b) pc+=a
|OP_JMPNOT' |SB |if !R(b) pc+=a
|OP_ONERR |sS |rescue_push(pc+a)
|OP_EXCEPT' |B |R(a) = exc
|OP_RESCUE" |BB |R(b) = R(a).isa?(R(b))
|OP_POPERR |B |a.times{rescue_pop()}
|OP_RAISE' |B |raise(R(a))
|OP_EPUSH' |B |ensure_push(SEQ[a])
|OP_EPOP |B |A.times{ensure_pop().call}
|OP_SENDV" |BB |R(a) = call(R(a),Syms(b),*R(a+1))
|OP_SENDVB" |BB |R(a) = call(R(a),Syms(b),*R(a+1),&R(a+2))
|OP_SEND" |BBB |R(a) = call(R(a),Syms(b),R(a+1),...,R(a+c))
|OP_SENDB" |BBB |R(a) = call(R(a),Syms(Bx),R(a+1),...,R(a+c),&R(a+c+1))
|OP_CALL' |B |R(a) = self.call(frame.argc, frame.argv)
|OP_SUPER' |BB |R(a) = super(R(a+1),... ,R(a+b+1))
|OP_ARGARY' |BS |R(a) = argument array (16=5:1:5:1:4)
|OP_ENTER |W |arg setup according to flags (23=5:5:1:5:5:1:1)
|OP_KARG" |BB |R(a) = kdict[Syms(Bx)] # todo
|OP_KARG2" |BB |R(a) = kdict[Syms(Bx)]; kdict.rm(Syms(b)) # todo
|OP_RETURN' |B |return R(a) (normal)
|OP_RETURN_BLK' |B |return R(a) (in-block return)
|OP_BREAK' |B |break R(a)
|OP_BLKPUSH' |BS |R(a) = block (16=5:1:5:1:4)
|OP_ADD" |BB |R(a) = R(a)+R(a+1)
|OP_ADDI" |BBB |R(a) = R(a)+mrb_int(c)
|OP_SUB" |BB |R(a) = R(a)-R(a+1)
|OP_SUBI" |BB |R(a) = R(a)-C
|OP_MUL" |BB |R(a) = R(a)*R(a+1)
|OP_DIV" |BB |R(a) = R(a)/R(a+1)
|OP_EQ" |BB |R(a) = R(a)==R(a+1)
|OP_LT" |BB |R(a) = R(a)<R(a+1)
|OP_LE" |BB |R(a) = R(a)<=R(a+1)
|OP_GT" |BB |R(a) = R(a)>R(a+1)
|OP_GE" |BB |R(a) = R(a)>=R(a+1)
|OP_ARRAY' |BB |R(a) = ary_new(R(a),R(a+1)..R(a+b))
|OP_ARRAY2" |BB |R(a) = ary_new(R(b),R(b+1)..R(b+c))
|OP_ARYCAT' |B |ary_cat(R(a),R(a+1))
|OP_ARYPUSH' |B |ary_push(R(a),R(a+1))
|OP_AREF' |BB |R(a) = R(a)[b]
|OP_ASET' |BB |R(a)[b] = R(a+1)
|OP_APOST' |BB |*R(a),R(A+1)..R(A+C) = R(a)[B..]
|OP_STRING" |BB |R(a) = str_dup(Lit(b))
|OP_STRCAT' |B |str_cat(R(a),R(a+1))
|OP_HASH' |BB |R(a) = hash_new(R(a),R(a+1)..R(a+b))
|OP_HASHADD' |BB |R(a) = hash_push(R(a),R(a+1)..R(a+b))
|OP_LAMBDA" |BB |R(a) = lambda(SEQ[b],OP_L_LAMBDA)
|OP_BLOCK" |BB |R(a) = lambda(SEQ[b],OP_L_BLOCK)
|OP_METHOD" |BB |R(a) = lambda(SEQ[b],OP_L_METHOD)
|OP_RANGE_INC' |B |R(a) = range_new(R(a),R(a+1),FALSE)
|OP_RANGE_EXC' |B |R(a) = range_new(R(a),R(a+1),TRUE)
|OP_OCLASS' |B |R(a) = ::Object
|OP_CLASS" |BB |R(a) = newclass(R(a),Syms(b),R(a+1))
|OP_MODULE" |BB |R(a) = newmodule(R(a),Syms(b))
|OP_EXEC" |BB |R(a) = blockexec(R(a),SEQ[b])
|OP_DEF" |BB |R(a).newmethod(Syms(b),R(a+1))
|OP_ALIAS' |B |alias_method(R(a),R(a+1),R(a+2))
|OP_UNDEF" |BB |undef_method(R(a),Syms(b))
|OP_SCLASS' |B |R(a) = R(a).singleton_class
|OP_TCLASS' |B |R(a) = target_class
|OP_ERR' |B |raise(RuntimeError, Lit(Bx))
|OP_EXT1 |- |make 1st operand 16bit
|OP_EXT2 |- |make 2nd operand 16bit
|OP_EXT3 |- |make 1st and 2nd operands 16bit
|OP_STOP |- |stop VM
@@ -46,7 +46,6 @@ MRuby::CrossBuild.new("ArduinoDue") do |conf|
#configuration for low memory environment
cc.defines << %w(MRB_HEAP_PAGE_SIZE=64)
cc.defines << %w(MRB_USE_IV_SEGLIST)
cc.defines << %w(KHASH_DEFAULT_SIZE=8)
cc.defines << %w(MRB_STR_BUF_MIN_SIZE=20)
cc.defines << %w(MRB_GC_STRESS)
-1
View File
@@ -32,7 +32,6 @@ MRuby::CrossBuild.new("RX630") do |conf|
#configuration for low memory environment
cc.defines << %w(MRB_USE_FLOAT)
cc.defines << %w(MRB_HEAP_PAGE_SIZE=64)
cc.defines << %w(MRB_USE_IV_SEGLIST)
cc.defines << %w(KHASH_DEFAULT_SIZE=8)
cc.defines << %w(MRB_STR_BUF_MIN_SIZE=20)
cc.defines << %w(MRB_GC_STRESS)
@@ -15,8 +15,8 @@ end
# Requires Android NDK r13 or later.
MRuby::CrossBuild.new('android-arm64-v8a') do |conf|
params = {
:arch => 'arm64-v8a',
params = {
:arch => 'arm64-v8a',
:platform => 'android-24',
:toolchain => :clang,
}
@@ -15,8 +15,8 @@ end
# Requires Android NDK r13 or later.
MRuby::CrossBuild.new('android-armeabi') do |conf|
params = {
:arch => 'armeabi',
params = {
:arch => 'armeabi',
:platform => 'android-24',
:toolchain => :clang,
}
@@ -43,7 +43,6 @@ MRuby::CrossBuild.new("chipKITMax32") do |conf|
#configuration for low memory environment
cc.defines << %w(MRB_HEAP_PAGE_SIZE=64)
cc.defines << %w(MRB_USE_IV_SEGLIST)
cc.defines << %w(KHASH_DEFAULT_SIZE=8)
cc.defines << %w(MRB_STR_BUF_MIN_SIZE=20)
cc.defines << %w(MRB_GC_STRESS)
+36 -12
View File
@@ -28,17 +28,46 @@
/* add -DMRB_USE_FLOAT to use float instead of double for floating point numbers */
//#define MRB_USE_FLOAT
/* exclude floating point numbers */
//#define MRB_WITHOUT_FLOAT
/* add -DMRB_METHOD_CACHE to use method cache to improve performance */
//#define MRB_METHOD_CACHE
/* size of the method cache (need to be the power of 2) */
//#define MRB_METHOD_CACHE_SIZE (1<<7)
/* add -DMRB_METHOD_TABLE_INLINE to reduce the size of method table */
/* MRB_METHOD_TABLE_INLINE requires LSB of function pointers to be zero */
/* you might need to specify --falign-functions=n (where n>1) */
//#define MRB_METHOD_TABLE_INLINE
/* add -DMRB_INT16 to use 16bit integer for mrb_int; conflict with MRB_INT64 */
//#define MRB_INT16
/* add -DMRB_INT64 to use 64bit integer for mrb_int; conflict with MRB_INT16 */
//#define MRB_INT64
/* represent mrb_value in boxed double; conflict with MRB_USE_FLOAT */
//#define MRB_NAN_BOXING
/* if no specific integer type is chosen */
#if !defined(MRB_INT16) && !defined(MRB_INT32) && !defined(MRB_INT64)
# if defined(MRB_64BIT) && !defined(MRB_NAN_BOXING)
/* Use 64bit integers on 64bit architecture (without MRB_NAN_BOXING) */
# define MRB_INT64
# else
/* Otherwise use 32bit integers */
# define MRB_INT32
# endif
#endif
/* define on big endian machines; used by MRB_NAN_BOXING */
//#define MRB_ENDIAN_BIG
/* define on big endian machines; used by MRB_NAN_BOXING, etc. */
#ifndef MRB_ENDIAN_BIG
# if (defined(BYTE_ORDER) && defined(BIG_ENDIAN) && BYTE_ORDER == BIG_ENDIAN) || \
(defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
# define MRB_ENDIAN_BIG
# endif
#endif
/* represent mrb_value in boxed double; conflict with MRB_USE_FLOAT and MRB_WITHOUT_FLOAT */
//#define MRB_NAN_BOXING
/* represent mrb_value as a word (natural unit of data for the processor) */
//#define MRB_WORD_BOXING
@@ -52,12 +81,6 @@
/* number of object per heap page */
//#define MRB_HEAP_PAGE_SIZE 1024
/* use segmented list for IV table */
//#define MRB_USE_IV_SEGLIST
/* initial size for IV khash; ignored when MRB_USE_IV_SEGLIST is set */
//#define MRB_IVHASH_INIT_SIZE 8
/* if _etext and _edata available, mruby can reduce memory used by symbols */
//#define MRB_USE_ETEXT_EDATA
@@ -93,10 +116,11 @@
//#define MRB_FIXED_STATE_ATEXIT_STACK
/* -DMRB_DISABLE_XXXX to drop following features */
//#define MRB_DISABLE_STDIO /* use of stdio */
//#define MRB_DISABLE_STDIO /* use of stdio */
/* -DMRB_ENABLE_XXXX to enable following features */
//#define MRB_ENABLE_DEBUG_HOOK /* hooks for debugger */
//#define MRB_ENABLE_DEBUG_HOOK /* hooks for debugger */
//#define MRB_ENABLE_ALL_SYMBOLS /* Symbols.all_symbols */
/* end of configuration */
+128 -47
View File
@@ -1,7 +1,7 @@
/*
** mruby - An embeddable Ruby implementation
**
** Copyright (c) mruby developers 2010-2017
** Copyright (c) mruby developers 2010-2019
**
** Permission is hereby granted, free of charge, to any person obtaining
** a copy of this software and associated documentation files (the
@@ -34,6 +34,7 @@
#define __STDC_FORMAT_MACROS
#endif
#include <stdarg.h>
#include <stdint.h>
#include <stddef.h>
#include <limits.h>
@@ -57,7 +58,7 @@
#define mrb_assert_int_fit(t1,n,t2,max) ((void)0)
#endif
#if __STDC_VERSION__ >= 201112L
#if defined __STDC_VERSION__ && __STDC_VERSION__ >= 201112L
#define mrb_static_assert(exp, str) _Static_assert(exp, str)
#else
#define mrb_static_assert(exp, str) mrb_assert(exp)
@@ -65,11 +66,23 @@
#include "mrbconf.h"
#ifndef MRB_WITHOUT_FLOAT
#ifndef FLT_EPSILON
#define FLT_EPSILON (1.19209290e-07f)
#endif
#ifndef DBL_EPSILON
#define DBL_EPSILON ((double)2.22044604925031308085e-16L)
#endif
#ifndef LDBL_EPSILON
#define LDBL_EPSILON (1.08420217248550443401e-19L)
#endif
#ifdef MRB_USE_FLOAT
#define MRB_FLOAT_EPSILON FLT_EPSILON
#else
#define MRB_FLOAT_EPSILON DBL_EPSILON
#endif
#endif
#include "mruby/common.h"
#include <mruby/value.h>
@@ -81,7 +94,7 @@
*/
MRB_BEGIN_DECL
typedef uint32_t mrb_code;
typedef uint8_t mrb_code;
/**
* Required arguments signature type.
@@ -111,9 +124,8 @@ typedef struct {
mrb_sym mid;
struct RProc *proc;
mrb_value *stackent;
int nregs;
int ridx;
int epos;
uint16_t ridx;
uint16_t epos;
struct REnv *env;
mrb_code *pc; /* return address */
mrb_code *err; /* error position */
@@ -140,16 +152,46 @@ struct mrb_context {
mrb_callinfo *ci;
mrb_callinfo *cibase, *ciend;
mrb_code **rescue; /* exception handler stack */
int rsize;
uint16_t *rescue; /* exception handler stack */
uint16_t rsize;
struct RProc **ensure; /* ensure handler stack */
int esize, eidx;
uint16_t esize, eidx;
enum mrb_fiber_state status;
mrb_bool vmexec;
struct RFiber *fib;
};
#ifdef MRB_METHOD_CACHE_SIZE
# define MRB_METHOD_CACHE
#else
/* default method cache size: 128 */
/* cache size needs to be power of 2 */
# define MRB_METHOD_CACHE_SIZE (1<<7)
#endif
typedef mrb_value (*mrb_func_t)(struct mrb_state *mrb, mrb_value);
#ifdef MRB_METHOD_TABLE_INLINE
typedef uintptr_t mrb_method_t;
#else
typedef struct {
mrb_bool func_p;
union {
struct RProc *proc;
mrb_func_t func;
};
} mrb_method_t;
#endif
#ifdef MRB_METHOD_CACHE
struct mrb_cache_entry {
struct RClass *c, *c0;
mrb_sym mid;
mrb_method_t m;
};
#endif
struct mrb_jmpbuf;
typedef void (*mrb_atexit_func)(struct mrb_state*);
@@ -178,8 +220,11 @@ typedef struct mrb_state {
struct RClass *string_class;
struct RClass *array_class;
struct RClass *hash_class;
struct RClass *range_class;
#ifndef MRB_WITHOUT_FLOAT
struct RClass *float_class;
#endif
struct RClass *fixnum_class;
struct RClass *true_class;
struct RClass *false_class;
@@ -190,10 +235,17 @@ typedef struct mrb_state {
struct alloca_header *mems;
mrb_gc gc;
#ifdef MRB_METHOD_CACHE
struct mrb_cache_entry cache[MRB_METHOD_CACHE_SIZE];
#endif
mrb_sym symidx;
struct kh_n2s *name2sym; /* symbol hash */
struct symbol_name *symtbl; /* symbol table */
mrb_sym symhash[256];
size_t symcapa;
#ifndef MRB_ENABLE_SYMBOLL_ALL
char symbuf[8]; /* buffer for small symbol names */
#endif
#ifdef MRB_ENABLE_DEBUG_HOOK
void (*code_fetch_hook)(struct mrb_state* mrb, struct mrb_irep *irep, mrb_code *pc, mrb_value *regs);
@@ -219,12 +271,10 @@ typedef struct mrb_state {
#else
mrb_atexit_func *atexit_stack;
#endif
mrb_int atexit_stack_len;
uint16_t atexit_stack_len;
uint16_t ecall_nest; /* prevent infinite recursive ecall() */
} mrb_state;
typedef mrb_value (*mrb_func_t)(mrb_state *mrb, mrb_value);
/**
* Defines a new class.
*
@@ -340,7 +390,7 @@ MRB_API void mrb_define_class_method(mrb_state *, struct RClass *, const char *,
MRB_API void mrb_define_singleton_method(mrb_state*, struct RObject*, const char*, mrb_func_t, mrb_aspec);
/**
* Defines a module fuction.
* Defines a module function.
*
* Example:
*
@@ -440,9 +490,10 @@ MRB_API void mrb_define_const(mrb_state*, struct RClass*, const char *name, mrb_
* }
* @param [mrb_state*] mrb_state* The mruby state reference.
* @param [struct RClass*] RClass* A class the method will be undefined from.
* @param [const char*] constchar* The name of the method to be undefined.
* @param [const char*] const char* The name of the method to be undefined.
*/
MRB_API void mrb_undef_method(mrb_state*, struct RClass*, const char*);
MRB_API void mrb_undef_method_id(mrb_state*, struct RClass*, mrb_sym);
/**
* Undefine a class method.
@@ -479,12 +530,12 @@ MRB_API void mrb_undef_method(mrb_state*, struct RClass*, const char*);
* }
* @param [mrb_state*] mrb_state* The mruby state reference.
* @param [RClass*] RClass* A class the class method will be undefined from.
* @param [constchar*] constchar* The name of the class method to be undefined.
* @param [const char*] const char* The name of the class method to be undefined.
*/
MRB_API void mrb_undef_class_method(mrb_state*, struct RClass*, const char*);
/**
* Initialize a new object instace of c class.
* Initialize a new object instance of c class.
*
* Example:
*
@@ -658,6 +709,9 @@ MRB_API struct RClass * mrb_module_get(mrb_state *mrb, const char *name);
* @return [struct RClass *] A reference to the module.
*/
MRB_API struct RClass * mrb_module_get_under(mrb_state *mrb, struct RClass *outer, const char *name);
/* a function to raise NotImplementedError with current method name */
MRB_API void mrb_notimplement(mrb_state*);
/* a function to be replacement of unimplemented method */
MRB_API mrb_value mrb_notimplement_m(mrb_state*, mrb_value);
/**
@@ -670,7 +724,6 @@ MRB_API mrb_value mrb_notimplement_m(mrb_state*, mrb_value);
* @return [mrb_value] The newly duplicated object.
*/
MRB_API mrb_value mrb_obj_dup(mrb_state *mrb, mrb_value obj);
MRB_API mrb_value mrb_check_to_integer(mrb_state *mrb, mrb_value val, const char *method);
/**
* Returns true if obj responds to the given method. If the method was defined for that
@@ -737,7 +790,7 @@ MRB_API struct RClass * mrb_define_module_under(mrb_state *mrb, struct RClass *o
#define MRB_ARGS_REQ(n) ((mrb_aspec)((n)&0x1f) << 18)
/**
* Funtion takes n optional arguments
* Function takes n optional arguments
*
* @param n
* The number of optional arguments.
@@ -745,7 +798,7 @@ MRB_API struct RClass * mrb_define_module_under(mrb_state *mrb, struct RClass *o
#define MRB_ARGS_OPT(n) ((mrb_aspec)((n)&0x1f) << 13)
/**
* Funtion takes n1 mandatory arguments and n2 optional arguments
* Function takes n1 mandatory arguments and n2 optional arguments
*
* @param n1
* The number of required arguments.
@@ -783,22 +836,22 @@ MRB_API struct RClass * mrb_define_module_under(mrb_state *mrb, struct RClass *o
*
* Must be a C string composed of the following format specifiers:
*
* | char | Ruby type | C types | Notes |
* | char | Ruby type | C types | Notes |
* |:----:|----------------|-------------------|----------------------------------------------------|
* | `o` | {Object} | {mrb_value} | Could be used to retrieve any type of argument |
* | `C` | {Class}/{Module} | {mrb_value} | |
* | `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} | char *, {mrb_int} | Receive two arguments; `s!` gives (`NULL`,`0`) for `nil` |
* | `s` | {String} | char *, {mrb_int} | Receive two arguments; `s!` gives (`NULL`,`0`) for `nil` |
* | `z` | {String} | char * | `NULL` terminated string; `z!` gives `NULL` for `nil` |
* | `a` | {Array} | {mrb_value} *, {mrb_int} | Receive two arguments; `a!` gives (`NULL`,`0`) for `nil` |
* | `f` | {Float} | {mrb_float} | |
* | `i` | {Integer} | {mrb_int} | |
* | `b` | boolean | {mrb_bool} | |
* | `n` | {Symbol} | {mrb_sym} | |
* | `&` | block | {mrb_value} | |
* | `*` | rest arguments | {mrb_value} *, {mrb_int} | Receive the rest of arguments as an array. |
* | `&` | block | {mrb_value} | &! raises exception if no block given. |
* | `*` | rest arguments | {mrb_value} *, {mrb_int} | Receive the rest of arguments as an array; *! avoid copy of the stack. |
* | &vert; | optional | | After this spec following specs would be optional. |
* | `?` | optional given | {mrb_bool} | `TRUE` if preceding argument is given. Used to check optional argument is given. |
*
@@ -809,10 +862,6 @@ typedef const char *mrb_args_format;
/**
* Retrieve arguments from mrb_state.
*
* When applicable, implicit conversions (such as `to_str`, `to_ary`, `to_hash`) are
* applied to received arguments.
* Used inside a function of mrb_func_t type.
*
* @param mrb The current MRuby state.
* @param format [mrb_args_format] is a list of format specifiers
* @param ... The passing variadic arguments must be a pointer of retrieving type.
@@ -827,11 +876,14 @@ mrb_get_mid(mrb_state *mrb) /* get method symbol */
return mrb->c->ci->mid;
}
static inline int
mrb_get_argc(mrb_state *mrb) /* get argc */
{
return mrb->c->ci->argc;
}
/**
* Retrieve number of arguments from mrb_state.
*
* Correctly handles *splat arguments.
*/
MRB_API mrb_int mrb_get_argc(mrb_state *mrb);
MRB_API mrb_value* mrb_get_argv(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.
@@ -945,13 +997,13 @@ MRB_API mrb_value mrb_str_new_static(mrb_state *mrb, const char *p, size_t len);
#define mrb_str_new_lit(mrb, lit) mrb_str_new_static(mrb, (lit), mrb_strlen_lit(lit))
#ifdef _WIN32
char* mrb_utf8_from_locale(const char *p, size_t len);
char* mrb_locale_from_utf8(const char *p, size_t len);
MRB_API char* mrb_utf8_from_locale(const char *p, int len);
MRB_API char* mrb_locale_from_utf8(const char *p, int len);
#define mrb_locale_free(p) free(p)
#define mrb_utf8_free(p) free(p)
#else
#define mrb_utf8_from_locale(p, l) (p)
#define mrb_locale_from_utf8(p, l) (p)
#define mrb_utf8_from_locale(p, l) ((char*)(p))
#define mrb_locale_from_utf8(p, l) ((char*)(p))
#define mrb_locale_free(p)
#define mrb_utf8_free(p)
#endif
@@ -1023,17 +1075,32 @@ MRB_API mrb_sym mrb_obj_to_sym(mrb_state *mrb, mrb_value name);
MRB_API mrb_bool mrb_obj_eq(mrb_state*, mrb_value, mrb_value);
MRB_API mrb_bool mrb_obj_equal(mrb_state*, mrb_value, mrb_value);
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, int base);
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_WITHOUT_FLOAT
MRB_API mrb_value mrb_Float(mrb_state *mrb, mrb_value 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);
static inline int mrb_gc_arena_save(mrb_state*);
static inline void mrb_gc_arena_restore(mrb_state*,int);
static inline int
mrb_gc_arena_save(mrb_state *mrb)
{
return mrb->gc.arena_idx;
}
static inline void
mrb_gc_arena_restore(mrb_state *mrb, int idx)
{
mrb->gc.arena_idx = idx;
}
MRB_API void mrb_garbage_collect(mrb_state*);
MRB_API void mrb_full_gc(mrb_state*);
MRB_API void mrb_incremental_gc(mrb_state *);
MRB_API int mrb_gc_arena_save(mrb_state*);
MRB_API void mrb_gc_arena_restore(mrb_state*,int);
MRB_API void mrb_gc_mark(mrb_state*,struct RBasic*);
#define mrb_gc_mark_value(mrb,val) do {\
if (!mrb_immediate_p(val)) mrb_gc_mark((mrb), mrb_basic_ptr(val)); \
@@ -1080,6 +1147,8 @@ MRB_API void mrb_warn(mrb_state *mrb, const char *fmt, ...);
MRB_API mrb_noreturn void mrb_bug(mrb_state *mrb, const char *fmt, ...);
MRB_API void mrb_print_backtrace(mrb_state *mrb);
MRB_API void mrb_print_error(mrb_state *mrb);
/* function for `raisef` formatting */
MRB_API mrb_value mrb_vformat(mrb_state *mrb, const char *format, va_list ap);
/* macros to get typical exception objects
note:
@@ -1097,9 +1166,12 @@ MRB_API void mrb_print_error(mrb_state *mrb);
#define E_SYNTAX_ERROR (mrb_exc_get(mrb, "SyntaxError"))
#define E_LOCALJUMP_ERROR (mrb_exc_get(mrb, "LocalJumpError"))
#define E_REGEXP_ERROR (mrb_exc_get(mrb, "RegexpError"))
#define E_FROZEN_ERROR (mrb_exc_get(mrb, "FrozenError"))
#define E_NOTIMP_ERROR (mrb_exc_get(mrb, "NotImplementedError"))
#ifndef MRB_WITHOUT_FLOAT
#define E_FLOATDOMAIN_ERROR (mrb_exc_get(mrb, "FloatDomainError"))
#endif
#define E_KEY_ERROR (mrb_exc_get(mrb, "KeyError"))
@@ -1121,6 +1193,7 @@ 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_fixnum(mrb_to_int(mrb, val))
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);
typedef enum call_type {
@@ -1130,7 +1203,7 @@ typedef enum call_type {
CALL_TYPE_MAX
} call_type;
MRB_API void mrb_define_alias(mrb_state *mrb, struct RClass *klass, const char *name1, const char *name2);
MRB_API void mrb_define_alias(mrb_state *mrb, struct RClass *c, const char *a, const char *b);
MRB_API const char *mrb_class_name(mrb_state *mrb, struct RClass* klass);
MRB_API void mrb_define_global_const(mrb_state *mrb, const char *name, mrb_value val);
@@ -1155,12 +1228,20 @@ MRB_API mrb_value mrb_fiber_resume(mrb_state *mrb, mrb_value fib, mrb_int argc,
*/
MRB_API mrb_value mrb_fiber_yield(mrb_state *mrb, mrb_int argc, const mrb_value *argv);
/*
* Check if a Fiber is alive
*
* @mrbgem mruby-fiber
*/
MRB_API mrb_value mrb_fiber_alive_p(mrb_state *mrb, mrb_value fib);
/*
* FiberError reference
*
* @mrbgem mruby-fiber
*/
#define E_FIBER_ERROR (mrb_exc_get(mrb, "FiberError"))
MRB_API void mrb_stack_extend(mrb_state*, mrb_int);
/* memory pool implementation */
typedef struct mrb_pool mrb_pool;
@@ -1183,21 +1264,21 @@ MRB_API mrb_value mrb_format(mrb_state *mrb, const char *format, ...);
/* use naive memcpy and memset instead */
#undef memcpy
#undef memset
static inline void*
static void*
mrbmemcpy(void *dst, const void *src, size_t n)
{
char *d = dst;
const char *s = src;
char *d = (char*)dst;
const char *s = (const char*)src;
while (n--)
*d++ = *s++;
return d;
}
#define memcpy(a,b,c) mrbmemcpy(a,b,c)
static inline void*
static void*
mrbmemset(void *s, int c, size_t n)
{
char *t = s;
char *t = (char*)s;
while (n--)
*t++ = c;
return s;
+61 -26
View File
@@ -21,22 +21,46 @@ typedef struct mrb_shared_array {
mrb_value *ptr;
} mrb_shared_array;
#define MRB_ARY_EMBED_LEN_MAX ((mrb_int)(sizeof(void*)*3/sizeof(mrb_value)))
struct RArray {
MRB_OBJECT_HEADER;
mrb_int len;
union {
mrb_int capa;
mrb_shared_array *shared;
} aux;
mrb_value *ptr;
struct {
mrb_int len;
union {
mrb_int capa;
mrb_shared_array *shared;
} aux;
mrb_value *ptr;
} heap;
mrb_value embed[MRB_ARY_EMBED_LEN_MAX];
} as;
};
#define mrb_ary_ptr(v) ((struct RArray*)(mrb_ptr(v)))
#define mrb_ary_value(p) mrb_obj_value((void*)(p))
#define RARRAY(v) ((struct RArray*)(mrb_ptr(v)))
#define RARRAY_LEN(a) (RARRAY(a)->len)
#define RARRAY_PTR(a) ((const mrb_value*)RARRAY(a)->ptr)
#define MRB_ARY_EMBED_MASK 7
#define ARY_EMBED_P(a) ((a)->flags & MRB_ARY_EMBED_MASK)
#define ARY_UNSET_EMBED_FLAG(a) ((a)->flags &= ~(MRB_ARY_EMBED_MASK))
#define ARY_EMBED_LEN(a) ((mrb_int)(((a)->flags & MRB_ARY_EMBED_MASK) - 1))
#define ARY_SET_EMBED_LEN(a,len) ((a)->flags = ((a)->flags&~MRB_ARY_EMBED_MASK) | ((uint32_t)(len) + 1))
#define ARY_EMBED_PTR(a) (&((a)->as.embed[0]))
#define ARY_LEN(a) (ARY_EMBED_P(a)?ARY_EMBED_LEN(a):(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))
#define ARY_SET_LEN(a,n) do {\
if (ARY_EMBED_P(a)) {\
mrb_assert((n) <= MRB_ARY_EMBED_LEN_MAX); \
ARY_SET_EMBED_LEN(a,n);\
}\
else\
(a)->as.heap.len = (n);\
} while (0)
#define ARY_CAPA(a) (ARY_EMBED_P(a)?MRB_ARY_EMBED_LEN_MAX:(a)->as.heap.aux.capa)
#define MRB_ARY_SHARED 256
#define ARY_SHARED_P(a) ((a)->flags & MRB_ARY_SHARED)
#define ARY_SET_SHARED_FLAG(a) ((a)->flags |= MRB_ARY_SHARED)
@@ -175,10 +199,11 @@ 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 an array
* Unshift an element into the array
*
* Equivalent to:
*
@@ -189,8 +214,35 @@ MRB_API mrb_value mrb_check_array_type(mrb_state *mrb, mrb_value self);
* @param item The item to unshift.
*/
MRB_API mrb_value mrb_ary_unshift(mrb_state *mrb, mrb_value self, mrb_value item);
/*
* Get nth element in the array
*
* Equivalent to:
*
* ary[offset]
*
* @param ary The target array.
* @param offset The element position (negative counts from the tail).
*/
MRB_API mrb_value mrb_ary_entry(mrb_value ary, mrb_int offset);
/*
* Replace subsequence of an array.
*
* Equivalent to:
*
* ary.shift
*
* @param mrb The mruby state reference.
* @param self The array from which the value will be shifted.
* @param head Beginning position of a replacement subsequence.
* @param len Length of a replacement subsequence.
* @param rpl The array of replacement elements.
* @return The receiver array.
*/
MRB_API mrb_value mrb_ary_splice(mrb_state *mrb, mrb_value self, mrb_int head, mrb_int len, mrb_value rpl);
/*
* Shifts the first element from the array.
*
@@ -205,7 +257,7 @@ MRB_API mrb_value mrb_ary_entry(mrb_value ary, mrb_int offset);
MRB_API mrb_value mrb_ary_shift(mrb_state *mrb, mrb_value self);
/*
* Removes all elements from this array
* Removes all elements from the array
*
* Equivalent to:
*
@@ -239,23 +291,6 @@ MRB_API mrb_value mrb_ary_join(mrb_state *mrb, mrb_value ary, mrb_value sep);
*/
MRB_API mrb_value mrb_ary_resize(mrb_state *mrb, mrb_value ary, mrb_int new_len);
static inline mrb_int
mrb_ary_len(mrb_state *mrb, mrb_value ary)
{
(void)mrb;
mrb_assert(mrb_array_p(ary));
return RARRAY_LEN(ary);
}
static inline mrb_value
ary_elt(mrb_value ary, mrb_int offset)
{
if (offset < 0 || RARRAY_LEN(ary) <= offset) {
return mrb_nil_value();
}
return RARRAY_PTR(ary)[offset];
}
MRB_END_DECL
#endif /* MRUBY_ARRAY_H */
+5 -1
View File
@@ -11,6 +11,10 @@
# error ---->> MRB_NAN_BOXING and MRB_USE_FLOAT conflict <<----
#endif
#ifdef MRB_WITHOUT_FLOAT
# error ---->> MRB_NAN_BOXING and MRB_WITHOUT_FLOAT conflict <<----
#endif
#ifdef MRB_INT64
# error ---->> MRB_NAN_BOXING and MRB_INT64 conflict <<----
#endif
@@ -77,7 +81,7 @@ typedef struct mrb_value {
} while (0)
#define SET_FLOAT_VALUE(mrb,r,v) do { \
if (v != v) { \
if ((v) != (v)) { \
(r).value.ttt = 0x7ff80000; \
(r).value.i = 0; \
} \
+8
View File
@@ -12,7 +12,9 @@
typedef struct mrb_value {
union {
#ifndef MRB_WITHOUT_FLOAT
mrb_float f;
#endif
void *p;
mrb_int i;
mrb_sym sym;
@@ -20,11 +22,15 @@ typedef struct mrb_value {
enum mrb_vtype tt;
} mrb_value;
#ifndef MRB_WITHOUT_FLOAT
#define mrb_float_pool(mrb,f) mrb_float_value(mrb,f)
#endif
#define mrb_ptr(o) (o).value.p
#define mrb_cptr(o) mrb_ptr(o)
#ifndef MRB_WITHOUT_FLOAT
#define mrb_float(o) (o).value.f
#endif
#define mrb_fixnum(o) (o).value.i
#define mrb_symbol(o) (o).value.sym
#define mrb_type(o) (o).tt
@@ -39,7 +45,9 @@ typedef struct mrb_value {
#define SET_TRUE_VALUE(r) BOXNIX_SET_VALUE(r, MRB_TT_TRUE, value.i, 1)
#define SET_BOOL_VALUE(r,b) BOXNIX_SET_VALUE(r, b ? MRB_TT_TRUE : MRB_TT_FALSE, value.i, 1)
#define SET_INT_VALUE(r,n) BOXNIX_SET_VALUE(r, MRB_TT_FIXNUM, value.i, (n))
#ifndef MRB_WITHOUT_FLOAT
#define SET_FLOAT_VALUE(mrb,r,v) BOXNIX_SET_VALUE(r, MRB_TT_FLOAT, value.f, (v))
#endif
#define SET_SYM_VALUE(r,v) BOXNIX_SET_VALUE(r, MRB_TT_SYMBOL, value.sym, (v))
#define SET_OBJ_VALUE(r,v) BOXNIX_SET_VALUE(r, (((struct RObject*)(v))->tt), value.p, (v))
#define SET_CPTR_VALUE(mrb,r,v) BOXNIX_SET_VALUE(r, MRB_TT_CPTR, value.p, v)
+28 -4
View File
@@ -15,10 +15,12 @@
#error MRB_INT64 cannot be used with MRB_WORD_BOXING in 32-bit mode.
#endif
#ifndef MRB_WITHOUT_FLOAT
struct RFloat {
MRB_OBJECT_HEADER;
mrb_float f;
};
#endif
struct RCptr {
MRB_OBJECT_HEADER;
@@ -26,7 +28,11 @@ struct RCptr {
};
#define MRB_FIXNUM_SHIFT 1
#ifdef MRB_WITHOUT_FLOAT
#define MRB_TT_HAS_BASIC MRB_TT_CPTR
#else
#define MRB_TT_HAS_BASIC MRB_TT_FLOAT
#endif
enum mrb_special_consts {
MRB_Qnil = 0,
@@ -39,6 +45,14 @@ enum mrb_special_consts {
#define MRB_SYMBOL_FLAG 0x0e
#define MRB_SPECIAL_SHIFT 8
#if defined(MRB_64BIT)
#define MRB_SYMBOL_BITSIZE (sizeof(mrb_sym) * CHAR_BIT)
#define MRB_SYMBOL_MAX UINT32_MAX
#else
#define MRB_SYMBOL_BITSIZE (sizeof(mrb_sym) * CHAR_BIT - MRB_SPECIAL_SHIFT)
#define MRB_SYMBOL_MAX (UINT32_MAX >> MRB_SPECIAL_SHIFT)
#endif
typedef union mrb_value {
union {
void *p;
@@ -48,24 +62,32 @@ typedef union mrb_value {
};
struct {
unsigned int sym_flag : MRB_SPECIAL_SHIFT;
mrb_sym sym : (sizeof(mrb_sym) * CHAR_BIT);
mrb_sym sym : MRB_SYMBOL_BITSIZE;
};
struct RBasic *bp;
#ifndef MRB_WITHOUT_FLOAT
struct RFloat *fp;
#endif
struct RCptr *vp;
} value;
unsigned long w;
} mrb_value;
MRB_API mrb_value mrb_word_boxing_cptr_value(struct mrb_state*, void*);
#ifndef MRB_WITHOUT_FLOAT
MRB_API mrb_value mrb_word_boxing_float_value(struct mrb_state*, mrb_float);
MRB_API mrb_value mrb_word_boxing_float_pool(struct mrb_state*, mrb_float);
#endif
#ifndef MRB_WITHOUT_FLOAT
#define mrb_float_pool(mrb,f) mrb_word_boxing_float_pool(mrb,f)
#endif
#define mrb_ptr(o) (o).value.p
#define mrb_cptr(o) (o).value.vp->p
#ifndef MRB_WITHOUT_FLOAT
#define mrb_float(o) (o).value.fp->f
#endif
#define mrb_fixnum(o) ((mrb_int)(o).value.i)
#define mrb_symbol(o) (o).value.sym
@@ -106,12 +128,14 @@ mrb_type(mrb_value o)
}\
} while (0)
#define SET_FLOAT_VALUE(mrb,r,v) r = mrb_word_boxing_float_value(mrb, v)
#define SET_CPTR_VALUE(mrb,r,v) r = mrb_word_boxing_cptr_value(mrb, v)
#ifndef MRB_WITHOUT_FLOAT
#define SET_FLOAT_VALUE(mrb,r,v) ((r) = mrb_word_boxing_float_value(mrb, v))
#endif
#define SET_CPTR_VALUE(mrb,r,v) ((r) = mrb_word_boxing_cptr_value(mrb, v))
#define SET_NIL_VALUE(r) BOXWORD_SET_VALUE(r, MRB_TT_FALSE, value.i, 0)
#define SET_FALSE_VALUE(r) BOXWORD_SET_VALUE(r, MRB_TT_FALSE, value.i, 1)
#define SET_TRUE_VALUE(r) BOXWORD_SET_VALUE(r, MRB_TT_TRUE, value.i, 1)
#define SET_BOOL_VALUE(r,b) BOXWORD_SET_VALUE(r, b ? MRB_TT_TRUE : MRB_TT_FALSE, value.i, 1)
#define SET_BOOL_VALUE(r,b) BOXWORD_SET_VALUE(r, (b) ? MRB_TT_TRUE : MRB_TT_FALSE, value.i, 1)
#define SET_INT_VALUE(r,n) BOXWORD_SET_VALUE(r, MRB_TT_FIXNUM, value.i, (n))
#define SET_SYM_VALUE(r,v) BOXWORD_SET_VALUE(r, MRB_TT_SYMBOL, value.sym, (v))
#define SET_OBJ_VALUE(r,v) BOXWORD_SET_VALUE(r, (((struct RObject*)(v))->tt), value.p, (v))
+25 -18
View File
@@ -22,9 +22,6 @@ struct RClass {
};
#define mrb_class_ptr(v) ((struct RClass*)(mrb_ptr(v)))
#define RCLASS_SUPER(v) (((struct RClass*)(mrb_ptr(v)))->super)
#define RCLASS_IV_TBL(v) (((struct RClass*)(mrb_ptr(v)))->iv)
#define RCLASS_M_TBL(v) (((struct RClass*)(mrb_ptr(v)))->mt)
static inline struct RClass*
mrb_class(mrb_state *mrb, mrb_value v)
@@ -40,8 +37,10 @@ mrb_class(mrb_state *mrb, mrb_value v)
return mrb->symbol_class;
case MRB_TT_FIXNUM:
return mrb->fixnum_class;
#ifndef MRB_WITHOUT_FLOAT
case MRB_TT_FLOAT:
return mrb->float_class;
#endif
case MRB_TT_CPTR:
return mrb->object_class;
case MRB_TT_ENV:
@@ -51,36 +50,44 @@ mrb_class(mrb_state *mrb, mrb_value v)
}
}
/* TODO: figure out where to put user flags */
#define MRB_FLAG_IS_FROZEN (1 << 18)
#define MRB_FLAG_IS_PREPENDED (1 << 19)
#define MRB_FLAG_IS_ORIGIN (1 << 20)
/* flags:
20: frozen
19: is_prepended
18: is_origin
17: is_inherited (used by method cache)
16: unused
0-15: instance type
*/
#define MRB_FL_CLASS_IS_PREPENDED (1 << 19)
#define MRB_FL_CLASS_IS_ORIGIN (1 << 18)
#define MRB_CLASS_ORIGIN(c) do {\
if (c->flags & MRB_FLAG_IS_PREPENDED) {\
c = c->super;\
while (!(c->flags & MRB_FLAG_IS_ORIGIN)) {\
c = c->super;\
if ((c)->flags & MRB_FL_CLASS_IS_PREPENDED) {\
(c) = (c)->super;\
while (!((c)->flags & MRB_FL_CLASS_IS_ORIGIN)) {\
(c) = (c)->super;\
}\
}\
} while (0)
#define MRB_FL_CLASS_IS_INHERITED (1 << 17)
#define MRB_INSTANCE_TT_MASK (0xFF)
#define MRB_SET_INSTANCE_TT(c, tt) c->flags = ((c->flags & ~MRB_INSTANCE_TT_MASK) | (char)tt)
#define MRB_INSTANCE_TT(c) (enum mrb_vtype)(c->flags & MRB_INSTANCE_TT_MASK)
#define MRB_SET_INSTANCE_TT(c, tt) ((c)->flags = (((c)->flags & ~MRB_INSTANCE_TT_MASK) | (char)(tt)))
#define MRB_INSTANCE_TT(c) (enum mrb_vtype)((c)->flags & MRB_INSTANCE_TT_MASK)
MRB_API struct RClass* mrb_define_class_id(mrb_state*, mrb_sym, struct RClass*);
MRB_API struct RClass* mrb_define_module_id(mrb_state*, mrb_sym);
MRB_API struct RClass *mrb_vm_define_class(mrb_state*, mrb_value, mrb_value, mrb_sym);
MRB_API struct RClass *mrb_vm_define_module(mrb_state*, mrb_value, mrb_sym);
MRB_API void mrb_define_method_raw(mrb_state*, struct RClass*, mrb_sym, struct RProc *);
MRB_API void mrb_define_method_raw(mrb_state*, struct RClass*, mrb_sym, mrb_method_t);
MRB_API void mrb_define_method_id(mrb_state *mrb, struct RClass *c, mrb_sym mid, mrb_func_t func, mrb_aspec aspec);
MRB_API void mrb_alias_method(mrb_state *mrb, struct RClass *c, mrb_sym a, mrb_sym b);
MRB_API void mrb_alias_method(mrb_state*, struct RClass *c, mrb_sym a, mrb_sym b);
MRB_API struct RClass *mrb_class_outer_module(mrb_state*, struct RClass *);
MRB_API struct RProc *mrb_method_search_vm(mrb_state*, struct RClass**, mrb_sym);
MRB_API struct RProc *mrb_method_search(mrb_state*, struct RClass*, mrb_sym);
MRB_API mrb_method_t mrb_method_search_vm(mrb_state*, struct RClass**, mrb_sym);
MRB_API mrb_method_t mrb_method_search(mrb_state*, struct RClass*, mrb_sym);
MRB_API struct RClass* mrb_class_real(struct RClass* cl);
void mrb_class_name_class(mrb_state*, struct RClass*, struct RClass*, mrb_sym);
mrb_value mrb_class_find_path(mrb_state*, struct RClass*);
void mrb_gc_mark_mt(mrb_state*, struct RClass*);
size_t mrb_gc_mark_mt_size(mrb_state*, struct RClass*);
void mrb_gc_free_mt(mrb_state*, struct RClass*);
+7 -2
View File
@@ -7,6 +7,11 @@
#ifndef MRUBY_COMMON_H
#define MRUBY_COMMON_H
#ifdef __APPLE__
#ifndef __TARGETCONDITIONALS__
#include "TargetConditionals.h"
#endif
#endif
#ifdef __cplusplus
#ifdef MRB_ENABLE_CXX_ABI
@@ -14,7 +19,7 @@
#define MRB_END_DECL
#else
# define MRB_BEGIN_DECL extern "C" {
# define MRB_END_DECL }
# define MRB_END_DECL }
#endif
#else
/** Start declarations in C mode */
@@ -29,7 +34,7 @@
MRB_BEGIN_DECL
/** Declare a function that never returns. */
#if __STDC_VERSION__ >= 201112L
#if defined __STDC_VERSION__ && __STDC_VERSION__ >= 201112L
# define mrb_noreturn _Noreturn
#elif defined __GNUC__ && !defined __STRICT_ANSI__
# define mrb_noreturn __attribute__((noreturn))
+12 -10
View File
@@ -33,6 +33,9 @@ typedef struct mrbc_context {
mrb_bool no_exec:1;
mrb_bool keep_lv:1;
mrb_bool no_optimize:1;
mrb_bool on_eval:1;
size_t parser_nerr;
} mrbc_context;
MRB_API mrbc_context* mrbc_context_new(mrb_state *mrb);
@@ -115,7 +118,7 @@ struct mrb_parser_state {
FILE *f;
#endif
mrbc_context *cxt;
char const *filename;
mrb_sym filename_sym;
int lineno;
int column;
@@ -136,11 +139,10 @@ struct mrb_parser_state {
int tidx;
int tsiz;
mrb_ast_node *all_heredocs; /* list of mrb_parser_heredoc_info* */
mrb_ast_node *all_heredocs; /* list of mrb_parser_heredoc_info* */
mrb_ast_node *heredocs_from_nextline;
mrb_ast_node *parsing_heredoc;
mrb_ast_node *lex_strterm_before_heredoc;
mrb_bool heredoc_end_now:1; /* for mirb */
void *ylval;
@@ -149,13 +151,14 @@ struct mrb_parser_state {
mrb_ast_node *tree;
mrb_bool no_optimize:1;
mrb_bool on_eval:1;
mrb_bool capture_errors:1;
struct mrb_parser_message error_buffer[10];
struct mrb_parser_message warn_buffer[10];
mrb_sym* filename_table;
size_t filename_table_length;
int current_filename_index;
uint16_t filename_table_length;
uint16_t current_filename_index;
struct mrb_jmpbuf* jmp;
};
@@ -163,17 +166,16 @@ struct mrb_parser_state {
MRB_API struct mrb_parser_state* mrb_parser_new(mrb_state*);
MRB_API void mrb_parser_free(struct mrb_parser_state*);
MRB_API void mrb_parser_parse(struct mrb_parser_state*,mrbc_context*);
MRB_API double mrb_float_read(const char*, char**);
MRB_API void mrb_parser_set_filename(struct mrb_parser_state*, char const*);
MRB_API char const* mrb_parser_get_filename(struct mrb_parser_state*, uint16_t idx);
MRB_API mrb_sym mrb_parser_get_filename(struct mrb_parser_state*, uint16_t idx);
/* utility functions */
#ifndef MRB_DISABLE_STDIO
MRB_API struct mrb_parser_state* mrb_parse_file(mrb_state*,FILE*,mrbc_context*);
#endif
MRB_API struct mrb_parser_state* mrb_parse_string(mrb_state*,const char*,mrbc_context*);
MRB_API struct mrb_parser_state* mrb_parse_nstring(mrb_state*,const char*,int,mrbc_context*);
MRB_API struct mrb_parser_state* mrb_parse_nstring(mrb_state*,const char*,size_t,mrbc_context*);
MRB_API struct RProc* mrb_generate_code(mrb_state*, struct mrb_parser_state*);
MRB_API mrb_value mrb_load_exec(mrb_state *mrb, struct mrb_parser_state *p, mrbc_context *c);
@@ -183,9 +185,9 @@ MRB_API mrb_value mrb_load_file(mrb_state*,FILE*);
MRB_API mrb_value mrb_load_file_cxt(mrb_state*,FILE*, mrbc_context *cxt);
#endif
MRB_API mrb_value mrb_load_string(mrb_state *mrb, const char *s);
MRB_API mrb_value mrb_load_nstring(mrb_state *mrb, const char *s, int len);
MRB_API mrb_value mrb_load_nstring(mrb_state *mrb, const char *s, size_t len);
MRB_API mrb_value mrb_load_string_cxt(mrb_state *mrb, const char *s, mrbc_context *cxt);
MRB_API mrb_value mrb_load_nstring_cxt(mrb_state *mrb, const char *s, int len, mrbc_context *cxt);
MRB_API mrb_value mrb_load_nstring_cxt(mrb_state *mrb, const char *s, size_t len, mrbc_context *cxt);
/** @} */
MRB_END_DECL
+5 -4
View File
@@ -39,10 +39,11 @@ MRB_API struct RData *mrb_data_object_alloc(mrb_state *mrb, struct RClass* klass
#define Data_Wrap_Struct(mrb,klass,type,ptr)\
mrb_data_object_alloc(mrb,klass,ptr,type)
#define Data_Make_Struct(mrb,klass,strct,type,sval,data) do { \
sval = mrb_malloc(mrb, sizeof(strct)); \
{ static const strct zero = { 0 }; *sval = zero; };\
data = Data_Wrap_Struct(mrb,klass,type,sval);\
#define Data_Make_Struct(mrb,klass,strct,type,sval,data_obj) do { \
(data_obj) = Data_Wrap_Struct(mrb,klass,type,NULL);\
(sval) = mrb_malloc(mrb, sizeof(strct)); \
{ static const strct zero = { 0 }; *(sval) = zero; };\
(data_obj)->data = (sval);\
} while (0)
#define RDATA(obj) ((struct RData *)(mrb_ptr(obj)))
+6 -6
View File
@@ -26,7 +26,6 @@ typedef struct mrb_irep_debug_info_line {
typedef struct mrb_irep_debug_info_file {
uint32_t start_pos;
const char *filename;
mrb_sym filename_sym;
uint32_t line_entry_count;
mrb_debug_line_type line_type;
@@ -47,18 +46,19 @@ typedef struct mrb_irep_debug_info {
* get line from irep's debug info and program counter
* @return returns NULL if not found
*/
MRB_API const char *mrb_debug_get_filename(mrb_irep *irep, uint32_t pc);
MRB_API const char *mrb_debug_get_filename(mrb_state *mrb, mrb_irep *irep, ptrdiff_t pc);
/*
* get line from irep's debug info and program counter
* @return returns -1 if not found
*/
MRB_API int32_t mrb_debug_get_line(mrb_irep *irep, uint32_t pc);
MRB_API int32_t mrb_debug_get_line(mrb_state *mrb, mrb_irep *irep, ptrdiff_t pc);
MRB_API mrb_irep_debug_info_file *mrb_debug_info_append_file(
mrb_state *mrb, mrb_irep *irep,
uint32_t start_pos, uint32_t end_pos);
MRB_API mrb_irep_debug_info *mrb_debug_info_alloc(mrb_state *mrb, mrb_irep *irep);
MRB_API mrb_irep_debug_info_file *mrb_debug_info_append_file(
mrb_state *mrb, mrb_irep_debug_info *info,
const char *filename, uint16_t *lines,
uint32_t start_pos, uint32_t end_pos);
MRB_API void mrb_debug_info_free(mrb_state *mrb, mrb_irep_debug_info *d);
MRB_END_DECL
+2 -2
View File
@@ -52,11 +52,11 @@ MRB_API mrb_irep *mrb_read_irep(mrb_state*, const uint8_t*);
/* Rite Binary File header */
#define RITE_BINARY_IDENT "RITE"
#define RITE_BINARY_IDENT_LIL "ETIR"
#define RITE_BINARY_FORMAT_VER "0004"
#define RITE_BINARY_FORMAT_VER "0006"
#define RITE_COMPILER_NAME "MATZ"
#define RITE_COMPILER_VERSION "0000"
#define RITE_VM_VER "0000"
#define RITE_VM_VER "0002"
#define RITE_BINARY_EOF "END\0"
#define RITE_SECTION_IREP_IDENT "IREP"
+2 -3
View File
@@ -24,17 +24,16 @@ struct RException {
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_str_lit(mrb, c, lit) mrb_exc_new_str(mrb, c, mrb_str_new_lit(mrb, lit))
MRB_API mrb_value mrb_make_exception(mrb_state *mrb, int argc, const mrb_value *argv);
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_API mrb_noreturn void mrb_no_method_error(mrb_state *mrb, mrb_sym id, mrb_value args, const char *fmt, ...);
/* declaration for fail method */
/* declaration for `fail` method */
MRB_API mrb_value mrb_f_raise(mrb_state*, mrb_value);
struct RBreak {
MRB_OBJECT_HEADER;
struct iv_tbl *iv;
struct RProc *proc;
mrb_value val;
};
+11
View File
@@ -33,6 +33,13 @@ typedef enum {
MRB_GC_STATE_SWEEP
} mrb_gc_state;
/* Disable MSVC warning "C4200: nonstandard extension used: zero-sized array
* in struct/union" when in C++ mode */
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4200)
#endif
typedef struct mrb_heap_page {
struct RBasic *freelist;
struct mrb_heap_page *prev;
@@ -43,6 +50,10 @@ typedef struct mrb_heap_page {
void *objects[];
} mrb_heap_page;
#ifdef _MSC_VER
#pragma warning(pop)
#endif
typedef struct mrb_gc {
mrb_heap_page *heaps; /* heaps for GC */
mrb_heap_page *sweeps;
+56 -9
View File
@@ -8,7 +8,6 @@
#define MRUBY_HASH_H
#include "common.h"
#include <mruby/khash.h>
/**
* Hash class
@@ -18,13 +17,15 @@ MRB_BEGIN_DECL
struct RHash {
MRB_OBJECT_HEADER;
struct iv_tbl *iv;
struct kh_ht *ht;
struct htable *ht;
};
#define mrb_hash_ptr(v) ((struct RHash*)(mrb_ptr(v)))
#define mrb_hash_value(p) mrb_obj_value((void*)(p))
MRB_API mrb_value mrb_hash_new_capa(mrb_state*, mrb_int);
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.
@@ -74,7 +75,7 @@ MRB_API mrb_value mrb_hash_get(mrb_state *mrb, mrb_value hash, mrb_value key);
*
* Equivalent to:
*
* hash.hash_key?(key) ? hash[key] : def
* hash.key?(key) ? hash[key] : def
*
* @param mrb The mruby state reference.
* @param hash The target hash.
@@ -110,7 +111,19 @@ MRB_API mrb_value mrb_hash_delete_key(mrb_state *mrb, mrb_value hash, mrb_value
* @return An array with the keys of the hash.
*/
MRB_API mrb_value mrb_hash_keys(mrb_state *mrb, mrb_value hash);
MRB_API mrb_value mrb_check_hash_type(mrb_state *mrb, mrb_value hash);
/*
* Check if the hash has the key.
*
* Equivalent to:
*
* hash.key?(key)
*
* @param mrb The mruby state reference.
* @param hash The target hash.
* @param key The key to check existence.
* @return True if the hash has the key
*/
MRB_API mrb_bool mrb_hash_key_p(mrb_state *mrb, mrb_value hash, mrb_value key);
/*
* Check if the hash is empty
@@ -123,7 +136,7 @@ MRB_API mrb_value mrb_check_hash_type(mrb_state *mrb, mrb_value hash);
* @param self The target hash.
* @return True if the hash is empty, false otherwise.
*/
MRB_API mrb_value mrb_hash_empty_p(mrb_state *mrb, mrb_value self);
MRB_API mrb_bool mrb_hash_empty_p(mrb_state *mrb, mrb_value self);
/*
* Gets an array of values.
@@ -151,21 +164,51 @@ MRB_API mrb_value mrb_hash_values(mrb_state *mrb, mrb_value hash);
*/
MRB_API mrb_value mrb_hash_clear(mrb_state *mrb, mrb_value hash);
/* declaration of struct kh_ht */
/*
* Get hash size.
*
* Equivalent to:
*
* hash.size
*
* @param mrb The mruby state reference.
* @param hash The target hash.
* @return The hash size.
*/
MRB_API mrb_int mrb_hash_size(mrb_state *mrb, mrb_value hash);
/*
* Copies the hash.
*
*
* @param mrb The mruby state reference.
* @param hash The target hash.
* @return The copy of the hash
*/
MRB_API mrb_value mrb_hash_dup(mrb_state *mrb, mrb_value hash);
/*
* Merges two hashes. The first hash will be modified by the
* second hash.
*
* @param mrb The mruby state reference.
* @param hash1 The target hash.
* @param hash2 Updating hash
*/
MRB_API void mrb_hash_merge(mrb_state *mrb, mrb_value hash1, mrb_value hash2);
/* declaration of struct mrb_hash_value */
/* be careful when you touch the internal */
typedef struct {
mrb_value v;
mrb_int n;
} mrb_hash_value;
KHASH_DECLARE(ht, mrb_value, mrb_hash_value, TRUE)
/* RHASH_TBL allocates st_table if not available. */
#define RHASH(obj) ((struct RHash*)(mrb_ptr(obj)))
#define RHASH_TBL(h) (RHASH(h)->ht)
#define RHASH_IFNONE(h) mrb_iv_get(mrb, (h), mrb_intern_lit(mrb, "ifnone"))
#define RHASH_PROCDEFAULT(h) RHASH_IFNONE(h)
MRB_API struct kh_ht * mrb_hash_tbl(mrb_state *mrb, mrb_value hash);
#define MRB_HASH_DEFAULT 1
#define MRB_HASH_PROC_DEFAULT 2
@@ -177,6 +220,10 @@ void mrb_gc_mark_hash(mrb_state*, struct RHash*);
size_t mrb_gc_mark_hash_size(mrb_state*, struct RHash*);
void mrb_gc_free_hash(mrb_state*, struct RHash*);
/* return non zero to break the loop */
typedef int (mrb_hash_foreach_func)(mrb_state *mrb, mrb_value key, mrb_value val, void *data);
MRB_API void mrb_hash_foreach(mrb_state *mrb, struct RHash *hash, mrb_hash_foreach_func *func, void *p);
MRB_END_DECL
#endif /* MRUBY_HASH_H */
+18 -4
View File
@@ -39,22 +39,36 @@ typedef struct mrb_irep {
struct mrb_locals *lv;
/* debug info */
mrb_bool own_filename;
const char *filename;
uint16_t *lines;
struct mrb_irep_debug_info* debug_info;
size_t ilen, plen, slen, rlen, refcnt;
uint16_t ilen, plen, slen, rlen;
uint32_t refcnt;
} mrb_irep;
#define MRB_ISEQ_NO_FREE 1
MRB_API mrb_irep *mrb_add_irep(mrb_state *mrb);
/* @param [const uint8_t*] irep code, expected as a literal */
MRB_API mrb_value mrb_load_irep(mrb_state*, const uint8_t*);
/* @param [const uint8_t*] irep code, expected as a literal */
MRB_API mrb_value mrb_load_irep_cxt(mrb_state*, const uint8_t*, mrbc_context*);
void mrb_irep_free(mrb_state*, struct mrb_irep*);
void mrb_irep_incref(mrb_state*, struct mrb_irep*);
void mrb_irep_decref(mrb_state*, struct mrb_irep*);
void mrb_irep_cutref(mrb_state*, struct mrb_irep*);
void mrb_irep_remove_lv(mrb_state *mrb, mrb_irep *irep);
struct mrb_insn_data {
uint8_t insn;
uint16_t a;
uint16_t b;
uint8_t c;
};
struct mrb_insn_data mrb_decode_insn(mrb_code *pc);
MRB_END_DECL
+13 -9
View File
@@ -16,21 +16,25 @@
*/
MRB_BEGIN_DECL
#define POSFIXABLE(f) ((f) <= MRB_INT_MAX)
#define NEGFIXABLE(f) ((f) >= MRB_INT_MIN)
#define FIXABLE(f) (POSFIXABLE(f) && NEGFIXABLE(f))
#ifdef MRB_INT64
#define FIXABLE_FLOAT(f) FIXABLE((mrb_int)(f))
#else
#define FIXABLE_FLOAT(f) FIXABLE(f)
#define TYPED_POSFIXABLE(f,t) ((f) <= (t)MRB_INT_MAX)
#define TYPED_NEGFIXABLE(f,t) ((f) >= (t)MRB_INT_MIN)
#define TYPED_FIXABLE(f,t) (TYPED_POSFIXABLE(f,t) && TYPED_NEGFIXABLE(f,t))
#define POSFIXABLE(f) TYPED_POSFIXABLE(f,mrb_int)
#define NEGFIXABLE(f) TYPED_NEGFIXABLE(f,mrb_int)
#define FIXABLE(f) TYPED_FIXABLE(f,mrb_int)
#ifndef MRB_WITHOUT_FLOAT
#define FIXABLE_FLOAT(f) TYPED_FIXABLE(f,double)
#endif
#ifndef MRB_WITHOUT_FLOAT
MRB_API mrb_value mrb_flo_to_fixnum(mrb_state *mrb, mrb_value val);
MRB_API mrb_value mrb_fixnum_to_str(mrb_state *mrb, mrb_value x, int base);
#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_WITHOUT_FLOAT
MRB_API mrb_value mrb_float_to_str(mrb_state *mrb, mrb_value x, const char *fmt);
MRB_API mrb_float mrb_to_flo(mrb_state *mrb, mrb_value x);
#endif
mrb_value mrb_fixnum_plus(mrb_state *mrb, mrb_value x, mrb_value y);
mrb_value mrb_fixnum_minus(mrb_state *mrb, mrb_value x, mrb_value y);
+5 -4
View File
@@ -14,7 +14,7 @@
struct RClass *c;\
struct RBasic *gcnext
#define MRB_FLAG_TEST(obj, flag) ((obj)->flags & flag)
#define MRB_FLAG_TEST(obj, flag) ((obj)->flags & (flag))
struct RBasic {
@@ -22,9 +22,10 @@ struct RBasic {
};
#define mrb_basic_ptr(v) ((struct RBasic*)(mrb_ptr(v)))
#define MRB_FROZEN_P(o) ((o)->flags & MRB_FLAG_IS_FROZEN)
#define MRB_SET_FROZEN_FLAG(o) ((o)->flags |= MRB_FLAG_IS_FROZEN)
#define MRB_UNSET_FROZEN_FLAG(o) ((o)->flags &= ~MRB_FLAG_IS_FROZEN)
#define MRB_FL_OBJ_IS_FROZEN (1 << 20)
#define MRB_FROZEN_P(o) ((o)->flags & MRB_FL_OBJ_IS_FROZEN)
#define MRB_SET_FROZEN_FLAG(o) ((o)->flags |= MRB_FL_OBJ_IS_FROZEN)
#define MRB_UNSET_FROZEN_FLAG(o) ((o)->flags &= ~MRB_FL_OBJ_IS_FROZEN)
struct RObject {
MRB_OBJECT_HEADER;
+47 -139
View File
@@ -7,145 +7,10 @@
#ifndef MRUBY_OPCODE_H
#define MRUBY_OPCODE_H
#define MAXARG_Bx (0xffff)
#define MAXARG_sBx (MAXARG_Bx>>1) /* 'sBx' is signed */
/* instructions: packed 32 bit */
/* ------------------------------- */
/* A:B:C:OP = 9: 9: 7: 7 */
/* A:Bx:OP = 9:16: 7 */
/* Ax:OP = 25: 7 */
/* A:Bz:Cz:OP = 9:14: 2: 7 */
#define GET_OPCODE(i) ((int)(((mrb_code)(i)) & 0x7f))
#define GETARG_A(i) ((int)((((mrb_code)(i)) >> 23) & 0x1ff))
#define GETARG_B(i) ((int)((((mrb_code)(i)) >> 14) & 0x1ff))
#define GETARG_C(i) ((int)((((mrb_code)(i)) >> 7) & 0x7f))
#define GETARG_Bx(i) ((int)((((mrb_code)(i)) >> 7) & 0xffff))
#define GETARG_sBx(i) ((int)(GETARG_Bx(i)-MAXARG_sBx))
#define GETARG_Ax(i) ((int32_t)((((mrb_code)(i)) >> 7) & 0x1ffffff))
#define GETARG_UNPACK_b(i,n1,n2) ((int)((((mrb_code)(i)) >> (7+(n2))) & (((1<<(n1))-1))))
#define GETARG_UNPACK_c(i,n1,n2) ((int)((((mrb_code)(i)) >> 7) & (((1<<(n2))-1))))
#define GETARG_b(i) GETARG_UNPACK_b(i,14,2)
#define GETARG_c(i) GETARG_UNPACK_c(i,14,2)
#define MKOPCODE(op) ((op) & 0x7f)
#define MKARG_A(c) ((mrb_code)((c) & 0x1ff) << 23)
#define MKARG_B(c) ((mrb_code)((c) & 0x1ff) << 14)
#define MKARG_C(c) (((c) & 0x7f) << 7)
#define MKARG_Bx(v) ((mrb_code)((v) & 0xffff) << 7)
#define MKARG_sBx(v) MKARG_Bx((v)+MAXARG_sBx)
#define MKARG_Ax(v) ((mrb_code)((v) & 0x1ffffff) << 7)
#define MKARG_PACK(b,n1,c,n2) ((((b) & ((1<<n1)-1)) << (7+n2))|(((c) & ((1<<n2)-1)) << 7))
#define MKARG_bc(b,c) MKARG_PACK(b,14,c,2)
#define MKOP_A(op,a) (MKOPCODE(op)|MKARG_A(a))
#define MKOP_AB(op,a,b) (MKOP_A(op,a)|MKARG_B(b))
#define MKOP_ABC(op,a,b,c) (MKOP_AB(op,a,b)|MKARG_C(c))
#define MKOP_ABx(op,a,bx) (MKOP_A(op,a)|MKARG_Bx(bx))
#define MKOP_Bx(op,bx) (MKOPCODE(op)|MKARG_Bx(bx))
#define MKOP_sBx(op,sbx) (MKOPCODE(op)|MKARG_sBx(sbx))
#define MKOP_AsBx(op,a,sbx) (MKOP_A(op,a)|MKARG_sBx(sbx))
#define MKOP_Ax(op,ax) (MKOPCODE(op)|MKARG_Ax(ax))
#define MKOP_Abc(op,a,b,c) (MKOP_A(op,a)|MKARG_bc(b,c))
enum {
/*-----------------------------------------------------------------------
operation code operand description
------------------------------------------------------------------------*/
OP_NOP=0,/* */
OP_MOVE,/* A B R(A) := R(B) */
OP_LOADL,/* A Bx R(A) := Pool(Bx) */
OP_LOADI,/* A sBx R(A) := sBx */
OP_LOADSYM,/* A Bx R(A) := Syms(Bx) */
OP_LOADNIL,/* A R(A) := nil */
OP_LOADSELF,/* A R(A) := self */
OP_LOADT,/* A R(A) := true */
OP_LOADF,/* A R(A) := false */
OP_GETGLOBAL,/* A Bx R(A) := getglobal(Syms(Bx)) */
OP_SETGLOBAL,/* A Bx setglobal(Syms(Bx), R(A)) */
OP_GETSPECIAL,/*A Bx R(A) := Special[Bx] */
OP_SETSPECIAL,/*A Bx Special[Bx] := R(A) */
OP_GETIV,/* A Bx R(A) := ivget(Syms(Bx)) */
OP_SETIV,/* A Bx ivset(Syms(Bx),R(A)) */
OP_GETCV,/* A Bx R(A) := cvget(Syms(Bx)) */
OP_SETCV,/* A Bx cvset(Syms(Bx),R(A)) */
OP_GETCONST,/* A Bx R(A) := constget(Syms(Bx)) */
OP_SETCONST,/* A Bx constset(Syms(Bx),R(A)) */
OP_GETMCNST,/* A Bx R(A) := R(A)::Syms(Bx) */
OP_SETMCNST,/* A Bx R(A+1)::Syms(Bx) := R(A) */
OP_GETUPVAR,/* A B C R(A) := uvget(B,C) */
OP_SETUPVAR,/* A B C uvset(B,C,R(A)) */
OP_JMP,/* sBx pc+=sBx */
OP_JMPIF,/* A sBx if R(A) pc+=sBx */
OP_JMPNOT,/* A sBx if !R(A) pc+=sBx */
OP_ONERR,/* sBx rescue_push(pc+sBx) */
OP_RESCUE,/* A B C if A (if C exc=R(A) else R(A) := exc);
if B R(B) := exc.isa?(R(B)); clear(exc) */
OP_POPERR,/* A A.times{rescue_pop()} */
OP_RAISE,/* A raise(R(A)) */
OP_EPUSH,/* Bx ensure_push(SEQ[Bx]) */
OP_EPOP,/* A A.times{ensure_pop().call} */
OP_SEND,/* A B C R(A) := call(R(A),Syms(B),R(A+1),...,R(A+C)) */
OP_SENDB,/* A B C R(A) := call(R(A),Syms(B),R(A+1),...,R(A+C),&R(A+C+1))*/
OP_FSEND,/* A B C R(A) := fcall(R(A),Syms(B),R(A+1),...,R(A+C-1)) */
OP_CALL,/* A R(A) := self.call(frame.argc, frame.argv) */
OP_SUPER,/* A C R(A) := super(R(A+1),... ,R(A+C+1)) */
OP_ARGARY,/* A Bx R(A) := argument array (16=6:1:5:4) */
OP_ENTER,/* Ax arg setup according to flags (23=5:5:1:5:5:1:1) */
OP_KARG,/* A B C R(A) := kdict[Syms(B)]; if C kdict.rm(Syms(B)) */
OP_KDICT,/* A C R(A) := kdict */
OP_RETURN,/* A B return R(A) (B=normal,in-block return/break) */
OP_TAILCALL,/* A B C return call(R(A),Syms(B),*R(C)) */
OP_BLKPUSH,/* A Bx R(A) := block (16=6:1:5:4) */
OP_ADD,/* A B C R(A) := R(A)+R(A+1) (Syms[B]=:+,C=1) */
OP_ADDI,/* A B C R(A) := R(A)+C (Syms[B]=:+) */
OP_SUB,/* A B C R(A) := R(A)-R(A+1) (Syms[B]=:-,C=1) */
OP_SUBI,/* A B C R(A) := R(A)-C (Syms[B]=:-) */
OP_MUL,/* A B C R(A) := R(A)*R(A+1) (Syms[B]=:*,C=1) */
OP_DIV,/* A B C R(A) := R(A)/R(A+1) (Syms[B]=:/,C=1) */
OP_EQ,/* A B C R(A) := R(A)==R(A+1) (Syms[B]=:==,C=1) */
OP_LT,/* A B C R(A) := R(A)<R(A+1) (Syms[B]=:<,C=1) */
OP_LE,/* A B C R(A) := R(A)<=R(A+1) (Syms[B]=:<=,C=1) */
OP_GT,/* A B C R(A) := R(A)>R(A+1) (Syms[B]=:>,C=1) */
OP_GE,/* A B C R(A) := R(A)>=R(A+1) (Syms[B]=:>=,C=1) */
OP_ARRAY,/* A B C R(A) := ary_new(R(B),R(B+1)..R(B+C)) */
OP_ARYCAT,/* A B ary_cat(R(A),R(B)) */
OP_ARYPUSH,/* A B ary_push(R(A),R(B)) */
OP_AREF,/* A B C R(A) := R(B)[C] */
OP_ASET,/* A B C R(B)[C] := R(A) */
OP_APOST,/* A B C *R(A),R(A+1)..R(A+C) := R(A) */
OP_STRING,/* A Bx R(A) := str_dup(Lit(Bx)) */
OP_STRCAT,/* A B str_cat(R(A),R(B)) */
OP_HASH,/* A B C R(A) := hash_new(R(B),R(B+1)..R(B+C)) */
OP_LAMBDA,/* A Bz Cz R(A) := lambda(SEQ[Bz],Cz) */
OP_RANGE,/* A B C R(A) := range_new(R(B),R(B+1),C) */
OP_OCLASS,/* A R(A) := ::Object */
OP_CLASS,/* A B R(A) := newclass(R(A),Syms(B),R(A+1)) */
OP_MODULE,/* A B R(A) := newmodule(R(A),Syms(B)) */
OP_EXEC,/* A Bx R(A) := blockexec(R(A),SEQ[Bx]) */
OP_METHOD,/* A B R(A).newmethod(Syms(B),R(A+1)) */
OP_SCLASS,/* A B R(A) := R(B).singleton_class */
OP_TCLASS,/* A R(A) := target_class */
OP_DEBUG,/* A B C print R(A),R(B),R(C) */
OP_STOP,/* stop VM */
OP_ERR,/* Bx raise RuntimeError with message Lit(Bx) */
OP_RSVD1,/* reserved instruction #1 */
OP_RSVD2,/* reserved instruction #2 */
OP_RSVD3,/* reserved instruction #3 */
OP_RSVD4,/* reserved instruction #4 */
OP_RSVD5,/* reserved instruction #5 */
enum mrb_insn {
#define OPCODE(x,_) OP_ ## x,
#include "mruby/ops.h"
#undef OPCODE
};
#define OP_L_STRICT 1
@@ -158,4 +23,47 @@ enum {
#define OP_R_BREAK 1
#define OP_R_RETURN 2
#define PEEK_B(pc) (*(pc))
#define PEEK_S(pc) ((pc)[0]<<8|(pc)[1])
#define PEEK_W(pc) ((pc)[0]<<16|(pc)[1]<<8|(pc)[2])
#define READ_B() PEEK_B(pc++)
#define READ_S() (pc+=2, PEEK_S(pc-2))
#define READ_W() (pc+=3, PEEK_W(pc-3))
#define FETCH_Z() /* nothing */
#define FETCH_B() do {a=READ_B();} while (0)
#define FETCH_BB() do {a=READ_B(); b=READ_B();} while (0)
#define FETCH_BBB() do {a=READ_B(); b=READ_B(); c=READ_B();} while (0)
#define FETCH_BS() do {a=READ_B(); b=READ_S();} while (0)
#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_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_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_S_3() FETCH_S()
#define FETCH_W_3() FETCH_W()
#endif /* MRUBY_OPCODE_H */
+117
View File
@@ -0,0 +1,117 @@
/* operand types:
+ Z: no operand (Z,Z,Z,Z)
+ B: 8bit (B,S,B,B)
+ BB: 8+8bit (BB,SB,BS,SS)
+ BBB: 8+8+8bit (BBB,SBB,BSB,SSB)
+ BS: 8+16bit (BS,SS,BS,BS)
+ S: 16bit (S,S,S,S)
+ W: 24bit (W,W,W,W)
*/
/*-----------------------------------------------------------------------
operation code operands semantics
------------------------------------------------------------------------*/
OPCODE(NOP, Z) /* no operation */
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(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(JMP, S) /* pc=a */
OPCODE(JMPIF, BS) /* if R(b) pc=a */
OPCODE(JMPNOT, BS) /* if !R(b) pc=a */
OPCODE(JMPNIL, BS) /* if R(b)==nil pc=a */
OPCODE(ONERR, S) /* rescue_push(a) */
OPCODE(EXCEPT, B) /* R(a) = exc */
OPCODE(RESCUE, BB) /* R(b) = R(a).isa?(R(b)) */
OPCODE(POPERR, B) /* a.times{rescue_pop()} */
OPCODE(RAISE, B) /* raise(R(a)) */
OPCODE(EPUSH, B) /* ensure_push(SEQ[a]) */
OPCODE(EPOP, B) /* A.times{ensure_pop().call} */
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(Bx),R(a+1),...,R(a+c),&R(a+c+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)) # todo */
OPCODE(KEYEND, Z) /* raise unless kdict.empty? # todo */
OPCODE(KARG, BB) /* R(a) = kdict[Syms(b)]; kdict.delete(Syms(b)) # todo */
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(c) */
OPCODE(SUB, B) /* R(a) = R(a)-R(a+1) */
OPCODE(SUBI, BB) /* R(a) = R(a)-C */
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(STRCAT, B) /* str_cat(R(a),R(a+1)) */
OPCODE(HASH, BB) /* R(a) = hash_new(R(a),R(a+1)..R(a+b)) */
OPCODE(HASHADD, BB) /* R(a) = hash_push(R(a),R(a+1)..R(a+b)) */
OPCODE(HASHCAT, B) /* R(a) = hash_cat(R(a),R(a+1)) */
OPCODE(LAMBDA, BB) /* R(a) = lambda(SEQ[b],L_LAMBDA) */
OPCODE(BLOCK, BB) /* R(a) = lambda(SEQ[b],L_BLOCK) */
OPCODE(METHOD, BB) /* 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(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(DEBUG, BBB) /* print a,b,c */
OPCODE(ERR, B) /* raise(LocalJumpError, Lit(a)) */
OPCODE(EXT1, Z) /* make 1st operand 16bit */
OPCODE(EXT2, Z) /* make 2nd operand 16bit */
OPCODE(EXT3, Z) /* make 1st and 2nd operands 16bit */
OPCODE(STOP, Z) /* stop VM */
+64 -16
View File
@@ -18,19 +18,20 @@ MRB_BEGIN_DECL
struct REnv {
MRB_OBJECT_HEADER;
mrb_value *stack;
ptrdiff_t cioff;
union {
mrb_sym mid;
struct mrb_context *c;
} cxt;
struct mrb_context *cxt;
mrb_sym mid;
};
#define MRB_SET_ENV_STACK_LEN(e,len) (e)->flags = (unsigned int)(len)
#define MRB_ENV_STACK_LEN(e) ((mrb_int)(e)->flags)
#define MRB_ENV_UNSHARE_STACK(e) ((e)->cioff = -1)
#define MRB_ENV_STACK_SHARED_P(e) ((e)->cioff >= 0)
/* flags (21bits): 1(shared flag):10(cioff/bidx):10(stack_len) */
#define MRB_ENV_SET_STACK_LEN(e,len) ((e)->flags = (((e)->flags & ~0x3ff)|((unsigned int)(len) & 0x3ff)))
#define MRB_ENV_STACK_LEN(e) ((mrb_int)((e)->flags & 0x3ff))
#define MRB_ENV_STACK_UNSHARED (1<<20)
#define MRB_ENV_UNSHARE_STACK(e) ((e)->flags |= MRB_ENV_STACK_UNSHARED)
#define MRB_ENV_STACK_SHARED_P(e) (((e)->flags & MRB_ENV_STACK_UNSHARED) == 0)
#define MRB_ENV_BIDX(e) (((e)->flags >> 10) & 0x3ff)
#define MRB_ENV_SET_BIDX(e,idx) ((e)->flags = (((e)->flags & ~(0x3ff<<10))|((unsigned int)(idx) & 0x3ff)<<10))
MRB_API void mrb_env_unshare(mrb_state*, struct REnv*);
void mrb_env_unshare(mrb_state*, struct REnv*);
struct RProc {
MRB_OBJECT_HEADER;
@@ -38,8 +39,11 @@ struct RProc {
mrb_irep *irep;
mrb_func_t func;
} body;
struct RClass *target_class;
struct REnv *env;
struct RProc *upper;
union {
struct RClass *target_class;
struct REnv *env;
} e;
};
/* aspec access */
@@ -51,12 +55,29 @@ struct RProc {
#define MRB_ASPEC_KDICT(a) ((a) & (1<<1))
#define MRB_ASPEC_BLOCK(a) ((a) & 1)
#define MRB_PROC_CFUNC 128
#define MRB_PROC_CFUNC_P(p) (((p)->flags & MRB_PROC_CFUNC) != 0)
#define MRB_PROC_CFUNC_FL 128
#define MRB_PROC_CFUNC_P(p) (((p)->flags & MRB_PROC_CFUNC_FL) != 0)
#define MRB_PROC_CFUNC(p) (p)->body.func
#define MRB_PROC_STRICT 256
#define MRB_PROC_STRICT_P(p) (((p)->flags & MRB_PROC_STRICT) != 0)
#define MRB_PROC_ORPHAN 512
#define MRB_PROC_ORPHAN_P(p) (((p)->flags & MRB_PROC_ORPHAN) != 0)
#define MRB_PROC_ENVSET 1024
#define MRB_PROC_ENV_P(p) (((p)->flags & MRB_PROC_ENVSET) != 0)
#define MRB_PROC_ENV(p) (MRB_PROC_ENV_P(p) ? (p)->e.env : NULL)
#define MRB_PROC_TARGET_CLASS(p) (MRB_PROC_ENV_P(p) ? (p)->e.env->c : (p)->e.target_class)
#define MRB_PROC_SET_TARGET_CLASS(p,tc) do {\
if (MRB_PROC_ENV_P(p)) {\
(p)->e.env->c = (tc);\
mrb_field_write_barrier(mrb, (struct RBasic*)(p)->e.env, (struct RBasic*)(tc));\
}\
else {\
(p)->e.target_class = (tc);\
mrb_field_write_barrier(mrb, (struct RBasic*)p, (struct RBasic*)(tc));\
}\
} while (0)
#define MRB_PROC_SCOPE 2048
#define MRB_PROC_SCOPE_P(p) (((p)->flags & MRB_PROC_SCOPE) != 0)
#define mrb_proc_ptr(v) ((struct RProc*)(mrb_ptr(v)))
@@ -67,7 +88,7 @@ MRB_API struct RProc *mrb_closure_new_cfunc(mrb_state *mrb, mrb_func_t func, int
void mrb_proc_copy(struct RProc *a, struct RProc *b);
/* implementation of #send method */
MRB_API mrb_value mrb_f_send(mrb_state *mrb, mrb_value self);
mrb_value mrb_f_send(mrb_state *mrb, mrb_value self);
/* following functions are defined in mruby-proc-ext so please include it when using */
MRB_API struct RProc *mrb_proc_new_cfunc_with_env(mrb_state*, mrb_func_t, mrb_int, const mrb_value*);
@@ -75,8 +96,35 @@ MRB_API mrb_value mrb_proc_cfunc_env_get(mrb_state*, mrb_int);
/* old name */
#define mrb_cfunc_env_get(mrb, idx) mrb_proc_cfunc_env_get(mrb, idx)
#ifdef MRB_METHOD_TABLE_INLINE
#define MRB_METHOD_FUNC_FL ((uintptr_t)1)
#define MRB_METHOD_FUNC_P(m) (((uintptr_t)(m))&MRB_METHOD_FUNC_FL)
#define MRB_METHOD_FUNC(m) ((mrb_func_t)((uintptr_t)(m)&(~MRB_METHOD_FUNC_FL)))
#define MRB_METHOD_FROM_FUNC(m,fn) ((m)=(mrb_method_t)((struct RProc*)((uintptr_t)(fn)|MRB_METHOD_FUNC_FL)))
#define MRB_METHOD_FROM_PROC(m,pr) ((m)=(mrb_method_t)(struct RProc*)(pr))
#define MRB_METHOD_PROC_P(m) (!MRB_METHOD_FUNC_P(m))
#define MRB_METHOD_PROC(m) ((struct RProc*)(m))
#define MRB_METHOD_UNDEF_P(m) ((m)==0)
#else
#define MRB_METHOD_FUNC_P(m) ((m).func_p)
#define MRB_METHOD_FUNC(m) ((m).func)
#define MRB_METHOD_FROM_FUNC(m,fn) do{(m).func_p=TRUE;(m).func=(fn);}while(0)
#define MRB_METHOD_FROM_PROC(m,pr) do{(m).func_p=FALSE;(m).proc=(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)
#endif /* MRB_METHOD_TABLE_INLINE */
#define MRB_METHOD_CFUNC_P(m) (MRB_METHOD_FUNC_P(m)?TRUE:(MRB_METHOD_PROC(m)?(MRB_PROC_CFUNC_P(MRB_METHOD_PROC(m))):FALSE))
#define MRB_METHOD_CFUNC(m) (MRB_METHOD_FUNC_P(m)?MRB_METHOD_FUNC(m):((MRB_METHOD_PROC(m)&&MRB_PROC_CFUNC_P(MRB_METHOD_PROC(m)))?MRB_PROC_CFUNC(MRB_METHOD_PROC(m)):NULL))
#include <mruby/khash.h>
KHASH_DECLARE(mt, mrb_sym, struct RProc*, TRUE)
KHASH_DECLARE(mt, mrb_sym, mrb_method_t, TRUE)
MRB_END_DECL
+29 -5
View File
@@ -14,20 +14,43 @@
*/
MRB_BEGIN_DECL
#if defined(MRB_NAN_BOXING) || defined(MRB_WORD_BOXING)
# define MRB_RANGE_EMBED
#endif
#ifdef MRB_RANGE_EMBED
struct RRange {
MRB_OBJECT_HEADER;
mrb_value beg;
mrb_value end;
mrb_bool excl;
};
# define mrb_gc_free_range(mrb, p) ((void)0)
# define RANGE_BEG(p) ((p)->beg)
# define RANGE_END(p) ((p)->end)
#else
typedef struct mrb_range_edges {
mrb_value beg;
mrb_value end;
} mrb_range_edges;
struct RRange {
MRB_OBJECT_HEADER;
mrb_range_edges *edges;
mrb_bool excl : 1;
mrb_bool excl;
};
# define mrb_gc_free_range(mrb, p) mrb_free(mrb, (p)->edges)
# define RANGE_BEG(p) ((p)->edges->beg)
# define RANGE_END(p) ((p)->edges->end)
#endif
MRB_API struct RRange* mrb_range_ptr(mrb_state *mrb, mrb_value v);
#define mrb_range_raw_ptr(v) ((struct RRange*)mrb_ptr(v))
#define mrb_range_value(p) mrb_obj_value((void*)(p))
#define mrb_range_beg(mrb, r) RANGE_BEG(mrb_range_ptr(mrb, r))
#define mrb_range_end(mrb, r) RANGE_END(mrb_range_ptr(mrb, r))
#define mrb_range_excl_p(mrb, r) RANGE_EXCL(mrb_range_ptr(mrb, r))
#define mrb_range_raw_ptr(r) ((struct RRange*)mrb_ptr(r))
#define mrb_range_value(p) mrb_obj_value((void*)(p))
#define RANGE_EXCL(p) ((p)->excl)
MRB_API struct RRange* mrb_range_ptr(mrb_state *mrb, mrb_value range);
/*
* Initializes a Range.
@@ -43,6 +66,7 @@ MRB_API mrb_value mrb_range_new(mrb_state *mrb, mrb_value start, mrb_value end,
MRB_API mrb_int mrb_range_beg_len(mrb_state *mrb, mrb_value range, mrb_int *begp, mrb_int *lenp, mrb_int len, mrb_bool trunc);
mrb_value mrb_get_values_at(mrb_state *mrb, mrb_value obj, mrb_int olen, mrb_int argc, const mrb_value *argv, mrb_value (*func)(mrb_state*, mrb_value, mrb_int));
void mrb_gc_mark_range(mrb_state *mrb, struct RRange *r);
MRB_END_DECL
+44 -16
View File
@@ -26,6 +26,7 @@ struct RString {
union {
mrb_int capa;
struct mrb_shared_string *shared;
struct RString *fshared;
} aux;
char *ptr;
} heap;
@@ -38,15 +39,15 @@ struct RString {
#define RSTR_UNSET_EMBED_FLAG(s) ((s)->flags &= ~(MRB_STR_EMBED|MRB_STR_EMBED_LEN_MASK))
#define RSTR_SET_EMBED_LEN(s, n) do {\
size_t tmp_n = (n);\
s->flags &= ~MRB_STR_EMBED_LEN_MASK;\
s->flags |= (tmp_n) << MRB_STR_EMBED_LEN_SHIFT;\
(s)->flags &= ~MRB_STR_EMBED_LEN_MASK;\
(s)->flags |= (tmp_n) << MRB_STR_EMBED_LEN_SHIFT;\
} while (0)
#define RSTR_SET_LEN(s, n) do {\
if (RSTR_EMBED_P(s)) {\
RSTR_SET_EMBED_LEN((s),(n));\
}\
else {\
s->as.heap.len = (mrb_int)(n);\
(s)->as.heap.len = (mrb_int)(n);\
}\
} while (0)
#define RSTR_EMBED_LEN(s)\
@@ -59,10 +60,17 @@ struct RString {
#define RSTR_SET_SHARED_FLAG(s) ((s)->flags |= MRB_STR_SHARED)
#define RSTR_UNSET_SHARED_FLAG(s) ((s)->flags &= ~MRB_STR_SHARED)
#define RSTR_FSHARED_P(s) ((s)->flags & MRB_STR_FSHARED)
#define RSTR_SET_FSHARED_FLAG(s) ((s)->flags |= MRB_STR_FSHARED)
#define RSTR_UNSET_FSHARED_FLAG(s) ((s)->flags &= ~MRB_STR_FSHARED)
#define RSTR_NOFREE_P(s) ((s)->flags & MRB_STR_NOFREE)
#define RSTR_SET_NOFREE_FLAG(s) ((s)->flags |= MRB_STR_NOFREE)
#define RSTR_UNSET_NOFREE_FLAG(s) ((s)->flags &= ~MRB_STR_NOFREE)
#define RSTR_POOL_P(s) ((s)->flags & MRB_STR_POOL)
#define RSTR_SET_POOL_FLAG(s) ((s)->flags |= MRB_STR_POOL)
/*
* Returns a pointer from a Ruby string
*/
@@ -76,16 +84,25 @@ struct RString {
MRB_API mrb_int mrb_str_strlen(mrb_state*, struct RString*);
#define MRB_STR_SHARED 1
#define MRB_STR_NOFREE 2
#define MRB_STR_NO_UTF 8
#define MRB_STR_EMBED 16
#define MRB_STR_EMBED_LEN_MASK 0x3e0
#define MRB_STR_EMBED_LEN_SHIFT 5
#define MRB_STR_FSHARED 2
#define MRB_STR_NOFREE 4
#define MRB_STR_POOL 8
#define MRB_STR_NO_UTF 16
#define MRB_STR_EMBED 32
#define MRB_STR_EMBED_LEN_MASK 0x7c0
#define MRB_STR_EMBED_LEN_SHIFT 6
void mrb_gc_free_str(mrb_state*, struct RString*);
MRB_API void mrb_str_modify(mrb_state*, struct RString*);
/*
* Appends self to other. Returns self as a concatnated string.
* Finds the index of a substring in a string
*/
MRB_API mrb_int mrb_str_index(mrb_state*, mrb_value, const char*, mrb_int, mrb_int);
#define mrb_str_index_lit(mrb, str, lit, off) mrb_str_index(mrb, str, lit, mrb_strlen_lit(lit), off);
/*
* Appends self to other. Returns self as a concatenated string.
*
*
* Example:
@@ -109,10 +126,10 @@ MRB_API void mrb_str_modify(mrb_state*, struct RString*);
* str1 = mrb_str_new_lit(mrb, "abc");
* str2 = mrb_str_new_lit(mrb, "def");
*
* // Concatnates str2 to str1.
* // Concatenates str2 to str1.
* mrb_str_concat(mrb, str1, str2);
*
* // Prints new Concatnated Ruby string.
* // Prints new Concatenated Ruby string.
* mrb_p(mrb, str1);
*
* mrb_close(mrb);
@@ -161,10 +178,10 @@ MRB_API void mrb_str_concat(mrb_state*, mrb_value, mrb_value);
* mrb_p(mrb, a);
* mrb_p(mrb, b);
*
* // Concatnates both Ruby strings.
* // Concatenates both Ruby strings.
* c = mrb_str_plus(mrb, a, b);
*
* // Prints new Concatnated Ruby string.
* // Prints new Concatenated Ruby string.
* mrb_p(mrb, c);
*
* mrb_close(mrb);
@@ -176,7 +193,7 @@ MRB_API void mrb_str_concat(mrb_state*, mrb_value, mrb_value);
*
* => "abc" # First string
* => "def" # Second string
* => "abcdef" # First & Second concatnated.
* => "abcdef" # First & Second concatenated.
*
* @param [mrb_state] mrb The current mruby state.
* @param [mrb_value] a First string to concatenate.
@@ -294,9 +311,13 @@ MRB_API mrb_value mrb_str_substr(mrb_state *mrb, mrb_value str, mrb_int beg, mrb
* @param [mrb_value] 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_check_string_type(mrb_state *mrb, mrb_value str);
MRB_API mrb_value mrb_str_new_capa(mrb_state *mrb, size_t capa);
MRB_API mrb_value mrb_str_buf_new(mrb_state *mrb, size_t capa);
MRB_API const char *mrb_string_value_cstr(mrb_state *mrb, mrb_value *ptr);
@@ -331,10 +352,13 @@ 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 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.
*/
MRB_API mrb_value mrb_str_to_str(mrb_state *mrb, mrb_value str);
@@ -401,7 +425,7 @@ MRB_API int mrb_str_cmp(mrb_state *mrb, mrb_value str1, mrb_value str2);
MRB_API char *mrb_str_to_cstr(mrb_state *mrb, mrb_value str);
mrb_value mrb_str_pool(mrb_state *mrb, mrb_value str);
mrb_int mrb_str_hash(mrb_state *mrb, mrb_value str);
uint32_t mrb_str_hash(mrb_state *mrb, mrb_value str);
mrb_value mrb_str_dump(mrb_state *mrb, mrb_value str);
/*
@@ -417,6 +441,10 @@ void mrb_regexp_check(mrb_state *mrb, mrb_value obj);
#define mrb_str_buf_cat(mrb, str, ptr, len) mrb_str_cat(mrb, str, ptr, len)
#define mrb_str_buf_append(mrb, str, str2) mrb_str_cat_str(mrb, str, str2)
#ifdef MRB_UTF8_STRING
mrb_int mrb_utf8_len(const char *str, mrb_int byte_len);
#endif
MRB_END_DECL
#endif /* MRUBY_STRING_H */
+4 -4
View File
@@ -15,9 +15,9 @@
#if defined(MRB_ENABLE_CXX_EXCEPTION) && defined(__cplusplus)
#define MRB_TRY(buf) do { try {
#define MRB_TRY(buf) try {
#define MRB_CATCH(buf) } catch(mrb_jmpbuf_impl e) { if (e != (buf)->impl) { throw e; }
#define MRB_END_EXC(buf) } } while(0)
#define MRB_END_EXC(buf) }
#define MRB_THROW(buf) throw((buf)->impl)
typedef mrb_int mrb_jmpbuf_impl;
@@ -34,9 +34,9 @@ typedef mrb_int mrb_jmpbuf_impl;
#define MRB_LONGJMP longjmp
#endif
#define MRB_TRY(buf) do { if (MRB_SETJMP((buf)->impl) == 0) {
#define MRB_TRY(buf) if (MRB_SETJMP((buf)->impl) == 0) {
#define MRB_CATCH(buf) } else {
#define MRB_END_EXC(buf) } } while(0)
#define MRB_END_EXC(buf) }
#define MRB_THROW(buf) MRB_LONGJMP((buf)->impl, 1);
#define mrb_jmpbuf_impl jmp_buf
+11 -1
View File
@@ -63,12 +63,14 @@ struct mrb_state;
#endif
#ifndef MRB_WITHOUT_FLOAT
MRB_API double mrb_float_read(const char*, char**);
#ifdef MRB_USE_FLOAT
typedef float mrb_float;
#else
typedef double mrb_float;
#endif
#endif
#if defined _MSC_VER && _MSC_VER < 1900
# ifndef __cplusplus
@@ -79,7 +81,7 @@ MRB_API int mrb_msvc_vsnprintf(char *s, size_t n, const char *format, va_list ar
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
# if _MSC_VER < 1800 && !defined MRB_WITHOUT_FLOAT
# include <float.h>
# define isfinite(n) _finite(n)
# define isnan _isnan
@@ -158,7 +160,13 @@ typedef void mrb_value;
#ifndef mrb_bool
#define mrb_bool(o) (mrb_type(o) != MRB_TT_FALSE)
#endif
#if !defined(MRB_SYMBOL_BITSIZE)
#define MRB_SYMBOL_BITSIZE (sizeof(mrb_sym) * CHAR_BIT)
#define MRB_SYMBOL_MAX UINT32_MAX
#endif
#ifndef MRB_WITHOUT_FLOAT
#define mrb_float_p(o) (mrb_type(o) == MRB_TT_FLOAT)
#endif
#define mrb_symbol_p(o) (mrb_type(o) == MRB_TT_SYMBOL)
#define mrb_array_p(o) (mrb_type(o) == MRB_TT_ARRAY)
#define mrb_string_p(o) (mrb_type(o) == MRB_TT_STRING)
@@ -171,6 +179,7 @@ MRB_API mrb_bool mrb_regexp_p(struct mrb_state*, mrb_value);
/*
* Returns a float in Ruby.
*/
#ifndef MRB_WITHOUT_FLOAT
MRB_INLINE mrb_value mrb_float_value(struct mrb_state *mrb, mrb_float f)
{
mrb_value v;
@@ -178,6 +187,7 @@ MRB_INLINE mrb_value mrb_float_value(struct mrb_state *mrb, mrb_float f)
SET_FLOAT_VALUE(mrb, v, f);
return v;
}
#endif
static inline mrb_value
mrb_cptr_value(struct mrb_state *mrb, void *p)
+7 -6
View File
@@ -31,8 +31,6 @@ struct global_entry {
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_iv_get(mrb_state*, mrb_sym);
void mrb_vm_iv_set(mrb_state*, mrb_sym, mrb_value);
mrb_value mrb_vm_cv_get(mrb_state*, mrb_sym);
void mrb_vm_cv_set(mrb_state*, mrb_sym, mrb_value);
mrb_value mrb_vm_const_get(mrb_state*, mrb_sym);
@@ -42,12 +40,11 @@ MRB_API void mrb_const_set(mrb_state*, mrb_value, mrb_sym, mrb_value);
MRB_API mrb_bool mrb_const_defined(mrb_state*, mrb_value, mrb_sym);
MRB_API void mrb_const_remove(mrb_state*, mrb_value, mrb_sym);
MRB_API mrb_bool mrb_iv_p(mrb_state *mrb, mrb_sym sym);
MRB_API void mrb_iv_check(mrb_state *mrb, mrb_sym sym);
MRB_API mrb_bool mrb_iv_name_sym_p(mrb_state *mrb, mrb_sym sym);
MRB_API void mrb_iv_name_sym_check(mrb_state *mrb, mrb_sym sym);
MRB_API mrb_value mrb_obj_iv_get(mrb_state *mrb, struct RObject *obj, mrb_sym sym);
MRB_API void mrb_obj_iv_set(mrb_state *mrb, struct RObject *obj, mrb_sym sym, mrb_value v);
MRB_API mrb_bool mrb_obj_iv_defined(mrb_state *mrb, struct RObject *obj, mrb_sym sym);
MRB_API void mrb_obj_iv_ifnone(mrb_state *mrb, struct RObject *obj, mrb_sym sym, mrb_value v);
MRB_API mrb_value mrb_iv_get(mrb_state *mrb, mrb_value obj, mrb_sym sym);
MRB_API void mrb_iv_set(mrb_state *mrb, mrb_value obj, mrb_sym sym, mrb_value v);
MRB_API mrb_bool mrb_iv_defined(mrb_state*, mrb_value, mrb_sym);
@@ -126,7 +123,7 @@ mrb_value mrb_obj_instance_variables(mrb_state*, mrb_value);
mrb_value mrb_mod_class_variables(mrb_state*, mrb_value);
mrb_value mrb_mod_cv_get(mrb_state *mrb, struct RClass * c, mrb_sym sym);
mrb_bool mrb_mod_cv_defined(mrb_state *mrb, struct RClass * c, mrb_sym sym);
mrb_sym mrb_class_sym(mrb_state *mrb, struct RClass *c, struct RClass *outer);
mrb_bool mrb_ident_p(const char *s, mrb_int len);
/* GC functions */
void mrb_gc_mark_gv(mrb_state*);
@@ -135,6 +132,10 @@ void mrb_gc_mark_iv(mrb_state*, struct RObject*);
size_t mrb_gc_mark_iv_size(mrb_state*, struct RObject*);
void mrb_gc_free_iv(mrb_state*, struct RObject*);
/* return non zero to break the loop */
typedef int (mrb_iv_foreach_func)(mrb_state*,mrb_sym,mrb_value,void*);
MRB_API void mrb_iv_foreach(mrb_state *mrb, mrb_value obj, mrb_iv_foreach_func *func, void *p);
MRB_END_DECL
#endif /* MRUBY_VARIABLE_H */
+6 -6
View File
@@ -27,7 +27,7 @@ MRB_BEGIN_DECL
/*
* The version of Ruby used by mruby.
*/
#define MRUBY_RUBY_VERSION "1.9"
#define MRUBY_RUBY_VERSION "2.0"
/*
* Ruby engine.
@@ -37,17 +37,17 @@ MRB_BEGIN_DECL
/*
* Major release version number.
*/
#define MRUBY_RELEASE_MAJOR 1
#define MRUBY_RELEASE_MAJOR 2
/*
* Minor release version number.
*/
#define MRUBY_RELEASE_MINOR 3
#define MRUBY_RELEASE_MINOR 0
/*
* Tiny release version number.
*/
#define MRUBY_RELEASE_TEENY 0
#define MRUBY_RELEASE_TEENY 1
/*
* The mruby version.
@@ -62,12 +62,12 @@ MRB_BEGIN_DECL
/*
* Release year.
*/
#define MRUBY_RELEASE_YEAR 2017
#define MRUBY_RELEASE_YEAR 2019
/*
* Release month.
*/
#define MRUBY_RELEASE_MONTH 7
#define MRUBY_RELEASE_MONTH 4
/*
* Release day.
+23 -17
View File
@@ -18,18 +18,20 @@ class String
end
# Compatible with 1.9 on 1.8
def %(params)
if params.is_a?(Hash)
str = self.clone
params.each do |k, v|
str.gsub!("%{#{k}}") { v }
end
str
else
if params.is_a?(Array)
sprintf(self, *params)
unless (sprintf("%{a}", :a => 1) rescue false)
def %(params)
if params.is_a?(Hash)
str = self.clone
params.each do |k, v|
str.gsub!("%{#{k}}") { v }
end
str
else
sprintf(self, params)
if params.is_a?(Array)
sprintf(self, *params)
else
sprintf(self, params)
end
end
end
end
@@ -37,17 +39,21 @@ end
class Symbol
# Compatible with 1.9 on 1.8
def to_proc
proc { |obj, *args| obj.send(self, *args) }
unless method_defined?(:to_proc)
def to_proc
proc { |obj, *args| obj.send(self, *args) }
end
end
end
module Enumerable
# Compatible with 1.9 on 1.8
def each_with_object(memo)
return to_enum :each_with_object, memo unless block_given?
each { |obj| yield obj, memo }
memo
unless method_defined?(:each_with_object)
def each_with_object(memo)
return to_enum :each_with_object, memo unless block_given?
each { |obj| yield obj, memo }
memo
end
end
end
+60 -12
View File
@@ -1,5 +1,5 @@
load "#{MRUBY_ROOT}/tasks/mruby_build_gem.rake"
load "#{MRUBY_ROOT}/tasks/mruby_build_commands.rake"
require "mruby/build/load_gems"
require "mruby/build/command"
module MRuby
class << self
@@ -45,9 +45,11 @@ module MRuby
include Rake::DSL
include LoadGems
attr_accessor :name, :bins, :exts, :file_separator, :build_dir, :gem_clone_dir
attr_reader :libmruby, :gems, :toolchains
attr_reader :libmruby_objs, :gems, :toolchains
attr_writer :enable_bintest, :enable_test
alias libmruby libmruby_objs
COMPILERS = %w(cc cxx objc asm)
COMMANDS = COMPILERS + %w(linker archiver yacc gperf git exts mrbc)
attr_block MRuby::Build::COMMANDS
@@ -81,7 +83,7 @@ module MRuby
@mrbc = Command::Mrbc.new(self)
@bins = []
@gems, @libmruby = MRuby::Gem::List.new, []
@gems, @libmruby_objs = MRuby::Gem::List.new, []
@build_mrbtest_lib_only = false
@cxx_exception_enabled = false
@cxx_exception_disabled = false
@@ -100,6 +102,10 @@ module MRuby
build_mrbtest if test_enabled?
end
def debug_enabled?
@enable_debug
end
def enable_debug
compilers.each do |c|
c.defines += %w(MRB_DEBUG)
@@ -108,6 +114,8 @@ module MRuby
end
end
@mrbc.compile_options += ' -g'
@enable_debug = true
end
def disable_cxx_exception
@@ -154,8 +162,6 @@ module MRuby
end
def compile_as_cxx src, cxx_src, obj = nil, includes = []
src = File.absolute_path src
cxx_src = File.absolute_path cxx_src
obj = objfile(cxx_src) if obj.nil?
file cxx_src => [src, __FILE__] do |t|
@@ -167,7 +173,7 @@ module MRuby
#ifndef MRB_ENABLE_CXX_ABI
extern "C" {
#endif
#include "#{src}"
#include "#{File.absolute_path src}"
#ifndef MRB_ENABLE_CXX_ABI
}
#endif
@@ -241,7 +247,7 @@ EOS
else
compiler.defines += %w(DISABLE_GEMS)
end
compiler.define_rules build_dir, File.expand_path(File.join(File.dirname(__FILE__), '..'))
compiler.define_rules build_dir, File.expand_path(File.join(File.dirname(__FILE__), '..', '..'))
end
end
@@ -264,8 +270,11 @@ EOS
def exefile(name)
if name.is_a?(Array)
name.flatten.map { |n| exefile(n) }
else
elsif File.extname(name).empty?
"#{name}#{exts.executable}"
else
# `name` sometimes have (non-standard) extension (e.g. `.bat`).
name
end
end
@@ -293,18 +302,22 @@ EOS
@build_mrbtest_lib_only
end
def verbose_flag
$verbose ? ' -v' : ''
end
def run_test
puts ">>> Test #{name} <<<"
mrbtest = exefile("#{build_dir}/bin/mrbtest")
sh "#{filename mrbtest.relative_path}#{$verbose ? ' -v' : ''}"
sh "#{filename mrbtest.relative_path}#{verbose_flag}"
puts
run_bintest if bintest_enabled?
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"
sh "ruby test/bintest.rb #{targets.join ' '}"
sh "ruby test/bintest.rb#{verbose_flag} #{targets.join ' '}"
end
def print_build_summary
@@ -324,6 +337,18 @@ EOS
puts "================================================"
puts
end
def libmruby_static
libfile("#{build_dir}/lib/libmruby")
end
def libmruby_core_static
libfile("#{build_dir}/lib/libmruby_core")
end
def libraries
[libmruby_static]
end
end # Build
class CrossBuild < Build
@@ -334,6 +359,7 @@ EOS
attr_accessor :host_target, :build_target
def initialize(name, build_dir=nil, &block)
@endian = nil
@test_runner = Command::CrossTestRunner.new(self)
super
end
@@ -343,6 +369,7 @@ EOS
end
def run_test
@test_runner.runner_options << ' -v' if $verbose
mrbtest = exefile("#{build_dir}/bin/mrbtest")
if (@test_runner.command == nil)
puts "You should run #{mrbtest} on target device."
@@ -351,5 +378,26 @@ EOS
@test_runner.run(mrbtest)
end
end
def big_endian
if @endian
puts "Endian has already specified as #{@endian}."
return
end
@endian = :big
@mrbc.compile_options += ' -E'
compilers.each do |c|
c.defines += %w(MRB_ENDIAN_BIG)
end
end
def little_endian
if @endian
puts "Endian has already specified as #{@endian}."
return
end
@endian = :little
@mrbc.compile_options += ' -e'
end
end # CrossBuild
end # MRuby
@@ -67,8 +67,8 @@ module MRuby
path && build.filename("#{path}/#{name}").sub(/^"(.*)"$/, '\1')
end
def all_flags(_defineds=[], _include_paths=[], _flags=[])
define_flags = [defines, _defineds].flatten.map{ |d| option_define % d }
def all_flags(_defines=[], _include_paths=[], _flags=[])
define_flags = [defines, _defines].flatten.map{ |d| option_define % d }
include_path_flags = [include_paths, _include_paths].flatten.map do |f|
if MRUBY_BUILD_HOST_IS_CYGWIN
option_include_path % cygwin_filename(f)
@@ -79,14 +79,14 @@ module MRuby
[flags, define_flags, include_path_flags, _flags].flatten.join(' ')
end
def run(outfile, infile, _defineds=[], _include_paths=[], _flags=[])
def run(outfile, infile, _defines=[], _include_paths=[], _flags=[])
FileUtils.mkdir_p File.dirname(outfile)
_pp "CC", infile.relative_path, outfile.relative_path
if MRUBY_BUILD_HOST_IS_CYGWIN
_run compile_options, { :flags => all_flags(_defineds, _include_paths, _flags),
_run compile_options, { :flags => all_flags(_defines, _include_paths, _flags),
:infile => cygwin_filename(infile), :outfile => cygwin_filename(outfile) }
else
_run compile_options, { :flags => all_flags(_defineds, _include_paths, _flags),
_run compile_options, { :flags => all_flags(_defines, _include_paths, _flags),
:infile => filename(infile), :outfile => filename(outfile) }
end
end
@@ -76,9 +76,6 @@ module MRuby
if params[:core]
gemdir = "#{root}/mrbgems/#{params[:core]}"
elsif params[:path]
require 'pathname'
gemdir = Pathname.new(params[:path]).absolute? ? params[:path] : "#{root}/#{params[:path]}"
elsif params[:git]
url = params[:git]
gemdir = "#{gem_clone_dir}/#{url.match(/([-\w]+)(\.[-\w]+|)$/).to_a[1]}"
@@ -108,6 +105,11 @@ module MRuby
# Jump to the top of the branch
git.run_checkout gemdir, branch if $pull_gems
end
gemdir << "/#{params[:path]}" if params[:path]
elsif params[:path]
require 'pathname'
gemdir = Pathname.new(params[:path]).absolute? ? params[:path] : "#{root}/#{params[:path]}"
else
fail "unknown gem option #{params}"
end
+30 -31
View File
@@ -52,6 +52,8 @@ module MRuby
end
def setup
return if defined?(@linker) # return if already set up
MRuby::Gem.current = self
MRuby::Build::COMMANDS.each do |command|
instance_variable_set("@#{command}", @build.send(command).clone)
@@ -63,10 +65,7 @@ module MRuby
objfile(f.relative_path_from(@dir).to_s.pathmap("#{build_dir}/%X"))
end
@generate_functions = !(@rbfiles.empty? && @objs.empty?)
@objs << objfile("#{build_dir}/gem_init") if @generate_functions
@test_rbfiles = Dir.glob("#{dir}/test/**/*.rb")
@test_rbfiles = Dir.glob("#{dir}/test/**/*.rb").sort
@test_objs = Dir.glob("#{dir}/test/*.{c,cpp,cxx,cc,m,asm,s,S}").map do |f|
objfile(f.relative_path_from(dir).to_s.pathmap("#{build_dir}/%X"))
end
@@ -83,11 +82,14 @@ module MRuby
instance_eval(&@initializer)
@generate_functions = !(@rbfiles.empty? && @objs.empty?)
@objs << objfile("#{build_dir}/gem_init") if @generate_functions
if !name || !licenses || !authors
fail "#{name || dir} required to set name, license(s) and author(s)"
end
build.libmruby << @objs
build.libmruby_objs << @objs
instance_eval(&@build_config_initializer) if @build_config_initializer
end
@@ -110,17 +112,13 @@ module MRuby
end
def add_test_dependency(*args)
add_dependency(*args) if build.test_enabled?
add_dependency(*args) if build.test_enabled? || build.bintest_enabled?
end
def add_conflict(name, *req)
@conflicts << {:gem => name, :requirements => req.empty? ? nil : req}
end
def self.bin=(bin)
@bins = [bin].flatten
end
def build_dir
"#{build.build_dir}/mrbgems/#{name}"
end
@@ -176,6 +174,7 @@ module MRuby
f.puts %Q[ mrb_load_irep(mrb, gem_mrblib_irep_#{funcname});]
f.puts %Q[ if (mrb->exc) {]
f.puts %Q[ mrb_print_error(mrb);]
f.puts %Q[ mrb_close(mrb);]
f.puts %Q[ exit(EXIT_FAILURE);]
f.puts %Q[ }]
end
@@ -323,38 +322,36 @@ module MRuby
@ary.empty?
end
def generate_gem_table build
gem_table = @ary.reduce({}) { |res,v| res[v.name] = v; res }
def default_gem_params dep
if dep[:default]; dep
elsif File.exist? "#{MRUBY_ROOT}/mrbgems/#{dep[:gem]}" # check core
{ :gem => dep[:gem], :default => { :core => dep[:gem] } }
else # fallback to mgem-list
{ :gem => dep[:gem], :default => { :mgem => dep[:gem] } }
end
end
default_gems = []
def generate_gem_table build
gem_table = each_with_object({}) { |spec, h| h[spec.name] = spec }
default_gems = {}
each do |g|
g.dependencies.each do |dep|
unless gem_table.key? dep[:gem]
if dep[:default]; default_gems << dep
elsif File.exist? "#{MRUBY_ROOT}/mrbgems/#{dep[:gem]}" # check core
default_gems << { :gem => dep[:gem], :default => { :core => dep[:gem] } }
else # fallback to mgem-list
default_gems << { :gem => dep[:gem], :default => { :mgem => dep[:gem] } }
end
end
default_gems[dep[:gem]] ||= default_gem_params(dep)
end
end
until default_gems.empty?
def_gem = default_gems.pop
def_name, def_gem = default_gems.shift
next if gem_table[def_name]
spec = build.gem def_gem[:default]
fail "Invalid gem name: #{spec.name} (Expected: #{def_gem[:gem]})" if spec.name != def_gem[:gem]
spec = gem_table[def_name] = build.gem(def_gem[:default])
fail "Invalid gem name: #{spec.name} (Expected: #{def_name})" if spec.name != def_name
spec.setup
spec.dependencies.each do |dep|
unless gem_table.key? dep[:gem]
if dep[:default]; default_gems << dep
else default_gems << { :gem => dep[:gem], :default => { :mgem => dep[:gem] } }
end
end
default_gems[dep[:gem]] ||= default_gem_params(dep)
end
gem_table[spec.name] = spec
end
each do |g|
@@ -429,7 +426,8 @@ module MRuby
end
def import_include_paths(g)
gem_table = @ary.reduce({}) { |res,v| res[v.name] = v; res }
gem_table = each_with_object({}) { |spec, h| h[spec.name] = spec }
g.dependencies.each do |dep|
dep_g = gem_table[dep[:gem]]
# We can do recursive call safely
@@ -455,5 +453,6 @@ module MRuby
def new(&block); block.call(self); end
def config=(obj); @config = obj; end
def gem(gemdir, &block); @config.gem(gemdir, &block); end
def gembox(gemfile); @config.gembox(gemfile); end
end # GemBox
end # MRuby
+136 -15
View File
@@ -7,6 +7,10 @@
require 'getoptlong'
require 'fileutils'
$rake_fiber_table = {}
$rake_jobs = 1
$rake_failed = []
class String
def ext(newext='')
return self.dup if ['.', '..'].include? self
@@ -86,14 +90,36 @@ module MiniRake
@name.to_s
end
# Invoke the task if it is needed. Prerequites are invoked first.
def done?; @done end
def running?; @running end
# Invoke the task if it is needed. Prerequisites are invoked first.
def invoke
puts "Invoke #{name} (already=[#{@already_invoked}], needed=[#{needed?}])" if $trace
return if @already_invoked
@already_invoked = true
prerequisites = @prerequisites.collect{ |n| n.is_a?(Proc) ? n.call(name) : n }.flatten
prerequisites.each { |n| Task[n].invoke }
execute if needed?
prerequisites.each do |n|
t = Task[n]
unless t.done?
return prerequisites.select{|v| v = Task[v]; v && (!v.done? || !v.running?) }
end
end
@already_invoked = true
if needed?
@running = true
if $rake_root_fiber
return Fiber.new do
self.execute
$rake_root_fiber.transfer
end
else
self.execute
end
end
@done = true
end
# Execute the actions associated with this task.
@@ -103,6 +129,8 @@ module MiniRake
unless $dryrun
@actions.each { |act| act.call(self) }
end
@done = true
@running = false
end
# Is this task needed?
@@ -281,7 +309,19 @@ module MiniRake
# Run the system command +cmd+.
def sh(cmd)
puts cmd if $verbose
system(cmd) or fail "Command Failed: [#{cmd}]"
if !$rake_root_fiber || Fiber.current == $rake_root_fiber
system(cmd) or fail "Command Failed: [#{cmd}]"
return
end
pid = Process.spawn(cmd)
$rake_fiber_table[pid] = {
fiber: Fiber.current,
command: cmd,
process_waiter: Process.detach(pid)
}
$rake_root_fiber.transfer
end
def desc(text)
@@ -329,7 +369,9 @@ class RakeApp
['--verbose', '-v', GetoptLong::NO_ARGUMENT,
"Log message to standard output."],
['--directory', '-C', GetoptLong::REQUIRED_ARGUMENT,
"Change executing directory of rakefiles."]
"Change executing directory of rakefiles."],
['--jobs', '-j', GetoptLong::REQUIRED_ARGUMENT,
'Execute rake with parallel jobs.']
]
# Create a RakeApp object.
@@ -422,6 +464,8 @@ class RakeApp
exit
when '--directory'
Dir.chdir value
when '--jobs'
$rake_jobs = [value.to_i, 1].max
else
fail "Unknown option: #{opt}"
end
@@ -438,6 +482,12 @@ class RakeApp
# Run the +rake+ application.
def run
handle_options
unless $rake_root_fiber
require 'fiber'
$rake_root_fiber = Fiber.current
end
begin
here = Dir.pwd
while ! have_rakefile
@@ -447,12 +497,12 @@ class RakeApp
end
here = Dir.pwd
end
tasks = []
root_tasks = []
ARGV.each do |task_name|
if /^(\w+)=(.*)/.match(task_name)
ENV[$1] = $2
else
tasks << task_name
root_tasks << task_name
end
end
puts "(in #{Dir.pwd})"
@@ -461,22 +511,93 @@ class RakeApp
if $show_tasks
display_tasks
else
tasks.push("default") if tasks.size == 0
tasks.each do |task_name|
MiniRake::Task[task_name].invoke
root_tasks.push("default") if root_tasks.empty?
# revese tasks for popping
root_tasks.reverse!
tasks = []
until root_tasks.empty?
root_name = root_tasks.pop
tasks << root_name
until tasks.empty?
task_name = tasks.pop
t = MiniRake::Task[task_name]
f = t.invoke
# append additional tasks to task queue
if f.kind_of?(Array)
tasks.push(*f)
tasks.uniq!
end
unless f.kind_of? Fiber
tasks.insert 0, task_name unless t.done?
if root_name == task_name
wait_process
end
next
end
wait_process while $rake_fiber_table.size >= $rake_jobs
f.transfer
end
end
wait_process until $rake_fiber_table.empty?
end
rescue Exception => ex
puts "rake aborted!"
rescue Exception => e
begin
$rake_failed << e
wait_process until $rake_fiber_table.empty?
rescue Exception => next_e
e = next_e
retry
end
end
return if $rake_failed.empty?
puts "rake aborted!"
$rake_failed.each do |ex|
puts ex.message
if $trace
if $trace || $verbose
puts ex.backtrace.join("\n")
else
puts ex.backtrace.find {|str| str =~ /#{@rakefile}/ } || ""
end
exit 1
end
exit 1
end
def wait_process(count = 0)
dur = [0.0001 * (10 ** count), 1].min
sleep dur
exited = []
$rake_fiber_table.each do |pid, v|
exited << pid unless v[:process_waiter].alive?
end
exited.each do |pid|
ent = $rake_fiber_table.delete pid
st = ent[:process_waiter].value
# ignore process that isn't created by `sh` method
return if ent.nil?
if st.exitstatus != 0
raise "Command Failed: [#{ent[:command]}]"
end
fail 'task scheduling bug!' if $rake_fiber_table.size >= $rake_jobs
ent[:fiber].transfer
end
wait_process(count + 1) if !$rake_fiber_table.empty? && exited.empty?
end
end
if __FILE__ == $0 then
+12
View File
@@ -1,4 +1,13 @@
MRuby::GemBox.new do |conf|
# Meta-programming features
conf.gem :core => "mruby-metaprog"
# Use standard IO/File class
conf.gem :core => "mruby-io"
# Use standard Array#pack, String#unpack methods
conf.gem :core => "mruby-pack"
# Use standard Kernel#sprintf method
conf.gem :core => "mruby-sprintf"
@@ -14,6 +23,9 @@ MRuby::GemBox.new do |conf|
# Use standard Struct class
conf.gem :core => "mruby-struct"
# Use Comparable module extension
conf.gem :core => "mruby-compar-ext"
# Use Enumerable module extension
conf.gem :core => "mruby-enum-ext"
+1
View File
@@ -2,4 +2,5 @@ MRuby::Gem::Specification.new('mruby-array-ext') do |spec|
spec.license = 'MIT'
spec.author = 'mruby developers'
spec.summary = 'Array class extension'
spec.add_test_dependency 'mruby-enumerator', core: 'mruby-enumerator'
end
+269 -95
View File
@@ -1,29 +1,4 @@
class Array
##
# call-seq:
# Array.try_convert(obj) -> array or nil
#
# Tries to convert +obj+ into an array, using +to_ary+ method.
# converted array or +nil+ if +obj+ cannot be converted for any reason.
# This method can be used to check if an argument is an array.
#
# Array.try_convert([1]) #=> [1]
# Array.try_convert("1") #=> nil
#
# if tmp = Array.try_convert(arg)
# # the argument is an array
# elsif tmp = String.try_convert(arg)
# # the argument is a string
# end
#
def self.try_convert(obj)
if obj.respond_to?(:to_ary)
obj.to_ary
else
nil
end
end
##
# call-seq:
# ary.uniq! -> ary or nil
@@ -41,23 +16,19 @@ class Array
# c.uniq! { |s| s.first } # => [["student", "sam"], ["teacher", "matz"]]
#
def uniq!(&block)
ary = self.dup
result = []
hash = {}
if block
hash = {}
while ary.size > 0
val = ary.shift
self.each do |val|
key = block.call(val)
hash[key] = val unless hash.has_key?(key)
end
hash.each_value do |value|
result << value
hash[key] = val unless hash.key?(key)
end
result = hash.values
else
while ary.size > 0
result << ary.shift
ary.delete(result.last)
hash = {}
self.each do |val|
hash[val] = val
end
result = hash.keys
end
if result.size == self.size
nil
@@ -81,11 +52,7 @@ class Array
#
def uniq(&block)
ary = self.dup
if block
ary.uniq!(&block)
else
ary.uniq!
end
ary.uniq!(&block)
ary
end
@@ -105,8 +72,19 @@ class Array
hash = {}
array = []
elem.each { |x| hash[x] = true }
self.each { |x| array << x unless hash[x] }
idx = 0
len = elem.size
while idx < len
hash[elem[idx]] = true
idx += 1
end
idx = 0
len = size
while idx < len
v = self[idx]
array << v unless hash[v]
idx += 1
end
array
end
@@ -127,6 +105,25 @@ class Array
ary.uniq! or ary
end
##
# call-seq:
# ary.union(other_ary,...) -> new_ary
#
# Set Union---Returns a new array by joining this array with
# <i>other_ary</i>, removing duplicates.
#
# ["a", "b", "c"].union(["c", "d", "a"], ["a", "c", "e"])
# #=> ["a", "b", "c", "d", "e"]
#
def union(*args)
ary = self.dup
args.each do |x|
ary.concat(x)
ary.uniq!
end
ary
end
##
# call-seq:
# ary & other_ary -> new_ary
@@ -141,12 +138,21 @@ class Array
hash = {}
array = []
elem.each{|v| hash[v] = true }
self.each do |v|
idx = 0
len = elem.size
while idx < len
hash[elem[idx]] = true
idx += 1
end
idx = 0
len = size
while idx < len
v = self[idx]
if hash[v]
array << v
hash.delete v
end
idx += 1
end
array
end
@@ -169,15 +175,9 @@ class Array
# a.flatten(1) #=> [1, 2, 3, [4, 5]]
#
def flatten(depth=nil)
ar = []
self.each do |e|
if e.is_a?(Array) && (depth.nil? || depth > 0)
ar += e.flatten(depth.nil? ? nil : depth - 1)
else
ar << e
end
end
ar
res = dup
res.flatten! depth
res
end
##
@@ -200,13 +200,17 @@ class Array
def flatten!(depth=nil)
modified = false
ar = []
self.each do |e|
idx = 0
len = size
while idx < len
e = self[idx]
if e.is_a?(Array) && (depth.nil? || depth > 0)
ar += e.flatten(depth.nil? ? nil : depth - 1)
modified = true
else
ar << e
end
idx += 1
end
if modified
self.replace(ar)
@@ -252,7 +256,7 @@ class Array
# for efficiency
def reverse_each(&block)
return to_enum :reverse_each unless block_given?
return to_enum :reverse_each unless block
i = self.size - 1
while i>=0
@@ -262,7 +266,6 @@ class Array
self
end
NONE=Object.new
##
# call-seq:
# ary.fetch(index) -> obj
@@ -287,7 +290,7 @@ class Array
# #=> "100 is out of bounds"
#
def fetch(n=nil, ifnone=NONE, &block)
def fetch(n, ifnone=NONE, &block)
warn "block supersedes default value argument" if !n.nil? && ifnone != NONE && block
idx = n
@@ -474,7 +477,7 @@ class Array
# scores.delete_if {|score| score < 80 } #=> [97]
def delete_if(&block)
return to_enum :delete_if unless block_given?
return to_enum :delete_if unless block
idx = 0
while idx < self.size do
@@ -503,7 +506,7 @@ class Array
# If no block is given, an Enumerator is returned instead.
def reject!(&block)
return to_enum :reject! unless block_given?
return to_enum :reject! unless block
len = self.size
idx = 0
@@ -593,33 +596,60 @@ class Array
# undefined which value is actually picked up at each iteration.
def bsearch(&block)
return to_enum :bsearch unless block_given?
return to_enum :bsearch unless block
if idx = bsearch_index(&block)
self[idx]
else
nil
end
end
##
# call-seq:
# ary.bsearch_index {|x| block } -> int or nil
#
# By using binary search, finds an index of a value from this array which
# meets the given condition in O(log n) where n is the size of the array.
#
# It supports two modes, depending on the nature of the block and they are
# exactly the same as in the case of #bsearch method with the only difference
# being that this method returns the index of the element instead of the
# element itself. For more details consult the documentation for #bsearch.
def bsearch_index(&block)
return to_enum :bsearch_index unless block
low = 0
high = self.size
high = size
satisfied = false
while low < high
mid = low + ((high - low) / 2).truncate
val = self[mid]
v = block.call(val)
if v.is_a?(Integer)
return val if v == 0
smaller = v < 0
elsif v == true
mid = ((low+high)/2).truncate
res = block.call self[mid]
case res
when 0 # find-any mode: Found!
return mid
when Numeric # find-any mode: Continue...
in_lower_half = res < 0
when true # find-min mode
in_lower_half = true
satisfied = true
smaller = true
elsif v == false || v.nil?
smaller = false
when false, nil # find-min mode
in_lower_half = false
else
raise TypeError, 'invalid block result (must be numeric, true, false or nil)'
end
if smaller
if in_lower_half
high = mid
else
low = mid + 1
end
end
return nil if low == self.size
return nil unless satisfied
self[low]
satisfied ? low : nil
end
##
@@ -640,7 +670,7 @@ class Array
# scores.delete_if {|score| score < 80 } #=> [97]
def delete_if(&block)
return to_enum :delete_if unless block_given?
return to_enum :delete_if unless block
idx = 0
while idx < self.size do
@@ -669,7 +699,7 @@ class Array
# a.keep_if { |val| val > 3 } #=> [4, 5]
def keep_if(&block)
return to_enum :keep_if unless block_given?
return to_enum :keep_if unless block
idx = 0
len = self.size
@@ -698,13 +728,17 @@ class Array
# If no block is given, an Enumerator is returned instead.
def select!(&block)
return to_enum :select! unless block_given?
return to_enum :select! unless block
result = []
self.each do |x|
result << x if block.call(x)
idx = 0
len = size
while idx < len
elem = self[idx]
result << elem if block.call(elem)
idx += 1
end
return nil if self.size == result.size
return nil if len == result.size
self.replace(result)
end
@@ -726,8 +760,9 @@ class Array
if block
idx = 0
self.each do |*e|
return idx if block.call(*e)
len = size
while idx < len
return idx if block.call self[idx]
idx += 1
end
else
@@ -736,16 +771,6 @@ class Array
nil
end
##
# call-seq:
# ary.to_ary -> ary
#
# Returns +self+.
#
def to_ary
self
end
##
# call-seq:
# ary.dig(idx, ...) -> object
@@ -762,4 +787,153 @@ class Array
n
end
end
##
# call-seq:
# ary.permutation { |p| block } -> ary
# ary.permutation -> Enumerator
# ary.permutation(n) { |p| block } -> ary
# ary.permutation(n) -> Enumerator
#
# When invoked with a block, yield all permutations of length +n+ of the
# elements of the array, then return the array itself.
#
# If +n+ is not specified, yield all permutations of all elements.
#
# The implementation makes no guarantees about the order in which the
# permutations are yielded.
#
# If no block is given, an Enumerator is returned instead.
#
# Examples:
#
# a = [1, 2, 3]
# a.permutation.to_a #=> [[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]]
# a.permutation(1).to_a #=> [[1],[2],[3]]
# a.permutation(2).to_a #=> [[1,2],[1,3],[2,1],[2,3],[3,1],[3,2]]
# a.permutation(3).to_a #=> [[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]]
# a.permutation(0).to_a #=> [[]] # one permutation of length 0
# a.permutation(4).to_a #=> [] # no permutations of length 4
def permutation(n=self.size, &block)
size = self.size
return to_enum(:permutation, n) unless block
return if n > size
if n == 0
yield []
else
i = 0
while i<size
result = [self[i]]
if n-1 > 0
ary = self[0...i] + self[i+1..-1]
ary.permutation(n-1) do |c|
yield result + c
end
else
yield result
end
i += 1
end
end
end
##
# call-seq:
# ary.combination(n) { |c| block } -> ary
# ary.combination(n) -> Enumerator
#
# When invoked with a block, yields all combinations of length +n+ of elements
# from the array and then returns the array itself.
#
# The implementation makes no guarantees about the order in which the
# combinations are yielded.
#
# If no block is given, an Enumerator is returned instead.
#
# Examples:
#
# a = [1, 2, 3, 4]
# a.combination(1).to_a #=> [[1],[2],[3],[4]]
# a.combination(2).to_a #=> [[1,2],[1,3],[1,4],[2,3],[2,4],[3,4]]
# a.combination(3).to_a #=> [[1,2,3],[1,2,4],[1,3,4],[2,3,4]]
# a.combination(4).to_a #=> [[1,2,3,4]]
# a.combination(0).to_a #=> [[]] # one combination of length 0
# a.combination(5).to_a #=> [] # no combinations of length 5
def combination(n, &block)
size = self.size
return to_enum(:combination, n) unless block
return if n > size
if n == 0
yield []
elsif n == 1
i = 0
while i<size
yield [self[i]]
i += 1
end
else
i = 0
while i<size
result = [self[i]]
self[i+1..-1].combination(n-1) do |c|
yield result + c
end
i += 1
end
end
end
##
# call-seq:
# ary.transpose -> new_ary
#
# Assumes that self is an array of arrays and transposes the rows and columns.
#
# If the length of the subarrays don't match, an IndexError is raised.
#
# Examples:
#
# a = [[1,2], [3,4], [5,6]]
# a.transpose #=> [[1, 3, 5], [2, 4, 6]]
def transpose
return [] if empty?
column_count = nil
self.each do |row|
raise TypeError unless row.is_a?(Array)
column_count ||= row.count
raise IndexError, 'element size differs' unless column_count == row.count
end
Array.new(column_count) do |column_index|
self.map { |row| row[column_index] }
end
end
##
# call-seq:
# ary.to_h -> Hash
# ary.to_h{|item| ... } -> Hash
#
# Returns the result of interpreting <i>aray</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.
#
# [[:foo, :bar], [1, 2]].to_h
# # => {:foo => :bar, 1 => 2}
# [1, 2].to_h{|x| [x, x*2]}
# # => {1 => 2, 2 => 4}
#
def to_h(&blk)
h = {}
self.each do |v|
v = blk.call(v) if blk
raise TypeError, "wrong element type #{v.class}" unless Array === v
raise ArgumentError, "wrong array length (expected 2, was #{v.length})" unless v.length == 2
h[v[0]] = v[1]
end
h
end
end
+17 -57
View File
@@ -106,48 +106,6 @@ mrb_ary_values_at(mrb_state *mrb, mrb_value self)
return mrb_get_values_at(mrb, self, RARRAY_LEN(self), argc, argv, mrb_ary_ref);
}
/*
* call-seq:
* ary.to_h -> Hash
*
* Returns the result of interpreting <i>aray</i> as an array of
* <tt>[key, value]</tt> paris.
*
* [[:foo, :bar], [1, 2]].to_h
* # => {:foo => :bar, 1 => 2}
*
*/
static mrb_value
mrb_ary_to_h(mrb_state *mrb, mrb_value ary)
{
mrb_int i;
mrb_value v, hash;
hash = mrb_hash_new_capa(mrb, 0);
for (i = 0; i < RARRAY_LEN(ary); ++i) {
v = mrb_check_array_type(mrb, RARRAY_PTR(ary)[i]);
if (mrb_nil_p(v)) {
mrb_raisef(mrb, E_TYPE_ERROR, "wrong element type %S at %S (expected array)",
mrb_str_new_cstr(mrb, mrb_obj_classname(mrb, ary_elt(ary, i))),
mrb_fixnum_value(i)
);
}
if (RARRAY_LEN(v) != 2) {
mrb_raisef(mrb, E_ARGUMENT_ERROR, "wrong array length at %S (expected 2, was %S)",
mrb_fixnum_value(i),
mrb_fixnum_value(RARRAY_LEN(v))
);
}
mrb_hash_set(mrb, hash, RARRAY_PTR(v)[0], RARRAY_PTR(v)[1]);
}
return hash;
}
/*
* call-seq:
@@ -174,18 +132,20 @@ static mrb_value
mrb_ary_slice_bang(mrb_state *mrb, mrb_value self)
{
struct RArray *a = mrb_ary_ptr(self);
mrb_int i, j, k, len;
mrb_value index;
mrb_int i, j, k, len, alen;
mrb_value val;
mrb_value *ptr;
mrb_value ary;
mrb_ary_modify(mrb, a);
if (mrb_get_args(mrb, "o|i", &index, &len) == 1) {
if (mrb_get_argc(mrb) == 1) {
mrb_value index;
mrb_get_args(mrb, "o|i", &index, &len);
switch (mrb_type(index)) {
case MRB_TT_RANGE:
if (mrb_range_beg_len(mrb, index, &i, &len, a->len, TRUE) == 1) {
if (mrb_range_beg_len(mrb, index, &i, &len, ARY_LEN(a), TRUE) == 1) {
goto delete_pos_len;
}
else {
@@ -200,27 +160,28 @@ mrb_ary_slice_bang(mrb_state *mrb, mrb_value self)
}
}
i = mrb_fixnum(index);
mrb_get_args(mrb, "ii", &i, &len);
delete_pos_len:
if (i < 0) i += a->len;
if (i < 0 || a->len < i) return mrb_nil_value();
alen = ARY_LEN(a);
if (i < 0) i += alen;
if (i < 0 || alen < i) return mrb_nil_value();
if (len < 0) return mrb_nil_value();
if (a->len == i) return mrb_ary_new(mrb);
if (len > a->len - i) len = a->len - i;
if (alen == i) return mrb_ary_new(mrb);
if (len > alen - i) len = alen - i;
ary = mrb_ary_new_capa(mrb, len);
ptr = ARY_PTR(a);
for (j = i, k = 0; k < len; ++j, ++k) {
mrb_ary_push(mrb, ary, a->ptr[j]);
mrb_ary_push(mrb, ary, ptr[j]);
}
ptr = a->ptr + i;
for (j = i; j < a->len - len; ++j) {
ptr += i;
for (j = i; j < alen - len; ++j) {
*ptr = *(ptr+len);
++ptr;
}
mrb_ary_resize(mrb, self, a->len - len);
mrb_ary_resize(mrb, self, alen - len);
return ary;
}
@@ -233,7 +194,6 @@ 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, "to_h", mrb_ary_to_h, MRB_ARGS_REQ(0));
mrb_define_method(mrb, a, "slice!", mrb_ary_slice_bang, MRB_ARGS_ANY());
}
+86 -33
View File
@@ -1,13 +1,6 @@
##
# Array(Ext) Test
assert("Array.try_convert") do
assert_nil Array.try_convert(0)
assert_nil Array.try_convert(nil)
assert_equal [], Array.try_convert([])
assert_equal [1,2,3], Array.try_convert([1,2,3])
end
assert("Array#assoc") do
s1 = [ "colors", "red", "blue", "green" ]
s2 = [ "letters", "a", "b", "c" ]
@@ -75,6 +68,14 @@ assert("Array#|") do
assert_equal [1, 2, 3, 1], a
end
assert("Array#union") do
a = [1, 2, 3, 1]
b = [1, 4]
c = [1, 5]
assert_equal [1, 2, 3, 4, 5], a.union(b,c)
end
assert("Array#&") do
a = [1, 2, 3, 1]
b = [1, 4]
@@ -228,18 +229,47 @@ end
assert("Array#bsearch") do
# Find minimum mode
a = [0, 4, 7, 10, 12]
assert_include [4, 7], a.bsearch {|x| x >= 4 }
assert_equal 7, a.bsearch {|x| x >= 6 }
assert_equal 0, a.bsearch {|x| x >= -1 }
assert_nil a.bsearch {|x| x >= 100 }
a = [0, 2, 4]
assert_equal 0, a.bsearch{ |x| x >= -1 }
assert_equal 0, a.bsearch{ |x| x >= 0 }
assert_equal 2, a.bsearch{ |x| x >= 1 }
assert_equal 2, a.bsearch{ |x| x >= 2 }
assert_equal 4, a.bsearch{ |x| x >= 3 }
assert_equal 4, a.bsearch{ |x| x >= 4 }
assert_nil a.bsearch{ |x| x >= 5 }
# Find any mode
a = [0, 4, 7, 10, 12]
assert_include [4, 7], a.bsearch {|x| 1 - (x / 4).truncate }
assert_nil a.bsearch {|x| 4 - (x / 2).truncate }
assert_equal(nil, a.bsearch {|x| 1 })
assert_equal(nil, a.bsearch {|x| -1 })
a = [0, 4, 8]
def between(lo, x, hi)
if x < lo
1
elsif x > hi
-1
else
0
end
end
assert_nil a.bsearch{ |x| between(-3, x, -1) }
assert_equal 0, a.bsearch{ |x| between(-1, x, 1) }
assert_nil a.bsearch{ |x| between( 1, x, 3) }
assert_equal 4, a.bsearch{ |x| between( 3, x, 5) }
assert_nil a.bsearch{ |x| between( 5, x, 7) }
assert_equal 8, a.bsearch{ |x| between( 7, x, 9) }
assert_nil a.bsearch{ |x| between( 9, x, 11) }
assert_equal 0, a.bsearch{ |x| between( 0, x, 3) }
assert_equal 4, a.bsearch{ |x| between( 0, x, 4) }
assert_equal 4, a.bsearch{ |x| between( 4, x, 8) }
assert_equal 8, a.bsearch{ |x| between( 5, x, 8) }
# Invalid block result
assert_raise TypeError, 'invalid block result (must be numeric, true, false or nil)' do
a.bsearch{ 'I like to watch the world burn' }
end
end
assert("Array#bsearch_index") do
# tested through Array#bsearch
end
assert("Array#delete_if") do
@@ -301,27 +331,11 @@ assert('Array#to_h') do
assert_raise(ArgumentError) { [[1]].to_h }
end
assert('Array#to_h (Modified)') do
class A
def to_ary
$a.clear
nil
end
end
$a = [A.new]
assert_raise(TypeError) { $a.to_h }
end
assert("Array#index (block)") do
assert_nil (1..10).to_a.index { |i| i % 5 == 0 and i % 7 == 0 }
assert_equal 34, (1..100).to_a.index { |i| i % 5 == 0 and i % 7 == 0 }
end
assert("Array#to_ary") do
assert_equal [], [].to_ary
assert_equal [1,2,3], [1,2,3].to_ary
end
assert("Array#dig") do
h = [[[1]], 0]
assert_equal(1, h.dig(0, 0, 0))
@@ -352,3 +366,42 @@ assert("Array#slice!") do
assert_equal(i, [1, 2, 3])
assert_equal(j, nil)
end
assert("Array#permutation") do
a = [1, 2, 3]
assert_equal([[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]],
a.permutation.to_a)
assert_equal([[1],[2],[3]],
a.permutation(1).to_a)
assert_equal([[1,2],[1,3],[2,1],[2,3],[3,1],[3,2]],
a.permutation(2).to_a)
assert_equal([[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]],
a.permutation(3).to_a)
assert_equal([[]], a.permutation(0).to_a)
assert_equal([], a.permutation(4).to_a)
end
assert("Array#combination") do
a = [1, 2, 3, 4]
assert_equal([[1],[2],[3],[4]],
a.combination(1).to_a)
assert_equal([[1,2],[1,3],[1,4],[2,3],[2,4],[3,4]],
a.combination(2).to_a)
assert_equal([[1,2,3],[1,2,4],[1,3,4],[2,3,4]],
a.combination(3).to_a)
assert_equal([[1,2,3,4]],
a.combination(4).to_a)
assert_equal([[]], a.combination(0).to_a)
assert_equal([], a.combination(5).to_a)
end
assert('Array#transpose') do
assert_equal([].transpose, [])
assert_equal([[]].transpose, [])
assert_equal([[1]].transpose, [[1]])
assert_equal([[1,2,3]].transpose, [[1], [2], [3]])
assert_equal([[1], [2], [3]].transpose, [[1,2,3]])
assert_equal([[1,2], [3,4], [5,6]].transpose, [[1,3,5], [2,4,6]])
assert_raise(TypeError) { [1].transpose }
assert_raise(IndexError) { [[1], [2,3,4]].transpose }
end
+23
View File
@@ -0,0 +1,23 @@
unless MRuby::Build.current.kind_of?(MRuby::CrossBuild)
MRuby::Gem::Specification.new('mruby-bin-config') do |spec|
name = 'mruby-config'
spec.license = 'MIT'
spec.author = 'mruby developers'
spec.summary = "#{name} command"
mruby_config = name + (ENV['OS'] == 'Windows_NT' ? '.bat' : '')
mruby_config_path = "#{build.build_dir}/bin/#{mruby_config}"
make_cfg = "#{build.build_dir}/lib/libmruby.flags.mak"
tmplt_path = "#{__dir__}/#{mruby_config}"
build.bins << mruby_config
file mruby_config_path => [make_cfg, tmplt_path] do |t|
config = Hash[File.readlines(make_cfg).map!(&:chomp).map! {|l|
l.gsub('\\"', '"').split(' = ', 2).map! {|s| s.sub(/^(?=.)/, 'echo ')}
}]
tmplt = File.read(tmplt_path)
File.write(t.name, tmplt.gsub(/(#{Regexp.union(*config.keys)})\b/, config))
FileUtils.chmod(0755, t.name)
end
end
end
+15 -15
View File
@@ -91,7 +91,7 @@ assert('mruby-bin-debugger(print) error') do
# test case
tc = []
tc << {:cmd=>"p (1+2", :exp=>'$1 = SyntaxError'}
tc << {:cmd=>"p bar", :exp=>'$2 = NoMethodError'}
tc << {:cmd=>"p bar", :exp=>'$2 = (eval):2: undefined method'}
BinTest_MrubyBinDebugger.test(src, tc)
end
@@ -317,7 +317,7 @@ TestConstNameSubClass.new.m()
bp = nil
SRC
# todo: wait for 'break' to be implimented
# todo: wait for 'break' to be implemented
tc = []
9.times { tc << {:cmd=>"s"} }
tc << {:cmd=>"p CONST", :exp=>"super class"}
@@ -341,13 +341,13 @@ assert('mruby-bin-debugger(print) Literal:Numeric') do
tc << {:cmd=>"p +0100", :exp=>'$3 = 64'}
tc << {:cmd=>"p 0x100", :exp=>'$4 = 256'}
tc << {:cmd=>"p 1_234", :exp=>'$5 = 1234'}
tc << {:cmd=>"p 0b1000_0000", :exp=>"$6 = #{0b1000_0000.to_s}"}
tc << {:cmd=>"p 0x1000_0000", :exp=>"$7 = #{0x1000_0000.to_s}"}
tc << {:cmd=>"p 0b1000_0000", :exp=>"$6 = #{0b1000_0000}"}
tc << {:cmd=>"p 0x1000_0000", :exp=>"$7 = #{0x1000_0000}"}
tc << {:cmd=>"p 3.14", :exp=>'$8 = 3.14'}
tc << {:cmd=>"p -12.3", :exp=>'$9 = -12.3'}
tc << {:cmd=>"p +12.000", :exp=>'$10 = 12.0'}
tc << {:cmd=>"p 1e4", :exp=>'$11 = 10000.0'}
tc << {:cmd=>"p +12.000", :exp=>'$10 = 12'}
tc << {:cmd=>"p 1e4", :exp=>'$11 = 10000'}
tc << {:cmd=>"p -0.1e-2", :exp=>'$12 = -0.001'}
BinTest_MrubyBinDebugger.test(src, tc)
@@ -368,28 +368,28 @@ SRC
tc << {:cmd=>'p "str"', :exp=>'$1 = "str"'}
tc << {:cmd=>'p "s\tt\rr\n"', :exp=>'$2 = "s\\tt\\rr\\n"'}
tc << {:cmd=>'p "\C-a\C-z"', :exp=>'$3 = "\\001\\032"'}
tc << {:cmd=>'p "\C-a\C-z"', :exp=>'$3 = "\\x01\\x1a"'}
tc << {:cmd=>'p "#{foo+bar}"', :exp=>'$4 = "foobar"'}
tc << {:cmd=>'p \'str\'', :exp=>'$5 = "str"'}
tc << {:cmd=>'p \'s\\tt\\rr\\n\'', :exp=>'$6 = "s\\\\tt\\\\rr\\\\n"'}
tc << {:cmd=>'p \'\\C-a\\C-z\'', :exp=>'$7 = "\\\\C-a\\\\C-z"'}
tc << {:cmd=>'p \'#{foo+bar}\'', :exp=>'$8 = "#{foo+bar}"'}
tc << {:cmd=>'p \'#{foo+bar}\'', :exp=>'$8 = "\\#{foo+bar}"'}
tc << {:cmd=>'p %!str!', :exp=>'$9 = "str"'}
tc << {:cmd=>'p %!s\tt\rr\n!', :exp=>'$10 = "s\\tt\\rr\\n"'}
tc << {:cmd=>'p %!\C-a\C-z!', :exp=>'$11 = "\\001\\032"'}
tc << {:cmd=>'p %!\C-a\C-z!', :exp=>'$11 = "\\x01\\x1a"'}
tc << {:cmd=>'p %!#{foo+bar}!', :exp=>'$12 = "foobar"'}
tc << {:cmd=>'p %Q!str!', :exp=>'$13 = "str"'}
tc << {:cmd=>'p %Q!s\tt\rr\n!', :exp=>'$14 = "s\\tt\\rr\\n"'}
tc << {:cmd=>'p %Q!\C-a\C-z!', :exp=>'$15 = "\\001\\032"'}
tc << {:cmd=>'p %Q!\C-a\C-z!', :exp=>'$15 = "\\x01\\x1a"'}
tc << {:cmd=>'p %Q!#{foo+bar}!', :exp=>'$16 = "foobar"'}
tc << {:cmd=>'p %q!str!', :exp=>'$17 = "str"'}
tc << {:cmd=>'p %q!s\\tt\\rr\\n!', :exp=>'$18 = "s\\\\tt\\\\rr\\\\n"'}
tc << {:cmd=>'p %q!\\C-a\\C-z!', :exp=>'$19 = "\\\\C-a\\\\C-z"'}
tc << {:cmd=>'p %q!#{foo+bar}!', :exp=>'$20 = "#{foo+bar}"'}
tc << {:cmd=>'p %q!#{foo+bar}!', :exp=>'$20 = "\\#{foo+bar}"'}
BinTest_MrubyBinDebugger.test(src, tc)
end
@@ -410,7 +410,7 @@ SRC
tc << {:cmd=>'p []', :exp=>'$1 = []'}
tc << {:cmd=>'p [ 5, 12, 8, 10, ]', :exp=>'$2 = [5, 12, 8, 10]'}
tc << {:cmd=>'p [1,2.5,"#{foo+bar}"]', :exp=>'$3 = [1, 2.5, "foobar"]'}
tc << {:cmd=>'p %w[3.14 A\ &\ B #{foo}]', :exp=>'$4 = ["3.14", "A & B", "#{foo}"]'}
tc << {:cmd=>'p %w[3.14 A\ &\ B #{foo}]', :exp=>'$4 = ["3.14", "A & B", "\#{foo}"]'}
tc << {:cmd=>'p %W[3.14 A\ &\ B #{foo}]', :exp=>'$5 = ["3.14", "A & B", "foo"]'}
BinTest_MrubyBinDebugger.test(src, tc)
@@ -588,7 +588,7 @@ SRC
tc << {:cmd=>'p foo=[foo,bar,baz]', :exp=>'$2 = ["foo", "bar", "baz"]'}
tc << {:cmd=>'p undefined=-1', :exp=>'$3 = -1'}
tc << {:cmd=>'p "#{undefined}"', :exp=>'$4 = NoMethodError'}
tc << {:cmd=>'p "#{undefined}"', :exp=>'$4 = (eval):2: undefined method'}
BinTest_MrubyBinDebugger.test(src, tc)
end
@@ -626,7 +626,7 @@ SRC
tc << {:cmd=>'p [a,b]', :exp=>'$13 = [20, 10]'}
tc << {:cmd=>'p undefined=-1', :exp=>'$14 = -1'}
tc << {:cmd=>'p "#{undefined}"', :exp=>'$15 = NoMethodError'}
tc << {:cmd=>'p "#{undefined}"', :exp=>'$15 = (eval):2: undefined method'}
BinTest_MrubyBinDebugger.test(src, tc)
end
@@ -694,7 +694,7 @@ SRC
tc << {:cmd=>'p [a,b]', :exp=>'$13 = [20, 10]'}
tc << {:cmd=>'p undefined=-1', :exp=>'$14 = -1'}
tc << {:cmd=>'p "#{undefined}"', :exp=>'$15 = NoMethodError'}
tc << {:cmd=>'p "#{undefined}"', :exp=>'$15 = (eval):2: undefined method'}
BinTest_MrubyBinDebugger.test(src, tc)
end
@@ -84,7 +84,7 @@ free_breakpoint(mrb_state *mrb, mrb_debug_breakpoint *bp)
}
static uint16_t
check_file_lineno(struct mrb_irep *irep, const char *file, uint16_t lineno)
check_file_lineno(mrb_state *mrb, struct mrb_irep *irep, const char *file, uint16_t lineno)
{
mrb_irep_debug_info_file *info_file;
uint16_t result = 0;
@@ -93,8 +93,10 @@ check_file_lineno(struct mrb_irep *irep, const char *file, uint16_t lineno)
uint16_t i;
for (f_idx = 0; f_idx < irep->debug_info->flen; ++f_idx) {
const char *filename;
info_file = irep->debug_info->files[f_idx];
if (!strcmp(info_file->filename, file)) {
filename = mrb_sym2name_len(mrb, info_file->filename_sym, NULL);
if (!strcmp(filename, file)) {
result = MRB_DEBUG_BP_FILE_OK;
fix_lineno = check_lineno(info_file, lineno);
@@ -103,7 +105,7 @@ check_file_lineno(struct mrb_irep *irep, const char *file, uint16_t lineno)
}
}
for (i=0; i < irep->rlen; ++i) {
result |= check_file_lineno(irep->reps[i], file, lineno);
result |= check_file_lineno(mrb, irep->reps[i], file, lineno);
if (result == (MRB_DEBUG_BP_FILE_OK | MRB_DEBUG_BP_LINENO_OK)) {
return result;
}
@@ -112,23 +114,12 @@ check_file_lineno(struct mrb_irep *irep, const char *file, uint16_t lineno)
return result;
}
static const char*
get_class_name(mrb_state *mrb, struct RClass *class_obj)
{
struct RClass *outer;
mrb_sym class_sym;
outer = mrb_class_outer_module(mrb, class_obj);
class_sym = mrb_class_sym(mrb, class_obj, outer);
return mrb_sym2name(mrb, class_sym);
}
static int32_t
compare_break_method(mrb_state *mrb, mrb_debug_breakpoint *bp, struct RClass *class_obj, mrb_sym method_sym, mrb_bool* isCfunc)
{
const char* class_name;
const char* method_name;
struct RProc* m;
mrb_method_t m;
struct RClass* sc;
const char* sn;
mrb_sym ssym;
@@ -139,7 +130,7 @@ compare_break_method(mrb_state *mrb, mrb_debug_breakpoint *bp, struct RClass *cl
method_p = &bp->point.methodpoint;
if (strcmp(method_p->method_name, method_name) == 0) {
class_name = get_class_name(mrb, class_obj);
class_name = mrb_class_name(mrb, class_obj);
if (class_name == NULL) {
if (method_p->class_name == NULL) {
return bp->bpno;
@@ -147,10 +138,10 @@ compare_break_method(mrb_state *mrb, mrb_debug_breakpoint *bp, struct RClass *cl
}
else if (method_p->class_name != NULL) {
m = mrb_method_search_vm(mrb, &class_obj, method_sym);
if (m == NULL) {
if (MRB_METHOD_UNDEF_P(m)) {
return MRB_DEBUG_OK;
}
if (MRB_PROC_CFUNC_P(m)) {
if (MRB_METHOD_CFUNC_P(m)) {
*isCfunc = TRUE;
}
@@ -162,12 +153,12 @@ compare_break_method(mrb_state *mrb, mrb_debug_breakpoint *bp, struct RClass *cl
sc = mrb_class_get(mrb, method_p->class_name);
ssym = mrb_symbol(mrb_check_intern_cstr(mrb, method_p->method_name));
m = mrb_method_search_vm(mrb, &sc, ssym);
if (m == NULL) {
if (MRB_METHOD_UNDEF_P(m)) {
return MRB_DEBUG_OK;
}
class_name = get_class_name(mrb, class_obj);
sn = get_class_name(mrb, sc);
class_name = mrb_class_name(mrb, class_obj);
sn = mrb_class_name(mrb, sc);
if (strcmp(sn, class_name) == 0) {
return bp->bpno;
}
@@ -196,7 +187,7 @@ mrb_debug_set_break_line(mrb_state *mrb, mrb_debug_context *dbg, const char *fil
}
/* file and lineno check (line type mrb_debug_line_ary only.) */
result = check_file_lineno(dbg->root_irep, file, lineno);
result = check_file_lineno(mrb, dbg->root_irep, file, lineno);
if (result == 0) {
return MRB_DEBUG_BREAK_INVALID_FILE;
}
@@ -204,7 +195,7 @@ mrb_debug_set_break_line(mrb_state *mrb, mrb_debug_context *dbg, const char *fil
return MRB_DEBUG_BREAK_INVALID_LINENO;
}
set_file = mrb_malloc(mrb, strlen(file) + 1);
set_file = (char*)mrb_malloc(mrb, strlen(file) + 1);
index = dbg->bpnum;
dbg->bp[index].bpno = dbg->next_bpno;
@@ -241,14 +232,14 @@ mrb_debug_set_break_method(mrb_state *mrb, mrb_debug_context *dbg, const char *c
}
if (class_name != NULL) {
set_class = mrb_malloc(mrb, strlen(class_name) + 1);
set_class = (char*)mrb_malloc(mrb, strlen(class_name) + 1);
strncpy(set_class, class_name, strlen(class_name) + 1);
}
else {
set_class = NULL;
}
set_method = mrb_malloc(mrb, strlen(method_name) + 1);
set_method = (char*)mrb_malloc(mrb, strlen(method_name) + 1);
strncpy(set_method, method_name, strlen(method_name) + 1);
@@ -437,10 +428,10 @@ mrb_debug_disable_break_all(mrb_state *mrb, mrb_debug_context *dbg)
}
static mrb_bool
check_start_pc_for_line(mrb_irep *irep, mrb_code *pc, uint16_t line)
check_start_pc_for_line(mrb_state *mrb, mrb_irep *irep, mrb_code *pc, uint16_t line)
{
if (pc > irep->iseq) {
if (line == mrb_debug_get_line(irep, (uint32_t)(pc - irep->iseq - 1))) {
if (line == mrb_debug_get_line(mrb, irep, pc - irep->iseq - 1)) {
return FALSE;
}
}
@@ -458,7 +449,7 @@ mrb_debug_check_breakpoint_line(mrb_state *mrb, mrb_debug_context *dbg, const ch
return MRB_DEBUG_INVALID_ARGUMENT;
}
if (!check_start_pc_for_line(dbg->irep, dbg->pc, line)) {
if (!check_start_pc_for_line(mrb, dbg->irep, dbg->pc, line)) {
return MRB_DEBUG_OK;
}
@@ -514,5 +505,3 @@ mrb_debug_check_breakpoint_method(mrb_state *mrb, mrb_debug_context *dbg, struct
return 0;
}
@@ -48,7 +48,7 @@ build_path(mrb_state *mrb, const char *dir, const char *base)
len += strlen(dir) + sizeof("/") - 1;
}
path = mrb_malloc(mrb, len);
path = (char*)mrb_malloc(mrb, len);
memset(path, 0, len);
if (strcmp(dir, ".")) {
@@ -64,7 +64,8 @@ static char*
dirname(mrb_state *mrb, const char *path)
{
size_t len;
char *p, *dir;
const char *p;
char *dir;
if (path == NULL) {
return NULL;
@@ -73,7 +74,7 @@ dirname(mrb_state *mrb, const char *path)
p = strrchr(path, '/');
len = p != NULL ? (size_t)(p - path) : strlen(path);
dir = mrb_malloc(mrb, len + 1);
dir = (char*)mrb_malloc(mrb, len + 1);
strncpy(dir, path, len);
dir[len] = '\0';
@@ -83,9 +84,9 @@ dirname(mrb_state *mrb, const char *path)
static source_file*
source_file_new(mrb_state *mrb, mrb_debug_context *dbg, char *filename)
{
source_file *file = NULL;
source_file *file;
file = mrb_malloc(mrb, sizeof(source_file));
file = (source_file*)mrb_malloc(mrb, sizeof(source_file));
memset(file, '\0', sizeof(source_file));
file->fp = fopen(filename, "rb");
@@ -96,7 +97,7 @@ source_file_new(mrb_state *mrb, mrb_debug_context *dbg, char *filename)
}
file->lineno = 1;
file->path = mrb_malloc(mrb, strlen(filename) + 1);
file->path = (char*)mrb_malloc(mrb, strlen(filename) + 1);
strcpy(file->path, filename);
return file;
}
@@ -174,9 +175,13 @@ mrb_debug_get_source(mrb_state *mrb, mrdb_state *mrdb, const char *srcpath, cons
FILE *fp;
const char *search_path[3];
char *path = NULL;
const char *srcname = strrchr(filename, '/');
if (srcname) srcname++;
else srcname = filename;
search_path[0] = srcpath;
search_path[1] = dirname(mrb, mrb_debug_get_filename(mrdb->dbg->root_irep, 0));
search_path[1] = dirname(mrb, mrb_debug_get_filename(mrb, mrdb->dbg->irep, 0));
search_path[2] = ".";
for (i = 0; i < 3; i++) {
@@ -184,7 +189,7 @@ mrb_debug_get_source(mrb_state *mrb, mrdb_state *mrdb, const char *srcpath, cons
continue;
}
if ((path = build_path(mrb, search_path[i], filename)) == NULL) {
if ((path = build_path(mrb, search_path[i], srcname)) == NULL) {
continue;
}
@@ -21,7 +21,7 @@ mrdb_check_syntax(mrb_state *mrb, mrb_debug_context *dbg, const char *expr, size
c = mrbc_context_new(mrb);
c->no_exec = TRUE;
c->capture_errors = TRUE;
c->filename = (char*)dbg->prvfile;
mrbc_filename(mrb, c, (const char*)dbg->prvfile);
c->lineno = dbg->prvline;
/* Load program */
@@ -31,7 +31,7 @@ mrdb_check_syntax(mrb_state *mrb, mrb_debug_context *dbg, const char *expr, size
}
mrb_value
mrb_debug_eval(mrb_state *mrb, mrb_debug_context *dbg, const char *expr, size_t len, mrb_bool *exc)
mrb_debug_eval(mrb_state *mrb, mrb_debug_context *dbg, const char *expr, size_t len, mrb_bool *exc, int direct_eval)
{
void (*tmp)(struct mrb_state *, struct mrb_irep *, mrb_code *, mrb_value *);
mrb_value ruby_code;
@@ -48,6 +48,11 @@ mrb_debug_eval(mrb_state *mrb, mrb_debug_context *dbg, const char *expr, size_t
v = mrb_obj_value(mrb->exc);
mrb->exc = 0;
}
else if (direct_eval) {
recv = dbg->regs[0];
v = mrb_funcall(mrb, recv, expr, 0);
}
else {
/*
* begin
@@ -8,6 +8,6 @@
#include <mruby.h>
#include "mrdb.h"
mrb_value mrb_debug_eval(mrb_state*, mrb_debug_context*, const char*, size_t, mrb_bool*);
mrb_value mrb_debug_eval(mrb_state*, mrb_debug_context*, const char*, size_t, mrb_bool*, int);
#endif /* APIPRINT_H_ */
@@ -242,7 +242,7 @@ info_break_select(mrb_state *mrb, mrdb_state *mrdb)
}
mrb_debug_bptype
parse_breakcommand(mrdb_state *mrdb, const char **file, uint32_t *line, char **cname, char **method)
parse_breakcommand(mrb_state *mrb, mrdb_state *mrdb, const char **file, uint32_t *line, char **cname, char **method)
{
mrb_debug_context *dbg = mrdb->dbg;
char *args;
@@ -274,7 +274,7 @@ parse_breakcommand(mrdb_state *mrdb, const char **file, uint32_t *line, char **c
STRTOUL(l, body);
if (l <= 65535) {
*line = l;
*file = (body == args)? mrb_debug_get_filename(dbg->irep, (uint32_t)(dbg->pc - dbg->irep->iseq)): args;
*file = (body == args)? mrb_debug_get_filename(mrb, dbg->irep, dbg->pc - dbg->irep->iseq): args;
}
else {
puts(BREAK_ERR_MSG_RANGEOVER);
@@ -332,7 +332,7 @@ dbgcmd_break(mrb_state *mrb, mrdb_state *mrdb)
char *method = NULL;
int32_t ret;
type = parse_breakcommand(mrdb, &file, &line, &cname, &method);
type = parse_breakcommand(mrb, mrdb, &file, &line, &cname, &method);
switch (type) {
case MRB_DEBUG_BPTYPE_LINE:
ret = mrb_debug_set_break_line(mrb, dbg, file, line);
@@ -81,6 +81,12 @@ static help_msg help_msg_list[] = {
"Status of specified breakpoints (all user-settable breakpoints if no argument).\n"
"Arguments are breakpoint numbers with spaces in between.\n"
},
{
"i[nfo]", "l[ocals]", "Print name of local variables",
"Usage: info locals\n"
"\n"
"Print name of local variables.\n"
},
{
"l[ist]", NULL, "List specified line",
"Usage: list\n"
@@ -133,7 +139,7 @@ typedef struct listcmd_parser_state {
static listcmd_parser_state*
listcmd_parser_state_new(mrb_state *mrb)
{
listcmd_parser_state *st = mrb_malloc(mrb, sizeof(listcmd_parser_state));
listcmd_parser_state *st = (listcmd_parser_state*)mrb_malloc(mrb, sizeof(listcmd_parser_state));
memset(st, 0, sizeof(listcmd_parser_state));
return st;
}
@@ -227,7 +233,7 @@ parse_filename(mrb_state *mrb, char **sp, listcmd_parser_state *st)
}
if (len > 0) {
st->filename = mrb_malloc(mrb, len + 1);
st->filename = (char*)mrb_malloc(mrb, len + 1);
strncpy(st->filename, *sp, len);
st->filename[len] = '\0';
*sp += len;
@@ -242,7 +248,8 @@ char*
replace_ext(mrb_state *mrb, const char *filename, const char *ext)
{
size_t len;
char *p, *s;
const char *p;
char *s;
if (filename == NULL) {
return NULL;
@@ -255,7 +262,7 @@ replace_ext(mrb_state *mrb, const char *filename, const char *ext)
len = strlen(filename);
}
s = mrb_malloc(mrb, len + strlen(ext) + 1);
s = (char*)mrb_malloc(mrb, len + strlen(ext) + 1);
memset(s, '\0', len + strlen(ext) + 1);
strncpy(s, filename, len);
strcat(s, ext);
@@ -325,7 +332,7 @@ parse_listcmd_args(mrb_state *mrb, mrdb_state *mrdb, listcmd_parser_state *st)
static mrb_bool
check_cmd_pattern(const char *pattern, const char *cmd)
{
char *lbracket, *rbracket, *p, *q;
const char *lbracket, *rbracket, *p, *q;
if (pattern == NULL && cmd == NULL) {
return TRUE;
@@ -494,7 +501,7 @@ dbgcmd_quit(mrb_state *mrb, mrdb_state *mrdb)
if (mrdb->dbg->xm == DBG_QUIT) {
struct RClass *exc;
exc = mrb_define_class(mrb, "DebuggerExit", mrb_class_get(mrb, "Exception"));
exc = mrb_define_class(mrb, "DebuggerExit", mrb->eException_class);
mrb_raise(mrb, exc, "Exit mrdb.");
}
return DBGST_PROMPT;
@@ -36,7 +36,7 @@ dbgcmd_print(mrb_state *mrb, mrdb_state *mrdb)
expr = mrb_str_cat_cstr(mrb, expr, mrdb->words[wcnt]);
}
result = mrb_debug_eval(mrb, mrdb->dbg, RSTRING_PTR(expr), RSTRING_LEN(expr), NULL);
result = mrb_debug_eval(mrb, mrdb->dbg, RSTRING_PTR(expr), RSTRING_LEN(expr), NULL, 0);
/* $print_no = result */
s = mrb_str_cat_lit(mrb, result, "\0");
@@ -56,3 +56,26 @@ dbgcmd_eval(mrb_state *mrb, mrdb_state *mrdb)
{
return dbgcmd_print(mrb, mrdb);
}
dbgcmd_state
dbgcmd_info_local(mrb_state *mrb, mrdb_state *mrdb)
{
mrb_value result;
mrb_value s;
int ai;
ai = mrb_gc_arena_save(mrb);
result = mrb_debug_eval(mrb, mrdb->dbg, "local_variables", 0, NULL, 1);
s = mrb_str_cat_lit(mrb, result, "\0");
printf("$%lu = %s\n", (unsigned long)mrdb->print_no++, RSTRING_PTR(s));
if (mrdb->print_no == 0) {
mrdb->print_no = 1;
}
mrb_gc_arena_restore(mrb, ai);
return DBGST_PROMPT;
}
@@ -19,7 +19,7 @@ dbgcmd_run(mrb_state *mrb, mrdb_state *mrdb)
if (dbg->xphase == DBG_PHASE_RUNNING){
struct RClass *exc;
puts("Start it from the beginning.");
exc = mrb_define_class(mrb, "DebuggerRestart", mrb_class_get(mrb, "Exception"));
exc = mrb_define_class(mrb, "DebuggerRestart", mrb->eException_class);
mrb_raise(mrb, exc, "Restart mrdb.");
}
}
+11 -8
View File
@@ -52,6 +52,7 @@ static const debug_command debug_command_list[] = {
{"eval", NULL, 2, 0, 0, DBGCMD_EVAL, dbgcmd_eval}, /* ev[al] */
{"help", NULL, 1, 0, 1, DBGCMD_HELP, dbgcmd_help}, /* h[elp] */
{"info", "breakpoints", 1, 1, 1, DBGCMD_INFO_BREAK, dbgcmd_info_break}, /* i[nfo] b[reakpoints] */
{"info", "locals", 1, 1, 0, DBGCMD_INFO_LOCAL, dbgcmd_info_local}, /* i[nfo] l[ocals] */
{"list", NULL, 1, 0, 1, DBGCMD_LIST, dbgcmd_list}, /* l[ist] */
{"print", NULL, 1, 0, 0, DBGCMD_PRINT, dbgcmd_print}, /* p[rint] */
{"quit", NULL, 1, 0, 0, DBGCMD_QUIT, dbgcmd_quit}, /* q[uit] */
@@ -184,7 +185,7 @@ cleanup(mrb_state *mrb, struct _args *args)
static mrb_debug_context*
mrb_debug_context_new(mrb_state *mrb)
{
mrb_debug_context *dbg = mrb_malloc(mrb, sizeof(mrb_debug_context));
mrb_debug_context *dbg = (mrb_debug_context*)mrb_malloc(mrb, sizeof(mrb_debug_context));
memset(dbg, 0, sizeof(mrb_debug_context));
@@ -223,12 +224,12 @@ mrb_debug_context_free(mrb_state *mrb)
static mrdb_state*
mrdb_state_new(mrb_state *mrb)
{
mrdb_state *mrdb = mrb_malloc(mrb, sizeof(mrdb_state));
mrdb_state *mrdb = (mrdb_state*)mrb_malloc(mrb, sizeof(mrdb_state));
memset(mrdb, 0, sizeof(mrdb_state));
mrdb->dbg = mrb_debug_context_get(mrb);
mrdb->command = mrb_malloc(mrb, MAX_COMMAND_LINE+1);
mrdb->command = (char*)mrb_malloc(mrb, MAX_COMMAND_LINE+1);
mrdb->print_no = 1;
return mrdb;
@@ -510,6 +511,7 @@ check_method_breakpoint(mrb_state *mrb, mrb_irep *irep, mrb_code *pc, mrb_value
mrb_sym sym;
int32_t bpno;
mrb_bool isCfunc;
struct mrb_insn_data insn;
mrb_debug_context *dbg = mrb_debug_context_get(mrb);
@@ -517,11 +519,12 @@ check_method_breakpoint(mrb_state *mrb, mrb_irep *irep, mrb_code *pc, mrb_value
bpno = dbg->method_bpno;
dbg->method_bpno = 0;
switch(GET_OPCODE(*pc)) {
insn = mrb_decode_insn(pc);
switch(insn.insn) {
case OP_SEND:
case OP_SENDB:
c = mrb_class(mrb, regs[GETARG_A(*pc)]);
sym = irep->syms[GETARG_B(*pc)];
c = mrb_class(mrb, regs[insn.a]);
sym = irep->syms[insn.b];
break;
case OP_SUPER:
c = mrb->c->ci->target_class->super;
@@ -566,8 +569,8 @@ mrb_code_fetch_hook(mrb_state *mrb, mrb_irep *irep, mrb_code *pc, mrb_value *reg
dbg->xphase = DBG_PHASE_RUNNING;
}
file = mrb_debug_get_filename(irep, (uint32_t)(pc - irep->iseq));
line = mrb_debug_get_line(irep, (uint32_t)(pc - irep->iseq));
file = mrb_debug_get_filename(mrb, irep, pc - irep->iseq);
line = mrb_debug_get_line(mrb, irep, pc - irep->iseq);
switch (dbg->xm) {
case DBG_STEP:
@@ -23,6 +23,7 @@ typedef enum debug_command_id {
DBGCMD_STEP,
DBGCMD_BREAK,
DBGCMD_INFO_BREAK,
DBGCMD_INFO_LOCAL,
DBGCMD_WATCH,
DBGCMD_INFO_WATCH,
DBGCMD_ENABLE,
@@ -151,6 +152,7 @@ dbgcmd_state dbgcmd_next(mrb_state*, mrdb_state*);
/* cmdbreak.c */
dbgcmd_state dbgcmd_break(mrb_state*, mrdb_state*);
dbgcmd_state dbgcmd_info_break(mrb_state*, mrdb_state*);
dbgcmd_state dbgcmd_info_local(mrb_state*, mrdb_state*);
dbgcmd_state dbgcmd_delete(mrb_state*, mrdb_state*);
dbgcmd_state dbgcmd_enable(mrb_state*, mrdb_state*);
dbgcmd_state dbgcmd_disable(mrb_state*, mrdb_state*);
+22
View File
@@ -10,3 +10,25 @@ assert('regression for #1563') do
o, s = Open3.capture2('bin/mirb', :stdin_data => "a=1;b=2;c=3\nb\nc")
assert_true o.include?('=> 3')
end
assert('mirb -d option') do
o, _ = Open3.capture2('bin/mirb', :stdin_data => "$DEBUG\n")
assert_true o.include?('=> false')
o, _ = Open3.capture2('bin/mirb -d', :stdin_data => "$DEBUG\n")
assert_true o.include?('=> true')
end
assert('mirb -r option') do
lib = Tempfile.new('lib.rb')
lib.write <<EOS
class Hoge
def hoge
:hoge
end
end
EOS
lib.flush
o, _ = Open3.capture2("bin/mirb -r #{lib.path}", :stdin_data => "Hoge.new.hoge\n")
assert_true o.include?('=> :hoge')
end
+111 -17
View File
@@ -6,6 +6,15 @@
** immediately. It's a REPL...
*/
#include <mruby.h>
#include <mruby/array.h>
#include <mruby/proc.h>
#include <mruby/compile.h>
#include <mruby/dump.h>
#include <mruby/string.h>
#include <mruby/variable.h>
#include <mruby/throw.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
@@ -19,6 +28,12 @@
#include <readline/history.h>
#define MIRB_ADD_HISTORY(line) add_history(line)
#define MIRB_READLINE(ch) readline(ch)
#if !defined(RL_READLINE_VERSION) || RL_READLINE_VERSION < 0x600
/* libedit & older readline do not have rl_free() */
#define MIRB_LINE_FREE(line) free(line)
#else
#define MIRB_LINE_FREE(line) rl_free(line)
#endif
#define MIRB_WRITE_HISTORY(path) write_history(path)
#define MIRB_READ_HISTORY(path) read_history(path)
#define MIRB_USING_HISTORY() using_history()
@@ -27,6 +42,7 @@
#include <linenoise.h>
#define MIRB_ADD_HISTORY(line) linenoiseHistoryAdd(line)
#define MIRB_READLINE(ch) linenoise(ch)
#define MIRB_LINE_FREE(line) linenoiseFree(line)
#define MIRB_WRITE_HISTORY(path) linenoiseHistorySave(path)
#define MIRB_READ_HISTORY(path) linenoiseHistoryLoad(history_path)
#define MIRB_USING_HISTORY()
@@ -42,12 +58,6 @@
#define SIGJMP_BUF jmp_buf
#endif
#include <mruby.h>
#include <mruby/array.h>
#include <mruby/proc.h>
#include <mruby/compile.h>
#include <mruby/string.h>
#ifdef ENABLE_READLINE
static const char history_file_name[] = ".mirb_history";
@@ -88,6 +98,7 @@ static void
p(mrb_state *mrb, mrb_value obj, int prompt)
{
mrb_value val;
char* msg;
val = mrb_funcall(mrb, obj, "inspect", 0);
if (prompt) {
@@ -101,7 +112,9 @@ p(mrb_state *mrb, mrb_value obj, int prompt)
if (!mrb_string_p(val)) {
val = mrb_obj_as_string(mrb, obj);
}
fwrite(RSTRING_PTR(val), RSTRING_LEN(val), 1, stdout);
msg = mrb_locale_from_utf8(RSTRING_PTR(val), (int)RSTRING_LEN(val));
fwrite(msg, strlen(msg), 1, stdout);
mrb_locale_free(msg);
putc('\n', stdout);
}
@@ -114,10 +127,6 @@ is_code_block_open(struct mrb_parser_state *parser)
/* check for heredoc */
if (parser->parsing_heredoc != NULL) return TRUE;
if (parser->heredoc_end_now) {
parser->heredoc_end_now = FALSE;
return FALSE;
}
/* check for unterminated string */
if (parser->lex_strterm) return TRUE;
@@ -209,8 +218,11 @@ is_code_block_open(struct mrb_parser_state *parser)
struct _args {
FILE *rfp;
mrb_bool verbose : 1;
mrb_bool debug : 1;
int argc;
char** argv;
int libc;
char **libv;
};
static void
@@ -218,6 +230,8 @@ usage(const char *name)
{
static const char *const usage_msg[] = {
"switches:",
"-d set $DEBUG to true (same as `mruby -d`)",
"-r library same as `mruby -r`",
"-v print version number, then run in verbose mode",
"--verbose run in verbose mode",
"--version print the version",
@@ -231,9 +245,19 @@ usage(const char *name)
printf(" %s\n", *p++);
}
static char *
dup_arg_item(mrb_state *mrb, const char *item)
{
size_t buflen = strlen(item) + 1;
char *buf = (char*)mrb_malloc(mrb, buflen);
memcpy(buf, item, buflen);
return buf;
}
static int
parse_args(mrb_state *mrb, int argc, char **argv, struct _args *args)
{
char **origargv = argv;
static const struct _args args_zero = { 0 };
*args = args_zero;
@@ -244,6 +268,26 @@ parse_args(mrb_state *mrb, int argc, char **argv, struct _args *args)
item = argv[0] + 1;
switch (*item++) {
case 'd':
args->debug = TRUE;
break;
case 'r':
if (!item[0]) {
if (argc <= 1) {
printf("%s: No library specified for -r\n", *origargv);
return EXIT_FAILURE;
}
argc--; argv++;
item = argv[0];
}
if (args->libc == 0) {
args->libv = (char**)mrb_malloc(mrb, sizeof(char*));
}
else {
args->libv = (char**)mrb_realloc(mrb, args->libv, sizeof(char*) * (args->libc + 1));
}
args->libv[args->libc++] = dup_arg_item(mrb, item);
break;
case 'v':
if (!args->verbose) mrb_show_version(mrb);
args->verbose = TRUE;
@@ -289,6 +333,12 @@ cleanup(mrb_state *mrb, struct _args *args)
if (args->rfp)
fclose(args->rfp);
mrb_free(mrb, args->argv);
if (args->libc) {
while (args->libc--) {
mrb_free(mrb, args->libv[args->libc]);
}
mrb_free(mrb, args->libv);
}
mrb_close(mrb);
}
@@ -323,7 +373,7 @@ check_keyword(const char *buf, const char *word)
size_t len = strlen(word);
/* skip preceding spaces */
while (*p && isspace((unsigned char)*p)) {
while (*p && ISSPACE(*p)) {
p++;
}
/* check keyword */
@@ -333,7 +383,7 @@ check_keyword(const char *buf, const char *word)
p += len;
/* skip trailing spaces */
while (*p) {
if (!isspace((unsigned char)*p)) return 0;
if (!ISSPACE(*p)) return 0;
p++;
}
return 1;
@@ -403,6 +453,7 @@ main(int argc, char **argv)
}
}
mrb_define_global_const(mrb, "ARGV", ARGV);
mrb_gv_set(mrb, mrb_intern_lit(mrb, "$DEBUG"), mrb_bool_value(args.debug));
#ifdef ENABLE_READLINE
history_path = get_history_path(mrb);
@@ -419,6 +470,19 @@ main(int argc, char **argv)
print_hint();
cxt = mrbc_context_new(mrb);
/* Load libraries */
for (i = 0; i < args.libc; i++) {
FILE *lfp = fopen(args.libv[i], "r");
if (lfp == NULL) {
printf("Cannot open library file. (%s)\n", args.libv[i]);
cleanup(mrb, &args);
return EXIT_FAILURE;
}
mrb_load_file_cxt(mrb, lfp, cxt);
fclose(lfp);
}
cxt->capture_errors = TRUE;
cxt->lineno = 1;
mrbc_filename(mrb, cxt, "(mirb)");
@@ -428,7 +492,10 @@ main(int argc, char **argv)
while (TRUE) {
char *utf8;
struct mrb_jmpbuf c_jmp;
MRB_TRY(&c_jmp);
mrb->jmp = &c_jmp;
if (args.rfp) {
if (fgets(last_code_line, sizeof(last_code_line)-1, args.rfp) != NULL)
goto done;
@@ -489,11 +556,10 @@ main(int argc, char **argv)
strcpy(last_code_line, line);
strcat(last_code_line, "\n");
MIRB_ADD_HISTORY(line);
free(line);
MIRB_LINE_FREE(line);
#endif
done:
done:
if (code_block_open) {
if (strlen(ruby_code)+strlen(last_code_line) > sizeof(ruby_code)-1) {
fputs("concatenated input string too long\n", stderr);
@@ -528,9 +594,17 @@ done:
/* no evaluation of code */
}
else {
if (0 < parser->nwarn) {
/* warning */
char* msg = mrb_locale_from_utf8(parser->warn_buffer[0].message, -1);
printf("line %d: %s\n", parser->warn_buffer[0].lineno, msg);
mrb_locale_free(msg);
}
if (0 < parser->nerr) {
/* syntax error */
printf("line %d: %s\n", parser->error_buffer[0].lineno, parser->error_buffer[0].message);
char* msg = mrb_locale_from_utf8(parser->error_buffer[0].message, -1);
printf("line %d: %s\n", parser->error_buffer[0].lineno, msg);
mrb_locale_free(msg);
}
else {
/* generate bytecode */
@@ -544,6 +618,13 @@ done:
if (args.verbose) {
mrb_codedump_all(mrb, proc);
}
/* adjust stack length of toplevel environment */
if (mrb->c->cibase->env) {
struct REnv *e = mrb->c->cibase->env;
if (e && MRB_ENV_STACK_LEN(e) < proc->body.irep->nlocals) {
MRB_ENV_SET_STACK_LEN(e, proc->body.irep->nlocals);
}
}
/* pass a proc for evaluation */
/* evaluate the bytecode */
result = mrb_vm_run(mrb,
@@ -570,6 +651,11 @@ done:
}
mrb_parser_free(parser);
cxt->lineno++;
MRB_CATCH(&c_jmp) {
p(mrb, mrb_obj_value(mrb->exc), 0);
mrb->exc = 0;
}
MRB_END_EXC(&c_jmp);
}
#ifdef ENABLE_READLINE
@@ -577,6 +663,14 @@ done:
mrb_free(mrb, history_path);
#endif
if (args.rfp) fclose(args.rfp);
mrb_free(mrb, args.argv);
if (args.libv) {
for (i = 0; i < args.libc; ++i) {
mrb_free(mrb, args.libv[i]);
}
mrb_free(mrb, args.libv);
}
mrbc_context_free(mrb, cxt);
mrb_close(mrb);
+1 -1
View File
@@ -8,7 +8,7 @@ MRuby::Gem::Specification.new 'mruby-bin-mrbc' do |spec|
exec = exefile("#{build.build_dir}/bin/mrbc")
mrbc_objs = Dir.glob("#{spec.dir}/tools/mrbc/*.c").map { |f| objfile(f.pathmap("#{spec.build_dir}/tools/mrbc/%n")) }.flatten
file exec => mrbc_objs + [libfile("#{build.build_dir}/lib/libmruby_core")] do |t|
file exec => mrbc_objs + [build.libmruby_core_static] do |t|
build.linker.run t.name, t.prerequisites
end
+9
View File
@@ -18,6 +18,7 @@ struct mrbc_args {
const char *initname;
mrb_bool check_syntax : 1;
mrb_bool verbose : 1;
mrb_bool remove_lv : 1;
unsigned int flags : 4;
};
@@ -33,6 +34,7 @@ usage(const char *name)
"-B<symbol> binary <symbol> output in C language format",
"-e generate little endian iseq data",
"-E generate big endian iseq data",
"--remove-lv remove local variables",
"--verbose run at verbose mode",
"--version print the version",
"--copyright print the copyright",
@@ -142,6 +144,10 @@ parse_args(mrb_state *mrb, int argc, char **argv, struct mrbc_args *args)
mrb_show_copyright(mrb);
exit(EXIT_SUCCESS);
}
else if (strcmp(argv[i] + 2, "remove-lv") == 0) {
args->remove_lv = TRUE;
break;
}
return -1;
default:
return i;
@@ -232,6 +238,9 @@ dump_file(mrb_state *mrb, FILE *wfp, const char *outfile, struct RProc *proc, st
int n = MRB_DUMP_OK;
mrb_irep *irep = proc->body.irep;
if (args->remove_lv) {
mrb_irep_remove_lv(mrb, irep);
}
if (args->initname) {
n = mrb_dump_irep_cfunc(mrb, irep, args->flags, wfp, args->initname);
if (n == MRB_DUMP_INVALID_ARGUMENT) {
@@ -1,30 +0,0 @@
module MRuby
class Build
def exefile(name)
if name.is_a?(Array)
name.flatten.map { |n| exefile(n) }
elsif name !~ /\./
"#{name}#{exts.executable}"
else
name
end
end
end
end
MRuby.each_target do
next if kind_of? MRuby::CrossBuild
mruby_config = 'mruby-config' + (ENV['OS'] == 'Windows_NT' ? '.bat' : '')
mruby_config_path = "#{build_dir}/bin/#{mruby_config}"
@bins << mruby_config
file mruby_config_path => libfile("#{build_dir}/lib/libmruby") do |t|
FileUtils.copy "#{File.dirname(__FILE__)}/#{mruby_config}", t.name
config = Hash[open("#{build_dir}/lib/libmruby.flags.mak").read.split("\n").map {|x| a = x.split(/\s*=\s*/, 2); [a[0], a[1].gsub('\\"', '"') ]}]
IO.write(t.name, File.open(t.name) {|f|
f.read.gsub (/echo (MRUBY_CFLAGS|MRUBY_LIBS|MRUBY_LDFLAGS_BEFORE_LIBS|MRUBY_LDFLAGS|MRUBY_LIBMRUBY_PATH)/) {|x| config[$1].empty? ? '' : "echo #{config[$1]}"}
})
FileUtils.chmod(0755, t.name)
end
end
+38 -1
View File
@@ -12,7 +12,7 @@ assert('regression for #1572') do
File.write script.path, 'p "ok"'
system "#{cmd('mrbc')} -g -o #{bin.path} #{script.path}"
o = `#{cmd('mruby')} -b #{bin.path}`.strip
assert_equal o, '"ok"'
assert_equal '"ok"', o
end
assert '$0 value' do
@@ -31,6 +31,13 @@ assert '$0 value' do
assert_equal '"-e"', `#{cmd('mruby')} -e #{shellquote('p $0')}`.chomp
end
assert('float literal') do
script, bin = Tempfile.new('test.rb'), Tempfile.new('test.mrb')
File.write script.path, 'p [3.21, 2e308.infinite?, -2e308.infinite?]'
system "#{cmd('mrbc')} -g -o #{bin.path} #{script.path}"
assert_equal "[3.21, 1, -1]", `#{cmd('mruby')} -b #{bin.path}`.chomp!
end
assert '__END__', '8.6' do
script = Tempfile.new('test.rb')
@@ -58,3 +65,33 @@ RUBY
assert_equal "NilClass", `#{cmd('mruby')} #{script.path}`
assert_equal 0, $?.exitstatus
end
assert('mruby -d option') do
o = `#{cmd('mruby')} -e #{shellquote('p $DEBUG')}`
assert_equal "false\n", o
o = `#{cmd('mruby')} -d -e #{shellquote('p $DEBUG')}`
assert_equal "true\n", o
end
assert('mruby -r option') do
lib = Tempfile.new('lib.rb')
lib.write <<EOS
class Hoge
def hoge
:hoge
end
end
EOS
lib.flush
script = Tempfile.new('test.rb')
script.write <<EOS
print Hoge.new.hoge
EOS
script.flush
assert_equal 'hoge', `#{cmd('mruby')} -r #{lib.path} #{script.path}`
assert_equal 0, $?.exitstatus
assert_equal 'hogeClass', `#{cmd('mruby')} -r #{lib.path} -r #{script.path} -e #{shellquote('print Hoge.class')}`
assert_equal 0, $?.exitstatus
end
+2 -2
View File
@@ -5,9 +5,9 @@ MRuby::Gem::Specification.new('mruby-bin-mruby') do |spec|
spec.bins = %w(mruby)
spec.add_dependency('mruby-compiler', :core => 'mruby-compiler')
spec.add_dependency('mruby-error', :core => 'mruby-error')
spec.add_test_dependency('mruby-print', :core => 'mruby-print')
if build.cxx_exception_enabled?
@objs << build.compile_as_cxx("#{spec.dir}/tools/mruby/mruby.c", "#{spec.build_dir}/tools/mruby/mruby.cxx")
@objs.delete_if { |v| v == objfile("#{spec.build_dir}/tools/mruby/mruby") }
build.compile_as_cxx("#{spec.dir}/tools/mruby/mruby.c", "#{spec.build_dir}/tools/mruby/mruby.cxx")
end
end
+60 -7
View File
@@ -27,8 +27,11 @@ struct _args {
mrb_bool mrbfile : 1;
mrb_bool check_syntax : 1;
mrb_bool verbose : 1;
mrb_bool debug : 1;
int argc;
char** argv;
int libc;
char **libv;
};
static void
@@ -38,7 +41,9 @@ usage(const char *name)
"switches:",
"-b load and execute RiteBinary (mrb) file",
"-c check syntax only",
"-d set debugging flags (set $DEBUG to true)",
"-e 'command' one line of script",
"-r library load the library before executing your script",
"-v print version number, then run in verbose mode",
"--verbose run in verbose mode",
"--version print the version",
@@ -52,6 +57,15 @@ usage(const char *name)
printf(" %s\n", *p++);
}
static char *
dup_arg_item(mrb_state *mrb, const char *item)
{
size_t buflen = strlen(item) + 1;
char *buf = (char*)mrb_malloc(mrb, buflen);
memcpy(buf, item, buflen);
return buf;
}
static int
parse_args(mrb_state *mrb, int argc, char **argv, struct _args *args)
{
@@ -78,6 +92,9 @@ parse_args(mrb_state *mrb, int argc, char **argv, struct _args *args)
case 'c':
args->check_syntax = TRUE;
break;
case 'd':
args->debug = TRUE;
break;
case 'e':
if (item[0]) {
goto append_cmdline;
@@ -87,13 +104,7 @@ parse_args(mrb_state *mrb, int argc, char **argv, struct _args *args)
item = argv[0];
append_cmdline:
if (!args->cmdline) {
size_t buflen;
char *buf;
buflen = strlen(item) + 1;
buf = (char *)mrb_malloc(mrb, buflen);
memcpy(buf, item, buflen);
args->cmdline = buf;
args->cmdline = dup_arg_item(mrb, item);
}
else {
size_t cmdlinelen;
@@ -112,6 +123,23 @@ append_cmdline:
return EXIT_SUCCESS;
}
break;
case 'r':
if (!item[0]) {
if (argc <= 1) {
printf("%s: No library specified for -r\n", *origargv);
return EXIT_FAILURE;
}
argc--; argv++;
item = argv[0];
}
if (args->libc == 0) {
args->libv = (char**)mrb_malloc(mrb, sizeof(char*));
}
else {
args->libv = (char**)mrb_realloc(mrb, args->libv, sizeof(char*) * (args->libc + 1));
}
args->libv[args->libc++] = dup_arg_item(mrb, item);
break;
case 'v':
if (!args->verbose) mrb_show_version(mrb);
args->verbose = TRUE;
@@ -162,6 +190,12 @@ cleanup(mrb_state *mrb, struct _args *args)
if (!args->fname)
mrb_free(mrb, args->cmdline);
mrb_free(mrb, args->argv);
if (args->libc) {
while (args->libc--) {
mrb_free(mrb, args->libv[args->libc]);
}
mrb_free(mrb, args->libv);
}
mrb_close(mrb);
}
@@ -199,6 +233,7 @@ main(int argc, char **argv)
}
}
mrb_define_global_const(mrb, "ARGV", ARGV);
mrb_gv_set(mrb, mrb_intern_lit(mrb, "$DEBUG"), mrb_bool_value(args.debug));
c = mrbc_context_new(mrb);
if (args.verbose)
@@ -219,6 +254,24 @@ main(int argc, char **argv)
mrb_gv_set(mrb, zero_sym, mrb_str_new_lit(mrb, "-e"));
}
/* Load libraries */
for (i = 0; i < args.libc; i++) {
FILE *lfp = fopen(args.libv[i], args.mrbfile ? "rb" : "r");
if (lfp == NULL) {
printf("Cannot open library file: %s\n", args.libv[i]);
mrbc_context_free(mrb, c);
cleanup(mrb, &args);
return EXIT_FAILURE;
}
if (args.mrbfile) {
v = mrb_load_irep_file_cxt(mrb, lfp, c);
}
else {
v = mrb_load_file_cxt(mrb, lfp, c);
}
fclose(lfp);
}
/* Load program */
if (args.mrbfile) {
v = mrb_load_irep_file_cxt(mrb, args.rfp, c);
@@ -67,7 +67,7 @@ EOS
`#{cmd('mruby-strip')} -l #{without_lv.path}`
assert_true without_lv.size < with_lv.size
assert_equal '[:a, :b]', `#{cmd('mruby')} -b #{with_lv.path}`.chomp
assert_equal '[]', `#{cmd('mruby')} -b #{without_lv.path}`.chomp
#
# assert_equal '[:a, :b]', `#{cmd('mruby')} -b #{with_lv.path}`.chomp
# assert_equal '[]', `#{cmd('mruby')} -b #{without_lv.path}`.chomp
end
@@ -12,22 +12,6 @@ struct strip_args {
mrb_bool lvar;
};
static void
irep_remove_lv(mrb_state *mrb, mrb_irep *irep)
{
size_t i;
if (irep->lv) {
mrb_free(mrb, irep->lv);
irep->lv = NULL;
}
for (i = 0; i < irep->rlen; ++i) {
irep_remove_lv(mrb, irep->reps[i]);
}
}
static void
print_usage(const char *f)
{
@@ -99,7 +83,7 @@ strip(mrb_state *mrb, struct strip_args *args)
/* clear lv if --lvar is enabled */
if (args->lvar) {
irep_remove_lv(mrb, irep);
mrb_irep_remove_lv(mrb, irep);
}
wfile = fopen(filename, "wb");
+89
View File
@@ -0,0 +1,89 @@
class Module
##
# call-seq:
# mod < other -> true, false, or nil
#
# Returns true if `mod` is a subclass of `other`. Returns
# <code>nil</code> if there's no relationship between the two.
# (Think of the relationship in terms of the class definition:
# "class A < B" implies "A < B".)
#
def <(other)
if self.equal?(other)
false
else
self <= other
end
end
##
# call-seq:
# mod <= other -> true, false, or nil
#
# Returns true if `mod` is a subclass of `other` or
# is the same as `other`. Returns
# <code>nil</code> if there's no relationship between the two.
# (Think of the relationship in terms of the class definition:
# "class A < B" implies "A < B".)
def <=(other)
raise TypeError, 'compared with non class/module' unless other.is_a?(Module)
if self.ancestors.include?(other)
return true
elsif other.ancestors.include?(self)
return false
end
end
##
# call-seq:
# mod > other -> true, false, or nil
#
# Returns true if `mod` is an ancestor of `other`. Returns
# <code>nil</code> if there's no relationship between the two.
# (Think of the relationship in terms of the class definition:
# "class A < B" implies "B > A".)
#
def >(other)
if self.equal?(other)
false
else
self >= other
end
end
##
# call-seq:
# mod >= other -> true, false, or nil
#
# Returns true if `mod` is an ancestor of `other`, or the
# two modules are the same. Returns
# <code>nil</code> if there's no relationship between the two.
# (Think of the relationship in terms of the class definition:
# "class A < B" implies "B > A".)
#
def >=(other)
raise TypeError, 'compared with non class/module' unless other.is_a?(Module)
return other < self
end
##
# call-seq:
# module <=> other_module -> -1, 0, +1, or nil
#
# Comparison---Returns -1, 0, +1 or nil depending on whether `module`
# includes `other_module`, they are the same, or if `module` is included by
# `other_module`.
#
# Returns `nil` if `module` has no relationship with `other_module`, if
# `other_module` is not a module, or if the two values are incomparable.
#
def <=>(other)
return 0 if self.equal?(other)
return nil unless other.is_a?(Module)
cmp = self < other
return -1 if cmp
return 1 unless cmp.nil?
return nil
end
end
+45
View File
@@ -9,12 +9,57 @@ mrb_mod_name(mrb_state *mrb, mrb_value self)
return mrb_nil_p(name)? name : mrb_str_dup(mrb, name);
}
static mrb_value
mrb_mod_singleton_class_p(mrb_state *mrb, mrb_value self)
{
return mrb_bool_value(mrb_type(self) == MRB_TT_SCLASS);
}
/*
* call-seq:
* module_exec(arg...) {|var...| block } -> obj
* class_exec(arg...) {|var...| block } -> obj
*
* Evaluates the given block in the context of the
* class/module. The method defined in the block will belong
* to the receiver. Any arguments passed to the method will be
* passed to the block. This can be used if the block needs to
* access instance variables.
*
* class Thing
* end
* Thing.class_exec{
* def hello() "Hello there!" end
* }
* puts Thing.new.hello()
*/
static mrb_value
mrb_mod_module_exec(mrb_state *mrb, mrb_value self)
{
const mrb_value *argv;
mrb_int argc;
mrb_value blk;
mrb_get_args(mrb, "*&", &argv, &argc, &blk);
if (mrb_nil_p(blk)) {
mrb_raise(mrb, E_ARGUMENT_ERROR, "no block given");
}
mrb->c->ci->target_class = mrb_class_ptr(self);
return mrb_yield_cont(mrb, blk, self, argc, argv);
}
void
mrb_mruby_class_ext_gem_init(mrb_state *mrb)
{
struct RClass *mod = mrb->module_class;
mrb_define_method(mrb, mod, "name", mrb_mod_name, MRB_ARGS_NONE());
mrb_define_method(mrb, mod, "singleton_class?", mrb_mod_singleton_class_p, MRB_ARGS_NONE());
mrb_define_method(mrb, mod, "module_exec", mrb_mod_module_exec, MRB_ARGS_ANY()|MRB_ARGS_BLOCK());
mrb_define_method(mrb, mod, "class_exec", mrb_mod_module_exec, MRB_ARGS_ANY()|MRB_ARGS_BLOCK());
}
void
+105 -6
View File
@@ -1,10 +1,109 @@
assert 'Module#<' do
a = Class.new
b = Class.new(a)
c = Class.new(a)
d = Module.new
e = Class.new { include d }
f = Module.new { include d }
# compare class to class
assert_true b < a
assert_false b < b
assert_false a < b
assert_nil c < b
# compare class to module
assert_true e < d
assert_false d < e
assert_nil a < d
# compare module to module
assert_true f < d
assert_false f < f
assert_false d < f
assert_raise(TypeError) { a < Object.new }
end
assert 'Module#<=' do
a = Class.new
b = Class.new(a)
c = Class.new(a)
d = Module.new
e = Class.new { include d }
f = Module.new { include d }
# compare class to class
assert_true b <= a
assert_true b <= b
assert_false a <= b
assert_nil c <= b
# compare class to module
assert_true e <= d
assert_false d <= e
assert_nil a <= d
# compare module to module
assert_true f <= d
assert_true f <= f
assert_false d <= f
assert_raise(TypeError) { a <= Object.new }
end
assert 'Module#name' do
module A
class B
end
module Outer
class Inner; end
const_set :SetInner, Class.new
end
assert_nil A::B.singleton_class.name
assert_equal 'Fixnum', Fixnum.name
assert_equal 'A::B', A::B.name
assert_equal 'Outer', Outer.name
assert_equal 'Outer::Inner', Outer::Inner.name
assert_equal 'Outer::SetInner', Outer::SetInner.name
outer = Module.new do
const_set :SetInner, Class.new
end
Object.const_set :SetOuter, outer
assert_equal 'SetOuter', SetOuter.name
assert_equal 'SetOuter::SetInner', SetOuter::SetInner.name
mod = Module.new
cls = Class.new
assert_nil mod.name
assert_nil cls.name
end
assert 'Module#singleton_class?' do
mod = Module.new
cls = Class.new
scl = (class <<cls; self; end)
assert_false mod.singleton_class?
assert_false cls.singleton_class?
assert_true scl.singleton_class?
end
assert 'Module#module_eval' do
mod = Module.new
mod.class_exec(1,2,3) do |a,b,c|
assert_equal([1,2,3], [a,b,c])
def hi
"hi"
end
end
cls = Class.new
cls.class_exec(42) do |x|
assert_equal(42, x)
include mod
def hello
"hello"
end
end
obj = cls.new
assert_equal("hi", obj.hi)
assert_equal("hello", obj.hello)
end
+5
View File
@@ -0,0 +1,5 @@
MRuby::Gem::Specification.new('mruby-compar-ext') do |spec|
spec.license = 'MIT'
spec.author = 'mruby developers'
spec.summary = 'Enumerable module extension'
end
+31
View File
@@ -0,0 +1,31 @@
module Comparable
##
# Returns <i>min</i> if <i>obj</i> <code><=></code> <i>min</i> is less
# than zero, <i>max</i> if <i>obj</i> <code><=></code> <i>max</i> is
# greater than zero and <i>obj</i> otherwise.
#
# 12.clamp(0, 100) #=> 12
# 523.clamp(0, 100) #=> 100
# -3.123.clamp(0, 100) #=> 0
#
# 'd'.clamp('a', 'f') #=> 'd'
# 'z'.clamp('a', 'f') #=> 'f'
#
def clamp(min, max)
if (min <=> max) > 0
raise ArgumentError, "min argument must be smaller than max argument"
end
c = self <=> min
if c == 0
return self
elsif c < 0
return min
end
c = self <=> max
if c > 0
return max
else
return self
end
end
end
File diff suppressed because it is too large Load Diff
+5 -6
View File
@@ -52,7 +52,7 @@ inline
#endif
#endif
static unsigned int
hash (register const char *str, register unsigned int len)
hash (const char *str, unsigned int len)
{
static const unsigned char asso_values[] =
{
@@ -83,7 +83,7 @@ hash (register const char *str, register unsigned int len)
51, 51, 51, 51, 51, 51, 51, 51, 51, 51,
51, 51, 51, 51, 51, 51
};
register int hval = len;
int hval = len;
switch (hval)
{
@@ -105,7 +105,7 @@ __attribute__ ((__gnu_inline__))
#endif
#endif
const struct kwtable *
mrb_reserved_word (register const char *str, register unsigned int len)
mrb_reserved_word (const char *str, unsigned int len)
{
static const struct kwtable wordlist[] =
{
@@ -196,11 +196,11 @@ mrb_reserved_word (register const char *str, register unsigned int len)
if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH)
{
register int key = hash (str, len);
int key = hash (str, len);
if (key <= MAX_HASH_VALUE && key >= 0)
{
register const char *s = wordlist[key].name;
const char *s = wordlist[key].name;
if (*str == *s && !strcmp (str + 1, s + 1))
return &wordlist[key];
@@ -209,4 +209,3 @@ mrb_reserved_word (register const char *str, register unsigned int len)
return 0;
}
#line 50 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
+4 -20
View File
@@ -9,14 +9,11 @@
enum node_type {
NODE_METHOD,
NODE_FBODY,
NODE_CFUNC,
NODE_SCOPE,
NODE_BLOCK,
NODE_IF,
NODE_CASE,
NODE_WHEN,
NODE_OPT_N,
NODE_WHILE,
NODE_UNTIL,
NODE_ITER,
@@ -40,12 +37,12 @@ enum node_type {
NODE_CALL,
NODE_SCALL,
NODE_FCALL,
NODE_VCALL,
NODE_SUPER,
NODE_ZSUPER,
NODE_ARRAY,
NODE_ZARRAY,
NODE_HASH,
NODE_KW_HASH,
NODE_RETURN,
NODE_YIELD,
NODE_LVAR,
@@ -57,8 +54,6 @@ enum node_type {
NODE_NTH_REF,
NODE_BACK_REF,
NODE_MATCH,
NODE_MATCH2,
NODE_MATCH3,
NODE_INT,
NODE_FLOAT,
NODE_NEGATE,
@@ -71,10 +66,10 @@ enum node_type {
NODE_REGX,
NODE_DREGX,
NODE_DREGX_ONCE,
NODE_LIST,
NODE_ARG,
NODE_ARGSCAT,
NODE_ARGSPUSH,
NODE_ARGS_TAIL,
NODE_KW_ARG,
NODE_KW_REST_ARGS,
NODE_SPLAT,
NODE_TO_ARY,
NODE_SVALUE,
@@ -88,26 +83,15 @@ enum node_type {
NODE_SCLASS,
NODE_COLON2,
NODE_COLON3,
NODE_CREF,
NODE_DOT2,
NODE_DOT3,
NODE_FLIP2,
NODE_FLIP3,
NODE_ATTRSET,
NODE_SELF,
NODE_NIL,
NODE_TRUE,
NODE_FALSE,
NODE_DEFINED,
NODE_NEWLINE,
NODE_POSTEXE,
NODE_ALLOCA,
NODE_DMETHOD,
NODE_BMETHOD,
NODE_MEMO,
NODE_IFUNC,
NODE_DSYM,
NODE_ATTRASGN,
NODE_HEREDOC,
NODE_LITERAL_DELIM,
NODE_WORDS,
File diff suppressed because it is too large Load Diff
+3 -3
View File
@@ -23,10 +23,10 @@ MRuby::Gem::Specification.new 'mruby-compiler' do |spec|
cc.run t.name, t.prerequisites.first, [], ["#{current_dir}/core"]
end
end
file objfile("#{current_build_dir}/core/y.tab") => lex_def
# Parser
file "#{current_build_dir}/core/y.tab.c" => ["#{current_dir}/core/parse.y"] do |t|
file "#{current_build_dir}/core/y.tab.c" => ["#{current_dir}/core/parse.y", lex_def] do |t|
FileUtils.mkdir_p File.dirname t.name
yacc.run t.name, t.prerequisites.first
end
@@ -35,6 +35,6 @@ MRuby::Gem::Specification.new 'mruby-compiler' do |spec|
gperf.run t.name, t.prerequisites.first
end
file libfile("#{build.build_dir}/lib/libmruby_core") => core_objs
file build.libmruby_core_static => core_objs
build.libmruby << core_objs
end
+6
View File
@@ -0,0 +1,6 @@
MRuby::Gem::Specification.new('mruby-enum-chain') do |spec|
spec.license = 'MIT'
spec.author = 'mruby developers'
spec.summary = 'Enumerator::Chain class'
spec.add_dependency('mruby-enumerator', :core => 'mruby-enumerator')
end

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