Commit Graph

1254 Commits

Author SHA1 Message Date
Yukihiro "Matz" Matsumoto ff57c0278f Remove broken MRB_INT16 configuration option. 2020-01-15 21:32:00 +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
Yukihiro "Matz" Matsumoto 9174b18f34 Rename mrb_num_args_error to mrb_argnum_error; ref #4863 2020-01-01 22:37:14 +09:00
Yukihiro "Matz" Matsumoto b9c78c3fcc Merge pull request #4863 from shuujii/add-mrb_num_args_error-for-wrong-number-of-arguments-error
Add `mrb_num_args_error()` for "wrong number of arguments" error
2020-01-01 22:34:22 +09:00
KOBAYASHI Shuji 0b2d54f4f1 Fix potentially use of wrong method cache
#### Example (with `MRB_METHOD_CACHE`)

  ```ruby
  GC.start
  c = Class.new
  p c            #=> #<Class:0x7fd6a180e790>
  c.new          #=> cache `c.new`
  c = nil
  GC.start       #=> `c` is GCed
  r = Range.dup
  p r            #=> #<Class:0x7fd6a180e790>
                 #   [same pointer as `c`]
  r.new(2, 3)    #=> ArgumentError: 'initialize':
                 #   wrong number of arguments (2 for 0)
                 #   [`c.new` is called instead of `r.new`]
  ```

#### Cause

  An entry of method cache is identified by class pointer and method
  id. However, reusing memory after GC may create a class with the same
  pointer as the cached class.

#### Treatment

  Cleared method caches of the class when the class is GCed.
2019-12-25 21:31:10 +09:00
KOBAYASHI Shuji d2f2f9db51 Remove location info from Exception#inspect
Because location info (file name and line number) is kept in the backtrace,
it should not be kept in the result of `inspect` (and the exception object
itself), I think.

### Example

  ```ruby
  # example.rb
  begin
    raise "err"
  rescue => e
    p e
  end
  ```

#### Before this patch:

  ```
  $ bin/mruby example.rb
  example.rb:2: err (RuntimeError)
  ```

#### After this patch:

  ```
  $ bin/mruby example.rb
  err (RuntimeError)
  ```
2019-12-14 22:29:37 +09:00
KOBAYASHI Shuji 81de1f159c Add mrb_num_args_error() for "wrong number of arguments" error
To unify the style of messages.
2019-12-12 11:45:58 +09:00
Ukrainskiy Sergey 72d57ad094 Implement numbered parameters 2019-12-09 20:50:41 +09:00
KOBAYASHI Shuji a53f28275e Fix MRB_FIXNUM_SHIFT with MRB_WORD_BOXING, MRB_INT32 and MRB_64BIT
### Example

  ```ruby
  # example.rb
  max32 = 2**30 - 1 + 2**30
  min32 = -max32-1
  [max32, max32+1, min32, min32-1].each{|n| p [n, n.class]}
  ```

#### Before this patch:

  ```
  $ bin/mruby example.rb
  [2147483647, Float]
  [2147483648, Float]
  [-2147483648, Float]
  [-2147483649, Float]
  ```

#### After this patch:

  ```
  $ bin/mruby example.rb
  [2147483647, Fixnum]
  [2147483648, Float]
  [-2147483648, Fixnum]
  [-2147483649, Float]
  ```
2019-12-01 22:09:38 +09:00
KOBAYASHI Shuji 375c1ebc41 Rename BITSIZE to BIT and BIT to BIT_POS for consistency
The bit width terminology is unified to `BIT` according to `MRB_INT_BIT`
and `CHAR_BIT`. Also the bit position terminology is unified to `BIT_POS`.
2019-11-23 20:40:23 +09:00
Yukihiro "Matz" Matsumoto 8bcf44669c Merge pull request #4835 from shuujii/introduce-mrb_ssize-type-for-buffer-size-on-memory
Introduce `mrb_ssize` type for buffer size on memory; ref #4483
2019-11-22 19:40:19 +09:00
KOBAYASHI Shuji a2df247063 Introduce mrb_ssize type for buffer size on memory; ref #4483
Previously, `mrb_int` was used as the type that represents the buffer size
on memory, but the sizes of `RString` and `RArray` exceed 6 words when
`MRB_INT64` is enabled on 32-bit CPU.

I don't think it is necessary to be able to represent the buffer size on
memory that exceeds the virtual address space. Therefore, for this purpose,
introduce `mrb_ssize` which doesn't exceed the sizes of `mrb_int` and
pointer.

I think all `mrb_int` used for this purpose should be changed to
`mrb_ssize`, but currently only the members of the structures (`RString`,
`mrb_shared_string`, `RArray` and `mrb_shared_array`) are changed.
2019-11-21 19:34:02 +09:00
Yukihiro "Matz" Matsumoto 1bb1df19d8 Merge pull request #4831 from shuujii/always-enable-the-rational-and-complex-literals
Always enable the rational and complex literals
2019-11-19 23:32:16 +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
Hiroshi Mimaki 57a56ddaa2 Release mruby 2.1.0. 2019-11-19 18:58:11 +09:00
Hiroshi Mimaki 4eb8fca140 Merge branch 'master' into stable 2019-10-23 15:44:21 +09:00
Yukihiro "Matz" Matsumoto fa85f91e0e Add type cast to avoid an error from int and enum mixture; fix #4786 2019-10-23 14:47:55 +09:00
Hiroshi Mimaki 4c91adc4b2 Update version to 2.1.0. (mruby 2.1.0 RC) 2019-10-18 14:59:27 +09:00
dearblue 5f929d6940 Get keyword arguments with mrb_get_args()
Keyword arguments can now be retrieved with the `:` specifier and
`mrb_kwargs` data.

For the interface, I referred to CRuby's `rb_get_kwargs()`.
For implementation, I referred to `OP_KARG` or etc.
2019-10-06 21:23:55 +09:00
Yukihiro "Matz" Matsumoto 1f5a7f2f49 Freeze strings from nil.to_s, true.to_s, false.to_s.
This is an experimental changes in Ruby 2.7.
2019-10-04 16:02:50 +09:00
Hirohito Higashi 63496a6730 Fix opcode semantics comment miss. (op_jmpnil) 2019-10-03 15:06:06 +09:00
Hirohito Higashi b4bf7a2282 Fix opcode semantics comment miss. 2019-10-03 14:44:47 +09:00
KOBAYASHI Shuji 482d0626b8 Remove a trailing space in MRUBY_DESCRIPTION 2019-09-30 21:39:13 +09:00
dearblue 40e8a90e89 Remove unnecessary type mrb_hash_value
The type `mrb_hash_value` is no longer used by the segmented list
implementation (ref e8dcfe1 and e65d426).
2019-09-29 23:55:38 +09:00
Yukihiro "Matz" Matsumoto bbfd64d01b Add an annotation of the return value from mrb_delete_key; #4737
The return value from `mrb_delete_key` needs to be protected from GC in
some cases.
2019-09-29 13:53:45 +09:00
Yukihiro "Matz" Matsumoto 5cd6ed4511 Merge pull request #4733 from shuujii/use-type-predicate-macros-instead-of-mrb_type-if-possible
Use type predicate macros instead of `mrb_type` if possible
2019-09-27 00:00:03 +09:00
Yukihiro "Matz" Matsumoto d4be545d54 Fixed codedump for human readable symbol format; ref #4684 2019-09-26 23:56:40 +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 184aeb0694 Merge pull request #4732 from dearblue/inttypes
Use inttypes for `snprintf()`
2019-09-26 06:31:07 +09:00
Yukihiro "Matz" Matsumoto 9bf193b49a Merge pull request #4728 from shuujii/remove-MRB_TT_HAS_BASIC-macro
Remove `MRB_TT_HAS_BASIC` macro
2019-09-25 23:55:55 +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
dearblue 84d9296c05 Use inttypes for snprintf() 2019-09-25 23:28:05 +09:00
KOBAYASHI Shuji 27e8ea4ea2 Remove MRB_TT_HAS_BASIC macro
The value of `MRB_TT_HAS_BASIC` is meaningless because `MRB_TT_HAS_BASIC` is
no longer used with `MRB_WORD_BOXING` at b2c3d88f.
2019-09-25 18:17:01 +09:00
KOBAYASHI Shuji 5dda4f5da3 Implement all type predicate macros for MRB_WORD_BOXING
The default implementations of type predicate macros use `mrb_type`.
But `mrb_type` with `MRB_WORD_BOXING` isn't very efficient, so the new
implementations avoid `mrb_type`.
2019-09-22 22:36:12 +09:00
Fangrui Song 7f044341f9 Rename MRB_USE_ETEXT_EDATA to MRB_USE_LINK_TIME_RO_DATA_P and support lld linked programs
In lld linked programs, .rodata comes before .text, thus mrb_ro_data_p
will return false for strings in .rodata. Change the lower bound from
_etext to __ehdr_start to catch these cases. This works for ld.bfd, gold
and lld, and it does not have false positives even if .init_array does
not exist.

Remove the branch that uses _edata: strings in .data can be modified so
this is semantically incorrect. Delete the __APPLE__ branch (its
manpages say get_etext() and get_edata() are strongly discouraged).
.init_array has been adopted by most ELF platforms to supersede .ctors.

Neither _etext nor _edata is used, so rename MRB_USE_ETEXT_EDATA to
MRB_USE_EHDR_START.
2019-09-21 17:55:14 -07:00
Yukihiro "Matz" Matsumoto 2256bb07b0 Remove MRB_METHOD_TABLE_INLINE.
`MRB_METHOD_TABLE_INLINE` was fragile. It requires `-falign-functions=n`.
On platform that uses higher bits of function pointers, you can use new
`MRB_METHOD_T_STRUCT` configuration macro.
2019-09-16 11:14:13 +09:00
Yukihiro "Matz" Matsumoto 30f3787248 Raise ArgumentError by aspec check; ref #4688
This is partial `aspec` check that only checks `MRB_ARGS_NONE()`.
2019-09-16 10:50:31 +09:00
Yukihiro "Matz" Matsumoto 2764fdf9f0 Share common definition of MRB_METHOD_FUNC_FL. 2019-09-16 10:10:09 +09:00
Yukihiro "Matz" Matsumoto 0eb9355acd Use bit shifting to pack function pointers to mrb_method_t.
So you don't need `-falign-functions=2` anymore. Instead your platform
must not use higher bits of the pointer (true for most platforms).
If not, you have to use `struct mrb_method_t` version.
2019-09-16 10:10:09 +09:00
Yukihiro "Matz" Matsumoto 743d480fba Refactor mrb_method_t. 2019-09-16 10:10:09 +09:00
KOBAYASHI Shuji 7fcda585bc Refactor mrb_type in include/mruby/boxing_word.h 2019-09-15 18:11:16 +09:00
Yukihiro "Matz" Matsumoto 28bbd3e7d9 Add argument names to C function prototypes. 2019-09-14 23:21:44 +09:00
Yukihiro "Matz" Matsumoto 57d7fe94a9 Add a macro mrb_frozen_p that points to MRB_FROZEN_P. 2019-09-14 23:21:44 +09:00
Yukihiro "Matz" Matsumoto 76f1aa7de5 Remove mrb_funcall from <=> operations. 2019-09-14 09:05:32 +09:00
KOBAYASHI Shuji d47bd0a2cd Optimize mrb_bool() with MRB_WORD_BOXING 2019-09-08 12:17:25 +09:00
KOBAYASHI Shuji 17c53040ab Increase symbol bit size on 32-bit mode with MRB_WORD_BOXING
This change increases the max length of lower inline symbols to 5 bytes.
2019-09-07 21:38:11 +09:00
KOBAYASHI Shuji 19e2cc187b Avoid bit fields in mrb_value; ref b2c3d88f
The changes at b2c3d88f were inappropriate because the memory layout of bit
fields are implementation defined. Therefor, I fixed it not to use bit
fields.
2019-09-06 13:24:35 +09:00
Yukihiro "Matz" Matsumoto 5cd52d2d69 Fix an error in refactoring; fix #4682 2019-09-02 08:41:44 +09:00
Yukihiro "Matz" Matsumoto 1a4ea94bc7 Fix mrb_immediate_p(MRB_TT_FREE) to return false; ref #4679 2019-08-31 23:19:08 +09:00
Yukihiro "Matz" Matsumoto d48a2190bf Refactor #4662 with different names. 2019-08-31 22:14:25 +09:00