dearblue
232e07ad61
Reimplement mruby-catch; ref #5321
...
When there is a corresponding tag, the `RBreak` object is used to make a global jump.
Like CRuby, it can't be caught by `rescue`.
It is also the same as CRuby that it can be canceled in the middle by `ensure`.
### How to find the corresponding tag with `throw`
The called `catch` method remains in the call stack, and the tag also remains in the stack at that time.
So it is possible to find the called location by searching the two.
Note that no method can be given to the `proc` object specified in `RBreak`.
Therefore, inside the `catch` method, the argument block is called in a seemingly meaningless closure.
Also, as a countermeasure against `alias` etc., the `proc` object, which is the body of the `catch` method, is saved when mrbgem is initialized.
2021-02-06 21:41:08 +09:00
dearblue
0f8d3d8777
No need to check class definition
...
Because now the `Struct` class is always defined when this file is included.
2021-02-06 18:05:05 +09:00
Yukihiro "Matz" Matsumoto
88113df098
Fixed compile errors in cmath.c in MinGW and macOS.
2021-02-06 17:00:03 +09:00
KOBAYASHI Shuji
1ea4c51245
Make the argument of Kernel#catch optional as Ruby does
...
Also implement the following changes.
* Add tests
* Use `Object#equal?` to compare tags for Ruby compatibility
* Use `attr_reader`
2021-02-06 13:28:47 +09:00
Yukihiro "Matz" Matsumoto
4bf4650321
Avoid implicit conversion from mrb_float to mrb_complex.
2021-02-06 00:50:13 +09:00
Yukihiro "Matz" Matsumoto
8945afe38e
Merge pull request #5322 from shuujii/fix-message-of-ThrowCatchJump-in-mruby-catch-gem
...
Fix message of `ThrowCatchJump` in `mruby-catch` gem
2021-02-06 00:42:51 +09:00
Yukihiro "Matz" Matsumoto
8ecd38d648
Reimplement complex division.
2021-02-06 00:40:18 +09:00
Yukihiro "Matz" Matsumoto
ea0737ecfd
Define M_E for some platforms.
2021-02-06 00:39:53 +09:00
Yukihiro "Matz" Matsumoto
a6994f51c8
Update mruby-cmath to support MSVC complex.
...
* Use `_Complex` instead of `complex` (MSYS2 do not support `complex`)
* Use `_Dcomplex` instead of `_Complex` on MSCV
* Avoid operator division and multiplication of complex
2021-02-06 00:08:25 +09:00
KOBAYASHI Shuji
80965fe2d7
Fix message of ThrowCatchJump in mruby-catch gem
...
### Example
```ruby
begin
throw 1
rescue Exception => e
puts e.message
end
```
#### Before this patch:
```console
$ bin/mruby example.rb
uncaught throw :1
```
#### After this patch (same as Ruby):
```console
$ bin/mruby example.rb
uncaught throw 1
```
2021-02-05 23:14:58 +09:00
Yukihiro "Matz" Matsumoto
a0050541d1
Add mruby-cmath gem to the core.
...
This gem uses C99 `_Complex` features. You need a C compiler that
supports `_Complex` to enable this gem. All `gcc`, `clang`, `VC` support
`_Complex` so there should not be a big problem.
2021-02-05 22:27:27 +09:00
Yukihiro "Matz" Matsumoto
d898002096
Add a few new API for complex access.
2021-02-05 21:54:49 +09:00
Yukihiro "Matz" Matsumoto
c6149370b0
Refactor method overriding.
...
* Use `class_eval` instead of `instance_eval`.
* Reduce `class_eval` calls
* define `Numeric#i`
* undefine `Complex#i`
2021-02-05 21:54:11 +09:00
Yukihiro "Matz" Matsumoto
7ce03e32b7
Add Complex#to_c method.
2021-02-05 21:42:42 +09:00
Yukihiro "Matz" Matsumoto
c43dd75ea9
Avoid Heap Overflow in heredoc_remove_indent; fix #5316
2021-02-03 13:06:13 +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
KOBAYASHI Shuji
1fc8e00e4a
Use mrb_open_core() instead of mrb_open() in mrbc
2021-01-31 22:37:27 +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
d42d308620
Remove duplicated --cflags; [ci skip]
2021-01-28 19:55:05 +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
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
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
17ecf14511
Revert "Minimize the changes in #5277 "
...
This reverts commit dc51d89ac2 .
2021-01-26 10:57:07 +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
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
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
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
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
c7452ff61f
Define Rational#quo; fix #5268
2021-01-17 23:02:35 +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
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
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
1310368b3f
Silence Windows warnings (cast and setmode).
2021-01-12 16:25:30 +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