Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mruby
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
mruby
Commits
73e289c5
Unverified
Commit
73e289c5
authored
4 years ago
by
Yukihiro "Matz" Matsumoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simplify `mrb_value` structure for `MRB_NAN_BOXING`.
parent
ce372122
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
47 additions
and
50 deletions
+47
-50
include/mruby/boxing_nan.h
include/mruby/boxing_nan.h
+47
-50
No files found.
include/mruby/boxing_nan.h
View file @
73e289c5
...
@@ -32,96 +32,93 @@
...
@@ -32,96 +32,93 @@
*/
*/
typedef
uint64_t
mrb_value
;
typedef
uint64_t
mrb_value
;
struct
mrb_value
{
union
mrb_value
{
union
{
mrb_float
f
;
mrb_float
f
;
uint64_t
u
;
uint64_t
u
;
union
{
#ifdef MRB_64BIT
#ifdef MRB_64BIT
void
*
p
;
void
*
p
;
#endif
#endif
struct
{
struct
{
MRB_ENDIAN_LOHI
(
MRB_ENDIAN_LOHI
(
uint32_t
ttt
;
uint32_t
ttt
;
,
union
{
,
union
{
mrb_int
i
;
mrb_int
i
;
mrb_sym
sym
;
mrb_sym
sym
;
#ifdef MRB_32BIT
#ifdef MRB_32BIT
void
*
p
;
void
*
p
;
#endif
#endif
};
)
};
};
}
value
;
)
};
};
};
};
static
inline
struct
mrb_value
static
inline
union
mrb_value
mrb_val_
stru
(
mrb_value
v
)
mrb_val_
union
(
mrb_value
v
)
{
{
struct
mrb_value
mrb_value_struct_variable
=
{.
u
=
v
};
union
mrb_value
x
;
return
mrb_value_struct_variable
;
x
.
u
=
v
;
return
x
;
}
}
#define mrb_tt(o) ((enum mrb_vtype)((mrb_val_
stru(o).value
.ttt & 0xfc000)>>14)-1)
#define mrb_tt(o) ((enum mrb_vtype)((mrb_val_
union(o)
.ttt & 0xfc000)>>14)-1)
#define mrb_type(o) (enum mrb_vtype)((uint32_t)0xfff00000 < mrb_val_
stru(o).value
.ttt ? mrb_tt(o) : MRB_TT_FLOAT)
#define mrb_type(o) (enum mrb_vtype)((uint32_t)0xfff00000 < mrb_val_
union(o)
.ttt ? mrb_tt(o) : MRB_TT_FLOAT)
#define mrb_float(o) mrb_val_
stru
(o).f
#define mrb_float(o) mrb_val_
union
(o).f
#define mrb_fixnum(o) mrb_val_
stru(o).value
.i
#define mrb_fixnum(o) mrb_val_
union(o)
.i
#define mrb_symbol(o) mrb_val_
stru(o).value
.sym
#define mrb_symbol(o) mrb_val_
union(o)
.sym
#ifdef MRB_64BIT
#ifdef MRB_64BIT
#define mrb_ptr(o) ((void*)((((uintptr_t)0x3fffffffffff)&((uintptr_t)(mrb_val_stru(o).value.p)))<<2))
#define mrb_ptr(o) ((void*)((((uintptr_t)0x3fffffffffff)&((uintptr_t)(mrb_val_union(o).p)))<<2))
MRB_API
mrb_value
mrb_nan_boxing_cptr_value
(
struct
mrb_state
*
,
void
*
);
#define mrb_cptr(o) (((struct RCptr*)mrb_ptr(o))->p)
#define mrb_cptr(o) (((struct RCptr*)mrb_ptr(o))->p)
#define BOXNAN_SHIFT_LONG_POINTER(v) (((uintptr_t)(v)>>34)&0x3fff)
#define BOXNAN_SHIFT_LONG_POINTER(v) (((uintptr_t)(v)>>34)&0x3fff)
#else
#else
#define mrb_ptr(o) (mrb_val_
stru(o).value
.p)
#define mrb_ptr(o) (mrb_val_
union(o)
.p)
#define mrb_cptr(o) mrb_ptr(o)
#define mrb_cptr(o) mrb_ptr(o)
#define BOXNAN_SHIFT_LONG_POINTER(v) 0
#define BOXNAN_SHIFT_LONG_POINTER(v) 0
#endif
#endif
#define BOXNAN_SET_VALUE(o, tt, attr, v) do { \
#define BOXNAN_SET_VALUE(o, tt, attr, v) do { \
struct mrb_value mrb_value_struct
_variable; \
union mrb_value mrb_value_union
_variable; \
mrb_value_
struct
_variable.attr = (v);\
mrb_value_
union
_variable.attr = (v);\
mrb_value_
struct_variable.valu
e.ttt = 0xfff00000 | (((tt)+1)<<14);\
mrb_value_
union_variabl
e.ttt = 0xfff00000 | (((tt)+1)<<14);\
o = mrb_value_
struct
_variable.u;\
o = mrb_value_
union
_variable.u;\
} while (0)
} while (0)
#ifdef MRB_64BIT
#ifdef MRB_64BIT
#define BOXNAN_SET_OBJ_VALUE(o, tt, v) do {\
#define BOXNAN_SET_OBJ_VALUE(o, tt, v) do {\
struct mrb_value mrb_value_struct
_variable;\
union mrb_value mrb_value_union
_variable;\
mrb_value_
struct_variable.valu
e.p = (void*)((uintptr_t)(v)>>2);\
mrb_value_
union_variabl
e.p = (void*)((uintptr_t)(v)>>2);\
mrb_value_
struct_variable.valu
e.ttt = (0xfff00000|(((tt)+1)<<14)|BOXNAN_SHIFT_LONG_POINTER(v));\
mrb_value_
union_variabl
e.ttt = (0xfff00000|(((tt)+1)<<14)|BOXNAN_SHIFT_LONG_POINTER(v));\
o = mrb_value_
struct
_variable.u;\
o = mrb_value_
union
_variable.u;\
} while (0)
} while (0)
#else
#else
#define BOXNAN_SET_OBJ_VALUE(o, tt, v) BOXNAN_SET_VALUE(o, tt,
value.
p, v)
#define BOXNAN_SET_OBJ_VALUE(o, tt, v) BOXNAN_SET_VALUE(o, tt, p, v)
#endif
#endif
#define SET_FLOAT_VALUE(mrb,r,v) do { \
#define SET_FLOAT_VALUE(mrb,r,v) do { \
struct mrb_value mrb_value_struct
_variable; \
union mrb_value mrb_value_union
_variable; \
if ((v) != (v)) {
/* NaN */
\
if ((v) != (v)) {
/* NaN */
\
mrb_value_
struct_variable.valu
e.ttt = 0x7ff80000; \
mrb_value_
union_variabl
e.ttt = 0x7ff80000; \
mrb_value_
struct_variable.valu
e.i = 0; \
mrb_value_
union_variabl
e.i = 0; \
} \
} \
else { \
else { \
mrb_value_
struct
_variable.f = (v); \
mrb_value_
union
_variable.f = (v); \
} \
} \
r = mrb_value_
struct
_variable.u; \
r = mrb_value_
union
_variable.u; \
} while(0)
} while(0)
#define SET_NIL_VALUE(r) BOXNAN_SET_VALUE(r, MRB_TT_FALSE,
value.
i, 0)
#define SET_NIL_VALUE(r) BOXNAN_SET_VALUE(r, MRB_TT_FALSE, i, 0)
#define SET_FALSE_VALUE(r) BOXNAN_SET_VALUE(r, MRB_TT_FALSE,
value.
i, 1)
#define SET_FALSE_VALUE(r) BOXNAN_SET_VALUE(r, MRB_TT_FALSE, i, 1)
#define SET_TRUE_VALUE(r) BOXNAN_SET_VALUE(r, MRB_TT_TRUE,
value.
i, 1)
#define SET_TRUE_VALUE(r) BOXNAN_SET_VALUE(r, MRB_TT_TRUE, i, 1)
#define SET_BOOL_VALUE(r,b) BOXNAN_SET_VALUE(r, b ? MRB_TT_TRUE : MRB_TT_FALSE,
value.
i, 1)
#define SET_BOOL_VALUE(r,b) BOXNAN_SET_VALUE(r, b ? MRB_TT_TRUE : MRB_TT_FALSE, i, 1)
#define SET_INT_VALUE(r,n) BOXNAN_SET_VALUE(r, MRB_TT_FIXNUM,
value.
i, (n))
#define SET_INT_VALUE(r,n) BOXNAN_SET_VALUE(r, MRB_TT_FIXNUM, i, (n))
#define SET_SYM_VALUE(r,v) BOXNAN_SET_VALUE(r, MRB_TT_SYMBOL,
value.
sym, (v))
#define SET_SYM_VALUE(r,v) BOXNAN_SET_VALUE(r, MRB_TT_SYMBOL, sym, (v))
#define SET_OBJ_VALUE(r,v) BOXNAN_SET_OBJ_VALUE(r, (((struct RObject*)(v))->tt), (v))
#define SET_OBJ_VALUE(r,v) BOXNAN_SET_OBJ_VALUE(r, (((struct RObject*)(v))->tt), (v))
#ifdef MRB_64BIT
#ifdef MRB_64BIT
MRB_API
mrb_value
mrb_nan_boxing_cptr_value
(
struct
mrb_state
*
,
void
*
);
#define SET_CPTR_VALUE(mrb,r,v) ((r) = mrb_nan_boxing_cptr_value(mrb, v))
#define SET_CPTR_VALUE(mrb,r,v) ((r) = mrb_nan_boxing_cptr_value(mrb, v))
#else
#else
#define SET_CPTR_VALUE(mrb,r,v) BOXNAN_SET_VALUE(r, MRB_TT_CPTR,
value.
p, v)
#define SET_CPTR_VALUE(mrb,r,v) BOXNAN_SET_VALUE(r, MRB_TT_CPTR, p, v)
#endif
#endif
#define SET_UNDEF_VALUE(r) BOXNAN_SET_VALUE(r, MRB_TT_UNDEF,
value.
i, 0)
#define SET_UNDEF_VALUE(r) BOXNAN_SET_VALUE(r, MRB_TT_UNDEF, i, 0)
#endif
/* MRUBY_BOXING_NAN_H */
#endif
/* MRUBY_BOXING_NAN_H */
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment