From 9c373683e39dc58664b45955d4cc04a27ad13f63 Mon Sep 17 00:00:00 2001 From: mame Date: Fri, 5 Jan 2018 00:49:40 +0000 Subject: compile.c: refactoring of defined? exception handler This commit removes tmp_node trick to create a special exception handler for `defined?`. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61599 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- compile.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'compile.c') diff --git a/compile.c b/compile.c index b876d9ab98..6280eab17e 100644 --- a/compile.c +++ b/compile.c @@ -4239,6 +4239,14 @@ defined_expr0(rb_iseq_t *iseq, LINK_ANCHOR *const ret, return 0; } +static VALUE +build_defined_rescue_iseq(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *unused) +{ + ADD_INSN(ret, 0, putnil); + iseq_set_exception_local_table(iseq); + return Qnil; +} + static int defined_expr(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const node, LABEL **lfinish, VALUE needstr) @@ -4250,13 +4258,10 @@ defined_expr(rb_iseq_t *iseq, LINK_ANCHOR *const ret, LABEL *lstart = NEW_LABEL(line); LABEL *lend = NEW_LABEL(line); const rb_iseq_t *rescue; - NODE tmp_node, *node = &tmp_node; - rb_node_init(node, NODE_NIL, 0, 0, 0); - rescue = NEW_CHILD_ISEQ(node, - rb_str_concat(rb_str_new2 - ("defined guard in "), - iseq->body->location.label), - ISEQ_TYPE_DEFINED_GUARD, 0); + rescue = new_child_iseq_ifunc(iseq, IFUNC_NEW(build_defined_rescue_iseq, 0, 0), + rb_str_concat(rb_str_new2("defined guard in "), + iseq->body->location.label), + iseq, ISEQ_TYPE_RESCUE, 0); lstart->rescued = LABEL_RESCUE_BEG; lend->rescued = LABEL_RESCUE_END; APPEND_LABEL(ret, lcur, lstart); -- cgit v1.2.3