diff options
-rw-r--r-- | ChangeLog | 76 | ||||
-rw-r--r-- | call_cfunc.ci | 38 | ||||
-rw-r--r-- | compile.c | 3262 | ||||
-rw-r--r-- | dir.c | 12 | ||||
-rw-r--r-- | eval.c | 180 | ||||
-rw-r--r-- | eval_jump.h | 46 | ||||
-rw-r--r-- | eval_method.h | 36 | ||||
-rw-r--r-- | numeric.c | 48 | ||||
-rw-r--r-- | pack.c | 50 | ||||
-rw-r--r-- | parse.y | 32 | ||||
-rw-r--r-- | re.c | 287 | ||||
-rw-r--r-- | thread.c | 214 | ||||
-rw-r--r-- | thread_pthread.ci | 4 | ||||
-rw-r--r-- | thread_win32.ci | 14 | ||||
-rw-r--r-- | version.h | 6 | ||||
-rw-r--r-- | vm.c | 164 | ||||
-rw-r--r-- | vm_dump.c | 22 |
17 files changed, 2261 insertions, 2230 deletions
@@ -1,3 +1,15 @@ +Tue Jun 5 13:26:36 2007 Nobuyoshi Nakada <nobu@ruby-lang.org> + + * compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c, + pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci, + thread_pthread.ci, thread_win32.ci: fixed indentation. + +Tue Jun 5 13:17:11 2007 Nobuyoshi Nakada <nobu@ruby-lang.org> + + * call_cfunc.ci, compile.c, dir.c, eval.c, eval_jump.h, numeric.c, + pack.c, re.c, thread.c, thread_win32.ci, vm.c, vm_dump.c: fixed + indentation. + Mon Jun 04 21:15:45 2007 NARUSE, Yui <naruse@ruby-lang.org> * lib/json.rb, lib/json, ext/json, test/json: @@ -965,8 +977,8 @@ Wed Mar 21 17:04:30 2007 Nobuyoshi Nakada <nobu@ruby-lang.org> Tue Mar 21 08:20:00 2007 Nathaniel Talbott <ntalbott@ruby-lang.org> - * test/testunit/collector/test_dir.rb: Fixed test/unit tests that - were breaking due to Module#public_instance_methods now + * test/testunit/collector/test_dir.rb: Fixed test/unit tests that + were breaking due to Module#public_instance_methods now returning a Symbol instead of a String. * test/testunit/collector/test_objectspace.rb: Ditto. @@ -1256,14 +1268,14 @@ Fri Mar 2 21:17:14 2007 Masaki Suketa <masaki.suketa@nifty.ne.jp> * ext/win32ole/win32ole.c (get_ptr_of_variant, ole_set_safe_array, ole_val2ptr_variant, ole_val2olevariantdata, ole_variant2val, - ): fix some bugs of WIN32OLE_VARIANT.new when variant type is + ): fix some bugs of WIN32OLE_VARIANT.new when variant type is VT_ARRAY|VT_BSTR or VT_BYREF. * ext/win32ole/win32ole.c (folevariant_s_array, folevariant_initialize): WIN32OLE_VARIANT#[], WIN32OLE_VARIANT#[]=, WIN32OLE_VARIANT#value= is defined as instance method of WIN32OLE_VARIANT. - * test/win32ole/test_win32ole_variant.rb: add some test for + * test/win32ole/test_win32ole_variant.rb: add some test for VT_ARRAY, VT_BYREF variant type. Fri Mar 2 07:58:24 2007 Yukihiro Matsumoto <matz@ruby-lang.org> @@ -1642,7 +1654,7 @@ Sat Feb 24 10:38:05 2007 Minero Aoki <aamine@loveruby.net> Sat Feb 24 07:31:35 2007 Masaki Suketa <masaki.suketa@nifty.ne.jp> - * ext/win32ole/win32ole.c: add WIN32OLE_VARIANT.array, + * ext/win32ole/win32ole.c: add WIN32OLE_VARIANT.array, WIN32OLE_VARIANT#value=, refactoring. * test/win32ole/test_win32ole_variant.rb: add some test for @@ -1757,7 +1769,7 @@ Wed Feb 21 09:14:04 2007 Nobuyoshi Nakada <nobu@ruby-lang.org> Tue Feb 20 21:19:29 2007 Masaki Suketa <masaki.suketa@nifty.ne.jp> - * ext/win32ole/win32ole.c (installed_code_page_proc, + * ext/win32ole/win32ole.c (installed_code_page_proc, ole_variant2val): small refactoring. Tue Feb 20 15:11:42 2007 Koichi Sasada <ko1@atdot.net> @@ -1822,7 +1834,7 @@ Fri Feb 16 20:59:10 2007 Koichi Sasada <ko1@atdot.net> Fri Feb 16 19:24:22 2007 Yukihiro Matsumoto <matz@ruby-lang.org> * math.c (math_log): update document to mention second optional - argument for logarithm base. + argument for logarithm base. Fri Feb 16 19:19:21 2007 Yukihiro Matsumoto <matz@ruby-lang.org> @@ -1872,7 +1884,7 @@ Thu Feb 15 01:43:45 2007 Koichi Sasada <ko1@atdot.net> Wed Feb 14 22:52:43 2007 Masaki Suketa <masaki.suketa@nifty.ne.jp> - * ext/win32ole/win32ole.c (ole_variant2val): VC++6 does not + * ext/win32ole/win32ole.c (ole_variant2val): VC++6 does not support VT_I8, VT_UI8. Wed Feb 14 22:10:21 2007 Koichi Sasada <ko1@atdot.net> @@ -1998,7 +2010,7 @@ Sun Feb 11 22:10:08 2007 Kouhei Sutou <kou@cozmixng.org> Sun Feb 11 18:47:14 2007 Masaki Suketa <masaki.suketa@nifty.ne.jp> - * ext/win32ole/win32ole.c (ole_val2olevariantdata): + * ext/win32ole/win32ole.c (ole_val2olevariantdata): WIN32OLE_VARIANT#new accepts nil when variant type is VT_ARRAY. * test/win32ole/test_win32ole_variant.rb: ditto. @@ -2026,7 +2038,7 @@ Sat Feb 10 17:46:52 2007 Nobuyoshi Nakada <nobu@ruby-lang.org> Sat Feb 10 00:13:11 2007 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp> - * ext/tk/lib/tk.rb: fix typo (TkConfigMethod::__confinfo_cmd, + * ext/tk/lib/tk.rb: fix typo (TkConfigMethod::__confinfo_cmd, __conv_keyonly_opts). Fri Feb 9 12:33:40 2007 Koichi Sasada <ko1@atdot.net> @@ -2066,7 +2078,7 @@ Thu Feb 8 22:44:04 2007 Masaki Suketa <masaki.suketa@nifty.ne.jp> * ext/win32ole/win32ole.c (ole_set_safe_array, ole_variant2val, ole_val_ary2variant_ary): fix WIN32OLE_VARIANT.new bug when - 1st argument is empty array, and when 2nd argument is + 1st argument is empty array, and when 2nd argument is VT_ARRAY|VT_BYREF. * test/win32ole/test_win32ole_variant.rb: ditto. @@ -2123,7 +2135,7 @@ Thu Feb 8 15:48:44 2007 Koichi Sasada <ko1@atdot.net> * thread.c: fix to use polling in select on cygwin and mswin32. - * thread.c, thread_pthread.ci, thread_win32.ci, yarvcore.h: + * thread.c, thread_pthread.ci, thread_win32.ci, yarvcore.h: rename: * rb_thread_t#interrupt_function -> unblock_function * rb_interrupt_function_t -> rb_unblock_function @@ -2223,7 +2235,7 @@ Wed Feb 7 09:35:32 2007 Koichi Sasada <ko1@atdot.net> * thread_pthread.ci: comment out codes with USE_THREAD_CACHE. - * vm.c (rb_svar, rb_backref_get, rb_backref_get, + * vm.c (rb_svar, rb_backref_get, rb_backref_get, rb_lastline_get, rb_lastline_set) : moved from yarvcore.c. * vm.c (yarv_init_redefined_flag): add a prototype and rename @@ -2409,7 +2421,7 @@ Sat Feb 3 23:51:58 2007 Yukihiro Matsumoto <matz@ruby-lang.org> symbol from a symbol and a class. back-ported from matzruby. * parse.y (rb_decompose_ivar2): reverse function of - rb_compose_ivar2(). + rb_compose_ivar2(). * marshal.c (w_symbol): support class local instance variables. @@ -2433,7 +2445,7 @@ Sat Feb 3 23:21:13 2007 Yukihiro Matsumoto <matz@ruby-lang.org> Sat Feb 3 14:32:58 2007 Masaki Suketa <masaki.suketa@nifty.ne.jp> * ext/win32ole/win32ole.c (ole_val2olevariantdata, ole_val2variant): - fix the bug of WIN32OLE_VARIANT.new when variant type is + fix the bug of WIN32OLE_VARIANT.new when variant type is VT_ARRAY. * ext/win32ole/sample/excel1.rb: rewrite using WIN32OLE_VARIANT. @@ -2484,7 +2496,7 @@ Fri Feb 2 18:27:54 2007 Yukihiro Matsumoto <matz@ruby-lang.org> Fri Feb 2 00:13:44 2007 Yukihiro Matsumoto <matz@ruby-lang.org> - * ruby.h (SYMBOL_P): make Symbol immediate again for performance. + * ruby.h (SYMBOL_P): make Symbol immediate again for performance. * string.c: redesign symbol methods. @@ -2556,7 +2568,7 @@ Mon Jan 29 21:32:37 2007 Masaki Suketa <masaki.suketa@nifty.ne.jp> * test/win32ole/test_win32ole.rb: add test for WIN32OLE.locale=, WIN32OLE.locale. - * test/win32ole/test_win32ole_variant.rb: add test for + * test/win32ole/test_win32ole_variant.rb: add test for WIN32OLE_VARIANT#vartype. Mon Jan 29 14:14:35 2007 Yukihiro Matsumoto <matz@ruby-lang.org> @@ -2570,11 +2582,11 @@ Sun Jan 28 08:41:49 2007 Masaki Suketa <masaki.suketa@nifty.ne.jp> Sat Jan 27 18:36:33 2007 Masaki Suketa <masaki.suketa@nifty.ne.jp> - * ext/win32ole/win32ole.c (ole_val2olevariantdata): bug fix. + * ext/win32ole/win32ole.c (ole_val2olevariantdata): bug fix. WIN32OLE_VARIANT.new check that 1st argument should T_ARRAY when variant type is VT_ARRAY. - * test/win32ole/test_win32ole_variant.rb: add some test. + * test/win32ole/test_win32ole_variant.rb: add some test. Fri Jan 26 23:55:56 2007 Masaki Suketa <masaki.suketa@nifty.ne.jp> @@ -2629,14 +2641,14 @@ Mon Jan 22 14:57:25 2007 Yukihiro Matsumoto <matz@ruby-lang.org> Sat Jan 20 21:05:18 2007 Masaki Suketa <masaki.suketa@nifty.ne.jp> - * ext/win32ole/win32ole.c (fole_s_set_code_page): WIN32OLE.codepage= + * ext/win32ole/win32ole.c (fole_s_set_code_page): WIN32OLE.codepage= accepts installed codepage. * test/win32ole/test_win32ole.rb (test_s_codepage_changed): ditto. Sat Jan 20 11:18:49 2007 Masaki Suketa <masaki.suketa@nifty.ne.jp> - * ext/win32ole/win32ole.c (ole_invoke, ole_invoke2, ole_propertyput): + * ext/win32ole/win32ole.c (ole_invoke, ole_invoke2, ole_propertyput): modify WIN32OLERuntimeError message. * test/win32ole/test_win32ole.rb: ditto. @@ -2665,11 +2677,11 @@ Fri Jan 19 06:53:38 2007 Masaki Suketa <masaki.suketa@nifty.ne.jp> * ext/win32ole/win32ole.c (olevariant_free): fix memory leak. - * ext/win32ole/win32ole.c (ole_val2olevariantdata): - WIN32OLE_VARIANT.new accepts nil as first argument for some VARIANT + * ext/win32ole/win32ole.c (ole_val2olevariantdata): + WIN32OLE_VARIANT.new accepts nil as first argument for some VARIANT TYPE. - * test/win32ole/test_win32ole_variant.rb: ditto. + * test/win32ole/test_win32ole_variant.rb: ditto. Wed Jan 17 17:31:28 2007 Koichi Sasada <ko1@atdot.net> @@ -2681,7 +2693,7 @@ Wed Jan 17 17:31:28 2007 Koichi Sasada <ko1@atdot.net> * yarvcore.h, yarvcore.c: rename or remove some global variables removed: mYarvCore, mYarvInsns - renamed: cYarvISeq -> rb_cISeq, + renamed: cYarvISeq -> rb_cISeq, cYarvProc -> rb_cProc, cYarvBinding -> rb_cBinding ::YarvCore module is removed and ::YarvCore::VM class becomes ::VM. And change/remove some functions which added with YARV. @@ -2733,8 +2745,8 @@ Tue Jan 16 12:00:06 2007 Koichi Sasada <ko1@atdot.net> Sat Jan 13 23:24:59 2007 Masaki Suketa <masaki.suketa@nifty.ne.jp> - * ext/win32ole/win32ole.c (ole_free, ole_type_free, - olemethod_free, olevariable_free, oleparam_free, + * ext/win32ole/win32ole.c (ole_free, ole_type_free, + olemethod_free, olevariable_free, oleparam_free, ole_event_free): fix memory leak. [ruby-core:09846] Wed Jan 10 00:10:23 2007 Nobuyoshi Nakada <nobu@ruby-lang.org> @@ -2783,7 +2795,7 @@ Sun Jan 7 17:47:16 2007 Masaki Suketa <masaki.suketa@nifty.ne.jp> * ext/win32ole/win32ole.c: update comment for rdoc of WIN32OLE#[] and WIN32OLE#[]=. -Sun Jan 7 12:13:26 2007 Eric Hodel <drbrain@segment7.net> +Sun Jan 7 12:13:26 2007 Eric Hodel <drbrain@segment7.net> * lib/rdoc/parsers/parse_c.rb (RDoc::C_Parser#find_class_comment): Look for class and module comments above rb_define_class and @@ -2843,7 +2855,7 @@ Sat Jan 6 09:10:52 2007 Koichi Sasada <ko1@atdot.net> Sat Jan 6 08:29:17 2007 Masaki Suketa <masaki.suketa@nifty.ne.jp> - * ext/win32ole/win32ole.c (Init_win32ole): add + * ext/win32ole/win32ole.c (Init_win32ole): add WIN32OLE::VARIANT::VT_EMPTY, WIN32OLE::VARIANT::VT_NULL * test/win32ole/test_win32ole_variant_m.rb (test_variant): ditto. @@ -2916,7 +2928,7 @@ Fri Jan 5 13:59:53 2007 Koichi Sasada <ko1@atdot.net> Fri Jan 5 12:03:07 2007 Koichi Sasada <ko1@atdot.net> - * compile.c (iseq_compile_each, set_block_local_tbl): + * compile.c (iseq_compile_each, set_block_local_tbl): support NODE_LAMBDA (partly). * sample/test.rb: restore test of NODE_LAMBDA @@ -2961,7 +2973,7 @@ Thu Jan 4 16:57:14 2007 Koichi Sasada <ko1@atdot.net> Thu Jan 4 17:00:06 2007 GOTOU Yuuzou <gotoyuzo@notwork.org> * ext/openssl/ossl_asn1.c (Init_ossl_asn1): - OpenSSL::ASN1::ASN1Data#value,#tag,#tag_class and + OpenSSL::ASN1::ASN1Data#value,#tag,#tag_class and OpenSSL::ASN1::BitString#unused_bits should be public. Thu Jan 04 13:45:10 2007 Koichi Sasada <ko1@atdot.net> @@ -3093,7 +3105,7 @@ Wed Dec 27 10:04:11 2006 Yukihiro Matsumoto <matz@ruby-lang.org> Tue Dec 26 21:02:14 2006 Masaki Suketa <masaki.suketa@nifty.ne.jp> - * test/win32ole/test_folderitem2_invokeverb.rb: The argument + * test/win32ole/test_folderitem2_invokeverb.rb: The argument of Shell.NameSpace should not be file path. Tue Dec 26 06:13:08 2006 Minero Aoki <aamine@loveruby.net> diff --git a/call_cfunc.ci b/call_cfunc.ci index 8f4525ca4a..8a94f3f206 100644 --- a/call_cfunc.ci +++ b/call_cfunc.ci @@ -17,76 +17,76 @@ call_cfunc(func, recv, len, argc, argv) } switch (len) { - case -2: + case -2: return (*func) (recv, rb_ary_new4(argc, argv)); break; - case -1: + case -1: return (*func) (argc, argv, recv); break; - case 0: + case 0: return (*func) (recv); break; - case 1: + case 1: return (*func) (recv, argv[0]); break; - case 2: + case 2: return (*func) (recv, argv[0], argv[1]); break; - case 3: + case 3: return (*func) (recv, argv[0], argv[1], argv[2]); break; - case 4: + case 4: return (*func) (recv, argv[0], argv[1], argv[2], argv[3]); break; - case 5: + case 5: return (*func) (recv, argv[0], argv[1], argv[2], argv[3], argv[4]); break; - case 6: + case 6: return (*func) (recv, argv[0], argv[1], argv[2], argv[3], argv[4], argv[5]); break; - case 7: + case 7: return (*func) (recv, argv[0], argv[1], argv[2], argv[3], argv[4], argv[5], argv[6]); break; - case 8: + case 8: return (*func) (recv, argv[0], argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7]); break; - case 9: + case 9: return (*func) (recv, argv[0], argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], argv[8]); break; - case 10: + case 10: return (*func) (recv, argv[0], argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], argv[8], argv[9]); break; - case 11: + case 11: return (*func) (recv, argv[0], argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], argv[8], argv[9], argv[10]); break; - case 12: + case 12: return (*func) (recv, argv[0], argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], argv[8], argv[9], argv[10], argv[11]); break; - case 13: + case 13: return (*func) (recv, argv[0], argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], argv[8], argv[9], argv[10], argv[11], argv[12]); break; - case 14: + case 14: return (*func) (recv, argv[0], argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], argv[8], argv[9], argv[10], argv[11], argv[12], argv[13]); break; - case 15: + case 15: return (*func) (recv, argv[0], argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], argv[8], argv[9], argv[10], argv[11], argv[12], argv[13], argv[14]); break; - default: + default: rb_raise(rb_eArgError, "too many arguments(%d)", len); break; } @@ -399,7 +399,7 @@ FIRST_ELEMENT(LINK_ANCHOR *anchor) return anchor->anchor.next; } -/* +/* static LINK_ELEMENT * LAST_ELEMENT(LINK_ANCHOR *anchor) { @@ -510,7 +510,7 @@ SWAP_LIST(LINK_ANCHOR *anc1, LINK_ANCHOR *anc2) /* it has bug */ *anc2 = *anc1; *anc1 = tmp; - + verify_list("swap1", anc1); verify_list("swap2", anc2); } @@ -1028,24 +1028,27 @@ set_sequence(rb_iseq_t *iseq, LINK_ANCHOR *anchor) k = pos = 0; while (list) { switch (list->type) { - case ISEQ_ELEMENT_INSN:{ + case ISEQ_ELEMENT_INSN: + { iobj = (INSN *)list; pos += insn_data_length(iobj); k += 1; break; } - case ISEQ_ELEMENT_LABEL:{ + case ISEQ_ELEMENT_LABEL: + { lobj = (LABEL *)list; lobj->position = pos; lobj->set = Qtrue; break; } - case ISEQ_ELEMENT_NONE:{ + case ISEQ_ELEMENT_NONE: + { /* ignore */ break; } - default: + default: dump_disasm_list(FIRST_ELEMENT(anchor)); dump_disasm_list(list); rb_bug("error: set_sequence"); @@ -1065,7 +1068,8 @@ set_sequence(rb_iseq_t *iseq, LINK_ANCHOR *anchor) while (list) { switch (list->type) { - case ISEQ_ELEMENT_INSN:{ + case ISEQ_ELEMENT_INSN: + { int j, len, insn; char *types; VALUE *operands; @@ -1191,7 +1195,8 @@ set_sequence(rb_iseq_t *iseq, LINK_ANCHOR *anchor) k++; break; } - case ISEQ_ELEMENT_LABEL:{ + case ISEQ_ELEMENT_LABEL: + { lobj = (LABEL *)list; if (lobj->sp == -1) { lobj->sp = sp; @@ -1201,7 +1206,7 @@ set_sequence(rb_iseq_t *iseq, LINK_ANCHOR *anchor) } break; } - default: + default: /* ignore */ break; } @@ -1546,7 +1551,7 @@ iseq_optimize(rb_iseq_t *iseq, LINK_ANCHOR *anchor) const int do_si = iseq->compile_data->option->specialized_instruction; const int do_ou = iseq->compile_data->option->operands_unification; list = FIRST_ELEMENT(anchor); - + while (list) { if (list->type == ISEQ_ELEMENT_INSN) { if (do_peepholeopt) { @@ -1733,14 +1738,16 @@ set_sequence_stackcaching(rb_iseq_t *iseq, LINK_ANCHOR *anchor) while (list) { redo_point: switch (list->type) { - case ISEQ_ELEMENT_INSN:{ + case ISEQ_ELEMENT_INSN: + { INSN *iobj = (INSN *)list; insn_id = iobj->insn_id; /* dump_disasm_list(list); */ switch (insn_id) { - case BIN(nop):{ + case BIN(nop): + { /* exception merge point */ if (state != SCS_AX) { INSN *rpobj = @@ -1753,7 +1760,8 @@ set_sequence_stackcaching(rb_iseq_t *iseq, LINK_ANCHOR *anchor) } break; } - case BIN(swap):{ + case BIN(swap): + { if (state == SCS_AB || state == SCS_BA) { state = (state == SCS_AB ? SCS_BA : SCS_AB); @@ -1763,21 +1771,22 @@ set_sequence_stackcaching(rb_iseq_t *iseq, LINK_ANCHOR *anchor) } break; } - case BIN(pop):{ + case BIN(pop): + { switch (state) { - case SCS_AX: - case SCS_BX: + case SCS_AX: + case SCS_BX: state = SCS_XX; break; - case SCS_AB: + case SCS_AB: state = SCS_AX; break; - case SCS_BA: + case SCS_BA: state = SCS_BX; break; - case SCS_XX: + case SCS_XX: goto normal_insn; - default: + default: rb_bug("unreachable"); } /* remove useless pop */ @@ -1785,20 +1794,21 @@ set_sequence_stackcaching(rb_iseq_t *iseq, LINK_ANCHOR *anchor) list = list->next; goto redo_point; } - default:; + default:; /* none */ } /* end of switch */ normal_insn: state = insn_set_sc_state(iobj, state); break; } - case ISEQ_ELEMENT_LABEL:{ + case ISEQ_ELEMENT_LABEL: + { LABEL *lobj; lobj = (LABEL *)list; state = label_set_sc_state(lobj, state); } - default: + default: break; } list = list->next; @@ -1815,7 +1825,7 @@ compile_dstr(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node) NODE *list = node->nd_next; VALUE lit = node->nd_lit; int cnt = 1; - + debugp_param("nd_lit", lit); ADD_INSN1(ret, nd_line(node), putobject, node->nd_lit); @@ -1834,12 +1844,13 @@ compile_branch_condition(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * cond, LABEL *then_label, LABEL *else_label) { switch (nd_type(cond)) { - case NODE_NOT: + case NODE_NOT: compile_branch_condition(iseq, ret, cond->nd_body, else_label, then_label); break; - case NODE_AND:{ + case NODE_AND: + { LABEL *label = NEW_LABEL(nd_line(cond)); compile_branch_condition(iseq, ret, cond->nd_1st, label, else_label); @@ -1848,7 +1859,8 @@ compile_branch_condition(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * cond, else_label); break; } - case NODE_OR:{ + case NODE_OR: + { LABEL *label = NEW_LABEL(nd_line(cond)); compile_branch_condition(iseq, ret, cond->nd_1st, then_label, label); @@ -1857,18 +1869,18 @@ compile_branch_condition(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * cond, else_label); break; } - case NODE_LIT: /* NODE_LIT is always not true */ - case NODE_TRUE: - case NODE_STR: + case NODE_LIT: /* NODE_LIT is always not true */ + case NODE_TRUE: + case NODE_STR: /* printf("useless conditon eliminate (%s)\n", ruby_node_name(nd_type(cond))); */ ADD_INSNL(ret, nd_line(cond), jump, then_label); break; - case NODE_FALSE: - case NODE_NIL: + case NODE_FALSE: + case NODE_NIL: /* printf("useless conditon eliminate (%s)\n", ruby_node_name(nd_type(cond))); */ ADD_INSNL(ret, nd_line(cond), jump, else_label); break; - default: + default: COMPILE(ret, "branch condition", cond); ADD_INSNL(ret, nd_line(cond), branchunless, else_label); ADD_INSNL(ret, nd_line(cond), jump, then_label); @@ -1970,7 +1982,7 @@ make_masgn_lhs(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node) { switch (nd_type(node)) { - case NODE_ATTRASGN:{ + case NODE_ATTRASGN:{ INSN *iobj; VALUE dupidx; @@ -1987,13 +1999,14 @@ make_masgn_lhs(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node) ADD_INSN(ret, nd_line(node), pop); /* result */ ADD_INSN(ret, nd_line(node), pop); /* rhs */ break; - } + } - case NODE_MASGN: + case NODE_MASGN: COMPILE_POPED(ret, "nest masgn lhs", node); break; - default:{ + default: + { DECL_ANCHOR(anchor); COMPILE_POPED(anchor, "masgn lhs", node); /* dump_disasm_list(FIRST_ELEMENT(anchor)); */ @@ -2064,24 +2077,24 @@ compile_massign(rb_iseq_t *iseq, LINK_ANCHOR *ret, } break; } - case NODE_TO_ARY: + case NODE_TO_ARY: COMPILE(ret, "rhs to ary", rhsn->nd_head); ADD_INSN2(ret, nd_line(rhsn), expandarray, INT2FIX(llen), INT2FIX(lhs_splat)); break; - case NODE_SPLAT: + case NODE_SPLAT: COMPILE(ret, "rhs to ary (splat)", rhsn->nd_head); ADD_INSN2(ret, nd_line(rhsn), expandarray, INT2FIX(llen), INT2FIX(lhs_splat)); break; - case NODE_ARGSCAT: + case NODE_ARGSCAT: COMPILE(ret, "rhs to argscat", rhsn); ADD_INSN2(ret, nd_line(rhsn), expandarray, INT2FIX(llen), INT2FIX(lhs_splat)); break; - default: + default: COMPILE(ret, "rhs to ary (splat/default)", rhsn); ADD_INSN2(ret, nd_line(rhsn), expandarray, INT2FIX(llen), INT2FIX(lhs_splat)); @@ -2482,49 +2495,49 @@ setup_arg(rb_iseq_t *iseq, LINK_ANCHOR *args, NODE *node, VALUE *flag) if (argn) { switch (nd_type(argn)) { case NODE_SPLAT: { - COMPILE(args, "args (splat)", argn->nd_head); - argc = INT2FIX(1); - *flag |= VM_CALL_ARGS_SPLAT_BIT; - break; + COMPILE(args, "args (splat)", argn->nd_head); + argc = INT2FIX(1); + *flag |= VM_CALL_ARGS_SPLAT_BIT; + break; } case NODE_ARGSCAT: case NODE_ARGSPUSH: { - int next_is_array = (nd_type(argn->nd_head) == NODE_ARRAY); - DECL_ANCHOR(tmp); + int next_is_array = (nd_type(argn->nd_head) == NODE_ARRAY); + DECL_ANCHOR(tmp); - COMPILE(tmp, "args (cat: splat)", argn->nd_body); - if (next_is_array && nsplat == 0) { - /* none */ - } - else { - if (nd_type(argn) == NODE_ARGSCAT) { - ADD_INSN1(tmp, nd_line(argn), splatarray, Qfalse); - } - else { - ADD_INSN1(tmp, nd_line(argn), newarray, INT2FIX(1)); - } - } - INSERT_LIST(args_splat, tmp); - nsplat++; - *flag |= VM_CALL_ARGS_SPLAT_BIT; + COMPILE(tmp, "args (cat: splat)", argn->nd_body); + if (next_is_array && nsplat == 0) { + /* none */ + } + else { + if (nd_type(argn) == NODE_ARGSCAT) { + ADD_INSN1(tmp, nd_line(argn), splatarray, Qfalse); + } + else { + ADD_INSN1(tmp, nd_line(argn), newarray, INT2FIX(1)); + } + } + INSERT_LIST(args_splat, tmp); + nsplat++; + *flag |= VM_CALL_ARGS_SPLAT_BIT; - if (next_is_array) { - argc = INT2FIX(compile_array(iseq, args, argn->nd_head, Qfalse) + 1); - POP_ELEMENT(args); - } - else { - argn = argn->nd_head; - goto setup_argn; - } - break; + if (next_is_array) { + argc = INT2FIX(compile_array(iseq, args, argn->nd_head, Qfalse) + 1); + POP_ELEMENT(args); + } + else { + argn = argn->nd_head; + goto setup_argn; + } + break; } case NODE_ARRAY: { - argc = INT2FIX(compile_array(iseq, args, argn, Qfalse)); - POP_ELEMENT(args); - break; + argc = INT2FIX(compile_array(iseq, args, argn, Qfalse)); + POP_ELEMENT(args); + break; } default: { - rb_bug("setup_arg: unknown node: %s\n", ruby_node_name(nd_type(node))); + rb_bug("setup_arg: unknown node: %s\n", ruby_node_name(nd_type(node))); } } } @@ -2545,7 +2558,7 @@ setup_arg(rb_iseq_t *iseq, LINK_ANCHOR *args, NODE *node, VALUE *flag) } return argc; } - + /** compile each node @@ -2583,1876 +2596,1876 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped) switch (type) { case NODE_METHOD:{ - /* OK */ - bp(); - COMPILE_ERROR(("BUG: unknown node: NODE_METHOD")); - break; + /* OK */ + bp(); + COMPILE_ERROR(("BUG: unknown node: NODE_METHOD")); + break; } case NODE_FBODY:{ - /* OK */ - COMPILE_ERROR(("BUG: unknown node: NODE_FBODY")); - break; + /* OK */ + COMPILE_ERROR(("BUG: unknown node: NODE_FBODY")); + break; } case NODE_CFUNC:{ - /* OK */ - COMPILE_ERROR(("BUG: unknown node: NODE_CFUNC")); - break; + /* OK */ + COMPILE_ERROR(("BUG: unknown node: NODE_CFUNC")); + break; } case NODE_SCOPE:{ - /* OK */ - COMPILE_ERROR(("BUG: shouldn't reach: NODE_SCOPE")); - break; + /* OK */ + COMPILE_ERROR(("BUG: shouldn't reach: NODE_SCOPE")); + break; } case NODE_BLOCK:{ - while (node && nd_type(node) == NODE_BLOCK) { - COMPILE_(ret, "BLOCK body", node->nd_head, - (node->nd_next == 0 && poped == 0) ? 0 : 1); - node = node->nd_next; - } - if (node) { - COMPILE_(ret, "BLOCK next", node->nd_next, poped); - } - break; + while (node && nd_type(node) == NODE_BLOCK) { + COMPILE_(ret, "BLOCK body", node->nd_head, + (node->nd_next == 0 && poped == 0) ? 0 : 1); + node = node->nd_next; + } + if (node) { + COMPILE_(ret, "BLOCK next", node->nd_next, poped); + } + break; } case NODE_IF:{ - DECL_ANCHOR(cond_seq); - DECL_ANCHOR(then_seq); - DECL_ANCHOR(else_seq); - LABEL *then_label, *else_label, *end_label; + DECL_ANCHOR(cond_seq); + DECL_ANCHOR(then_seq); + DECL_ANCHOR(else_seq); + LABEL *then_label, *else_label, *end_label; - then_label = NEW_LABEL(nd_line(node)); - else_label = NEW_LABEL(nd_line(node)); - end_label = NEW_LABEL(nd_line(node)); + then_label = NEW_LABEL(nd_line(node)); + else_label = NEW_LABEL(nd_line(node)); + end_label = NEW_LABEL(nd_line(node)); - compile_branch_condition(iseq, cond_seq, node->nd_cond, - then_label, else_label); - COMPILE_(then_seq, "then", node->nd_body, poped); - COMPILE_(else_seq, "else", node->nd_else, poped); + compile_branch_condition(iseq, cond_seq, node->nd_cond, + then_label, else_label); + COMPILE_(then_seq, "then", node->nd_body, poped); + COMPILE_(else_seq, "else", node->nd_else, poped); - ADD_SEQ(ret, cond_seq); + ADD_SEQ(ret, cond_seq); - ADD_LABEL(ret, then_label); - ADD_SEQ(ret, then_seq); - ADD_INSNL(ret, nd_line(node), jump, end_label); + ADD_LABEL(ret, then_label); + ADD_SEQ(ret, then_seq); + ADD_INSNL(ret, nd_line(node), jump, end_label); - ADD_LABEL(ret, else_label); - ADD_SEQ(ret, else_seq); + ADD_LABEL(ret, else_label); + ADD_SEQ(ret, else_seq); - ADD_LABEL(ret, end_label); + ADD_LABEL(ret, end_label); - break; + break; } case NODE_CASE:{ - NODE *vals; - NODE *tempnode = node; - LABEL *endlabel, *elselabel; - DECL_ANCHOR(head); - DECL_ANCHOR(body_seq); - DECL_ANCHOR(cond_seq); - VALUE special_literals = rb_ary_new(); - - if (node->nd_head == 0) { - COMPILE_(ret, "when", node->nd_body, poped); - break; - } - COMPILE(head, "case base", node->nd_head); + NODE *vals; + NODE *tempnode = node; + LABEL *endlabel, *elselabel; + DECL_ANCHOR(head); + DECL_ANCHOR(body_seq); + DECL_ANCHOR(cond_seq); + VALUE special_literals = rb_ary_new(); + + if (node->nd_head == 0) { + COMPILE_(ret, "when", node->nd_body, poped); + break; + } + COMPILE(head, "case base", node->nd_head); - node = node->nd_body; - type = nd_type(node); + node = node->nd_body; + type = nd_type(node); - if (type != NODE_WHEN) { - COMPILE_ERROR(("NODE_CASE: unexpected node. must be NODE_WHEN, but %s", ruby_node_name(type))); - } + if (type != NODE_WHEN) { + COMPILE_ERROR(("NODE_CASE: unexpected node. must be NODE_WHEN, but %s", ruby_node_name(type))); + } - endlabel = NEW_LABEL(nd_line(node)); - elselabel = NEW_LABEL(nd_line(node)); + endlabel = NEW_LABEL(nd_line(node)); + elselabel = NEW_LABEL(nd_line(node)); - ADD_SEQ(ret, head); /* case VAL */ + ADD_SEQ(ret, head); /* case VAL */ - while (type == NODE_WHEN) { - LABEL *l1; + while (type == NODE_WHEN) { + LABEL *l1; - l1 = NEW_LABEL(nd_line(node)); - ADD_LABEL(body_seq, l1); - ADD_INSN(body_seq, nd_line(node), pop); - COMPILE_(body_seq, "when body", node->nd_body, poped); - ADD_INSNL(body_seq, nd_line(node), jump, endlabel); + l1 = NEW_LABEL(nd_line(node)); + ADD_LABEL(body_seq, l1); + ADD_INSN(body_seq, nd_line(node), pop); + COMPILE_(body_seq, "when body", node->nd_body, poped); + ADD_INSNL(body_seq, nd_line(node), jump, endlabel); - vals = node->nd_head; - if (vals) { - if (nd_type(vals) == NODE_ARRAY) { - special_literals = when_vals(iseq, cond_seq, vals, l1, special_literals); - } - else if (nd_type(vals) == NODE_SPLAT || nd_type(vals) == NODE_ARGSCAT) { - NODE *val = vals->nd_head; - special_literals = 0; + vals = node->nd_head; + if (vals) { + if (nd_type(vals) == NODE_ARRAY) { + special_literals = when_vals(iseq, cond_seq, vals, l1, special_literals); + } + else if (nd_type(vals) == NODE_SPLAT || nd_type(vals) == NODE_ARGSCAT) { + NODE *val = vals->nd_head; + special_literals = 0; - if (nd_type(vals) == NODE_ARGSCAT) { - when_vals(iseq, cond_seq, vals->nd_head, l1, 0); - val = vals->nd_body; - } + if (nd_type(vals) == NODE_ARGSCAT) { + when_vals(iseq, cond_seq, vals->nd_head, l1, 0); + val = vals->nd_body; + } - COMPILE(cond_seq, "when/cond splat", val); - ADD_INSN1(cond_seq, nd_line(val), checkincludearray, Qtrue); - ADD_INSNL(cond_seq, nd_line(val), branchif, l1); - } - else { - rb_bug("NODE_CASAE: unknown node (%s)", ruby_node_name(nd_type(vals))); - } - } - else { - rb_bug("NODE_CASAE: must be NODE_ARRAY, but 0\n"); - } + COMPILE(cond_seq, "when/cond splat", val); + ADD_INSN1(cond_seq, nd_line(val), checkincludearray, Qtrue); + ADD_INSNL(cond_seq, nd_line(val), branchif, l1); + } + else { + rb_bug("NODE_CASAE: unknown node (%s)", ruby_node_name(nd_type(vals))); + } + } + else { + rb_bug("NODE_CASAE: must be NODE_ARRAY, but 0\n"); + } - node = node->nd_next; - if (!node) { - break; - } - type = nd_type(node); - } - /* else */ - if (node) { - ADD_LABEL(cond_seq, elselabel); - ADD_INSN(cond_seq, nd_line(node), pop); - COMPILE_(cond_seq, "else", node, poped); - ADD_INSNL(cond_seq, nd_line(node), jump, endlabel); - } - else { - debugs("== else (implicit)\n"); - ADD_LABEL(cond_seq, elselabel); - ADD_INSN(cond_seq, nd_line(tempnode), pop); - if (!poped) { - ADD_INSN(cond_seq, nd_line(tempnode), putnil); - } - ADD_INSNL(cond_seq, nd_line(tempnode), jump, endlabel); - } + node = node->nd_next; + if (!node) { + break; + } + type = nd_type(node); + } + /* else */ + if (node) { + ADD_LABEL(cond_seq, elselabel); + ADD_INSN(cond_seq, nd_line(node), pop); + COMPILE_(cond_seq, "else", node, poped); + ADD_INSNL(cond_seq, nd_line(node), jump, endlabel); + } + else { + debugs("== else (implicit)\n"); + ADD_LABEL(cond_seq, elselabel); + ADD_INSN(cond_seq, nd_line(tempnode), pop); + if (!poped) { + ADD_INSN(cond_seq, nd_line(tempnode), putnil); + } + ADD_INSNL(cond_seq, nd_line(tempnode), jump, endlabel); + } - if (special_literals) { - ADD_INSN(ret, nd_line(tempnode), dup); - ADD_INSN2(ret, nd_line(tempnode), opt_case_dispatch, - special_literals, elselabel); - iseq_add_mark_object_compile_time(iseq, special_literals); - } + if (special_literals) { + ADD_INSN(ret, nd_line(tempnode), dup); + ADD_INSN2(ret, nd_line(tempnode), opt_case_dispatch, + special_literals, elselabel); + iseq_add_mark_object_compile_time(iseq, special_literals); + } - ADD_SEQ(ret, cond_seq); - ADD_SEQ(ret, body_seq); - ADD_LABEL(ret, endlabel); - break; + ADD_SEQ(ret, cond_seq); + ADD_SEQ(ret, body_seq); + ADD_LABEL(ret, endlabel); + break; } case NODE_WHEN:{ - NODE *vals; - NODE *val; - NODE *orig_node = node; - LABEL *endlabel; - DECL_ANCHOR(body_seq); - - endlabel = NEW_LABEL(nd_line(node)); - - while (node && nd_type(node) == NODE_WHEN) { - LABEL *l1 = NEW_LABEL(nd_line(node)); - ADD_LABEL(body_seq, l1); - COMPILE_(body_seq, "when", node->nd_body, poped); - ADD_INSNL(body_seq, nd_line(node), jump, endlabel); - - vals = node->nd_head; - if (vals && nd_type(vals) == NODE_ARRAY) { - while (vals) { - val = vals->nd_head; - COMPILE(ret, "when2", val); - ADD_INSNL(ret, nd_line(val), branchif, l1); - vals = vals->nd_next; - } - } - else if (nd_type(vals) == NODE_SPLAT || nd_type(vals) == NODE_ARGSCAT) { - NODE *val = vals->nd_head; - - if (nd_type(vals) == NODE_ARGSCAT) { - NODE *vs = vals->nd_head; - val = vals->nd_body; - - while (vs) { - NODE* val = vs->nd_head; - COMPILE(ret, "when/argscat", val); - ADD_INSNL(ret, nd_line(val), branchif, l1); - vs = vs->nd_next; - } - } + NODE *vals; + NODE *val; + NODE *orig_node = node; + LABEL *endlabel; + DECL_ANCHOR(body_seq); + + endlabel = NEW_LABEL(nd_line(node)); + + while (node && nd_type(node) == NODE_WHEN) { + LABEL *l1 = NEW_LABEL(nd_line(node)); + ADD_LABEL(body_seq, l1); + COMPILE_(body_seq, "when", node->nd_body, poped); + ADD_INSNL(body_seq, nd_line(node), jump, endlabel); + + vals = node->nd_head; + if (vals && nd_type(vals) == NODE_ARRAY) { + while (vals) { + val = vals->nd_head; + COMPILE(ret, "when2", val); + ADD_INSNL(ret, nd_line(val), branchif, l1); + vals = vals->nd_next; + } + } + else if (nd_type(vals) == NODE_SPLAT || nd_type(vals) == NODE_ARGSCAT) { + NODE *val = vals->nd_head; + + if (nd_type(vals) == NODE_ARGSCAT) { + NODE *vs = vals->nd_head; + val = vals->nd_body; + + while (vs) { + NODE* val = vs->nd_head; + COMPILE(ret, "when/argscat", val); + ADD_INSNL(ret, nd_line(val), branchif, l1); + vs = vs->nd_next; + } + } - ADD_INSN(ret, nd_line(val), putnil); - COMPILE(ret, "when2/splat", val); - ADD_INSN1(ret, nd_line(val), checkincludearray, Qfalse); - ADD_INSN(ret, nd_line(val), pop); - ADD_INSNL(ret, nd_line(val), branchif, l1); - } - else { - rb_bug("err"); - } - node = node->nd_next; - } - /* else */ - COMPILE_(ret, "else", node, poped); - ADD_INSNL(ret, nd_line(orig_node), jump, endlabel); + ADD_INSN(ret, nd_line(val), putnil); + COMPILE(ret, "when2/splat", val); + ADD_INSN1(ret, nd_line(val), checkincludearray, Qfalse); + ADD_INSN(ret, nd_line(val), pop); + ADD_INSNL(ret, nd_line(val), branchif, l1); + } + else { + rb_bug("err"); + } + node = node->nd_next; + } + /* else */ + COMPILE_(ret, "else", node, poped); + ADD_INSNL(ret, nd_line(orig_node), jump, endlabel); - ADD_SEQ(ret, body_seq); - ADD_LABEL(ret, endlabel); + ADD_SEQ(ret, body_seq); + ADD_LABEL(ret, endlabel); - break; + break; } case NODE_OPT_N: case NODE_WHILE: case NODE_UNTIL:{ - LABEL *prev_start_label = iseq->compile_data->start_label; - LABEL *prev_end_label = iseq->compile_data->end_label; - LABEL *prev_redo_label = iseq->compile_data->redo_label; - VALUE prev_loopval_popped = iseq->compile_data->loopval_popped; + LABEL *prev_start_label = iseq->compile_data->start_label; + LABEL *prev_end_label = iseq->compile_data->end_label; + LABEL *prev_redo_label = iseq->compile_data->redo_label; + VALUE prev_loopval_popped = iseq->compile_data->loopval_popped; - struct iseq_compile_data_ensure_node_stack *enlp = + struct iseq_compile_data_ensure_node_stack *enlp = iseq->compile_data->ensure_node_stack; - LABEL *next_label = iseq->compile_data->start_label = NEW_LABEL(nd_line(node)); /* next */ - LABEL *redo_label = iseq->compile_data->redo_label = NEW_LABEL(nd_line(node)); /* redo */ - LABEL *break_label = iseq->compile_data->end_label = NEW_LABEL(nd_line(node)); /* break */ - LABEL *end_label = NEW_LABEL(nd_line(node)); + LABEL *next_label = iseq->compile_data->start_label = NEW_LABEL(nd_line(node)); /* next */ + LABEL *redo_label = iseq->compile_data->redo_label = NEW_LABEL(nd_line(node)); /* redo */ + LABEL *break_label = iseq->compile_data->end_label = NEW_LABEL(nd_line(node)); /* break */ + LABEL *end_label = NEW_LABEL(nd_line(node)); - iseq->compile_data->loopval_popped = 0; - iseq->compile_data->ensure_node_stack = 0; + iseq->compile_data->loopval_popped = 0; + iseq->compile_data->ensure_node_stack = 0; - if (type == NODE_OPT_N || node->nd_state == 1) { - ADD_INSNL(ret, nd_line(node), jump, next_label); - } + if (type == NODE_OPT_N || node->nd_state == 1) { + ADD_INSNL(ret, nd_line(node), jump, next_label); + } - ADD_LABEL(ret, redo_label); - COMPILE_POPED(ret, "while body", node->nd_body); - ADD_LABEL(ret, next_label); /* next */ + ADD_LABEL(ret, redo_label); + COMPILE_POPED(ret, "while body", node->nd_body); + ADD_LABEL(ret, next_label); /* next */ - if (type == NODE_WHILE) { - compile_branch_condition(iseq, ret, node->nd_cond, - redo_label, end_label); - } - else if (type == NODE_UNTIL) { - /* untile */ - compile_branch_condition(iseq, ret, node->nd_cond, - end_label, redo_label); - } - else { - ADD_CALL_RECEIVER(ret, nd_line(node)); - ADD_CALL(ret, nd_line(node), ID2SYM(idGets), INT2FIX(0)); - ADD_INSNL(ret, nd_line(node), branchif, redo_label); - /* opt_n */ - } + if (type == NODE_WHILE) { + compile_branch_condition(iseq, ret, node->nd_cond, + redo_label, end_label); + } + else if (type == NODE_UNTIL) { + /* untile */ + compile_branch_condition(iseq, ret, node->nd_cond, + end_label, redo_label); + } + else { + ADD_CALL_RECEIVER(ret, nd_line(node)); + ADD_CALL(ret, nd_line(node), ID2SYM(idGets), INT2FIX(0)); + ADD_INSNL(ret, nd_line(node), branchif, redo_label); + /* opt_n */ + } - ADD_LABEL(ret, end_label); + ADD_LABEL(ret, end_label); - if (node->nd_state == Qundef) { - ADD_INSN(ret, nd_line(node), putundef); - } - else { - ADD_INSN(ret, nd_line(node), putnil); - } + if (node->nd_state == Qundef) { + ADD_INSN(ret, nd_line(node), putundef); + } + else { + ADD_INSN(ret, nd_line(node), putnil); + } - ADD_LABEL(ret, break_label); /* braek */ + ADD_LABEL(ret, break_label); /* braek */ - if (poped) { - ADD_INSN(ret, nd_line(node), pop); - } + if (poped) { + ADD_INSN(ret, nd_line(node), pop); + } - ADD_CATCH_ENTRY(CATCH_TYPE_BREAK, redo_label, break_label, - 0, break_label); - ADD_CATCH_ENTRY(CATCH_TYPE_NEXT | 0x10000, redo_label, - break_label, 0, iseq->compile_data->start_label); - ADD_CATCH_ENTRY(CATCH_TYPE_REDO, redo_label, break_label, 0, - iseq->compile_data->redo_label); - - iseq->compile_data->start_label = prev_start_label; - iseq->compile_data->end_label = prev_end_label; - iseq->compile_data->redo_label = prev_redo_label; - iseq->compile_data->loopval_popped = prev_loopval_popped; - iseq->compile_data->ensure_node_stack = enlp; - break; + ADD_CATCH_ENTRY(CATCH_TYPE_BREAK, redo_label, break_label, + 0, break_label); + ADD_CATCH_ENTRY(CATCH_TYPE_NEXT | 0x10000, redo_label, + break_label, 0, iseq->compile_data->start_label); + ADD_CATCH_ENTRY(CATCH_TYPE_REDO, redo_label, break_label, 0, + iseq->compile_data->redo_label); + + iseq->compile_data->start_label = prev_start_label; + iseq->compile_data->end_label = prev_end_label; + iseq->compile_data->redo_label = prev_redo_label; + iseq->compile_data->loopval_popped = prev_loopval_popped; + iseq->compile_data->ensure_node_stack = enlp; + break; } case NODE_ITER: case NODE_FOR:{ - VALUE prevblock = iseq->compile_data->current_block; - LABEL *retry_label = NEW_LABEL(nd_line(node)); - LABEL *retry_end_l = NEW_LABEL(nd_line(node)); - ID mid = 0; + VALUE prevblock = iseq->compile_data->current_block; + LABEL *retry_label = NEW_LABEL(nd_line(node)); + LABEL *retry_end_l = NEW_LABEL(nd_line(node)); + ID mid = 0; - ADD_LABEL(ret, retry_label); - if (nd_type(node) == NODE_FOR) { - COMPILE(ret, "iter caller (for)", node->nd_iter); + ADD_LABEL(ret, retry_label); + if (nd_type(node) == NODE_FOR) { + COMPILE(ret, "iter caller (for)", node->nd_iter); - iseq->compile_data->current_block = + iseq->compile_data->current_block = NEW_CHILD_ISEQVAL(node->nd_body, make_name_for_block(iseq), ISEQ_TYPE_BLOCK); - mid = idEach; - ADD_SEND_R(ret, nd_line(node), ID2SYM(idEach), INT2FIX(0), - iseq->compile_data->current_block, INT2FIX(0)); - if (poped) { - ADD_INSN(ret, nd_line(node), pop); - } - } - else { - iseq->compile_data->current_block = + mid = idEach; + ADD_SEND_R(ret, nd_line(node), ID2SYM(idEach), INT2FIX(0), + iseq->compile_data->current_block, INT2FIX(0)); + if (poped) { + ADD_INSN(ret, nd_line(node), pop); + } + } + else { + iseq->compile_data->current_block = NEW_CHILD_ISEQVAL(node->nd_body, make_name_for_block(iseq), ISEQ_TYPE_BLOCK); - COMPILE_(ret, "iter caller", node->nd_iter, poped); - } - ADD_LABEL(ret, retry_end_l); - iseq->compile_data->current_block = prevblock; + COMPILE_(ret, "iter caller", node->nd_iter, poped); + } + ADD_LABEL(ret, retry_end_l); + iseq->compile_data->current_block = prevblock; - ADD_CATCH_ENTRY(CATCH_TYPE_RETRY, retry_label, retry_end_l, 0, - retry_label); - break; + ADD_CATCH_ENTRY(CATCH_TYPE_RETRY, retry_label, retry_end_l, 0, + retry_label); + break; } case NODE_BREAK:{ - unsigned long level = 0; - - if (iseq->compile_data->redo_label != 0) { - /* while/until */ - add_ensure_iseq(ret, iseq); - COMPILE_(ret, "break val (while/until)", node->nd_stts, - iseq->compile_data->loopval_popped); - ADD_INSNL(ret, nd_line(node), jump, - iseq->compile_data->end_label); - } - else if (iseq->type == ISEQ_TYPE_BLOCK) { - break_by_insn: - /* escape from block */ - COMPILE(ret, "break val (block)", node->nd_stts); - ADD_INSN1(ret, nd_line(node), throw, - INT2FIX(level | 0x02) /* TAG_BREAK */ ); - } - else if (iseq->type == ISEQ_TYPE_EVAL) { - COMPILE_ERROR(("Can't escape from eval with break")); - } - else { - rb_iseq_t *ip = iseq->parent_iseq; - while (ip) { - level++; - if (ip->compile_data->redo_label != 0) { - level = 0x8000; - if (ip->compile_data->loopval_popped == 0) { - /* need value */ - level |= 0x4000; - } - goto break_by_insn; - } - else if (ip->type == ISEQ_TYPE_BLOCK) { - level <<= 16; - goto break_by_insn; - } - ip = ip->parent_iseq; - } - COMPILE_ERROR(("Illegal break")); - } - break; + unsigned long level = 0; + + if (iseq->compile_data->redo_label != 0) { + /* while/until */ + add_ensure_iseq(ret, iseq); + COMPILE_(ret, "break val (while/until)", node->nd_stts, + iseq->compile_data->loopval_popped); + ADD_INSNL(ret, nd_line(node), jump, + iseq->compile_data->end_label); + } + else if (iseq->type == ISEQ_TYPE_BLOCK) { + break_by_insn: + /* escape from block */ + COMPILE(ret, "break val (block)", node->nd_stts); + ADD_INSN1(ret, nd_line(node), throw, + INT2FIX(level | 0x02) /* TAG_BREAK */ ); + } + else if (iseq->type == ISEQ_TYPE_EVAL) { + COMPILE_ERROR(("Can't escape from eval with break")); + } + else { + rb_iseq_t *ip = iseq->parent_iseq; + while (ip) { + level++; + if (ip->compile_data->redo_label != 0) { + level = 0x8000; + if (ip->compile_data->loopval_popped == 0) { + /* need value */ + level |= 0x4000; + } + goto break_by_insn; + } + else if (ip->type == ISEQ_TYPE_BLOCK) { + level <<= 16; + goto break_by_insn; + } + ip = ip->parent_iseq; + } + COMPILE_ERROR(("Illegal break")); + } + break; } case NODE_NEXT:{ - unsigned long level = 0; + unsigned long level = 0; - if (iseq->compile_data->redo_label != 0) { - add_ensure_iseq(ret, iseq); - ADD_INSNL(ret, nd_line(node), jump, - iseq->compile_data->start_label); - } - else if (iseq->compile_data->end_label) { - COMPILE(ret, "next val", node->nd_stts); - add_ensure_iseq(ret, iseq); - ADD_INSNL(ret, nd_line(node), jump, - iseq->compile_data->end_label); - } - else if (iseq->type == ISEQ_TYPE_EVAL) { - COMPILE_ERROR(("Can't escape from eval with next")); - } - else { - rb_iseq_t *ip = iseq->parent_iseq; - while (ip) { - level = 0x8000; - if (ip->type == ISEQ_TYPE_BLOCK) { - level |= 0x4000; - break; - } - else if (ip->compile_data->redo_label != 0) { - break; - } - ip = ip->parent_iseq; - } - if (ip != 0) { - COMPILE(ret, "next val", node->nd_stts); - add_ensure_iseq(ret, iseq); - ADD_INSN1(ret, nd_line(node), throw, - INT2FIX(level | 0x03) /* TAG_NEXT */ ); - } - else { - COMPILE_ERROR(("Illegal next")); - } - } - break; + if (iseq->compile_data->redo_label != 0) { + add_ensure_iseq(ret, iseq); + ADD_INSNL(ret, nd_line(node), jump, + iseq->compile_data->start_label); + } + else if (iseq->compile_data->end_label) { + COMPILE(ret, "next val", node->nd_stts); + add_ensure_iseq(ret, iseq); + ADD_INSNL(ret, nd_line(node), jump, + iseq->compile_data->end_label); + } + else if (iseq->type == ISEQ_TYPE_EVAL) { + COMPILE_ERROR(("Can't escape from eval with next")); + } + else { + rb_iseq_t *ip = iseq->parent_iseq; + while (ip) { + level = 0x8000; + if (ip->type == ISEQ_TYPE_BLOCK) { + level |= 0x4000; + break; + } + else if (ip->compile_data->redo_label != 0) { + break; + } + ip = ip->parent_iseq; + } + if (ip != 0) { + COMPILE(ret, "next val", node->nd_stts); + add_ensure_iseq(ret, iseq); + ADD_INSN1(ret, nd_line(node), throw, + INT2FIX(level | 0x03) /* TAG_NEXT */ ); + } + else { + COMPILE_ERROR(("Illegal next")); + } + } + break; } case NODE_REDO:{ - if (iseq->compile_data->redo_label) { - add_ensure_iseq(ret, iseq); - ADD_INSNL(ret, nd_line(node), jump, - iseq->compile_data->redo_label); - if (!poped) { /* for stack consistency */ - ADD_INSN(ret, nd_line(node), putnil); - } - } - else if (iseq->type == ISEQ_TYPE_EVAL) { - COMPILE_ERROR(("Can't escape from eval with redo")); - } - else if (iseq->compile_data->start_label) { - ADD_INSNL(ret, nd_line(node), jump, - iseq->compile_data->start_label); - if (!poped) { /* for stack consistency */ - ADD_INSN(ret, nd_line(node), putnil); - } - } - else { - rb_iseq_t *ip = iseq->parent_iseq; - unsigned long level = 0x8000 | 0x4000; - while (ip) { - if (ip->type == ISEQ_TYPE_BLOCK) { - break; - } - else if (ip->type == ISEQ_TYPE_EVAL) { - COMPILE_ERROR(("Can't escape from eval with redo")); - } - else if (ip->compile_data->redo_label != 0) { - break; - } - ip = ip->parent_iseq; - } - if (ip != 0) { - add_ensure_iseq(ret, iseq); - ADD_INSN1(ret, nd_line(node), throw, - INT2FIX(level | 0x05) /* TAG_REDO */ ); - } - else { - COMPILE_ERROR(("Illegal redo")); - } - } - break; + if (iseq->compile_data->redo_label) { + add_ensure_iseq(ret, iseq); + ADD_INSNL(ret, nd_line(node), jump, + iseq->compile_data->redo_label); + if (!poped) { /* for stack consistency */ + ADD_INSN(ret, nd_line(node), putnil); + } + } + else if (iseq->type == ISEQ_TYPE_EVAL) { + COMPILE_ERROR(("Can't escape from eval with redo")); + } + else if (iseq->compile_data->start_label) { + ADD_INSNL(ret, nd_line(node), jump, + iseq->compile_data->start_label); + if (!poped) { /* for stack consistency */ + ADD_INSN(ret, nd_line(node), putnil); + } + } + else { + rb_iseq_t *ip = iseq->parent_iseq; + unsigned long level = 0x8000 | 0x4000; + while (ip) { + if (ip->type == ISEQ_TYPE_BLOCK) { + break; + } + else if (ip->type == ISEQ_TYPE_EVAL) { + COMPILE_ERROR(("Can't escape from eval with redo")); + } + else if (ip->compile_data->redo_label != 0) { + break; + } + ip = ip->parent_iseq; + } + if (ip != 0) { + add_ensure_iseq(ret, iseq); + ADD_INSN1(ret, nd_line(node), throw, + INT2FIX(level | 0x05) /* TAG_REDO */ ); + } + else { + COMPILE_ERROR(("Illegal redo")); + } + } + break; } case NODE_RETRY:{ - if (iseq->type == ISEQ_TYPE_BLOCK || - iseq->type == ISEQ_TYPE_RESCUE) { - ADD_INSN(ret, nd_line(node), putnil); - ADD_INSN1(ret, nd_line(node), throw, - INT2FIX(0x04) /* TAG_RETRY */ ); - } - else { - COMPILE_ERROR(("Illegal retry")); - } - break; + if (iseq->type == ISEQ_TYPE_BLOCK || + iseq->type == ISEQ_TYPE_RESCUE) { + ADD_INSN(ret, nd_line(node), putnil); + ADD_INSN1(ret, nd_line(node), throw, + INT2FIX(0x04) /* TAG_RETRY */ ); + } + else { + COMPILE_ERROR(("Illegal retry")); + } + break; } case NODE_BEGIN:{ - COMPILE_(ret, "NODE_BEGIN", node->nd_body, poped); - break; + COMPILE_(ret, "NODE_BEGIN", node->nd_body, poped); + break; } case NODE_RESCUE:{ - LABEL *lstart = NEW_LABEL(nd_line(node)); - LABEL *lend = NEW_LABEL(nd_line(node)); - LABEL *lcont = NEW_LABEL(nd_line(node)); - VALUE rescue = NEW_CHILD_ISEQVAL(node->nd_resq, - rb_str_concat(rb_str_new2 - ("rescue in "), - iseq->name), - ISEQ_TYPE_RESCUE); - - ADD_LABEL(ret, lstart); - COMPILE(ret, "rescue head", node->nd_head); - ADD_LABEL(ret, lend); - if (node->nd_else) { - ADD_INSN(ret, nd_line(node), pop); - COMPILE(ret, "rescue else", node->nd_else); - } - ADD_INSN(ret, nd_line(node), nop); - ADD_LABEL(ret, lcont); + LABEL *lstart = NEW_LABEL(nd_line(node)); + LABEL *lend = NEW_LABEL(nd_line(node)); + LABEL *lcont = NEW_LABEL(nd_line(node)); + VALUE rescue = NEW_CHILD_ISEQVAL(node->nd_resq, + rb_str_concat(rb_str_new2 + ("rescue in "), + iseq->name), + ISEQ_TYPE_RESCUE); - if (poped) { - ADD_INSN(ret, nd_line(node), pop); - } + ADD_LABEL(ret, lstart); + COMPILE(ret, "rescue head", node->nd_head); + ADD_LABEL(ret, lend); + if (node->nd_else) { + ADD_INSN(ret, nd_line(node), pop); + COMPILE(ret, "rescue else", node->nd_else); + } + ADD_INSN(ret, nd_line(node), nop); + ADD_LABEL(ret, lcont); + + if (poped) { + ADD_INSN(ret, nd_line(node), pop); + } - /* resgister catch entry */ - ADD_CATCH_ENTRY(CATCH_TYPE_RESCUE, lstart, lend, rescue, lcont); - ADD_CATCH_ENTRY(CATCH_TYPE_RETRY, lend, lcont, 0, lstart); - break; + /* resgister catch entry */ + ADD_CATCH_ENTRY(CATCH_TYPE_RESCUE, lstart, lend, rescue, lcont); + ADD_CATCH_ENTRY(CATCH_TYPE_RETRY, lend, lcont, 0, lstart); + break; } case NODE_RESBODY:{ - NODE *resq = node; - NODE *narg; - LABEL *label_miss, *label_hit; - - while (resq) { - label_miss = NEW_LABEL(nd_line(node)); - label_hit = NEW_LABEL(nd_line(node)); - - narg = resq->nd_args; - while (narg) { - COMPILE(ret, "rescue arg", narg->nd_head); - ADD_INSN2(ret, nd_line(node), getdynamic, INT2FIX(1), - INT2FIX(0)); - ADD_SEND(ret, nd_line(node), ID2SYM(idEqq), INT2FIX(1)); - ADD_INSNL(ret, nd_line(node), branchif, label_hit); - narg = narg->nd_next; - } - if (resq->nd_args == 0) { - ADD_INSN1(ret, nd_line(node), putobject, - rb_eStandardError); - ADD_INSN2(ret, nd_line(node), getdynamic, INT2FIX(1), - INT2FIX(0)); - ADD_SEND(ret, nd_line(node), ID2SYM(idEqq), INT2FIX(1)); - ADD_INSNL(ret, nd_line(node), branchif, label_hit); - } - ADD_INSNL(ret, nd_line(node), jump, label_miss); - ADD_LABEL(ret, label_hit); - COMPILE(ret, "resbody body", resq->nd_body); - ADD_INSN(ret, nd_line(node), leave); - ADD_LABEL(ret, label_miss); - resq = resq->nd_head; - } - break; + NODE *resq = node; + NODE *narg; + LABEL *label_miss, *label_hit; + + while (resq) { + label_miss = NEW_LABEL(nd_line(node)); + label_hit = NEW_LABEL(nd_line(node)); + + narg = resq->nd_args; + while (narg) { + COMPILE(ret, "rescue arg", narg->nd_head); + ADD_INSN2(ret, nd_line(node), getdynamic, INT2FIX(1), + INT2FIX(0)); + ADD_SEND(ret, nd_line(node), ID2SYM(idEqq), INT2FIX(1)); + ADD_INSNL(ret, nd_line(node), branchif, label_hit); + narg = narg->nd_next; + } + if (resq->nd_args == 0) { + ADD_INSN1(ret, nd_line(node), putobject, + rb_eStandardError); + ADD_INSN2(ret, nd_line(node), getdynamic, INT2FIX(1), + INT2FIX(0)); + ADD_SEND(ret, nd_line(node), ID2SYM(idEqq), INT2FIX(1)); + ADD_INSNL(ret, nd_line(node), branchif, label_hit); + } + ADD_INSNL(ret, nd_line(node), jump, label_miss); + ADD_LABEL(ret, label_hit); + COMPILE(ret, "resbody body", resq->nd_body); + ADD_INSN(ret, nd_line(node), leave); + ADD_LABEL(ret, label_miss); + resq = resq->nd_head; + } + break; } case NODE_ENSURE:{ - DECL_ANCHOR(ensr); - VALUE ensure = NEW_CHILD_ISEQVAL(node->nd_ensr, - rb_str_concat(rb_str_new2 - ("ensure in "), - iseq->name), - ISEQ_TYPE_ENSURE); - LABEL *lstart = NEW_LABEL(nd_line(node)); - LABEL *lend = NEW_LABEL(nd_line(node)); - LABEL *lcont = NEW_LABEL(nd_line(node)); - struct ensure_range er = { lstart, lend, 0 }; - struct iseq_compile_data_ensure_node_stack enl = { - node->nd_ensr, - iseq->compile_data->ensure_node_stack, /* prev */ - &er, - }; - struct ensure_range *erange; - - COMPILE_POPED(ensr, "ensure ensr", node->nd_ensr); - - iseq->compile_data->ensure_node_stack = &enl; - - ADD_LABEL(ret, lstart); - COMPILE_(ret, "ensure head", node->nd_head, poped); - ADD_LABEL(ret, lend); - if (ensr->anchor.next == 0) { - ADD_INSN(ret, nd_line(node), nop); - } - else { - ADD_SEQ(ret, ensr); - } - ADD_LABEL(ret, lcont); + DECL_ANCHOR(ensr); + VALUE ensure = NEW_CHILD_ISEQVAL(node->nd_ensr, + rb_str_concat(rb_str_new2 + ("ensure in "), + iseq->name), + ISEQ_TYPE_ENSURE); + LABEL *lstart = NEW_LABEL(nd_line(node)); + LABEL *lend = NEW_LABEL(nd_line(node)); + LABEL *lcont = NEW_LABEL(nd_line(node)); + struct ensure_range er = { lstart, lend, 0 }; + struct iseq_compile_data_ensure_node_stack enl = { + node->nd_ensr, + iseq->compile_data->ensure_node_stack, /* prev */ + &er, + }; + struct ensure_range *erange; - erange = iseq->compile_data->ensure_node_stack->erange; - while (erange) { - ADD_CATCH_ENTRY(CATCH_TYPE_ENSURE, erange->begin, erange->end, - ensure, lcont); - erange = erange->next; - } - iseq->compile_data->ensure_node_stack = enl.prev; - break; + COMPILE_POPED(ensr, "ensure ensr", node->nd_ensr); + + iseq->compile_data->ensure_node_stack = &enl; + + ADD_LABEL(ret, lstart); + COMPILE_(ret, "ensure head", node->nd_head, poped); + ADD_LABEL(ret, lend); + if (ensr->anchor.next == 0) { + ADD_INSN(ret, nd_line(node), nop); + } + else { + ADD_SEQ(ret, ensr); + } + ADD_LABEL(ret, lcont); + + erange = iseq->compile_data->ensure_node_stack->erange; + while (erange) { + ADD_CATCH_ENTRY(CATCH_TYPE_ENSURE, erange->begin, erange->end, + ensure, lcont); + erange = erange->next; + } + iseq->compile_data->ensure_node_stack = enl.prev; + break; } case NODE_AND: case NODE_OR:{ - LABEL *end_label = NEW_LABEL(nd_line(node)); - COMPILE(ret, "nd_1st", node->nd_1st); - if (!poped) { - ADD_INSN(ret, nd_line(node), dup); - } - if (type == NODE_AND) { - ADD_INSNL(ret, nd_line(node), branchunless, end_label); - } - else { - ADD_INSNL(ret, nd_line(node), branchif, end_label); - } - if (!poped) { - ADD_INSN(ret, nd_line(node), pop); - } - COMPILE_(ret, "nd_2nd", node->nd_2nd, poped); - ADD_LABEL(ret, end_label); - break; + LABEL *end_label = NEW_LABEL(nd_line(node)); + COMPILE(ret, "nd_1st", node->nd_1st); + if (!poped) { + ADD_INSN(ret, nd_line(node), dup); + } + if (type == NODE_AND) { + ADD_INSNL(ret, nd_line(node), branchunless, end_label); + } + else { + ADD_INSNL(ret, nd_line(node), branchif, end_label); + } + if (!poped) { + ADD_INSN(ret, nd_line(node), pop); + } + COMPILE_(ret, "nd_2nd", node->nd_2nd, poped); + ADD_LABEL(ret, end_label); + break; } case NODE_NOT:{ - COMPILE(ret, "value", node->nd_body); - ADD_INSN(ret, nd_line(node), putnot); - if (poped) { - ADD_INSN(ret, nd_line(node), pop); - } - break; + COMPILE(ret, "value", node->nd_body); + ADD_INSN(ret, nd_line(node), putnot); + if (poped) { + ADD_INSN(ret, nd_line(node), pop); + } + break; } case NODE_MASGN:{ - compile_massign(iseq, ret, - node->nd_value, /* rhsn */ - node->nd_args, /* splat */ - node->nd_head, /* lhsn */ - 0); - if (!poped) { - ADD_INSN1(ret, nd_line(node), putobject, Qtrue); - } - break; + compile_massign(iseq, ret, + node->nd_value, /* rhsn */ + node->nd_args, /* splat */ + node->nd_head, /* lhsn */ + 0); + if (!poped) { + ADD_INSN1(ret, nd_line(node), putobject, Qtrue); + } + break; } case NODE_LASGN:{ - ID id = node->nd_vid; - int idx = iseq->local_iseq->local_size - get_local_var_idx(iseq, id); + ID id = node->nd_vid; + int idx = iseq->local_iseq->local_size - get_local_var_idx(iseq, id); - debugs("lvar: %s idx: %d\n", rb_id2name(id), idx); - COMPILE(ret, "rvalue", node->nd_value); + debugs("lvar: %s idx: %d\n", rb_id2name(id), idx); + COMPILE(ret, "rvalue", node->nd_value); - if (!poped) { - ADD_INSN(ret, nd_line(node), dup); - } - ADD_INSN1(ret, nd_line(node), setlocal, INT2FIX(idx)); + if (!poped) { + ADD_INSN(ret, nd_line(node), dup); + } + ADD_INSN1(ret, nd_line(node), setlocal, INT2FIX(idx)); - break; + break; } case NODE_DASGN: case NODE_DASGN_CURR:{ - int idx, lv, ls; - COMPILE(ret, "dvalue", node->nd_value); - debugp_param("dassn id", rb_str_new2(rb_id2name(node->nd_vid))); + int idx, lv, ls; + COMPILE(ret, "dvalue", node->nd_value); + debugp_param("dassn id", rb_str_new2(rb_id2name(node->nd_vid))); - if (!poped) { - ADD_INSN(ret, nd_line(node), dup); - } + if (!poped) { + ADD_INSN(ret, nd_line(node), dup); + } - idx = get_dyna_var_idx(iseq, node->nd_vid, &lv, &ls); + idx = get_dyna_var_idx(iseq, node->nd_vid, &lv, &ls); - if (idx < 0) { - debugi("unknown id", node->nd_vid); - COMPILE_ERROR(("NODE_DASGN error")); - } - ADD_INSN2(ret, nd_line(node), setdynamic, - INT2FIX(ls - idx), INT2FIX(lv)); - break; + if (idx < 0) { + debugi("unknown id", node->nd_vid); + COMPILE_ERROR(("NODE_DASGN error")); + } + ADD_INSN2(ret, nd_line(node), setdynamic, + INT2FIX(ls - idx), INT2FIX(lv)); + break; } case NODE_GASGN:{ - COMPILE(ret, "lvalue", node->nd_value); + COMPILE(ret, "lvalue", node->nd_value); - if (!poped) { - ADD_INSN(ret, nd_line(node), dup); - } - ADD_INSN1(ret, nd_line(node), setglobal, - (((long)node->nd_entry) | 1)); - break; + if (!poped) { + ADD_INSN(ret, nd_line(node), dup); + } + ADD_INSN1(ret, nd_line(node), setglobal, + (((long)node->nd_entry) | 1)); + break; } case NODE_IASGN: case NODE_IASGN2:{ - COMPILE(ret, "lvalue", node->nd_value); - if (!poped) { - ADD_INSN(ret, nd_line(node), dup); - } - ADD_INSN1(ret, nd_line(node), setinstancevariable, - ID2SYM(node->nd_vid)); - break; + COMPILE(ret, "lvalue", node->nd_value); + if (!poped) { + ADD_INSN(ret, nd_line(node), dup); + } + ADD_INSN1(ret, nd_line(node), setinstancevariable, + ID2SYM(node->nd_vid)); + break; } case NODE_CDECL:{ - COMPILE(ret, "lvalue", node->nd_value); + COMPILE(ret, "lvalue", node->nd_value); - if (!poped) { - ADD_INSN(ret, nd_line(node), dup); - } + if (!poped) { + ADD_INSN(ret, nd_line(node), dup); + } - if (node->nd_vid) { - ADD_INSN(ret, nd_line(node), putnil); - ADD_INSN1(ret, nd_line(node), setconstant, - ID2SYM(node->nd_vid)); - } - else { - compile_cpath(ret, iseq, node->nd_else); - ADD_INSN1(ret, nd_line(node), setconstant, - ID2SYM(node->nd_else->nd_mid)); - } - break; + if (node->nd_vid) { + ADD_INSN(ret, nd_line(node), putnil); + ADD_INSN1(ret, nd_line(node), setconstant, + ID2SYM(node->nd_vid)); + } + else { + compile_cpath(ret, iseq, node->nd_else); + ADD_INSN1(ret, nd_line(node), setconstant, + ID2SYM(node->nd_else->nd_mid)); + } + break; } case NODE_CVASGN:{ - COMPILE(ret, "cvasgn val", node->nd_value); - if (!poped) { - ADD_INSN(ret, nd_line(node), dup); - } - ADD_INSN1(ret, nd_line(node), setclassvariable, - ID2SYM(node->nd_vid)); - break; + COMPILE(ret, "cvasgn val", node->nd_value); + if (!poped) { + ADD_INSN(ret, nd_line(node), dup); + } + ADD_INSN1(ret, nd_line(node), setclassvariable, + ID2SYM(node->nd_vid)); + break; } case NODE_OP_ASGN1:{ - DECL_ANCHOR(args); - int argc; - ID id = node->nd_mid; - - /* - * a[x] (op)= y - * - * eval a # a - * eval x # a x - * dupn 2 # a x a x - * send :[] # a x a[x] - * eval y # a x a[x] y - * send op # a x a[x]+y - * send []= # ret - */ - - /* - * nd_recv[nd_args->nd_body] (nd_mid)= nd_args->nd_head; - * NODE_OP_ASGN nd_recv - * nd_args->nd_head - * nd_args->nd_body - * nd_mid - */ - - COMPILE(ret, "NODE_OP_ASGN1 recv", node->nd_recv); - argc = compile_array(iseq, args, node->nd_args->nd_body, Qfalse); - POP_ELEMENT(args); - ADD_SEQ(ret, args); - ADD_INSN1(ret, nd_line(node), dupn, INT2FIX(argc+1)); - ADD_SEND(ret, nd_line(node), ID2SYM(idAREF), INT2FIX(argc)); - - if (id == 0 || id == 1) { - /* 0: or, 1: and - a[x] ||= y - - unless/if a[x] - a[x]= y - else - nil - end - */ - LABEL *label = NEW_LABEL(nd_line(node)); - LABEL *lfin = NEW_LABEL(nd_line(node)); - - if (id == 0) { - /* or */ - ADD_INSN(ret, nd_line(node), dup); - ADD_INSNL(ret, nd_line(node), branchif, label); - ADD_INSN(ret, nd_line(node), pop); - } - else { - /* and */ - ADD_INSNL(ret, nd_line(node), branchunless, label); - } + DECL_ANCHOR(args); + int argc; + ID id = node->nd_mid; - COMPILE(ret, "NODE_OP_ASGN1 args->head: ", - node->nd_args->nd_head); - ADD_SEND(ret, nd_line(node), ID2SYM(idASET), - INT2FIX(argc + 1)); - ADD_INSNL(ret, nd_line(node), jump, lfin); - ADD_LABEL(ret, label); - if (id == 0) { /* or */ - ADD_INSN(ret, nd_line(node), swap); - ADD_INSN(ret, nd_line(node), pop); - ADD_INSN(ret, nd_line(node), swap); - ADD_INSN(ret, nd_line(node), pop); - } - else if (id == 1) { /* and */ - ADD_INSN(ret, nd_line(node), pop); - ADD_INSN(ret, nd_line(node), pop); - ADD_INSN(ret, nd_line(node), putnil); - } - ADD_LABEL(ret, lfin); - } - else { - COMPILE(ret, "NODE_OP_ASGN1 args->head: ", - node->nd_args->nd_head); - ADD_SEND(ret, nd_line(node), ID2SYM(id), INT2FIX(1)); - ADD_SEND(ret, nd_line(node), ID2SYM(idASET), - INT2FIX(argc + 1)); - } + /* + * a[x] (op)= y + * + * eval a # a + * eval x # a x + * dupn 2 # a x a x + * send :[] # a x a[x] + * eval y # a x a[x] y + * send op # a x a[x]+y + * send []= # ret + */ - if (poped) { - ADD_INSN(ret, nd_line(node), pop); - } + /* + * nd_recv[nd_args->nd_body] (nd_mid)= nd_args->nd_head; + * NODE_OP_ASGN nd_recv + * nd_args->nd_head + * nd_args->nd_body + * nd_mid + */ + + COMPILE(ret, "NODE_OP_ASGN1 recv", node->nd_recv); + argc = compile_array(iseq, args, node->nd_args->nd_body, Qfalse); + POP_ELEMENT(args); + ADD_SEQ(ret, args); + ADD_INSN1(ret, nd_line(node), dupn, INT2FIX(argc+1)); + ADD_SEND(ret, nd_line(node), ID2SYM(idAREF), INT2FIX(argc)); + + if (id == 0 || id == 1) { + /* 0: or, 1: and + a[x] ||= y + + unless/if a[x] + a[x]= y + else + nil + end + */ + LABEL *label = NEW_LABEL(nd_line(node)); + LABEL *lfin = NEW_LABEL(nd_line(node)); + + if (id == 0) { + /* or */ + ADD_INSN(ret, nd_line(node), dup); + ADD_INSNL(ret, nd_line(node), branchif, label); + ADD_INSN(ret, nd_line(node), pop); + } + else { + /* and */ + ADD_INSNL(ret, nd_line(node), branchunless, label); + } + + COMPILE(ret, "NODE_OP_ASGN1 args->head: ", + node->nd_args->nd_head); + ADD_SEND(ret, nd_line(node), ID2SYM(idASET), + INT2FIX(argc + 1)); + ADD_INSNL(ret, nd_line(node), jump, lfin); + ADD_LABEL(ret, label); + if (id == 0) { /* or */ + ADD_INSN(ret, nd_line(node), swap); + ADD_INSN(ret, nd_line(node), pop); + ADD_INSN(ret, nd_line(node), swap); + ADD_INSN(ret, nd_line(node), pop); + } + else if (id == 1) { /* and */ + ADD_INSN(ret, nd_line(node), pop); + ADD_INSN(ret, nd_line(node), pop); + ADD_INSN(ret, nd_line(node), putnil); + } + ADD_LABEL(ret, lfin); + } + else { + COMPILE(ret, "NODE_OP_ASGN1 args->head: ", + node->nd_args->nd_head); + ADD_SEND(ret, nd_line(node), ID2SYM(id), INT2FIX(1)); + ADD_SEND(ret, nd_line(node), ID2SYM(idASET), + INT2FIX(argc + 1)); + } - break; + if (poped) { + ADD_INSN(ret, nd_line(node), pop); + } + + break; } case NODE_OP_ASGN2:{ - ID atype = node->nd_next->nd_mid; - LABEL *lfin = NEW_LABEL(nd_line(node)); - LABEL *lcfin = NEW_LABEL(nd_line(node)); - /* - class C; attr_accessor :c; end - r = C.new - r.a &&= v # asgn2 - - eval r # r - dup # r r - eval r.a # r o - - # or - dup # r o o - if lcfin # r o - pop # r - eval v # r v - send a= # v - jump lfin # v - - lcfin: # r o - swap # o r - pop # o - - lfin: # v - - # and - dup # r o o - unless lcfin - pop # r - eval v # r v - send a= # v - jump lfin # v - - # others - eval v # r o v - send ?? # r w - send a= # w - - */ - - COMPILE(ret, "NODE_OP_ASGN2#recv", node->nd_recv); - ADD_INSN(ret, nd_line(node), dup); - ADD_SEND(ret, nd_line(node), ID2SYM(node->nd_next->nd_vid), - INT2FIX(0)); - - if (atype == 0 || atype == 1) { /* 0: OR or 1: AND */ - ADD_INSN(ret, nd_line(node), dup); - if (atype == 0) { - ADD_INSNL(ret, nd_line(node), branchif, lcfin); - } - else { - ADD_INSNL(ret, nd_line(node), branchunless, lcfin); - } - ADD_INSN(ret, nd_line(node), pop); - COMPILE(ret, "NODE_OP_ASGN2 val", node->nd_value); - ADD_SEND(ret, nd_line(node), ID2SYM(node->nd_next->nd_aid), - INT2FIX(1)); - ADD_INSNL(ret, nd_line(node), jump, lfin); + ID atype = node->nd_next->nd_mid; + LABEL *lfin = NEW_LABEL(nd_line(node)); + LABEL *lcfin = NEW_LABEL(nd_line(node)); + /* + class C; attr_accessor :c; end + r = C.new + r.a &&= v # asgn2 + + eval r # r + dup # r r + eval r.a # r o + + # or + dup # r o o + if lcfin # r o + pop # r + eval v # r v + send a= # v + jump lfin # v + + lcfin: # r o + swap # o r + pop # o + + lfin: # v + + # and + dup # r o o + unless lcfin + pop # r + eval v # r v + send a= # v + jump lfin # v + + # others + eval v # r o v + send ?? # r w + send a= # w + + */ + + COMPILE(ret, "NODE_OP_ASGN2#recv", node->nd_recv); + ADD_INSN(ret, nd_line(node), dup); + ADD_SEND(ret, nd_line(node), ID2SYM(node->nd_next->nd_vid), + INT2FIX(0)); + + if (atype == 0 || atype == 1) { /* 0: OR or 1: AND */ + ADD_INSN(ret, nd_line(node), dup); + if (atype == 0) { + ADD_INSNL(ret, nd_line(node), branchif, lcfin); + } + else { + ADD_INSNL(ret, nd_line(node), branchunless, lcfin); + } + ADD_INSN(ret, nd_line(node), pop); + COMPILE(ret, "NODE_OP_ASGN2 val", node->nd_value); + ADD_SEND(ret, nd_line(node), ID2SYM(node->nd_next->nd_aid), + INT2FIX(1)); + ADD_INSNL(ret, nd_line(node), jump, lfin); - ADD_LABEL(ret, lcfin); - ADD_INSN(ret, nd_line(node), swap); - ADD_INSN(ret, nd_line(node), pop); + ADD_LABEL(ret, lcfin); + ADD_INSN(ret, nd_line(node), swap); + ADD_INSN(ret, nd_line(node), pop); - ADD_LABEL(ret, lfin); - } - else { - COMPILE(ret, "NODE_OP_ASGN2 val", node->nd_value); - ADD_SEND(ret, nd_line(node), ID2SYM(node->nd_next->nd_mid), - INT2FIX(1)); - ADD_SEND(ret, nd_line(node), ID2SYM(node->nd_next->nd_aid), - INT2FIX(1)); - } + ADD_LABEL(ret, lfin); + } + else { + COMPILE(ret, "NODE_OP_ASGN2 val", node->nd_value); + ADD_SEND(ret, nd_line(node), ID2SYM(node->nd_next->nd_mid), + INT2FIX(1)); + ADD_SEND(ret, nd_line(node), ID2SYM(node->nd_next->nd_aid), + INT2FIX(1)); + } - if (poped) { - /* we can apply more optimize */ - ADD_INSN(ret, nd_line(node), pop); - } - break; + if (poped) { + /* we can apply more optimize */ + ADD_INSN(ret, nd_line(node), pop); + } + break; } case NODE_OP_ASGN_AND: case NODE_OP_ASGN_OR:{ - LABEL *lfin = NEW_LABEL(nd_line(node)); - LABEL *lassign = NEW_LABEL(nd_line(node)); - - if (nd_type(node) == NODE_OP_ASGN_OR) { - defined_expr(iseq, ret, node->nd_head, lassign, Qfalse); - ADD_INSNL(ret, nd_line(node), branchunless, lassign); - } - - COMPILE(ret, "NODE_OP_ASGN_AND/OR#nd_head", node->nd_head); - ADD_INSN(ret, nd_line(node), dup); - - if (nd_type(node) == NODE_OP_ASGN_AND) { - ADD_INSNL(ret, nd_line(node), branchunless, lfin); - } - else { - ADD_INSNL(ret, nd_line(node), branchif, lfin); - } + LABEL *lfin = NEW_LABEL(nd_line(node)); + LABEL *lassign = NEW_LABEL(nd_line(node)); + + if (nd_type(node) == NODE_OP_ASGN_OR) { + defined_expr(iseq, ret, node->nd_head, lassign, Qfalse); + ADD_INSNL(ret, nd_line(node), branchunless, lassign); + } + + COMPILE(ret, "NODE_OP_ASGN_AND/OR#nd_head", node->nd_head); + ADD_INSN(ret, nd_line(node), dup); + + if (nd_type(node) == NODE_OP_ASGN_AND) { + ADD_INSNL(ret, nd_line(node), branchunless, lfin); + } + else { + ADD_INSNL(ret, nd_line(node), branchif, lfin); + } - ADD_INSN(ret, nd_line(node), pop); - ADD_LABEL(ret, lassign); - COMPILE(ret, "NODE_OP_ASGN_AND/OR#nd_value", node->nd_value); - ADD_LABEL(ret, lfin); + ADD_INSN(ret, nd_line(node), pop); + ADD_LABEL(ret, lassign); + COMPILE(ret, "NODE_OP_ASGN_AND/OR#nd_value", node->nd_value); + ADD_LABEL(ret, lfin); - if (poped) { - /* we can apply more optimize */ - ADD_INSN(ret, nd_line(node), pop); - } - break; + if (poped) { + /* we can apply more optimize */ + ADD_INSN(ret, nd_line(node), pop); + } + break; } case NODE_CALL: case NODE_FCALL: case NODE_VCALL:{ /* VCALL: variable or call */ - /* - call: obj.method(...) - fcall: func(...) - vcall: func - */ - DECL_ANCHOR(recv); - DECL_ANCHOR(args); - ID mid = node->nd_mid; - VALUE argc; - VALUE flag = 0; - VALUE parent_block = iseq->compile_data->current_block; - iseq->compile_data->current_block = Qfalse; + /* + call: obj.method(...) + fcall: func(...) + vcall: func + */ + DECL_ANCHOR(recv); + DECL_ANCHOR(args); + ID mid = node->nd_mid; + VALUE argc; + VALUE flag = 0; + VALUE parent_block = iseq->compile_data->current_block; + iseq->compile_data->current_block = Qfalse; #if SUPPORT_JOKE - if (nd_type(node) == NODE_VCALL) { - if (mid == idBitblt) { - ADD_INSN(ret, nd_line(node), bitblt); - break; - } - else if (mid == idAnswer) { - ADD_INSN(ret, nd_line(node), answer); - break; - } - } - /* only joke */ - { - static ID goto_id; - static ID label_id; - VALUE label; - VALUE label_sym; - - if (goto_id == 0) { - goto_id = rb_intern("__goto__"); - label_id = rb_intern("__label__"); - } + if (nd_type(node) == NODE_VCALL) { + if (mid == idBitblt) { + ADD_INSN(ret, nd_line(node), bitblt); + break; + } + else if (mid == idAnswer) { + ADD_INSN(ret, nd_line(node), answer); + break; + } + } + /* only joke */ + { + static ID goto_id; + static ID label_id; + VALUE label; + VALUE label_sym; + + if (goto_id == 0) { + goto_id = rb_intern("__goto__"); + label_id = rb_intern("__label__"); + } - if (nd_type(node) == NODE_FCALL && - (mid == goto_id || mid == label_id)) { - if (nd_type(node->nd_args->nd_head) == NODE_LIT && - SYMBOL_P(node->nd_args->nd_head->nd_lit)) { - - label_sym = label = node->nd_args->nd_head->nd_lit; - if ((label = - rb_hash_aref(iseq->compile_data, - label_sym)) == Qnil) { - rb_hash_aset(iseq->compile_data, label_sym, - label = NEW_LABEL(nd_line(node))); - } - } - else { - rb_bug("illegal goto/label format"); - } - - - if (mid == goto_id) { - ADD_INSNL(ret, nd_line(node), jump, label); - } - else { - ADD_LABEL(ret, label); - } - break; - } - } + if (nd_type(node) == NODE_FCALL && + (mid == goto_id || mid == label_id)) { + if (nd_type(node->nd_args->nd_head) == NODE_LIT && + SYMBOL_P(node->nd_args->nd_head->nd_lit)) { + + label_sym = label = node->nd_args->nd_head->nd_lit; + if ((label = + rb_hash_aref(iseq->compile_data, + label_sym)) == Qnil) { + rb_hash_aset(iseq->compile_data, label_sym, + label = NEW_LABEL(nd_line(node))); + } + } + else { + rb_bug("illegal goto/label format"); + } + + + if (mid == goto_id) { + ADD_INSNL(ret, nd_line(node), jump, label); + } + else { + ADD_LABEL(ret, label); + } + break; + } + } #endif - /* reciever */ - if (type == NODE_CALL) { - COMPILE(recv, "recv", node->nd_recv); - } - else if (type == NODE_FCALL || type == NODE_VCALL) { - ADD_CALL_RECEIVER(recv, nd_line(node)); - } + /* reciever */ + if (type == NODE_CALL) { + COMPILE(recv, "recv", node->nd_recv); + } + else if (type == NODE_FCALL || type == NODE_VCALL) { + ADD_CALL_RECEIVER(recv, nd_line(node)); + } - /* args */ - if (nd_type(node) != NODE_VCALL) { - argc = setup_arg(iseq, args, node, &flag); - } - else { - argc = INT2FIX(0); - } + /* args */ + if (nd_type(node) != NODE_VCALL) { + argc = setup_arg(iseq, args, node, &flag); + } + else { + argc = INT2FIX(0); + } - ADD_SEQ(ret, recv); - ADD_SEQ(ret, args); + ADD_SEQ(ret, recv); + ADD_SEQ(ret, args); - debugp_param("call args argc", argc); - debugp_param("call method", ID2SYM(mid)); + debugp_param("call args argc", argc); + debugp_param("call method", ID2SYM(mid)); - switch (nd_type(node)) { - case NODE_VCALL: - flag |= VM_CALL_VCALL_BIT; - /* VCALL is funcall, so fall through */ - case NODE_FCALL: - flag |= VM_CALL_FCALL_BIT; - } + switch (nd_type(node)) { + case NODE_VCALL: + flag |= VM_CALL_VCALL_BIT; + /* VCALL is funcall, so fall through */ + case NODE_FCALL: + flag |= VM_CALL_FCALL_BIT; + } - ADD_SEND_R(ret, nd_line(node), ID2SYM(mid), - argc, parent_block, INT2FIX(flag)); + ADD_SEND_R(ret, nd_line(node), ID2SYM(mid), + argc, parent_block, INT2FIX(flag)); - if (poped) { - ADD_INSN(ret, nd_line(node), pop); - } - break; + if (poped) { + ADD_INSN(ret, nd_line(node), pop); + } + break; } case NODE_SUPER: case NODE_ZSUPER:{ - DECL_ANCHOR(args); - VALUE argc; - VALUE flag = 0; - VALUE parent_block = iseq->compile_data->current_block; - iseq->compile_data->current_block = Qfalse; - - if (nd_type(node) == NODE_SUPER) { - argc = setup_arg(iseq, args, node, &flag); - } - else { - /* NODE_ZSUPER */ - int i; - rb_iseq_t *liseq = iseq->local_iseq; + DECL_ANCHOR(args); + VALUE argc; + VALUE flag = 0; + VALUE parent_block = iseq->compile_data->current_block; + iseq->compile_data->current_block = Qfalse; + + if (nd_type(node) == NODE_SUPER) { + argc = setup_arg(iseq, args, node, &flag); + } + else { + /* NODE_ZSUPER */ + int i; + rb_iseq_t *liseq = iseq->local_iseq; - argc = INT2FIX(liseq->argc); + argc = INT2FIX(liseq->argc); - /* normal arguments */ - for (i = 0; i < liseq->argc; i++) { - int idx = liseq->local_size - i; - ADD_INSN1(args, nd_line(node), getlocal, INT2FIX(idx)); - } + /* normal arguments */ + for (i = 0; i < liseq->argc; i++) { + int idx = liseq->local_size - i; + ADD_INSN1(args, nd_line(node), getlocal, INT2FIX(idx)); + } - if (!liseq->arg_simple) { - if (liseq->arg_opts) { - /* optional arguments */ - int j; - for (j = 0; j < liseq->arg_opts - 1; j++) { - int idx = liseq->local_size - (i + j); - ADD_INSN1(args, nd_line(node), getlocal, - INT2FIX(idx)); - } - i += j; - argc = INT2FIX(i); - } + if (!liseq->arg_simple) { + if (liseq->arg_opts) { + /* optional arguments */ + int j; + for (j = 0; j < liseq->arg_opts - 1; j++) { + int idx = liseq->local_size - (i + j); + ADD_INSN1(args, nd_line(node), getlocal, + INT2FIX(idx)); + } + i += j; + argc = INT2FIX(i); + } - if (liseq->arg_rest) { - /* rest arguments */ + if (liseq->arg_rest) { + /* rest arguments */ - if (liseq->arg_rest == -1) { - /* TODO */ - } - else { - int idx = liseq->local_size - liseq->arg_rest + 1; - ADD_INSN1(args, nd_line(node), getlocal, - INT2FIX(idx)); - argc = INT2FIX(liseq->arg_rest); - flag |= VM_CALL_ARGS_SPLAT_BIT; - } - } - } - } + if (liseq->arg_rest == -1) { + /* TODO */ + } + else { + int idx = liseq->local_size - liseq->arg_rest + 1; + ADD_INSN1(args, nd_line(node), getlocal, + INT2FIX(idx)); + argc = INT2FIX(liseq->arg_rest); + flag |= VM_CALL_ARGS_SPLAT_BIT; + } + } + } + } - /* dummy reciever */ - ADD_INSN1(ret, nd_line(node), putobject, - nd_type(node) == NODE_ZSUPER ? Qfalse : Qtrue); - ADD_SEQ(ret, args); - ADD_INSN3(ret, nd_line(node), invokesuper, - argc, parent_block, INT2FIX(flag)); + /* dummy reciever */ + ADD_INSN1(ret, nd_line(node), putobject, + nd_type(node) == NODE_ZSUPER ? Qfalse : Qtrue); + ADD_SEQ(ret, args); + ADD_INSN3(ret, nd_line(node), invokesuper, + argc, parent_block, INT2FIX(flag)); - if (poped) { - ADD_INSN(ret, nd_line(node), pop); - } - break; + if (poped) { + ADD_INSN(ret, nd_line(node), pop); + } + break; } case NODE_ARRAY:{ - compile_array(iseq, ret, node, Qtrue); - if (poped) { - ADD_INSN(ret, nd_line(node), pop); - } - break; + compile_array(iseq, ret, node, Qtrue); + if (poped) { + ADD_INSN(ret, nd_line(node), pop); + } + break; } case NODE_ZARRAY:{ - if (!poped) { - ADD_INSN1(ret, nd_line(node), newarray, INT2FIX(0)); - } - break; + if (!poped) { + ADD_INSN1(ret, nd_line(node), newarray, INT2FIX(0)); + } + break; } case NODE_VALUES:{ - NODE *n = node; - while (n) { - COMPILE(ret, "values item", n->nd_head); - n = n->nd_next; - } - ADD_INSN1(ret, nd_line(node), newarray, INT2FIX(node->nd_alen)); - if (poped) { - ADD_INSN(ret, nd_line(node), pop); - } - break; + NODE *n = node; + while (n) { + COMPILE(ret, "values item", n->nd_head); + n = n->nd_next; + } + ADD_INSN1(ret, nd_line(node), newarray, INT2FIX(node->nd_alen)); + if (poped) { + ADD_INSN(ret, nd_line(node), pop); + } + break; } case NODE_HASH:{ - DECL_ANCHOR(list); - VALUE size = 0; - int type = node->nd_head ? nd_type(node->nd_head) : NODE_ZARRAY; - - switch (type) { - case NODE_ARRAY:{ - compile_array(iseq, list, node->nd_head, Qfalse); - size = OPERAND_AT(POP_ELEMENT(list), 0); - ADD_SEQ(ret, list); - break; - } - case NODE_ZARRAY: - size = INT2FIX(0); - break; + DECL_ANCHOR(list); + VALUE size = 0; + int type = node->nd_head ? nd_type(node->nd_head) : NODE_ZARRAY; - default: - rb_bug("can't make hash with this node: %s", ruby_node_name(type)); + switch (type) { + case NODE_ARRAY:{ + compile_array(iseq, list, node->nd_head, Qfalse); + size = OPERAND_AT(POP_ELEMENT(list), 0); + ADD_SEQ(ret, list); + break; } + case NODE_ZARRAY: + size = INT2FIX(0); + break; - ADD_INSN1(ret, nd_line(node), newhash, size); + default: + rb_bug("can't make hash with this node: %s", ruby_node_name(type)); + } - if (poped) { - ADD_INSN(ret, nd_line(node), pop); - } - break; + ADD_INSN1(ret, nd_line(node), newhash, size); + + if (poped) { + ADD_INSN(ret, nd_line(node), pop); + } + break; } case NODE_RETURN:{ - rb_iseq_t *is = iseq; + rb_iseq_t *is = iseq; - while (is) { - if (is->type == ISEQ_TYPE_TOP || is->type == ISEQ_TYPE_CLASS) { - COMPILE_ERROR(("Illegal return")); - break; - } - else { - if (is->type == ISEQ_TYPE_METHOD) { - ADD_INSN(ret, nd_line(node), emptstack); - } - - COMPILE(ret, "return nd_stts (return val)", - node->nd_stts); - - if (is->type == ISEQ_TYPE_METHOD) { - add_ensure_iseq(ret, iseq); - ADD_INSN(ret, nd_line(node), leave); - } - else { - ADD_INSN1(ret, nd_line(node), throw, - INT2FIX(0x01) /* TAG_RETURN */ ); - } - break; - } - } + while (is) { + if (is->type == ISEQ_TYPE_TOP || is->type == ISEQ_TYPE_CLASS) { + COMPILE_ERROR(("Illegal return")); + break; + } + else { + if (is->type == ISEQ_TYPE_METHOD) { + ADD_INSN(ret, nd_line(node), emptstack); + } + + COMPILE(ret, "return nd_stts (return val)", + node->nd_stts); - break; + if (is->type == ISEQ_TYPE_METHOD) { + add_ensure_iseq(ret, iseq); + ADD_INSN(ret, nd_line(node), leave); + } + else { + ADD_INSN1(ret, nd_line(node), throw, + INT2FIX(0x01) /* TAG_RETURN */ ); + } + break; + } + } + + break; } case NODE_YIELD:{ - DECL_ANCHOR(args); - int argc; - unsigned long flag = 0; + DECL_ANCHOR(args); + int argc; + unsigned long flag = 0; - if (iseq->type == ISEQ_TYPE_TOP || iseq->type == ISEQ_TYPE_CLASS) { - COMPILE_ERROR(("Illegal yield")); - } + if (iseq->type == ISEQ_TYPE_TOP || iseq->type == ISEQ_TYPE_CLASS) { + COMPILE_ERROR(("Illegal yield")); + } - if (node->nd_head) { - if (nd_type(node->nd_head) == NODE_ARRAY) { - NODE *p; - for (argc = 0, p = node->nd_head; p; - p = p->nd_next, argc++) { - /* count argc */ - } - - if (argc == 1) { - COMPILE(args, "yield with an arg", node->nd_head); - } - else { - compile_array(iseq, args, node->nd_head, Qfalse); - POP_ELEMENT(args); - } - debugs("argc: %d\n", argc); - } - else { - if (nd_type(node->nd_head) == NODE_ARGSCAT) { - if (node->nd_state == Qtrue) { - flag |= VM_CALL_ARGS_SPLAT_BIT; - } + if (node->nd_head) { + if (nd_type(node->nd_head) == NODE_ARRAY) { + NODE *p; + for (argc = 0, p = node->nd_head; p; + p = p->nd_next, argc++) { + /* count argc */ + } - compile_array(iseq, args, node->nd_head->nd_head, - Qfalse); - POP_ELEMENT(args); - argc = LIST_SIZE(args) + 1; - - COMPILE(args, "args(cat: splat)", - node->nd_head->nd_body); - } - else if (nd_type(node->nd_head) == NODE_SPLAT) { - if (node->nd_state == Qtrue) { - flag |= VM_CALL_ARGS_SPLAT_BIT; - } + if (argc == 1) { + COMPILE(args, "yield with an arg", node->nd_head); + } + else { + compile_array(iseq, args, node->nd_head, Qfalse); + POP_ELEMENT(args); + } + debugs("argc: %d\n", argc); + } + else { + if (nd_type(node->nd_head) == NODE_ARGSCAT) { + if (node->nd_state == Qtrue) { + flag |= VM_CALL_ARGS_SPLAT_BIT; + } - argc = 1; - COMPILE(args, "splat", node->nd_head->nd_head); - } - else { - COMPILE(args, "nd_head(1)", node->nd_head); - argc = 1; - } - } - } - else { - argc = 0; - } - ADD_SEQ(ret, args); - ADD_INSN2(ret, nd_line(node), invokeblock, INT2FIX(argc), - INT2FIX(flag)); + compile_array(iseq, args, node->nd_head->nd_head, + Qfalse); + POP_ELEMENT(args); + argc = LIST_SIZE(args) + 1; - if (poped) { - ADD_INSN(ret, nd_line(node), pop); - } - break; + COMPILE(args, "args(cat: splat)", + node->nd_head->nd_body); + } + else if (nd_type(node->nd_head) == NODE_SPLAT) { + if (node->nd_state == Qtrue) { + flag |= VM_CALL_ARGS_SPLAT_BIT; + } + + argc = 1; + COMPILE(args, "splat", node->nd_head->nd_head); + } + else { + COMPILE(args, "nd_head(1)", node->nd_head); + argc = 1; + } + } + } + else { + argc = 0; + } + ADD_SEQ(ret, args); + ADD_INSN2(ret, nd_line(node), invokeblock, INT2FIX(argc), + INT2FIX(flag)); + + if (poped) { + ADD_INSN(ret, nd_line(node), pop); + } + break; } case NODE_LVAR:{ - if (!poped) { - ID id = node->nd_vid; - int idx = iseq->local_iseq->local_size - get_local_var_idx(iseq, id); + if (!poped) { + ID id = node->nd_vid; + int idx = iseq->local_iseq->local_size - get_local_var_idx(iseq, id); - debugs("id: %s idx: %d\n", rb_id2name(id), idx); - ADD_INSN1(ret, nd_line(node), getlocal, INT2FIX(idx)); - } - break; + debugs("id: %s idx: %d\n", rb_id2name(id), idx); + ADD_INSN1(ret, nd_line(node), getlocal, INT2FIX(idx)); + } + break; } case NODE_DVAR:{ - int lv, idx, ls; - debugi("nd_vid", node->nd_vid); - if (!poped) { - idx = get_dyna_var_idx(iseq, node->nd_vid, &lv, &ls); - if (idx < 0) { - rb_bug("unknown dvar (%s)", rb_id2name(node->nd_vid)); - } - ADD_INSN2(ret, nd_line(node), getdynamic, INT2FIX(ls - idx), - INT2FIX(lv)); - } - break; + int lv, idx, ls; + debugi("nd_vid", node->nd_vid); + if (!poped) { + idx = get_dyna_var_idx(iseq, node->nd_vid, &lv, &ls); + if (idx < 0) { + rb_bug("unknown dvar (%s)", rb_id2name(node->nd_vid)); + } + ADD_INSN2(ret, nd_line(node), getdynamic, INT2FIX(ls - idx), + INT2FIX(lv)); + } + break; } case NODE_GVAR:{ - ADD_INSN1(ret, nd_line(node), getglobal, - (((long)node->nd_entry) | 1)); - if (poped) { - ADD_INSN(ret, nd_line(node), pop); - } - break; + ADD_INSN1(ret, nd_line(node), getglobal, + (((long)node->nd_entry) | 1)); + if (poped) { + ADD_INSN(ret, nd_line(node), pop); + } + break; } case NODE_IVAR:{ - debugi("nd_vid", node->nd_vid); - if (!poped) { - ADD_INSN1(ret, nd_line(node), getinstancevariable, - ID2SYM(node->nd_vid)); - } - break; + debugi("nd_vid", node->nd_vid); + if (!poped) { + ADD_INSN1(ret, nd_line(node), getinstancevariable, + ID2SYM(node->nd_vid)); + } + break; } case NODE_CONST:{ - debugi("nd_vid", node->nd_vid); - - if (iseq->compile_data->option->inline_const_cache) { - LABEL *lstart = NEW_LABEL(nd_line(node)); - LABEL *lend = NEW_LABEL(nd_line(node)); - - ADD_LABEL(ret, lstart); - ADD_INSN2(ret, nd_line(node), getinlinecache, - NEW_INLINE_CACHE_ENTRY(), lend); - ADD_INSN1(ret, nd_line(node), getconstant, ID2SYM(node->nd_vid)); - ADD_INSN1(ret, nd_line(node), setinlinecache, lstart); - ADD_LABEL(ret, lend); - } - else { - ADD_INSN(ret, nd_line(node), putnil); - ADD_INSN1(ret, nd_line(node), getconstant, ID2SYM(node->nd_vid)); - } + debugi("nd_vid", node->nd_vid); + + if (iseq->compile_data->option->inline_const_cache) { + LABEL *lstart = NEW_LABEL(nd_line(node)); + LABEL *lend = NEW_LABEL(nd_line(node)); + + ADD_LABEL(ret, lstart); + ADD_INSN2(ret, nd_line(node), getinlinecache, + NEW_INLINE_CACHE_ENTRY(), lend); + ADD_INSN1(ret, nd_line(node), getconstant, ID2SYM(node->nd_vid)); + ADD_INSN1(ret, nd_line(node), setinlinecache, lstart); + ADD_LABEL(ret, lend); + } + else { + ADD_INSN(ret, nd_line(node), putnil); + ADD_INSN1(ret, nd_line(node), getconstant, ID2SYM(node->nd_vid)); + } - if (poped) { - ADD_INSN(ret, nd_line(node), pop); - } - break; + if (poped) { + ADD_INSN(ret, nd_line(node), pop); + } + break; } case NODE_CVAR:{ - if (!poped) { - ADD_INSN1(ret, nd_line(node), getclassvariable, - ID2SYM(node->nd_vid)); - } - break; + if (!poped) { + ADD_INSN1(ret, nd_line(node), getclassvariable, + ID2SYM(node->nd_vid)); + } + break; } case NODE_NTH_REF:{ - ADD_INSN2(ret, nd_line(node), getspecial, INT2FIX(1) /* '~' */, - INT2FIX(node->nd_nth << 1)); - break; + ADD_INSN2(ret, nd_line(node), getspecial, INT2FIX(1) /* '~' */, + INT2FIX(node->nd_nth << 1)); + break; } case NODE_BACK_REF:{ - ADD_INSN2(ret, nd_line(node), getspecial, INT2FIX(1) /* '~' */, - INT2FIX(0x01 | (node->nd_nth << 1))); - break; + ADD_INSN2(ret, nd_line(node), getspecial, INT2FIX(1) /* '~' */, + INT2FIX(0x01 | (node->nd_nth << 1))); + break; } case NODE_MATCH: case NODE_MATCH2: case NODE_MATCH3:{ - DECL_ANCHOR(recv); - DECL_ANCHOR(val); - - switch(nd_type(node)) { - case NODE_MATCH: - ADD_INSN1(recv, nd_line(node), putobject, node->nd_lit); - ADD_INSN2(val, nd_line(node), getspecial, INT2FIX(0), - INT2FIX(0)); - break; - case NODE_MATCH2: - COMPILE(recv, "reciever", node->nd_recv); - COMPILE(val, "value", node->nd_value); - break; - case NODE_MATCH3: - COMPILE(recv, "reciever", node->nd_value); - COMPILE(val, "value", node->nd_recv); - break; - } + DECL_ANCHOR(recv); + DECL_ANCHOR(val); + + switch(nd_type(node)) { + case NODE_MATCH: + ADD_INSN1(recv, nd_line(node), putobject, node->nd_lit); + ADD_INSN2(val, nd_line(node), getspecial, INT2FIX(0), + INT2FIX(0)); + break; + case NODE_MATCH2: + COMPILE(recv, "reciever", node->nd_recv); + COMPILE(val, "value", node->nd_value); + break; + case NODE_MATCH3: + COMPILE(recv, "reciever", node->nd_value); + COMPILE(val, "value", node->nd_recv); + break; + } - if (iseq->compile_data->option->specialized_instruction) { - /* TODO: detect by node */ - if (recv->last == recv->anchor.next && - INSN_OF(recv->last) == BIN(putobject) && - nd_type(node) == NODE_MATCH2) { - ADD_SEQ(ret, val); - ADD_INSN1(ret, nd_line(node), opt_regexpmatch1, - OPERAND_AT(recv->last, 0)); - } - else { - ADD_SEQ(ret, recv); - ADD_SEQ(ret, val); - ADD_INSN(ret, nd_line(node), opt_regexpmatch2); - } - } - else { - ADD_SEQ(ret, recv); - ADD_SEQ(ret, val); - ADD_SEND(ret, nd_line(node), ID2SYM(idEqTilde), INT2FIX(1)); - } + if (iseq->compile_data->option->specialized_instruction) { + /* TODO: detect by node */ + if (recv->last == recv->anchor.next && + INSN_OF(recv->last) == BIN(putobject) && + nd_type(node) == NODE_MATCH2) { + ADD_SEQ(ret, val); + ADD_INSN1(ret, nd_line(node), opt_regexpmatch1, + OPERAND_AT(recv->last, 0)); + } + else { + ADD_SEQ(ret, recv); + ADD_SEQ(ret, val); + ADD_INSN(ret, nd_line(node), opt_regexpmatch2); + } + } + else { + ADD_SEQ(ret, recv); + ADD_SEQ(ret, val); + ADD_SEND(ret, nd_line(node), ID2SYM(idEqTilde), INT2FIX(1)); + } - if (poped) { - ADD_INSN(ret, nd_line(node), pop); - } - break; + if (poped) { + ADD_INSN(ret, nd_line(node), pop); + } + break; } case NODE_LIT:{ - debugp_param("lit", node->nd_lit); - if (!poped) { - ADD_INSN1(ret, nd_line(node), putobject, node->nd_lit); - } - break; + debugp_param("lit", node->nd_lit); + if (!poped) { + ADD_INSN1(ret, nd_line(node), putobject, node->nd_lit); + } + break; } case NODE_STR:{ - debugp_param("nd_lit", node->nd_lit); - if (!poped) { - ADD_INSN1(ret, nd_line(node), putstring, node->nd_lit); - } - break; + debugp_param("nd_lit", node->nd_lit); + if (!poped) { + ADD_INSN1(ret, nd_line(node), putstring, node->nd_lit); + } + break; } case NODE_DSTR:{ - compile_dstr(iseq, ret, node); + compile_dstr(iseq, ret, node); - if (poped) { - ADD_INSN(ret, nd_line(node), pop); - } - break; + if (poped) { + ADD_INSN(ret, nd_line(node), pop); + } + break; } case NODE_XSTR:{ - ADD_CALL_RECEIVER(ret, nd_line(node)); - ADD_INSN1(ret, nd_line(node), putobject, node->nd_lit); - ADD_CALL(ret, nd_line(node), ID2SYM(idBackquote), INT2FIX(1)); + ADD_CALL_RECEIVER(ret, nd_line(node)); + ADD_INSN1(ret, nd_line(node), putobject, node->nd_lit); + ADD_CALL(ret, nd_line(node), ID2SYM(idBackquote), INT2FIX(1)); - if (poped) { - ADD_INSN(ret, nd_line(node), pop); - } - break; + if (poped) { + ADD_INSN(ret, nd_line(node), pop); + } + break; } case NODE_DXSTR:{ - ADD_CALL_RECEIVER(ret, nd_line(node)); - compile_dstr(iseq, ret, node); - ADD_CALL(ret, nd_line(node), ID2SYM(idBackquote), INT2FIX(1)); + ADD_CALL_RECEIVER(ret, nd_line(node)); + compile_dstr(iseq, ret, node); + ADD_CALL(ret, nd_line(node), ID2SYM(idBackquote), INT2FIX(1)); - if (poped) { - ADD_INSN(ret, nd_line(node), pop); - } - break; + if (poped) { + ADD_INSN(ret, nd_line(node), pop); + } + break; } case NODE_EVSTR:{ - COMPILE(ret, "nd_body", node->nd_body); + COMPILE(ret, "nd_body", node->nd_body); - if (poped) { - ADD_INSN(ret, nd_line(node), pop); - } - else { - ADD_INSN(ret, nd_line(node), tostring); - } - break; + if (poped) { + ADD_INSN(ret, nd_line(node), pop); + } + else { + ADD_INSN(ret, nd_line(node), tostring); + } + break; } case NODE_DREGX:{ - compile_dstr(iseq, ret, node); - ADD_INSN1(ret, nd_line(node), toregexp, INT2FIX(node->nd_cflag)); + compile_dstr(iseq, ret, node); + ADD_INSN1(ret, nd_line(node), toregexp, INT2FIX(node->nd_cflag)); - if (poped) { - ADD_INSN(ret, nd_line(node), pop); - } - break; + if (poped) { + ADD_INSN(ret, nd_line(node), pop); + } + break; } case NODE_DREGX_ONCE:{ - /* fix me: once? */ - LABEL *lstart = NEW_LABEL(nd_line(node)); - LABEL *lend = NEW_LABEL(nd_line(node)); + /* fix me: once? */ + LABEL *lstart = NEW_LABEL(nd_line(node)); + LABEL *lend = NEW_LABEL(nd_line(node)); - ADD_LABEL(ret, lstart); - ADD_INSN2(ret, nd_line(node), onceinlinecache, - NEW_INLINE_CACHE_ENTRY(), lend); - ADD_INSN(ret, nd_line(node), pop); + ADD_LABEL(ret, lstart); + ADD_INSN2(ret, nd_line(node), onceinlinecache, + NEW_INLINE_CACHE_ENTRY(), lend); + ADD_INSN(ret, nd_line(node), pop); - compile_dstr(iseq, ret, node); - ADD_INSN1(ret, nd_line(node), toregexp, INT2FIX(node->nd_cflag)); + compile_dstr(iseq, ret, node); + ADD_INSN1(ret, nd_line(node), toregexp, INT2FIX(node->nd_cflag)); - ADD_INSN1(ret, nd_line(node), setinlinecache, lstart); - ADD_LABEL(ret, lend); + ADD_INSN1(ret, nd_line(node), setinlinecache, lstart); + ADD_LABEL(ret, lend); - if (poped) { - ADD_INSN(ret, nd_line(node), pop); - } - break; + if (poped) { + ADD_INSN(ret, nd_line(node), pop); + } + break; } case NODE_ARGS:{ - /* OK */ - COMPILE_ERROR(("BUG: should not reach here: compile_each#NODE_ARGS")); - break; + /* OK */ + COMPILE_ERROR(("BUG: should not reach here: compile_each#NODE_ARGS")); + break; } case NODE_ARGSCAT:{ - COMPILE(ret, "argscat head", node->nd_head); - COMPILE(ret, "argscat body", node->nd_body); - ADD_INSN(ret, nd_line(node), concatarray); - break; + COMPILE(ret, "argscat head", node->nd_head); + COMPILE(ret, "argscat body", node->nd_body); + ADD_INSN(ret, nd_line(node), concatarray); + break; } case NODE_ARGSPUSH:{ - COMPILE(ret, "arsgpush head", node->nd_head); - COMPILE(ret, "argspush body", node->nd_body); - ADD_INSN1(ret, nd_line(node), newarray, INT2FIX(1)); - ADD_INSN(ret, nd_line(node), concatarray); - break; + COMPILE(ret, "arsgpush head", node->nd_head); + COMPILE(ret, "argspush body", node->nd_body); + ADD_INSN1(ret, nd_line(node), newarray, INT2FIX(1)); + ADD_INSN(ret, nd_line(node), concatarray); + break; } case NODE_SPLAT:{ - COMPILE(ret, "splat", node->nd_head); - ADD_INSN1(ret, nd_line(node), splatarray, Qfalse); - break; + COMPILE(ret, "splat", node->nd_head); + ADD_INSN1(ret, nd_line(node), splatarray, Qfalse); + break; } case NODE_TO_ARY:{ - /* OK */ - COMPILE_ERROR(("BUG: unknown node: NODE_TO_ARY")); - break; + /* OK */ + COMPILE_ERROR(("BUG: unknown node: NODE_TO_ARY")); + break; } case NODE_BLOCK_PASS:{ - /* OK */ - COMPILE_ERROR(("BUG: unknown node: NODE_BLOCK_PASS")); - break; + /* OK */ + COMPILE_ERROR(("BUG: unknown node: NODE_BLOCK_PASS")); + break; } case NODE_DEFN:{ - VALUE iseqval = NEW_ISEQVAL(node->nd_defn, - rb_str_new2(rb_id2name(node->nd_mid)), - ISEQ_TYPE_METHOD); + VALUE iseqval = NEW_ISEQVAL(node->nd_defn, + rb_str_new2(rb_id2name(node->nd_mid)), + ISEQ_TYPE_METHOD); - debugp_param("defn/iseq", iseqval); + debugp_param("defn/iseq", iseqval); - ADD_INSN (ret, nd_line(node), putnil); - ADD_INSN3(ret, nd_line(node), definemethod, - ID2SYM(node->nd_mid), iseqval, INT2FIX(0)); - if (!poped) { - ADD_INSN(ret, nd_line(node), putnil); - } - debugp_param("defn", iseqval); - break; + ADD_INSN (ret, nd_line(node), putnil); + ADD_INSN3(ret, nd_line(node), definemethod, + ID2SYM(node->nd_mid), iseqval, INT2FIX(0)); + if (!poped) { + ADD_INSN(ret, nd_line(node), putnil); + } + debugp_param("defn", iseqval); + break; } case NODE_DEFS:{ - VALUE iseqval = NEW_ISEQVAL(node->nd_defn, - rb_str_new2(rb_id2name(node->nd_mid)), - ISEQ_TYPE_METHOD); + VALUE iseqval = NEW_ISEQVAL(node->nd_defn, + rb_str_new2(rb_id2name(node->nd_mid)), + ISEQ_TYPE_METHOD); - debugp_param("defs/iseq", iseqval); + debugp_param("defs/iseq", iseqval); - COMPILE(ret, "defs: recv", node->nd_recv); - ADD_INSN3(ret, nd_line(node), definemethod, - ID2SYM(node->nd_mid), iseqval, INT2FIX(1)); - if (!poped) { - ADD_INSN(ret, nd_line(node), putnil); - } - break; + COMPILE(ret, "defs: recv", node->nd_recv); + ADD_INSN3(ret, nd_line(node), definemethod, + ID2SYM(node->nd_mid), iseqval, INT2FIX(1)); + if (!poped) { + ADD_INSN(ret, nd_line(node), putnil); + } + break; } case NODE_ALIAS:{ - VALUE s1, s2; + VALUE s1, s2; - if (nd_type(node->u1.node) != NODE_LIT || - nd_type(node->u2.node) != NODE_LIT) { - rb_bug("alias args must be NODE_LIT"); - } - s1 = node->u1.node->nd_lit; - s2 = node->u2.node->nd_lit; + if (nd_type(node->u1.node) != NODE_LIT || + nd_type(node->u2.node) != NODE_LIT) { + rb_bug("alias args must be NODE_LIT"); + } + s1 = node->u1.node->nd_lit; + s2 = node->u2.node->nd_lit; - ADD_INSN3(ret, nd_line(node), alias, Qfalse, ID2SYM(rb_to_id(s1)), - ID2SYM(rb_to_id(s2))); - if (!poped) { - ADD_INSN(ret, nd_line(node), putnil); - } - break; + ADD_INSN3(ret, nd_line(node), alias, Qfalse, ID2SYM(rb_to_id(s1)), + ID2SYM(rb_to_id(s2))); + if (!poped) { + ADD_INSN(ret, nd_line(node), putnil); + } + break; } case NODE_VALIAS:{ - ADD_INSN3(ret, nd_line(node), alias, Qtrue, ID2SYM(node->u1.id), - ID2SYM(node->u2.id)); - if (!poped) { - ADD_INSN(ret, nd_line(node), putnil); - } - break; + ADD_INSN3(ret, nd_line(node), alias, Qtrue, ID2SYM(node->u1.id), + ID2SYM(node->u2.id)); + if (!poped) { + ADD_INSN(ret, nd_line(node), putnil); + } + break; } case NODE_UNDEF:{ - if (nd_type(node->u2.node) != NODE_LIT) { - rb_bug("undef args must be NODE_LIT"); - } - ADD_INSN1(ret, nd_line(node), undef, - ID2SYM(rb_to_id(node->u2.node->nd_lit))); - if (!poped) { - ADD_INSN(ret, nd_line(node), putnil); - } - break; + if (nd_type(node->u2.node) != NODE_LIT) { + rb_bug("undef args must be NODE_LIT"); + } + ADD_INSN1(ret, nd_line(node), undef, + ID2SYM(rb_to_id(node->u2.node->nd_lit))); + if (!poped) { + ADD_INSN(ret, nd_line(node), putnil); + } + break; } case NODE_CLASS:{ - VALUE iseqval = + VALUE iseqval = NEW_CHILD_ISEQVAL( node->nd_body, make_name_with_str("<class:%s>", rb_id2name(node->nd_cpath->nd_mid)), ISEQ_TYPE_CLASS); - compile_cpath(ret, iseq, node->nd_cpath); - COMPILE(ret, "super", node->nd_super); - ADD_INSN3(ret, nd_line(node), defineclass, - ID2SYM(node->nd_cpath->nd_mid), iseqval, INT2FIX(0)); + compile_cpath(ret, iseq, node->nd_cpath); + COMPILE(ret, "super", node->nd_super); + ADD_INSN3(ret, nd_line(node), defineclass, + ID2SYM(node->nd_cpath->nd_mid), iseqval, INT2FIX(0)); - if (poped) { - ADD_INSN(ret, nd_line(node), pop); - } - break; + if (poped) { + ADD_INSN(ret, nd_line(node), pop); + } + break; } case NODE_MODULE:{ - VALUE iseqval = NEW_CHILD_ISEQVAL(node->nd_body, - make_name_with_str - ("<module:%s>", - rb_id2name(node->nd_cpath-> - nd_mid)), - ISEQ_TYPE_CLASS); - - COMPILE(ret, "mbase", node->nd_cpath->nd_head); - ADD_INSN (ret, nd_line(node), putnil); /* dummy */ - ADD_INSN3(ret, nd_line(node), defineclass, - ID2SYM(node->nd_cpath->nd_mid), iseqval, INT2FIX(2)); - if (poped) { - ADD_INSN(ret, nd_line(node), pop); - } - break; + VALUE iseqval = NEW_CHILD_ISEQVAL(node->nd_body, + make_name_with_str + ("<module:%s>", + rb_id2name(node->nd_cpath-> + nd_mid)), + ISEQ_TYPE_CLASS); + + COMPILE(ret, "mbase", node->nd_cpath->nd_head); + ADD_INSN (ret, nd_line(node), putnil); /* dummy */ + ADD_INSN3(ret, nd_line(node), defineclass, + ID2SYM(node->nd_cpath->nd_mid), iseqval, INT2FIX(2)); + if (poped) { + ADD_INSN(ret, nd_line(node), pop); + } + break; } case NODE_SCLASS:{ - VALUE iseqval = + VALUE iseqval = NEW_ISEQVAL(node->nd_body, rb_str_new2("singletonclass"), ISEQ_TYPE_CLASS); - COMPILE(ret, "sclass#recv", node->nd_recv); - ADD_INSN (ret, nd_line(node), putnil); - ADD_INSN3(ret, nd_line(node), defineclass, - ID2SYM(rb_intern("singletonclass")), iseqval, INT2FIX(1)); + COMPILE(ret, "sclass#recv", node->nd_recv); + ADD_INSN (ret, nd_line(node), putnil); + ADD_INSN3(ret, nd_line(node), defineclass, + ID2SYM(rb_intern("singletonclass")), iseqval, INT2FIX(1)); - if (poped) { - ADD_INSN(ret, nd_line(node), pop); - } - break; + if (poped) { + ADD_INSN(ret, nd_line(node), pop); + } + break; } case NODE_COLON2:{ - if (rb_is_const_id(node->nd_mid)) { - /* constant */ - LABEL *lstart = NEW_LABEL(nd_line(node)); - LABEL *lend = NEW_LABEL(nd_line(node)); - DECL_ANCHOR(pref); - DECL_ANCHOR(body); - - compile_colon2(iseq, node, pref, body); - if (LIST_SIZE_ZERO(pref)) { - if (iseq->compile_data->option->inline_const_cache) { - ADD_LABEL(ret, lstart); - ADD_INSN2(ret, nd_line(node), getinlinecache, - NEW_INLINE_CACHE_ENTRY(), lend); - } - else { - ADD_INSN(ret, nd_line(node), putnil); - } - - ADD_SEQ(ret, body); - - if (iseq->compile_data->option->inline_const_cache) { - ADD_INSN1(ret, nd_line(node), setinlinecache, lstart); - ADD_LABEL(ret, lend); - } - } - else { - ADD_SEQ(ret, pref); - ADD_SEQ(ret, body); - } - } - else { - /* function call */ - ADD_CALL_RECEIVER(ret, nd_line(node)); - COMPILE(ret, "colon2#nd_head", node->nd_head); - ADD_CALL(ret, nd_line(node), ID2SYM(node->nd_mid), - INT2FIX(1)); - } - if (poped) { - ADD_INSN(ret, nd_line(node), pop); - } - break; + if (rb_is_const_id(node->nd_mid)) { + /* constant */ + LABEL *lstart = NEW_LABEL(nd_line(node)); + LABEL *lend = NEW_LABEL(nd_line(node)); + DECL_ANCHOR(pref); + DECL_ANCHOR(body); + + compile_colon2(iseq, node, pref, body); + if (LIST_SIZE_ZERO(pref)) { + if (iseq->compile_data->option->inline_const_cache) { + ADD_LABEL(ret, lstart); + ADD_INSN2(ret, nd_line(node), getinlinecache, + NEW_INLINE_CACHE_ENTRY(), lend); + } + else { + ADD_INSN(ret, nd_line(node), putnil); + } + + ADD_SEQ(ret, body); + + if (iseq->compile_data->option->inline_const_cache) { + ADD_INSN1(ret, nd_line(node), setinlinecache, lstart); + ADD_LABEL(ret, lend); + } + } + else { + ADD_SEQ(ret, pref); + ADD_SEQ(ret, body); + } + } + else { + /* function call */ + ADD_CALL_RECEIVER(ret, nd_line(node)); + COMPILE(ret, "colon2#nd_head", node->nd_head); + ADD_CALL(ret, nd_line(node), ID2SYM(node->nd_mid), + INT2FIX(1)); + } + if (poped) { + ADD_INSN(ret, nd_line(node), pop); + } + break; } case NODE_COLON3:{ - LABEL *lstart = NEW_LABEL(nd_line(node)); - LABEL *lend = NEW_LABEL(nd_line(node)); - debugi("colon3#nd_mid", node->nd_mid); - - /* add cache insn */ - if (iseq->compile_data->option->inline_const_cache) { - ADD_LABEL(ret, lstart); - ADD_INSN2(ret, nd_line(node), getinlinecache, - NEW_INLINE_CACHE_ENTRY(), lend); - ADD_INSN(ret, nd_line(node), pop); - } + LABEL *lstart = NEW_LABEL(nd_line(node)); + LABEL *lend = NEW_LABEL(nd_line(node)); + debugi("colon3#nd_mid", node->nd_mid); + + /* add cache insn */ + if (iseq->compile_data->option->inline_const_cache) { + ADD_LABEL(ret, lstart); + ADD_INSN2(ret, nd_line(node), getinlinecache, + NEW_INLINE_CACHE_ENTRY(), lend); + ADD_INSN(ret, nd_line(node), pop); + } - ADD_INSN1(ret, nd_line(node), putobject, rb_cObject); - ADD_INSN1(ret, nd_line(node), getconstant, ID2SYM(node->nd_mid)); + ADD_INSN1(ret, nd_line(node), putobject, rb_cObject); + ADD_INSN1(ret, nd_line(node), getconstant, ID2SYM(node->nd_mid)); - if (iseq->compile_data->option->inline_const_cache) { - ADD_INSN1(ret, nd_line(node), setinlinecache, lstart); - ADD_LABEL(ret, lend); - } + if (iseq->compile_data->option->inline_const_cache) { + ADD_INSN1(ret, nd_line(node), setinlinecache, lstart); + ADD_LABEL(ret, lend); + } - if (poped) { - ADD_INSN(ret, nd_line(node), pop); - } - break; + if (poped) { + ADD_INSN(ret, nd_line(node), pop); + } + break; } case NODE_CREF:{ - /* OK */ - COMPILE_ERROR(("BUG: unknown node: NODE_CREF")); - break; + /* OK */ + COMPILE_ERROR(("BUG: unknown node: NODE_CREF")); + break; } case NODE_DOT2: case NODE_DOT3:{ - int flag = type == NODE_DOT2 ? INT2FIX(0) : INT2FIX(1); - COMPILE(ret, "min", (NODE *) node->nd_beg); - COMPILE(ret, "max", (NODE *) node->nd_end); - if (poped) { - ADD_INSN(ret, nd_line(node), pop); - ADD_INSN(ret, nd_line(node), pop); - } - else { - ADD_INSN1(ret, nd_line(node), newrange, flag); - } - break; + int flag = type == NODE_DOT2 ? INT2FIX(0) : INT2FIX(1); + COMPILE(ret, "min", (NODE *) node->nd_beg); + COMPILE(ret, "max", (NODE *) node->nd_end); + if (poped) { + ADD_INSN(ret, nd_line(node), pop); + ADD_INSN(ret, nd_line(node), pop); + } + else { + ADD_INSN1(ret, nd_line(node), newrange, flag); + } + break; } case NODE_FLIP2: case NODE_FLIP3:{ - LABEL *lend = NEW_LABEL(nd_line(node)); - LABEL *lfin = NEW_LABEL(nd_line(node)); - LABEL *ltrue = NEW_LABEL(nd_line(node)); - - ADD_INSN2(ret, nd_line(node), getspecial, INT2FIX(node->nd_cnt), - INT2FIX(0)); - ADD_INSNL(ret, nd_line(node), branchif, lend); - - /* *flip == 0 */ - COMPILE(ret, "flip2 beg", node->nd_beg); - ADD_INSN(ret, nd_line(node), dup); - ADD_INSNL(ret, nd_line(node), branchunless, lfin); - if (nd_type(node) == NODE_FLIP3) { - ADD_INSN(ret, nd_line(node), dup); - ADD_INSN1(ret, nd_line(node), setspecial, INT2FIX(node->nd_cnt)); - ADD_INSNL(ret, nd_line(node), jump, lfin); - } - else { - ADD_INSN1(ret, nd_line(node), setspecial, INT2FIX(node->nd_cnt)); - } + LABEL *lend = NEW_LABEL(nd_line(node)); + LABEL *lfin = NEW_LABEL(nd_line(node)); + LABEL *ltrue = NEW_LABEL(nd_line(node)); + + ADD_INSN2(ret, nd_line(node), getspecial, INT2FIX(node->nd_cnt), + INT2FIX(0)); + ADD_INSNL(ret, nd_line(node), branchif, lend); + + /* *flip == 0 */ + COMPILE(ret, "flip2 beg", node->nd_beg); + ADD_INSN(ret, nd_line(node), dup); + ADD_INSNL(ret, nd_line(node), branchunless, lfin); + if (nd_type(node) == NODE_FLIP3) { + ADD_INSN(ret, nd_line(node), dup); + ADD_INSN1(ret, nd_line(node), setspecial, INT2FIX(node->nd_cnt)); + ADD_INSNL(ret, nd_line(node), jump, lfin); + } + else { + ADD_INSN1(ret, nd_line(node), setspecial, INT2FIX(node->nd_cnt)); + } - /* *flip == 1 */ - ADD_LABEL(ret, lend); - COMPILE(ret, "flip2 end", node->nd_end); - ADD_INSNL(ret, nd_line(node), branchunless, ltrue); - ADD_INSN1(ret, nd_line(node), putobject, Qfalse); - ADD_INSN1(ret, nd_line(node), setspecial, INT2FIX(node->nd_cnt)); + /* *flip == 1 */ + ADD_LABEL(ret, lend); + COMPILE(ret, "flip2 end", node->nd_end); + ADD_INSNL(ret, nd_line(node), branchunless, ltrue); + ADD_INSN1(ret, nd_line(node), putobject, Qfalse); + ADD_INSN1(ret, nd_line(node), setspecial, INT2FIX(node->nd_cnt)); - ADD_LABEL(ret, ltrue); - ADD_INSN1(ret, nd_line(node), putobject, Qtrue); + ADD_LABEL(ret, ltrue); + ADD_INSN1(ret, nd_line(node), putobject, Qtrue); - ADD_LABEL(ret, lfin); - break; + ADD_LABEL(ret, lfin); + break; } case NODE_ATTRSET:{ - /* OK */ - COMPILE_ERROR(("BUG: unknown node: NODE_ATTRSET")); - break; + /* OK */ + COMPILE_ERROR(("BUG: unknown node: NODE_ATTRSET")); + break; } case NODE_SELF:{ - if (!poped) { - ADD_INSN(ret, nd_line(node), putself); - } + if (!poped) { + ADD_INSN(ret, nd_line(node), putself); + } - break; + break; } case NODE_NIL:{ - if (!poped) { - ADD_INSN(ret, nd_line(node), putnil); - } - break; + if (!poped) { + ADD_INSN(ret, nd_line(node), putnil); + } + break; } case NODE_TRUE:{ - if (!poped) { - ADD_INSN1(ret, nd_line(node), putobject, Qtrue); - } - break; + if (!poped) { + ADD_INSN1(ret, nd_line(node), putobject, Qtrue); + } + break; } case NODE_FALSE:{ - if (!poped) { - ADD_INSN1(ret, nd_line(node), putobject, Qfalse); - } - break; + if (!poped) { + ADD_INSN1(ret, nd_line(node), putobject, Qfalse); + } + break; } case NODE_ERRINFO:{ - if (!poped) { - if (iseq->type == ISEQ_TYPE_RESCUE) { - ADD_INSN2(ret, nd_line(node), getdynamic, INT2FIX(1), - INT2FIX(0)); - } - else { - rb_iseq_t *ip = iseq; - int level = 0; - while (ip) { - if (ip->type == ISEQ_TYPE_RESCUE) { - break; - } - ip = ip->parent_iseq; - level++; - } - if (ip) { - ADD_INSN2(ret, nd_line(node), getdynamic, INT2FIX(1), - INT2FIX(level)); - } - else { - ADD_INSN(ret, nd_line(node), putnil); - } - } - } - break; + if (!poped) { + if (iseq->type == ISEQ_TYPE_RESCUE) { + ADD_INSN2(ret, nd_line(node), getdynamic, INT2FIX(1), + INT2FIX(0)); + } + else { + rb_iseq_t *ip = iseq; + int level = 0; + while (ip) { + if (ip->type == ISEQ_TYPE_RESCUE) { + break; + } + ip = ip->parent_iseq; + level++; + } + if (ip) { + ADD_INSN2(ret, nd_line(node), getdynamic, INT2FIX(1), + INT2FIX(level)); + } + else { + ADD_INSN(ret, nd_line(node), putnil); + } + } + } + break; } case NODE_DEFINED:{ - if (!poped) { - LABEL *lfinish = NEW_LABEL(nd_line(node)); - defined_expr(iseq, ret, node->nd_head, lfinish, Qtrue); - ADD_LABEL(ret, lfinish); - } - break; + if (!poped) { + LABEL *lfinish = NEW_LABEL(nd_line(node)); + defined_expr(iseq, ret, node->nd_head, lfinish, Qtrue); + ADD_LABEL(ret, lfinish); + } + break; } case NODE_POSTEXE:{ - VALUE block = NEW_CHILD_ISEQVAL(node->nd_body, make_name_for_block(iseq), ISEQ_TYPE_BLOCK); - ADD_INSN1(ret, nd_line(node), postexe, block); - if (!poped) { - ADD_INSN(ret, nd_line(node), putnil); - } - break; + VALUE block = NEW_CHILD_ISEQVAL(node->nd_body, make_name_for_block(iseq), ISEQ_TYPE_BLOCK); + ADD_INSN1(ret, nd_line(node), postexe, block); + if (!poped) { + ADD_INSN(ret, nd_line(node), putnil); + } + break; } #ifdef C_ALLOCA case NODE_ALLOCA:{ - /* OK */ - COMPILE_ERROR(("BUG: unknown node: NODE_ALLOCA")); - break; + /* OK */ + COMPILE_ERROR(("BUG: unknown node: NODE_ALLOCA")); + break; } #endif case NODE_BMETHOD:{ - /* block method, OK */ - COMPILE_ERROR(("BUG: unknown node: NODE_BMETHOD")); - break; + /* block method, OK */ + COMPILE_ERROR(("BUG: unknown node: NODE_BMETHOD")); + break; } case NODE_MEMO:{ - /* OK */ - COMPILE_ERROR(("BUG: unknown node: NODE_MEMO")); - break; + /* OK */ + COMPILE_ERROR(("BUG: unknown node: NODE_MEMO")); + break; } case NODE_IFUNC:{ - /* OK */ - COMPILE_ERROR(("BUG: unknown node: NODE_IFUNC")); - break; + /* OK */ + COMPILE_ERROR(("BUG: unknown node: NODE_IFUNC")); + break; } case NODE_DSYM:{ - compile_dstr(iseq, ret, node); - if (!poped) { - ADD_SEND(ret, nd_line(node), ID2SYM(idIntern), INT2FIX(0)); - } - else { - ADD_INSN(ret, nd_line(node), pop); - } - break; + compile_dstr(iseq, ret, node); + if (!poped) { + ADD_SEND(ret, nd_line(node), ID2SYM(idIntern), INT2FIX(0)); + } + else { + ADD_INSN(ret, nd_line(node), pop); + } + break; } case NODE_ATTRASGN:{ - DECL_ANCHOR(recv); - DECL_ANCHOR(args); - VALUE flag = 0; - VALUE argc; + DECL_ANCHOR(recv); + DECL_ANCHOR(args); + VALUE flag = 0; + VALUE argc; - argc = setup_arg(iseq, args, node, &flag); + argc = setup_arg(iseq, args, node, &flag); - if (node->nd_recv == (NODE *) 1) { - ADD_INSN(recv, nd_line(node), putself); - } - else { - COMPILE(recv, "recv", node->nd_recv); - } + if (node->nd_recv == (NODE *) 1) { + ADD_INSN(recv, nd_line(node), putself); + } + else { + COMPILE(recv, "recv", node->nd_recv); + } - debugp_param("argc", argc); - debugp_param("nd_mid", ID2SYM(node->nd_mid)); + debugp_param("argc", argc); + debugp_param("nd_mid", ID2SYM(node->nd_mid)); - if (!poped) { - ADD_INSN(ret, nd_line(node), putnil); - ADD_SEQ(ret, recv); - ADD_SEQ(ret, args); - ADD_INSN1(ret, nd_line(node), setn, INT2FIX(FIX2INT(argc) + 1)); - } - else { - ADD_SEQ(ret, recv); - ADD_SEQ(ret, args); - } - ADD_SEND_R(ret, nd_line(node), ID2SYM(node->nd_mid), argc, 0, INT2FIX(flag)); - ADD_INSN(ret, nd_line(node), pop); + if (!poped) { + ADD_INSN(ret, nd_line(node), putnil); + ADD_SEQ(ret, recv); + ADD_SEQ(ret, args); + ADD_INSN1(ret, nd_line(node), setn, INT2FIX(FIX2INT(argc) + 1)); + } + else { + ADD_SEQ(ret, recv); + ADD_SEQ(ret, args); + } + ADD_SEND_R(ret, nd_line(node), ID2SYM(node->nd_mid), argc, 0, INT2FIX(flag)); + ADD_INSN(ret, nd_line(node), pop); - break; + break; } case NODE_OPTBLOCK:{ - /* for optimize */ - LABEL *redo_label = NEW_LABEL(0); - LABEL *next_label = NEW_LABEL(0); - - iseq->compile_data->start_label = next_label; - iseq->compile_data->redo_label = redo_label; - - ADD_LABEL(ret, redo_label); - COMPILE_(ret, "optblock body", node->nd_head, 1 /* pop */ ); - ADD_LABEL(ret, next_label); - ADD_INSN(ret, 0, opt_checkenv); - break; + /* for optimize */ + LABEL *redo_label = NEW_LABEL(0); + LABEL *next_label = NEW_LABEL(0); + + iseq->compile_data->start_label = next_label; + iseq->compile_data->redo_label = redo_label; + + ADD_LABEL(ret, redo_label); + COMPILE_(ret, "optblock body", node->nd_head, 1 /* pop */ ); + ADD_LABEL(ret, next_label); + ADD_INSN(ret, 0, opt_checkenv); + break; } case NODE_PRELUDE:{ - COMPILE_POPED(ret, "prelude", node->nd_head); - COMPILE_(ret, "body", node->nd_body, poped); - break; + COMPILE_POPED(ret, "prelude", node->nd_head); + COMPILE_(ret, "body", node->nd_body, poped); + break; } case NODE_LAMBDA:{ - /* compile same as lambda{...} */ - VALUE block = NEW_CHILD_ISEQVAL(node->nd_body, make_name_for_block(iseq), ISEQ_TYPE_BLOCK); - VALUE argc = INT2FIX(0); - ADD_CALL_RECEIVER(ret, nd_line(node)); - ADD_CALL_WITH_BLOCK(ret, nd_line(node), ID2SYM(idLambda), argc, block); - - if (poped) { - ADD_INSN(ret, nd_line(node), pop); - } - break; + /* compile same as lambda{...} */ + VALUE block = NEW_CHILD_ISEQVAL(node->nd_body, make_name_for_block(iseq), ISEQ_TYPE_BLOCK); + VALUE argc = INT2FIX(0); + ADD_CALL_RECEIVER(ret, nd_line(node)); + ADD_CALL_WITH_BLOCK(ret, nd_line(node), ID2SYM(idLambda), argc, block); + + if (poped) { + ADD_INSN(ret, nd_line(node), pop); + } + break; } default: COMPILE_ERROR(("BUG: unknown node (default): %s", ruby_node_name(type))); @@ -4565,7 +4578,8 @@ dump_disasm_list(struct iseq_link_element *link) while (link) { switch (link->type) { - case ISEQ_ELEMENT_INSN:{ + case ISEQ_ELEMENT_INSN: + { iobj = (INSN *)link; str = insn_data_to_s_detail(iobj); printf("%04d %-65s(%4d)\n", pos, StringValueCStr(str), @@ -4573,16 +4587,18 @@ dump_disasm_list(struct iseq_link_element *link) pos += insn_data_length(iobj); break; } - case ISEQ_ELEMENT_LABEL:{ + case ISEQ_ELEMENT_LABEL: + { lobj = (LABEL *)link; printf("<L%03d>\n", lobj->label_no); break; } - case ISEQ_ELEMENT_NONE:{ + case ISEQ_ELEMENT_NONE: + { printf("[none]\n"); break; } - default: + default: /* ignore */ printf("%ld\n", FIX2LONG(link->type)); rb_bug("dump_disasm_list error"); @@ -4829,11 +4845,11 @@ iseq_build_from_ary(rb_iseq_t *iseq, VALUE line, iseq->local_table_size = iseq->local_size; iseq->local_table = (ID *)ALLOC_N(ID *, iseq->local_size); tbl = iseq->local_table + opt; - + for (i=0; i<RARRAY_LEN(locals); i++) { tbl[i] = SYM2ID(RARRAY_PTR(locals)[i]); } - + /* args */ if (FIXNUM_P(args)) { iseq->argc = FIX2INT(args); @@ -4865,7 +4881,7 @@ iseq_build_from_ary(rb_iseq_t *iseq, VALUE line, iseq->arg_opt_tbl = (VALUE *)ALLOC_N(VALUE, iseq->arg_opts); for (i=0; i<RARRAY_LEN(arg_opt_labels); i++) { - iseq->arg_opt_tbl[i] = + iseq->arg_opt_tbl[i] = (VALUE)register_label(iseq, labels_table, rb_ary_entry(arg_opt_labels, i)); } @@ -4873,7 +4889,7 @@ iseq_build_from_ary(rb_iseq_t *iseq, VALUE line, /* exception */ iseq_build_exception(iseq, labels_table, exception); - + /* body */ iseq_build_body(iseq, anchor, body, line, labels_table); return iseq->self; @@ -1209,19 +1209,19 @@ glob_helper( p = p->next; } switch (p->type) { - case PLAIN: + case PLAIN: plain = 1; break; - case MAGICAL: + case MAGICAL: magical = 1; break; - case MATCH_ALL: + case MATCH_ALL: match_all = 1; break; - case MATCH_DIR: + case MATCH_DIR: match_dir = 1; break; - case RECURSIVE: + case RECURSIVE: rb_bug("continuous RECURSIVEs"); } } @@ -1593,7 +1593,7 @@ dir_globs(long argc, VALUE *argv, int flags) * Dir[ string [, string ...] ] => array * * Equivalent to calling - * <code>Dir.glob(</code><i>array,</i><code>0)</code> and + * <code>Dir.glob(</code><i>array,</i><code>0)</code> and * <code>Dir.glob([</code><i>string,...</i><code>],0)</code>. * */ @@ -340,9 +340,9 @@ rb_eval_cmd(VALUE cmd, VALUE arg, int level) /* * call-seq: * Module.nesting => array - * + * * Returns the list of +Modules+ nested at the point of call. - * + * * module M1 * module M2 * $a = Module.nesting @@ -371,14 +371,14 @@ rb_mod_nesting(void) /* * call-seq: * Module.constants => array - * + * * Returns an array of the names of all constants defined in the * system. This list includes the names of all modules and classes. - * + * * p Module.constants.sort[1..5] - * + * * <em>produces:</em> - * + * * ["ARGV", "ArgumentError", "Array", "Bignum", "Binding"] */ @@ -421,11 +421,11 @@ rb_frozen_class_p(VALUE klass) desc = "object"; else { switch (TYPE(klass)) { - case T_MODULE: - case T_ICLASS: + case T_MODULE: + case T_ICLASS: desc = "module"; break; - case T_CLASS: + case T_CLASS: desc = "class"; break; } @@ -437,7 +437,7 @@ rb_frozen_class_p(VALUE klass) /* * call-seq: * obj.respond_to?(symbol, include_private=false) => true or false - * + * * Returns +true+> if _obj_ responds to the given * method. Private methods are included in the search only if the * optional second parameter evaluates to +true+. @@ -472,7 +472,7 @@ rb_respond_to(VALUE obj, ID id) /* * call-seq: * obj.respond_to?(symbol, include_private=false) => true or false - * + * * Returns +true+> if _obj_ responds to the given * method. Private methods are included in the search only if the * optional second parameter evaluates to +true+. @@ -495,11 +495,11 @@ obj_respond_to(int argc, VALUE *argv, VALUE obj) /* * call-seq: * mod.method_defined?(symbol) => true or false - * + * * Returns +true+ if the named method is defined by * _mod_ (or its included modules and, if _mod_ is a class, * its ancestors). Public and protected methods are matched. - * + * * module A * def method1() end * end @@ -510,7 +510,7 @@ obj_respond_to(int argc, VALUE *argv, VALUE obj) * include A * def method3() end * end - * + * * A.method_defined? :method1 #=> true * C.method_defined? "method1" #=> true * C.method_defined? "method2" #=> true @@ -530,11 +530,11 @@ rb_mod_method_defined(mod, mid) /* * call-seq: * mod.public_method_defined?(symbol) => true or false - * + * * Returns +true+ if the named public method is defined by * _mod_ (or its included modules and, if _mod_ is a class, * its ancestors). - * + * * module A * def method1() end * end @@ -546,7 +546,7 @@ rb_mod_method_defined(mod, mid) * include A * def method3() end * end - * + * * A.method_defined? :method1 #=> true * C.public_method_defined? "method1" #=> true * C.public_method_defined? "method2" #=> false @@ -570,11 +570,11 @@ rb_mod_public_method_defined(VALUE mod, VALUE mid) /* * call-seq: * mod.private_method_defined?(symbol) => true or false - * + * * Returns +true+ if the named private method is defined by * _ mod_ (or its included modules and, if _mod_ is a class, * its ancestors). - * + * * module A * def method1() end * end @@ -586,7 +586,7 @@ rb_mod_public_method_defined(VALUE mod, VALUE mid) * include A * def method3() end * end - * + * * A.method_defined? :method1 #=> true * C.private_method_defined? "method1" #=> false * C.private_method_defined? "method2" #=> true @@ -610,11 +610,11 @@ rb_mod_private_method_defined(VALUE mod, VALUE mid) /* * call-seq: * mod.protected_method_defined?(symbol) => true or false - * + * * Returns +true+ if the named protected method is defined * by _mod_ (or its included modules and, if _mod_ is a * class, its ancestors). - * + * * module A * def method1() end * end @@ -626,7 +626,7 @@ rb_mod_private_method_defined(VALUE mod, VALUE mid) * include A * def method3() end * end - * + * * A.method_defined? :method1 #=> true * C.protected_method_defined? "method1" #=> false * C.protected_method_defined? "method2" #=> true @@ -745,7 +745,7 @@ rb_interrupt() * fail * fail(string) * fail(exception [, string [, array]]) - * + * * With no arguments, raises the exception in <code>$!</code> or raises * a <code>RuntimeError</code> if <code>$!</code> is +nil+. * With a single +String+ argument, raises a @@ -756,7 +756,7 @@ rb_interrupt() * message associated with the exception, and the third parameter is an * array of callback information. Exceptions are caught by the * +rescue+ clause of <code>begin...end</code> blocks. - * + * * raise "Failed to create socket" * raise ArgumentError, "No parameters", caller */ @@ -787,10 +787,10 @@ rb_make_exception(int argc, VALUE *argv) mesg = Qnil; switch (argc) { - case 0: + case 0: mesg = Qnil; break; - case 1: + case 1: if (NIL_P(argv[0])) break; if (TYPE(argv[0]) == T_STRING) { @@ -800,8 +800,8 @@ rb_make_exception(int argc, VALUE *argv) n = 0; goto exception_call; - case 2: - case 3: + case 2: + case 3: n = 1; exception_call: exception = rb_intern("exception"); @@ -810,7 +810,7 @@ rb_make_exception(int argc, VALUE *argv) } mesg = rb_funcall(argv[0], exception, n, argv[1]); break; - default: + default: rb_raise(rb_eArgError, "wrong number of arguments"); break; } @@ -861,11 +861,11 @@ rb_iterator_p() * call-seq: * block_given? => true or false * iterator? => true or false - * + * * Returns <code>true</code> if <code>yield</code> would execute a * block in the current context. The <code>iterator?</code> form * is mildly deprecated. - * + * * def try * if block_given? * yield @@ -969,9 +969,9 @@ rb_yield_splat(VALUE values) /* * call-seq: * loop {|| block } - * + * * Repeatedly executes the block. - * + * * loop do * print "Input: " * line = gets @@ -1254,7 +1254,7 @@ stack_check(void) /* * call-seq: * obj.method_missing(symbol [, *args] ) => result - * + * * Invoked by Ruby when <i>obj</i> is sent a message it cannot handle. * <i>symbol</i> is the symbol for the method called, and <i>args</i> * are any arguments that were passed to it. By default, the interpreter @@ -1264,7 +1264,7 @@ stack_check(void) * a class <code>Roman</code>, which responds to methods with names * consisting of roman numerals, returning the corresponding integer * values. - * + * * class Roman * def romanToInt(str) * # ... @@ -1274,7 +1274,7 @@ stack_check(void) * romanToInt(str) * end * end - * + * * r = Roman.new * r.iv #=> 4 * r.xxiii #=> 23 @@ -1462,11 +1462,11 @@ send_funcall(int argc, VALUE *argv, VALUE recv, int scope) * call-seq: * obj.send(symbol [, args...]) => obj * obj.__send__(symbol [, args...]) => obj - * + * * Invokes the method identified by _symbol_, passing it any * arguments specified. You can use <code>__send__</code> if the name * +send+ clashes with an existing method in _obj_. - * + * * class Klass * def hello(*args) * "Hello " + args.join(' ') @@ -1494,12 +1494,12 @@ rb_f_send(int argc, VALUE *argv, VALUE recv) * call-seq: * obj.funcall(symbol [, args...]) => obj * obj.__send!(symbol [, args...]) => obj - * + * * Invokes the method identified by _symbol_, passing it any * arguments specified. Unlike send, which calls private methods only * when it is invoked in function call style, funcall always aware of * private methods. - * + * * 1.funcall(:puts, "hello") # prints "foo" */ @@ -1555,13 +1555,13 @@ backtrace(int lev) /* * call-seq: * caller(start=1) => array - * + * * Returns the current execution stack---an array containing strings in * the form ``<em>file:line</em>'' or ``<em>file:line: in * `method'</em>''. The optional _start_ parameter * determines the number of initial stack entries to omit from the * result. - * + * * def a(skip) * caller(skip) * end @@ -1710,7 +1710,7 @@ eval(VALUE self, VALUE src, VALUE scope, char *file, int line) VALUE iseqval; if (scope != Qnil) { - + if (CLASS_OF(scope) == rb_cBinding) { GetBindingPtr(scope, bind); envval = bind->env; @@ -1788,14 +1788,14 @@ eval(VALUE self, VALUE src, VALUE scope, char *file, int line) /* * call-seq: * eval(string [, binding [, filename [,lineno]]]) => obj - * + * * Evaluates the Ruby expression(s) in <em>string</em>. If * <em>binding</em> is given, the evaluation is performed in its * context. The binding may be a <code>Binding</code> object or a * <code>Proc</code> object. If the optional <em>filename</em> and * <em>lineno</em> parameters are present, they will be used when * reporting syntax errors. - * + * * def getBinding(str) * return binding * end @@ -1865,7 +1865,7 @@ exec_under(VALUE (*func) (VALUE), VALUE under, VALUE self, VALUE args) while (!RUBY_VM_NORMAL_ISEQ_P(cfp->iseq)) { cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp); } - + pcref = (NODE **) th_cfp_svar(cfp, -1); stored_cref = *pcref; *pcref = th_cref_push(th, under, NOEX_PUBLIC); @@ -1890,7 +1890,7 @@ static VALUE yield_under_i(VALUE arg) { int avalue = Qtrue; - + if (arg == Qundef) { avalue = Qfalse; } @@ -1974,7 +1974,7 @@ specific_eval(int argc, VALUE *argv, VALUE klass, VALUE self) * call-seq: * obj.instance_eval(string [, filename [, lineno]] ) => obj * obj.instance_eval {| | block } => obj - * + * * Evaluates a string containing Ruby source code, or the given block, * within the context of the receiver (_obj_). In order to set the * context, the variable +self+ is set to _obj_ while @@ -1983,7 +1983,7 @@ specific_eval(int argc, VALUE *argv, VALUE klass, VALUE self) * that takes a +String+, the optional second and third * parameters supply a filename and starting line number that are used * when reporting compilation errors. - * + * * class Klass * def initialize * @secret = 99 @@ -2010,12 +2010,12 @@ rb_obj_instance_eval(int argc, VALUE *argv, VALUE self) /* * call-seq: * obj.instance_exec(arg...) {|var...| block } => obj - * + * * Executes the given block within the context of the receiver * (_obj_). In order to set the context, the variable +self+ is set * to _obj_ while the code is executing, giving the code access to * _obj_'s instance variables. Arguments are passed as block parameters. - * + * * class Klass * def initialize * @secret = 99 @@ -2043,21 +2043,21 @@ rb_obj_instance_exec(int argc, VALUE *argv, VALUE self) * call-seq: * mod.class_eval(string [, filename [, lineno]]) => obj * mod.module_eval {|| block } => obj - * + * * Evaluates the string or block in the context of _mod_. This can * be used to add methods to a class. <code>module_eval</code> returns * the result of evaluating its argument. The optional _filename_ * and _lineno_ parameters set the text for error messages. - * + * * class Thing * end * a = %q{def hello() "Hello there!" end} * Thing.module_eval(a) * puts Thing.new.hello() * Thing.module_eval("invalid code", "dummy", 123) - * + * * <em>produces:</em> - * + * * Hello there! * dummy:123:in `module_eval': undefined local variable * or method `code' for Thing:Class @@ -2073,19 +2073,19 @@ rb_mod_module_eval(int argc, VALUE *argv, VALUE mod) * call-seq: * mod.module_exec(arg...) {|var...| block } => obj * mod.class_exec(arg...) {|var...| block } => obj - * + * * Evaluates the given block in the context of the class/module. * The method defined in the block will belong to the receiver. - * + * * class Thing * end * Thing.class_exec{ * def hello() "Hello there!" end * } * puts Thing.new.hello() - * + * * <em>produces:</em> - * + * * Hello there! */ @@ -2119,7 +2119,7 @@ set_method_visibility(VALUE self, int argc, VALUE *argv, ID ex) * call-seq: * public => self * public(symbol, ...) => self - * + * * With no arguments, sets the default visibility for subsequently * defined methods to public. With arguments, sets the named methods to * have public visibility. @@ -2142,7 +2142,7 @@ rb_mod_public(int argc, VALUE *argv, VALUE module) * call-seq: * protected => self * protected(symbol, ...) => self - * + * * With no arguments, sets the default visibility for subsequently * defined methods to protected. With arguments, sets the named methods * to have protected visibility. @@ -2165,11 +2165,11 @@ rb_mod_protected(int argc, VALUE *argv, VALUE module) * call-seq: * private => self * private(symbol, ...) => self - * + * * With no arguments, sets the default visibility for subsequently * defined methods to private. With arguments, sets the named methods * to have private visibility. - * + * * module Mod * def a() end * def b() end @@ -2196,7 +2196,7 @@ rb_mod_private(int argc, VALUE *argv, VALUE module) /* * call-seq: * mod.public_class_method(symbol, ...) => mod - * + * * Makes a list of existing class methods public. */ @@ -2210,10 +2210,10 @@ rb_mod_public_method(int argc, VALUE *argv, VALUE obj) /* * call-seq: * mod.private_class_method(symbol, ...) => mod - * + * * Makes existing class methods private. Often used to hide the default * constructor <code>new</code>. - * + * * class SimpleSingleton # Not thread safe * private_class_method :new * def SimpleSingleton.create(*args, &block) @@ -2234,7 +2234,7 @@ rb_mod_private_method(int argc, VALUE *argv, VALUE obj) * call-seq: * public * public(symbol, ...) - * + * * With no arguments, sets the default visibility for subsequently * defined methods to public. With arguments, sets the named methods to * have public visibility. @@ -2255,7 +2255,7 @@ top_private(int argc, VALUE *argv) /* * call-seq: * module_function(symbol, ...) => self - * + * * Creates module functions for the named methods. These functions may * be called with the module as a receiver, and also become available * as instance methods to classes that mix in the module. Module @@ -2263,7 +2263,7 @@ top_private(int argc, VALUE *argv) * independently. The instance-method versions are made private. If * used with no arguments, subsequently defined methods become module * functions. - * + * * module Mod * def one * "This is one" @@ -2335,7 +2335,7 @@ rb_mod_modfunc(int argc, VALUE *argv, VALUE module) /* * call-seq: * append_features(mod) => mod - * + * * When this module is included in another, Ruby calls * <code>append_features</code> in this module, passing it the * receiving module in _mod_. Ruby's default implementation is @@ -2348,10 +2348,10 @@ static VALUE rb_mod_append_features(VALUE module, VALUE include) { switch (TYPE(include)) { - case T_CLASS: - case T_MODULE: + case T_CLASS: + case T_MODULE: break; - default: + default: Check_Type(include, T_CLASS); break; } @@ -2363,7 +2363,7 @@ rb_mod_append_features(VALUE module, VALUE include) /* * call-seq: * include(module, ...) => self - * + * * Invokes <code>Module.append_features</code> on each parameter in turn. */ @@ -2397,11 +2397,11 @@ rb_extend_object(VALUE obj, VALUE module) /* * call-seq: * extend_object(obj) => obj - * + * * Extends the specified object by adding this module's constants and * methods (which are added as singleton methods). This is the callback * method used by <code>Object#extend</code>. - * + * * module Picky * def Picky.extend_object(o) * if String === o @@ -2414,9 +2414,9 @@ rb_extend_object(VALUE obj, VALUE module) * end * (s = Array.new).extend Picky # Call Object.extend * (s = "quick brown fox").extend Picky - * + * * <em>produces:</em> - * + * * Picky added to Array * Can't add Picky to a String */ @@ -2431,22 +2431,22 @@ rb_mod_extend_object(VALUE mod, VALUE obj) /* * call-seq: * obj.extend(module, ...) => obj - * + * * Adds to _obj_ the instance methods from each module given as a * parameter. - * + * * module Mod * def hello * "Hello from Mod.\n" * end * end - * + * * class Klass * def hello * "Hello from Klass.\n" * end * end - * + * * k = Klass.new * k.hello #=> "Hello from Klass.\n" * k.extend(Mod) #=> #<Klass:0x401b3bc8> @@ -2473,7 +2473,7 @@ rb_obj_extend(int argc, VALUE *argv, VALUE obj) /* * call-seq: * include(module, ...) => self - * + * * Invokes <code>Module.append_features</code> * on each parameter in turn. Effectively adds the methods and constants * in each module to the receiver. @@ -2572,9 +2572,9 @@ errat_setter(VALUE val, ID id, VALUE *var) /* * call-seq: * local_variables => array - * + * * Returns the names of the current local variables. - * + * * fred = 1 * for i in 1..10 * # ... @@ -2630,7 +2630,7 @@ rb_f_local_variables(void) /* * call-seq: * __method__ => symbol - * + * * Returns the name of the current method as a Symbol. * If called from inside of an aliased method it will return the original * nonaliased name. @@ -2655,7 +2655,7 @@ rb_f_method_name(void) /* * call-seq: * __callee__ => symbol - * + * * Returns the name of the current method as Symbol. * If called from inside of an aliased method it will return the aliased * name. @@ -2683,7 +2683,7 @@ Init_eval(void) { /* TODO: fix position */ GET_THREAD()->vm->mark_object_ary = rb_ary_new(); - + init = rb_intern("initialize"); eqq = rb_intern("==="); each = rb_intern("each"); @@ -2729,7 +2729,7 @@ Init_eval(void) rb_define_global_function("__method__", rb_f_method_name, 0); rb_define_global_function("__callee__", rb_f_callee_name, 0); - + rb_define_method(rb_cBasicObject, "send", rb_f_send, -1); rb_define_method(rb_cBasicObject, "__send__", rb_f_send, -1); rb_define_method(rb_cBasicObject, "__send", rb_f_send, -1); diff --git a/eval_jump.h b/eval_jump.h index 331bdbf6b1..ff45080178 100644 --- a/eval_jump.h +++ b/eval_jump.h @@ -9,7 +9,7 @@ NORETURN(static VALUE rb_f_throw _((int, VALUE *))); /* * call-seq: * throw(symbol [, obj]) - * + * * Transfers control to the end of the active +catch+ block * waiting for _symbol_. Raises +NameError+ if there * is no +catch+ block for the symbol. The optional second @@ -61,7 +61,7 @@ rb_throw(const char *tag, VALUE val) /* * call-seq: * catch(symbol) {| | block } > obj - * + * * +catch+ executes its block. If a +throw+ is * executed, Ruby searches up its stack for a +catch+ block * with a tag corresponding to the +throw+'s @@ -71,18 +71,18 @@ rb_throw(const char *tag, VALUE val) * the value of +catch+ is the value of the last expression * evaluated. +catch+ expressions may be nested, and the * +throw+ call need not be in lexical scope. - * + * * def routine(n) * puts n * throw :done if n <= 0 * routine(n-1) * end - * - * + * + * * catch(:done) { routine(3) } - * + * * <em>produces:</em> - * + * * 3 * 2 * 1 @@ -162,12 +162,12 @@ rb_exit(int status) * exit(integer=0) * Kernel::exit(integer=0) * Process::exit(integer=0) - * + * * Initiates the termination of the Ruby script by raising the * <code>SystemExit</code> exception. This exception may be caught. The * optional parameter is used to return a status code to the invoking * environment. - * + * * begin * exit * puts "never get here" @@ -175,22 +175,22 @@ rb_exit(int status) * puts "rescued a SystemExit exception" * end * puts "after begin block" - * + * * <em>produces:</em> - * + * * rescued a SystemExit exception * after begin block - * + * * Just prior to termination, Ruby executes any <code>at_exit</code> functions * (see Kernel::at_exit) and runs any object finalizers (see * ObjectSpace::define_finalizer). - * + * * at_exit { puts "at_exit function" } * ObjectSpace.define_finalizer("string", proc { puts "in finalizer" }) * exit - * + * * <em>produces:</em> - * + * * at_exit function * in finalizer */ @@ -204,13 +204,13 @@ rb_f_exit(int argc, VALUE *argv) rb_secure(4); if (rb_scan_args(argc, argv, "01", &status) == 1) { switch (status) { - case Qtrue: + case Qtrue: istatus = EXIT_SUCCESS; break; - case Qfalse: + case Qfalse: istatus = EXIT_FAILURE; break; - default: + default: istatus = NUM2INT(status); #if EXIT_SUCCESS != 0 if (istatus == 0) @@ -232,7 +232,7 @@ rb_f_exit(int argc, VALUE *argv) * abort * Kernel::abort * Process::abort - * + * * Terminate execution immediately, effectively by calling * <code>Kernel.exit(1)</code>. If _msg_ is given, it is written * to STDERR prior to terminating. @@ -272,21 +272,21 @@ call_end_proc(VALUE data) /* * call-seq: * at_exit { block } -> proc - * + * * Converts _block_ to a +Proc+ object (and therefore * binds it at the point of call) and registers it for execution when * the program exits. If multiple handlers are registered, they are * executed in reverse order of registration. - * + * * def do_at_exit(str1) * at_exit { print str1 } * end * at_exit { puts "cruel world" } * do_at_exit("goodbye ") * exit - * + * * <em>produces:</em> - * + * * goodbye cruel world */ diff --git a/eval_method.h b/eval_method.h index fb19af5f25..ac092d7bcc 100644 --- a/eval_method.h +++ b/eval_method.h @@ -317,7 +317,7 @@ rb_remove_method(VALUE klass, const char *name) /* * call-seq: * remove_method(symbol) => self - * + * * Removes the method identified by _symbol_ from the current * class. For an example, see <code>Module.undef_method</code>. */ @@ -460,8 +460,8 @@ rb_undef(VALUE klass, ID id) VALUE obj = rb_iv_get(klass, "__attached__"); switch (TYPE(obj)) { - case T_MODULE: - case T_CLASS: + case T_MODULE: + case T_CLASS: c = obj; s0 = ""; } @@ -487,12 +487,12 @@ rb_undef(VALUE klass, ID id) /* * call-seq: * undef_method(symbol) => self - * + * * Prevents the current class from responding to calls to the named * method. Contrast this with <code>remove_method</code>, which deletes * the method from the particular class; Ruby will still search * superclasses and mixed-in modules for a possible receiver. - * + * * class Parent * def hello * puts "In parent" @@ -503,25 +503,25 @@ rb_undef(VALUE klass, ID id) * puts "In child" * end * end - * - * + * + * * c = Child.new * c.hello - * - * + * + * * class Child * remove_method :hello # remove from child, still in parent * end * c.hello - * - * + * + * * class Child * undef_method :hello # prevent any calls to 'hello' * end * c.hello - * + * * <em>produces:</em> - * + * * In child * In parent * prog.rb:23: undefined method `hello' for #<Child:0x401b3bb4> (NoMethodError) @@ -563,7 +563,7 @@ rb_alias(VALUE klass, ID name, ID def) } orig_fbody->nd_cnt++; - + if (st_lookup(RCLASS(klass)->m_tbl, name, (st_data_t *) & node)) { if (node) { if (RTEST(ruby_verbose) && node->nd_cnt == 0 && node->nd_body) { @@ -594,10 +594,10 @@ rb_alias(VALUE klass, ID name, ID def) /* * call-seq: * alias_method(new_name, old_name) => self - * + * * Makes <i>new_name</i> a new copy of the method <i>old_name</i>. This can * be used to retain access to methods that are overridden. - * + * * module Mod * alias_method :orig_exit, :exit * def exit(code=0) @@ -607,9 +607,9 @@ rb_alias(VALUE klass, ID name, ID def) * end * include Mod * exit(99) - * + * * <em>produces:</em> - * + * * Exiting with code 99 */ @@ -1225,7 +1225,7 @@ flo_ceil(VALUE num) * * Rounds <i>flt</i> to a given precision in decimal digits (default 0 digits). * Precision may be negative. Returns a a floating point number when ndigits - * is more than one. + * is more than one. * * 1.5.round #=> 2 * (-1.5).round #=> -2 @@ -1624,7 +1624,7 @@ rb_num2ll(VALUE val) if (FIXNUM_P(val)) return (LONG_LONG)FIX2LONG(val); switch (TYPE(val)) { - case T_FLOAT: + case T_FLOAT: if (RFLOAT(val)->value <= (double)LLONG_MAX && RFLOAT(val)->value >= (double)LLONG_MIN) { return (LONG_LONG)(RFLOAT(val)->value); @@ -1638,21 +1638,21 @@ rb_num2ll(VALUE val) rb_raise(rb_eRangeError, "float %s out of range of long long", buf); } - case T_BIGNUM: + case T_BIGNUM: return rb_big2ll(val); - case T_STRING: + case T_STRING: rb_raise(rb_eTypeError, "no implicit conversion from string"); return Qnil; /* not reached */ - case T_TRUE: - case T_FALSE: + case T_TRUE: + case T_FALSE: rb_raise(rb_eTypeError, "no implicit conversion from boolean"); return Qnil; /* not reached */ default: - val = rb_to_int(val); - return NUM2LL(val); + val = rb_to_int(val); + return NUM2LL(val); } } @@ -1867,14 +1867,14 @@ static VALUE rb_int_induced_from(VALUE klass, VALUE x) { switch (TYPE(x)) { - case T_FIXNUM: - case T_BIGNUM: - return x; - case T_FLOAT: - return rb_funcall(x, id_to_i, 0); - default: - rb_raise(rb_eTypeError, "failed to convert %s into Integer", - rb_obj_classname(x)); + case T_FIXNUM: + case T_BIGNUM: + return x; + case T_FLOAT: + return rb_funcall(x, id_to_i, 0); + default: + rb_raise(rb_eTypeError, "failed to convert %s into Integer", + rb_obj_classname(x)); } } @@ -1889,14 +1889,14 @@ static VALUE rb_flo_induced_from(VALUE klass, VALUE x) { switch (TYPE(x)) { - case T_FIXNUM: - case T_BIGNUM: - return rb_funcall(x, rb_intern("to_f"), 0); - case T_FLOAT: - return x; - default: - rb_raise(rb_eTypeError, "failed to convert %s into Float", - rb_obj_classname(x)); + case T_FIXNUM: + case T_BIGNUM: + return rb_funcall(x, rb_intern("to_f"), 0); + case T_FLOAT: + return x; + default: + rb_raise(rb_eTypeError, "failed to convert %s into Float", + rb_obj_classname(x)); } } @@ -344,13 +344,13 @@ num2i32(VALUE x) } #if SIZEOF_LONG == SIZE32 -# define EXTEND32(x) +# define EXTEND32(x) #else /* invariant in modulo 1<<31 */ # define EXTEND32(x) do { if (!natint) {(x) = (((1L<<31)-1-(x))^~(~0L<<31));}} while(0) #endif #if SIZEOF_SHORT == SIZE16 -# define EXTEND16(x) +# define EXTEND16(x) #else # define EXTEND16(x) do { if (!natint) {(x) = (short)(((1<<15)-1-(x))^~(~0<<15));}} while(0) #endif @@ -371,7 +371,7 @@ static unsigned long utf8_to_uv(const char*,long*); /* * call-seq: * arr.pack ( aTemplateString ) -> aBinaryString - * + * * Packs the contents of <i>arr</i> into a binary sequence according to * the directives in <i>aTemplateString</i> (see the table below) * Directives ``A,'' ``a,'' and ``Z'' may be followed by a count, @@ -384,13 +384,13 @@ static unsigned long utf8_to_uv(const char*,long*); * platform's native size for the specified type; otherwise, they use a * platform-independent size. Spaces are ignored in the template * string. See also <code>String#unpack</code>. - * + * * a = [ "a", "b", "c" ] * n = [ 65, 66, 67 ] * a.pack("A3A3A3") #=> "a b c " * a.pack("a3a3a3") #=> "a\000\000b\000\000c\000\000" * n.pack("ccc") #=> "ABC" - * + * * Directives for +pack+. * * Directive Meaning @@ -1101,16 +1101,16 @@ static inline int hex2num(char c) { switch (c) { - case '0': case '1': case '2': case '3': case '4': - case '5': case '6': case '7': case '8': case '9': + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': return c - '0'; - case 'a': case 'b': case 'c': - case 'd': case 'e': case 'f': + case 'a': case 'b': case 'c': + case 'd': case 'e': case 'f': return c - 'a' + 10; - case 'A': case 'B': case 'C': - case 'D': case 'E': case 'F': + case 'A': case 'B': case 'C': + case 'D': case 'E': case 'F': return c - 'A' + 10; - default: + default: return -1; } } @@ -1145,11 +1145,11 @@ infected_str_new(const char *ptr, long len, VALUE str) OBJ_INFECT(s, str); return s; } - + /* * call-seq: * str.unpack(format) => anArray - * + * * Decodes <i>str</i> (which may contain binary data) according to the * format string, returning an array of each value extracted. The * format string consists of a sequence of single-character directives, @@ -1162,7 +1162,7 @@ infected_str_new(const char *ptr, long len, VALUE str) * platform's native size for the specified type; otherwise, it uses a * platform-independent consistent size. Spaces are ignored in the * format string. See also <code>Array#pack</code>. - * + * * "abc \0\0abc \0\0".unpack('A6Z6') #=> ["abc", "abc "] * "abc \0\0".unpack('a3a3') #=> ["abc", " \000\000"] * "abc \0abc \0".unpack('Z*Z*') #=> ["abc ", "abc "] @@ -1174,7 +1174,7 @@ infected_str_new(const char *ptr, long len, VALUE str) * * This table summarizes the various formats and the Ruby classes * returned by each. - * + * * Format | Returns | Function * -------+---------+----------------------------------------- * A | String | with trailing nulls and spaces removed @@ -1246,17 +1246,17 @@ infected_str_new(const char *ptr, long len, VALUE str) * p | String | treat sizeof(char *) characters as a * | | pointer to a null-terminated string * -------+---------+----------------------------------------- - * Q | Integer | treat 8 characters as an unsigned + * Q | Integer | treat 8 characters as an unsigned * | | quad word (64 bits) * -------+---------+----------------------------------------- - * q | Integer | treat 8 characters as a signed + * q | Integer | treat 8 characters as a signed * | | quad word (64 bits) * -------+---------+----------------------------------------- * S | Fixnum | treat two (different if _ used) * | | successive characters as an unsigned * | | short in native byte order * -------+---------+----------------------------------------- - * s | Fixnum | Treat two (different if _ used) + * s | Fixnum | Treat two (different if _ used) * | | successive characters as a signed short * | | in native byte order * -------+---------+----------------------------------------- @@ -1279,7 +1279,7 @@ infected_str_new(const char *ptr, long len, VALUE str) * Z | String | with trailing nulls removed * | | upto first null with * * -------+---------+----------------------------------------- - * @ | --- | skip to the offset given by the + * @ | --- | skip to the offset given by the * | | length argument * -------+---------+----------------------------------------- */ @@ -1574,7 +1574,7 @@ pack_unpack(VALUE str, VALUE fmt) } PACK_ITEM_ADJUST(); break; - case 'Q': + case 'Q': PACK_LENGTH_ADJUST_SIZE(QUAD_SIZE); while (len-- > 0) { char *tmp = (char*)s; @@ -1652,7 +1652,7 @@ pack_unpack(VALUE str, VALUE fmt) } PACK_ITEM_ADJUST(); break; - + case 'E': PACK_LENGTH_ADJUST(double,sizeof(double)); while (len-- > 0) { @@ -1666,7 +1666,7 @@ pack_unpack(VALUE str, VALUE fmt) } PACK_ITEM_ADJUST(); break; - + case 'D': case 'd': PACK_LENGTH_ADJUST(double,sizeof(double)); @@ -1692,7 +1692,7 @@ pack_unpack(VALUE str, VALUE fmt) } PACK_ITEM_ADJUST(); break; - + case 'G': PACK_LENGTH_ADJUST(double,sizeof(double)); while (len-- > 0) { @@ -1706,7 +1706,7 @@ pack_unpack(VALUE str, VALUE fmt) } PACK_ITEM_ADJUST(); break; - + case 'U': if (len > send - s) len = send - s; while (len > 0 && s < send) { @@ -171,7 +171,7 @@ vtable_add(struct vtable *tbl, ID id) rb_bug("vtable_add: vtable is not allocated (%p)", tbl); } if (VTBL_DEBUG) printf("vtable_add: %p, %s\n", tbl, rb_id2name(id)); - + if (tbl->pos == tbl->capa) { tbl->capa = tbl->capa * 2; REALLOC_N(tbl->tbl, ID, tbl->capa); @@ -4055,7 +4055,7 @@ f_norm_arg : tCONSTANT { /*%%%*/ yyerror("formal argument cannot be a constant"); - $$ = 0; + $$ = 0; /*% $$ = dispatch1(param_error, $1); %*/ @@ -4064,7 +4064,7 @@ f_norm_arg : tCONSTANT { /*%%%*/ yyerror("formal argument cannot be an instance variable"); - $$ = 0; + $$ = 0; /*% $$ = dispatch1(param_error, $1); %*/ @@ -4073,7 +4073,7 @@ f_norm_arg : tCONSTANT { /*%%%*/ yyerror("formal argument cannot be a global variable"); - $$ = 0; + $$ = 0; /*% $$ = dispatch1(param_error, $1); %*/ @@ -4082,7 +4082,7 @@ f_norm_arg : tCONSTANT { /*%%%*/ yyerror("formal argument cannot be a class variable"); - $$ = 0; + $$ = 0; /*% $$ = dispatch1(param_error, $1); %*/ @@ -4642,7 +4642,7 @@ rb_parser_compile_string(volatile VALUE vparser, const char *f, VALUE s, int lin struct parser_params *parser; NODE *node; volatile VALUE tmp; - + Data_Get_Struct(vparser, struct parser_params, parser); lex_gets = lex_get_str; lex_gets_ptr = 0; @@ -4688,7 +4688,7 @@ rb_parser_compile_file(volatile VALUE vparser, const char *f, VALUE file, int st struct parser_params *parser; volatile VALUE tmp; NODE *node; - + Data_Get_Struct(vparser, struct parser_params, parser); lex_gets = lex_io_gets; lex_input = file; @@ -5489,7 +5489,7 @@ parser_pragma(struct parser_params *parser, const char *str, int len) if (!(end = pragma_marker(beg, str + len - beg))) return Qfalse; str = beg; len = end - beg - 3; - + /* %r"([^\\s\'\":;]+)\\s*:\\s*(\"(?:\\\\.|[^\"])*\"|[^\"\\s;]+)[\\s;]*" */ while (len > 0) { #ifndef RIPPER @@ -6314,7 +6314,7 @@ parser_yylex(struct parser_params *parser) lex_state = EXPR_DOT; return tCOLON2; } - if (lex_state == EXPR_END || + if (lex_state == EXPR_END || lex_state == EXPR_ENDARG || ISSPACE(c)) { pushback(c); lex_state = EXPR_BEG; @@ -7915,7 +7915,7 @@ arg_dup_check(ID vid, VALUE m, VALUE list, NODE *node) ruby_sourceline = nd_line(node); return 1; } - rb_ary_push(list, sym); + rb_ary_push(list, sym); return 0; } @@ -8114,7 +8114,7 @@ rb_parser_append_print(NODE *node) NODE *prelude = 0; NODE *scope = node; node = node->nd_body; - + if (node && (nd_type(node) == NODE_PRELUDE)) { prelude = node; node = node->nd_body; @@ -8523,15 +8523,15 @@ symbols_i(VALUE sym, ID value, VALUE ary) /* * call-seq: * Symbol.all_symbols => array - * + * * Returns an array of all the symbols currently in Ruby's symbol * table. - * + * * Symbol.all_symbols.size #=> 903 * Symbol.all_symbols[1,20] #=> [:floor, :ARGV, :Binding, :symlink, - * :chown, :EOFError, :$;, :String, - * :LOCK_SH, :"setuid?", :$<, - * :default_proc, :compact, :extend, + * :chown, :EOFError, :$;, :String, + * :LOCK_SH, :"setuid?", :$<, + * :default_proc, :compact, :extend, * :Tms, :getwd, :$=, :ThreadGroup, * :wait2, :$>] */ @@ -172,115 +172,118 @@ rb_memsearch(const void *x0, long m, const void *y0, long n) static int reg_kcode = DEFAULT_KCODE; -static int char_to_option(int c) -{ - int val; - - switch (c) { - case 'i': - val = ONIG_OPTION_IGNORECASE; - break; - case 'x': - val = ONIG_OPTION_EXTEND; - break; - case 'm': - val = ONIG_OPTION_MULTILINE; - break; - default: - val = 0; - break; - } - return val; -} - -extern int rb_char_to_option_kcode(int c, int *option, int *kcode) -{ - *option = 0; - - switch (c) { - case 'n': - *kcode = ARG_KCODE_NONE; - break; - case 'e': - *kcode = ARG_KCODE_EUC; - break; - case 's': - *kcode = ARG_KCODE_SJIS; - break; - case 'u': - *kcode = ARG_KCODE_UTF8; - break; - default: - *kcode = 0; - *option = char_to_option(c); - break; - } +static int +char_to_option(int c) +{ + int val; - return ((*kcode == 0 && *option == 0) ? 0 : 1); + switch (c) { + case 'i': + val = ONIG_OPTION_IGNORECASE; + break; + case 'x': + val = ONIG_OPTION_EXTEND; + break; + case 'm': + val = ONIG_OPTION_MULTILINE; + break; + default: + val = 0; + break; + } + return val; } -static int char_to_arg_kcode(int c) +extern int +rb_char_to_option_kcode(int c, int *option, int *kcode) { - int kcode, option; + *option = 0; - if (ISUPPER(c)) c = tolower(c); + switch (c) { + case 'n': + *kcode = ARG_KCODE_NONE; + break; + case 'e': + *kcode = ARG_KCODE_EUC; + break; + case 's': + *kcode = ARG_KCODE_SJIS; + break; + case 'u': + *kcode = ARG_KCODE_UTF8; + break; + default: + *kcode = 0; + *option = char_to_option(c); + break; + } - (void )rb_char_to_option_kcode(c, &option, &kcode); - return kcode; + return ((*kcode == 0 && *option == 0) ? 0 : 1); +} + +static int +char_to_arg_kcode(int c) +{ + int kcode, option; + + if (ISUPPER(c)) c = tolower(c); + + (void )rb_char_to_option_kcode(c, &option, &kcode); + return kcode; } static int kcode_to_arg_value(unsigned int kcode) { - switch (kcode & KCODE_MASK) { - case KCODE_NONE: - return ARG_KCODE_NONE; - case KCODE_EUC: - return ARG_KCODE_EUC; - case KCODE_SJIS: - return ARG_KCODE_SJIS; - case KCODE_UTF8: - return ARG_KCODE_UTF8; - default: - return 0; - } + switch (kcode & KCODE_MASK) { + case KCODE_NONE: + return ARG_KCODE_NONE; + case KCODE_EUC: + return ARG_KCODE_EUC; + case KCODE_SJIS: + return ARG_KCODE_SJIS; + case KCODE_UTF8: + return ARG_KCODE_UTF8; + default: + return 0; + } } static void set_re_kcode_by_option(struct RRegexp *re, int options) { - switch (options & ARG_KCODE_MASK) { - case ARG_KCODE_NONE: - FL_UNSET(re, KCODE_MASK); - FL_SET(re, KCODE_FIXED); - break; - case ARG_KCODE_EUC: - FL_UNSET(re, KCODE_MASK); - FL_SET(re, KCODE_EUC); - FL_SET(re, KCODE_FIXED); - break; - case ARG_KCODE_SJIS: - FL_UNSET(re, KCODE_MASK); - FL_SET(re, KCODE_SJIS); - FL_SET(re, KCODE_FIXED); - break; - case ARG_KCODE_UTF8: - FL_UNSET(re, KCODE_MASK); - FL_SET(re, KCODE_UTF8); - FL_SET(re, KCODE_FIXED); - break; - - case 0: - default: - FL_SET(re, reg_kcode); - break; + switch (options & ARG_KCODE_MASK) { + case ARG_KCODE_NONE: + FL_UNSET(re, KCODE_MASK); + FL_SET(re, KCODE_FIXED); + break; + case ARG_KCODE_EUC: + FL_UNSET(re, KCODE_MASK); + FL_SET(re, KCODE_EUC); + FL_SET(re, KCODE_FIXED); + break; + case ARG_KCODE_SJIS: + FL_UNSET(re, KCODE_MASK); + FL_SET(re, KCODE_SJIS); + FL_SET(re, KCODE_FIXED); + break; + case ARG_KCODE_UTF8: + FL_UNSET(re, KCODE_MASK); + FL_SET(re, KCODE_UTF8); + FL_SET(re, KCODE_FIXED); + break; + + case 0: + default: + FL_SET(re, reg_kcode); + break; } } static int re_to_kcode_arg_value(VALUE re) { - return kcode_to_arg_value(RBASIC(re)->flags); + return kcode_to_arg_value(RBASIC(re)->flags); } static int curr_kcode; @@ -444,9 +447,9 @@ rb_reg_desc(const char *s, long len, VALUE re) /* * call-seq: * rxp.source => str - * + * * Returns the original string of the pattern. - * + * * /ab+c/ix.source #=> "ab+c" */ @@ -483,7 +486,7 @@ rb_reg_inspect(VALUE re) /* * call-seq: * rxp.to_s => str - * + * * Returns a string containing the regular expression and its options (using the * <code>(?xxx:yyy)</code> notation. This string can be fed back in to * <code>Regexp::new</code> to a regular expression with the same semantics as @@ -491,7 +494,7 @@ rb_reg_inspect(VALUE re) * comparing the two, as the source of the regular expression itself may * differ, as the example shows). <code>Regexp#inspect</code> produces a * generally more readable version of <i>rxp</i>. - * + * * r1 = /ab+c/ix #=> /ab+c/ix * s1 = r1.to_s #=> "(?ix-m:ab+c)" * r2 = Regexp.new(s1) #=> /(?ix-m:ab+c)/ @@ -606,7 +609,7 @@ rb_reg_raise(const char *s, long len, const char *err, VALUE re, int ce) /* * call-seq: * rxp.casefold? => true or false - * + * * Returns the value of the case-insensitive flag. */ @@ -622,22 +625,22 @@ rb_reg_casefold_p(VALUE re) /* * call-seq: * rxp.options => fixnum - * + * * Returns the set of bits corresponding to the options used when creating this * Regexp (see <code>Regexp::new</code> for details. Note that additional bits * may be set in the returned options: these are used internally by the regular * expression code. These extra bits are ignored if the options are passed to * <code>Regexp::new</code>. - * + * * Regexp::IGNORECASE #=> 1 * Regexp::EXTENDED #=> 2 * Regexp::MULTILINE #=> 4 - * + * * /cat/.options #=> 128 * /cat/ix.options #=> 131 * Regexp.new('cat', true).options #=> 129 * Regexp.new('cat', 0, 's').options #=> 384 - * + * * r = /cat/ix * Regexp.new(r.source, r.options) #=> /cat/ix */ @@ -653,7 +656,7 @@ rb_reg_options_m(VALUE re) /* * call-seq: * rxp.kcode => str - * + * * Returns the character set code for the regexp. */ @@ -769,9 +772,9 @@ match_init_copy(VALUE obj, VALUE orig) * call-seq: * mtch.length => integer * mtch.size => integer - * + * * Returns the number of elements in the match array. - * + * * m = /(.)(.)(\d+)(\d)/.match("THX1138.") * m.length #=> 5 * m.size #=> 5 @@ -787,10 +790,10 @@ match_size(VALUE match) /* * call-seq: * mtch.offset(n) => array - * + * * Returns a two-element array containing the beginning and ending offsets of * the <em>n</em>th match. - * + * * m = /(.)(.)(\d+)(\d)/.match("THX1138.") * m.offset(0) #=> [1, 7] * m.offset(4) #=> [6, 7] @@ -815,10 +818,10 @@ match_offset(VALUE match, VALUE n) /* * call-seq: * mtch.begin(n) => integer - * + * * Returns the offset of the start of the <em>n</em>th element of the match * array in the string. - * + * * m = /(.)(.)(\d+)(\d)/.match("THX1138.") * m.begin(0) #=> 1 * m.begin(2) #=> 2 @@ -842,10 +845,10 @@ match_begin(VALUE match, VALUE n) /* * call-seq: * mtch.end(n) => integer - * + * * Returns the offset of the character immediately following the end of the * <em>n</em>th element of the match array in the string. - * + * * m = /(.)(.)(\d+)(\d)/.match("THX1138.") * m.end(0) #=> 7 * m.end(2) #=> 3 @@ -1088,10 +1091,10 @@ rb_reg_last_match(VALUE match) /* * call-seq: * mtch.pre_match => str - * + * * Returns the portion of the original string before the current match. * Equivalent to the special variable <code>$`</code>. - * + * * m = /(.)(.)(\d+)(\d)/.match("THX1138.") * m.pre_match #=> "T" */ @@ -1112,10 +1115,10 @@ rb_reg_match_pre(VALUE match) /* * call-seq: * mtch.post_match => str - * + * * Returns the portion of the original string after the current match. * Equivalent to the special variable <code>$'</code>. - * + * * m = /(.)(.)(\d+)(\d)/.match("THX1138: The Movie") * m.post_match #=> ": The Movie" */ @@ -1203,18 +1206,18 @@ match_array(VALUE match, int start) /* * call-seq: * mtch.to_a => anArray - * + * * Returns the array of matches. - * + * * m = /(.)(.)(\d+)(\d)/.match("THX1138.") * m.to_a #=> ["HX1138", "H", "X", "113", "8"] - * + * * Because <code>to_a</code> is called when expanding * <code>*</code><em>variable</em>, there's a useful assignment * shortcut for extracting matched fields. This is slightly slower than * accessing the fields directly (as an intermediate array is * generated). - * + * * all,f1,f2,f3 = *(/(.)(.)(\d+)(\d)/.match("THX1138.")) * all #=> "HX1138" * f1 #=> "H" @@ -1270,13 +1273,13 @@ name_to_backref_number(struct re_registers *regs, VALUE regexp, const char* name * mtch[start, length] => array * mtch[range] => array * mtch[name] => str or nil - * + * * Match Reference---<code>MatchData</code> acts as an array, and may be * accessed using the normal array indexing techniques. <i>mtch</i>[0] is * equivalent to the special variable <code>$&</code>, and returns the entire * matched string. <i>mtch</i>[1], <i>mtch</i>[2], and so on return the values * of the matched backreferences (portions of the pattern between parentheses). - * + * * m = /(.)(.)(\d+)(\d)/.match("THX1138.") * m[0] #=> "HX1138" * m[1, 2] #=> ["H", "X"] @@ -1340,10 +1343,10 @@ match_entry(VALUE match, long n) if (!OBJ_TAINTED(obj) && rb_safe_level() >= 4) rb_raise(rb_eSecurityError, "Insecure: can't modify regexp"); * mtch.select([index]*) => array - * + * * Uses each <i>index</i> to access the matching values, returning an array of * the corresponding matches. - * + * * m = /(.)(.)(\d+)(\d)/.match("THX1138: The Movie") * m.to_a #=> ["HX1138", "H", "X", "113", "8"] * m.select(0, 2, -2) #=> ["HX1138", "X", "113"] @@ -1359,10 +1362,10 @@ match_values_at(int argc, VALUE *argv, VALUE match) /* * call-seq: * mtch.select([index]*) => array - * + * * Uses each <i>index</i> to access the matching values, returning an * array of the corresponding matches. - * + * * m = /(.)(.)(\d+)(\d)/.match("THX1138: The Movie") * m.to_a #=> ["HX1138", "H", "X", "113", "8"] * m.select(0, 2, -2) #=> ["HX1138", "X", "113"] @@ -1396,9 +1399,9 @@ match_select(int argc, VALUE *argv, VALUE match) /* * call-seq: * mtch.to_s => str - * + * * Returns the entire matched string. - * + * * m = /(.)(.)(\d+)(\d)/.match("THX1138.") * m.to_s #=> "HX1138" */ @@ -1418,9 +1421,9 @@ match_to_s(VALUE match) /* * call-seq: * mtch.string => str - * + * * Returns a frozen copy of the string passed in to <code>match</code>. - * + * * m = /(.)(.)(\d+)(\d)/.match("THX1138.") * m.string #=> "THX1138." */ @@ -1560,11 +1563,11 @@ rb_reg_hash(VALUE re) * call-seq: * rxp == other_rxp => true or false * rxp.eql?(other_rxp) => true or false - * + * * Equality---Two regexps are equal if their patterns are identical, they have * the same character set code, and their <code>casefold?</code> values are the * same. - * + * * /abc/ == /abc/x #=> false * /abc/ == /abc/i #=> false * /abc/u == /abc/n #=> false @@ -1628,7 +1631,7 @@ rb_reg_match_pos(VALUE re, VALUE str, long pos) /* * call-seq: * rxp =~ str => integer or nil - * + * * Match---Matches <i>rxp</i> against <i>str</i>. * * /at/ =~ "input data" #=> 7 @@ -1643,18 +1646,18 @@ rb_reg_match(VALUE re, VALUE str) /* * call-seq: * rxp === str => true or false - * + * * Case Equality---Synonym for <code>Regexp#=~</code> used in case statements. - * + * * a = "HELLO" * case a * when /^[a-z]*$/; print "Lower case\n" * when /^[A-Z]*$/; print "Upper case\n" * else; print "Mixed case\n" * end - * + * * <em>produces:</em> - * + * * Upper case */ @@ -1679,10 +1682,10 @@ rb_reg_eqq(VALUE re, VALUE str) /* * call-seq: * ~ rxp => integer or nil - * + * * Match---Matches <i>rxp</i> against the contents of <code>$_</code>. * Equivalent to <code><i>rxp</i> =~ $_</code>. - * + * * $_ = "input data" * ~ /at/ #=> 7 */ @@ -1710,13 +1713,13 @@ rb_reg_match2(VALUE re) * call-seq: * rxp.match(str) => matchdata or nil * rxp.match(str,pos) => matchdata or nil - * + * * Returns a <code>MatchData</code> object describing the match, or * <code>nil</code> if there was no match. This is equivalent to retrieving the * value of the special variable <code>$~</code> following a normal match. * If the second parameter is present, it specifies the position in the string * to begin the search. - * + * * /(.)(.)(.)/.match("abc")[2] #=> "b" * /(.)(.)/.match("abc", 1)[2] #=> "c" */ @@ -1757,7 +1760,7 @@ rb_reg_match_m(int argc, VALUE *argv, VALUE re) * Regexp.new(regexp) => regexp * Regexp.compile(string [, options [, lang]]) => regexp * Regexp.compile(regexp) => regexp - * + * * Constructs a new regular expression from <i>pattern</i>, which can be either * a <code>String</code> or a <code>Regexp</code> (in which case that regexp's * options are propagated, and new options may not be specified (a change as of @@ -1768,7 +1771,7 @@ rb_reg_match_m(int argc, VALUE *argv, VALUE re) * <code>nil</code>, the regexp will be case insensitive. The <i>lang</i> * parameter enables multibyte support for the regexp: `n', `N' = none, `e', * `E' = EUC, `s', `S' = SJIS, `u', `U' = UTF-8. - * + * * r1 = Regexp.new('^a-z+:\\s+\w+') #=> /^a-z+:\s+\w+/ * r2 = Regexp.new('cat', true) #=> /cat/i * r3 = Regexp.new('dog', Regexp::EXTENDED) #=> /dog/x @@ -1904,12 +1907,12 @@ rb_reg_quote(VALUE str) * call-seq: * Regexp.escape(str) => a_str * Regexp.quote(str) => a_str - * + * * Escapes any characters that would have special meaning in a regular * expression. Returns a new escaped string, or self if no characters are * escaped. For any string, * <code>Regexp.escape(<i>str</i>)=~<i>str</i></code> will be true. - * + * * Regexp.escape('\\*?{}.') #=> \\\\\*\?\{\}\. */ @@ -1965,12 +1968,12 @@ rb_reg_options(VALUE re) /* * call-seq: * Regexp.union([pattern]*) => new_str - * + * * Return a <code>Regexp</code> object that is the union of the given * <em>pattern</em>s, i.e., will match any of its parts. The <em>pattern</em>s * can be Regexp objects, in which case their options will be preserved, or * Strings. If no arguments are given, returns <code>/(?!)/</code>. - * + * * Regexp.union #=> /(?!)/ * Regexp.union("penzance") #=> /penzance/ * Regexp.union("skiing", "sledding") #=> /skiing|sledding/ @@ -2279,12 +2282,12 @@ match_setter(VALUE val) * call-seq: * Regexp.last_match => matchdata * Regexp.last_match(fixnum) => str - * + * * The first form returns the <code>MatchData</code> object generated by the * last successful pattern match. Equivalent to reading the global variable * <code>$~</code>. The second form returns the nth field in this * <code>MatchData</code> object. - * + * * /c(.)t/ =~ 'cat' #=> 0 * Regexp.last_match #=> #<MatchData:0x401b3d30> * Regexp.last_match(0) #=> "cat" @@ -361,7 +361,7 @@ thread_create_core(VALUE klass, VALUE args, VALUE (*fn)(ANYARGS), void *arg) * call-seq: * Thread.start([args]*) {|args| block } => thread * Thread.fork([args]*) {|args| block } => thread - * + * * Basically the same as <code>Thread::new</code>. However, if class * <code>Thread</code> is subclassed, then calling <code>start</code> in that * subclass will not invoke the subclass's <code>initialize</code> method. @@ -390,7 +390,7 @@ thread_join(rb_thread_t *target_th, double delay) { rb_thread_t *th = GET_THREAD(); double now, limit = timeofday() + delay; - + thread_debug("thread_join (thid: %p)\n", target_th->thread_id); if (target_th->status != THREAD_KILLED) { @@ -440,39 +440,39 @@ thread_join(rb_thread_t *target_th, double delay) * call-seq: * thr.join => thr * thr.join(limit) => thr - * + * * The calling thread will suspend execution and run <i>thr</i>. Does not * return until <i>thr</i> exits or until <i>limit</i> seconds have passed. If * the time limit expires, <code>nil</code> will be returned, otherwise * <i>thr</i> is returned. - * + * * Any threads not joined will be killed when the main program exits. If * <i>thr</i> had previously raised an exception and the * <code>abort_on_exception</code> and <code>$DEBUG</code> flags are not set * (so the exception has not yet been processed) it will be processed at this * time. - * + * * a = Thread.new { print "a"; sleep(10); print "b"; print "c" } * x = Thread.new { print "x"; Thread.pass; print "y"; print "z" } * x.join # Let x thread finish, a will be killed on exit. - * + * * <em>produces:</em> - * + * * axyz - * + * * The following example illustrates the <i>limit</i> parameter. - * + * * y = Thread.new { 4.times { sleep 0.1; puts 'tick... ' }} * puts "Waiting" until y.join(0.15) - * + * * <em>produces:</em> - * + * * tick... * Waiting * tick... * Waitingtick... - * - * + * + * * tick... */ @@ -482,7 +482,7 @@ thread_join_m(int argc, VALUE *argv, VALUE self) rb_thread_t *target_th; double delay = DELAY_INFTY; VALUE limit; - + GetThreadPtr(self, target_th); rb_scan_args(argc, argv, "01", &limit); @@ -495,10 +495,10 @@ thread_join_m(int argc, VALUE *argv, VALUE self) /* * call-seq: * thr.value => obj - * + * * Waits for <i>thr</i> to complete (via <code>Thread#join</code>) and returns * its value. - * + * * a = Thread.new { 2 + 2 } * a.value #=> 4 */ @@ -651,9 +651,9 @@ rb_thread_blocking_region( /* * call-seq: * Thread.pass => nil - * + * * Invokes the thread scheduler to pass execution to another thread. - * + * * a = Thread.new { print "a"; Thread.pass; * print "b"; Thread.pass; * print "c" } @@ -662,9 +662,9 @@ rb_thread_blocking_region( * print "z" } * a.join * b.join - * + * * <em>produces:</em> - * + * * axbycz */ @@ -807,16 +807,16 @@ rb_thread_fd_close(int fd) /* * call-seq: * thr.raise(exception) - * + * * Raises an exception (see <code>Kernel::raise</code>) from <i>thr</i>. The * caller does not have to be <i>thr</i>. - * + * * Thread.abort_on_exception = true * a = Thread.new { sleep(200) } * a.raise("Gotcha") - * + * * <em>produces:</em> - * + * * prog.rb:3: Gotcha (RuntimeError) * from prog.rb:2:in `initialize' * from prog.rb:2:in `new' @@ -838,7 +838,7 @@ thread_raise_m(int argc, VALUE *argv, VALUE self) * thr.exit => thr or nil * thr.kill => thr or nil * thr.terminate => thr or nil - * + * * Terminates <i>thr</i> and schedules another thread to be run. If this thread * is already marked to be killed, <code>exit</code> returns the * <code>Thread</code>. If this is the main thread, or the last thread, exits @@ -875,9 +875,9 @@ rb_thread_kill(VALUE thread) /* * call-seq: * Thread.kill(thread) => thread - * + * * Causes the given <em>thread</em> to exit (see <code>Thread::exit</code>). - * + * * count = 0 * a = Thread.new { loop { count += 1 } } * sleep(0.1) #=> 0 @@ -896,7 +896,7 @@ rb_thread_s_kill(VALUE obj, VALUE th) /* * call-seq: * Thread.exit => thread - * + * * Terminates the currently running thread and schedules another thread to be * run. If this thread is already marked to be killed, <code>exit</code> * returns the <code>Thread</code>. If this is the main thread, or the last @@ -913,15 +913,15 @@ rb_thread_exit(void) /* * call-seq: * thr.wakeup => thr - * + * * Marks <i>thr</i> as eligible for scheduling (it may still remain blocked on * I/O, however). Does not invoke the scheduler (see <code>Thread#run</code>). - * + * * c = Thread.new { Thread.stop; puts "hey!" } * c.wakeup - * + * * <em>produces:</em> - * + * * hey! */ @@ -942,18 +942,18 @@ rb_thread_wakeup(VALUE thread) /* * call-seq: * thr.run => thr - * + * * Wakes up <i>thr</i>, making it eligible for scheduling. If not in a critical * section, then invokes the scheduler. - * + * * a = Thread.new { puts "a"; Thread.stop; puts "c" } * Thread.pass * puts "Got here" * a.run * a.join - * + * * <em>produces:</em> - * + * * a * Got here * c @@ -971,19 +971,19 @@ rb_thread_run(VALUE thread) /* * call-seq: * Thread.stop => nil - * + * * Stops execution of the current thread, putting it into a ``sleep'' state, * and schedules execution of another thread. Resets the ``critical'' condition * to <code>false</code>. - * + * * a = Thread.new { print "a"; Thread.stop; print "c" } * Thread.pass * print "b" * a.run * a.join - * + * * <em>produces:</em> - * + * * abc */ @@ -1006,11 +1006,11 @@ thread_list_i(st_data_t key, st_data_t val, void *data) GetThreadPtr((VALUE)key, th); switch (th->status) { - case THREAD_RUNNABLE: - case THREAD_STOPPED: - case THREAD_TO_KILL: + case THREAD_RUNNABLE: + case THREAD_STOPPED: + case THREAD_TO_KILL: rb_ary_push(ary, th->self); - default: + default: break; } return ST_CONTINUE; @@ -1021,17 +1021,17 @@ thread_list_i(st_data_t key, st_data_t val, void *data) /* * call-seq: * Thread.list => array - * + * * Returns an array of <code>Thread</code> objects for all threads that are * either runnable or stopped. - * + * * Thread.new { sleep(200) } * Thread.new { 1000000.times {|i| i*i } } * Thread.new { Thread.stop } * Thread.list.each {|t| p t} - * + * * <em>produces:</em> - * + * * #<Thread:0x401b3e84 sleep> * #<Thread:0x401b3f38 run> * #<Thread:0x401b3fb0 sleep> @@ -1055,9 +1055,9 @@ rb_thread_current(void) /* * call-seq: * Thread.current => thread - * + * * Returns the currently executing thread. - * + * * Thread.current #=> #<Thread:0x401bdf4c run> */ @@ -1083,7 +1083,7 @@ rb_thread_s_main(VALUE klass) /* * call-seq: * Thread.abort_on_exception => true or false - * + * * Returns the status of the global ``abort on exception'' condition. The * default is <code>false</code>. When set to <code>true</code>, or if the * global <code>$DEBUG</code> flag is <code>true</code> (perhaps because the @@ -1102,10 +1102,10 @@ rb_thread_s_abort_exc(void) /* * call-seq: * Thread.abort_on_exception= boolean => true or false - * + * * When set to <code>true</code>, all threads will abort if an exception is * raised. Returns the new state. - * + * * Thread.abort_on_exception = true * t1 = Thread.new do * puts "In new thread" @@ -1113,9 +1113,9 @@ rb_thread_s_abort_exc(void) * end * sleep(1) * puts "not reached" - * + * * <em>produces:</em> - * + * * In new thread * prog.rb:4: Exception from thread (RuntimeError) * from prog.rb:2:in `initialize' @@ -1135,7 +1135,7 @@ rb_thread_s_abort_exc_set(VALUE self, VALUE val) /* * call-seq: * thr.abort_on_exception => true or false - * + * * Returns the status of the thread-local ``abort on exception'' condition for * <i>thr</i>. The default is <code>false</code>. See also * <code>Thread::abort_on_exception=</code>. @@ -1153,7 +1153,7 @@ rb_thread_abort_exc(VALUE thread) /* * call-seq: * thr.abort_on_exception= boolean => true or false - * + * * When set to <code>true</code>, causes all threads (including the main * program) to abort if an exception is raised in <i>thr</i>. The process will * effectively <code>exit(0)</code>. @@ -1174,10 +1174,10 @@ rb_thread_abort_exc_set(VALUE thread, VALUE val) /* * call-seq: * thr.group => thgrp or nil - * + * * Returns the <code>ThreadGroup</code> which contains <i>thr</i>, or nil if * the thread is not a member of any group. - * + * * Thread.main.group #=> #<ThreadGroup:0x4029d914> */ @@ -1199,15 +1199,15 @@ static const char * thread_status_name(enum rb_thread_status status) { switch (status) { - case THREAD_RUNNABLE: + case THREAD_RUNNABLE: return "run"; - case THREAD_STOPPED: + case THREAD_STOPPED: return "sleep"; - case THREAD_TO_KILL: + case THREAD_TO_KILL: return "aborting"; - case THREAD_KILLED: + case THREAD_KILLED: return "dead"; - default: + default: return "unknown"; } } @@ -1222,13 +1222,13 @@ rb_thread_dead(rb_thread_t *th) /* * call-seq: * thr.status => string, false or nil - * + * * Returns the status of <i>thr</i>: ``<code>sleep</code>'' if <i>thr</i> is * sleeping or waiting on I/O, ``<code>run</code>'' if <i>thr</i> is executing, * ``<code>aborting</code>'' if <i>thr</i> is aborting, <code>false</code> if * <i>thr</i> terminated normally, and <code>nil</code> if <i>thr</i> * terminated with an exception. - * + * * a = Thread.new { raise("die now") } * b = Thread.new { Thread.stop } * c = Thread.new { Thread.exit } @@ -1262,9 +1262,9 @@ rb_thread_status(VALUE thread) /* * call-seq: * thr.alive? => true or false - * + * * Returns <code>true</code> if <i>thr</i> is running or sleeping. - * + * * thr = Thread.new { } * thr.join #=> #<Thread:0x401b3fb0 dead> * Thread.current.alive? #=> true @@ -1285,9 +1285,9 @@ rb_thread_alive_p(VALUE thread) /* * call-seq: * thr.stop? => true or false - * + * * Returns <code>true</code> if <i>thr</i> is dead or sleeping. - * + * * a = Thread.new { Thread.stop } * b = Thread.current * a.stop? #=> true @@ -1310,10 +1310,10 @@ rb_thread_stop_p(VALUE thread) /* * call-seq: * thr.safe_level => integer - * + * * Returns the safe level in effect for <i>thr</i>. Setting thread-local safe * levels can help when implementing sandboxes which run insecure code. - * + * * thr = Thread.new { $SAFE = 3; sleep } * Thread.current.safe_level #=> 0 * thr.safe_level #=> 3 @@ -1373,18 +1373,18 @@ rb_thread_local_aref(VALUE thread, ID id) /* * call-seq: * thr[sym] => obj or nil - * + * * Attribute Reference---Returns the value of a thread-local variable, using * either a symbol or a string name. If the specified variable does not exist, * returns <code>nil</code>. - * + * * a = Thread.new { Thread.current["name"] = "A"; Thread.stop } * b = Thread.new { Thread.current[:name] = "B"; Thread.stop } * c = Thread.new { Thread.current["name"] = "C"; Thread.stop } * Thread.list.each {|x| puts "#{x.inspect}: #{x[:name]}" } - * + * * <em>produces:</em> - * + * * #<Thread:0x401b3b3c sleep>: C * #<Thread:0x401b3bc8 sleep>: B * #<Thread:0x401b3c68 sleep>: A @@ -1423,7 +1423,7 @@ rb_thread_local_aset(VALUE thread, ID id, VALUE val) /* * call-seq: * thr[sym] = obj => obj - * + * * Attribute Assignment---Sets or creates the value of a thread-local variable, * using either a symbol or a string. See also <code>Thread#[]</code>. */ @@ -1437,10 +1437,10 @@ rb_thread_aset(VALUE self, ID id, VALUE val) /* * call-seq: * thr.key?(sym) => true or false - * + * * Returns <code>true</code> if the given string (or symbol) exists as a * thread-local variable. - * + * * me = Thread.current * me[:oliver] = "a" * me.key?(:oliver) #=> true @@ -1483,9 +1483,9 @@ rb_thread_alone() /* * call-seq: * thr.keys => array - * + * * Returns an an array of the names of the thread-local variables (as Symbols). - * + * * thr = Thread.new do * Thread.current[:cat] = 'meow' * Thread.current["dog"] = 'woof' @@ -1531,16 +1531,16 @@ rb_thread_priority(VALUE thread) /* * call-seq: * thr.priority= integer => thr - * + * * Sets the priority of <i>thr</i> to <i>integer</i>. Higher-priority threads * will run before lower-priority threads. - * + * * count1 = count2 = 0 * a = Thread.new do * loop { count1 += 1 } * end * a.priority = -1 - * + * * b = Thread.new do * loop { count2 += 1 } * end @@ -1660,7 +1660,7 @@ cmp_tv(const struct timeval *a, const struct timeval *b) return (d != 0) ? d : (a->tv_usec - b->tv_usec); } -static int +static int subst(struct timeval *rest, const struct timeval *wait) { while (rest->tv_usec < wait->tv_usec) { @@ -1915,7 +1915,7 @@ struct thgroup { * threads as a group. A <code>Thread</code> can belong to only one * <code>ThreadGroup</code> at a time; adding a thread to a new group will * remove it from any previous group. - * + * * Newly created threads belong to the same group as the thread from which they * were created. */ @@ -1957,10 +1957,10 @@ thgroup_list_i(st_data_t key, st_data_t val, st_data_t data) /* * call-seq: * thgrp.list => array - * + * * Returns an array of all existing <code>Thread</code> objects that belong to * this group. - * + * * ThreadGroup::Default.list #=> [#<Thread:0x401bdf4c run>] */ @@ -1979,11 +1979,11 @@ thgroup_list(VALUE group) /* * call-seq: * thgrp.enclose => thgrp - * + * * Prevents threads from being added to or removed from the receiving * <code>ThreadGroup</code>. New threads can still be started in an enclosed * <code>ThreadGroup</code>. - * + * * ThreadGroup::Default.enclose #=> #<ThreadGroup:0x4029d914> * thr = Thread::new { Thread.stop } #=> #<Thread:0x402a7210 sleep> * tg = ThreadGroup::new #=> #<ThreadGroup:0x402752d4> @@ -2009,7 +2009,7 @@ thgroup_enclose(VALUE group) /* * call-seq: * thgrp.enclosed? => true or false - * + * * Returns <code>true</code> if <em>thgrp</em> is enclosed. See also * ThreadGroup#enclose. */ @@ -2029,10 +2029,10 @@ thgroup_enclosed_p(VALUE group) /* * call-seq: * thgrp.add(thread) => thgrp - * + * * Adds the given <em>thread</em> to this group, removing it from any other * group to which it may have previously belonged. - * + * * puts "Initial group is #{ThreadGroup::Default.list}" * tg = ThreadGroup.new * t1 = Thread.new { sleep } @@ -2042,9 +2042,9 @@ thgroup_enclosed_p(VALUE group) * tg.add(t1) * puts "Initial group now #{ThreadGroup::Default.list}" * puts "tg group now #{tg.list}" - * + * * <em>produces:</em> - * + * * Initial group is #<Thread:0x401bdf4c> * t1 is #<Thread:0x401b3c90> * t2 is #<Thread:0x401b3c18> @@ -2291,7 +2291,7 @@ rb_mutex_sleep(VALUE self, VALUE timeout) * mutex.sleep(timeout = nil) => self * * Releases the lock and sleeps +timeout+ seconds if it is given and - * non-nil or forever. Raises +ThreadError+ if +mutex+ wasn't locked by + * non-nil or forever. Raises +ThreadError+ if +mutex+ wasn't locked by * the current thread. */ static VALUE @@ -2668,7 +2668,7 @@ rb_clear_trace_func(void) * call-seq: * set_trace_func(proc) => proc * set_trace_func(nil) => nil - * + * * Establishes _proc_ as the handler for tracing, or disables * tracing if the parameter is +nil+. _proc_ takes up * to six parameters: an event name, a filename, a line number, an @@ -2764,23 +2764,23 @@ static char * get_event_name(rb_event_flag_t event) { switch (event) { - case RUBY_EVENT_LINE: + case RUBY_EVENT_LINE: return "line"; - case RUBY_EVENT_CLASS: + case RUBY_EVENT_CLASS: return "class"; - case RUBY_EVENT_END: + case RUBY_EVENT_END: return "end"; - case RUBY_EVENT_CALL: + case RUBY_EVENT_CALL: return "call"; - case RUBY_EVENT_RETURN: + case RUBY_EVENT_RETURN: return "return"; - case RUBY_EVENT_C_CALL: + case RUBY_EVENT_C_CALL: return "c-call"; - case RUBY_EVENT_C_RETURN: + case RUBY_EVENT_C_RETURN: return "c-return"; - case RUBY_EVENT_RAISE: + case RUBY_EVENT_RAISE: return "raise"; - default: + default: return "unknown"; } } @@ -2826,7 +2826,7 @@ call_trace_func(rb_event_flag_t event, VALUE proc, VALUE self, ID id, VALUE klas /* * +Thread+ encapsulates the behavior of a thread of * execution, including the main thread of the Ruby script. - * + * * In the descriptions of the methods in this class, the parameter _sym_ * refers to a symbol, which is either a quoted string or a * +Symbol+ (such as <code>:name</code>). diff --git a/thread_pthread.ci b/thread_pthread.ci index 43dac0be5a..87cbc26e50 100644 --- a/thread_pthread.ci +++ b/thread_pthread.ci @@ -150,7 +150,7 @@ register_cached_thread_and_wait(void) gettimeofday(&tv, 0); ts.tv_sec = tv.tv_sec + 60; ts.tv_nsec = tv.tv_usec * 1000; - + pthread_mutex_lock(&thread_cache_lock); { entry->th_area = &th_area; @@ -335,7 +335,7 @@ native_sleep(rb_thread_t *th, struct timeval *tv) ts.tv_nsec -= 1000000000; } } - + th->status = THREAD_STOPPED; pthread_cond_init(&th->native_thread_data.sleep_cond, 0); diff --git a/thread_win32.ci b/thread_win32.ci index d046775302..d69cd98a01 100644 --- a/thread_win32.ci +++ b/thread_win32.ci @@ -196,22 +196,22 @@ native_mutex_lock(rb_thread_lock_t *lock) thread_debug("native_mutex_lock: %p\n", *lock); result = w32_wait_events(&*lock, 1, INFINITE, 0); switch (result) { - case WAIT_OBJECT_0: + case WAIT_OBJECT_0: /* get mutex object */ thread_debug("acquire mutex: %p\n", *lock); return 0; - case WAIT_OBJECT_0 + 1: + case WAIT_OBJECT_0 + 1: /* interrupt */ errno = EINTR; thread_debug("acquire mutex interrupted: %p\n", *lock); return 0; - case WAIT_TIMEOUT: + case WAIT_TIMEOUT: thread_debug("timeout mutex: %p\n", *lock); break; - case WAIT_ABANDONED: + case WAIT_ABANDONED: rb_bug("win32_mutex_lock: WAIT_ABANDONED"); break; - default: + default: rb_bug("win32_mutex_lock: unknown result (%d)", result); break; } @@ -244,9 +244,9 @@ native_mutex_trylock(rb_thread_lock_t *lock) result = w32_wait_events(&*lock, 1, 1, 0); thread_debug("native_mutex_trylock result: %d\n", result); switch (result) { - case WAIT_OBJECT_0: + case WAIT_OBJECT_0: return 0; - case WAIT_TIMEOUT: + case WAIT_TIMEOUT: return EBUSY; } return EINVAL; @@ -1,7 +1,7 @@ #define RUBY_VERSION "1.9.0" -#define RUBY_RELEASE_DATE "2007-06-04" +#define RUBY_RELEASE_DATE "2007-06-05" #define RUBY_VERSION_CODE 190 -#define RUBY_RELEASE_CODE 20070604 +#define RUBY_RELEASE_CODE 20070605 #define RUBY_PATCHLEVEL 0 #define RUBY_VERSION_MAJOR 1 @@ -9,7 +9,7 @@ #define RUBY_VERSION_TEENY 0 #define RUBY_RELEASE_YEAR 2007 #define RUBY_RELEASE_MONTH 6 -#define RUBY_RELEASE_DAY 4 +#define RUBY_RELEASE_DAY 5 #ifdef RUBY_EXTERN RUBY_EXTERN const char ruby_version[]; @@ -120,7 +120,7 @@ pop_frame(rb_thread_t *th) { #if COLLECT_PROFILE rb_control_frame_t *cfp = th->cfp; - + if (RUBY_VM_NORMAL_ISEQ_P(cfp->iseq)) { VALUE current_time = clock(); rb_control_frame_t *cfp = th->cfp; @@ -322,7 +322,7 @@ th_make_env_each(rb_thread_t *th, rb_control_frame_t *cfp, BUILTIN_TYPE(cfp->lfp[-1]) == T_VALUES))) { rb_bug("illegal svar"); } - + if (!RUBY_VM_NORMAL_ISEQ_P(cfp->iseq)) { /* TODO */ env->block.iseq = 0; @@ -524,64 +524,64 @@ th_call0(rb_thread_t *th, VALUE klass, VALUE recv, } switch (nd_type(body)) { case RUBY_VM_METHOD_NODE:{ - rb_control_frame_t *reg_cfp; - int i; - const int flag = 0; - - th_set_finish_env(th); - reg_cfp = th->cfp; - for (i = 0; i < argc; i++) { - *reg_cfp->sp++ = argv[i]; - } - macro_eval_invoke_func(body->nd_body, recv, klass, blockptr, - argc); - val = th_eval_body(th); - break; + rb_control_frame_t *reg_cfp; + int i; + const int flag = 0; + + th_set_finish_env(th); + reg_cfp = th->cfp; + for (i = 0; i < argc; i++) { + *reg_cfp->sp++ = argv[i]; + } + macro_eval_invoke_func(body->nd_body, recv, klass, blockptr, + argc); + val = th_eval_body(th); + break; } case NODE_CFUNC: { - EXEC_EVENT_HOOK(th, RUBY_EVENT_C_CALL, recv, id, klass); - { - rb_control_frame_t *reg_cfp = th->cfp; - rb_control_frame_t *cfp = + EXEC_EVENT_HOOK(th, RUBY_EVENT_C_CALL, recv, id, klass); + { + rb_control_frame_t *reg_cfp = th->cfp; + rb_control_frame_t *cfp = push_frame(th, 0, FRAME_MAGIC_CFUNC, recv, (VALUE)blockptr, 0, reg_cfp->sp, 0, 1); - cfp->method_id = id; - cfp->method_klass = klass; - - val = call_cfunc(body->nd_cfnc, recv, body->nd_argc, argc, argv); - - if (reg_cfp != th->cfp + 1) { - SDR2(reg_cfp); - SDR2(th->cfp-5); - rb_bug("cfp consistency error - call0"); - th->cfp = reg_cfp; - } - pop_frame(th); - } - EXEC_EVENT_HOOK(th, RUBY_EVENT_C_RETURN, recv, id, klass); - break; + cfp->method_id = id; + cfp->method_klass = klass; + + val = call_cfunc(body->nd_cfnc, recv, body->nd_argc, argc, argv); + + if (reg_cfp != th->cfp + 1) { + SDR2(reg_cfp); + SDR2(th->cfp-5); + rb_bug("cfp consistency error - call0"); + th->cfp = reg_cfp; + } + pop_frame(th); + } + EXEC_EVENT_HOOK(th, RUBY_EVENT_C_RETURN, recv, id, klass); + break; } case NODE_ATTRSET:{ - if (argc != 1) { - rb_raise(rb_eArgError, "wrong number of arguments (%d for 1)", - argc); - } - val = rb_ivar_set(recv, body->nd_vid, argv[0]); - break; + if (argc != 1) { + rb_raise(rb_eArgError, "wrong number of arguments (%d for 1)", + argc); + } + val = rb_ivar_set(recv, body->nd_vid, argv[0]); + break; } case NODE_IVAR: { - if (argc != 0) { - rb_raise(rb_eArgError, "wrong number of arguments (%d for 0)", - argc); - } - val = rb_attr_get(recv, body->nd_vid); - break; + if (argc != 0) { + rb_raise(rb_eArgError, "wrong number of arguments (%d for 0)", + argc); + } + val = rb_attr_get(recv, body->nd_vid); + break; } case NODE_BMETHOD:{ - val = th_invoke_bmethod(th, id, body->nd_cval, - recv, klass, argc, (VALUE *)argv); - break; + val = th_invoke_bmethod(th, id, body->nd_cval, + recv, klass, argc, (VALUE *)argv); + break; } default: rb_bug("unsupported: th_call0"); @@ -895,22 +895,22 @@ lfp_svar(VALUE *lfp, int cnt) } } switch (cnt) { - case -1: + case -1: return &val->basic.klass; - case 0: + case 0: return &val->v1; - case 1: + case 1: return &val->v2; - default:{ - VALUE ary; - if ((ary = val->v3) == Qnil) { - ary = val->v3 = rb_ary_new(); - } - if (RARRAY_LEN(ary) <= cnt) { - rb_ary_store(ary, cnt, Qnil); - } - return &RARRAY_PTR(ary)[cnt]; + default:{ + VALUE ary; + if ((ary = val->v3) == Qnil) { + ary = val->v3 = rb_ary_new(); + } + if (RARRAY_LEN(ary) <= cnt) { + rb_ary_store(ary, cnt, Qnil); } + return &RARRAY_PTR(ary)[cnt]; + } } } @@ -1195,7 +1195,7 @@ eval_get_ev_const(rb_thread_t *th, rb_iseq_t *iseq, while (cref && cref->nd_next) { klass = cref->nd_clss; cref = cref->nd_next; - + if (klass == 0) { continue; } @@ -1236,10 +1236,10 @@ eval_get_ev_const(rb_thread_t *th, rb_iseq_t *iseq, } else { switch (TYPE(klass)) { - case T_CLASS: - case T_MODULE: + case T_CLASS: + case T_MODULE: break; - default: + default: rb_raise(rb_eTypeError, "%s is not a class/module", RSTRING_PTR(rb_obj_as_string(klass))); } @@ -1361,24 +1361,24 @@ make_localjump_error(const char *mesg, VALUE value, int reason) rb_exc_new2(rb_const_get(rb_cObject, rb_intern("LocalJumpError")), mesg); ID id; - + switch (reason) { - case TAG_BREAK: + case TAG_BREAK: id = rb_intern("break"); break; - case TAG_REDO: + case TAG_REDO: id = rb_intern("redo"); break; - case TAG_RETRY: + case TAG_RETRY: id = rb_intern("retry"); break; - case TAG_NEXT: + case TAG_NEXT: id = rb_intern("next"); break; - case TAG_RETURN: + case TAG_RETURN: id = rb_intern("return"); break; - default: + default: id = rb_intern("noreason"); break; } @@ -1398,28 +1398,28 @@ VALUE th_make_jump_tag_but_local_jump(int state, VALUE val) { VALUE result = Qnil; - + if (val == Qundef) val = GET_THREAD()->tag->retval; switch (state) { - case 0: + case 0: break; - case TAG_RETURN: + case TAG_RETURN: result = make_localjump_error("unexpected return", val, state); break; - case TAG_BREAK: + case TAG_BREAK: result = make_localjump_error("unexpected break", val, state); break; - case TAG_NEXT: + case TAG_NEXT: result = make_localjump_error("unexpected next", val, state); break; - case TAG_REDO: + case TAG_REDO: result = make_localjump_error("unexpected redo", Qnil, state); break; - case TAG_RETRY: + case TAG_RETRY: result = make_localjump_error("retry outside of rescue clause", Qnil, state); break; - default: + default: break; } return result; @@ -1453,7 +1453,7 @@ void rb_vm_check_redefinition_opt_method(NODE *node) { VALUE bop; - + if (st_lookup(vm_opt_method_table, (st_data_t)node, &bop)) { yarv_redefined_flag |= bop; } @@ -1828,7 +1828,7 @@ rb_thread_eval(rb_thread_t *th, VALUE iseqval) { VALUE val; volatile VALUE tmp; - + th_set_top_stack(th, iseqval); if (!rb_const_defined(rb_cObject, rb_intern("TOPLEVEL_BINDING"))) { @@ -47,40 +47,40 @@ control_frame_dump(rb_thread_t *th, rb_control_frame_t *cfp) } switch (cfp->magic) { - case FRAME_MAGIC_TOP: + case FRAME_MAGIC_TOP: magic = "TOP"; break; - case FRAME_MAGIC_METHOD: + case FRAME_MAGIC_METHOD: magic = "METHOD"; break; - case FRAME_MAGIC_CLASS: + case FRAME_MAGIC_CLASS: magic = "CLASS"; break; - case FRAME_MAGIC_BLOCK: + case FRAME_MAGIC_BLOCK: magic = "BLOCK"; break; - case FRAME_MAGIC_FINISH: + case FRAME_MAGIC_FINISH: magic = "FINISH"; break; - case FRAME_MAGIC_CFUNC: + case FRAME_MAGIC_CFUNC: magic = "CFUNC"; break; - case FRAME_MAGIC_PROC: + case FRAME_MAGIC_PROC: magic = "PROC"; break; case FRAME_MAGIC_LAMBDA: magic = "LAMBDA"; break; - case FRAME_MAGIC_IFUNC: + case FRAME_MAGIC_IFUNC: magic = "IFUNC"; break; - case FRAME_MAGIC_EVAL: + case FRAME_MAGIC_EVAL: magic = "EVAL"; break; - case 0: + case 0: magic = "------"; break; - default: + default: magic = "(none)"; break; } |