12 Commits

Author SHA1 Message Date
dearblue cc95e346fd Added MRB_OBJ_ALLOC() macro that does not require a cast
The `MRB_OBJ_ALLOC()` macro function returns a pointer of the type corresponding to the constant literal defined in `enum mrb_vtype`.
2021-06-20 11:08:28 +09:00
dearblue 94c5c8f44c Introduce MRB_GC_RED
Replaces the magic number `7` except in `src/gc.c`.
2021-04-24 10:31:21 +09:00
dearblue caeacea86e Making a proc object static for a method with static irep
The following methods will be made static.

  - `Class#new`
  - `Proc#call`
  - `Kernel#catch`

Previously, static const RProc could not be registered as a method, but this has been changed to allow it.
2021-04-04 15:44:19 +09:00
Yukihiro "Matz" Matsumoto 5ba37db981 Merge pull request #5336 from shuujii/fix-build-mruby-catch-gem-without-presym
Fix build `mruby-catch` gem without presym
2021-02-12 21:11:59 +09:00
KOBAYASHI Shuji 8ba7be0999 Fix build mruby-catch gem without presym 2021-02-12 19:19:32 +09:00
KOBAYASHI Shuji 955464ca3c Add UncaughtThrowError#{tag,value} for Ruby compatibility 2021-02-12 19:09:18 +09:00
Yukihiro "Matz" Matsumoto 0db6e3eb6f Rename mruby-catch.c to catch.c; ref #5328 2021-02-12 10:09:19 +09:00
Yukihiro "Matz" Matsumoto c7809ca025 Refactor mruby-catch; ref #5328
- Move `#catch` definition to `mruby-catch.c` to avoid tweaking
- Remove `#__preserve_catch_method`
- Implement whole `#throw` method in C
2021-02-10 20:09:00 +09:00
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
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
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 7eaaee5405 Add a new gem: mruby-catch.
Implements `catch`/`throw` non-local jump inherited from Lisp.

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

Example:
```
  catch(:foo) { 123 }               # => 123
  catch(:foo) { throw(:foo, 456) }  # => 456
  catch(:foo) { throw(:foo) }       # => nil
```
2020-10-12 18:20:07 +09:00