Commit Graph

523 Commits

Author SHA1 Message Date
Yukihiro "Matz" Matsumoto 5522c94bb3 mruby.h: remove mrb_allocf type
As a result, we removed (already obsoleted) `mrb_open_allocf()', and
made `mrb_open_core()` take no argument. [incompatible changes]
2025-05-10 08:59:18 +09:00
Yukihiro "Matz" Matsumoto 5c71681d82 allocf.c (mrb_basic_alloc_func): remove ud argument 2025-05-10 08:59:18 +09:00
Yukihiro "Matz" Matsumoto c3cc559dfc allocf.c: rename mrb_default_alloc to mrb_basic_alloc_func
Along with removing mrb_state first argument from the function. From
mruby 3.2, this function is *not* the default function, but the entry
point that can be redefined for the application. The function in
`src/allocf.c` is the default *implementation* (using malloc / realloc /
free) of the function.
2025-05-09 21:50:18 +09:00
Yukihiro "Matz" Matsumoto 0bdd529430 mruby.h: remove allocf and allocf_ud from mrb_state
This is preparation for memory allocation restructuring.
2025-05-09 18:13:28 +09:00
dearblue 3fd5e1c250 Fixed visibility at method definition
There was a problem with visibility state from proc that straddles a fiber or is independent.

Therefore, it has been changed to give priority to env objects, if any.
Also, added "separate module" flag to block traversal to a higher level env object.

Note that the "separate module" flag is now set when calling blocks with the `mrb_yield_with_class()` function.

fixed https://github.com/mruby/mruby/issues/6494
2025-04-11 21:36:26 +09:00
Yukihiro "Matz" Matsumoto 889f09f8b7 class.c: move visibility flags from classes/modules to callinfo 2025-03-07 17:17:50 +09:00
Yukihiro "Matz" Matsumoto ca20017ac9 class.c: implement mrb_define_private_method() 2025-03-07 17:17:36 +09:00
dearblue a981f5aed7 Add more const qualifier for RProc 2025-01-20 22:25:50 +09:00
Yukihiro "Matz" Matsumoto d13e6ff8c9 include/presym.h: MRB_GVSYM() for global variables is now available 2024-12-14 16:03:35 +09:00
Yukihiro "Matz" Matsumoto 49525fa207 mempool.c: renamed from pool.c
To avoid confusion with pools in irep, we renamed region-based memory
manager from pool to mempool.

- rename pool.c to mempool.c
- separate mempool.h
- rename all mrb_pool to mrb_mempool

So if someone is using pool.c functions (I suppose no one does though),
they need to rename all `mrb_pool` to `mrb_mempool` and include
`mruby/mempool.h` header at the top.
2024-10-31 14:06:10 +09:00
Yukihiro "Matz" Matsumoto d6fa7772a0 mruby.h (mrb_method_t): avoid unnamed union
It caused errors in the pedantic-mode of GCC.
2024-09-26 00:07:03 +09:00
dearblue ad576f1e75 Revert "Delegate the care of a directly given block from cipop() to cipush()"
This reverts commit ad2e626e7a.

Because of the changes made by #6282, the following code caused a problem.

```ruby
b = proc { break "BAD!" }
p self.tap { b.call }
# (expected)    => break from proc-closure (LocalJumpError)
# (after #6282) => "BAD!"
```

I revived the `mrb_callinfo::blk` field to fix this, but it did not overcome the following problem.

```ruby
def m(&b); b = b.clone; GC.start; b.call; end
p m { break "OK!" }
# (expected)    => "OK!"
# (revived blk) => break from proc-closure (LocalJumpError)
```
2024-06-30 21:01:45 +09:00
dearblue ad2e626e7a Delegate the care of a directly given block from cipop() to cipush()
Outlines:
  - Removed `mrb_callinfo::blk`
  - Added `mrb_callinfo::flags`
  - Added `MRB_CI_COMPANION_BLOCK` flag
2024-05-31 22:03:15 +09:00
dearblue a0526418ce Update documentation for mrb_top_run()
Also, add explanations for the `mrb_load_irep()` and `mrb_load_string()` families, which are indirect calls to `mrb_top_run()`.
2024-04-26 22:05:45 +09:00
dearblue 328eb71e52 Reorganize mrb_cache_entry and mrb_method_t types
The purpose is to remove the `mid` field from the `mrb_cache_entry` structure.
The resulting RAM requirement for the method cache is reduced from 5 words per entry to 4 words per entry for 32-bit CPUs.

The relevant changes are as follows:

  - Removed `MRB_USE_METHOD_T_STRUCT`.

    The `mrb_method_t` type is now always defined as a structure.

  - Include method IDs in `mrb_method_t`

    Change the `flags` member to `uint32_t`.
    The bitstring structure should be the same as the keys of the `mt` table in `class.c`.

I believe the impact on API compatibility with previous versions is minimal.
2024-03-30 18:19:26 +09:00
Yukihiro "Matz" Matsumoto 87b358a342 Including header files in include/* by <> 2024-03-26 13:59:59 +09:00
Yukihiro "Matz" Matsumoto 96fa3461f0 mruby.h: move integer hash function from khash.h 2024-03-26 13:59:58 +09:00
Yukihiro "Matz" Matsumoto aa0cb370a8 kernel.c (mrb_obj_is_instance_of): add const qualifier 2024-03-04 13:01:20 +09:00
dearblue ce8b2d4973 Added mrb_callinfo::u.keep_context for clarity 2024-02-24 21:32:11 +09:00
Yukihiro "Matz" Matsumoto c3f8227c6d mruby.h: adjust comment offset [ci skip] 2024-02-15 14:01:48 +09:00
dearblue 3111990089 Introduce mrb_obj_itself()
Some method definitions were changed to use this function.
2024-01-20 22:07:29 +09:00
Yukihiro "Matz" Matsumoto 899a09152b mruby.h (mrb_alloc): better description for the function type 2023-12-20 19:39:09 +09:00
dearblue ef8b0b7ed8 Allows calling Fiber#resume from C
This patch is effectively reverts to the following:
  - commit dc65b1faf1 (#5782)
  - commit f4c4809750 (#5947)

Ref. #6063
2023-12-04 22:32:51 +09:00
dearblue 1bb77170ec Add a new mrb_fiber_new() with MRB_API 2023-11-05 20:36:29 +09:00
Yukihiro "Matz" Matsumoto 461c97225e LICENSE: remove the end date of copyright notice; close #6080 2023-10-23 15:31:34 +09:00
Yukihiro "Matz" Matsumoto 82a48bd455 error.c (mrb_bug): avoid formatting in mrb_bug()
Since mrb_bug() would be called under the abnormal situation (and should
not be called if possible), the process should be minimal.
2023-07-14 21:48:11 +09:00
Yukihiro "Matz" Matsumoto e6c89ef1f9 mruby.h: make mrb_check_frozen to a normal function from inline one 2023-05-31 08:33:58 +09:00
Yukihiro "Matz" Matsumoto ccdf75c1c2 error.c: a new function mrb_check_frozen_value() 2023-05-31 08:31:13 +09:00
Yukihiro "Matz" Matsumoto eea72ec84a fix spaces in the type cast expressions (cosmetic changes) 2023-05-18 23:29:16 +09:00
John Bampton 06a765a1c2 Change MRuby to mruby 2023-05-03 22:12:59 +10:00
Yukihiro "Matz" Matsumoto 2c046eb512 mruby.h: replace frequently used inline functions with macros
- mrb_gc_arena_save()
- mrb_gc_arena_restore()
2023-02-22 16:35:14 +09:00
John Bampton 8af0aa4905 Update License year to 2023 2023-02-10 11:55:32 +10:00
dearblue a93807f48f Improve consistency of how error classes are retrieved 2023-02-07 22:46:56 +09:00
Yukihiro "Matz" Matsumoto 7ad657b532 mrb_kwargs numbers changed to mrb_int from uint32_t
They are unsigned but `mrb_int` is more common among mruby
implementation, e.g. length of strings and arrays.
2022-12-12 14:42:38 +09:00
dearblue 6fed73445e Updates documentation for mrb_fiber_resume() and mrb_fiber_yield()
- Added note on `mrb_fiber_resume()` and `mrb_fiber_yield()`.
  Removed comments from C files that were not documented by yard and doxygen instead.
- Leads to use of `mrb_fiber_resume()` instead of `Fiber#resume` in C.
- Leads to use of `mrb_fiber_yield()` instead of `Fiber.yield` in C.
2022-11-19 16:59:28 +09:00
Daniel Bovensiepen Li c47038462f Update year to 2022 in mruby.h 2022-10-09 17:02:27 +08:00
Yukihiro "Matz" Matsumoto 27619cebc0 mruby.h: update documentation for mrb_singleton_class(); ref #5800 2022-10-07 12:03:28 +09:00
dearblue dbc78cd861 Added documentation for mrb_singleton_class() 2022-10-06 21:56:07 +09:00
Yukihiro "Matz" Matsumoto eecb6cc080 vm.c (cipush): push block information in the callinfoa; fix #5786 2022-09-01 18:57:19 +09:00
Yukihiro "Matz" Matsumoto eaa89fbe2a Merge branch 'get-args-array' of https://github.com/sasq64/mruby into sasq64-get-args-array 2022-08-24 16:46:00 +09:00
dearblue 1e72c61b0f Make definition of mrb_irep by typedef in mruby.h
Eliminated invisible dependencies from `mruby/debug.h` to `mruby/irep.h`.
2022-08-12 22:25:27 +09:00
dearblue 5215b9ce8b Avoid comparing mrb_bool to integer values in the documentation 2022-07-31 20:38:31 +09:00
Yukihiro "Matz" Matsumoto ede3bed9e6 object.c: add new function mrb_ensure_integer_type().
that checks if the value is an `Integer` which may be a big integer,
where existing `mrb_ensure_int_type()` checks if the value is an Integer
**and** fits in `mrb_int`.
2022-04-25 07:21:40 +09:00
dearblue 34048abcfc Correct truncated SystemStackError [ci skip] 2022-03-13 14:56:56 +09:00
Yukihiro "Matz" Matsumoto ef3a56c92b error.c: (mrb_exc_new) use mrb_int instead of size_t. 2022-03-03 14:48:39 +09:00
Yukihiro "Matz" Matsumoto a4f740ff9a string.c: use mrb_int instead of size_t. 2022-03-03 08:08:02 +09:00
dearblue d7c09fb24a Improved documentation for struct mrb_kwargs [ci skip]
- Changed the description to match the order of the changed members.
- Replaced "array of symbols" instead of "array of strings that mean symbols".
- The `mrb_kwargs::optional` member has not been present since the first merge. It is a remnant from development time.
- Removed `const` modifier used in variable declarations in examples. This is not always necessary from a user perspective.
- Added note on the use of `MRB_SYM()`.

resolved #5649
2022-02-19 21:55:52 +09:00
dearblue 82a1b00eb6 Assert that MRB_METHOD_CACHE_SIZE is a power of 2
The `mrb_static_assert_powerof2()` macro has been introduced for this purpose.
2022-01-02 14:59:55 +09:00
Yukihiro "Matz" Matsumoto b9e1b9b328 numeric.c: merge mrb_as_float implementation to mrb_ensure_float_type.
Since they are basically duplicated functionality. `mrb_as_float` is now
a macro defined using `mrb_ensure_float_type`; #5620
2021-12-31 15:14:37 +09:00
Yukihiro "Matz" Matsumoto 4f297ac29c object.c: introduce mrb_ensure_{int,float}_type.
Since `mrb_to_integer` and `mrb_to_float` does not convert the object
but checks types, they are named so by historical reason. We introduced
properly named functions.

This commit obsoletes the following functions:

* mrb_to_integer()
* mrb_to_int()
* mrb_to_float()

Use `mrb_ensure_int_type()` instead for the first 2 functions. Use
`mrb_ensure_float_type()` for the last.
2021-12-29 16:39:29 +09:00