Yukihiro "Matz" Matsumoto
9f37733382
numeric.c: fix a bug in left shift of negative integer.
...
`-1 * (1<<63)` causes overflow, but `-1<<63` is a valid value.
2021-08-04 12:05:09 +09:00
Yukihiro "Matz" Matsumoto
9b3b2a4c95
numeric.c: check zero division before modulo.
2021-08-03 16:45:08 +09:00
Yukihiro "Matz" Matsumoto
caaa07f2da
codegen.c: check zero division before constant folding.
2021-08-03 16:43:50 +09:00
Yukihiro "Matz" Matsumoto
c480ac4457
numeric_ext.c: modulo and remainder should handle infinite argument.
2021-08-03 16:35:31 +09:00
Yukihiro "Matz" Matsumoto
e75572af6a
numeric_ext.c: add Float#modulo and #remainder methods.
2021-08-03 16:30:47 +09:00
Yukihiro "Matz" Matsumoto
f4afcbef67
numeric_ext.c: update Integer#remainder method.
...
- need to detect zero division error
- support floating point number argument (as `%`)
2021-08-03 16:28:11 +09:00
Yukihiro "Matz" Matsumoto
b70fd09f47
Revert "numeric.c: simplifies int_mod definition."
...
This reverts commit 3738d62a86 .
The change changed the behavior with floating point numbers.
2021-08-03 16:11:02 +09:00
Yukihiro "Matz" Matsumoto
2092bc7fe8
codegen.c: avoid division by zero in constant folding.
2021-08-03 15:57:01 +09:00
Yukihiro "Matz" Matsumoto
fad47a98a7
numeric_ext.c: use mrb_integer instead of mrb_as_int.
...
`mrb_as_int` implicitly converts the value into the integer, but those
methods are defined for Integer class so that the value should always be
integers.
2021-08-03 13:15:34 +09:00
Yukihiro "Matz" Matsumoto
3738d62a86
numeric.c: simplifies int_mod definition.
2021-08-03 13:14:23 +09:00
Yukihiro "Matz" Matsumoto
df6ef39d1c
numeric_ext.c: define modulo and remainder methods for Integer.
2021-08-03 13:13:42 +09:00
Yukihiro "Matz" Matsumoto
b9d2b47f16
Replace mrb_fixnum_value() with mrb_int_value().
...
Use `mrb_fixnum_value()` only when you are absolutely sure that the
value is within `Fixnum` range, i.e. 31 bits signed integer at least.
2021-08-03 13:00:11 +09:00
Yukihiro "Matz" Matsumoto
23e7cb41e5
Replace fixnum references with int.
...
The `Fixnum` class is no longer provided by `mruby`.
2021-08-03 13:00:10 +09:00
Yukihiro "Matz" Matsumoto
019b006ee5
numeric_ext.c: remove unnecessary prefix mrb_ from static functions.
2021-08-03 10:33:04 +09:00
Yukihiro "Matz" Matsumoto
1f0238a928
numeric.c: rename fixdivmod to intdivmod.
2021-08-03 07:30:59 +09:00
Yukihiro "Matz" Matsumoto
4fa24e4ff9
codegen.c: allow constant folding for negative integer modulo.
2021-08-02 16:48:16 +09:00
Yukihiro "Matz" Matsumoto
81d56477f2
numeric.c: simpler integer modulo calculation.
2021-08-02 16:47:50 +09:00
Yukihiro "Matz" Matsumoto
504d05232d
mrdb.c: do not skip OP_JMP on step execution.
2021-08-02 16:19:08 +09:00
Yukihiro "Matz" Matsumoto
e93642d53f
codegen.c: refactor readint() to read MRB_INT_MIN.
2021-08-02 14:10:38 +09:00
Yukihiro "Matz" Matsumoto
6ea0c04c06
numeric.c: use C's modulo operator if both operands are positive.
2021-08-02 14:09:38 +09:00
Yukihiro "Matz" Matsumoto
a5ac9c8790
test/driver.c: remove unused constants related to FIXNUM.
2021-08-02 08:56:38 +09:00
Yukihiro "Matz" Matsumoto
9902ab50fc
codegen.c: fix a bug in bit shift constant folding.
2021-08-02 08:53:50 +09:00
Yukihiro "Matz" Matsumoto
a9d721ea8f
numeric.c: refactor integer bit shift operations.
2021-08-02 08:53:14 +09:00
Yukihiro "Matz" Matsumoto
907df715ef
codegen.c: refactor unary operator optimization.
2021-08-02 08:51:39 +09:00
Yukihiro "Matz" Matsumoto
188c150f44
codegen.c: constant folding binary operators, <<, >>, %, &, |, ^.
2021-08-02 07:34:54 +09:00
Yukihiro "Matz" Matsumoto
1315e8751e
codegen.c: eliminate loop if condition is constant.
...
For example, `while false; ...; end` should be removed.
2021-08-01 20:33:41 +09:00
Yukihiro "Matz" Matsumoto
9dc801a798
codegen.c: peephole optimize OP_JMPxxx.
2021-08-01 20:31:19 +09:00
Yukihiro "Matz" Matsumoto
b1cb6c3c69
codegen.c: allow constant folding for mul / div.
2021-07-31 21:14:54 +09:00
Yukihiro "Matz" Matsumoto
43999492a7
codegen.c: mrb_prev_pc() to take previous instruction position.
...
It rescans `s->iseq` so that peephole optimizer can take multiple
previous instructions for constant folding, etc.
2021-07-31 21:11:36 +09:00
Yukihiro "Matz" Matsumoto
4306893971
codedump.c: instruction length should be ilen, not iseq.
2021-07-30 17:50:24 +09:00
Yukihiro "Matz" Matsumoto
517071e3fa
codegen.c: order instructions in natural order for loops.
...
`while` and `until` generates in `cond` `jmpif` `body` `jmp` order.
It used to be in `jmp` `body` `cond` `jmpif` order.
2021-07-29 17:38:18 +09:00
Yukihiro "Matz" Matsumoto
5cde5983d9
debug.c: uses most space efficient packed map for line information.
2021-07-28 23:08:58 +09:00
Yukihiro "Matz" Matsumoto
64358c09d9
codegen.c: labels should be uint32_t.
2021-07-28 23:08:58 +09:00
Yukihiro "Matz" Matsumoto
adfd29c1b0
codegen.c: fix loopinfo structure members.
...
- `pc0`: `next` destination
- `pc1`: `redo` destination (renamed from `pc2`)
- `pc3`: `break` destination (renamed from `pc3`)
old `pc1` was unused so removed.
2021-07-28 23:08:58 +09:00
Yukihiro "Matz" Matsumoto
e81d497155
codegen.c: removed bytecode when the value of while is not used.
2021-07-28 23:08:58 +09:00
Yukihiro "Matz" Matsumoto
2910af0010
codegen.c: fixed a bug when value is taken from while and until.
...
```ruby
p ((while true; p 1; break; end))
```
should print `1 nil` but was `1`.
2021-07-28 23:08:57 +09:00
Yukihiro "Matz" Matsumoto
9dd3e23fc9
Merge pull request #5518 from jbampton/pre-commit-autoupdate
...
pre-commit autoupdate
2021-07-28 23:08:10 +09:00
John Bampton
cbd54782c6
pre-commit autoupdate
...
https://pre-commit.com/#pre-commit-autoupdate
2021-07-28 21:21:57 +10:00
Yukihiro "Matz" Matsumoto
1f1dca1746
parse.y: fix an integer cast warning.
2021-07-26 11:46:22 +09:00
Yukihiro "Matz" Matsumoto
984161e6bb
parse.y: mrb_int_read() returns mrb_int not unsigned long.
...
Also, now too big capture group index just gives `nil`, not error.
2021-07-26 11:20:59 +09:00
Yukihiro "Matz" Matsumoto
4803718b14
parse.y: unify redundant functions yywarn() and yywarning().
2021-07-26 11:12:10 +09:00
Yukihiro "Matz" Matsumoto
f6b37ff44d
debug.c: small refactoring.
2021-07-26 11:10:20 +09:00
Yukihiro "Matz" Matsumoto
b4696c3935
debug.c: remove type cast warnings.
2021-07-26 11:09:42 +09:00
Yukihiro "Matz" Matsumoto
642497fe19
fmt_fp.c: add implicit cast from mrb_float to int8_t.
2021-07-26 10:57:42 +09:00
Yukihiro "Matz" Matsumoto
966aa476d1
vm.c: fix integer type error in mrb_protect_error.
2021-07-26 10:49:12 +09:00
Yukihiro "Matz" Matsumoto
6175db2746
irep.h: operand c should be fit in uint8_t.
2021-07-26 10:47:40 +09:00
Yukihiro "Matz" Matsumoto
22b24d5d76
test/binding.rb: remove a duplicated test.
2021-07-26 10:46:36 +09:00
Yukihiro "Matz" Matsumoto
26340a8818
time.c: fixed a potential buffer overflow in time_zonename.
2021-07-25 16:43:00 +09:00
Yukihiro "Matz" Matsumoto
c2c0250063
time.c: fixed time_zonename buffer size bug.
2021-07-25 16:38:37 +09:00
Yukihiro "Matz" Matsumoto
368b75d81b
time.c: stop returning LOCAL for the zone name from Time.zone.
2021-07-25 13:07:11 +09:00