Navigation Menu

Skip to content

Commit

Permalink
mrb converter: support accessor
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Jun 8, 2014
1 parent 74e8c18 commit 2ca439e
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 22 deletions.
16 changes: 1 addition & 15 deletions lib/mrb/mrb_accessor.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 Down Expand Up @@ -32,20 +32,6 @@ static struct mrb_data_type mrb_grn_accessor_type = {
NULL
};

mrb_value
mrb_grn_accessor_new(mrb_state *mrb, grn_accessor *accessor)
{
grn_ctx *ctx = (grn_ctx *)mrb->ud;
struct RClass *module = ctx->impl->mrb.module;
struct RClass *klass;
mrb_value mrb_accessor_ptr;

mrb_accessor_ptr = mrb_cptr_value(mrb, accessor);
klass = mrb_class_ptr(mrb_const_get(mrb, mrb_obj_value(module),
mrb_intern(mrb, "Accessor")));
return mrb_obj_new(mrb, klass, 1, &mrb_accessor_ptr);
}

static mrb_value
mrb_grn_accessor_initialize(mrb_state *mrb, mrb_value self)
{
Expand Down
5 changes: 1 addition & 4 deletions lib/mrb/mrb_accessor.h
@@ -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 @@ -27,9 +27,6 @@ extern "C" {
#endif

void grn_mrb_accessor_init(grn_ctx *ctx);
#ifdef GRN_WITH_MRUBY
mrb_value mrb_grn_accessor_new(mrb_state *mrb, grn_accessor *accessor);
#endif

#ifdef __cplusplus
}
Expand Down
3 changes: 3 additions & 0 deletions lib/mrb/mrb_converter.c
Expand Up @@ -34,6 +34,9 @@ grn_mrb_class_from_grn_obj(mrb_state *mrb, grn_obj *object)

data = &(ctx->impl->mrb);
switch (object->header.type) {
case GRN_ACCESSOR :
klass = mrb_class_get_under(mrb, data->module, "Accessor");
break;
case GRN_COLUMN_FIX_SIZE :
klass = mrb_class_get_under(mrb, data->module, "FixedSizeColumn");
break;
Expand Down
6 changes: 3 additions & 3 deletions lib/mrb/mrb_expr.c
Expand Up @@ -188,7 +188,7 @@ scan_info_build(grn_ctx *ctx, grn_obj *expr, int *n,
mrb_value mrb_accessor;
weight = mrb_fixnum(mrb_funcall(mrb, mrb_ec, "weight", 0));
grn_scan_info_set_flags(si, grn_scan_info_get_flags(si) | SCAN_ACCESSOR);
mrb_accessor = mrb_grn_accessor_new(mrb, (grn_accessor *)ec->value);
mrb_accessor = grn_mrb_value_from_grn_obj(mrb, ec->value);
if (!mrb_nil_p(mrb_funcall(mrb, mrb_accessor, "next", 0))) {
mrb_funcall(mrb, mrb_si, "put_index", 3,
mrb_cptr_value(mrb, ec->value),
Expand Down Expand Up @@ -246,7 +246,7 @@ scan_info_build(grn_ctx *ctx, grn_obj *expr, int *n,
} else if (GRN_ACCESSORP(*p)) {
grn_scan_info_set_flags(si, grn_scan_info_get_flags(si) | SCAN_ACCESSOR);
if (grn_column_index(ctx, *p, c->op, &index, 1, &sid)) {
mrb_value mrb_accessor = mrb_grn_accessor_new(mrb, (grn_accessor *)*p);
mrb_value mrb_accessor = grn_mrb_value_from_grn_obj(mrb, *p);
if (!mrb_nil_p(mrb_funcall(mrb, mrb_accessor, "next", 0))) {
mrb_funcall(mrb, mrb_si, "put_index", 3,
mrb_cptr_value(mrb, *p),
Expand Down Expand Up @@ -362,7 +362,7 @@ scan_info_build(grn_ctx *ctx, grn_obj *expr, int *n,
mrb_funcall(mrb, mrb_si, "resolve_index_db_obj", 1, mrb_target);
} else if (GRN_ACCESSORP(*p)) {
mrb_value mrb_target;
mrb_target = mrb_grn_accessor_new(mrb, (grn_accessor *)(*p));
mrb_target = grn_mrb_value_from_grn_obj(mrb, *p);
mrb_funcall(mrb, mrb_si, "resolve_index_accessor", 1, mrb_target);
} else {
mrb_funcall(mrb, mrb_si, "query=", 1, mrb_cptr_value(mrb, *p));
Expand Down

0 comments on commit 2ca439e

Please sign in to comment.