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
53e46be7
Unverified
Commit
53e46be7
authored
Aug 07, 2020
by
Yukihiro "Matz" Matsumoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simplify `mrb_value` structure for `MRB_WORD_BOXING`.
parent
73e289c5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
55 additions
and
43 deletions
+55
-43
include/mruby/boxing_word.h
include/mruby/boxing_word.h
+50
-38
src/etc.c
src/etc.c
+5
-5
No files found.
include/mruby/boxing_word.h
View file @
53e46be7
...
...
@@ -47,13 +47,13 @@ enum mrb_special_consts {
#define BOXWORD_IMMEDIATE_MASK 0x07
#define BOXWORD_SHIFT_VALUE(o,n,t) \
(t)(((long)(o)
.w
) >> BOXWORD_##n##_SHIFT)
(t)(((long)(o)) >> BOXWORD_##n##_SHIFT)
#define BOXWORD_SET_SHIFT_VALUE(o,n,v) \
((o)
.w
= (((unsigned long)(v)) << BOXWORD_##n##_SHIFT) | BOXWORD_##n##_FLAG)
((o) = (((unsigned long)(v)) << BOXWORD_##n##_SHIFT) | BOXWORD_##n##_FLAG)
#define BOXWORD_SHIFT_VALUE_P(o,n) \
(((o)
.w
& BOXWORD_##n##_MASK) == BOXWORD_##n##_FLAG)
(((o) & BOXWORD_##n##_MASK) == BOXWORD_##n##_FLAG)
#define BOXWORD_OBJ_TYPE_P(o,n) \
(!mrb_immediate_p(o) &&
(o).value
.bp->tt == MRB_TT_##n)
(!mrb_immediate_p(o) &&
mrb_val_union(o)
.bp->tt == MRB_TT_##n)
/*
* mrb_value representation:
...
...
@@ -67,56 +67,63 @@ enum mrb_special_consts {
* symbol: ...SSSS SS10 (use only upper 32-bit as symbol value on 64-bit CPU)
* object: ...PPPP P000 (any bits are 1)
*/
typedef
u
nion
mrb_value
{
union
{
void
*
p
;
typedef
u
intptr_t
mrb_value
;
union
mrb_value
{
void
*
p
;
#ifdef MRB_64BIT
/* use struct to avoid bit shift. */
struct
{
MRB_ENDIAN_LOHI
(
mrb_sym
sym
;
,
uint32_t
sym_flag
;
)
};
/* use struct to avoid bit shift. */
struct
{
MRB_ENDIAN_LOHI
(
mrb_sym
sym
;
,
uint32_t
sym_flag
;
)
};
#endif
struct
RBasic
*
bp
;
struct
RBasic
*
bp
;
#ifndef MRB_WITHOUT_FLOAT
struct
RFloat
*
fp
;
struct
RFloat
*
fp
;
#endif
struct
RCptr
*
vp
;
}
value
;
unsigned
long
w
;
}
mrb_value
;
struct
RCptr
*
vp
;
uintptr_t
w
;
};
static
inline
union
mrb_value
mrb_val_union
(
mrb_value
v
)
{
union
mrb_value
x
;
x
.
w
=
v
;
return
x
;
}
MRB_API
mrb_value
mrb_word_boxing_cptr_value
(
struct
mrb_state
*
,
void
*
);
#ifndef MRB_WITHOUT_FLOAT
MRB_API
mrb_value
mrb_word_boxing_float_value
(
struct
mrb_state
*
,
mrb_float
);
#endif
#define mrb_ptr(o)
(o).value
.p
#define mrb_cptr(o)
(o).value
.vp->p
#define mrb_ptr(o)
mrb_val_union(o)
.p
#define mrb_cptr(o)
mrb_val_union(o)
.vp->p
#ifndef MRB_WITHOUT_FLOAT
#define mrb_float(o)
(o).value
.fp->f
#define mrb_float(o)
mrb_val_union(o)
.fp->f
#endif
#define mrb_fixnum(o) BOXWORD_SHIFT_VALUE(o, FIXNUM, mrb_int)
#ifdef MRB_64BIT
#define mrb_symbol(o)
(o).value
.sym
#define mrb_symbol(o)
mrb_val_union(o)
.sym
#else
#define mrb_symbol(o) BOXWORD_SHIFT_VALUE(o, SYMBOL, mrb_sym)
#endif
#define mrb_bool(o) (((o)
.w
& ~(unsigned long)MRB_Qfalse) != 0)
#define mrb_bool(o) (((o) & ~(unsigned long)MRB_Qfalse) != 0)
#define mrb_immediate_p(o) ((o)
.w & BOXWORD_IMMEDIATE_MASK || (o).w
== MRB_Qnil)
#define mrb_immediate_p(o) ((o)
& BOXWORD_IMMEDIATE_MASK || (o)
== MRB_Qnil)
#define mrb_fixnum_p(o) BOXWORD_SHIFT_VALUE_P(o, FIXNUM)
#ifdef MRB_64BIT
#define mrb_symbol_p(o) (
(o).value
.sym_flag == BOXWORD_SYMBOL_FLAG)
#define mrb_symbol_p(o) (
mrb_val_union(o)
.sym_flag == BOXWORD_SYMBOL_FLAG)
#else
#define mrb_symbol_p(o) BOXWORD_SHIFT_VALUE_P(o, SYMBOL)
#endif
#define mrb_undef_p(o) ((o)
.w
== MRB_Qundef)
#define mrb_nil_p(o) ((o)
.w
== MRB_Qnil)
#define mrb_false_p(o) ((o)
.w
== MRB_Qfalse)
#define mrb_true_p(o) ((o)
.w
== MRB_Qtrue)
#define mrb_undef_p(o) ((o) == MRB_Qundef)
#define mrb_nil_p(o) ((o) == MRB_Qnil)
#define mrb_false_p(o) ((o) == MRB_Qfalse)
#define mrb_true_p(o) ((o) == MRB_Qtrue)
#ifndef MRB_WITHOUT_FLOAT
#define mrb_float_p(o) BOXWORD_OBJ_TYPE_P(o, FLOAT)
#endif
...
...
@@ -143,18 +150,23 @@ MRB_API mrb_value mrb_word_boxing_float_value(struct mrb_state*, mrb_float);
#define SET_FLOAT_VALUE(mrb,r,v) ((r) = mrb_word_boxing_float_value(mrb, v))
#endif
#define SET_CPTR_VALUE(mrb,r,v) ((r) = mrb_word_boxing_cptr_value(mrb, v))
#define SET_UNDEF_VALUE(r) ((r)
.w
= MRB_Qundef)
#define SET_NIL_VALUE(r) ((r)
.w
= MRB_Qnil)
#define SET_FALSE_VALUE(r) ((r)
.w
= MRB_Qfalse)
#define SET_TRUE_VALUE(r) ((r)
.w
= MRB_Qtrue)
#define SET_UNDEF_VALUE(r) ((r) = MRB_Qundef)
#define SET_NIL_VALUE(r) ((r) = MRB_Qnil)
#define SET_FALSE_VALUE(r) ((r) = MRB_Qfalse)
#define SET_TRUE_VALUE(r) ((r) = MRB_Qtrue)
#define SET_BOOL_VALUE(r,b) ((b) ? SET_TRUE_VALUE(r) : SET_FALSE_VALUE(r))
#define SET_INT_VALUE(r,n) BOXWORD_SET_SHIFT_VALUE(r, FIXNUM, n)
#ifdef MRB_64BIT
#define SET_SYM_VALUE(r,v) ((r).value.sym = v, (r).value.sym_flag = BOXWORD_SYMBOL_FLAG)
#define SET_SYM_VALUE(r,v) do {\
union mrb_value mrb_value_union_variable;\
mrb_value_union_variable.sym = v;\
mrb_value_union_variable.sym_flag = BOXWORD_SYMBOL_FLAG;\
(r) = mrb_value_union_variable.w;\
} while (0)
#else
#define SET_SYM_VALUE(r,n) BOXWORD_SET_SHIFT_VALUE(r, SYMBOL, n)
#endif
#define SET_OBJ_VALUE(r,v) ((r)
.value.p =
v)
#define SET_OBJ_VALUE(r,v) ((r)
= (uintptr_t)
v)
MRB_INLINE
enum
mrb_vtype
mrb_type
(
mrb_value
o
)
...
...
@@ -164,7 +176,7 @@ mrb_type(mrb_value o)
mrb_fixnum_p
(
o
)
?
MRB_TT_FIXNUM
:
mrb_symbol_p
(
o
)
?
MRB_TT_SYMBOL
:
mrb_undef_p
(
o
)
?
MRB_TT_UNDEF
:
o
.
value
.
bp
->
tt
;
mrb_val_union
(
o
)
.
bp
->
tt
;
}
#endif
/* MRUBY_BOXING_WORD_H */
src/etc.c
View file @
53e46be7
...
...
@@ -151,12 +151,12 @@ mrb_obj_id(mrb_value obj)
MRB_API
mrb_value
mrb_word_boxing_float_value
(
mrb_state
*
mrb
,
mrb_float
f
)
{
mrb_value
v
;
union
mrb_value
v
;
v
.
value
.
p
=
mrb_obj_alloc
(
mrb
,
MRB_TT_FLOAT
,
mrb
->
float_class
);
v
.
value
.
fp
->
f
=
f
;
MRB_SET_FROZEN_FLAG
(
v
.
value
.
bp
);
return
v
;
v
.
p
=
mrb_obj_alloc
(
mrb
,
MRB_TT_FLOAT
,
mrb
->
float_class
);
v
.
fp
->
f
=
f
;
MRB_SET_FROZEN_FLAG
(
v
.
bp
);
return
v
.
w
;
}
#endif
/* MRB_WITHOUT_FLOAT */
#endif
/* MRB_WORD_BOXING */
...
...
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