Skip to content

Commit 15164bf

Browse files
committed
* insns.def (defined), vm_insnhelper.c (vm_defined):
move instruction body to the vm_defined() function. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50736 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent 86bafab commit 15164bf

File tree

3 files changed

+114
-100
lines changed

3 files changed

+114
-100
lines changed

ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
Wed Jun 3 04:14:13 2015 Koichi Sasada <[email protected]>
2+
3+
* insns.def (defined), vm_insnhelper.c (vm_defined):
4+
move instruction body to the vm_defined() function.
5+
16
Wed Jun 3 02:29:25 2015 Benoit Daloze <[email protected]>
27

38
* test/ruby/test_module.rb: Do not assume class variable order.

insns.def

Lines changed: 1 addition & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -715,106 +715,7 @@ defined
715715
(VALUE v)
716716
(VALUE val)
717717
{
718-
VALUE klass;
719-
enum defined_type expr_type = 0;
720-
enum defined_type type = (enum defined_type)op_type;
721-
722-
val = Qnil;
723-
724-
switch (type) {
725-
case DEFINED_IVAR:
726-
if (rb_ivar_defined(GET_SELF(), SYM2ID(obj))) {
727-
expr_type = DEFINED_IVAR;
728-
}
729-
break;
730-
case DEFINED_IVAR2:
731-
klass = vm_get_cbase(GET_EP());
732-
break;
733-
case DEFINED_GVAR:
734-
if (rb_gvar_defined(rb_global_entry(SYM2ID(obj)))) {
735-
expr_type = DEFINED_GVAR;
736-
}
737-
break;
738-
case DEFINED_CVAR: {
739-
const rb_cref_t *cref = rb_vm_get_cref(GET_EP());
740-
klass = vm_get_cvar_base(cref, GET_CFP());
741-
if (rb_cvar_defined(klass, SYM2ID(obj))) {
742-
expr_type = DEFINED_CVAR;
743-
}
744-
break;
745-
}
746-
case DEFINED_CONST:
747-
klass = v;
748-
if (vm_get_ev_const(th, klass, SYM2ID(obj), 1)) {
749-
expr_type = DEFINED_CONST;
750-
}
751-
break;
752-
case DEFINED_FUNC:
753-
klass = CLASS_OF(v);
754-
if (rb_method_boundp(klass, SYM2ID(obj), 0)) {
755-
expr_type = DEFINED_METHOD;
756-
}
757-
break;
758-
case DEFINED_METHOD:{
759-
VALUE klass = CLASS_OF(v);
760-
const rb_method_entry_t *me = rb_method_entry(klass, SYM2ID(obj), 0);
761-
762-
if (me) {
763-
const rb_method_definition_t *def = me->def;
764-
if (!(def->flag & NOEX_PRIVATE)) {
765-
if (!((def->flag & NOEX_PROTECTED) &&
766-
!rb_obj_is_kind_of(GET_SELF(),
767-
rb_class_real(klass)))) {
768-
expr_type = DEFINED_METHOD;
769-
}
770-
}
771-
}
772-
{
773-
VALUE args[2];
774-
VALUE r;
775-
776-
args[0] = obj; args[1] = Qfalse;
777-
r = rb_check_funcall(v, idRespond_to_missing, 2, args);
778-
if (r != Qundef && RTEST(r))
779-
expr_type = DEFINED_METHOD;
780-
}
781-
break;
782-
}
783-
case DEFINED_YIELD:
784-
if (GET_BLOCK_PTR()) {
785-
expr_type = DEFINED_YIELD;
786-
}
787-
break;
788-
case DEFINED_ZSUPER:{
789-
rb_call_info_t cit;
790-
if (vm_search_superclass(GET_CFP(), GET_ISEQ(), Qnil, &cit) == 0) {
791-
VALUE klass = cit.klass;
792-
ID id = cit.mid;
793-
if (rb_method_boundp(klass, id, 0)) {
794-
expr_type = DEFINED_ZSUPER;
795-
}
796-
}
797-
break;
798-
}
799-
case DEFINED_REF:{
800-
val = vm_getspecial(th, GET_LEP(), Qfalse, FIX2INT(obj));
801-
if (val != Qnil) {
802-
expr_type = DEFINED_GVAR;
803-
}
804-
break;
805-
}
806-
default:
807-
rb_bug("unimplemented defined? type (VM)");
808-
break;
809-
}
810-
if (expr_type != 0) {
811-
if (needstr != Qfalse) {
812-
val = rb_iseq_defined_string(expr_type);
813-
}
814-
else {
815-
val = Qtrue;
816-
}
817-
}
718+
val = vm_defined(th, GET_CFP(), op_type, obj, needstr, v);
818719
}
819720

820721
/**

vm_insnhelper.c

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2406,3 +2406,111 @@ FUNC_FASTCALL(rb_vm_opt_struct_aset)(rb_thread_t *th, rb_control_frame_t *reg_cf
24062406
rb_struct_aset(GET_SELF(), TOPN(0), TOPN(1));
24072407
return reg_cfp;
24082408
}
2409+
2410+
/* defined insn */
2411+
2412+
static VALUE
2413+
vm_defined(rb_thread_t *th, rb_control_frame_t *reg_cfp, rb_num_t op_type, VALUE obj, VALUE needstr, VALUE v)
2414+
{
2415+
VALUE klass;
2416+
enum defined_type expr_type = 0;
2417+
enum defined_type type = (enum defined_type)op_type;
2418+
2419+
switch (type) {
2420+
case DEFINED_IVAR:
2421+
if (rb_ivar_defined(GET_SELF(), SYM2ID(obj))) {
2422+
expr_type = DEFINED_IVAR;
2423+
}
2424+
break;
2425+
case DEFINED_IVAR2:
2426+
klass = vm_get_cbase(GET_EP());
2427+
break;
2428+
case DEFINED_GVAR:
2429+
if (rb_gvar_defined(rb_global_entry(SYM2ID(obj)))) {
2430+
expr_type = DEFINED_GVAR;
2431+
}
2432+
break;
2433+
case DEFINED_CVAR: {
2434+
const rb_cref_t *cref = rb_vm_get_cref(GET_EP());
2435+
klass = vm_get_cvar_base(cref, GET_CFP());
2436+
if (rb_cvar_defined(klass, SYM2ID(obj))) {
2437+
expr_type = DEFINED_CVAR;
2438+
}
2439+
break;
2440+
}
2441+
case DEFINED_CONST:
2442+
klass = v;
2443+
if (vm_get_ev_const(th, klass, SYM2ID(obj), 1)) {
2444+
expr_type = DEFINED_CONST;
2445+
}
2446+
break;
2447+
case DEFINED_FUNC:
2448+
klass = CLASS_OF(v);
2449+
if (rb_method_boundp(klass, SYM2ID(obj), 0)) {
2450+
expr_type = DEFINED_METHOD;
2451+
}
2452+
break;
2453+
case DEFINED_METHOD:{
2454+
VALUE klass = CLASS_OF(v);
2455+
const rb_method_entry_t *me = rb_method_entry(klass, SYM2ID(obj), 0);
2456+
2457+
if (me) {
2458+
const rb_method_definition_t *def = me->def;
2459+
if (!(def->flag & NOEX_PRIVATE)) {
2460+
if (!((def->flag & NOEX_PROTECTED) &&
2461+
!rb_obj_is_kind_of(GET_SELF(),
2462+
rb_class_real(klass)))) {
2463+
expr_type = DEFINED_METHOD;
2464+
}
2465+
}
2466+
}
2467+
{
2468+
VALUE args[2];
2469+
VALUE r;
2470+
2471+
args[0] = obj; args[1] = Qfalse;
2472+
r = rb_check_funcall(v, idRespond_to_missing, 2, args);
2473+
if (r != Qundef && RTEST(r))
2474+
expr_type = DEFINED_METHOD;
2475+
}
2476+
break;
2477+
}
2478+
case DEFINED_YIELD:
2479+
if (GET_BLOCK_PTR()) {
2480+
expr_type = DEFINED_YIELD;
2481+
}
2482+
break;
2483+
case DEFINED_ZSUPER:{
2484+
rb_call_info_t cit;
2485+
if (vm_search_superclass(GET_CFP(), GET_ISEQ(), Qnil, &cit) == 0) {
2486+
VALUE klass = cit.klass;
2487+
ID id = cit.mid;
2488+
if (rb_method_boundp(klass, id, 0)) {
2489+
expr_type = DEFINED_ZSUPER;
2490+
}
2491+
}
2492+
break;
2493+
}
2494+
case DEFINED_REF:{
2495+
if (vm_getspecial(th, GET_LEP(), Qfalse, FIX2INT(obj)) != Qnil) {
2496+
expr_type = DEFINED_GVAR;
2497+
}
2498+
break;
2499+
}
2500+
default:
2501+
rb_bug("unimplemented defined? type (VM)");
2502+
break;
2503+
}
2504+
2505+
if (expr_type != 0) {
2506+
if (needstr != Qfalse) {
2507+
return rb_iseq_defined_string(expr_type);
2508+
}
2509+
else {
2510+
return Qtrue;
2511+
}
2512+
}
2513+
else {
2514+
return Qnil;
2515+
}
2516+
}

0 commit comments

Comments
 (0)