Skip to content

Commit

Permalink
expr optimize: add support for assign and ref
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Mar 4, 2019
1 parent 89776fa commit c9b8fe6
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/mrb/scripts/expression_tree.rb
@@ -1,10 +1,12 @@
require "expression_tree/accessor"
require "expression_tree/assign"
require "expression_tree/binary_operation"
require "expression_tree/constant"
require "expression_tree/function_call"
require "expression_tree/index_column"
require "expression_tree/logical_operation"
require "expression_tree/procedure"
require "expression_tree/reference"
require "expression_tree/table"
require "expression_tree/unary_operation"
require "expression_tree/variable"
18 changes: 18 additions & 0 deletions lib/mrb/scripts/expression_tree/assign.rb
@@ -0,0 +1,18 @@
module Groonga
module ExpressionTree
class Assign
attr_reader :variable
attr_reader :value
def initialize(variable, value)
@variable = variable
@value = value
end

def build(expression)
@variable.build(expression)
@value.build(expression)
expression.append_operator(Operator::ASSIGN, 2)
end
end
end
end
18 changes: 18 additions & 0 deletions lib/mrb/scripts/expression_tree/reference.rb
@@ -0,0 +1,18 @@
module Groonga
module ExpressionTree
class Reference
attr_reader :column
def initialize(column)
@column = column
end

def build(expression)
expression.append_object(@column, Operator::GET_REF, 1)
end

def estimate_size(table)
table.size
end
end
end
end
2 changes: 2 additions & 0 deletions lib/mrb/scripts/expression_tree/sources.am
@@ -1,11 +1,13 @@
RUBY_SCRIPT_FILES = \
accessor.rb \
assign.rb \
binary_operation.rb \
constant.rb \
function_call.rb \
index_column.rb \
logical_operation.rb \
procedure.rb \
reference.rb \
table.rb \
unary_operation.rb \
variable.rb
8 changes: 8 additions & 0 deletions lib/mrb/scripts/expression_tree_builder.rb
Expand Up @@ -83,9 +83,17 @@ def build
value = stack.pop
node = ExpressionTree::UnaryOperation.new(code.op, value)
stack.push(node)
when Operator::GET_REF
node = ExpressionTree::Reference.new(code.value)
stack.push(node)
when Operator::GET_VALUE
node = ExpressionTree::Variable.new(code.value)
stack.push(node)
when Operator::ASSIGN
value = stack.pop
variable = stack.pop
node = ExpressionTree::Assign.new(variable, value)
stack.push(node)
when Operator::PUSH
case code.value
when Procedure
Expand Down

0 comments on commit c9b8fe6

Please sign in to comment.