668 Commits

Author SHA1 Message Date
Yukihiro "Matz" Matsumoto e6cf932d38 fixup! mruby/internal.h: add codedump functions to the internal function header 2023-01-18 10:37:48 +09:00
Yukihiro "Matz" Matsumoto 55eea005c8 mruby/internal.h: add codedump functions to the internal function header
ref #5906
2023-01-18 10:37:48 +09:00
dearblue c101261f45 Call mrb_env_unshare() in mrb_top_run() if necessary
This is to keep the local variables of the previously created blocks consistent in case the `mrbc_context` passed to `mrb_load_exec()` is `NULL` or different.
Switching between `mrbc_context` pointers that are non `NULL` can be done safely by calling `mrbc_cleanup_local_variables()`.

Before this patch, the result of the following code is not as expected.

```console
% cat loadstr.c
#include <mruby.h>
#include <mruby/compile.h>

int
main(int argc, char *argv[])
{
  mrb_state *mrb = mrb_open();

  mrb_load_string(
      mrb,
      "(a, b, c, d, e, f, g) = [1, 2, 3, 4, 5, 6, 7] \n"
      "$lambda = -> { p [a, b, c, d, e, f, g] }");
  mrb_load_string(mrb, "$lambda.call");

  mrb_close(mrb);

  return 0;
}

% $(bin/mruby-config --cc --cflags --ldflags) loadstr.c $(bin/mruby-config --libs) && ./a.out
[main, nil, nil, main, nil, nil, main]
```

Also, since `mrb_env_unshare()` was not used before, the internal stack of simply detached `env` objects could show invalid addresses by `stack_extend()`.
ref. https://github.com/kou/mruby-pp/commit/ef5951aca870183d8767cb61f6414240988ca35e
2023-01-09 22:47:37 +09:00
Yukihiro "Matz" Matsumoto f7a8a42521 mruby-compiler/parse.y: allow multiple anonymous splat in args rule
For example, this should be allowed:

```ruby
def f(*)
  p(*,*)
end
```
2022-12-17 09:37:44 +09:00
Yukihiro "Matz" Matsumoto 855e63e17c parse.y: avoid using mrb_bug(); ref #5852 2022-11-25 16:17:29 +09:00
Yukihiro "Matz" Matsumoto 9c5dc42e59 small cosmetic changes.
I prefer `i++` style unless absolutely necessary.
This commit is an addition to 41e4148.
2022-11-19 17:11:56 +09:00
Yukihiro "Matz" Matsumoto 4a888a34bb readfloat.c (mrb_read_float): a new function.
We no longer use `mrb_float_read()` that depends on `errno`.
2022-11-07 16:09:31 +09:00
Yukihiro "Matz" Matsumoto 4e9773ae3d readint.c (mrb_int_read): new function.
We no longer use `mrb_read_int` which is kinda compatible with `strtol`.
2022-11-07 16:09:31 +09:00
Yukihiro "Matz" Matsumoto 4f385f119c parse.y (call_with_block): a->cdr may be NULL. 2022-11-04 14:05:52 +09:00
fn ⌃ ⌥ 273fcbc347 ops.h: update OP_ARYDUP instruction and rename to OP_ARYSPLAT.
Transforms the value of a splat inside a return statement (similar
to an array). For example, `return *nil` should return `nil.to_a`,
while `return *1` should return `[1]`
2022-10-29 19:54:34 -07:00
Yukihiro "Matz" Matsumoto ce86585281 Merge pull request #5812 from FnControlRuby/block
parse.y: fix return/break/next with method call with args and block
2022-10-29 16:29:41 +09:00
Yukihiro "Matz" Matsumoto 02f44d76fc codegen.c: stop peephole optimization for headless case statement.
This fixes #5815
2022-10-28 15:57:35 +09:00
Yukihiro "Matz" Matsumoto 9ff247c5c2 Revert "codegen.c: exit headless case early if a condition is always true"
This reverts commit e5b32e559860073632fc7b69cb98b90f2c069e81; ref #5815
2022-10-28 15:54:40 +09:00
fn ⌃ ⌥ fee8f540c6 parse.y: fix return/break/next with method call with args and block 2022-10-21 20:01:08 -07:00
fn ⌃ ⌥ e5b32e5598 codegen.c: exit headless case early if a condition is always true 2022-10-21 20:00:44 -07:00
fn ⌃ ⌥ 6ba44f64d5 parse.y: fix NODE_REGX dump 2022-10-18 20:56:00 -07:00
Yukihiro "Matz" Matsumoto 751ac378bd codegen.c: should not skip rhs array; fix #5797
When the value of multiple assignment taken, the rhs array needs to be
generated anyway.
2022-10-01 15:18:45 +09:00
Yukihiro "Matz" Matsumoto 7c0f7e2665 parse.y: allow NUMPARAMs (e.g. _1) as hash keys; fix #5785 2022-08-23 18:36:26 +09:00
Yukihiro "Matz" Matsumoto a641f146fc codegen.c (gen_assignment): use nsym() instead of simple type cast. 2022-08-23 11:30:54 +09:00
Yukihiro "Matz" Matsumoto 108875c972 codegen.c (gen_assignment): support NODE_COLON3 as lhs; fix #5752
We should allow `::C = 1` for example.
2022-08-23 07:53:23 +09:00
dearblue 5bc15dd69b Fixed assertion in ARGUMENT_NORMALIZE() for bidx.
It should be compared to the `irep->nregs` value as is.

At the same time, discovered problems have been fixed.
2022-08-04 22:43:06 +09:00
dearblue 43fdce5019 Protected proc objects given by OP_DEF on registers
If a GC occurs in `mrb_calloc()` called by `mt_rehash()` inside `mrb_define_method_raw(), the `proc` may be destroyed.
2022-07-30 22:34:50 +09:00
Yukihiro "Matz" Matsumoto c2e4b82d84 codegen.c (new_litbint): remove surrounding braces.
It was to allow local variable declarations, but now we allow
declarations in the middle.
2022-07-26 13:55:54 +09:00
Yukihiro "Matz" Matsumoto e8ce82bf31 codegen.c (new_litbint): forgot else in a107b85. 2022-07-26 00:11:53 +09:00
Yukihiro "Matz" Matsumoto c6bf4eaac0 codegen.c (new_litbint): renamed from new_litbn. 2022-07-25 15:33:43 +09:00
Yukihiro "Matz" Matsumoto a107b850eb codegen.c (new_bitbn): fixed wrong packing of integer radix. 2022-07-25 15:31:43 +09:00
Yukihiro "Matz" Matsumoto 2b07489372 codegen.c: keep stack space for block argument. 2022-07-20 14:27:02 +09:00
Yukihiro "Matz" Matsumoto e1980d7596 numeric.c (mrb_div_int): separate the function in two.
- mrb_div_int() does integer division in Ruby way (mdiv)
  returns mrb_int
- mrb_div_int_value() division with zero div and overflow checks.
  returns mrb_value
2022-07-09 14:38:18 +09:00
Yukihiro "Matz" Matsumoto ce89ab8660 parse.y: class cannot be followed by modifier if. [ruby-bugs:18884] 2022-07-02 10:31:33 +09:00
Yukihiro "Matz" Matsumoto 7005f8661b parse.y (paser_pfree): recycle memory if possible. 2022-06-15 07:28:05 +09:00
Yukihiro "Matz" Matsumoto 561dffcccc parse.y: fix nested here-document bug; fix #5607
- remove `lex_strterm_before_heredoc` that does not nest
- remove `all_heredocs` that cannot distinguish nested and followed
  here-doc
- replace `lex_strterm` represented by cons list by C struct
- push/pop `lex_strterm` before/after interpolation
2022-06-13 22:25:37 +09:00
Yukihiro "Matz" Matsumoto 3cab2e7b78 mruby-compiler: remove spaces before * in type casting. 2022-06-13 17:00:30 +09:00
Yukihiro "Matz" Matsumoto b1f6c856e3 parse.y (nextc0): small refactoring. 2022-06-08 21:59:51 +09:00
Yukihiro "Matz" Matsumoto 0d2c550f0f parse.y: use info as abbreviation for information.
Replace `inf` that looks like abbreviation for `infinity`.
2022-06-07 18:42:53 +09:00
Yukihiro "Matz" Matsumoto 9cc9c9fe63 parse.y (heredoc_treat_nextline): simplify the logic using append(). 2022-06-06 08:00:04 +09:00
Yukihiro "Matz" Matsumoto 81fb3c5a4b parse.y: need to update p->lex_strterm in heredoc_treat_nextline(). 2022-06-06 08:00:03 +09:00
Yukihiro "Matz" Matsumoto 5233865c47 codegen.c (search_upvar): update messages for anonymous parameters. 2022-06-03 13:00:13 +09:00
Yukihiro "Matz" Matsumoto aec849888e parse.y (new_kw_rest_args): aggregate integer to node* type casts. 2022-06-03 13:00:12 +09:00
Yukihiro "Matz" Matsumoto 5cbce646b0 parse.y: allow anonymous rest (and keyword rest) arguments. 2022-06-03 13:00:12 +09:00
Yukihiro "Matz" Matsumoto af5acf3566 parse.y: fix wrong indent [ci skip]. 2022-05-30 01:16:47 +09:00
John Bampton 73580c49c4 Fix spelling 2022-05-17 19:47:54 +10:00
Yukihiro "Matz" Matsumoto 0299ccf6c7 parse.y: allow inner anonymous block argument. 2022-05-16 14:17:21 +09:00
Yukihiro "Matz" Matsumoto 790910b50a codegen.c: genop_3 to take uint16_t instead of uint8_t. 2022-04-17 09:32:04 +09:00
dearblue 1354ad96ec Avoid creating temporary objects with new_lit() in codegen.c
At the same time, the saving and restoration of unwanted object arenas was removed.
In addition, the common code to extend the pool that existed before has been grouped together and newly established as `lit_pool_extend()`.
Note that previously the variable `i` was updated at that time, but since it is the same as the value at the end of a `for` statement, it has been omitted.

The original catalyst was that `bin/mrbc` with the `MRB_WORD_BOXING` + not `MRB_BOXWORD_NO_FLOAT_TRUNCATE` configuration caused `bin/mrbtest` with the `MRB_NO_BOXING` configuration to fail.
Upon investigation, I concluded that avoiding the creation of temporary objects would prevent the truncation of floating point numbers.
Therefore, this patch also prevents the `rake test` from failing with the following configuration.

```console
% cat test_config.rb
bootstrap_mrbc = nil

MRuby::Build.new do |conf|
  conf.toolchain
  conf.enable_debug
  conf.enable_test
  conf.disable_presym
  conf.defines << %w(MRB_WORD_BOXING)
  #conf.defines << %w(MRB_WORDBOX_NO_FLOAT_TRUNCATE)
  gem core: "mruby-bin-mrbc"
  gem core: "mruby-kernel-ext"
  bootstrap_mrbc = File.join(conf.build_dir, "bin/mrbc")
end

MRuby::Build.new("nobox") do |conf|
  conf.toolchain
  conf.enable_debug
  conf.enable_test
  conf.defines << %(MRB_NO_BOXING)
  conf.mrbcfile = bootstrap_mrbc
  gem core: "mruby-kernel-ext"
end
```
2022-04-16 18:22:32 +09:00
Yukihiro "Matz" Matsumoto c8c083cb75 codegen.c: need to pack argument when n==13 too.
Because we have extra 2 arguments coming (kw and rhs).
2022-04-09 17:16:12 +09:00
Yukihiro "Matz" Matsumoto b99c389ec3 internal.h: aggregate internal functions.
Internal functions can only be called from within the library.
Functions listed in `mruby/internal.h` can be called from:

* core (src/*.c)
* gems (mrbgems/**/*.c)

But not from the application linked with `libmruby`.
2022-04-02 18:25:13 +09:00
Yukihiro "Matz" Matsumoto a3f2c95334 codegen.c: skip overwritten MOVE instructions. 2022-03-30 15:34:40 +09:00
Yukihiro "Matz" Matsumoto 60cf382ff9 codegen.c: peephole optimize consecutive MOVE instructions. 2022-03-29 22:36:40 +09:00
Yukihiro "Matz" Matsumoto a91b55f5ca codegen.c: allow constant folding for multiply with zero. 2022-03-26 11:20:59 +09:00
Yukihiro "Matz" Matsumoto 90969cef4c codegen.c: fix the negative division regression; fix #5678 2022-03-26 11:20:59 +09:00