mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
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.
This commit is contained in:
committed by
Yukihiro "Matz" Matsumoto
parent
784e07f902
commit
4cca8bac6b
+20
@@ -14,6 +14,7 @@
|
||||
#include <mruby/variable.h>
|
||||
#include <mruby/error.h>
|
||||
#include <mruby/data.h>
|
||||
#include <mruby/inline.h>
|
||||
|
||||
KHASH_DEFINE(mt, mrb_sym, struct RProc*, TRUE, kh_int_hash_func, kh_int_hash_equal)
|
||||
|
||||
@@ -491,6 +492,7 @@ to_sym(mrb_state *mrb, mrb_value ss)
|
||||
b: Boolean [mrb_bool]
|
||||
n: Symbol [mrb_sym]
|
||||
d: Data [void*,mrb_data_type const] 2nd argument will be used to check data type so it won't be modified
|
||||
I: Inline struct [void*]
|
||||
&: Block [mrb_value]
|
||||
*: rest argument [mrb_value*,mrb_int] Receive the rest of the arguments as an array.
|
||||
|: optional Next argument of '|' and later are optional.
|
||||
@@ -702,6 +704,24 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'I':
|
||||
{
|
||||
void* *p;
|
||||
mrb_value ss;
|
||||
|
||||
p = va_arg(ap, void**);
|
||||
if (i < argc) {
|
||||
ss = ARGV[arg_i];
|
||||
if (mrb_type(ss) != MRB_TT_INLINE)
|
||||
{
|
||||
mrb_raisef(mrb, E_TYPE_ERROR, "%S is not inline struct", ss);
|
||||
}
|
||||
*p = mrb_inline_ptr(ss);
|
||||
arg_i++;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'f':
|
||||
{
|
||||
mrb_float *p;
|
||||
|
||||
@@ -139,6 +139,7 @@ mrb_obj_id(mrb_value obj)
|
||||
case MRB_TT_EXCEPTION:
|
||||
case MRB_TT_FILE:
|
||||
case MRB_TT_DATA:
|
||||
case MRB_TT_INLINE:
|
||||
default:
|
||||
return MakeID(mrb_ptr(obj));
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include <mruby/string.h>
|
||||
#include <mruby/variable.h>
|
||||
#include <mruby/error.h>
|
||||
#include <mruby/inline.h>
|
||||
|
||||
typedef enum {
|
||||
NOEX_PUBLIC = 0x00,
|
||||
@@ -301,6 +302,9 @@ init_copy(mrb_state *mrb, mrb_value dest, mrb_value obj)
|
||||
case MRB_TT_EXCEPTION:
|
||||
mrb_iv_copy(mrb, dest, obj);
|
||||
break;
|
||||
case MRB_TT_INLINE:
|
||||
mrb_inline_copy(dest, obj);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
|
||||
+2
-2
@@ -348,7 +348,7 @@ mrb_check_convert_type(mrb_state *mrb, mrb_value val, enum mrb_vtype type, const
|
||||
{
|
||||
mrb_value v;
|
||||
|
||||
if (mrb_type(val) == type && type != MRB_TT_DATA) return val;
|
||||
if (mrb_type(val) == type && type != MRB_TT_DATA && type != MRB_TT_INLINE) return val;
|
||||
v = convert_type(mrb, val, tname, method, FALSE);
|
||||
if (mrb_nil_p(v) || mrb_type(v) != type) return mrb_nil_value();
|
||||
return v;
|
||||
@@ -390,7 +390,7 @@ mrb_check_type(mrb_state *mrb, mrb_value x, enum mrb_vtype t)
|
||||
enum mrb_vtype xt;
|
||||
|
||||
xt = mrb_type(x);
|
||||
if ((xt != t) || (xt == MRB_TT_DATA)) {
|
||||
if ((xt != t) || (xt == MRB_TT_DATA) || (xt == MRB_TT_INLINE)) {
|
||||
while (type->type < MRB_TT_MAXDEFINE) {
|
||||
if (type->type == t) {
|
||||
const char *etype;
|
||||
|
||||
Reference in New Issue
Block a user