mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
renamed "inline" to "istruct" to represent inline struct; ref #3251
This commit is contained in:
@@ -1,47 +0,0 @@
|
||||
/*
|
||||
** mruby/inline.h - Inline structures
|
||||
**
|
||||
** See Copyright Notice in mruby.h
|
||||
*/
|
||||
|
||||
#ifndef MRUBY_INLINE_H
|
||||
#define MRUBY_INLINE_H
|
||||
|
||||
#include "common.h"
|
||||
#include <string.h>
|
||||
|
||||
/**
|
||||
* Inline structures that fit in RVALUE
|
||||
*
|
||||
* They cannot have finalizer, and cannot have instance variables.
|
||||
*/
|
||||
MRB_BEGIN_DECL
|
||||
|
||||
#define INLINE_DATA_SIZE (sizeof(void*) * 3)
|
||||
|
||||
struct RInline {
|
||||
MRB_OBJECT_HEADER;
|
||||
char inline_data[INLINE_DATA_SIZE];
|
||||
};
|
||||
|
||||
#define RINLINE(obj) ((struct RInline*)(mrb_ptr(obj)))
|
||||
#define INLINE_PTR(obj) (RINLINE(obj)->inline_data)
|
||||
|
||||
MRB_INLINE mrb_int mrb_inline_size()
|
||||
{
|
||||
return INLINE_DATA_SIZE;
|
||||
}
|
||||
|
||||
MRB_INLINE void* mrb_inline_ptr(mrb_value object)
|
||||
{
|
||||
return INLINE_PTR(object);
|
||||
}
|
||||
|
||||
MRB_INLINE void mrb_inline_copy(mrb_value dest, mrb_value src)
|
||||
{
|
||||
memcpy(INLINE_PTR(dest), INLINE_PTR(src), INLINE_DATA_SIZE);
|
||||
}
|
||||
|
||||
MRB_END_DECL
|
||||
|
||||
#endif /* MRUBY_INLINE_H */
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
** mruby/instruct.h - Inline structures
|
||||
**
|
||||
** See Copyright Notice in mruby.h
|
||||
*/
|
||||
|
||||
#ifndef MRUBY_ISTRUCT_H
|
||||
#define MRUBY_ISTRUCT_H
|
||||
|
||||
#include "common.h"
|
||||
#include <string.h>
|
||||
|
||||
/**
|
||||
* Inline structures that fit in RVALUE
|
||||
*
|
||||
* They cannot have finalizer, and cannot have instance variables.
|
||||
*/
|
||||
MRB_BEGIN_DECL
|
||||
|
||||
#define ISTRUCT_DATA_SIZE (sizeof(void*) * 3)
|
||||
|
||||
struct RIstruct {
|
||||
MRB_OBJECT_HEADER;
|
||||
char inline_data[ISTRUCT_DATA_SIZE];
|
||||
};
|
||||
|
||||
#define RISTRUCT(obj) ((struct RIstruct*)(mrb_ptr(obj)))
|
||||
#define ISTRUCT_PTR(obj) (RISTRUCT(obj)->inline_data)
|
||||
|
||||
MRB_INLINE mrb_int mrb_istruct_size()
|
||||
{
|
||||
return ISTRUCT_DATA_SIZE;
|
||||
}
|
||||
|
||||
MRB_INLINE void* mrb_istruct_ptr(mrb_value object)
|
||||
{
|
||||
return ISTRUCT_PTR(object);
|
||||
}
|
||||
|
||||
MRB_INLINE void mrb_istruct_copy(mrb_value dest, mrb_value src)
|
||||
{
|
||||
memcpy(ISTRUCT_PTR(dest), ISTRUCT_PTR(src), ISTRUCT_DATA_SIZE);
|
||||
}
|
||||
|
||||
MRB_END_DECL
|
||||
|
||||
#endif /* MRUBY_ISTRUCT_H */
|
||||
@@ -116,7 +116,7 @@ enum mrb_vtype {
|
||||
MRB_TT_ENV, /* 20 */
|
||||
MRB_TT_DATA, /* 21 */
|
||||
MRB_TT_FIBER, /* 22 */
|
||||
MRB_TT_INLINE, /* 23 */
|
||||
MRB_TT_ISTRUCT, /* 23 */
|
||||
MRB_TT_MAXDEFINE /* 24 */
|
||||
};
|
||||
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
#include <mruby.h>
|
||||
#include <mruby/class.h>
|
||||
#include <mruby/string.h>
|
||||
#include <mruby/inline.h>
|
||||
#include <mruby/istruct.h>
|
||||
|
||||
static mrb_value
|
||||
inline_test_initialize(mrb_state *mrb, mrb_value self)
|
||||
istruct_test_initialize(mrb_state *mrb, mrb_value self)
|
||||
{
|
||||
char *string = mrb_inline_ptr(self);
|
||||
mrb_int size = mrb_inline_size();
|
||||
char *string = mrb_istruct_ptr(self);
|
||||
mrb_int size = mrb_istruct_size();
|
||||
mrb_value object;
|
||||
mrb_get_args(mrb, "o", &object);
|
||||
|
||||
@@ -29,19 +29,19 @@ inline_test_initialize(mrb_state *mrb, mrb_value self)
|
||||
}
|
||||
|
||||
static mrb_value
|
||||
inline_test_to_s(mrb_state *mrb, mrb_value self)
|
||||
istruct_test_to_s(mrb_state *mrb, mrb_value self)
|
||||
{
|
||||
return mrb_str_new_cstr(mrb, mrb_inline_ptr(self));
|
||||
return mrb_str_new_cstr(mrb, mrb_istruct_ptr(self));
|
||||
}
|
||||
|
||||
static mrb_value
|
||||
inline_test_length(mrb_state *mrb, mrb_value self)
|
||||
istruct_test_length(mrb_state *mrb, mrb_value self)
|
||||
{
|
||||
return mrb_fixnum_value(mrb_inline_size());
|
||||
return mrb_fixnum_value(mrb_istruct_size());
|
||||
}
|
||||
|
||||
static mrb_value
|
||||
inline_test_test_receive(mrb_state *mrb, mrb_value self)
|
||||
istruct_test_test_receive(mrb_state *mrb, mrb_value self)
|
||||
{
|
||||
mrb_value object;
|
||||
mrb_get_args(mrb, "o", &object);
|
||||
@@ -49,11 +49,11 @@ inline_test_test_receive(mrb_state *mrb, mrb_value self)
|
||||
{
|
||||
mrb_raisef(mrb, E_TYPE_ERROR, "Expected InlineStructTest");
|
||||
}
|
||||
return mrb_bool_value(((char*)mrb_inline_ptr(object))[0] == 's');
|
||||
return mrb_bool_value(((char*)mrb_istruct_ptr(object))[0] == 's');
|
||||
}
|
||||
|
||||
static mrb_value
|
||||
inline_test_test_receive_direct(mrb_state *mrb, mrb_value self)
|
||||
istruct_test_test_receive_direct(mrb_state *mrb, mrb_value self)
|
||||
{
|
||||
char *ptr;
|
||||
mrb_get_args(mrb, "I", &ptr);
|
||||
@@ -61,9 +61,9 @@ inline_test_test_receive_direct(mrb_state *mrb, mrb_value self)
|
||||
}
|
||||
|
||||
static mrb_value
|
||||
inline_test_mutate(mrb_state *mrb, mrb_value self)
|
||||
istruct_test_mutate(mrb_state *mrb, mrb_value self)
|
||||
{
|
||||
char *ptr = mrb_inline_ptr(self);
|
||||
char *ptr = mrb_istruct_ptr(self);
|
||||
memcpy(ptr, "mutate", 6);
|
||||
return mrb_nil_value();
|
||||
}
|
||||
@@ -73,11 +73,11 @@ void mrb_mruby_inline_struct_gem_test(mrb_state *mrb)
|
||||
struct RClass *cls;
|
||||
|
||||
cls = mrb_define_class(mrb, "InlineStructTest", mrb->object_class);
|
||||
MRB_SET_INSTANCE_TT(cls, MRB_TT_INLINE);
|
||||
mrb_define_method(mrb, cls, "initialize", inline_test_initialize, MRB_ARGS_REQ(1));
|
||||
mrb_define_method(mrb, cls, "to_s", inline_test_to_s, MRB_ARGS_NONE());
|
||||
mrb_define_method(mrb, cls, "mutate", inline_test_mutate, MRB_ARGS_NONE());
|
||||
mrb_define_class_method(mrb, cls, "length", inline_test_length, MRB_ARGS_NONE());
|
||||
mrb_define_class_method(mrb, cls, "test_receive", inline_test_test_receive, MRB_ARGS_REQ(1));
|
||||
mrb_define_class_method(mrb, cls, "test_receive_direct", inline_test_test_receive_direct, MRB_ARGS_REQ(1));
|
||||
MRB_SET_INSTANCE_TT(cls, MRB_TT_ISTRUCT);
|
||||
mrb_define_method(mrb, cls, "initialize", istruct_test_initialize, MRB_ARGS_REQ(1));
|
||||
mrb_define_method(mrb, cls, "to_s", istruct_test_to_s, MRB_ARGS_NONE());
|
||||
mrb_define_method(mrb, cls, "mutate", istruct_test_mutate, MRB_ARGS_NONE());
|
||||
mrb_define_class_method(mrb, cls, "length", istruct_test_length, MRB_ARGS_NONE());
|
||||
mrb_define_class_method(mrb, cls, "test_receive", istruct_test_test_receive, MRB_ARGS_REQ(1));
|
||||
mrb_define_class_method(mrb, cls, "test_receive_direct", istruct_test_test_receive_direct, MRB_ARGS_REQ(1));
|
||||
}
|
||||
|
||||
+3
-3
@@ -14,7 +14,7 @@
|
||||
#include <mruby/variable.h>
|
||||
#include <mruby/error.h>
|
||||
#include <mruby/data.h>
|
||||
#include <mruby/inline.h>
|
||||
#include <mruby/istruct.h>
|
||||
|
||||
KHASH_DEFINE(mt, mrb_sym, struct RProc*, TRUE, kh_int_hash_func, kh_int_hash_equal)
|
||||
|
||||
@@ -712,11 +712,11 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
|
||||
p = va_arg(ap, void**);
|
||||
if (i < argc) {
|
||||
ss = ARGV[arg_i];
|
||||
if (mrb_type(ss) != MRB_TT_INLINE)
|
||||
if (mrb_type(ss) != MRB_TT_ISTRUCT)
|
||||
{
|
||||
mrb_raisef(mrb, E_TYPE_ERROR, "%S is not inline struct", ss);
|
||||
}
|
||||
*p = mrb_inline_ptr(ss);
|
||||
*p = mrb_istruct_ptr(ss);
|
||||
arg_i++;
|
||||
i++;
|
||||
}
|
||||
|
||||
@@ -139,7 +139,7 @@ mrb_obj_id(mrb_value obj)
|
||||
case MRB_TT_EXCEPTION:
|
||||
case MRB_TT_FILE:
|
||||
case MRB_TT_DATA:
|
||||
case MRB_TT_INLINE:
|
||||
case MRB_TT_ISTRUCT:
|
||||
default:
|
||||
return MakeID(mrb_ptr(obj));
|
||||
}
|
||||
|
||||
+3
-3
@@ -11,7 +11,7 @@
|
||||
#include <mruby/string.h>
|
||||
#include <mruby/variable.h>
|
||||
#include <mruby/error.h>
|
||||
#include <mruby/inline.h>
|
||||
#include <mruby/istruct.h>
|
||||
|
||||
typedef enum {
|
||||
NOEX_PUBLIC = 0x00,
|
||||
@@ -302,8 +302,8 @@ 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);
|
||||
case MRB_TT_ISTRUCT:
|
||||
mrb_istruct_copy(dest, obj);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
+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 && type != MRB_TT_INLINE) return val;
|
||||
if (mrb_type(val) == type && type != MRB_TT_DATA && type != MRB_TT_ISTRUCT) 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) || (xt == MRB_TT_INLINE)) {
|
||||
if ((xt != t) || (xt == MRB_TT_DATA) || (xt == MRB_TT_ISTRUCT)) {
|
||||
while (type->type < MRB_TT_MAXDEFINE) {
|
||||
if (type->type == t) {
|
||||
const char *etype;
|
||||
|
||||
Reference in New Issue
Block a user