Navigation Menu

Skip to content

Commit

Permalink
mrb: bind ExpressionCode#value
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Jun 10, 2014
1 parent 0f9061f commit 5f42e2d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
19 changes: 13 additions & 6 deletions lib/mrb/mrb_expr.c
Expand Up @@ -187,26 +187,22 @@ scan_info_build(grn_ctx *ctx, grn_obj *expr, int *n,
switch (ec->value->header.type) {
case GRN_ACCESSOR :
{
mrb_value mrb_accessor;
mrb_value mrb_ec;

mrb_accessor = grn_mrb_value_from_grn_obj(mrb, ec->value);
mrb_ec = mrb_grn_expr_code_new(mrb, ec);
mrb_funcall(mrb, mrb_si, "match_expr_resolve_index_accessor",
2, mrb_accessor, mrb_ec);
1, mrb_ec);
}
break;
case GRN_COLUMN_FIX_SIZE :
case GRN_COLUMN_VAR_SIZE :
{
mrb_value mrb_column;
mrb_value mrb_ec;

mrb_column = grn_mrb_value_from_grn_obj(mrb, ec->value);
mrb_ec = mrb_grn_expr_code_new(mrb, ec);
mrb_funcall(mrb, mrb_si,
"match_expr_resolve_index_data_column",
2, mrb_column, mrb_ec);
1, mrb_ec);
}
break;
case GRN_COLUMN_INDEX :
Expand Down Expand Up @@ -513,6 +509,15 @@ mrb_grn_expr_code_get_weight(mrb_state *mrb, mrb_value self)
return mrb_fixnum_value(grn_expr_code_get_weight(ctx, DATA_PTR(self)));
}

static mrb_value
mrb_grn_expr_code_get_value(mrb_state *mrb, mrb_value self)
{
grn_expr_code *expr_code;

expr_code = DATA_PTR(self);
return grn_mrb_value_from_grn_obj(mrb, expr_code->value);
}

static mrb_value
mrb_grn_expression_initialize(mrb_state *mrb, mrb_value self)
{
Expand Down Expand Up @@ -580,6 +585,8 @@ grn_mrb_expr_init(grn_ctx *ctx)
mrb_grn_expr_code_initialize, MRB_ARGS_REQ(1));
mrb_define_method(mrb, klass, "weight",
mrb_grn_expr_code_get_weight, MRB_ARGS_NONE());
mrb_define_method(mrb, klass, "value",
mrb_grn_expr_code_get_value, MRB_ARGS_NONE());

klass = mrb_define_class_under(mrb, module, "Expression", object_class);
MRB_SET_INSTANCE_TT(klass, MRB_TT_DATA);
Expand Down
6 changes: 4 additions & 2 deletions lib/mrb/scripts/scan_info.rb
Expand Up @@ -18,7 +18,8 @@ def each_arg
nil
end

def match_expr_resolve_index_accessor(accessor, expr_code)
def match_expr_resolve_index_accessor(expr_code)
accessor = expr_code.value
self.flags |= Flags::ACCESSOR
index_info = accessor.find_index(op)
return if index_info.nil?
Expand All @@ -29,7 +30,8 @@ def match_expr_resolve_index_accessor(accessor, expr_code)
end
end

def match_expr_resolve_index_data_column(column, expr_code)
def match_expr_resolve_index_data_column(expr_code)
column = expr_code.value
index_info = column.find_index(op)
return if index_info.nil?
put_index(index_info.index, index_info.section_id, expr_code.weight)
Expand Down

0 comments on commit 5f42e2d

Please sign in to comment.