Commit Graph

82 Commits

Author SHA1 Message Date
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
dearblue 926ec1dc7e Define mrb_value in struct for Word/NaN boxing
This is to make it possible to distinguish between `mrb_value` and `mrb_sym` in C++ "Function overloading" and C11 "Generic selection".
2020-11-08 14:14:00 +09:00
KOBAYASHI Shuji 43863d5f01 Fix mrb_obj_id to Float 2020-10-28 23:03:26 +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 4e56e0defc Rename union mrb_value to union mrb_value_.
Since some compiler complains when we `typedef` `mrb_value`.
2020-10-12 16:21:30 +09:00
Yukihiro "Matz" Matsumoto 53e46be7e2 Simplify mrb_value structure for MRB_WORD_BOXING. 2020-10-12 16:21:29 +09:00
Yukihiro "Matz" Matsumoto d428fa0c4a Replace entire irep->pool.
Changes:
- `pool format is completely replaced
  - supported types: `STR`, `INT32`, `INT64`, `FLOAT`
  - `FLOAT` may be replaced by binary representation in the future
- insert `NUL` after string literals in `mrb` files
- `irep->pool` no longer store values in `mrb_value`
- instead it stores in `mrb_pool_value`
- less allocation
- `mrb_irep` can be stored in ROM
2020-10-12 16:21:08 +09:00
Rory OConnell 5746958470 fix object_id of true, false, and undef all 0 2020-07-04 20:33:38 -07: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
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
KOBAYASHI Shuji 334afb167c Use new specifiers/modifiers of mrb_vfromat()
The binary sizes (gems are only `mruby-bin-mruby`) are reduced slightly in
my environment than before the introduction of new specifiers/modifiers
(5116789a) with this change.

  ------------+-------------------+-------------------+--------
   BINARY     | BEFORE (5116789a) |   AFTER (This PR) |  RATIO
  ------------+-------------------+-------------------+--------
   mruby      |      593416 bytes |      593208 bytes | -0.04%
   libmruby.a |      769048 bytes |      767264 bytes | -0.23%
  ------------+-------------------+-------------------+--------

BTW, I accidentally changed `tasks/toolchains/visualcpp.rake` at #4613,
so I put it back.
2019-08-05 13:18:50 +09:00
KOBAYASHI Shuji 0d54dbb264 Fix and refine error message in mrb_obj_to_sym()
Before this patch:

  $ bin/mruby -e '1.respond_to?(2)'  #=> nil is not a symbol

After this patch (same as Ruby):

  $ bin/mruby -e '1.respond_to?(2)'  #=> 2 is not a symbol nor a string
2019-07-02 19:41:40 +09:00
KOBAYASHI Shuji 7e3a8b7a75 Remove unused C header file from src/etc.c 2019-07-01 12:29:02 +09:00
Yukihiro "Matz" Matsumoto 0c5f26e0ff Remove unnecessary mrb_regexp_check() and related functions. 2019-04-24 11:43:05 +09:00
KOBAYASHI Shuji 0c9c3f08ee Remove incorrect flags updating in mrb_regexp_p() 2019-04-11 21:42:18 +09:00
KOBAYASHI Shuji 7b0ebed033 Use mrb_immediate_p() in mrb_obj_freeze() and mrb_obj_frozen() 2019-04-10 19:19:53 +09:00
Yukihiro "Matz" Matsumoto e471d37ca5 Separate meta-programming features to mruby-metaprog gem.
We assume meta-programming is less used in embedded environments.
We have moved following methods:

 * Kernel module
   global_variables, local_variables, singleton_class,
   instance_variables, instance_variables_defined?, instance_variable_get,
   instance_variable_set, methods, private_methods, public_methods,
   protected_methods, singleton_methods, define_singleton_methods

 * Module class
   class_variables, class_variables_defined?, class_variable_get,
   class_variable_set, remove_class_variable, included_modules,
   instance_methods, remove_method, method_removed, constants

 * Module class methods
   constants, nesting

Note:
Following meta-programming methods are kept in the core:

 * Module class
   alias_method, undef_method, ancestors, const_defined?, const_get,
   const_set, remove_const, method_defined?, define_method

 * Toplevel object
   define_method

`mruby-metaprog` gem is linked by default (specified in default.gembox).
When it is removed, it will save 40KB (stripped:8KB) on x86-64
environment last time I measured.
2018-08-30 22:30:36 +09:00
YAMAMOTO Masaya acdc2d1f24 Add MRB_WITHOUT_FLOAT 2017-10-11 17:58:11 +09:00
Yukihiro "Matz" Matsumoto c3c882f681 Use uint32_t to avoid signed integer overflow warning; #3816 2017-10-01 17:53:10 +09:00
Yukihiro "Matz" Matsumoto 78be0172f7 Normalize float numbers before calculating a hash value. 2017-08-10 08:36:09 +09:00
Yukihiro "Matz" Matsumoto 8438792d27 renamed "inline" to "istruct" to represent inline struct; ref #3251 2016-11-17 17:19:49 +09:00
Tomasz Dąbrowski 4cca8bac6b inline structures data type for mruby (MRB_TT_INLINE) (fix #3237)
Inline structures have no instance variables, no finalizer, and offer as much space as possible in RBASIC object. This means 24 bytes on 64-bit platforms and 12 bytes on 32-bit platforms.
mruby-inline-struct gem is only provided for testing.
2016-11-17 17:19:49 +09:00
Yukihiro "Matz" Matsumoto 5e514c910f cache mrb_regexp_p(); ref #980 2016-02-04 23:22:01 +09:00
Yukihiro "Matz" Matsumoto 5c405dea3d include changed from by quotes ("") to by brackets (<>); close #3032 2015-11-27 17:48:23 +09:00
go.kikuta 96c948d812 Remove non-need tmp value 2015-08-11 18:02:12 +09:00
cremno ef0fc90cd0 remove unnecessary mrb_immediate_p()
`!mrb_array_p(ary2)` and `mrb_type(obj) != MRB_TT_DATA` are  sufficient.
2015-06-02 08:56:41 +02:00
kkkkkt d94469ac23 changed to call check_cv_name_str in check_cv_name_sym and adjust indent 2014-08-21 13:56:43 +09:00
bggd d95f77c1cb Fix a typo in etc.c 2014-08-06 21:36:36 +09:00
Yukihiro "Matz" Matsumoto ea80e82852 Merge branch 'master' of github.com:mruby/mruby 2014-08-04 16:28:02 +09:00
cremno b6e27218ad MSVC: add simple (v)snprintf implementation
_snprintf is not C99's snprintf!

This simple implementation, unlike _snprintf,
always null-terminates and returns the expected
return value (in most cases).
Other C99 behaviors (like format specifiers) require
adding a complete snprintf implementation.
Do we want or need that?

The same applies to vsnprintf (aka _vsnprintf).
2014-08-03 21:15:48 +02:00
Yukihiro "Matz" Matsumoto 6aa6e75f75 rename obsolete mrb_special_const_p to mrb_immediate_p 2014-08-04 00:50:03 +09:00
Yukihiro "Matz" Matsumoto 206f89e209 add MRB_API modifiers to mruby API functions 2014-08-04 00:47:08 +09:00
Yukihiro "Matz" Matsumoto 61bba9accf rename word boxing functions 2014-07-09 06:40:56 +09:00
David Turnbull 249f05e7d7 Clean up value.h and mrb_value boxing 2014-07-09 06:32:11 +09:00
Yukihiro "Matz" Matsumoto f0b86f36c3 move mrb_irep_remove_lv from etc.c to mruby-bin-strip gem 2014-05-15 17:13:16 +09:00
take_cheeze 30e0dc7956 Support LVAR section removing. 2014-05-15 15:08:30 +09:00
Yukihiro "Matz" Matsumoto 48e82d7c77 cast intptr_t to mrb_int to pacify compiler warning; close #2148 2014-04-29 12:21:49 +09:00
take_cheeze d4a510f751 Add mrb_regexp_p to check whether mrb_value is Regexp. 2014-04-17 14:32:45 +09:00
Yukihiro "Matz" Matsumoto 62505d51cc calc hash value directly for strings, symbols and numbers 2014-03-15 15:53:12 +09:00
cremno d90f52f552 etc.c: small cleanup (delete unused functions)
mrb_data_object_alloc: unnecessary cast
mrb_lastline_get: mruby doesn't support $_, weird and unused code
mrb_exec_recursive: see 4e46abb869
mrb_block_proc: unused, doesn't really do anything (or needs to be
rewritten)
mrb_obj_to_sym: actually use id (and MSVC detected unreachable code)
2014-01-30 23:16:46 +01:00
cremno aa655b9ee1 remove superfluous includes
- reduce compile time by a little bit (full-core: ~0.7s for me)
- thanks to 'include-what-you-use' for some help
- include Standard C header files before any other (coding style)
2014-01-07 17:56:30 +01:00
Yukihiro "Matz" Matsumoto 9ac386923d float objects in pool are objects when MRB_WORD_BOXING is set 2013-11-27 17:29:28 +09:00
Yukihiro "Matz" Matsumoto 3995e7ff8f rename voidp to cptr 2013-09-21 17:28:47 +09:00
Yukihiro "Matz" Matsumoto b225e4cc82 redesign mruby/data.h API; use DATA_PTR() for raw data pointer, DATA_GET_PTR() to type safe retrieval (TypeError will be raised), DATA_CHECK_GET_PTR() to get nil if type mismatched 2013-08-15 01:33:36 +09:00
Yukihiro "Matz" Matsumoto 40e6cdcb5c rename mrb_value_p() to mrb_ptr() since _p means predicate in mruby source 2013-08-07 17:39:28 +09:00
Yuichi Nishiwaki 8dc2fa3bc8 add read barrier to value.p
API changes:
- value.p must be accessed via mrb_value_p macro
- value.p must be mutated via MRB_SET_VALUE_P macro
2013-08-03 14:03:44 -07:00
kimu_shu e720782f81 Add MRB_WORD_BOXING mode (represent mrb_value as a word) 2013-05-26 10:09:17 +09:00