Commit Graph

160 Commits

Author SHA1 Message Date
fn ⌃ ⌥ 8c23385f62 Add reason for include 2022-12-29 08:08:55 -08:00
fn ⌃ ⌥ e6c0f324ae Use getsegmentdata instead of deprecated get_etext/get_edata 2022-12-28 08:50:59 -08:00
Yukihiro "Matz" Matsumoto 48e5ca4802 include/value.h (mrb_float_p): define always
even when `MRB_NO_FLOAT` is set. In that case, it is FALSE always.
2022-12-24 19:05:41 +09:00
Yukihiro "Matz" Matsumoto 9992de5a4f Rename MRB_TT_DATA to MRB_TT_CDATA
`TT_DATA` is too confusing with `Data` objects (which is immutable
Struct like objects introduced in Ruby 3.2).
2022-12-04 22:45:36 +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
dearblue 61c68927a2 Match the mrb_value documentation to the current implementation 2022-08-12 22:35:35 +09:00
Yukihiro "Matz" Matsumoto 72b60eb449 include/mruby/value.h: remove assertion from mrb_obj_value()
The function was called too often, so that even slightest assertion may
bother performance. The function is stable enough.
2022-06-30 08:11:36 +09:00
Yukihiro "Matz" Matsumoto dcaf4083d5 src/bigint.c: implement multi-precision integer.
To enable multi-precision integer support, you need to link
`mruby-bigint` mrbgem. The gem itself is empty but it turns on
the "bigint" support.
2022-04-09 17:16:10 +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 49602f636d value.h: add configuration macros around mrb_ro_data_p(); close #5547
- `MRB_USE_ETEXT_RO_DATA_P`: use `etext` and `edata`
- `MRB_NO_DEFAULT_RO_DATA_P`: not use the default `mrb_ro_data_p()`
2021-09-09 16:15:25 +09:00
Yukihiro "Matz" Matsumoto a503484cb3 value.h: use etext and edata which are more widely available; #5547 2021-09-09 10:12:50 +09:00
Yukihiro "Matz" Matsumoto 1d1a89874f value.h: fixed address comparison on macOS. 2021-09-07 18:51:04 +09:00
Yukihiro "Matz" Matsumoto e9c6e52f5b value.h: reconstruct mrb_ro_data_p().
* use predefined `mrb_ro_data_p()` for user-mode Linux and macOS
* define `MRB_LINK_TIME_RO_DATA_P` if predefined one is used
* configure macro `MRB_USE_LINK_TIME_RO_DATA_P` is no longer used
* contributions for new platforms are welcome
2021-08-26 16:06:01 +09:00
Yukihiro "Matz" Matsumoto 6f305c01a2 value.h: fixed warnings on __APPLE__. 2021-08-19 13:08:39 +09:00
Yukihiro "Matz" Matsumoto 959383df75 value.h: enable mrb_ro_data_p() on __linux__ and __APPLE__.
Probably we should add conditions for FreeBSD, etc.
2021-08-19 12:52:10 +09:00
Yukihiro "Matz" Matsumoto 5c804cf68f Remove redundant include headers.
- stdlib.h
- stddef.h
- stdint.h
- stdarg.h
- limits.h
- float.h
2021-07-25 13:07:10 +09:00
dearblue cc95e346fd Added MRB_OBJ_ALLOC() macro that does not require a cast
The `MRB_OBJ_ALLOC()` macro function returns a pointer of the type corresponding to the constant literal defined in `enum mrb_vtype`.
2021-06-20 11:08:28 +09:00
Yukihiro "Matz" Matsumoto 49af1fca03 readint.c: add new function mrb_int_read.
Difference from `strtoul(3)`:

* reads `mrb_int` based on configuration
* specifies the end of the string
* no sign interpretation
* base 10 only
2021-06-11 15:14:17 +09:00
Yukihiro "Matz" Matsumoto 1d0cfb359c Update mrb_bool definition; close #2385
- move `TRUE/FALSE` definition from `mrbconf.h` (not configurable)
- use C/C++ definition of boolean type for `mrb_bool`

The fix is originally written by @take-cheeze.
2021-05-13 19:30:41 +09:00
Yukihiro "Matz" Matsumoto 08f9d5bab5 rational.c: overhaul rational operators.
- define `MRB_TT_RATIONAL`
- change object structure (`struct RRational`)
- add memory management for `MRB_TT_RATIONAL`
- avoid operator overloading as much as possible
- implement division overloading in C
- as a result, performance improved a lot
2021-03-19 10:37:10 +09:00
Yukihiro "Matz" Matsumoto 16fe040479 mruby/value.h: MRB_TT_CPTR is immediate with MRB_NO_BOXING.
The issue is reported by @shuujii.
2021-02-19 23:23:18 +09:00
Yukihiro "Matz" Matsumoto e5559184e0 Fix mrb_immediate_p() definition for MRB_NO_BOXING; ref #5352 2021-02-19 21:02:31 +09:00
Yukihiro "Matz" Matsumoto 787487b16d Check MRB_TT_* before object allocation; ref #5352 2021-02-19 15:36:41 +09:00
Yukihiro "Matz" Matsumoto e1c9e7efab Changed packing format of inline symbols.
To make inline symbols packed in 30 bits.
2021-01-12 14:51:33 +09:00
Yukihiro "Matz" Matsumoto 92cc6b4996 Introduce mrb_uint which is unsigned integer with size of mrb_int. 2021-01-09 19:09:56 +09:00
Yukihiro "Matz" Matsumoto 7c80edb577 Revert half of 9fbf0ef8.
I misunderstand the meaning of #4483. Sorry.
2020-11-17 22:47:25 +09:00
Yukihiro "Matz" Matsumoto 9fbf0ef886 Refactoring integer ranges.
- Remove `mrb_ssize`
- Fix `MRB_FIXNUM_{MIN,MAX}` to 32 bits on `MRB_NAN_BOXING`
2020-11-17 12:41:10 +09:00
Yukihiro "Matz" Matsumoto 3107d1caae Allow int size combinations for MRB_WORD_BOXING.
- `MRB_64BIT` and `MRB_INT32`
- `MRB_32BIT` and `MRB_INT64`
2020-11-16 22:49:55 +09:00
Yukihiro "Matz" Matsumoto 2b188ed8a1 Reorganize Integer system.
- Integrate `Fixnum` and `Integer`
- Remove `Integral`
- `int / int -> int`
- Replace `mrb_fixnum()` to `mrb_int()`
- Replace `mrb_fixnum_value()` to `mrb_int_value()`.
- Use `mrb_integer_p()` instead of `mrb_fixnum_p()`
2020-10-12 18:19:54 +09:00
Yukihiro "Matz" Matsumoto 55163a8a0a Rename MRB_TT_FIXNUM to MRB_TT_INTEGER.
We still have `#define MRB_TT_FIXNUM MRB_TT_INTEGER` for compatibility.
2020-10-12 16:21:47 +09:00
Yukihiro "Matz" Matsumoto 8a87549315 Rename float configuration option names.
- `MRB_WITHOUT_FLOAT` => `MRB_NO_FLOAT`
- `MRB_USE_FLOAT` => `MRB_USE_FLOAT32`

The former is to use `USE_XXX` naming convention. The latter is to make
sure `float` is 32bit float and not floating point number in general.
2020-10-12 16:21:40 +09:00
Yukihiro "Matz" Matsumoto dad99afae8 Remove unnecessary comments from MRB_TT_* definitions. 2020-06-15 09:54:55 +09:00
Yukihiro "Matz" Matsumoto f93dffb5ee Remove unused MRB_TT_FILE. 2020-06-15 07:47:22 +09:00
dearblue d0501c69b0 Fix MRB_TT_CPTR object with MRB_NAN_BOXING
Previously, if `MRB_NAN_BOXING` is defined, for example,
`mrb_cptr_value()` could not keep an odd address.

If it is `MRB_32BIT`, it can be embedded in `NaN` as it is.

If it is `MRB_64BIT`, some operations are shared with `MRB_WORD_BOXING`.
In this case, the MRB_API function `mrb_nan_boxing_cptr_value()` is
defined.
2020-04-13 23:12:09 +09:00
Yukihiro "Matz" Matsumoto ff57c0278f Remove broken MRB_INT16 configuration option. 2020-01-15 21:32:00 +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
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
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
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
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 1a4ea94bc7 Fix mrb_immediate_p(MRB_TT_FREE) to return false; ref #4679 2019-08-31 23:19:08 +09:00
KOBAYASHI Shuji b2c3d88fbf Implement mrb_immediate_p macro for MRB_WORD_BOXING
The default implementation of `mrb_immediate_p` uses `mrb_type`. However,
in `MRB_WORD_BOXING`, `mrb_type` has many branches and is inefficient, so
provide an implementation that does not use `mrb_type`.
2019-08-31 16:55:57 +09:00
David Siaw e1e96c0cf4 change doc directory and reduce warnings 2019-08-26 00:23:28 +09:00
David Siaw b5299b1c58 fix up documentation for values 2019-08-18 20:12:44 +09:00