ruby-changes:50884
From: nobu <ko1@a...>
Date: Wed, 4 Apr 2018 20:00:46 +0900 (JST)
Subject: [ruby-changes:50884] nobu:r63091 (trunk): iseq.c: indent iseq dump
nobu 2018-04-04 20:00:39 +0900 (Wed, 04 Apr 2018) New Revision: 63091 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=63091 Log: iseq.c: indent iseq dump * iseq.c (rb_iseq_disasm): indent catch_table iseq entries. Modified files: trunk/iseq.c Index: iseq.c =================================================================== --- iseq.c (revision 63090) +++ iseq.c (revision 63091) @@ -1926,8 +1926,8 @@ iseq_inspect(const rb_iseq_t *iseq) https://github.com/ruby/ruby/blob/trunk/iseq.c#L1926 } } -VALUE -rb_iseq_disasm(const rb_iseq_t *iseq) +static VALUE +rb_iseq_disasm_recursive(const rb_iseq_t *iseq, VALUE indent) { VALUE *code; VALUE str = rb_str_new(0, 0); @@ -1938,46 +1938,61 @@ rb_iseq_disasm(const rb_iseq_t *iseq) https://github.com/ruby/ruby/blob/trunk/iseq.c#L1938 size_t n; enum {header_minlen = 72}; st_table *done_iseq = 0; + const char *indent_str; + long indent_len; rb_secure(1); size = iseq->body->iseq_size; + indent_len = RSTRING_LEN(indent); + indent_str = RSTRING_PTR(indent); + + rb_str_cat(str, indent_str, indent_len); rb_str_cat2(str, "== disasm: "); - rb_str_concat(str, iseq_inspect(iseq)); + rb_str_append(str, iseq_inspect(iseq)); rb_str_catf(str, " (catch: %s)", iseq->body->catch_except_p ? "TRUE" : "FALSE"); - if ((l = RSTRING_LEN(str)) < header_minlen) { - rb_str_resize(str, header_minlen); - memset(RSTRING_PTR(str) + l, '=', header_minlen - l); + if ((l = RSTRING_LEN(str) - indent_len) < header_minlen) { + rb_str_modify_expand(str, header_minlen - l); + memset(RSTRING_END(str), '=', header_minlen - l); } rb_str_cat2(str, "\n"); /* show catch table information */ if (iseq->body->catch_table) { + rb_str_cat(str, indent_str, indent_len); rb_str_cat2(str, "== catch table\n"); } if (iseq->body->catch_table) { + rb_str_cat_cstr(indent, "| "); + indent_str = RSTRING_PTR(indent); for (i = 0; i < iseq->body->catch_table->size; i++) { const struct iseq_catch_table_entry *entry = &iseq->body->catch_table->entries[i]; + rb_str_cat(str, indent_str, indent_len); rb_str_catf(str, "| catch type: %-6s st: %04d ed: %04d sp: %04d cont: %04d\n", catch_type((int)entry->type), (int)entry->start, (int)entry->end, (int)entry->sp, (int)entry->cont); if (entry->iseq && !(done_iseq && st_is_member(done_iseq, (st_data_t)entry->iseq))) { - rb_str_concat(str, rb_iseq_disasm(rb_iseq_check(entry->iseq))); + rb_str_concat(str, rb_iseq_disasm_recursive(rb_iseq_check(entry->iseq), indent)); if (!done_iseq) done_iseq = st_init_numtable(); st_insert(done_iseq, (st_data_t)entry->iseq, (st_data_t)0); + indent_str = RSTRING_PTR(indent); } } + rb_str_resize(indent, indent_len); + indent_str = RSTRING_PTR(indent); } if (iseq->body->catch_table) { + rb_str_cat(str, indent_str, indent_len); rb_str_cat2(str, "|-------------------------------------" "-----------------------------------\n"); } /* show local table information */ if (iseq->body->local_table) { + rb_str_cat(str, indent_str, indent_len); rb_str_catf(str, "local table (size: %d, argc: %d " "[opts: %d, rest: %d, post: %d, block: %d, kw: %d@%d, kwrest: %d])\n", @@ -2015,6 +2030,7 @@ rb_iseq_disasm(const rb_iseq_t *iseq) https://github.com/ruby/ruby/blob/trunk/iseq.c#L2030 (iseq->body->param.flags.has_kwrest && iseq->body->param.keyword->rest_start == li) ? "Kwrest" : "", (iseq->body->param.flags.has_block && iseq->body->param.block_start == li) ? "Block" : ""); + rb_str_cat(str, indent_str, indent_len); rb_str_catf(str, "[%2d] ", i + 1); width = RSTRING_LEN(str) + 11; rb_str_append(str, name); @@ -2027,19 +2043,28 @@ rb_iseq_disasm(const rb_iseq_t *iseq) https://github.com/ruby/ruby/blob/trunk/iseq.c#L2043 /* show each line */ code = rb_iseq_original_iseq(iseq); for (n = 0; n < size;) { + rb_str_cat(str, indent_str, indent_len); n += rb_iseq_disasm_insn(str, code, n, iseq, child); } for (l = 0; l < RARRAY_LEN(child); l++) { VALUE isv = rb_ary_entry(child, l); if (done_iseq && st_is_member(done_iseq, (st_data_t)isv)) continue; - rb_str_concat(str, rb_iseq_disasm(rb_iseq_check((rb_iseq_t *)isv))); + rb_str_cat_cstr(str, "\n"); + rb_str_concat(str, rb_iseq_disasm_recursive(rb_iseq_check((rb_iseq_t *)isv), indent)); + indent_str = RSTRING_PTR(indent); } if (done_iseq) st_free_table(done_iseq); return str; } +VALUE +rb_iseq_disasm(const rb_iseq_t *iseq) +{ + return rb_iseq_disasm_recursive(iseq, rb_str_new(0, 0)); +} + static VALUE rb_iseq_all_children(const rb_iseq_t *iseq) { -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/