# HG changeset patch # User Max Brister # Date 1340129410 18000 # Node ID 903a5ee2cdde36df2fe7205da94ce042641aa9aa # Parent c959136f8c3edaeea6f9a777888cacd229bc9128 Simplify the creation of error checks in jit * src/pt-jit.h (jit_convert::create_checked, jit_convert::create_checked_impl): New function. * src/pt-jit.cc (jit_convert::visit_binary_expression, jit_convert::visit_if_command, jit_convert::visit_index_expression): Use create_checked. diff -r c959136f8c3e -r 903a5ee2cdde src/pt-jit.cc --- a/src/pt-jit.cc Tue Jun 19 12:36:53 2012 -0500 +++ b/src/pt-jit.cc Tue Jun 19 13:10:10 2012 -0500 @@ -1615,13 +1615,7 @@ jit_value *rhsv = visit (rhs); const jit_function& fn = jit_typeinfo::binary_op (be.op_type ()); - jit_call *call = block->append (create (fn, lhsv, rhsv)); - - jit_block *normal = create (block->name ()); - block->append (create (call, normal, final_block)); - add_block (normal); - block = normal; - result = call; + result = create_checked (fn, lhsv, rhsv); } void @@ -1869,15 +1863,10 @@ { tree_expression *expr = tic->condition (); jit_value *cond = visit (expr); - jit_call *check = create (&jit_typeinfo::logically_true, - cond); + jit_call *check = create_checked (&jit_typeinfo::logically_true, + cond); block->append (check); - jit_block *next = create (block->name ()); - add_block (next); - block->append (create (check, next, final_block)); - block = next; - jit_block *body = create (i == 0 ? "if_body" : "ifelse_body"); add_block (body); @@ -1935,15 +1924,7 @@ tree_expression *arg0 = arg_list->front (); jit_value *index = visit (arg0); - jit_call *call = create (jit_typeinfo::paren_subsref, object, - index); - block->append (call); - - jit_block *normal = create (block->name ()); - block->append (create (call, normal, final_block)); - add_block (normal); - block = normal; - result = call; + result = create_checked (jit_typeinfo::paren_subsref, object, index); } void diff -r c959136f8c3e -r 903a5ee2cdde src/pt-jit.h --- a/src/pt-jit.h Tue Jun 19 12:36:53 2012 -0500 +++ b/src/pt-jit.h Tue Jun 19 13:10:10 2012 -0500 @@ -2061,6 +2061,21 @@ track_value (ret); return ret; } + + template + jit_call *create_checked (const ARG0& arg0, const ARG1& arg1) + { + jit_call *ret = create (arg0, arg1); + return create_checked_impl (ret); + } + + template + jit_call *create_checked (const ARG0& arg0, const ARG1& arg1, + const ARG2& arg2) + { + jit_call *ret = create (arg0, arg1, arg2); + return create_checked_impl (ret); + } private: typedef std::list block_list; typedef block_list::iterator block_iterator; @@ -2098,6 +2113,18 @@ ablock->stash_location (--blocks.end ()); } + jit_call *create_checked_impl (jit_call *ret) + { + block->append (ret); + + jit_block *normal = create (block->name ()); + block->append (create (ret, normal, final_block)); + add_block (normal); + block = normal; + + return ret; + } + jit_variable *get_variable (const std::string& vname); jit_value *do_assign (const std::string& lhs, jit_value *rhs, bool print);