333 Commits

Author SHA1 Message Date
Yukihiro "Matz" Matsumoto 226fcb4f2a Avoid unnecessary nextc() recursion. 2020-04-01 23:23:07 +09:00
Yukihiro "Matz" Matsumoto dbba0ca517 p->locals may be NULL when error occurs before the point.
This is reported by oss-fuzz:
Issue 19886: mruby:mruby_fuzzer: Potential-null-reference in setup_numparams
2020-01-08 01:18:53 +09:00
Yukihiro "Matz" Matsumoto 111045ecad Avoid creating temporary objects in read_irep_record_1; close #4920
The basic idea of this change is from @dearblue.

Note: the arguments of `mrb_str_pool()` have changed, but the function
is provided for internal use (No `MRB_API`). So basically you don't have
to worry about the change.
2020-01-06 15:52:39 +09:00
dearblue 541185ef14 Fix ainfo with keyword arguments; fix #4921 2020-01-05 16:48:34 +09:00
Yukihiro "Matz" Matsumoto 943fbb2bea Allow here-doc in the middle of Hash expressions; fix #4815 2020-01-01 12:21:17 +09:00
Yukihiro "Matz" Matsumoto d2f34a8455 Merge pull request #4910 from shuujii/use-Rake-DSL-instead-of-commands-of-FileUtils
Use Rake DSL instead of commands of `FileUtils`
2019-12-27 18:35:19 +09:00
KOBAYASHI Shuji 26e6e75ba6 Use Rake DSL instead of commands of FileUtils
- Respect `--verbose(-v)` and `--dry-run(-n)` options.
- Silence warnings to keyword arguments on Ruby 2.7.
2019-12-27 16:49:32 +09:00
Yukihiro "Matz" Matsumoto d15e56dab0 Prohibit assignment to numbered parameters.
It is stricter than CRuby but confusing anyway.
2019-12-27 11:05:56 +09:00
Yukihiro "Matz" Matsumoto ff16331754 Allow non numbered-parameter identifier like _1 outside of blocks.
But it causes warnings as CRuby does; fix #4892 fix #489
2019-12-27 11:05:56 +09:00
Yukihiro "Matz" Matsumoto ed8491cde6 Numbered parameters: usually linked list uses cdr for links. 2019-12-27 11:05:56 +09:00
Yukihiro "Matz" Matsumoto 7e6355975e Prohibit numbered parameters as method arguments; fix #4892
As of CRuby2.7 it is only warned. `mruby` prohibits explicitly to
implement the future Ruby3 behavior.
2019-12-27 11:05:56 +09:00
take-cheeze 10e9f193ca Handle CR LF newline natively in lexer 2019-12-23 21:01:11 +09:00
Yukihiro "Matz" Matsumoto 06e09fc7a9 Numbered parameters should not be available in the lambda bodies.
`mruby` does not warn like `CRuby` for cases like #4893.
Fix #4890, fix #4891, fix #4893.
2019-12-21 22:41:32 +09:00
KOBAYASHI Shuji 74f564b0bb _0 is not numbered parameter
#### Before this patch:

  ```console
  $ bin/mruby rb -e '_0=:l; p ->{_0}.()'
  -e:1:13: _0 is not available
  -e:1:13: syntax error, unexpected $end, expecting '}'
  ```

#### After this patch (same as Ruby):

  ```console
  $ bin/mruby rb -e '_0=:l; p ->{_0}.()'
  :l
  ```
2019-12-21 18:54:15 +09:00
Yukihiro "Matz" Matsumoto 5cc595cb2a Fix SEGV from numbered parameters outside of blocks; fix #4862 2019-12-21 01:24:56 +09:00
Yukihiro "Matz" Matsumoto fb9e92e828 Warnings for numbered parameters in nested blocks. 2019-12-09 20:50:41 +09:00
Yukihiro "Matz" Matsumoto f7a0f11c36 Parser refactoring on numbered parameters.
Now identifiers like `_1abc` are allowed.
2019-12-09 20:50:41 +09:00
Yukihiro "Matz" Matsumoto 0011652a28 Support new numbered parameter syntax _1 instead of @1. 2019-12-09 20:50:41 +09:00
Ukrainskiy Sergey 72d57ad094 Implement numbered parameters 2019-12-09 20:50:41 +09:00
KOBAYASHI Shuji 351c9c80e7 Always enable the rational and complex literals
I think they can always be enabled because the regular expression literal is
always enabled.
2019-11-19 21:10:59 +09:00
KOBAYASHI Shuji 455930fbc4 Fix here document with EOF
#### Before this patch:

  ```
  $ bin/mruby -e 'p <<EOS
1
EOS'
  -e:4:0: can't find heredoc delimiter "EOS" anywhere before EOF
  -e:4:0: syntax error, unexpected $end, expecting tHEREDOC_END or tHD_STRING_PART or tHD_STRING_MID
  ```

#### After this patch (same as Ruby):

  ```
  $ bin/mruby -e 'p <<EOS
1
EOS'
  "1\n"
  ```
2019-11-14 20:28:36 +09:00
KOBAYASHI Shuji 29133b2fe2 Use mrb_intern_lit if possible in parse.y 2019-11-13 19:20:47 +09:00
KOBAYASHI Shuji ac917983c5 Use intern instead of intern_cstr if possible in parse.y 2019-11-12 21:04:12 +09:00
Yukihiro "Matz" Matsumoto 7750c61e29 Fixed a bug in keyword arguments in block parameters; fix #4810
This is caused by incomplete fix in #4746
2019-11-08 14:06:46 +09:00
Yukihiro "Matz" Matsumoto 962776fe25 Allow here-doc before closing parentheses; ref #4796 2019-11-08 09:50:48 +09:00
KOBAYASHI Shuji 4841754aba Avoid using C++ style comments (//) in parse.y [ci skip] 2019-11-04 22:12:59 +09:00
Yukihiro "Matz" Matsumoto 1dc0da8218 Fix here-doc inside parens and brackets; fix #4796 2019-10-30 10:05:28 +09:00
Yukihiro "Matz" Matsumoto c310c8dc24 Move exception raising to scope_new.
Besides that fix bugs that mistakenly calls `raise_error` that emits
code to raise runtime error instead of `codegen_error` that terminates
code generation immediately.
2019-10-11 20:31:29 +09:00
Yukihiro "Matz" Matsumoto 264239f78f Refactor local variables addition in optional/keyword arguments. 2019-10-04 14:39:53 +09:00
Yukihiro "Matz" Matsumoto ec6c8b2a3c Add local variable reordering to kwargs; ref #4746 2019-10-03 09:17:37 +09:00
Yukihiro "Matz" Matsumoto 47cdda370e Need to reorder local variables defined in opt; fix #4746
For example, local variables in the following def:
```ruby
def foo(a = (not_set = true), &block)
  ...
end
```
should be `a, block, not_set`, but were `a, not_set, block`.
2019-10-03 07:52:31 +09:00
Yukihiro "Matz" Matsumoto 306f02117b Refactor append_gen function. 2019-10-03 07:52:03 +09:00
Yukihiro "Matz" Matsumoto c33100c4f0 Merge pull request #4736 from dearblue/ast-strdump
Escape the AST string
2019-10-02 07:07:20 +09:00
KOBAYASHI Shuji 8df2763b56 Support NODE_LITERAL_DELIM in mrb_parser_dump
#### Before this patch:

  ```terminal
  $ bin/mruby -v -e '%w[1 2]'
  mruby 2.0.1 (2019-04-04)
  00001 NODE_SCOPE:
  00001   NODE_BEGIN:
  00001     NODE_WORDS:
  00001       NODE_STR "1" len 1
  00001       node type: 85 (0x55)
  00001       NODE_STR "2" len 1
  (snip)
  ```

#### After this patch:

  ```terminal
  $ bin/mruby -v -e '%w[1 2]'
  mruby 2.0.1 (2019-04-04)
  00001 NODE_SCOPE:
  00001   NODE_BEGIN:
  00001     NODE_WORDS:
  00001       NODE_STR "1" len 1
  00001       NODE_LITERAL_DELIM
  00001       NODE_STR "2" len 1
  (snip)
  ```
2019-10-01 17:20:39 +09:00
KOBAYASHI Shuji 42c7f2d6b0 Support NODE_SYMBOLS in mrb_parser_dump
#### Before this patch:

  ```terminal
  $ bin/mruby -v -e '%i[1]; %I[#{2}]'
  mruby 2.0.1 (2019-04-04)
  00001 NODE_SCOPE:
  00001   NODE_BEGIN:
  00001     node type: 87 (0x57)
  00001     node type: 87 (0x57)
  (snip)
  ```

#### After this patch:

  ```terminal
  $ bin/mruby -v -e '%i[1]; %I[#{2}]'
  mruby 2.0.1 (2019-04-04)
  00001 NODE_SCOPE:
  00001   NODE_BEGIN:
  00001     NODE_SYMBOLS:
  00001       NODE_STR "1" len 1
  00001     NODE_SYMBOLS:
  00001       NODE_STR "" len 0
  00001       NODE_BEGIN:
  00001         NODE_INT 2 base 10
  00001       NODE_STR "" len 0
  (snip)
  ```
2019-10-01 17:10:34 +09:00
KOBAYASHI Shuji 732ef6b10e Support NODE_WORDS in mrb_parser_dump
#### Before this patch:

  ```terminal
  $ bin/mruby -v -e '%w[1]; %W[#{2}]'
  mruby 2.0.1 (2019-04-04)
  00001 NODE_SCOPE:
  00001   NODE_BEGIN:
  00001     node type: 86 (0x56)
  00001     node type: 86 (0x56)
  (snip)
  ```

#### After this patch:

  ```terminal
  $ bin/mruby -v -e '%w[1]; %W[#{2}]'
  mruby 2.0.1 (2019-04-04)
  00001 NODE_SCOPE:
  00001   NODE_BEGIN:
  00001     NODE_WORDS:
  00001       NODE_STR "1" len 1
  00001     NODE_WORDS:
  00001       NODE_STR "" len 0
  00001       NODE_BEGIN:
  00001         NODE_INT 2 base 10
  00001       NODE_STR "" len 0
  (snip)
  ```
2019-10-01 17:07:30 +09:00
KOBAYASHI Shuji 16745261e3 Support NODE_DSYM in mrb_parser_dump
#### Before this patch:

  ```terminal
  $ bin/mruby -v -e ':"#{1}"; ["#{2}": 0]'
  mruby 2.0.1 (2019-04-04)
  00001 NODE_SCOPE:
  00001   NODE_BEGIN:
  00001     node type: 83 (0x53)
  00001     NODE_ARRAY:
  00001       NODE_KW_HASH:
  00001         key:
  00001           node type: 83 (0x53)
  00001         value:
  00001           NODE_INT 0 base 10
  (snip)
  ```

#### After this patch:

  ```terminal
  $ bin/mruby -v -e ':"#{1}"; ["#{2}": 0]'
  mruby 2.0.1 (2019-04-04)
  00001 NODE_SCOPE:
  00001   NODE_BEGIN:
  00001     NODE_DSYM:
  00001       NODE_DSTR:
  00001         NODE_STR "" len 0
  00001         NODE_BEGIN:
  00001           NODE_INT 1 base 10
  00001         NODE_STR "" len 0
  00001     NODE_ARRAY:
  00001       NODE_KW_HASH:
  00001         key:
  00001           NODE_DSYM:
  00001             NODE_DSTR:
  00001               NODE_STR "" len 0
  00001               NODE_BEGIN:
  00001                 NODE_INT 2 base 10
  00001               NODE_STR "" len 0
  00001         value:
  00001           NODE_INT 0 base 10
  (snip)
  ```
2019-09-30 11:54:51 +09:00
KOBAYASHI Shuji a5d140ae42 Print missing : before newline in mrb_parser_dump 2019-09-29 17:14:52 +09:00
dearblue e2f54ff594 Escape the AST string 2019-09-29 10:39:55 +09:00
KOBAYASHI Shuji ae530d89c4 Remove unused node type in codegen() 2019-09-28 15:15:31 +09:00
Yukihiro "Matz" Matsumoto 2de757eef0 Replace mrb_sym_name with mrb_sym_dump; ref #4684 2019-09-28 00:06:01 +09:00
KOBAYASHI Shuji feaf80d899 Use type predicate macros instead of mrb_type if possible
For efficiency with `MRB_WORD_BOXING` (implement type predicate macros for
all `enum mrb_vtype`).
2019-09-26 22:23:27 +09:00
Yukihiro "Matz" Matsumoto a365f9a67d Rename symbol-to-string functions; close #4684
* mrb_sym2name -> mrb_sym_name
* mrb_sym2name_len -> mrb_sym_name_len
* mrb_sym2str -> mrb_sym_str
2019-09-25 23:52:00 +09:00
Yukihiro "Matz" Matsumoto 0734d9f314 Merge pull request #4512 from lopopolo/patch-1
Support parsing a Regexp literal with 'o' option
2019-09-15 18:19:59 +09:00
Yukihiro "Matz" Matsumoto 6620b1cdcb Revert "Update %pure-parser to %define api.pure for newer bison; fix #4706"
The `bison` on MacOS does not support `%define api.pure`.
This reverts commit f7c9f1f796.
2019-09-14 10:28:07 +09:00
Yukihiro "Matz" Matsumoto f7c9f1f796 Update %pure-parser to %define api.pure for newer bison; fix #4706 2019-09-14 09:05:32 +09:00
Yukihiro "Matz" Matsumoto 49967097ed Skip nil? method call in if conditionals.
Compile `if expr.nil?` to use `OP_JMPNIL` instead of calls.
2019-08-31 22:14:25 +09:00
Yukihiro "Matz" Matsumoto 183fb961b3 Fixed a bug in the OP_JMPNOT optimization (13eaff4); fix #4644 2019-08-20 22:01:50 +09:00
Yukihiro "Matz" Matsumoto 3fbd5f0029 Merge pull request #4639 from dearblue/suppress-Wstringop-truncation
Suppress warnings for `strncat()`
2019-08-19 07:31:26 +09:00
dearblue 74395d7577 Suppress warnings for strncat()
`strncat()` also needs `'\0'`.
2019-08-18 15:46:17 +09:00