From 5485df3e105aadfd6b61854180a8c4a803fe993f Mon Sep 17 00:00:00 2001 From: ko1 Date: Wed, 19 Dec 2007 21:39:08 +0000 Subject: [PATCH] * 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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@14348 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 8 +++++++ bootstraptest/test_knownbug.rb | 4 ---- bootstraptest/test_syntax.rb | 3 +++ compile.c | 5 +++-- iseq.c | 41 +++++++++++++++++++++++----------- vm_core.h | 1 + 6 files changed, 43 insertions(+), 19 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5b15b95779..5801955a65 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +Thu Dec 20 06:34:27 2007 Koichi Sasada + + * 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 * compile.c (iseq_compile_each): remove unused retry entry. diff --git a/bootstraptest/test_knownbug.rb b/bootstraptest/test_knownbug.rb index 30a83259f0..2108a59168 100644 --- a/bootstraptest/test_knownbug.rb +++ b/bootstraptest/test_knownbug.rb @@ -31,10 +31,6 @@ assert_equal 'ok', %q{ end } -assert_normal_exit %q{ - eval "while true; return; end rescue p $!" -}, '[ruby-dev:31663]' - assert_equal 'ok', %q{ 1.times{ eval("break") diff --git a/bootstraptest/test_syntax.rb b/bootstraptest/test_syntax.rb index 0ba8f658f2..e407d7cf5f 100644 --- a/bootstraptest/test_syntax.rb +++ b/bootstraptest/test_syntax.rb @@ -641,5 +641,8 @@ assert_equal 'true', %q{ class C; def !@; true; end; end !C.new } +assert_normal_exit %q{ + eval "while true; return; end rescue p $!" +}, '[ruby-dev:31663]' diff --git a/compile.c b/compile.c index 07e70666d4..bbb43003ad 100644 --- a/compile.c +++ b/compile.c @@ -1127,6 +1127,7 @@ iseq_set_sequence(rb_iseq_t *iseq, LINK_ANCHOR *anchor) } 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 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped) 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; } diff --git a/iseq.c b/iseq.c index e9e65c76fa..6ad0e8d25a 100644 --- a/iseq.c +++ b/iseq.c @@ -534,24 +534,33 @@ iseq_to_a(VALUE self) 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) { @@ -569,8 +578,6 @@ find_prev_line_no(rb_iseq_t *iseqdat, unsigned long pos) } } - /* rb_bug("find_prev_line_no: can't find - %lu", pos); */ - return 0; } @@ -717,7 +724,7 @@ ruby_iseq_disasm_insn(VALUE ret, VALUE *iseq, int pos, } } - { + 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 @@ ruby_iseq_disasm_insn(VALUE ret, VALUE *iseq, int pos, 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); diff --git a/vm_core.h b/vm_core.h index a104778b44..8f8079e31d 100644 --- a/vm_core.h +++ b/vm_core.h @@ -108,6 +108,7 @@ struct iseq_insn_info_entry { unsigned short position; unsigned short line_no; + unsigned short sp; }; struct iseq_catch_table_entry {