Compare commits

...

1415 Commits

Author SHA1 Message Date
Hiroshi Mimaki b6b9c57f24 Update version to 2.1.2. (mruby 2.1.2 RC) 2020-07-01 16:49:21 +09:00
Hiroshi Mimaki aa578c346d Revert "Free the original pointer if realloc failed."
This reverts commit 9cdf439db5.
2020-06-30 18:33:47 +09:00
Yukihiro "Matz" Matsumoto ac8360003e Fix the bug that mrbc generates a.rb.mrb instead of a.mrb.
The bug was introduced by 9dfe50f1d.
2020-06-29 07:25:03 +09:00
Yukihiro "Matz" Matsumoto 233cb49903 Remove unnecessary stack adjustment in OP_CALL. 2020-06-25 06:57:43 +09:00
Yukihiro "Matz" Matsumoto 9cdf439db5 Free the original pointer if realloc failed.
The POSIX `realloc` keep the original pointer untouched, so it can
easily leads to memory leakage. `mrb_realloc()` should handle those
bookkeeping, while `mrb_realloc_simple()` keeps the original `realloc`
behavior.
2020-06-25 06:57:43 +09:00
Yukihiro "Matz" Matsumoto 95360a17f2 Remove unnecessary break from numeric.c. 2020-06-25 06:57:42 +09:00
Yukihiro "Matz" Matsumoto 9dfe50f1d9 Use snprintf instead of memcpy in mrbc.c. 2020-06-25 06:57:42 +09:00
Yukihiro "Matz" Matsumoto c07f24cd18 Change flag names in preparation of REnv refactoring. 2020-06-25 06:57:41 +09:00
Yukihiro "Matz" Matsumoto 03c2b8656b Use mrb_get_argc() to improve performance. 2020-06-25 06:57:41 +09:00
Yukihiro "Matz" Matsumoto ea6e1b003c Create codeql-analysis.yml 2020-06-23 12:36:20 +09:00
Yukihiro "Matz" Matsumoto c2b37e76b3 Skip mrb_get_args() in mrb_ary_{aget,aset} unless necessary.
Use simpler `mrb_get_argc()` and `mrb_get_arg1()` instead.
2020-06-22 21:47:23 +09:00
Yukihiro "Matz" Matsumoto d40b922c98 Fix potential buffer overflow in sprintf.c. 2020-06-20 18:56:33 +09:00
Yukihiro "Matz" Matsumoto 28e793496a Support integer and float combination in mrb_equal(). 2020-06-20 18:56:05 +09:00
Yukihiro "Matz" Matsumoto 33c8d6af1e Move definition of BasicObject#!= to mrblib.
C implementation used `mrb_funcall()` that bypassed many optimization.
2020-06-20 14:09:23 +09:00
Yukihiro "Matz" Matsumoto 49ae2a69f2 Add mrb_get_arg1() that retrieves single (and only) argument.
`mrb_get_arg1()` raises `ArgumentError` if the method does not receive one
argument.

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

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

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

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

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

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

    Fix invalid pointer free inside other heap's block

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

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

    Fix memory leak for temporary symbols when out of memory

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

    Fix uninitialized pointer dereference for debug section

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

    Fix memory leak for temporary filenames when out of memory

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

    Fix memory leak for irep when out of memory

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

    Fix uninitialized pointer dereference when do not finished initializing irep

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

    Fix NULL pointer dereference when do not finished initializing irep

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

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

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

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

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

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

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

    Fix keep wrong symbol index when out of memory

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

    Fix keep wrong symbol capacity when out of memory

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

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

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

    Fix protect exception for print error message

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

    Protect exception for mruby core initialization

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

    Fix memory leak for string object when out of memory

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

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

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

    Fix stack overflow when out of memory

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

    Detailes:

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

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

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

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

    Add internal functions (not `static`):

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

  ```ruby
  def a
    "Safe!"
  end

  a = "Auto!"

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

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

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

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

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

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

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

  class B < A; end

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

#### Before this patch:

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

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

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

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

no patched:

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

### Example

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

#### Before this patch:

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

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

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

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

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

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

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

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

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

Before this patch:

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

After this patch:

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

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

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

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

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

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

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

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

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

In any case, you can disable it by defining
`MRB_WITHOUT_IO_PREAD_PWRITE`.
2020-02-02 21:20:25 +09:00
Yukihiro "Matz" Matsumoto 3c67d9b1c0 Merge pull request #4938 from dearblue/socket-mingw
Fix builds for old mingw in mruby-socket; ref #4914
2020-02-01 17:41:19 +09:00
dearblue 8020374d6b Fix builds for old mingw in mruby-socket; ref #4914 2020-02-01 15:58:32 +09:00
Yukihiro "Matz" Matsumoto db64bd42d3 Add explicit casting in file.c to silence warnings. 2020-01-31 09:26:45 +09:00
Yukihiro "Matz" Matsumoto 724c90f369 Avoid casting warning from mrb_int to int in io.c. 2020-01-31 09:26:05 +09:00
Yukihiro "Matz" Matsumoto c0a6439a69 Avoid implicit integer casting in backtrace.c and hash.c. 2020-01-31 09:25:10 +09:00
Yukihiro "Matz" Matsumoto 10c2b7ee1c Remove unnecessary use of uint16_t in symbol.c. 2020-01-31 09:22:27 +09:00
Yukihiro "Matz" Matsumoto f34623fb03 Fix arena index type from mrb_int to just int. 2020-01-30 17:35:50 +09:00
Yukihiro "Matz" Matsumoto c8f4d72302 Move fallback definitions of FLT_EPSILON etc. after #include <mruby/value.h>
that includes `float.h`. It allows definitions from native headers.
2020-01-30 17:16:12 +09:00
Yukihiro "Matz" Matsumoto 7771c215e4 Removed junk.
My cat stepped on the keyboard at the last moment before the commit.
2020-01-29 10:23:31 +09:00
Yukihiro "Matz" Matsumoto ff5d1914ab Remove unused local variable mid; ref #4936 2020-01-29 08:56:05 +09:00
Yukihiro "Matz" Matsumoto e7e999414c Merge pull request #4873 from dearblue/open-flags
Support bit flags for `IO.open`
2020-01-28 11:09:33 +09:00
David Siaw 36efc33650 include time.h for ios 2020-01-28 00:43:49 +08:00
Yukihiro "Matz" Matsumoto 364c47610f Fixed backtrace message for top-level blocks; fix #4936
In top-level, `mid` is `NULL`. We used to ignore 'mid` update for `NULL`.
2020-01-27 14:34:54 +09:00
Yukihiro "Matz" Matsumoto 59464f3528 Merge pull request #4935 from mimaki/delete-duplicated-Array-delete_if
Delete duplicated `Array#delete_if`.
2020-01-21 13:40:30 +09:00
Hiroshi Mimaki 7d9a49efab Delete duplicated Array#delete_if test. 2020-01-21 12:50:26 +09:00
Hiroshi Mimaki e24b4a1e19 Delete duplicated Array#delete_if. 2020-01-21 11:35:53 +09:00
Yukihiro "Matz" Matsumoto f7abda1437 Remove debug target from travis_config.rb. 2020-01-15 23:39:19 +09:00
Yukihiro "Matz" Matsumoto ff57c0278f Remove broken MRB_INT16 configuration option. 2020-01-15 21:32:00 +09:00
Yukihiro "Matz" Matsumoto 2742ded32f Fixed wrong condition in #4926 fix. 2020-01-10 23:05:27 +09:00
Yukihiro "Matz" Matsumoto 70e5746896 Fixed wrong condition for copying arguments on stack; fix #4926
This bug was introduced in 694089f to address #4832
2020-01-10 17:58:15 +09:00
Yukihiro "Matz" Matsumoto fc8fb41451 Small refactoring in hash_slice; ref #4926 2020-01-10 17:57:33 +09:00
Yukihiro "Matz" Matsumoto dc86e35cac Add MRB_WITHOUT_FLOAT guard to <math.h>. 2020-01-08 10:53:11 +09:00
Yukihiro "Matz" Matsumoto 2124b9b4c9 Fix buffer overflow in mrb_str_len_to_dbl.
Issue 19902: mruby:mruby_fuzzer: Stack-buffer-overflow in mrb_str_len_to_dbl
2020-01-08 10:52:24 +09:00
Yukihiro "Matz" Matsumoto dbba0ca517 p->locals may be NULL when error occurs before the point.
This is reported by oss-fuzz:
Issue 19886: mruby:mruby_fuzzer: Potential-null-reference in setup_numparams
2020-01-08 01:18:53 +09:00
Yukihiro "Matz" Matsumoto afad939173 Check memory boundary in mrb_str_len_to_dbl. 2020-01-07 08:58:06 +09:00
Yukihiro "Matz" Matsumoto 3e4e10ffb6 "0x10".to_f should be 0, not 16.0; fix #4924 2020-01-06 22:27:39 +09:00
Yukihiro "Matz" Matsumoto c60bccaa94 Check remaining string length before access to avoid OOB access. 2020-01-06 22:25:47 +09:00
Yukihiro "Matz" Matsumoto 59756aef14 Need to preserve the original input string in mrb_str_len_to_dbl. 2020-01-06 22:25:05 +09:00
Yukihiro "Matz" Matsumoto 874797f36f Merge branch 'dearblue-file-size-truncate' 2020-01-06 18:58:42 +09:00
Yukihiro "Matz" Matsumoto b545f62aeb Avoid Boxing/Unboxing of file descriptors; ref #4872 2020-01-06 18:57:43 +09:00
Yukihiro "Matz" Matsumoto ca71eb7eef Merge branch 'file-size-truncate' of https://github.com/dearblue/mruby into dearblue-file-size-truncate 2020-01-06 18:49:52 +09:00
Yukihiro "Matz" Matsumoto ccf28775b8 Fix mrb_str_len_to_dbl to support Hexadecimal like 0x10. 2020-01-06 15:52:39 +09:00
Yukihiro "Matz" Matsumoto 2532e625ed Refactor mrb_cstr_to_dbl; ref #4920 2020-01-06 15:52:39 +09:00
Yukihiro "Matz" Matsumoto 111045ecad Avoid creating temporary objects in read_irep_record_1; close #4920
The basic idea of this change is from @dearblue.

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

#### Example:

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

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

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

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

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

#### Cause

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

#### Treatment

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

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

#### After this patch:

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

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

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

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

#### After this patch:

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

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

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

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

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

### Example

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

#### Before this patch:

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

#### After this patch:

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

### Example

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

#### Before this patch:

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

#### After this patch:

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

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

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

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

#### After this patch:

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

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

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

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

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

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

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

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

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

Before this patch:

  "1_2__3".to_f      #=> 123

After this patch:

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

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

#### After this patch:

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

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

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

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

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

#### Before this patch:

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

#### After this patch:

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

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

#### After this patch:

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

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

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

#### After this patch:

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

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

#### After this patch:

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

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

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

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

#### After this patch:

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

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

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

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

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

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

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

#### Before this patch:

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

#### After this patch:

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

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

#### Before this patch:

  ```
  1
  3
  ```

#### After this patch:

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

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

#### After this patch:

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

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

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

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

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

#### After this patch:

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

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

#### After this patch:

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

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

#### After this patch:

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

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

#### After this patch:

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

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

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

```
module Mod1
  class << Object.new

    C = 1
    @@cv = 1

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

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

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

After this patch:

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

Reduction of object code can be expected.

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

- Prepare file:

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

- Before patched:

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

- After patched:

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

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

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

#### Before this patch:

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

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

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

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

After this patch (same as Ruby):

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

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

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

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

The reasons are as follows:

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

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

    __attribute__((visibility(default)))

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

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

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

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

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

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

NOTE:

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

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

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

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

  %[modifier]specifier

Modifiers:

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

Specifiers:

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

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

== Example:

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

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

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

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

  === Before this patch:

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

  === After this patch:

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

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

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

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

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

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

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

before this patch:

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

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

So add encoding argument according to Ruby.

after this patch:

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

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

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

After this patch (same as Ruby):

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

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

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

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

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

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

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

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

It is also very slow. This code hangs unnecessarily:

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

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

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

After this patch (same as Ruby):

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

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

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

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

Incompatibility:

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

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

  Before this patch:

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

  After this patch (same as Ruby):

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

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

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

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

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

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

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

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

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

After this patch (same as Ruby):

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

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

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

After this patch:

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

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

After this patch:

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

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

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

This PR divides into four profiles.

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

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

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

How to reproduce:

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

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

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

Example:

  Before this patch:

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

  After this patch:

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

Implementation:

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

Before this patch:

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

After this patch:

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

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

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

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

After this patch / Ruby:

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

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

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

After this patch / Ruby:

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

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

Cause:

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

Treatment:

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

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

    Object.const_set :A, Module.new{const_set :B, Class.new}
    ab = A::B.to_s
    p ab         #=> "A::B" # Good
    ab[0] = "x"
    p A::B.to_s  #=> "x::B" # Bad
2019-04-01 20:12:43 +09:00
KOBAYASHI Shuji 465fdde52d Enumerator#size is not supported [ci skip] 2019-01-31 21:25:35 +09:00
take-cheeze b6850f88a1 Support lock file for git. 2018-12-06 11:47:17 +09:00
Bhargava Shastry 05b4eaac4b ossfuzz: Moved config related files to a namesake directory under ossfuzz 2018-12-05 18:06:30 +01:00
Bhargava Shastry bccf9e4a3f ossfuzz: Add fuzzing dictionary for mruby. 2018-12-05 18:00:47 +01:00
Bhargava Shastry 1d1b47044c ossfuzz: Add simple mruby compile test harness 2018-12-05 17:45:27 +01:00
Ichito Nagata 2af92d0ebc Let inspect recursion do the right thing 2018-06-04 11:25:10 +09:00
279 changed files with 30092 additions and 8912 deletions
+106
View File
@@ -0,0 +1,106 @@
name: Build & Test
on: [push, pull_request]
jobs:
Ubuntu-1604:
runs-on: ubuntu-16.04
steps:
- uses: actions/checkout@v1
- name: apt
run: sudo apt install ruby gperf
- name: build and test
run: rake -m -j4 all test
env:
MRUBY_CONFIG: travis_config.rb
Ubuntu-1804-gcc:
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v1
- name: apt
run: sudo apt install ruby gperf gcc g++
- name: build and test
run: rake -m -j4 all test
env:
MRUBY_CONFIG: travis_config.rb
CC: gcc
CXX: g++
Ubuntu-1804-clang:
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v1
- name: apt
run: sudo apt install ruby gperf
- name: build and test
run: rake -m -j4 all test
env:
MRUBY_CONFIG: travis_config.rb
CC: clang
CXX: clang++
macOS:
runs-on: macos-latest
steps:
- uses: actions/checkout@v1
- name: brew
run: brew install ruby gperf
- name: build and test
run: rake -m -j4 all test
env:
MRUBY_CONFIG: travis_config.rb
Windows-MinGW:
runs-on: windows-latest
steps:
- uses: actions/checkout@v1
- name: chocolatey
run: choco install -y ruby gperf
- name: build and test
run: rake -E '$stdout.sync=true' -j4 test
env:
MRUBY_CONFIG: travis_config.rb
CFLAGS: -g -O1 -Wall -Wundef
Windows-Cygwin:
runs-on: windows-latest
steps:
- uses: actions/checkout@v1
- uses: actions/cache@v1
with:
path: C:\Users\runneradmin\AppData\Local\Temp\chocolatey
key: ${{ runner.os }}-cygwin-chocolatey-${{ matrix.os }}-${{ github.sha }}
restore-keys: |
${{ runner.os }}-cygwin-chocolatey-${{ matrix.os }}-
${{ runner.os }}-cygwin-chocolatey-
- name: chocolatey
run: choco install -y cygwin
- name: Install cygwin packages
shell: cmd
run: C:\tools\cygwin\cygwinsetup.exe -qgnNdO -R C:/tools/cygwin -l C:/tools/cygwin/package -s http://mirrors.kernel.org/sourceware/cygwin/ -P gcc-core,gcc-g++,make,gperf,ruby
- name: Set ENV
run: |
echo '::set-env name=PATH::C:\tools\cygwin\bin;C:\tools\cygwin\usr\bin'
- name: build and test
shell: cmd
run: C:\tools\cygwin\bin\ruby.exe /usr/bin/rake -m -j4 -E 'STDOUT.sync=true' test
env:
MRUBY_CONFIG: travis_config.rb
Windows-VC:
runs-on: windows-latest
steps:
- uses: actions/checkout@v1
- name: chocolatey
run: choco install -y ruby gperf
- name: build and test
shell: cmd
run: |
call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\Build\vcvars64.bat"
rake -E "STDOUT.sync=true" -m -j4 test
env:
MRUBY_CONFIG: appveyor_config.rb
# TODO(take-cheeze): Re-enable /O2
CFLAGS: "/c /nologo /W3 /we4013 /Zi /MD /D_CRT_SECURE_NO_WARNINGS"
CXXFLAGS: "/c /nologo /W3 /Zi /MD /EHs /D_CRT_SECURE_NO_WARNINGS"
+51
View File
@@ -0,0 +1,51 @@
name: "Code scanning - action"
on:
push:
pull_request:
schedule:
- cron: '0 19 * * 4'
jobs:
CodeQL-Build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
with:
# We must fetch at least the immediate parents so that if this is
# a pull request then we can checkout the head.
fetch-depth: 2
# If this run was triggered by a pull request event, then checkout
# the head of the pull request instead of the merge commit.
- run: git checkout HEAD^2
if: ${{ github.event_name == 'pull_request' }}
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
# Override language selection by uncommenting this and choosing your languages
# with:
# languages: go, javascript, csharp, python, cpp, java
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v1
# ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
# and modify them (or add more) to build your code if your project
# uses a compiled language
#- run: |
# make bootstrap
# make release
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
+24
View File
@@ -0,0 +1,24 @@
name: CIFuzz
on: [pull_request]
jobs:
Fuzzing:
runs-on: ubuntu-latest
steps:
- name: Build Fuzzers
uses: google/oss-fuzz/infra/cifuzz/actions/build_fuzzers@master
with:
oss-fuzz-project-name: 'mruby'
dry-run: false
- name: Run Fuzzers
uses: google/oss-fuzz/infra/cifuzz/actions/run_fuzzers@master
with:
oss-fuzz-project-name: 'mruby'
fuzz-seconds: 600
dry-run: false
- name: Upload Crash
uses: actions/upload-artifact@v1
if: failure()
with:
name: artifacts
path: ./out/artifacts
+5 -2
View File
@@ -1,3 +1,4 @@
*.lock
*.bak
*.bc
*.d
@@ -16,6 +17,9 @@
.svn
.vscode
.yardoc
.ccls*
compile_flags.txt
compile_commands.json
cscope.files
cscope.out
tags
@@ -30,5 +34,4 @@ tags
/benchmark/*.png
/doc/api
/src/y.tab.c
/doc/capi
+1601 -401
View File
File diff suppressed because it is too large Load Diff
+6 -14
View File
@@ -1,19 +1,11 @@
language: c
sudo: false
matrix:
include:
- os: linux
sudo: false
- os: osx
osx_image: xcode7.1
addons:
apt:
packages:
- gperf
jobs:
- os: linux
- os: osx
env:
- MRUBY_CONFIG=travis_config.rb
script: "./minirake -j4 all test"
script:
- rake -m && rake test
+1
View File
@@ -42,3 +42,4 @@ of this list.
Masahiro Wakame
YAMAMOTO Masaya
KOBAYASHI Shuji
RIZAL Reckordp
+11 -4
View File
@@ -9,7 +9,7 @@ things in mind before submitting your pull request:
* Work on the latest possible state of **mruby/master**
* Create a branch which is dedicated to your change
* Test your changes before creating a pull request (```./minirake test```)
* Test your changes before creating a pull request (```rake test```)
* If possible write a test case which confirms your change
* Don't mix several features or bug-fixes in one pull request
* Create a meaningful commit message
@@ -33,9 +33,16 @@ mruby should be highly portable to other systems and compilers. For this it is
recommended to keep your code as close as possible to the C99 standard
(http://www.open-std.org/jtc1/sc22/WG14/www/docs/n1256.pdf).
Although we target C99, Visual C++ is also an important target for mruby. For
this reason a declaration of a local variable has to be at the beginning of a
scope block.
Although we target C99, we've heard some compilers in the embedded environment
still requires declarations of local variables to be at the beginning of a
scope. Until we confirm the situation has changed, we use the old-style
variable declaration.
Visual C++ is also an important target for mruby (supported version is 2013 or
later). For this reason features that are not supported by Visual C++ may not
be used (e.g. `%z` of `strftime()`).
NOTE: Old GCC requires `-std=gnu99` option to enable C99 support.
#### Reduce library dependencies to a minimum
+2408
View File
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -1,4 +1,4 @@
Copyright (c) 2019 mruby developers
Copyright (c) 2020 mruby developers
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
+1 -3
View File
@@ -1,8 +1,6 @@
# mruby is using Rake (http://rake.rubyforge.org) as a build tool.
# We provide a minimalistic version called minirake inside of our
# codebase.
RAKE = ruby ./minirake
RAKE = rake
all :
$(RAKE)
+25 -12
View File
@@ -3,7 +3,7 @@
## What is mruby
mruby is the lightweight implementation of the Ruby language complying to (part
of) the [ISO standard][ISO-standard]. Its syntax is Ruby 1.9 compatible.
of) the [ISO standard][ISO-standard]. Its syntax is Ruby 2.x compatible.
mruby can be linked and embedded within your application. We provide the
interpreter program "mruby" and the interactive mruby shell "mirb" as examples.
@@ -17,7 +17,7 @@ of the Ministry of Economy, Trade and Industry of Japan.
## How to get mruby
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 stable version 2.1.2 of mruby can be downloaded via the following URL: [https://github.com/mruby/mruby/archive/2.1.2.zip](https://github.com/mruby/mruby/archive/2.1.2.zip)
The 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)
@@ -30,36 +30,49 @@ You can also install and compile mruby using [ruby-install](https://github.com/p
## mruby home-page
The URL of the mruby home-page is: [http://www.mruby.org](http://www.mruby.org).
The URL of the mruby home-page is: https://mruby.org.
## Mailing list
We don't have a mailing list, but you can use [GitHub issues](https://github.com/mruby/mruby).
We don't have a mailing list, but you can use [GitHub issues](https://github.com/mruby/mruby/issues).
## How to compile and install (mruby and gems)
See the [doc/guides/compile.md](doc/guides/compile.md) file.
See the [compile.md](https://github.com/mruby/mruby/blob/master/doc/guides/compile.md) file.
## Running Tests
To run the tests, execute the following from the project's root directory.
$ make test
$ rake test
Or
Note: `bison` bundled with MacOS is too old to compile `mruby`.
Try `brew install bison` and follow the instuction shown to update
the `$PATH` to compile `mruby`.
$ ruby ./minirake test
## Building documentation
There are two sets of documentation in mruby: the mruby API (generated by yard) and C API (Doxygen)
To build both of them, simply go
rake doc
You can also view them in your browser
rake view_api
rake view_capi
## How to customize mruby (mrbgems)
mruby contains a package manager called *mrbgems*. To create extensions
in C and/or Ruby you should create a *GEM*. For a documentation of how to
use mrbgems consult the file [doc/guides/mrbgems.md](doc/guides/mrbgems.md). For example code of
how to use mrbgems look into the folder *examples/mrbgems/*.
use mrbgems consult the file [mrbgems.md](https://github.com/mruby/mruby/blob/master/doc/guides/mrbgems.md).
For example code of how to use mrbgems look into the folder *examples/mrbgems/*.
## License
mruby is released under the [MIT License](LICENSE).
mruby is released under the [MIT License](https://github.com/mruby/mruby/blob/master/LICENSE).
## Note for License
@@ -88,5 +101,5 @@ file in your pull request.
[ISO-standard]: http://www.iso.org/iso/iso_catalogue/catalogue_tc/catalogue_detail.htm?csnumber=59579
[build-status-img]: https://travis-ci.org/mruby/mruby.svg?branch=master
[contribution-guidelines]: CONTRIBUTING.md
[contribution-guidelines]: https://github.com/mruby/mruby/blob/master/CONTRIBUTING.md
[travis-ci]: https://travis-ci.org/mruby/mruby
+12 -20
View File
@@ -5,12 +5,13 @@ MRUBY_ROOT = File.dirname(File.expand_path(__FILE__))
MRUBY_BUILD_HOST_IS_CYGWIN = RUBY_PLATFORM.include?('cygwin')
MRUBY_BUILD_HOST_IS_OPENBSD = RUBY_PLATFORM.include?('openbsd')
Rake.verbose(false) if Rake.verbose == Rake::DSL::DEFAULT
$LOAD_PATH << File.join(MRUBY_ROOT, "lib")
# load build systems
require "mruby-core-ext"
require "mruby/build"
require "mruby/gem"
# load configuration file
MRUBY_CONFIG = (ENV['MRUBY_CONFIG'] && ENV['MRUBY_CONFIG'] != '') ? ENV['MRUBY_CONFIG'] : "#{MRUBY_ROOT}/build_config.rb"
@@ -31,12 +32,12 @@ load "#{MRUBY_ROOT}/tasks/libmruby.rake"
load "#{MRUBY_ROOT}/tasks/benchmark.rake"
load "#{MRUBY_ROOT}/tasks/gitlab.rake"
load "#{MRUBY_ROOT}/tasks/doc.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
rm_f dst
mkdir_p File.dirname(dst)
cp src, dst
end
##############################
@@ -62,7 +63,7 @@ MRuby.each_target do |target|
relative_from_root = gem.dir.relative_path_from(MRUBY_ROOT)
current_build_dir = File.expand_path "#{build_dir}/#{relative_from_root}"
if current_build_dir !~ /^#{build_dir}/
if current_build_dir !~ /^#{Regexp.escape(build_dir)}/
current_build_dir = "#{build_dir}/mrbgems/#{gem.name}"
end
@@ -118,6 +119,7 @@ task :all => depfiles do
MRuby.each_target do
print_build_summary
end
MRuby::Lockfile.write
end
desc "run all mruby tests"
@@ -143,26 +145,16 @@ end
desc "clean all built and in-repo installed artifacts"
task :clean do
MRuby.each_target do |t|
FileUtils.rm_rf t.build_dir, { :verbose => $verbose }
rm_rf t.build_dir
end
FileUtils.rm_f depfiles, { :verbose => $verbose }
rm_f depfiles
puts "Cleaned up target build folder"
end
desc "clean everything!"
task :deep_clean => ["clean"] do
task :deep_clean => ["clean", "clean_doc"] do
MRuby.each_target do |t|
FileUtils.rm_rf t.gem_clone_dir, { :verbose => $verbose }
rm_rf t.gem_clone_dir
end
puts "Cleaned up mrbgems build folder"
end
desc 'generate document'
task :doc do
begin
sh "mrbdoc"
rescue
puts "ERROR: To generate documents, you should install yard-mruby gem."
puts " $ gem install yard-mruby"
end
end
+9 -12
View File
@@ -4,20 +4,23 @@ os: Visual Studio 2017
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 2017 32bit
- visualcpp: C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat
machine: x86
# Visual Studio 2015 64bit
- visualcpp: C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat
machine: amd64
# Visual Studio 2015 32bit
- visualcpp: C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat
machine: x86
# Visual Studio 2013 64bit
- visualcpp: C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\vcvarsall.bat
machine: amd64
@@ -30,13 +33,7 @@ init:
- 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
- rake -m
- rake -E $stdout.sync=true test
+8 -12
View File
@@ -1,14 +1,7 @@
MRuby::Build.new('debug') do |conf|
toolchain :visualcpp
enable_debug
# include all core GEMs
conf.gembox 'full-core'
conf.compilers.each do |c|
c.defines += %w(MRB_GC_STRESS MRB_GC_FIXED_ARENA MRB_METHOD_CACHE)
end
build_mrbc_exec
def setup_option(conf)
conf.cc.flags[0].delete("/Zi") unless ENV['CFLAGS']
conf.cxx.flags[0].delete("/Zi") unless ENV['CFLAGS'] || ENV['CXXFLAGS']
conf.linker.flags << "/DEBUG:NONE" unless ENV['LDFLAGS']
end
MRuby::Build.new('full-debug') do |conf|
@@ -17,7 +10,8 @@ MRuby::Build.new('full-debug') do |conf|
# include all core GEMs
conf.gembox 'full-core'
conf.cc.defines = %w(MRB_ENABLE_DEBUG_HOOK)
conf.cc.defines += %w(MRB_GC_STRESS MRB_METHOD_CACHE MRB_ENABLE_DEBUG_HOOK)
setup_option(conf)
conf.enable_test
end
@@ -30,6 +24,7 @@ MRuby::Build.new do |conf|
conf.compilers.each do |c|
c.defines += %w(MRB_GC_FIXED_ARENA)
end
setup_option(conf)
conf.enable_bintest
conf.enable_test
end
@@ -41,6 +36,7 @@ MRuby::Build.new('cxx_abi') do |conf|
conf.compilers.each do |c|
c.defines += %w(MRB_GC_FIXED_ARENA)
end
setup_option(conf)
conf.enable_bintest
conf.enable_test
+9 -9
View File
@@ -18,9 +18,9 @@ MRuby::Build.new do |conf|
# end
# conf.gem 'examples/mrbgems/c_and_ruby_extension_example'
# conf.gem :core => 'mruby-eval'
# conf.gem :mgem => 'mruby-io'
# conf.gem :github => 'iij/mruby-io'
# conf.gem :git => 'git@github.com:iij/mruby-io.git', :branch => 'master', :options => '-v'
# conf.gem :mgem => 'mruby-onig-regexp'
# conf.gem :github => 'mattn/mruby-onig-regexp'
# conf.gem :git => 'git@github.com:mattn/mruby-onig-regexp.git', :branch => 'master', :options => '-v'
# include the default GEMs
conf.gembox 'default'
@@ -30,9 +30,9 @@ MRuby::Build.new do |conf|
# cc.flags = [ENV['CFLAGS'] || %w()]
# cc.include_paths = ["#{root}/include"]
# cc.defines = %w()
# cc.option_include_path = '-I%s'
# cc.option_include_path = %q[-I"%s"]
# cc.option_define = '-D%s'
# cc.compile_options = "%{flags} -MMD -o %{outfile} -c %{infile}"
# cc.compile_options = %Q[%{flags} -MMD -o "%{outfile}" -c "%{infile}"]
# end
# mrbc settings
@@ -50,25 +50,25 @@ MRuby::Build.new do |conf|
# linker.library_paths = []
# linker.option_library = '-l%s'
# linker.option_library_path = '-L%s'
# linker.link_options = "%{flags} -o %{outfile} %{objs} %{libs}"
# linker.link_options = "%{flags} -o "%{outfile}" %{objs} %{libs}"
# end
# Archiver settings
# conf.archiver do |archiver|
# archiver.command = ENV['AR'] || 'ar'
# archiver.archive_options = 'rs %{outfile} %{objs}'
# archiver.archive_options = 'rs "%{outfile}" %{objs}'
# end
# Parser generator settings
# conf.yacc do |yacc|
# yacc.command = ENV['YACC'] || 'bison'
# yacc.compile_options = '-o %{outfile} %{infile}'
# yacc.compile_options = %q[-o "%{outfile}" "%{infile}"]
# end
# gperf settings
# conf.gperf do |gperf|
# gperf.command = 'gperf'
# gperf.compile_options = '-L ANSI-C -C -p -j1 -i 1 -g -o -t -N mrb_reserved_word -k"1,3,$" %{infile} > %{outfile}'
# gperf.compile_options = %q[-L ANSI-C -C -p -j1 -i 1 -g -o -t -N mrb_reserved_word -k"1,3,$" "%{infile}" > "%{outfile}"]
# end
# file extensions
+46 -42
View File
@@ -6,11 +6,15 @@ binaries.
## Prerequisites
To compile mruby out of the source code you need the following tools:
* C Compiler (i.e. ```gcc```)
* Linker (i.e. ```gcc```)
* Archive utility (i.e. ```ar```)
* Parser generator (i.e. ```bison```)
* Ruby 1.8 or 1.9 (i.e. ```ruby``` or ```jruby```)
* C Compiler (e.g. `gcc` or `clang`)
* Linker (e.g. `gcc` or `clang`)
* Archive utility (e.g. `ar`)
* Parser generator (e.g. `bison`)
* Ruby 2.0 or later (e.g. `ruby` or `jruby`)
Note that `bison` bundled with MacOS is too old to compile `mruby`.
Try `brew install bison` and follow the instuction shown to update
the `$PATH` to compile `mruby`.
Optional:
* GIT (to update mruby source and integrate mrbgems easier)
@@ -32,10 +36,10 @@ All tools necessary to compile mruby can be set or modified here. In case
you want to maintain an additional *build_config.rb* you can define a
customized path using the *$MRUBY_CONFIG* environment variable.
To compile just call ```./minirake``` inside of the mruby source root. To
generate and execute the test tools call ```./minirake test```. To clean
all build files call ```./minirake clean```. To see full command line on
build, call ```./minirake -v```.
To compile just call `rake` inside of the mruby source root. To
generate and execute the test tools call `rake test`. To clean
all build files call `rake clean`. To see full command line on
build, call `rake -v`.
## Build Configuration
@@ -79,7 +83,7 @@ toolchain :android
```
Requires the custom standalone Android NDK and the toolchain path
in ```ANDROID_STANDALONE_TOOLCHAIN```.
in `ANDROID_STANDALONE_TOOLCHAIN`.
### Binaries
@@ -97,7 +101,7 @@ conf.gem "#{root}/mrbgems/mruby-bin-mirb"
### File Separator
Some environments require a different file separator character. It is possible to
set the character via ```conf.file_separator```.
set the character via `conf.file_separator`.
```ruby
conf.file_separator = '/'
```
@@ -119,7 +123,7 @@ end
C Compiler has header searcher to detect installed library.
If you need a include path of header file use ```search_header_path```:
If you need a include path of header file use `search_header_path`:
```ruby
# Searches ```iconv.h```.
# If found it will return include path of the header file.
@@ -127,7 +131,7 @@ If you need a include path of header file use ```search_header_path```:
fail 'iconv.h not found' unless conf.cc.search_header_path 'iconv.h'
```
If you need a full file name of header file use ```search_header```:
If you need a full file name of header file use `search_header`:
```ruby
# Searches ```iconv.h```.
# If found it will return full path of the header file.
@@ -136,11 +140,11 @@ iconv_h = conf.cc.search_header 'iconv.h'
print "iconv.h found: #{iconv_h}\n"
```
Header searcher uses compiler's ```include_paths``` by default.
Header searcher uses compiler's `include_paths` by default.
When you are using GCC toolchain (including clang toolchain since its base is gcc toolchain)
it will use compiler specific include paths too. (For example ```/usr/local/include```, ```/usr/include```)
it will use compiler specific include paths too. (For example `/usr/local/include`, `/usr/include`)
If you need a special header search paths define a singleton method ```header_search_paths``` to C compiler:
If you need a special header search paths define a singleton method `header_search_paths` to C compiler:
```ruby
def conf.cc.header_search_paths
['/opt/local/include'] + include_paths
@@ -222,7 +226,7 @@ See doc/mrbgems/README.md for more option about mrbgems.
Configuration Mrbtest build process.
If you want mrbtest.a only, You should set ```conf.build_mrbtest_lib_only```
If you want mrbtest.a only, You should set `conf.build_mrbtest_lib_only`
```ruby
conf.build_mrbtest_lib_only
```
@@ -230,9 +234,9 @@ conf.build_mrbtest_lib_only
### Bintest
Tests for mrbgem tools using CRuby.
To have bintests place \*.rb scripts to ```bintest/``` directory of mrbgems.
See ```mruby-bin-*/bintest/*.rb``` if you need examples.
If you want a temporary files use `tempfile` module of CRuby instead of ```/tmp/```.
To have bintests place \*.rb scripts to `bintest/` directory of mrbgems.
See `mruby-bin-*/bintest/*.rb` if you need examples.
If you want a temporary files use `tempfile` module of CRuby instead of `/tmp/`.
You can enable it with following:
```ruby
@@ -247,8 +251,8 @@ correctly. To support mrbgems written in C++, mruby can be
configured to use C++ exception.
There are two levels of C++ exception handling. The one is
```enable_cxx_exception``` that enables C++ exception, but
uses C ABI. The other is ```enable_cxx_abi``` where all
`enable_cxx_exception` that enables C++ exception, but
uses C ABI. The other is `enable_cxx_abi` where all
files are compiled by C++ compiler.
When you mix C++ code, C++ exception would be enabled automatically.
@@ -266,7 +270,7 @@ C++ exception, add following:
conf.disable_cxx_exception
```
and you will get an error when you try to use C++ gem.
Note that it must be called before ```enable_cxx_exception``` or ```gem``` method.
Note that it must be called before `enable_cxx_exception` or `gem` method.
### Debugging mode
@@ -276,17 +280,17 @@ conf.enable_debug
```
When debugging mode is enabled
* Macro ```MRB_DEBUG``` would be defined.
* Which means ```mrb_assert()``` macro is enabled.
* Debug information of irep would be generated by ```mrbc```.
* Because ```-g``` flag would be added to ```mrbc``` runner.
* Macro `MRB_DEBUG` would be defined.
* Which means `mrb_assert()` macro is enabled.
* Debug information of irep would be generated by `mrbc`.
* Because `-g` flag would be added to `mrbc` runner.
* You can have better backtrace of mruby scripts with this.
## Cross-Compilation
mruby can also be cross-compiled from one platform to another. To
achieve this the *build_config.rb* needs to contain an instance of
```MRuby::CrossBuild```. This instance defines the compilation
`MRuby::CrossBuild`. This instance defines the compilation
tools and flags for the target platform. An example could look
like this:
```ruby
@@ -298,12 +302,12 @@ MRuby::CrossBuild.new('32bit') do |conf|
end
```
All configuration options of ```MRuby::Build``` can also be used
in ```MRuby::CrossBuild```.
All configuration options of `MRuby::Build` can also be used
in `MRuby::CrossBuild`.
### Mrbtest in Cross-Compilation
In cross compilation, you can run ```mrbtest``` on emulator if
In cross compilation, you can run `mrbtest` on emulator if
you have it by changing configuration of test runner.
```ruby
conf.test_runner do |t|
@@ -350,15 +354,15 @@ in *build/host/src*)
result will be stored in *build/host/src/y.tab.c*)
* compile *build/host/src/y.tab.c* to *build/host/src/y.tab.o*
* create *build/host/lib/libmruby_core.a* out of all object files (C only)
* create ```build/host/bin/mrbc``` by compiling *tools/mrbc/mrbc.c* and
* create `build/host/bin/mrbc` by compiling *tools/mrbc/mrbc.c* and
linking with *build/host/lib/libmruby_core.a*
* create *build/host/mrblib/mrblib.c* by compiling all \*.rb files
under *mrblib* with ```build/host/bin/mrbc```
under *mrblib* with `build/host/bin/mrbc`
* compile *build/host/mrblib/mrblib.c* to *build/host/mrblib/mrblib.o*
* create *build/host/lib/libmruby.a* out of all object files (C and Ruby)
* create ```build/host/bin/mruby``` by compiling *mrbgems/mruby-bin-mruby/tools/mruby/mruby.c* and
* create `build/host/bin/mruby` by compiling *mrbgems/mruby-bin-mruby/tools/mruby/mruby.c* and
linking with *build/host/lib/libmruby.a*
* create ```build/host/bin/mirb``` by compiling *mrbgems/mruby-bin-mirb/tools/mirb/mirb.c* and
* create `build/host/bin/mirb` by compiling *mrbgems/mruby-bin-mirb/tools/mirb/mirb.c* and
linking with *build/host/lib/libmruby.a*
```
@@ -427,15 +431,15 @@ in *build/i386/src*)
result will be stored in *build/i386/src/y.tab.c*)
* cross-compile *build/i386/src/y.tab.c* to *build/i386/src/y.tab.o*
* create *build/i386/mrblib/mrblib.c* by compiling all \*.rb files
under *mrblib* with the native ```build/host/bin/mrbc```
under *mrblib* with the native `build/host/bin/mrbc`
* cross-compile *build/host/mrblib/mrblib.c* to *build/host/mrblib/mrblib.o*
* create *build/i386/lib/libmruby.a* out of all object files (C and Ruby)
* create ```build/i386/bin/mruby``` by cross-compiling *mrbgems/mruby-bin-mruby/tools/mruby/mruby.c* and
* create `build/i386/bin/mruby` by cross-compiling *mrbgems/mruby-bin-mruby/tools/mruby/mruby.c* and
linking with *build/i386/lib/libmruby.a*
* create ```build/i386/bin/mirb``` by cross-compiling *mrbgems/mruby-bin-mirb/tools/mirb/mirb.c* and
* create `build/i386/bin/mirb` by cross-compiling *mrbgems/mruby-bin-mirb/tools/mirb/mirb.c* and
linking with *build/i386/lib/libmruby.a*
* create *build/i386/lib/libmruby_core.a* out of all object files (C only)
* create ```build/i386/bin/mrbc``` by cross-compiling *tools/mrbc/mrbc.c* and
* create `build/i386/bin/mrbc` by cross-compiling *tools/mrbc/mrbc.c* and
linking with *build/i386/lib/libmruby_core.a*
```
@@ -463,7 +467,7 @@ linking with *build/i386/lib/libmruby_core.a*
### Minimal Library
To build a minimal mruby library you need to use the Cross Compiling
feature due to the reason that there are functions (i.e. stdio) which
feature due to the reason that there are functions (e.g. stdio) which
can't be disabled for the main build.
```ruby
@@ -477,12 +481,12 @@ end
This configuration defines a cross compile build called 'Minimal' which
is using the GCC and compiles for the host machine. It also disables
all usages of stdio and doesn't compile any binaries (i.e. mrbc).
all usages of stdio and doesn't compile any binaries (e.g. mrbc).
## Test Environment
mruby's build process includes a test environment. In case you start the testing
of mruby, a native binary called ```mrbtest``` will be generated and executed.
of mruby, a native binary called `mrbtest` will be generated and executed.
This binary contains all test cases which are defined under *test/t*. In case
of a cross-compilation an additional cross-compiled *mrbtest* binary is
generated. You can copy this binary and run on your target system.
+1 -1
View File
@@ -38,7 +38,7 @@ To confirm mrdb was installed properly, run mrdb with the `--version` option:
```bash
$ mrdb --version
mruby 2.0.1 (2019-4-4)
mruby 2.1.2 (2020-07-10)
```
## 2.2 Basic Operation
+42 -7
View File
@@ -50,15 +50,17 @@ You can use mrbconfs with following ways:
* When defined single precision floating point type(C type `float`) is used as `mrb_float`.
* Else double precision floating point type(C type `double`) is used as `mrb_float`.
`MRB_INT16`
* When defined `int16_t` will be defined as `mrb_int`.
`MRB_WITHOUT_FLOAT`
* When defined removes floating point numbers from mruby.
* It makes mruby easier to handle in "Microcontroller without FPU" and "Kernel Space".
`MRB_INT32`
* When defined, or `MRB_INT64` are not defined on 32-bit CPU mode, `mrb_int` will be defined as `int32_t`.
* Conflicts with `MRB_INT64`.
`MRB_INT64`
* When defined `int64_t` will be defined as `mrb_int`.
* Conflicts with `MRB_INT16`.
* When `MRB_INT16` or `MRB_INT64` isn't defined `int`(most of the times 32-bit integer)
will be defined as `mrb_int`.
* When defined, or `MRB_INT32` are not defined on 64-bit CPU mode, `mrb_int` will be defined as `int64_t`.
* Conflicts with `MRB_INT32`.
## Garbage collector configuration.
@@ -115,7 +117,7 @@ largest value of required alignment.
`MRB_NAN_BOXING`
* If defined represent `mrb_value` in boxed `double`.
* Conflicts with `MRB_USE_FLOAT`.
* Conflicts with `MRB_USE_FLOAT` and `MRB_WITHOUT_FLOAT`.
`MRB_WORD_BOXING`
* If defined represent `mrb_value` as a word.
@@ -126,6 +128,22 @@ largest value of required alignment.
* Default value is `4`.
* Specifies size of each segment in segment list.
## Reduce heap memory configuration.
`MRB_USE_LINK_TIME_RO_DATA_P`
* Only available on ELF platforms.
* If you specify the address of a read-only section when creating a symbol or string, that string will be used as it is.
* Heap memory can be saved.
* Uses `__ehdr_start` and `__init_array_start`.
* It must be `__ehdr_start < data_addr < __init_array_start`.
`MRB_USE_CUSTOM_RO_DATA_P`
* Takes precedence over `MRB_USE_LINK_TIME_RO_DATA_P`.
* Please try if `MRB_USE_LINK_TIME_RO_DATA_P` is not available.
* The `mrb_ro_data_p()` function is implemented by the user in an arbitrary file.
* The prototype declaration is `mrb_bool mrb_ro_data_p(const char *ptr)`.
* Return `TRUE` if `ptr` is in read-only section, otherwise return `FALSE`.
## Other configuration.
`MRB_UTF8_STRING`
* Adds UTF-8 encoding support to character-oriented String instance methods.
@@ -144,3 +162,20 @@ largest value of required alignment.
`MRB_STR_BUF_MIN_SIZE`
* Default value is `128`.
* Specifies initial capacity of `RString` created by `mrb_str_buf_new` function..
`MRB_METHOD_CACHE`
* Improve performance for method dispatch.
`MRB_METHOD_CACHE_SIZE`
* Default value is `128`.
* Ignored if `MRB_METHOD_CACHE` is not defined.
* Need to be the power of 2.
`MRB_METHOD_T_STRUCT`
* Use C struct to represent `mrb_method_t`
* No `MRB_METHOD_T_STRUCT` requires highest 2 bits of function pointers to be zero
* Define this macro on machines that use higher bits of pointers
`MRB_ENABLE_ALL_SYMBOLS`
* Make it available `Symbols.all_symbols` in `mrbgems/mruby-symbol-ext`
* Increase heap memory usage.
+8 -3
View File
@@ -37,11 +37,16 @@ conf.gem :mgem => 'mruby-yaml'
conf.gem :mgem => 'yaml' # 'mruby-' prefix could be omitted
```
For specifying commit hash to checkout use `:checksum_hash` option:
```ruby
conf.gem mgem: 'mruby-redis', checksum_hash: '3446d19fc4a3f9697b5ddbf2a904f301c42f2f4e'
```
If there is missing dependencies, mrbgem dependencies solver will reference
mrbgem from core or mgem-list.
To pull all gems from remote GIT repository on build, call ```./minirake -p```,
or ```./minirake --pull-gems```.
To pull all gems from remote GIT repository on build, call ```rake -p```,
or ```rake --pull-gems```.
NOTE: `:bitbucket` option supports only git. Hg is unsupported in this version.
@@ -230,7 +235,7 @@ So it is recommended not to put GEM's local header files on include/.
These exports are retroactive.
For example: when B depends to C and A depends to B, A will get include paths exported by C.
Exported include_paths are automatically appended to GEM local include_paths by Minirake.
Exported include_paths are automatically appended to GEM local include_paths by rake.
You can use `spec.export_include_paths` accessor if you want more complex build.
+88 -38
View File
@@ -14,17 +14,17 @@ This document does not contain a complete list of limitations.
Please help to improve it by submitting your findings.
## ```1/2``` gives ```0.5```
## `1/2` gives `0.5`
Since mruby does not have ```Bignum```, bigger integers are represented
by ```Float``` numbers. To enhance interoperability between ```Fixnum```
and ```Float```, mruby provides ```Float#upto``` and other iterating
methods for the ```Float``` class. As a side effect, ```1/2``` gives ```0.5```
not ```0```.
Since mruby does not have `Bignum`, bigger integers are represented
by `Float` numbers. To enhance interoperability between `Fixnum`
and `Float`, mruby provides `Float#upto` and other iterating
methods for the `Float` class. As a side effect, `1/2` gives `0.5`
not `0`.
## ```Array``` passed to ```puts```
## `Array` passed to `puts`
Passing an Array to ```puts``` results in different output.
Passing an Array to `puts` results in different output.
```ruby
puts [1,2,3]
@@ -38,15 +38,15 @@ puts [1,2,3]
3
```
#### mruby [2.0.1 (2019-4-4)]
#### mruby [2.1.2 (2020-07-10)]
```
[1, 2, 3]
```
## ```Kernel.raise``` in rescue clause
## `Kernel.raise` in rescue clause
```Kernel.raise``` without arguments does not raise the current exception within
`Kernel.raise` without arguments does not raise the current exception within
a rescue clause.
```ruby
@@ -59,21 +59,21 @@ end
#### Ruby [ruby 2.0.0p645 (2015-04-13 revision 50299)]
```ZeroDivisionError``` is raised.
`ZeroDivisionError` is raised.
#### mruby [2.0.1 (2019-4-4)]
#### mruby [2.1.2 (2020-07-10)]
No exception is raised.
## Fiber execution can't cross C function boundary
mruby's ```Fiber``` is implemented in a similar way to Lua's co-routine. This
mruby's `Fiber` is implemented in a similar way to Lua's co-routine. This
results in the consequence that you can't switch context within C functions.
Only exception is ```mrb_fiber_yield``` at return.
Only exception is `mrb_fiber_yield` at return.
## ```Array``` does not support instance variables
## `Array` does not support instance variables
To reduce memory consumption ```Array``` does not support instance variables.
To reduce memory consumption `Array` does not support instance variables.
```ruby
class Liste < Array
@@ -87,16 +87,16 @@ p Liste.new "foobar"
#### Ruby [ruby 2.0.0p645 (2015-04-13 revision 50299)]
``` [] ```
` [] `
#### mruby [2.0.1 (2019-4-4)]
#### mruby [2.1.2 (2020-07-10)]
```ArgumentError``` is raised.
`ArgumentError` is raised.
## Method visibility
For simplicity reasons no method visibility (public/private/protected) is
supported.
supported. Those methods are defined but they are dummy methods.
```ruby
class VisibleTest
@@ -119,17 +119,53 @@ false
true
```
#### mruby [2.0.1 (2019-4-4)]
#### mruby [2.1.2 (2020-07-10)]
```
true
true
```
## defined?
### Visibility Declaration
The ```defined?``` keyword is considered too complex to be fully
implemented. It is recommended to use ```const_defined?``` and
The declaration form of following visibility methods are not implemented.
* `public`
* `private`
* `protected`
* `module_function`
Especially, `module_function` method is not dummy, but no declaration form.
```
module TestModule
module_function
def test_func
p 'test_func called'
end
test_func
end
p 'ok'
```
#### Ruby [ruby 2.5.5p157 (2019-03-15 revision 67260)]
```
ok
```
#### mruby [2.1.2 (2020-07-10)]
```
test.rb:8: undefined method 'test_func' (NoMethodError)
```
## `defined?`
The `defined?` keyword is considered too complex to be fully
implemented. It is recommended to use `const_defined?` and
other reflection methods instead.
```ruby
@@ -142,11 +178,11 @@ defined?(Foo)
nil
```
#### mruby [2.0.1 (2019-4-4)]
#### mruby [2.1.2 (2020-07-10)]
```NameError``` is raised.
`NameError` is raised.
## ```alias``` on global variables
## `alias` on global variables
Aliasing a global variable works in CRuby but is not part
of the ISO standard.
@@ -157,9 +193,9 @@ alias $a $__a__
#### Ruby [ruby 2.0.0p645 (2015-04-13 revision 50299)]
``` nil ```
` nil `
#### mruby [2.0.1 (2019-4-4)]
#### mruby [2.1.2 (2020-07-10)]
Syntax error
@@ -178,15 +214,15 @@ end
#### Ruby [ruby 2.0.0p645 (2015-04-13 revision 50299)]
```ArgumentError``` is raised.
The re-defined ```+``` operator does not accept any arguments.
`ArgumentError` is raised.
The re-defined `+` operator does not accept any arguments.
#### mruby [2.0.1 (2019-4-4)]
#### mruby [2.1.2 (2020-07-10)]
``` 'ab' ```
` 'ab' `
Behavior of the operator wasn't changed.
## Kernel#binding is not supported
## `Kernel#binding` is not supported
`Kernel#binding` method is not supported.
@@ -197,7 +233,7 @@ $ ruby -e 'puts Proc.new {}.binding'
#<Binding:0x00000e9deabb9950>
```
#### mruby [2.0.1 (2019-4-4)]
#### mruby [2.1.2 (2020-07-10)]
```
$ ./bin/mruby -e 'puts Proc.new {}.binding'
@@ -219,7 +255,7 @@ $ ruby -e 'def m(*r,**k) p [r,k] end; m("a"=>1,:b=>2)'
[[{"a"=>1}], {:b=>2}]
```
#### mruby [mruby 2.0.1]
#### mruby [mruby 2.1.2]
```
$ ./bin/mruby -e 'def m(*r,**k) p [r,k] end; m("a"=>1,:b=>2)'
@@ -238,7 +274,7 @@ 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]
@@ -247,3 +283,17 @@ f(1,[2,3])
```
CRuby gives `[1,2,3,nil]`. mruby raises `NoMethodError` for `b`.
## `nil?` redefinition in conditional expressions
Redefinition of `nil?` is ignored in conditional expressions.
```ruby
a = "a"
def a.nil?
true
end
puts(a.nil? ? "truthy" : "falsy")
```
Ruby outputs `falsy`. mruby outputs `truthy`.
Binary file not shown.

After

Width:  |  Height:  |  Size: 8.4 KiB

+108 -95
View File
@@ -16,7 +16,6 @@ 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
@@ -31,97 +30,111 @@ 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
| Instruction Name | Operand type | Semantics |
|------------------|--------------|--------------------------------------------------------|
| OP_NOP | - | no operation |
| OP_MOVE" | BB | R(a) = R(b) |
| OP_LOADL" | BB | R(a) = Pool(b) |
| OP_LOADI" | BB | R(a) = mrb_int(b) |
| OP_LOADINEG" | BB | R(a) = mrb_int(-b) |
| OP_LOADI__1' | B | R(a) = mrb_int(-1) |
| OP_LOADI_0' | B | R(a) = mrb_int(0) |
| OP_LOADI_1' | B | R(a) = mrb_int(1) |
| OP_LOADI_2' | B | R(a) = mrb_int(2) |
| OP_LOADI_3' | B | R(a) = mrb_int(3) |
| OP_LOADI_4' | B | R(a) = mrb_int(4) |
| OP_LOADI_5' | B | R(a) = mrb_int(5) |
| OP_LOADI_6' | B | R(a) = mrb_int(6) |
| OP_LOADI_7' | B | R(a) = mrb_int(7) |
| OP_LOADI16' | BsS | R(a) = mrb_int(b) |
| OP_LOADSYM" | BB | R(a) = Syms(b) |
| OP_LOADNIL' | B | R(a) = nil |
| OP_LOADSELF' | B | R(a) = self |
| OP_LOADT' | B | R(a) = true |
| OP_LOADF' | B | R(a) = false |
| OP_GETGV" | BB | R(a) = getglobal(Syms(b)) |
| OP_SETGV" | BB | setglobal(Syms(b), R(a)) |
| OP_GETSV" | BB | R(a) = Special[Syms(b)] |
| OP_SETSV" | BB | Special[Syms(b)] = R(a) |
| OP_GETIV" | BB | R(a) = ivget(Syms(b)) |
| OP_SETIV" | BB | ivset(Syms(b),R(a)) |
| OP_GETCV" | BB | R(a) = cvget(Syms(b)) |
| OP_SETCV" | BB | cvset(Syms(b),R(a)) |
| OP_GETCONST" | BB | R(a) = constget(Syms(b)) |
| OP_SETCONST" | BB | constset(Syms(b),R(a)) |
| OP_GETMCNST" | BB | R(a) = R(a)::Syms(b) |
| OP_SETMCNST" | BB | R(a+1)::Syms(b) = R(a) |
| OP_GETUPVAR" | BBB | R(a) = uvget(b,c) |
| OP_SETUPVAR" | BBB | uvset(b,c,R(a)) |
| OP_JMP | S | pc=a |
| OP_JMPIF' | BS | if R(a) pc=b |
| OP_JMPNOT' | BS | if !R(a) pc=b |
| OP_JMPNIL' | BS | if R(a)==nil pc=b |
| OP_ONERR | S | rescue_push(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(b),R(a+1),...,R(a+c),&R(a+c+1)) |
| OP_CALL | - | R(0) = self.call(frame.argc, frame.argv) |
| OP_SUPER" | BB | R(a) = super(R(a+1),... ,R(a+b+1)) |
| OP_ARGARY' | BS | R(a) = argument array (16=5:1:5:1:4) |
| OP_ENTER | W | arg setup according to flags (23=5:5:1:5:5:1:1) |
| OP_KEY_P" | BB | R(a) = kdict.key?(Syms(b)) |
| OP_KEYEND | - | raise unless kdict.empty? |
| OP_KARG" | BB | R(a) = kdict[Syms(b)]; kdict.delete(Syms(b)) |
| OP_RETURN' | B | return R(a) (normal) |
| OP_RETURN_BLK' | B | return R(a) (in-block return) |
| OP_BREAK' | B | break R(a) |
| OP_BLKPUSH' | BS | R(a) = block (16=5:1:5:1:4) |
| OP_ADD' | B | R(a) = R(a)+R(a+1) |
| OP_ADDI" | BB | R(a) = R(a)+mrb_int(b) |
| OP_SUB' | B | R(a) = R(a)-R(a+1) |
| OP_SUBI" | BB | R(a) = R(a)-mrb_int(b) |
| OP_MUL' | B | R(a) = R(a)*R(a+1) |
| OP_DIV' | B | R(a) = R(a)/R(a+1) |
| OP_EQ' | B | R(a) = R(a)==R(a+1) |
| OP_LT' | B | R(a) = R(a)<R(a+1) |
| OP_LE' | B | R(a) = R(a)<=R(a+1) |
| OP_GT' | B | R(a) = R(a)>R(a+1) |
| OP_GE' | B | R(a) = R(a)>=R(a+1) |
| OP_ARRAY" | BB | R(a) = ary_new(R(a),R(a+1)..R(a+b)) |
| OP_ARRAY2" | BBB | R(a) = ary_new(R(b),R(b+1)..R(b+c)) |
| OP_ARYCAT' | B | ary_cat(R(a),R(a+1)) |
| OP_ARYPUSH' | B | ary_push(R(a),R(a+1)) |
| OP_ARYDUP' | B | R(a) = ary_dup(R(a)) |
| OP_AREF" | BBB | R(a) = R(b)[c] |
| OP_ASET" | BBB | R(a)[c] = R(b) |
| OP_APOST" | BBB | *R(a),R(a+1)..R(a+c) = R(a)[b..] |
| OP_INTERN' | B | R(a) = intern(R(a)) |
| OP_STRING" | BB | R(a) = str_dup(Lit(b)) |
| OP_STRCAT' | B | str_cat(R(a),R(a+1)) |
| OP_HASH" | BB | R(a) = hash_new(R(a),R(a+1)..R(a+b)) |
| OP_HASHADD" | BB | R(a) = hash_push(R(a),R(a+1)..R(a+b)) |
| OP_HASHCAT' | B | R(a) = hash_cat(R(a),R(a+1)) |
| OP_LAMBDA" | BB | R(a) = lambda(SEQ[b],OP_L_LAMBDA) |
| OP_BLOCK" | BB | R(a) = lambda(SEQ[b],OP_L_BLOCK) |
| OP_METHOD" | BB | R(a) = lambda(SEQ[b],OP_L_METHOD) |
| OP_RANGE_INC' | B | R(a) = range_new(R(a),R(a+1),FALSE) |
| OP_RANGE_EXC' | B | R(a) = range_new(R(a),R(a+1),TRUE) |
| OP_OCLASS' | B | R(a) = ::Object |
| OP_CLASS" | BB | R(a) = newclass(R(a),Syms(b),R(a+1)) |
| OP_MODULE" | BB | R(a) = newmodule(R(a),Syms(b)) |
| OP_EXEC" | BB | R(a) = blockexec(R(a),SEQ[b]) |
| OP_DEF" | BB | R(a).newmethod(Syms(b),R(a+1)) |
| OP_ALIAS" | BB | alias_method(target_class,Syms(a),Syms(b)) |
| OP_UNDEF' | B | undef_method(target_class,Syms(a)) |
| OP_SCLASS' | B | R(a) = R(a).singleton_class |
| OP_TCLASS' | B | R(a) = target_class |
| OP_DEBUG" | BBB | print a,b,c |
| OP_ERR' | B | raise(LocalJumpError, Lit(a)) |
| OP_EXT1 | - | make 1st operand 16bit |
| OP_EXT2 | - | make 2nd operand 16bit |
| OP_EXT3 | - | make 1st and 2nd operands 16bit |
| OP_STOP | - | stop VM |
|------------------|--------------|--------------------------------------------------------|
+2 -2
View File
@@ -42,7 +42,7 @@ MRuby::CrossBuild.new("ArduinoDue") do |conf|
cc.flags = %w(-g -Os -w -ffunction-sections -fdata-sections -nostdlib --param max-inline-insns-single=500
-Dprintf=iprintf -mcpu=cortex-m3 -DF_CPU=84000000L -DARDUINO=156 -DARDUINO_SAM_DUE -DARDUINO_ARCH_SAM
-D__SAM3X8E__ -mthumb -DUSB_PID=0x003e -DUSB_VID=0x2341 -DUSBCON -DUSB_MANUFACTURER="Unknown" -DUSB_PRODUCT="Arduino Due")
cc.compile_options = "%{flags} -o %{outfile} -c %{infile}"
cc.compile_options = %Q[%{flags} -o "%{outfile}" -c "%{infile}"]
#configuration for low memory environment
cc.defines << %w(MRB_HEAP_PAGE_SIZE=64)
@@ -64,7 +64,7 @@ MRuby::CrossBuild.new("ArduinoDue") do |conf|
conf.archiver do |archiver|
archiver.command = "#{BIN_PATH}/arm-none-eabi-ar"
archiver.archive_options = 'rcs %{outfile} %{objs}'
archiver.archive_options = 'rcs "%{outfile}" %{objs}'
end
#no executables
+2 -2
View File
@@ -32,7 +32,7 @@ MRuby::CrossBuild.new('core2-32-poky-linux') do |conf|
cc.flags = %w(-m32 -march=core2 -mtune=core2 -msse3 -mfpmath=sse -mstackrealign -fno-omit-frame-pointer)
cc.flags << %w(-O2 -pipe -g -feliminate-unused-debug-types)
cc.flags << "--sysroot=#{POKY_EDISON_SYSROOT}"
cc.compile_options = "%{flags} -o %{outfile} -c %{infile}"
cc.compile_options = %Q[%{flags} -o "%{outfile}" -c "%{infile}"]
cc.defines = %w(ENABLE_READLINE)
end
@@ -47,7 +47,7 @@ MRuby::CrossBuild.new('core2-32-poky-linux') do |conf|
conf.archiver do |archiver|
archiver.command = "#{POKY_EDISON_BIN_PATH}/i586-poky-linux-ar"
archiver.archive_options = 'rcs %{outfile} %{objs}'
archiver.archive_options = 'rcs "%{outfile}" %{objs}'
end
conf.linker do |linker|
@@ -39,7 +39,7 @@ MRuby::CrossBuild.new("Galileo") do |conf|
cc.flags = %w(-m32 -march=i586 -c -g -Os -w
-ffunction-sections -fdata-sections -MMD -DARDUINO=153)
cc.flags << "--sysroot=#{GALILEO_SYSROOT}"
cc.compile_options = "%{flags} -o %{outfile} -c %{infile}"
cc.compile_options = %Q[%{flags} -o "%{outfile}" -c "%{infile}"]
end
conf.cxx do |cxx|
@@ -54,7 +54,7 @@ MRuby::CrossBuild.new("Galileo") do |conf|
conf.archiver do |archiver|
archiver.command = "#{GALILEO_BIN_PATH}/i586-poky-linux-uclibc-ar"
archiver.archive_options = 'rcs %{outfile} %{objs}'
archiver.archive_options = 'rcs "%{outfile}" %{objs}'
end
conf.linker do |linker|
+2 -2
View File
@@ -27,7 +27,7 @@ MRuby::CrossBuild.new("RX630") do |conf|
conf.cc do |cc|
cc.command = "#{BIN_PATH}/rx-elf-gcc"
cc.flags = "-Wall -g -O2 -flto -mcpu=rx600 -m64bit-doubles"
cc.compile_options = "%{flags} -o %{outfile} -c %{infile}"
cc.compile_options = %Q[%{flags} -o "%{outfile}" -c "%{infile}"]
#configuration for low memory environment
cc.defines << %w(MRB_USE_FLOAT)
@@ -53,7 +53,7 @@ MRuby::CrossBuild.new("RX630") do |conf|
conf.archiver do |archiver|
archiver.command = "#{BIN_PATH}/rx-elf-ar"
archiver.archive_options = 'rcs %{outfile} %{objs}'
archiver.archive_options = 'rcs "%{outfile}" %{objs}'
end
#no executables
@@ -39,7 +39,7 @@ MRuby::CrossBuild.new("chipKITMax32") do |conf|
cc.flags = %w(-O2 -mno-smart-io -w -ffunction-sections -fdata-sections -g -mdebugger -Wcast-align
-fno-short-double -mprocessor=32MX795F512L -DF_CPU=80000000L -DARDUINO=23 -D_BOARD_MEGA_
-DMPIDEVER=0x01000202 -DMPIDE=23)
cc.compile_options = "%{flags} -o %{outfile} -c %{infile}"
cc.compile_options = %Q[%{flags} -o "%{outfile}" -c "%{infile}"]
#configuration for low memory environment
cc.defines << %w(MRB_HEAP_PAGE_SIZE=64)
@@ -60,7 +60,7 @@ MRuby::CrossBuild.new("chipKITMax32") do |conf|
conf.archiver do |archiver|
archiver.command = "#{PIC32_PATH}/compiler/pic32-tools/bin/pic32-ar"
archiver.archive_options = 'rcs %{outfile} %{objs}'
archiver.archive_options = 'rcs "%{outfile}" %{objs}'
end
#no executables
@@ -0,0 +1,108 @@
MRuby::Build.new do |conf|
# Gets set by the VS command prompts
if ENV['VisualStudioVersion'] || ENV['VSINSTALLDIR']
toolchain :visualcpp
else
toolchain :gcc
end
enable_debug
# Include the default GEMs
conf.gembox 'default'
end
# Cross Compiling configuration for the Sega Dreamcast
# This configuration requires KallistiOS (KOS)
# https://dreamcast.wiki
#
# Tested on GNU/Linux, MinGW-w64/MSYS2, Cygwin, macOS and MinGW/MSYS (see below)
#
MRuby::CrossBuild.new("dreamcast") do |conf|
toolchain :gcc
# Support for DreamSDK (based on MinGW/MSYS)
# To compile mruby with DreamSDK, RubyInstaller for Windows should be installed
DREAMSDK_HOME = ENV["DREAMSDK_HOME"]
MSYS_ROOT = !(DREAMSDK_HOME.nil? || DREAMSDK_HOME.empty?) ? "#{DREAMSDK_HOME}/msys/1.0" : ""
# Setting paths
DREAMCAST_PATH = "#{MSYS_ROOT}/opt/toolchains/dc"
KOS_PATH = "#{DREAMCAST_PATH}/kos"
BIN_PATH = "#{DREAMCAST_PATH}/sh-elf/bin"
# C compiler
# Flags were extracted from KallistiOS environment files
conf.cc do |cc|
cc.command = "#{BIN_PATH}/sh-elf-gcc"
cc.include_paths << ["#{KOS_PATH}/include", "#{KOS_PATH}/kernel/arch/dreamcast/include", "#{KOS_PATH}/addons/include", "#{KOS_PATH}/../kos-ports/include"]
cc.flags << ["-O2", "-fomit-frame-pointer", "-ml", "-m4-single-only", "-ffunction-sections", "-fdata-sections", "-Wall", "-g", "-fno-builtin", "-ml", "-m4-single-only", "-Wl,-Ttext=0x8c010000", "-Wl,--gc-sections", "-T#{KOS_PATH}/utils/ldscripts/shlelf.xc", "-nodefaultlibs"]
cc.compile_options = %Q[%{flags} -o "%{outfile}" -c "%{infile}"]
cc.defines << %w(_arch_dreamcast)
cc.defines << %w(_arch_sub_pristine)
end
# C++ compiler
conf.cxx do |cxx|
cxx.command = conf.cc.command.dup
cxx.include_paths = conf.cc.include_paths.dup
cxx.flags = conf.cc.flags.dup
cxx.flags << %w(-fno-rtti -fno-exceptions)
cxx.defines = conf.cc.defines.dup
cxx.compile_options = conf.cc.compile_options.dup
end
# Linker
# There is an issue when making the mruby library with KallistiOS:
# 'newlib_kill.o' and 'newlib_getpid.o' aren't found so they are explicitly
# specified here at least for now.
conf.linker do |linker|
linker.command="#{BIN_PATH}/sh-elf-gcc"
linker.flags << ["#{MSYS_ROOT}/opt/toolchains/dc/kos/kernel/build/newlib_kill.o", "#{MSYS_ROOT}/opt/toolchains/dc/kos/kernel/build/newlib_getpid.o", "-Wl,--start-group -lkallisti -lc -lgcc -Wl,--end-group"]
linker.library_paths << ["#{KOS_PATH}/lib/dreamcast", "#{KOS_PATH}/addons/lib/dreamcast", "#{KOS_PATH}/../kos-ports/lib"]
end
# Archiver
conf.archiver do |archiver|
archiver.command = "#{BIN_PATH}/sh-elf-ar"
archiver.archive_options = 'rcs "%{outfile}" %{objs}'
end
# No executables
conf.bins = []
# Do not build executable test
conf.build_mrbtest_lib_only
# Disable C++ exception
conf.disable_cxx_exception
# Gems from core
# removing mruby-io
conf.gem :core => "mruby-metaprog"
conf.gem :core => "mruby-pack"
conf.gem :core => "mruby-sprintf"
conf.gem :core => "mruby-print"
conf.gem :core => "mruby-math"
conf.gem :core => "mruby-time"
conf.gem :core => "mruby-struct"
conf.gem :core => "mruby-compar-ext"
conf.gem :core => "mruby-enum-ext"
conf.gem :core => "mruby-string-ext"
conf.gem :core => "mruby-numeric-ext"
conf.gem :core => "mruby-array-ext"
conf.gem :core => "mruby-hash-ext"
conf.gem :core => "mruby-range-ext"
conf.gem :core => "mruby-proc-ext"
conf.gem :core => "mruby-symbol-ext"
conf.gem :core => "mruby-random"
conf.gem :core => "mruby-object-ext"
conf.gem :core => "mruby-objectspace"
conf.gem :core => "mruby-fiber"
conf.gem :core => "mruby-enumerator"
conf.gem :core => "mruby-enum-lazy"
conf.gem :core => "mruby-toplevel-ext"
conf.gem :core => "mruby-kernel-ext"
conf.gem :core => "mruby-class-ext"
conf.gem :core => "mruby-compiler"
end
+79 -13
View File
@@ -36,19 +36,26 @@
/* 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_METHOD_T_STRUCT on machines that use higher bits of pointers */
/* no MRB_METHOD_T_STRUCT requires highest 2 bits of function pointers to be zero */
#ifndef MRB_METHOD_T_STRUCT
// can't use highest 2 bits of function pointers at least on 32bit
// Windows and 32bit Linux.
# ifdef MRB_32BIT
# define MRB_METHOD_T_STRUCT
# endif
#endif
/* add -DMRB_INT16 to use 16bit integer for mrb_int; conflict with MRB_INT64 */
//#define MRB_INT16
/* add -DMRB_INT32 to use 32bit integer for mrb_int; conflict with MRB_INT64;
Default for 32-bit CPU mode. */
//#define MRB_INT32
/* add -DMRB_INT64 to use 64bit integer for mrb_int; conflict with MRB_INT16 */
/* add -DMRB_INT64 to use 64bit integer for mrb_int; conflict with MRB_INT32;
Default for 64-bit CPU mode. */
//#define MRB_INT64
/* if no specific integer type is chosen */
#if !defined(MRB_INT16) && !defined(MRB_INT32) && !defined(MRB_INT64)
#if !defined(MRB_INT32) && !defined(MRB_INT64)
# if defined(MRB_64BIT) && !defined(MRB_NAN_BOXING)
/* Use 64bit integers on 64bit architecture (without MRB_NAN_BOXING) */
# define MRB_INT64
@@ -81,12 +88,13 @@
/* number of object per heap page */
//#define MRB_HEAP_PAGE_SIZE 1024
/* if _etext and _edata available, mruby can reduce memory used by symbols */
//#define MRB_USE_ETEXT_EDATA
/* if __ehdr_start is available, mruby can reduce memory used by symbols */
//#define MRB_USE_LINK_TIME_RO_DATA_P
/* do not use __init_array_start to determine readonly data section;
effective only when MRB_USE_ETEXT_EDATA is defined */
//#define MRB_NO_INIT_ARRAY_START
/* if MRB_USE_LINK_TIME_RO_DATA_P does not work,
you can try mrb_ro_data_p() that you have implemented yourself in any file;
prototype is `mrb_bool mrb_ro_data_p(const char *ptr)` */
//#define MRB_USE_CUSTOM_RO_DATA_P
/* turn off generational GC by default */
//#define MRB_GC_TURN_OFF_GENERATIONAL
@@ -146,4 +154,62 @@
# define TRUE 1
#endif
/*
** mruby tuning profiles
**/
/* A profile for micro controllers */
#if defined(MRB_CONSTRAINED_BASELINE_PROFILE)
# ifndef KHASH_DEFAULT_SIZE
# define KHASH_DEFAULT_SIZE 16
# endif
# ifndef MRB_STR_BUF_MIN_SIZE
# define MRB_STR_BUF_MIN_SIZE 32
# endif
# ifndef MRB_HEAP_PAGE_SIZE
# define MRB_HEAP_PAGE_SIZE 256
# endif
/* A profile for default mruby */
#elif defined(MRB_BASELINE_PROFILE)
/* A profile for desktop computers or workstations; rich memory! */
#elif defined(MRB_MAIN_PROFILE)
# ifndef MRB_METHOD_CACHE
# define MRB_METHOD_CACHE
# endif
# ifndef MRB_METHOD_CACHE_SIZE
# define MRB_METHOD_CACHE_SIZE (1<<10)
# endif
# ifndef MRB_IV_SEGMENT_SIZE
# define MRB_IV_SEGMENT_SIZE 32
# endif
# ifndef MRB_HEAP_PAGE_SIZE
# define MRB_HEAP_PAGE_SIZE 4096
# endif
/* A profile for server; mruby vm is long life */
#elif defined(MRB_HIGH_PROFILE)
# ifndef MRB_METHOD_CACHE
# define MRB_METHOD_CACHE
# endif
# ifndef MRB_METHOD_CACHE_SIZE
# define MRB_METHOD_CACHE_SIZE (1<<12)
# endif
# ifndef MRB_IV_SEGMENT_SIZE
# define MRB_IV_SEGMENT_SIZE 64
# endif
# ifndef MRB_HEAP_PAGE_SIZE
# define MRB_HEAP_PAGE_SIZE 4096
# endif
#endif
#endif /* MRUBYCONF_H */
+265 -153
View File
@@ -1,7 +1,7 @@
/*
** mruby - An embeddable Ruby implementation
**
** Copyright (c) mruby developers 2010-2019
** Copyright (c) mruby developers 2010-2020
**
** Permission is hereby granted, free of charge, to any person obtaining
** a copy of this software and associated documentation files (the
@@ -25,6 +25,10 @@
** [ MIT license: http://www.opensource.org/licenses/mit-license.php ]
*/
/**
* @file mruby.h
*/
#ifndef MRUBY_H
#define MRUBY_H
@@ -66,7 +70,13 @@
#include "mrbconf.h"
#include <mruby/common.h>
#include <mruby/value.h>
#include <mruby/gc.h>
#include <mruby/version.h>
#ifndef MRB_WITHOUT_FLOAT
#include <float.h>
#ifndef FLT_EPSILON
#define FLT_EPSILON (1.19209290e-07f)
#endif
@@ -84,11 +94,6 @@
#endif
#endif
#include "mruby/common.h"
#include <mruby/value.h>
#include <mruby/gc.h>
#include <mruby/version.h>
/**
* MRuby C API entry point
*/
@@ -97,11 +102,14 @@ MRB_BEGIN_DECL
typedef uint8_t mrb_code;
/**
* Required arguments signature type.
* \class mrb_aspec
*
* Specifies the number of arguments a function takes
*
* Example: `MRB_ARGS_REQ(2) | MRB_ARGS_OPT(1)` for a method that expects 2..3 arguments
*/
typedef uint32_t mrb_aspec;
struct mrb_irep;
struct mrb_state;
@@ -127,8 +135,8 @@ typedef struct {
uint16_t ridx;
uint16_t epos;
struct REnv *env;
mrb_code *pc; /* return address */
mrb_code *err; /* error position */
const mrb_code *pc; /* return address */
const mrb_code *err; /* error position */
int argc;
int acc;
struct RClass *target_class;
@@ -157,8 +165,8 @@ struct mrb_context {
struct RProc **ensure; /* ensure handler stack */
uint16_t esize, eidx;
enum mrb_fiber_state status;
mrb_bool vmexec;
enum mrb_fiber_state status : 4;
mrb_bool vmexec : 1;
struct RFiber *fib;
};
@@ -170,13 +178,22 @@ struct mrb_context {
# define MRB_METHOD_CACHE_SIZE (1<<7)
#endif
typedef mrb_value (*mrb_func_t)(struct mrb_state *mrb, mrb_value);
/**
* Function pointer type for a function callable by mruby.
*
* The arguments to the function are stored on the mrb_state. To get them see mrb_get_args
*
* @param mrb The mruby state
* @param self The self object
* @return [mrb_value] The function's return value
*/
typedef mrb_value (*mrb_func_t)(struct mrb_state *mrb, mrb_value self);
#ifdef MRB_METHOD_TABLE_INLINE
#ifndef MRB_METHOD_T_STRUCT
typedef uintptr_t mrb_method_t;
#else
typedef struct {
mrb_bool func_p;
uint8_t flags;
union {
struct RProc *proc;
mrb_func_t func;
@@ -196,13 +213,9 @@ struct mrb_jmpbuf;
typedef void (*mrb_atexit_func)(struct mrb_state*);
#define MRB_STATE_NO_REGEXP 1
#define MRB_STATE_REGEXP 2
typedef struct mrb_state {
struct mrb_jmpbuf *jmp;
uint32_t flags;
mrb_allocf allocf; /* memory allocation function */
void *allocf_ud; /* auxiliary data of allocf */
@@ -232,7 +245,6 @@ typedef struct mrb_state {
struct RClass *symbol_class;
struct RClass *kernel_module;
struct alloca_header *mems;
mrb_gc gc;
#ifdef MRB_METHOD_CACHE
@@ -248,8 +260,8 @@ typedef struct mrb_state {
#endif
#ifdef MRB_ENABLE_DEBUG_HOOK
void (*code_fetch_hook)(struct mrb_state* mrb, struct mrb_irep *irep, mrb_code *pc, mrb_value *regs);
void (*debug_op_hook)(struct mrb_state* mrb, struct mrb_irep *irep, mrb_code *pc, mrb_value *regs);
void (*code_fetch_hook)(struct mrb_state* mrb, struct mrb_irep *irep, const mrb_code *pc, mrb_value *regs);
void (*debug_op_hook)(struct mrb_state* mrb, struct mrb_irep *irep, const mrb_code *pc, mrb_value *regs);
#endif
#ifdef MRB_BYTECODE_DECODE_OPTION
@@ -290,9 +302,9 @@ typedef struct mrb_state {
* //free(TheAnimals);
* }
*
* @param [mrb_state *] mrb The current mruby state.
* @param [const char *] name The name of the defined class.
* @param [struct RClass *] super The new class parent.
* @param mrb The current mruby state.
* @param name The name of the defined class.
* @param super The new class parent.
* @return [struct RClass *] Reference to the newly defined class.
* @see mrb_define_class_under
*/
@@ -301,12 +313,14 @@ MRB_API struct RClass *mrb_define_class(mrb_state *mrb, const char *name, struct
/**
* Defines a new module.
*
* @param [mrb_state *] mrb_state* The current mruby state.
* @param [const char *] char* The name of the module.
* @param mrb The current mruby state.
* @param name The name of the module.
* @return [struct RClass *] Reference to the newly defined module.
*/
MRB_API struct RClass *mrb_define_module(mrb_state *, const char*);
MRB_API mrb_value mrb_singleton_class(mrb_state*, mrb_value);
MRB_API struct RClass *mrb_define_module(mrb_state *mrb, const char *name);
MRB_API mrb_value mrb_singleton_class(mrb_state *mrb, mrb_value val);
MRB_API struct RClass *mrb_singleton_class_ptr(mrb_state *mrb, mrb_value val);
/**
* Include a module in another class or module.
@@ -315,11 +329,11 @@ MRB_API mrb_value mrb_singleton_class(mrb_state*, mrb_value);
* module B
* include A
* end
* @param [mrb_state *] mrb_state* The current mruby state.
* @param [struct RClass *] RClass* A reference to module or a class.
* @param [struct RClass *] RClass* A reference to the module to be included.
* @param mrb The current mruby state.
* @param cla A reference to module or a class.
* @param included A reference to the module to be included.
*/
MRB_API void mrb_include_module(mrb_state*, struct RClass*, struct RClass*);
MRB_API void mrb_include_module(mrb_state *mrb, struct RClass *cla, struct RClass *included);
/**
* Prepends a module in another class or module.
@@ -328,11 +342,11 @@ MRB_API void mrb_include_module(mrb_state*, struct RClass*, struct RClass*);
* module B
* prepend A
* end
* @param [mrb_state *] mrb_state* The current mruby state.
* @param [struct RClass *] RClass* A reference to module or a class.
* @param [struct RClass *] RClass* A reference to the module to be prepended.
* @param mrb The current mruby state.
* @param cla A reference to module or a class.
* @param prepended A reference to the module to be prepended.
*/
MRB_API void mrb_prepend_module(mrb_state*, struct RClass*, struct RClass*);
MRB_API void mrb_prepend_module(mrb_state *mrb, struct RClass *cla, struct RClass *prepended);
/**
* Defines a global function in ruby.
@@ -341,7 +355,6 @@ MRB_API void mrb_prepend_module(mrb_state*, struct RClass*, struct RClass*);
*
* Example:
*
* !!!c
* mrb_value example_method(mrb_state* mrb, mrb_value self)
* {
* puts("Executing example command!");
@@ -353,11 +366,11 @@ MRB_API void mrb_prepend_module(mrb_state*, struct RClass*, struct RClass*);
* mrb_define_method(mrb, mrb->kernel_module, "example_method", example_method, MRB_ARGS_NONE());
* }
*
* @param [mrb_state *] mrb The MRuby state reference.
* @param [struct RClass *] cla The class pointer where the method will be defined.
* @param [const char *] name The name of the method being defined.
* @param [mrb_func_t] func The function pointer to the method definition.
* @param [mrb_aspec] aspec The method parameters declaration.
* @param mrb The MRuby state reference.
* @param cla The class pointer where the method will be defined.
* @param name The name of the method being defined.
* @param func The function pointer to the method definition.
* @param aspec The method parameters declaration.
*/
MRB_API void mrb_define_method(mrb_state *mrb, struct RClass *cla, const char *name, mrb_func_t func, mrb_aspec aspec);
@@ -380,14 +393,20 @@ MRB_API void mrb_define_method(mrb_state *mrb, struct RClass *cla, const char *n
* foo = mrb_define_class(mrb, "Foo", mrb->object_class);
* mrb_define_class_method(mrb, foo, "bar", bar_method, MRB_ARGS_NONE());
* }
* @param [mrb_state *] mrb_state* The MRuby state reference.
* @param [struct RClass *] RClass* The class where the class method will be defined.
* @param [const char *] char* The name of the class method being defined.
* @param [mrb_func_t] mrb_func_t The function pointer to the class method definition.
* @param [mrb_aspec] mrb_aspec The method parameters declaration.
* @param mrb The MRuby state reference.
* @param cla The class where the class method will be defined.
* @param name The name of the class method being defined.
* @param fun The function pointer to the class method definition.
* @param aspec The method parameters declaration.
*/
MRB_API void mrb_define_class_method(mrb_state *, struct RClass *, const char *, mrb_func_t, mrb_aspec);
MRB_API void mrb_define_singleton_method(mrb_state*, struct RObject*, const char*, mrb_func_t, mrb_aspec);
MRB_API void mrb_define_class_method(mrb_state *mrb, struct RClass *cla, const char *name, mrb_func_t fun, mrb_aspec aspec);
/**
* Defines a singleton method
*
* @see mrb_define_class_method
*/
MRB_API void mrb_define_singleton_method(mrb_state *mrb, struct RObject *cla, const char *name, mrb_func_t fun, mrb_aspec aspec);
/**
* Defines a module function.
@@ -408,13 +427,13 @@ MRB_API void mrb_define_singleton_method(mrb_state*, struct RObject*, const char
* foo = mrb_define_module(mrb, "Foo");
* mrb_define_module_function(mrb, foo, "bar", bar_method, MRB_ARGS_NONE());
* }
* @param [mrb_state *] mrb_state* The MRuby state reference.
* @param [struct RClass *] RClass* The module where the module function will be defined.
* @param [const char *] char* The name of the module function being defined.
* @param [mrb_func_t] mrb_func_t The function pointer to the module function definition.
* @param [mrb_aspec] mrb_aspec The method parameters declaration.
* @param mrb The MRuby state reference.
* @param cla The module where the module function will be defined.
* @param name The name of the module function being defined.
* @param fun The function pointer to the module function definition.
* @param aspec The method parameters declaration.
*/
MRB_API void mrb_define_module_function(mrb_state*, struct RClass*, const char*, mrb_func_t, mrb_aspec);
MRB_API void mrb_define_module_function(mrb_state *mrb, struct RClass *cla, const char *name, mrb_func_t fun, mrb_aspec aspec);
/**
* Defines a constant.
@@ -437,12 +456,12 @@ MRB_API void mrb_define_module_function(mrb_state*, struct RClass*, const char*,
* mrb_value
* mrb_example_gem_final(mrb_state* mrb){
* }
* @param [mrb_state *] mrb_state* The MRuby state reference.
* @param [struct RClass *] RClass* A class or module the constant is defined in.
* @param [const char *] name The name of the constant being defined.
* @param [mrb_value] mrb_value The value for the constant.
* @param mrb The MRuby state reference.
* @param cla A class or module the constant is defined in.
* @param name The name of the constant being defined.
* @param val The value for the constant.
*/
MRB_API void mrb_define_const(mrb_state*, struct RClass*, const char *name, mrb_value);
MRB_API void mrb_define_const(mrb_state* mrb, struct RClass* cla, const char *name, mrb_value val);
/**
* Undefines a method.
@@ -488,11 +507,11 @@ MRB_API void mrb_define_const(mrb_state*, struct RClass*, const char *name, mrb_
*
* mrb_example_gem_final(mrb_state* 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*] const char* The name of the method to be undefined.
* @param mrb The mruby state reference.
* @param cla The class the method will be undefined from.
* @param name 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(mrb_state *mrb, struct RClass *cla, const char *name);
MRB_API void mrb_undef_method_id(mrb_state*, struct RClass*, mrb_sym);
/**
@@ -528,11 +547,11 @@ MRB_API void mrb_undef_method_id(mrb_state*, struct RClass*, mrb_sym);
* void
* mrb_example_gem_final(mrb_state* mrb){
* }
* @param [mrb_state*] mrb_state* The mruby state reference.
* @param [RClass*] RClass* A class the class method will be undefined from.
* @param [const char*] const char* The name of the class method to be undefined.
* @param mrb The mruby state reference.
* @param cls A class the class method will be undefined from.
* @param name The name of the class method to be undefined.
*/
MRB_API void mrb_undef_class_method(mrb_state*, struct RClass*, const char*);
MRB_API void mrb_undef_class_method(mrb_state *mrb, struct RClass *cls, const char *name);
/**
* Initialize a new object instance of c class.
@@ -556,10 +575,10 @@ MRB_API void mrb_undef_class_method(mrb_state*, struct RClass*, const char*);
* obj = mrb_obj_new(mrb, example_class, 0, NULL); # => ExampleClass.new
* mrb_p(mrb, obj); // => Kernel#p
* }
* @param [mrb_state*] mrb The current mruby state.
* @param [RClass*] c Reference to the class of the new object.
* @param [mrb_int] argc Number of arguments in argv
* @param [const mrb_value *] argv Array of mrb_value to initialize the object
* @param mrb The current mruby state.
* @param c Reference to the class of the new object.
* @param argc Number of arguments in argv
* @param argv Array of mrb_value to initialize the object
* @return [mrb_value] The newly initialized object
*/
MRB_API mrb_value mrb_obj_new(mrb_state *mrb, struct RClass *c, mrb_int argc, const mrb_value *argv);
@@ -570,8 +589,6 @@ MRB_INLINE mrb_value mrb_class_new_instance(mrb_state *mrb, mrb_int argc, const
return mrb_obj_new(mrb,c,argc,argv);
}
MRB_API mrb_value mrb_instance_new(mrb_state *mrb, mrb_value cv);
/**
* Creates a new instance of Class, Class.
*
@@ -587,8 +604,8 @@ MRB_API mrb_value mrb_instance_new(mrb_state *mrb, mrb_value cv);
* mrb_p(mrb, obj); // => Kernel#p
* }
*
* @param [mrb_state*] mrb The current mruby state.
* @param [struct RClass *] super The super class or parent.
* @param mrb The current mruby state.
* @param super The super class or parent.
* @return [struct RClass *] Reference to the new class.
*/
MRB_API struct RClass * mrb_class_new(mrb_state *mrb, struct RClass *super);
@@ -604,7 +621,7 @@ MRB_API struct RClass * mrb_class_new(mrb_state *mrb, struct RClass *super);
* example_module = mrb_module_new(mrb);
* }
*
* @param [mrb_state*] mrb The current mruby state.
* @param mrb The current mruby state.
* @return [struct RClass *] Reference to the new module.
*/
MRB_API struct RClass * mrb_module_new(mrb_state *mrb);
@@ -631,24 +648,24 @@ MRB_API struct RClass * mrb_module_new(mrb_state *mrb);
* }
* }
*
* @param [mrb_state*] mrb The current mruby state.
* @param [const char *] name A string representing the name of the class.
* @param mrb The current mruby state.
* @param name A string representing the name of the class.
* @return [mrb_bool] A boolean value.
*/
MRB_API mrb_bool mrb_class_defined(mrb_state *mrb, const char *name);
/**
* Gets a class.
* @param [mrb_state*] mrb The current mruby state.
* @param [const char *] name The name of the class.
* @param mrb The current mruby state.
* @param name The name of the class.
* @return [struct RClass *] A reference to the class.
*/
MRB_API struct RClass * mrb_class_get(mrb_state *mrb, const char *name);
/**
* Gets a exception class.
* @param [mrb_state*] mrb The current mruby state.
* @param [const char *] name The name of the class.
* @param mrb The current mruby state.
* @param name The name of the class.
* @return [struct RClass *] A reference to the class.
*/
MRB_API struct RClass * mrb_exc_get(mrb_state *mrb, const char *name);
@@ -677,35 +694,35 @@ MRB_API struct RClass * mrb_exc_get(mrb_state *mrb, const char *name);
* }
* }
*
* @param [mrb_state*] mrb The current mruby state.
* @param [struct RClass *] outer The name of the outer class.
* @param [const char *] name A string representing the name of the inner class.
* @param mrb The current mruby state.
* @param outer The name of the outer class.
* @param name A string representing the name of the inner class.
* @return [mrb_bool] A boolean value.
*/
MRB_API mrb_bool mrb_class_defined_under(mrb_state *mrb, struct RClass *outer, const char *name);
/**
* Gets a child class.
* @param [mrb_state*] mrb The current mruby state.
* @param [struct RClass *] outer The name of the parent class.
* @param [const char *] name The name of the class.
* @param mrb The current mruby state.
* @param outer The name of the parent class.
* @param name The name of the class.
* @return [struct RClass *] A reference to the class.
*/
MRB_API struct RClass * mrb_class_get_under(mrb_state *mrb, struct RClass *outer, const char *name);
/**
* Gets a module.
* @param [mrb_state*] mrb The current mruby state.
* @param [const char *] name The name of the module.
* @param mrb The current mruby state.
* @param name The name of the module.
* @return [struct RClass *] A reference to the module.
*/
MRB_API struct RClass * mrb_module_get(mrb_state *mrb, const char *name);
/**
* Gets a module defined under another module.
* @param [mrb_state*] mrb The current mruby state.
* @param [struct RClass *] outer The name of the outer module.
* @param [const char *] name The name of the module.
* @param mrb The current mruby state.
* @param outer The name of the outer module.
* @param name The name of the module.
* @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);
@@ -719,8 +736,8 @@ MRB_API mrb_value mrb_notimplement_m(mrb_state*, mrb_value);
*
* Equivalent to:
* Object#dup
* @param [mrb_state*] mrb The current mruby state.
* @param [mrb_value] obj Object to be duplicate.
* @param mrb The current mruby state.
* @param obj Object to be duplicate.
* @return [mrb_value] The newly duplicated object.
*/
MRB_API mrb_value mrb_obj_dup(mrb_state *mrb, mrb_value obj);
@@ -760,9 +777,9 @@ MRB_API mrb_value mrb_obj_dup(mrb_state *mrb, mrb_value obj);
* }
* }
*
* @param [mrb_state*] mrb The current mruby state.
* @param [struct RClass *] c A reference to a class.
* @param [mrb_sym] mid A symbol referencing a method id.
* @param mrb The current mruby state.
* @param c A reference to a class.
* @param mid A symbol referencing a method id.
* @return [mrb_bool] A boolean value.
*/
MRB_API mrb_bool mrb_obj_respond_to(mrb_state *mrb, struct RClass* c, mrb_sym mid);
@@ -770,10 +787,10 @@ MRB_API mrb_bool mrb_obj_respond_to(mrb_state *mrb, struct RClass* c, mrb_sym mi
/**
* Defines a new class under a given module
*
* @param [mrb_state*] mrb The current mruby state.
* @param [struct RClass *] outer Reference to the module under which the new class will be defined
* @param [const char *] name The name of the defined class
* @param [struct RClass *] super The new class parent
* @param mrb The current mruby state.
* @param outer Reference to the module under which the new class will be defined
* @param name The name of the defined class
* @param super The new class parent
* @return [struct RClass *] Reference to the newly defined class
* @see mrb_define_class
*/
@@ -843,34 +860,93 @@ MRB_API struct RClass * mrb_define_module_under(mrb_state *mrb, struct RClass *o
* | `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} | |
* | `f` | {Fixnum}/{Float} | {mrb_float} | |
* | `i` | {Fixnum}/{Float} | {mrb_int} | |
* | `b` | boolean | {mrb_bool} | |
* | `n` | {Symbol} | {mrb_sym} | |
* | `n` | {String}/{Symbol} | {mrb_sym} | |
* | `d` | data | void *, {mrb_data_type} const | 2nd argument will be used to check data type so it won't be modified; when `!` follows, the value may be `nil` |
* | `I` | inline struct | void * | |
* | `&` | 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. |
* | `*` | rest arguments | {mrb_value} *, {mrb_int} | Receive the rest of arguments as an array; `*!` avoid copy of the stack. |
* | <code>\|</code> | optional | | After this spec following specs would be optional. |
* | `?` | optional given | {mrb_bool} | `TRUE` if preceding argument is given. Used to check optional argument is given. |
* | `:` | keyword args | {mrb_kwargs} const | Get keyword arguments. @see mrb_kwargs |
*
* @see mrb_get_args
*/
typedef const char *mrb_args_format;
/**
* Get keyword arguments by `mrb_get_args()` with `:` specifier.
*
* `mrb_kwargs::num` indicates that the number of keyword values.
*
* `mrb_kwargs::values` is an object array, and the keyword argument corresponding to the string array is assigned.
* Note that `undef` is assigned if there is no keyword argument corresponding to `mrb_kwargs::optional`.
*
* `mrb_kwargs::table` accepts a string array.
*
* `mrb_kwargs::required` indicates that the specified number of keywords starting from the beginning of the string array are required.
*
* `mrb_kwargs::rest` is the remaining keyword argument that can be accepted as `**rest` in Ruby.
* If `NULL` is specified, `ArgumentError` is raised when there is an undefined keyword.
*
* Examples:
*
* // def method(a: 1, b: 2)
*
* uint32_t kw_num = 2;
* const char *kw_names[kw_num] = { "a", "b" };
* uint32_t kw_required = 0;
* mrb_value kw_values[kw_num];
* const mrb_kwargs kwargs = { kw_num, kw_values, kw_names, kw_required, NULL };
*
* mrb_get_args(mrb, ":", &kwargs);
* if (mrb_undef_p(kw_values[0])) { kw_values[0] = mrb_fixnum_value(1); }
* if (mrb_undef_p(kw_values[1])) { kw_values[1] = mrb_fixnum_value(2); }
*
*
* // def method(str, x:, y: 2, z: "default string", **opts)
*
* mrb_value str, kw_rest;
* uint32_t kw_num = 3;
* const char *kw_names[kw_num] = { "x", "y", "z" };
* uint32_t kw_required = 1;
* mrb_value kw_values[kw_num];
* const mrb_kwargs kwargs = { kw_num, kw_values, kw_names, kw_required, &kw_rest };
*
* mrb_get_args(mrb, "S:", &str, &kwargs);
* // or: mrb_get_args(mrb, ":S", &kwargs, &str);
* if (mrb_undef_p(kw_values[1])) { kw_values[1] = mrb_fixnum_value(2); }
* if (mrb_undef_p(kw_values[2])) { kw_values[2] = mrb_str_new_cstr(mrb, "default string"); }
*/
typedef struct mrb_kwargs mrb_kwargs;
struct mrb_kwargs
{
uint32_t num;
mrb_value *values;
const char *const *table;
uint32_t required;
mrb_value *rest;
};
/**
* Retrieve arguments from mrb_state.
*
* @param mrb The current MRuby state.
* @param format [mrb_args_format] is a list of format specifiers
* @param format is a list of format specifiers
* @param ... The passing variadic arguments must be a pointer of retrieving type.
* @return the number of arguments retrieved.
* @see mrb_args_format
* @see mrb_kwargs
*/
MRB_API mrb_int mrb_get_args(mrb_state *mrb, mrb_args_format format, ...);
static inline mrb_sym
MRB_INLINE mrb_sym
mrb_get_mid(mrb_state *mrb) /* get method symbol */
{
return mrb->c->ci->mid;
@@ -883,8 +959,21 @@ mrb_get_mid(mrb_state *mrb) /* get method symbol */
*/
MRB_API mrb_int mrb_get_argc(mrb_state *mrb);
/**
* Retrieve an array of arguments from mrb_state.
*
* Correctly handles *splat arguments.
*/
MRB_API mrb_value* mrb_get_argv(mrb_state *mrb);
/**
* Retrieve the first and only argument from mrb_state.
* Raises ArgumentError unless the number of arguments is exactly one.
*
* Correctly handles *splat arguments.
*/
MRB_API mrb_value mrb_get_arg1(mrb_state *mrb);
/* `strlen` for character string literals (use with caution or `strlen` instead)
Adjacent string literals are concatenated in C/C++ in translation phase 6.
If `lit` is not one, the compiler will report a syntax error:
@@ -896,6 +985,8 @@ MRB_API mrb_value* mrb_get_argv(mrb_state *mrb);
/**
* Call existing ruby functions.
*
* Example:
*
* #include <stdio.h>
* #include <mruby.h>
* #include "mruby/compile.h"
@@ -912,15 +1003,16 @@ MRB_API mrb_value* mrb_get_argv(mrb_state *mrb);
* mrb_funcall(mrb, obj, "method_name", 1, mrb_fixnum_value(i));
* fclose(fp);
* mrb_close(mrb);
* }
* @param [mrb_state*] mrb_state* The current mruby state.
* @param [mrb_value] mrb_value A reference to an mruby value.
* @param [const char*] const char* The name of the method.
* @param [mrb_int] mrb_int The number of arguments the method has.
* @param [...] ... Variadic values(not type safe!).
* @return [mrb_value] mrb_value mruby function value.
* }
*
* @param mrb The current mruby state.
* @param val A reference to an mruby value.
* @param name The name of the method.
* @param argc The number of arguments the method has.
* @param ... Variadic values(not type safe!).
* @return [mrb_value] mruby function value.
*/
MRB_API mrb_value mrb_funcall(mrb_state*, mrb_value, const char*, mrb_int,...);
MRB_API mrb_value mrb_funcall(mrb_state *mrb, mrb_value val, const char *name, mrb_int argc, ...);
/**
* Call existing ruby functions. This is basically the type safe version of mrb_funcall.
*
@@ -942,32 +1034,35 @@ MRB_API mrb_value mrb_funcall(mrb_state*, mrb_value, const char*, mrb_int,...);
* fclose(fp);
* mrb_close(mrb);
* }
* @param [mrb_state*] mrb_state* The current mruby state.
* @param [mrb_value] mrb_value A reference to an mruby value.
* @param [mrb_sym] mrb_sym The symbol representing the method.
* @param [mrb_int] mrb_int The number of arguments the method has.
* @param [const mrb_value*] mrb_value* Pointer to the object.
* @param mrb The current mruby state.
* @param val A reference to an mruby value.
* @param name_sym The symbol representing the method.
* @param argc The number of arguments the method has.
* @param obj Pointer to the object.
* @return [mrb_value] mrb_value mruby function value.
* @see mrb_funcall
*/
MRB_API mrb_value mrb_funcall_argv(mrb_state*, mrb_value, mrb_sym, mrb_int, const mrb_value*);
MRB_API mrb_value mrb_funcall_argv(mrb_state *mrb, mrb_value val, mrb_sym name, mrb_int argc, const mrb_value *argv);
/**
* Call existing ruby functions with a block.
*/
MRB_API mrb_value mrb_funcall_with_block(mrb_state*, mrb_value, mrb_sym, mrb_int, const mrb_value*, mrb_value);
MRB_API mrb_value mrb_funcall_with_block(mrb_state *mrb, mrb_value val, mrb_sym name, mrb_int argc, const mrb_value *argv, mrb_value block);
/**
* Create a symbol
*
* Example:
*
* # Ruby style:
* :pizza # => :pizza
*
* // C style:
* mrb_sym m_sym = mrb_intern_lit(mrb, "pizza"); // => :pizza
* @param [mrb_state*] mrb_state* The current mruby state.
* @param [const char*] const char* The name of the method.
*
* @param mrb The current mruby state.
* @param str The string to be symbolized
* @return [mrb_sym] mrb_sym A symbol.
*/
MRB_API mrb_sym mrb_intern_cstr(mrb_state*,const char*);
MRB_API mrb_sym mrb_intern_cstr(mrb_state *mrb, const char* str);
MRB_API mrb_sym mrb_intern(mrb_state*,const char*,size_t);
MRB_API mrb_sym mrb_intern_static(mrb_state*,const char*,size_t);
#define mrb_intern_lit(mrb, lit) mrb_intern_static(mrb, lit, mrb_strlen_lit(lit))
@@ -975,9 +1070,13 @@ MRB_API mrb_sym mrb_intern_str(mrb_state*,mrb_value);
MRB_API mrb_value mrb_check_intern_cstr(mrb_state*,const char*);
MRB_API mrb_value mrb_check_intern(mrb_state*,const char*,size_t);
MRB_API mrb_value mrb_check_intern_str(mrb_state*,mrb_value);
MRB_API const char *mrb_sym2name(mrb_state*,mrb_sym);
MRB_API const char *mrb_sym2name_len(mrb_state*,mrb_sym,mrb_int*);
MRB_API mrb_value mrb_sym2str(mrb_state*,mrb_sym);
MRB_API const char *mrb_sym_name(mrb_state*,mrb_sym);
MRB_API const char *mrb_sym_name_len(mrb_state*,mrb_sym,mrb_int*);
MRB_API const char *mrb_sym_dump(mrb_state*,mrb_sym);
MRB_API mrb_value mrb_sym_str(mrb_state*,mrb_sym);
#define mrb_sym2name(mrb,sym) mrb_sym_name(mrb,sym)
#define mrb_sym2name_len(mrb,sym,len) mrb_sym_name_len(mrb,sym,len)
#define mrb_sym2str(mrb,sym) mrb_sym_str(mrb,sym)
MRB_API void *mrb_malloc(mrb_state*, size_t); /* raise RuntimeError if no mem */
MRB_API void *mrb_calloc(mrb_state*, size_t, size_t); /* ditto */
@@ -996,6 +1095,12 @@ MRB_API mrb_value mrb_str_new_cstr(mrb_state*, const char*);
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))
MRB_API mrb_value mrb_obj_freeze(mrb_state*, mrb_value);
#define mrb_str_new_frozen(mrb,p,len) mrb_obj_freeze(mrb,mrb_str_new(mrb,p,len))
#define mrb_str_new_cstr_frozen(mrb,p) mrb_obj_freeze(mrb,mrb_str_new_cstr(mrb,p))
#define mrb_str_new_static_frozen(mrb,p,len) mrb_obj_freeze(mrb,mrb_str_new_static(mrb,p,len))
#define mrb_str_new_lit_frozen(mrb,lit) mrb_obj_freeze(mrb,mrb_str_new_lit(mrb,lit))
#ifdef _WIN32
MRB_API char* mrb_utf8_from_locale(const char *p, int len);
MRB_API char* mrb_locale_from_utf8(const char *p, int len);
@@ -1058,11 +1163,10 @@ MRB_API void mrb_close(mrb_state *mrb);
*/
MRB_API void* mrb_default_allocf(mrb_state*, void*, size_t, void*);
MRB_API mrb_value mrb_top_self(mrb_state *);
MRB_API mrb_value mrb_run(mrb_state*, struct RProc*, mrb_value);
MRB_API mrb_value mrb_top_run(mrb_state*, struct RProc*, mrb_value, unsigned int);
MRB_API mrb_value mrb_vm_run(mrb_state*, struct RProc*, mrb_value, unsigned int);
MRB_API mrb_value mrb_vm_exec(mrb_state*, struct RProc*, mrb_code*);
MRB_API mrb_value mrb_top_self(mrb_state *mrb);
MRB_API mrb_value mrb_top_run(mrb_state *mrb, struct RProc *proc, mrb_value self, unsigned int stack_keep);
MRB_API mrb_value mrb_vm_run(mrb_state *mrb, struct RProc *proc, mrb_value self, unsigned int stack_keep);
MRB_API mrb_value mrb_vm_exec(mrb_state *mrb, struct RProc *proc, const mrb_code *iseq);
/* compatibility macros */
#define mrb_toplevel_run_keep(m,p,k) mrb_top_run((m),(p),mrb_top_self(m),(k))
#define mrb_toplevel_run(m,p) mrb_toplevel_run_keep((m),(p),0)
@@ -1072,8 +1176,8 @@ MRB_API void mrb_p(mrb_state*, mrb_value);
MRB_API mrb_int mrb_obj_id(mrb_value obj);
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_obj_eq(mrb_state *mrb, mrb_value a, mrb_value b);
MRB_API mrb_bool mrb_obj_equal(mrb_state *mrb, mrb_value a, mrb_value b);
MRB_API mrb_bool mrb_equal(mrb_state *mrb, mrb_value obj1, mrb_value obj2);
MRB_API mrb_value mrb_convert_to_integer(mrb_state *mrb, mrb_value val, mrb_int base);
MRB_API mrb_value mrb_Integer(mrb_state *mrb, mrb_value val);
@@ -1082,17 +1186,16 @@ 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);
/* mrb_cmp(mrb, obj1, obj2): 1:0:-1; -2 for error */
MRB_API mrb_int mrb_cmp(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_INLINE int
mrb_gc_arena_save(mrb_state *mrb)
{
return mrb->gc.arena_idx;
}
static inline void
MRB_INLINE void
mrb_gc_arena_restore(mrb_state *mrb, int idx)
{
mrb->gc.arena_idx = idx;
@@ -1143,6 +1246,8 @@ MRB_API mrb_noreturn void mrb_exc_raise(mrb_state *mrb, mrb_value exc);
MRB_API mrb_noreturn void mrb_raise(mrb_state *mrb, struct RClass *c, const char *msg);
MRB_API mrb_noreturn void mrb_raisef(mrb_state *mrb, struct RClass *c, const char *fmt, ...);
MRB_API mrb_noreturn void mrb_name_error(mrb_state *mrb, mrb_sym id, const char *fmt, ...);
MRB_API mrb_noreturn void mrb_frozen_error(mrb_state *mrb, void *frozen_obj);
MRB_API mrb_noreturn void mrb_argnum_error(mrb_state *mrb, mrb_int argc, int min, int max);
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);
@@ -1193,9 +1298,15 @@ 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))
/* string type checking (contrary to the name, it doesn't convert) */
MRB_API mrb_value mrb_to_str(mrb_state *mrb, mrb_value val);
MRB_API void mrb_check_type(mrb_state *mrb, mrb_value x, enum mrb_vtype t);
MRB_INLINE void mrb_check_frozen(mrb_state *mrb, void *o)
{
if (mrb_frozen_p((struct RBasic*)o)) mrb_frozen_error(mrb, o);
}
typedef enum call_type {
CALL_PUBLIC,
CALL_FCALL,
@@ -1214,31 +1325,31 @@ MRB_API mrb_bool mrb_obj_is_instance_of(mrb_state *mrb, mrb_value obj, struct RC
MRB_API mrb_bool mrb_func_basic_p(mrb_state *mrb, mrb_value obj, mrb_sym mid, mrb_func_t func);
/*
/**
* Resume a Fiber
*
* @mrbgem mruby-fiber
* Implemented in mruby-fiber
*/
MRB_API mrb_value mrb_fiber_resume(mrb_state *mrb, mrb_value fib, mrb_int argc, const mrb_value *argv);
/*
/**
* Yield a Fiber
*
* @mrbgem mruby-fiber
* Implemented in mruby-fiber
*/
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
* Implemented in mruby-fiber
*/
MRB_API mrb_value mrb_fiber_alive_p(mrb_state *mrb, mrb_value fib);
/*
/**
* FiberError reference
*
* @mrbgem mruby-fiber
* Implemented in mruby-fiber
*/
#define E_FIBER_ERROR (mrb_exc_get(mrb, "FiberError"))
MRB_API void mrb_stack_extend(mrb_state*, mrb_int);
@@ -1250,6 +1361,7 @@ MRB_API void mrb_pool_close(struct mrb_pool*);
MRB_API void* mrb_pool_alloc(struct mrb_pool*, size_t);
MRB_API void* mrb_pool_realloc(struct mrb_pool*, void*, size_t oldlen, size_t newlen);
MRB_API mrb_bool mrb_pool_can_realloc(struct mrb_pool*, void*, size_t);
/* temporary memory allocation, only effective while GC arena is kept */
MRB_API void* mrb_alloca(mrb_state *mrb, size_t);
MRB_API void mrb_state_atexit(mrb_state *mrb, mrb_atexit_func func);
+11 -7
View File
@@ -1,5 +1,5 @@
/*
** mruby/array.h - Array class
/**
** @file mruby/array.h - Array class
**
** See Copyright Notice in mruby.h
*/
@@ -17,7 +17,7 @@ MRB_BEGIN_DECL
typedef struct mrb_shared_array {
int refcnt;
mrb_int len;
mrb_ssize len;
mrb_value *ptr;
} mrb_shared_array;
@@ -26,14 +26,14 @@ struct RArray {
MRB_OBJECT_HEADER;
union {
struct {
mrb_int len;
mrb_ssize len;
union {
mrb_int capa;
mrb_ssize capa;
mrb_shared_array *shared;
} aux;
mrb_value *ptr;
} heap;
mrb_value embed[MRB_ARY_EMBED_LEN_MAX];
void *ary[3];
} as;
};
@@ -46,7 +46,7 @@ struct RArray {
#define ARY_UNSET_EMBED_FLAG(a) ((a)->flags &= ~(MRB_ARY_EMBED_MASK))
#define ARY_EMBED_LEN(a) ((mrb_int)(((a)->flags & MRB_ARY_EMBED_MASK) - 1))
#define ARY_SET_EMBED_LEN(a,len) ((a)->flags = ((a)->flags&~MRB_ARY_EMBED_MASK) | ((uint32_t)(len) + 1))
#define ARY_EMBED_PTR(a) (&((a)->as.embed[0]))
#define ARY_EMBED_PTR(a) ((mrb_value*)(&(a)->as.ary))
#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)
@@ -239,6 +239,7 @@ MRB_API mrb_value mrb_ary_entry(mrb_value ary, mrb_int offset);
* @param head Beginning position of a replacement subsequence.
* @param len Length of a replacement subsequence.
* @param rpl The array of replacement elements.
* It is possible to pass `mrb_undef_value()` instead of an empty array.
* @return The receiver array.
*/
MRB_API mrb_value mrb_ary_splice(mrb_state *mrb, mrb_value self, mrb_int head, mrb_int len, mrb_value rpl);
@@ -291,6 +292,9 @@ MRB_API mrb_value mrb_ary_join(mrb_state *mrb, mrb_value ary, mrb_value sep);
*/
MRB_API mrb_value mrb_ary_resize(mrb_state *mrb, mrb_value ary, mrb_int new_len);
/* helper functions */
mrb_value mrb_ary_subseq(mrb_state *mrb, mrb_value ary, mrb_int beg, mrb_int len);
MRB_END_DECL
#endif /* MRUBY_ARRAY_H */
+14 -11
View File
@@ -1,5 +1,5 @@
/*
** mruby/boxing_nan.h - nan boxing mrb_value definition
/**
** @file mruby/boxing_nan.h - nan boxing mrb_value definition
**
** See Copyright Notice in mruby.h
*/
@@ -20,13 +20,7 @@
#endif
#define MRB_FIXNUM_SHIFT 0
#define MRB_TT_HAS_BASIC MRB_TT_OBJECT
#ifdef MRB_ENDIAN_BIG
#define MRB_ENDIAN_LOHI(a,b) a b
#else
#define MRB_ENDIAN_LOHI(a,b) b a
#endif
#define MRB_SYMBOL_SHIFT 0
/* value representation by nan-boxing:
* float : FFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFF
@@ -50,6 +44,9 @@ typedef struct mrb_value {
};
)
};
#ifdef MRB_64BIT
struct RCptr *vp;
#endif
} value;
};
} mrb_value;
@@ -60,13 +57,15 @@ typedef struct mrb_value {
#define mrb_type(o) (enum mrb_vtype)((uint32_t)0xfff00000 < (o).value.ttt ? mrb_tt(o) : MRB_TT_FLOAT)
#define mrb_ptr(o) ((void*)((((uintptr_t)0x3fffffffffff)&((uintptr_t)((o).value.p)))<<2))
#define mrb_float(o) (o).f
#define mrb_cptr(o) mrb_ptr(o)
#define mrb_fixnum(o) (o).value.i
#define mrb_symbol(o) (o).value.sym
#ifdef MRB_64BIT
MRB_API mrb_value mrb_nan_boxing_cptr_value(struct mrb_state*, void*);
#define mrb_cptr(o) (((struct RCptr*)mrb_ptr(o))->p)
#define BOXNAN_SHIFT_LONG_POINTER(v) (((uintptr_t)(v)>>34)&0x3fff)
#else
#define mrb_cptr(o) ((o).value.p)
#define BOXNAN_SHIFT_LONG_POINTER(v) 0
#endif
@@ -96,7 +95,11 @@ typedef struct mrb_value {
#define SET_INT_VALUE(r,n) BOXNAN_SET_VALUE(r, MRB_TT_FIXNUM, value.i, (n))
#define SET_SYM_VALUE(r,v) BOXNAN_SET_VALUE(r, MRB_TT_SYMBOL, value.sym, (v))
#define SET_OBJ_VALUE(r,v) BOXNAN_SET_OBJ_VALUE(r, (((struct RObject*)(v))->tt), (v))
#define SET_CPTR_VALUE(mrb,r,v) BOXNAN_SET_OBJ_VALUE(r, MRB_TT_CPTR, v)
#ifdef MRB_64BIT
#define SET_CPTR_VALUE(mrb,r,v) ((r) = mrb_nan_boxing_cptr_value(mrb, v))
#else
#define SET_CPTR_VALUE(mrb,r,v) BOXNAN_SET_VALUE(r, MRB_TT_CPTR, value.p, v)
#endif
#define SET_UNDEF_VALUE(r) BOXNAN_SET_VALUE(r, MRB_TT_UNDEF, value.i, 0)
#endif /* MRUBY_BOXING_NAN_H */
+13 -11
View File
@@ -1,5 +1,5 @@
/*
** mruby/boxing_no.h - unboxed mrb_value definition
/**
** @file mruby/boxing_no.h - unboxed mrb_value definition
**
** See Copyright Notice in mruby.h
*/
@@ -8,17 +8,19 @@
#define MRUBY_BOXING_NO_H
#define MRB_FIXNUM_SHIFT 0
#define MRB_TT_HAS_BASIC MRB_TT_OBJECT
#define MRB_SYMBOL_SHIFT 0
union mrb_value_union {
#ifndef MRB_WITHOUT_FLOAT
mrb_float f;
#endif
void *p;
mrb_int i;
mrb_sym sym;
};
typedef struct mrb_value {
union {
#ifndef MRB_WITHOUT_FLOAT
mrb_float f;
#endif
void *p;
mrb_int i;
mrb_sym sym;
} value;
union mrb_value_union value;
enum mrb_vtype tt;
} mrb_value;
+110 -80
View File
@@ -1,5 +1,5 @@
/*
** mruby/boxing_word.h - word boxing mrb_value definition
/**
** @file mruby/boxing_word.h - word boxing mrb_value definition
**
** See Copyright Notice in mruby.h
*/
@@ -7,10 +7,6 @@
#ifndef MRUBY_BOXING_WORD_H
#define MRUBY_BOXING_WORD_H
#if defined(MRB_INT16)
# error MRB_INT16 is too small for MRB_WORD_BOXING.
#endif
#if defined(MRB_INT64) && !defined(MRB_64BIT)
#error MRB_INT64 cannot be used with MRB_WORD_BOXING in 32-bit mode.
#endif
@@ -22,48 +18,66 @@ struct RFloat {
};
#endif
struct RCptr {
MRB_OBJECT_HEADER;
void *p;
};
#define MRB_FIXNUM_SHIFT 1
#ifdef MRB_WITHOUT_FLOAT
#define MRB_TT_HAS_BASIC MRB_TT_CPTR
#else
#define MRB_TT_HAS_BASIC MRB_TT_FLOAT
#endif
enum mrb_special_consts {
MRB_Qnil = 0,
MRB_Qfalse = 2,
MRB_Qtrue = 4,
MRB_Qundef = 6,
MRB_Qnil = 0,
MRB_Qfalse = 4,
MRB_Qtrue = 12,
MRB_Qundef = 20,
};
#define MRB_FIXNUM_FLAG 0x01
#define MRB_SYMBOL_FLAG 0x0e
#define MRB_SPECIAL_SHIFT 8
#if defined(MRB_64BIT)
#define MRB_SYMBOL_BITSIZE (sizeof(mrb_sym) * CHAR_BIT)
#define MRB_SYMBOL_MAX UINT32_MAX
#if defined(MRB_64BIT) && defined(MRB_INT32)
#define MRB_FIXNUM_SHIFT 0
#else
#define MRB_SYMBOL_BITSIZE (sizeof(mrb_sym) * CHAR_BIT - MRB_SPECIAL_SHIFT)
#define MRB_SYMBOL_MAX (UINT32_MAX >> MRB_SPECIAL_SHIFT)
#define MRB_FIXNUM_SHIFT BOXWORD_FIXNUM_SHIFT
#endif
#define MRB_SYMBOL_SHIFT BOXWORD_SYMBOL_SHIFT
#define BOXWORD_FIXNUM_BIT_POS 1
#define BOXWORD_SYMBOL_BIT_POS 2
#define BOXWORD_FIXNUM_SHIFT BOXWORD_FIXNUM_BIT_POS
#ifdef MRB_64BIT
#define BOXWORD_SYMBOL_SHIFT 0
#else
#define BOXWORD_SYMBOL_SHIFT BOXWORD_SYMBOL_BIT_POS
#endif
#define BOXWORD_FIXNUM_FLAG (1 << (BOXWORD_FIXNUM_BIT_POS - 1))
#define BOXWORD_SYMBOL_FLAG (1 << (BOXWORD_SYMBOL_BIT_POS - 1))
#define BOXWORD_FIXNUM_MASK ((1 << BOXWORD_FIXNUM_BIT_POS) - 1)
#define BOXWORD_SYMBOL_MASK ((1 << BOXWORD_SYMBOL_BIT_POS) - 1)
#define BOXWORD_IMMEDIATE_MASK 0x07
#define BOXWORD_SHIFT_VALUE(o,n,t) \
(t)(((long)(o).w) >> BOXWORD_##n##_SHIFT)
#define BOXWORD_SET_SHIFT_VALUE(o,n,v) \
((o).w = (((unsigned long)(v)) << BOXWORD_##n##_SHIFT) | BOXWORD_##n##_FLAG)
#define BOXWORD_SHIFT_VALUE_P(o,n) \
(((o).w & BOXWORD_##n##_MASK) == BOXWORD_##n##_FLAG)
#define BOXWORD_OBJ_TYPE_P(o,n) \
(!mrb_immediate_p(o) && (o).value.bp->tt == MRB_TT_##n)
/*
* mrb_value representation:
*
* nil : ...0000 0000 (all bits are 0)
* false : ...0000 0100 (mrb_fixnum(v) != 0)
* true : ...0000 1100
* undef : ...0001 0100
* fixnum: ...IIII III1
* symbol: ...SSSS SS10 (use only upper 32-bit as symbol value on 64-bit CPU)
* object: ...PPPP P000 (any bits are 1)
*/
typedef union mrb_value {
union {
void *p;
#ifdef MRB_64BIT
/* use struct to avoid bit shift. */
struct {
unsigned int i_flag : MRB_FIXNUM_SHIFT;
mrb_int i : (MRB_INT_BIT - MRB_FIXNUM_SHIFT);
};
struct {
unsigned int sym_flag : MRB_SPECIAL_SHIFT;
mrb_sym sym : MRB_SYMBOL_BITSIZE;
MRB_ENDIAN_LOHI(
mrb_sym sym;
,uint32_t sym_flag;
)
};
#endif
struct RBasic *bp;
#ifndef MRB_WITHOUT_FLOAT
struct RFloat *fp;
@@ -88,57 +102,73 @@ MRB_API mrb_value mrb_word_boxing_float_pool(struct mrb_state*, mrb_float);
#ifndef MRB_WITHOUT_FLOAT
#define mrb_float(o) (o).value.fp->f
#endif
#define mrb_fixnum(o) ((mrb_int)(o).value.i)
#define mrb_fixnum(o) BOXWORD_SHIFT_VALUE(o, FIXNUM, mrb_int)
#ifdef MRB_64BIT
#define mrb_symbol(o) (o).value.sym
#else
#define mrb_symbol(o) BOXWORD_SHIFT_VALUE(o, SYMBOL, mrb_sym)
#endif
#define mrb_bool(o) (((o).w & ~(unsigned long)MRB_Qfalse) != 0)
static inline enum mrb_vtype
mrb_type(mrb_value o)
{
switch (o.w) {
case MRB_Qfalse:
case MRB_Qnil:
return MRB_TT_FALSE;
case MRB_Qtrue:
return MRB_TT_TRUE;
case MRB_Qundef:
return MRB_TT_UNDEF;
}
if (o.value.i_flag == MRB_FIXNUM_FLAG) {
return MRB_TT_FIXNUM;
}
if (o.value.sym_flag == MRB_SYMBOL_FLAG) {
return MRB_TT_SYMBOL;
}
return o.value.bp->tt;
}
#define mrb_bool(o) ((o).w != MRB_Qnil && (o).w != MRB_Qfalse)
#define mrb_fixnum_p(o) ((o).value.i_flag == MRB_FIXNUM_FLAG)
#define mrb_immediate_p(o) ((o).w & BOXWORD_IMMEDIATE_MASK || (o).w == MRB_Qnil)
#define mrb_fixnum_p(o) BOXWORD_SHIFT_VALUE_P(o, FIXNUM)
#ifdef MRB_64BIT
#define mrb_symbol_p(o) ((o).value.sym_flag == BOXWORD_SYMBOL_FLAG)
#else
#define mrb_symbol_p(o) BOXWORD_SHIFT_VALUE_P(o, SYMBOL)
#endif
#define mrb_undef_p(o) ((o).w == MRB_Qundef)
#define mrb_nil_p(o) ((o).w == MRB_Qnil)
#define BOXWORD_SET_VALUE(o, ttt, attr, v) do { \
switch (ttt) {\
case MRB_TT_FALSE: (o).w = (v) ? MRB_Qfalse : MRB_Qnil; break;\
case MRB_TT_TRUE: (o).w = MRB_Qtrue; break;\
case MRB_TT_UNDEF: (o).w = MRB_Qundef; break;\
case MRB_TT_FIXNUM: (o).w = 0;(o).value.i_flag = MRB_FIXNUM_FLAG; (o).attr = (v); break;\
case MRB_TT_SYMBOL: (o).w = 0;(o).value.sym_flag = MRB_SYMBOL_FLAG; (o).attr = (v); break;\
default: (o).w = 0; (o).attr = (v); if ((o).value.bp) (o).value.bp->tt = ttt; break;\
}\
} while (0)
#define mrb_false_p(o) ((o).w == MRB_Qfalse)
#define mrb_true_p(o) ((o).w == MRB_Qtrue)
#ifndef MRB_WITHOUT_FLOAT
#define mrb_float_p(o) BOXWORD_OBJ_TYPE_P(o, FLOAT)
#endif
#define mrb_array_p(o) BOXWORD_OBJ_TYPE_P(o, ARRAY)
#define mrb_string_p(o) BOXWORD_OBJ_TYPE_P(o, STRING)
#define mrb_hash_p(o) BOXWORD_OBJ_TYPE_P(o, HASH)
#define mrb_cptr_p(o) BOXWORD_OBJ_TYPE_P(o, CPTR)
#define mrb_exception_p(o) BOXWORD_OBJ_TYPE_P(o, EXCEPTION)
#define mrb_free_p(o) BOXWORD_OBJ_TYPE_P(o, FREE)
#define mrb_object_p(o) BOXWORD_OBJ_TYPE_P(o, OBJECT)
#define mrb_class_p(o) BOXWORD_OBJ_TYPE_P(o, CLASS)
#define mrb_module_p(o) BOXWORD_OBJ_TYPE_P(o, MODULE)
#define mrb_iclass_p(o) BOXWORD_OBJ_TYPE_P(o, ICLASS)
#define mrb_sclass_p(o) BOXWORD_OBJ_TYPE_P(o, SCLASS)
#define mrb_proc_p(o) BOXWORD_OBJ_TYPE_P(o, PROC)
#define mrb_range_p(o) BOXWORD_OBJ_TYPE_P(o, RANGE)
#define mrb_env_p(o) BOXWORD_OBJ_TYPE_P(o, ENV)
#define mrb_data_p(o) BOXWORD_OBJ_TYPE_P(o, DATA)
#define mrb_fiber_p(o) BOXWORD_OBJ_TYPE_P(o, FIBER)
#define mrb_istruct_p(o) BOXWORD_OBJ_TYPE_P(o, ISTRUCT)
#define mrb_break_p(o) BOXWORD_OBJ_TYPE_P(o, BREAK)
#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_INT_VALUE(r,n) BOXWORD_SET_VALUE(r, MRB_TT_FIXNUM, value.i, (n))
#define SET_SYM_VALUE(r,v) BOXWORD_SET_VALUE(r, MRB_TT_SYMBOL, value.sym, (v))
#define SET_OBJ_VALUE(r,v) BOXWORD_SET_VALUE(r, (((struct RObject*)(v))->tt), value.p, (v))
#define SET_UNDEF_VALUE(r) BOXWORD_SET_VALUE(r, MRB_TT_UNDEF, value.i, 0)
#define SET_UNDEF_VALUE(r) ((r).w = MRB_Qundef)
#define SET_NIL_VALUE(r) ((r).w = MRB_Qnil)
#define SET_FALSE_VALUE(r) ((r).w = MRB_Qfalse)
#define SET_TRUE_VALUE(r) ((r).w = MRB_Qtrue)
#define SET_BOOL_VALUE(r,b) ((b) ? SET_TRUE_VALUE(r) : SET_FALSE_VALUE(r))
#define SET_INT_VALUE(r,n) BOXWORD_SET_SHIFT_VALUE(r, FIXNUM, n)
#ifdef MRB_64BIT
#define SET_SYM_VALUE(r,v) ((r).value.sym = v, (r).value.sym_flag = BOXWORD_SYMBOL_FLAG)
#else
#define SET_SYM_VALUE(r,n) BOXWORD_SET_SHIFT_VALUE(r, SYMBOL, n)
#endif
#define SET_OBJ_VALUE(r,v) ((r).value.p = v)
MRB_INLINE enum mrb_vtype
mrb_type(mrb_value o)
{
return !mrb_bool(o) ? MRB_TT_FALSE :
mrb_true_p(o) ? MRB_TT_TRUE :
mrb_fixnum_p(o) ? MRB_TT_FIXNUM :
mrb_symbol_p(o) ? MRB_TT_SYMBOL :
mrb_undef_p(o) ? MRB_TT_UNDEF :
o.value.bp->tt;
}
#endif /* MRUBY_BOXING_WORD_H */
+14 -5
View File
@@ -1,5 +1,5 @@
/*
** mruby/class.h - Class class
/**
** @file mruby/class.h - Class class
**
** See Copyright Notice in mruby.h
*/
@@ -23,7 +23,7 @@ struct RClass {
#define mrb_class_ptr(v) ((struct RClass*)(mrb_ptr(v)))
static inline struct RClass*
MRB_INLINE struct RClass*
mrb_class(mrb_state *mrb, mrb_value v)
{
switch (mrb_type(v)) {
@@ -75,8 +75,8 @@ mrb_class(mrb_state *mrb, mrb_value v)
MRB_API struct RClass* mrb_define_class_id(mrb_state*, mrb_sym, struct RClass*);
MRB_API struct RClass* mrb_define_module_id(mrb_state*, mrb_sym);
MRB_API struct RClass *mrb_vm_define_class(mrb_state*, mrb_value, mrb_value, mrb_sym);
MRB_API struct RClass *mrb_vm_define_module(mrb_state*, mrb_value, mrb_sym);
struct RClass *mrb_vm_define_class(mrb_state*, mrb_value, mrb_value, mrb_sym);
struct RClass *mrb_vm_define_module(mrb_state*, mrb_value, mrb_sym);
MRB_API void mrb_define_method_raw(mrb_state*, struct RClass*, mrb_sym, mrb_method_t);
MRB_API void mrb_define_method_id(mrb_state *mrb, struct RClass *c, mrb_sym mid, mrb_func_t func, mrb_aspec aspec);
MRB_API void mrb_alias_method(mrb_state*, struct RClass *c, mrb_sym a, mrb_sym b);
@@ -85,13 +85,22 @@ MRB_API mrb_method_t mrb_method_search_vm(mrb_state*, struct RClass**, mrb_sym);
MRB_API mrb_method_t mrb_method_search(mrb_state*, struct RClass*, mrb_sym);
MRB_API struct RClass* mrb_class_real(struct RClass* cl);
mrb_value mrb_instance_new(mrb_state *mrb, mrb_value cv);
void mrb_class_name_class(mrb_state*, struct RClass*, struct RClass*, mrb_sym);
mrb_bool mrb_const_name_p(mrb_state*, const char*, mrb_int);
mrb_value mrb_class_find_path(mrb_state*, struct RClass*);
mrb_value mrb_mod_to_s(mrb_state*, mrb_value);
void mrb_gc_mark_mt(mrb_state*, struct RClass*);
size_t mrb_gc_mark_mt_size(mrb_state*, struct RClass*);
void mrb_gc_free_mt(mrb_state*, struct RClass*);
#ifdef MRB_METHOD_CACHE
void mrb_mc_clear_by_class(mrb_state *mrb, struct RClass* c);
#else
#define mrb_mc_clear_by_class(mrb,c)
#endif
MRB_END_DECL
#endif /* MRUBY_CLASS_H */
+19 -7
View File
@@ -1,5 +1,5 @@
/*
**"common.h - mruby common platform definition"
/**
** @file common.h - mruby common platform definition"
**
** See Copyright Notice in mruby.h
*/
@@ -54,14 +54,15 @@ MRB_BEGIN_DECL
#endif
/** Declare a function as always inlined. */
#if defined(_MSC_VER)
# define MRB_INLINE static __inline
#else
# define MRB_INLINE static inline
#if defined _MSC_VER && _MSC_VER < 1900
# ifndef __cplusplus
# define inline __inline
# endif
#endif
#define MRB_INLINE static inline
/** Declare a public MRuby API function. */
#ifndef MRB_API
#if defined(MRB_BUILD_AS_DLL)
#if defined(MRB_CORE) || defined(MRB_LIB)
# define MRB_API __declspec(dllexport)
@@ -71,6 +72,17 @@ MRB_BEGIN_DECL
#else
# define MRB_API extern
#endif
#endif
/** Declare mingw versions */
#if defined(__MINGW32__) || defined(__MINGW64__)
# include <_mingw.h>
# if defined(__MINGW64_VERSION_MAJOR)
# define MRB_MINGW64_VERSION (__MINGW64_VERSION_MAJOR * 1000 + __MINGW64_VERSION_MINOR)
# elif defined(__MINGW32_MAJOR_VERSION)
# define MRB_MINGW32_VERSION (__MINGW32_MAJOR_VERSION * 1000 + __MINGW32_MINOR_VERSION)
# endif
#endif
MRB_END_DECL
+18 -9
View File
@@ -1,5 +1,5 @@
/*
** mruby/compile.h - mruby parser
/**
** @file mruby/compile.h - mruby parser
**
** See Copyright Notice in mruby.h
*/
@@ -24,7 +24,7 @@ typedef struct mrbc_context {
mrb_sym *syms;
int slen;
char *filename;
short lineno;
uint16_t lineno;
int (*partial_hook)(struct mrb_parser_state*);
void *partial_data;
struct RClass *target_class;
@@ -33,7 +33,7 @@ typedef struct mrbc_context {
mrb_bool no_exec:1;
mrb_bool keep_lv:1;
mrb_bool no_optimize:1;
mrb_bool on_eval:1;
struct RProc *upper;
size_t parser_nerr;
} mrbc_context;
@@ -67,7 +67,7 @@ enum mrb_lex_state_enum {
/* saved error message */
struct mrb_parser_message {
int lineno;
uint16_t lineno;
int column;
char* message;
};
@@ -105,7 +105,7 @@ struct mrb_parser_heredoc_info {
mrb_ast_node *doc;
};
#define MRB_PARSER_TOKBUF_MAX 65536
#define MRB_PARSER_TOKBUF_MAX (UINT16_MAX-1)
#define MRB_PARSER_TOKBUF_SIZE 256
/* parser structure */
@@ -119,7 +119,7 @@ struct mrb_parser_state {
#endif
mrbc_context *cxt;
mrb_sym filename_sym;
int lineno;
uint16_t lineno;
int column;
enum mrb_lex_state_enum lstate;
@@ -151,8 +151,8 @@ struct mrb_parser_state {
mrb_ast_node *tree;
mrb_bool no_optimize:1;
mrb_bool on_eval:1;
mrb_bool capture_errors:1;
struct RProc *upper;
struct mrb_parser_message error_buffer[10];
struct mrb_parser_message warn_buffer[10];
@@ -161,6 +161,7 @@ struct mrb_parser_state {
uint16_t current_filename_index;
struct mrb_jmpbuf* jmp;
mrb_ast_node *nvars;
};
MRB_API struct mrb_parser_state* mrb_parser_new(mrb_state*);
@@ -179,7 +180,15 @@ MRB_API struct mrb_parser_state* mrb_parse_nstring(mrb_state*,const char*,size_t
MRB_API struct RProc* mrb_generate_code(mrb_state*, struct mrb_parser_state*);
MRB_API mrb_value mrb_load_exec(mrb_state *mrb, struct mrb_parser_state *p, mrbc_context *c);
/* program load functions */
/** program load functions
* Please note! Currently due to interactions with the GC calling these functions will
* leak one RProc object per function call.
* To prevent this save the current memory arena before calling and restore the arena
* right after, like so
* int ai = mrb_gc_arena_save(mrb);
* mrb_value status = mrb_load_string(mrb, buffer);
* mrb_gc_arena_restore(mrb, ai);
*/
#ifndef MRB_DISABLE_STDIO
MRB_API mrb_value mrb_load_file(mrb_state*,FILE*);
MRB_API mrb_value mrb_load_file_cxt(mrb_state*,FILE*, mrbc_context *cxt);
+5 -5
View File
@@ -1,5 +1,5 @@
/*
** mruby/data.h - Data class
/**
** @file mruby/data.h - Data class
**
** See Copyright Notice in mruby.h
*/
@@ -41,7 +41,7 @@ MRB_API struct RData *mrb_data_object_alloc(mrb_state *mrb, struct RClass* klass
#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)); \
(sval) = (strct *)mrb_malloc(mrb, sizeof(strct)); \
{ static const strct zero = { 0 }; *(sval) = zero; };\
(data_obj)->data = (sval);\
} while (0)
@@ -63,10 +63,10 @@ MRB_API void *mrb_data_check_get_ptr(mrb_state *mrb, mrb_value, const mrb_data_t
*(void**)&sval = mrb_data_get_ptr(mrb, obj, type); \
} while (0)
static inline void
MRB_INLINE void
mrb_data_init(mrb_value v, void *ptr, const mrb_data_type *type)
{
mrb_assert(mrb_type(v) == MRB_TT_DATA);
mrb_assert(mrb_data_p(v));
DATA_PTR(v) = ptr;
DATA_TYPE(v) = type;
}
+2 -2
View File
@@ -1,5 +1,5 @@
/*
** mruby/debug.h - mruby debug info
/**
** @file mruby/debug.h - mruby debug info
**
** See Copyright Notice in mruby.h
*/
+4 -24
View File
@@ -1,5 +1,5 @@
/*
** mruby/dump.h - mruby binary dumper (mrbc binary format)
/**
** @file mruby/dump.h - mruby binary dumper (mrbc binary format)
**
** See Copyright Notice in mruby.h
*/
@@ -17,10 +17,6 @@
MRB_BEGIN_DECL
#define DUMP_DEBUG_INFO 1
#define DUMP_ENDIAN_BIG 2
#define DUMP_ENDIAN_LIL 4
#define DUMP_ENDIAN_NAT 6
#define DUMP_ENDIAN_MASK 6
int mrb_dump_irep(mrb_state *mrb, mrb_irep *irep, uint8_t flags, uint8_t **bin, size_t *bin_size);
#ifndef MRB_DISABLE_STDIO
@@ -31,6 +27,7 @@ MRB_API mrb_value mrb_load_irep_file(mrb_state*,FILE*);
MRB_API mrb_value mrb_load_irep_file_cxt(mrb_state*, FILE*, mrbc_context*);
#endif
MRB_API mrb_irep *mrb_read_irep(mrb_state*, const uint8_t*);
MRB_API mrb_irep *mrb_read_irep_buf(mrb_state*, const void*, size_t);
/* dump/load error code
*
@@ -51,8 +48,7 @@ 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 "0006"
#define RITE_BINARY_FORMAT_VER "0007"
#define RITE_COMPILER_NAME "MATZ"
#define RITE_COMPILER_VERSION "0000"
@@ -60,7 +56,6 @@ MRB_API mrb_irep *mrb_read_irep(mrb_state*, const uint8_t*);
#define RITE_BINARY_EOF "END\0"
#define RITE_SECTION_IREP_IDENT "IREP"
#define RITE_SECTION_LINENO_IDENT "LINE"
#define RITE_SECTION_DEBUG_IDENT "DBG\0"
#define RITE_SECTION_LV_IDENT "LVAR"
@@ -92,10 +87,6 @@ struct rite_section_irep_header {
uint8_t rite_version[4]; /* Rite Instruction Specification Version */
};
struct rite_section_lineno_header {
RITE_SECTION_HEADER;
};
struct rite_section_debug_header {
RITE_SECTION_HEADER;
};
@@ -110,17 +101,6 @@ struct rite_binary_footer {
RITE_SECTION_HEADER;
};
static inline int
bigendian_p()
{
int i;
char *p;
i = 1;
p = (char*)&i;
return p[0]?0:1;
}
static inline size_t
uint8_to_bin(uint8_t s, uint8_t *bin)
{
+34 -6
View File
@@ -1,5 +1,5 @@
/*
** mruby/error.h - Exception class
/**
** @file mruby/error.h - Exception class
**
** See Copyright Notice in mruby.h
*/
@@ -32,23 +32,51 @@ MRB_API mrb_noreturn void mrb_no_method_error(mrb_state *mrb, mrb_sym id, mrb_va
/* declaration for `fail` method */
MRB_API mrb_value mrb_f_raise(mrb_state*, mrb_value);
#if defined(MRB_64BIT) || defined(MRB_USE_FLOAT) || defined(MRB_NAN_BOXING) || defined(MRB_WORD_BOXING)
struct RBreak {
MRB_OBJECT_HEADER;
struct RProc *proc;
mrb_value val;
};
#define mrb_break_value_get(brk) ((brk)->val)
#define mrb_break_value_set(brk, v) ((brk)->val = v)
#else
struct RBreak {
MRB_OBJECT_HEADER;
struct RProc *proc;
union mrb_value_union value;
};
#define RBREAK_VALUE_TT_MASK ((1 << 8) - 1)
static inline mrb_value
mrb_break_value_get(struct RBreak *brk)
{
mrb_value val;
val.value = brk->value;
val.tt = (enum mrb_vtype)(brk->flags & RBREAK_VALUE_TT_MASK);
return val;
}
static inline void
mrb_break_value_set(struct RBreak *brk, mrb_value val)
{
brk->value = val.value;
brk->flags &= ~RBREAK_VALUE_TT_MASK;
brk->flags |= val.tt;
}
#endif /* MRB_64BIT || MRB_USE_FLOAT || MRB_NAN_BOXING || MRB_WORD_BOXING */
#define mrb_break_proc_get(brk) ((brk)->proc)
#define mrb_break_proc_set(brk, p) ((brk)->proc = p)
/**
* Protect
*
* @mrbgem mruby-error
* Implemented in the mruby-error mrbgem
*/
MRB_API mrb_value mrb_protect(mrb_state *mrb, mrb_func_t body, mrb_value data, mrb_bool *state);
/**
* Ensure
*
* @mrbgem mruby-error
* Implemented in the mruby-error mrbgem
*/
MRB_API mrb_value mrb_ensure(mrb_state *mrb, mrb_func_t body, mrb_value b_data,
mrb_func_t ensure, mrb_value e_data);
@@ -56,7 +84,7 @@ MRB_API mrb_value mrb_ensure(mrb_state *mrb, mrb_func_t body, mrb_value b_data,
/**
* Rescue
*
* @mrbgem mruby-error
* Implemented in the mruby-error mrbgem
*/
MRB_API mrb_value mrb_rescue(mrb_state *mrb, mrb_func_t body, mrb_value b_data,
mrb_func_t rescue, mrb_value r_data);
@@ -64,7 +92,7 @@ MRB_API mrb_value mrb_rescue(mrb_state *mrb, mrb_func_t body, mrb_value b_data,
/**
* Rescue exception
*
* @mrbgem mruby-error
* Implemented in the mruby-error mrbgem
*/
MRB_API mrb_value mrb_rescue_exceptions(mrb_state *mrb, mrb_func_t body, mrb_value b_data,
mrb_func_t rescue, mrb_value r_data,
+2 -2
View File
@@ -1,5 +1,5 @@
/*
** mruby/gc.h - garbage collector for mruby
/**
** @file mruby/gc.h - garbage collector for mruby
**
** See Copyright Notice in mruby.h
*/
+4 -11
View File
@@ -1,5 +1,5 @@
/*
** mruby/hash.h - Hash class
/**
** @file mruby/hash.h - Hash class
**
** See Copyright Notice in mruby.h
*/
@@ -23,7 +23,7 @@ struct RHash {
#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_hash_new_capa(mrb_state *mrb, mrb_int capa);
MRB_API mrb_value mrb_ensure_hash_type(mrb_state *mrb, mrb_value hash);
MRB_API mrb_value mrb_check_hash_type(mrb_state *mrb, mrb_value hash);
@@ -95,7 +95,7 @@ MRB_API mrb_value mrb_hash_fetch(mrb_state *mrb, mrb_value hash, mrb_value key,
* @param mrb The mruby state reference.
* @param hash The target hash.
* @param key The key to delete.
* @return The deleted value.
* @return The deleted value. This value is not protected from GC. Use `mrb_gc_protect()` if necessary.
*/
MRB_API mrb_value mrb_hash_delete_key(mrb_state *mrb, mrb_value hash, mrb_value key);
@@ -197,13 +197,6 @@ MRB_API mrb_value mrb_hash_dup(mrb_state *mrb, mrb_value 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;
/* RHASH_TBL allocates st_table if not available. */
#define RHASH(obj) ((struct RHash*)(mrb_ptr(obj)))
#define RHASH_TBL(h) (RHASH(h)->ht)
+26 -4
View File
@@ -1,5 +1,5 @@
/*
** mruby/irep.h - mrb_irep structure
/**
** @file mruby/irep.h - mrb_irep structure
**
** See Copyright Notice in mruby.h
*/
@@ -32,7 +32,7 @@ typedef struct mrb_irep {
uint16_t nregs; /* Number of register variables */
uint8_t flags;
mrb_code *iseq;
const mrb_code *iseq;
mrb_value *pool;
mrb_sym *syms;
struct mrb_irep **reps;
@@ -49,12 +49,34 @@ typedef struct mrb_irep {
MRB_API mrb_irep *mrb_add_irep(mrb_state *mrb);
/** load mruby bytecode functions
* Please note! Currently due to interactions with the GC calling these functions will
* leak one RProc object per function call.
* To prevent this save the current memory arena before calling and restore the arena
* right after, like so
* int ai = mrb_gc_arena_save(mrb);
* mrb_value status = mrb_load_irep(mrb, buffer);
* mrb_gc_arena_restore(mrb, ai);
*/
/* @param [const uint8_t*] irep code, expected as a literal */
MRB_API mrb_value mrb_load_irep(mrb_state*, const uint8_t*);
/*
* @param [const void*] irep code
* @param [size_t] size of irep buffer. If -1 is given, it is considered unrestricted.
*/
MRB_API mrb_value mrb_load_irep_buf(mrb_state*, const void*, size_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*);
/*
* @param [const void*] irep code
* @param [size_t] size of irep buffer. If -1 is given, it is considered unrestricted.
*/
MRB_API mrb_value mrb_load_irep_buf_cxt(mrb_state*, const void*, size_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*);
@@ -68,7 +90,7 @@ struct mrb_insn_data {
uint8_t c;
};
struct mrb_insn_data mrb_decode_insn(mrb_code *pc);
struct mrb_insn_data mrb_decode_insn(const mrb_code *pc);
MRB_END_DECL
+8 -5
View File
@@ -1,5 +1,5 @@
/*
** mruby/istruct.h - Inline structures
/**
** @file mruby/istruct.h - Inline structures
**
** See Copyright Notice in mruby.h
*/
@@ -19,12 +19,15 @@ MRB_BEGIN_DECL
#define ISTRUCT_DATA_SIZE (sizeof(void*) * 3)
struct RIstruct {
struct RIStruct {
MRB_OBJECT_HEADER;
char inline_data[ISTRUCT_DATA_SIZE];
union {
intptr_t inline_alignment[3];
char inline_data[ISTRUCT_DATA_SIZE];
};
};
#define RISTRUCT(obj) ((struct RIstruct*)(mrb_ptr(obj)))
#define RISTRUCT(obj) ((struct RIStruct*)(mrb_ptr(obj)))
#define ISTRUCT_PTR(obj) (RISTRUCT(obj)->inline_data)
MRB_INLINE mrb_int mrb_istruct_size()
+25 -7
View File
@@ -1,5 +1,5 @@
/*
** mruby/khash.c - Hash for mruby
/**
** @file mruby/khash.h - Hash for mruby
**
** See Copyright Notice in mruby.h
*/
@@ -73,6 +73,7 @@ static const uint8_t __m_either[] = {0x03, 0x0c, 0x30, 0xc0};
void kh_clear_##name(mrb_state *mrb, kh_##name##_t *h); \
khint_t kh_get_##name(mrb_state *mrb, kh_##name##_t *h, khkey_t key); \
khint_t kh_put_##name(mrb_state *mrb, kh_##name##_t *h, khkey_t key, int *ret); \
void kh_put_prepare_##name(mrb_state *mrb, kh_##name##_t *h); \
void kh_resize_##name(mrb_state *mrb, kh_##name##_t *h, khint_t new_n_buckets); \
void kh_del_##name(mrb_state *mrb, kh_##name##_t *h, khint_t x); \
kh_##name##_t *kh_copy_##name(mrb_state *mrb, kh_##name##_t *h);
@@ -95,16 +96,25 @@ kh_fill_flags(uint8_t *p, uint8_t c, size_t len)
__hash_equal: hash comparation function
*/
#define KHASH_DEFINE(name, khkey_t, khval_t, kh_is_map, __hash_func, __hash_equal) \
void kh_alloc_##name(mrb_state *mrb, kh_##name##_t *h) \
mrb_noreturn void mrb_raise_nomemory(mrb_state *mrb); \
int kh_alloc_simple_##name(mrb_state *mrb, kh_##name##_t *h) \
{ \
khint_t sz = h->n_buckets; \
size_t len = sizeof(khkey_t) + (kh_is_map ? sizeof(khval_t) : 0); \
uint8_t *p = (uint8_t*)mrb_malloc(mrb, sizeof(uint8_t)*sz/4+len*sz); \
uint8_t *p = (uint8_t*)mrb_malloc_simple(mrb, sizeof(uint8_t)*sz/4+len*sz); \
if (!p) { return 1; } \
h->size = h->n_occupied = 0; \
h->keys = (khkey_t *)p; \
h->vals = kh_is_map ? (khval_t *)(p+sizeof(khkey_t)*sz) : NULL; \
h->ed_flags = p+len*sz; \
kh_fill_flags(h->ed_flags, 0xaa, sz/4); \
return 0; \
} \
void kh_alloc_##name(mrb_state *mrb, kh_##name##_t *h) \
{ \
if (kh_alloc_simple_##name(mrb, h)) { \
mrb_raise_nomemory(mrb); \
} \
} \
kh_##name##_t *kh_init_##name##_size(mrb_state *mrb, khint_t size) { \
kh_##name##_t *h = (kh_##name##_t*)mrb_calloc(mrb, 1, sizeof(kh_##name##_t)); \
@@ -112,7 +122,10 @@ kh_fill_flags(uint8_t *p, uint8_t c, size_t len)
size = KHASH_MIN_SIZE; \
khash_power2(size); \
h->n_buckets = size; \
kh_alloc_##name(mrb, h); \
if (kh_alloc_simple_##name(mrb, h)) { \
mrb_free(mrb, h); \
mrb_raise_nomemory(mrb); \
} \
return h; \
} \
kh_##name##_t *kh_init_##name(mrb_state *mrb) { \
@@ -171,12 +184,16 @@ kh_fill_flags(uint8_t *p, uint8_t c, size_t len)
mrb_free(mrb, old_keys); \
} \
} \
khint_t kh_put_##name(mrb_state *mrb, kh_##name##_t *h, khkey_t key, int *ret) \
void kh_put_prepare_##name(mrb_state *mrb, kh_##name##_t *h) \
{ \
khint_t k, del_k, step = 0; \
if (h->n_occupied >= khash_upper_bound(h)) { \
kh_resize_##name(mrb, h, h->n_buckets*2); \
} \
} \
khint_t kh_put_##name(mrb_state *mrb, kh_##name##_t *h, khkey_t key, int *ret) \
{ \
khint_t k, del_k, step = 0; \
kh_put_prepare_##name(mrb, h); \
k = __hash_func(mrb,key) & khash_mask(h); \
del_k = kh_end(h); \
while (!__ac_isempty(h->ed_flags, k)) { \
@@ -239,6 +256,7 @@ kh_fill_flags(uint8_t *p, uint8_t c, size_t len)
#define kh_destroy(name, mrb, h) kh_destroy_##name(mrb, h)
#define kh_clear(name, mrb, h) kh_clear_##name(mrb, h)
#define kh_resize(name, mrb, h, s) kh_resize_##name(mrb, h, s)
#define kh_put_prepare(name, mrb, h) kh_put_prepare_##name(mrb, h)
#define kh_put(name, mrb, h, k) kh_put_##name(mrb, h, k, NULL)
#define kh_put2(name, mrb, h, k, r) kh_put_##name(mrb, h, k, r)
#define kh_get(name, mrb, h, k) kh_get_##name(mrb, h, k)
+42 -7
View File
@@ -1,5 +1,5 @@
/*
** mruby/numeric.h - Numeric, Integer, Float, Fixnum class
/**
** @file mruby/numeric.h - Numeric, Integer, Float, Fixnum class
**
** See Copyright Notice in mruby.h
*/
@@ -23,7 +23,11 @@ MRB_BEGIN_DECL
#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)
#ifdef MRB_INT64
#define FIXABLE_FLOAT(f) ((f)>=-9223372036854775808.0 && (f)<9223372036854775808.0)
#else
#define FIXABLE_FLOAT(f) TYPED_FIXABLE(f,mrb_float)
#endif
#endif
#ifndef MRB_WITHOUT_FLOAT
@@ -33,13 +37,14 @@ 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 int mrb_float_to_cstr(mrb_state *mrb, char *buf, size_t len, const char *fmt, mrb_float f);
MRB_API mrb_float mrb_to_flo(mrb_state *mrb, mrb_value x);
MRB_API mrb_value mrb_int_value(mrb_state *mrb, mrb_float f);
#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);
mrb_value mrb_fixnum_mul(mrb_state *mrb, mrb_value x, mrb_value y);
mrb_value mrb_num_div(mrb_state *mrb, mrb_value x, mrb_value y);
MRB_API mrb_value mrb_num_plus(mrb_state *mrb, mrb_value x, mrb_value y);
MRB_API mrb_value mrb_num_minus(mrb_state *mrb, mrb_value x, mrb_value y);
MRB_API mrb_value mrb_num_mul(mrb_state *mrb, mrb_value x, mrb_value y);
#ifndef __has_builtin
#define __has_builtin(x) 0
@@ -156,6 +161,36 @@ mrb_int_mul_overflow(mrb_int multiplier, mrb_int multiplicand, mrb_int *product)
#endif
#ifndef MRB_WITHOUT_FLOAT
# include <stdint.h>
# include <float.h>
# define MRB_FLT_RADIX FLT_RADIX
# ifdef MRB_USE_FLOAT
# define MRB_FLT_MANT_DIG FLT_MANT_DIG
# define MRB_FLT_EPSILON FLT_EPSILON
# define MRB_FLT_DIG FLT_DIG
# define MRB_FLT_MIN_EXP FLT_MIN_EXP
# define MRB_FLT_MIN FLT_MIN
# define MRB_FLT_MIN_10_EXP FLT_MIN_10_EXP
# define MRB_FLT_MAX_EXP FLT_MAX_EXP
# define MRB_FLT_MAX FLT_MAX
# define MRB_FLT_MAX_10_EXP FLT_MAX_10_EXP
# else /* not MRB_USE_FLOAT */
# define MRB_FLT_MANT_DIG DBL_MANT_DIG
# define MRB_FLT_EPSILON DBL_EPSILON
# define MRB_FLT_DIG DBL_DIG
# define MRB_FLT_MIN_EXP DBL_MIN_EXP
# define MRB_FLT_MIN DBL_MIN
# define MRB_FLT_MIN_10_EXP DBL_MIN_10_EXP
# define MRB_FLT_MAX_EXP DBL_MAX_EXP
# define MRB_FLT_MAX DBL_MAX
# define MRB_FLT_MAX_10_EXP DBL_MAX_10_EXP
# endif /* MRB_USE_FLOAT */
#endif /* MRB_WITHOUT_FLOAT */
MRB_END_DECL
#endif /* MRUBY_NUMERIC_H */
+8 -9
View File
@@ -1,5 +1,5 @@
/*
** mruby/object.h - mruby object definition
/**
** @file mruby/object.h - mruby object definition
**
** See Copyright Notice in mruby.h
*/
@@ -8,15 +8,14 @@
#define MRUBY_OBJECT_H
#define MRB_OBJECT_HEADER \
enum mrb_vtype tt:8;\
uint32_t color:3;\
uint32_t flags:21;\
struct RClass *c;\
struct RBasic *gcnext
struct RClass *c; \
struct RBasic *gcnext; \
enum mrb_vtype tt:8; \
uint32_t color:3; \
uint32_t flags:21
#define MRB_FLAG_TEST(obj, flag) ((obj)->flags & (flag))
struct RBasic {
MRB_OBJECT_HEADER;
};
@@ -26,6 +25,7 @@ struct RBasic {
#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)
#define mrb_frozen_p(o) MRB_FROZEN_P(o)
struct RObject {
MRB_OBJECT_HEADER;
@@ -33,7 +33,6 @@ struct RObject {
};
#define mrb_obj_ptr(v) ((struct RObject*)(mrb_ptr(v)))
#define mrb_immediate_p(x) (mrb_type(x) < MRB_TT_HAS_BASIC)
#define mrb_special_const_p(x) mrb_immediate_p(x)
struct RFiber {
+2 -2
View File
@@ -1,5 +1,5 @@
/*
** mruby/opcode.h - RiteVM operation codes
/**
** @file mruby/opcode.h - RiteVM operation codes
**
** See Copyright Notice in mruby.h
*/
+9 -8
View File
@@ -45,9 +45,9 @@ 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(JMPIF, BS) /* if R(a) pc=b */
OPCODE(JMPNOT, BS) /* if !R(a) pc=b */
OPCODE(JMPNIL, BS) /* if R(a)==nil pc=b */
OPCODE(ONERR, S) /* rescue_push(a) */
OPCODE(EXCEPT, B) /* R(a) = exc */
OPCODE(RESCUE, BB) /* R(b) = R(a).isa?(R(b)) */
@@ -58,7 +58,7 @@ 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(SENDB, BBB) /* R(a) = call(R(a),Syms(b),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) */
@@ -71,9 +71,9 @@ 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(ADDI, BB) /* R(a) = R(a)+mrb_int(b) */
OPCODE(SUB, B) /* R(a) = R(a)-R(a+1) */
OPCODE(SUBI, BB) /* R(a) = R(a)-C */
OPCODE(SUBI, BB) /* R(a) = R(a)-mrb_int(b) */
OPCODE(MUL, B) /* R(a) = R(a)*R(a+1) */
OPCODE(DIV, B) /* R(a) = R(a)/R(a+1) */
OPCODE(EQ, B) /* R(a) = R(a)==R(a+1) */
@@ -92,8 +92,8 @@ 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(HASH, BB) /* R(a) = hash_new(R(a),R(a+1)..R(a+b*2-1)) */
OPCODE(HASHADD, BB) /* R(a) = hash_push(R(a),R(a+1)..R(a+b*2)) */
OPCODE(HASHCAT, B) /* R(a) = hash_cat(R(a),R(a+1)) */
OPCODE(LAMBDA, BB) /* R(a) = lambda(SEQ[b],L_LAMBDA) */
OPCODE(BLOCK, BB) /* R(a) = lambda(SEQ[b],L_BLOCK) */
@@ -115,3 +115,4 @@ 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 */
OPCODE(LOADI16, BS) /* R(a) = mrb_int(b) */
+32 -21
View File
@@ -1,5 +1,5 @@
/*
** mruby/proc.h - Proc class
/**
** @file mruby/proc.h - Proc class
**
** See Copyright Notice in mruby.h
*/
@@ -22,14 +22,19 @@ struct REnv {
mrb_sym mid;
};
/* 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))
/* flags (21bits): 1(close):1(touched):1(heap):8(cioff/bidx):8(stack_len) */
#define MRB_ENV_SET_LEN(e,len) ((e)->flags = (((e)->flags & ~0xff)|((unsigned int)(len) & 0xff)))
#define MRB_ENV_LEN(e) ((mrb_int)((e)->flags & 0xff))
#define MRB_ENV_CLOSED (1<<20)
#define MRB_ENV_TOUCHED (1<<19)
#define MRB_ENV_HEAPED (1<<18)
#define MRB_ENV_CLOSE(e) ((e)->flags |= MRB_ENV_CLOSED)
#define MRB_ENV_TOUCH(e) ((e)->flags |= MRB_ENV_TOUCHED)
#define MRB_ENV_HEAP(e) ((e)->flags |= MRB_ENV_HEAPED)
#define MRB_ENV_HEAP_P(e) ((e)->flags & MRB_ENV_HEAPED)
#define MRB_ENV_ONSTACK_P(e) (((e)->flags & MRB_ENV_CLOSED) == 0)
#define MRB_ENV_BIDX(e) (((e)->flags >> 8) & 0xff)
#define MRB_ENV_SET_BIDX(e,idx) ((e)->flags = (((e)->flags & ~(0xff<<8))|((unsigned int)(idx) & 0xff)<<10))
void mrb_env_unshare(mrb_state*, struct REnv*);
@@ -86,38 +91,44 @@ struct RProc *mrb_closure_new(mrb_state*, mrb_irep*);
MRB_API struct RProc *mrb_proc_new_cfunc(mrb_state*, mrb_func_t);
MRB_API struct RProc *mrb_closure_new_cfunc(mrb_state *mrb, mrb_func_t func, int nlocals);
void mrb_proc_copy(struct RProc *a, struct RProc *b);
mrb_int mrb_proc_arity(const struct RProc *p);
/* implementation of #send method */
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*);
MRB_API mrb_value mrb_proc_cfunc_env_get(mrb_state*, mrb_int);
MRB_API struct RProc *mrb_proc_new_cfunc_with_env(mrb_state *mrb, mrb_func_t func, mrb_int argc, const mrb_value *argv);
MRB_API mrb_value mrb_proc_cfunc_env_get(mrb_state *mrb, mrb_int idx);
/* 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 1
#define MRB_METHOD_NOARG_FL 2
#ifndef MRB_METHOD_T_STRUCT
#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_NOARG_P(m) (((uintptr_t)(m))&MRB_METHOD_NOARG_FL)
#define MRB_METHOD_NOARG_SET(m) ((m)=(mrb_method_t)(((uintptr_t)(m))|MRB_METHOD_NOARG_FL))
#define MRB_METHOD_FUNC(m) ((mrb_func_t)((uintptr_t)(m)>>2))
#define MRB_METHOD_FROM_FUNC(m,fn) ((m)=(mrb_method_t)((((uintptr_t)(fn))<<2)|MRB_METHOD_FUNC_FL))
#define MRB_METHOD_FROM_PROC(m,pr) ((m)=(mrb_method_t)(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_P(m) ((m).flags&MRB_METHOD_FUNC_FL)
#define MRB_METHOD_NOARG_P(m) ((m).flags&MRB_METHOD_NOARG_FL)
#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_NOARG_SET(m) do{(m).flags|=MRB_METHOD_NOARG_FL;}while(0)
#define MRB_METHOD_FROM_FUNC(m,fn) do{(m).flags=MRB_METHOD_FUNC_FL;(m).func=(fn);}while(0)
#define MRB_METHOD_FROM_PROC(m,pr) do{(m).flags=0;(m).proc=(pr);}while(0)
#define MRB_METHOD_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 */
#endif /* MRB_METHOD_T_STRUCT */
#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))
+10 -4
View File
@@ -1,5 +1,5 @@
/*
** mruby/range.h - Range class
/**
** @file mruby/range.h - Range class
**
** See Copyright Notice in mruby.h
*/
@@ -14,7 +14,7 @@
*/
MRB_BEGIN_DECL
#if defined(MRB_NAN_BOXING) || defined(MRB_WORD_BOXING)
#if defined(MRB_NAN_BOXING) && defined(MRB_64BIT) || defined(MRB_WORD_BOXING)
# define MRB_RANGE_EMBED
#endif
@@ -64,7 +64,13 @@ MRB_API struct RRange* mrb_range_ptr(mrb_state *mrb, mrb_value range);
*/
MRB_API mrb_value mrb_range_new(mrb_state *mrb, mrb_value start, mrb_value end, mrb_bool exclude);
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);
enum mrb_range_beg_len {
MRB_RANGE_TYPE_MISMATCH = 0, /* (failure) not range */
MRB_RANGE_OK = 1, /* (success) range */
MRB_RANGE_OUT = 2 /* (failure) out of range */
};
MRB_API enum mrb_range_beg_len 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);
+2 -2
View File
@@ -1,5 +1,5 @@
/*
** mruby/re.h - Regexp class
/**
** @file mruby/re.h - Regexp class
**
** See Copyright Notice in mruby.h
*/
+133 -109
View File
@@ -1,5 +1,5 @@
/*
** mruby/string.h - String class
/**
** @file mruby/string.h - String class
**
** See Copyright Notice in mruby.h
*/
@@ -16,23 +16,30 @@ MRB_BEGIN_DECL
extern const char mrb_digitmap[];
#define RSTRING_EMBED_LEN_MAX ((mrb_int)(sizeof(void*) * 3 - 1))
#define RSTRING_EMBED_LEN_MAX \
((mrb_int)(sizeof(void*) * 3 + sizeof(void*) - 32 / CHAR_BIT - 1))
struct RString {
MRB_OBJECT_HEADER;
union {
struct {
mrb_int len;
mrb_ssize len;
union {
mrb_int capa;
mrb_ssize capa;
struct mrb_shared_string *shared;
struct RString *fshared;
} aux;
char *ptr;
} heap;
char ary[RSTRING_EMBED_LEN_MAX + 1];
} as;
};
struct RStringEmbed {
MRB_OBJECT_HEADER;
char ary[];
};
#define RSTR_SET_TYPE_FLAG(s, type) (RSTR_UNSET_TYPE_FLAG(s), (s)->flags |= MRB_STR_##type)
#define RSTR_UNSET_TYPE_FLAG(s) ((s)->flags &= ~(MRB_STR_TYPE_MASK|MRB_STR_EMBED_LEN_MASK))
#define RSTR_EMBED_P(s) ((s)->flags & MRB_STR_EMBED)
#define RSTR_SET_EMBED_FLAG(s) ((s)->flags |= MRB_STR_EMBED)
@@ -47,12 +54,15 @@ struct RString {
RSTR_SET_EMBED_LEN((s),(n));\
}\
else {\
(s)->as.heap.len = (mrb_int)(n);\
(s)->as.heap.len = (mrb_ssize)(n);\
}\
} while (0)
#define RSTR_EMBED_PTR(s) (((struct RStringEmbed*)(s))->ary)
#define RSTR_EMBED_LEN(s)\
(mrb_int)(((s)->flags & MRB_STR_EMBED_LEN_MASK) >> MRB_STR_EMBED_LEN_SHIFT)
#define RSTR_PTR(s) ((RSTR_EMBED_P(s)) ? (s)->as.ary : (s)->as.heap.ptr)
#define RSTR_EMBEDDABLE_P(len) ((len) <= RSTRING_EMBED_LEN_MAX)
#define RSTR_PTR(s) ((RSTR_EMBED_P(s)) ? RSTR_EMBED_PTR(s) : (s)->as.heap.ptr)
#define RSTR_LEN(s) ((RSTR_EMBED_P(s)) ? RSTR_EMBED_LEN(s) : (s)->as.heap.len)
#define RSTR_CAPA(s) (RSTR_EMBED_P(s) ? RSTRING_EMBED_LEN_MAX : (s)->as.heap.aux.capa)
@@ -68,10 +78,24 @@ struct RString {
#define RSTR_SET_NOFREE_FLAG(s) ((s)->flags |= MRB_STR_NOFREE)
#define RSTR_UNSET_NOFREE_FLAG(s) ((s)->flags &= ~MRB_STR_NOFREE)
#ifdef MRB_UTF8_STRING
# define RSTR_ASCII_P(s) ((s)->flags & MRB_STR_ASCII)
# define RSTR_SET_ASCII_FLAG(s) ((s)->flags |= MRB_STR_ASCII)
# define RSTR_UNSET_ASCII_FLAG(s) ((s)->flags &= ~MRB_STR_ASCII)
# define RSTR_WRITE_ASCII_FLAG(s, v) (RSTR_UNSET_ASCII_FLAG(s), (s)->flags |= v)
# define RSTR_COPY_ASCII_FLAG(dst, src) RSTR_WRITE_ASCII_FLAG(dst, RSTR_ASCII_P(src))
#else
# define RSTR_ASCII_P(s) (void)0
# define RSTR_SET_ASCII_FLAG(s) (void)0
# define RSTR_UNSET_ASCII_FLAG(s) (void)0
# define RSTR_WRITE_ASCII_FLAG(s, v) (void)0
# define RSTR_COPY_ASCII_FLAG(dst, src) (void)0
#endif
#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
*/
#define mrb_str_ptr(s) ((struct RString*)(mrb_ptr(s)))
@@ -82,32 +106,38 @@ struct RString {
#define RSTRING_CAPA(s) RSTR_CAPA(RSTRING(s))
#define RSTRING_END(s) (RSTRING_PTR(s) + RSTRING_LEN(s))
MRB_API mrb_int mrb_str_strlen(mrb_state*, struct RString*);
#define RSTRING_CSTR(mrb,s) mrb_string_cstr(mrb, s)
#define MRB_STR_SHARED 1
#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 8 /* type flags up to here */
#define MRB_STR_POOL 16 /* status flags from here */
#define MRB_STR_ASCII 32
#define MRB_STR_EMBED_LEN_SHIFT 6
#define MRB_STR_EMBED_LEN_BIT 5
#define MRB_STR_EMBED_LEN_MASK (((1 << MRB_STR_EMBED_LEN_BIT) - 1) << MRB_STR_EMBED_LEN_SHIFT)
#define MRB_STR_TYPE_MASK (MRB_STR_POOL - 1)
void mrb_gc_free_str(mrb_state*, struct RString*);
MRB_API void mrb_str_modify(mrb_state*, struct RString*);
/*
MRB_API void mrb_str_modify(mrb_state *mrb, struct RString *s);
/* mrb_str_modify() with keeping ASCII flag if set */
MRB_API void mrb_str_modify_keep_ascii(mrb_state *mrb, struct RString *s);
/**
* 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);
MRB_API mrb_int mrb_str_index(mrb_state *mrb, mrb_value str, const char *p, mrb_int len, mrb_int offset);
#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:
* Example:
*
* !!!c
* int
* main(int argc,
* char **argv)
@@ -129,32 +159,30 @@ MRB_API mrb_int mrb_str_index(mrb_state*, mrb_value, const char*, mrb_int, mrb_i
* // Concatenates str2 to str1.
* mrb_str_concat(mrb, str1, str2);
*
* // Prints new Concatenated Ruby string.
* mrb_p(mrb, str1);
* // Prints new Concatenated Ruby string.
* mrb_p(mrb, str1);
*
* mrb_close(mrb);
* return 0;
* }
* mrb_close(mrb);
* return 0;
* }
*
*
* Result:
* Result:
*
* => "abcdef"
*
* @param [mrb_state] mrb The current mruby state.
* @param [mrb_value] self String to concatenate.
* @param [mrb_value] other String to append to self.
* @param mrb The current mruby state.
* @param self String to concatenate.
* @param other String to append to self.
* @return [mrb_value] Returns a new String appending other to self.
*/
MRB_API void mrb_str_concat(mrb_state*, mrb_value, mrb_value);
MRB_API void mrb_str_concat(mrb_state *mrb, mrb_value self, mrb_value other);
/*
/**
* Adds two strings together.
*
*
* Example:
* Example:
*
* !!!c
* int
* main(int argc,
* char **argv)
@@ -181,52 +209,51 @@ MRB_API void mrb_str_concat(mrb_state*, mrb_value, mrb_value);
* // Concatenates both Ruby strings.
* c = mrb_str_plus(mrb, a, b);
*
* // Prints new Concatenated Ruby string.
* mrb_p(mrb, c);
* // Prints new Concatenated Ruby string.
* mrb_p(mrb, c);
*
* mrb_close(mrb);
* return 0;
* }
* mrb_close(mrb);
* return 0;
* }
*
*
* Result:
* Result:
*
* => "abc" # First string
* => "def" # Second string
* => "abcdef" # First & Second concatenated.
*
* @param [mrb_state] mrb The current mruby state.
* @param [mrb_value] a First string to concatenate.
* @param [mrb_value] b Second string to concatenate.
* @param mrb The current mruby state.
* @param a First string to concatenate.
* @param b Second string to concatenate.
* @return [mrb_value] Returns a new String containing a concatenated to b.
*/
MRB_API mrb_value mrb_str_plus(mrb_state*, mrb_value, mrb_value);
MRB_API mrb_value mrb_str_plus(mrb_state *mrb, mrb_value a, mrb_value b);
/*
/**
* Converts pointer into a Ruby string.
*
* @param [mrb_state] mrb The current mruby state.
* @param [void*] p The pointer to convert to Ruby string.
* @param mrb The current mruby state.
* @param p The pointer to convert to Ruby string.
* @return [mrb_value] Returns a new Ruby String.
*/
MRB_API mrb_value mrb_ptr_to_str(mrb_state *, void*);
MRB_API mrb_value mrb_ptr_to_str(mrb_state *mrb, void *p);
/*
/**
* Returns an object as a Ruby string.
*
* @param [mrb_state] mrb The current mruby state.
* @param [mrb_value] obj An object to return as a Ruby string.
* @param mrb The current mruby state.
* @param obj An object to return as a Ruby string.
* @return [mrb_value] An object as a Ruby string.
*/
MRB_API mrb_value mrb_obj_as_string(mrb_state *mrb, mrb_value obj);
/*
/**
* Resizes the string's length. Returns the amount of characters
* in the specified by len.
*
* Example:
*
* !!!c
* int
* main(int argc,
* char **argv)
@@ -251,21 +278,20 @@ MRB_API mrb_value mrb_obj_as_string(mrb_state *mrb, mrb_value obj);
*
* Result:
*
* => "Hello"
* => "Hello"
*
* @param [mrb_state] mrb The current mruby state.
* @param [mrb_value] str The Ruby string to resize.
* @param [mrb_value] len The length.
* @param mrb The current mruby state.
* @param str The Ruby string to resize.
* @param len The length.
* @return [mrb_value] An object as a Ruby string.
*/
MRB_API mrb_value mrb_str_resize(mrb_state *mrb, mrb_value str, mrb_int len);
/*
/**
* Returns a sub string.
*
* Example:
* Example:
*
* !!!c
* int
* main(int argc,
* char const **argv)
@@ -291,24 +317,24 @@ MRB_API mrb_value mrb_str_resize(mrb_state *mrb, mrb_value str, mrb_int len);
* return 0;
* }
*
* Result:
* Result:
*
* => "He"
*
* @param [mrb_state] mrb The current mruby state.
* @param [mrb_value] str Ruby string.
* @param [mrb_int] beg The beginning point of the sub-string.
* @param [mrb_int] len The end point of the sub-string.
* @param mrb The current mruby state.
* @param str Ruby string.
* @param beg The beginning point of the sub-string.
* @param len The end point of the sub-string.
* @return [mrb_value] An object as a Ruby sub-string.
*/
MRB_API mrb_value mrb_str_substr(mrb_state *mrb, mrb_value str, mrb_int beg, mrb_int len);
/*
/**
* Returns a Ruby string type.
*
*
* @param [mrb_state] mrb The current mruby state.
* @param [mrb_value] str Ruby string.
* @param mrb The current mruby state.
* @param str Ruby string.
* @return [mrb_value] A Ruby string.
*/
MRB_API mrb_value mrb_ensure_string_type(mrb_state *mrb, mrb_value str);
@@ -320,33 +346,30 @@ MRB_API mrb_value mrb_string_type(mrb_state *mrb, mrb_value str);
MRB_API mrb_value mrb_str_new_capa(mrb_state *mrb, size_t capa);
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);
/* NULL terminated C string from mrb_value */
MRB_API const char *mrb_string_cstr(mrb_state *mrb, mrb_value str);
/* NULL terminated C string from mrb_value; `str` will be updated */
MRB_API const char *mrb_string_value_cstr(mrb_state *mrb, mrb_value *str);
/* obslete: use RSTRING_PTR() */
MRB_API const char *mrb_string_value_ptr(mrb_state *mrb, mrb_value str);
/*
* Returns the length of the Ruby string.
*
*
* @param [mrb_state] mrb The current mruby state.
* @param [mrb_value] str Ruby string.
* @return [mrb_int] The length of the passed in Ruby string.
*/
/* obslete: use RSTRING_LEN() */
MRB_API mrb_int mrb_string_value_len(mrb_state *mrb, mrb_value str);
/*
/**
* Duplicates a string object.
*
*
* @param [mrb_state] mrb The current mruby state.
* @param [mrb_value] str Ruby string.
* @param mrb The current mruby state.
* @param str Ruby string.
* @return [mrb_value] Duplicated Ruby string.
*/
MRB_API mrb_value mrb_str_dup(mrb_state *mrb, mrb_value str);
/*
/**
* Returns a symbol from a passed in Ruby string.
*
* @param [mrb_state] mrb The current mruby state.
* @param [mrb_value] self Ruby string.
* @param mrb The current mruby state.
* @param self Ruby string.
* @return [mrb_value] A symbol.
*/
MRB_API mrb_value mrb_str_intern(mrb_state *mrb, mrb_value self);
@@ -356,40 +379,40 @@ MRB_API mrb_value mrb_cstr_to_inum(mrb_state *mrb, const char *s, mrb_int base,
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);
/*
/**
* Returns true if the strings match and false if the strings don't match.
*
* @param [mrb_state] mrb The current mruby state.
* @param [mrb_value] str1 Ruby string to compare.
* @param [mrb_value] str2 Ruby string to compare.
* @param mrb The current mruby state.
* @param str1 Ruby string to compare.
* @param str2 Ruby string to compare.
* @return [mrb_value] boolean value.
*/
MRB_API mrb_bool mrb_str_equal(mrb_state *mrb, mrb_value str1, mrb_value str2);
/*
* Returns a concated string comprised of a Ruby string and a C string.
/**
* Returns a concatenated string comprised of a Ruby string and a C string.
*
* @param [mrb_state] mrb The current mruby state.
* @param [mrb_value] str Ruby string.
* @param [const char *] ptr A C string.
* @param [size_t] len length of C string.
* @param mrb The current mruby state.
* @param str Ruby string.
* @param ptr A C string.
* @param len length of C string.
* @return [mrb_value] A Ruby string.
* @see mrb_str_cat_cstr
*/
MRB_API mrb_value mrb_str_cat(mrb_state *mrb, mrb_value str, const char *ptr, size_t len);
/*
* Returns a concated string comprised of a Ruby string and a C string.
/**
* Returns a concatenated string comprised of a Ruby string and a C string.
*
* @param [mrb_state] mrb The current mruby state.
* @param [mrb_value] str Ruby string.
* @param [const char *] ptr A C string.
* @param mrb The current mruby state.
* @param str Ruby string.
* @param ptr A C string.
* @return [mrb_value] A Ruby string.
* @see mrb_str_cat
*/
@@ -397,17 +420,17 @@ MRB_API mrb_value mrb_str_cat_cstr(mrb_state *mrb, mrb_value str, const char *pt
MRB_API mrb_value mrb_str_cat_str(mrb_state *mrb, mrb_value str, mrb_value str2);
#define mrb_str_cat_lit(mrb, str, lit) mrb_str_cat(mrb, str, lit, mrb_strlen_lit(lit))
/*
/**
* Adds str2 to the end of str1.
*/
MRB_API mrb_value mrb_str_append(mrb_state *mrb, mrb_value str, mrb_value str2);
/*
/**
* Returns 0 if both Ruby strings are equal. Returns a value < 0 if Ruby str1 is less than Ruby str2. Returns a value > 0 if Ruby str2 is greater than Ruby str1.
*/
MRB_API int mrb_str_cmp(mrb_state *mrb, mrb_value str1, mrb_value str2);
/*
/**
* Returns a newly allocated C string from a Ruby string.
* This is an utility function to pass a Ruby string to C library functions.
*
@@ -418,31 +441,32 @@ MRB_API int mrb_str_cmp(mrb_state *mrb, mrb_value str1, mrb_value str2);
* - Caller can modify returned string without affecting Ruby string
* (e.g. it can be used for mkstemp(3)).
*
* @param [mrb_state *] mrb The current mruby state.
* @param [mrb_value] str Ruby string. Must be an instance of String.
* @param mrb The current mruby state.
* @param str Ruby string. Must be an instance of String.
* @return [char *] A newly allocated C string.
*/
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_value mrb_str_pool(mrb_state *mrb, const char *s, mrb_int len, mrb_bool nofree);
uint32_t mrb_str_hash(mrb_state *mrb, mrb_value str);
mrb_value mrb_str_dump(mrb_state *mrb, mrb_value str);
/*
/**
* Returns a printable version of str, surrounded by quote marks, with special characters escaped.
*/
mrb_value mrb_str_inspect(mrb_state *mrb, mrb_value str);
void mrb_noregexp(mrb_state *mrb, mrb_value self);
void mrb_regexp_check(mrb_state *mrb, mrb_value obj);
/* For backward compatibility */
#define mrb_str_cat2(mrb, str, ptr) mrb_str_cat_cstr(mrb, str, ptr)
#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)
mrb_bool mrb_str_beg_len(mrb_int str_len, mrb_int *begp, mrb_int *lenp);
mrb_value mrb_str_byte_subseq(mrb_state *mrb, mrb_value str, mrb_int beg, mrb_int len);
#ifdef MRB_UTF8_STRING
mrb_int mrb_utf8_len(const char *str, mrb_int byte_len);
mrb_int mrb_utf8len(const char *str, const char *end);
mrb_int mrb_utf8_strlen(const char *str, mrb_int byte_len);
#endif
MRB_END_DECL
+2 -2
View File
@@ -1,5 +1,5 @@
/*
** mruby/throw.h - mruby exception throwing handler
/**
** @file mruby/throw.h - mruby exception throwing handler
**
** See Copyright Notice in mruby.h
*/
+167 -90
View File
@@ -1,5 +1,5 @@
/*
** mruby/value.h - mruby value definitions
/**
** @file mruby/value.h - mruby value definitions
**
** See Copyright Notice in mruby.h
*/
@@ -9,28 +9,43 @@
#include "common.h"
/**
/*
* MRuby Value definition functions and macros.
*/
MRB_BEGIN_DECL
/**
* mruby Symbol.
* @class mrb_sym
*
* You can create an mrb_sym by simply using mrb_str_intern() or mrb_intern_cstr()
*/
typedef uint32_t mrb_sym;
/**
* mruby Boolean.
* @class mrb_bool
*
*
* Used internally to represent boolean. Can be TRUE or FALSE.
* Not to be confused with Ruby's boolean classes, which can be
* obtained using mrb_false_value() and mrb_true_value()
*/
typedef uint8_t mrb_bool;
struct mrb_state;
#if defined(MRB_INT16) && defined(MRB_INT64)
# error "You can't define MRB_INT16 and MRB_INT64 at the same time."
#endif
#if defined _MSC_VER && _MSC_VER < 1800
# define PRIo64 "llo"
# define PRId64 "lld"
# define PRIu64 "llu"
# define PRIx64 "llx"
# define PRIo16 "ho"
# define PRId16 "hd"
# define PRIu16 "hu"
# define PRIx16 "hx"
# define PRIo32 "o"
# define PRId32 "d"
# define PRIu32 "u"
# define PRIx32 "x"
#else
# include <inttypes.h>
@@ -44,14 +59,6 @@ struct mrb_state;
# define MRB_PRIo PRIo64
# define MRB_PRId PRId64
# define MRB_PRIx PRIx64
#elif defined(MRB_INT16)
typedef int16_t mrb_int;
# define MRB_INT_BIT 16
# define MRB_INT_MIN (INT16_MIN>>MRB_FIXNUM_SHIFT)
# define MRB_INT_MAX (INT16_MAX>>MRB_FIXNUM_SHIFT)
# define MRB_PRIo PRIo16
# define MRB_PRId PRId16
# define MRB_PRIx PRIx16
#else
typedef int32_t mrb_int;
# define MRB_INT_BIT 32
@@ -62,6 +69,11 @@ struct mrb_state;
# define MRB_PRIx PRIx32
#endif
#ifdef MRB_ENDIAN_BIG
# define MRB_ENDIAN_LOHI(a,b) a b
#else
# define MRB_ENDIAN_LOHI(a,b) b a
#endif
#ifndef MRB_WITHOUT_FLOAT
MRB_API double mrb_float_read(const char*, char**);
@@ -73,9 +85,6 @@ MRB_API double mrb_float_read(const char*, char**);
#endif
#if defined _MSC_VER && _MSC_VER < 1900
# ifndef __cplusplus
# define inline __inline
# endif
# include <stdarg.h>
MRB_API int mrb_msvc_vsnprintf(char *s, size_t n, const char *format, va_list arg);
MRB_API int mrb_msvc_snprintf(char *s, size_t n, const char *format, ...);
@@ -94,32 +103,31 @@ static const unsigned int IEEE754_INFINITY_BITS_SINGLE = 0x7F800000;
#endif
enum mrb_vtype {
MRB_TT_FALSE = 0, /* 0 */
MRB_TT_FREE, /* 1 */
MRB_TT_TRUE, /* 2 */
MRB_TT_FIXNUM, /* 3 */
MRB_TT_SYMBOL, /* 4 */
MRB_TT_UNDEF, /* 5 */
MRB_TT_FLOAT, /* 6 */
MRB_TT_CPTR, /* 7 */
MRB_TT_OBJECT, /* 8 */
MRB_TT_CLASS, /* 9 */
MRB_TT_MODULE, /* 10 */
MRB_TT_ICLASS, /* 11 */
MRB_TT_SCLASS, /* 12 */
MRB_TT_PROC, /* 13 */
MRB_TT_ARRAY, /* 14 */
MRB_TT_HASH, /* 15 */
MRB_TT_STRING, /* 16 */
MRB_TT_RANGE, /* 17 */
MRB_TT_EXCEPTION, /* 18 */
MRB_TT_FILE, /* 19 */
MRB_TT_ENV, /* 20 */
MRB_TT_DATA, /* 21 */
MRB_TT_FIBER, /* 22 */
MRB_TT_ISTRUCT, /* 23 */
MRB_TT_BREAK, /* 24 */
MRB_TT_MAXDEFINE /* 25 */
MRB_TT_FALSE = 0,
MRB_TT_TRUE,
MRB_TT_FLOAT,
MRB_TT_FIXNUM,
MRB_TT_SYMBOL,
MRB_TT_UNDEF,
MRB_TT_CPTR,
MRB_TT_FREE,
MRB_TT_OBJECT,
MRB_TT_CLASS,
MRB_TT_MODULE,
MRB_TT_ICLASS,
MRB_TT_SCLASS,
MRB_TT_PROC,
MRB_TT_ARRAY,
MRB_TT_HASH,
MRB_TT_STRING,
MRB_TT_RANGE,
MRB_TT_EXCEPTION,
MRB_TT_ENV,
MRB_TT_DATA,
MRB_TT_FIBER,
MRB_TT_ISTRUCT,
MRB_TT_BREAK,
MRB_TT_MAXDEFINE
};
#include <mruby/object.h>
@@ -140,6 +148,13 @@ typedef void mrb_value;
#endif
#if defined(MRB_WORD_BOXING) || (defined(MRB_NAN_BOXING) && defined(MRB_64BIT))
struct RCptr {
MRB_OBJECT_HEADER;
void *p;
};
#endif
#if defined(MRB_NAN_BOXING)
#include "boxing_nan.h"
#elif defined(MRB_WORD_BOXING)
@@ -148,36 +163,106 @@ typedef void mrb_value;
#include "boxing_no.h"
#endif
#define MRB_SYMBOL_BIT (sizeof(mrb_sym) * CHAR_BIT - MRB_SYMBOL_SHIFT)
#define MRB_SYMBOL_MAX (UINT32_MAX >> MRB_SYMBOL_SHIFT)
#if INTPTR_MAX < MRB_INT_MAX
typedef intptr_t mrb_ssize;
# define MRB_SSIZE_MAX (INTPTR_MAX>>MRB_FIXNUM_SHIFT)
#else
typedef mrb_int mrb_ssize;
# define MRB_SSIZE_MAX MRB_INT_MAX
#endif
#ifndef mrb_immediate_p
#define mrb_immediate_p(o) (mrb_type(o) < MRB_TT_FREE)
#endif
#ifndef mrb_fixnum_p
#define mrb_fixnum_p(o) (mrb_type(o) == MRB_TT_FIXNUM)
#endif
#ifndef mrb_symbol_p
#define mrb_symbol_p(o) (mrb_type(o) == MRB_TT_SYMBOL)
#endif
#ifndef mrb_undef_p
#define mrb_undef_p(o) (mrb_type(o) == MRB_TT_UNDEF)
#endif
#ifndef mrb_nil_p
#define mrb_nil_p(o) (mrb_type(o) == MRB_TT_FALSE && !mrb_fixnum(o))
#endif
#ifndef mrb_false_p
#define mrb_false_p(o) (mrb_type(o) == MRB_TT_FALSE && !!mrb_fixnum(o))
#endif
#ifndef mrb_true_p
#define mrb_true_p(o) (mrb_type(o) == MRB_TT_TRUE)
#endif
#ifndef MRB_WITHOUT_FLOAT
#ifndef mrb_float_p
#define mrb_float_p(o) (mrb_type(o) == MRB_TT_FLOAT)
#endif
#endif
#ifndef mrb_array_p
#define mrb_array_p(o) (mrb_type(o) == MRB_TT_ARRAY)
#endif
#ifndef mrb_string_p
#define mrb_string_p(o) (mrb_type(o) == MRB_TT_STRING)
#endif
#ifndef mrb_hash_p
#define mrb_hash_p(o) (mrb_type(o) == MRB_TT_HASH)
#endif
#ifndef mrb_cptr_p
#define mrb_cptr_p(o) (mrb_type(o) == MRB_TT_CPTR)
#endif
#ifndef mrb_exception_p
#define mrb_exception_p(o) (mrb_type(o) == MRB_TT_EXCEPTION)
#endif
#ifndef mrb_free_p
#define mrb_free_p(o) (mrb_type(o) == MRB_TT_FREE)
#endif
#ifndef mrb_object_p
#define mrb_object_p(o) (mrb_type(o) == MRB_TT_OBJECT)
#endif
#ifndef mrb_class_p
#define mrb_class_p(o) (mrb_type(o) == MRB_TT_CLASS)
#endif
#ifndef mrb_module_p
#define mrb_module_p(o) (mrb_type(o) == MRB_TT_MODULE)
#endif
#ifndef mrb_iclass_p
#define mrb_iclass_p(o) (mrb_type(o) == MRB_TT_ICLASS)
#endif
#ifndef mrb_sclass_p
#define mrb_sclass_p(o) (mrb_type(o) == MRB_TT_SCLASS)
#endif
#ifndef mrb_proc_p
#define mrb_proc_p(o) (mrb_type(o) == MRB_TT_PROC)
#endif
#ifndef mrb_range_p
#define mrb_range_p(o) (mrb_type(o) == MRB_TT_RANGE)
#endif
#ifndef mrb_env_p
#define mrb_env_p(o) (mrb_type(o) == MRB_TT_ENV)
#endif
#ifndef mrb_data_p
#define mrb_data_p(o) (mrb_type(o) == MRB_TT_DATA)
#endif
#ifndef mrb_fiber_p
#define mrb_fiber_p(o) (mrb_type(o) == MRB_TT_FIBER)
#endif
#ifndef mrb_istruct_p
#define mrb_istruct_p(o) (mrb_type(o) == MRB_TT_ISTRUCT)
#endif
#ifndef mrb_break_p
#define mrb_break_p(o) (mrb_type(o) == MRB_TT_BREAK)
#endif
#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)
#define mrb_hash_p(o) (mrb_type(o) == MRB_TT_HASH)
#define mrb_cptr_p(o) (mrb_type(o) == MRB_TT_CPTR)
#define mrb_exception_p(o) (mrb_type(o) == MRB_TT_EXCEPTION)
#define mrb_test(o) mrb_bool(o)
MRB_API mrb_bool mrb_regexp_p(struct mrb_state*, mrb_value);
/*
/**
* Returns a float in Ruby.
*
* Takes a float and boxes it into an mrb_value
*/
#ifndef MRB_WITHOUT_FLOAT
MRB_INLINE mrb_value mrb_float_value(struct mrb_state *mrb, mrb_float f)
@@ -189,7 +274,7 @@ MRB_INLINE mrb_value mrb_float_value(struct mrb_state *mrb, mrb_float f)
}
#endif
static inline mrb_value
MRB_INLINE mrb_value
mrb_cptr_value(struct mrb_state *mrb, void *p)
{
mrb_value v;
@@ -198,8 +283,10 @@ mrb_cptr_value(struct mrb_state *mrb, void *p)
return v;
}
/*
/**
* Returns a fixnum in Ruby.
*
* Takes an integer and boxes it into an mrb_value
*/
MRB_INLINE mrb_value mrb_fixnum_value(mrb_int i)
{
@@ -208,7 +295,7 @@ MRB_INLINE mrb_value mrb_fixnum_value(mrb_int i)
return v;
}
static inline mrb_value
MRB_INLINE mrb_value
mrb_symbol_value(mrb_sym i)
{
mrb_value v;
@@ -216,7 +303,7 @@ mrb_symbol_value(mrb_sym i)
return v;
}
static inline mrb_value
MRB_INLINE mrb_value
mrb_obj_value(void *p)
{
mrb_value v;
@@ -226,8 +313,7 @@ mrb_obj_value(void *p)
return v;
}
/*
/**
* Get a nil mrb_value object.
*
* @return
@@ -240,7 +326,7 @@ MRB_INLINE mrb_value mrb_nil_value(void)
return v;
}
/*
/**
* Returns false in Ruby.
*/
MRB_INLINE mrb_value mrb_false_value(void)
@@ -250,7 +336,7 @@ MRB_INLINE mrb_value mrb_false_value(void)
return v;
}
/*
/**
* Returns true in Ruby.
*/
MRB_INLINE mrb_value mrb_true_value(void)
@@ -260,7 +346,7 @@ MRB_INLINE mrb_value mrb_true_value(void)
return v;
}
static inline mrb_value
MRB_INLINE mrb_value
mrb_bool_value(mrb_bool boolean)
{
mrb_value v;
@@ -268,7 +354,7 @@ mrb_bool_value(mrb_bool boolean)
return v;
}
static inline mrb_value
MRB_INLINE mrb_value
mrb_undef_value(void)
{
mrb_value v;
@@ -276,34 +362,25 @@ mrb_undef_value(void)
return v;
}
#ifdef MRB_USE_ETEXT_EDATA
#if (defined(__APPLE__) && defined(__MACH__))
#include <mach-o/getsect.h>
static inline mrb_bool
mrb_ro_data_p(const char *p)
{
return (const char*)get_etext() < p && p < (const char*)get_edata();
}
#else
extern char _etext[];
#ifdef MRB_NO_INIT_ARRAY_START
extern char _edata[];
#if defined(MRB_USE_ETEXT_EDATA) && !defined(MRB_USE_LINK_TIME_RO_DATA_P)
# ifdef __GNUC__
# warning MRB_USE_ETEXT_EDATA is deprecated. Define MRB_USE_LINK_TIME_RO_DATA_P instead.
# endif
# define MRB_USE_LINK_TIME_RO_DATA_P
#endif
static inline mrb_bool
mrb_ro_data_p(const char *p)
{
return _etext < p && p < _edata;
}
#else
#if defined(MRB_USE_CUSTOM_RO_DATA_P)
/* If you define `MRB_USE_CUSTOM_RO_DATA_P`, you must implement `mrb_ro_data_p()`. */
mrb_bool mrb_ro_data_p(const char *p);
#elif defined(MRB_USE_LINK_TIME_RO_DATA_P)
extern char __ehdr_start[];
extern char __init_array_start[];
static inline mrb_bool
mrb_ro_data_p(const char *p)
{
return _etext < p && p < (char*)&__init_array_start;
return __ehdr_start < p && p < __init_array_start;
}
#endif
#endif
#else
# define mrb_ro_data_p(p) FALSE
#endif
+3 -5
View File
@@ -1,5 +1,5 @@
/*
** mruby/variable.h - mruby variables
/**
** @file mruby/variable.h - mruby variables
**
** See Copyright Notice in mruby.h
*/
@@ -97,18 +97,15 @@ MRB_API void mrb_gv_set(mrb_state *mrb, mrb_sym sym, mrb_value val);
*
* Example:
*
* !!!ruby
* # Ruby style
* $value = nil
*
* !!!c
* // C style
* mrb_sym sym = mrb_intern_lit(mrb, "$value");
* mrb_gv_remove(mrb, sym);
*
* @param mrb The mruby state reference
* @param sym The name of the global variable
* @param val The value of the global variable
*/
MRB_API void mrb_gv_remove(mrb_state *mrb, mrb_sym sym);
@@ -117,6 +114,7 @@ MRB_API void mrb_mod_cv_set(mrb_state *mrb, struct RClass * c, mrb_sym sym, mrb_
MRB_API void mrb_cv_set(mrb_state *mrb, mrb_value mod, mrb_sym sym, mrb_value v);
MRB_API mrb_bool mrb_cv_defined(mrb_state *mrb, mrb_value mod, mrb_sym sym);
mrb_value mrb_obj_iv_inspect(mrb_state*, struct RObject*);
void mrb_obj_iv_set_force(mrb_state *mrb, struct RObject *obj, mrb_sym sym, mrb_value v);
mrb_value mrb_mod_constants(mrb_state *mrb, mrb_value mod);
mrb_value mrb_f_global_variables(mrb_state *mrb, mrb_value self);
mrb_value mrb_obj_instance_variables(mrb_state*, mrb_value);
+25 -11
View File
@@ -1,5 +1,5 @@
/*
** mruby/version.h - mruby version definition
/**
** @file mruby/version.h - mruby version definition
**
** See Copyright Notice in mruby.h
*/
@@ -42,12 +42,12 @@ MRB_BEGIN_DECL
/*
* Minor release version number.
*/
#define MRUBY_RELEASE_MINOR 0
#define MRUBY_RELEASE_MINOR 1
/*
* Tiny release version number.
*/
#define MRUBY_RELEASE_TEENY 1
#define MRUBY_RELEASE_TEENY 2
/*
* The mruby version.
@@ -62,22 +62,36 @@ MRB_BEGIN_DECL
/*
* Release year.
*/
#define MRUBY_RELEASE_YEAR 2019
#define MRUBY_RELEASE_YEAR 2020
/*
* Release month.
*/
#define MRUBY_RELEASE_MONTH 4
#define MRUBY_RELEASE_MONTH 7
/*
* Release day.
*/
#define MRUBY_RELEASE_DAY 4
#define MRUBY_RELEASE_DAY 10
/*
* Release date as a string.
*/
#define MRUBY_RELEASE_DATE MRB_STRINGIZE(MRUBY_RELEASE_YEAR) "-" MRB_STRINGIZE(MRUBY_RELEASE_MONTH) "-" MRB_STRINGIZE(MRUBY_RELEASE_DAY)
#define MRUBY_RELEASE_DATE \
MRUBY_RELEASE_YEAR_STR "-" \
MRUBY_RELEASE_MONTH_STR "-" \
MRUBY_RELEASE_DAY_STR
#define MRUBY_RELEASE_YEAR_STR MRB_STRINGIZE(MRUBY_RELEASE_YEAR)
#if MRUBY_RELEASE_MONTH < 10
#define MRUBY_RELEASE_MONTH_STR "0" MRB_STRINGIZE(MRUBY_RELEASE_MONTH)
#else
#define MRUBY_RELEASE_MONTH_STR MRB_STRINGIZE(MRUBY_RELEASE_MONTH)
#endif
#if MRUBY_RELEASE_DAY < 10
#define MRUBY_RELEASE_DAY_STR "0" MRB_STRINGIZE(MRUBY_RELEASE_DAY)
#else
#define MRUBY_RELEASE_DAY_STR MRB_STRINGIZE(MRUBY_RELEASE_DAY)
#endif
/*
* The year mruby was first created.
@@ -92,9 +106,9 @@ MRB_BEGIN_DECL
/*
* mruby's version, and release date.
*/
#define MRUBY_DESCRIPTION \
"mruby " MRUBY_VERSION \
" (" MRUBY_RELEASE_DATE ") " \
#define MRUBY_DESCRIPTION \
"mruby " MRUBY_VERSION \
" (" MRUBY_RELEASE_DATE ")" \
/*
* mruby's copyright information.
+3 -59
View File
@@ -1,3 +1,5 @@
autoload :Pathname, 'pathname'
class Object
class << self
def attr_block(*syms)
@@ -16,68 +18,10 @@ class String
def relative_path
relative_path_from(Dir.pwd)
end
# Compatible with 1.9 on 1.8
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
if params.is_a?(Array)
sprintf(self, *params)
else
sprintf(self, params)
end
end
end
end
end
class Symbol
# Compatible with 1.9 on 1.8
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
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
$pp_show = true
if $verbose.nil?
if Rake.respond_to?(:verbose) && !Rake.verbose.nil?
if Rake.verbose.class == TrueClass
# verbose message logging
$pp_show = false
else
$pp_show = true
Rake.verbose(false)
end
else
# could not identify rake version
$pp_show = false
end
else
$pp_show = false if $verbose
end
def _pp(cmd, src, tgt=nil, options={})
return unless $pp_show
return if Rake.verbose
width = 5
template = options[:indent] ? "%#{width*options[:indent]}s %s %s" : "%-#{width}s %s %s"
+36 -47
View File
@@ -1,7 +1,11 @@
require "mruby-core-ext"
require "mruby/build/load_gems"
require "mruby/build/command"
module MRuby
autoload :Gem, "mruby/gem"
autoload :Lockfile, "mruby/lockfile"
class << self
def targets
@targets ||= {}
@@ -22,7 +26,6 @@ module MRuby
def initialize(name, &block)
@name, @initializer = name.to_s, block
MRuby::Toolchain.toolchains ||= {}
MRuby::Toolchain.toolchains[@name] = self
end
@@ -30,13 +33,8 @@ module MRuby
conf.instance_exec(conf, params, &@initializer)
end
def self.load
Dir.glob("#{MRUBY_ROOT}/tasks/toolchains/*.rake").each do |file|
Kernel.load file
end
end
self.toolchains = {}
end
Toolchain.load
class Build
class << self
@@ -45,7 +43,7 @@ module MRuby
include Rake::DSL
include LoadGems
attr_accessor :name, :bins, :exts, :file_separator, :build_dir, :gem_clone_dir
attr_reader :libmruby_objs, :gems, :toolchains
attr_reader :libmruby_objs, :gems, :toolchains, :gem_dir_to_repo_url
attr_writer :enable_bintest, :enable_test
alias libmruby libmruby_objs
@@ -70,7 +68,7 @@ module MRuby
@file_separator = '/'
@build_dir = "#{build_dir}/#{@name}"
@gem_clone_dir = "#{build_dir}/mrbgems"
@gem_clone_dir = "#{build_dir}/repos/#{@name}"
@cc = Command::Compiler.new(self, %w(.c))
@cxx = Command::Compiler.new(self, %w(.cc .cxx .cpp))
@objc = Command::Compiler.new(self, %w(.m))
@@ -90,7 +88,9 @@ module MRuby
@cxx_abi_enabled = false
@enable_bintest = false
@enable_test = false
@enable_lock = true
@toolchains = []
@gem_dir_to_repo_url = {}
MRuby.targets[@name] = self
end
@@ -118,6 +118,14 @@ module MRuby
@enable_debug = true
end
def disable_lock
@enable_lock = false
end
def lock_enabled?
Lockfile.enabled? && @enable_lock
end
def disable_cxx_exception
if @cxx_exception_enabled or @cxx_abi_enabled
raise "cxx_exception already enabled"
@@ -155,8 +163,8 @@ module MRuby
compilers.each { |c|
c.defines += %w(MRB_ENABLE_CXX_EXCEPTION MRB_ENABLE_CXX_ABI)
c.flags << c.cxx_compile_flag
c.flags = c.flags.flatten - c.cxx_invalid_flags.flatten
}
compilers.each { |c| c.flags << c.cxx_compile_flag }
linker.command = cxx.command if toolchains.find { |v| v == 'gcc' }
@cxx_abi_enabled = true
end
@@ -165,7 +173,7 @@ module MRuby
obj = objfile(cxx_src) if obj.nil?
file cxx_src => [src, __FILE__] do |t|
FileUtils.mkdir_p File.dirname t.name
mkdir_p File.dirname t.name
IO.write t.name, <<EOS
#define __STDC_CONSTANT_MACROS
#define __STDC_LIMIT_MACROS
@@ -196,10 +204,15 @@ EOS
end
def toolchain(name, params={})
tc = Toolchain.toolchains[name.to_s]
fail "Unknown #{name} toolchain" unless tc
name = name.to_s
tc = Toolchain.toolchains[name] || begin
path = "#{MRUBY_ROOT}/tasks/toolchains/#{name}.rake"
fail "Unknown #{name} toolchain" unless File.exist?(path)
load path
Toolchain.toolchains[name]
end
tc.setup(self, params)
@toolchains.unshift name.to_s
@toolchains.unshift name
end
def primary_toolchain
@@ -226,6 +239,10 @@ EOS
gem :core => 'mruby-bin-mrbc'
end
def locks
Lockfile.build(@name)
end
def mrbcfile
return @mrbcfile if @mrbcfile
@@ -255,15 +272,7 @@ EOS
if name.is_a?(Array)
name.flatten.map { |n| filename(n) }
else
'"%s"' % name.gsub('/', file_separator)
end
end
def cygwin_filename(name)
if name.is_a?(Array)
name.flatten.map { |n| cygwin_filename(n) }
else
'"%s"' % `cygpath -w "#{filename(name)}"`.strip
name.gsub('/', file_separator)
end
end
@@ -303,7 +312,7 @@ EOS
end
def verbose_flag
$verbose ? ' -v' : ''
Rake.verbose ? ' -v' : ''
end
def run_test
@@ -327,7 +336,8 @@ EOS
puts " Binaries: #{@bins.join(', ')}" unless @bins.empty?
unless @gems.empty?
puts " Included Gems:"
@gems.map do |gem|
gems = @gems.sort_by { |gem| gem.name }
gems.each do |gem|
gem_version = " - #{gem.version}" if gem.version != '0.0.0'
gem_summary = " - #{gem.summary}" if gem.summary
puts " #{gem.name}#{gem_version}#{gem_summary}"
@@ -369,7 +379,7 @@ EOS
end
def run_test
@test_runner.runner_options << ' -v' if $verbose
@test_runner.runner_options << verbose_flag
mrbtest = exefile("#{build_dir}/bin/mrbtest")
if (@test_runner.command == nil)
puts "You should run #{mrbtest} on target device."
@@ -378,26 +388,5 @@ 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
+96 -69
View File
@@ -4,7 +4,7 @@ module MRuby
class Command
include Rake::DSL
extend Forwardable
def_delegators :@build, :filename, :objfile, :libfile, :exefile, :cygwin_filename
def_delegators :@build, :filename, :objfile, :libfile, :exefile
attr_accessor :build, :command
def initialize(build)
@@ -24,6 +24,14 @@ module MRuby
target
end
def shellquote(s)
if ENV['OS'] == 'Windows_NT'
"\"#{s}\""
else
"#{s}"
end
end
NotFoundCommands = {}
private
@@ -41,7 +49,7 @@ module MRuby
class Command::Compiler < Command
attr_accessor :flags, :include_paths, :defines, :source_exts
attr_accessor :compile_options, :option_define, :option_include_path, :out_ext
attr_accessor :cxx_compile_flag, :cxx_exception_flag
attr_accessor :cxx_compile_flag, :cxx_exception_flag, :cxx_invalid_flags
def initialize(build, source_exts=[])
super(build)
@@ -50,9 +58,10 @@ module MRuby
@source_exts = source_exts
@include_paths = ["#{MRUBY_ROOT}/include"]
@defines = %w()
@option_include_path = '-I%s'
@option_define = '-D%s'
@compile_options = '%{flags} -o %{outfile} -c %{infile}'
@option_include_path = %q[-I"%s"]
@option_define = %q[-D"%s"]
@compile_options = %q[%{flags} -o "%{outfile}" -c "%{infile}"]
@cxx_invalid_flags = []
end
alias header_search_paths include_paths
@@ -70,25 +79,16 @@ module MRuby
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)
else
option_include_path % filename(f)
end
option_include_path % filename(f)
end
[flags, define_flags, include_path_flags, _flags].flatten.join(' ')
end
def run(outfile, infile, _defines=[], _include_paths=[], _flags=[])
FileUtils.mkdir_p File.dirname(outfile)
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(_defines, _include_paths, _flags),
:infile => cygwin_filename(infile), :outfile => cygwin_filename(outfile) }
else
_run compile_options, { :flags => all_flags(_defines, _include_paths, _flags),
:infile => filename(infile), :outfile => filename(outfile) }
end
_run compile_options, { :flags => all_flags(_defines, _include_paths, _flags),
:infile => filename(infile), :outfile => filename(outfile) }
end
def define_rules(build_dir, source_dir='')
@@ -127,13 +127,40 @@ module MRuby
end
private
#
# === Example of +.d+ file
#
# ==== Without <tt>-MP</tt> compiler flag
#
# /build/host/src/array.o: \
# /src/array.c \
# /include/mruby/common.h \
# /include/mruby/value.h \
# /src/value_array.h
#
# ==== With <tt>-MP</tt> compiler flag
#
# /build/host/src/array.o: \
# /src/array.c \
# /include/mruby/common.h \
# /include/mruby/value.h \
# /src/value_array.h
#
# /include/mruby/common.h:
#
# /include/mruby/value.h:
#
# /src/value_array.h:
#
def get_dependencies(file)
file = file.ext('d') unless File.extname(file) == '.d'
deps = []
if File.exist?(file)
File.read(file).gsub("\\\n ", "").scan(/^\S+:\s+(.+)$/).flatten.map {|s| s.split(' ') }.flatten
else
[]
end + [ MRUBY_CONFIG ]
File.foreach(file){|line| deps << $1 if /^ +(.*?)(?: *\\)?$/ =~ line}
deps.uniq!
end
deps << MRUBY_CONFIG
end
end
@@ -148,18 +175,14 @@ module MRuby
@flags_before_libraries, @flags_after_libraries = [], []
@libraries = []
@library_paths = []
@option_library = '-l%s'
@option_library_path = '-L%s'
@link_options = "%{flags} -o %{outfile} %{objs} %{flags_before_libraries} %{libs} %{flags_after_libraries}"
@option_library = %q[-l"%s"]
@option_library_path = %q[-L"%s"]
@link_options = %Q[%{flags} -o "%{outfile}" %{objs} %{flags_before_libraries} %{libs} %{flags_after_libraries}]
end
def all_flags(_library_paths=[], _flags=[])
library_path_flags = [library_paths, _library_paths].flatten.map do |f|
if MRUBY_BUILD_HOST_IS_CYGWIN
option_library_path % cygwin_filename(f)
else
option_library_path % filename(f)
end
option_library_path % filename(f)
end
[flags, library_path_flags, _flags].flatten.join(' ')
end
@@ -169,23 +192,15 @@ module MRuby
end
def run(outfile, objfiles, _libraries=[], _library_paths=[], _flags=[], _flags_before_libraries=[], _flags_after_libraries=[])
FileUtils.mkdir_p File.dirname(outfile)
mkdir_p File.dirname(outfile)
library_flags = [libraries, _libraries].flatten.map { |d| option_library % d }
_pp "LD", outfile.relative_path
if MRUBY_BUILD_HOST_IS_CYGWIN
_run link_options, { :flags => all_flags(_library_paths, _flags),
:outfile => cygwin_filename(outfile) , :objs => cygwin_filename(objfiles).join(' '),
:flags_before_libraries => [flags_before_libraries, _flags_before_libraries].flatten.join(' '),
:flags_after_libraries => [flags_after_libraries, _flags_after_libraries].flatten.join(' '),
:libs => library_flags.join(' ') }
else
_run link_options, { :flags => all_flags(_library_paths, _flags),
:outfile => filename(outfile) , :objs => filename(objfiles).join(' '),
:flags_before_libraries => [flags_before_libraries, _flags_before_libraries].flatten.join(' '),
:flags_after_libraries => [flags_after_libraries, _flags_after_libraries].flatten.join(' '),
:libs => library_flags.join(' ') }
end
_run link_options, { :flags => all_flags(_library_paths, _flags),
:outfile => filename(outfile) , :objs => filename(objfiles).map{|f| %Q["#{f}"]}.join(' '),
:flags_before_libraries => [flags_before_libraries, _flags_before_libraries].flatten.join(' '),
:flags_after_libraries => [flags_after_libraries, _flags_after_libraries].flatten.join(' '),
:libs => library_flags.join(' ') }
end
end
@@ -195,17 +210,13 @@ module MRuby
def initialize(build)
super
@command = ENV['AR'] || 'ar'
@archive_options = 'rs %{outfile} %{objs}'
@archive_options = 'rs "%{outfile}" %{objs}'
end
def run(outfile, objfiles)
FileUtils.mkdir_p File.dirname(outfile)
mkdir_p File.dirname(outfile)
_pp "AR", outfile.relative_path
if MRUBY_BUILD_HOST_IS_CYGWIN
_run archive_options, { :outfile => cygwin_filename(outfile), :objs => cygwin_filename(objfiles).join(' ') }
else
_run archive_options, { :outfile => filename(outfile), :objs => filename(objfiles).join(' ') }
end
_run archive_options, { :outfile => filename(outfile), :objs => filename(objfiles).map{|f| %Q["#{f}"]}.join(' ') }
end
end
@@ -215,11 +226,11 @@ module MRuby
def initialize(build)
super
@command = 'bison'
@compile_options = '-o %{outfile} %{infile}'
@compile_options = %q[-o "%{outfile}" "%{infile}"]
end
def run(outfile, infile)
FileUtils.mkdir_p File.dirname(outfile)
mkdir_p File.dirname(outfile)
_pp "YACC", infile.relative_path, outfile.relative_path
_run compile_options, { :outfile => filename(outfile) , :infile => filename(infile) }
end
@@ -231,11 +242,11 @@ module MRuby
def initialize(build)
super
@command = 'gperf'
@compile_options = '-L ANSI-C -C -p -j1 -i 1 -g -o -t -N mrb_reserved_word -k"1,3,$" %{infile} > %{outfile}'
@compile_options = %q[-L ANSI-C -C -p -j1 -i 1 -g -o -t -N mrb_reserved_word -k"1,3,$" "%{infile}" > "%{outfile}"]
end
def run(outfile, infile)
FileUtils.mkdir_p File.dirname(outfile)
mkdir_p File.dirname(outfile)
_pp "GPERF", infile.relative_path, outfile.relative_path
_run compile_options, { :outfile => filename(outfile) , :infile => filename(infile) }
end
@@ -243,36 +254,50 @@ module MRuby
class Command::Git < Command
attr_accessor :flags
attr_accessor :clone_options, :pull_options, :checkout_options
attr_accessor :clone_options, :pull_options, :checkout_options, :checkout_detach_options, :reset_options
def initialize(build)
super
@command = 'git'
@flags = %w[]
@clone_options = "clone %{flags} %{url} %{dir}"
@pull_options = "pull"
@checkout_options = "checkout %{checksum_hash}"
@pull_options = "--git-dir %{repo_dir}/.git --work-tree %{repo_dir} pull"
@checkout_options = "--git-dir %{repo_dir}/.git --work-tree %{repo_dir} checkout %{checksum_hash}"
@checkout_detach_options = "--git-dir %{repo_dir}/.git --work-tree %{repo_dir} checkout --detach %{checksum_hash}"
@reset_options = "--git-dir %{repo_dir}/.git --work-tree %{repo_dir} reset %{checksum_hash}"
end
def run_clone(dir, url, _flags = [])
_pp "GIT", url, dir.relative_path
_run clone_options, { :flags => [flags, _flags].flatten.join(' '), :url => url, :dir => filename(dir) }
_run clone_options, { :flags => [flags, _flags].flatten.join(' '), :url => shellquote(url), :dir => shellquote(filename(dir)) }
end
def run_pull(dir, url)
root = Dir.pwd
Dir.chdir dir
_pp "GIT PULL", url, dir.relative_path
_run pull_options
Dir.chdir root
_run pull_options, { :repo_dir => shellquote(dir) }
end
def run_checkout(dir, checksum_hash)
root = Dir.pwd
Dir.chdir dir
_pp "GIT CHECKOUT", checksum_hash
_run checkout_options, { :checksum_hash => checksum_hash }
Dir.chdir root
_pp "GIT CHECKOUT", dir, checksum_hash
_run checkout_options, { :checksum_hash => checksum_hash, :repo_dir => shellquote(dir) }
end
def run_checkout_detach(dir, checksum_hash)
_pp "GIT CHECKOUT DETACH", dir, checksum_hash
_run checkout_detach_options, { :checksum_hash => checksum_hash, :repo_dir => shellquote(dir) }
end
def run_reset_hard(dir, checksum_hash)
_pp "GIT RESET", dir, checksum_hash
_run reset_options, { :checksum_hash => checksum_hash, :repo_dir => shellquote(dir) }
end
def commit_hash(dir)
`#{@command} --git-dir #{shellquote(dir +'/.git')} --work-tree #{shellquote(dir)} rev-parse --verify HEAD`.strip
end
def current_branch(dir)
`#{@command} --git-dir #{shellquote(dir + '/.git')} --work-tree #{shellquote(dir)} rev-parse --abbrev-ref HEAD`.strip
end
end
@@ -291,7 +316,9 @@ module MRuby
infiles.each do |f|
_pp "MRBC", f.relative_path, nil, :indent => 2
end
IO.popen("#{filename @command} #{@compile_options % {:funcname => funcname}} #{filename(infiles).join(' ')}", 'r+') do |io|
cmd = %Q["#{filename @command}" #{@compile_options % {:funcname => funcname}} #{filename(infiles).map{|f| %Q["#{f}"]}.join(' ')}]
puts cmd if Rake.verbose
IO.popen(cmd, 'r+') do |io|
out.puts io.read
end
# if mrbc execution fail, drop the file
+25 -12
View File
@@ -13,13 +13,12 @@ module MRuby
end
def gem(gemdir, &block)
caller_dir = File.expand_path(File.dirname(/^(.*?):\d/.match(caller.first).to_a[1]))
if gemdir.is_a?(Hash)
gemdir = load_special_path_gem(gemdir)
elsif GemBox.path && gemdir.is_a?(String)
gemdir = File.expand_path(gemdir, File.dirname(GemBox.path))
else
caller_dir = File.expand_path(File.dirname(caller(1,1)[0][/^(.*?):\d/,1]))
gemdir = File.expand_path(gemdir, caller_dir)
end
@@ -58,7 +57,7 @@ module MRuby
if File.exist? mgem_list_dir
git.run_pull mgem_list_dir, mgem_list_url if $pull_gems
else
FileUtils.mkdir_p mgem_list_dir
mkdir_p mgem_list_dir
git.run_clone mgem_list_dir, mgem_list_url, "--depth 1"
end
@@ -83,27 +82,41 @@ module MRuby
# by default the 'master' branch is used
branch = params[:branch] ? params[:branch] : 'master'
lock = locks[url] if lock_enabled?
if File.exist?(gemdir)
if $pull_gems
# Jump to the top of the branch
git.run_checkout gemdir, branch
git.run_pull gemdir, url
else
gemdir
elsif params[:checksum_hash]
git.run_checkout_detach gemdir, params[:checksum_hash]
elsif lock
git.run_checkout_detach gemdir, lock['commit']
end
else
options = [params[:options]] || []
options << "--recursive"
options << "--branch \"#{branch}\""
options << "--depth 1" unless params[:checksum_hash]
FileUtils.mkdir_p "#{gem_clone_dir}"
mkdir_p "#{gem_clone_dir}"
git.run_clone gemdir, url, options
# Jump to the specified commit
if params[:checksum_hash]
git.run_checkout_detach gemdir, params[:checksum_hash]
elsif lock
git.run_checkout_detach gemdir, lock['commit']
end
end
if params[:checksum_hash]
# Jump to the specified commit
git.run_checkout gemdir, params[:checksum_hash]
else
# Jump to the top of the branch
git.run_checkout gemdir, branch if $pull_gems
if lock_enabled?
@gem_dir_to_repo_url[gemdir] = url unless params[:path]
locks[url] = {
'url' => url,
'branch' => git.current_branch(gemdir),
'commit' => git.commit_hash(gemdir),
}
end
gemdir << "/#{params[:path]}" if params[:path]
+21 -8
View File
@@ -1,7 +1,6 @@
require 'pathname'
require 'forwardable'
require 'tsort'
require 'shellwords'
autoload :TSort, 'tsort'
autoload :Shellwords, 'shellwords'
module MRuby
module Gem
@@ -92,6 +91,9 @@ module MRuby
build.libmruby_objs << @objs
instance_eval(&@build_config_initializer) if @build_config_initializer
repo_url = build.gem_dir_to_repo_url[dir]
build.locks[repo_url]['version'] = version if repo_url
end
def setup_compilers
@@ -104,6 +106,15 @@ module MRuby
define_gem_init_builder if @generate_functions
end
def for_windows?
if build.kind_of?(MRuby::CrossBuild)
return %w(x86_64-w64-mingw32 i686-w64-mingw32).include?(build.host_target)
elsif build.kind_of?(MRuby::Build)
return ('A'..'Z').to_a.any? { |vol| Dir.exist?("#{vol}:") }
end
return false
end
def add_dependency(name, *requirements)
default_gem = requirements.last.kind_of?(Hash) ? requirements.pop : nil
requirements = ['>= 0.0.0'] if requirements.empty?
@@ -155,7 +166,7 @@ module MRuby
def define_gem_init_builder
file objfile("#{build_dir}/gem_init") => [ "#{build_dir}/gem_init.c", File.join(dir, "mrbgem.rake") ]
file "#{build_dir}/gem_init.c" => [build.mrbcfile, __FILE__] + [rbfiles].flatten do |t|
FileUtils.mkdir_p build_dir
mkdir_p build_dir
generate_gem_init("#{build_dir}/gem_init.c")
end
end
@@ -267,16 +278,18 @@ module MRuby
# ~> compare algorithm
#
# Example:
# ~> 2 means >= 2.0.0 and < 3.0.0
# ~> 2.2 means >= 2.2.0 and < 3.0.0
# ~> 2.2.0 means >= 2.2.0 and < 2.3.0
# ~> 2.2.2 means >= 2.2.2 and < 2.3.0
def twiddle_wakka_ok?(other)
gr_or_eql = (self <=> other) >= 0
still_minor = (self <=> other.skip_minor) < 0
gr_or_eql and still_minor
still_major_or_minor = (self <=> other.skip_major_or_minor) < 0
gr_or_eql and still_major_or_minor
end
def skip_minor
def skip_major_or_minor
a = @ary.dup
a << 0 if a.size == 1 # ~> 2 can also be represented as ~> 2.0
a.slice!(-1)
a[-1] = a[-1].succ
a
+81
View File
@@ -0,0 +1,81 @@
autoload :YAML, 'yaml'
module MRuby
autoload :Source, 'mruby/source'
class Lockfile
class << self
def enable
@enabled = true
end
def disable
@enabled = false
end
def enabled?
@enabled
end
def build(target_name)
instance.build(target_name)
end
def write
instance.write if enabled?
end
def instance
@instance ||= new("#{MRUBY_CONFIG}.lock")
end
end
def initialize(filename)
@filename = filename
end
def build(target_name)
read[target_name] ||= {}
end
def write
locks = {"mruby_version" => mruby}
locks["builds"] = @builds if @builds
File.write(@filename, YAML.dump(locks))
end
private
def read
@builds ||= if File.exist?(@filename)
YAML.load_file(@filename)["builds"] || {}
else
{}
end
end
def shellquote(s)
if ENV['OS'] == 'Windows_NT'
"\"#{s}\""
else
"'#{s}'"
end
end
def mruby
mruby = {
'version' => MRuby::Source::MRUBY_VERSION,
'release_no' => MRuby::Source::MRUBY_RELEASE_NO,
}
git_dir = "#{MRUBY_ROOT}/.git"
if File.directory?(git_dir)
mruby['git_commit'] = `git --git-dir #{shellquote(git_dir)} --work-tree #{shellquote(MRUBY_ROOT)} rev-parse --verify HEAD`.strip
end
mruby
end
enable
end
end
+3 -1
View File
@@ -6,7 +6,9 @@ module MRuby
ROOT = Pathname.new(File.expand_path('../../../',__FILE__))
# Reads a constant defined at version.h
MRUBY_READ_VERSION_CONSTANT = Proc.new { |name| ROOT.join('include','mruby','version.h').read.match(/^#define #{name} +"?([\w\. ]+)"?$/)[1] }
MRUBY_READ_VERSION_CONSTANT = Proc.new do |name|
ROOT.join('include','mruby','version.h').read.match(/^#define #{name} +"?([\w\. ]+)"?\r?$/)[1]
end
MRUBY_RUBY_VERSION = MRUBY_READ_VERSION_CONSTANT['MRUBY_RUBY_VERSION']
MRUBY_RUBY_ENGINE = MRUBY_READ_VERSION_CONSTANT['MRUBY_RUBY_ENGINE']
+2 -605
View File
@@ -1,605 +1,2 @@
#!/usr/bin/env ruby
# Original is https://github.com/jimweirich/rake/
# Copyright (c) 2003 Jim Weirich
# License: MIT-LICENSE
require 'getoptlong'
require 'fileutils'
$rake_fiber_table = {}
$rake_jobs = 1
$rake_failed = []
class String
def ext(newext='')
return self.dup if ['.', '..'].include? self
if newext != ''
newext = (newext =~ /^\./) ? newext : ("." + newext)
end
self.chomp(File.extname(self)) << newext
end
def pathmap(spec=nil, &block)
return self if spec.nil?
result = ''
spec.scan(/%\{[^}]*\}-?\d*[sdpfnxX%]|%-?\d+d|%.|[^%]+/) do |frag|
case frag
when '%f'
result << File.basename(self)
when '%n'
result << File.basename(self).ext
when '%d'
result << File.dirname(self)
when '%x'
result << File.extname(self)
when '%X'
result << self.ext
when '%p'
result << self
when '%s'
result << (File::ALT_SEPARATOR || File::SEPARATOR)
when '%-'
# do nothing
when '%%'
result << "%"
when /%(-?\d+)d/
result << pathmap_partial($1.to_i)
when /^%\{([^}]*)\}(\d*[dpfnxX])/
patterns, operator = $1, $2
result << pathmap('%' + operator).pathmap_replace(patterns, &block)
when /^%/
fail ArgumentError, "Unknown pathmap specifier #{frag} in '#{spec}'"
else
result << frag
end
end
result
end
end
module MiniRake
class Task
TASKS = Hash.new
RULES = Array.new
# List of prerequisites for a task.
attr_reader :prerequisites
# Source dependency for rule synthesized tasks. Nil if task was not
# sythesized from a rule.
attr_accessor :source
# Create a task named +task_name+ with no actions or prerequisites..
# use +enhance+ to add actions and prerequisites.
def initialize(task_name)
@name = task_name
@prerequisites = []
@actions = []
end
# Enhance a task with prerequisites or actions. Returns self.
def enhance(deps=nil, &block)
@prerequisites |= deps if deps
@actions << block if block_given?
self
end
# Name of the task.
def name
@name.to_s
end
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
prerequisites = @prerequisites.collect{ |n| n.is_a?(Proc) ? n.call(name) : n }.flatten
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.
def execute
puts "Execute #{name}" if $trace
self.class.enhance_with_matching_rule(name) if @actions.empty?
unless $dryrun
@actions.each { |act| act.call(self) }
end
@done = true
@running = false
end
# Is this task needed?
def needed?
true
end
# Timestamp for this task. Basic tasks return the current time for
# their time stamp. Other tasks can be more sophisticated.
def timestamp
Time.now
end
# Class Methods ----------------------------------------------------
class << self
# Clear the task list. This cause rake to immediately forget all
# the tasks that have been assigned. (Normally used in the unit
# tests.)
def clear
TASKS.clear
RULES.clear
end
# List of all defined tasks.
def tasks
TASKS.keys.sort.collect { |tn| Task[tn] }
end
# Return a task with the given name. If the task is not currently
# known, try to synthesize one from the defined rules. If no
# rules are found, but an existing file matches the task name,
# assume it is a file task with no dependencies or actions.
def [](task_name)
task_name = task_name.to_s
if task = TASKS[task_name]
return task
end
if task = enhance_with_matching_rule(task_name)
return task
end
if File.exist?(task_name)
return FileTask.define_task(task_name)
end
fail "Don't know how to rake #{task_name}"
end
# Define a task given +args+ and an option block. If a rule with
# the given name already exists, the prerequisites and actions are
# added to the existing task.
def define_task(args, &block)
task_name, deps = resolve_args(args)
lookup(task_name).enhance([deps].flatten, &block)
end
# Define a rule for synthesizing tasks.
def create_rule(args, &block)
pattern, deps = resolve_args(args)
pattern = Regexp.new(Regexp.quote(pattern) + '$') if String === pattern
RULES << [pattern, deps, block]
end
# Lookup a task. Return an existing task if found, otherwise
# create a task of the current type.
def lookup(task_name)
name = task_name.to_s
TASKS[name] ||= self.new(name)
end
# If a rule can be found that matches the task name, enhance the
# task with the prerequisites and actions from the rule. Set the
# source attribute of the task appropriately for the rule. Return
# the enhanced task or nil of no rule was found.
def enhance_with_matching_rule(task_name)
RULES.each do |pattern, extensions, block|
if pattern.match(task_name)
ext = extensions.first
deps = extensions[1..-1]
case ext
when String
source = task_name.sub(/\.[^.]*$/, ext)
when Proc
source = ext.call(task_name)
else
fail "Don't know how to handle rule dependent: #{ext.inspect}"
end
if File.exist?(source)
task = FileTask.define_task({task_name => [source]+deps}, &block)
task.source = source
return task
end
end
end
nil
end
private
# Resolve the arguments for a task/rule.
def resolve_args(args)
case args
when Hash
fail "Too Many Task Names: #{args.keys.join(' ')}" if args.size > 1
fail "No Task Name Given" if args.size < 1
task_name = args.keys[0]
deps = args[task_name]
deps = [deps] if (String===deps) || (Regexp===deps) || (Proc===deps)
else
task_name = args
deps = []
end
[task_name, deps]
end
end
end
######################################################################
class FileTask < Task
# Is this file task needed? Yes if it doesn't exist, or if its time
# stamp is out of date.
def needed?
return true unless File.exist?(name)
prerequisites = @prerequisites.collect{ |n| n.is_a?(Proc) ? n.call(name) : n }.flatten
latest_prereq = prerequisites.collect{|n| Task[n].timestamp}.max
return false if latest_prereq.nil?
timestamp < latest_prereq
end
# Time stamp for file task.
def timestamp
return Time.at(0) unless File.exist?(name)
stat = File::stat(name.to_s)
stat.directory? ? Time.at(0) : stat.mtime
end
end
module DSL
# Declare a basic task.
def task(args, &block)
MiniRake::Task.define_task(args, &block)
end
# Declare a file task.
def file(args, &block)
MiniRake::FileTask.define_task(args, &block)
end
# Declare a set of files tasks to create the given directories on
# demand.
def directory(args, &block)
MiniRake::FileTask.define_task(args) do |t|
block.call(t) unless block.nil?
dir = args.is_a?(Hash) ? args.keys.first : args
(dir.split(File::SEPARATOR) + ['']).inject do |acc, part|
(acc + File::SEPARATOR).tap do |d|
Dir.mkdir(d) unless File.exists? d
end + part
end
end
end
# Declare a rule for auto-tasks.
def rule(args, &block)
MiniRake::Task.create_rule(args, &block)
end
# Write a message to standard out if $verbose is enabled.
def log(msg)
print " " if $trace && $verbose
puts msg if $verbose
end
# Run the system command +cmd+.
def sh(cmd)
puts cmd if $verbose
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)
end
end
end
Rake = MiniRake
extend MiniRake::DSL
######################################################################
# Task Definition Functions ...
######################################################################
# Rake main application object. When invoking +rake+ from the command
# line, a RakeApp object is created and run.
#
class RakeApp
RAKEFILES = ['rakefile', 'Rakefile']
OPTIONS = [
['--dry-run', '-n', GetoptLong::NO_ARGUMENT,
"Do a dry run without executing actions."],
['--help', '-H', GetoptLong::NO_ARGUMENT,
"Display this help message."],
['--libdir', '-I', GetoptLong::REQUIRED_ARGUMENT,
"Include LIBDIR in the search path for required modules."],
['--nosearch', '-N', GetoptLong::NO_ARGUMENT,
"Do not search parent directories for the Rakefile."],
['--quiet', '-q', GetoptLong::NO_ARGUMENT,
"Do not log messages to standard output (default)."],
['--rakefile', '-f', GetoptLong::REQUIRED_ARGUMENT,
"Use FILE as the rakefile."],
['--require', '-r', GetoptLong::REQUIRED_ARGUMENT,
"Require MODULE before executing rakefile."],
['--tasks', '-T', GetoptLong::NO_ARGUMENT,
"Display the tasks and dependencies, then exit."],
['--pull-gems','-p', GetoptLong::NO_ARGUMENT,
"Pull all git mrbgems."],
['--trace', '-t', GetoptLong::NO_ARGUMENT,
"Turn on invoke/execute tracing."],
['--usage', '-h', GetoptLong::NO_ARGUMENT,
"Display usage."],
['--verbose', '-v', GetoptLong::NO_ARGUMENT,
"Log message to standard output."],
['--directory', '-C', GetoptLong::REQUIRED_ARGUMENT,
"Change executing directory of rakefiles."],
['--jobs', '-j', GetoptLong::REQUIRED_ARGUMENT,
'Execute rake with parallel jobs.']
]
# Create a RakeApp object.
def initialize
@rakefile = nil
@nosearch = false
end
# True if one of the files in RAKEFILES is in the current directory.
# If a match is found, it is copied into @rakefile.
def have_rakefile
RAKEFILES.each do |fn|
if File.exist?(fn)
@rakefile = fn
return true
end
end
return false
end
# Display the program usage line.
def usage
puts "rake [-f rakefile] {options} targets..."
end
# Display the rake command line help.
def help
usage
puts
puts "Options are ..."
puts
OPTIONS.sort.each do |long, short, mode, desc|
if mode == GetoptLong::REQUIRED_ARGUMENT
if desc =~ /\b([A-Z]{2,})\b/
long = long + "=#{$1}"
end
end
printf " %-20s (%s)\n", long, short
printf " %s\n", desc
end
end
# Display the tasks and dependencies.
def display_tasks
MiniRake::Task.tasks.each do |t|
puts "#{t.class} #{t.name}"
t.prerequisites.each { |pre| puts " #{pre}" }
end
end
# Return a list of the command line options supported by the
# program.
def command_line_options
OPTIONS.collect { |lst| lst[0..-2] }
end
# Do the option defined by +opt+ and +value+.
def do_option(opt, value)
case opt
when '--dry-run'
$dryrun = true
$trace = true
when '--help'
help
exit
when '--libdir'
$:.push(value)
when '--nosearch'
@nosearch = true
when '--quiet'
$verbose = false
when '--rakefile'
RAKEFILES.clear
RAKEFILES << value
when '--require'
require value
when '--tasks'
$show_tasks = true
when '--pull-gems'
$pull_gems = true
when '--trace'
$trace = true
when '--usage'
usage
exit
when '--verbose'
$verbose = true
when '--version'
puts "rake, version #{RAKEVERSION}"
exit
when '--directory'
Dir.chdir value
when '--jobs'
$rake_jobs = [value.to_i, 1].max
else
fail "Unknown option: #{opt}"
end
end
# Read and handle the command line options.
def handle_options
$verbose = false
$pull_gems = false
opts = GetoptLong.new(*command_line_options)
opts.each { |opt, value| do_option(opt, value) }
end
# 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
Dir.chdir("..")
if Dir.pwd == here || @nosearch
fail "No Rakefile found (looking for: #{RAKEFILES.join(', ')})"
end
here = Dir.pwd
end
root_tasks = []
ARGV.each do |task_name|
if /^(\w+)=(.*)/.match(task_name)
ENV[$1] = $2
else
root_tasks << task_name
end
end
puts "(in #{Dir.pwd})"
$rakefile = @rakefile
load @rakefile
if $show_tasks
display_tasks
else
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 => 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 || $verbose
puts ex.backtrace.join("\n")
else
puts ex.backtrace.find {|str| str =~ /#{@rakefile}/ } || ""
end
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
RakeApp.new.run
end
#! /usr/bin/env ruby
exec "rake", *ARGV
+10
View File
@@ -71,6 +71,10 @@ MRuby::GemBox.new do |conf|
# Use toplevel object (main) methods extension
conf.gem :core => "mruby-toplevel-ext"
# Use Rational/Complex numbers
conf.gem :core => "mruby-rational"
conf.gem :core => "mruby-complex"
# Generate mirb command
conf.gem :core => "mruby-bin-mirb"
@@ -86,6 +90,12 @@ MRuby::GemBox.new do |conf|
# Use class/module extension
conf.gem :core => "mruby-class-ext"
# Use Method/UnboundMethod class
conf.gem :core => "mruby-method"
# Use eval()
conf.gem :core => "mruby-eval"
# Use mruby-compiler to build other mrbgems
conf.gem :core => "mruby-compiler"
end
-1
View File
@@ -2,5 +2,4 @@ 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
+47 -40
View File
@@ -88,6 +88,22 @@ class Array
array
end
##
# call-seq:
# ary.difference(other_ary1, other_ary2, ...) -> new_ary
#
# Returns a new array that is a copy of the original array, removing all
# occurrences of any item that also appear in +other_ary+. The order is
# preserved from the original array.
#
def difference(*args)
ary = self
args.each do |x|
ary = ary - x
end
ary
end
##
# call-seq:
# ary | other_ary -> new_ary
@@ -157,6 +173,24 @@ class Array
array
end
##
# call-seq:
# ary.intersection(other_ary,...) -> new_ary
#
# Set Intersection---Returns a new array containing elements common to
# this array and <i>other_ary</i>s, removing duplicates. The order is
# preserved from the original array.
#
# [1, 2, 3].intersection([3, 4, 1], [1, 3, 5]) #=> [1, 3]
#
def intersection(*args)
ary = self
args.each do |x|
ary = ary & x
end
ary
end
##
# call-seq:
# ary.flatten -> new_ary
@@ -652,37 +686,6 @@ class Array
satisfied ? low : nil
end
##
# call-seq:
# ary.delete_if { |item| block } -> ary
# ary.delete_if -> Enumerator
#
# Deletes every element of +self+ for which block evaluates to +true+.
#
# The array is changed instantly every time the block is called, not after
# the iteration is over.
#
# See also Array#reject!
#
# If no block is given, an Enumerator is returned instead.
#
# scores = [ 97, 42, 75 ]
# scores.delete_if {|score| score < 80 } #=> [97]
def delete_if(&block)
return to_enum :delete_if unless block
idx = 0
while idx < self.size do
if block.call(self[idx])
self.delete_at(idx)
else
idx += 1
end
end
self
end
##
# call-seq:
# ary.keep_if { |item| block } -> ary
@@ -815,12 +818,11 @@ class Array
# 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
size = self.size
if n == 0
yield []
else
yield []
elsif 0 < n && n <= size
i = 0
while i<size
result = [self[i]]
@@ -835,6 +837,7 @@ class Array
i += 1
end
end
self
end
##
@@ -861,9 +864,8 @@ class Array
# 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
size = self.size
if n == 0
yield []
elsif n == 1
@@ -872,7 +874,7 @@ class Array
yield [self[i]]
i += 1
end
else
elsif n <= size
i = 0
while i<size
result = [self[i]]
@@ -882,6 +884,7 @@ class Array
i += 1
end
end
self
end
##
@@ -903,8 +906,8 @@ class Array
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
column_count ||= row.size
raise IndexError, 'element size differs' unless column_count == row.size
end
Array.new(column_count) do |column_index|
@@ -936,4 +939,8 @@ class Array
end
h
end
alias append push
alias prepend unshift
alias filter! select!
end
+8 -11
View File
@@ -28,9 +28,8 @@ static mrb_value
mrb_ary_assoc(mrb_state *mrb, mrb_value ary)
{
mrb_int i;
mrb_value v, k;
mrb_get_args(mrb, "o", &k);
mrb_value v;
mrb_value k = mrb_get_arg1(mrb);
for (i = 0; i < RARRAY_LEN(ary); ++i) {
v = mrb_check_array_type(mrb, RARRAY_PTR(ary)[i]);
@@ -59,13 +58,12 @@ static mrb_value
mrb_ary_rassoc(mrb_state *mrb, mrb_value ary)
{
mrb_int i;
mrb_value v, value;
mrb_get_args(mrb, "o", &value);
mrb_value v;
mrb_value value = mrb_get_arg1(mrb);
for (i = 0; i < RARRAY_LEN(ary); ++i) {
v = RARRAY_PTR(ary)[i];
if (mrb_type(v) == MRB_TT_ARRAY &&
if (mrb_array_p(v) &&
RARRAY_LEN(v) > 1 &&
mrb_equal(mrb, RARRAY_PTR(v)[1], value))
return v;
@@ -140,12 +138,11 @@ mrb_ary_slice_bang(mrb_state *mrb, mrb_value self)
mrb_ary_modify(mrb, a);
if (mrb_get_argc(mrb) == 1) {
mrb_value index;
mrb_value index = mrb_get_arg1(mrb);
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, ARY_LEN(a), TRUE) == 1) {
if (mrb_range_beg_len(mrb, index, &i, &len, ARY_LEN(a), TRUE) == MRB_RANGE_OK) {
goto delete_pos_len;
}
else {
@@ -194,7 +191,7 @@ mrb_mruby_array_ext_gem_init(mrb_state* mrb)
mrb_define_method(mrb, a, "at", mrb_ary_at, MRB_ARGS_REQ(1));
mrb_define_method(mrb, a, "rassoc", mrb_ary_rassoc, MRB_ARGS_REQ(1));
mrb_define_method(mrb, a, "values_at", mrb_ary_values_at, MRB_ARGS_ANY());
mrb_define_method(mrb, a, "slice!", mrb_ary_slice_bang, MRB_ARGS_ANY());
mrb_define_method(mrb, a, "slice!", mrb_ary_slice_bang, MRB_ARGS_ARG(1,1));
}
void
+50 -42
View File
@@ -1,6 +1,23 @@
##
# Array(Ext) Test
def assert_permutation_combination(exp, receiver, meth, *args)
act = []
ret = receiver.__send__(meth, *args) { |v| act << v }
assert "assert_#{meth}" do
assert_equal(exp, act.sort)
assert_same(receiver, ret)
end
end
def assert_permutation(exp, receiver, *args)
assert_permutation_combination(exp, receiver, :permutation, *args)
end
def assert_combination(exp, receiver, *args)
assert_permutation_combination(exp, receiver, :combination, *args)
end
assert("Array#assoc") do
s1 = [ "colors", "red", "blue", "green" ]
s2 = [ "letters", "a", "b", "c" ]
@@ -76,6 +93,14 @@ assert("Array#union") do
assert_equal [1, 2, 3, 4, 5], a.union(b,c)
end
assert("Array#difference") do
a = [1, 2, 3, 1, 6, 7]
b = [1, 4, 6]
c = [1, 5, 7]
assert_equal [2, 3], a.difference(b,c)
end
assert("Array#&") do
a = [1, 2, 3, 1]
b = [1, 4]
@@ -86,6 +111,14 @@ assert("Array#&") do
assert_equal [1, 2, 3, 1], a
end
assert("Array#intersection") do
a = [1, 2, 3, 1, 8, 6, 7, 8]
b = [1, 4, 6, 8]
c = [1, 5, 7, 8]
assert_equal [1, 8], a.intersection(b,c)
end
assert("Array#flatten") do
assert_equal [1, 2, "3", {4=>5}, :'6'], [1, 2, "3", {4=>5}, :'6'].flatten
assert_equal [1, 2, 3, 4, 5, 6], [1, 2, [3, 4, 5], 6].flatten
@@ -162,12 +195,6 @@ assert("Array#reverse_each") do
b << i
end
assert_equal [ "d", "c", "b", "a" ], b
if Object.const_defined?(:Enumerator)
assert_equal [ "d", "c", "b", "a" ], a.reverse_each.to_a
else
true
end
end
assert("Array#rotate") do
@@ -268,22 +295,9 @@ assert("Array#bsearch") do
end
end
assert("Array#bsearch_index") do
# tested through Array#bsearch
end
assert("Array#delete_if") do
a = [1, 2, 3, 4, 5]
assert_equal [1, 2, 3, 4, 5], a.delete_if { false }
assert_equal [1, 2, 3, 4, 5], a
a = [1, 2, 3, 4, 5]
assert_equal [], a.delete_if { true }
assert_equal [], a
a = [ 1, 2, 3, 4, 5 ]
assert_equal [1, 2, 3], a.delete_if { |val| val > 3 }
end
# tested through Array#bsearch
#assert("Array#bsearch_index") do
#end
assert("Array#keep_if") do
a = [1, 2, 3, 4, 5]
@@ -369,30 +383,24 @@ 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)
assert_permutation([[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]], a)
assert_permutation([[1],[2],[3]], a, 1)
assert_permutation([[1,2],[1,3],[2,1],[2,3],[3,1],[3,2]], a, 2)
assert_permutation([[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]], a, 3)
assert_permutation([[]], a, 0)
assert_permutation([], a, 4)
assert_permutation([], a, -1)
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)
assert_combination([[1],[2],[3],[4]], a, 1)
assert_combination([[1,2],[1,3],[1,4],[2,3],[2,4],[3,4]], a, 2)
assert_combination([[1,2,3],[1,2,4],[1,3,4],[2,3,4]], a, 3)
assert_combination([[1,2,3,4]], a, 4)
assert_combination([[]], a, 0)
assert_combination([], a, 5)
assert_combination([], a, -1)
end
assert('Array#transpose') do
+6 -3
View File
@@ -5,19 +5,22 @@ unless MRuby::Build.current.kind_of?(MRuby::CrossBuild)
spec.author = 'mruby developers'
spec.summary = "#{name} command"
mruby_config_dir = "#{build.build_dir}/bin"
mruby_config = name + (ENV['OS'] == 'Windows_NT' ? '.bat' : '')
mruby_config_path = "#{build.build_dir}/bin/#{mruby_config}"
mruby_config_path = "#{mruby_config_dir}/#{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|
directory mruby_config_dir
file mruby_config_path => [mruby_config_dir, 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)
chmod(0755, t.name)
end
end
end
+19 -17
View File
@@ -1,9 +1,10 @@
require 'open3'
require 'tempfile'
require 'strscan'
class BinTest_MrubyBinDebugger
@debug1=false
@debug2=true
# @debug1=false
# @debug2=true
def self.test(rubysource, testcase)
script, bin = Tempfile.new(['test', '.rb']), Tempfile.new(['test', '.mrb'])
@@ -19,10 +20,20 @@ class BinTest_MrubyBinDebugger
stdin_data = testcase.map{|t| t[:cmd]}.join("\n") << "\n"
prompt = /^\(#{Regexp.escape(script.path)}:\d+\) /
["bin/mrdb #{script.path}","bin/mrdb -b #{bin.path}"].each do |cmd|
o, s = Open3.capture2(cmd, :stdin_data => stdin_data)
scanner = StringScanner.new(o)
scanner.skip_until(prompt)
testcase.each do |tc|
exp = tc[:exp]
if exp
act = scanner.scan_until(/\n/)
break unless assert_operator act, :start_with?, exp
end
scanner.skip_until(prompt)
end
exp_vals = testcase.map{|t| t.fetch(:exp, nil)}
=begin
if @debug1
o.split("\n").each_with_index do |i,actual|
@@ -41,14 +52,6 @@ end
assert_true actual.include?(exp) unless exp.nil?
end
=end
idx = 0
exp_vals.each do |exp|
next if exp.nil?
idx = o.index(exp, idx)
assert_false idx.nil?
break unless idx
idx += 1
end
end
end
end
@@ -90,8 +93,8 @@ assert('mruby-bin-debugger(print) error') do
# test case
tc = []
tc << {:cmd=>"p (1+2", :exp=>'$1 = SyntaxError'}
tc << {:cmd=>"p bar", :exp=>'$2 = (eval):2: undefined method'}
tc << {:cmd=>"p (1+2", :exp=>'$1 = line 1: syntax error'}
tc << {:cmd=>"p bar", :exp=>'$2 = undefined method'}
BinTest_MrubyBinDebugger.test(src, tc)
end
@@ -588,7 +591,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 = (eval):2: undefined method'}
tc << {:cmd=>'p "#{undefined}"', :exp=>'$4 = undefined method'}
BinTest_MrubyBinDebugger.test(src, tc)
end
@@ -626,7 +629,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 = (eval):2: undefined method'}
tc << {:cmd=>'p "#{undefined}"', :exp=>'$15 = undefined method'}
BinTest_MrubyBinDebugger.test(src, tc)
end
@@ -694,8 +697,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 = (eval):2: undefined method'}
tc << {:cmd=>'p "#{undefined}"', :exp=>'$15 = undefined method'}
BinTest_MrubyBinDebugger.test(src, tc)
end
@@ -95,7 +95,7 @@ check_file_lineno(mrb_state *mrb, struct mrb_irep *irep, const char *file, uint1
for (f_idx = 0; f_idx < irep->debug_info->flen; ++f_idx) {
const char *filename;
info_file = irep->debug_info->files[f_idx];
filename = mrb_sym2name_len(mrb, info_file->filename_sym, NULL);
filename = mrb_sym_name_len(mrb, info_file->filename_sym, NULL);
if (!strcmp(filename, file)) {
result = MRB_DEBUG_BP_FILE_OK;
@@ -126,7 +126,7 @@ compare_break_method(mrb_state *mrb, mrb_debug_breakpoint *bp, struct RClass *cl
mrb_debug_methodpoint *method_p;
mrb_bool is_defined;
method_name = mrb_sym2name(mrb, method_sym);
method_name = mrb_sym_name(mrb, method_sym);
method_p = &bp->point.methodpoint;
if (strcmp(method_p->method_name, method_name) == 0) {
@@ -428,7 +428,7 @@ mrb_debug_disable_break_all(mrb_state *mrb, mrb_debug_context *dbg)
}
static mrb_bool
check_start_pc_for_line(mrb_state *mrb, mrb_irep *irep, mrb_code *pc, uint16_t line)
check_start_pc_for_line(mrb_state *mrb, mrb_irep *irep, const mrb_code *pc, uint16_t line)
{
if (pc > irep->iseq) {
if (line == mrb_debug_get_line(mrb, irep, pc - irep->iseq - 1)) {
@@ -33,7 +33,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, int direct_eval)
{
void (*tmp)(struct mrb_state *, struct mrb_irep *, mrb_code *, mrb_value *);
void (*tmp)(struct mrb_state *, struct mrb_irep *, const mrb_code *, mrb_value *);
mrb_value ruby_code;
mrb_value s;
mrb_value v;
@@ -74,7 +74,7 @@ mrb_debug_eval(mrb_state *mrb, mrb_debug_context *dbg, const char *expr, size_t
*exc = mrb_obj_is_kind_of(mrb, v, mrb->eException_class);
}
s = mrb_funcall(mrb, v, "inspect", 0);
s = mrb_inspect(mrb, v);
/* enable code_fetch_hook */
mrb->code_fetch_hook = tmp;
@@ -18,7 +18,6 @@ dbgcmd_print(mrb_state *mrb, mrdb_state *mrdb)
{
mrb_value expr;
mrb_value result;
mrb_value s;
uint8_t wcnt;
int ai;
@@ -39,8 +38,9 @@ dbgcmd_print(mrb_state *mrb, mrdb_state *mrdb)
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");
printf("$%lu = %s\n", (unsigned long)mrdb->print_no++, RSTRING_PTR(s));
printf("$%lu = ", (unsigned long)mrdb->print_no++);
fwrite(RSTRING_PTR(result), RSTRING_LEN(result), 1, stdout);
putc('\n', stdout);
if (mrdb->print_no == 0) {
mrdb->print_no = 1;
+2 -3
View File
@@ -5,7 +5,6 @@
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <ctype.h>
#include <mruby.h>
@@ -505,7 +504,7 @@ get_and_parse_command(mrb_state *mrb, mrdb_state *mrdb)
}
static int32_t
check_method_breakpoint(mrb_state *mrb, mrb_irep *irep, mrb_code *pc, mrb_value *regs)
check_method_breakpoint(mrb_state *mrb, mrb_irep *irep, const mrb_code *pc, mrb_value *regs)
{
struct RClass* c;
mrb_sym sym;
@@ -546,7 +545,7 @@ check_method_breakpoint(mrb_state *mrb, mrb_irep *irep, mrb_code *pc, mrb_value
}
static void
mrb_code_fetch_hook(mrb_state *mrb, mrb_irep *irep, mrb_code *pc, mrb_value *regs)
mrb_code_fetch_hook(mrb_state *mrb, mrb_irep *irep, const mrb_code *pc, mrb_value *regs)
{
const char *file;
int32_t line;
+1 -1
View File
@@ -105,7 +105,7 @@ typedef struct mrb_debug_breakpoint {
typedef struct mrb_debug_context {
struct mrb_irep *root_irep;
struct mrb_irep *irep;
mrb_code *pc;
const mrb_code *pc;
mrb_value *regs;
const char *prvfile;
@@ -6,6 +6,14 @@
#ifndef MRDBCONF_H
#define MRDBCONF_H
#ifndef MRB_ENABLE_DEBUG_HOOK
# error mruby-bin-debugger need 'MRB_ENABLE_DEBUG_HOOK' configuration in your 'build_config.rb'
#endif
#ifdef MRB_DISABLE_STDIO
# error mruby-bin-debugger conflicts 'MRB_DISABLE_STDIO' configuration in your 'build_config.rb'
#endif
/* configuration options: */
/* maximum size for command buffer */
#define MAX_COMMAND_LINE 1024
+35 -4
View File
@@ -7,6 +7,11 @@
*/
#include <mruby.h>
#ifdef MRB_DISABLE_STDIO
# error mruby-bin-mirb conflicts 'MRB_DISABLE_STDIO' configuration in your 'build_config.rb'
#endif
#include <mruby/array.h>
#include <mruby/proc.h>
#include <mruby/compile.h>
@@ -17,7 +22,6 @@
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <ctype.h>
#include <signal.h>
@@ -240,7 +244,7 @@ usage(const char *name)
};
const char *const *p = usage_msg;
printf("Usage: %s [switches]\n", name);
printf("Usage: %s [switches] [programfile] [arguments]\n", name);
while (*p)
printf(" %s\n", *p++);
}
@@ -406,6 +410,26 @@ ctrl_c_handler(int signo)
}
#endif
#ifndef DISABLE_MIRB_UNDERSCORE
void decl_lv_underscore(mrb_state *mrb, mrbc_context *cxt)
{
struct RProc *proc;
struct mrb_parser_state *parser;
parser = mrb_parse_string(mrb, "_=nil", cxt);
if (parser == NULL) {
fputs("create parser state error\n", stderr);
mrb_close(mrb);
exit(EXIT_FAILURE);
}
proc = mrb_generate_code(mrb, parser);
mrb_vm_run(mrb, proc, mrb_top_self(mrb), 0);
mrb_parser_free(parser);
}
#endif
int
main(int argc, char **argv)
{
@@ -471,6 +495,10 @@ main(int argc, char **argv)
cxt = mrbc_context_new(mrb);
#ifndef DISABLE_MIRB_UNDERSCORE
decl_lv_underscore(mrb, cxt);
#endif
/* Load libraries */
for (i = 0; i < args.libc; i++) {
FILE *lfp = fopen(args.libv[i], "r");
@@ -621,8 +649,8 @@ main(int argc, char **argv)
/* 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);
if (e && MRB_ENV_LEN(e) < proc->body.irep->nlocals) {
MRB_ENV_SET_LEN(e, proc->body.irep->nlocals);
}
}
/* pass a proc for evaluation */
@@ -643,6 +671,9 @@ main(int argc, char **argv)
result = mrb_any_to_s(mrb, result);
}
p(mrb, result, 1);
#ifndef DISABLE_MIRB_UNDERSCORE
*(mrb->c->stack + 1) = result;
#endif
}
}
ruby_code[0] = '\0';
+27 -25
View File
@@ -1,7 +1,11 @@
#include <stdio.h>
#include <mruby.h>
#ifdef MRB_DISABLE_STDIO
# error mruby-bin-mrbc conflicts 'MRB_DISABLE_STDIO' configuration in your 'build_config.rb'
#endif
#include <stdlib.h>
#include <string.h>
#include <mruby.h>
#include <mruby/compile.h>
#include <mruby/dump.h>
#include <mruby/proc.h>
@@ -32,8 +36,6 @@ usage(const char *name)
"-v print version number, then turn on verbose mode",
"-g produce debugging information",
"-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",
@@ -50,19 +52,26 @@ usage(const char *name)
static char *
get_outfilename(mrb_state *mrb, char *infile, const char *ext)
{
size_t infilelen;
size_t extlen;
size_t ilen, flen, elen;
char *outfile;
char *p;
char *p = NULL;
infilelen = strlen(infile);
extlen = strlen(ext);
outfile = (char*)mrb_malloc(mrb, infilelen + extlen + 1);
memcpy(outfile, infile, infilelen + 1);
ilen = strlen(infile);
flen = ilen;
if (*ext) {
if ((p = strrchr(outfile, '.')) == NULL)
p = outfile + infilelen;
memcpy(p, ext, extlen + 1);
elen = strlen(ext);
if ((p = strrchr(infile, '.'))) {
ilen = p - infile;
}
flen += elen;
}
else {
flen = ilen;
}
outfile = (char*)mrb_malloc(mrb, flen+1);
strncpy(outfile, infile, ilen+1);
if (p) {
strncpy(outfile+ilen, ext, elen+1);
}
return outfile;
@@ -71,7 +80,6 @@ get_outfilename(mrb_state *mrb, char *infile, const char *ext)
static int
parse_args(mrb_state *mrb, int argc, char **argv, struct mrbc_args *args)
{
char *outfile = NULL;
static const struct mrbc_args args_zero = { 0 };
int i;
@@ -86,7 +94,7 @@ parse_args(mrb_state *mrb, int argc, char **argv, struct mrbc_args *args)
case 'o':
if (args->outfile) {
fprintf(stderr, "%s: an output file is already specified. (%s)\n",
args->prog, outfile);
args->prog, args->outfile);
return -1;
}
if (argv[i][2] == '\0' && argv[i+1]) {
@@ -121,10 +129,8 @@ parse_args(mrb_state *mrb, int argc, char **argv, struct mrbc_args *args)
args->flags |= DUMP_DEBUG_INFO;
break;
case 'E':
args->flags = DUMP_ENDIAN_BIG | (args->flags & ~DUMP_ENDIAN_MASK);
break;
case 'e':
args->flags = DUMP_ENDIAN_LIL | (args->flags & ~DUMP_ENDIAN_MASK);
fprintf(stderr, "%s: -e/-E option no longer needed.\n", args->prog);
break;
case 'h':
return -1;
@@ -157,10 +163,6 @@ parse_args(mrb_state *mrb, int argc, char **argv, struct mrbc_args *args)
break;
}
}
if (args->verbose && args->initname && (args->flags & DUMP_ENDIAN_MASK) == 0) {
fprintf(stderr, "%s: generating %s endian C file. specify -e/-E for cross compiling.\n",
args->prog, bigendian_p() ? "big" : "little");
}
return i;
}
@@ -184,7 +186,7 @@ partial_hook(struct mrb_parser_state *p)
return -1;
}
fn = args->argv[args->idx++];
p->f = fopen(fn, "r");
p->f = fopen(fn, "rb");
if (p->f == NULL) {
fprintf(stderr, "%s: cannot open program file. (%s)\n", args->prog, fn);
return -1;
@@ -211,7 +213,7 @@ load_file(mrb_state *mrb, struct mrbc_args *args)
}
else {
need_close = TRUE;
if ((infile = fopen(input, "r")) == NULL) {
if ((infile = fopen(input, "rb")) == NULL) {
fprintf(stderr, "%s: cannot open program file. (%s)\n", args->prog, input);
return mrb_nil_value();
}
+75 -8
View File
@@ -1,10 +1,18 @@
require 'tempfile'
require 'open3'
def assert_mruby(exp_out, exp_err, exp_success, args)
out, err, stat = Open3.capture3(cmd("mruby"), *args)
assert "assert_mruby" do
assert_operator(exp_out, :===, out, "standard output")
assert_operator(exp_err, :===, err, "standard error")
assert_equal(exp_success, stat.success?, "exit success?")
end
end
assert('regression for #1564') do
o = `#{cmd('mruby')} -e #{shellquote('<<')} 2>&1`
assert_include o, "-e:1:2: syntax error"
o = `#{cmd('mruby')} -e #{shellquote('<<-')} 2>&1`
assert_include o, "-e:1:3: syntax error"
assert_mruby("", /\A-e:1:2: syntax error, .*\n\z/, false, %w[-e <<])
assert_mruby("", /\A-e:1:3: syntax error, .*\n\z/, false, %w[-e <<-])
end
assert('regression for #1572') do
@@ -31,6 +39,11 @@ assert '$0 value' do
assert_equal '"-e"', `#{cmd('mruby')} -e #{shellquote('p $0')}`.chomp
end
assert 'ARGV value' do
assert_mruby(%{["ab", "cde"]\n}, "", true, %w[-e p(ARGV) ab cde])
assert_mruby("[]\n", "", true, %w[-e p(ARGV)])
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?]'
@@ -66,11 +79,22 @@ RUBY
assert_equal 0, $?.exitstatus
end
assert('mruby -c option') do
assert_mruby("Syntax OK\n", "", true, ["-c", "-e", "p 1"])
assert_mruby("", /\A-e:1:7: syntax error, .*\n\z/, false, ["-c", "-e", "p 1; 1."])
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
assert_mruby("false\n", "", true, ["-e", "p $DEBUG"])
assert_mruby("true\n", "", true, ["-dep $DEBUG"])
end
assert('mruby -e option (no code specified)') do
assert_mruby("", /\A.*: No code specified for -e\n\z/, false, %w[-e])
end
assert('mruby -h option') do
assert_mruby(/\AUsage: #{Regexp.escape cmd("mruby")} .*/m, "", true, %w[-h])
end
assert('mruby -r option') do
@@ -95,3 +119,46 @@ EOS
assert_equal 'hogeClass', `#{cmd('mruby')} -r #{lib.path} -r #{script.path} -e #{shellquote('print Hoge.class')}`
assert_equal 0, $?.exitstatus
end
assert('mruby -r option (no library specified)') do
assert_mruby("", /\A.*: No library specified for -r\n\z/, false, %w[-r])
end
assert('mruby -r option (file not found)') do
assert_mruby("", /\A.*: Cannot open library file: .*\n\z/, false, %w[-r _no_exists_])
end
assert('mruby -v option') do
ver_re = '\Amruby \d+\.\d+\.\d+ \(\d+-\d+-\d+\)\n'
assert_mruby(/#{ver_re}\z/, "", true, %w[-v])
assert_mruby(/#{ver_re}^[^\n]*NODE.*\n:end\n\z/m, "", true, %w[-v -e p(:end)])
end
assert('mruby --verbose option') do
assert_mruby(/\A[^\n]*NODE.*\n:end\n\z/m, "", true, %w[--verbose -e p(:end)])
end
assert('mruby --') do
assert_mruby(%{["-x", "1"]\n}, "", true, %w[-e p(ARGV) -- -x 1])
end
assert('mruby invalid short option') do
assert_mruby("", /\A.*: invalid option -1 .*\n\z/, false, %w[-1])
end
assert('mruby invalid long option') do
assert_mruby("", /\A.*: invalid option --longopt .*\n\z/, false, %w[--longopt])
end
assert('unhandled exception') do
assert_mruby("", /\bEXCEPTION\b.*\n\z/, false, %w[-e raise("EXCEPTION")])
end
assert('program file not found') do
assert_mruby("", /\A.*: Cannot open program file: .*\n\z/, false, %w[_no_exists_])
end
assert('codegen error') do
code = "def f(#{(1..100).map{|n| "a#{n}"} * ","}); end"
assert_mruby("", /\Acodegen error:.*\n\z/, false, ["-e", code])
end
-1
View File
@@ -4,7 +4,6 @@ MRuby::Gem::Specification.new('mruby-bin-mruby') do |spec|
spec.summary = 'mruby command'
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?
+140 -92
View File
@@ -1,39 +1,39 @@
#include <stdio.h>
#include <mruby.h>
#ifdef MRB_DISABLE_STDIO
# error mruby-bin-mruby conflicts 'MRB_DISABLE_STDIO' configuration in your 'build_config.rb'
#endif
#include <stdlib.h>
#include <string.h>
#include <mruby.h>
#include <mruby/array.h>
#include <mruby/compile.h>
#include <mruby/dump.h>
#include <mruby/variable.h>
#ifdef MRB_DISABLE_STDIO
static void
p(mrb_state *mrb, mrb_value obj)
{
mrb_value val = mrb_inspect(mrb, obj);
fwrite(RSTRING_PTR(val), RSTRING_LEN(val), 1, stdout);
putc('\n', stdout);
}
#else
#define p(mrb,obj) mrb_p(mrb,obj)
#endif
struct _args {
FILE *rfp;
char* cmdline;
char *cmdline;
mrb_bool fname : 1;
mrb_bool mrbfile : 1;
mrb_bool check_syntax : 1;
mrb_bool verbose : 1;
mrb_bool version : 1;
mrb_bool debug : 1;
int argc;
char** argv;
char **argv;
int libc;
char **libv;
};
struct options {
int argc;
char **argv;
char *program;
char *opt;
char short_opt[2];
};
static void
usage(const char *name)
{
@@ -52,11 +52,69 @@ usage(const char *name)
};
const char *const *p = usage_msg;
printf("Usage: %s [switches] programfile\n", name);
printf("Usage: %s [switches] [programfile] [arguments]\n", name);
while (*p)
printf(" %s\n", *p++);
}
static void
options_init(struct options *opts, int argc, char **argv)
{
opts->argc = argc;
opts->argv = argv;
opts->program = *argv;
*opts->short_opt = 0;
}
static const char *
options_opt(struct options *opts)
{
/* concatenated short options (e.g. `-cv`) */
if (*opts->short_opt && *++opts->opt) {
short_opt:
opts->short_opt[0] = *opts->opt;
opts->short_opt[1] = 0;
return opts->short_opt;
}
while (++opts->argv, --opts->argc) {
opts->opt = *opts->argv;
/* empty || not start with `-` || `-` */
if (!opts->opt[0] || opts->opt[0] != '-' || !opts->opt[1]) return NULL;
if (opts->opt[1] == '-') {
/* `--` */
if (!opts->opt[2]) {
++opts->argv, --opts->argc;
return NULL;
}
/* long option */
opts->opt += 2;
*opts->short_opt = 0;
return opts->opt;
}
else {
/* short option */
++opts->opt;
goto short_opt;
}
}
return NULL;
}
static const char *
options_arg(struct options *opts)
{
if (*opts->short_opt && opts->opt[1]) {
/* concatenated short option and option argument (e.g. `-rLIBRARY`) */
*opts->short_opt = 0;
return opts->opt + 1;
}
--opts->argc, ++opts->argv;
return opts->argc ? *opts->argv : NULL;
}
static char *
dup_arg_item(mrb_state *mrb, const char *item)
{
@@ -69,40 +127,24 @@ dup_arg_item(mrb_state *mrb, const char *item)
static int
parse_args(mrb_state *mrb, int argc, char **argv, struct _args *args)
{
char **origargv = argv;
static const struct _args args_zero = { 0 };
struct options opts[1];
const char *opt, *item;
*args = args_zero;
for (argc--,argv++; argc > 0; argc--,argv++) {
char *item;
if (argv[0][0] != '-') break;
if (strlen(*argv) <= 1) {
argc--; argv++;
args->rfp = stdin;
break;
}
item = argv[0] + 1;
switch (*item++) {
case 'b':
options_init(opts, argc, argv);
while ((opt = options_opt(opts))) {
if (strcmp(opt, "b") == 0) {
args->mrbfile = TRUE;
break;
case 'c':
}
else if (strcmp(opt, "c") == 0) {
args->check_syntax = TRUE;
break;
case 'd':
}
else if (strcmp(opt, "d") == 0) {
args->debug = TRUE;
break;
case 'e':
if (item[0]) {
goto append_cmdline;
}
else if (argc > 1) {
argc--; argv++;
item = argv[0];
append_cmdline:
}
else if (strcmp(opt, "e") == 0) {
if ((item = options_arg(opts))) {
if (!args->cmdline) {
args->cmdline = dup_arg_item(mrb, item);
}
@@ -119,55 +161,65 @@ append_cmdline:
}
}
else {
printf("%s: No code specified for -e\n", *origargv);
return EXIT_SUCCESS;
fprintf(stderr, "%s: No code specified for -e\n", opts->program);
return EXIT_FAILURE;
}
break;
case 'r':
if (!item[0]) {
if (argc <= 1) {
printf("%s: No library specified for -r\n", *origargv);
return EXIT_FAILURE;
}
else if (strcmp(opt, "h") == 0) {
usage(opts->program);
exit(EXIT_SUCCESS);
}
else if (strcmp(opt, "r") == 0) {
if ((item = options_arg(opts))) {
if (args->libc == 0) {
args->libv = (char**)mrb_malloc(mrb, sizeof(char*));
}
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);
}
else {
args->libv = (char**)mrb_realloc(mrb, args->libv, sizeof(char*) * (args->libc + 1));
fprintf(stderr, "%s: No library specified for -r\n", opts->program);
return EXIT_FAILURE;
}
args->libv[args->libc++] = dup_arg_item(mrb, item);
break;
case 'v':
if (!args->verbose) mrb_show_version(mrb);
args->verbose = TRUE;
break;
case '-':
if (strcmp((*argv) + 2, "version") == 0) {
}
else if (strcmp(opt, "v") == 0) {
if (!args->verbose) {
mrb_show_version(mrb);
exit(EXIT_SUCCESS);
args->version = TRUE;
}
else if (strcmp((*argv) + 2, "verbose") == 0) {
args->verbose = TRUE;
break;
}
else if (strcmp((*argv) + 2, "copyright") == 0) {
mrb_show_copyright(mrb);
exit(EXIT_SUCCESS);
}
default:
args->verbose = TRUE;
}
else if (strcmp(opt, "version") == 0) {
mrb_show_version(mrb);
exit(EXIT_SUCCESS);
}
else if (strcmp(opt, "verbose") == 0) {
args->verbose = TRUE;
}
else if (strcmp(opt, "copyright") == 0) {
mrb_show_copyright(mrb);
exit(EXIT_SUCCESS);
}
else {
fprintf(stderr, "%s: invalid option %s%s (-h will show valid options)\n",
opts->program, opt[1] ? "--" : "-", opt);
return EXIT_FAILURE;
}
}
if (args->rfp == NULL && args->cmdline == NULL) {
if (*argv == NULL) args->rfp = stdin;
argc = opts->argc; argv = opts->argv;
if (args->cmdline == NULL) {
if (*argv == NULL) {
if (args->version) exit(EXIT_SUCCESS);
args->rfp = stdin;
}
else {
args->rfp = fopen(argv[0], args->mrbfile ? "rb" : "r");
args->rfp = strcmp(argv[0], "-") == 0 ?
stdin : fopen(argv[0], args->mrbfile ? "rb" : "r");
if (args->rfp == NULL) {
printf("%s: Cannot open program file. (%s)\n", *origargv, *argv);
fprintf(stderr, "%s: Cannot open program file: %s\n", opts->program, argv[0]);
return EXIT_FAILURE;
}
args->fname = TRUE;
@@ -212,14 +264,13 @@ main(int argc, char **argv)
mrb_sym zero_sym;
if (mrb == NULL) {
fputs("Invalid mrb_state, exiting mruby\n", stderr);
fprintf(stderr, "%s: Invalid mrb_state, exiting mruby\n", *argv);
return EXIT_FAILURE;
}
n = parse_args(mrb, argc, argv, &args);
if (n == EXIT_FAILURE || (args.cmdline == NULL && args.rfp == NULL)) {
cleanup(mrb, &args);
usage(argv[0]);
return n;
}
else {
@@ -258,7 +309,7 @@ main(int argc, char **argv)
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]);
fprintf(stderr, "%s: Cannot open library file: %s\n", *argv, args.libv[i]);
mrbc_context_free(mrb, c);
cleanup(mrb, &args);
return EXIT_FAILURE;
@@ -289,19 +340,16 @@ main(int argc, char **argv)
mrb_gc_arena_restore(mrb, ai);
mrbc_context_free(mrb, c);
if (mrb->exc) {
if (mrb_undef_p(v)) {
mrb_p(mrb, mrb_obj_value(mrb->exc));
}
else {
if (!mrb_undef_p(v)) {
mrb_print_error(mrb);
}
n = -1;
n = EXIT_FAILURE;
}
else if (args.check_syntax) {
printf("Syntax OK\n");
puts("Syntax OK");
}
}
cleanup(mrb, &args);
return n == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
return n;
}
@@ -1,7 +1,11 @@
#include <stdio.h>
#include <mruby.h>
#ifdef MRB_DISABLE_STDIO
# error mruby-bin-strip conflicts 'MRB_DISABLE_STDIO' configuration in your 'build_config.rb'
#endif
#include <stdlib.h>
#include <string.h>
#include <mruby.h>
#include <mruby/irep.h>
#include <mruby/dump.h>
+12 -8
View File
@@ -5,14 +5,17 @@
static mrb_value
mrb_mod_name(mrb_state *mrb, mrb_value self)
{
mrb_value name = mrb_class_path(mrb, mrb_class_ptr(self));
return mrb_nil_p(name)? name : mrb_str_dup(mrb, name);
mrb_value name = mrb_class_path(mrb, mrb_class_ptr(self));
if (mrb_string_p(name)) {
MRB_SET_FROZEN_FLAG(mrb_basic_ptr(name));
}
return 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);
return mrb_bool_value(mrb_sclass_p(self));
}
/*
@@ -40,14 +43,15 @@ mrb_mod_module_exec(mrb_state *mrb, mrb_value self)
const mrb_value *argv;
mrb_int argc;
mrb_value blk;
struct RClass *c;
mrb_get_args(mrb, "*&", &argv, &argc, &blk);
mrb_get_args(mrb, "*&!", &argv, &argc, &blk);
if (mrb_nil_p(blk)) {
mrb_raise(mrb, E_ARGUMENT_ERROR, "no block given");
c = mrb_class_ptr(self);
if (mrb->c->ci->acc < 0) {
return mrb_yield_with_class(mrb, blk, argc, argv, self, c);
}
mrb->c->ci->target_class = mrb_class_ptr(self);
mrb->c->ci->target_class = c;
return mrb_yield_cont(mrb, blk, self, argc, argv);
}
+161 -95
View File
@@ -102,12 +102,13 @@ codegen_error(codegen_scope *s, const char *message)
while (s->prev) {
codegen_scope *tmp = s->prev;
mrb_free(s->mrb, s->iseq);
mrb_free(s->mrb, s->lines);
mrb_pool_close(s->mpool);
s = tmp;
}
#ifndef MRB_DISABLE_STDIO
if (s->filename_sym && s->lineno) {
const char *filename = mrb_sym2name_len(s->mrb, s->filename_sym, NULL);
const char *filename = mrb_sym_name_len(s->mrb, s->filename_sym, NULL);
fprintf(stderr, "codegen error:%s:%d: %s\n", filename, s->lineno, message);
}
else {
@@ -272,8 +273,7 @@ genop_W(codegen_scope *s, mrb_code i, uint32_t a)
#define NOVAL 0
#define VAL 1
//static
mrb_bool
static mrb_bool
no_optimize(codegen_scope *s)
{
if (s && s->parser && s->parser->no_optimize)
@@ -281,17 +281,8 @@ no_optimize(codegen_scope *s)
return FALSE;
}
static
mrb_bool
on_eval(codegen_scope *s)
{
if (s && s->parser && s->parser->on_eval)
return TRUE;
return FALSE;
}
struct mrb_insn_data
mrb_decode_insn(mrb_code *pc)
mrb_decode_insn(const mrb_code *pc)
{
struct mrb_insn_data data = { 0 };
mrb_code insn = READ_B();
@@ -407,9 +398,6 @@ gen_move(codegen_scope *s, uint16_t dst, uint16_t src, int nopeep)
if (no_peephole(s)) {
normal:
genop_2(s, OP_MOVE, dst, src);
if (on_eval(s)) {
genop_0(s, OP_NOP);
}
return;
}
else {
@@ -559,7 +547,7 @@ new_lit(codegen_scope *s, mrb_value val)
mrb_int len;
pv = &s->irep->pool[i];
if (mrb_type(*pv) != MRB_TT_STRING) continue;
if (!mrb_string_p(*pv)) continue;
if ((len = RSTRING_LEN(*pv)) != RSTRING_LEN(val)) continue;
if (memcmp(RSTRING_PTR(*pv), RSTRING_PTR(val), len) == 0)
return i;
@@ -570,7 +558,7 @@ new_lit(codegen_scope *s, mrb_value val)
for (i=0; i<s->irep->plen; i++) {
mrb_float f1, f2;
pv = &s->irep->pool[i];
if (mrb_type(*pv) != MRB_TT_FLOAT) continue;
if (!mrb_float_p(*pv)) continue;
f1 = mrb_float(*pv);
f2 = mrb_float(val);
if (f1 == f2 && !signbit(f1) == !signbit(f2)) return i;
@@ -599,7 +587,7 @@ new_lit(codegen_scope *s, mrb_value val)
switch (mrb_type(val)) {
case MRB_TT_STRING:
*pv = mrb_str_pool(s->mrb, val);
*pv = mrb_str_pool(s->mrb, RSTRING_PTR(val), RSTRING_LEN(val), RSTR_NOFREE_P(RSTRING(val)));
break;
#ifndef MRB_WITHOUT_FLOAT
@@ -674,6 +662,43 @@ lv_idx(codegen_scope *s, mrb_sym id)
return 0;
}
static int
search_upvar(codegen_scope *s, mrb_sym id, int *idx)
{
struct RProc *u;
int lv = 0;
codegen_scope *up = s->prev;
while (up) {
*idx = lv_idx(up, id);
if (*idx > 0) {
return lv;
}
lv ++;
up = up->prev;
}
if (lv < 1) lv = 1;
u = s->parser->upper;
while (u && !MRB_PROC_CFUNC_P(u)) {
struct mrb_irep *ir = u->body.irep;
uint_fast16_t n = ir->nlocals;
const struct mrb_locals *v = ir->lv;
for (; n > 1; n --, v ++) {
if (v->name == id) {
*idx = v->r;
return lv - 1;
}
}
if (MRB_PROC_SCOPE_P(u)) break;
u = u->upper;
lv ++;
}
codegen_error(s, "Can't found local variables");
return -1; /* not reached */
}
static void
for_body(codegen_scope *s, node *tree)
{
@@ -686,9 +711,6 @@ for_body(codegen_scope *s, node *tree)
codegen(s, tree->cdr->car, VAL);
/* generate loop-block */
s = scope_new(s->mrb, s, NULL);
if (s == NULL) {
raise_error(prev, "unexpected scope");
}
push(); /* push for a block parameter */
@@ -724,9 +746,6 @@ lambda_body(codegen_scope *s, node *tree, int blk)
{
codegen_scope *parent = s;
s = scope_new(s->mrb, s, tree->car);
if (s == NULL) {
raise_error(parent, "unexpected scope");
}
s->mscope = !blk;
@@ -777,7 +796,7 @@ lambda_body(codegen_scope *s, node *tree, int blk)
s->ainfo = (((ma+oa) & 0x3f) << 7) /* (12bits = 5:1:5:1) */
| ((ra & 0x1) << 6)
| ((pa & 0x1f) << 1)
| (kd & 0x1);
| ((ka | kd) != 0 ? 0x01 : 0x00);
genop_W(s, OP_ENTER, a);
/* generate jump table for optional arguments initializer */
pos = new_label(s);
@@ -792,12 +811,19 @@ lambda_body(codegen_scope *s, node *tree, int blk)
i = 0;
while (opt) {
int idx;
mrb_sym id = nsym(opt->car->car);
dispatch(s, pos+i*3+1);
codegen(s, opt->car->cdr, VAL);
pop();
idx = lv_idx(s, nsym(opt->car->car));
gen_move(s, idx, cursp(), 0);
idx = lv_idx(s, id);
if (idx > 0) {
gen_move(s, idx, cursp(), 0);
}
else {
int lv = search_upvar(s, id, &idx);
genop_3(s, OP_GETUPVAR, cursp(), idx, lv);
}
i++;
opt = opt->cdr;
}
@@ -824,11 +850,19 @@ lambda_body(codegen_scope *s, node *tree, int blk)
mrb_assert(nint(kwd->car) == NODE_KW_ARG);
if (def_arg) {
int idx;
genop_2(s, OP_KEY_P, lv_idx(s, kwd_sym), new_sym(s, kwd_sym));
jmpif_key_p = genjmp2(s, OP_JMPIF, lv_idx(s, kwd_sym), 0, 0);
codegen(s, def_arg, VAL);
pop();
gen_move(s, lv_idx(s, kwd_sym), cursp(), 0);
idx = lv_idx(s, kwd_sym);
if (idx > 0) {
gen_move(s, idx, cursp(), 0);
}
else {
int lv = search_upvar(s, kwd_sym, &idx);
genop_3(s, OP_GETUPVAR, cursp(), idx, lv);
}
jmp_def_set = genjmp(s, OP_JMP, 0);
dispatch(s, jmpif_key_p);
}
@@ -888,9 +922,6 @@ static int
scope_body(codegen_scope *s, node *tree, int val)
{
codegen_scope *scope = scope_new(s->mrb, s, tree->car);
if (scope == NULL) {
codegen_error(s, "unexpected scope");
}
codegen(scope, tree->cdr, VAL);
gen_return(scope, OP_RETURN, scope->sp-1);
@@ -922,7 +953,7 @@ attrsym(codegen_scope *s, mrb_sym a)
mrb_int len;
char *name2;
name = mrb_sym2name_len(s->mrb, a, &len);
name = mrb_sym_name_len(s->mrb, a, &len);
name2 = (char *)codegen_palloc(s,
(size_t)len
+ 1 /* '=' */
@@ -956,7 +987,12 @@ gen_values(codegen_scope *s, node *t, int val, int extra)
}
else {
pop_n(n);
genop_2(s, OP_ARRAY, cursp(), n);
if (n == 0 && is_splat) {
genop_1(s, OP_LOADNIL, cursp());
}
else {
genop_2(s, OP_ARRAY, cursp(), n);
}
push();
codegen(s, t->car, VAL);
pop(); pop();
@@ -1041,7 +1077,7 @@ gen_call(codegen_scope *s, node *tree, mrb_sym name, int sp, int val, int safe)
pop_n(n+1);
{
mrb_int symlen;
const char *symname = mrb_sym2name_len(s->mrb, sym, &symlen);
const char *symname = mrb_sym_name_len(s->mrb, sym, &symlen);
if (!noop && symlen == 1 && symname[0] == '+' && n == 1) {
gen_addsub(s, OP_ADD, cursp());
@@ -1107,25 +1143,18 @@ gen_assignment(codegen_scope *s, node *tree, int sp, int val)
if (idx > 0) {
if (idx != sp) {
gen_move(s, idx, sp, val);
if (val && on_eval(s)) genop_0(s, OP_NOP);
}
break;
}
else { /* upvar */
int lv = 0;
codegen_scope *up = s->prev;
while (up) {
idx = lv_idx(up, nsym(tree));
if (idx > 0) {
genop_3(s, OP_SETUPVAR, sp, idx, lv);
break;
}
lv++;
up = up->prev;
}
int lv = search_upvar(s, nsym(tree), &idx);
genop_3(s, OP_SETUPVAR, sp, idx, lv);
}
break;
case NODE_NVAR:
idx = nint(tree);
codegen_error(s, "Can't assign to numbered parameter");
break;
case NODE_IVAR:
idx = new_sym(s, nsym(tree));
genop_2(s, OP_SETIV, sp, idx);
@@ -1401,7 +1430,7 @@ codegen(codegen_scope *s, node *tree, int val)
}
if (s->irep && s->filename_index != tree->filename_index) {
mrb_sym fname = mrb_parser_get_filename(s->parser, s->filename_index);
const char *filename = mrb_sym2name_len(s->mrb, fname, NULL);
const char *filename = mrb_sym_name_len(s->mrb, fname, NULL);
mrb_debug_info_append_file(s->mrb, s->irep->debug_info,
filename, s->lines, s->debug_start_pos, s->pc);
@@ -1553,7 +1582,7 @@ codegen(codegen_scope *s, node *tree, int val)
case NODE_IF:
{
int pos1, pos2;
int pos1, pos2, nil_p = FALSE;
node *elsepart = tree->cdr->cdr->car;
if (!tree->car) {
@@ -1570,32 +1599,59 @@ codegen(codegen_scope *s, node *tree, int val)
case NODE_NIL:
codegen(s, elsepart, val);
goto exit;
case NODE_CALL:
{
node *n = tree->car->cdr;
mrb_sym mid = nsym(n->cdr->car);
mrb_sym mnil = mrb_intern_lit(s->mrb, "nil?");
if (mid == mnil && n->cdr->cdr->car == NULL) {
nil_p = TRUE;
codegen(s, n->car, VAL);
}
}
break;
}
if (!nil_p) {
codegen(s, tree->car, VAL);
}
codegen(s, tree->car, VAL);
pop();
pos1 = genjmp2(s, OP_JMPNOT, cursp(), 0, val);
codegen(s, tree->cdr->car, val);
if (elsepart) {
if (val || tree->cdr->car) {
if (nil_p) {
pos2 = genjmp2(s, OP_JMPNIL, cursp(), 0, val);
pos1 = genjmp(s, OP_JMP, 0);
dispatch(s, pos2);
}
else {
pos1 = genjmp2(s, OP_JMPNOT, cursp(), 0, val);
}
codegen(s, tree->cdr->car, val);
if (val) pop();
pos2 = genjmp(s, OP_JMP, 0);
dispatch(s, pos1);
codegen(s, elsepart, val);
dispatch(s, pos2);
}
else {
if (val) {
pop();
if (elsepart || val) {
pos2 = genjmp(s, OP_JMP, 0);
dispatch(s, pos1);
genop_1(s, OP_LOADNIL, cursp());
codegen(s, elsepart, val);
dispatch(s, pos2);
push();
}
else {
dispatch(s, pos1);
}
}
else { /* empty then-part */
if (elsepart) {
if (nil_p) {
pos1 = genjmp2(s, OP_JMPNIL, cursp(), 0, val);
}
else {
pos1 = genjmp2(s, OP_JMPIF, cursp(), 0, val);
}
codegen(s, elsepart, val);
dispatch(s, pos1);
}
else if (val && !nil_p) {
genop_1(s, OP_LOADNIL, cursp());
push();
}
}
}
break;
@@ -1833,7 +1889,7 @@ codegen(codegen_scope *s, node *tree, int val)
len++;
}
tree = tree->cdr;
if (val && len == 255) {
if (val && cursp() > 127) {
pop_n(len*2);
if (!update) {
genop_2(s, OP_HASH, cursp(), len);
@@ -1955,7 +2011,7 @@ codegen(codegen_scope *s, node *tree, int val)
{
mrb_sym sym = nsym(tree->cdr->car);
mrb_int len;
const char *name = mrb_sym2name_len(s->mrb, sym, &len);
const char *name = mrb_sym_name_len(s->mrb, sym, &len);
int idx, callargs = -1, vsp = -1;
if ((len == 2 && name[0] == '|' && name[1] == '|') &&
@@ -2297,26 +2353,25 @@ codegen(codegen_scope *s, node *tree, int val)
if (idx > 0) {
gen_move(s, cursp(), idx, val);
if (val && on_eval(s)) genop_0(s, OP_NOP);
}
else {
int lv = 0;
codegen_scope *up = s->prev;
while (up) {
idx = lv_idx(up, nsym(tree));
if (idx > 0) {
genop_3(s, OP_GETUPVAR, cursp(), idx, lv);
break;
}
lv++;
up = up->prev;
}
int lv = search_upvar(s, nsym(tree), &idx);
genop_3(s, OP_GETUPVAR, cursp(), idx, lv);
}
push();
}
break;
case NODE_NVAR:
if (val) {
int idx = nint(tree);
gen_move(s, cursp(), idx, val);
push();
}
break;
case NODE_GVAR:
{
int sym = new_sym(s, nsym(tree));
@@ -2353,10 +2408,6 @@ codegen(codegen_scope *s, node *tree, int val)
}
break;
case NODE_DEFINED:
codegen(s, tree, val);
break;
case NODE_BACK_REF:
if (val) {
char buf[] = {'$', nchar(tree)};
@@ -2373,7 +2424,7 @@ codegen(codegen_scope *s, node *tree, int val)
mrb_value str;
int sym;
str = mrb_format(mrb, "$%S", mrb_fixnum_value(nint(tree)));
str = mrb_format(mrb, "$%d", nint(tree));
sym = new_sym(s, mrb_intern_str(mrb, str));
genop_2(s, OP_GETGV, cursp(), sym);
push();
@@ -2406,12 +2457,20 @@ codegen(codegen_scope *s, node *tree, int val)
else
#endif
{
if (i == -1) genop_1(s, OP_LOADI__1, cursp());
else if (i < 0) genop_2(s, OP_LOADINEG, cursp(), (uint16_t)-i);
if (i < 0) {
if (i == -1) genop_1(s, OP_LOADI__1, cursp());
else if (i >= -0xff) genop_2(s, OP_LOADINEG, cursp(), (uint16_t)-i);
else if (i >= -0x8000) genop_2S(s, OP_LOADI16, cursp(), (uint16_t)i);
else goto lit_int;
}
else if (i < 8) genop_1(s, OP_LOADI_0 + (uint8_t)i, cursp());
else if (i <= 0xffff) genop_2(s, OP_LOADI, cursp(), (uint16_t)i);
else if (i <= 0xff) genop_2(s, OP_LOADI, cursp(), (uint16_t)i);
else if (i <= 0x7fff) genop_2S(s, OP_LOADI16, cursp(), (uint16_t)i);
else {
int off = new_lit(s, mrb_fixnum_value(i));
int off;
lit_int:
off = new_lit(s, mrb_fixnum_value(i));
genop_2(s, OP_LOADL, cursp(), off);
}
}
@@ -2467,9 +2526,12 @@ codegen(codegen_scope *s, node *tree, int val)
else {
#endif
if (i == -1) genop_1(s, OP_LOADI__1, cursp());
else if (i >= -0xffff) {
else if (i >= -0xff) {
genop_2(s, OP_LOADINEG, cursp(), (uint16_t)-i);
}
else if (i >= -0x8000) {
genop_2S(s, OP_LOADI16, cursp(), (uint16_t)i);
}
else {
int off = new_lit(s, mrb_fixnum_value(i));
genop_2(s, OP_LOADL, cursp(), off);
@@ -2944,7 +3006,11 @@ scope_new(mrb_state *mrb, codegen_scope *prev, node *lv)
mrb_pool *pool = mrb_pool_open(mrb);
codegen_scope *p = (codegen_scope *)mrb_pool_alloc(pool, sizeof(codegen_scope));
if (!p) return NULL;
if (!p) {
if (prev)
codegen_error(prev, "unexpected scope");
return NULL;
}
*p = codegen_scope_zero;
p->mrb = mrb;
p->mpool = pool;
@@ -3020,6 +3086,9 @@ scope_finish(codegen_scope *s)
mrb_state *mrb = s->mrb;
mrb_irep *irep = s->irep;
if (s->nlocals >= 0x3ff) {
codegen_error(s, "too many local variables");
}
irep->flags = 0;
if (s->iseq) {
irep->iseq = (mrb_code *)codegen_realloc(s, s->iseq, sizeof(mrb_code)*s->pc);
@@ -3030,7 +3099,7 @@ scope_finish(codegen_scope *s)
irep->reps = (mrb_irep**)codegen_realloc(s, irep->reps, sizeof(mrb_irep*)*irep->rlen);
if (s->filename_sym) {
mrb_sym fname = mrb_parser_get_filename(s->parser, s->filename_index);
const char *filename = mrb_sym2name_len(s->mrb, fname, NULL);
const char *filename = mrb_sym_name_len(s->mrb, fname, NULL);
mrb_debug_info_append_file(s->mrb, s->irep->debug_info,
filename, s->lines, s->debug_start_pos, s->pc);
@@ -3134,9 +3203,6 @@ generate_code(mrb_state *mrb, parser_state *p, int val)
struct RProc *proc;
struct mrb_jmpbuf *prev_jmp = mrb->jmp;
if (!scope) {
return NULL;
}
scope->mrb = mrb;
scope->parser = p;
scope->filename_sym = p->filename_sym;
-3
View File
@@ -1,8 +1,5 @@
%{
struct kwtable {const char *name; int id[2]; enum mrb_lex_state_enum state;};
const struct kwtable *mrb_reserved_word(const char *, unsigned int);
static const struct kwtable *reserved_word(const char *, unsigned int);
#define mrb_reserved_word(str, len) reserved_word(str, len)
%}
struct kwtable;
+86 -94
View File
@@ -1,4 +1,4 @@
/* ANSI-C code produced by gperf version 3.0.4 */
/* ANSI-C code produced by gperf version 3.1 */
/* Command-line: gperf -L ANSI-C -C -p -j1 -i 1 -g -o -t -N mrb_reserved_word -k'1,3,$' /home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords */
#if !((' ' == 32) && ('!' == 33) && ('"' == 34) && ('#' == 35) \
@@ -25,16 +25,13 @@
&& ('w' == 119) && ('x' == 120) && ('y' == 121) && ('z' == 122) \
&& ('{' == 123) && ('|' == 124) && ('}' == 125) && ('~' == 126))
/* The character set is not based on ISO-646. */
#error "gperf generated tables don't work with this execution character set. Please report a bug to <bug-gnu-gperf@gnu.org>."
#error "gperf generated tables don't work with this execution character set. Please report a bug to <bug-gperf@gnu.org>."
#endif
#line 1 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
struct kwtable {const char *name; int id[2]; enum mrb_lex_state_enum state;};
const struct kwtable *mrb_reserved_word(const char *, unsigned int);
static const struct kwtable *reserved_word(const char *, unsigned int);
#define mrb_reserved_word(str, len) reserved_word(str, len)
#line 8 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
#line 5 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
struct kwtable;
#define TOTAL_KEYWORDS 40
@@ -52,7 +49,7 @@ inline
#endif
#endif
static unsigned int
hash (const char *str, unsigned int len)
hash (register const char *str, register size_t len)
{
static const unsigned char asso_values[] =
{
@@ -83,7 +80,7 @@ hash (const char *str, unsigned int len)
51, 51, 51, 51, 51, 51, 51, 51, 51, 51,
51, 51, 51, 51, 51, 51
};
int hval = len;
register unsigned int hval = len;
switch (hval)
{
@@ -98,109 +95,103 @@ hash (const char *str, unsigned int len)
return hval + asso_values[(unsigned char)str[len - 1]];
}
#ifdef __GNUC__
__inline
#if defined __GNUC_STDC_INLINE__ || defined __GNUC_GNU_INLINE__
__attribute__ ((__gnu_inline__))
#endif
#endif
const struct kwtable *
mrb_reserved_word (const char *str, unsigned int len)
mrb_reserved_word (register const char *str, register size_t len)
{
static const struct kwtable wordlist[] =
{
{""}, {""}, {""}, {""}, {""}, {""}, {""}, {""},
#line 18 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
{"break", {keyword_break, keyword_break}, EXPR_MID},
#line 23 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
{"else", {keyword_else, keyword_else}, EXPR_BEG},
#line 33 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
{"nil", {keyword_nil, keyword_nil}, EXPR_END},
#line 26 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
{"ensure", {keyword_ensure, keyword_ensure}, EXPR_BEG},
#line 25 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
{"end", {keyword_end, keyword_end}, EXPR_END},
#line 42 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
{"then", {keyword_then, keyword_then}, EXPR_BEG},
#line 34 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
{"not", {keyword_not, keyword_not}, EXPR_ARG},
#line 27 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
{"false", {keyword_false, keyword_false}, EXPR_END},
#line 40 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
{"self", {keyword_self, keyword_self}, EXPR_END},
#line 24 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
{"elsif", {keyword_elsif, keyword_elsif}, EXPR_VALUE},
#line 37 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
{"rescue", {keyword_rescue, modifier_rescue}, EXPR_MID},
#line 43 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
{"true", {keyword_true, keyword_true}, EXPR_END},
#line 46 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
{"until", {keyword_until, modifier_until}, EXPR_VALUE},
#line 45 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
{"unless", {keyword_unless, modifier_unless}, EXPR_VALUE},
#line 39 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
{"return", {keyword_return, keyword_return}, EXPR_MID},
#line 21 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
{"def", {keyword_def, keyword_def}, EXPR_FNAME},
#line 16 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
{"and", {keyword_and, keyword_and}, EXPR_VALUE},
#line 22 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
{"do", {keyword_do, keyword_do}, EXPR_BEG},
#line 49 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
{"yield", {keyword_yield, keyword_yield}, EXPR_ARG},
#line 28 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
{"for", {keyword_for, keyword_for}, EXPR_VALUE},
#line 44 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
{"undef", {keyword_undef, keyword_undef}, EXPR_FNAME},
#line 35 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
{"or", {keyword_or, keyword_or}, EXPR_VALUE},
#line 30 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
{"in", {keyword_in, keyword_in}, EXPR_VALUE},
#line 47 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
{"when", {keyword_when, keyword_when}, EXPR_VALUE},
#line 38 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
{"retry", {keyword_retry, keyword_retry}, EXPR_END},
#line 29 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
{"if", {keyword_if, modifier_if}, EXPR_VALUE},
#line 19 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
{"case", {keyword_case, keyword_case}, EXPR_VALUE},
#line 36 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
{"redo", {keyword_redo, keyword_redo}, EXPR_END},
#line 32 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
{"next", {keyword_next, keyword_next}, EXPR_MID},
#line 41 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
{"super", {keyword_super, keyword_super}, EXPR_ARG},
#line 31 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
{"module", {keyword_module, keyword_module}, EXPR_VALUE},
#line 17 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
{"begin", {keyword_begin, keyword_begin}, EXPR_BEG},
#line 12 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
{"__LINE__", {keyword__LINE__, keyword__LINE__}, EXPR_END},
#line 11 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
{"__FILE__", {keyword__FILE__, keyword__FILE__}, EXPR_END},
#line 10 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
{"__ENCODING__", {keyword__ENCODING__, keyword__ENCODING__}, EXPR_END},
#line 14 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
{"END", {keyword_END, keyword_END}, EXPR_END},
#line 15 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
{"alias", {keyword_alias, keyword_alias}, EXPR_FNAME},
{"break", {keyword_break, keyword_break}, EXPR_MID},
#line 20 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
{"else", {keyword_else, keyword_else}, EXPR_BEG},
#line 30 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
{"nil", {keyword_nil, keyword_nil}, EXPR_END},
#line 23 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
{"ensure", {keyword_ensure, keyword_ensure}, EXPR_BEG},
#line 22 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
{"end", {keyword_end, keyword_end}, EXPR_END},
#line 39 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
{"then", {keyword_then, keyword_then}, EXPR_BEG},
#line 31 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
{"not", {keyword_not, keyword_not}, EXPR_ARG},
#line 24 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
{"false", {keyword_false, keyword_false}, EXPR_END},
#line 37 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
{"self", {keyword_self, keyword_self}, EXPR_END},
#line 21 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
{"elsif", {keyword_elsif, keyword_elsif}, EXPR_VALUE},
#line 34 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
{"rescue", {keyword_rescue, modifier_rescue}, EXPR_MID},
#line 40 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
{"true", {keyword_true, keyword_true}, EXPR_END},
#line 43 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
{"until", {keyword_until, modifier_until}, EXPR_VALUE},
#line 42 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
{"unless", {keyword_unless, modifier_unless}, EXPR_VALUE},
#line 36 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
{"return", {keyword_return, keyword_return}, EXPR_MID},
#line 18 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
{"def", {keyword_def, keyword_def}, EXPR_FNAME},
#line 13 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
{"and", {keyword_and, keyword_and}, EXPR_VALUE},
#line 19 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
{"do", {keyword_do, keyword_do}, EXPR_BEG},
#line 46 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
{"yield", {keyword_yield, keyword_yield}, EXPR_ARG},
#line 25 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
{"for", {keyword_for, keyword_for}, EXPR_VALUE},
#line 41 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
{"undef", {keyword_undef, keyword_undef}, EXPR_FNAME},
#line 32 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
{"or", {keyword_or, keyword_or}, EXPR_VALUE},
#line 27 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
{"in", {keyword_in, keyword_in}, EXPR_VALUE},
#line 44 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
{"when", {keyword_when, keyword_when}, EXPR_VALUE},
#line 35 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
{"retry", {keyword_retry, keyword_retry}, EXPR_END},
#line 26 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
{"if", {keyword_if, modifier_if}, EXPR_VALUE},
#line 16 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
{"case", {keyword_case, keyword_case}, EXPR_VALUE},
#line 33 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
{"redo", {keyword_redo, keyword_redo}, EXPR_END},
#line 29 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
{"next", {keyword_next, keyword_next}, EXPR_MID},
#line 38 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
{"super", {keyword_super, keyword_super}, EXPR_ARG},
#line 28 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
{"module", {keyword_module, keyword_module}, EXPR_VALUE},
#line 14 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
{"begin", {keyword_begin, keyword_begin}, EXPR_BEG},
#line 9 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
{"__LINE__", {keyword__LINE__, keyword__LINE__}, EXPR_END},
#line 8 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
{"__FILE__", {keyword__FILE__, keyword__FILE__}, EXPR_END},
#line 7 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
{"__ENCODING__", {keyword__ENCODING__, keyword__ENCODING__}, EXPR_END},
#line 11 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
{"END", {keyword_END, keyword_END}, EXPR_END},
#line 12 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
{"alias", {keyword_alias, keyword_alias}, EXPR_FNAME},
#line 10 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
{"BEGIN", {keyword_BEGIN, keyword_BEGIN}, EXPR_END},
{""},
#line 20 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
#line 17 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
{"class", {keyword_class, keyword_class}, EXPR_CLASS},
{""}, {""},
#line 48 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
#line 45 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
{"while", {keyword_while, modifier_while}, EXPR_VALUE}
};
if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH)
{
int key = hash (str, len);
register unsigned int key = hash (str, len);
if (key <= MAX_HASH_VALUE && key >= 0)
if (key <= MAX_HASH_VALUE)
{
const char *s = wordlist[key].name;
register const char *s = wordlist[key].name;
if (*str == *s && !strcmp (str + 1, s + 1))
return &wordlist[key];
@@ -208,4 +199,5 @@ mrb_reserved_word (const char *str, unsigned int len)
}
return 0;
}
#line 50 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
#line 47 "/home/matz/work/mruby/mrbgems/mruby-compiler/core/keywords"
+1
View File
@@ -51,6 +51,7 @@ enum node_type {
NODE_IVAR,
NODE_CONST,
NODE_CVAR,
NODE_NVAR,
NODE_NTH_REF,
NODE_BACK_REF,
NODE_MATCH,
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+13 -15
View File
@@ -3,35 +3,33 @@ MRuby::Gem::Specification.new 'mruby-compiler' do |spec|
spec.author = 'mruby developers'
spec.summary = 'mruby compiler library'
current_dir = spec.dir
current_build_dir = spec.build_dir
lex_def = "#{current_dir}/core/lex.def"
core_objs = Dir.glob("#{current_dir}/core/*.c").map { |f|
lex_def = "#{dir}/core/lex.def"
core_objs = Dir.glob("#{dir}/core/*.c").map { |f|
next nil if build.cxx_exception_enabled? and f =~ /(codegen).c$/
objfile(f.pathmap("#{current_build_dir}/core/%n"))
objfile(f.pathmap("#{build_dir}/core/%n"))
}.compact
if build.cxx_exception_enabled?
core_objs <<
build.compile_as_cxx("#{current_build_dir}/core/y.tab.c", "#{current_build_dir}/core/y.tab.cxx",
objfile("#{current_build_dir}/y.tab"), ["#{current_dir}/core"]) <<
build.compile_as_cxx("#{current_dir}/core/codegen.c", "#{current_build_dir}/core/codegen.cxx")
build.compile_as_cxx("#{dir}/core/y.tab.c", "#{build_dir}/core/y.tab.cxx",
objfile("#{build_dir}/y.tab"), ["#{dir}/core"]) <<
build.compile_as_cxx("#{dir}/core/codegen.c", "#{build_dir}/core/codegen.cxx")
else
core_objs << objfile("#{current_build_dir}/core/y.tab")
file objfile("#{current_build_dir}/core/y.tab") => "#{current_build_dir}/core/y.tab.c" do |t|
cc.run t.name, t.prerequisites.first, [], ["#{current_dir}/core"]
core_objs << objfile("#{build_dir}/core/y.tab")
file objfile("#{build_dir}/core/y.tab") => "#{dir}/core/y.tab.c" do |t|
cc.run t.name, t.prerequisites.first, [], ["#{dir}/core"]
end
end
# Parser
file "#{current_build_dir}/core/y.tab.c" => ["#{current_dir}/core/parse.y", lex_def] do |t|
FileUtils.mkdir_p File.dirname t.name
file "#{dir}/core/y.tab.c" => ["#{dir}/core/parse.y", lex_def] do |t|
yacc.run t.name, t.prerequisites.first
content = File.read(t.name).gsub(/^#line +\d+ +"\K.*$/){$&.relative_path}
File.write(t.name, content)
end
# Lexical analyzer
file lex_def => "#{current_dir}/core/keywords" do |t|
file lex_def => "#{dir}/core/keywords" do |t|
gperf.run t.name, t.prerequisites.first
end
+7
View File
@@ -0,0 +1,7 @@
MRuby::Gem::Specification.new('mruby-complex') do |spec|
spec.license = 'MIT'
spec.author = 'mruby developers'
spec.summary = 'Complex class'
spec.add_dependency 'mruby-math', core: 'mruby-math'
end
+122
View File
@@ -0,0 +1,122 @@
class Complex < Numeric
def self.polar(abs, arg = 0)
Complex(abs * Math.cos(arg), abs * Math.sin(arg))
end
def inspect
"(#{to_s})"
end
def to_s
"#{real}#{'+' unless imaginary < 0}#{imaginary}i"
end
def +@
Complex(real, imaginary)
end
def -@
Complex(-real, -imaginary)
end
def +(rhs)
if rhs.is_a? Complex
Complex(real + rhs.real, imaginary + rhs.imaginary)
elsif rhs.is_a? Numeric
Complex(real + rhs, imaginary)
end
end
def -(rhs)
if rhs.is_a? Complex
Complex(real - rhs.real, imaginary - rhs.imaginary)
elsif rhs.is_a? Numeric
Complex(real - rhs, imaginary)
end
end
def *(rhs)
if rhs.is_a? Complex
Complex(real * rhs.real - imaginary * rhs.imaginary, real * rhs.imaginary + rhs.real * imaginary)
elsif rhs.is_a? Numeric
Complex(real * rhs, imaginary * rhs)
end
end
def /(rhs)
if rhs.is_a? Complex
__div__(rhs)
elsif rhs.is_a? Numeric
Complex(real / rhs, imaginary / rhs)
end
end
alias_method :quo, :/
def ==(rhs)
if rhs.is_a? Complex
real == rhs.real && imaginary == rhs.imaginary
elsif rhs.is_a? Numeric
imaginary == 0 && real == rhs
end
end
def abs
Math.hypot imaginary, real
end
alias_method :magnitude, :abs
def abs2
real * real + imaginary * imaginary
end
def arg
Math.atan2 imaginary, real
end
alias_method :angle, :arg
alias_method :phase, :arg
def conjugate
Complex(real, -imaginary)
end
alias_method :conj, :conjugate
def fdiv(numeric)
Complex(real.to_f / numeric, imaginary.to_f / numeric)
end
def polar
[abs, arg]
end
def real?
false
end
def rectangular
[real, imaginary]
end
alias_method :rect, :rectangular
def to_r
raise RangeError.new "can't convert #{to_s} into Rational" unless imaginary.zero?
Rational(real, 1)
end
alias_method :imag, :imaginary
[Fixnum, Float].each do |cls|
[:+, :-, :*, :/, :==].each do |op|
cls.instance_eval do
original_operator_name = :"__original_operator_#{op}_complex"
alias_method original_operator_name, op
define_method op do |rhs|
if rhs.is_a? Complex
Complex(self).__send__(op, rhs)
else
__send__(original_operator_name, rhs)
end
end
end
end
end
end
+248
View File
@@ -0,0 +1,248 @@
#include <mruby.h>
#include <mruby/class.h>
#include <mruby/numeric.h>
#include <math.h>
#ifdef MRB_WITHOUT_FLOAT
# error Complex conflicts 'MRB_WITHOUT_FLOAT' configuration in your 'build_config.rb'
#endif
struct mrb_complex {
mrb_float real;
mrb_float imaginary;
};
#ifdef MRB_USE_FLOAT
#define F(x) x##f
#else
#define F(x) x
#endif
#if defined(MRB_64BIT) || defined(MRB_USE_FLOAT)
#define COMPLEX_USE_ISTRUCT
/* use TT_ISTRUCT */
#include <mruby/istruct.h>
#define complex_ptr(mrb, v) (struct mrb_complex*)mrb_istruct_ptr(v)
static struct RBasic*
complex_alloc(mrb_state *mrb, struct RClass *c, struct mrb_complex **p)
{
struct RIStruct *s;
s = (struct RIStruct*)mrb_obj_alloc(mrb, MRB_TT_ISTRUCT, c);
*p = (struct mrb_complex*)s->inline_data;
return (struct RBasic*)s;
}
#else
/* use TT_DATA */
#include <mruby/data.h>
static const struct mrb_data_type mrb_complex_type = {"Complex", mrb_free};
static struct RBasic*
complex_alloc(mrb_state *mrb, struct RClass *c, struct mrb_complex **p)
{
struct RData *d;
Data_Make_Struct(mrb, c, struct mrb_complex, &mrb_complex_type, *p, d);
return (struct RBasic*)d;
}
static struct mrb_complex*
complex_ptr(mrb_state *mrb, mrb_value v)
{
struct mrb_complex *p;
p = DATA_GET_PTR(mrb, v, &mrb_complex_type, struct mrb_complex);
if (!p) {
mrb_raise(mrb, E_ARGUMENT_ERROR, "uninitialized complex");
}
return p;
}
#endif
static mrb_value
complex_new(mrb_state *mrb, mrb_float real, mrb_float imaginary)
{
struct RClass *c = mrb_class_get(mrb, "Complex");
struct mrb_complex *p;
struct RBasic *comp = complex_alloc(mrb, c, &p);
p->real = real;
p->imaginary = imaginary;
MRB_SET_FROZEN_FLAG(comp);
return mrb_obj_value(comp);
}
static mrb_value
complex_real(mrb_state *mrb, mrb_value self)
{
struct mrb_complex *p = complex_ptr(mrb, self);
return mrb_float_value(mrb, p->real);
}
static mrb_value
complex_imaginary(mrb_state *mrb, mrb_value self)
{
struct mrb_complex *p = complex_ptr(mrb, self);
return mrb_float_value(mrb, p->imaginary);
}
static mrb_value
complex_s_rect(mrb_state *mrb, mrb_value self)
{
mrb_float real, imaginary = 0.0;
mrb_get_args(mrb, "f|f", &real, &imaginary);
return complex_new(mrb, real, imaginary);
}
static mrb_value
complex_to_f(mrb_state *mrb, mrb_value self)
{
struct mrb_complex *p = complex_ptr(mrb, self);
if (p->imaginary != 0) {
mrb_raisef(mrb, E_RANGE_ERROR, "can't convert %v into Float", self);
}
return mrb_float_value(mrb, p->real);
}
static mrb_value
complex_to_i(mrb_state *mrb, mrb_value self)
{
struct mrb_complex *p = complex_ptr(mrb, self);
if (p->imaginary != 0) {
mrb_raisef(mrb, E_RANGE_ERROR, "can't convert %v into Float", self);
}
return mrb_int_value(mrb, p->real);
}
static mrb_value
complex_to_c(mrb_state *mrb, mrb_value self)
{
return self;
}
/* Arithmetic on (significand, exponent) pairs avoids premature overflow in
complex division */
struct float_pair {
mrb_float s;
int x;
};
static void
add_pair(struct float_pair *s, struct float_pair const *a,
struct float_pair const *b)
{
if (b->s == 0.0F) {
*s = *a;
} else if (a->s == 0.0F) {
*s = *b;
} else if (a->x >= b->x) {
s->s = a->s + F(ldexp)(b->s, b->x - a->x);
s->x = a->x;
} else {
s->s = F(ldexp)(a->s, a->x - b->x) + b->s;
s->x = b->x;
}
}
static void
mul_pair(struct float_pair *p, struct float_pair const *a,
struct float_pair const *b)
{
p->s = a->s * b->s;
p->x = a->x + b->x;
}
static void
div_pair(struct float_pair *q, struct float_pair const *a,
struct float_pair const *b)
{
q->s = a->s / b->s;
q->x = a->x - b->x;
}
static mrb_value
complex_div(mrb_state *mrb, mrb_value self)
{
mrb_value rhs = mrb_get_arg1(mrb);
struct mrb_complex *a, *b;
struct float_pair ar, ai, br, bi;
struct float_pair br2, bi2;
struct float_pair div;
struct float_pair ar_br, ai_bi;
struct float_pair ai_br, ar_bi;
struct float_pair zr, zi;
a = complex_ptr(mrb, self);
b = complex_ptr(mrb, rhs);
/* Split floating point components into significand and exponent */
ar.s = F(frexp)(a->real, &ar.x);
ai.s = F(frexp)(a->imaginary, &ai.x);
br.s = F(frexp)(b->real, &br.x);
bi.s = F(frexp)(b->imaginary, &bi.x);
/* Perform arithmetic on (significand, exponent) pairs to produce
the result: */
/* the divisor */
mul_pair(&br2, &br, &br);
mul_pair(&bi2, &bi, &bi);
add_pair(&div, &br2, &bi2);
/* real component */
mul_pair(&ar_br, &ar, &br);
mul_pair(&ai_bi, &ai, &bi);
add_pair(&zr, &ar_br, &ai_bi);
div_pair(&zr, &zr, &div);
/* imaginary component */
mul_pair(&ai_br, &ai, &br);
mul_pair(&ar_bi, &ar, &bi);
ar_bi.s = -ar_bi.s;
add_pair(&zi, &ai_br, &ar_bi);
div_pair(&zi, &zi, &div);
/* assemble the result */
return complex_new(mrb, F(ldexp)(zr.s, zr.x), F(ldexp)(zi.s, zi.x));
}
void mrb_mruby_complex_gem_init(mrb_state *mrb)
{
struct RClass *comp;
#ifdef COMPLEX_USE_ISTRUCT
mrb_assert(sizeof(struct mrb_complex) < ISTRUCT_DATA_SIZE);
#endif
comp = mrb_define_class(mrb, "Complex", mrb_class_get(mrb, "Numeric"));
#ifdef COMPLEX_USE_ISTRUCT
MRB_SET_INSTANCE_TT(comp, MRB_TT_ISTRUCT);
#else
MRB_SET_INSTANCE_TT(comp, MRB_TT_DATA);
#endif
mrb_undef_class_method(mrb, comp, "new");
mrb_define_class_method(mrb, comp, "rectangular", complex_s_rect, MRB_ARGS_REQ(1)|MRB_ARGS_OPT(1));
mrb_define_class_method(mrb, comp, "rect", complex_s_rect, MRB_ARGS_REQ(1)|MRB_ARGS_OPT(1));
mrb_define_method(mrb, mrb->kernel_module, "Complex", complex_s_rect, MRB_ARGS_REQ(1)|MRB_ARGS_OPT(1));
mrb_define_method(mrb, comp, "real", complex_real, MRB_ARGS_NONE());
mrb_define_method(mrb, comp, "imaginary", complex_imaginary, MRB_ARGS_NONE());
mrb_define_method(mrb, comp, "to_f", complex_to_f, MRB_ARGS_NONE());
mrb_define_method(mrb, comp, "to_i", complex_to_i, MRB_ARGS_NONE());
mrb_define_method(mrb, comp, "to_c", complex_to_c, MRB_ARGS_NONE());
mrb_define_method(mrb, comp, "__div__", complex_div, MRB_ARGS_REQ(1));
}
void
mrb_mruby_complex_gem_final(mrb_state* mrb)
{
}
+153
View File
@@ -0,0 +1,153 @@
def assert_complex(real, exp)
assert "assert_complex" do
assert_float real.real, exp.real
assert_float real.imaginary, exp.imaginary
end
end
assert 'Complex' do
c = 123i
assert_equal Complex, c.class
assert_equal [c.real, c.imaginary], [0, 123]
c = 123 + -1.23i
assert_equal Complex, c.class
assert_equal [c.real, c.imaginary], [123, -1.23]
end
assert 'Complex::polar' do
assert_complex Complex.polar(3, 0), (3 + 0i)
assert_complex Complex.polar(3, Math::PI/2), (0 + 3i)
assert_complex Complex.polar(3, Math::PI), (-3 + 0i)
assert_complex Complex.polar(3, -Math::PI/2), (0 + -3i)
end
assert 'Complex::rectangular' do
assert_complex Complex.rectangular(1, 2), (1 + 2i)
end
assert 'Complex#*' do
assert_complex Complex(2, 3) * Complex(2, 3), (-5 + 12i)
assert_complex Complex(900) * Complex(1), (900 + 0i)
assert_complex Complex(-2, 9) * Complex(-9, 2), (0 - 85i)
assert_complex Complex(9, 8) * 4, (36 + 32i)
assert_complex Complex(20, 9) * 9.8, (196.0 + 88.2i)
end
assert 'Complex#+' do
assert_complex Complex(2, 3) + Complex(2, 3) , (4 + 6i)
assert_complex Complex(900) + Complex(1) , (901 + 0i)
assert_complex Complex(-2, 9) + Complex(-9, 2), (-11 + 11i)
assert_complex Complex(9, 8) + 4 , (13 + 8i)
assert_complex Complex(20, 9) + 9.8 , (29.8 + 9i)
end
assert 'Complex#-' do
assert_complex Complex(2, 3) - Complex(2, 3) , (0 + 0i)
assert_complex Complex(900) - Complex(1) , (899 + 0i)
assert_complex Complex(-2, 9) - Complex(-9, 2), (7 + 7i)
assert_complex Complex(9, 8) - 4 , (5 + 8i)
assert_complex Complex(20, 9) - 9.8 , (10.2 + 9i)
end
assert 'Complex#-@' do
assert_complex(-Complex(1, 2), (-1 - 2i))
end
assert 'Complex#/' do
assert_complex Complex(2, 3) / Complex(2, 3) , (1 + 0i)
assert_complex Complex(900) / Complex(1) , (900 + 0i)
assert_complex Complex(-2, 9) / Complex(-9, 2), ((36 / 85) - (77i / 85))
assert_complex Complex(9, 8) / 4 , ((9 / 4) + 2i)
assert_complex Complex(20, 9) / 9.8 , (2.0408163265306123 + 0.9183673469387754i)
if 1e39.infinite? then
# MRB_USE_FLOAT in effect
ten = 1e21
one = 1e20
else
ten = 1e201
one = 1e200
end
assert_complex Complex(ten, ten) / Complex(one, one), Complex(10.0, 0.0)
end
assert 'Complex#==' do
assert_true Complex(2, 3) == Complex(2, 3)
assert_true Complex(5) == 5
assert_true Complex(0) == 0.0
end
assert 'Complex#abs' do
assert_float Complex(-1).abs, 1
assert_float Complex(3.0, -4.0).abs, 5.0
if 1e39.infinite? then
# MRB_USE_FLOAT in effect
exp = 125
else
exp = 1021
end
assert_true Complex(3.0*2.0**exp, 4.0*2.0**exp).abs.finite?
assert_float Complex(3.0*2.0**exp, 4.0*2.0**exp).abs, 5.0*2.0**exp
end
assert 'Complex#abs2' do
assert_float Complex(-1).abs2, 1
assert_float Complex(3.0, -4.0).abs2, 25.0
end
assert 'Complex#arg' do
assert_float Complex.polar(3, Math::PI/2).arg, 1.5707963267948966
end
assert 'Complex#conjugate' do
assert_complex Complex(1, 2).conjugate, (1 - 2i)
end
assert 'Complex#fdiv' do
assert_complex Complex(11, 22).fdiv(3), (3.6666666666666665 + 7.333333333333333i)
end
assert 'Complex#imaginary' do
assert_float Complex(7).imaginary , 0
assert_float Complex(9, -4).imaginary, -4
end
assert 'Complex#polar' do
assert_equal Complex(1, 2).polar, [2.23606797749979, 1.1071487177940904]
end
assert 'Complex#real' do
assert_float Complex(7).real, 7
assert_float Complex(9, -4).real, 9
end
assert 'Complex#real?' do
assert_false Complex(1).real?
end
assert 'Complex::rectangular' do
assert_equal Complex(1, 2).rectangular, [1, 2]
end
assert 'Complex::to_c' do
assert_equal Complex(1, 2).to_c, Complex(1, 2)
end
assert 'Complex::to_f' do
assert_float Complex(1, 0).to_f, 1.0
assert_raise(RangeError) do
Complex(1, 2).to_f
end
end
assert 'Complex::to_i' do
assert_equal Complex(1, 0).to_i, 1
assert_raise(RangeError) do
Complex(1, 2).to_i
end
end
assert 'Complex#frozen?' do
assert_predicate(1i, :frozen?)
assert_predicate(Complex(2,3), :frozen?)
assert_predicate(4+5i, :frozen?)
end
+20 -18
View File
@@ -6,28 +6,30 @@ module Enumerable
def chain(*args)
Enumerator::Chain.new(self, *args)
end
def +(other)
Enumerator::Chain.new(self, other)
end
end
class Enumerator
def +(other)
Chain.new(self, other)
end
class Chain
include Enumerable
def initialize(*args)
@enums = args
end
def initialize_copy(orig)
@enums = orig.__copy_enums
@enums = args.freeze
@pos = -1
end
def each(&block)
return to_enum unless block_given?
return to_enum unless block
@enums.each { |e| e.each(&block) }
i = 0
while i < @enums.size
@pos = i
@enums[i].each(&block)
i += 1
end
self
end
@@ -40,21 +42,21 @@ class Enumerator
end
def rewind
@enums.reverse_each do |e|
while 0 <= @pos && @pos < @enums.size
e = @enums[@pos]
e.rewind if e.respond_to?(:rewind)
@pos -= 1
end
self
end
def +(other)
self.class.new(self, other)
end
def inspect
"#<#{self.class}: #{@enums.inspect}>"
end
def __copy_enums
@enums.each_with_object([]) do |e, a|
a << e.clone
end
end
end
end
+41 -9
View File
@@ -12,9 +12,9 @@ assert("Enumerable#chain") do
assert_raise(NoMethodError) { c.chain }
end
assert("Enumerable#+") do
assert("Enumerator#+") do
a = [].each
b = {}.reverse_each
b = {}.each
c = Object.new # not has #each method
assert_kind_of Enumerator::Chain, a + b
@@ -24,7 +24,7 @@ assert("Enumerable#+") do
assert_raise(NoMethodError) { c + a }
end
assert("Enumerator.new") do
assert("Enumerator::Chain.new") do
a = []
b = {}
c = Object.new # not has #each method
@@ -46,13 +46,13 @@ assert("Enumerator::Chain#each") do
assert_kind_of Enumerator, aa.each
assert_equal [1, 2, 3, 1, 2, 3], aa.each.to_a
aa = a.chain(a.reverse_each)
aa = a.chain(6..9)
assert_kind_of Enumerator, aa.each
assert_equal [1, 2, 3, 3, 2, 1], aa.each.to_a
assert_equal [1, 2, 3, 6, 7, 8, 9], aa.each.to_a
aa = a.chain(a.reverse_each, a)
aa = a.chain((-3..-2).each_with_index, a)
assert_kind_of Enumerator, aa.each
assert_equal [1, 2, 3, 3, 2, 1, 1, 2, 3], aa.each.to_a
assert_equal [1, 2, 3, [-3, 0], [-2, 1], 1, 2, 3], aa.each.to_a
aa = a.chain(Object.new)
assert_kind_of Enumerator, aa.each
@@ -65,12 +65,44 @@ assert("Enumerator::Chain#size") do
aa = a.chain(a)
assert_equal 6, aa.size
aa = a.chain(a.reverse_each)
aa = a.chain(3..4)
assert_nil aa.size
aa = a.chain(a.reverse_each, a)
aa = a.chain(3..4, a)
assert_nil aa.size
aa = a.chain(Object.new)
assert_nil aa.size
end
assert("Enumerator::Chain#rewind") do
rewound = nil
e1 = [1, 2]
e2 = (4..6)
(class << e1; self end).define_method(:rewind) { rewound << self }
(class << e2; self end).define_method(:rewind) { rewound << self }
c = e1.chain(e2)
rewound = []
c.rewind
assert_equal [], rewound
rewound = []
c.each{break c}.rewind
assert_equal [e1], rewound
rewound = []
c.each{}.rewind
assert_equal [e2, e1], rewound
end
assert("Enumerator::Chain#+") do
a = [].chain
b = {}.chain
c = Object.new # not has #each method
assert_kind_of Enumerator::Chain, a + b
assert_kind_of Enumerator::Chain, a + c
assert_kind_of Enumerator::Chain, b + a
assert_kind_of Enumerator::Chain, b + c
end

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