Yukihiro "Matz" Matsumoto
521766009b
Merge pull request #6405 from ArtSin/io_read-fix-mrb_raisef-arg
2024-11-05 13:08:42 +09:00
Yukihiro "Matz" Matsumoto
fed631c21b
mruby-bigint (mrb_bint_sub_n): avoid allocating mpz_z
2024-11-05 13:03:54 +09:00
Yukihiro "Matz" Matsumoto
6085ffb968
mruby-bigint (mrb_bint_add_n): avoid allocating mpz_z
2024-11-05 12:22:10 +09:00
Yukihiro "Matz" Matsumoto
ef18bd86a6
mruby-bigint (mpz_sub_int): avoid allocating mpz_t for mrb_int
2024-11-05 11:52:22 +09:00
Yukihiro "Matz" Matsumoto
fe12e840f3
mruby-bigint (mpz_add_int): move the function definition
...
To prepare `mpz_sub_int` update.
2024-11-05 11:52:22 +09:00
ArtSin
0afc7ae13b
io_read: use %i instead of %d in call to mrb_raisef
...
`length` is `mrb_int`, not `int`.
2024-11-04 13:56:46 +04:00
Yukihiro "Matz" Matsumoto
3885e14049
mruby-rational: explicitly add return for error cases too
2024-10-31 14:06:10 +09:00
Yukihiro "Matz" Matsumoto
19d3620965
mruby-bigint (mrb_bint_powm): stop a warning for no return
2024-10-31 14:06:10 +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
62ef5db13e
irep.h: rename mrb_pool_value to mrb_irep_pool
...
mrb_pool_value is a structure that represents a value in the irep
literal pool and is unrelated to mrb_pool, which performs region-based
memory management. It has been renamed mrb_irep_pool to avoid confusion.
2024-10-29 20:34:53 +09:00
dearblue
a196d8a5f3
Fixed also argument forwarding in class_exec
...
Pointed out by @matz.
https://github.com/mruby/mruby/pull/6391#issuecomment-2433662139
2024-10-24 22:05:59 +09:00
dearblue
f9151e0bd9
Fixed argument forwarding in instance_exec
...
However, on C, there is no easy way to pass keyword arguments.
Therefore, when called `Kernel#instance_exec` on C, keyword arguments are converted to positional arguments.
This is a limitation of current mruby.
fixed #6389
2024-10-24 21:20:46 +09:00
Yukihiro "Matz" Matsumoto
f245943aed
mruby-bigint (mrb_bint_powm): fixed bugs in type casting
2024-10-24 07:21:12 +09:00
Yukihiro "Matz" Matsumoto
0b96f7f2f7
mruby-bigint (mrb_bint_to_s): add uzero_p() check
2024-10-24 07:20:24 +09:00
Yukihiro "Matz" Matsumoto
c5565a37ac
mruby-bigint: add checks for divided by zero by sizes and contents
2024-10-24 07:18:34 +09:00
Yukihiro "Matz" Matsumoto
5e9593e285
mruby-bigint (udiv): add assertion for divided by zero
2024-10-24 07:16:32 +09:00
Yukihiro "Matz" Matsumoto
b95ca53e5c
mruby-compiler: revert ce2fdb7; close #6388
...
The commit was to stop warnings from Visual C but unexpectedly caused
compilation errors on some configuration.
2024-10-22 14:46:12 +09:00
Yukihiro "Matz" Matsumoto
51fd065722
mruby-compiler (parser_yylex): skip sign if bigint starts with +
...
To reserve memory (1 byte) and avoid error (fixed by 11cff8f ).
2024-10-22 14:45:48 +09:00
Yukihiro "Matz" Matsumoto
11cff8fa7d
mruby-bigint (mpz_init_set_str): should skip + in the string
...
When the string starts with `+` it should not cause error silently. It
might cause serious error afterwards.
2024-10-22 14:44:51 +09:00
Yukihiro "Matz" Matsumoto
f3257c448b
mruby-bigint (mrb_bint_powm): should call mpz_clear() on exceptions
2024-10-19 13:09:03 +09:00
Yukihiro "Matz" Matsumoto
e4d2f343fe
mruby-bigint (mrb_bint_neg): move the function to group bit operations
2024-10-19 12:47:06 +09:00
Yukihiro "Matz" Matsumoto
ee13b9e67b
mruby-bigint: fix mrb_int optimization bugs for and, or, xor
...
If the operand is a small integer, those functions tried to reduce
bigint allocations, but we had some bugs in them. We removed those
imperfect optimization altogether.
2024-10-19 12:45:04 +09:00
Yukihiro "Matz" Matsumoto
2430eaba13
mruby-bigint (mrb_bint_powm): fixed memory leak
2024-10-19 07:32:06 +09:00
Yukihiro "Matz" Matsumoto
001d5fcc3f
mruby-bigint (mpz_get_str): get b2 by table lookup
...
The `b2` is the power of `base` no bigger than DIG_BASE.
2024-10-19 07:32:05 +09:00
Yukihiro "Matz" Matsumoto
4aa87acfc9
mruby-bigint (mpz_set_uint64): adjust reallocation size for uint64
...
The uint64_t value may fit in `mp_limb*n` where n is 1..4.
2024-10-19 07:32:05 +09:00
Yukihiro "Matz" Matsumoto
5e6d382782
mruby-bigint (mpz_set_uint64): fixed a bug in for loop
...
Found double increments in a loop. Since no one called mpz_set_int64()
in the real code, we could not find this bug for long time.
2024-10-18 12:27:02 +09:00
Yukihiro "Matz" Matsumoto
fe42f1d047
mruby-bigint (mpz_set_int): simplify using early return
2024-10-18 12:27:02 +09:00
Yukihiro "Matz" Matsumoto
a5c0b2114a
mruby-bigint (mrb_bint_2comp): need to initialize mpz_t
2024-10-18 12:27:02 +09:00
Yukihiro "Matz" Matsumoto
f1863163a8
mruby-bigint (uzero_p): avoid signed and unsigned comparison in loop
2024-10-16 16:33:43 +09:00
Yukihiro "Matz" Matsumoto
7b5608e78a
mruby-rational: refactor float to rational conversion
...
- the function `float_decode_internal` was removed
- simplified `rational_new_f()`
- do not need to call `ldexp`
- allocate less bigint objects
2024-10-15 21:10:11 +09:00
Yukihiro "Matz" Matsumoto
51b11a6919
mruby-rational: add comments
...
We used `mrb_bint_mul(mrb, n, ONE)` to normalize `n`. The code confused
ChatGPT that could not read the intention.
2024-10-15 21:10:10 +09:00
Yukihiro "Matz" Matsumoto
06f45f8635
mruby-compiler (codegen): detect too-deep nesting error; fix #6270
2024-10-15 21:10:10 +09:00
Yukihiro "Matz" Matsumoto
b5801cd730
mruby-bigint (mrb_bint_new_int64): fixed a bug on the 32bit platforms
2024-10-11 14:19:33 +09:00
Yukihiro "Matz" Matsumoto
e29f3d64b2
mruby-compiler: stop malloc/free warnings from Visual Studio build
2024-10-11 09:10:44 +09:00
Yukihiro "Matz" Matsumoto
763c9cba03
mruby-rational (int_lshift): add cast to stop overflow warning
2024-10-11 08:44:12 +09:00
Yukihiro "Matz" Matsumoto
f4fdf25bb0
mruby-bigint (mrb_bint_new_int64): wrong return value
2024-10-11 08:41:51 +09:00
John Bampton
6f97cf10e9
docs: fix grammar
2024-10-11 04:07:58 +10:00
Yukihiro "Matz" Matsumoto
6d4de2496c
mruby-bigint: remove unused macros; ref #6371
2024-10-10 23:14:27 +09:00
Yukihiro "Matz" Matsumoto
e21055604c
mruby-bigint: separate mpz and bint functions; ref #6371
...
The pull-request #6371 was tight integration of mpz and bint functions.
The mpz functions take `struct RBigint*` instead of `mpz_t*`. It
decrease maintainability, in my opinion. This commit initializes `mpz_t`
from `struct RBigint*` in bint functions, so that we can keep separation
of function roles.
2024-10-10 23:04:04 +09:00
Yukihiro "Matz" Matsumoto
12b97ceb78
fixup! Merge branch 'bigint-embed' of https://github.com/dearblue/mruby into bigint-embed
2024-10-10 22:57:32 +09:00
Yukihiro "Matz" Matsumoto
bda2fa39d2
Merge branch 'bigint-embed' of https://github.com/dearblue/mruby into bigint-embed
2024-10-10 22:31:55 +09:00
Yukihiro "Matz" Matsumoto
453e9eabf0
mruby-rational (rat_add_b): might have called rational_new_b with int
...
`rational_new_b` should be called with bigint objects.
2024-10-10 07:55:51 +09:00
Yukihiro "Matz" Matsumoto
b56ad8fdee
mruby-bigint: improve mpz_mul_int() and mpz_add_int()
...
Both functions are only called from mpz_init_set_str(). We can assume
- mpz_t is modifiable
- mpz_t is positive
- n is positive and small (n <= 36)
Those new definitions consume less memory and are slightly faster.
2024-10-08 16:09:46 +09:00
Yukihiro "Matz" Matsumoto
3b06ad4737
mruby-bigint (mpz_mul): cancel Karatsuba algorithm
...
We tried many times to implement the Karatsuba method to improve the
performance of multiplication of large multi-precision integers. But it
did not speed up in all cases due to the cost of memory allocation. We
decided to go back to the basic multiplication method.
If anyone wants to take on the challenge of improving the performance of
multiplication, we welcome it.
2024-10-08 16:02:19 +09:00
Yukihiro "Matz" Matsumoto
77fb1b1b65
mruby-bigint (mul_karatsuba): use byte-wise addition to combine
2024-10-07 07:28:24 +09:00
dearblue
6366f1cbb9
Update mrbgems/mruby-bigint/core/bigint.h
...
Co-authored-by: John Bampton <jbampton@users.noreply.github.com >
2024-10-06 23:03:03 +09:00
dearblue
009a79b5c9
Embedding in RBigint objects
...
Integers up to 3 words long will no longer allocate heap space.
2024-10-06 22:28:22 +09:00
Yukihiro "Matz" Matsumoto
40c7febca8
mruby-bigint (uadd): remove redundant trim()
2024-10-05 15:08:16 +09:00
Yukihiro "Matz" Matsumoto
be9da7199b
mruby-bigint (mul_karatsuba) improve performance
...
Unnecessary mpz_t u0u1 and v0v1 are removed.
2024-10-05 10:57:42 +09:00
Yukihiro "Matz" Matsumoto
8faf78f1b8
mruby-method: singleton_method() should search in superclasses
...
[ruby-bugs:20620](https://bugs.ruby-lang.org/issues/20620 )
2024-10-04 21:37:49 +09:00