Kouhei Sutou
null+****@clear*****
Sun Jun 8 18:28:20 JST 2014
Kouhei Sutou 2014-06-08 18:28:20 +0900 (Sun, 08 Jun 2014) New Revision: 72a2782783aafa3db90f9c81a25728e25bc51972 https://github.com/groonga/groonga/commit/72a2782783aafa3db90f9c81a25728e25bc51972 Message: mrb: implement IndexInfo by mruby Added files: lib/mrb/scripts/index_info.rb Removed files: lib/mrb/mrb_index_info.c lib/mrb/mrb_index_info.h Modified files: lib/ctx_impl_mrb.c lib/mrb/mrb_obj.c lib/mrb/mrb_procedure.c lib/mrb/scripts/scan_info.rb lib/mrb/scripts/sources.am lib/mrb/sources.am Modified: lib/ctx_impl_mrb.c (+0 -2) =================================================================== --- lib/ctx_impl_mrb.c 2014-06-08 18:21:55 +0900 (a5a0cc4) +++ lib/ctx_impl_mrb.c 2014-06-08 18:28:20 +0900 (ba7df47) @@ -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 @@ -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); } Deleted: lib/mrb/mrb_index_info.c (+0 -85) 100644 =================================================================== --- lib/mrb/mrb_index_info.c 2014-06-08 18:21:55 +0900 (3470a7d) +++ /dev/null @@ -1,85 +0,0 @@ -/* -*- c-basic-offset: 2 -*- */ -/* - Copyright(C) 2014 Brazil - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License version 2.1 as published by the Free Software Foundation. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#include "../ctx_impl.h" - -#ifdef GRN_WITH_MRUBY -#include <mruby.h> -#include <mruby/class.h> -#include <mruby/variable.h> - -#include "../db.h" -#include "mrb_index_info.h" -#include "mrb_converter.h" - -mrb_value -mrb_grn_index_info_new(mrb_state *mrb, grn_obj *index, int section_id) -{ - grn_ctx *ctx = (grn_ctx *)mrb->ud; - struct RClass *module = ctx->impl->mrb.module; - struct RClass *klass; - mrb_value args[2]; - - args[0] = grn_mrb_value_from_grn_obj(mrb, index); - args[1] = mrb_fixnum_value(section_id); - klass = mrb_class_ptr(mrb_const_get(mrb, mrb_obj_value(module), - mrb_intern(mrb, "IndexInfo"))); - return mrb_obj_new(mrb, klass, 2, args); -} - -static mrb_value -mrb_grn_index_info_initialize(mrb_state *mrb, mrb_value self) -{ - mrb_value index; - mrb_value section_id; - - mrb_get_args(mrb, "oo", &index, §ion_id); - mrb_iv_set(mrb, self, mrb_intern_cstr(mrb, "index"), index); - mrb_iv_set(mrb, self, mrb_intern_cstr(mrb, "section_id"), section_id); - return self; -} - -static mrb_value -mrb_grn_index_info_get_index(mrb_state *mrb, mrb_value self) -{ - return mrb_iv_get(mrb, self, mrb_intern_cstr(mrb, "index")); -} - -static mrb_value -mrb_grn_index_info_get_section_id(mrb_state *mrb, mrb_value self) -{ - return mrb_iv_get(mrb, self, mrb_intern_cstr(mrb, "section_id")); -} - -void -grn_mrb_index_info_init(grn_ctx *ctx) -{ - grn_mrb_data *data = &(ctx->impl->mrb); - mrb_state *mrb = data->state; - struct RClass *module = data->module; - struct RClass *klass; - - klass = mrb_define_class_under(mrb, module, "IndexInfo", data->object_class); - mrb_define_method(mrb, klass, "initialize", - mrb_grn_index_info_initialize, MRB_ARGS_REQ(2)); - mrb_define_method(mrb, klass, "index", - mrb_grn_index_info_get_index, MRB_ARGS_NONE()); - mrb_define_method(mrb, klass, "section_id", - mrb_grn_index_info_get_section_id, MRB_ARGS_NONE()); -} -#endif Deleted: lib/mrb/mrb_index_info.h (+0 -38) 100644 =================================================================== --- lib/mrb/mrb_index_info.h 2014-06-08 18:21:55 +0900 (9337c7f) +++ /dev/null @@ -1,38 +0,0 @@ -/* -*- c-basic-offset: 2 -*- */ -/* - Copyright(C) 2014 Brazil - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License version 2.1 as published by the Free Software Foundation. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#ifndef GRN_MRB_INDEX_INFO_H -#define GRN_MRB_INDEX_INFO_H - -#include "../ctx.h" -#include "../db.h" - -#ifdef __cplusplus -extern "C" { -#endif - -void grn_mrb_index_info_init(grn_ctx *ctx); -#ifdef GRN_WITH_MRUBY -mrb_value mrb_grn_index_info_new(mrb_state *mrb, grn_obj *index, int section_id); -#endif - -#ifdef __cplusplus -} -#endif - -#endif /* GRN_MRB_INDEX_INFO_H */ Modified: lib/mrb/mrb_obj.c (+14 -3) =================================================================== --- lib/mrb/mrb_obj.c 2014-06-08 18:21:55 +0900 (8b41675) +++ lib/mrb/mrb_obj.c 2014-06-08 18:28:20 +0900 (e4bd3fd) @@ -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 @@ -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) @@ -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); } } @@ -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 Modified: lib/mrb/mrb_procedure.c (+0 -1) =================================================================== --- lib/mrb/mrb_procedure.c 2014-06-08 18:21:55 +0900 (ecc177e) +++ lib/mrb/mrb_procedure.c 2014-06-08 18:28:20 +0900 (fa9c677) @@ -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", Added: lib/mrb/scripts/index_info.rb (+10 -0) 100644 =================================================================== --- /dev/null +++ lib/mrb/scripts/index_info.rb 2014-06-08 18:28:20 +0900 (cf8336e) @@ -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 Modified: lib/mrb/scripts/scan_info.rb (+11 -0) =================================================================== --- lib/mrb/scripts/scan_info.rb 2014-06-08 18:21:55 +0900 (173506b) +++ lib/mrb/scripts/scan_info.rb 2014-06-08 18:28:20 +0900 (63e3a51) @@ -24,6 +24,17 @@ module Groonga 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| Modified: lib/mrb/scripts/sources.am (+1 -0) =================================================================== --- lib/mrb/scripts/sources.am 2014-06-08 18:21:55 +0900 (fb6dea3) +++ lib/mrb/scripts/sources.am 2014-06-08 18:28:20 +0900 (b4f7717) @@ -1,4 +1,5 @@ RUBY_SCRIPT_FILES = \ eval_context.rb \ expression.rb \ + index_info.rb \ scan_info.rb Modified: lib/mrb/sources.am (+0 -2) =================================================================== --- lib/mrb/sources.am 2014-06-08 18:21:55 +0900 (7943506) +++ lib/mrb/sources.am 2014-06-08 18:28:20 +0900 (9e4b1bd) @@ -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 \ -------------- next part -------------- HTML����������������������������...Download