Navigation Menu

Skip to content

Commit

Permalink
mrb: implement IndexInfo by mruby
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Jun 8, 2014
1 parent 3758dab commit 72a2782
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 131 deletions.
2 changes: 0 additions & 2 deletions lib/ctx_impl_mrb.c
Expand Up @@ -29,7 +29,6 @@
#include "mrb/mrb_index_column.h"
#include "mrb/mrb_expr.h"
#include "mrb/mrb_accessor.h"
#include "mrb/mrb_index_info.h"
#include "mrb/mrb_procedure.h"

#ifdef GRN_WITH_MRUBY
Expand All @@ -50,7 +49,6 @@ grn_ctx_impl_mrb_init_bindings(grn_ctx *ctx)
grn_mrb_index_column_init(ctx);
grn_mrb_expr_init(ctx);
grn_mrb_accessor_init(ctx);
grn_mrb_index_info_init(ctx);
grn_mrb_procedure_init(ctx);
}

Expand Down
85 changes: 0 additions & 85 deletions lib/mrb/mrb_index_info.c

This file was deleted.

38 changes: 0 additions & 38 deletions lib/mrb/mrb_index_info.h

This file was deleted.

17 changes: 14 additions & 3 deletions lib/mrb/mrb_obj.c
@@ -1,6 +1,6 @@
/* -*- c-basic-offset: 2 -*- */
/*
Copyright(C) 2013 Brazil
Copyright(C) 2013-2014 Brazil
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
Expand All @@ -23,8 +23,9 @@
#include <mruby/class.h>
#include <mruby/data.h>

#include "../mrb.h"
#include "mrb_obj.h"
#include "mrb_index_info.h"
#include "mrb_converter.h"

static mrb_value
object_get_name(mrb_state *mrb, mrb_value self)
Expand Down Expand Up @@ -61,7 +62,15 @@ object_find_index(mrb_state *mrb, mrb_value self)
if (n_indexes == 0) {
return mrb_nil_value();
} else {
return mrb_grn_index_info_new(mrb, index, section_id);
grn_mrb_data *data;
struct RClass *klass;
mrb_value args[2];

data = &(ctx->impl->mrb);
klass = mrb_class_get_under(mrb, data->module, "IndexInfo");
args[0] = grn_mrb_value_from_grn_obj(mrb, index);
args[1] = mrb_fixnum_value(section_id);
return mrb_obj_new(mrb, klass, 2, args);
}
}

Expand All @@ -80,5 +89,7 @@ grn_mrb_obj_init(grn_ctx *ctx)
mrb_define_method(mrb, klass, "name", object_get_name, MRB_ARGS_NONE());
mrb_define_method(mrb, klass, "find_index",
object_find_index, MRB_ARGS_REQ(1));

grn_mrb_load(ctx, "index_info.rb");
}
#endif
1 change: 0 additions & 1 deletion lib/mrb/mrb_procedure.c
Expand Up @@ -24,7 +24,6 @@
#include <mruby/data.h>

#include "mrb_procedure.h"
#include "mrb_index_info.h"

static struct mrb_data_type mrb_grn_procedure_type = {
"Groonga::Procedure",
Expand Down
10 changes: 10 additions & 0 deletions lib/mrb/scripts/index_info.rb
@@ -0,0 +1,10 @@
module Groonga
class IndexInfo
attr_reader :index
attr_reader :section_id
def initialize(index, section_id)
@index = index
@section_id = section_id
end
end
end
11 changes: 11 additions & 0 deletions lib/mrb/scripts/scan_info.rb
Expand Up @@ -24,6 +24,17 @@ def match_resolve_index_db_obj(db_obj)
put_index(index_info.index, index_info.section_id, 1)
end

def match_resolve_index_accessor(accessor)
self.flags |= Flags::ACCESSOR
index_info = accessor.find_index(op)
return if index_info.nil?
if acessor.next
put_index(accessor, index_info.section_id, 1)
else
put_index(index_info.index, index_info.section_id, 1)
end
end

def call_relational_resolve_indexes
# better index resolving framework for functions should be implemented
each_arg do |arg|
Expand Down
1 change: 1 addition & 0 deletions lib/mrb/scripts/sources.am
@@ -1,4 +1,5 @@
RUBY_SCRIPT_FILES = \
eval_context.rb \
expression.rb \
index_info.rb \
scan_info.rb
2 changes: 0 additions & 2 deletions lib/mrb/sources.am
Expand Up @@ -15,8 +15,6 @@ libgrnmrb_la_SOURCES = \
mrb_fixed_size_column.h \
mrb_index_column.c \
mrb_index_column.h \
mrb_index_info.c \
mrb_index_info.h \
mrb_obj.c \
mrb_obj.h \
mrb_procedure.c \
Expand Down

0 comments on commit 72a2782

Please sign in to comment.