diff src/interp-core/pt-jit.cc @ 15146:709e8928e68c

Scalar unary operation support in JIT * jit-typeinfo.cc (jit_typeinfo::jit_typeinfo): Add scalar unary operations. * jit-typeinfo.h (jit_typeinfo::unary_op, jit_typeinfo::do_unary_op): New function. * pt-jit.cc (jit_convert::visit_postfix_expression, jit_convert::visit_prefix_expression): Impelment. (jit_convert::visit): Protect result.
author Max Brister <max@2bass.com>
date Fri, 10 Aug 2012 15:05:29 -0500
parents 6ea86e1d0f5f
children 98a65d9e426f
line wrap: on
line diff
--- a/src/interp-core/pt-jit.cc
+++ b/src/interp-core/pt-jit.cc
@@ -581,15 +581,33 @@
 }
 
 void
-jit_convert::visit_postfix_expression (tree_postfix_expression&)
+jit_convert::visit_postfix_expression (tree_postfix_expression& tpe)
 {
-  throw jit_fail_exception ();
+  octave_value::unary_op etype = tpe.op_type ();
+  tree_expression *operand = tpe.operand ();
+  jit_value *operandv = visit (operand);
+
+  const jit_operation& fn = jit_typeinfo::unary_op (etype);
+  result = create_checked (fn, operandv);
+
+  if (etype == octave_value::op_incr || etype == octave_value::op_decr)
+    {
+      // FIXME: Somehow copy operandv
+      // do_assign (operand, operandv);
+      throw jit_fail_exception ("Postfix ++ and -- not yet supported");
+    }
 }
 
 void
-jit_convert::visit_prefix_expression (tree_prefix_expression&)
+jit_convert::visit_prefix_expression (tree_prefix_expression& tpe)
 {
-  throw jit_fail_exception ();
+  octave_value::unary_op etype = tpe.op_type ();
+  tree_expression *operand = tpe.operand ();
+  const jit_operation& fn = jit_typeinfo::unary_op (etype);
+  result = create_checked (fn, visit (operand));
+
+  if (etype == octave_value::op_incr || etype == octave_value::op_decr)
+    do_assign (operand, result);
 }
 
 void
@@ -905,12 +923,11 @@
 jit_value *
 jit_convert::visit (tree& tee)
 {
-  result = 0;
-  tee.accept (*this);
+  unwind_protect prot;
+  prot.protect_var (result);
 
-  jit_value *ret = result;
-  result = 0;
-  return ret;
+  tee.accept (*this);
+  return result;
 }
 
 void
@@ -1963,4 +1980,12 @@
 %! endwhile
 %! assert (i == 10);
 
+%!test
+%! i = 0;
+%! while i < 10
+%!   a = ++i;
+%! endwhile
+%! assert (i == 10);
+%! assert (a == 10);
+
 */