diff options
author | ko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-11-27 04:43:54 +0000 |
---|---|---|
committer | ko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-11-27 04:43:54 +0000 |
commit | 123387ed294aa83cc506ef7d8733b5fd042bd67f (patch) | |
tree | 01e457b0aa89e3a4c67a05d29996b89f804d4275 | |
parent | aa6e2791083b5ecfb4249773b99b11431e271a46 (diff) | |
download | ruby-123387ed294aa83cc506ef7d8733b5fd042bd67f.tar.gz ruby-123387ed294aa83cc506ef7d8733b5fd042bd67f.tar.xz ruby-123387ed294aa83cc506ef7d8733b5fd042bd67f.zip |
* compile.c, insns.def: change return value of "defined?"
for $&, $1, ... . If such variables are defined,
return "global-variable".
* test/ruby/test_defined.rb: add tests.
* bootstraptest/test_syntax.rb: fix a test.
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@14031 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 10 | ||||
-rw-r--r-- | bootstraptest/test_syntax.rb | 2 | ||||
-rw-r--r-- | compile.c | 4 | ||||
-rw-r--r-- | insns.def | 11 | ||||
-rw-r--r-- | test/ruby/test_defined.rb | 29 |
5 files changed, 46 insertions, 10 deletions
@@ -1,3 +1,13 @@ +Tue Nov 27 12:47:23 2007 Koichi Sasada <ko1@atdot.net> + + * compile.c, insns.def: change return value of "defined?" + for $&, $1, ... . If such variables are defined, + return "global-variable". + + * test/ruby/test_defined.rb: add tests. + + * bootstraptest/test_syntax.rb: fix a test. + Tue Nov 27 11:54:46 2007 Koichi Sasada <ko1@atdot.net> * insns.def: fix typo. diff --git a/bootstraptest/test_syntax.rb b/bootstraptest/test_syntax.rb index 9541d6708..b1517e697 100644 --- a/bootstraptest/test_syntax.rb +++ b/bootstraptest/test_syntax.rb @@ -248,7 +248,7 @@ assert_equal %q{["method", "method", "method", "method", nil, nil, "method", "me end C.new.test + [defined?(C.new.m3)] } -assert_equal %q{[nil, nil, nil, nil, "$1", "$2", nil, nil]}, %q{ +assert_equal %q{[nil, nil, nil, nil, "global-variable", "global-variable", nil, nil]}, %q{ $ans = [defined?($1), defined?($2), defined?($3), defined?($4)] /(a)(b)/ =~ 'ab' $ans + [defined?($1), defined?($2), defined?($3), defined?($4)] @@ -2333,10 +2333,12 @@ defined_expr(rb_iseq_t *iseq, LINK_ANCHOR *ret, needstr); return 1; + case NODE_BACK_REF: case NODE_NTH_REF: ADD_INSN(ret, nd_line(node), putnil); ADD_INSN3(ret, nd_line(node), defined, INT2FIX(DEFINED_REF), - INT2FIX(node->nd_nth), needstr); + INT2FIX(node->nd_nth << 1 | type == NODE_BACK_REF), + needstr); return 1; case NODE_ZSUPER: @@ -795,8 +795,6 @@ defined { VALUE klass; char *expr_type = 0; - char buf[0x10]; - val = Qnil; switch (type) { @@ -868,12 +866,9 @@ defined break; } case DEFINED_REF:{ - int nth = FIX2INT(obj); - VALUE backref = lfp_svar_get(th, GET_LFP(), 1); - - if (rb_reg_nth_match(nth, backref) != Qnil) { - snprintf(buf, 0x10, "$%d", nth); - expr_type = buf; + val = vm_getspecial(th, GET_LFP(), Qfalse, FIX2INT(obj)); + if (val != Qnil) { + expr_type = "global-variable"; } break; } diff --git a/test/ruby/test_defined.rb b/test/ruby/test_defined.rb index 84b9bf7b9..bfcd7fb66 100644 --- a/test/ruby/test_defined.rb +++ b/test/ruby/test_defined.rb @@ -48,5 +48,34 @@ class TestDefined < Test::Unit::TestCase assert(defined_test) # not iterator assert(!defined_test{}) # called as iterator + + /a/ =~ '' + assert_equal nil, defined?($&) + assert_equal nil, defined?($`) + assert_equal nil, defined?($') + assert_equal nil, defined?($+) + assert_equal nil, defined?($1) + assert_equal nil, defined?($2) + /a/ =~ 'a' + assert_equal 'global-variable', defined?($&) + assert_equal 'global-variable', defined?($`) + assert_equal 'global-variable', defined?($') + assert_equal nil, defined?($+) + assert_equal nil, defined?($1) + assert_equal nil, defined?($2) + /(a)/ =~ 'a' + assert_equal 'global-variable', defined?($&) + assert_equal 'global-variable', defined?($`) + assert_equal 'global-variable', defined?($') + assert_equal 'global-variable', defined?($+) + assert_equal 'global-variable', defined?($1) + assert_equal nil, defined?($2) + /(a)b/ =~ 'ab' + assert_equal 'global-variable', defined?($&) + assert_equal 'global-variable', defined?($`) + assert_equal 'global-variable', defined?($') + assert_equal 'global-variable', defined?($+) + assert_equal 'global-variable', defined?($1) + assert_equal nil, defined?($2) end end |