Yukihiro "Matz" Matsumoto
ab1047b445
codegen.c: no OP_ARGARY is needed here.
2021-10-04 07:45:46 +09:00
Yukihiro "Matz" Matsumoto
09336c5d49
mruby/ops.h: add new instructions OP_GETIDX and OP_SETIDX.
...
Which represent `obj[int]` and `obj[int]=val` respectively where `obj`
is either `string`, `array` or `hash`, so that index access could be
faster. When `obj` is not assumed type or `R(a+1)` is not integer, the
instructions fallback to method calls.
2021-10-03 17:14:00 +09:00
Yukihiro "Matz" Matsumoto
31e3dbc5a8
Merge branch 'inline-struct-gem' of https://github.com/dearblue/mruby into dearblue-inline-struct-gem
2021-10-02 20:09:20 +09:00
Yukihiro "Matz" Matsumoto
bb3cd69aff
value.h: introduce MRB_TT_STRUCT for mruby-struct.
2021-09-30 12:46:45 +09:00
Yukihiro "Matz" Matsumoto
906f9f2ba7
parse.y: __ENCODING__ should be determined in run-time; fix #5552
...
It used to be compiled to the static string in the compiler. But the
encoding status actually depends on the runtime configuration. A new
method `Kernel#__ENCODING__` is introduced to implement the feature.
2021-09-27 10:10:35 +09:00
Yukihiro "Matz" Matsumoto
368e8ce3d5
codegen.c: should not loop_push() before constant folding.
...
Otherwise, the following code will crash:
```ruby
1.times{{}until 1; break}
```
2021-09-26 16:58:40 +09:00
Yukihiro "Matz" Matsumoto
89ea41f15e
mrbconf.h: rename a configuration macro for no truncate floats.
...
Rename `MRB_WORDBOX_USE_HEAP_FLOAT` to `MRB_WORDBOX_NO_FLOAT_TRUNCATE'.
2021-09-25 14:44:43 +09:00
Yukihiro "Matz" Matsumoto
ab54ca272a
codegen.c: refactor NODE_WHILE and NODE_UNTIL.
2021-09-24 11:39:00 +09:00
Yukihiro "Matz" Matsumoto
7c6c4ebb56
codegen.c: add short circuit constant folding for NODE_AND, NODE_OR.
2021-09-24 11:38:02 +09:00
Yukihiro "Matz" Matsumoto
863671c89f
codegen.c: refactor NODE_IF generation for boolean constants.
...
In addition, add `NODE_SYM` for always true expression.
2021-09-24 11:36:27 +09:00
Yukihiro "Matz" Matsumoto
a844f89655
codegen.c: need to check no_peephole() before constant folding.
2021-09-23 21:19:36 +09:00
Yukihiro "Matz" Matsumoto
4c196dbba5
codegen.c: separate maximum stack size from GEN_LIT_ARY_MAX.
2021-09-23 20:11:30 +09:00
Yukihiro "Matz" Matsumoto
d6dd6f0e7b
Update struct initializer to work with relatively older C++.
2021-09-20 19:13:17 +09:00
Yukihiro "Matz" Matsumoto
c29822f80c
codegen.c (gen_addsub): use mrb_int_sub_overflow().
2021-09-20 17:32:38 +09:00
Yukihiro "Matz" Matsumoto
0455313a9b
codegen.c: avoid constant folding OP_LOADI16 across branch target.
2021-09-20 17:30:14 +09:00
Yukihiro "Matz" Matsumoto
ca7228ad42
codegen.c: gen_move should generate proper OP_LOADI16.
2021-09-20 16:58:27 +09:00
Yukihiro "Matz" Matsumoto
1baf08f174
codegen.c: rename loopinfo->acc to reg.
...
`acc` meant `accumulator` but it is not an accumulator but just a
register position.
2021-09-20 10:40:30 +09:00
Yukihiro "Matz" Matsumoto
2083d99392
codegen.c: check no_peephole(s) before mrb_last_insn(s).
2021-09-20 10:37:11 +09:00
Yukihiro "Matz" Matsumoto
f85c50543b
codegen.c (mrb_last_insn): no previous instruction on top.
2021-09-20 10:35:01 +09:00
Yukihiro "Matz" Matsumoto
8bfa99975c
codegen.c: unify OP_ARYPUSH and OP_ARYPUSH_N.
...
- `OP_ARYPUSH` now takes operand for the number of pushing elements
- the code generator consume the stack no more than `64` for `mruby/c`
2021-09-19 09:07:20 +09:00
Yukihiro "Matz" Matsumoto
7c99df8416
ops.h: add OP_ARYPUSH_N instruction.
...
Add n elements at once. Reduces instructions for huge array
initialization. In addition, `gen_value` function in `codegen.c` was
refactored and clarified.
2021-09-17 07:49:47 +09:00
Yukihiro "Matz" Matsumoto
8619ba6a38
Use struct initializer instead of memset.
2021-09-15 13:02:15 +09:00
Yukihiro "Matz" Matsumoto
e5e7bd29ef
sprintf.c: width may have been INT_MAX.
...
Now `width` is limited to `INT16_MIN..INT16_MAX`.
2021-09-14 14:12:56 +09:00
Yukihiro "Matz" Matsumoto
6dbf49fdb4
parse.y: cons_free unused node (empty string node).
2021-09-13 12:20:11 +09:00
Yukihiro "Matz" Matsumoto
100eac3fec
parse.y: allow non-local variable access from hash value omission.
...
For example, `{p:}` (means `{p:p}`) and `{String:}` (`{String:String}`)
should be allowed like CRuby.
2021-09-13 12:15:10 +09:00
Yukihiro "Matz" Matsumoto
6c76926d05
parse.y: allow value omission in Hash literals introduced in Ruby3.1.
...
`{x:, y:}` now is a syntax sugar of `{x: x, y: y}`.
This fix also includes the update of #4815 fix.
2021-09-13 11:04:27 +09:00
Yukihiro "Matz" Matsumoto
31fc74f5a8
parse.y: fix nint (int to node) and intn (node to int).
2021-09-12 23:14:43 +09:00
Yukihiro "Matz" Matsumoto
9e86d204e5
parse.y: avoid adding zero length strings.
2021-09-12 07:58:57 +09:00
Yukihiro "Matz" Matsumoto
cd0ffd6f1c
codegen.c: fixed gen_setxv bug with taking assignment value; fix #5550
2021-09-10 15:39:24 +09:00
Yukihiro "Matz" Matsumoto
69da192eec
codegen.c: gen_move refactoring.
2021-09-10 15:38:51 +09:00
Yukihiro "Matz" Matsumoto
7df31d9451
mruby.h: remove acc from callinfo; add cci instead.
...
`acc` was used as an index of the receiver (if positive), or a flag for
methods implemented in C. We replace `regs[ci->acc]` by `ci[1].stack[0]`.
And renamed `acc` (originally meant accumulator position) to `cci`
(means callinfo for C implemented method).
2021-09-10 12:39:51 +09:00
Yukihiro "Matz" Matsumoto
28b5c30b96
ops.h: add OP_SYMBOL instruction.
...
It generates a symbol by interning from the pool string.
2021-09-10 10:23:28 +09:00
Yukihiro "Matz" Matsumoto
b34713304a
fixup! codegen.c: resurrect s->lastpc to reduce iseq scans.
2021-09-10 10:22:49 +09:00
Yukihiro "Matz" Matsumoto
5fbea87fe5
codegen.c: resurrect s->lastpc to reduce iseq scans.
...
When parsing scripts frequent scans could cost too much.
2021-09-10 10:15:55 +09:00
Yukihiro "Matz" Matsumoto
cbfaa5e20f
object.c: rename mrb_to_int to mrb_to_integer.
...
Consistent naming: `integer` to represent integer packed in `mrb_value`
instead of `int`.
2021-09-07 14:31:56 +09:00
Yukihiro "Matz" Matsumoto
79bc8e2539
string.h: rename mrb_str_to_inum to mrb_str_to_integer.
...
Consistent naming: `integer` to represent integer packed in `mrb_value`
instead of `inum`.
2021-09-07 14:31:56 +09:00
Yukihiro "Matz" Matsumoto
674d841ead
eval.c: if the parser raises an exception without an error message
...
`eval` would have crashed in formatting.
2021-09-07 07:37:19 +09:00
Yukihiro "Matz" Matsumoto
711f06a562
eval.c: check length of the file name.
...
It should be lexx than `UINT16_MAX`. If you don't check here, the parser
would raise an exception.
2021-09-07 07:35:35 +09:00
Yukihiro "Matz" Matsumoto
6fc6880f1f
codegen.c: improve exception handling in generate_code.
...
- remove `mrb_jmpbuf` from `codegen_scope`
- unify exception handling of `mrb_state` and `codegen_scope`
2021-09-07 07:33:28 +09:00
Yukihiro "Matz" Matsumoto
2fb06aabe6
parse.y: refactor mrb_parser_parse().
...
- remove `mrb_jmpbuf` from `truct mrb_parser_state`
- unify exception handling of `mrb_state` and `mrb_parser_state`.
2021-09-07 07:31:21 +09:00
Yukihiro "Matz" Matsumoto
ad3404229f
parse.y: refactoring mrb_parser_parser().
2021-09-06 13:58:01 +09:00
Yukihiro "Matz" Matsumoto
7552b9322a
codegen.c: avoid integer overflow.
2021-09-05 09:25:44 +09:00
Yukihiro "Matz" Matsumoto
28c4f2f683
kernel.c: add __method__; ref #4468
2021-09-04 17:57:35 +09:00
KOBAYASHI Shuji
8a9f891fd3
Rename Kernel#__method__ to Kernel#__callee__
...
Because the current behavior of `__method__` is equivalent to `__callee__`.
Example:
# example.rb
def src
__send__(ARGV[0])
end
alias dst src
%w[src dst].each {|n| puts "call #{n} => #{__send__(n).inspect}"}
Ruby:
$ ruby example.rb __method__
call src => :src
call dst => :src
$ ruby example.rb __callee__
call src => :src
call dst => :dst
mruby:
$ mruby example.rb __method__
call src => :src
call dst => :dst
2021-09-04 16:17:06 +09:00
Stuart Hinson
2c167361d5
use gender-neutral pronouns
2021-08-31 19:17:49 -07:00
Yukihiro "Matz" Matsumoto
2c41739b66
mruby.h: obsolete mrb_to_str().
...
Replace them by `mrb_ensure_string_type()`.
2021-09-01 07:00:55 +09:00
Yukihiro "Matz" Matsumoto
8c296a3818
object.c: remove `mrb_convert_to_integer()' function.
...
And merged to `mrb_f_integer()` which is only usage of the function.
2021-09-01 07:00:54 +09:00
Yukihiro "Matz" Matsumoto
37a7ff228b
string-ext/string.c: implement casecmp in C.
...
* should not raise error for non-string arguments
* avoid allocating case converted string internally
2021-09-01 07:00:54 +09:00
Yukihiro "Matz" Matsumoto
e86c9cb57c
Do no use return values from mrb_ensure_ functions.
...
They return the checking argument without modification, so the values
are already there. Maybe we should change the return type to `void` but
keep them unchanged for compatibility.
2021-09-01 07:00:54 +09:00
Yukihiro "Matz" Matsumoto
fdfa0caa46
boxing_word.h: rename configuration macro name.
...
`MRB_WORDBOX_USE_HEAP_FLOAT` instead of `MRB_USE_FLOAT_FULL_PRECISION`.
2021-08-26 16:06:01 +09:00