changeset 14961:903a5ee2cdde

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.
author Max Brister <max@2bass.com>
date Tue, 19 Jun 2012 13:10:10 -0500
parents c959136f8c3e
children 90a7a2af2cd5
files src/pt-jit.cc src/pt-jit.h
diffstat 2 files changed, 31 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- 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<jit_call> (fn, lhsv, rhsv));
-
-  jit_block *normal = create<jit_block> (block->name ());
-  block->append (create<jit_error_check> (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_call> (&jit_typeinfo::logically_true,
-                                              cond);
+          jit_call *check = create_checked (&jit_typeinfo::logically_true,
+                                            cond);
           block->append (check);
 
-          jit_block *next = create<jit_block> (block->name ());
-          add_block (next);
-          block->append (create<jit_error_check> (check, next, final_block));
-          block = next;
-
           jit_block *body = create<jit_block> (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_call> (jit_typeinfo::paren_subsref, object,
-                                     index);
-  block->append (call);
-
-  jit_block *normal = create<jit_block> (block->name ());
-  block->append (create<jit_error_check> (call, normal, final_block));
-  add_block (normal);
-  block = normal;
-  result = call;
+  result = create_checked (jit_typeinfo::paren_subsref, object, index);
 }
 
 void
--- 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 <typename ARG0, typename ARG1>
+  jit_call *create_checked (const ARG0& arg0, const ARG1& arg1)
+  {
+    jit_call *ret = create<jit_call> (arg0, arg1);
+    return create_checked_impl (ret);
+  }
+
+  template <typename ARG0, typename ARG1, typename ARG2>
+  jit_call *create_checked (const ARG0& arg0, const ARG1& arg1,
+                            const ARG2& arg2)
+  {
+    jit_call *ret = create<jit_call> (arg0, arg1, arg2);
+    return create_checked_impl (ret);
+  }
 private:
   typedef std::list<jit_block *> 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<jit_block> (block->name ());
+    block->append (create<jit_error_check> (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);