[Groonga-commit] groonga/groonga at 993ee78 [master] expr optimize: add support for unary minus

Back to archive index
Kouhei Sutou null+****@clear*****
Mon Mar 4 18:02:55 JST 2019


Kouhei Sutou	2019-03-04 18:02:55 +0900 (Mon, 04 Mar 2019)

  Revision: 993ee782b95e6f075f92e127af9ab95f7fb4935a
  https://github.com/groonga/groonga/commit/993ee782b95e6f075f92e127af9ab95f7fb4935a

  Message:
    expr optimize: add support for unary minus

  Modified files:
    lib/mrb/scripts/expression_tree_builder.rb

  Modified: lib/mrb/scripts/expression_tree_builder.rb (+10 -2)
===================================================================
--- lib/mrb/scripts/expression_tree_builder.rb    2019-03-04 17:59:33 +0900 (021842c2a)
+++ lib/mrb/scripts/expression_tree_builder.rb    2019-03-04 18:02:55 +0900 (076f3e26f)
@@ -32,7 +32,6 @@ module Groonga
       Operator::SHIFTR,
       Operator::SHIFTRR,
       Operator::PLUS,
-      Operator::MINUS,
       Operator::STAR,
       Operator::SLASH,
       Operator::MOD,
@@ -48,7 +47,6 @@ module Groonga
     UNARY_OPERATIONS = [
       Operator::NOT,
       Operator::BITWISE_NOT,
-      Operator::MINUS,
       Operator::INCR,
       Operator::DECR,
       Operator::INCR_POST,
@@ -108,6 +106,16 @@ module Groonga
                                                            variable,
                                                            value)
           stack.push(node)
+        when Operator::MINUS
+          if code.n_args == 1
+            value = stack.pop
+            node = ExpressionTree::UnaryOperation.new(code.op, value)
+          else
+            right = stack.pop
+            left = stack.pop
+            node = ExpressionTree::BinaryOperation.new(code.op, left, right)
+          end
+          stack.push(node)
         when Operator::GET_REF
           node = ExpressionTree::Reference.new(code.value)
           stack.push(node)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20190304/acd1d947/attachment.html>


More information about the Groonga-commit mailing list
Back to archive index