ruby-changes:2857
From: ko1@a...
Date: 20 Dec 2007 06:40:10 +0900
Subject: [ruby-changes:2857] ko1 - Ruby:r14348 (trunk): * compile.c (iseq_compile_each): add pop after throw as return.
ko1 2007-12-20 06:39:08 +0900 (Thu, 20 Dec 2007) New Revision: 14348 Modified files: trunk/ChangeLog trunk/bootstraptest/test_knownbug.rb trunk/bootstraptest/test_syntax.rb trunk/compile.c trunk/iseq.c trunk/vm_core.h Log: * compile.c (iseq_compile_each): add pop after throw as return. * bootstraptest/test_knownbug.rb, test_syntax.rb: move resolved test. * vm_core.h, iseq.c, compile.h: add debug output code. http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/compile.c?r1=14348&r2=14347 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=14348&r2=14347 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/vm_core.h?r1=14348&r2=14347 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/iseq.c?r1=14348&r2=14347 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/bootstraptest/test_syntax.rb?r1=14348&r2=14347 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/bootstraptest/test_knownbug.rb?r1=14348&r2=14347 Index: ChangeLog =================================================================== --- ChangeLog (revision 14347) +++ ChangeLog (revision 14348) @@ -1,3 +1,11 @@ +Thu Dec 20 06:34:27 2007 Koichi Sasada <ko1@a...> + + * compile.c (iseq_compile_each): add pop after throw as return. + + * bootstraptest/test_knownbug.rb, test_syntax.rb: move resolved test. + + * vm_core.h, iseq.c, compile.h: add debug output code. + Thu Dec 20 04:57:18 2007 Koichi Sasada <ko1@a...> * compile.c (iseq_compile_each): remove unused retry entry. Index: bootstraptest/test_syntax.rb =================================================================== --- bootstraptest/test_syntax.rb (revision 14347) +++ bootstraptest/test_syntax.rb (revision 14348) @@ -641,5 +641,8 @@ class C; def !@; true; end; end !C.new } +assert_normal_exit %q{ + eval "while true; return; end rescue p $!" +}, '[ruby-dev:31663]' Index: bootstraptest/test_knownbug.rb =================================================================== --- bootstraptest/test_knownbug.rb (revision 14347) +++ bootstraptest/test_knownbug.rb (revision 14348) @@ -31,10 +31,6 @@ end } -assert_normal_exit %q{ - eval "while true; return; end rescue p $!" -}, '[ruby-dev:31663]' - assert_equal 'ok', %q{ 1.times{ eval("break") Index: vm_core.h =================================================================== --- vm_core.h (revision 14347) +++ vm_core.h (revision 14348) @@ -108,6 +108,7 @@ struct iseq_insn_info_entry { unsigned short position; unsigned short line_no; + unsigned short sp; }; struct iseq_catch_table_entry { Index: iseq.c =================================================================== --- iseq.c (revision 14347) +++ iseq.c (revision 14348) @@ -534,25 +534,34 @@ return iseq_data_to_ary(iseq); } -/* - now, search algorithm is brute force. but this should be binary search. - */ -static unsigned short -find_line_no(rb_iseq_t *iseqdat, unsigned long pos) +/* TODO: search algorithm is brute force. + this should be binary search or so. */ + +static struct iseq_insn_info_entry * +get_insn_info(const rb_iseq_t *iseq, const unsigned long pos) { - unsigned long i, size = iseqdat->insn_info_size; - struct iseq_insn_info_entry *iiary = iseqdat->insn_info_table; + unsigned long i, size = iseq->insn_info_size; + struct iseq_insn_info_entry *table = iseq->insn_info_table; for (i = 0; i < size; i++) { - if (iiary[i].position == pos) { - return iiary[i].line_no; + if (table[i].position == pos) { + return &table[i]; } } - /* rb_bug("find_line_no: can't find %lu", pos); */ + return 0; } static unsigned short +find_line_no(rb_iseq_t *iseq, unsigned long pos) +{ + struct iseq_insn_info_entry *entry = get_insn_info(iseq, pos); + if (entry) { + return entry->line_no; + } +} + +static unsigned short find_prev_line_no(rb_iseq_t *iseqdat, unsigned long pos) { unsigned long i, size = iseqdat->insn_info_size; @@ -569,8 +578,6 @@ } } - /* rb_bug("find_prev_line_no: can't find - %lu", pos); */ - return 0; } @@ -717,7 +724,7 @@ } } - { + if (1) { int line_no = find_line_no(iseqdat, pos); int prev = find_prev_line_no(iseqdat, pos); if (line_no && line_no != prev) { @@ -726,6 +733,14 @@ str = rb_str_new2(buff); } } + else { + /* for debug */ + struct iseq_insn_info_entry *entry = get_insn_info(iseqdat, pos); + snprintf(buff, sizeof(buff), "%-60s(line: %d, sp: %d)", + RSTRING_PTR(str), entry->line_no, entry->sp); + str = rb_str_new2(buff); + } + if (ret) { rb_str_cat2(str, "\n"); rb_str_concat(ret, str); Index: compile.c =================================================================== --- compile.c (revision 14347) +++ compile.c (revision 14348) @@ -1127,6 +1127,7 @@ } insn_info_table[k].line_no = iobj->line_no; insn_info_table[k].position = pos; + insn_info_table[k].sp = sp; pos += len; k++; break; @@ -3802,8 +3803,8 @@ ADD_INSN(ret, nd_line(node), leave); } else { - ADD_INSN1(ret, nd_line(node), throw, - INT2FIX(0x01) /* TAG_RETURN */ ); + ADD_INSN1(ret, nd_line(node), throw, INT2FIX(0x01) /* TAG_RETURN */ ); + ADD_INSN(ret, nd_line(node), pop); } break; } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml