Compare commits

...

1167 Commits

Author SHA1 Message Date
mimaki ea3874ed3c Update version to 3.0.0RC. 2021-02-03 16:45:11 +09:00
Yukihiro "Matz" Matsumoto c43dd75ea9 Avoid Heap Overflow in heredoc_remove_indent; fix #5316 2021-02-03 13:06:13 +09:00
Yukihiro "Matz" Matsumoto 810d13dacd Move MRB_TRY part of mrb_close to src/error.c; ref 6cc52b3
We don't want to increase number of files that should be compiled by C++
compiler when `enable_cxx_exception` is turned on.
2021-02-03 09:43:41 +09:00
Yukihiro "Matz" Matsumoto 6cc52b3210 Ignore errors from atexit finalizers. 2021-02-02 10:57:32 +09:00
Yukihiro "Matz" Matsumoto d759a73525 Allow more than 256 child irep; fix #5310
We have introduced following new instructions.

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

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

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

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

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

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

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

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

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

  ...SNIP...

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

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

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

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

Note: `mruby/c` should be updated to support this change.
2021-01-20 23:12:43 +09:00
Yukihiro "Matz" Matsumoto e91dfd07be Compile mruby-bin-debugger with ci/gcc-clang.rb. 2021-01-19 12:05:16 +09:00
Yukihiro "Matz" Matsumoto 0661ebb669 Merge pull request #5294 from shuujii/fix-that-Hash-may-not-contain-any-empty-buckets
Fix that Hash may not contain any empty buckets
2021-01-18 23:19:47 +09:00
KOBAYASHI Shuji dd81de49a6 Fix that Hash may not contain any empty buckets
The Hash implementation assumed that there were always empty buckets, but
sometimes there were only active or deleted buckets (no empty buckets).
Therefore, fix it so that this situation does not occur.

### Example

```ruby
# example.rb
class A
  attr_reader :v
  def initialize(v) @v = v end
  def ==(o) @v == o.v end
  def hash; @v end
  def to_s; "#{self.class}[#{@v}]" end
  alias eql? ==
  alias inspect to_s
end

keys = (0..31).map{A.new(_1)}
h = {}
(0..16).each{h[keys[_1]] = _1}
(17..31).each do
  k = keys[_1]
  h[k] = _1
  h.delete(k)
end
p h.keys
```

#### Before this patch:

```console
$ bin/mruby example.rb
[A[0], A[1], A[2], A[3], A[4], A[5], A[6], A[7], A[8], A[9], A[10], A[11], A[12], A[13], A[14], A[15], A[16], A[30], A[31]]
```

#### After this patch:

```console
$ bin/mruby example.rb
[A[0], A[1], A[2], A[3], A[4], A[5], A[6], A[7], A[8], A[9], A[10], A[11], A[12], A[13], A[14], A[15], A[16]]
```
2021-01-18 21:32:10 +09:00
Yukihiro "Matz" Matsumoto e4fc42ea11 Merge pull request #5293 from dearblue/fix-5272.2
Fix build error for mruby-bin-debugger
2021-01-18 00:23:13 +09:00
dearblue 04a4e59c83 Fix build error for mruby-bin-debugger
This is a missing change in #5272.

This issue was reported by @shuujii.
https://github.com/mruby/mruby/pull/5272#issuecomment-761819737
2021-01-18 00:00:53 +09:00
Yukihiro "Matz" Matsumoto f4a3dc4f07 Add tests for Integer#quo and Float#quo; #5268 2021-01-17 23:02:36 +09:00
Yukihiro "Matz" Matsumoto 12ff88563d Fix int_quo to do float division; fix #5268 2021-01-17 23:02:36 +09:00
Yukihiro "Matz" Matsumoto c7452ff61f Define Rational#quo; fix #5268 2021-01-17 23:02:35 +09:00
Yukihiro "Matz" Matsumoto b4817a54f0 Make mrb_to_flo() to convert objects, not integer, not float; #5268
Thinking `Ratinal` and `Complex` in mind.
2021-01-17 23:02:35 +09:00
Yukihiro "Matz" Matsumoto 126f0f0563 Merge pull request #5292 from dearblue/objspace-memsize
Fix NULL pointer dereference with mruby-os-memsize and mruby-method
2021-01-16 17:55:43 +09:00
dearblue 0fdf5d9bb9 Fix NULL pointer dereference with mruby-os-memsize and mruby-method
If it gets an insubstantial method object with `obj.method`, it will raise a `SIGSEGV` with `ObjectSpace.memsize_of(method)`.
2021-01-16 15:52:52 +09:00
Yukihiro "Matz" Matsumoto 0aa8db9a06 Merge pull request #5291 from dearblue/fix-5272
Fixed stack position of return value; ref #5272
2021-01-16 13:56:26 +09:00
dearblue 414a61a9d2 Fixed stack position of return value; ref #5272
When I `#call` the "proc" object created by the `mrb_proc_new_cfunc()` function from Ruby space, the return value did not go into the correct stack position.
This can destroy the calling variable.

This issue is now caused by #5272. sorry.
2021-01-16 11:05:15 +09:00
Yukihiro "Matz" Matsumoto 4bba769b95 Avoid syntax error regarding colons in the expression; fix #5290
Reported and inspired by @hasumikin; based on CRuby's `parse.y`.
2021-01-15 22:49:40 +09:00
Yukihiro "Matz" Matsumoto 28d5dabacd Merge pull request #5273 from dearblue/fiber
Capture the return value of `Fiber.yield` via C; ref #5261
2021-01-14 23:47:25 +09:00
Yukihiro "Matz" Matsumoto a639a39883 Rational denominator should not be zero. 2021-01-13 09:17:20 +09:00
dearblue 0229446a30 Capture the return value of Fiber.yield via C; ref #5261 2021-01-12 23:04:36 +09:00
Yukihiro "Matz" Matsumoto c7d96dbf84 Merge pull request #5289 from dearblue/sockaddr_un
Initialize all area of `struct sockaddr_un`
2021-01-12 22:22:44 +09:00
Yukihiro "Matz" Matsumoto 9d950818ce Merge branch 'dearblue-reorganize-ci' 2021-01-12 22:14:53 +09:00
dearblue 8928bc2dce Initialize all area of struct sockaddr_un
Members of `struct sockaddr_un` are requesting the definitions of `sun_family` and `sun_path`.
https://pubs.opengroup.org/onlinepubs/009696699/basedefs/sys/un.h.html

But the other members are optional and environment dependent.

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

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

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

It's still not available for target devices.
2021-01-11 17:07:05 +09:00
Yukihiro "Matz" Matsumoto 672e016b13 Merge pull request #5281 from shuujii/remove-the-definition-of-mrb_uint-in-numeric.h-that-is-no-longer-needed
Remove the definition of `mrb_uint` in `numeric.h` that is no longer needed
2021-01-11 16:35:42 +09:00
Yukihiro "Matz" Matsumoto 9577e6ca6a Merge pull request #5280 from shuujii/remove-unneeded-check-to-mrbtest-in-tasks-presym.rake
Remove unneeded check to `mrbtest` in `tasks/presym.rake`
2021-01-11 16:34:05 +09:00
KOBAYASHI Shuji 48feda0692 Remove the definition of mrb_uint in numeric.h that is no longer needed 2021-01-11 16:20:27 +09:00
KOBAYASHI Shuji 123d15c5ab Remove unneeded check to mrbtest in tasks/presym.rake
With the change in #5267, `build.products` no longer contains `mrbtest` when
`tasks/presym.rake` is loaded.
2021-01-11 16:15:12 +09:00
Yukihiro "Matz" Matsumoto 0290f06681 Merge pull request #5279 from shuujii/remove-unneeded-mruby-test-gem-in-build_config-no-float.rb
Remove unneeded `mruby-test` gem in `build_config/no-float.rb` [ci skip]
2021-01-11 12:53:17 +09:00
KOBAYASHI Shuji 2ddd66cc4b Remove unneeded mruby-test gem in build_config/no-float.rb [ci skip]
Use `enable_test` to enable the test.
2021-01-11 12:07:08 +09:00
Yukihiro "Matz" Matsumoto ffea200075 Merge pull request #5278 from dearblue/annotation
Fix annotations [ci skip]
2021-01-11 11:57:09 +09:00
dearblue a0662a16a3 Fix annotations [ci skip] 2021-01-11 11:33:39 +09:00
KOBAYASHI Shuji 90b53f4c29 Avoid including presym.inc in existing header files
Addressed an issue where existing programs linking `libmruby.a` could only
be built by adding `<build-dir>/include` to compiler's include path.
2021-01-11 09:21:07 +09:00
Yukihiro "Matz" Matsumoto 3deb3a7aac Fix CI failure on Windows environment.
`1L` on Windows means `32 bit int`.
2021-01-10 22:52:41 +09:00
Yukihiro "Matz" Matsumoto e66c6edaba Fix mixture of inline int declaration in for statement. 2021-01-10 22:52:40 +09:00
Yukihiro "Matz" Matsumoto 80a7655b10 Merge pull request #5271 from shuujii/fix-build-error-in-cross-build-with-presym
Fix build error in cross-build with presym
2021-01-10 22:15:52 +09:00
Yukihiro "Matz" Matsumoto dc5ade3729 Merge pull request #5275 from dearblue/read_irep
Replace `tempirep` with `RProc`
2021-01-10 22:13:51 +09:00
Yukihiro "Matz" Matsumoto 596b542720 Merge pull request #5274 from shuujii/fix-the-condition-to-remove-mrbtest-when-rake-clean
Fix the condition to remove `mrbtest` when `rake clean`
2021-01-10 22:07:22 +09:00
dearblue 3fc848b545 Replace tempirep with RProc
Previously I used the `RData` object to avoid a memory leak in `mrb_irep` if `src/load.c` failed.
ref: https://github.com/mruby/mruby/pull/4250
commit: f1523d2404

Considering that the `RProc` object will be created in the subsequent process, it is preferable to create the `RProc` object from the beginning.
Along with this, the inside of `read_irep()` is replaced with the processing centered on the `RProc` object.

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

This is because the `mrb_callinfo::pc` has been reorganized, resulting in over-correction.
2021-01-10 13:33:17 +09:00
dearblue ced89c25ff Unified pc and err of mrb_callinfo
This enhances self-containment.

- Changed the `mrb_callinfo::pc` field to point to itself.
  Previously it indicated the return destination of the previous call level.
  `mrb_callinfo::pc` will now hold the address to its own `proc->body.irep->iseq`.
- Removed `mrb_callinfo::err` field.
  This is because `mrb_callinfo::pc - 1` is semantically the same as the previous `err`.
- The `pc0` and `pc_save` variables in `mrb_vm_exec()` are no longer needed and have been deleted.
- It removes the argument because `cipush()` doesn't need to save the previous `pc`.
2021-01-10 13:23:43 +09:00
dearblue 16baea0677 Changes stackent to stack of mrb_callinfo
This enhances self-containment.

Previously `mrb_context::stack` had the current call level stack, but now it owns it.
The `mrb_context::stack` field, which is no longer needed, will be removed.
2021-01-10 13:23:35 +09:00
dearblue 58e9442737 Unified target_class and env of mrb_callinfo
If there is `env`, `env->c` means `target_class`.
2021-01-10 13:23:28 +09:00
dearblue b210cfa34e Use uint16_t for argc and acc of mrb_callinfo
This is because it is enough to express the range up to (-1..255) or (-3..255).
2021-01-10 13:22:28 +09:00
KOBAYASHI Shuji f80d5ece27 Fix build error in cross-build with presym
Fix the following issues.

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

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

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

- mrb_intern_cstr
- mrb_define_singleton_method
- mrb_define_class_under
- mrb_define_module_under
2021-01-07 16:38:46 +09:00
Yukihiro "Matz" Matsumoto ec6f46c05d Use nint() for implicit cast; ref #5260 2021-01-07 11:49:50 +09:00
Yukihiro "Matz" Matsumoto 7e116b5e8b Merge pull request #5260 from SeekingMeaning/squiggly-fix-5
Fix line continuations with mixed indentation in squiggly heredocs
2021-01-07 11:45:24 +09:00
Yukihiro "Matz" Matsumoto 5e752caf67 Merge pull request #5259 from shuujii/consider-the-case-a-local-variable-name-does-not-become-a-named-presym
Consider the case a local variable name does not become a named presym
2021-01-07 10:22:10 +09:00
Seeker d52c82d648 Add heredoc_push_indented helper function 2021-01-06 16:46:44 -08:00
Seeker e279528ff3 Fix line continuations with mixed indentation in squiggly heredocs 2021-01-06 16:35:46 -08:00
KOBAYASHI Shuji b8486d73e2 Consider the case a local variable name does not become a named presym
Non-ASCII characters are allowed to local variable names, so they are not
always named presym.
2021-01-06 23:29:45 +09:00
Yukihiro "Matz" Matsumoto 676054c8df Merge pull request #5258 from shuujii/fix-build-with-enable_cxx_exception
Fix build with `enable_cxx_exception`
2021-01-06 19:50:03 +09:00
KOBAYASHI Shuji 90283432a4 Fix build with enable_cxx_exception 2021-01-06 19:03:10 +09:00
Yukihiro "Matz" Matsumoto 01aa2a990f Specify receivers for gembox methods; ref #5241 2021-01-06 18:10:21 +09:00
Yukihiro "Matz" Matsumoto aecb3a33e6 Merge pull request #5241 from dearblue/gembox
Take advantage of gembox
2021-01-06 18:06:18 +09:00
Yukihiro "Matz" Matsumoto 0d76b90758 Use ~0U instead of ~0 to avoid sign comparison warnings. 2021-01-06 17:15:21 +09:00
Yukihiro "Matz" Matsumoto 8e048ae25d Merge branch 'shuujii-improve-source-scanning-for-presym' 2021-01-06 17:14:12 +09:00
Yukihiro "Matz" Matsumoto 74c9502bd4 Merge branch 'improve-source-scanning-for-presym' of https://github.com/shuujii/mruby into shuujii-improve-source-scanning-for-presym 2021-01-06 17:06:07 +09:00
Yukihiro "Matz" Matsumoto 1341e53961 Avoid comparing -1 with size_t (unsigned); Use ~0 instead. 2021-01-06 14:23:12 +09:00
Yukihiro "Matz" Matsumoto ca3a6156bf Allow context switch from C using mrb_fiber_resume().
But you still cannot cross C function boundary.
2021-01-06 14:16:56 +09:00
Yukihiro "Matz" Matsumoto 4585c360e4 Remove duplicated remove_sign_bits() call. 2021-01-05 21:09:46 +09:00
Yukihiro "Matz" Matsumoto bb5c451dd4 Fix mirb not to be terminated by codegen error. 2021-01-04 07:42:21 +09:00
Yukihiro "Matz" Matsumoto 7c9d9b1c89 Merge pull request #5255 from shuujii/avoid-64-bit-operations-in-src-hash.c
Avoid 64-bit operations in `src/hash.c`; close #5201
2021-01-03 20:28:00 +09:00
Yukihiro "Matz" Matsumoto 0d22e11b75 Merge pull request #5254 from SeekingMeaning/squiggly-fix-4
Fix for escaped newlines in squiggly heredocs
2021-01-03 20:25:34 +09:00
Yukihiro "Matz" Matsumoto 5798c03de6 Merge pull request #5256 from katsuyoshi/master
replace ; to : of OPT_SETGV in codedump.c
2021-01-03 20:25:02 +09:00
Katsuyoshi Ito f23918f61a replace ; to : of OPT_SETGV in codedump.c
Maybe it's a typo.
2021-01-03 19:47:30 +09:00
KOBAYASHI Shuji eb9d9e3425 Avoid 64-bit operations in src/hash.c; close #5201
The idea of using `size_t` in `ea_next_capa_for` is by @dearblue.
2021-01-03 18:42:22 +09:00
Seeker 8286e6052a Fix for escaped newlines in squiggly heredocs 2021-01-03 00:48:10 -08:00
Yukihiro "Matz" Matsumoto c52efe7be8 Avoid double inclusion on <mruby.h>. 2021-01-02 23:50:18 +09:00
Yukihiro "Matz" Matsumoto 17cb50f8d0 Avoid int64_t on 32 bit platforms. 2021-01-02 23:49:41 +09:00
Yukihiro "Matz" Matsumoto 757902c497 Check NaN and Infinity before converting Float to Rational. 2021-01-02 23:36:41 +09:00
Yukihiro "Matz" Matsumoto 392aff7099 Use Jenkins One At A Time Hash for mrb_str_hash(). 2021-01-02 20:28:29 +09:00
Yukihiro "Matz" Matsumoto d55367582c Allow negative integer value formatting in base 8 and 16. 2021-01-02 20:28:29 +09:00
Yukihiro "Matz" Matsumoto b151a697e0 Fixed wrong casting in OP_LOADI32.
Negative integer `>-65535` had wrong value, e,g, `p(-40550)` printed
`4294926746` since Nov. 2020, sigh.
2021-01-02 20:28:28 +09:00
Yukihiro "Matz" Matsumoto c1f05a7fb3 Avoid uint64_t in string-to-integer conversion; ref #5201 2021-01-02 20:28:27 +09:00
Yukihiro "Matz" Matsumoto 4ac73307fd Reduce strength of the hash function; ref #5201
Also avoid using `uint64_t`.
2021-01-02 20:28:27 +09:00
Yukihiro "Matz" Matsumoto 6323c995f3 Use type casting macros; ref #5246 #5247 2021-01-02 20:28:26 +09:00
Yukihiro "Matz" Matsumoto 15e7b3e8fe Merge pull request #5251 from SeekingMeaning/squiggly-fix-3
Fix regression for squiggly heredocs
2021-01-02 20:28:13 +09:00
Yukihiro "Matz" Matsumoto 12cb7207ec Merge pull request #5253 from shuujii/refine-wrong-number-of-arguments-message-in-mrb_get_args
Refine "wrong number of arguments" message in `mrb_get_args`
2021-01-02 19:45:09 +09:00
KOBAYASHI Shuji 1a9ac02d8d Refine "wrong number of arguments" message in mrb_get_args
#### Before this patch:

```ruby
__send__         #=> wrong number of arguments
{}.default(1,2)  #=> wrong number of arguments
```

#### After this patch:

```ruby
__send__         #=> wrong number of arguments (given 0, expected 1+)
{}.default(1,2)  #=> wrong number of arguments (given 2, expected 0..1)
```
2021-01-02 19:15:34 +09:00
Seeker 1099050377 Treat tabs as 8 spaces in squiggly heredocs 2020-12-31 19:09:38 -08:00
Seeker 4683a196d9 Fix regression for squiggly heredocs 2020-12-31 19:08:44 -08:00
Yukihiro "Matz" Matsumoto 1fbabe207d Merge pull request #5245 from jbampton/for-mruby-for-2021
Update copyright year for 2021
2021-01-01 00:24:53 +09:00
Yukihiro "Matz" Matsumoto db2a7a1e6e Merge pull request #5252 from dearblue/rm-gc_test
Removed unusable `GC.test`
2021-01-01 00:24:12 +09:00
dearblue ae72feb468 Removed unusable GC.test
The substance of the method was removed in commit 15ceb35e05.
2020-12-31 22:22:45 +09:00
Yukihiro "Matz" Matsumoto aabfe31d98 Merge pull request #5250 from shuujii/refine-error-message-from-mrb_get_arg1
Refine error message from `mrb_get_arg1`
2020-12-29 22:44:43 +09:00
KOBAYASHI Shuji 1fae7c0a69 Refine error message from mrb_get_arg1
#### Before this patch:

```console
$ bin/mruby -e '{}.key?'
trace (most recent call last):
-e:1: wrong number of arguments (ArgumentError)
```

#### After this patch:

```console
$ bin/mruby -e '{}.key?'
trace (most recent call last):
-e:1: wrong number of arguments (given 0, expected 1) (ArgumentError)
```
2020-12-29 19:04:19 +09:00
Yukihiro "Matz" Matsumoto d44a1de8f4 Merge pull request #5249 from SeekingMeaning/squiggly-fix-2
Fix mixed indentation and escaped tabs in squiggly heredocs
2020-12-29 13:51:41 +09:00
Seeker 49b01f23a4 Fix mixed indentation and escaped tabs in squiggly heredocs 2020-12-28 18:22:13 -08:00
Yukihiro "Matz" Matsumoto 9b501ab507 Merge pull request #5247 from SeekingMeaning/squiggly-fix
Fix for empty lines in squiggly heredocs
2020-12-28 17:03:52 +09:00
Seeker 3a2ff9824e Fix for empty lines in squiggly heredocs 2020-12-27 23:10:08 -08:00
Yukihiro "Matz" Matsumoto 6d98ae57f2 Merge pull request #5248 from SeekingMeaning/hash-except
Add `Hash#except` [Ruby 3.0]
2020-12-28 15:19:13 +09:00
Seeker 14a92f9705 Add Hash#except [Ruby 3.0] 2020-12-27 16:33:12 -08:00
Yukihiro "Matz" Matsumoto d57d6e2b5b Merge pull request #5246 from SeekingMeaning/squiggly-heredocs
Add support for squiggly heredocs
2020-12-27 20:05:45 +09:00
Seeker 6312a50045 Fix operand types error 2020-12-27 00:20:02 -08:00
Seeker 6491d8dd28 Commit y.tab.c 2020-12-27 00:09:39 -08:00
Seeker 54bfcaf1ff Add support for squiggly heredocs 2020-12-26 23:48:20 -08:00
John Bampton 38de04c4f7 Update copyright year for 2021 2020-12-27 01:11:47 +10:00
Yukihiro "Matz" Matsumoto dad43359cb Merge pull request #5244 from dearblue/eval-nomem
Improves out of memory messages for `eval`
2020-12-26 08:44:08 +09:00
dearblue 88a11d81b0 Improves out of memory messages for eval
The comment says that if `mrb_parse_nstring()` returns `NULL`, it is only out of memory.
I'm worried about compatibility if I set the exception class to `NoMemoryError`, so it's still `RuntimeError`.
2020-12-25 23:24:20 +09:00
Yukihiro "Matz" Matsumoto 825c14a0c5 Reset paren_nest at tAREF and tASET. 2020-12-24 23:30:42 +09:00
Yukihiro "Matz" Matsumoto 2850b58dd9 Check integer overflow in float bit operations. 2020-12-24 23:17:18 +09:00
Yukihiro "Matz" Matsumoto 3419426dbf Avoid division by zero in rational_to_f(). 2020-12-24 23:16:49 +09:00
Yukihiro "Matz" Matsumoto 4e90d6938a Merge pull request #5242 from jbampton/add-codeowners
Create CODEOWNERS file
2020-12-23 15:59:30 +09:00
Yukihiro "Matz" Matsumoto 7f73af079a Merge pull request #5243 from boatrite/add-gba-build-config
Add example for cross-compiling to Nintendo GameBoyAdvance
2020-12-23 15:55:38 +09:00
Gwen Boatrite 3bfafd198c Add example for cross-compiling to Nintendo GameBoyAdvance 2020-12-23 00:26:49 -06:00
Yukihiro "Matz" Matsumoto 0bb4afe942 Fix the integer overflow in mrb_str_len_to_inum(). 2020-12-23 10:35:15 +09:00
John Bampton e96620cd23 Create CODEOWNERS file
- You can use a CODEOWNERS file to define individuals or teams that are responsible for code in a repository.
- Code owners are automatically requested for review when someone opens a pull request that modifies code that they own. Code owners are not automatically requested to review draft pull requests.
- https://docs.github.com/en/free-pro-team@latest/github/creating-cloning-and-archiving-repositories/about-code-owners
- This creates a bit more automation so that after you merge this PR, next time someone submits a PR @matz will be automatically assigned as the PR reviewer as CODEOWNER
- CODEOWNERS can even be assigned directories or file types
2020-12-22 16:09:41 +10:00
Yukihiro "Matz" Matsumoto 8b2fd45d46 Merge pull request #5239 from jbampton/fix-links
refactor: fix Rake link and fix missing HTTPS on links
2020-12-21 23:11:40 +09:00
dearblue 6c1c2041ef Take advantage of gembox
I think that it is easy to use if it is divided according to the type of library and the general purpose.
It is a subdivision from the previous `default.gembox`.

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

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

Therefore, rename them to `gcc-clang.rb` and `msvc.rb`, respectively, and
move them under `build_config/ci/` to clarify that they are for CI.
2020-12-16 21:56:32 +09:00
Yukihiro "Matz" Matsumoto 1b7197622f Merge pull request #5226 from shuujii/guess-toolchain-when-MRubyBuild-toolchain-argument-is-omitted
Guess toolchain when `MRuby::Build#toolchain` argument is omitted
2020-12-16 20:25:35 +09:00
KOBAYASHI Shuji 0396f3f0fd Guess toolchain when MRuby::Build#toolchain argument is omitted 2020-12-16 19:17:44 +09:00
John Bampton aa6fc8c38e feat(CI): add a GitHub Action to lint the YAML
- Run only on pull request
- Add a `.yamllint` config file
- Lint YAML
2020-12-15 23:39:36 +10:00
Yukihiro "Matz" Matsumoto c1c8c25e70 Merge pull request #5223 from shuujii/ensure-initialization-of-RVALUE_zero-in-mrb_obj_alloc
Ensure initialization of `RVALUE_zero` in `mrb_obj_alloc`
2020-12-15 22:32:32 +09:00
Yukihiro "Matz" Matsumoto aec8eba076 Merge pull request #5225 from shuujii/output-build-log-at-the-time-of-installation
Output build log at the time of installation
2020-12-15 22:31:26 +09:00
Yukihiro "Matz" Matsumoto 2f177dcd72 Merge pull request #5222 from jbampton/remove-trailing-whitespace
refactor: remove trailing whitespace from C, Header, Ruby and YAML files
2020-12-15 22:30:38 +09:00
KOBAYASHI Shuji c6364edd96 Output build log at the time of installation 2020-12-15 21:54:19 +09:00
John Bampton 4fa3359d44 refactor: remove trailing whitespace from C, Header, Ruby and YAML files
Lint
2020-12-15 19:44:02 +10:00
KOBAYASHI Shuji d5cb54d4df Ensure initialization of RVALUE_zero in mrb_obj_alloc
Union initialization initializes the first member. The first member of
`RVALUE` is `struct free_obj`, but because it is only 4-words, it seems that
initialization after the 5th word is not ensured.

Therefore, I created 6-words `struct RVALUE_initializer` for initialization
and made it the first member.
2020-12-15 17:48:06 +09:00
Yukihiro "Matz" Matsumoto e9fe337b95 Merge pull request #5221 from jbampton/fix-spelling
Fix spelling
2020-12-13 23:36:18 +09:00
John Bampton 940dec5e7d Fix spelling 2020-12-13 18:38:22 +10:00
KOBAYASHI Shuji 456878ba06 Improve source scanning for presym
The accuracy is greatly improved by using the C preprocessor to scan C
sources for presym. C preprocessor can perfectly interpret all comments and
preprocessor directives, so it can detect all symbols defined, for example
`mrbgems/mruby-socket/src/const.cstub`.

Also, as described later, this change will greatly improve the accuracy of
presym detection from Ruby sources.

## Result

The number of lines in the `presym` file for all gems is as follows:

  ```console
  Previous:   999 (false positive = 89, undetected = 297)
  New:       1207
  ```

## Build process

The new build process (with presym) is as follows:

1. Build `mrbc` without presym (more on building without presym later).
2. Compile Ruby sources to C struct format with the `mrbc` created in
   step 1, and create` mrblib.c` and `gem_init.c`. Note that the symbols
   in the created files are output as `MRB_SYM` family macros or
   `mrb_intern_lit` instead of IDs (details will be described later).
3. C preprocessor processes C sources including the created files of
   step 2 and outputs them as `.i` files. In these files, for example,
   `MRB_IVSYM(foo)` is converted to `<@! "@" "foo" !@>` and
   `mrb_define_module(mrb, "Foo")` is converted to `<@! "Foo" !@>`.
4. Scan the files created in step 3 and create `presym` and` presym.inc`
   files.

The files created in step 2 should output all static symbols defined in Ruby
sources, including local variables, so we can detect all presyms by just
scanning C sources without scanning Ruby sources directly.

Further, by this process, the files to be scanned becomes the same as the
files to be compiled, so that there is no excess or deficiency.

## Related changes

The following changes have been made in relation to realizing this feature.

### Allow build without presym

It enables build without presym to achieve the "Build process: 1". This
incorporates #5202, see its issue for details.

Note that when presym is enabled, even adding a local variable to a Ruby
source may change contents of presym and require recompilation of almost
all C sources. This is inconvenient, especially during trial and error in
development, but this feature is also useful because it does not cause
this problem if presym is disabled.

### Automatically create build target for `mrbc` without presym

The `mrbc` used in the "Build process: 1" will be built by automatically
creating a build target for it. The build name is `SOURCE_BUILD_NAME/mrbc`.

### Constantize output of C struct format by `mrbc`

To realizing the "Build process: 2", as mentioned above, symbol IDs are not
output directly in C struct format output by `mrbc`. As a result, the output
becomes constant regardless of the state of presym at the time of `mrbc`
build, and it is possible to detect symbols of Ruby sources in the same way
as other C sources.

Note that `mrb_intern_lit` is used for symbols that do not become presym,
but in this state, the corresponding element in the symbol array cannot be
statically initialized, so it is initialized at run time (therefore, in this
case, the `const` qualifier is not added to the symbol array).

### Specify arbitrary `mrbc` file

To realizing the "Build process: 2", enabled to specify `mrbc` created by
another build target or pre-built` mrbc`. Use `MRuby::Build#mrbcfile =` to
specify it explicitly. You can omit the "Build process: 1" by specifying
pre-built `mrbc`, and you can always use an optimized build to compile Ruby
sources faster. I think changes that affect the output of `mrbc` are rare,
so in many cases it helps to improve efficiency.

With presym, the build will be a little slower due to more build steps, but
this feature will improve it a bit.

### Create presym files for each build target

This feature was proposed at #5194 and merged once, but was reverted in
5c205e6e due to problems especially with cross-compilation. It has been
introduced again because this change solves the problem.

The presym files will be created below.

* `build/NAME/presym`
* `build/NAME/include/mruby/presym.inc`

### Other changes

* Because presym detection accuracy is greatly improved as mentioned above,
  `MRuby::Gem::Specification#cdump?` is set to true by default, and
  `disable_cdump` is added instead of `enable_cdump`. Also, support for gem
  specific presym files has been discontinued (https://github.com/mruby/mruby/issues/5151#issuecomment-730967232).
* Previously, `mrbc` was automatically created for the `host` build, but it
  will not be created if the build target for `mrbc` mentioned above is
  automatically created. At this time, `mrbc` file of the `mrbc` build is
  copied to` bin/`.
* Two types of `.d` files will be created, `.o.d` and `.i.d`. oThis is
  because if `.i` depends on `presym.inc`, the dependency will circulate, so
  the `.d` file cannot be shared.
* Changed file created with `enable_cxx_exception` to `X-cxx.cxx` from
  `X.cxx` to use the mruby standard Rake rule.

### Note

Almost all C sources will need to be recompiled if there are any changes to
`persym.inc` (if not recompiled properly, it will often result in run-time
error). If `gcc` toolchain is used, dependencies are resolved by the `.d`
file, so it become automatically recompile target, but if not (e.g. MSVC),
it is necessary to manually make it recompile target.

Also, even if `gcc` toolchain is used, it may not become recompile target if
external gems does not use the mruby standard Rake rule. In particular, if
the standard rule is overwritten, such as
https://github.com/mruby/mruby/pull/5112/files, `.d` file will not be read,
so be careful.
2020-12-13 15:27:53 +09:00
Yukihiro "Matz" Matsumoto 116e128b1a Remove positive check for unsigned integer; close #5218 2020-12-12 18:25:47 +09:00
Yukihiro "Matz" Matsumoto 092dd4a667 Argument forwarding with ... now supports leading arguments.
```ruby
def method_missing(meth, ...)
  send(:"do_#{meth}", ...)
end
```
2020-12-09 11:56:54 +09:00
Yukihiro "Matz" Matsumoto 2e9b8f0d9b Fix a bug caused by tBDOT3 (argument forwarding). 2020-12-08 22:01:47 +09:00
Yukihiro "Matz" Matsumoto ed29d74bfd Make type of pc arguments in debug.c consistent; close #5218
They used to be `size_t`, `uint32_t` and `ptrdiff_t`. Now all of them
made to be `uint32_t`.
2020-12-07 13:59:00 +09:00
Yukihiro "Matz" Matsumoto 8b52c67be9 Merge pull request #5217 from shuujii/call-super-before-creating-host-build-in-MRubyCrossBuild-initialize
Call `super` before creating `host` build in `MRuby::CrossBuild#initialize`
2020-12-06 17:30:34 +09:00
KOBAYASHI Shuji de03e97a50 Call super before creating host build in MRuby::CrossBuild#initialize
Call `super` (`block`) ahead so that creation of the `host` build can be
skipped if pre-built `mrbc` can be specified in the future.

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

### Note

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

Due to the above changes, `build_config/boxing.rb` etc. will not work, but I
have added` mruby-bin-mrbc` to `default.gembox` to fix it. I don't think
this change is a big deal because originally `mruby-compiler` was included.
2020-12-05 09:16:08 +09:00
Yukihiro "Matz" Matsumoto 00d1fd0e6f Fixed a bug with modules prepended many times.
Adjust insertion point in `fix_prepend_module()`.
2020-12-05 08:01:05 +09:00
Yukihiro "Matz" Matsumoto 3972df57fe Make Module#include and Module#prepend behave like Ruby3.0.
Module#include and Module#prepend now affect classes and modules
that have already included or prepended the receiver, mirroring the
behavior if the arguments were included in the receiver before
the other modules and classes included or prepended the receiver.

```ruby
class C; end
module M1; end
module M2; end
C.include M1
M1.include M2
p C.ancestors #=> [C, M1, M2, Object, Kernel, BasicObject]
```
2020-12-04 22:02:37 +09:00
Yukihiro "Matz" Matsumoto 4cd3493737 Merge pull request #5211 from shuujii/move-mrbc-test-to-mruby-bin-mrbc-gem-from-mruby-compiler-gem
Move `mrbc` test to `mruby-bin-mrbc` gem from `mruby-compiler` gem
2020-12-04 12:50:48 +09:00
KOBAYASHI Shuji 4452041ebb Move mrbc test to mruby-bin-mrbc gem from mruby-compiler gem 2020-12-04 09:22:13 +09:00
Yukihiro "Matz" Matsumoto f6ad163841 Merge pull request #5209 from shuujii/remove-build-presym.inc-by-rake-clean
Remove `build/presym{,.inc}` by `rake clean` [ci skip]
2020-12-03 07:17:37 +09:00
KOBAYASHI Shuji e1fa01b9c8 Remove build/presym{,.inc} by rake clean [ci skip]
Currently, adding gems to build configuration and rebuilding does not
regenerate `presym`, which can lead to build errors.

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

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

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

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

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

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

### Benchmark

#### Code

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

#### Result

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

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

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

#### Before this patch:

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

#### After this patch:

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

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

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

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

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

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

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

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

`mrb_int` size

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

Architecture

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

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

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

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

#### Before this patch:

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

#### After this patch:

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

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

### Example

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

#### Before this patch:

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

#### After this patch:

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

### Example

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

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

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

## Benchmark Summary

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

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

### Memory Usage

Lower value is better.

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

### Performance

Higher value is better.

#### `mrb_hash_set`

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

#### `mrb_hash_get`

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

#### `mrb_hash_each`

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

#### `Hash#[]=`

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

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

#### `Hash#each`

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

#### `Hash#delete`

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

#### `Hash#shift`

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

#### `Hash#dup`

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

### Binary Size

Lower value is better.

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

## Other Fixes

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

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

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

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

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

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

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

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

Other new functions:

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

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

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

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

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

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

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

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

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

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

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

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

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

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

The former is to use `USE_XXX` naming convention. The latter is to make
sure `float` is 32bit float and not floating point number in general.
2020-10-12 16:21:40 +09:00
Yukihiro "Matz" Matsumoto ef9df5dc7d Allow MRUBY_CONFIG to specify target file out of source tree. 2020-10-12 16:21:39 +09:00
Yukihiro "Matz" Matsumoto 7dc595f98f Add a new document named mruby3.md.
That describes the changes in `mruby3`.
2020-10-12 16:21:39 +09:00
Yukihiro "Matz" Matsumoto d4b89ccc61 Add assertion we can pack function pointers in mrb_method_t.
If this assertion fails, you have to define `MRB_USE_METHOD_T_STRUCT`.
2020-10-12 16:21:39 +09:00
Yukihiro "Matz" Matsumoto 72d071540c Rename MRB_METHOD_T_STRUCT to MRB_USE_METHOD_T_STRUCT.
It's the first change of renaming configuration options to `MRB_XXX` to
`MRB_USE_XXX` or `MRB_NO_XXX`.
2020-10-12 16:21:38 +09:00
Yukihiro "Matz" Matsumoto dea185e687 Change out-of-range condition of time_t conversion. 2020-10-12 16:21:38 +09:00
Yukihiro "Matz" Matsumoto 968053a35b Avoid out-of-range error for negative time on MRB_TIME_T_UINT.
On platforms where `time_t` is unsigned, negative time can be a result
of integer casting. Out-of-range error is too strict for those cases.
This fix does not address wrong time value in `MRB_WORD_BOXING`. It will
be addressed later (by introducing "big" integers).
2020-10-12 16:21:37 +09:00
Yukihiro "Matz" Matsumoto 66114f8332 Change default mrb_value representation to MRB_WORD_BOXING. 2020-10-12 16:21:37 +09:00
Yukihiro "Matz" Matsumoto 8813ebec07 Skip array embedding if MRB_NO_BOXING and MRB_32BIT; fix #4382
On some platforms, `sizeof(mrb_value) > sizeof(void*)*3`, which makes
`MRB_ARY_EMBED_LEN_MAX` zero. And zero sized array cause compile errors.
2020-10-12 16:21:36 +09:00
Yukihiro "Matz" Matsumoto a93ef815be Add static check for MRB_USE_FLOAT and MRB_WITHOUT_FLOAT. 2020-10-12 16:21:36 +09:00
Yukihiro "Matz" Matsumoto 905d4010bf Fix wrong YAML in .github/workflows/build.yml. 2020-10-12 16:21:36 +09:00
Yukihiro "Matz" Matsumoto 763b39d00b Simplify NaN boxing definitions.
Remove `#ifdef` from `union mrb_value_`.
2020-10-12 16:21:35 +09:00
Yukihiro "Matz" Matsumoto 107c777341 Rename OP_JUW instruction to OP_JMPUW. 2020-10-12 16:21:35 +09:00
Yukihiro "Matz" Matsumoto 500f721f70 Fix typo _hander -> _handler. 2020-10-12 16:21:34 +09:00
Yukihiro "Matz" Matsumoto cb89e1f0d9 Adjust PR #5060 to the latest mruby3 branch. 2020-10-12 16:21:34 +09:00
dearblue 6bc5857125 Suppress warnings for C++
Variables in jump destination block separate declaration and assignment.
2020-10-12 16:21:34 +09:00
dearblue bfb7b491cc Restore the variable pc after longjmp()
Changes made after `setjmp()` are destroyed and need reassignment.
This problem is now caused by the addition of the `OP_JUW` instruction.

When actually building on FreeBSD 12.1 with `clang10 -fsanitize=address`, mrbtest "NameError#name [15.2.31.2.1]" is failed.

However, qualifying `pc` with `volatile` slows down significantly and increases the object code.
Suppress them by qualifying only the variables that restore `pc`.
2020-10-12 16:21:33 +09:00
dearblue c1f112c49a Replace global jump with catch handler implementation
When a global jump occurs, look at the catch handler table to determine where to jump.
In that case, `pc` already shows the following instruction, but since the table shows `begin_offset ... end_offset`, the comparison is done with `begin_offset < pc && pc <= end_offset`.
If there is a corresponding handler, move `pc` to `handler.target_offset` and continue running the VM.

When a global jump across `ensure` is made by `return`, `break`, `next`, `redo` and `retry`, the extended `RBreak` object saves and restores the C-level execution position.
This extended `RBreak` can have tag information, which makes it a pseudo coroutine (the "tag" mimics CRuby).

The implementation of pseudo coroutines by `RBreak` is summarized by `CHECKPOINT_RESTORE ... CHECKPOINT_MAIN ... CHECKPOINT_END` and `throw_tagged_break` / `unwind_ensure` macros.
The restart of processing is branched by `RBREAK_TAG_FOREACH(DISPATCH_CHECKPOINTS)`.

- Not only `rescue` blocks but also `ensure` blocks are now sandwiched between `OP_EXCEPT` and `OP_RAISEIF`.

- Remove the function `ecall()`.
  It is no longer necessary to re-enter the VM to perform an "ensure block".

  This will resolves #1888.

- Added instruction `OP_JUW` (Jump while UnWind).

  It jumps unconditionally like `OP_JMP`, but searches the catch handler table and executes the ensure block.
  Since it searches the catch handler table, it is much heavier than `OP_JMP`.
2020-10-12 16:21:33 +09:00
dearblue 0d7b4deccf Removed push/pop instructions for rescue/ensure
`OP_PUSHERR`, `OP_POPERR`, `OP_EPUSH` and `OP_EPOP` are removed.
2020-10-12 16:21:32 +09:00
dearblue f467b02d45 Extended OP_EXCEPT and OP_RAISE (OP_RAISEIF) instructions
- `OP_EXCEPT` checks if `mrb->exc` is `NULL`, `MRB_TT_EXCEPTION` or
  `MRB_TT_BREAK`.
  If `mrb->exc` is `NULL`, it will be replaced with `nil`.

- If `OP_RAISE` is `nil`, it does nothing and the immediately
  following instruction is executed (like `OP_NOP`).
  Also, in case of `RBreak` object, it moves to the processing for
  `break`.
  With this change, the instruction name is changed from
  `OP_RAISE` to `OP_RAISEIF`.
2020-10-12 16:21:32 +09:00
dearblue a54a3df32c Extended mruby binary format
The catch handler table is combined with iseq block.
This is to prevent the structure from growing by adding a field for the
catch handler table to the `mrb_irep` structure.

"iseq block" and "catch handler table":
  [number of catch handler table (2 bytes)]
  [number of byte code (4 bytes)]
  [iseq (any bytes)]
  [catch handlers (multiple of 7 bytes)]

catch handler:
  [catch type (1 byte)]
  [begin offset (2 bytes)]
  [end offset (2 bytes)]
  [target offset (2 bytes)]

catch type: enum mrb_catch_type (0 = rescue, 1 = ensure)
begin offset: Includes the specified instruction address
end offset: Does not include the specified instruction address
target offset: replaces pc with the specified instruction address

This table is not expanded by `read_irep_record_1()`.
The necessary elements are expanded one by one when used.
2020-10-12 16:21:32 +09:00
Yukihiro "Matz" Matsumoto 3ad6bbc40c Add target/host-cxx.rb to compile mruby with cxx_abi. 2020-10-12 16:21:31 +09:00
Yukihiro "Matz" Matsumoto 67d92c48b5 Avoid breaking the result array by side-effect in C++. 2020-10-12 16:21:31 +09:00
Yukihiro "Matz" Matsumoto 6fbc03b3a8 Revert 4c001673b
Probably I misunderstand strict aliasing rule of C++. The fix in
4c001673b was other way around.
2020-10-12 16:21:30 +09:00
Yukihiro "Matz" Matsumoto 690cafe274 Initialize kdict in OP_ENTER in vm.c. 2020-10-12 16:21:30 +09:00
Yukihiro "Matz" Matsumoto 4e56e0defc Rename union mrb_value to union mrb_value_.
Since some compiler complains when we `typedef` `mrb_value`.
2020-10-12 16:21:30 +09:00
Yukihiro "Matz" Matsumoto 53e46be7e2 Simplify mrb_value structure for MRB_WORD_BOXING. 2020-10-12 16:21:29 +09:00
Yukihiro "Matz" Matsumoto 73e289c54e Simplify mrb_value structure for MRB_NAN_BOXING. 2020-10-12 16:21:29 +09:00
Yukihiro "Matz" Matsumoto ce372122ed Remove mc_clear_by_id.
Clearing all method cache using `memset` is faster than conditional
clear by method id.
2020-10-12 16:21:28 +09:00
Yukihiro "Matz" Matsumoto a733c6e0ea Do not call mrb_mc_clear_by_class at mrb finalization. 2020-10-12 16:21:28 +09:00
Yukihiro "Matz" Matsumoto 425b142168 Refine MRB_NAN_BOXING on 32bit architecture.
You don't need pointer tweaking on 32bit architecture, where pointers
fit in 32bit (lower half of mrb_value).
2020-10-12 16:21:27 +09:00
Yukihiro "Matz" Matsumoto f751c28ca4 Add target/host-m32.rb to compile mruby in 32bit mode.
Tested only on Linux. You need to install 32bit relate libraries,
e.g. libc6-dev-i386.
2020-10-12 16:21:27 +09:00
Yukihiro "Matz" Matsumoto 4281429412 Use memset() to clear method cache. 2020-10-12 16:21:27 +09:00
Yukihiro "Matz" Matsumoto 0e50ea90f3 Add const specifier to cipush(); ref #5052 2020-10-12 16:21:26 +09:00
Yukihiro "Matz" Matsumoto 1eb71b008f Change default boxing scheme from MRB_NO_BOXING.
On 64bit platforms: `MRB_NAN_BOXING`
On 32bit platforms: `MRB_WORD_BOXING`
On debugging: `MRB_NO_BOXING`
2020-10-12 16:21:26 +09:00
Yukihiro "Matz" Matsumoto 84a68ca5ae Make sure bintest only works with host target. 2020-10-12 16:21:26 +09:00
Yukihiro "Matz" Matsumoto 5e9dc72bc5 Pack mrb_value into uint64_t when MRB_NAN_BOXING. 2020-10-12 16:21:25 +09:00
Yukihiro "Matz" Matsumoto 1eacdae319 Use hash table instead of segment list for instance variables. 2020-10-12 16:21:25 +09:00
Yukihiro "Matz" Matsumoto 59b35250cc Rename mrb_hash_modify to hash_modify.
Since it's an internal static function.
2020-10-12 16:21:24 +09:00
Yukihiro "Matz" Matsumoto 2b45d454bc Use mrb_field_write_barrier instead of mrb_write_barrier for push.
When the array is very big, the simpler `mrb_write_barrier` causes
calling `gc_mark_children` for big arrays repeatedly. That would hinder
performance very badly.
2020-10-12 16:21:24 +09:00
Yukihiro "Matz" Matsumoto ff0e3bcea6 Check lv before printing local variable names. 2020-10-12 16:21:24 +09:00
Yukihiro "Matz" Matsumoto 8b3f3c0bf3 Fix the bug by the combination with MRB_64BIT and MRB_INT32.
Which is caused by `MRB_NAN_BOXING`.
2020-10-12 16:21:23 +09:00
Yukihiro "Matz" Matsumoto cf2aabdad6 Run tests for target/boxing.rb. 2020-10-12 16:21:23 +09:00
Yukihiro "Matz" Matsumoto 3d8a38bea4 You don't need to keep index in local variables info in irep. 2020-10-12 16:21:22 +09:00
Yukihiro "Matz" Matsumoto 639946a006 Enable method cache by default.
Introduced `MRB_NO_METHOD_CACHE` which is inverse of `MRB_METHOD_CACHE`
that should be enabled intestinally. In addition, the default cache is
made bigger (128 -> 256).
2020-10-12 16:21:22 +09:00
Yukihiro "Matz" Matsumoto fb5e8ab6d5 Provide a new build target host-gprof that enables profiling. 2020-10-12 16:21:21 +09:00
Yukihiro "Matz" Matsumoto 11955ca1a1 Call #initialize_copy from init_copy only if it's redefined. 2020-10-12 16:21:21 +09:00
Yukihiro "Matz" Matsumoto 52dd0a8cd7 Skip mrb_get_args() in mrb_ary_push(). 2020-10-12 16:21:21 +09:00
Yukihiro "Matz" Matsumoto 6db0162ec7 Upgrade RITE_VM_VERSION to 0300 (means mruby 3.0). 2020-10-12 16:21:20 +09:00
Yukihiro "Matz" Matsumoto dec34d6c7b Split MRB_BINARY_FORMAT to major and minor.
The minor versions should be upper compatible. So mere opcode, section
addition can be done without breaking compiled binary.
2020-10-12 16:21:20 +09:00
Yukihiro "Matz" Matsumoto 8f0ac27196 Update opcode reference and comment.
- no OP_EXT_ anymore
- OP_LOADI16 in right position
2020-10-12 16:21:19 +09:00
Yukihiro "Matz" Matsumoto fd10c72319 Remove OP_EXT[123] from operands. 2020-10-12 16:21:19 +09:00
Yukihiro "Matz" Matsumoto ce7508e0d5 Allow rescue modifier in endless method definitions. 2020-10-12 16:21:19 +09:00
Yukihiro "Matz" Matsumoto c29212cf44 Implement endless-def as in CRuby [Feature#16746]. 2020-10-12 16:21:18 +09:00
Yukihiro "Matz" Matsumoto 6e86e290e4 Rightward-assign by ASSOC.
[ruby-bugs:15921]
2020-10-12 16:21:18 +09:00
Yukihiro "Matz" Matsumoto b2398879fa Avoid including limits.h and stdint.h before mruby.h.
They are included from `mruby.h` anyway, and including it ahead can
cause some errors regarding `INT32_MAX` etc. with C++ compiler.
2020-10-12 16:21:18 +09:00
Yukihiro "Matz" Matsumoto e01648b86b Stop CXX_ABI test with VisualC++.
This combination is too hard to support. Difference between C and C++ is
too big with VisualC++. GCC and clang are OK.
2020-10-12 16:21:17 +09:00
Yukihiro "Matz" Matsumoto e0c9b53217 Run rake gensym on AppVeyor. 2020-10-12 16:21:17 +09:00
Yukihiro "Matz" Matsumoto ce30a4e04b Add const to irep structure to place data on ROM. 2020-10-12 16:21:16 +09:00
Yukihiro "Matz" Matsumoto 31877043c4 Invoke rake gensym for GitHub action build. 2020-10-12 16:21:16 +09:00
Yukihiro "Matz" Matsumoto 167a747a41 Constify irep struct for Class#new. 2020-10-12 16:21:16 +09:00
Yukihiro "Matz" Matsumoto cfc958b01a Add const qualifier to generated Proc structures. 2020-10-12 16:21:15 +09:00
Yukihiro "Matz" Matsumoto 015f06ed8e Should not mark red (i.e. ROM allocated) objects. 2020-10-12 16:21:15 +09:00
Yukihiro "Matz" Matsumoto 95169097fc Add /std:c++latest option to VC CXX_ABI build. 2020-10-12 16:21:14 +09:00
Yukihiro "Matz" Matsumoto 474545bba2 Do not define mrb_lstat unless S_ISLNK is defined. 2020-10-12 16:21:14 +09:00
Yukihiro "Matz" Matsumoto 925cd2ab8f Use int instead of mrb_int for arena index. 2020-10-12 16:21:14 +09:00
Yukihiro "Matz" Matsumoto 9debf63340 Specify the size of struct RStringEmbed array part. 2020-10-12 16:21:13 +09:00
Yukihiro "Matz" Matsumoto 0f978932e2 Use %u instead of %d to dump symbol IDs. 2020-10-12 16:21:13 +09:00
Yukihiro "Matz" Matsumoto 6488ae855f Avoid use of designated initializer for the sake of cxx_abi. 2020-10-12 16:21:13 +09:00
Yukihiro "Matz" Matsumoto d2f267a13d Add casts to silence warnings. 2020-10-12 16:21:12 +09:00
Yukihiro "Matz" Matsumoto a4a1e01e81 Add explicit gensym to GitHub Actions. 2020-10-12 16:21:12 +09:00
Yukihiro "Matz" Matsumoto ee111dd175 Clarify the use of MRB_64BIT and MRB_INT64 in dump.c and load.c.
- `MRB_64BIT`: the size of a pointer is 64 bits
- `MRB_INT64`: the size of `mrb_int` is 64 bits
2020-10-12 16:21:11 +09:00
Yukihiro "Matz" Matsumoto f0c1126997 Fix dump.c for MRB_INT32 env. 2020-10-12 16:21:11 +09:00
Yukihiro "Matz" Matsumoto b7031e8bc8 Enable NUL (\0) again. 2020-10-12 16:21:10 +09:00
Yukihiro "Matz" Matsumoto 52507b1083 Generate C struct from irep instead of binary dump. 2020-10-12 16:21:10 +09:00
Yukihiro "Matz" Matsumoto 7deb41b0e8 Generate C source file to represent mrb_irep structures.
Type `mrbc -S -B<init> -o<outfile> <rbfiles...>` to generate the C
source code that holds compiled `mrb_irep`.

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

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

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

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

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

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

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

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

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

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

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

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

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

After this commit:

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

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

After this commit:

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

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

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

and it has been parsed to:

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    Fix invalid pointer free inside other heap's block

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

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

    Fix memory leak for temporary symbols when out of memory

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

    Fix uninitialized pointer dereference for debug section

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

    Fix memory leak for temporary filenames when out of memory

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

    Fix memory leak for irep when out of memory

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

    Fix uninitialized pointer dereference when do not finished initializing irep

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

    Fix NULL pointer dereference when do not finished initializing irep

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

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

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

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

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

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

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

    Fix keep wrong symbol index when out of memory

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

    Fix keep wrong symbol capacity when out of memory

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

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

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

    Fix protect exception for print error message

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

    Protect exception for mruby core initialization

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

    Fix memory leak for string object when out of memory

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

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

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

    Fix stack overflow when out of memory

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

    Detailes:

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

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

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

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

    Add internal functions (not `static`):

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

  ```ruby
  def a
    "Safe!"
  end

  a = "Auto!"

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

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

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

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

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

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

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

  class B < A; end

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

#### Before this patch:

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

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

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

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

no patched:

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

### Example

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

#### Before this patch:

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

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

  ```console
  $ bin/mruby example.rb
  [1, 2, 3]
  [1, 2, 3]
  {[2]=>1, [2]=>2, [3]=>3}
  ```
2020-05-09 15:27:42 +09:00
Yukihiro "Matz" Matsumoto 3491372a1d Update doc/opcode.md for operand signs. [ci skip] 2020-05-07 18:41:43 +09:00
Yukihiro "Matz" Matsumoto 03b0741994 Remove unnecessary sprintf test that fails since 91368c1. 2020-05-07 10:31:49 +09:00
Yukihiro "Matz" Matsumoto a87f0b158d Update README.md to address old bison problem on macOS. 2020-05-07 10:17:38 +09:00
Yukihiro "Matz" Matsumoto 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 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
dearblue 9840e5352b Isolate top-level local variables by file scope; fix #4931 2020-01-29 23:30:13 +09:00
dearblue 0aa5aa1de2 Add test for top level local variables are in file scope; ref #4931 2020-01-29 23:29:48 +09:00
dearblue 25d9370f97 Fix take over file scope variable names with mirb command
Ref #4931

With this change, the `_` variable is defined after the `-r` switch.
2020-01-19 21:59:47 +09:00
dearblue 2bab6e197d Fix take over file scope variables with mruby command
Resolve #4931
2020-01-19 21:52:37 +09:00
dearblue 893cc2780c Add mrbc_cleanup_local_variables() with mrbc_context; ref #4931
Clean up defined local variables.
2020-01-19 21:42:09 +09:00
take-cheeze 6af555b394 Align RIStruct data for rational 2019-12-13 04:41:43 +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
281 changed files with 27217 additions and 8741 deletions
+149
View File
@@ -0,0 +1,149 @@
name: Build & Test
on: [push, pull_request]
jobs:
Check-Skip:
if: |
!contains(github.event.head_commit.message, '[ci skip]') &&
!contains(github.event.head_commit.message, '[skip ci]') &&
!contains(github.event.head_commit.message, '[skip gha]')
runs-on: ubuntu-latest
steps:
- run: echo not skip
Ubuntu-1604:
needs: Check-Skip
runs-on: ubuntu-16.04
env:
MRUBY_CONFIG: ci/gcc-clang
CC: gcc
steps:
- uses: actions/checkout@v2
- name: Ruby version
run: ruby -v
- name: Compiler version
run: ${{ env.CC }} --version
- name: Build and test
run: rake -m test:build && rake test:run
Ubuntu-1804-gcc:
needs: Check-Skip
runs-on: ubuntu-18.04
env:
MRUBY_CONFIG: ci/gcc-clang
CC: gcc
steps:
- uses: actions/checkout@v2
- name: Ruby version
run: ruby -v
- name: Compiler version
run: ${{ env.CC }} --version
- name: Build and test
run: rake -m test:build && rake test:run
Ubuntu-1804-clang:
needs: Check-Skip
runs-on: ubuntu-18.04
env:
MRUBY_CONFIG: ci/gcc-clang
CC: clang
steps:
- uses: actions/checkout@v2
- name: Ruby version
run: ruby -v
- name: Compiler version
run: ${{ env.CC }} --version
- name: Build and test
run: rake -m test:build && rake test:run
macOS:
needs: Check-Skip
runs-on: macos-latest
env:
MRUBY_CONFIG: ci/gcc-clang
CC: clang
steps:
- uses: actions/checkout@v2
- name: Ruby version
run: ruby -v
- name: Compiler version
run: ${{ env.CC }} --version
- name: Build and test
run: rake -m test:build && rake test:run
Windows-MinGW:
needs: Check-Skip
runs-on: windows-latest
env:
MRUBY_CONFIG: ci/gcc-clang
CC: gcc
steps:
- uses: actions/checkout@v2
- name: Ruby version
run: ruby -v
- name: Compiler version
run: ${{ env.CC }} --version
- name: Build and test
run: rake -m test:build && rake test:run
Windows-Cygwin:
needs: Check-Skip
runs-on: windows-latest
env:
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
MRUBY_CONFIG: ci/gcc-clang
CC: gcc
installer-path: '%TMP%\cygwin-setup.exe'
cygwin-root: C:\cygwin
package-dir: C:\cygwin-package
cache-version: v1
steps:
- uses: actions/checkout@v2
- uses: actions/cache@v2
with:
path: ${{ env.package-dir }}
key: ${{ runner.os }}-cygwin-${{ env.cache-version }}
- name: Download Cygwin installer
shell: cmd
run: >
bitsadmin /transfer download /priority foreground
https://cygwin.com/setup-x86_64.exe ${{ env.installer-path }}
- name: Install Cygwin
shell: cmd
run: >
${{ env.installer-path }}
--quiet-mode --no-shortcuts --no-startmenu --no-desktop --no-admin
--only-site --site http://mirrors.kernel.org/sourceware/cygwin/
--root ${{ env.cygwin-root }}
--local-package-dir ${{ env.package-dir }}
--packages gcc-core,gcc-g++,ruby
- name: Set PATH for Cygwin
run: |
echo '::set-env name=PATH::${{ env.cygwin-root }}\bin;${{ env.cygwin-root }}\usr\bin'
- name: Ruby version
shell: cmd
run: ruby -v
- name: Compiler version
run: ${{ env.CC }} --version
- name: Build and test
shell: cmd
run: ruby /usr/bin/rake -m test:build && ruby /usr/bin/rake test:run
- name: Set PATH for cache archiving (tar)
# set Windows path so that Cygwin tar is not used for cache archiving
run: echo '::set-env name=PATH::C:\windows\System32'
Windows-VC:
needs: Check-Skip
runs-on: windows-latest
env:
MRUBY_CONFIG: ci/msvc
steps:
- uses: actions/checkout@v2
- name: Ruby version
run: ruby -v
- name: Build and test
shell: cmd
run: |
call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\Build\vcvars64.bat"
rake -m test:build && rake test:run
+55
View File
@@ -0,0 +1,55 @@
name: "Code scanning - action"
on:
push:
pull_request:
schedule:
- cron: '0 19 * * 4'
jobs:
CodeQL-Build:
if: |
!contains(github.event.head_commit.message, '[ci skip]') &&
!contains(github.event.head_commit.message, '[skip ci]') &&
!contains(github.event.head_commit.message, '[skip gha]')
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
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
+23
View File
@@ -0,0 +1,23 @@
name: ❄️ Lint
on: [pull_request]
jobs:
yamllint:
name: 🍶 YAML
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: 🧹 YAML Lint
uses: ibiqlik/action-yamllint@v3
markdownlint:
name: 🍸 Markdown
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: 🚀 Use Node.js
uses: actions/setup-node@v2.1.4
with:
node-version: '12.x'
- run: npm install -g markdownlint-cli@0.25.0
- run: markdownlint '**/*.md'
-24
View File
@@ -1,24 +0,0 @@
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
+27
View File
@@ -0,0 +1,27 @@
name: CIFuzz
on: [pull_request]
jobs:
Fuzzing:
if: |
!contains(github.event.head_commit.message, '[ci skip]') &&
!contains(github.event.head_commit.message, '[skip ci]') &&
!contains(github.event.head_commit.message, '[skip gha]')
runs-on: ubuntu-latest
steps:
- name: Build Fuzzers
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
+17
View File
@@ -0,0 +1,17 @@
name: 💎 Spellchecker
on: [pull_request]
jobs:
misspell:
name: 🧹 Check Spelling
runs-on: ubuntu-latest
steps:
- name: 🍒 Check Out
uses: actions/checkout@v2
- name: 🍅 Install
run: |
wget -O - -q https://git.io/misspell | sh -s -- -b .
- name: 🌶️ Misspell
run: |
git ls-files --empty-directory | xargs ./misspell -error
+3
View File
@@ -17,6 +17,9 @@
.svn
.vscode
.yardoc
.ccls*
compile_flags.txt
compile_commands.json
cscope.files
cscope.out
tags
+3 -3
View File
@@ -1,12 +1,12 @@
---
stages:
- pretest
- test
- pretest
- test
pretest:
stage: pretest
image: registry.gitlab.com/dabroz/mruby:gcc47_0.1
tags:
- linux
- linux
variables:
CC: gcc-4.7
CXX: g++-4.7
+16
View File
@@ -0,0 +1,16 @@
MD001: false
MD003: false
MD004: false
MD005: false
MD007: false
MD010: false
MD011: false
MD013: false
MD014: false
MD024: false
MD025: false
MD026: false
MD034: false
MD040: false
MD041: false
MD046: false
+7 -10
View File
@@ -1,14 +1,11 @@
language: c
sudo: false
matrix:
include:
- os: linux
sudo: false
- os: osx
osx_image: xcode7.1
jobs:
- os: linux
- os: osx
env:
- MRUBY_CONFIG=travis_config.rb
script: "rake -m && rake test"
- MRUBY_CONFIG=ci/gcc-clang
script:
- rake -m test:build && rake test:run
+8
View File
@@ -0,0 +1,8 @@
---
extends: default
rules:
document-start: disable
line-length: disable
truthy: false
+3
View File
@@ -43,3 +43,6 @@ of this list.
YAMAMOTO Masaya
KOBAYASHI Shuji
RIZAL Reckordp
Rory O'Connell
John Bampton
Seeker
+1
View File
@@ -0,0 +1 @@
* @matz
+6 -13
View File
@@ -1,6 +1,7 @@
# How to contribute
mruby is an open-source project which is looking forward to each contribution.
Contributors agree to license their contribution(s) under MIT license.
## Your Pull Request
@@ -33,11 +34,6 @@ 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, 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()`).
@@ -50,19 +46,15 @@ The dependencies to libraries should be kept to an absolute minimum. This
increases the portability but makes it also easier to cut away parts of mruby
on-demand.
#### Don't use C++ style comments
/* This is the preferred comment style */
Use C++ style comments only for temporary comment e.g. commenting out some code lines.
#### Insert a break after the method return value:
#### Insert a break after the function return value:
```C
int
main(void)
{
...
}
```
### Ruby code
@@ -72,4 +64,5 @@ language itself. Please note the following hints for your Ruby code:
#### Comply with the Ruby standard (ISO/IEC 30170:2012)
mruby is currently targeting to execute Ruby code which complies to ISO/IEC
30170:2012 (http://www.iso.org/iso/iso_catalogue/catalogue_tc/catalogue_detail.htm?csnumber=59579).
30170:2012 (https://www.iso.org/iso/iso_catalogue/catalogue_tc/catalogue_detail.htm?csnumber=59579),
unless there's a clear reason, e.g. the latest Ruby has changed behavior from ISO.
+4 -4
View File
@@ -6,7 +6,7 @@
DOXYFILE_ENCODING = UTF-8
PROJECT_NAME = "mruby"
PROJECT_NUMBER = 2.1.1
PROJECT_NUMBER = 2.1.2
PROJECT_BRIEF = "mruby is the lightweight implementation of the Ruby language"
@@ -27,12 +27,12 @@ INPUT = README.md \
# Red for Ruby
HTML_COLORSTYLE_HUE = 359
# The following expansions
# The following expansions
ENABLE_PREPROCESSING = YES
MACRO_EXPANSION = YES
EXPAND_ONLY_PREDEF = NO
PREDEFINED =
EXPAND_AS_DEFINED =
PREDEFINED =
EXPAND_AS_DEFINED =
SKIP_FUNCTION_MACROS = NO
# This tells doxygen to search the places that make sense
+1 -1
View File
@@ -1,4 +1,4 @@
Copyright (c) 2020 mruby developers
Copyright (c) 2010-2021 mruby developers
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
+1 -1
View File
@@ -1,4 +1,4 @@
# mruby is using Rake (http://rake.rubyforge.org) as a build tool.
# mruby is using Rake (https://ruby.github.io/rake/) as a build tool.
RAKE = rake
+6 -10
View File
@@ -17,7 +17,9 @@ of the Ministry of Economy, Trade and Industry of Japan.
## How to get mruby
The stable version 2.1.1 of mruby can be downloaded via the following URL: [https://github.com/mruby/mruby/archive/2.1.1.zip](https://github.com/mruby/mruby/archive/2.1.1.zip)
The releace candidate version 3.0.0 of mruby can be downloaded via the following URL: [https://github.com/mruby/mruby/archive/3.0.0-rc.zip](https://github.com/mruby/mruby/archive/3.0.0-rc.zip)
The stable version 2.1.2 of mruby can be downloaded via the following URL: [https://github.com/mruby/mruby/archive/2.1.2.zip](https://github.com/mruby/mruby/archive/2.1.2.zip)
The 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)
@@ -36,16 +38,10 @@ The URL of the mruby home-page is: https://mruby.org.
We don't have a mailing list, but you can use [GitHub issues](https://github.com/mruby/mruby/issues).
## How to compile and install (mruby and gems)
## How to compile, test, and install (mruby and gems)
See the [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.
$ rake test
## Building documentation
There are two sets of documentation in mruby: the mruby API (generated by yard) and C API (Doxygen)
@@ -90,12 +86,12 @@ Please ask us if you want to distribute your code under another license.
## How to Contribute
See the [contribution guidelines][contribution-guidelines], and then send a pull
request to <http://github.com/mruby/mruby>. We consider you have granted
request to <https://github.com/mruby/mruby>. We consider you have granted
non-exclusive right to your contributed code under MIT license. If you want to
be named as one of mruby developers, please include an update to the AUTHORS
file in your pull request.
[ISO-standard]: http://www.iso.org/iso/iso_catalogue/catalogue_tc/catalogue_detail.htm?csnumber=59579
[ISO-standard]: https://www.iso.org/iso/iso_catalogue/catalogue_tc/catalogue_detail.htm?csnumber=59579
[build-status-img]: https://travis-ci.org/mruby/mruby.svg?branch=master
[contribution-guidelines]: https://github.com/mruby/mruby/blob/master/CONTRIBUTING.md
[travis-ci]: https://travis-ci.org/mruby/mruby
+18 -108
View File
@@ -10,11 +10,11 @@ Rake.verbose(false) if Rake.verbose == Rake::DSL::DEFAULT
$LOAD_PATH << File.join(MRUBY_ROOT, "lib")
# load build systems
require "mruby-core-ext"
require "mruby/core_ext"
require "mruby/build"
# load configuration file
MRUBY_CONFIG = (ENV['MRUBY_CONFIG'] && ENV['MRUBY_CONFIG'] != '') ? ENV['MRUBY_CONFIG'] : "#{MRUBY_ROOT}/build_config.rb"
MRUBY_CONFIG = MRuby::Build.mruby_config_path
load MRUBY_CONFIG
# load basic rules
@@ -23,138 +23,48 @@ MRuby.each_target do |build|
end
# load custom rules
load "#{MRUBY_ROOT}/src/mruby_core.rake"
load "#{MRUBY_ROOT}/mrblib/mrblib.rake"
load "#{MRUBY_ROOT}/tasks/core.rake"
load "#{MRUBY_ROOT}/tasks/mrblib.rake"
load "#{MRUBY_ROOT}/tasks/mrbgems.rake"
load "#{MRUBY_ROOT}/tasks/libmruby.rake"
load "#{MRUBY_ROOT}/tasks/bin.rake"
load "#{MRUBY_ROOT}/tasks/presym.rake"
load "#{MRUBY_ROOT}/tasks/test.rake"
load "#{MRUBY_ROOT}/tasks/benchmark.rake"
load "#{MRUBY_ROOT}/tasks/gitlab.rake"
load "#{MRUBY_ROOT}/tasks/doc.rake"
def install_D(src, dst)
rm_f dst
mkdir_p File.dirname(dst)
cp src, dst
end
##############################
# generic build targets, rules
task :default => :all
bin_path = ENV['INSTALL_DIR'] || "#{MRUBY_ROOT}/bin"
depfiles = MRuby.targets['host'].bins.map do |bin|
install_path = MRuby.targets['host'].exefile("#{bin_path}/#{bin}")
source_path = MRuby.targets['host'].exefile("#{MRuby.targets['host'].build_dir}/bin/#{bin}")
file install_path => source_path do |t|
install_D t.prerequisites.first, t.name
end
install_path
end
MRuby.each_target do |target|
gems.map do |gem|
current_dir = gem.dir.relative_path_from(Dir.pwd)
relative_from_root = gem.dir.relative_path_from(MRUBY_ROOT)
current_build_dir = File.expand_path "#{build_dir}/#{relative_from_root}"
if current_build_dir !~ /^#{Regexp.escape(build_dir)}/
current_build_dir = "#{build_dir}/mrbgems/#{gem.name}"
end
gem.bins.each do |bin|
exec = exefile("#{build_dir}/bin/#{bin}")
objs = Dir.glob("#{current_dir}/tools/#{bin}/*.{c,cpp,cxx,cc}").map { |f| objfile(f.pathmap("#{current_build_dir}/tools/#{bin}/%n")) }
file exec => objs + target.libraries do |t|
gem_flags = gems.map { |g| g.linker.flags }
gem_flags_before_libraries = gems.map { |g| g.linker.flags_before_libraries }
gem_flags_after_libraries = gems.map { |g| g.linker.flags_after_libraries }
gem_libraries = gems.map { |g| g.linker.libraries }
gem_library_paths = gems.map { |g| g.linker.library_paths }
linker.run t.name, t.prerequisites, gem_libraries, gem_library_paths, gem_flags, gem_flags_before_libraries, gem_flags_after_libraries
end
if target == MRuby.targets['host']
install_path = MRuby.targets['host'].exefile("#{bin_path}/#{bin}")
file install_path => exec do |t|
install_D t.prerequisites.first, t.name
end
depfiles += [ install_path ]
elsif target == MRuby.targets['host-debug']
unless MRuby.targets['host'].gems.map {|g| g.bins}.include?([bin])
install_path = MRuby.targets['host-debug'].exefile("#{bin_path}/#{bin}")
file install_path => exec do |t|
install_D t.prerequisites.first, t.name
end
depfiles += [ install_path ]
end
else
depfiles += [ exec ]
end
end
end
end
depfiles += MRuby.targets.map { |n, t|
t.libraries
}.flatten
depfiles += MRuby.targets.reject { |n, t| n == 'host' }.map { |n, t|
t.bins.map { |bin| t.exefile("#{t.build_dir}/bin/#{bin}") }
}.flatten
desc "build all targets, install (locally) in-repo"
task :all => depfiles do
task :all => :gensym do
Rake::Task[:build].invoke
puts
puts "Build summary:"
puts
MRuby.each_target do
print_build_summary
MRuby.each_target do |build|
build.print_build_summary
end
MRuby::Lockfile.write
end
desc "run all mruby tests"
task :test
MRuby.each_target do
if test_enabled?
t = :"test_#{self.name}"
task t => ["all"] do
run_test
end
task :test => t
end
if bintest_enabled?
t = :"bintest_#{self.name}"
task t => ["all"] do
run_bintest
end
task :test => t
end
end
task :build => MRuby.targets.flat_map{|_, build| build.products}
desc "clean all built and in-repo installed artifacts"
task :clean do
MRuby.each_target do |t|
rm_rf t.build_dir
MRuby.each_target do |build|
rm_rf build.build_dir
rm_f build.products
end
rm_f depfiles
puts "Cleaned up target build folder"
end
desc "clean everything!"
task :deep_clean => ["clean", "clean_doc"] do
MRuby.each_target do |t|
rm_rf t.gem_clone_dir
task :deep_clean => %w[clean doc:clean] do
MRuby.each_target do |build|
rm_rf build.gem_clone_dir
end
puts "Cleaned up mrbgems build folder"
end
-8
View File
@@ -1,8 +0,0 @@
Things to do (Things that are not done yet)
* special variables ($1,$2..)
* super in aliased methods
Things to improve (Done but things to fix)
* Make additions as they are noticed.
+17
View File
@@ -0,0 +1,17 @@
Thing to Do in the future
===
# After mruby 3.0
* replace `fp_fmt.c` by `float_format` (https://github.com/dhylands/format-float.git)
* multi-precision integer
* WORD_BOXING: Pack some floats in `mrb_value`
* NAN_BOXING: Allow `MRB_INT64` along with NaN boxing
* keyword arguments a la Ruby3.0 (using `OP_SENDVK`)
* parser and code generator independent from `mrb_state` (mmruby?)
# Things to do (Things that are not done yet)
* `begin ... end while cond` to behave as CRuby
* special variables ($1,$2..)
* super in aliased methods
+30 -35
View File
@@ -1,50 +1,45 @@
version: "{build}"
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
- job_name: Visual Studio 2019 64bit
visualcpp: C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars64.bat
appveyor_build_worker_image: Visual Studio 2019
# Visual Studio 2017 32bit
- visualcpp: C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat
- job_name: Visual Studio 2019 32bit
visualcpp: C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars32.bat
appveyor_build_worker_image: Visual Studio 2019
- job_name: Visual Studio 2017 64bit
visualcpp: C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars64.bat
appveyor_build_worker_image: Visual Studio 2017
- job_name: Visual Studio 2017 32bit
visualcpp: C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars32.bat
appveyor_build_worker_image: Visual Studio 2017
- job_name: Visual Studio 2015 64bit
visualcpp: C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat
appveyor_build_worker_image: Visual Studio 2015
machine: x86_amd64
- job_name: Visual Studio 2015 32bit
visualcpp: C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat
appveyor_build_worker_image: Visual Studio 2015
machine: x86
# 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
init:
- call "%visualcpp%" %machine%
# For using Rubyinstaller's Ruby 2.4 64bit
- set PATH=C:\Ruby24-x64\bin;%PATH%
# For using Rubyins4aller's Ruby 2.6 64bit
# 2.6 is the highest supported Ruby version across all historical
# Visual Studio AppVeyor images. Ruby 2.7 is only on the 2019 image.
- set PATH=C:\Ruby26-x64\bin;%PATH%
- ruby --version
install:
- if not exist win_flex_bison (
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 -E $stdout.sync=true test
- set MRUBY_CONFIG=ci/msvc
- rake -m test:build
- rake test:run
-37
View File
@@ -1,37 +0,0 @@
MRuby::Build.new('full-debug') do |conf|
toolchain :visualcpp
enable_debug
# include all core GEMs
conf.gembox 'full-core'
conf.cc.defines += %w(MRB_GC_STRESS MRB_METHOD_CACHE MRB_ENABLE_DEBUG_HOOK)
conf.enable_test
end
MRuby::Build.new do |conf|
toolchain :visualcpp
# include all core GEMs
conf.gembox 'full-core'
conf.compilers.each do |c|
c.defines += %w(MRB_GC_FIXED_ARENA)
end
conf.enable_bintest
conf.enable_test
end
MRuby::Build.new('cxx_abi') do |conf|
toolchain :visualcpp
conf.gembox 'full-core'
conf.compilers.each do |c|
c.defines += %w(MRB_GC_FIXED_ARENA)
end
conf.enable_bintest
conf.enable_test
enable_cxx_abi
build_mrbc_exec
end
+1 -1
View File
@@ -260,7 +260,7 @@ class Scene
w.times do |x|
rad = Vec.new(0.0, 0.0, 0.0)
# Subsmpling
# Subsampling
nsubsamples.times do |v|
nsubsamples.times do |u|
cnt = cnt + 1
-28
View File
@@ -1,28 +0,0 @@
MRuby::Build.new do |conf|
toolchain :gcc
end
MRuby::Build.new('no_boxing') do |conf|
toolchain :gcc
conf.gembox 'default'
end
MRuby::Build.new('word_boxing') do |conf|
toolchain :gcc
conf.gembox 'default'
conf.compilers.each do |c|
c.defines += %w(MRB_WORD_BOXING)
end
end
MRuby::Build.new('nan_boxing') do |conf|
toolchain :gcc
conf.gembox 'default'
conf.compilers.each do |c|
c.defines += %w(MRB_NAN_BOXING)
end
end
+8 -151
View File
@@ -1,152 +1,9 @@
MRuby::Build.new do |conf|
# load specific toolchain settings
# Gets set by the VS command prompts.
if ENV['VisualStudioVersion'] || ENV['VSINSTALLDIR']
toolchain :visualcpp
else
toolchain :gcc
end
# Turn on `enable_debug` for better debugging
# enable_debug
# Use mrbgems
# conf.gem 'examples/mrbgems/ruby_extension_example'
# conf.gem 'examples/mrbgems/c_extension_example' do |g|
# g.cc.flags << '-g' # append cflags in this gem
# end
# conf.gem 'examples/mrbgems/c_and_ruby_extension_example'
# conf.gem :core => 'mruby-eval'
# conf.gem :mgem => 'mruby-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'
# C compiler settings
# conf.cc do |cc|
# cc.command = ENV['CC'] || 'gcc'
# cc.flags = [ENV['CFLAGS'] || %w()]
# cc.include_paths = ["#{root}/include"]
# cc.defines = %w()
# cc.option_include_path = %q[-I"%s"]
# cc.option_define = '-D%s'
# cc.compile_options = %Q[%{flags} -MMD -o "%{outfile}" -c "%{infile}"]
# end
# mrbc settings
# conf.mrbc do |mrbc|
# mrbc.compile_options = "-g -B%{funcname} -o-" # The -g option is required for line numbers
# end
# Linker settings
# conf.linker do |linker|
# linker.command = ENV['LD'] || 'gcc'
# linker.flags = [ENV['LDFLAGS'] || []]
# linker.flags_before_libraries = []
# linker.libraries = %w()
# linker.flags_after_libraries = []
# linker.library_paths = []
# linker.option_library = '-l%s'
# linker.option_library_path = '-L%s'
# linker.link_options = "%{flags} -o "%{outfile}" %{objs} %{libs}"
# end
# Archiver settings
# conf.archiver do |archiver|
# archiver.command = ENV['AR'] || 'ar'
# archiver.archive_options = 'rs "%{outfile}" %{objs}'
# end
# Parser generator settings
# conf.yacc do |yacc|
# yacc.command = ENV['YACC'] || 'bison'
# yacc.compile_options = %q[-o "%{outfile}" "%{infile}"]
# end
# gperf settings
# conf.gperf do |gperf|
# gperf.command = 'gperf'
# gperf.compile_options = %q[-L ANSI-C -C -p -j1 -i 1 -g -o -t -N mrb_reserved_word -k"1,3,$" "%{infile}" > "%{outfile}"]
# end
# file extensions
# conf.exts do |exts|
# exts.object = '.o'
# exts.executable = '' # '.exe' if Windows
# exts.library = '.a'
# end
# file separetor
# conf.file_separator = '/'
# bintest
# conf.enable_bintest
end
MRuby::Build.new('host-debug') do |conf|
# load specific toolchain settings
# Gets set by the VS command prompts.
if ENV['VisualStudioVersion'] || ENV['VSINSTALLDIR']
toolchain :visualcpp
else
toolchain :gcc
end
enable_debug
# include the default GEMs
conf.gembox 'default'
# C compiler settings
conf.cc.defines = %w(MRB_ENABLE_DEBUG_HOOK)
# Generate mruby debugger command (require mruby-eval)
conf.gem :core => "mruby-bin-debugger"
# bintest
# conf.enable_bintest
end
MRuby::Build.new('test') do |conf|
# Gets set by the VS command prompts.
if ENV['VisualStudioVersion'] || ENV['VSINSTALLDIR']
toolchain :visualcpp
else
toolchain :gcc
end
enable_debug
conf.enable_bintest
conf.enable_test
conf.gembox 'default'
end
#MRuby::Build.new('bench') do |conf|
# # Gets set by the VS command prompts.
# if ENV['VisualStudioVersion'] || ENV['VSINSTALLDIR']
# toolchain :visualcpp
# else
# toolchain :gcc
# conf.cc.flags << '-O3'
# end
# The default build configuration file was moved to `build_config/default.rb`.
#
# conf.gembox 'default'
#end
# Define cross build settings
# MRuby::CrossBuild.new('32bit') do |conf|
# toolchain :gcc
#
# conf.cc.flags << "-m32"
# conf.linker.flags << "-m32"
#
# conf.build_mrbtest_lib_only
#
# conf.gem 'examples/mrbgems/c_and_ruby_extension_example'
#
# conf.test_runner.command = 'env'
# end
# Recommended way to customize the build configuration is:
# * copy `default.rb` (or any config file) to a new file (e.g. `myconfig.rb`)
# * edit `myconfig.rb`.
# * `rake MRUBY_CONFIG=/path/to/myconfig.rb` to compile and test.
# * or `rake MRUBY_CONFIG=myconfig` if your configuration file is in the `build_config` directory.
# * (optional) submit your configuration as a pull-request if it's useful for others
raise "The default configuration was moved to `build_config/default.rb`"
@@ -1,21 +1,5 @@
MRuby::Build.new do |conf|
# Gets set by the VS command prompts.
if ENV['VisualStudioVersion'] || ENV['VSINSTALLDIR']
toolchain :visualcpp
else
toolchain :gcc
end
enable_debug
# include the default GEMs
conf.gembox 'default'
end
# Cross Compiling configuration for Arduino Due
# http://arduino.cc/en/Main/ArduinoBoardDue
# https://arduino.cc/en/Main/ArduinoBoardDue
#
# Requires Arduino IDE >= 1.5
MRuby::CrossBuild.new("ArduinoDue") do |conf|
@@ -47,9 +31,8 @@ MRuby::CrossBuild.new("ArduinoDue") do |conf|
#configuration for low memory environment
cc.defines << %w(MRB_HEAP_PAGE_SIZE=64)
cc.defines << %w(KHASH_DEFAULT_SIZE=8)
cc.defines << %w(MRB_STR_BUF_MIN_SIZE=20)
cc.defines << %w(MRB_GC_STRESS)
#cc.defines << %w(MRB_DISABLE_STDIO) #if you dont need stdio.
#cc.defines << %w(MRB_NO_STDIO) #if you dont need stdio.
#cc.defines << %w(POOL_PAGE_SIZE=1000) #effective only for use with mruby-eval
end
@@ -5,7 +5,7 @@
MRuby::Build.new do |conf|
toolchain :gcc
conf.gembox 'default'
conf.cc.defines = %w(ENABLE_READLINE)
conf.cc.defines = %w(MRB_USE_READLINE)
conf.gembox 'default'
#lightweight regular expression
@@ -33,7 +33,7 @@ MRuby::CrossBuild.new('core2-32-poky-linux') do |conf|
cc.flags << %w(-O2 -pipe -g -feliminate-unused-debug-types)
cc.flags << "--sysroot=#{POKY_EDISON_SYSROOT}"
cc.compile_options = %Q[%{flags} -o "%{outfile}" -c "%{infile}"]
cc.defines = %w(ENABLE_READLINE)
cc.defines = %w(MRB_USE_READLINE)
end
conf.cxx do |cxx|
@@ -1,22 +1,5 @@
MRuby::Build.new do |conf|
# Gets set by the VS command prompts.
if ENV['VisualStudioVersion'] || ENV['VSINSTALLDIR']
toolchain :visualcpp
else
toolchain :gcc
end
enable_debug
# include the default GEMs
conf.gembox 'default'
end
# Cross Compiling configuration for Intel Galileo on Arduino environment
# http://arduino.cc/en/ArduinoCertified/IntelGalileo
# https://arduino.cc/en/ArduinoCertified/IntelGalileo
#
# Requires Arduino IDE for Intel Galileo
MRuby::CrossBuild.new("Galileo") do |conf|
@@ -1,19 +1,3 @@
MRuby::Build.new do |conf|
# Gets set by the VS command prompts.
if ENV['VisualStudioVersion'] || ENV['VSINSTALLDIR']
toolchain :visualcpp
else
toolchain :gcc
end
enable_debug
# include the default GEMs
conf.gembox 'default'
end
# Cross Compiling configuration for RX630
# http://gadget.renesas.com/
#
@@ -30,12 +14,11 @@ MRuby::CrossBuild.new("RX630") do |conf|
cc.compile_options = %Q[%{flags} -o "%{outfile}" -c "%{infile}"]
#configuration for low memory environment
cc.defines << %w(MRB_USE_FLOAT)
cc.defines << %w(MRB_USE_FLOAT32)
cc.defines << %w(MRB_HEAP_PAGE_SIZE=64)
cc.defines << %w(KHASH_DEFAULT_SIZE=8)
cc.defines << %w(MRB_STR_BUF_MIN_SIZE=20)
cc.defines << %w(MRB_GC_STRESS)
cc.defines << %w(MRB_DISABLE_STDIO) #if you dont need stdio.
cc.defines << %w(MRB_NO_STDIO) #if you dont need stdio.
#cc.defines << %w(POOL_PAGE_SIZE=1000) #effective only for use with mruby-eval
end
+11
View File
@@ -0,0 +1,11 @@
# Requires Android NDK r13 or later.
MRuby::CrossBuild.new('android-arm64-v8a') do |conf|
params = {
:arch => 'arm64-v8a',
:platform => 'android-24',
:toolchain => :clang,
}
toolchain :android, params
conf.gembox 'default'
end
+11
View File
@@ -0,0 +1,11 @@
# Requires Android NDK r13 or later.
MRuby::CrossBuild.new('android-armeabi') do |conf|
params = {
:arch => 'armeabi',
:platform => 'android-24',
:toolchain => :clang,
}
toolchain :android, params
conf.gembox 'default'
end
@@ -1,18 +1,3 @@
MRuby::Build.new do |conf|
# Gets set by the VS command prompts.
if ENV['VisualStudioVersion'] || ENV['VSINSTALLDIR']
toolchain :visualcpp
else
toolchain :gcc
end
enable_debug
# include the default GEMs
conf.gembox 'default'
end
# Requires Android NDK r13 or later.
MRuby::CrossBuild.new('android-armeabi-v7a-neon-hard') do |conf|
params = {
+11
View File
@@ -0,0 +1,11 @@
MRuby::Build.new('bench') do |conf|
# Gets set by the VS command prompts.
if ENV['VisualStudioVersion'] || ENV['VSINSTALLDIR']
toolchain :visualcpp
else
toolchain :gcc
conf.cc.flags << '-O3'
end
conf.gembox 'default'
end
+21
View File
@@ -0,0 +1,21 @@
boxings = %w[no word nan]
bits = [64, 32]
ints = [64, 32]
boxings.product(bits, ints) do |boxing, bit, int|
next if boxing == "nan" && int == 64
MRuby::Build.new("boxing-#{boxing}-m#{bit}-i#{int}") do |conf|
conf.toolchain :gcc
conf.gembox 'default'
conf.compilers.each do |c|
c.defines << "MRB_#{boxing.upcase}_BOXING"
c.defines << "MRB_INT#{int}"
c.flags << "-m#{bit}"
end
conf.linker.flags << "-m#{bit}"
conf.enable_debug
conf.enable_test
conf.enable_bintest
end
end
@@ -1,21 +1,5 @@
MRuby::Build.new do |conf|
# Gets set by the VS command prompts.
if ENV['VisualStudioVersion'] || ENV['VSINSTALLDIR']
toolchain :visualcpp
else
toolchain :gcc
end
enable_debug
# include the default GEMs
conf.gembox 'default'
end
# Cross Compiling configuration for Digilent chipKIT Max32
# http://www.digilentinc.com/Products/Detail.cfm?Prod=CHIPKIT-MAX32
# https://www.digilentinc.com/Products/Detail.cfm?Prod=CHIPKIT-MAX32
#
# Requires MPIDE (https://github.com/chipKIT32/chipKIT32-MAX)
#
@@ -44,9 +28,8 @@ MRuby::CrossBuild.new("chipKITMax32") do |conf|
#configuration for low memory environment
cc.defines << %w(MRB_HEAP_PAGE_SIZE=64)
cc.defines << %w(KHASH_DEFAULT_SIZE=8)
cc.defines << %w(MRB_STR_BUF_MIN_SIZE=20)
cc.defines << %w(MRB_GC_STRESS)
#cc.defines << %w(MRB_DISABLE_STDIO) #if you dont need stdio.
#cc.defines << %w(MRB_NO_STDIO) #if you dont need stdio.
#cc.defines << %w(POOL_PAGE_SIZE=1000) #effective only for use with mruby-eval
end
@@ -1,21 +1,22 @@
STDOUT.sync = STDERR.sync = true unless Rake.application.options.always_multitask
MRuby::Build.new('full-debug') do |conf|
toolchain :gcc
enable_debug
conf.toolchain
conf.enable_debug
# include all core GEMs
conf.gembox 'full-core'
conf.cc.flags += %w(-Werror=declaration-after-statement)
conf.cc.defines += %w(MRB_GC_STRESS MRB_METHOD_CACHE MRB_ENABLE_DEBUG_HOOK)
conf.cc.defines += %w(MRB_GC_STRESS MRB_USE_DEBUG_HOOK)
conf.enable_test
end
MRuby::Build.new do |conf|
toolchain :gcc
conf.toolchain
# include all core GEMs
conf.gembox 'full-core'
conf.cc.flags += %w(-Werror=declaration-after-statement)
conf.gem :core => 'mruby-bin-debugger'
conf.compilers.each do |c|
c.defines += %w(MRB_GC_FIXED_ARENA)
end
@@ -24,17 +25,16 @@ MRuby::Build.new do |conf|
end
MRuby::Build.new('cxx_abi') do |conf|
toolchain :gcc
conf.toolchain
conf.gembox 'full-core'
conf.cc.flags += %w(-fpermissive)
conf.compilers.each do |c|
c.defines += %w(MRB_GC_FIXED_ARENA)
end
conf.enable_bintest
conf.enable_test
enable_cxx_abi
conf.enable_cxx_abi
build_mrbc_exec
conf.build_mrbc_exec
end
+20
View File
@@ -0,0 +1,20 @@
STDOUT.sync = STDERR.sync = true unless Rake.application.options.always_multitask
def setup_option(conf)
conf.cc.compile_options.sub!(%r{/Zi }, "") unless ENV['CFLAGS']
conf.cxx.compile_options.sub!(%r{/Zi }, "") unless ENV['CFLAGS'] || ENV['CXXFLAGS']
conf.linker.flags << "/DEBUG:NONE" unless ENV['LDFLAGS']
end
MRuby::Build.new do |conf|
conf.toolchain :visualcpp
# include all core GEMs
conf.gembox 'full-core'
conf.compilers.each do |c|
c.defines += %w(MRB_GC_FIXED_ARENA)
end
setup_option(conf)
conf.enable_bintest
conf.enable_test
end
+11
View File
@@ -0,0 +1,11 @@
MRuby::Build.new do |conf|
conf.toolchain :clang
# include the GEM box
conf.gembox 'default'
# Turn on `enable_debug` for better debugging
conf.enable_sanitizer "address,undefined"
conf.enable_debug
conf.enable_bintest
conf.enable_test
end
+14
View File
@@ -0,0 +1,14 @@
# Define cross build settings
MRuby::CrossBuild.new('cross-32bit') do |conf|
conf.toolchain :gcc
conf.cc.flags << "-m32"
conf.linker.flags << "-m32"
# conf.build_mrbtest_lib_only
conf.gem :core => "mruby-bin-mruby"
conf.gem "#{MRUBY_ROOT}/examples/mrbgems/c_and_ruby_extension_example"
conf.test_runner.command = 'env'
end
+80
View File
@@ -0,0 +1,80 @@
MRuby::Build.new do |conf|
# load specific toolchain settings
conf.toolchain
# Use mrbgems
# conf.gem 'examples/mrbgems/ruby_extension_example'
# conf.gem 'examples/mrbgems/c_extension_example' do |g|
# g.cc.flags << '-g' # append cflags in this gem
# end
# conf.gem 'examples/mrbgems/c_and_ruby_extension_example'
# conf.gem :core => 'mruby-eval'
# conf.gem :mgem => 'mruby-onig-regexp'
# conf.gem :github => 'mattn/mruby-onig-regexp'
# conf.gem :git => 'git@github.com:mattn/mruby-onig-regexp.git', :branch => 'master', :options => '-v'
# include the GEM box
conf.gembox 'default'
# C compiler settings
# conf.cc do |cc|
# cc.command = ENV['CC'] || 'gcc'
# cc.flags = [ENV['CFLAGS'] || %w()]
# cc.include_paths = ["#{root}/include"]
# cc.defines = %w()
# cc.option_include_path = %q[-I"%s"]
# cc.option_define = '-D%s'
# cc.compile_options = %Q[%{flags} -MMD -o "%{outfile}" -c "%{infile}"]
# end
# mrbc settings
# conf.mrbc do |mrbc|
# mrbc.compile_options = "-g -B%{funcname} -o-" # The -g option is required for line numbers
# end
# Linker settings
# conf.linker do |linker|
# linker.command = ENV['LD'] || 'gcc'
# linker.flags = [ENV['LDFLAGS'] || []]
# linker.flags_before_libraries = []
# linker.libraries = %w()
# linker.flags_after_libraries = []
# linker.library_paths = []
# linker.option_library = '-l%s'
# linker.option_library_path = '-L%s'
# linker.link_options = "%{flags} -o "%{outfile}" %{objs} %{libs}"
# end
# Archiver settings
# conf.archiver do |archiver|
# archiver.command = ENV['AR'] || 'ar'
# archiver.archive_options = 'rs "%{outfile}" %{objs}'
# end
# Parser generator settings
# conf.yacc do |yacc|
# yacc.command = ENV['YACC'] || 'bison'
# yacc.compile_options = %q[-o "%{outfile}" "%{infile}"]
# end
# gperf settings
# conf.gperf do |gperf|
# gperf.command = 'gperf'
# gperf.compile_options = %q[-L ANSI-C -C -p -j1 -i 1 -g -o -t -N mrb_reserved_word -k"1,3,$" "%{infile}" > "%{outfile}"]
# end
# file extensions
# conf.exts do |exts|
# exts.object = '.o'
# exts.executable = '' # '.exe' if Windows
# exts.library = '.a'
# end
# file separator
# conf.file_separator = '/'
# Turn on `enable_debug` for better debugging
# conf.enable_debug
conf.enable_bintest
conf.enable_test
end
@@ -1,17 +1,3 @@
MRuby::Build.new do |conf|
# Gets set by the VS command prompts
if ENV['VisualStudioVersion'] || ENV['VSINSTALLDIR']
toolchain :visualcpp
else
toolchain :gcc
end
enable_debug
# Include the default GEMs
conf.gembox 'default'
end
# Cross Compiling configuration for the Sega Dreamcast
# This configuration requires KallistiOS (KOS)
# https://dreamcast.wiki
@@ -25,7 +11,7 @@ MRuby::CrossBuild.new("dreamcast") do |conf|
# 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"
@@ -51,16 +37,16 @@ MRuby::CrossBuild.new("dreamcast") do |conf|
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
# '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
end
# Archiver
conf.archiver do |archiver|
@@ -76,7 +62,7 @@ MRuby::CrossBuild.new("dreamcast") do |conf|
# Disable C++ exception
conf.disable_cxx_exception
# Gems from core
# removing mruby-io
conf.gem :core => "mruby-metaprog"
+73
View File
@@ -0,0 +1,73 @@
# Cross Compiling configuration for the Nintendo GameBoyAdvance.
# This configuration requires devkitARM
# https://devkitpro.org/wiki/Getting_Started/devkitARM
#
# Tested only on GNU/Linux
#
MRuby::CrossBuild.new("gameboyadvance") do |conf|
toolchain :gcc
DEVKITPRO_PATH = "/opt/devkitpro"
BIN_PATH = "#{DEVKITPRO_PATH}/devkitARM/bin"
# C compiler
conf.cc do |cc|
cc.command = "#{BIN_PATH}/arm-none-eabi-gcc"
cc.flags << ["-mthumb-interwork", "-mthumb", "-O2"]
cc.compile_options = %(%{flags} -o "%{outfile}" -c "%{infile}")
end
# C++ compiler
conf.cxx do |cxx|
cxx.command = "#{BIN_PATH}/arm-none-eabi-g++"
cxx.include_paths = conf.cc.include_paths.dup
cxx.flags = conf.cc.flags.dup
cxx.flags << %w[-fno-rtti -fno-exceptions]
cxx.defines = conf.cc.defines.dup
cxx.compile_options = conf.cc.compile_options.dup
end
# Linker
conf.linker do |linker|
linker.command = "#{BIN_PATH}/arm-none-eabi-gcc"
linker.flags << ["-mthumb-interwork", "-mthumb", "-specs=gba.specs"]
end
# No executables
conf.bins = []
# Do not build executable test
conf.build_mrbtest_lib_only
# Disable C++ exception
conf.disable_cxx_exception
# Gems from core
# removing mruby-io
conf.gem core: "mruby-metaprog"
conf.gem core: "mruby-pack"
conf.gem core: "mruby-sprintf"
conf.gem core: "mruby-print"
conf.gem core: "mruby-math"
conf.gem core: "mruby-time"
conf.gem core: "mruby-struct"
conf.gem core: "mruby-compar-ext"
conf.gem core: "mruby-enum-ext"
conf.gem core: "mruby-string-ext"
conf.gem core: "mruby-numeric-ext"
conf.gem core: "mruby-array-ext"
conf.gem core: "mruby-hash-ext"
conf.gem core: "mruby-range-ext"
conf.gem core: "mruby-proc-ext"
conf.gem core: "mruby-symbol-ext"
conf.gem core: "mruby-random"
conf.gem core: "mruby-object-ext"
conf.gem core: "mruby-objectspace"
conf.gem core: "mruby-fiber"
conf.gem core: "mruby-enumerator"
conf.gem core: "mruby-enum-lazy"
conf.gem core: "mruby-toplevel-ext"
conf.gem core: "mruby-kernel-ext"
conf.gem core: "mruby-class-ext"
conf.gem core: "mruby-compiler"
end
+12
View File
@@ -0,0 +1,12 @@
MRuby::Build.new do |conf|
conf.toolchain
# include the default GEMs
conf.gembox 'default'
# C compiler settings
conf.cc.defines = %w(MRB_USE_DEBUG_HOOK)
conf.enable_debug
conf.enable_cxx_abi
conf.enable_test
end
+20
View File
@@ -0,0 +1,20 @@
MRuby::Build.new('host') do |conf|
# load specific toolchain settings
conf.toolchain
conf.enable_debug
# include the default GEMs
conf.gembox 'full-core'
# C compiler settings
conf.cc.defines = %w(MRB_USE_DEBUG_HOOK MRB_NO_BOXING)
# Generate mruby debugger command (require mruby-eval)
conf.gem :core => "mruby-bin-debugger"
# test
conf.enable_test
# bintest
conf.enable_bintest
end
+14
View File
@@ -0,0 +1,14 @@
MRuby::Build.new do |conf|
# load specific toolchain settings
toolchain :gcc
# include the GEM box
conf.gembox 'default'
conf.cc.flags << '-pg'
conf.linker.flags << '-pg'
# Turn on `enable_debug` for better debugging
conf.enable_debug
conf.enable_test
end
+15
View File
@@ -0,0 +1,15 @@
MRuby::Build.new do |conf|
# load specific toolchain settings
toolchain :gcc
# include the GEM box
conf.gembox 'default'
conf.cc.flags << '-m32'
conf.linker.flags << '-m32'
# Turn on `enable_debug` for better debugging
conf.enable_debug
conf.enable_test
conf.enable_bintest
end
+36
View File
@@ -0,0 +1,36 @@
MRuby::Build.new do |conf|
# load specific toolchain settings
# Gets set by the VS command prompts.
if ENV['VisualStudioVersion'] || ENV['VSINSTALLDIR']
toolchain :visualcpp
else
toolchain :gcc
end
# include the GEM box
conf.gembox 'default'
# C compiler settings
conf.cc do |cc|
cc.flags = '-fPIC'
end
conf.archiver do |archiver|
archiver.command = 'gcc'
archiver.archive_options = '-shared -o %{outfile} %{objs}'
end
# file extensions
conf.exts do |exts|
exts.library = '.so'
end
# file separator
# conf.file_separator = '/'
# Turn on `enable_debug` for better debugging
conf.enable_debug
conf.enable_bintest
conf.enable_test
end
+11
View File
@@ -0,0 +1,11 @@
MRuby::Build.new do |conf|
if ENV['VisualStudioVersion'] || ENV['VSINSTALLDIR']
conf.toolchain :visualcpp
else
conf.toolchain :gcc
end
conf.build_mrbc_exec
conf.disable_libmruby
conf.disable_presym
end
+17
View File
@@ -0,0 +1,17 @@
# Define cross build settings
MRuby::CrossBuild.new('no-float') do |conf|
conf.toolchain
# Add configuration
conf.compilers.each do |c|
c.defines << "MRB_NO_FLOAT"
end
conf.gem :core => "mruby-bin-mruby"
conf.test_runner.command = 'env'
conf.enable_debug
# conf.enable_bintest
conf.enable_test
end
+143 -50
View File
@@ -6,41 +6,53 @@ binaries.
## Prerequisites
To compile mruby out of the source code you need the following tools:
* C Compiler (e.g. `gcc`)
* Linker (e.g. `gcc`)
* C Compiler (e.g. `gcc` or `clang`)
* Linker (e.g. `gcc` or `clang`)
* Archive utility (e.g. `ar`)
* Parser generator (e.g. `bison`)
* Parser generator (`bison`)
* Ruby 2.0 or later (e.g. `ruby` or `jruby`)
Note that `bison` bundled with MacOS is too old to compile `mruby`.
Try `brew install bison` and follow the instruction shown to update
the `$PATH` to compile `mruby`. We also encourage to upgrade `ruby`
on MacOS in similar manner.
Optional:
* GIT (to update mruby source and integrate mrbgems easier)
* git (to update mruby source and integrate mrbgems easier)
* C++ compiler (to use GEMs which include \*.cpp, \*.cxx, \*.cc)
* Assembler (to use GEMs which include \*.asm)
## Usage
## Build
To compile `mruby` with the default build configuration, just invoke `rake`
inside of the mruby source root. To generate and execute the test tools call
`rake test`. To clean all build files call `rake clean`. To see full command
line on build, call `rake -v`.
You can specify your own configuration file by the `MRUBY_CONFIG` environment
variable (you can use `CONFIG` for shorthand for `MRUBY_CONFIG`). If the path
doesn't exist, *build_config/${MRUBY_CONFIG}.rb* is used. The default
configuration is defined in the `build_config/default.rb` file.
Those build configuration files contain the build configuration of mruby, for
example:
Inside of the root directory of the mruby source a file exists
called *build_config.rb*. This file contains the build configuration
of mruby and looks like this for example:
```ruby
MRuby::Build.new do |conf|
toolchain :gcc
conf.toolchain :gcc
end
```
All tools necessary to compile mruby can be set or modified here. In case
you want to maintain an additional *build_config.rb* you can define a
customized path using the *$MRUBY_CONFIG* environment variable.
To compile just call `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`.
All tools necessary to compile mruby can be set or modified here.
## Build Configuration
Inside of the *build_config.rb* the following options can be configured
based on your environment.
We wish you submit a pull-request to *build_config/**PLATFORM**.rb*, once you
created a new configuration for a new platform.
Inside of the configuration file, the following options can be
configured based on your environment.
### Toolchains
@@ -50,32 +62,36 @@ configure the build environment for specific compiler infrastructures.
#### GCC
Toolchain configuration for the GNU C Compiler.
```ruby
toolchain :gcc
conf.toolchain :gcc
```
#### clang
Toolchain configuration for the LLVM C Compiler clang. Mainly equal to the
GCC toolchain.
```ruby
toolchain :clang
conf.toolchain :clang
```
#### Visual Studio 2010, 2012 and 2013
Toolchain configuration for Visual Studio on Windows. If you use the
[Visual Studio Command Prompt](http://msdn.microsoft.com/en-us/library/ms229859\(v=vs.110\).aspx),
[Visual Studio Command Prompt](https://msdn.microsoft.com/en-us/library/ms229859\(v=vs.110\).aspx),
you normally do not have to specify this manually, since it gets automatically detected by our build process.
```ruby
toolchain :visualcpp
conf.toolchain :visualcpp
```
#### Android
Toolchain configuration for Android.
```ruby
toolchain :android
conf.toolchain :android
```
Requires the custom standalone Android NDK and the toolchain path
@@ -84,20 +100,18 @@ in `ANDROID_STANDALONE_TOOLCHAIN`.
### Binaries
It is possible to select which tools should be compiled during the compilation
process. The following tools can be selected:
* mruby (mruby interpreter)
* mirb (mruby interactive shell)
process. For example,
To select them declare conf.gem as follows:
```ruby
conf.gem "#{root}/mrbgems/mruby-bin-mruby"
conf.gem "#{root}/mrbgems/mruby-bin-mirb"
```
* `mruby`
* `mirb`
The configuration are done via `mrbgems`. See `Mrbgems` section.
### File Separator
Some environments require a different file separator character. It is possible to
set the character via `conf.file_separator`.
```ruby
conf.file_separator = '/'
```
@@ -105,6 +119,7 @@ conf.file_separator = '/'
### C Compiler
Configuration of the C compiler binary, flags and include paths.
```ruby
conf.cc do |cc|
cc.command = ...
@@ -120,6 +135,7 @@ end
C Compiler has header searcher to detect installed library.
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.
@@ -128,6 +144,7 @@ fail 'iconv.h not found' unless conf.cc.search_header_path 'iconv.h'
```
If you need a full file name of header file use `search_header`:
```ruby
# Searches ```iconv.h```.
# If found it will return full path of the header file.
@@ -141,6 +158,7 @@ When you are using GCC toolchain (including clang toolchain since its base is gc
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:
```ruby
def conf.cc.header_search_paths
['/opt/local/include'] + include_paths
@@ -150,6 +168,7 @@ end
### Linker
Configuration of the Linker binary, flags and library paths.
```ruby
conf.linker do |linker|
linker.command = ...
@@ -167,6 +186,7 @@ end
### Archiver
Configuration of the Archiver binary and flags.
```ruby
conf.archiver do |archiver|
archiver.command = ...
@@ -177,6 +197,7 @@ end
### Parser Generator
Configuration of the Parser Generator binary and flags.
```ruby
conf.yacc do |yacc|
yacc.command = ...
@@ -187,6 +208,7 @@ end
### GPerf
Configuration of the GPerf binary and flags.
```ruby
conf.gperf do |gperf|
gperf.command = ...
@@ -195,6 +217,7 @@ end
```
### File Extensions
```ruby
conf.exts do |exts|
exts.object = ...
@@ -203,19 +226,44 @@ conf.exts do |exts|
end
```
### Preallocated Symbols
By far, preallocate symbols are highly compatible with the previous versions, so
we expect you won't see any problem with them. But just in case you face any
issue, you can disable preallocated symbols by specifying `conf.disable_presym`.
In the build process, `mrbc` under cross compiling environment will be compiled
with this configuration.
### Mrbgems
Integrate GEMs in the build process.
```ruby
# Integrate GEM with additional configuration
conf.gem 'path/to/gem' do |g|
g.cc.flags << ...
end
`mruby` comes with the (sort of) packaging system named `mrbgems`. To
specify `gem`, you can use `conf.gem` in the configuration file.
# Integrate GEM without additional configuration
conf.gem 'path/to/another/gem'
```ruby
# Integrate a bundled Gem you see in `mrbgems` directory
conf.gem :core => 'mruby-something'
# Integrate a Gem from GitHub
conf.gem :github => 'someone/mruby-another'
# Integrate a mruby binary Gem
conf.gem :core => 'mruby-bin-mruby'
# Integrate a interactive mruby binary Gem
conf.gem :core => 'mruby-bin-mirb'
# Integrate GemBox (set of Gems)
conf.gembox "default"
```
A GemBox is a set of Gems defined in `mrbgems/default.gembox` for example.
It's just a set of `mrbgem` configurations.
There is a `RubyGem` (gem for CRuby) named `mgem` that help you to
manage `mrbgems`. Try `gem install mgem`. `mgem` can show you the list
of registered `mrbgems`.
See doc/mrbgems/README.md for more option about mrbgems.
### Mrbtest
@@ -223,6 +271,7 @@ See doc/mrbgems/README.md for more option about mrbgems.
Configuration Mrbtest build process.
If you want mrbtest.a only, You should set `conf.build_mrbtest_lib_only`
```ruby
conf.build_mrbtest_lib_only
```
@@ -235,6 +284,7 @@ See `mruby-bin-*/bintest/*.rb` if you need examples.
If you want a temporary files use `tempfile` module of CRuby instead of `/tmp/`.
You can enable it with following:
```ruby
conf.enable_bintest
```
@@ -253,6 +303,7 @@ files are compiled by C++ compiler.
When you mix C++ code, C++ exception would be enabled automatically.
If you need to enable C++ exception explicitly add the following:
```ruby
conf.enable_cxx_exception
```
@@ -262,20 +313,24 @@ conf.enable_cxx_exception
If your compiler does not support C++ and you want to ensure
you don't use mrbgem written in C++, you can explicitly disable
C++ exception, add following:
```ruby
conf.disable_cxx_exception
```
and you will get an error when you try to use C++ gem.
Note that it must be called before `enable_cxx_exception` or `gem` method.
### Debugging mode
To enable debugging mode add the following:
```ruby
conf.enable_debug
```
When debugging mode is enabled
* Macro `MRB_DEBUG` would be defined.
* Which means `mrb_assert()` macro is enabled.
* Debug information of irep would be generated by `mrbc`.
@@ -284,27 +339,29 @@ When debugging mode is enabled
## Cross-Compilation
mruby can also be cross-compiled from one platform to another. To
achieve this the *build_config.rb* needs to contain an instance of
`MRuby::CrossBuild`. This instance defines the compilation
tools and flags for the target platform. An example could look
like this:
mruby can also be cross-compiled from one platform to another. To achieve
cross-compilation, the build configuration needs to contain an instance of
`MRuby::CrossBuild`. This instance defines the compilation tools and flags
for the target platform. An example could look like this:
```ruby
MRuby::CrossBuild.new('32bit') do |conf|
toolchain :gcc
conf.toolchain :gcc
conf.cc.flags << "-m32"
conf.linker.flags << "-m32"
end
```
All configuration options of `MRuby::Build` can also be used
in `MRuby::CrossBuild`.
All configuration options of `MRuby::Build` can also be used in
`MRuby::CrossBuild`. You can find examples under the *build_config*
directory.
### Mrbtest in Cross-Compilation
In cross compilation, you can run `mrbtest` on emulator if
you have it by changing configuration of test runner.
```ruby
conf.test_runner do |t|
t.command = ... # set emulator. this value must be non nil or false
@@ -344,6 +401,7 @@ root directory. The structure of this directory will look like this:
+- mruby
The compilation workflow will look like this:
* compile all files under *src* (object files will be stored
in *build/host/src*)
* generate parser grammar out of *src/parse.y* (generated
@@ -421,6 +479,7 @@ build directory.
The cross compilation workflow starts in the same way as the normal
compilation by compiling all *native* libraries and binaries.
Afterwards the cross compilation process proceeds like this:
* cross-compile all files under *src* (object files will be stored
in *build/i386/src*)
* generate parser grammar out of *src/parse.y* (generated
@@ -470,7 +529,7 @@ can't be disabled for the main build.
MRuby::CrossBuild.new('Minimal') do |conf|
toolchain :gcc
conf.cc.defines = %w(MRB_DISABLE_STDIO)
conf.cc.defines = %w(MRB_NO_STDIO)
conf.bins = []
end
```
@@ -486,3 +545,37 @@ of mruby, a native binary called `mrbtest` will be generated and executed.
This binary contains all test cases which are defined under *test/t*. In case
of a cross-compilation an additional cross-compiled *mrbtest* binary is
generated. You can copy this binary and run on your target system.
## Embedding `mruby` in Your Application
After the build, you will get `libmruby.a`. You can link it to your application.
For compiler options and library path, you can use `mruby-config` command for
convenience. `mruby-config` command prints the configuration used for `libmruby.a`.
```
$ mruby-config --help
Usage: mruby-config [switches]
switches:
--cflags print flags passed to compiler
--ldflags print flags passed to linker
--ldflags-before-libs print flags passed to linker before linked libraries
--libs print linked libraries
--libmruby-path print libmruby path
```
For example, when you have a C source file (`c.c`) and try to
compile and link it with `libmruby.a`, you can run the following command,
```
gcc `mruby-config --cflags` c.c `mruby-config --ldflags` `mruby-config --libs`
```
When you use `make`, add following lines in `Makefile`
```
MRB_CONFIG = <path-to-mruby-config>
CFLAGS = `$(MRB_CONFIG) --cflags`
LDFLAGS = `$(MRB_CONFIG) --ldflags`
LIBS = `$(MRB_CONFIG) --libs`
```
+5 -4
View File
@@ -38,7 +38,7 @@ To confirm mrdb was installed properly, run mrdb with the `--version` option:
```bash
$ mrdb --version
mruby 2.1.1 (2020-04-20)
mruby 2.1.2 (2020-08-06)
```
## 2.2 Basic Operation
@@ -220,6 +220,7 @@ Example:
```
Enabling all breakpoints
```
(foo.rb:1) enable 1 3
```
@@ -263,7 +264,7 @@ Example:
```
(sample.rb:1) info breakpoints
Num Type Enb What
Num Type Enb What
1 breakpoint y at sample.rb:3 -> file name,line number
2 breakpoint n in Sample_class:sample_class_method -> [class:]method name
3 breakpoint y in sample_global_method
@@ -273,8 +274,8 @@ Displaying the specified breakpoint number:
```
(foo.rb:1) info breakpoints 1 3
Num Type Enb What
1 breakpoint y at sample.rb:3
Num Type Enb What
1 breakpoint y at sample.rb:3
3 breakpoint y in sample_global_method
```
+1 -1
View File
@@ -3,7 +3,7 @@
_This is an English translation of [Matz's blog post][matz blog post]
written in Japanese._
_Some parts are updated to reflect recent changes._
[matz blog post]: http://www.rubyist.net/~matz/20130731.html
[matz blog post]: https://www.rubyist.net/~matz/20130731.html
When you are extending mruby using C language, you may encounter
mysterious "arena overflow error" or memory leak or very slow
+50 -23
View File
@@ -1,7 +1,9 @@
# mruby configuration macros.
## How to use these macros.
You can use mrbconfs with following ways:
* Write them in `mrbconf.h`.
* Using compiler flags is preferred when building a cross binaries or multiple mruby binaries
since it's easier to use different mrbconf per each `MRuby::Build`.
@@ -11,7 +13,9 @@ You can use mrbconfs with following ways:
changes `struct` layout and cause memory access error when C and other language(e.g., C++) is mixed.
## stdio setting.
`MRB_DISABLE_STDIO`
`MRB_NO_STDIO`
* When defined `<stdio.h>` functions won't be used.
* Some features will be disabled when this is enabled:
* `mrb_irep` load/dump from/to file.
@@ -19,80 +23,97 @@ You can use mrbconfs with following ways:
* Printing features in **src/print.c**.
## Debug macros.
`MRB_ENABLE_DEBUG_HOOK`
`MRB_USE_DEBUG_HOOK`
* When defined code fetch hook and debug OP hook will be enabled.
* When using any of the hook set function pointer `code_fetch_hook` and/or `debug_op_hook` of `mrb_state`.
* Fetch hook will be called before any OP.
* Debug OP hook will be called when dispatching `OP_DEBUG`.
`MRB_DEBUG`
* When defined `mrb_assert*` macro will be defined with macros from `<assert.h>`.
* Could be enabled via `enable_debug` method of `MRuby::Build`.
## Stack configuration
`MRB_STACK_EXTEND_DOUBLING`
* If defined doubles the stack size when extending it.
* Else extends stack with `MRB_STACK_GROWTH`.
`MRB_STACK_GROWTH`
* Default value is `128`.
* Used in stack extending.
* Ignored when `MRB_STACK_EXTEND_DOUBLING` is defined.
`MRB_STACK_MAX`
* Default value is `0x40000 - MRB_STACK_GROWTH`.
* Raises `RuntimeError` when stack size exceeds this value.
## Primitive type configuration.
`MRB_USE_FLOAT`
* When defined single precision floating point type(C type `float`) is used as `mrb_float`.
* Else double precision floating point type(C type `double`) is used as `mrb_float`.
`MRB_USE_FLOAT32`
* When defined single precision floating point type(C type `float`) is used as `mrb_float`.
* Otherwise double precision floating point type(C type `double`) is used as `mrb_float`.
`MRB_NO_FLOAT`
`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, or `MRB_INT32` are not defined on 64-bit CPU mode, `mrb_int` will be defined as `int64_t`.
* Conflicts with `MRB_INT32`.
## Garbage collector configuration.
`MRB_GC_STRESS`
* When defined full GC is emitted per each `RBasic` allocation.
* Mainly used in memory manager debugging.
`MRB_GC_TURN_OFF_GENERATIONAL`
* When defined turns generational GC by default.
`MRB_GC_FIXED_ARENA`
* When defined used fixed size GC arena.
* Raises `RuntimeError` when this is defined and GC arena size exceeds `MRB_GC_ARENA_SIZE`.
* Useful tracking unnecessary mruby object allocation.
`MRB_GC_ARENA_SIZE`
* Default value is `100`.
* Ignored when `MRB_GC_FIXED_ARENA` isn't defined.
* Defines fixed GC arena size.
`MRB_HEAP_PAGE_SIZE`
* Defines value is `1024`.
* Specifies number of `RBasic` per each heap page.
## Memory pool configuration.
`POOL_ALIGNMENT`
* Default value is `4`.
* If you're allocating data types that requires alignment more than default value define the
largest value of required alignment.
`POOL_PAGE_SIZE`
* Default value is `16000`.
* Specifies page size of pool page.
* Smaller the value is increases memory overhead.
@@ -100,37 +121,38 @@ largest value of required alignment.
## State atexit configuration.
`MRB_FIXED_STATE_ATEXIT_STACK`
* If defined enables fixed size `mrb_state` atexit stack.
* Raises `RuntimeError` when `mrb_state_atexit` call count to same `mrb_state` exceeds
`MRB_FIXED_STATE_ATEXIT_STACK_SIZE`'s value.
`MRB_FIXED_STATE_ATEXIT_STACK_SIZE`
* Default value is `5`.
* If `MRB_FIXED_STATE_ATEXIT_STACK` isn't defined this macro is ignored.
## `mrb_value` configuration.
`MRB_ENDIAN_BIG`
* If defined compiles mruby for big endian machines.
* Used in `MRB_NAN_BOXING`.
* Some mrbgem use this mrbconf.
`MRB_NAN_BOXING`
* If defined represent `mrb_value` in boxed `double`.
* Conflicts with `MRB_USE_FLOAT` and `MRB_WITHOUT_FLOAT`.
* Conflicts with `MRB_USE_FLOAT32` and `MRB_NO_FLOAT`.
`MRB_WORD_BOXING`
* If defined represent `mrb_value` as a word.
* If defined `Float` will be a mruby object with `RBasic`.
## Instance variable configuration.
`MRB_IV_SEGMENT_SIZE`
* Default value is `4`.
* Specifies size of each segment in segment list.
## Reduce heap memory configuration.
`MRB_USE_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.
@@ -138,6 +160,7 @@ largest value of required alignment.
* 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.
@@ -145,37 +168,41 @@ largest value of required alignment.
* 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.
* If it isn't defined, they only support the US-ASCII encoding.
`MRB_FUNCALL_ARGC_MAX`
* Default value is `16`.
* Specifies 4th argument(`argc`) max value of `mrb_funcall`.
* Raises `ArgumentError` when the `argc` argument is bigger then this value `mrb_funcall`.
`KHASH_DEFAULT_SIZE`
* Default value is `32`.
* Specifies default size of khash table bucket.
* Used in `kh_init_ ## name` function.
`MRB_STR_BUF_MIN_SIZE`
* Default value is `128`.
* Specifies initial capacity of `RString` created by `mrb_str_buf_new` function..
`MRB_NO_METHOD_CACHE`
`MRB_METHOD_CACHE`
* Improve performance for method dispatch.
* Disable method cache to save memory.
`MRB_METHOD_CACHE_SIZE`
* Default value is `128`.
* Ignored if `MRB_METHOD_CACHE` is not defined.
* Default value is `256`.
* Ignored if `MRB_NO_METHOD_CACHE` is defined.
* Need to be the power of 2.
`MRB_METHOD_T_STRUCT`
`MRB_USE_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
* No `MRB_USE_METHOD_T_STRUCT` requires highest 2 bits of function pointers to be zero
* Define this macro on machines that use higher bits of pointers
`MRB_ENABLE_ALL_SYMBOLS`
* Make it available `Symbols.all_symbols` in `mrbgems/mruby-symbol-ext`
`MRB_USE_ALL_SYMBOLS`
* Make it available `Symbol.all_symbols` in `mrbgems/mruby-symbol-ext`
* Increase heap memory usage.
+31 -14
View File
@@ -5,21 +5,27 @@ standardised way into mruby.
## Usage
By default mrbgems is currently deactivated. As soon as you add a GEM to your
build configuration (i.e. *build_config.rb*), mrbgems will be activated and the
extension integrated.
You have to activate mrbgems explicitly in your build configuration. To add
a GEM, add the following line to your build configuration file, for example:
To add a GEM into the *build_config.rb* add the following line for example:
```ruby
conf.gem '/path/to/your/gem/dir'
```
You can also use a relative path which would be relative from the mruby root:
You can also use a relative path to specify a gem.
```ruby
conf.gem 'examples/mrbgems/ruby_extension_example'
```
In that case,
* if your build configuration file is in the `build_config` directory, it's
relative from `MRUBY_ROOT`.
* otherwise, it is relative from the directory where your build configuration is.
A remote GIT repository location for a GEM is also supported:
```ruby
conf.gem :git => 'https://github.com/masuidrive/mrbgems-example.git', :branch => 'master'
conf.gem :github => 'masuidrive/mrbgems-example', :branch => 'master'
@@ -27,17 +33,20 @@ conf.gem :bitbucket => 'mruby/mrbgems-example', :branch => 'master'
```
You can specify the sub directory of the repository with `:path` option:
```ruby
conf.gem github: 'mruby/mruby', path: 'mrbgems/mruby-socket'
```
To use mrbgem from [mgem-list](https://github.com/mruby/mgem-list) use `:mgem` option:
```ruby
conf.gem :mgem => 'mruby-yaml'
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'
```
@@ -54,13 +63,14 @@ NOTE: `:bitbucket` option supports only git. Hg is unsupported in this version.
There are instances when you wish to add a collection of mrbgems into mruby at
once, or be able to substitute mrbgems based on configuration, without having to
add each gem to the *build_config.rb* file. A packaged collection of mrbgems
add each gem to your build configuration file. A packaged collection of mrbgems
is called a GemBox. A GemBox is a file that contains a list of mrbgems to load
into mruby, in the same format as if you were adding them to *build_config.rb*
into mruby, in the same format as if you were adding them to the build config
via `config.gem`, but wrapped in an `MRuby::GemBox` object. GemBoxes are
loaded into mruby via `config.gembox 'boxname'`.
Below we have created a GemBox containing *mruby-time* and *mrbgems-example*:
```ruby
MRuby::GemBox.new do |conf|
conf.gem "#{root}/mrbgems/mruby-time"
@@ -73,16 +83,19 @@ must be saved with a *.gembox* extension inside the *mrbgems* directory to to be
picked up by mruby.
To use this example GemBox, we save it as `custom.gembox` inside the *mrbgems*
directory in mruby, and add the following to our *build_config.rb* file inside
directory in mruby, and add the following to your build configuration file inside
the build block:
```ruby
conf.gembox 'custom'
```
This will cause the *custom* GemBox to be read in during the build process,
adding *mruby-time* and *mrbgems-example* to the build.
If you want, you can put GemBox outside of mruby directory. In that case you must
specify an absolute path like below.
```ruby
conf.gembox "#{ENV["HOME"]}/mygemboxes/custom"
```
@@ -120,6 +133,7 @@ to compile C and Ruby files. *README.md* is a short description of your GEM.
mrbgems expects a specification file called *mrbgem.rake* inside of your
GEM directory. A typical GEM specification could look like this for example:
```ruby
MRuby::Gem::Specification.new('c_and_ruby_extension_example') do |spec|
spec.license = 'MIT'
@@ -149,6 +163,7 @@ The `license` and `author` properties are required in every GEM!
In case your GEM is depending on other GEMs please use
`spec.add_dependency(gem, *requirements[, default_get_info])` like:
```ruby
MRuby::Gem::Specification.new('c_and_ruby_extension_example') do |spec|
spec.license = 'MIT'
@@ -158,10 +173,10 @@ MRuby::Gem::Specification.new('c_and_ruby_extension_example') do |spec|
# The version must be between 1.0.0 and 1.5.2 .
spec.add_dependency('mruby-parser', '>= 1.0.0', '<= 1.5.2')
# Use any version of mruby-uv from github.
# Use any version of mruby-uv from GitHub.
spec.add_dependency('mruby-uv', '>= 0.0.0', :github => 'mattn/mruby-uv')
# Use latest mruby-onig-regexp from github. (version requirements can be omitted)
# Use latest mruby-onig-regexp from GitHub. (version requirements can be omitted)
spec.add_dependency('mruby-onig-regexp', :github => 'mattn/mruby-onig-regexp')
# You can add extra mgems active only on test
@@ -172,6 +187,7 @@ end
The version requirements and default gem information are optional.
Version requirement supports following operators:
* '=': is equal
* '!=': is not equal
* '>': is greater
@@ -184,18 +200,20 @@ Version requirement supports following operators:
When more than one version requirements is passed, the dependency must satisfy all of it.
You can have default gem to use as dependency when it's not defined in *build_config.rb*.
You can have default gem to use as dependency when it's not defined in your build configuration.
When the last argument of `add_dependency` call is `Hash`, it will be treated as default gem information.
Its format is same as argument of method `MRuby::Build#gem`, expect that it can't be treated as path gem location.
When a special version of dependency is required,
use `MRuby::Build#gem` in *build_config.rb* to override default gem.
use `MRuby::Build#gem` in the build configuration to override default gem.
If you have conflicting GEMs use the following method:
* `spec.add_conflict(gem, *requirements)`
* The `requirements` argument is same as in `add_dependency` method.
like following code:
```ruby
MRuby::Gem::Specification.new 'some-regexp-binding' do |spec|
spec.license = 'BSD'
@@ -238,7 +256,6 @@ For example: when B depends to C and A depends to B, A will get include paths ex
Exported include_paths are automatically appended to GEM local include_paths by rake.
You can use `spec.export_include_paths` accessor if you want more complex build.
## C Extension
mruby can be extended with C. This is possible by using the C API to
@@ -250,6 +267,7 @@ mrbgems expects that you have implemented a C method called
`mrb_YOURGEMNAME_gem_init(mrb_state)`. `YOURGEMNAME` will be replaced
by the name of your GEM. If you call your GEM *c_extension_example*, your
initialisation method could look like this:
```C
void
mrb_c_extension_example_gem_init(mrb_state* mrb) {
@@ -294,7 +312,6 @@ mruby can be extended with pure Ruby. It is possible to override existing
classes or add new ones in this way. Put all Ruby files into the *mrblib*
folder.
### Pre-Conditions
none
+83
View File
@@ -0,0 +1,83 @@
# Symbols
Symbols in `mruby` C source code is represented by `mrb_sym` which is alias of
`uint32_t`. Lower 30 bits are used for symbols so that higher 2 bits can be
used as flags, e.g. `struct mt_elem` in `class.c`.
```C
struct mt_elem {
union mt_ptr ptr;
size_t func_p:1;
size_t noarg_p:1;
mrb_sym key:sizeof(mrb_sym)*8-2;
};
```
## C API
We provide following C API for symbols.
### Generate Symbols
#### `mrb_sym mrb_intern(mrb_state*,const char*,size_t)`
Get a symbol from a string.
#### `mrb_sym mrb_intern_check_cstr(mrb_state*,const char*)`
Get a symbol from a NULL terminated (C) string.
#### `mrb_sym mrb_intern_str(mrb_state*,mrb_value)`
Get a symbol from a Ruby string object.
#### `mrb_intern_lit(mrb_state*,const char*)`
Get a symbol from a C string literal. The second argument should be a C string
literal, otherwise you will get a compilation error. It does not copy C string
given the fact it's a literal.
#### `mrb_sym mrb_intern_check(mrb_state*,const char*,size_t)`
Get a symbol from a string if the string has been already registered as a
symbol, otherwise return `0`. We also provide variants `mrb_intern_check_str()`
(from Ruby string) and `mrb_intern_check_cstr()` (from C string).
#### `const char *mrb_sym_name(mrb_state*,mrb_sym)`
Get a string representation of a symbol as a C string.
#### `const char *mrb_sym_name_len(mrb_state*,mrb_sym,mrb_int*)`
Get a string representation of a symbol, and its length.
## Preallocate Symbols
To save RAM, `mruby` can use compile-time allocation of some symbols. You can
use following macros to get preallocated symbols by including `mruby/presym.h`
header.
* `MRB_SYM(xor)` //=> xor (Word characters)
* `MRB_SYM_B(xor)` //=> xor! (Method with Bang)
* `MRB_SYM_Q(xor)` //=> xor? (Method with Question mark)
* `MRB_SYM_E(xor)` //=> xor= (Method with Equal)
* `MRB_CVSYM(xor)` //=> @@xor (Class Variable)
* `MRB_IVSYM(xor)` //=> @xor (Instance Variable)
* `MRB_OPSYM(xor)` //=> ^ (Operator)
For `MRB_OPSYM()`, specify the names corresponding to operators (see
`MRuby::Presym::OPERATORS` in `lib/mruby/presym.rb` for the names that
can be specified for it). Other than that, describe only word characters
excluding leading and ending punctuations.
These macros are converted to static symbol IDs at compile time, unless
preallocate symbols are disabled by `conf.disable_presym`. In that case,
these macros are expanded to `mrb_intern_lit` calls, therefore the mruby state
variable is required. The above macros assume the variable name is `mrb`. If
its name is not `mrb`, you need to use macros with `_2` suffix, such as
`MRB_SYM_2` to specify `mrb_state*` variable.
### Disabling Preallocated Symbols
You can disable preallocated symbols by specifying `conf.disable_presym` in the
configuration file.
+41 -42
View File
@@ -13,15 +13,6 @@ This document is collecting these limitations.
This document does not contain a complete list of limitations.
Please help to improve it by submitting your findings.
## `1/2` gives `0.5`
Since mruby does not have `Bignum`, bigger integers are represented
by `Float` numbers. To enhance interoperability between `Fixnum`
and `Float`, mruby provides `Float#upto` and other iterating
methods for the `Float` class. As a side effect, `1/2` gives `0.5`
not `0`.
## `Array` passed to `puts`
Passing an Array to `puts` results in different output.
@@ -38,7 +29,7 @@ puts [1,2,3]
3
```
#### mruby [2.1.1 (2020-04-20)]
#### mruby [2.1.2 (2020-08-06)]
```
[1, 2, 3]
@@ -61,9 +52,17 @@ end
`ZeroDivisionError` is raised.
#### mruby [2.1.1 (2020-04-20)]
#### mruby [2.1.2 (2020-08-06)]
No exception is raised.
No exception is raised. Instead you have to do:
```ruby
begin
1 / 0
rescue => e
raise e
end
```
## Fiber execution can't cross C function boundary
@@ -89,7 +88,7 @@ p Liste.new "foobar"
` [] `
#### mruby [2.1.1 (2020-04-20)]
#### mruby [2.1.2 (2020-08-06)]
`ArgumentError` is raised.
@@ -119,7 +118,7 @@ false
true
```
#### mruby [2.1.1 (2020-04-20)]
#### mruby [2.1.2 (2020-08-06)]
```
true
@@ -156,7 +155,7 @@ p 'ok'
ok
```
#### mruby [2.1.1 (2020-04-20)]
#### mruby [2.1.2 (2020-08-06)]
```
test.rb:8: undefined method 'test_func' (NoMethodError)
@@ -178,7 +177,7 @@ defined?(Foo)
nil
```
#### mruby [2.1.1 (2020-04-20)]
#### mruby [2.1.2 (2020-08-06)]
`NameError` is raised.
@@ -195,7 +194,7 @@ alias $a $__a__
` nil `
#### mruby [2.1.1 (2020-04-20)]
#### mruby [2.1.2 (2020-08-06)]
Syntax error
@@ -217,7 +216,7 @@ end
`ArgumentError` is raised.
The re-defined `+` operator does not accept any arguments.
#### mruby [2.1.1 (2020-04-20)]
#### mruby [2.1.2 (2020-08-06)]
` 'ab' `
Behavior of the operator wasn't changed.
@@ -233,7 +232,7 @@ $ ruby -e 'puts Proc.new {}.binding'
#<Binding:0x00000e9deabb9950>
```
#### mruby [2.1.1 (2020-04-20)]
#### mruby [2.1.2 (2020-08-06)]
```
$ ./bin/mruby -e 'puts Proc.new {}.binding'
@@ -245,8 +244,7 @@ trace (most recent call last):
## Keyword arguments
mruby keyword arguments behave slightly different from CRuby 2.5
to make the behavior simpler and less confusing. Maybe in the
future, the simpler behavior will be adopted to CRuby as well.
to make the behavior simpler and less confusing.
#### Ruby [ruby 2.5.1p57 (2018-03-29 revision 63029)]
@@ -255,7 +253,7 @@ $ ruby -e 'def m(*r,**k) p [r,k] end; m("a"=>1,:b=>2)'
[[{"a"=>1}], {:b=>2}]
```
#### mruby [mruby 2.1.1]
#### mruby [mruby 2.1.2]
```
$ ./bin/mruby -e 'def m(*r,**k) p [r,k] end; m("a"=>1,:b=>2)'
@@ -264,26 +262,6 @@ trace (most recent call last):
-e:1: keyword argument hash with non symbol keys (ArgumentError)
```
## Argument Destructuring
```ruby
def m(a,(b,c),d); p [a,b,c,d]; end
m(1,[2,3],4) # => [1,2,3,4]
```
Destructured arguments (`b` and `c` in above example) cannot be accessed
from the default expression of optional arguments and keyword arguments,
since actual assignment is done after the evaluation of those default
expressions. Thus:
```ruby
def f(a,(b,c),d=b)
p [a,b,c,d]
end
f(1,[2,3])
```
CRuby gives `[1,2,3,nil]`. mruby raises `NoMethodError` for `b`.
## `nil?` redefinition in conditional expressions
Redefinition of `nil?` is ignored in conditional expressions.
@@ -297,3 +275,24 @@ puts(a.nil? ? "truthy" : "falsy")
```
Ruby outputs `falsy`. mruby outputs `truthy`.
## Argument Destructuring
```ruby
def m(a,(b,c),d); p [a,b,c,d]; end
m(1,[2,3],4) # => [1,2,3,4]
```
Destructured arguments (`b` and `c` in above example) cannot be accessed
from the default expression of optional arguments and keyword arguments,
since actual assignment is done after the evaluation of those default
expressions. Thus:
```ruby
def f(a,(b,c),d=b)
p [a,b,c,d]
end
f(1,[2,3])
```
CRuby gives `[1,2,3,nil]`. mruby raises `NoMethodError` for `b`.
+163
View File
@@ -0,0 +1,163 @@
User visible changes in `mruby3`
===
# Build System
## `build_config` directory
Typical build configuration files are located in `build_config`
directory. For examples:
* `default`: the default configuration
* `host-gprof`: compiles with `gprof` for performance tuning
* `host-m32`: compiles in gcc 32bit mode on 64bit platforms
* `boxing`: compiles all three boxing options
* `clang-asan`: compiles with `clang`'s Address Sanitizer
You can specify the build configuration file with the
`MRUBY_CONFIG` environment variable (or `CONFIG` in short).
If the value specified by `MRUBY_CONFIG` is not the path to
the configuration file, `build_config/${MRUBY_CONFIG}.rb` is
used. So you can specify it as `rake MRUBY_CONFIG=boxing`,
for example.
# Build Configuration Contribution
When you write a new build configuration description, please
contribute. We welcome your contribution as a GitHub
pull-request.
# Language Changes
## New Syntax
We have ported some new syntax from CRuby.
* Single line pattern matching (`12 => x`);
mruby matches only with local variables at the moment
* Numbered block parameter (`x.map{_1 * 2}`)
* End-less `def` (`def double(x) = x*2`)
# Configuration Options Changed
## Renamed for consistency
Some configuration macro names are changed for consistency (use `MRB_USE_XXX`
or `MRB_NO_XXX`).
| mruby2 | mruby3 |
|--------------------------------|---------------------------|
| `MRB_ENABLE_ALL_SYMBOLS` | `MRB_USE_ALL_SYMBOLS` |
| `MRB_ENABLE_CXX_ABI` | `MRB_USE_CXX_ABI` |
| `MRB_ENABLE_CXX_EXCEPTION` | `MRB_USE_CXX_EXCEPTION` |
| `MRB_ENABLE_DEBUG_HOOK` | `MRB_USE_DEBUG_HOOK` |
| `MRB_DISABLE_DIRECT_THREADING` | `MRB_NO_DIRECT_THREADING` |
| `MRB_DISABLE_STDIO` | `MRB_NO_STDIO` |
| `MRB_METHOD_T_STRUCT` | `MRB_USE_METHOD_T_STRUCT` |
| `MRB_USE_FLOAT` | `MRB_USE_FLOAT32` |
| `MRB_WITHOUT_FLOAT` | `MRB_NO_FLOAT` |
| `ENABLE_LINENOISE` | `MRB_USE_LINENOISE` |
| `ENABLE_READLINE` | `MRB_USE_READLINE` |
| `DISABLE_MIRB_UNDERSCORE` | `MRB_NO_MIRB_UNDERSCORE` |
* `MRB_USE_FLOAT32` is changed from `MRB_USE_FLOAT` to make sure `float` here
means using single precision float, and not the opposite of `MRB_NO_FLOAT`.
* `MRB_USE_METHOD_T_STRUCT` uses `struct` version of `mrb_method_t`. More
portable but consumes more memory. Turned on by default on 32bit platforms.
* `MRB_` prefix is added to those without.
## `MRB_NO_BOXING`
Uses `struct` to represent `mrb_value`. Consumes more memory
but easier to investigate the internal and to debug. It used
to be default `mrb_value` representation. Now the default is
`MRB_WORD_BOXING`.
## `MRB_WORD_BOXING`
Pack `mrb_value` in an `intptr_t` integer. Consumes less
memory compared to `MRB_NO_BOXING` especially on 32 bit
platforms. `Fixnum` size is 31 bits so some integer values
does not fit in `Fixnum` integers.
## `MRB_NAN_BOXING`
Pack `mrb_value` in a floating pointer number. Nothing
changed from previous versions.
## `MRB_USE_MALLOC_TRIM`
Call `malloc_trim(0)` from mrb_full_gc() if this macro is defined.
If you are using glibc malloc, this macro could reduce memory consumption.
# Command Line Program
## `bin/mruby` (by mrbgems/mruby-bin-mruby)
The mruby3 now automatically detects `*.mrb` files without the `-b`
switch. Therefore, it can be mixed with the `*.rb` file in combination
with the `-r` switch and specified at the same time.
Here's an example that works fine:
```console
$ bin/mruby app.mrb
$ bin/mruby -r lib1.mrb -r lib2.rb app.rb
$ bin/mruby -r lib1.rb -r lib2.rb < app.mrb
```
# Internal Changes
## New Instructions
`mruby3` introduces a few new instructions.
Instructions that access pool[i]/syms[i] where i>255.
* `OP_LOADL16`
* `OP_STRING16`
* `OP_LOADSYM16`
Instructions that load a 32 bit integer.
* `OP_LOADI32`
Instruction that unwinds jump table for rescue/ensure.
* `OP_JMPUW`
Renamed from `OP_RAISE`
* `OP_RAISEIF`
Instruction that is reserved for the future keyword argument support.
* OP_SENDVK
## Removed Instructions
Instructions for old exception handling
* `OP_ONERR`
* `OP_POPERR`
* `OP_EPUSH`
* `OP_EPOP`
No more operand extension
* `OP_EXT1`
* `OP_EXT2`
* `OP_EXT3`
## Changed Instructions
Jump addresses used to be specified by absolute offset from the start of `iseq`. Now they are relative offset from the address of the next instruction.
## `Random` now use `xoshiro128++`.
For better and faster random number generation.
## Preallocated Symbol
Preallocated symbols are interned at compile-time. They can be accessed via symbols macros (e.g. `MRB_SYM()`).
See [Symbols](https://github.com/mruby/mruby/blob/master/doc/guides/symbol.md).
+102 -103
View File
@@ -16,112 +16,111 @@ In the table.1 below, the second field describes the size (and
sign) of operands.
* B: 8bit
* sB: signed 8bit
* S: 16bit
* sS: signed 16bit
* W: 24bit
First two byte operands may be extended to 16bit. When those byte
operands are bigger than 256, the instruction will be prefixed by
`OP_EXT1` (means 1st operand is 16bit) or `OP_EXT2` (means 2nd operand
is 16bit) or `OP_EXT3` (means 1st and 2nd operands are 16bit).
For instructions marked by `'`, `OP_EXT1` can be prefixed. For those
with `"`, either `OP_EXT1` or `OP_EXT2` or `OP_EXT2` can be prefixed.
## table.1 Instruction Table
| Instruction Name | Operand type | Semantics |
|:-----------------|--------------|---------------------|
| OP_NOP | - | |
| OP_MOVE" | BB | R(a) = R(b)
| OP_LOADL" | BB | R(a) = Pool(b)
| OP_LOADI" | BsB | R(a) = mrb_int(b)
| OP_LOADI_0' | B | R(a) = 0
| OP_LOADI_1' | B | R(a) = 1
| OP_LOADI_2' | B | R(a) = 2
| OP_LOADI_3' | B | R(a) = 3
| OP_LOADSYM" | BB | R(a) = Syms(b)
| OP_LOADNIL' | B | R(a) = nil
| OP_LOADSELF' | B | R(a) = self
| OP_LOADT' | B | R(a) = true
| OP_LOADF' | B | R(a) = false
| OP_GETGV" | BB | R(a) = getglobal(Syms(b))
| OP_SETGV" | BB | setglobal(Syms(b), R(a))
| OP_GETSV" | BB | R(a) = Special[b]
| OP_SETSV" | BB | Special[b] = R(a)
| OP_GETIV" | BB | R(a) = ivget(Syms(b))
| OP_SETIV" | BB | ivset(Syms(b),R(a))
| OP_GETCV" | BB | R(a) = cvget(Syms(b))
| OP_SETCV" | BB | cvset(Syms(b),R(a))
| OP_GETCONST" | BB | R(a) = constget(Syms(b))
| OP_SETCONST" | BB | constset(Syms(b),R(a))
| OP_GETMCNST" | BB | R(a) = R(a)::Syms(b)
| OP_SETMCNST" | BB | R(a+1)::Syms(b) = R(a)
| OP_GETUPVAR' | BBB | R(a) = uvget(b,c)
| OP_SETUPVAR' | BBB | uvset(b,c,R(a))
| OP_JMP | S | pc+=a
| OP_JMPIF' | SB | if R(b) pc+=a
| OP_JMPNOT' | SB | if !R(b) pc+=a
| OP_ONERR | sS | rescue_push(pc+a)
| OP_EXCEPT' | B | R(a) = exc
| OP_RESCUE" | BB | R(b) = R(a).isa?(R(b))
| OP_POPERR | B | a.times{rescue_pop()}
| OP_RAISE' | B | raise(R(a))
| OP_EPUSH' | B | ensure_push(SEQ[a])
| OP_EPOP | B | A.times{ensure_pop().call}
| OP_SENDV" | BB | R(a) = call(R(a),Syms(b),*R(a+1))
| OP_SENDVB" | BB | R(a) = call(R(a),Syms(b),*R(a+1),&R(a+2))
| OP_SEND" | BBB | R(a) = call(R(a),Syms(b),R(a+1),...,R(a+c))
| OP_SENDB" | BBB | R(a) = call(R(a),Syms(Bx),R(a+1),...,R(a+c),&R(a+c+1))
| OP_CALL' | B | R(a) = self.call(frame.argc, frame.argv)
| OP_SUPER' | BB | R(a) = super(R(a+1),... ,R(a+b+1))
| OP_ARGARY' | BS | R(a) = argument array (16=5:1:5:1:4)
| OP_ENTER | W | arg setup according to flags (23=5:5:1:5:5:1:1)
| OP_KARG" | BB | R(a) = kdict[Syms(Bx)] # todo
| OP_KARG2" | BB | R(a) = kdict[Syms(Bx)]; kdict.rm(Syms(b)) # todo
| OP_RETURN' | B | return R(a) (normal)
| OP_RETURN_BLK' | B | return R(a) (in-block return)
| OP_BREAK' | B | break R(a)
| OP_BLKPUSH' | BS | R(a) = block (16=5:1:5:1:4)
| OP_ADD" | BB | R(a) = R(a)+R(a+1)
| OP_ADDI" | BBB | R(a) = R(a)+mrb_int(c)
| OP_SUB" | BB | R(a) = R(a)-R(a+1)
| OP_SUBI" | BB | R(a) = R(a)-C
| OP_MUL" | BB | R(a) = R(a)*R(a+1)
| OP_DIV" | BB | R(a) = R(a)/R(a+1)
| OP_EQ" | BB | R(a) = R(a)==R(a+1)
| OP_LT" | BB | R(a) = R(a)<R(a+1)
| OP_LE" | BB | R(a) = R(a)<=R(a+1)
| OP_GT" | BB | R(a) = R(a)>R(a+1)
| OP_GE" | BB | R(a) = R(a)>=R(a+1)
| OP_ARRAY' | BB | R(a) = ary_new(R(a),R(a+1)..R(a+b))
| OP_ARRAY2" | BB | R(a) = ary_new(R(b),R(b+1)..R(b+c))
| OP_ARYCAT' | B | ary_cat(R(a),R(a+1))
| OP_ARYPUSH' | B | ary_push(R(a),R(a+1))
| OP_AREF' | BB | R(a) = R(a)[b]
| OP_ASET' | BB | R(a)[b] = R(a+1)
| OP_APOST' | BB | *R(a),R(A+1)..R(A+C) = R(a)[B..]
| OP_STRING" | BB | R(a) = str_dup(Lit(b))
| OP_STRCAT' | B | str_cat(R(a),R(a+1))
| OP_HASH' | BB | R(a) = hash_new(R(a),R(a+1)..R(a+b))
| OP_HASHADD' | BB | R(a) = hash_push(R(a),R(a+1)..R(a+b))
| OP_LAMBDA" | BB | R(a) = lambda(SEQ[b],OP_L_LAMBDA)
| OP_BLOCK" | BB | R(a) = lambda(SEQ[b],OP_L_BLOCK)
| OP_METHOD" | BB | R(a) = lambda(SEQ[b],OP_L_METHOD)
| OP_RANGE_INC' | B | R(a) = range_new(R(a),R(a+1),FALSE)
| OP_RANGE_EXC' | B | R(a) = range_new(R(a),R(a+1),TRUE)
| OP_OCLASS' | B | R(a) = ::Object
| OP_CLASS" | BB | R(a) = newclass(R(a),Syms(b),R(a+1))
| OP_MODULE" | BB | R(a) = newmodule(R(a),Syms(b))
| OP_EXEC" | BB | R(a) = blockexec(R(a),SEQ[b])
| OP_DEF" | BB | R(a).newmethod(Syms(b),R(a+1))
| OP_ALIAS' | B | alias_method(R(a),R(a+1),R(a+2))
| OP_UNDEF" | BB | undef_method(R(a),Syms(b))
| OP_SCLASS' | B | R(a) = R(a).singleton_class
| OP_TCLASS' | B | R(a) = target_class
| OP_ERR' | B | raise(RuntimeError, Lit(Bx))
| OP_EXT1 | - | make 1st operand 16bit
| OP_EXT2 | - | make 2nd operand 16bit
| OP_EXT3 | - | make 1st and 2nd operands 16bit
| OP_STOP | - | stop VM
| Instruction Name | Operand type | Semantics |
|------------------|--------------|--------------------------------------------------------|
| OP_NOP | - | no operation |
| OP_MOVE | BB | R(a) = R(b) |
| OP_LOADL | BB | R(a) = Pool(b) |
| OP_LOADI | BB | R(a) = mrb_int(b) |
| OP_LOADINEG | BB | R(a) = mrb_int(-b) |
| OP_LOADI__1 | B | R(a) = mrb_int(-1) |
| OP_LOADI_0 | B | R(a) = mrb_int(0) |
| OP_LOADI_1 | B | R(a) = mrb_int(1) |
| OP_LOADI_2 | B | R(a) = mrb_int(2) |
| OP_LOADI_3 | B | R(a) = mrb_int(3) |
| OP_LOADI_4 | B | R(a) = mrb_int(4) |
| OP_LOADI_5 | B | R(a) = mrb_int(5) |
| OP_LOADI_6 | B | R(a) = mrb_int(6) |
| OP_LOADI_7 | B | R(a) = mrb_int(7) |
| OP_LOADI16 | BsS | R(a) = mrb_int(b) |
| OP_LOADSYM | BB | R(a) = Syms(b) |
| OP_LOADNIL | B | R(a) = nil |
| OP_LOADSELF | B | R(a) = self |
| OP_LOADT | B | R(a) = true |
| OP_LOADF | B | R(a) = false |
| OP_GETGV | BB | R(a) = getglobal(Syms(b)) |
| OP_SETGV | BB | setglobal(Syms(b), R(a)) |
| OP_GETSV | BB | R(a) = Special[Syms(b)] |
| OP_SETSV | BB | Special[Syms(b)] = R(a) |
| OP_GETIV | BB | R(a) = ivget(Syms(b)) |
| OP_SETIV | BB | ivset(Syms(b),R(a)) |
| OP_GETCV | BB | R(a) = cvget(Syms(b)) |
| OP_SETCV | BB | cvset(Syms(b),R(a)) |
| OP_GETCONST | BB | R(a) = constget(Syms(b)) |
| OP_SETCONST | BB | constset(Syms(b),R(a)) |
| OP_GETMCNST | BB | R(a) = R(a)::Syms(b) |
| OP_SETMCNST | BB | R(a+1)::Syms(b) = R(a) |
| OP_GETUPVAR | BBB | R(a) = uvget(b,c) |
| OP_SETUPVAR | BBB | uvset(b,c,R(a)) |
| OP_JMP | S | pc=a |
| OP_JMPIF | BS | if R(a) pc=b |
| OP_JMPNOT | BS | if !R(a) pc=b |
| OP_JMPNIL | BS | if R(a)==nil pc=b |
| OP_JMPUW | S | unwind_and_jump_to(a) |
| OP_EXCEPT | B | R(a) = exc |
| OP_RESCUE | BB | R(b) = R(a).isa?(R(b)) |
| OP_RAISEIF | B | raise(R(a)) if R(a) |
| OP_SENDV | BB | R(a) = call(R(a),Syms(b),*R(a+1)) |
| OP_SENDVB | BB | R(a) = call(R(a),Syms(b),*R(a+1),&R(a+2)) |
| OP_SEND | BBB | R(a) = call(R(a),Syms(b),R(a+1),...,R(a+c)) |
| OP_SENDB | BBB | R(a) = call(R(a),Syms(b),R(a+1),...,R(a+c),&R(a+c+1)) |
| OP_CALL | - | R(0) = self.call(frame.argc, frame.argv) |
| OP_SUPER | BB | R(a) = super(R(a+1),... ,R(a+b+1)) |
| OP_ARGARY | BS | R(a) = argument array (16=5:1:5:1:4) |
| OP_ENTER | W | arg setup according to flags (23=5:5:1:5:5:1:1) |
| OP_KEY_P | BB | R(a) = kdict.key?(Syms(b)) |
| OP_KEYEND | - | raise unless kdict.empty? |
| OP_KARG | BB | R(a) = kdict[Syms(b)]; kdict.delete(Syms(b)) |
| OP_RETURN | B | return R(a) (normal) |
| OP_RETURN_BLK | B | return R(a) (in-block return) |
| OP_BREAK | B | break R(a) |
| OP_BLKPUSH | BS | R(a) = block (16=5:1:5:1:4) |
| OP_ADD | B | R(a) = R(a)+R(a+1) |
| OP_ADDI | BB | R(a) = R(a)+mrb_int(b) |
| OP_SUB | B | R(a) = R(a)-R(a+1) |
| OP_SUBI | BB | R(a) = R(a)-mrb_int(b) |
| OP_MUL | B | R(a) = R(a)*R(a+1) |
| OP_DIV | B | R(a) = R(a)/R(a+1) |
| OP_EQ | B | R(a) = R(a)==R(a+1) |
| OP_LT | B | R(a) = R(a)<R(a+1) |
| OP_LE | B | R(a) = R(a)<=R(a+1) |
| OP_GT | B | R(a) = R(a)>R(a+1) |
| OP_GE | B | R(a) = R(a)>=R(a+1) |
| OP_ARRAY | BB | R(a) = ary_new(R(a),R(a+1)..R(a+b)) |
| OP_ARRAY2 | BBB | R(a) = ary_new(R(b),R(b+1)..R(b+c)) |
| OP_ARYCAT | B | ary_cat(R(a),R(a+1)) |
| OP_ARYPUSH | B | ary_push(R(a),R(a+1)) |
| OP_ARYDUP | B | R(a) = ary_dup(R(a)) |
| OP_AREF | BBB | R(a) = R(b)[c] |
| OP_ASET | BBB | R(a)[c] = R(b) |
| OP_APOST | BBB | *R(a),R(a+1)..R(a+c) = R(a)[b..] |
| OP_INTERN | B | R(a) = intern(R(a)) |
| OP_STRING | BB | R(a) = str_dup(Lit(b)) |
| OP_STRCAT | B | str_cat(R(a),R(a+1)) |
| OP_HASH | BB | R(a) = hash_new(R(a),R(a+1)..R(a+b)) |
| OP_HASHADD | BB | R(a) = hash_push(R(a),R(a+1)..R(a+b)) |
| OP_HASHCAT | B | R(a) = hash_cat(R(a),R(a+1)) |
| OP_LAMBDA | BB | R(a) = lambda(SEQ[b],OP_L_LAMBDA) |
| OP_BLOCK | BB | R(a) = lambda(SEQ[b],OP_L_BLOCK) |
| OP_METHOD | BB | R(a) = lambda(SEQ[b],OP_L_METHOD) |
| OP_RANGE_INC | B | R(a) = range_new(R(a),R(a+1),FALSE) |
| OP_RANGE_EXC | B | R(a) = range_new(R(a),R(a+1),TRUE) |
| OP_OCLASS | B | R(a) = ::Object |
| OP_CLASS | BB | R(a) = newclass(R(a),Syms(b),R(a+1)) |
| OP_MODULE | BB | R(a) = newmodule(R(a),Syms(b)) |
| OP_EXEC | BB | R(a) = blockexec(R(a),SEQ[b]) |
| OP_DEF | BB | R(a).newmethod(Syms(b),R(a+1)) |
| OP_ALIAS | BB | alias_method(target_class,Syms(a),Syms(b)) |
| OP_UNDEF | B | undef_method(target_class,Syms(a)) |
| OP_SCLASS | B | R(a) = R(a).singleton_class |
| OP_TCLASS | B | R(a) = target_class |
| OP_DEBUG | BBB | print a,b,c |
| OP_ERR | B | raise(LocalJumpError, Lit(a)) |
| OP_STOP | - | stop VM |
|------------------|--------------|--------------------------------------------------------|
@@ -1,5 +1,5 @@
module CRubyExtension
def CRubyExtension.ruby_method
puts "A Ruby Extension"
puts "#{self}: A Ruby Extension"
end
end
@@ -1,10 +1,14 @@
#include <mruby.h>
#include <mruby/string.h>
#include <stdio.h>
static mrb_value
mrb_c_method(mrb_state *mrb, mrb_value self)
{
puts("A C Extension");
mrb_value self_str = mrb_str_to_str(mrb, self);
printf("%s: A C Extension\n", mrb_str_to_cstr(mrb, self_str));
return self;
}
@@ -1,10 +1,14 @@
#include <mruby.h>
#include <mruby/string.h>
#include <stdio.h>
static mrb_value
mrb_c_method(mrb_state *mrb, mrb_value self)
{
puts("A C Extension");
mrb_value self_str = mrb_str_to_str(mrb, self);
printf("%s: A C Extension\n", mrb_str_to_cstr(mrb, self_str));
return self;
}
@@ -1,5 +1,5 @@
class RubyExtension
def RubyExtension.ruby_method
puts "A Ruby Extension"
puts "#{self}: A Ruby Extension"
end
end
@@ -1,26 +0,0 @@
MRuby::Build.new do |conf|
# Gets set by the VS command prompts.
if ENV['VisualStudioVersion'] || ENV['VSINSTALLDIR']
toolchain :visualcpp
else
toolchain :gcc
end
enable_debug
# include the default GEMs
conf.gembox 'default'
end
# Requires Android NDK r13 or later.
MRuby::CrossBuild.new('android-arm64-v8a') do |conf|
params = {
:arch => 'arm64-v8a',
:platform => 'android-24',
:toolchain => :clang,
}
toolchain :android, params
conf.gembox 'default'
end
@@ -1,26 +0,0 @@
MRuby::Build.new do |conf|
# Gets set by the VS command prompts.
if ENV['VisualStudioVersion'] || ENV['VSINSTALLDIR']
toolchain :visualcpp
else
toolchain :gcc
end
enable_debug
# include the default GEMs
conf.gembox 'default'
end
# Requires Android NDK r13 or later.
MRuby::CrossBuild.new('android-armeabi') do |conf|
params = {
:arch => 'armeabi',
:platform => 'android-24',
:toolchain => :clang,
}
toolchain :android, params
conf.gembox 'default'
end
+85 -65
View File
@@ -25,32 +25,69 @@
#endif
/* configuration options: */
/* add -DMRB_USE_FLOAT to use float instead of double for floating point numbers */
//#define MRB_USE_FLOAT
/* add -DMRB_USE_FLOAT32 to use float instead of double for floating point numbers */
//#define MRB_USE_FLOAT32
/* exclude floating point numbers */
//#define MRB_WITHOUT_FLOAT
//#define MRB_NO_FLOAT
/* add -DMRB_METHOD_CACHE to use method cache to improve performance */
//#define MRB_METHOD_CACHE
/* obsolete configuration */
#if defined(MRB_USE_FLOAT)
# define MRB_USE_FLOAT32
#endif
/* obsolete configuration */
#if defined(MRB_WITHOUT_FLOAT)
# define MRB_NO_FLOAT
#endif
#if defined(MRB_USE_FLOAT32) && defined(MRB_NO_FLOAT)
#error Cannot define MRB_USE_FLOAT32 and MRB_NO_FLOAT at the same time
#endif
/* add -DMRB_NO_METHOD_CACHE to disable method cache to save memory */
//#define MRB_NO_METHOD_CACHE
/* size of the method cache (need to be the power of 2) */
//#define MRB_METHOD_CACHE_SIZE (1<<7)
//#define MRB_METHOD_CACHE_SIZE (1<<8)
/* add -DMRB_METHOD_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 on 32bit Windows.
# if defined(_WIN32) && !defined(_WIN64)
# define MRB_METHOD_T_STRUCT
/* add -DMRB_USE_METHOD_T_STRUCT on machines that use higher bits of function pointers */
/* no MRB_USE_METHOD_T_STRUCT requires highest 2 bits of function pointers to be zero */
#ifndef MRB_USE_METHOD_T_STRUCT
// can't use highest 2 bits of function pointers at least on 32bit
// Windows and 32bit Linux.
# ifdef MRB_32BIT
# define MRB_USE_METHOD_T_STRUCT
# endif
#endif
/* define on big endian machines; used by MRB_NAN_BOXING, etc. */
#ifndef MRB_ENDIAN_BIG
# if (defined(BYTE_ORDER) && defined(BIG_ENDIAN) && BYTE_ORDER == BIG_ENDIAN) || \
(defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
# define MRB_ENDIAN_BIG
# endif
#endif
/* represent mrb_value in boxed double; conflict with MRB_USE_FLOAT32 and MRB_NO_FLOAT */
//#define MRB_NAN_BOXING
/* represent mrb_value as a word (natural unit of data for the processor) */
//#define MRB_WORD_BOXING
/* represent mrb_value as a struct; occupies 2 words */
//#define MRB_NO_BOXING
/* if no specific boxing type is chosen */
#if !defined(MRB_NAN_BOXING) && !defined(MRB_WORD_BOXING) && !defined(MRB_NO_BOXING)
# define MRB_WORD_BOXING
#endif
/* add -DMRB_INT32 to use 32bit integer for mrb_int; conflict with MRB_INT64;
Default for 32-bit CPU mode. */
//#define MRB_INT32
/* add -DMRB_INT64 to use 64bit integer for mrb_int; conflict with MRB_INT32;
Default for 64-bit CPU mode. */
Default for 64-bit CPU mode (unless using MRB_NAN_BOXING). */
//#define MRB_INT64
/* if no specific integer type is chosen */
@@ -64,19 +101,8 @@
# endif
#endif
/* define on big endian machines; used by MRB_NAN_BOXING, etc. */
#ifndef MRB_ENDIAN_BIG
# if (defined(BYTE_ORDER) && defined(BIG_ENDIAN) && BYTE_ORDER == BIG_ENDIAN) || \
(defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
# define MRB_ENDIAN_BIG
# endif
#endif
/* represent mrb_value in boxed double; conflict with MRB_USE_FLOAT and MRB_WITHOUT_FLOAT */
//#define MRB_NAN_BOXING
/* represent mrb_value as a word (natural unit of data for the processor) */
//#define MRB_WORD_BOXING
/* call malloc_trim(0) from mrb_full_gc() */
//#define MRB_USE_MALLOC_TRIM
/* string class to handle UTF-8 encoding */
//#define MRB_UTF8_STRING
@@ -107,9 +133,6 @@
/* page size of memory pool */
//#define POOL_PAGE_SIZE 16000
/* initial minimum size for string buffer */
//#define MRB_STR_BUF_MIN_SIZE 128
/* arena size */
//#define MRB_GC_ARENA_SIZE 100
@@ -122,26 +145,39 @@
/* fixed size state atexit stack */
//#define MRB_FIXED_STATE_ATEXIT_STACK
/* -DMRB_DISABLE_XXXX to drop following features */
//#define MRB_DISABLE_STDIO /* use of stdio */
/* -DMRB_NO_XXXX to drop following features */
//#define MRB_NO_STDIO /* use of stdio */
/* -DMRB_ENABLE_XXXX to enable following features */
//#define MRB_ENABLE_DEBUG_HOOK /* hooks for debugger */
//#define MRB_ENABLE_ALL_SYMBOLS /* Symbols.all_symbols */
/* -DMRB_USE_XXXX to enable following features */
//#define MRB_USE_DEBUG_HOOK /* hooks for debugger */
//#define MRB_USE_ALL_SYMBOLS /* Symbol.all_symbols */
/* obsolete configurations */
#ifdef MRB_METHOD_T_STRUCT
# define MRB_USE_METHOD_T_STRUCT
#endif
#if defined(DISABLE_STDIO) || defined(MRB_DISABLE_STDIO)
# define MRB_NO_STDIO
#endif
#ifdef MRB_DISABLE_DIRECT_THREADING
# define MRB_NO_DIRECT_THREADING
#endif
#if defined(ENABLE_DEBUG) || defined(MRB_ENABLE_DEBUG_HOOK)
# define MRB_USE_DEBUG_HOOK
#endif
#ifdef MRB_ENABLE_ALL_SYMBOLS
# define MRB_USE_ALL_SYMBOLS
#endif
#ifdef MRB_ENABLE_CXX_ABI
# define MRB_USE_CXX_ABI
#endif
#ifdef MRB_ENABLE_CXX_EXCEPTION
# define MRB_USE_CXX_EXCEPTION
#endif
/* end of configuration */
/* define MRB_DISABLE_XXXX from DISABLE_XXX (for compatibility) */
#ifdef DISABLE_STDIO
#define MRB_DISABLE_STDIO
#endif
/* define MRB_ENABLE_XXXX from ENABLE_XXX (for compatibility) */
#ifdef ENABLE_DEBUG
#define MRB_ENABLE_DEBUG_HOOK
#endif
#ifndef MRB_DISABLE_STDIO
#ifndef MRB_NO_STDIO
# include <stdio.h>
#endif
@@ -159,12 +195,12 @@
/* A profile for micro controllers */
#if defined(MRB_CONSTRAINED_BASELINE_PROFILE)
# ifndef KHASH_DEFAULT_SIZE
# define KHASH_DEFAULT_SIZE 16
# ifndef MRB_NO_METHOD_CACHE
# define MRB_NO_METHOD_CACHE
# endif
# ifndef MRB_STR_BUF_MIN_SIZE
# define MRB_STR_BUF_MIN_SIZE 32
# ifndef KHASH_DEFAULT_SIZE
# define KHASH_DEFAULT_SIZE 16
# endif
# ifndef MRB_HEAP_PAGE_SIZE
@@ -176,36 +212,20 @@
/* 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
+155 -99
View File
@@ -1,7 +1,7 @@
/*
** mruby - An embeddable Ruby implementation
**
** Copyright (c) mruby developers 2010-2020
** Copyright (c) mruby developers 2010-2021
**
** Permission is hereby granted, free of charge, to any person obtaining
** a copy of this software and associated documentation files (the
@@ -22,7 +22,7 @@
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
**
** [ MIT license: http://www.opensource.org/licenses/mit-license.php ]
** [ MIT license: https://www.opensource.org/licenses/mit-license.php ]
*/
/**
@@ -53,6 +53,10 @@
#endif
#endif
#ifdef _MSC_VER
# define __func__ __FUNCTION__
#endif
#ifdef MRB_DEBUG
#include <assert.h>
#define mrb_assert(p) assert(p)
@@ -62,11 +66,27 @@
#define mrb_assert_int_fit(t1,n,t2,max) ((void)0)
#endif
#if defined __STDC_VERSION__ && __STDC_VERSION__ >= 201112L
#define mrb_static_assert(exp, str) _Static_assert(exp, str)
#if (defined __cplusplus && __cplusplus >= 201103L) || \
(defined _MSC_VER) || \
(defined __GXX_EXPERIMENTAL_CXX0X__) /* for old G++/Clang++ */
# define mrb_static_assert(exp, str) static_assert(exp, str)
#elif defined __STDC_VERSION__ && \
((__STDC_VERSION__ >= 201112L) || \
(defined __GNUC__ && __GNUC__ * 100 + __GNUC_MINOR__ >= 406))
# define mrb_static_assert(exp, str) _Static_assert(exp, str)
#else
#define mrb_static_assert(exp, str) mrb_assert(exp)
# /* alternative implementation of static_assert() */
# define _mrb_static_assert_cat0(a, b) a##b
# define _mrb_static_assert_cat(a, b) _mrb_static_assert_cat0(a, b)
# ifdef __COUNTER__
# define _mrb_static_assert_id(prefix) _mrb_static_assert_cat(prefix, __COUNTER__)
# else
# define _mrb_static_assert_id(prefix) _mrb_static_assert_cat(prefix, __LINE__)
# endif
# define mrb_static_assert(exp, str) \
struct _mrb_static_assert_id(_mrb_static_assert_) { char x[(exp) ? 1 : -1]; }
#endif
#define mrb_static_assert1(exp) mrb_static_assert(exp, #exp)
#include "mrbconf.h"
@@ -75,7 +95,8 @@
#include <mruby/gc.h>
#include <mruby/version.h>
#ifndef MRB_WITHOUT_FLOAT
#ifndef MRB_NO_FLOAT
#include <float.h>
#ifndef FLT_EPSILON
#define FLT_EPSILON (1.19209290e-07f)
#endif
@@ -86,7 +107,7 @@
#define LDBL_EPSILON (1.08420217248550443401e-19L)
#endif
#ifdef MRB_USE_FLOAT
#ifdef MRB_USE_FLOAT32
#define MRB_FLOAT_EPSILON FLT_EPSILON
#else
#define MRB_FLOAT_EPSILON DBL_EPSILON
@@ -129,16 +150,15 @@ typedef void* (*mrb_allocf) (struct mrb_state *mrb, void*, size_t, void *ud);
typedef struct {
mrb_sym mid;
struct RProc *proc;
mrb_value *stackent;
uint16_t ridx;
uint16_t epos;
struct REnv *env;
const mrb_code *pc; /* return address */
const mrb_code *err; /* error position */
int argc;
int acc;
struct RClass *target_class;
int16_t argc;
int16_t acc;
const struct RProc *proc;
mrb_value *stack;
const mrb_code *pc; /* current address on iseq of this proc */
union {
struct REnv *env;
struct RClass *target_class;
} u;
} mrb_callinfo;
enum mrb_fiber_state {
@@ -153,28 +173,22 @@ enum mrb_fiber_state {
struct mrb_context {
struct mrb_context *prev;
mrb_value *stack; /* stack of virtual machine */
mrb_value *stbase, *stend;
mrb_value *stbase, *stend; /* stack of virtual machine */
mrb_callinfo *ci;
mrb_callinfo *cibase, *ciend;
uint16_t *rescue; /* exception handler stack */
uint16_t rsize;
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;
};
#ifdef MRB_METHOD_CACHE_SIZE
# define MRB_METHOD_CACHE
# undef MRB_NO_METHOD_CACHE
#else
/* default method cache size: 128 */
/* default method cache size: 256 */
/* cache size needs to be power of 2 */
# define MRB_METHOD_CACHE_SIZE (1<<7)
# define MRB_METHOD_CACHE_SIZE (1<<8)
#endif
/**
@@ -188,7 +202,7 @@ struct mrb_context {
*/
typedef mrb_value (*mrb_func_t)(struct mrb_state *mrb, mrb_value self);
#ifndef MRB_METHOD_T_STRUCT
#ifndef MRB_USE_METHOD_T_STRUCT
typedef uintptr_t mrb_method_t;
#else
typedef struct {
@@ -200,7 +214,7 @@ typedef struct {
} mrb_method_t;
#endif
#ifdef MRB_METHOD_CACHE
#ifndef MRB_NO_METHOD_CACHE
struct mrb_cache_entry {
struct RClass *c, *c0;
mrb_sym mid;
@@ -234,10 +248,10 @@ typedef struct mrb_state {
struct RClass *hash_class;
struct RClass *range_class;
#ifndef MRB_WITHOUT_FLOAT
#ifndef MRB_NO_FLOAT
struct RClass *float_class;
#endif
struct RClass *fixnum_class;
struct RClass *integer_class;
struct RClass *true_class;
struct RClass *false_class;
struct RClass *nil_class;
@@ -246,7 +260,7 @@ typedef struct mrb_state {
mrb_gc gc;
#ifdef MRB_METHOD_CACHE
#ifndef MRB_NO_METHOD_CACHE
struct mrb_cache_entry cache[MRB_METHOD_CACHE_SIZE];
#endif
@@ -254,13 +268,13 @@ typedef struct mrb_state {
struct symbol_name *symtbl; /* symbol table */
mrb_sym symhash[256];
size_t symcapa;
#ifndef MRB_ENABLE_SYMBOLL_ALL
#ifndef MRB_USE_ALL_SYMBOLS
char symbuf[8]; /* buffer for small symbol names */
#endif
#ifdef MRB_ENABLE_DEBUG_HOOK
void (*code_fetch_hook)(struct mrb_state* mrb, struct mrb_irep *irep, 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);
#ifdef MRB_USE_DEBUG_HOOK
void (*code_fetch_hook)(struct mrb_state* mrb, const struct mrb_irep *irep, const mrb_code *pc, mrb_value *regs);
void (*debug_op_hook)(struct mrb_state* mrb, const struct mrb_irep *irep, const mrb_code *pc, mrb_value *regs);
#endif
#ifdef MRB_BYTECODE_DECODE_OPTION
@@ -272,7 +286,7 @@ typedef struct mrb_state {
struct RObject *nomem_err; /* pre-allocated NoMemoryError */
struct RObject *stack_err; /* pre-allocated SysStackError */
#ifdef MRB_GC_FIXED_ARENA
struct RObject *arena_err; /* pre-allocated arena overfow error */
struct RObject *arena_err; /* pre-allocated arena overflow error */
#endif
void *ud; /* auxiliary data */
@@ -283,7 +297,6 @@ typedef struct mrb_state {
mrb_atexit_func *atexit_stack;
#endif
uint16_t atexit_stack_len;
uint16_t ecall_nest; /* prevent infinite recursive ecall() */
} mrb_state;
/**
@@ -308,6 +321,7 @@ typedef struct mrb_state {
* @see mrb_define_class_under
*/
MRB_API struct RClass *mrb_define_class(mrb_state *mrb, const char *name, struct RClass *super);
MRB_API struct RClass *mrb_define_class_id(mrb_state *mrb, mrb_sym name, struct RClass *super);
/**
* Defines a new module.
@@ -317,7 +331,10 @@ MRB_API struct RClass *mrb_define_class(mrb_state *mrb, const char *name, struct
* @return [struct RClass *] Reference to the newly defined module.
*/
MRB_API struct RClass *mrb_define_module(mrb_state *mrb, const char *name);
MRB_API struct RClass *mrb_define_module_id(mrb_state *mrb, mrb_sym 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.
@@ -370,6 +387,7 @@ MRB_API void mrb_prepend_module(mrb_state *mrb, struct RClass *cla, struct RClas
* @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);
MRB_API void mrb_define_method_id(mrb_state *mrb, struct RClass *c, mrb_sym mid, mrb_func_t func, mrb_aspec aspec);
/**
* Defines a class method.
@@ -397,6 +415,7 @@ MRB_API void mrb_define_method(mrb_state *mrb, struct RClass *cla, const char *n
* @param aspec The method parameters declaration.
*/
MRB_API void mrb_define_class_method(mrb_state *mrb, struct RClass *cla, const char *name, mrb_func_t fun, mrb_aspec aspec);
MRB_API void mrb_define_class_method_id(mrb_state *mrb, struct RClass *cla, mrb_sym name, mrb_func_t fun, mrb_aspec aspec);
/**
* Defines a singleton method
@@ -404,6 +423,7 @@ MRB_API void mrb_define_class_method(mrb_state *mrb, struct RClass *cla, const c
* @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);
MRB_API void mrb_define_singleton_method_id(mrb_state *mrb, struct RObject *cla, mrb_sym name, mrb_func_t fun, mrb_aspec aspec);
/**
* Defines a module function.
@@ -431,6 +451,7 @@ MRB_API void mrb_define_singleton_method(mrb_state *mrb, struct RObject *cla, co
* @param aspec The method parameters declaration.
*/
MRB_API void mrb_define_module_function(mrb_state *mrb, struct RClass *cla, const char *name, mrb_func_t fun, mrb_aspec aspec);
MRB_API void mrb_define_module_function_id(mrb_state *mrb, struct RClass *cla, mrb_sym name, mrb_func_t fun, mrb_aspec aspec);
/**
* Defines a constant.
@@ -459,6 +480,7 @@ MRB_API void mrb_define_module_function(mrb_state *mrb, struct RClass *cla, cons
* @param val The value for the constant.
*/
MRB_API void mrb_define_const(mrb_state* mrb, struct RClass* cla, const char *name, mrb_value val);
MRB_API void mrb_define_const_id(mrb_state* mrb, struct RClass* cla, mrb_sym name, mrb_value val);
/**
* Undefines a method.
@@ -549,6 +571,7 @@ MRB_API void mrb_undef_method_id(mrb_state*, struct RClass*, mrb_sym);
* @param name The name of the class method to be undefined.
*/
MRB_API void mrb_undef_class_method(mrb_state *mrb, struct RClass *cls, const char *name);
MRB_API void mrb_undef_class_method_id(mrb_state *mrb, struct RClass *cls, mrb_sym name);
/**
* Initialize a new object instance of c class.
@@ -650,6 +673,7 @@ MRB_API struct RClass * mrb_module_new(mrb_state *mrb);
* @return [mrb_bool] A boolean value.
*/
MRB_API mrb_bool mrb_class_defined(mrb_state *mrb, const char *name);
MRB_API mrb_bool mrb_class_defined_id(mrb_state *mrb, mrb_sym name);
/**
* Gets a class.
@@ -657,7 +681,8 @@ MRB_API mrb_bool mrb_class_defined(mrb_state *mrb, const char *name);
* @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);
MRB_API struct RClass* mrb_class_get(mrb_state *mrb, const char *name);
MRB_API struct RClass* mrb_class_get_id(mrb_state *mrb, mrb_sym name);
/**
* Gets a exception class.
@@ -665,7 +690,8 @@ MRB_API struct RClass * mrb_class_get(mrb_state *mrb, const char *name);
* @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);
MRB_API struct RClass* mrb_exc_get_id(mrb_state *mrb, mrb_sym name);
#define mrb_exc_get(mrb, name) mrb_exc_get_id(mrb, mrb_intern_cstr(mrb, name))
/**
* Returns an mrb_bool. True if inner class was defined, and false if the inner class was not defined.
@@ -697,6 +723,7 @@ MRB_API struct RClass * mrb_exc_get(mrb_state *mrb, const char *name);
* @return [mrb_bool] A boolean value.
*/
MRB_API mrb_bool mrb_class_defined_under(mrb_state *mrb, struct RClass *outer, const char *name);
MRB_API mrb_bool mrb_class_defined_under_id(mrb_state *mrb, struct RClass *outer, mrb_sym name);
/**
* Gets a child class.
@@ -706,6 +733,7 @@ MRB_API mrb_bool mrb_class_defined_under(mrb_state *mrb, struct RClass *outer, c
* @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);
MRB_API struct RClass * mrb_class_get_under_id(mrb_state *mrb, struct RClass *outer, mrb_sym name);
/**
* Gets a module.
@@ -714,6 +742,7 @@ MRB_API struct RClass * mrb_class_get_under(mrb_state *mrb, struct RClass *outer
* @return [struct RClass *] A reference to the module.
*/
MRB_API struct RClass * mrb_module_get(mrb_state *mrb, const char *name);
MRB_API struct RClass * mrb_module_get_id(mrb_state *mrb, mrb_sym name);
/**
* Gets a module defined under another module.
@@ -723,6 +752,8 @@ MRB_API struct RClass * mrb_module_get(mrb_state *mrb, const char *name);
* @return [struct RClass *] A reference to the module.
*/
MRB_API struct RClass * mrb_module_get_under(mrb_state *mrb, struct RClass *outer, const char *name);
MRB_API struct RClass * mrb_module_get_under_id(mrb_state *mrb, struct RClass *outer, mrb_sym name);
/* a function to raise NotImplementedError with current method name */
MRB_API void mrb_notimplement(mrb_state*);
/* a function to be replacement of unimplemented method */
@@ -791,9 +822,11 @@ MRB_API mrb_bool mrb_obj_respond_to(mrb_state *mrb, struct RClass* c, mrb_sym mi
* @return [struct RClass *] Reference to the newly defined class
* @see mrb_define_class
*/
MRB_API struct RClass * mrb_define_class_under(mrb_state *mrb, struct RClass *outer, const char *name, struct RClass *super);
MRB_API struct RClass* mrb_define_class_under(mrb_state *mrb, struct RClass *outer, const char *name, struct RClass *super);
MRB_API struct RClass* mrb_define_class_under_id(mrb_state *mrb, struct RClass *outer, mrb_sym name, struct RClass *super);
MRB_API struct RClass * mrb_define_module_under(mrb_state *mrb, struct RClass *outer, const char *name);
MRB_API struct RClass* mrb_define_module_under(mrb_state *mrb, struct RClass *outer, const char *name);
MRB_API struct RClass* mrb_define_module_under_id(mrb_state *mrb, struct RClass *outer, mrb_sym name);
/**
* Function requires n arguments.
@@ -857,17 +890,17 @@ 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` |
* | `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` | {Fixnum}/{Float} | {mrb_float} | |
* | `i` | {Fixnum}/{Float} | {mrb_int} | |
* | `s` | {String} | const char *, {mrb_int} | Receive two arguments; `s!` gives (`NULL`,`0`) for `nil` |
* | `z` | {String} | const char * | `NULL` terminated string; `z!` gives `NULL` for `nil` |
* | `a` | {Array} | const {mrb_value} *, {mrb_int} | Receive two arguments; `a!` gives (`NULL`,`0`) for `nil` |
* | `f` | {Integer}/{Float} | {mrb_float} | |
* | `i` | {Integer}/{Float} | {mrb_int} | |
* | `b` | boolean | {mrb_bool} | |
* | `n` | {String}/{Symbol} | {mrb_sym} | |
* | `d` | data | void *, {mrb_data_type} const | 2nd argument will be used to check data type so it won't be modified; when `!` follows, the value may be `nil` |
* | `I` | inline struct | void * | |
* | `&` | 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. |
* | `*` | rest arguments | const {mrb_value} *, {mrb_int} | Receive the rest of arguments as an array; `*!` avoid copy of the stack. |
* | <code>\|</code> | optional | | After this spec following specs would be optional. |
* | `?` | 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 |
@@ -899,7 +932,7 @@ typedef const char *mrb_args_format;
* 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 };
* const mrb_kwargs kwargs = { kw_num, kw_required, kw_names, kw_values, NULL };
*
* mrb_get_args(mrb, ":", &kwargs);
* if (mrb_undef_p(kw_values[0])) { kw_values[0] = mrb_fixnum_value(1); }
@@ -910,10 +943,10 @@ typedef const char *mrb_args_format;
*
* mrb_value str, kw_rest;
* uint32_t kw_num = 3;
* const char *kw_names[kw_num] = { "x", "y", "z" };
* const mrb_sym kw_names[kw_num] = { MRB_SYM(x), MRB_SYM(y), MRB_SYM(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 };
* const mrb_kwargs kwargs = { kw_num, kw_required, kw_names, kw_values, &kw_rest };
*
* mrb_get_args(mrb, "S:", &str, &kwargs);
* // or: mrb_get_args(mrb, ":S", &kwargs, &str);
@@ -924,11 +957,11 @@ 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;
uint32_t num; /* number of keyword arguments */
uint32_t required; /* number of required keyword arguments */
const mrb_sym *table; /* C array of symbols for keyword names */
mrb_value *values; /* keyword argument values */
mrb_value *rest; /* keyword rest (dict) */
};
/**
@@ -956,7 +989,20 @@ mrb_get_mid(mrb_state *mrb) /* get method symbol */
*/
MRB_API mrb_int mrb_get_argc(mrb_state *mrb);
MRB_API mrb_value* mrb_get_argv(mrb_state *mrb);
/**
* Retrieve an array of arguments from mrb_state.
*
* Correctly handles *splat arguments.
*/
MRB_API const 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.
@@ -985,6 +1031,7 @@ MRB_API mrb_value* mrb_get_argv(mrb_state *mrb);
* FILE *fp = fopen("test.rb","r");
* mrb_value obj = mrb_load_file(mrb,fp);
* mrb_funcall(mrb, obj, "method_name", 1, mrb_fixnum_value(i));
* mrb_funcall_id(mrb, obj, MRB_SYM(method_name), 1, mrb_fixnum_value(i));
* fclose(fp);
* mrb_close(mrb);
* }
@@ -997,6 +1044,7 @@ MRB_API mrb_value* mrb_get_argv(mrb_state *mrb);
* @return [mrb_value] mruby function value.
*/
MRB_API mrb_value mrb_funcall(mrb_state *mrb, mrb_value val, const char *name, mrb_int argc, ...);
MRB_API mrb_value mrb_funcall_id(mrb_state *mrb, mrb_value val, mrb_sym mid, mrb_int argc, ...);
/**
* Call existing ruby functions. This is basically the type safe version of mrb_funcall.
*
@@ -1006,15 +1054,14 @@ MRB_API mrb_value mrb_funcall(mrb_state *mrb, mrb_value val, const char *name, m
* int
* main()
* {
* mrb_int i = 99;
* mrb_state *mrb = mrb_open();
* mrb_value obj = mrb_fixnum_value(1);
*
* if (!mrb) { }
* mrb_sym m_sym = mrb_intern_lit(mrb, "method_name"); // Symbol for method.
*
* FILE *fp = fopen("test.rb","r");
* mrb_value obj = mrb_load_file(mrb,fp);
* mrb_funcall_argv(mrb, obj, m_sym, 1, &obj); // Calling ruby function from test.rb.
* mrb_funcall_argv(mrb, obj, MRB_SYM(method_name), 1, &obj); // Calling ruby function from test.rb.
* fclose(fp);
* mrb_close(mrb);
* }
@@ -1032,7 +1079,8 @@ MRB_API mrb_value mrb_funcall_argv(mrb_state *mrb, mrb_value val, mrb_sym name,
*/
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
* Create a symbol from C string. But usually it's better to use MRB_SYM,
* MRB_OPSYM, MRB_CVSYM, MRB_IVSYM, MRB_SYM_B, MRB_SYM_Q, MRB_SYM_E macros.
*
* Example:
*
@@ -1040,7 +1088,9 @@ MRB_API mrb_value mrb_funcall_with_block(mrb_state *mrb, mrb_value val, mrb_sym
* :pizza # => :pizza
*
* // C style:
* mrb_sym m_sym = mrb_intern_lit(mrb, "pizza"); // => :pizza
* mrb_sym sym1 = mrb_intern_lit(mrb, "pizza"); // => :pizza
* mrb_sym sym2 = MRB_SYM(pizza); // => :pizza
* mrb_sym sym3 = MRB_SYM_Q(pizza); // => :pizza?
*
* @param mrb The current mruby state.
* @param str The string to be symbolized
@@ -1049,8 +1099,14 @@ MRB_API mrb_value mrb_funcall_with_block(mrb_state *mrb, mrb_value val, mrb_sym
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))
#define mrb_intern_lit(mrb, lit) mrb_intern_static(mrb, (lit ""), mrb_strlen_lit(lit))
MRB_API mrb_sym mrb_intern_str(mrb_state*,mrb_value);
/* mrb_intern_check series functions returns 0 if the symbol is not defined */
MRB_API mrb_sym mrb_intern_check_cstr(mrb_state*,const char*);
MRB_API mrb_sym mrb_intern_check(mrb_state*,const char*,size_t);
MRB_API mrb_sym mrb_intern_check_str(mrb_state*,mrb_value);
/* mrb_check_intern series functions returns nil if the symbol is not defined */
/* otherwise returns 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);
@@ -1148,10 +1204,9 @@ 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);
MRB_API mrb_value mrb_run(mrb_state *mrb, struct RProc* proc, mrb_value self);
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);
MRB_API mrb_value mrb_top_run(mrb_state *mrb, const struct RProc *proc, mrb_value self, mrb_int stack_keep);
MRB_API mrb_value mrb_vm_run(mrb_state *mrb, const struct RProc *proc, mrb_value self, mrb_int stack_keep);
MRB_API mrb_value mrb_vm_exec(mrb_state *mrb, const 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)
@@ -1166,7 +1221,7 @@ MRB_API mrb_bool mrb_obj_equal(mrb_state *mrb, mrb_value a, mrb_value b);
MRB_API mrb_bool mrb_equal(mrb_state *mrb, mrb_value obj1, mrb_value obj2);
MRB_API mrb_value mrb_convert_to_integer(mrb_state *mrb, mrb_value val, mrb_int base);
MRB_API mrb_value mrb_Integer(mrb_state *mrb, mrb_value val);
#ifndef MRB_WITHOUT_FLOAT
#ifndef MRB_NO_FLOAT
MRB_API mrb_value mrb_Float(mrb_state *mrb, mrb_value val);
#endif
MRB_API mrb_value mrb_inspect(mrb_state *mrb, mrb_value obj);
@@ -1199,12 +1254,15 @@ MRB_API void mrb_field_write_barrier(mrb_state *, struct RBasic*, struct RBasic*
} while (0)
MRB_API void mrb_write_barrier(mrb_state *, struct RBasic*);
MRB_API mrb_value mrb_check_convert_type(mrb_state *mrb, mrb_value val, enum mrb_vtype type, const char *tname, const char *method);
MRB_API mrb_value mrb_type_convert(mrb_state *mrb, mrb_value val, enum mrb_vtype type, mrb_sym method);
#define mrb_convert_type(mrb, val, type, tname, method) mrb_type_convert(mrb, val, type, mrb_intern_lit(mrb, method))
MRB_API mrb_value mrb_type_convert_check(mrb_state *mrb, mrb_value val, enum mrb_vtype type, mrb_sym method);
#define mrb_check_convert_type(mrb, val, type, tname, method) mrb_type_convert_check(mrb, val, type, mrb_intern_lit(mrb, method))
MRB_API mrb_value mrb_any_to_s(mrb_state *mrb, mrb_value obj);
MRB_API const char * mrb_obj_classname(mrb_state *mrb, mrb_value obj);
MRB_API struct RClass* mrb_obj_class(mrb_state *mrb, mrb_value obj);
MRB_API mrb_value mrb_class_path(mrb_state *mrb, struct RClass *c);
MRB_API mrb_value mrb_convert_type(mrb_state *mrb, mrb_value val, enum mrb_vtype type, const char *tname, const char *method);
MRB_API mrb_bool mrb_obj_is_kind_of(mrb_state *mrb, mrb_value obj, struct RClass *c);
MRB_API mrb_value mrb_obj_inspect(mrb_state *mrb, mrb_value self);
MRB_API mrb_value mrb_obj_clone(mrb_state *mrb, mrb_value self);
@@ -1245,26 +1303,26 @@ MRB_API mrb_value mrb_vformat(mrb_state *mrb, const char *format, va_list ap);
+ those E_* macros requires mrb_state* variable named mrb.
+ exception objects obtained from those macros are local to mrb
*/
#define E_RUNTIME_ERROR (mrb_exc_get(mrb, "RuntimeError"))
#define E_TYPE_ERROR (mrb_exc_get(mrb, "TypeError"))
#define E_ARGUMENT_ERROR (mrb_exc_get(mrb, "ArgumentError"))
#define E_INDEX_ERROR (mrb_exc_get(mrb, "IndexError"))
#define E_RANGE_ERROR (mrb_exc_get(mrb, "RangeError"))
#define E_NAME_ERROR (mrb_exc_get(mrb, "NameError"))
#define E_NOMETHOD_ERROR (mrb_exc_get(mrb, "NoMethodError"))
#define E_SCRIPT_ERROR (mrb_exc_get(mrb, "ScriptError"))
#define E_SYNTAX_ERROR (mrb_exc_get(mrb, "SyntaxError"))
#define E_LOCALJUMP_ERROR (mrb_exc_get(mrb, "LocalJumpError"))
#define E_REGEXP_ERROR (mrb_exc_get(mrb, "RegexpError"))
#define E_FROZEN_ERROR (mrb_exc_get(mrb, "FrozenError"))
#define E_NOTIMP_ERROR (mrb_exc_get(mrb, "NotImplementedError"))
#ifndef MRB_WITHOUT_FLOAT
#define E_FLOATDOMAIN_ERROR (mrb_exc_get(mrb, "FloatDomainError"))
#define MRB_ERROR_SYM(sym) mrb_intern_lit(mrb, #sym)
#define E_RUNTIME_ERROR mrb_exc_get_id(mrb, MRB_ERROR_SYM(RuntimeError))
#define E_TYPE_ERROR mrb_exc_get_id(mrb, MRB_ERROR_SYM(TypeError))
#define E_ZERODIV_ERROR mrb_exc_get_id(mrb, MRB_ERROR_SYM(ZeroDivisionError))
#define E_ARGUMENT_ERROR mrb_exc_get_id(mrb, MRB_ERROR_SYM(ArgumentError))
#define E_INDEX_ERROR mrb_exc_get_id(mrb, MRB_ERROR_SYM(IndexError))
#define E_RANGE_ERROR mrb_exc_get_id(mrb, MRB_ERROR_SYM(RangeError))
#define E_NAME_ERROR mrb_exc_get_id(mrb, MRB_ERROR_SYM(NameError))
#define E_NOMETHOD_ERROR mrb_exc_get_id(mrb, MRB_ERROR_SYM(NoMethodError))
#define E_SCRIPT_ERROR mrb_exc_get_id(mrb, MRB_ERROR_SYM(ScriptError))
#define E_SYNTAX_ERROR mrb_exc_get_id(mrb, MRB_ERROR_SYM(SyntaxError))
#define E_LOCALJUMP_ERROR mrb_exc_get_id(mrb, MRB_ERROR_SYM(LocalJumpError))
#define E_REGEXP_ERROR mrb_exc_get_id(mrb, MRB_ERROR_SYM(RegexpError))
#define E_FROZEN_ERROR mrb_exc_get_id(mrb, MRB_ERROR_SYM(FrozenError))
#define E_NOTIMP_ERROR mrb_exc_get_id(mrb, MRB_ERROR_SYM(NotImplementedError))
#define E_KEY_ERROR mrb_exc_get_id(mrb, MRB_ERROR_SYM(KeyError))
#ifndef MRB_NO_FLOAT
# define E_FLOATDOMAIN_ERROR mrb_exc_get_id(mrb, MRB_ERROR_SYM(FloatDomainError))
#endif
#define E_KEY_ERROR (mrb_exc_get(mrb, "KeyError"))
MRB_API mrb_value mrb_yield(mrb_state *mrb, mrb_value b, mrb_value arg);
MRB_API mrb_value mrb_yield_argv(mrb_state *mrb, mrb_value b, mrb_int argc, const mrb_value *argv);
MRB_API mrb_value mrb_yield_with_class(mrb_state *mrb, mrb_value b, mrb_int argc, const mrb_value *argv, mrb_value self, struct RClass *c);
@@ -1282,7 +1340,7 @@ MRB_API void mrb_gc_register(mrb_state *mrb, mrb_value obj);
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))
#define mrb_int(mrb, val) mrb_integer(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);
@@ -1292,14 +1350,8 @@ 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,
CALL_VCALL,
CALL_TYPE_MAX
} call_type;
MRB_API void mrb_define_alias(mrb_state *mrb, struct RClass *c, const char *a, const char *b);
MRB_API void mrb_define_alias_id(mrb_state *mrb, struct RClass *c, mrb_sym a, mrb_sym b);
MRB_API const char *mrb_class_name(mrb_state *mrb, struct RClass* klass);
MRB_API void mrb_define_global_const(mrb_state *mrb, const char *name, mrb_value val);
@@ -1336,7 +1388,7 @@ MRB_API mrb_value mrb_fiber_alive_p(mrb_state *mrb, mrb_value fib);
*
* Implemented in mruby-fiber
*/
#define E_FIBER_ERROR (mrb_exc_get(mrb, "FiberError"))
#define E_FIBER_ERROR mrb_exc_get_id(mrb, MRB_ERROR_SYM(FiberError))
MRB_API void mrb_stack_extend(mrb_state*, mrb_int);
/* memory pool implementation */
@@ -1356,6 +1408,10 @@ MRB_API void mrb_show_copyright(mrb_state *mrb);
MRB_API mrb_value mrb_format(mrb_state *mrb, const char *format, ...);
#ifdef MRB_PRESYM_SCANNING
# include <mruby/presym/scanning.h>
#endif
#if 0
/* memcpy and memset does not work with gdb reverse-next on my box */
/* use naive memcpy and memset instead */
+27 -6
View File
@@ -21,7 +21,14 @@ typedef struct mrb_shared_array {
mrb_value *ptr;
} mrb_shared_array;
#define MRB_ARY_EMBED_LEN_MAX ((mrb_int)(sizeof(void*)*3/sizeof(mrb_value)))
#if defined(MRB_32BIT) && defined(MRB_NO_BOXING)
# define MRB_ARY_NO_EMBED
# define MRB_ARY_EMBED_LEN_MAX 0
#else
# define MRB_ARY_EMBED_LEN_MAX ((mrb_int)(sizeof(void*)*3/sizeof(mrb_value)))
mrb_static_assert(MRB_ARY_EMBED_LEN_MAX > 0, "MRB_ARY_EMBED_LEN_MAX > 0");
#endif
struct RArray {
MRB_OBJECT_HEADER;
union {
@@ -33,7 +40,9 @@ struct RArray {
} aux;
mrb_value *ptr;
} heap;
void *ary[3];
#ifndef MRB_ARY_NO_EMBED
mrb_value ary[MRB_ARY_EMBED_LEN_MAX];
#endif
} as;
};
@@ -41,12 +50,20 @@ struct RArray {
#define mrb_ary_value(p) mrb_obj_value((void*)(p))
#define RARRAY(v) ((struct RArray*)(mrb_ptr(v)))
#ifdef MRB_ARY_NO_EMBED
#define ARY_EMBED_P(a) 0
#define ARY_UNSET_EMBED_FLAG(a) (void)0
#define ARY_EMBED_LEN(a) 0
#define ARY_SET_EMBED_LEN(a,len) (void)0
#define ARY_EMBED_PTR(a) 0
#else
#define MRB_ARY_EMBED_MASK 7
#define ARY_EMBED_P(a) ((a)->flags & MRB_ARY_EMBED_MASK)
#define ARY_UNSET_EMBED_FLAG(a) ((a)->flags &= ~(MRB_ARY_EMBED_MASK))
#define ARY_EMBED_LEN(a) ((mrb_int)(((a)->flags & MRB_ARY_EMBED_MASK) - 1))
#define ARY_SET_EMBED_LEN(a,len) ((a)->flags = ((a)->flags&~MRB_ARY_EMBED_MASK) | ((uint32_t)(len) + 1))
#define ARY_EMBED_PTR(a) ((mrb_value*)(&(a)->as.ary))
#define ARY_EMBED_PTR(a) ((a)->as.ary)
#endif
#define ARY_LEN(a) (ARY_EMBED_P(a)?ARY_EMBED_LEN(a):(a)->as.heap.len)
#define ARY_PTR(a) (ARY_EMBED_P(a)?ARY_EMBED_PTR(a):(a)->as.heap.ptr)
@@ -232,13 +249,14 @@ MRB_API mrb_value mrb_ary_entry(mrb_value ary, mrb_int offset);
*
* Equivalent to:
*
* ary.shift
* ary[head, len] = rpl
*
* @param mrb The mruby state reference.
* @param self The array from which the value will be shifted.
* @param self The array from which the value will be partiality replaced.
* @param head Beginning position of a replacement subsequence.
* @param len Length of a replacement subsequence.
* @param rpl The array of replacement elements.
* It is possible to pass `mrb_undef_value()` instead of an empty array.
* @return The receiver array.
*/
MRB_API mrb_value mrb_ary_splice(mrb_state *mrb, mrb_value self, mrb_int head, mrb_int len, mrb_value rpl);
@@ -278,7 +296,7 @@ MRB_API mrb_value mrb_ary_clear(mrb_state *mrb, mrb_value self);
*
* @param mrb The mruby state reference.
* @param ary The target array
* @param sep The separater, can be NULL
* @param sep The separator, can be NULL
*/
MRB_API mrb_value mrb_ary_join(mrb_state *mrb, mrb_value ary, mrb_value sep);
@@ -291,6 +309,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 */
+79 -45
View File
@@ -7,12 +7,12 @@
#ifndef MRUBY_BOXING_NAN_H
#define MRUBY_BOXING_NAN_H
#ifdef MRB_USE_FLOAT
# error ---->> MRB_NAN_BOXING and MRB_USE_FLOAT conflict <<----
#ifdef MRB_USE_FLOAT32
# error ---->> MRB_NAN_BOXING and MRB_USE_FLOAT32 conflict <<----
#endif
#ifdef MRB_WITHOUT_FLOAT
# error ---->> MRB_NAN_BOXING and MRB_WITHOUT_FLOAT conflict <<----
#ifdef MRB_NO_FLOAT
# error ---->> MRB_NAN_BOXING and MRB_NO_FLOAT conflict <<----
#endif
#ifdef MRB_INT64
@@ -21,6 +21,8 @@
#define MRB_FIXNUM_SHIFT 0
#define MRB_SYMBOL_SHIFT 0
#define MRB_FIXNUM_MIN INT32_MIN
#define MRB_FIXNUM_MAX INT32_MAX
/* value representation by nan-boxing:
* float : FFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFF
@@ -31,66 +33,98 @@
* in the right direction. Also, TTTTTT is the mrb_vtype + 1;
*/
typedef struct mrb_value {
union {
mrb_float f;
union {
void *p;
struct {
MRB_ENDIAN_LOHI(
uint32_t ttt;
,union {
mrb_int i;
mrb_sym sym;
};
)
};
} value;
};
uint64_t u;
} mrb_value;
#define mrb_float_pool(mrb,f) mrb_float_value(mrb,f)
union mrb_value_ {
mrb_float f;
uint64_t u;
#ifdef MRB_64BIT
void *p;
# define BOXNAN_IMMEDIATE_VALUE uint32_t i
#else
# define BOXNAN_IMMEDIATE_VALUE union { uint32_t i; void *p; }
#endif
struct {
MRB_ENDIAN_LOHI(
uint32_t ttt;
,BOXNAN_IMMEDIATE_VALUE;
)
};
mrb_value value;
};
#define mrb_tt(o) ((enum mrb_vtype)(((o).value.ttt & 0xfc000)>>14)-1)
#define mrb_type(o) (enum mrb_vtype)((uint32_t)0xfff00000 < (o).value.ttt ? mrb_tt(o) : MRB_TT_FLOAT)
#define mrb_ptr(o) ((void*)((((uintptr_t)0x3fffffffffff)&((uintptr_t)((o).value.p)))<<2))
#define mrb_float(o) (o).f
#define mrb_cptr(o) mrb_ptr(o)
#define mrb_fixnum(o) (o).value.i
#define mrb_symbol(o) (o).value.sym
mrb_static_assert1(sizeof(mrb_value) == sizeof(union mrb_value_));
static inline union mrb_value_
mrb_val_union(mrb_value v)
{
union mrb_value_ x;
x.value = v;
return x;
}
#define mrb_tt(o) ((enum mrb_vtype)((mrb_val_union(o).ttt & 0xfc000)>>14)-1)
#define mrb_type(o) (enum mrb_vtype)((uint32_t)0xfff00000 < mrb_val_union(o).ttt ? mrb_tt(o) : MRB_TT_FLOAT)
#define mrb_float(o) mrb_val_union(o).f
#define mrb_fixnum(o) ((mrb_int)mrb_val_union(o).i)
#define mrb_integer(o) mrb_fixnum(o)
#define mrb_symbol(o) ((mrb_sym)mrb_val_union(o).i)
#ifdef MRB_64BIT
#define mrb_ptr(o) ((void*)((((uintptr_t)0x3fffffffffff)&((uintptr_t)(mrb_val_union(o).p)))<<2))
#define mrb_cptr(o) (((struct RCptr*)mrb_ptr(o))->p)
#define BOXNAN_SHIFT_LONG_POINTER(v) (((uintptr_t)(v)>>34)&0x3fff)
#else
#define mrb_ptr(o) ((void*)mrb_val_union(o).i)
#define mrb_cptr(o) mrb_ptr(o)
#define BOXNAN_SHIFT_LONG_POINTER(v) 0
#endif
#define BOXNAN_SET_VALUE(o, tt, attr, v) do {\
(o).attr = (v);\
(o).value.ttt = 0xfff00000 | (((tt)+1)<<14);\
#define BOXNAN_SET_VALUE(o, tt, attr, v) do { \
union mrb_value_ mrb_value_union_variable; \
mrb_value_union_variable.attr = (v);\
mrb_value_union_variable.ttt = 0xfff00000 | (((tt)+1)<<14);\
o = mrb_value_union_variable.value;\
} while (0)
#ifdef MRB_64BIT
#define BOXNAN_SET_OBJ_VALUE(o, tt, v) do {\
(o).value.p = (void*)((uintptr_t)(v)>>2);\
(o).value.ttt = (0xfff00000|(((tt)+1)<<14)|BOXNAN_SHIFT_LONG_POINTER(v));\
union mrb_value_ mrb_value_union_variable;\
mrb_value_union_variable.p = (void*)((uintptr_t)(v)>>2);\
mrb_value_union_variable.ttt = (0xfff00000|(((tt)+1)<<14)|BOXNAN_SHIFT_LONG_POINTER(v));\
o = mrb_value_union_variable.value;\
} while (0)
#else
#define BOXNAN_SET_OBJ_VALUE(o, tt, v) BOXNAN_SET_VALUE(o, tt, i, (uint32_t)v)
#endif
#define SET_FLOAT_VALUE(mrb,r,v) do { \
if ((v) != (v)) { \
(r).value.ttt = 0x7ff80000; \
(r).value.i = 0; \
union mrb_value_ mrb_value_union_variable; \
if ((v) != (v)) { /* NaN */ \
mrb_value_union_variable.ttt = 0x7ff80000; \
mrb_value_union_variable.i = 0; \
} \
else { \
(r).f = v; \
}} while(0)
mrb_value_union_variable.f = (v); \
} \
r = mrb_value_union_variable.value; \
} while(0)
#define SET_NIL_VALUE(r) BOXNAN_SET_VALUE(r, MRB_TT_FALSE, value.i, 0)
#define SET_FALSE_VALUE(r) BOXNAN_SET_VALUE(r, MRB_TT_FALSE, value.i, 1)
#define SET_TRUE_VALUE(r) BOXNAN_SET_VALUE(r, MRB_TT_TRUE, value.i, 1)
#define SET_BOOL_VALUE(r,b) BOXNAN_SET_VALUE(r, b ? MRB_TT_TRUE : MRB_TT_FALSE, value.i, 1)
#define SET_INT_VALUE(r,n) BOXNAN_SET_VALUE(r, MRB_TT_FIXNUM, value.i, (n))
#define SET_SYM_VALUE(r,v) BOXNAN_SET_VALUE(r, MRB_TT_SYMBOL, value.sym, (v))
#define SET_NIL_VALUE(r) BOXNAN_SET_VALUE(r, MRB_TT_FALSE, i, 0)
#define SET_FALSE_VALUE(r) BOXNAN_SET_VALUE(r, MRB_TT_FALSE, i, 1)
#define SET_TRUE_VALUE(r) BOXNAN_SET_VALUE(r, MRB_TT_TRUE, i, 1)
#define SET_BOOL_VALUE(r,b) BOXNAN_SET_VALUE(r, b ? MRB_TT_TRUE : MRB_TT_FALSE, i, 1)
#define SET_INT_VALUE(mrb, r,n) BOXNAN_SET_VALUE(r, MRB_TT_INTEGER, i, (uint32_t)(n))
#define SET_FIXNUM_VALUE(r,n) BOXNAN_SET_VALUE(r, MRB_TT_INTEGER, i, (uint32_t)(n))
#define SET_SYM_VALUE(r,v) BOXNAN_SET_VALUE(r, MRB_TT_SYMBOL, i, (uint32_t)(v))
#define SET_OBJ_VALUE(r,v) BOXNAN_SET_OBJ_VALUE(r, (((struct RObject*)(v))->tt), (v))
#define SET_CPTR_VALUE(mrb,r,v) BOXNAN_SET_OBJ_VALUE(r, MRB_TT_CPTR, v)
#define SET_UNDEF_VALUE(r) BOXNAN_SET_VALUE(r, MRB_TT_UNDEF, value.i, 0)
#ifdef MRB_64BIT
MRB_API mrb_value mrb_nan_boxing_cptr_value(struct mrb_state*, void*);
#define SET_CPTR_VALUE(mrb,r,v) ((r) = mrb_nan_boxing_cptr_value(mrb, v))
#else
#define SET_CPTR_VALUE(mrb,r,v) BOXNAN_SET_VALUE(r, MRB_TT_CPTR, p, v)
#endif
#define SET_UNDEF_VALUE(r) BOXNAN_SET_VALUE(r, MRB_TT_UNDEF, i, 0)
#endif /* MRUBY_BOXING_NAN_H */
+8 -8
View File
@@ -9,9 +9,11 @@
#define MRB_FIXNUM_SHIFT 0
#define MRB_SYMBOL_SHIFT 0
#define MRB_FIXNUM_MIN MRB_INT_MIN
#define MRB_FIXNUM_MAX MRB_INT_MAX
union mrb_value_union {
#ifndef MRB_WITHOUT_FLOAT
#ifndef MRB_NO_FLOAT
mrb_float f;
#endif
void *p;
@@ -24,16 +26,13 @@ typedef struct mrb_value {
enum mrb_vtype tt;
} mrb_value;
#ifndef MRB_WITHOUT_FLOAT
#define mrb_float_pool(mrb,f) mrb_float_value(mrb,f)
#endif
#define mrb_ptr(o) (o).value.p
#define mrb_cptr(o) mrb_ptr(o)
#ifndef MRB_WITHOUT_FLOAT
#ifndef MRB_NO_FLOAT
#define mrb_float(o) (o).value.f
#endif
#define mrb_fixnum(o) (o).value.i
#define mrb_integer(o) mrb_fixnum(o)
#define mrb_symbol(o) (o).value.sym
#define mrb_type(o) (o).tt
@@ -46,8 +45,9 @@ typedef struct mrb_value {
#define SET_FALSE_VALUE(r) BOXNIX_SET_VALUE(r, MRB_TT_FALSE, value.i, 1)
#define SET_TRUE_VALUE(r) BOXNIX_SET_VALUE(r, MRB_TT_TRUE, value.i, 1)
#define SET_BOOL_VALUE(r,b) BOXNIX_SET_VALUE(r, b ? MRB_TT_TRUE : MRB_TT_FALSE, value.i, 1)
#define SET_INT_VALUE(r,n) BOXNIX_SET_VALUE(r, MRB_TT_FIXNUM, value.i, (n))
#ifndef MRB_WITHOUT_FLOAT
#define SET_INT_VALUE(mrb,r,n) BOXNIX_SET_VALUE(r, MRB_TT_INTEGER, value.i, (n))
#define SET_FIXNUM_VALUE(r,n) BOXNIX_SET_VALUE(r, MRB_TT_INTEGER, value.i, (n))
#ifndef MRB_NO_FLOAT
#define SET_FLOAT_VALUE(mrb,r,v) BOXNIX_SET_VALUE(r, MRB_TT_FLOAT, value.f, (v))
#endif
#define SET_SYM_VALUE(r,v) BOXNIX_SET_VALUE(r, MRB_TT_SYMBOL, value.sym, (v))
+85 -60
View File
@@ -7,20 +7,16 @@
#ifndef MRUBY_BOXING_WORD_H
#define MRUBY_BOXING_WORD_H
#if defined(MRB_INT64) && !defined(MRB_64BIT)
#error MRB_INT64 cannot be used with MRB_WORD_BOXING in 32-bit mode.
#endif
#ifndef MRB_WITHOUT_FLOAT
#ifndef MRB_NO_FLOAT
struct RFloat {
MRB_OBJECT_HEADER;
mrb_float f;
};
#endif
struct RCptr {
struct RInteger {
MRB_OBJECT_HEADER;
void *p;
mrb_int i;
};
enum mrb_special_consts {
@@ -37,6 +33,14 @@ enum mrb_special_consts {
#endif
#define MRB_SYMBOL_SHIFT BOXWORD_SYMBOL_SHIFT
#if defined(MRB_64BIT) && defined(MRB_INT64)
# define MRB_FIXNUM_MIN (INT64_MIN>>MRB_FIXNUM_SHIFT)
# define MRB_FIXNUM_MAX (INT64_MAX>>MRB_FIXNUM_SHIFT)
#else
# define MRB_FIXNUM_MIN (INT32_MIN>>MRB_FIXNUM_SHIFT)
# define MRB_FIXNUM_MAX (INT32_MAX>>MRB_FIXNUM_SHIFT)
#endif
#define BOXWORD_FIXNUM_BIT_POS 1
#define BOXWORD_SYMBOL_BIT_POS 2
#define BOXWORD_FIXNUM_SHIFT BOXWORD_FIXNUM_BIT_POS
@@ -51,14 +55,12 @@ enum mrb_special_consts {
#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)
((o).w = (((uintptr_t)(v)) << BOXWORD_##n##_SHIFT) | BOXWORD_##n##_FLAG)
#define BOXWORD_SHIFT_VALUE_P(o,n) \
(((o).w & BOXWORD_##n##_MASK) == BOXWORD_##n##_FLAG)
#define BOXWORD_OBJ_TYPE_P(o,n) \
(!mrb_immediate_p(o) && (o).value.bp->tt == MRB_TT_##n)
(!mrb_immediate_p(o) && mrb_val_union(o).bp->tt == MRB_TT_##n)
/*
* mrb_value representation:
@@ -71,54 +73,72 @@ enum mrb_special_consts {
* 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 {
MRB_ENDIAN_LOHI(
mrb_sym sym;
,uint32_t sym_flag;
)
};
#endif
struct RBasic *bp;
#ifndef MRB_WITHOUT_FLOAT
struct RFloat *fp;
#endif
struct RCptr *vp;
} value;
unsigned long w;
typedef struct mrb_value {
uintptr_t w;
} mrb_value;
MRB_API mrb_value mrb_word_boxing_cptr_value(struct mrb_state*, void*);
#ifndef MRB_WITHOUT_FLOAT
MRB_API mrb_value mrb_word_boxing_float_value(struct mrb_state*, mrb_float);
MRB_API mrb_value mrb_word_boxing_float_pool(struct mrb_state*, mrb_float);
#endif
#ifndef MRB_WITHOUT_FLOAT
#define mrb_float_pool(mrb,f) mrb_word_boxing_float_pool(mrb,f)
#endif
#define mrb_ptr(o) (o).value.p
#define mrb_cptr(o) (o).value.vp->p
#ifndef MRB_WITHOUT_FLOAT
#define mrb_float(o) (o).value.fp->f
#endif
#define mrb_fixnum(o) BOXWORD_SHIFT_VALUE(o, FIXNUM, mrb_int)
union mrb_value_ {
void *p;
#ifdef MRB_64BIT
#define mrb_symbol(o) (o).value.sym
#else
#define mrb_symbol(o) BOXWORD_SHIFT_VALUE(o, SYMBOL, mrb_sym)
/* use struct to avoid bit shift. */
struct {
MRB_ENDIAN_LOHI(
mrb_sym sym;
,uint32_t sym_flag;
)
};
#endif
#define mrb_bool(o) (((o).w & ~(unsigned long)MRB_Qfalse) != 0)
struct RBasic *bp;
#ifndef MRB_NO_FLOAT
struct RFloat *fp;
#endif
struct RInteger *ip;
struct RCptr *vp;
uintptr_t w;
mrb_value value;
};
mrb_static_assert1(sizeof(mrb_value) == sizeof(union mrb_value_));
static inline union mrb_value_
mrb_val_union(mrb_value v)
{
union mrb_value_ x;
x.value = v;
return x;
}
MRB_API mrb_value mrb_word_boxing_cptr_value(struct mrb_state*, void*);
#ifndef MRB_NO_FLOAT
MRB_API mrb_value mrb_word_boxing_float_value(struct mrb_state*, mrb_float);
#endif
MRB_API mrb_value mrb_word_boxing_int_value(struct mrb_state*, mrb_int);
#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)
#define mrb_ptr(o) mrb_val_union(o).p
#define mrb_cptr(o) mrb_val_union(o).vp->p
#ifndef MRB_NO_FLOAT
#define mrb_float(o) mrb_val_union(o).fp->f
#endif
#define mrb_fixnum(o) (mrb_int)(((intptr_t)(o).w) >> BOXWORD_FIXNUM_SHIFT)
MRB_INLINE mrb_int
mrb_integer_func(mrb_value o) {
if (mrb_immediate_p(o)) return mrb_fixnum(o);
return mrb_val_union(o).ip->i;
}
#define mrb_integer(o) mrb_integer_func(o)
#ifdef MRB_64BIT
#define mrb_symbol_p(o) ((o).value.sym_flag == BOXWORD_SYMBOL_FLAG)
#define mrb_symbol(o) mrb_val_union(o).sym
#else
#define mrb_symbol(o) (mrb_sym)(((o).w) >> BOXWORD_SYMBOL_SHIFT)
#endif
#define mrb_bool(o) (((o).w & ~(uintptr_t)MRB_Qfalse) != 0)
#define mrb_fixnum_p(o) BOXWORD_SHIFT_VALUE_P(o, FIXNUM)
#define mrb_integer_p(o) (BOXWORD_SHIFT_VALUE_P(o, FIXNUM)||BOXWORD_OBJ_TYPE_P(o, INTEGER))
#ifdef MRB_64BIT
#define mrb_symbol_p(o) (mrb_val_union(o).sym_flag == BOXWORD_SYMBOL_FLAG)
#else
#define mrb_symbol_p(o) BOXWORD_SHIFT_VALUE_P(o, SYMBOL)
#endif
@@ -126,7 +146,7 @@ MRB_API mrb_value mrb_word_boxing_float_pool(struct mrb_state*, mrb_float);
#define mrb_nil_p(o) ((o).w == MRB_Qnil)
#define mrb_false_p(o) ((o).w == MRB_Qfalse)
#define mrb_true_p(o) ((o).w == MRB_Qtrue)
#ifndef MRB_WITHOUT_FLOAT
#ifndef MRB_NO_FLOAT
#define mrb_float_p(o) BOXWORD_OBJ_TYPE_P(o, FLOAT)
#endif
#define mrb_array_p(o) BOXWORD_OBJ_TYPE_P(o, ARRAY)
@@ -142,14 +162,13 @@ MRB_API mrb_value mrb_word_boxing_float_pool(struct mrb_state*, mrb_float);
#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_file_p(o) BOXWORD_OBJ_TYPE_P(o, FILE)
#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
#ifndef MRB_NO_FLOAT
#define SET_FLOAT_VALUE(mrb,r,v) ((r) = mrb_word_boxing_float_value(mrb, v))
#endif
#define SET_CPTR_VALUE(mrb,r,v) ((r) = mrb_word_boxing_cptr_value(mrb, v))
@@ -158,23 +177,29 @@ MRB_API mrb_value mrb_word_boxing_float_pool(struct mrb_state*, mrb_float);
#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)
#define SET_INT_VALUE(mrb,r,n) ((r) = mrb_word_boxing_int_value(mrb, n))
#define SET_FIXNUM_VALUE(r,n) BOXWORD_SET_SHIFT_VALUE(r, FIXNUM, n)
#ifdef MRB_64BIT
#define SET_SYM_VALUE(r,v) ((r).value.sym = v, (r).value.sym_flag = BOXWORD_SYMBOL_FLAG)
#define SET_SYM_VALUE(r,v) do {\
union mrb_value_ mrb_value_union_variable;\
mrb_value_union_variable.sym = v;\
mrb_value_union_variable.sym_flag = BOXWORD_SYMBOL_FLAG;\
(r) = mrb_value_union_variable.value;\
} while (0)
#else
#define SET_SYM_VALUE(r,n) BOXWORD_SET_SHIFT_VALUE(r, SYMBOL, n)
#endif
#define SET_OBJ_VALUE(r,v) ((r).value.p = v)
#define SET_OBJ_VALUE(r,v) ((r).w = (uintptr_t)(v))
MRB_INLINE enum mrb_vtype
mrb_type(mrb_value o)
{
return !mrb_bool(o) ? MRB_TT_FALSE :
mrb_true_p(o) ? MRB_TT_TRUE :
mrb_fixnum_p(o) ? MRB_TT_FIXNUM :
mrb_fixnum_p(o) ? MRB_TT_INTEGER :
mrb_symbol_p(o) ? MRB_TT_SYMBOL :
mrb_undef_p(o) ? MRB_TT_UNDEF :
o.value.bp->tt;
mrb_val_union(o).bp->tt;
}
#endif /* MRUBY_BOXING_WORD_H */
+10 -8
View File
@@ -17,7 +17,7 @@ MRB_BEGIN_DECL
struct RClass {
MRB_OBJECT_HEADER;
struct iv_tbl *iv;
struct kh_mt *mt;
struct mt_tbl *mt;
struct RClass *super;
};
@@ -35,9 +35,9 @@ mrb_class(mrb_state *mrb, mrb_value v)
return mrb->true_class;
case MRB_TT_SYMBOL:
return mrb->symbol_class;
case MRB_TT_FIXNUM:
return mrb->fixnum_class;
#ifndef MRB_WITHOUT_FLOAT
case MRB_TT_INTEGER:
return mrb->integer_class;
#ifndef MRB_NO_FLOAT
case MRB_TT_FLOAT:
return mrb->float_class;
#endif
@@ -73,13 +73,11 @@ mrb_class(mrb_state *mrb, mrb_value v)
#define MRB_SET_INSTANCE_TT(c, tt) ((c)->flags = (((c)->flags & ~MRB_INSTANCE_TT_MASK) | (char)(tt)))
#define MRB_INSTANCE_TT(c) (enum mrb_vtype)((c)->flags & MRB_INSTANCE_TT_MASK)
MRB_API struct RClass* mrb_define_class_id(mrb_state*, mrb_sym, struct RClass*);
MRB_API struct RClass* mrb_define_module_id(mrb_state*, mrb_sym);
struct RClass *mrb_vm_define_class(mrb_state*, mrb_value, mrb_value, mrb_sym);
struct RClass *mrb_vm_define_module(mrb_state*, mrb_value, mrb_sym);
MRB_API void mrb_define_method_raw(mrb_state*, struct RClass*, mrb_sym, mrb_method_t);
MRB_API void mrb_define_method_id(mrb_state *mrb, struct RClass *c, mrb_sym mid, mrb_func_t func, mrb_aspec aspec);
MRB_API void mrb_alias_method(mrb_state*, struct RClass *c, mrb_sym a, mrb_sym b);
MRB_API void mrb_remove_method(mrb_state *mrb, struct RClass *c, mrb_sym sym);
MRB_API mrb_method_t mrb_method_search_vm(mrb_state*, struct RClass**, mrb_sym);
MRB_API mrb_method_t mrb_method_search(mrb_state*, struct RClass*, mrb_sym);
@@ -95,12 +93,16 @@ 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
#ifndef MRB_NO_METHOD_CACHE
void mrb_mc_clear_by_class(mrb_state *mrb, struct RClass* c);
#else
#define mrb_mc_clear_by_class(mrb,c)
#endif
/* return non zero to break the loop */
typedef int (mrb_mt_foreach_func)(mrb_state*,mrb_sym,mrb_method_t,void*);
MRB_API void mrb_mt_foreach(mrb_state*, struct RClass*, mrb_mt_foreach_func*, void*);
MRB_END_DECL
#endif /* MRUBY_CLASS_H */
+4 -1
View File
@@ -14,7 +14,7 @@
#endif
#ifdef __cplusplus
#ifdef MRB_ENABLE_CXX_ABI
#ifdef MRB_USE_CXX_ABI
#define MRB_BEGIN_DECL
#define MRB_END_DECL
#else
@@ -82,6 +82,9 @@ MRB_BEGIN_DECL
# elif defined(__MINGW32_MAJOR_VERSION)
# define MRB_MINGW32_VERSION (__MINGW32_MAJOR_VERSION * 1000 + __MINGW32_MINOR_VERSION)
# endif
# if defined(__MINGW32__) && !defined(__MINGW64__)
# define MRB_MINGW32_LEGACY
# endif
#endif
MRB_END_DECL
+20 -6
View File
@@ -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;
const struct RProc *upper;
size_t parser_nerr;
} mrbc_context;
@@ -42,6 +42,7 @@ MRB_API mrbc_context* mrbc_context_new(mrb_state *mrb);
MRB_API void mrbc_context_free(mrb_state *mrb, mrbc_context *cxt);
MRB_API const char *mrbc_filename(mrb_state *mrb, mrbc_context *c, const char *s);
MRB_API void mrbc_partial_hook(mrb_state *mrb, mrbc_context *c, int (*partial_hook)(struct mrb_parser_state*), void*data);
MRB_API void mrbc_cleanup_local_variables(mrb_state *mrb, mrbc_context *c);
/* AST node structure */
typedef struct mrb_ast_node {
@@ -98,6 +99,9 @@ enum mrb_string_type {
/* heredoc structure */
struct mrb_parser_heredoc_info {
mrb_bool allow_indent:1;
mrb_bool remove_indent:1;
size_t indent;
mrb_ast_node *indented;
mrb_bool line_head:1;
enum mrb_string_type type;
const char *term;
@@ -114,7 +118,8 @@ struct mrb_parser_state {
struct mrb_pool *pool;
mrb_ast_node *cells;
const char *s, *send;
#ifndef MRB_DISABLE_STDIO
#ifndef MRB_NO_STDIO
/* If both f and s are non-null, it will be taken preferentially from s until s < send. */
FILE *f;
#endif
mrbc_context *cxt;
@@ -151,8 +156,8 @@ struct mrb_parser_state {
mrb_ast_node *tree;
mrb_bool no_optimize:1;
mrb_bool on_eval:1;
mrb_bool capture_errors:1;
const struct RProc *upper;
struct mrb_parser_message error_buffer[10];
struct mrb_parser_message warn_buffer[10];
@@ -172,7 +177,7 @@ MRB_API void mrb_parser_set_filename(struct mrb_parser_state*, char const*);
MRB_API mrb_sym mrb_parser_get_filename(struct mrb_parser_state*, uint16_t idx);
/* utility functions */
#ifndef MRB_DISABLE_STDIO
#ifndef MRB_NO_STDIO
MRB_API struct mrb_parser_state* mrb_parse_file(mrb_state*,FILE*,mrbc_context*);
#endif
MRB_API struct mrb_parser_state* mrb_parse_string(mrb_state*,const char*,mrbc_context*);
@@ -180,10 +185,19 @@ MRB_API struct mrb_parser_state* mrb_parse_nstring(mrb_state*,const char*,size_t
MRB_API struct RProc* mrb_generate_code(mrb_state*, struct mrb_parser_state*);
MRB_API mrb_value mrb_load_exec(mrb_state *mrb, struct mrb_parser_state *p, mrbc_context *c);
/* program load functions */
#ifndef MRB_DISABLE_STDIO
/** program load functions
* Please note! Currently due to interactions with the GC calling these functions will
* leak one RProc object per function call.
* To prevent this save the current memory arena before calling and restore the arena
* right after, like so
* int ai = mrb_gc_arena_save(mrb);
* mrb_value status = mrb_load_string(mrb, buffer);
* mrb_gc_arena_restore(mrb, ai);
*/
#ifndef MRB_NO_STDIO
MRB_API mrb_value mrb_load_file(mrb_state*,FILE*);
MRB_API mrb_value mrb_load_file_cxt(mrb_state*,FILE*, mrbc_context *cxt);
MRB_API mrb_value mrb_load_detect_file_cxt(mrb_state *mrb, FILE *fp, mrbc_context *c);
#endif
MRB_API mrb_value mrb_load_string(mrb_state *mrb, const char *s);
MRB_API mrb_value mrb_load_nstring(mrb_state *mrb, const char *s, size_t len);
+2 -2
View File
@@ -46,13 +46,13 @@ typedef struct mrb_irep_debug_info {
* get line from irep's debug info and program counter
* @return returns NULL if not found
*/
MRB_API const char *mrb_debug_get_filename(mrb_state *mrb, mrb_irep *irep, ptrdiff_t pc);
MRB_API const char *mrb_debug_get_filename(mrb_state *mrb, const mrb_irep *irep, uint32_t pc);
/*
* get line from irep's debug info and program counter
* @return returns -1 if not found
*/
MRB_API int32_t mrb_debug_get_line(mrb_state *mrb, mrb_irep *irep, ptrdiff_t pc);
MRB_API int32_t mrb_debug_get_line(mrb_state *mrb, const mrb_irep *irep, uint32_t pc);
MRB_API mrb_irep_debug_info *mrb_debug_info_alloc(mrb_state *mrb, mrb_irep *irep);
MRB_API mrb_irep_debug_info_file *mrb_debug_info_append_file(
+17 -51
View File
@@ -17,15 +17,12 @@
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
int mrb_dump_irep_binary(mrb_state*, mrb_irep*, uint8_t, FILE*);
int mrb_dump_irep_cfunc(mrb_state *mrb, mrb_irep*, uint8_t flags, FILE *f, const char *initname);
int mrb_dump_irep(mrb_state *mrb, const mrb_irep *irep, uint8_t flags, uint8_t **bin, size_t *bin_size);
#ifndef MRB_NO_STDIO
int mrb_dump_irep_binary(mrb_state*, const mrb_irep*, uint8_t, FILE*);
int mrb_dump_irep_cfunc(mrb_state *mrb, const mrb_irep*, uint8_t flags, FILE *f, const char *initname);
int mrb_dump_irep_cstruct(mrb_state *mrb, const mrb_irep*, uint8_t flags, FILE *f, const char *initname);
mrb_irep *mrb_read_irep_file(mrb_state*, FILE*);
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*);
@@ -42,22 +39,25 @@ MRB_API mrb_irep *mrb_read_irep_buf(mrb_state*, const void*, size_t);
#define MRB_DUMP_GENERAL_FAILURE (-1)
#define MRB_DUMP_WRITE_FAULT (-2)
#define MRB_DUMP_READ_FAULT (-3)
#define MRB_DUMP_CRC_ERROR (-4)
#define MRB_DUMP_INVALID_FILE_HEADER (-5)
#define MRB_DUMP_INVALID_IREP (-6)
#define MRB_DUMP_INVALID_ARGUMENT (-7)
#define MRB_DUMP_INVALID_FILE_HEADER (-4)
#define MRB_DUMP_INVALID_IREP (-5)
#define MRB_DUMP_INVALID_ARGUMENT (-6)
/* null symbol length */
#define MRB_DUMP_NULL_SYM_LEN 0xFFFF
/* Rite Binary File header */
#define RITE_BINARY_IDENT "RITE"
#define RITE_BINARY_IDENT_LIL "ETIR"
#define RITE_BINARY_FORMAT_VER "0006"
/* Binary Format Version Major:Minor */
/* Major: Incompatible to prior versions */
/* Minor: Upper-compatible to prior versions */
#define RITE_BINARY_MAJOR_VER "02"
#define RITE_BINARY_MINOR_VER "00"
#define RITE_BINARY_FORMAT_VER RITE_BINARY_MAJOR_VER RITE_BINARY_MINOR_VER
#define RITE_COMPILER_NAME "MATZ"
#define RITE_COMPILER_VERSION "0000"
#define RITE_VM_VER "0002"
#define RITE_VM_VER "0300"
#define RITE_BINARY_EOF "END\0"
#define RITE_SECTION_IREP_IDENT "IREP"
@@ -70,8 +70,8 @@ MRB_API mrb_irep *mrb_read_irep_buf(mrb_state*, const void*, size_t);
/* binary header */
struct rite_binary_header {
uint8_t binary_ident[4]; /* Binary Identifier */
uint8_t binary_version[4]; /* Binary Format Version */
uint8_t binary_crc[2]; /* Binary CRC */
uint8_t major_version[2]; /* Binary Format Major Version */
uint8_t minor_version[2]; /* Binary Format Minor Version */
uint8_t binary_size[4]; /* Binary Size */
uint8_t compiler_name[4]; /* Compiler name */
uint8_t compiler_version[4];
@@ -106,17 +106,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)
{
@@ -142,16 +131,6 @@ uint32_to_bin(uint32_t l, uint8_t *bin)
return sizeof(uint32_t);
}
static inline size_t
uint32l_to_bin(uint32_t l, uint8_t *bin)
{
bin[3] = (l >> 24) & 0xff;
bin[2] = (l >> 16) & 0xff;
bin[1] = (l >> 8) & 0xff;
bin[0] = l & 0xff;
return sizeof(uint32_t);
}
static inline uint32_t
bin_to_uint32(const uint8_t *bin)
{
@@ -161,15 +140,6 @@ bin_to_uint32(const uint8_t *bin)
(uint32_t)bin[3];
}
static inline uint32_t
bin_to_uint32l(const uint8_t *bin)
{
return (uint32_t)bin[3] << 24 |
(uint32_t)bin[2] << 16 |
(uint32_t)bin[1] << 8 |
(uint32_t)bin[0];
}
static inline uint16_t
bin_to_uint16(const uint8_t *bin)
{
@@ -185,8 +155,4 @@ bin_to_uint8(const uint8_t *bin)
MRB_END_DECL
/** @internal crc.c */
uint16_t
calc_crc_16_ccitt(const uint8_t *src, size_t nbytes, uint16_t crc);
#endif /* MRUBY_DUMP_H */
+44
View File
@@ -0,0 +1,44 @@
/**
** @file mruby/endian.h - detect endian-ness
**
** See Copyright Notice in mruby.h
*/
#ifndef MRUBY_ENDIAN_H
#define MRUBY_ENDIAN_H
#include <limits.h>
MRB_BEGIN_DECL
#if !defined(BYTE_ORDER) && defined(__BYTE_ORDER__)
# define BYTE_ORDER __BYTE_ORDER__
#endif
#if !defined(BIG_ENDIAN) && defined(__ORDER_BIG_ENDIAN__)
# define BIG_ENDIAN __ORDER_BIG_ENDIAN__
#endif
#if !defined(LITTLE_ENDIAN) && defined(__ORDER_LITTLE_ENDIAN__)
# define LITTLE_ENDIAN __ORDER_LITTLE_ENDIAN__
#endif
#ifdef BYTE_ORDER
# if BYTE_ORDER == BIG_ENDIAN
# define littleendian 0
# elif BYTE_ORDER == LITTLE_ENDIAN
# define littleendian 1
# endif
#endif
#ifndef littleendian
/* can't distinguish endian in compile time */
static inline int
check_little_endian(void)
{
unsigned int n = 1;
return (*(unsigned char *)&n == 1);
}
# define littleendian check_little_endian()
#endif
MRB_END_DECL
#endif /* MRUBY_ENDIAN_H */
+39 -5
View File
@@ -23,7 +23,8 @@ struct RException {
MRB_API void mrb_sys_fail(mrb_state *mrb, const char *mesg);
MRB_API mrb_value mrb_exc_new_str(mrb_state *mrb, struct RClass* c, mrb_value str);
#define mrb_exc_new_str_lit(mrb, c, lit) mrb_exc_new_str(mrb, c, mrb_str_new_lit(mrb, lit))
#define mrb_exc_new_lit(mrb, c, lit) mrb_exc_new_str(mrb, c, mrb_str_new_lit(mrb, lit))
#define mrb_exc_new_str_lit(mrb, c, lit) mrb_exc_new_lit(mrb, c, lit)
MRB_API mrb_value mrb_make_exception(mrb_state *mrb, mrb_int argc, const mrb_value *argv);
MRB_API mrb_value mrb_exc_backtrace(mrb_state *mrb, mrb_value exc);
MRB_API mrb_value mrb_get_backtrace(mrb_state *mrb);
@@ -32,10 +33,10 @@ 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)
#if defined(MRB_64BIT) || defined(MRB_USE_FLOAT32) || defined(MRB_NAN_BOXING) || defined(MRB_WORD_BOXING)
struct RBreak {
MRB_OBJECT_HEADER;
struct RProc *proc;
const struct RProc *proc;
mrb_value val;
};
#define mrb_break_value_get(brk) ((brk)->val)
@@ -43,7 +44,7 @@ struct RBreak {
#else
struct RBreak {
MRB_OBJECT_HEADER;
struct RProc *proc;
const struct RProc *proc;
union mrb_value_union value;
};
#define RBREAK_VALUE_TT_MASK ((1 << 8) - 1)
@@ -62,10 +63,43 @@ mrb_break_value_set(struct RBreak *brk, mrb_value val)
brk->flags &= ~RBREAK_VALUE_TT_MASK;
brk->flags |= val.tt;
}
#endif /* MRB_64BIT || MRB_USE_FLOAT || MRB_NAN_BOXING || MRB_WORD_BOXING */
#endif /* MRB_64BIT || MRB_USE_FLOAT32 || MRB_NAN_BOXING || MRB_WORD_BOXING */
#define mrb_break_proc_get(brk) ((brk)->proc)
#define mrb_break_proc_set(brk, p) ((brk)->proc = p)
#define RBREAK_TAG_FOREACH(f) \
f(RBREAK_TAG_BREAK, 0) \
f(RBREAK_TAG_BREAK_UPPER, 1) \
f(RBREAK_TAG_BREAK_INTARGET, 2) \
f(RBREAK_TAG_RETURN_BLOCK, 3) \
f(RBREAK_TAG_RETURN, 4) \
f(RBREAK_TAG_RETURN_TOPLEVEL, 5) \
f(RBREAK_TAG_JUMP, 6) \
f(RBREAK_TAG_STOP, 7)
#define RBREAK_TAG_DEFINE(tag, i) tag = i,
enum {
RBREAK_TAG_FOREACH(RBREAK_TAG_DEFINE)
};
#undef RBREAK_TAG_DEFINE
#define RBREAK_TAG_BIT 3
#define RBREAK_TAG_BIT_OFF 8
#define RBREAK_TAG_MASK (~(~UINT32_C(0) << RBREAK_TAG_BIT))
static inline uint32_t
mrb_break_tag_get(struct RBreak *brk)
{
return (brk->flags >> RBREAK_TAG_BIT_OFF) & RBREAK_TAG_MASK;
}
static inline void
mrb_break_tag_set(struct RBreak *brk, uint32_t tag)
{
brk->flags &= ~(RBREAK_TAG_MASK << RBREAK_TAG_BIT_OFF);
brk->flags |= (tag & RBREAK_TAG_MASK) << RBREAK_TAG_BIT_OFF;
}
/**
* Protect
*
+1
View File
@@ -21,6 +21,7 @@ struct mrb_state;
#define MRB_EACH_OBJ_BREAK 1
typedef int (mrb_each_object_callback)(struct mrb_state *mrb, struct RBasic *obj, void *data);
void mrb_objspace_each_objects(struct mrb_state *mrb, mrb_each_object_callback *callback, void *data);
size_t mrb_objspace_page_slot_size(void);
MRB_API void mrb_free_context(struct mrb_state *mrb, struct mrb_context *c);
#ifndef MRB_GC_ARENA_SIZE
+32 -12
View File
@@ -14,15 +14,28 @@
*/
MRB_BEGIN_DECL
/* offset of `iv` must be 3 words */
struct RHash {
MRB_OBJECT_HEADER;
#ifdef MRB_64BIT
uint32_t size;
struct iv_tbl *iv;
struct htable *ht;
uint32_t ea_capa;
uint32_t ea_n_used;
#else
struct iv_tbl *iv;
uint32_t size;
#endif
union {
struct hash_entry *ea;
struct hash_table *ht;
};
};
#define mrb_hash_ptr(v) ((struct RHash*)(mrb_ptr(v)))
#define mrb_hash_value(p) mrb_obj_value((void*)(p))
size_t mrb_hash_memsize(mrb_value obj);
MRB_API mrb_value mrb_hash_new_capa(mrb_state *mrb, mrb_int capa);
MRB_API mrb_value mrb_ensure_hash_type(mrb_state *mrb, mrb_value hash);
MRB_API mrb_value mrb_check_hash_type(mrb_state *mrb, mrb_value hash);
@@ -178,8 +191,9 @@ MRB_API mrb_value mrb_hash_clear(mrb_state *mrb, mrb_value hash);
MRB_API mrb_int mrb_hash_size(mrb_state *mrb, mrb_value hash);
/*
* Copies the hash.
*
* Copies the hash. This function does NOT copy the instance variables
* (except for the default value). Use mrb_obj_dup() to copy the instance
* variables as well.
*
* @param mrb The mruby state reference.
* @param hash The target hash.
@@ -197,16 +211,22 @@ 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);
/* RHASH_TBL allocates st_table if not available. */
#define RHASH(obj) ((struct RHash*)(mrb_ptr(obj)))
#define RHASH_TBL(h) (RHASH(h)->ht)
#define RHASH_IFNONE(h) mrb_iv_get(mrb, (h), mrb_intern_lit(mrb, "ifnone"))
#define RHASH_PROCDEFAULT(h) RHASH_IFNONE(h)
#define RHASH(hash) ((struct RHash*)(mrb_ptr(hash)))
#define MRB_HASH_DEFAULT 1
#define MRB_HASH_PROC_DEFAULT 2
#define MRB_RHASH_DEFAULT_P(h) (RHASH(h)->flags & MRB_HASH_DEFAULT)
#define MRB_RHASH_PROCDEFAULT_P(h) (RHASH(h)->flags & MRB_HASH_PROC_DEFAULT)
#define MRB_HASH_IB_BIT_BIT 5
#define MRB_HASH_AR_EA_CAPA_BIT 5
#define MRB_HASH_IB_BIT_SHIFT 0
#define MRB_HASH_AR_EA_CAPA_SHIFT 0
#define MRB_HASH_AR_EA_N_USED_SHIFT MRB_HASH_AR_EA_CAPA_BIT
#define MRB_HASH_SIZE_FLAGS_SHIFT (MRB_HASH_AR_EA_CAPA_BIT * 2)
#define MRB_HASH_IB_BIT_MASK ((1 << MRB_HASH_IB_BIT_BIT) - 1)
#define MRB_HASH_AR_EA_CAPA_MASK ((1 << MRB_HASH_AR_EA_CAPA_BIT) - 1)
#define MRB_HASH_AR_EA_N_USED_MASK (MRB_HASH_AR_EA_CAPA_MASK << MRB_HASH_AR_EA_N_USED_SHIFT)
#define MRB_HASH_DEFAULT (1 << (MRB_HASH_SIZE_FLAGS_SHIFT + 0))
#define MRB_HASH_PROC_DEFAULT (1 << (MRB_HASH_SIZE_FLAGS_SHIFT + 1))
#define MRB_HASH_HT (1 << (MRB_HASH_SIZE_FLAGS_SHIFT + 2))
#define MRB_RHASH_DEFAULT_P(hash) (RHASH(hash)->flags & MRB_HASH_DEFAULT)
#define MRB_RHASH_PROCDEFAULT_P(hash) (RHASH(hash)->flags & MRB_HASH_PROC_DEFAULT)
/* GC functions */
void mrb_gc_mark_hash(mrb_state*, struct RHash*);
+73 -13
View File
@@ -16,39 +16,85 @@
MRB_BEGIN_DECL
enum irep_pool_type {
IREP_TT_STRING,
IREP_TT_FIXNUM,
IREP_TT_FLOAT,
IREP_TT_STR = 0, /* string (need free) */
IREP_TT_SSTR = 2, /* string (static) */
IREP_TT_INT32 = 1, /* 32bit integer */
IREP_TT_INT64 = 3, /* 64bit integer */
IREP_TT_FLOAT = 5, /* float (double/float) */
};
struct mrb_locals {
mrb_sym name;
uint16_t r;
#define IREP_TT_NFLAG 1 /* number (non string) flag */
#define IREP_TT_SFLAG 2 /* static string flag */
typedef struct mrb_pool_value {
uint32_t tt; /* packed type and length (for string) */
union {
const char *str;
int32_t i32;
#if defined(MRB_64BIT) || defined(MRB_INT64)
int64_t i64;
#endif
#ifndef MRB_NO_FLOAT
mrb_float f;
#endif
} u;
} mrb_pool_value;
enum mrb_catch_type {
MRB_CATCH_RESCUE = 0,
MRB_CATCH_ENSURE = 1,
};
struct mrb_irep_catch_handler {
uint8_t type; /* enum mrb_catch_type */
uint8_t begin[4]; /* The starting address to match the hander. Includes this. */
uint8_t end[4]; /* The endpoint address that matches the hander. Not Includes this. */
uint8_t target[4]; /* The address to jump to if a match is made. */
};
/* Program data array struct */
typedef struct mrb_irep {
uint16_t nlocals; /* Number of local variables */
uint16_t nregs; /* Number of register variables */
uint16_t clen; /* Number of catch handlers */
uint8_t flags;
const mrb_code *iseq;
mrb_value *pool;
mrb_sym *syms;
struct mrb_irep **reps;
/*
* A catch handler table is placed after the iseq entity.
* The reason it doesn't add fields to the structure is to keep the mrb_irep structure from bloating.
* The catch handler table can be obtained with `mrb_irep_catch_handler_table(irep)`.
*/
const mrb_pool_value *pool;
const mrb_sym *syms;
const struct mrb_irep * const *reps;
struct mrb_locals *lv;
const mrb_sym *lv;
/* debug info */
struct mrb_irep_debug_info* debug_info;
uint16_t ilen, plen, slen, rlen;
uint32_t refcnt;
uint32_t ilen;
uint16_t plen, slen;
uint16_t rlen;
uint16_t refcnt;
} mrb_irep;
#define MRB_ISEQ_NO_FREE 1
#define MRB_IREP_NO_FREE 2
#define MRB_IREP_STATIC (MRB_ISEQ_NO_FREE | MRB_IREP_NO_FREE)
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*);
@@ -77,11 +123,25 @@ struct mrb_insn_data {
uint8_t insn;
uint16_t a;
uint16_t b;
uint8_t c;
uint16_t c;
};
struct mrb_insn_data mrb_decode_insn(const mrb_code *pc);
static inline const struct mrb_irep_catch_handler *
mrb_irep_catch_handler_table(const struct mrb_irep *irep)
{
if (irep->clen > 0) {
return (const struct mrb_irep_catch_handler*)(irep->iseq + irep->ilen);
}
else {
return (const struct mrb_irep_catch_handler*)NULL;
}
}
#define mrb_irep_catch_handler_pack(n, v) uint32_to_bin(n, v)
#define mrb_irep_catch_handler_unpack(v) bin_to_uint32(v)
MRB_END_DECL
#endif /* MRUBY_IREP_H */
+4 -1
View File
@@ -21,7 +21,10 @@ MRB_BEGIN_DECL
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)))
+19 -9
View File
@@ -61,7 +61,6 @@ static const uint8_t __m_either[] = {0x03, 0x0c, 0x30, 0xc0};
typedef struct kh_##name { \
khint_t n_buckets; \
khint_t size; \
khint_t n_occupied; \
uint8_t *ed_flags; \
khkey_t *keys; \
khval_t *vals; \
@@ -92,19 +91,28 @@ kh_fill_flags(uint8_t *p, uint8_t c, size_t len)
khval_t: value data type
kh_is_map: (0: hash set / 1: hash map)
__hash_func: hash function
__hash_equal: hash comparation function
__hash_equal: hash comparison 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); \
h->size = h->n_occupied = 0; \
uint8_t *p = (uint8_t*)mrb_malloc_simple(mrb, sizeof(uint8_t)*sz/4+len*sz); \
if (!p) { return 1; } \
h->size = 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 +120,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) { \
@@ -130,7 +141,7 @@ kh_fill_flags(uint8_t *p, uint8_t c, size_t len)
(void)mrb; \
if (h && h->ed_flags) { \
kh_fill_flags(h->ed_flags, 0xaa, h->n_buckets/4); \
h->size = h->n_occupied = 0; \
h->size = 0; \
} \
} \
khint_t kh_get_##name(mrb_state *mrb, kh_##name##_t *h, khkey_t key) \
@@ -174,7 +185,7 @@ kh_fill_flags(uint8_t *p, uint8_t c, size_t len)
khint_t kh_put_##name(mrb_state *mrb, kh_##name##_t *h, khkey_t key, int *ret) \
{ \
khint_t k, del_k, step = 0; \
if (h->n_occupied >= khash_upper_bound(h)) { \
if (h->size >= khash_upper_bound(h)) { \
kh_resize_##name(mrb, h, h->n_buckets*2); \
} \
k = __hash_func(mrb,key) & khash_mask(h); \
@@ -204,7 +215,6 @@ kh_fill_flags(uint8_t *p, uint8_t c, size_t len)
h->keys[k] = key; \
h->ed_flags[k/4] &= ~__m_empty[k%4]; \
h->size++; \
h->n_occupied++; \
if (ret) *ret = 1; \
return k; \
} \
+37 -63
View File
@@ -1,5 +1,5 @@
/**
** @file mruby/numeric.h - Numeric, Integer, Float, Fixnum class
** @file mruby/numeric.h - Numeric, Integer, Float class
**
** See Copyright Notice in mruby.h
*/
@@ -12,17 +12,17 @@
/**
* Numeric class and it's sub-classes.
*
* Integer, Float and Fixnum
* Integer and Float
*/
MRB_BEGIN_DECL
#define TYPED_POSFIXABLE(f,t) ((f) <= (t)MRB_INT_MAX)
#define TYPED_NEGFIXABLE(f,t) ((f) >= (t)MRB_INT_MIN)
#define TYPED_POSFIXABLE(f,t) ((f) <= (t)MRB_FIXNUM_MAX)
#define TYPED_NEGFIXABLE(f,t) ((f) >= (t)MRB_FIXNUM_MIN)
#define TYPED_FIXABLE(f,t) (TYPED_POSFIXABLE(f,t) && TYPED_NEGFIXABLE(f,t))
#define POSFIXABLE(f) TYPED_POSFIXABLE(f,mrb_int)
#define NEGFIXABLE(f) TYPED_NEGFIXABLE(f,mrb_int)
#define FIXABLE(f) TYPED_FIXABLE(f,mrb_int)
#ifndef MRB_WITHOUT_FLOAT
#ifndef MRB_NO_FLOAT
#ifdef MRB_INT64
#define FIXABLE_FLOAT(f) ((f)>=-9223372036854775808.0 && (f)<9223372036854775808.0)
#else
@@ -30,15 +30,15 @@ MRB_BEGIN_DECL
#endif
#endif
#ifndef MRB_WITHOUT_FLOAT
#ifndef MRB_NO_FLOAT
MRB_API mrb_value mrb_flo_to_fixnum(mrb_state *mrb, mrb_value val);
#endif
MRB_API mrb_value mrb_fixnum_to_str(mrb_state *mrb, mrb_value x, mrb_int base);
/* ArgumentError if format string doesn't match /%(\.[0-9]+)?[aAeEfFgG]/ */
#ifndef MRB_WITHOUT_FLOAT
#ifndef MRB_NO_FLOAT
MRB_API mrb_value mrb_float_to_str(mrb_state *mrb, mrb_value x, const char *fmt);
MRB_API int mrb_float_to_cstr(mrb_state *mrb, char *buf, size_t len, const char *fmt, mrb_float f);
MRB_API mrb_float mrb_to_flo(mrb_state *mrb, mrb_value x);
MRB_API mrb_value mrb_int_value(mrb_state *mrb, mrb_float f);
#endif
MRB_API mrb_value mrb_num_plus(mrb_state *mrb, mrb_value x, mrb_value y);
@@ -70,103 +70,77 @@ MRB_API mrb_value mrb_num_mul(mrb_state *mrb, mrb_value x, mrb_value y);
#ifdef MRB_HAVE_TYPE_GENERIC_CHECKED_ARITHMETIC_BUILTINS
#ifndef MRB_WORD_BOXING
# define WBCHK(x) 0
#else
# define WBCHK(x) !FIXABLE(x)
#endif
static inline mrb_bool
mrb_int_add_overflow(mrb_int augend, mrb_int addend, mrb_int *sum)
{
return __builtin_add_overflow(augend, addend, sum) || WBCHK(*sum);
return __builtin_add_overflow(augend, addend, sum);
}
static inline mrb_bool
mrb_int_sub_overflow(mrb_int minuend, mrb_int subtrahend, mrb_int *difference)
{
return __builtin_sub_overflow(minuend, subtrahend, difference) || WBCHK(*difference);
return __builtin_sub_overflow(minuend, subtrahend, difference);
}
static inline mrb_bool
mrb_int_mul_overflow(mrb_int multiplier, mrb_int multiplicand, mrb_int *product)
{
return __builtin_mul_overflow(multiplier, multiplicand, product) || WBCHK(*product);
return __builtin_mul_overflow(multiplier, multiplicand, product);
}
#undef WBCHK
#else
#define MRB_UINT_MAKE2(n) uint ## n ## _t
#define MRB_UINT_MAKE(n) MRB_UINT_MAKE2(n)
#define mrb_uint MRB_UINT_MAKE(MRB_INT_BIT)
#define MRB_INT_OVERFLOW_MASK ((mrb_uint)1 << (MRB_INT_BIT - 1 - MRB_FIXNUM_SHIFT))
#define MRB_INT_OVERFLOW_MASK ((mrb_uint)1 << (MRB_INT_BIT - 1))
static inline mrb_bool
mrb_int_add_overflow(mrb_int augend, mrb_int addend, mrb_int *sum)
mrb_int_add_overflow(mrb_int a, mrb_int b, mrb_int *c)
{
mrb_uint x = (mrb_uint)augend;
mrb_uint y = (mrb_uint)addend;
mrb_uint x = (mrb_uint)a;
mrb_uint y = (mrb_uint)b;
mrb_uint z = (mrb_uint)(x + y);
*sum = (mrb_int)z;
*c = (mrb_int)z;
return !!(((x ^ z) & (y ^ z)) & MRB_INT_OVERFLOW_MASK);
}
static inline mrb_bool
mrb_int_sub_overflow(mrb_int minuend, mrb_int subtrahend, mrb_int *difference)
mrb_int_sub_overflow(mrb_int a, mrb_int b, mrb_int *c)
{
mrb_uint x = (mrb_uint)minuend;
mrb_uint y = (mrb_uint)subtrahend;
mrb_uint x = (mrb_uint)a;
mrb_uint y = (mrb_uint)b;
mrb_uint z = (mrb_uint)(x - y);
*difference = (mrb_int)z;
*c = (mrb_int)z;
return !!(((x ^ z) & (~y ^ z)) & MRB_INT_OVERFLOW_MASK);
}
static inline mrb_bool
mrb_int_mul_overflow(mrb_int multiplier, mrb_int multiplicand, mrb_int *product)
mrb_int_mul_overflow(mrb_int a, mrb_int b, mrb_int *c)
{
#if MRB_INT_BIT == 32
int64_t n = (int64_t)multiplier * multiplicand;
*product = (mrb_int)n;
return !FIXABLE(n);
#else
if (multiplier > 0) {
if (multiplicand > 0) {
if (multiplier > MRB_INT_MAX / multiplicand) return TRUE;
}
else {
if (multiplicand < MRB_INT_MAX / multiplier) return TRUE;
}
}
else {
if (multiplicand > 0) {
if (multiplier < MRB_INT_MAX / multiplicand) return TRUE;
}
else {
if (multiplier != 0 && multiplicand < MRB_INT_MAX / multiplier) return TRUE;
}
}
*product = multiplier * multiplicand;
#ifdef MRB_INT32
int64_t n = (int64_t)a * b;
*c = (mrb_int)n;
return n > MRB_INT_MAX || n < MRB_INT_MIN;
#else /* MRB_INT64 */
if (a > 0 && b > 0 && a > MRB_INT_MAX / b) return TRUE;
if (a < 0 && b > 0 && a < MRB_INT_MIN / b) return TRUE;
if (a > 0 && b < 0 && b < MRB_INT_MIN / a) return TRUE;
if (a < 0 && b < 0 && (a <= MRB_INT_MIN || b <= MRB_INT_MIN || -a > MRB_INT_MAX / -b))
return TRUE;
*c = a * b;
return FALSE;
#endif
}
#undef MRB_INT_OVERFLOW_MASK
#undef mrb_uint
#undef MRB_UINT_MAKE
#undef MRB_UINT_MAKE2
#endif
#ifndef MRB_WITHOUT_FLOAT
#ifndef MRB_NO_FLOAT
# include <stdint.h>
# include <float.h>
# define MRB_FLT_RADIX FLT_RADIX
# ifdef MRB_USE_FLOAT
# ifdef MRB_USE_FLOAT32
# define MRB_FLT_MANT_DIG FLT_MANT_DIG
# define MRB_FLT_EPSILON FLT_EPSILON
# define MRB_FLT_DIG FLT_DIG
@@ -177,7 +151,7 @@ mrb_int_mul_overflow(mrb_int multiplier, mrb_int multiplicand, mrb_int *product)
# define MRB_FLT_MAX FLT_MAX
# define MRB_FLT_MAX_10_EXP FLT_MAX_10_EXP
# else /* not MRB_USE_FLOAT */
# else /* not MRB_USE_FLOAT32 */
# define MRB_FLT_MANT_DIG DBL_MANT_DIG
# define MRB_FLT_EPSILON DBL_EPSILON
# define MRB_FLT_DIG DBL_DIG
@@ -187,8 +161,8 @@ mrb_int_mul_overflow(mrb_int multiplier, mrb_int multiplicand, mrb_int *product)
# 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 */
# endif /* MRB_USE_FLOAT32 */
#endif /* MRB_NO_FLOAT */
MRB_END_DECL
+1 -27
View File
@@ -36,34 +36,8 @@ enum mrb_insn {
#define FETCH_BB() do {a=READ_B(); b=READ_B();} while (0)
#define FETCH_BBB() do {a=READ_B(); b=READ_B(); c=READ_B();} while (0)
#define FETCH_BS() do {a=READ_B(); b=READ_S();} while (0)
#define FETCH_BSS() do {a=READ_B(); b=READ_S(); c=READ_S();} while (0)
#define FETCH_S() do {a=READ_S();} while (0)
#define FETCH_W() do {a=READ_W();} while (0)
/* with OP_EXT1 (1st 16bit) */
#define FETCH_Z_1() FETCH_Z()
#define FETCH_B_1() FETCH_S()
#define FETCH_BB_1() do {a=READ_S(); b=READ_B();} while (0)
#define FETCH_BBB_1() do {a=READ_S(); b=READ_B(); c=READ_B();} while (0)
#define FETCH_BS_1() do {a=READ_S(); b=READ_S();} while (0)
#define FETCH_S_1() FETCH_S()
#define FETCH_W_1() FETCH_W()
/* with OP_EXT2 (2nd 16bit) */
#define FETCH_Z_2() FETCH_Z()
#define FETCH_B_2() FETCH_B()
#define FETCH_BB_2() do {a=READ_B(); b=READ_S();} while (0)
#define FETCH_BBB_2() do {a=READ_B(); b=READ_S(); c=READ_B();} while (0)
#define FETCH_BS_2() FETCH_BS()
#define FETCH_S_2() FETCH_S()
#define FETCH_W_2() FETCH_W()
/* with OP_EXT3 (1st & 2nd 16bit) */
#define FETCH_Z_3() FETCH_Z()
#define FETCH_B_3() FETCH_B()
#define FETCH_BB_3() do {a=READ_S(); b=READ_S();} while (0)
#define FETCH_BBB_3() do {a=READ_S(); b=READ_S(); c=READ_B();} while (0)
#define FETCH_BS_3() do {a=READ_S(); b=READ_S();} while (0)
#define FETCH_S_3() FETCH_S()
#define FETCH_W_3() FETCH_W()
#endif /* MRUBY_OPCODE_H */
+29 -24
View File
@@ -1,11 +1,12 @@
/* operand types:
+ Z: no operand (Z,Z,Z,Z)
+ B: 8bit (B,S,B,B)
+ BB: 8+8bit (BB,SB,BS,SS)
+ BBB: 8+8+8bit (BBB,SBB,BSB,SSB)
+ BS: 8+16bit (BS,SS,BS,BS)
+ S: 16bit (S,S,S,S)
+ W: 24bit (W,W,W,W)
+ Z: no operand
+ B: 8bit
+ BB: 8+8bit
+ BBB: 8+8+8bit
+ BS: 8+16bit
+ BSS: 8+16+16bit
+ S: 16bit
+ W: 24bit
*/
/*-----------------------------------------------------------------------
@@ -14,6 +15,7 @@ operation code operands semantics
OPCODE(NOP, Z) /* no operation */
OPCODE(MOVE, BB) /* R(a) = R(b) */
OPCODE(LOADL, BB) /* R(a) = Pool(b) */
OPCODE(LOADL16, BS) /* R(a) = Pool(b) */
OPCODE(LOADI, BB) /* R(a) = mrb_int(b) */
OPCODE(LOADINEG, BB) /* R(a) = mrb_int(-b) */
OPCODE(LOADI__1, B) /* R(a) = mrb_int(-1) */
@@ -25,7 +27,10 @@ OPCODE(LOADI_4, B) /* R(a) = mrb_int(4) */
OPCODE(LOADI_5, B) /* R(a) = mrb_int(5) */
OPCODE(LOADI_6, B) /* R(a) = mrb_int(6) */
OPCODE(LOADI_7, B) /* R(a) = mrb_int(7) */
OPCODE(LOADI16, BS) /* R(a) = mrb_int(b) */
OPCODE(LOADI32, BSS) /* R(a) = mrb_int((b<<16)+c) */
OPCODE(LOADSYM, BB) /* R(a) = Syms(b) */
OPCODE(LOADSYM16, BS) /* R(a) = Syms(b) */
OPCODE(LOADNIL, B) /* R(a) = nil */
OPCODE(LOADSELF, B) /* R(a) = self */
OPCODE(LOADT, B) /* R(a) = true */
@@ -44,28 +49,26 @@ OPCODE(GETMCNST, BB) /* R(a) = R(a)::Syms(b) */
OPCODE(SETMCNST, BB) /* R(a+1)::Syms(b) = R(a) */
OPCODE(GETUPVAR, BBB) /* R(a) = uvget(b,c) */
OPCODE(SETUPVAR, BBB) /* uvset(b,c,R(a)) */
OPCODE(JMP, S) /* pc=a */
OPCODE(JMPIF, BS) /* if R(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(JMP, S) /* pc+=a */
OPCODE(JMPIF, BS) /* if R(a) pc+=b */
OPCODE(JMPNOT, BS) /* if !R(a) pc+=b */
OPCODE(JMPNIL, BS) /* if R(a)==nil pc+=b */
OPCODE(JMPUW, S) /* unwind_and_jump_to(a) */
OPCODE(EXCEPT, B) /* R(a) = exc */
OPCODE(RESCUE, BB) /* R(b) = R(a).isa?(R(b)) */
OPCODE(POPERR, B) /* a.times{rescue_pop()} */
OPCODE(RAISE, B) /* raise(R(a)) */
OPCODE(EPUSH, B) /* ensure_push(SEQ[a]) */
OPCODE(EPOP, B) /* A.times{ensure_pop().call} */
OPCODE(RAISEIF, B) /* raise(R(a)) if R(a) */
OPCODE(SENDV, BB) /* R(a) = call(R(a),Syms(b),*R(a+1)) */
OPCODE(SENDVB, BB) /* R(a) = call(R(a),Syms(b),*R(a+1),&R(a+2)) */
OPCODE(SEND, BBB) /* R(a) = call(R(a),Syms(b),R(a+1),...,R(a+c)) */
OPCODE(SENDB, BBB) /* R(a) = call(R(a),Syms(b),R(a+1),...,R(a+c),&R(a+c+1)) */
OPCODE(SENDVK, BB) /* R(a) = call(R(a),Syms(b),*R(a+1),**(a+2),&R(a+3)) # todo */
OPCODE(CALL, Z) /* R(0) = self.call(frame.argc, frame.argv) */
OPCODE(SUPER, BB) /* R(a) = super(R(a+1),... ,R(a+b+1)) */
OPCODE(ARGARY, BS) /* R(a) = argument array (16=m5:r1:m5:d1:lv4) */
OPCODE(ENTER, W) /* arg setup according to flags (23=m5:o5:r1:m5:k5:d1:b1) */
OPCODE(KEY_P, BB) /* R(a) = kdict.key?(Syms(b)) # todo */
OPCODE(KEYEND, Z) /* raise unless kdict.empty? # todo */
OPCODE(KARG, BB) /* R(a) = kdict[Syms(b)]; kdict.delete(Syms(b)) # todo */
OPCODE(KEY_P, BB) /* R(a) = kdict.key?(Syms(b)) */
OPCODE(KEYEND, Z) /* raise unless kdict.empty? */
OPCODE(KARG, BB) /* R(a) = kdict[Syms(b)]; kdict.delete(Syms(b)) */
OPCODE(RETURN, B) /* return R(a) (normal) */
OPCODE(RETURN_BLK, B) /* return R(a) (in-block return) */
OPCODE(BREAK, B) /* break R(a) */
@@ -91,19 +94,24 @@ OPCODE(ASET, BBB) /* R(a)[c] = R(b) */
OPCODE(APOST, BBB) /* *R(a),R(a+1)..R(a+c) = R(a)[b..] */
OPCODE(INTERN, B) /* R(a) = intern(R(a)) */
OPCODE(STRING, BB) /* R(a) = str_dup(Lit(b)) */
OPCODE(STRING16, BS) /* R(a) = str_dup(Lit(b)) */
OPCODE(STRCAT, B) /* str_cat(R(a),R(a+1)) */
OPCODE(HASH, BB) /* R(a) = hash_new(R(a),R(a+1)..R(a+b)) */
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(LAMBDA16, BS) /* R(a) = lambda(SEQ[b],L_LAMBDA) */
OPCODE(BLOCK, BB) /* R(a) = lambda(SEQ[b],L_BLOCK) */
OPCODE(BLOCK16, BS) /* R(a) = lambda(SEQ[b],L_BLOCK) */
OPCODE(METHOD, BB) /* R(a) = lambda(SEQ[b],L_METHOD) */
OPCODE(METHOD16, BS) /* R(a) = lambda(SEQ[b],L_METHOD) */
OPCODE(RANGE_INC, B) /* R(a) = range_new(R(a),R(a+1),FALSE) */
OPCODE(RANGE_EXC, B) /* R(a) = range_new(R(a),R(a+1),TRUE) */
OPCODE(OCLASS, B) /* R(a) = ::Object */
OPCODE(CLASS, BB) /* R(a) = newclass(R(a),Syms(b),R(a+1)) */
OPCODE(MODULE, BB) /* R(a) = newmodule(R(a),Syms(b)) */
OPCODE(EXEC, BB) /* R(a) = blockexec(R(a),SEQ[b]) */
OPCODE(EXEC16, BS) /* R(a) = blockexec(R(a),SEQ[b]) */
OPCODE(DEF, BB) /* R(a).newmethod(Syms(b),R(a+1)) */
OPCODE(ALIAS, BB) /* alias_method(target_class,Syms(a),Syms(b)) */
OPCODE(UNDEF, B) /* undef_method(target_class,Syms(a)) */
@@ -111,7 +119,4 @@ OPCODE(SCLASS, B) /* R(a) = R(a).singleton_class */
OPCODE(TCLASS, B) /* R(a) = target_class */
OPCODE(DEBUG, BBB) /* print a,b,c */
OPCODE(ERR, B) /* raise(LocalJumpError, Lit(a)) */
OPCODE(EXT1, Z) /* make 1st operand 16bit */
OPCODE(EXT2, Z) /* make 2nd operand 16bit */
OPCODE(EXT3, Z) /* make 1st and 2nd operands 16bit */
OPCODE(STOP, Z) /* stop VM */
+40
View File
@@ -0,0 +1,40 @@
/**
** @file mruby/presym.h - Preallocated Symbols
**
** See Copyright Notice in mruby.h
*/
#ifndef MRUBY_PRESYM_H
#define MRUBY_PRESYM_H
#if defined(MRB_NO_PRESYM)
# include <mruby/presym/disable.h>
#elif !defined(MRB_PRESYM_SCANNING)
# include <mruby/presym/enable.h>
#endif
/*
* Where `mrb_intern_lit` is allowed for symbol interning, it is directly
* replaced by the symbol ID if presym is enabled by using the following
* macros.
*
* MRB_OPSYM(xor) //=> ^ (Operator)
* MRB_CVSYM(xor) //=> @@xor (Class Variable)
* MRB_IVSYM(xor) //=> @xor (Instance Variable)
* MRB_SYM_B(xor) //=> xor! (Method with Bang)
* MRB_SYM_Q(xor) //=> xor? (Method with Question mark)
* MRB_SYM_E(xor) //=> xor= (Method with Equal)
* MRB_SYM(xor) //=> xor (Word characters)
*
* For `MRB_OPSYM`, specify the names corresponding to operators (see
* `MRuby::Presym::OPERATORS` in `lib/mruby/presym.rb` for the names that
* can be specified for it). Other than that, describe only word characters
* excluding leading and ending punctuations.
*
* These macros are expanded to `mrb_intern_lit` if presym is disabled,
* therefore the mruby state variable is required. The above macros can be
* used when the variable name is `mrb`. If you want to use other variable
* names, you need to use macros with `_2` suffix, such as `MRB_SYM_2`.
*/
#endif /* MRUBY_PRESYM_H */
+70
View File
@@ -0,0 +1,70 @@
/**
** @file mruby/presym/disable.h - Disable Preallocated Symbols
**
** See Copyright Notice in mruby.h
*/
#ifndef MRUBY_PRESYM_DISABLE_H
#define MRUBY_PRESYM_DISABLE_H
#include <string.h>
#define MRB_PRESYM_MAX 0
#define MRB_OPSYM(name) MRB_OPSYM__##name(mrb)
#define MRB_CVSYM(name) mrb_intern_lit(mrb, "@@" #name)
#define MRB_IVSYM(name) mrb_intern_lit(mrb, "@" #name)
#define MRB_SYM_B(name) mrb_intern_lit(mrb, #name "!")
#define MRB_SYM_Q(name) mrb_intern_lit(mrb, #name "?")
#define MRB_SYM_E(name) mrb_intern_lit(mrb, #name "=")
#define MRB_SYM(name) mrb_intern_lit(mrb, #name)
#define MRB_OPSYM_2(mrb, name) MRB_OPSYM__##name(mrb)
#define MRB_CVSYM_2(mrb, name) mrb_intern_lit(mrb, "@@" #name)
#define MRB_IVSYM_2(mrb, name) mrb_intern_lit(mrb, "@" #name)
#define MRB_SYM_B_2(mrb, name) mrb_intern_lit(mrb, #name "!")
#define MRB_SYM_Q_2(mrb, name) mrb_intern_lit(mrb, #name "?")
#define MRB_SYM_E_2(mrb, name) mrb_intern_lit(mrb, #name "=")
#define MRB_SYM_2(mrb, name) mrb_intern_lit(mrb, #name)
#define MRB_OPSYM__not(mrb) mrb_intern_lit(mrb, "!")
#define MRB_OPSYM__mod(mrb) mrb_intern_lit(mrb, "%")
#define MRB_OPSYM__and(mrb) mrb_intern_lit(mrb, "&")
#define MRB_OPSYM__mul(mrb) mrb_intern_lit(mrb, "*")
#define MRB_OPSYM__add(mrb) mrb_intern_lit(mrb, "+")
#define MRB_OPSYM__sub(mrb) mrb_intern_lit(mrb, "-")
#define MRB_OPSYM__div(mrb) mrb_intern_lit(mrb, "/")
#define MRB_OPSYM__lt(mrb) mrb_intern_lit(mrb, "<")
#define MRB_OPSYM__gt(mrb) mrb_intern_lit(mrb, ">")
#define MRB_OPSYM__xor(mrb) mrb_intern_lit(mrb, "^")
#define MRB_OPSYM__tick(mrb) mrb_intern_lit(mrb, "`")
#define MRB_OPSYM__or(mrb) mrb_intern_lit(mrb, "|")
#define MRB_OPSYM__neg(mrb) mrb_intern_lit(mrb, "~")
#define MRB_OPSYM__neq(mrb) mrb_intern_lit(mrb, "!=")
#define MRB_OPSYM__nmatch(mrb) mrb_intern_lit(mrb, "!~")
#define MRB_OPSYM__andand(mrb) mrb_intern_lit(mrb, "&&")
#define MRB_OPSYM__pow(mrb) mrb_intern_lit(mrb, "**")
#define MRB_OPSYM__plus(mrb) mrb_intern_lit(mrb, "+@")
#define MRB_OPSYM__minus(mrb) mrb_intern_lit(mrb, "-@")
#define MRB_OPSYM__lshift(mrb) mrb_intern_lit(mrb, "<<")
#define MRB_OPSYM__le(mrb) mrb_intern_lit(mrb, "<=")
#define MRB_OPSYM__eq(mrb) mrb_intern_lit(mrb, "==")
#define MRB_OPSYM__match(mrb) mrb_intern_lit(mrb, "=~")
#define MRB_OPSYM__ge(mrb) mrb_intern_lit(mrb, ">=")
#define MRB_OPSYM__rshift(mrb) mrb_intern_lit(mrb, ">>")
#define MRB_OPSYM__aref(mrb) mrb_intern_lit(mrb, "[]")
#define MRB_OPSYM__oror(mrb) mrb_intern_lit(mrb, "||")
#define MRB_OPSYM__cmp(mrb) mrb_intern_lit(mrb, "<=>")
#define MRB_OPSYM__eqq(mrb) mrb_intern_lit(mrb, "===")
#define MRB_OPSYM__aset(mrb) mrb_intern_lit(mrb, "[]=")
#define MRB_PRESYM_DEFINE_VAR_AND_INITER(name, size, ...) \
static mrb_sym name[size]; \
static void presym_init_##name(mrb_state *mrb) { \
mrb_sym name__[] = {__VA_ARGS__}; \
memcpy(name, name__, sizeof(name)); \
}
#define MRB_PRESYM_INIT_SYMBOLS(mrb, name) presym_init_##name(mrb)
#endif /* MRUBY_PRESYM_DISABLE_H */
+37
View File
@@ -0,0 +1,37 @@
/**
** @file mruby/presym/enable.h - Enable Preallocated Symbols
**
** See Copyright Notice in mruby.h
*/
#ifndef MRUBY_PRESYM_ENABLE_H
#define MRUBY_PRESYM_ENABLE_H
#include <mruby/presym/id.h>
#define MRB_OPSYM(name) MRB_OPSYM__##name
#define MRB_CVSYM(name) MRB_CVSYM__##name
#define MRB_IVSYM(name) MRB_IVSYM__##name
#define MRB_SYM_B(name) MRB_SYM_B__##name
#define MRB_SYM_Q(name) MRB_SYM_Q__##name
#define MRB_SYM_E(name) MRB_SYM_E__##name
#define MRB_SYM(name) MRB_SYM__##name
#define MRB_OPSYM_2(mrb, name) MRB_OPSYM__##name
#define MRB_CVSYM_2(mrb, name) MRB_CVSYM__##name
#define MRB_IVSYM_2(mrb, name) MRB_IVSYM__##name
#define MRB_SYM_B_2(mrb, name) MRB_SYM_B__##name
#define MRB_SYM_Q_2(mrb, name) MRB_SYM_Q__##name
#define MRB_SYM_E_2(mrb, name) MRB_SYM_E__##name
#define MRB_SYM_2(mrb, name) MRB_SYM__##name
#define MRB_PRESYM_DEFINE_VAR_AND_INITER(name, size, ...) \
static const mrb_sym name[] = {__VA_ARGS__};
#define MRB_PRESYM_INIT_SYMBOLS(mrb, name) (void)(mrb)
/* use MRB_SYM() for E_RUNTIME_ERROR etc. */
#undef MRB_ERROR_SYM
#define MRB_ERROR_SYM(sym) MRB_SYM(sym)
#endif /* MRUBY_PRESYM_ENABLE_H */
+73
View File
@@ -0,0 +1,73 @@
/**
** @file mruby/presym/scanning.h - Scanning Preallocated Symbols
**
** See Copyright Notice in mruby.h
*/
#ifndef MRUBY_PRESYM_SCANNING_H
#define MRUBY_PRESYM_SCANNING_H
#define MRB_PRESYM_SCANNING_TAGGED(arg) <@! arg !@>
#undef mrb_intern_lit
#define mrb_intern_lit(mrb, name) MRB_PRESYM_SCANNING_TAGGED(name)
#define mrb_intern_cstr(mrb, name) MRB_PRESYM_SCANNING_TAGGED(name)
#define mrb_define_method(mrb, c, name, f, a) MRB_PRESYM_SCANNING_TAGGED(name)
#define mrb_define_class_method(mrb, c, name, f, a) MRB_PRESYM_SCANNING_TAGGED(name)
#define mrb_define_singleton_method(mrb, c, name, f, a) MRB_PRESYM_SCANNING_TAGGED(name)
#define mrb_define_class(mrb, name, s) MRB_PRESYM_SCANNING_TAGGED(name)
#define mrb_define_class_under(mrb, o, name, s) MRB_PRESYM_SCANNING_TAGGED(name)
#define mrb_define_module(mrb, name) MRB_PRESYM_SCANNING_TAGGED(name)
#define mrb_define_module_under(mrb, o, name) MRB_PRESYM_SCANNING_TAGGED(name)
#define mrb_define_module_function(mrb, c, name, f, s) MRB_PRESYM_SCANNING_TAGGED(name)
#define mrb_define_const(mrb, c, name, v) MRB_PRESYM_SCANNING_TAGGED(name)
#define mrb_define_global_const(mrb, name, v) MRB_PRESYM_SCANNING_TAGGED(name)
#define MRB_OPSYM(name) MRB_OPSYM__##name(mrb)
#define MRB_CVSYM(name) MRB_PRESYM_SCANNING_TAGGED("@@" #name)
#define MRB_IVSYM(name) MRB_PRESYM_SCANNING_TAGGED("@" #name)
#define MRB_SYM_B(name) MRB_PRESYM_SCANNING_TAGGED(#name "!")
#define MRB_SYM_Q(name) MRB_PRESYM_SCANNING_TAGGED(#name "?")
#define MRB_SYM_E(name) MRB_PRESYM_SCANNING_TAGGED(#name "=")
#define MRB_SYM(name) MRB_PRESYM_SCANNING_TAGGED(#name)
#define MRB_OPSYM_2(mrb, name) MRB_OPSYM__##name(mrb)
#define MRB_CVSYM_2(mrb, name) MRB_PRESYM_SCANNING_TAGGED("@@" #name)
#define MRB_IVSYM_2(mrb, name) MRB_PRESYM_SCANNING_TAGGED("@" #name)
#define MRB_SYM_B_2(mrb, name) MRB_PRESYM_SCANNING_TAGGED(#name "!")
#define MRB_SYM_Q_2(mrb, name) MRB_PRESYM_SCANNING_TAGGED(#name "?")
#define MRB_SYM_E_2(mrb, name) MRB_PRESYM_SCANNING_TAGGED(#name "=")
#define MRB_SYM_2(mrb, name) MRB_PRESYM_SCANNING_TAGGED(#name)
#define MRB_OPSYM__not(mrb) MRB_PRESYM_SCANNING_TAGGED("!")
#define MRB_OPSYM__mod(mrb) MRB_PRESYM_SCANNING_TAGGED("%")
#define MRB_OPSYM__and(mrb) MRB_PRESYM_SCANNING_TAGGED("&")
#define MRB_OPSYM__mul(mrb) MRB_PRESYM_SCANNING_TAGGED("*")
#define MRB_OPSYM__add(mrb) MRB_PRESYM_SCANNING_TAGGED("+")
#define MRB_OPSYM__sub(mrb) MRB_PRESYM_SCANNING_TAGGED("-")
#define MRB_OPSYM__div(mrb) MRB_PRESYM_SCANNING_TAGGED("/")
#define MRB_OPSYM__lt(mrb) MRB_PRESYM_SCANNING_TAGGED("<")
#define MRB_OPSYM__gt(mrb) MRB_PRESYM_SCANNING_TAGGED(">")
#define MRB_OPSYM__xor(mrb) MRB_PRESYM_SCANNING_TAGGED("^")
#define MRB_OPSYM__tick(mrb) MRB_PRESYM_SCANNING_TAGGED("`")
#define MRB_OPSYM__or(mrb) MRB_PRESYM_SCANNING_TAGGED("|")
#define MRB_OPSYM__neg(mrb) MRB_PRESYM_SCANNING_TAGGED("~")
#define MRB_OPSYM__neq(mrb) MRB_PRESYM_SCANNING_TAGGED("!=")
#define MRB_OPSYM__nmatch(mrb) MRB_PRESYM_SCANNING_TAGGED("!~")
#define MRB_OPSYM__andand(mrb) MRB_PRESYM_SCANNING_TAGGED("&&")
#define MRB_OPSYM__pow(mrb) MRB_PRESYM_SCANNING_TAGGED("**")
#define MRB_OPSYM__plus(mrb) MRB_PRESYM_SCANNING_TAGGED("+@")
#define MRB_OPSYM__minus(mrb) MRB_PRESYM_SCANNING_TAGGED("-@")
#define MRB_OPSYM__lshift(mrb) MRB_PRESYM_SCANNING_TAGGED("<<")
#define MRB_OPSYM__le(mrb) MRB_PRESYM_SCANNING_TAGGED("<=")
#define MRB_OPSYM__eq(mrb) MRB_PRESYM_SCANNING_TAGGED("==")
#define MRB_OPSYM__match(mrb) MRB_PRESYM_SCANNING_TAGGED("=~")
#define MRB_OPSYM__ge(mrb) MRB_PRESYM_SCANNING_TAGGED(">=")
#define MRB_OPSYM__rshift(mrb) MRB_PRESYM_SCANNING_TAGGED(">>")
#define MRB_OPSYM__aref(mrb) MRB_PRESYM_SCANNING_TAGGED("[]")
#define MRB_OPSYM__oror(mrb) MRB_PRESYM_SCANNING_TAGGED("||")
#define MRB_OPSYM__cmp(mrb) MRB_PRESYM_SCANNING_TAGGED("<=>")
#define MRB_OPSYM__eqq(mrb) MRB_PRESYM_SCANNING_TAGGED("===")
#define MRB_OPSYM__aset(mrb) MRB_PRESYM_SCANNING_TAGGED("[]=")
#endif /* MRUBY_PRESYM_SCANNING_H */
+93 -21
View File
@@ -22,24 +22,29 @@ 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)<<8))
void mrb_env_unshare(mrb_state*, struct REnv*);
struct RProc {
MRB_OBJECT_HEADER;
union {
mrb_irep *irep;
const mrb_irep *irep;
mrb_func_t func;
} body;
struct RProc *upper;
const struct RProc *upper;
union {
struct RClass *target_class;
struct REnv *env;
@@ -52,7 +57,7 @@ struct RProc {
#define MRB_ASPEC_REST(a) (((a) >> 12) & 0x1)
#define MRB_ASPEC_POST(a) (((a) >> 7) & 0x1f)
#define MRB_ASPEC_KEY(a) (((a) >> 2) & 0x1f)
#define MRB_ASPEC_KDICT(a) ((a) & (1<<1))
#define MRB_ASPEC_KDICT(a) (((a) >> 1) & 0x1)
#define MRB_ASPEC_BLOCK(a) ((a) & 1)
#define MRB_PROC_CFUNC_FL 128
@@ -81,16 +86,13 @@ struct RProc {
#define mrb_proc_ptr(v) ((struct RProc*)(mrb_ptr(v)))
struct RProc *mrb_proc_new(mrb_state*, mrb_irep*);
struct RProc *mrb_closure_new(mrb_state*, mrb_irep*);
struct RProc *mrb_proc_new(mrb_state*, const mrb_irep*);
struct RProc *mrb_closure_new(mrb_state*, const mrb_irep*);
MRB_API struct RProc *mrb_proc_new_cfunc(mrb_state*, mrb_func_t);
MRB_API struct RProc *mrb_closure_new_cfunc(mrb_state *mrb, mrb_func_t func, int nlocals);
void mrb_proc_copy(struct RProc *a, struct RProc *b);
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, 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);
@@ -99,10 +101,11 @@ MRB_API mrb_value mrb_proc_cfunc_env_get(mrb_state *mrb, mrb_int idx);
#define MRB_METHOD_FUNC_FL 1
#define MRB_METHOD_NOARG_FL 2
#ifndef MRB_METHOD_T_STRUCT
#ifndef MRB_USE_METHOD_T_STRUCT
#define MRB_METHOD_FUNC_P(m) (((uintptr_t)(m))&MRB_METHOD_FUNC_FL)
#define MRB_METHOD_NOARG_P(m) (((uintptr_t)(m))&MRB_METHOD_NOARG_FL)
#define MRB_METHOD_NOARG_P(m) ((((uintptr_t)(m))&MRB_METHOD_NOARG_FL)?1:0)
#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))
@@ -114,7 +117,7 @@ MRB_API mrb_value mrb_proc_cfunc_env_get(mrb_state *mrb, mrb_int idx);
#else
#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_NOARG_P(m) (((m).flags&MRB_METHOD_NOARG_FL)?1:0)
#define MRB_METHOD_FUNC(m) ((m).func)
#define MRB_METHOD_NOARG_SET(m) do{(m).flags|=MRB_METHOD_NOARG_FL;}while(0)
#define MRB_METHOD_FROM_FUNC(m,fn) do{(m).flags=MRB_METHOD_FUNC_FL;(m).func=(fn);}while(0)
@@ -123,14 +126,83 @@ MRB_API mrb_value mrb_proc_cfunc_env_get(mrb_state *mrb, mrb_int idx);
#define MRB_METHOD_PROC(m) ((m).proc)
#define MRB_METHOD_UNDEF_P(m) ((m).proc==NULL)
#endif /* MRB_METHOD_T_STRUCT */
#endif /* MRB_USE_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))
#include <mruby/khash.h>
KHASH_DECLARE(mt, mrb_sym, mrb_method_t, TRUE)
MRB_API mrb_value mrb_load_proc(mrb_state *mrb, const struct RProc *proc);
static inline void
mrb_vm_ci_proc_set(mrb_callinfo *ci, const struct RProc *p)
{
ci->proc = p;
ci->pc = (p && !MRB_PROC_CFUNC_P(p)) ? p->body.irep->iseq : NULL;
}
static inline struct RClass *
mrb_vm_ci_target_class(const mrb_callinfo *ci)
{
if (ci->u.env && ci->u.env->tt == MRB_TT_ENV) {
return ci->u.env->c;
}
else {
return ci->u.target_class;
}
}
static inline void
mrb_vm_ci_target_class_set(mrb_callinfo *ci, struct RClass *tc)
{
struct REnv *e = ci->u.env;
if (e) {
if (e->tt == MRB_TT_ENV) {
e->c = tc;
}
else {
ci->u.target_class = tc;
}
}
}
static inline struct REnv *
mrb_vm_ci_env(const mrb_callinfo *ci)
{
if (ci->u.env && ci->u.env->tt == MRB_TT_ENV) {
return ci->u.env;
}
else {
return NULL;
}
}
static inline void
mrb_vm_ci_env_set(mrb_callinfo *ci, struct REnv *e)
{
if (ci->u.env) {
if (ci->u.env->tt == MRB_TT_ENV) {
if (e) {
e->c = ci->u.env->c;
ci->u.env = e;
}
else {
ci->u.target_class = ci->u.env->c;
}
}
else {
if (e) {
e->c = ci->u.target_class;
ci->u.env = e;
}
}
}
else {
ci->u.env = e;
}
}
MRB_END_DECL
+10 -15
View File
@@ -35,7 +35,7 @@ struct RString {
};
struct RStringEmbed {
MRB_OBJECT_HEADER;
char ary[];
char ary[RSTRING_EMBED_LEN_MAX+1];
};
#define RSTR_SET_TYPE_FLAG(s, type) (RSTR_UNSET_TYPE_FLAG(s), (s)->flags |= MRB_STR_##type)
@@ -92,9 +92,6 @@ struct RStringEmbed {
# 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
*/
@@ -112,13 +109,11 @@ MRB_API mrb_int mrb_str_strlen(mrb_state*, struct RString*);
#define MRB_STR_FSHARED 2
#define MRB_STR_NOFREE 4
#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_ASCII 16
#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)
#define MRB_STR_TYPE_MASK 15
void mrb_gc_free_str(mrb_state*, struct RString*);
@@ -164,7 +159,7 @@ MRB_API mrb_int mrb_str_index(mrb_state *mrb, mrb_value str, const char *p, mrb_
*
* mrb_close(mrb);
* return 0;
* }
* }
*
* Result:
*
@@ -344,15 +339,15 @@ 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);
#define mrb_str_buf_new(mrb, capa) mrb_str_new_capa(mrb, (capa))
/* 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() */
/* obsolete: use RSTRING_PTR() */
MRB_API const char *mrb_string_value_ptr(mrb_state *mrb, mrb_value str);
/* obslete: use RSTRING_LEN() */
/* obsolete: use RSTRING_LEN() */
MRB_API mrb_int mrb_string_value_len(mrb_state *mrb, mrb_value str);
/**
@@ -382,8 +377,9 @@ MRB_API double mrb_cstr_to_dbl(mrb_state *mrb, const char *s, mrb_bool badcheck)
/**
* Returns a converted string type.
* For type checking, non converting `mrb_to_str` is recommended.
* obsolete: use `mrb_obj_as_string()` instead.
*/
MRB_API mrb_value mrb_str_to_str(mrb_state *mrb, mrb_value str);
#define mrb_str_to_str(mrb, str) mrb_obj_as_string(mrb, str)
/**
* Returns true if the strings match and false if the strings don't match.
@@ -437,7 +433,7 @@ MRB_API int mrb_str_cmp(mrb_state *mrb, mrb_value str1, mrb_value str2);
* - Returned string does not contain any NUL characters (but terminator).
* - It raises an ArgumentError exception if Ruby string contains
* NUL characters.
* - Retured string will be freed automatically on next GC.
* - Returned string will be freed automatically on next GC.
* - Caller can modify returned string without affecting Ruby string
* (e.g. it can be used for mkstemp(3)).
*
@@ -447,7 +443,6 @@ MRB_API int mrb_str_cmp(mrb_state *mrb, mrb_value str1, mrb_value str2);
*/
MRB_API char *mrb_str_to_cstr(mrb_state *mrb, mrb_value str);
mrb_value mrb_str_pool(mrb_state *mrb, 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);
+14 -3
View File
@@ -7,13 +7,15 @@
#ifndef MRB_THROW_H
#define MRB_THROW_H
#if defined(MRB_ENABLE_CXX_ABI)
#if defined(MRB_USE_CXX_ABI)
# if !defined(__cplusplus)
# error Trying to use C++ exception handling in C code
# endif
#endif
#if defined(MRB_ENABLE_CXX_EXCEPTION) && defined(__cplusplus)
#if defined(MRB_USE_CXX_EXCEPTION)
# if defined(__cplusplus)
#define MRB_TRY(buf) try {
#define MRB_CATCH(buf) } catch(mrb_jmpbuf_impl e) { if (e != (buf)->impl) { throw e; }
@@ -22,6 +24,10 @@
#define MRB_THROW(buf) throw((buf)->impl)
typedef mrb_int mrb_jmpbuf_impl;
# else
# error "need to be compiled with C++ compiler"
# endif /* __cplusplus */
#else
#include <setjmp.h>
@@ -29,6 +35,9 @@ typedef mrb_int mrb_jmpbuf_impl;
#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
#define MRB_SETJMP _setjmp
#define MRB_LONGJMP _longjmp
#elif defined(__MINGW64__) && defined(__GNUC__) && __GNUC__ >= 4
#define MRB_SETJMP __builtin_setjmp
#define MRB_LONGJMP __builtin_longjmp
#else
#define MRB_SETJMP setjmp
#define MRB_LONGJMP longjmp
@@ -46,9 +55,11 @@ typedef mrb_int mrb_jmpbuf_impl;
struct mrb_jmpbuf {
mrb_jmpbuf_impl impl;
#if defined(MRB_ENABLE_CXX_EXCEPTION) && defined(__cplusplus)
#if defined(MRB_USE_CXX_EXCEPTION)
static mrb_int jmpbuf_id;
# if defined(__cplusplus)
mrb_jmpbuf() : impl(jmpbuf_id++) {}
# endif
#endif
};
+60 -47
View File
@@ -53,17 +53,19 @@ struct mrb_state;
#if defined(MRB_INT64)
typedef int64_t mrb_int;
typedef uint64_t mrb_uint;
# define MRB_INT_BIT 64
# define MRB_INT_MIN (INT64_MIN>>MRB_FIXNUM_SHIFT)
# define MRB_INT_MAX (INT64_MAX>>MRB_FIXNUM_SHIFT)
# define MRB_INT_MIN INT64_MIN
# define MRB_INT_MAX INT64_MAX
# define MRB_PRIo PRIo64
# define MRB_PRId PRId64
# define MRB_PRIx PRIx64
#else
typedef int32_t mrb_int;
typedef uint32_t mrb_uint;
# define MRB_INT_BIT 32
# define MRB_INT_MIN (INT32_MIN>>MRB_FIXNUM_SHIFT)
# define MRB_INT_MAX (INT32_MAX>>MRB_FIXNUM_SHIFT)
# define MRB_INT_MIN INT32_MIN
# define MRB_INT_MAX INT32_MAX
# define MRB_PRIo PRIo32
# define MRB_PRId PRId32
# define MRB_PRIx PRIx32
@@ -75,9 +77,9 @@ struct mrb_state;
# define MRB_ENDIAN_LOHI(a,b) b a
#endif
#ifndef MRB_WITHOUT_FLOAT
#ifndef MRB_NO_FLOAT
MRB_API double mrb_float_read(const char*, char**);
#ifdef MRB_USE_FLOAT
#ifdef MRB_USE_FLOAT32
typedef float mrb_float;
#else
typedef double mrb_float;
@@ -90,7 +92,7 @@ MRB_API int mrb_msvc_vsnprintf(char *s, size_t n, const char *format, va_list ar
MRB_API int mrb_msvc_snprintf(char *s, size_t n, const char *format, ...);
# define vsnprintf(s, n, format, arg) mrb_msvc_vsnprintf(s, n, format, arg)
# define snprintf(s, n, format, ...) mrb_msvc_snprintf(s, n, format, __VA_ARGS__)
# if _MSC_VER < 1800 && !defined MRB_WITHOUT_FLOAT
# if _MSC_VER < 1800 && !defined MRB_NO_FLOAT
# include <float.h>
# define isfinite(n) _finite(n)
# define isnan _isnan
@@ -103,34 +105,36 @@ static const unsigned int IEEE754_INFINITY_BITS_SINGLE = 0x7F800000;
#endif
enum mrb_vtype {
MRB_TT_FALSE = 0, /* 0 */
MRB_TT_TRUE, /* 1 */
MRB_TT_FLOAT, /* 2 */
MRB_TT_FIXNUM, /* 3 */
MRB_TT_SYMBOL, /* 4 */
MRB_TT_UNDEF, /* 5 */
MRB_TT_CPTR, /* 6 */
MRB_TT_FREE, /* 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_INTEGER,
MRB_TT_SYMBOL,
MRB_TT_UNDEF,
MRB_TT_CPTR,
MRB_TT_FREE,
MRB_TT_OBJECT,
MRB_TT_CLASS,
MRB_TT_MODULE,
MRB_TT_ICLASS,
MRB_TT_SCLASS,
MRB_TT_PROC,
MRB_TT_ARRAY,
MRB_TT_HASH,
MRB_TT_STRING,
MRB_TT_RANGE,
MRB_TT_EXCEPTION,
MRB_TT_ENV,
MRB_TT_DATA,
MRB_TT_FIBER,
MRB_TT_ISTRUCT,
MRB_TT_BREAK,
MRB_TT_MAXDEFINE
};
/* for compatibility */
#define MRB_TT_FIXNUM MRB_TT_INTEGER
#include <mruby/object.h>
#ifdef MRB_DOCUMENTATION_BLOCK
@@ -149,6 +153,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)
@@ -157,12 +168,9 @@ 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)
# define MRB_SSIZE_MAX INTPTR_MAX
#else
typedef mrb_int mrb_ssize;
# define MRB_SSIZE_MAX MRB_INT_MAX
@@ -171,8 +179,11 @@ typedef void mrb_value;
#ifndef mrb_immediate_p
#define mrb_immediate_p(o) (mrb_type(o) < MRB_TT_FREE)
#endif
#ifndef mrb_integer_p
#define mrb_integer_p(o) (mrb_type(o) == MRB_TT_INTEGER)
#endif
#ifndef mrb_fixnum_p
#define mrb_fixnum_p(o) (mrb_type(o) == MRB_TT_FIXNUM)
#define mrb_fixnum_p(o) mrb_integer_p(o)
#endif
#ifndef mrb_symbol_p
#define mrb_symbol_p(o) (mrb_type(o) == MRB_TT_SYMBOL)
@@ -189,7 +200,7 @@ typedef void mrb_value;
#ifndef mrb_true_p
#define mrb_true_p(o) (mrb_type(o) == MRB_TT_TRUE)
#endif
#ifndef MRB_WITHOUT_FLOAT
#ifndef MRB_NO_FLOAT
#ifndef mrb_float_p
#define mrb_float_p(o) (mrb_type(o) == MRB_TT_FLOAT)
#endif
@@ -233,9 +244,6 @@ typedef void mrb_value;
#ifndef mrb_range_p
#define mrb_range_p(o) (mrb_type(o) == MRB_TT_RANGE)
#endif
#ifndef mrb_file_p
#define mrb_file_p(o) (mrb_type(o) == MRB_TT_FILE)
#endif
#ifndef mrb_env_p
#define mrb_env_p(o) (mrb_type(o) == MRB_TT_ENV)
#endif
@@ -261,7 +269,7 @@ typedef void mrb_value;
*
* Takes a float and boxes it into an mrb_value
*/
#ifndef MRB_WITHOUT_FLOAT
#ifndef MRB_NO_FLOAT
MRB_INLINE mrb_value mrb_float_value(struct mrb_state *mrb, mrb_float f)
{
mrb_value v;
@@ -281,14 +289,19 @@ mrb_cptr_value(struct mrb_state *mrb, void *p)
}
/**
* Returns a fixnum in Ruby.
*
* Takes an integer and boxes it into an mrb_value
* Returns an integer in Ruby.
*/
MRB_INLINE mrb_value mrb_int_value(struct mrb_state *mrb, mrb_int i)
{
mrb_value v;
SET_INT_VALUE(mrb, v, i);
return v;
}
MRB_INLINE mrb_value mrb_fixnum_value(mrb_int i)
{
mrb_value v;
SET_INT_VALUE(v, i);
SET_FIXNUM_VALUE(v, i);
return v;
}
+1
View File
@@ -35,6 +35,7 @@ mrb_value mrb_vm_cv_get(mrb_state*, mrb_sym);
void mrb_vm_cv_set(mrb_state*, mrb_sym, mrb_value);
mrb_value mrb_vm_const_get(mrb_state*, mrb_sym);
void mrb_vm_const_set(mrb_state*, mrb_sym, mrb_value);
size_t mrb_obj_iv_tbl_memsize(mrb_value);
MRB_API mrb_value mrb_const_get(mrb_state*, mrb_value, mrb_sym);
MRB_API void mrb_const_set(mrb_state*, mrb_value, mrb_sym, mrb_value);
MRB_API mrb_bool mrb_const_defined(mrb_state*, mrb_value, mrb_sym);
+26 -7
View File
@@ -27,7 +27,7 @@ MRB_BEGIN_DECL
/*
* The version of Ruby used by mruby.
*/
#define MRUBY_RUBY_VERSION "2.0"
#define MRUBY_RUBY_VERSION "3.0"
/*
* Ruby engine.
@@ -37,17 +37,35 @@ MRB_BEGIN_DECL
/*
* Major release version number.
*/
#define MRUBY_RELEASE_MAJOR 2
#define MRUBY_RELEASE_MAJOR 3
/*
* Minor release version number.
*/
#define MRUBY_RELEASE_MINOR 1
#define MRUBY_RELEASE_MINOR 0
/*
* Tiny release version number.
*/
#define MRUBY_RELEASE_TEENY 1
#define MRUBY_RELEASE_TEENY 0
/*
* Patch level.
*/
#define MRUBY_PATCHLEVEL -1
/*
* Patch level string. (optional)
*/
#define MRUBY_PATCHLEVEL_STR "RC"
#ifndef MRUBY_PATCHLEVEL_STR
# if MRUBY_PATCHLEVEL < 0
# define MRUBY_PATCHLEVEL_STR "dev"
# else
# define MRUBY_PATCHLEVEL_STR "p"MRB_STRINGIZE(MRUBY_PATCHLEVEL)
# endif
#endif
/*
* The mruby version.
@@ -62,17 +80,17 @@ MRB_BEGIN_DECL
/*
* Release year.
*/
#define MRUBY_RELEASE_YEAR 2020
#define MRUBY_RELEASE_YEAR 2021
/*
* Release month.
*/
#define MRUBY_RELEASE_MONTH 4
#define MRUBY_RELEASE_MONTH 2
/*
* Release day.
*/
#define MRUBY_RELEASE_DAY 20
#define MRUBY_RELEASE_DAY 3
/*
* Release date as a string.
@@ -108,6 +126,7 @@ MRB_BEGIN_DECL
*/
#define MRUBY_DESCRIPTION \
"mruby " MRUBY_VERSION \
MRUBY_PATCHLEVEL_STR \
" (" MRUBY_RELEASE_DATE ")" \
/*
+198 -64
View File
@@ -1,10 +1,11 @@
require "mruby-core-ext"
require "mruby/core_ext"
require "mruby/build/load_gems"
require "mruby/build/command"
module MRuby
autoload :Gem, "mruby/gem"
autoload :Lockfile, "mruby/lockfile"
autoload :Presym, "mruby/presym"
class << self
def targets
@@ -22,6 +23,18 @@ module MRuby
class Toolchain
class << self
attr_accessor :toolchains
def guess
if cc = ENV["CC"] || ENV["CXX"]
return "clang" if cc.include?("clang")
else
return "clang" if RUBY_PLATFORM =~ /darwin|(?:free|open)bsd/
return "gcc" if RUBY_PLATFORM.include?("cygwin")
return "visualcpp" if ENV.include?("VisualStudioVersion")
return "visualcpp" if ENV.include?("VSINSTALLDIR")
end
"gcc"
end
end
def initialize(name, &block)
@@ -29,7 +42,7 @@ module MRuby
MRuby::Toolchain.toolchains[@name] = self
end
def setup(conf,params={})
def setup(conf, params={})
conf.instance_exec(conf, params, &@initializer)
end
@@ -39,12 +52,27 @@ module MRuby
class Build
class << self
attr_accessor :current
def mruby_config_path
path = ENV['MRUBY_CONFIG'] || ENV['CONFIG']
if path.nil? || path.empty?
path = "#{MRUBY_ROOT}/build_config/default.rb"
elsif !File.file?(path) && !Pathname.new(path).absolute?
f = "#{MRUBY_ROOT}/build_config/#{path}.rb"
path = File.exist?(f) ? f : File.extname(path).empty? ? f : path
end
path
end
def install_dir
@install_dir ||= ENV['INSTALL_DIR'] || "#{MRUBY_ROOT}/bin"
end
end
include Rake::DSL
include LoadGems
attr_accessor :name, :bins, :exts, :file_separator, :build_dir, :gem_clone_dir
attr_reader :libmruby_objs, :gems, :toolchains, :gem_dir_to_repo_url
attr_writer :enable_bintest, :enable_test
attr_reader :products, :libmruby_core_objs, :libmruby_objs, :gems, :toolchains, :presym, :mrbc_build, :gem_dir_to_repo_url
alias libmruby libmruby_objs
@@ -52,16 +80,16 @@ module MRuby
COMMANDS = COMPILERS + %w(linker archiver yacc gperf git exts mrbc)
attr_block MRuby::Build::COMMANDS
Exts = Struct.new(:object, :executable, :library)
Exts = Struct.new(:object, :executable, :library, :presym_preprocessed)
def initialize(name='host', build_dir=nil, &block)
def initialize(name='host', build_dir=nil, internal: false, &block)
@name = name.to_s
unless MRuby.targets[@name]
unless current = MRuby.targets[@name]
if ENV['OS'] == 'Windows_NT'
@exts = Exts.new('.o', '.exe', '.a')
@exts = Exts.new('.o', '.exe', '.a', '.pi')
else
@exts = Exts.new('.o', '', '.a')
@exts = Exts.new('.o', '', '.a', '.pi')
end
build_dir = build_dir || ENV['MRUBY_BUILD_DIR'] || "#{MRUBY_ROOT}/build"
@@ -69,10 +97,10 @@ module MRuby
@file_separator = '/'
@build_dir = "#{build_dir}/#{@name}"
@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))
@asm = Command::Compiler.new(self, %w(.S .asm))
@cc = Command::Compiler.new(self, %w(.c), label: "CC")
@cxx = Command::Compiler.new(self, %w(.cc .cxx .cpp), label: "CXX")
@objc = Command::Compiler.new(self, %w(.m), label: "OBJC")
@asm = Command::Compiler.new(self, %w(.S .asm .s), label: "ASM")
@linker = Command::Linker.new(self)
@archiver = Command::Archiver.new(self)
@yacc = Command::Yacc.new(self)
@@ -80,8 +108,12 @@ module MRuby
@git = Command::Git.new(self)
@mrbc = Command::Mrbc.new(self)
@products = []
@bins = []
@gems, @libmruby_objs = MRuby::Gem::List.new, []
@gems = MRuby::Gem::List.new
@libmruby_core_objs = []
@libmruby_objs = [@libmruby_core_objs]
@enable_libmruby = true
@build_mrbtest_lib_only = false
@cxx_exception_enabled = false
@cxx_exception_disabled = false
@@ -89,17 +121,33 @@ module MRuby
@enable_bintest = false
@enable_test = false
@enable_lock = true
@enable_presym = true
@mrbcfile_external = false
@internal = internal
@toolchains = []
@gem_dir_to_repo_url = {}
MRuby.targets[@name] = self
MRuby.targets[@name] = current = self
end
MRuby::Build.current = MRuby.targets[@name]
MRuby.targets[@name].instance_eval(&block)
MRuby::Build.current = current
current.instance_eval(&block)
if current.libmruby_enabled? && !current.mrbcfile_external?
if current.presym_enabled?
current.create_mrbc_build if current.host? || current.gems["mruby-bin-mrbc"]
elsif current.host?
current.build_mrbc_exec
end
end
current.presym = Presym.new(current) if current.presym_enabled?
end
build_mrbc_exec if name == 'host'
build_mrbtest if test_enabled?
def libmruby_enabled?
@enable_libmruby
end
def disable_libmruby
@enable_libmruby = false
end
def debug_enabled?
@@ -118,6 +166,17 @@ module MRuby
@enable_debug = true
end
def presym_enabled?
@enable_presym
end
def disable_presym
if @enable_presym
@enable_presym = false
compilers.each{|c| c.defines << "MRB_NO_PRESYM"}
end
end
def disable_lock
@enable_lock = false
end
@@ -141,7 +200,7 @@ module MRuby
end
@cxx_exception_enabled = true
compilers.each { |c|
c.defines += %w(MRB_ENABLE_CXX_EXCEPTION)
c.defines += %w(MRB_USE_CXX_EXCEPTION)
c.flags << c.cxx_exception_flag
}
linker.command = cxx.command if toolchains.find { |v| v == 'gcc' }
@@ -161,7 +220,7 @@ module MRuby
raise "cxx_exception already enabled"
end
compilers.each { |c|
c.defines += %w(MRB_ENABLE_CXX_EXCEPTION MRB_ENABLE_CXX_ABI)
c.defines += %w(MRB_USE_CXX_EXCEPTION MRB_USE_CXX_ABI)
c.flags << c.cxx_compile_flag
c.flags = c.flags.flatten - c.cxx_invalid_flags.flatten
}
@@ -169,8 +228,29 @@ module MRuby
@cxx_abi_enabled = true
end
def compile_as_cxx src, cxx_src, obj = nil, includes = []
obj = objfile(cxx_src) if obj.nil?
def compile_as_cxx(src, cxx_src = nil, obj = nil, includes = [])
#
# If `cxx_src` is specified, this method behaves the same as before as
# compatibility mode, but `.d` file is not read.
#
# If `cxx_src` is omitted, `.d` file is read by using mruby standard
# Rake rule (C++ source name is also changed).
#
if cxx_src
obj ||= cxx_src + @exts.object
dsts = [obj]
dsts << (cxx_src + @exts.presym_preprocessed) if presym_enabled?
defines = []
include_paths = ["#{MRUBY_ROOT}/src", *includes]
dsts.each do |dst|
file dst => cxx_src do |t|
cxx.run t.name, t.prerequisites.first, defines, include_paths
end
end
else
cxx_src = "#{build_dir}/#{src.relative_path})".ext << "-cxx.cxx"
obj = cxx_src.ext(@exts.object)
end
file cxx_src => [src, __FILE__] do |t|
mkdir_p File.dirname t.name
@@ -178,20 +258,16 @@ module MRuby
#define __STDC_CONSTANT_MACROS
#define __STDC_LIMIT_MACROS
#ifndef MRB_ENABLE_CXX_ABI
#ifndef MRB_USE_CXX_ABI
extern "C" {
#endif
#include "#{File.absolute_path src}"
#ifndef MRB_ENABLE_CXX_ABI
#ifndef MRB_USE_CXX_ABI
}
#endif
EOS
end
file obj => cxx_src do |t|
cxx.run t.name, t.prerequisites.first, [], ["#{MRUBY_ROOT}/src"] + includes
end
obj
end
@@ -203,7 +279,7 @@ EOS
@enable_bintest
end
def toolchain(name, params={})
def toolchain(name=Toolchain.guess, params={})
name = name.to_s
tc = Toolchain.toolchains[name] || begin
path = "#{MRUBY_ROOT}/tasks/toolchains/#{name}.rake"
@@ -226,17 +302,14 @@ EOS
def enable_test
@enable_test = true
end
alias build_mrbtest enable_test
def test_enabled?
@enable_test
end
def build_mrbtest
gem :core => 'mruby-test'
end
def build_mrbc_exec
gem :core => 'mruby-bin-mrbc'
gem :core => 'mruby-bin-mrbc' unless @gems['mruby-bin-mrbc']
end
def locks
@@ -246,9 +319,22 @@ EOS
def mrbcfile
return @mrbcfile if @mrbcfile
mrbc_build = MRuby.targets['host']
gems.each { |v| mrbc_build = self if v.name == 'mruby-bin-mrbc' }
@mrbcfile = mrbc_build.exefile("#{mrbc_build.build_dir}/bin/mrbc")
gem_name = "mruby-bin-mrbc"
gem = @gems[gem_name]
gem ||= (host = MRuby.targets["host"]) && host.gems[gem_name]
unless gem
fail "external mrbc or mruby-bin-mrbc gem in current('#{@name}') or 'host' build is required"
end
@mrbcfile = exefile("#{gem.build.build_dir}/bin/mrbc")
end
def mrbcfile=(path)
@mrbcfile = path
@mrbcfile_external = true
end
def mrbcfile_external?
@mrbcfile_external
end
def compilers
@@ -258,14 +344,32 @@ EOS
end
def define_rules
use_mrdb = @gems["mruby-bin-debugger"]
compilers.each do |compiler|
if respond_to?(:enable_gems?) && enable_gems?
compiler.defines -= %w(DISABLE_GEMS)
compiler.defines -= %w(MRB_NO_GEMS)
else
compiler.defines += %w(DISABLE_GEMS)
compiler.defines += %w(MRB_NO_GEMS)
end
compiler.define_rules build_dir, File.expand_path(File.join(File.dirname(__FILE__), '..', '..'))
compiler.defines |= %w(MRB_USE_DEBUG_HOOK) if use_mrdb
end
[@cc, *(@cxx if cxx_exception_enabled?)].each do |compiler|
compiler.define_rules(@build_dir, MRUBY_ROOT, @exts.object)
compiler.define_rules(@build_dir, MRUBY_ROOT, @exts.presym_preprocessed) if presym_enabled?
end
end
def define_installer(src)
dst = "#{self.class.install_dir}/#{File.basename(src)}"
file dst => src do
install_D src, dst
end
dst
end
def define_installer_if_needed(bin)
exe = exefile("#{build_dir}/bin/#{bin}")
host? ? define_installer(exe) : exe
end
def filename(name)
@@ -326,7 +430,9 @@ EOS
puts ">>> Bintest #{name} <<<"
targets = @gems.select { |v| File.directory? "#{v.dir}/bintest" }.map { |v| filename v.dir }
targets << filename(".") if File.directory? "./bintest"
sh "ruby test/bintest.rb#{verbose_flag} #{targets.join ' '}"
mrbc = @gems["mruby-bin-mrbc"] ? exefile("#{@build_dir}/bin/mrbc") : mrbcfile
env = {"BUILD_DIR" => @build_dir, "MRBCFILE" => mrbc}
sh env, "ruby test/bintest.rb#{verbose_flag} #{targets.join ' '}"
end
def print_build_summary
@@ -336,7 +442,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}"
@@ -358,6 +465,42 @@ EOS
def libraries
[libmruby_static]
end
def host?
@name == "host"
end
def internal?
@internal
end
protected
attr_writer :presym
def create_mrbc_build
exclusions = %i[@name @build_dir @gems @enable_test @enable_bintest @internal]
name = "#{@name}/mrbc"
MRuby.targets.delete(name)
build = self.class.new(name, internal: true){}
build.build_dir = "#{@build_dir}/mrbc"
instance_variables.each do |n|
next if exclusions.include?(n)
v = instance_variable_get(n)
v = case v
when nil, true, false, Numeric; v
when String, Command; v.clone
else Marshal.load(Marshal.dump(v)) # deep clone
end
build.instance_variable_set(n, v)
end
build.build_mrbc_exec
build.disable_libmruby
build.disable_presym
@mrbc_build = build
self.mrbcfile = build.mrbcfile
build
end
end # Build
class CrossBuild < Build
@@ -368,13 +511,21 @@ EOS
attr_accessor :host_target, :build_target
def initialize(name, build_dir=nil, &block)
@endian = nil
@test_runner = Command::CrossTestRunner.new(self)
super
unless mrbcfile_external? || MRuby.targets['host']
# add minimal 'host'
MRuby::Build.new('host') do |conf|
conf.toolchain
conf.build_mrbc_exec
conf.disable_libmruby
conf.disable_presym
end
end
end
def mrbcfile
MRuby.targets['host'].exefile("#{MRuby.targets['host'].build_dir}/bin/mrbc")
mrbcfile_external? ? super : MRuby::targets['host'].mrbcfile
end
def run_test
@@ -388,25 +539,8 @@ EOS
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
protected
def little_endian
if @endian
puts "Endian has already specified as #{@endian}."
return
end
@endian = :little
@mrbc.compile_options += ' -e'
end
def create_mrbc_build; end
end # CrossBuild
end # MRuby
+55 -37
View File
@@ -32,28 +32,22 @@ module MRuby
end
end
NotFoundCommands = {}
private
def _run(options, params={})
return sh command + ' ' + ( options % params ) if NotFoundCommands.key? @command
begin
sh build.filename(command) + ' ' + ( options % params )
rescue RuntimeError
NotFoundCommands[@command] = true
_run options, params
end
sh "#{build.filename(command)} #{options % params}"
end
end
class Command::Compiler < Command
attr_accessor :flags, :include_paths, :defines, :source_exts
attr_accessor :label, :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, :cxx_invalid_flags
attr_writer :preprocess_options
def initialize(build, source_exts=[])
def initialize(build, source_exts=[], label: "CC")
super(build)
@command = ENV['CC'] || 'cc'
@label = label
@flags = [ENV['CFLAGS'] || []]
@source_exts = source_exts
@include_paths = ["#{MRUBY_ROOT}/include"]
@@ -62,9 +56,15 @@ module MRuby
@option_define = %q[-D"%s"]
@compile_options = %q[%{flags} -o "%{outfile}" -c "%{infile}"]
@cxx_invalid_flags = []
@out_ext = build.exts.object
end
alias header_search_paths include_paths
def preprocess_options
@preprocess_options ||= @compile_options.sub(/(?:\A|\s)\K-c(?=\s)/, "-E -P")
end
def search_header_path(name)
header_search_paths.find do |v|
File.exist? build.filename("#{v}/#{name}").sub(/^"(.*)"$/, '\1')
@@ -86,13 +86,20 @@ module MRuby
def run(outfile, infile, _defines=[], _include_paths=[], _flags=[])
mkdir_p File.dirname(outfile)
_pp "CC", infile.relative_path, outfile.relative_path
_run compile_options, { :flags => all_flags(_defines, _include_paths, _flags),
:infile => filename(infile), :outfile => filename(outfile) }
flags = all_flags(_defines, _include_paths, _flags)
if object_ext?(outfile)
label = @label
opts = compile_options
else
label = "CPP"
opts = preprocess_options
flags << " -DMRB_PRESYM_SCANNING"
end
_pp label, infile.relative_path, outfile.relative_path
_run opts, flags: flags, infile: filename(infile), outfile: filename(outfile)
end
def define_rules(build_dir, source_dir='')
@out_ext = build.exts.object
def define_rules(build_dir, source_dir='', out_ext=build.exts.object)
gemrake = File.join(source_dir, "mrbgem.rake")
rakedep = File.exist?(gemrake) ? [ gemrake ] : []
@@ -133,18 +140,14 @@ module MRuby
#
# ==== Without <tt>-MP</tt> compiler flag
#
# /build/host/src/array.o: \
# /src/array.c \
# /include/mruby/common.h \
# /include/mruby/value.h \
# /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 \
# /build/host/src/array.o: /src/array.c \
# /include/mruby/common.h /include/mruby/value.h \
# /src/value_array.h
#
# /include/mruby/common.h:
@@ -154,14 +157,25 @@ module MRuby
# /src/value_array.h:
#
def get_dependencies(file)
file = file.ext('d') unless File.extname(file) == '.d'
deps = []
if File.exist?(file)
File.foreach(file){|line| deps << $1 if /^ +(.*?)(?: *\\)?$/ =~ line}
deps.uniq!
end
dep_file = file.ext(".d")
return [MRUBY_CONFIG] unless object_ext?(file) && File.exist?(dep_file)
deps = File.read(dep_file).gsub("\\\n ", "").split("\n").map do |dep_line|
# dep_line:
# - "/build/host/src/array.o: /src/array.c /include/mruby/common.h ..."
# - ""
# - "/include/mruby/common.h:"
dep_line.scan(/^\S+:\s+(.+)$/).flatten.map { |s| s.split(' ') }.flatten
# => ["/src/array.c", "/include/mruby/common.h" , ...]
# []
# []
end.flatten.uniq
deps << MRUBY_CONFIG
end
def object_ext?(path)
File.extname(path) == build.exts.object
end
end
class Command::Linker < Command
@@ -191,6 +205,10 @@ module MRuby
[libraries, _libraries].flatten.map{ |d| option_library % d }.join(' ')
end
def run_attrs
[@libraries, @library_paths, @flags, @flags_before_libraries, @flags_after_libraries]
end
def run(outfile, objfiles, _libraries=[], _library_paths=[], _flags=[], _flags_before_libraries=[], _flags_after_libraries=[])
mkdir_p File.dirname(outfile)
library_flags = [libraries, _libraries].flatten.map { |d| option_library % d }
@@ -310,21 +328,21 @@ module MRuby
@compile_options = "-B%{funcname} -o-"
end
def run(out, infiles, funcname)
def run(out, infiles, funcname, cdump = true)
@command ||= @build.mrbcfile
infiles = [infiles].flatten
infiles.each do |f|
_pp "MRBC", f.relative_path, nil, :indent => 2
infiles.each_with_index do |f, i|
_pp i == 0 ? "MRBC" : "", f.relative_path, indent: 2
end
cmd = %Q["#{filename @command}" #{@compile_options % {:funcname => funcname}} #{filename(infiles).map{|f| %Q["#{f}"]}.join(' ')}]
cmd = %Q["#{filename @command}" #{cdump ? "-S" : ""} #{@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
if $?.exitstatus != 0
File.delete(out.path)
exit(-1)
unless $?.success?
rm_f out.path
fail "Command failed with status (#{$?.exitstatus}): [#{cmd[0,42]}...]"
end
end
end
+11 -9
View File
@@ -15,10 +15,13 @@ module MRuby
def gem(gemdir, &block)
if gemdir.is_a?(Hash)
gemdir = load_special_path_gem(gemdir)
elsif GemBox.path && gemdir.is_a?(String)
elsif GemBox.path
gemdir = File.expand_path(gemdir, File.dirname(GemBox.path))
else
caller_dir = File.expand_path(File.dirname(caller(1,1)[0][/^(.*?):\d/,1]))
if caller_dir == "#{MRUBY_ROOT}/build_config"
caller_dir = MRUBY_ROOT
end
gemdir = File.expand_path(gemdir, caller_dir)
end
@@ -28,18 +31,17 @@ module MRuby
Gem.current = nil
load gemrake
return nil unless Gem.current
current = Gem.current
Gem.current.dir = gemdir
Gem.current.build = self.is_a?(MRuby::Build) ? self : MRuby::Build.current
Gem.current.build_config_initializer = block
gems << Gem.current
current.dir = gemdir
current.build = self.is_a?(MRuby::Build) ? self : MRuby::Build.current
current.build_config_initializer = block
gems << current
cxx_srcs = ['src', 'test', 'tools'].map do |subdir|
Dir.glob("#{Gem.current.dir}/#{subdir}/*.{cpp,cxx,cc}")
end.flatten
cxx_srcs = Dir.glob("#{current.dir}/{src,test,tools}/*.{cpp,cxx,cc}")
enable_cxx_exception unless cxx_srcs.empty?
Gem.current
current
end
def load_special_path_gem(params)
@@ -20,10 +20,17 @@ class String
end
end
def _pp(cmd, src, tgt=nil, options={})
return if Rake.verbose
def install_D(src, dst)
_pp "INSTALL", src.relative_path, dst.relative_path
rm_f dst
mkdir_p File.dirname(dst)
cp src, dst
end
def _pp(cmd, src, tgt=nil, indent: nil)
return if Rake.application.options.silent
width = 5
template = options[:indent] ? "%#{width*options[:indent]}s %s %s" : "%-#{width}s %s %s"
template = indent ? "%#{width * indent}s %s %s" : "%-#{width}s %s %s"
puts template % [cmd, src, tgt ? "-> #{tgt}" : nil]
end

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