2008-01-01
Ruby 1.9.0のバイトコードをいじり倒す(その7)
|正月から何をやってるんだか・・・。(その5)の問題http://d.hatena.ne.jp/miura1729/20071230/1198973841が解決できました。
compile.cのiseq_build_from_aryで、arg_simpleというiseq構造体のメンバーをリストアするようにしました。
パッチ(これまでのものも全部含むです)
Index: iseq.c =================================================================== --- iseq.c (revision 14778) +++ iseq.c (working copy) @@ -354,7 +354,7 @@ name = CHECK_STRING(rb_ary_entry(data, 5)); filename = CHECK_STRING(rb_ary_entry(data, 6)); - line = CHECK_ARRAY(rb_ary_entry(data, 7)); + line = CHECK_INTEGER(rb_ary_entry(data, 7)); type = CHECK_SYMBOL(rb_ary_entry(data, 8)); locals = CHECK_ARRAY(rb_ary_entry(data, 9)); @@ -1054,6 +1054,7 @@ } else { rb_ary_push(args, INT2FIX(iseq->argc)); + rb_ary_push(args, INT2FIX(iseq->arg_opts)); rb_ary_push(args, arg_opt_labels); rb_ary_push(args, INT2FIX(iseq->arg_post_len)); rb_ary_push(args, INT2FIX(iseq->arg_post_start)); @@ -1195,6 +1196,7 @@ rb_ary_push(val, misc); rb_ary_push(val, iseq->name); rb_ary_push(val, iseq->filename); + rb_ary_push(val, INT2FIX(0)); rb_ary_push(val, type); rb_ary_push(val, locals); rb_ary_push(val, args); @@ -1285,7 +1287,7 @@ rb_define_method(rb_cISeq, "eval", iseq_eval, 0); /* disable this feature because there is no verifier. */ - /* rb_define_singleton_method(rb_cISeq, "load", iseq_s_load, -1); */ + rb_define_singleton_method(rb_cISeq, "load", iseq_s_load, -1); rb_define_singleton_method(rb_cISeq, "compile", iseq_s_compile, -1); rb_define_singleton_method(rb_cISeq, "new", iseq_s_compile, -1); Index: compile.c =================================================================== --- compile.c (revision 14778) +++ compile.c (working copy) @@ -4852,7 +4852,7 @@ opt = 1; } - iseq->local_table_size = opt + RARRAY_LEN(locals); + iseq->local_table_size = RARRAY_LEN(locals); iseq->local_table = tbl = (ID *)ALLOC_N(ID *, iseq->local_table_size); iseq->local_size = opt + iseq->local_table_size; @@ -4867,14 +4867,15 @@ iseq->arg_simple = 1; } else { - int i = 0; - VALUE argc = CHECK_INTEGER(rb_ary_entry(args, i++)); - VALUE arg_opts = CHECK_INTEGER(rb_ary_entry(args, i++)); - VALUE arg_opt_labels = CHECK_ARRAY(rb_ary_entry(args, i++)); - VALUE arg_post_len = CHECK_INTEGER(rb_ary_entry(args, i++)); - VALUE arg_post_start = CHECK_INTEGER(rb_ary_entry(args, i++)); - VALUE arg_rest = CHECK_INTEGER(rb_ary_entry(args, i++)); - VALUE arg_block = CHECK_INTEGER(rb_ary_entry(args, i++)); + int i; + VALUE argc = CHECK_INTEGER(rb_ary_entry(args, 0)); + VALUE arg_opts = CHECK_INTEGER(rb_ary_entry(args, 1)); + VALUE arg_opt_labels = CHECK_ARRAY(rb_ary_entry(args, 2)); + VALUE arg_post_len = CHECK_INTEGER(rb_ary_entry(args, 3)); + VALUE arg_post_start = CHECK_INTEGER(rb_ary_entry(args, 4)); + VALUE arg_rest = CHECK_INTEGER(rb_ary_entry(args, 5)); + VALUE arg_block = CHECK_INTEGER(rb_ary_entry(args, 6)); + VALUE arg_simple = CHECK_INTEGER(rb_ary_entry(args, 7)); iseq->argc = FIX2INT(argc); iseq->arg_opts = FIX2INT(arg_opts); @@ -4882,6 +4883,7 @@ iseq->arg_post_len = FIX2INT(arg_post_len); iseq->arg_post_start = FIX2INT(arg_post_start); iseq->arg_block = FIX2INT(arg_block); + iseq->arg_simple = FIX2INT(arg_simple); iseq->arg_opt_table = (VALUE *)ALLOC_N(VALUE, iseq->arg_opts); if (iseq->arg_block != -1) {
- 7 http://d.hatena.ne.jp/ihag/comment?date=20080101
- 3 http://www.google.com/search?q=require pp&hl=ja&lr=
- 2 http://d.hatena.ne.jp/fd0/20071230/p1
- 1 http://d.hatena.ne.jp/higepon/20071230/1199017601
- 1 http://d.hatena.ne.jp/higepon/edit
- 1 http://d.hatena.ne.jp/keyword/gnuplot
- 1 http://d.hatena.ne.jp/keyworddiary/Ruby
- 1 http://www.google.co.jp/search?hl=ja&client=firefox-a&rls=org.mozilla:ja:official&q=vm+バイトコード&btnG=検索&lr=lang_ja