[Groonga-commit] groonga/groonga at e1c3c46 [master] mrb: implement match with expr case in mruby

Back to archive index

Kouhei Sutou null+****@clear*****
Wed Jun 11 00:08:54 JST 2014


Kouhei Sutou	2014-06-11 00:08:54 +0900 (Wed, 11 Jun 2014)

  New Revision: e1c3c46cfd2d17756df7e7afbe358873e93caea2
  https://github.com/groonga/groonga/commit/e1c3c46cfd2d17756df7e7afbe358873e93caea2

  Message:
    mrb: implement match with expr case in mruby

  Added files:
    lib/mrb/mrb_id.c
    lib/mrb/mrb_id.h
    lib/mrb/mrb_operator.c
    lib/mrb/mrb_operator.h
  Modified files:
    lib/ctx_impl_mrb.c
    lib/mrb/mrb_bulk.c
    lib/mrb/mrb_expr.c
    lib/mrb/scripts/scan_info.rb
    lib/mrb/sources.am

  Modified: lib/ctx_impl_mrb.c (+4 -0)
===================================================================
--- lib/ctx_impl_mrb.c    2014-06-10 23:19:26 +0900 (ba7df47)
+++ lib/ctx_impl_mrb.c    2014-06-11 00:08:54 +0900 (f2f53f3)
@@ -20,6 +20,8 @@
 #include "ctx_impl.h"
 
 #include "mrb.h"
+#include "mrb/mrb_id.h"
+#include "mrb/mrb_operator.h"
 #include "mrb/mrb_ctx.h"
 #include "mrb/mrb_bulk.h"
 #include "mrb/mrb_obj.h"
@@ -40,6 +42,8 @@ grn_ctx_impl_mrb_init_bindings(grn_ctx *ctx)
   mrb->ud = ctx;
   ctx->impl->mrb.module = mrb_define_module(mrb, "Groonga");
 
+  grn_mrb_id_init(ctx);
+  grn_mrb_operator_init(ctx);
   grn_mrb_ctx_init(ctx);
   grn_mrb_bulk_init(ctx);
   grn_mrb_obj_init(ctx);

  Modified: lib/mrb/mrb_bulk.c (+5 -4)
===================================================================
--- lib/mrb/mrb_bulk.c    2014-06-10 23:19:26 +0900 (8ebbc8b)
+++ lib/mrb/mrb_bulk.c    2014-06-11 00:08:54 +0900 (aa680b0)
@@ -63,12 +63,13 @@ mrb_grn_bulk_get_value(mrb_state *mrb, mrb_value self)
   switch (bulk->header.domain) {
   case GRN_DB_UINT32 :
     {
-      uint32_t value;
+      int64_t value;
       value = GRN_UINT32_VALUE(bulk);
       if (!FIXABLE(value)) {
-        mrb_raisef(mrb, E_ARGUMENT_ERROR,
-                   "can't handle large number: <%u>: max: <%" PRIiMRB_INT ">",
-                   value, PRIiMRB_INT);
+        mrb_raisef(mrb, E_RANGE_ERROR,
+                   "can't handle large number: <%S>: max: <%S>",
+                   mrb_fixnum_value(value), /* TODO: This will cause overflow */
+                   mrb_fixnum_value(MRB_INT_MAX));
       }
       mrb_value_ = mrb_fixnum_value(value);
     }

  Modified: lib/mrb/mrb_expr.c (+17 -52)
===================================================================
--- lib/mrb/mrb_expr.c    2014-06-10 23:19:26 +0900 (d06f838)
+++ lib/mrb/mrb_expr.c    2014-06-11 00:08:54 +0900 (fa3840b)
@@ -174,60 +174,14 @@ scan_info_build(grn_ctx *ctx, grn_obj *expr, int *n,
       mrb_funcall(mrb, mrb_si, "end=", 1, mrb_fixnum_value(c - e->codes));
       sis[i++] = si;
       {
-        int sid, k;
-        grn_obj *index, *arg, **p = &arg;
+        int k;
+        grn_obj *arg, **p = &arg;
         for (k = 0; (arg = grn_scan_info_get_arg(ctx, si, k)) ; k++) {
           if ((*p)->header.type == GRN_EXPR) {
-            uint32_t j;
-            grn_expr_code *ec;
-            grn_expr *e = (grn_expr *)(*p);
-            for (j = e->codes_curr, ec = e->codes; j--; ec++) {
-              int32_t weight;
-              if (ec->value) {
-                switch (ec->value->header.type) {
-                case GRN_ACCESSOR :
-                  {
-                    mrb_value mrb_ec;
-
-                    mrb_ec = mrb_grn_expr_code_new(mrb, ec);
-                    mrb_funcall(mrb, mrb_si, "match_expr_resolve_index_accessor",
-                                1, mrb_ec);
-                  }
-                  break;
-                case GRN_COLUMN_FIX_SIZE :
-                case GRN_COLUMN_VAR_SIZE :
-                  {
-                    mrb_value mrb_ec;
-
-                    mrb_ec = mrb_grn_expr_code_new(mrb, ec);
-                    mrb_funcall(mrb, mrb_si,
-                                "match_expr_resolve_index_data_column",
-                                1, mrb_ec);
-                  }
-                  break;
-                case GRN_COLUMN_INDEX :
-                  sid = 0;
-                  index = ec->value;
-                  if (j > 2 &&
-                      ec[1].value &&
-                      ec[1].value->header.domain == GRN_DB_UINT32 &&
-                      ec[2].op == GRN_OP_GET_MEMBER) {
-                    sid = GRN_UINT32_VALUE(ec[1].value) + 1;
-                    j -= 2;
-                    ec += 2;
-                  }
-                  {
-                    mrb_value mrb_ec = mrb_grn_expr_code_new(mrb, ec);
-                    weight = mrb_fixnum(mrb_funcall(mrb, mrb_ec, "weight", 0));
-                  }
-                  mrb_funcall(mrb, mrb_si, "put_index", 3,
-                              grn_mrb_value_from_grn_obj(mrb, index),
-                              mrb_fixnum_value(sid),
-                              mrb_fixnum_value(weight));
-                  break;
-                }
-              }
-            }
+            mrb_value mrb_expr;
+            mrb_expr = grn_mrb_value_from_grn_obj(mrb, *p);
+            mrb_funcall(mrb, mrb_si, "match_resolve_index_expression",
+                        1, mrb_expr);
           } else if (GRN_DB_OBJP(*p)) {
             mrb_value mrb_db_obj = grn_mrb_value_from_grn_obj(mrb, *p);
             mrb_funcall(mrb, mrb_si, "match_resolve_index_db_obj", 1, mrb_db_obj);
@@ -519,6 +473,15 @@ mrb_grn_expr_code_get_value(mrb_state *mrb, mrb_value self)
 }
 
 static mrb_value
+mrb_grn_expr_code_get_op(mrb_state *mrb, mrb_value self)
+{
+  grn_expr_code *expr_code;
+
+  expr_code = DATA_PTR(self);
+  return mrb_fixnum_value(expr_code->op);
+}
+
+static mrb_value
 mrb_grn_expression_initialize(mrb_state *mrb, mrb_value self)
 {
   mrb_value mrb_expression_ptr;
@@ -587,6 +550,8 @@ grn_mrb_expr_init(grn_ctx *ctx)
                     mrb_grn_expr_code_get_weight, MRB_ARGS_NONE());
   mrb_define_method(mrb, klass, "value",
                     mrb_grn_expr_code_get_value, MRB_ARGS_NONE());
+  mrb_define_method(mrb, klass, "op",
+                    mrb_grn_expr_code_get_op, MRB_ARGS_NONE());
 
   klass = mrb_define_class_under(mrb, module, "Expression", object_class);
   MRB_SET_INSTANCE_TT(klass, MRB_TT_DATA);

  Added: lib/mrb/mrb_id.c (+74 -0) 100644
===================================================================
--- /dev/null
+++ lib/mrb/mrb_id.c    2014-06-11 00:08:54 +0900 (aa907b8)
@@ -0,0 +1,74 @@
+/* -*- 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 "mrb_id.h"
+
+void
+grn_mrb_id_init(grn_ctx *ctx)
+{
+  mrb_state *mrb = ctx->impl->mrb.state;
+  struct RClass *module = ctx->impl->mrb.module;
+  struct RClass *id_module;
+
+  id_module = mrb_define_module_under(mrb, module, "ID");
+
+  mrb_define_const(mrb, id_module, "VOID",
+                   mrb_fixnum_value(GRN_DB_VOID));
+  mrb_define_const(mrb, id_module, "DB",
+                   mrb_fixnum_value(GRN_DB_DB));
+  mrb_define_const(mrb, id_module, "OBJECT",
+                   mrb_fixnum_value(GRN_DB_OBJECT));
+  mrb_define_const(mrb, id_module, "BOOL",
+                   mrb_fixnum_value(GRN_DB_BOOL));
+  mrb_define_const(mrb, id_module, "INT8",
+                   mrb_fixnum_value(GRN_DB_INT8));
+  mrb_define_const(mrb, id_module, "UINT8",
+                   mrb_fixnum_value(GRN_DB_UINT8));
+  mrb_define_const(mrb, id_module, "INT16",
+                   mrb_fixnum_value(GRN_DB_INT16));
+  mrb_define_const(mrb, id_module, "UINT16",
+                   mrb_fixnum_value(GRN_DB_UINT16));
+  mrb_define_const(mrb, id_module, "INT32",
+                   mrb_fixnum_value(GRN_DB_INT32));
+  mrb_define_const(mrb, id_module, "UINT32",
+                   mrb_fixnum_value(GRN_DB_UINT32));
+  mrb_define_const(mrb, id_module, "INT64",
+                   mrb_fixnum_value(GRN_DB_INT64));
+  mrb_define_const(mrb, id_module, "UINT64",
+                   mrb_fixnum_value(GRN_DB_UINT64));
+  mrb_define_const(mrb, id_module, "FLOAT",
+                   mrb_fixnum_value(GRN_DB_FLOAT));
+  mrb_define_const(mrb, id_module, "TIME",
+                   mrb_fixnum_value(GRN_DB_TIME));
+  mrb_define_const(mrb, id_module, "SHORT_TEXT",
+                   mrb_fixnum_value(GRN_DB_SHORT_TEXT));
+  mrb_define_const(mrb, id_module, "TEXT",
+                   mrb_fixnum_value(GRN_DB_TEXT));
+  mrb_define_const(mrb, id_module, "LONG_TEXT",
+                   mrb_fixnum_value(GRN_DB_LONG_TEXT));
+  mrb_define_const(mrb, id_module, "TOKYO_GEO_POINT",
+                   mrb_fixnum_value(GRN_DB_TOKYO_GEO_POINT));
+  mrb_define_const(mrb, id_module, "WGS84_GEO_POINT",
+                   mrb_fixnum_value(GRN_DB_WGS84_GEO_POINT));
+}
+#endif

  Added: lib/mrb/mrb_id.h (+34 -0) 100644
===================================================================
--- /dev/null
+++ lib/mrb/mrb_id.h    2014-06-11 00:08:54 +0900 (f5b4435)
@@ -0,0 +1,34 @@
+/* -*- 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_ID_H
+#define GRN_MRB_ID_H
+
+#include "../ctx.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void grn_mrb_id_init(grn_ctx *ctx);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* GRN_MRB_ID_H */

  Added: lib/mrb/mrb_operator.c (+190 -0) 100644
===================================================================
--- /dev/null
+++ lib/mrb/mrb_operator.c    2014-06-11 00:08:54 +0900 (5a18d2e)
@@ -0,0 +1,190 @@
+/* -*- 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 "mrb_operator.h"
+
+void
+grn_mrb_operator_init(grn_ctx *ctx)
+{
+  mrb_state *mrb = ctx->impl->mrb.state;
+  struct RClass *module = ctx->impl->mrb.module;
+  struct RClass *operator_module;
+
+  operator_module = mrb_define_module_under(mrb, module, "Operator");
+
+  mrb_define_const(mrb, operator_module, "PUSH",
+                   mrb_fixnum_value(GRN_OP_PUSH));
+  mrb_define_const(mrb, operator_module, "POP",
+                   mrb_fixnum_value(GRN_OP_POP));
+  mrb_define_const(mrb, operator_module, "NOP",
+                   mrb_fixnum_value(GRN_OP_NOP));
+  mrb_define_const(mrb, operator_module, "CALL",
+                   mrb_fixnum_value(GRN_OP_CALL));
+  mrb_define_const(mrb, operator_module, "INTERN",
+                   mrb_fixnum_value(GRN_OP_INTERN));
+  mrb_define_const(mrb, operator_module, "GET_REF",
+                   mrb_fixnum_value(GRN_OP_GET_REF));
+  mrb_define_const(mrb, operator_module, "GET_VALUE",
+                   mrb_fixnum_value(GRN_OP_GET_VALUE));
+  mrb_define_const(mrb, operator_module, "AND",
+                   mrb_fixnum_value(GRN_OP_AND));
+  mrb_define_const(mrb, operator_module, "AND_NOT",
+                   mrb_fixnum_value(GRN_OP_AND_NOT));
+  mrb_define_const(mrb, operator_module, "OR",
+                   mrb_fixnum_value(GRN_OP_OR));
+  mrb_define_const(mrb, operator_module, "ASSIGN",
+                   mrb_fixnum_value(GRN_OP_ASSIGN));
+  mrb_define_const(mrb, operator_module, "STAR_ASSIGN",
+                   mrb_fixnum_value(GRN_OP_STAR_ASSIGN));
+  mrb_define_const(mrb, operator_module, "SLASH_ASSIGN",
+                   mrb_fixnum_value(GRN_OP_SLASH_ASSIGN));
+  mrb_define_const(mrb, operator_module, "MOD_ASSIGN",
+                   mrb_fixnum_value(GRN_OP_MOD_ASSIGN));
+  mrb_define_const(mrb, operator_module, "PLUS_ASSIGN",
+                   mrb_fixnum_value(GRN_OP_PLUS_ASSIGN));
+  mrb_define_const(mrb, operator_module, "MINUS_ASSIGN",
+                   mrb_fixnum_value(GRN_OP_MINUS_ASSIGN));
+  mrb_define_const(mrb, operator_module, "SHIFTL_ASSIGN",
+                   mrb_fixnum_value(GRN_OP_SHIFTL_ASSIGN));
+  mrb_define_const(mrb, operator_module, "SHIFTR_ASSIGN",
+                   mrb_fixnum_value(GRN_OP_SHIFTR_ASSIGN));
+  mrb_define_const(mrb, operator_module, "SHIFTRR_ASSIGN",
+                   mrb_fixnum_value(GRN_OP_SHIFTRR_ASSIGN));
+  mrb_define_const(mrb, operator_module, "AND_ASSIGN",
+                   mrb_fixnum_value(GRN_OP_AND_ASSIGN));
+  mrb_define_const(mrb, operator_module, "XOR_ASSIGN",
+                   mrb_fixnum_value(GRN_OP_XOR_ASSIGN));
+  mrb_define_const(mrb, operator_module, "OR_ASSIGN",
+                   mrb_fixnum_value(GRN_OP_OR_ASSIGN));
+  mrb_define_const(mrb, operator_module, "JUMP",
+                   mrb_fixnum_value(GRN_OP_JUMP));
+  mrb_define_const(mrb, operator_module, "CJUMP",
+                   mrb_fixnum_value(GRN_OP_CJUMP));
+  mrb_define_const(mrb, operator_module, "COMMA",
+                   mrb_fixnum_value(GRN_OP_COMMA));
+  mrb_define_const(mrb, operator_module, "BITWISE_OR",
+                   mrb_fixnum_value(GRN_OP_BITWISE_OR));
+  mrb_define_const(mrb, operator_module, "BITWISE_XOR",
+                   mrb_fixnum_value(GRN_OP_BITWISE_XOR));
+  mrb_define_const(mrb, operator_module, "BITWISE_AND",
+                   mrb_fixnum_value(GRN_OP_BITWISE_AND));
+  mrb_define_const(mrb, operator_module, "BITWISE_NOT",
+                   mrb_fixnum_value(GRN_OP_BITWISE_NOT));
+  mrb_define_const(mrb, operator_module, "EQUAL",
+                   mrb_fixnum_value(GRN_OP_EQUAL));
+  mrb_define_const(mrb, operator_module, "NOT_EQUAL",
+                   mrb_fixnum_value(GRN_OP_NOT_EQUAL));
+  mrb_define_const(mrb, operator_module, "LESS",
+                   mrb_fixnum_value(GRN_OP_LESS));
+  mrb_define_const(mrb, operator_module, "GREATER",
+                   mrb_fixnum_value(GRN_OP_GREATER));
+  mrb_define_const(mrb, operator_module, "LESS_EQUAL",
+                   mrb_fixnum_value(GRN_OP_LESS_EQUAL));
+  mrb_define_const(mrb, operator_module, "GREATER_EQUAL",
+                   mrb_fixnum_value(GRN_OP_GREATER_EQUAL));
+  mrb_define_const(mrb, operator_module, "IN",
+                   mrb_fixnum_value(GRN_OP_IN));
+  mrb_define_const(mrb, operator_module, "MATCH",
+                   mrb_fixnum_value(GRN_OP_MATCH));
+  mrb_define_const(mrb, operator_module, "NEAR",
+                   mrb_fixnum_value(GRN_OP_NEAR));
+  mrb_define_const(mrb, operator_module, "NEAR2",
+                   mrb_fixnum_value(GRN_OP_NEAR2));
+  mrb_define_const(mrb, operator_module, "SIMILAR",
+                   mrb_fixnum_value(GRN_OP_SIMILAR));
+  mrb_define_const(mrb, operator_module, "TERM_EXTRACT",
+                   mrb_fixnum_value(GRN_OP_TERM_EXTRACT));
+  mrb_define_const(mrb, operator_module, "SHIFTL",
+                   mrb_fixnum_value(GRN_OP_SHIFTL));
+  mrb_define_const(mrb, operator_module, "SHIFTR",
+                   mrb_fixnum_value(GRN_OP_SHIFTR));
+  mrb_define_const(mrb, operator_module, "SHIFTRR",
+                   mrb_fixnum_value(GRN_OP_SHIFTRR));
+  mrb_define_const(mrb, operator_module, "PLUS",
+                   mrb_fixnum_value(GRN_OP_PLUS));
+  mrb_define_const(mrb, operator_module, "MINUS",
+                   mrb_fixnum_value(GRN_OP_MINUS));
+  mrb_define_const(mrb, operator_module, "STAR",
+                   mrb_fixnum_value(GRN_OP_STAR));
+  mrb_define_const(mrb, operator_module, "SLASH",
+                   mrb_fixnum_value(GRN_OP_SLASH));
+  mrb_define_const(mrb, operator_module, "MOD",
+                   mrb_fixnum_value(GRN_OP_MOD));
+  mrb_define_const(mrb, operator_module, "DELETE",
+                   mrb_fixnum_value(GRN_OP_DELETE));
+  mrb_define_const(mrb, operator_module, "INCR",
+                   mrb_fixnum_value(GRN_OP_INCR));
+  mrb_define_const(mrb, operator_module, "DECR",
+                   mrb_fixnum_value(GRN_OP_DECR));
+  mrb_define_const(mrb, operator_module, "INCR_POST",
+                   mrb_fixnum_value(GRN_OP_INCR_POST));
+  mrb_define_const(mrb, operator_module, "DECR_POST",
+                   mrb_fixnum_value(GRN_OP_DECR_POST));
+  mrb_define_const(mrb, operator_module, "NOT",
+                   mrb_fixnum_value(GRN_OP_NOT));
+  mrb_define_const(mrb, operator_module, "ADJUST",
+                   mrb_fixnum_value(GRN_OP_ADJUST));
+  mrb_define_const(mrb, operator_module, "EXACT",
+                   mrb_fixnum_value(GRN_OP_EXACT));
+  mrb_define_const(mrb, operator_module, "LCP",
+                   mrb_fixnum_value(GRN_OP_LCP));
+  mrb_define_const(mrb, operator_module, "PARTIAL",
+                   mrb_fixnum_value(GRN_OP_PARTIAL));
+  mrb_define_const(mrb, operator_module, "UNSPLIT",
+                   mrb_fixnum_value(GRN_OP_UNSPLIT));
+  mrb_define_const(mrb, operator_module, "PREFIX",
+                   mrb_fixnum_value(GRN_OP_PREFIX));
+  mrb_define_const(mrb, operator_module, "SUFFIX",
+                   mrb_fixnum_value(GRN_OP_SUFFIX));
+  mrb_define_const(mrb, operator_module, "GEO_DISTANCE1",
+                   mrb_fixnum_value(GRN_OP_GEO_DISTANCE1));
+  mrb_define_const(mrb, operator_module, "GEO_DISTANCE2",
+                   mrb_fixnum_value(GRN_OP_GEO_DISTANCE2));
+  mrb_define_const(mrb, operator_module, "GEO_DISTANCE3",
+                   mrb_fixnum_value(GRN_OP_GEO_DISTANCE3));
+  mrb_define_const(mrb, operator_module, "GEO_DISTANCE4",
+                   mrb_fixnum_value(GRN_OP_GEO_DISTANCE4));
+  mrb_define_const(mrb, operator_module, "GEO_WITHINP5",
+                   mrb_fixnum_value(GRN_OP_GEO_WITHINP5));
+  mrb_define_const(mrb, operator_module, "GEO_WITHINP6",
+                   mrb_fixnum_value(GRN_OP_GEO_WITHINP6));
+  mrb_define_const(mrb, operator_module, "GEO_WITHINP8",
+                   mrb_fixnum_value(GRN_OP_GEO_WITHINP8));
+  mrb_define_const(mrb, operator_module, "OBJ_SEARCH",
+                   mrb_fixnum_value(GRN_OP_OBJ_SEARCH));
+  mrb_define_const(mrb, operator_module, "EXPR_GET_VAR",
+                   mrb_fixnum_value(GRN_OP_EXPR_GET_VAR));
+  mrb_define_const(mrb, operator_module, "TABLE_CREATE",
+                   mrb_fixnum_value(GRN_OP_TABLE_CREATE));
+  mrb_define_const(mrb, operator_module, "TABLE_SELECT",
+                   mrb_fixnum_value(GRN_OP_TABLE_SELECT));
+  mrb_define_const(mrb, operator_module, "TABLE_SORT",
+                   mrb_fixnum_value(GRN_OP_TABLE_SORT));
+  mrb_define_const(mrb, operator_module, "TABLE_GROUP",
+                   mrb_fixnum_value(GRN_OP_TABLE_GROUP));
+  mrb_define_const(mrb, operator_module, "JSON_PUT",
+                   mrb_fixnum_value(GRN_OP_JSON_PUT));
+  mrb_define_const(mrb, operator_module, "GET_MEMBER",
+                   mrb_fixnum_value(GRN_OP_GET_MEMBER));
+}
+#endif

  Added: lib/mrb/mrb_operator.h (+34 -0) 100644
===================================================================
--- /dev/null
+++ lib/mrb/mrb_operator.h    2014-06-11 00:08:54 +0900 (2650cc9)
@@ -0,0 +1,34 @@
+/* -*- 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_OPERATOR_H
+#define GRN_MRB_OPERATOR_H
+
+#include "../ctx.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void grn_mrb_operator_init(grn_ctx *ctx);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* GRN_MRB_OPERATOR_H */

  Modified: lib/mrb/scripts/scan_info.rb (+35 -2)
===================================================================
--- lib/mrb/scripts/scan_info.rb    2014-06-10 23:19:26 +0900 (f9edae1)
+++ lib/mrb/scripts/scan_info.rb    2014-06-11 00:08:54 +0900 (18636c1)
@@ -18,7 +18,40 @@ module Groonga
       nil
     end
 
-    def match_expr_resolve_index_accessor(expr_code)
+    def match_resolve_index_expression(expression)
+      codes = expression.codes
+      n_codes = codes.size
+      i = 0
+      while i < n_codes
+        code = codes[i]
+        value = code.value
+        case value
+        when Groonga::Accessor
+          match_resolve_index_expression_accessor(code)
+        when Groonga::FixedSizeColumn, Groonga::VariableSizeColumn
+          match_resolve_index_expression_data_column(code)
+        when Groonga::IndexColumn
+          section_id = 0
+          rest_n_codes = n_codes - i
+          if rest_n_codes >= 2 and
+              codes[i + 1].value.is_a?(Groonga::Bulk) and
+              codes[i + 1].value.domain == Groonga::ID::UINT32 and
+              codes[i + 2].op == Groonga::Operator::GET_MEMBER
+            section_id = codes[i + 1].value.value + 1
+            code = codes[i + 2]
+            i += 2
+          end
+          put_index(value, section_id, code.weight)
+        end
+        i += 1
+      end
+    rescue => exception
+      p exception
+      p exception.class
+      puts exception.backtrace
+    end
+
+    def match_resolve_index_expression_accessor(expr_code)
       accessor = expr_code.value
       self.flags |= Flags::ACCESSOR
       index_info = accessor.find_index(op)
@@ -30,7 +63,7 @@ module Groonga
       end
     end
 
-    def match_expr_resolve_index_data_column(expr_code)
+    def match_resolve_index_expression_data_column(expr_code)
       column = expr_code.value
       index_info = column.find_index(op)
       return if index_info.nil?

  Modified: lib/mrb/sources.am (+4 -0)
===================================================================
--- lib/mrb/sources.am    2014-06-10 23:19:26 +0900 (9e4b1bd)
+++ lib/mrb/sources.am    2014-06-11 00:08:54 +0900 (710ecb5)
@@ -13,10 +13,14 @@ libgrnmrb_la_SOURCES =				\
 	mrb_expr.h				\
 	mrb_fixed_size_column.c			\
 	mrb_fixed_size_column.h			\
+	mrb_id.c				\
+	mrb_id.h				\
 	mrb_index_column.c			\
 	mrb_index_column.h			\
 	mrb_obj.c				\
 	mrb_obj.h				\
+	mrb_operator.c				\
+	mrb_operator.h				\
 	mrb_procedure.c				\
 	mrb_procedure.h				\
 	mrb_variable_size_column.c		\
-------------- next part --------------
HTML����������������������������...
Télécharger 



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