Compare commits

..

544 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
232 changed files with 12017 additions and 9087 deletions
+108 -65
View File
@@ -3,104 +3,147 @@ 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_TARGET: travis
MRUBY_CONFIG: ci/gcc-clang
CC: gcc
steps:
- uses: actions/checkout@v1
- name: apt
run: sudo apt install ruby gperf
- name: build and test
run: rake -m -j4 gensym all test
- 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_TARGET: travis
MRUBY_CONFIG: ci/gcc-clang
CC: gcc
CXX: g++
steps:
- uses: actions/checkout@v1
- name: apt
run: sudo apt install ruby gperf gcc g++
- name: build and test
run: rake -m -j4 gensym all test
- 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_TARGET: travis
MRUBY_CONFIG: ci/gcc-clang
CC: clang
CXX: clang++
steps:
- uses: actions/checkout@v1
- name: apt
run: sudo apt install ruby gperf
- name: build and test
run: rake -m -j4 gensym all test
- 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_TARGET: travis
MRUBY_CONFIG: ci/gcc-clang
CC: clang
steps:
- uses: actions/checkout@v1
- name: brew
run: brew install ruby gperf
- name: build and test
run: rake -m -j4 gensym all test
- 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_TARGET: travis
CFLAGS: -g -O1 -Wall -Wundef
MRUBY_CONFIG: ci/gcc-clang
CC: gcc
steps:
- uses: actions/checkout@v1
- name: chocolatey
run: choco install -y ruby gperf
- name: build
run: rake -E 'STDOUT.sync=true' -j4 gensym all test
- 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:
MRUBY_TARGET: travis
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@v1
- uses: actions/cache@v1
with:
path: C:\Users\runneradmin\AppData\Local\Temp\chocolatey
key: ${{ runner.os }}-cygwin-chocolatey-${{ matrix.os }}-${{ github.sha }}
restore-keys: |
${{ runner.os }}-cygwin-chocolatey-${{ matrix.os }}-
${{ runner.os }}-cygwin-chocolatey-
- name: chocolatey
run: choco install -y cygwin
- name: Install cygwin packages
shell: cmd
run: C:\tools\cygwin\cygwinsetup.exe -qgnNdO -R C:/tools/cygwin -l C:/tools/cygwin/package -s http://mirrors.kernel.org/sourceware/cygwin/ -P gcc-core,gcc-g++,make,gperf,ruby
- name: Set ENV
run: |
echo '::set-env name=PATH::C:\tools\cygwin\bin;C:\tools\cygwin\usr\bin'
- name: build and test
shell: cmd
run: C:\tools\cygwin\bin\ruby.exe /usr/bin/rake -E 'STDOUT.sync=true' -m gensym all test
- 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_TARGET: appveyor
# TODO(take-cheeze): Re-enable /O2
CFLAGS: "/c /nologo /W3 /we4013 /Zi /MD /D_CRT_SECURE_NO_WARNINGS"
CXXFLAGS: "/c /nologo /W3 /Zi /MD /EHs /D_CRT_SECURE_NO_WARNINGS"
MRUBY_CONFIG: ci/msvc
steps:
- uses: actions/checkout@v1
- name: chocolatey
run: choco install -y ruby gperf
- name: build and test
shell: cmd
run: |
call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\Build\vcvars64.bat"
rake -E "STDOUT.sync=true" gensym all test
- 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
+35 -31
View File
@@ -8,44 +8,48 @@ on:
jobs:
CodeQL-Build:
if: |
!contains(github.event.head_commit.message, '[ci skip]') &&
!contains(github.event.head_commit.message, '[skip ci]') &&
!contains(github.event.head_commit.message, '[skip gha]')
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
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
- 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
# 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' }}
# 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
# 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
# ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl
# 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
# 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
# Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl
#- run: |
# make bootstrap
# make release
# ✏️ 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
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
# - 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 -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
+2 -5
View File
@@ -3,12 +3,9 @@ language: c
jobs:
- os: linux
- os: osx
before_install:
- HOMEBREW_NO_AUTO_UPDATE=1 HOMEBREW_NO_INSTALL_CLEANUP=1 brew install bison
- export PATH="/usr/local/opt/bison/bin:$PATH"
env:
- MRUBY_TARGET=travis
- MRUBY_CONFIG=ci/gcc-clang
script:
- rake gensym && rake -m && rake test
- 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
+2
View File
@@ -44,3 +44,5 @@ of this list.
KOBAYASHI Shuji
RIZAL Reckordp
Rory O'Connell
John Bampton
Seeker
+1
View File
@@ -0,0 +1 @@
* @matz
+4 -12
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 function return value:
```C
int
main(void)
{
...
}
```
### Ruby code
@@ -72,5 +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.
+3 -3
View File
@@ -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
+4 -16
View File
@@ -17,7 +17,7 @@ of the Ministry of Economy, Trade and Industry of Japan.
## How to get mruby
The preview version 3.0.0 of mruby can be downloaded via the following URL: [https://github.com/mruby/mruby/archive/3.0.0-preview.zip](https://github.com/mruby/mruby/archive/3.0.0-preview.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)
@@ -38,22 +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.
## How to Build
To build mruby, execute the following from the project's root directory.
$ rake TARGET=<target> test
The default `TARGET` is `host`. `TARGET` will be loaded from `target` directory.
Note: `bison` bundled with MacOS is too old to compile `mruby`.
Try `brew install bison` and follow the instuction shown to update
the `$PATH` to compile `mruby`.
## Building documentation
There are two sets of documentation in mruby: the mruby API (generated by yard) and C API (Doxygen)
@@ -98,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 -248
View File
@@ -10,17 +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
if ENV['MRUBY_CONFIG']
MRUBY_CONFIG = ENV['MRUBY_CONFIG']
MRUBY_TARGET = File.basename(MRUBY_CONFIG, ".rb")
else
MRUBY_TARGET = ENV['MRUBY_TARGET'] || ENV['TARGET'] || "host"
MRUBY_CONFIG = "#{MRUBY_ROOT}/target/#{MRUBY_TARGET}.rb"
end
MRUBY_CONFIG = MRuby::Build.mruby_config_path
load MRUBY_CONFIG
# load basic rules
@@ -29,272 +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"
if MRuby.targets['host']
target = MRuby.targets['host']
depfiles = target.bins.map do |bin|
install_path = target.exefile("#{bin_path}/#{bin}")
source_path = target.exefile("#{target.build_dir}/bin/#{bin}")
file install_path => source_path do |t|
install_D t.prerequisites.first, t.name
end
install_path
end
else
depfiles = []
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 ]
else
depfiles += [ exec ]
end
end
end
end
mkdir_p "#{MRUBY_ROOT}/build"
cfiles = (
Dir.glob("#{MRUBY_ROOT}/src/*.c")+
Dir.glob("#{MRUBY_ROOT}/mrbgems/**/*.c")+
Dir.glob("#{MRUBY_ROOT}/build/repos/**/{src,core}/*.c")
).uniq
rbfiles = (
Dir.glob("#{MRUBY_ROOT}/mrblib/**/*.rb")+
Dir.glob("#{MRUBY_ROOT}/mrbgems/*/mrblib/**/*.rb")+
Dir.glob("#{MRUBY_ROOT}/build/repos/**/mrblib/**/*.rb")
).uniq
psfiles = Dir.glob("#{MRUBY_ROOT}/{mrblib,mrbgems,build/repos}/**/presym")
symbols = []
psfiles.each do |file|
symbols += File.readlines(file).grep_v(/^# /)
end
symbols.each{|x| x.chomp!}
presym_file="#{MRUBY_ROOT}/build/presym"
op_table = {
"!" => "not",
"!=" => "neq",
"!~" => "nmatch",
"%" => "mod",
"&" => "and",
"&&" => "andand",
"*" => "mul",
"**" => "pow",
"+" => "add",
"+@" => "plus",
"-" => "sub",
"-@" => "minus",
"/" => "div",
"<" => "lt",
"<=" => "le",
"<<" => "lshift",
"<=>" => "cmp",
"==" => "eq",
"===" => "eqq",
"=~" => "match",
">" => "gt",
">=" => "ge",
">>" => "rshift",
"[]" => "aref",
"[]=" => "aset",
"^" => "xor",
"`" => "tick",
"|" => "or",
"||" => "oror",
"~" => "neg",
}
file presym_file => cfiles+rbfiles+psfiles+[__FILE__] do
csymbols = cfiles.map do |f|
src = File.read(f)
src.gsub!(/\/\/.+(\n|$)/, "\n")
[src.scan(/intern_lit\([^\n"]*"([^\n "]*)"/),
src.scan(/mrb_define_method\([^\n"]*"([^\n"]*)"/),
src.scan(/mrb_define_class_method\([^\n"]*"([^\n"]*)"/),
src.scan(/mrb_define_class\([^\n"]*"([^\n"]*)"/),
src.scan(/mrb_define_module\([^\n"]*"([^\n"]*)"/),
src.scan(/mrb_define_module_function\([^\n"]*"([^\n"]*)"/),
src.scan(/mrb_define_const\([^\n"]*"([^\n"]*)"/),
src.scan(/mrb_define_global_const\([^\n"]*"([^\n"]*)"/),
src.scan(/MRB_SYM\((\w+)\)/),
src.scan(/MRB_QSYM\((\w+)\)/).map{|x,|
x.sub!(/_p$/, "?") || x.sub!(/_b$/, "!") || x.sub!(/_e$/, "=") || x.sub!(/^0_/, "@") || x.sub!(/^00_/, "@@")
}.compact]
end
rbsymbols = rbfiles.map do |f|
src = File.read(f)
src.force_encoding(Encoding::BINARY)
[src.scan(/\bclass +([A-Z]\w*)/),
src.scan(/\bmodule +([A-Z]\w*)/),
src.scan(/\bdef +(\w+[!?=]?)/),
src.scan(/\balias +(\w+[!?]?)/),
src.scan(/\b([A-Z]\w*) *=[^=]/),
src.scan(/(\$[a-zA-Z_]\w*)/),
src.scan(/(\$[$!?0-9]\w*)/),
src.scan(/(@@?[a-zA-Z_]\w*)/),
src.scan(/[^.]\.([a-zA-Z_]\w*[!?]?)/),
src.scan(/\.([a-zA-Z_]\w* *=)/).map{|x|x.map{|s|s.gsub(' ', '')}},
src.scan(/\b([a-zA-Z_]\w*):/),
src.scan(/:([a-zA-Z_]\w*[!?=]?)/),
src.scan(/[\(\[\{ ]:"([^"]+)"/).map{|x|x.map{|s|s.gsub('\#', '#')}},
src.scan(/[ \(\[\{]:'([^']+)'/)
]
end
symbols = (symbols+csymbols+rbsymbols+op_table.keys).flatten.compact.uniq.sort.map{|x| x.gsub("\n", '\n')}
presyms = File.readlines(presym_file) rescue []
presyms.each{|x| x.chomp!}
if presyms != symbols
File.write(presym_file, symbols.join("\n"))
end
end
presym_inc=presym_file+".inc"
file presym_inc => presym_file do
presyms = File.readlines(presym_file)
presyms.each{|x| x.chomp!}
File.open(presym_inc, "w") do |f|
f.print "/* MRB_PRESYM_CSYM(sym, num) - symbol which is valid C id name */\n"
f.print "/* MRB_PRESYM_QSYM(name, sym, num) - symbol with alias name */\n"
f.print "/* MRB_PRESYM_SYM(name, num) - symbol which is not valid C id */\n"
presyms.each.with_index do |sym,i|
if sym.bytes.detect{|x|x>0x80} || /\A\$/ =~ sym
f.print "MRB_PRESYM_SYM(\"#{sym}\", #{i+1})\n"
elsif /\A\w+\Z/ =~ sym
f.print "MRB_PRESYM_CSYM(#{sym}, #{i+1})\n"
elsif op_table.key?(sym)
f.print "MRB_PRESYM_QSYM(\"#{sym}\", #{op_table[sym]}, #{i+1})\n"
elsif /\A[A-Za-z_]\w*\?\Z/ =~ sym
s = sym.dup; s[-1] = "_p"
f.print "MRB_PRESYM_QSYM(\"#{sym}\", #{s}, #{i+1})\n"
elsif /\A[A-Za-z_]\w*\!\Z/ =~ sym
s = sym.dup; s[-1] = "_b"
f.print "MRB_PRESYM_QSYM(\"#{sym}\", #{s}, #{i+1})\n"
elsif /\A[A-Za-z_]\w*\=\Z/ =~ sym
s = sym.dup; s[-1] = "_e"
f.print "MRB_PRESYM_QSYM(\"#{sym}\", #{s}, #{i+1})\n"
elsif /\A@@/ =~ sym
s = sym.dup; s[0,2] = "00_"
f.print "MRB_PRESYM_QSYM(\"#{sym}\", #{s}, #{i+1})\n"
elsif /\A@/ =~ sym
s = sym.dup; s[0] = "0_"
f.print "MRB_PRESYM_QSYM(\"#{sym}\", #{s}, #{i+1})\n"
else
f.print "MRB_PRESYM_SYM(\"#{sym}\", #{i+1})\n"
end
end
f.print "#define MRB_PRESYM_MAX #{presyms.size}"
end
end
desc "preallocated symbols"
task :gensym => presym_inc
task :all => :gensym
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
rm_f presym_file
rm_f presym_inc
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
+3 -4
View File
@@ -40,7 +40,6 @@ init:
build_script:
- set MRUBY_TARGET=appveyor
- rake gensym
- rake -m all
- rake -E $stdout.sync=true test
- set MRUBY_CONFIG=ci/msvc
- rake -m test:build
- rake test:run
+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
+9
View File
@@ -0,0 +1,9 @@
# The default build configuration file was moved to `build_config/default.rb`.
#
# 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,5 +1,5 @@
# 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|
@@ -31,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,5 +1,5 @@
# 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 -2
View File
@@ -17,9 +17,8 @@ MRuby::CrossBuild.new("RX630") do |conf|
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
+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,5 +1,5 @@
# 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)
#
@@ -28,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_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,7 +25,7 @@ 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)
@@ -33,7 +34,7 @@ MRuby::Build.new('cxx_abi') do |conf|
end
conf.enable_test
enable_cxx_abi
conf.enable_cxx_abi
build_mrbc_exec
conf.build_mrbc_exec
end
@@ -1,11 +1,13 @@
STDOUT.sync = STDERR.sync = true unless Rake.application.options.always_multitask
def setup_option(conf)
conf.cc.flags[0].delete("/Zi") unless ENV['CFLAGS']
conf.cxx.flags[0].delete("/Zi") unless ENV['CFLAGS'] || ENV['CXXFLAGS']
conf.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|
toolchain :visualcpp
conf.toolchain :visualcpp
# include all core GEMs
conf.gembox 'full-core'
+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
@@ -1,6 +1,6 @@
# Define cross build settings
MRuby::CrossBuild.new('cross-32bit') do |conf|
toolchain :gcc
conf.toolchain :gcc
conf.cc.flags << "-m32"
conf.linker.flags << "-m32"
+4 -10
View File
@@ -1,12 +1,6 @@
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
conf.toolchain
# Use mrbgems
# conf.gem 'examples/mrbgems/ruby_extension_example'
@@ -20,7 +14,7 @@ MRuby::Build.new do |conf|
# conf.gem :git => 'git@github.com:mattn/mruby-onig-regexp.git', :branch => 'master', :options => '-v'
# include the GEM box
conf.gembox 'full-core'
conf.gembox 'default'
# C compiler settings
# conf.cc do |cc|
@@ -76,11 +70,11 @@ MRuby::Build.new do |conf|
# exts.library = '.a'
# end
# file separetor
# file separator
# conf.file_separator = '/'
# Turn on `enable_debug` for better debugging
enable_debug
# conf.enable_debug
conf.enable_bintest
conf.enable_test
end
@@ -11,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"
@@ -37,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|
@@ -62,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
@@ -1,12 +1,11 @@
MRuby::Build.new do |conf|
toolchain :gcc
conf.toolchain
enable_debug
# include the default GEMs
conf.gembox 'full-core'
conf.gembox 'default'
# C compiler settings
conf.cc.defines = %w(MRB_ENABLE_DEBUG_HOOK)
conf.cc.defines = %w(MRB_USE_DEBUG_HOOK)
conf.enable_debug
conf.enable_cxx_abi
conf.enable_test
@@ -1,26 +1,20 @@
MRuby::Build.new('host') do |conf|
# load specific toolchain settings
conf.toolchain
# Gets set by the VS command prompts.
if ENV['VisualStudioVersion'] || ENV['VSINSTALLDIR']
toolchain :visualcpp
else
toolchain :gcc
end
enable_debug
conf.enable_debug
# include the default GEMs
conf.gembox 'full-core'
# C compiler settings
conf.cc.defines = %w(MRB_ENABLE_DEBUG_HOOK MRB_NO_BOXING)
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
enable_test
conf.enable_test
# bintest
enable_bintest
conf.enable_bintest
end
@@ -3,12 +3,12 @@ MRuby::Build.new do |conf|
toolchain :gcc
# include the GEM box
conf.gembox 'full-core'
conf.gembox 'default'
conf.cc.flags << '-pg'
conf.linker.flags << '-pg'
# Turn on `enable_debug` for better debugging
enable_debug
conf.enable_debug
conf.enable_test
end
@@ -3,13 +3,13 @@ MRuby::Build.new do |conf|
toolchain :gcc
# include the GEM box
conf.gembox 'full-core'
conf.gembox 'default'
conf.cc.flags << '-m32'
conf.linker.flags << '-m32'
# Turn on `enable_debug` for better debugging
enable_debug
conf.enable_debug
conf.enable_test
conf.enable_bintest
end
@@ -26,11 +26,11 @@ MRuby::Build.new do |conf|
exts.library = '.so'
end
# file separetor
# file separator
# conf.file_separator = '/'
# Turn on `enable_debug` for better debugging
enable_debug
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
+101 -49
View File
@@ -6,58 +6,50 @@ binaries.
## Prerequisites
To compile mruby out of the source code you need the following tools:
* C Compiler (e.g. `gcc` or `clang`)
* Linker (e.g. `gcc` or `clang`)
* Archive utility (e.g. `ar`)
* Parser generator (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 instuction shown to update
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)
* C++ compiler (to use GEMs which include \*.cpp, \*.cxx, \*.cc)
* Assembler (to use GEMs which include \*.asm)
## Build
To compile `mruby`, 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`.
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`.
If you want to compile for the specific configuration, specify
`MRUBY_TARGET` or `TARGET` environment variable, e.g
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.
```sh
rake TAGRET=host
```
The default target is `host`. The compilation target desciption files
(with `.rb` suffix) are contained in the `target` directory.
A build description file contains the build configuration of mruby and
looks like the following for example:
Those build configuration files contain the build configuration of mruby, 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 try different configuration, you can create a new
configuration file under `target` and specify the configuration using
the `MRUBY_TARGET` environment variable.
All tools necessary to compile mruby can be set or modified here.
## Build Configuration
To create a new configuration, copy the existing configuration in the
`target` directory, and modify it. We wish you submit a pull-request,
once you created a new configuration for a new platform.
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.
@@ -70,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
@@ -104,7 +100,7 @@ in `ANDROID_STANDALONE_TOOLCHAIN`.
### Binaries
It is possible to select which tools should be compiled during the compilation
process. For example,
process. For example,
* `mruby`
* `mirb`
@@ -115,6 +111,7 @@ The configuration are done via `mrbgems`. See `Mrbgems` section.
Some environments require a different file separator character. It is possible to
set the character via `conf.file_separator`.
```ruby
conf.file_separator = '/'
```
@@ -122,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 = ...
@@ -137,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.
@@ -145,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.
@@ -158,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
@@ -167,6 +168,7 @@ end
### Linker
Configuration of the Linker binary, flags and library paths.
```ruby
conf.linker do |linker|
linker.command = ...
@@ -184,6 +186,7 @@ end
### Archiver
Configuration of the Archiver binary and flags.
```ruby
conf.archiver do |archiver|
archiver.command = ...
@@ -194,6 +197,7 @@ end
### Parser Generator
Configuration of the Parser Generator binary and flags.
```ruby
conf.yacc do |yacc|
yacc.command = ...
@@ -204,6 +208,7 @@ end
### GPerf
Configuration of the GPerf binary and flags.
```ruby
conf.gperf do |gperf|
gperf.command = ...
@@ -212,6 +217,7 @@ end
```
### File Extensions
```ruby
conf.exts do |exts|
exts.object = ...
@@ -220,6 +226,15 @@ 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
`mruby` comes with the (sort of) packaging system named `mrbgems`. To
@@ -256,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
```
@@ -268,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
```
@@ -286,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
```
@@ -295,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`.
@@ -317,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
@@ -356,10 +380,6 @@ root directory. The structure of this directory will look like this:
+- build
|
+- presym <- List of preallocated symbolx
|
+- presym.inc <- C source file for preallocated symbols
|
+- host
|
+- bin <- Binaries (mirb, mrbc and mruby)
@@ -381,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
@@ -411,10 +432,6 @@ In case of a cross-compilation to *i386* the *build* directory structure looks
like this:
+- build
|
+- presym <- List of preallocated symbolx
|
+- presym.inc <- C source file for preallocated symbols
|
+- host
| |
@@ -462,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
@@ -511,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
```
@@ -527,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`
```
+4 -3
View File
@@ -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
+40 -13
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_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`
* 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_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`
* Disable method cache to save memory.
`MRB_METHOD_CACHE_SIZE`
* Default value is `256`.
* Ignored if `MRB_NO_METHOD_CACHE` is defined.
* Need to be the power of 2.
`MRB_USE_METHOD_T_STRUCT`
* Use C struct to represent `mrb_method_t`
* No `MRB_USE_METHOD_T_STRUCT` requires highest 2 bits of function pointers to be zero
* Define this macro on machines that use higher bits of pointers
`MRB_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.
+3 -10
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 `Integer`
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.
@@ -72,6 +63,7 @@ rescue => e
raise e
end
```
## Fiber execution can't cross C function boundary
mruby's `Fiber` is implemented in a similar way to Lua's co-routine. This
@@ -252,7 +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.
to make the behavior simpler and less confusing.
#### Ruby [ruby 2.5.1p57 (2018-03-29 revision 63029)]
@@ -290,6 +282,7 @@ Ruby outputs `falsy`. mruby outputs `truthy`.
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
+104 -49
View File
@@ -3,84 +3,73 @@ User visible changes in `mruby3`
# Build System
You can specify `TARGET` option to `rake` via a command line
option, or via an environment variable, e.g.
## `build_config` directory
`rake TARGET=host all`
or
`TARGET=host rake all`
It's much easier to switch multiple targets than the
previous `build_config.rb` system.
## `presym` target
The first compilation of `mruby` may require generation of a
static symbol table named `build/presym`. You can generate
the table by `rake gensym`.
## `target` directory
Build target specification files are loaded from `target`
directory. The default `TARGET` is `host` which is described
in `target/host.rb`. There are many other targets for example:
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
`target/host.rb` comes with comments to help writing a new
target description.
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.
If you want to have your target description out of the
source tree, you can specify the path to the description
file in `MRUBY_CONFIG`.
# Build Configuration Contribution
# Build Target Contribution
When you write a new target description, please
When you write a new build configuration description, please
contribute. We welcome your contribution as a GitHub
pull-request.
# Languge Changes
# Language Changes
## New Syntax
We have ported some new syntax from CRuby.
* R-assignment (`12 => x`)
* 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
Some configuration macro names are changed for consistency
## Renamed for consistency
## `MRB_NO_FLOAT`
Some configuration macro names are changed for consistency (use `MRB_USE_XXX`
or `MRB_NO_XXX`).
Changed from `MRB_WITHOUT_FLOAT` to conform `USE_XXX` naming
convention.
| 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`
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`
Changed from `MRB_METHOD_T_STRUCT`.
To use `struct` version of `mrb_method_t`. More portable but consumes more memory.
Turned on by default on 32bit platforms.
* `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 inveticate the internal and to debug. It used
but easier to investigate the internal and to debug. It used
to be default `mrb_value` representation. Now the default is
`MRB_WORD_BOXING`.
@@ -101,8 +90,74 @@ changed from previous versions.
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).
+29 -31
View File
@@ -133,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
@@ -148,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
@@ -193,10 +203,6 @@
# define KHASH_DEFAULT_SIZE 16
# endif
# ifndef MRB_STR_BUF_MIN_SIZE
# define MRB_STR_BUF_MIN_SIZE 32
# endif
# ifndef MRB_HEAP_PAGE_SIZE
# define MRB_HEAP_PAGE_SIZE 256
# endif
@@ -210,10 +216,6 @@
# 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
@@ -224,10 +226,6 @@
# 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
+46 -39
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)
@@ -89,7 +93,6 @@
#include <mruby/common.h>
#include <mruby/value.h>
#include <mruby/gc.h>
#include <mruby/presym.h>
#include <mruby/version.h>
#ifndef MRB_NO_FLOAT
@@ -147,14 +150,15 @@ typedef void* (*mrb_allocf) (struct mrb_state *mrb, void*, size_t, void *ud);
typedef struct {
mrb_sym mid;
int16_t argc;
int16_t acc;
const struct RProc *proc;
mrb_value *stackent;
struct REnv *env;
const mrb_code *pc; /* return address */
const mrb_code *err; /* error position */
mrb_int argc;
mrb_int acc;
struct RClass *target_class;
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 {
@@ -169,8 +173,7 @@ 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;
@@ -265,11 +268,11 @@ 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
#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
@@ -283,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 */
@@ -889,7 +892,7 @@ MRB_API struct RClass* mrb_define_module_under_id(mrb_state *mrb, struct RClass
* | `H` | {Hash} | {mrb_value} | when `!` follows, the value may be `nil` |
* | `s` | {String} | const char *, {mrb_int} | Receive two arguments; `s!` gives (`NULL`,`0`) for `nil` |
* | `z` | {String} | const char * | `NULL` terminated string; `z!` gives `NULL` for `nil` |
* | `a` | {Array} | {mrb_value} *, {mrb_int} | Receive two arguments; `a!` gives (`NULL`,`0`) 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} | |
@@ -897,7 +900,7 @@ MRB_API struct RClass* mrb_define_module_under_id(mrb_state *mrb, struct RClass
* | `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 |
@@ -991,7 +994,7 @@ MRB_API mrb_int mrb_get_argc(mrb_state *mrb);
*
* Correctly handles *splat arguments.
*/
MRB_API mrb_value* mrb_get_argv(mrb_state *mrb);
MRB_API const mrb_value *mrb_get_argv(mrb_state *mrb);
/**
* Retrieve the first and only argument from mrb_state.
@@ -1076,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 from C string. But usually it's better to use MRB_SYM(sym) and MRB_QSYM(qsym).
* 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:
*
@@ -1086,7 +1090,7 @@ MRB_API mrb_value mrb_funcall_with_block(mrb_state *mrb, mrb_value val, mrb_sym
* // C style:
* mrb_sym sym1 = mrb_intern_lit(mrb, "pizza"); // => :pizza
* mrb_sym sym2 = MRB_SYM(pizza); // => :pizza
* mrb_sym sym3 = MRB_SYM(pizza_p); // => :pizza?
* mrb_sym sym3 = MRB_SYM_Q(pizza); // => :pizza?
*
* @param mrb The current mruby state.
* @param str The string to be symbolized
@@ -1299,27 +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_id(mrb, MRB_SYM(RuntimeError)))
#define E_TYPE_ERROR (mrb_exc_get_id(mrb, MRB_SYM(TypeError)))
#define E_ZERODIV_ERROR (mrb_exc_get_id(mrb, MRB_SYM(ZeroDivisionError)))
#define E_ARGUMENT_ERROR (mrb_exc_get_id(mrb, MRB_SYM(ArgumentError)))
#define E_INDEX_ERROR (mrb_exc_get_id(mrb, MRB_SYM(IndexError)))
#define E_RANGE_ERROR (mrb_exc_get_id(mrb, MRB_SYM(RangeError)))
#define E_NAME_ERROR (mrb_exc_get_id(mrb, MRB_SYM(NameError)))
#define E_NOMETHOD_ERROR (mrb_exc_get_id(mrb, MRB_SYM(NoMethodError)))
#define E_SCRIPT_ERROR (mrb_exc_get_id(mrb, MRB_SYM(ScriptError)))
#define E_SYNTAX_ERROR (mrb_exc_get_id(mrb, MRB_SYM(SyntaxError)))
#define E_LOCALJUMP_ERROR (mrb_exc_get_id(mrb, MRB_SYM(LocalJumpError)))
#define E_REGEXP_ERROR (mrb_exc_get_id(mrb, MRB_SYM(RegexpError)))
#define E_FROZEN_ERROR (mrb_exc_get_id(mrb, MRB_SYM(FrozenError)))
#define E_NOTIMP_ERROR (mrb_exc_get_id(mrb, MRB_SYM(NotImplementedError)))
#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_SYM(FloatDomainError)))
# define E_FLOATDOMAIN_ERROR mrb_exc_get_id(mrb, MRB_ERROR_SYM(FloatDomainError))
#endif
#define E_KEY_ERROR (mrb_exc_get_id(mrb, MRB_SYM(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);
@@ -1385,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_id(mrb, MRB_SYM(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 */
@@ -1405,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 */
+4 -4
View File
@@ -64,7 +64,7 @@ struct RArray {
#define ARY_SET_EMBED_LEN(a,len) ((a)->flags = ((a)->flags&~MRB_ARY_EMBED_MASK) | ((uint32_t)(len) + 1))
#define ARY_EMBED_PTR(a) ((a)->as.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)
#define RARRAY_LEN(a) ARY_LEN(RARRAY(a))
@@ -249,10 +249,10 @@ 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.
@@ -296,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);
+16 -6
View File
@@ -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
@@ -30,27 +32,35 @@
* In order to get enough bit size to save TT, all pointers are shifted 2 bits
* in the right direction. Also, TTTTTT is the mrb_vtype + 1;
*/
typedef uint64_t mrb_value;
typedef struct mrb_value {
uint64_t u;
} mrb_value;
union mrb_value_ {
mrb_float f;
uint64_t u;
#ifdef MRB_64BIT
void *p;
# define BOXNAN_IMMEDIATE_VALUE uint32_t i
#else
# define BOXNAN_IMMEDIATE_VALUE union { uint32_t i; void *p; }
#endif
struct {
MRB_ENDIAN_LOHI(
uint32_t ttt;
,uint32_t i;
,BOXNAN_IMMEDIATE_VALUE;
)
};
mrb_value value;
};
mrb_static_assert1(sizeof(mrb_value) == sizeof(union mrb_value_));
static inline union mrb_value_
mrb_val_union(mrb_value v)
{
union mrb_value_ x;
x.u = v;
x.value = v;
return x;
}
@@ -75,7 +85,7 @@ mrb_val_union(mrb_value v)
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.u;\
o = mrb_value_union_variable.value;\
} while (0)
#ifdef MRB_64BIT
@@ -83,7 +93,7 @@ mrb_val_union(mrb_value 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.u;\
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)
@@ -98,7 +108,7 @@ mrb_val_union(mrb_value v)
else { \
mrb_value_union_variable.f = (v); \
} \
r = mrb_value_union_variable.u; \
r = mrb_value_union_variable.value; \
} while(0)
#define SET_NIL_VALUE(r) BOXNAN_SET_VALUE(r, MRB_TT_FALSE, i, 0)
+2
View File
@@ -9,6 +9,8 @@
#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_NO_FLOAT
+32 -24
View File
@@ -7,10 +7,6 @@
#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_NO_FLOAT
struct RFloat {
MRB_OBJECT_HEADER;
@@ -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,12 +55,10 @@ 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)(((intptr_t)(o)) >> BOXWORD_##n##_SHIFT)
#define BOXWORD_SET_SHIFT_VALUE(o,n,v) \
((o) = (((uintptr_t)(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) & BOXWORD_##n##_MASK) == BOXWORD_##n##_FLAG)
(((o).w & BOXWORD_##n##_MASK) == BOXWORD_##n##_FLAG)
#define BOXWORD_OBJ_TYPE_P(o,n) \
(!mrb_immediate_p(o) && mrb_val_union(o).bp->tt == MRB_TT_##n)
@@ -71,7 +73,10 @@ 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 uintptr_t mrb_value;
typedef struct mrb_value {
uintptr_t w;
} mrb_value;
union mrb_value_ {
void *p;
#ifdef MRB_64BIT
@@ -90,13 +95,16 @@ union mrb_value_ {
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.w = v;
x.value = v;
return x;
}
@@ -106,14 +114,14 @@ 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) & BOXWORD_IMMEDIATE_MASK || (o) == MRB_Qnil)
#define mrb_immediate_p(o) ((o).w & BOXWORD_IMMEDIATE_MASK || (o).w == MRB_Qnil)
#define mrb_ptr(o) mrb_val_union(o).p
#define mrb_cptr(o) mrb_val_union(o).vp->p
#ifndef MRB_NO_FLOAT
#define mrb_float(o) mrb_val_union(o).fp->f
#endif
#define mrb_fixnum(o) BOXWORD_SHIFT_VALUE(o, FIXNUM, mrb_int)
#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);
@@ -123,9 +131,9 @@ mrb_integer_func(mrb_value o) {
#ifdef MRB_64BIT
#define mrb_symbol(o) mrb_val_union(o).sym
#else
#define mrb_symbol(o) BOXWORD_SHIFT_VALUE(o, SYMBOL, mrb_sym)
#define mrb_symbol(o) (mrb_sym)(((o).w) >> BOXWORD_SYMBOL_SHIFT)
#endif
#define mrb_bool(o) (((o) & ~(unsigned long)MRB_Qfalse) != 0)
#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))
@@ -134,10 +142,10 @@ mrb_integer_func(mrb_value o) {
#else
#define mrb_symbol_p(o) BOXWORD_SHIFT_VALUE_P(o, SYMBOL)
#endif
#define mrb_undef_p(o) ((o) == MRB_Qundef)
#define mrb_nil_p(o) ((o) == MRB_Qnil)
#define mrb_false_p(o) ((o) == MRB_Qfalse)
#define mrb_true_p(o) ((o) == MRB_Qtrue)
#define mrb_undef_p(o) ((o).w == MRB_Qundef)
#define mrb_nil_p(o) ((o).w == MRB_Qnil)
#define mrb_false_p(o) ((o).w == MRB_Qfalse)
#define mrb_true_p(o) ((o).w == MRB_Qtrue)
#ifndef MRB_NO_FLOAT
#define mrb_float_p(o) BOXWORD_OBJ_TYPE_P(o, FLOAT)
#endif
@@ -164,10 +172,10 @@ mrb_integer_func(mrb_value o) {
#define SET_FLOAT_VALUE(mrb,r,v) ((r) = mrb_word_boxing_float_value(mrb, v))
#endif
#define SET_CPTR_VALUE(mrb,r,v) ((r) = mrb_word_boxing_cptr_value(mrb, v))
#define SET_UNDEF_VALUE(r) ((r) = MRB_Qundef)
#define SET_NIL_VALUE(r) ((r) = MRB_Qnil)
#define SET_FALSE_VALUE(r) ((r) = MRB_Qfalse)
#define SET_TRUE_VALUE(r) ((r) = MRB_Qtrue)
#define SET_UNDEF_VALUE(r) ((r).w = MRB_Qundef)
#define SET_NIL_VALUE(r) ((r).w = MRB_Qnil)
#define SET_FALSE_VALUE(r) ((r).w = MRB_Qfalse)
#define SET_TRUE_VALUE(r) ((r).w = MRB_Qtrue)
#define SET_BOOL_VALUE(r,b) ((b) ? SET_TRUE_VALUE(r) : SET_FALSE_VALUE(r))
#define SET_INT_VALUE(mrb,r,n) ((r) = mrb_word_boxing_int_value(mrb, n))
#define SET_FIXNUM_VALUE(r,n) BOXWORD_SET_SHIFT_VALUE(r, FIXNUM, n)
@@ -176,12 +184,12 @@ mrb_integer_func(mrb_value o) {
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.w;\
(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) = (uintptr_t)v)
#define SET_OBJ_VALUE(r,v) ((r).w = (uintptr_t)(v))
MRB_INLINE enum mrb_vtype
mrb_type(mrb_value o)
+1 -2
View File
@@ -100,8 +100,7 @@ void mrb_mc_clear_by_class(mrb_state *mrb, struct RClass* c);
#endif
/* return non zero to break the loop */
struct mt_elem;
typedef int (mrb_mt_foreach_func)(mrb_state*,mrb_sym,struct mt_elem*,void*);
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
+1 -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
+10 -5
View File
@@ -99,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;
@@ -115,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;
@@ -173,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*);
@@ -181,8 +185,8 @@ 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
* Please note! Currently due to interactions with the GC calling these functions will
/** 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
@@ -190,9 +194,10 @@ MRB_API mrb_value mrb_load_exec(mrb_state *mrb, struct mrb_parser_state *p, mrbc
* mrb_value status = mrb_load_string(mrb, buffer);
* mrb_gc_arena_restore(mrb, ai);
*/
#ifndef MRB_DISABLE_STDIO
#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, const 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, const mrb_irep *irep, size_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(
+5 -11
View File
@@ -19,7 +19,7 @@ MRB_BEGIN_DECL
#define DUMP_DEBUG_INFO 1
int mrb_dump_irep(mrb_state *mrb, const mrb_irep *irep, uint8_t flags, uint8_t **bin, size_t *bin_size);
#ifndef MRB_DISABLE_STDIO
#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);
@@ -39,10 +39,9 @@ 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
@@ -52,7 +51,7 @@ MRB_API mrb_irep *mrb_read_irep_buf(mrb_state*, const void*, size_t);
/* Binary Format Version Major:Minor */
/* Major: Incompatible to prior versions */
/* Minor: Upper-compatible to prior versions */
#define RITE_BINARY_MAJOR_VER "01"
#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"
@@ -73,7 +72,6 @@ struct rite_binary_header {
uint8_t binary_ident[4]; /* Binary Identifier */
uint8_t major_version[2]; /* Binary Format Major Version */
uint8_t minor_version[2]; /* Binary Format Minor Version */
uint8_t binary_crc[2]; /* Binary CRC */
uint8_t binary_size[4]; /* Binary Size */
uint8_t compiler_name[4]; /* Compiler name */
uint8_t compiler_version[4];
@@ -157,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 */
+1 -1
View File
@@ -24,7 +24,7 @@ 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_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_str_lit(mrb, c, 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 -13
View File
@@ -14,16 +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_os_memsize_of_hash_table(mrb_value obj);
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);
@@ -179,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.
@@ -198,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_SYM(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*);
+14 -7
View File
@@ -31,10 +31,12 @@ typedef struct mrb_pool_value {
union {
const char *str;
int32_t i32;
#ifdef MRB_64BIT
#if defined(MRB_64BIT) || defined(MRB_INT64)
int64_t i64;
#endif
#ifndef MRB_NO_FLOAT
mrb_float f;
#endif
} u;
} mrb_pool_value;
@@ -45,9 +47,9 @@ enum mrb_catch_type {
struct mrb_irep_catch_handler {
uint8_t type; /* enum mrb_catch_type */
uint8_t begin[2]; /* The starting address to match the hander. Includes this. */
uint8_t end[2]; /* The endpoint address that matches the hander. Not Includes this. */
uint8_t target[2]; /* The address to jump to if a match is made. */
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 */
@@ -71,8 +73,10 @@ typedef struct mrb_irep {
/* 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
@@ -119,7 +123,7 @@ 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);
@@ -135,6 +139,9 @@ mrb_irep_catch_handler_table(const struct mrb_irep *irep)
}
}
#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 */
+1 -1
View File
@@ -91,7 +91,7 @@ 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) \
mrb_noreturn void mrb_raise_nomemory(mrb_state *mrb); \
+24 -50
View File
@@ -70,93 +70,67 @@ 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 < 0) {
if (multiplicand < MRB_INT_MAX / multiplier) return TRUE;
}
}
else if (multiplier < 0) {
if (multiplicand > 0) {
if (multiplier < MRB_INT_MAX / multiplicand) return TRUE;
}
else if (multiplicand < 0) {
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
+1
View File
@@ -36,6 +36,7 @@ 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)
+24 -14
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) */
@@ -26,7 +28,9 @@ 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 */
@@ -45,10 +49,10 @@ 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(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)) */
@@ -57,13 +61,14 @@ 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) */
@@ -89,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*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)) */
+28 -13
View File
@@ -7,19 +7,34 @@
#ifndef MRUBY_PRESYM_H
#define MRUBY_PRESYM_H
#undef MRB_PRESYM_MAX
#define MRB_PRESYM_CSYM(sym, num) MRB_PRESYM__##sym = (num<<1),
#define MRB_PRESYM_QSYM(str, sym, num) MRB_PRESYM_q_##sym = (num<<1),
#define MRB_PRESYM_SYM(sym, num)
#if defined(MRB_NO_PRESYM)
# include <mruby/presym/disable.h>
#elif !defined(MRB_PRESYM_SCANNING)
# include <mruby/presym/enable.h>
#endif
enum mruby_presym {
#include <../build/presym.inc>
};
/*
* 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`.
*/
#undef MRB_PRESYM_CSYM
#undef MRB_PRESYM_QSYM
#undef MRB_PRESYM_SYM
#define MRB_SYM(sym) MRB_PRESYM__##sym
#define MRB_QSYM(sym) MRB_PRESYM_q_##sym
#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 */
+70 -3
View File
@@ -105,7 +105,7 @@ MRB_API mrb_value mrb_proc_cfunc_env_get(mrb_state *mrb, mrb_int idx);
#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))
@@ -117,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)
@@ -133,10 +133,77 @@ MRB_API mrb_value mrb_proc_cfunc_env_get(mrb_state *mrb, mrb_int idx);
#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
#endif /* MRUBY_PROC_H */
+5 -5
View File
@@ -159,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:
*
@@ -339,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);
/**
@@ -433,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)).
*
+6 -3
View File
@@ -7,13 +7,13 @@
#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)
#if defined(MRB_USE_CXX_EXCEPTION)
# if defined(__cplusplus)
@@ -35,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
@@ -52,7 +55,7 @@ typedef mrb_int mrb_jmpbuf_impl;
struct mrb_jmpbuf {
mrb_jmpbuf_impl impl;
#if defined(MRB_ENABLE_CXX_EXCEPTION)
#if defined(MRB_USE_CXX_EXCEPTION)
static mrb_int jmpbuf_id;
# if defined(__cplusplus)
mrb_jmpbuf() : impl(jmpbuf_id++) {}
+3 -8
View File
@@ -53,21 +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
# define MRB_INT_MAX INT64_MAX
# define MRB_FIXNUM_MIN (INT64_MIN>>MRB_FIXNUM_SHIFT)
# define MRB_FIXNUM_MAX (INT64_MAX>>MRB_FIXNUM_SHIFT)
# 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
# define MRB_INT_MAX INT32_MAX
# define MRB_FIXNUM_MIN (INT32_MIN>>MRB_FIXNUM_SHIFT)
# define MRB_FIXNUM_MAX (INT32_MAX>>MRB_FIXNUM_SHIFT)
# define MRB_PRIo PRIo32
# define MRB_PRId PRId32
# define MRB_PRIx PRIx32
@@ -170,12 +168,9 @@ struct RCptr {
#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
+1 -1
View File
@@ -35,7 +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_state*, 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);
+22 -3
View File
@@ -49,6 +49,24 @@ MRB_BEGIN_DECL
*/
#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 10
#define MRUBY_RELEASE_MONTH 2
/*
* Release day.
*/
#define MRUBY_RELEASE_DAY 16
#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 ")" \
/*
+195 -56
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,9 +108,12 @@ module MRuby
@git = Command::Git.new(self)
@mrbc = Command::Mrbc.new(self)
@products = []
@bins = []
@gems = MRuby::Gem::List.new
@libmruby_objs = []
@libmruby_core_objs = []
@libmruby_objs = [@libmruby_core_objs]
@enable_libmruby = true
@build_mrbtest_lib_only = false
@cxx_exception_enabled = false
@cxx_exception_disabled = false
@@ -90,16 +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
current = MRuby.targets[@name]
MRuby::Build.current = current
current.instance_eval(&block)
current.build_mrbtest if current.test_enabled?
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
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,25 +258,20 @@ 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
def enable_bintest
raise "bintest works only on 'host' target" unless name == "host"
@enable_bintest = true
end
@@ -204,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"
@@ -227,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
@@ -247,11 +319,22 @@ EOS
def mrbcfile
return @mrbcfile if @mrbcfile
unless gems.detect {|v| v.name == 'mruby-bin-mrbc' }
build_mrbc_exec
gems.detect {|v| v.name == 'mruby-bin-mrbc' }.setup
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 = self.exefile("#{self.build_dir}/bin/mrbc")
@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
@@ -261,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)
@@ -329,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
@@ -362,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
@@ -372,25 +511,21 @@ EOS
attr_accessor :host_target, :build_target
def initialize(name, build_dir=nil, &block)
unless MRuby.targets['host']
# add minimal 'host'
MRuby::Build.new('host') do |conf|
if ENV['VisualStudioVersion'] || ENV['VSINSTALLDIR']
toolchain :visualcpp
else
toolchain :gcc
end
conf.gem :core => 'mruby-bin-mrbc'
end
end
@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
host = MRuby.targets['host']
host.exefile("#{host.build_dir}/bin/mrbc")
mrbcfile_external? ? super : MRuby::targets['host'].mrbcfile
end
def run_test
@@ -403,5 +538,9 @@ EOS
@test_runner.run(mrbtest)
end
end
protected
def create_mrbc_build; end
end # CrossBuild
end # MRuby
+39 -24
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 ] : []
@@ -150,10 +157,10 @@ module MRuby
# /src/value_array.h:
#
def get_dependencies(file)
file = file.ext('d') unless File.extname(file) == '.d'
return [MRUBY_CONFIG] unless File.exist?(file)
dep_file = file.ext(".d")
return [MRUBY_CONFIG] unless object_ext?(file) && File.exist?(dep_file)
deps = File.read(file).gsub("\\\n ", "").split("\n").map do |dep_line|
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 ..."
# - ""
@@ -165,6 +172,10 @@ module MRuby
end.flatten.uniq
deps << MRUBY_CONFIG
end
def object_ext?(path)
File.extname(path) == build.exts.object
end
end
class Command::Linker < Command
@@ -194,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 }
@@ -316,8 +331,8 @@ module MRuby
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}" #{cdump ? "-S" : ""} #{@compile_options % {:funcname => funcname}} #{filename(infiles).map{|f| %Q["#{f}"]}.join(' ')}]
puts cmd if Rake.verbose
@@ -325,9 +340,9 @@ module MRuby
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
+5 -4
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
@@ -35,9 +38,7 @@ module MRuby
current.build_config_initializer = block
gems << current
cxx_srcs = ['src', 'test', 'tools'].map do |subdir|
Dir.glob("#{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?
current
@@ -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
+71 -37
View File
@@ -7,7 +7,6 @@ module MRuby
class << self
attr_accessor :current
end
LinkerConfig = Struct.new(:libraries, :library_paths, :flags, :flags_before_libraries, :flags_after_libraries)
class Specification
include Rake::DSL
@@ -17,7 +16,6 @@ module MRuby
attr_accessor :name, :dir, :build
alias mruby build
attr_accessor :build_config_initializer
attr_accessor :mrblib_dir, :objs_dir
attr_accessor :version
attr_accessor :description, :summary
@@ -27,8 +25,8 @@ module MRuby
alias :author= :authors=
attr_accessor :rbfiles, :objs
attr_accessor :test_objs, :test_rbfiles, :test_args
attr_accessor :test_preload
attr_writer :test_objs, :test_rbfiles
attr_accessor :test_args, :test_preload
attr_accessor :bins
@@ -45,36 +43,28 @@ module MRuby
@name = name
@initializer = block
@version = "0.0.0"
@mrblib_dir = "mrblib"
@objs_dir = "src"
@dependencies = []
@conflicts = []
MRuby::Gem.current = self
end
def setup
return if defined?(@linker) # return if already set up
return if defined?(@bins) # return if already set up
MRuby::Gem.current = self
MRuby::Build::COMMANDS.each do |command|
instance_variable_set("@#{command}", @build.send(command).clone)
end
@linker = LinkerConfig.new([], [], [], [], [])
@linker.run_attrs.each(&:clear)
@rbfiles = Dir.glob("#{@dir}/#{@mrblib_dir}/**/*.rb").sort
@objs = Dir.glob("#{@dir}/#{@objs_dir}/*.{c,cpp,cxx,cc,m,asm,s,S}").map do |f|
objfile(f.relative_path_from(@dir).to_s.pathmap("#{build_dir}/%X"))
end
@rbfiles = Dir.glob("#{@dir}/mrblib/**/*.rb").sort
@objs = srcs_to_objs("src")
@test_rbfiles = Dir.glob("#{dir}/test/**/*.rb").sort
@test_objs = Dir.glob("#{dir}/test/*.{c,cpp,cxx,cc,m,asm,s,S}").map do |f|
objfile(f.relative_path_from(dir).to_s.pathmap("#{build_dir}/%X"))
end
@custom_test_init = !@test_objs.empty?
@test_preload = nil # 'test/assert.rb'
@test_args = {}
@bins = []
@cdump = true
@requirements = []
@export_include_paths = []
@@ -98,10 +88,11 @@ module MRuby
end
def setup_compilers
compilers.each do |compiler|
compiler.define_rules build_dir, "#{dir}"
(core? ? [@cc, *(@cxx if build.cxx_exception_enabled?)] : compilers).each do |compiler|
compiler.define_rules build_dir, @dir, @build.exts.presym_preprocessed if build.presym_enabled?
compiler.define_rules build_dir, @dir, @build.exts.object
compiler.defines << %Q[MRBGEM_#{funcname.upcase}_VERSION=#{version}]
compiler.include_paths << "#{dir}/include" if File.directory? "#{dir}/include"
compiler.include_paths << "#{@dir}/include" if File.directory? "#{@dir}/include"
end
define_gem_init_builder if @generate_functions
@@ -116,6 +107,18 @@ module MRuby
return false
end
def disable_cdump
@cdump = false
end
def cdump?
build.presym_enabled? && @cdump
end
def core?
@dir.start_with?("#{MRUBY_ROOT}/mrbgems/")
end
def add_dependency(name, *requirements)
default_gem = requirements.last.kind_of?(Hash) ? requirements.pop : nil
requirements = ['>= 0.0.0'] if requirements.empty?
@@ -139,6 +142,14 @@ module MRuby
"#{build_dir}/gem_test.c"
end
def test_objs
@test_objs ||= srcs_to_objs("test")
end
def test_rbfiles
@test_rbfiles ||= Dir["#{@dir}/test/**/*.rb"].sort!
end
def search_package(name, version_query=nil)
package_query = name
package_query += " #{version_query}" if version_query
@@ -164,8 +175,14 @@ module MRuby
end
end
def srcs_to_objs(src_dir_from_gem_dir)
exts = compilers.flat_map{|c| c.source_exts} * ","
Dir["#{@dir}/#{src_dir_from_gem_dir}/*{#{exts}}"].map do |f|
objfile(f.relative_path_from(@dir).to_s.pathmap("#{build_dir}/%X"))
end
end
def define_gem_init_builder
file objfile("#{build_dir}/gem_init") => [ "#{build_dir}/gem_init.c", File.join(dir, "mrbgem.rake") ]
file "#{build_dir}/gem_init.c" => [build.mrbcfile, __FILE__] + [rbfiles].flatten do |t|
mkdir_p build_dir
generate_gem_init("#{build_dir}/gem_init.c")
@@ -173,25 +190,36 @@ module MRuby
end
def generate_gem_init(fname)
_pp "GEN", fname.relative_path
open(fname, 'w') do |f|
print_gem_init_header f
build.mrbc.run f, rbfiles, "gem_mrblib_#{funcname}_proc" unless rbfiles.empty?
unless rbfiles.empty?
if cdump?
build.mrbc.run f, rbfiles, "gem_mrblib_#{funcname}_proc"
else
build.mrbc.run f, rbfiles, "gem_mrblib_irep_#{funcname}", false
end
end
f.puts %Q[void mrb_#{funcname}_gem_init(mrb_state *mrb);]
f.puts %Q[void mrb_#{funcname}_gem_final(mrb_state *mrb);]
f.puts %Q[]
f.puts %Q[void GENERATED_TMP_mrb_#{funcname}_gem_init(mrb_state *mrb) {]
f.puts %Q[ int ai = mrb_gc_arena_save(mrb);]
f.puts %Q[ struct REnv *e;] unless rbfiles.empty?
f.puts %Q[ gem_mrblib_#{funcname}_proc_init_syms(mrb);] if !rbfiles.empty? && cdump?
f.puts %Q[ mrb_#{funcname}_gem_init(mrb);] if objs != [objfile("#{build_dir}/gem_init")]
unless rbfiles.empty?
f.puts %Q[ mrb_load_proc(mrb, gem_mrblib_#{funcname}_proc);]
if cdump?
f.puts %Q[ mrb_load_proc(mrb, gem_mrblib_#{funcname}_proc);]
else
f.puts %Q[ mrb_load_irep(mrb, gem_mrblib_irep_#{funcname});]
end
f.puts %Q[ if (mrb->exc) {]
f.puts %Q[ mrb_print_error(mrb);]
f.puts %Q[ mrb_close(mrb);]
f.puts %Q[ exit(EXIT_FAILURE);]
f.puts %Q[ }]
f.puts %Q[ e = mrb->c->cibase->env;]
f.puts %Q[ mrb->c->cibase->env = NULL;]
f.puts %Q[ struct REnv *e = mrb_vm_ci_env(mrb->c->cibase);]
f.puts %Q[ mrb_vm_ci_env_set(mrb->c->cibase, NULL);]
f.puts %Q[ mrb_env_unshare(mrb, e);]
end
f.puts %Q[ mrb_gc_arena_restore(mrb, ai);]
@@ -216,12 +244,14 @@ module MRuby
def print_gem_init_header(f)
print_gem_comment(f)
unless rbfiles.empty?
f.puts %Q[#include <stdlib.h>]
if rbfiles.empty?
f.puts %Q[#include <mruby.h>]
f.puts %Q[#include <mruby/proc.h>]
else
f.puts %Q[#include <mruby.h>]
f.puts %Q[#include <stdlib.h>]
unless build.presym_enabled?
f.puts %Q[#include <mruby.h>]
f.puts %Q[#include <mruby/proc.h>]
end
end
end
@@ -230,17 +260,13 @@ module MRuby
f.puts %Q[#include <stdio.h>]
f.puts %Q[#include <stdlib.h>]
f.puts %Q[#include <mruby.h>]
f.puts %Q[#include <mruby/proc.h>]
f.puts %Q[#include <mruby/irep.h>]
f.puts %Q[#include <mruby/variable.h>]
f.puts %Q[#include <mruby/hash.h>] unless test_args.empty?
end
def test_dependencies
[@name]
end
def custom_test_init?
@custom_test_init
!test_objs.empty?
end
def version_ok?(req_versions)
@@ -332,6 +358,10 @@ module MRuby
@ary.each(&b)
end
def [](name)
@ary.detect {|g| g.name == name}
end
def <<(gem)
unless @ary.detect {|g| g.dir == gem.dir }
@ary << gem
@@ -465,6 +495,10 @@ module MRuby
end
end
end
def linker_attrs
map{|g| g.linker.run_attrs}.transpose
end
end # List
end # Gem
+1 -1
View File
@@ -26,7 +26,7 @@ module MRuby
end
def instance
@instance ||= new("#{MRUBY_ROOT}/build/#{MRUBY_TARGET}.lock")
@instance ||= new("#{MRUBY_CONFIG}.lock")
end
end
+132
View File
@@ -0,0 +1,132 @@
module MRuby
class Presym
include Rake::DSL
OPERATORS = {
"!" => "not",
"%" => "mod",
"&" => "and",
"*" => "mul",
"+" => "add",
"-" => "sub",
"/" => "div",
"<" => "lt",
">" => "gt",
"^" => "xor",
"`" => "tick",
"|" => "or",
"~" => "neg",
"!=" => "neq",
"!~" => "nmatch",
"&&" => "andand",
"**" => "pow",
"+@" => "plus",
"-@" => "minus",
"<<" => "lshift",
"<=" => "le",
"==" => "eq",
"=~" => "match",
">=" => "ge",
">>" => "rshift",
"[]" => "aref",
"||" => "oror",
"<=>" => "cmp",
"===" => "eqq",
"[]=" => "aset",
}.freeze
SYMBOL_TO_MACRO = {
# Symbol => Macro
# [prefix, suffix] => [prefix, suffix]
["@@" , "" ] => ["CV" , "" ],
["@" , "" ] => ["IV" , "" ],
["" , "!" ] => ["" , "_B" ],
["" , "?" ] => ["" , "_Q" ],
["" , "=" ] => ["" , "_E" ],
["" , "" ] => ["" , "" ],
}.freeze
C_STR_LITERAL_RE = /"(?:[^\\\"]|\\.)*"/
def initialize(build)
@build = build
end
def scan(paths)
presym_hash = {}
paths.each {|path| read_preprocessed(presym_hash, path)}
presym_hash.keys.sort_by!{|sym| [c_literal_size(sym), sym]}
end
def read_list
File.readlines(list_path, mode: "r:binary").each(&:chomp!)
end
def write_list(presyms)
_pp "GEN", list_path.relative_path
File.binwrite(list_path, presyms.join("\n") << "\n")
end
def write_id_header(presyms)
prefix_re = Regexp.union(*SYMBOL_TO_MACRO.keys.map(&:first).uniq)
suffix_re = Regexp.union(*SYMBOL_TO_MACRO.keys.map(&:last).uniq)
sym_re = /\A(#{prefix_re})?([\w&&\D]\w*)(#{suffix_re})?\z/o
_pp "GEN", id_header_path.relative_path
File.open(id_header_path, "w:binary") do |f|
f.puts "enum mruby_presym {"
presyms.each.with_index(1) do |sym, num|
if sym_re =~ sym && (affixes = SYMBOL_TO_MACRO[[$1, $3]])
f.puts " MRB_#{affixes * 'SYM'}__#{$2} = #{num},"
elsif name = OPERATORS[sym]
f.puts " MRB_OPSYM__#{name} = #{num},"
end
end
f.puts "};"
f.puts
f.puts "#define MRB_PRESYM_MAX #{presyms.size}"
end
end
def write_table_header(presyms)
_pp "GEN", table_header_path.relative_path
File.open(table_header_path, "w:binary") do |f|
f.puts "static const uint16_t presym_length_table[] = {"
presyms.each{|sym| f.puts " #{sym.bytesize},\t/* #{sym} */"}
f.puts "};"
f.puts
f.puts "static const char * const presym_name_table[] = {"
presyms.each{|sym| f.puts %| "#{sym}",|}
f.puts "};"
end
end
def list_path
@list_pat ||= "#{@build.build_dir}/presym".freeze
end
def header_dir;
@header_dir ||= "#{@build.build_dir}/include/mruby/presym".freeze
end
def id_header_path
@id_header_path ||= "#{header_dir}/id.h".freeze
end
def table_header_path
@table_header_path ||= "#{header_dir}/table.h".freeze
end
private
def read_preprocessed(presym_hash, path)
File.binread(path).scan(/<@! (.*?) !@>/) do |part,|
literals = part.scan(C_STR_LITERAL_RE)
presym_hash[literals.map{|l| l[1..-2]}.join] = true unless literals.empty?
end
end
def c_literal_size(literal_without_quote)
literal_without_quote.size # TODO: consider escape sequence
end
end
end
+3
View File
@@ -0,0 +1,3 @@
MRuby::GemBox.new do |conf|
conf.gembox "stdlib"
end
+4
View File
@@ -0,0 +1,4 @@
MRuby::GemBox.new do |conf|
conf.gembox "stdlib"
conf.gembox "math"
end
+7 -92
View File
@@ -1,82 +1,12 @@
MRuby::GemBox.new do |conf|
# Meta-programming features
conf.gem :core => "mruby-metaprog"
conf.gembox "stdlib"
conf.gembox "stdlib-ext"
conf.gembox "stdlib-io"
conf.gembox "math"
conf.gembox "metaprog"
# Use standard IO/File class
conf.gem :core => "mruby-io"
# Use standard IO/File class
conf.gem :core => "mruby-socket"
# Use standard Array#pack, String#unpack methods
conf.gem :core => "mruby-pack"
# Use standard Kernel#sprintf method
conf.gem :core => "mruby-sprintf"
# Use standard print/puts/p
conf.gem :core => "mruby-print"
# Use standard Math module
conf.gem :core => "mruby-math"
# Use standard Time class
conf.gem :core => "mruby-time"
# Use standard Struct class
conf.gem :core => "mruby-struct"
# Use Comparable module extension
conf.gem :core => "mruby-compar-ext"
# Use Enumerable module extension
conf.gem :core => "mruby-enum-ext"
# Use String class extension
conf.gem :core => "mruby-string-ext"
# Use Numeric class extension
conf.gem :core => "mruby-numeric-ext"
# Use Array class extension
conf.gem :core => "mruby-array-ext"
# Use Hash class extension
conf.gem :core => "mruby-hash-ext"
# Use Range class extension
conf.gem :core => "mruby-range-ext"
# Use Proc class extension
conf.gem :core => "mruby-proc-ext"
# Use Symbol class extension
conf.gem :core => "mruby-symbol-ext"
# Use Random class
conf.gem :core => "mruby-random"
# Use Object class extension
conf.gem :core => "mruby-object-ext"
# Use ObjectSpace class
conf.gem :core => "mruby-objectspace"
# Use Fiber class
conf.gem :core => "mruby-fiber"
# Use Enumerator class (require mruby-fiber)
conf.gem :core => "mruby-enumerator"
# Use Enumerator::Lazy class (require mruby-enumerator)
conf.gem :core => "mruby-enum-lazy"
# Use toplevel object (main) methods extension
conf.gem :core => "mruby-toplevel-ext"
# Use Rational/Complex numbers
conf.gem :core => "mruby-rational"
conf.gem :core => "mruby-complex"
# Generate mrbc command
conf.gem :core => "mruby-bin-mrbc"
# Generate mirb command
conf.gem :core => "mruby-bin-mirb"
@@ -89,19 +19,4 @@ MRuby::GemBox.new do |conf|
# Generate mruby-config command
conf.gem :core => "mruby-bin-config"
# Use Kernel module extension
conf.gem :core => "mruby-kernel-ext"
# Use class/module extension
conf.gem :core => "mruby-class-ext"
# Use Method/UnboundMethod class
conf.gem :core => "mruby-method"
# Use eval()
conf.gem :core => "mruby-eval"
# Use mruby-compiler to build other mrbgems
conf.gem :core => "mruby-compiler"
end
+1 -4
View File
@@ -1,9 +1,6 @@
MRuby::GemBox.new do |conf|
conf.gem :core => "mruby-sprintf"
conf.gem :core => "mruby-print"
Dir.glob("#{root}/mrbgems/mruby-*/mrbgem.rake") do |x|
g = File.basename File.dirname x
conf.gem :core => g unless g =~ /^mruby-(print|sprintf|bin-debugger|test)$/
conf.gem :core => g unless g =~ /^mruby-(?:bin-debugger|test)$/
end
end
+10
View File
@@ -0,0 +1,10 @@
# It also works with MRB_NO_STDIO.
MRuby::GemBox.new do |conf|
# Use standard Math module
conf.gem :core => "mruby-math"
# Use Rational/Complex numbers
conf.gem :core => "mruby-rational"
conf.gem :core => "mruby-complex"
end
+15
View File
@@ -0,0 +1,15 @@
# It also works with MRB_NO_STDIO and MRB_NO_FLOAT.
MRuby::GemBox.new do |conf|
# Meta-programming features
conf.gem :core => "mruby-metaprog"
# Use Method/UnboundMethod class
conf.gem :core => "mruby-method"
# Use eval()
conf.gem :core => "mruby-eval"
# Use mruby-compiler to build other mrbgems
conf.gem :core => "mruby-compiler"
end
+1 -1
View File
@@ -209,7 +209,7 @@ class Array
# a.flatten(1) #=> [1, 2, 3, [4, 5]]
#
def flatten(depth=nil)
res = dup
res = Array.new(self)
res.flatten! depth
res
end
+2 -1
View File
@@ -3,6 +3,7 @@
#include <mruby/array.h>
#include <mruby/range.h>
#include <mruby/hash.h>
#include <mruby/presym.h>
/*
* call-seq:
@@ -97,7 +98,7 @@ static mrb_value
mrb_ary_values_at(mrb_state *mrb, mrb_value self)
{
mrb_int argc;
mrb_value *argv;
const mrb_value *argv;
mrb_get_args(mrb, "*", &argv, &argc);
+28 -19
View File
@@ -1,26 +1,35 @@
unless MRuby::Build.current.kind_of?(MRuby::CrossBuild)
MRuby::Gem::Specification.new('mruby-bin-config') do |spec|
name = 'mruby-config'
spec.license = 'MIT'
spec.author = 'mruby developers'
spec.summary = "#{name} command"
iscross = MRuby::Build.current.kind_of?(MRuby::CrossBuild)
MRuby::Gem::Specification.new('mruby-bin-config') do |spec|
name = 'mruby-config'
spec.license = 'MIT'
spec.author = 'mruby developers'
spec.summary = "#{name} command"
if iscross
mruby_config_dir = "#{build.build_dir}/host-bin"
else
mruby_config_dir = "#{build.build_dir}/bin"
mruby_config = name + (ENV['OS'] == 'Windows_NT' ? '.bat' : '')
mruby_config_path = "#{mruby_config_dir}/#{mruby_config}"
make_cfg = "#{build.build_dir}/lib/libmruby.flags.mak"
tmplt_path = "#{__dir__}/#{mruby_config}"
end
mruby_config = name + (ENV['OS'] == 'Windows_NT' ? '.bat' : '')
mruby_config_path = "#{mruby_config_dir}/#{mruby_config}"
make_cfg = "#{build.build_dir}/lib/libmruby.flags.mak"
tmplt_path = "#{__dir__}/#{mruby_config}"
if iscross
build.products << mruby_config_path
else
build.bins << mruby_config
end
directory mruby_config_dir
directory mruby_config_dir
file mruby_config_path => [mruby_config_dir, make_cfg, tmplt_path] do |t|
config = Hash[File.readlines(make_cfg).map!(&:chomp).map! {|l|
l.gsub('\\"', '"').split(' = ', 2).map! {|s| s.sub(/^(?=.)/, 'echo ')}
}]
tmplt = File.read(tmplt_path)
File.write(t.name, tmplt.gsub(/(#{Regexp.union(*config.keys)})\b/, config))
chmod(0755, t.name)
end
file mruby_config_path => [mruby_config_dir, make_cfg, tmplt_path] do |t|
config = Hash[File.readlines(make_cfg).map!(&:chomp).map! {|l|
l.gsub('\\"', '"').split(' = ', 2).map! {|s| s.sub(/^(?=.)/, 'echo ')}
}]
tmplt = File.read(tmplt_path)
File.write(t.name, tmplt.gsub(/(#{Regexp.union(*config.keys)})\b/, config))
chmod(0755, t.name)
end
end
+18 -8
View File
@@ -1,5 +1,22 @@
#!/bin/sh
print_help()
{
echo "Usage: mruby-config [switches]"
echo " switches:"
echo " --cflags print flags passed to compiler"
echo " --ldflags print flags passed to linker"
echo " --ldflags-before-libs print flags passed to linker before linked libraries"
echo " --libs print linked libraries"
echo " --libmruby-path print libmruby path"
echo " --help print this help"
exit 0
}
if [ $# -eq 0 ]; then
print_help
fi
while [ $# -gt 0 ]; do
case $1 in
--cflags) echo MRUBY_CFLAGS;;
@@ -7,14 +24,7 @@ while [ $# -gt 0 ]; do
--ldflags-before-libs) echo MRUBY_LDFLAGS_BEFORE_LIBS;;
--libs) echo MRUBY_LIBS;;
--libmruby-path) echo MRUBY_LIBMRUBY_PATH;;
--help) echo "Usage: mruby-config [switches]"
echo " switches:"
echo " --cflags print flags passed to compiler"
echo " --ldflags print flags passed to linker"
echo " --ldflags-before-libs print flags passed to linker before linked libraries"
echo " --libs print linked libraries"
echo " --libmruby-path print libmruby path"
exit 0;;
*) print_help;;
esac
shift
done

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