Navigation Menu

Skip to content

Commit

Permalink
expr_code: count called function to the number of arguments
Browse files Browse the repository at this point in the history
It's internal change but it breaks a compatibility that uses
grn_expr_append_op() such as Rroonga.
  • Loading branch information
kou committed Apr 19, 2017
1 parent 872b9d1 commit f940037
Show file tree
Hide file tree
Showing 11 changed files with 116 additions and 35 deletions.
16 changes: 8 additions & 8 deletions lib/expr.c
Expand Up @@ -903,11 +903,11 @@ grn_expr_append_obj(grn_ctx *ctx, grn_obj *expr, grn_obj *obj, grn_operator op,
case GRN_OP_CALL :
{
grn_obj *proc = NULL;
if (e->codes_curr - nargs > 0) {
if (e->codes_curr - (nargs - 1) > 0) {
int i;
grn_expr_code *code;
code = &(e->codes[e->codes_curr - 1]);
for (i = 0; i < nargs; i++) {
for (i = 0; i < nargs - 1; i++) {
int rest_n_codes = 1;
while (rest_n_codes > 0) {
rest_n_codes += code->nargs;
Expand Down Expand Up @@ -951,7 +951,7 @@ grn_expr_append_obj(grn_ctx *ctx, grn_obj *expr, grn_obj *obj, grn_operator op,
}
PUSH_CODE(e, op, obj, nargs, code);
{
int i = nargs;
int i = nargs - 1;
while (i--) { dfi = grn_expr_dfi_pop(e); }
}
if (!obj) { dfi = grn_expr_dfi_pop(e); }
Expand Down Expand Up @@ -2595,16 +2595,16 @@ grn_expr_exec(grn_ctx *ctx, grn_obj *expr, int nargs)
{
grn_obj *proc;
if (code->value) {
if (sp < s_ + code->nargs) {
if (sp < s_ + code->nargs - 1) {
ERR(GRN_INVALID_ARGUMENT, "stack error");
goto exit;
}
proc = code->value;
WITH_SPSAVE({
grn_proc_call(ctx, proc, code->nargs, expr);
grn_proc_call(ctx, proc, code->nargs - 1, expr);
});
} else {
int offset = code->nargs + 1;
int offset = code->nargs;
if (sp < s_ + offset) {
ERR(GRN_INVALID_ARGUMENT, "stack error");
goto exit;
Expand All @@ -2622,7 +2622,7 @@ grn_expr_exec(grn_ctx *ctx, grn_obj *expr, int nargs)
goto exit;
} else {
WITH_SPSAVE({
grn_proc_call(ctx, proc, code->nargs, expr);
grn_proc_call(ctx, proc, code->nargs - 1, expr);
});
}
if (ctx->rc) {
Expand Down Expand Up @@ -7075,7 +7075,7 @@ parse_query(grn_ctx *ctx, efs_info *q)
/* dummy token */
PARSE(GRN_EXPR_TOKEN_QSTRING);
grn_expr_append_obj(ctx, q->e, all_records, GRN_OP_PUSH, 1);
grn_expr_append_op(ctx, q->e, GRN_OP_CALL, 0);
grn_expr_append_op(ctx, q->e, GRN_OP_CALL, 1);
}
}
op->op = GRN_OP_AND_NOT;
Expand Down
24 changes: 4 additions & 20 deletions lib/expr_code.c
Expand Up @@ -24,24 +24,17 @@ grn_expr_code_n_used_codes(grn_ctx *ctx,
{
unsigned int n_codes;
int i, n_args;
grn_bool have_proc_push_code = GRN_FALSE;
grn_expr_code *sub_code;

if (start == target) {
return 0;
}

n_args = target->nargs;
if (target->op == GRN_OP_CALL) {
if (!target->value) {
have_proc_push_code = GRN_TRUE;
}
} else {
if (target->value) {
n_args--;
if (n_args == 0) {
return 1;
}
if (target->value) {
n_args--;
if (n_args == 0) {
return 1;
}
}

Expand All @@ -58,14 +51,5 @@ grn_expr_code_n_used_codes(grn_ctx *ctx,
}
}

if (have_proc_push_code) {
n_codes++;
sub_code--;
if (sub_code < start) {
/* TODO: report error */
return 0;
}
}

return n_codes;
}
2 changes: 1 addition & 1 deletion lib/grn_ecmascript.c
Expand Up @@ -1946,7 +1946,7 @@ static void yy_reduce(
case 65: /* call_expression ::= member_expression arguments */
#line 371 "grn_ecmascript.lemon"
{
grn_expr_append_op(efsi->ctx, efsi->e, GRN_OP_CALL, yymsp[0].minor.yy0);
grn_expr_append_op(efsi->ctx, efsi->e, GRN_OP_CALL, 1 + yymsp[0].minor.yy0);
}
#line 1952 "grn_ecmascript.c"
break;
Expand Down
2 changes: 1 addition & 1 deletion lib/grn_ecmascript.lemon
Expand Up @@ -369,7 +369,7 @@ lefthand_side_expression ::= call_expression.
lefthand_side_expression ::= member_expression.

call_expression ::= member_expression arguments(A). {
grn_expr_append_op(efsi->ctx, efsi->e, GRN_OP_CALL, A);
grn_expr_append_op(efsi->ctx, efsi->e, GRN_OP_CALL, 1 + A);
}

member_expression ::= primary_expression.
Expand Down
2 changes: 1 addition & 1 deletion lib/mrb/scripts/expression_tree/function_call.rb
Expand Up @@ -13,7 +13,7 @@ def build(expression)
@arguments.each do |argument|
argument.build(expression)
end
expression.append_operator(Operator::CALL, @arguments.size)
expression.append_operator(Operator::CALL, 1 + @arguments.size)
end

def estimate_size(table)
Expand Down
2 changes: 1 addition & 1 deletion lib/mrb/scripts/expression_tree_builder.rb
Expand Up @@ -85,7 +85,7 @@ def build
stack.push(node)
when Operator::CALL
arguments = []
code.n_args.times do
(code.n_args - 1).times do
arguments.unshift(stack.pop)
end
procedure = stack.pop
Expand Down
2 changes: 1 addition & 1 deletion lib/window_function.c
Expand Up @@ -241,7 +241,7 @@ grn_expr_is_window_function_call(grn_ctx *ctx,
if (call->op != GRN_OP_CALL) {
return GRN_FALSE;
}
if (call->nargs != (expr->codes_curr - 2)) {
if (call->nargs != (expr->codes_curr - 1)) {
return GRN_FALSE;
}

Expand Down
2 changes: 1 addition & 1 deletion plugins/sharding/range_expression_builder.rb
Expand Up @@ -55,7 +55,7 @@ def build_partial_min_and_max(expression)
expression.append_constant(@target_range.max, Operator::PUSH, 1)
expression.append_constant(@target_range.max_border,
Operator::PUSH, 1)
expression.append_operator(Operator::CALL, 5)
expression.append_operator(Operator::CALL, 6)
build_condition(expression)
end

Expand Down
2 changes: 1 addition & 1 deletion plugins/suggest/suggest.c
Expand Up @@ -462,7 +462,7 @@ correct(grn_ctx *ctx, grn_obj *items, grn_obj *items_boost,
key,
GRN_OP_GET_VALUE, 1);
grn_expr_append_const(ctx, expr, query, GRN_OP_PUSH, 1);
grn_expr_append_op(ctx, expr, GRN_OP_CALL, 2);
grn_expr_append_op(ctx, expr, GRN_OP_CALL, 3);
grn_expr_append_op(ctx, expr, GRN_OP_MINUS_ASSIGN, 2);

if ((tc = grn_table_cursor_open(ctx, res, NULL, 0, NULL, 0, 0, -1, 0))) {
Expand Down
@@ -0,0 +1,48 @@
plugin_register sharding
[[0,0.0,0.0],true]
table_create Logs_20150203 TABLE_NO_KEY
[[0,0.0,0.0],true]
column_create Logs_20150203 timestamp COLUMN_SCALAR Time
[[0,0.0,0.0],true]
column_create Logs_20150203 message COLUMN_SCALAR Text
[[0,0.0,0.0],true]
table_create Logs_20150204 TABLE_NO_KEY
[[0,0.0,0.0],true]
column_create Logs_20150204 timestamp COLUMN_SCALAR Time
[[0,0.0,0.0],true]
column_create Logs_20150204 message COLUMN_SCALAR Text
[[0,0.0,0.0],true]
table_create Logs_20150205 TABLE_NO_KEY
[[0,0.0,0.0],true]
column_create Logs_20150205 timestamp COLUMN_SCALAR Time
[[0,0.0,0.0],true]
column_create Logs_20150205 message COLUMN_SCALAR Text
[[0,0.0,0.0],true]
load --table Logs_20150203
[
{"timestamp": "2015-02-03 23:59:58", "message": "Start"},
{"timestamp": "2015-02-03 23:59:58", "message": "Shutdown"},
{"timestamp": "2015-02-03 23:59:59", "message": "Start"},
{"timestamp": "2015-02-03 23:59:59", "message": "Shutdown"}
]
[[0,0.0,0.0],4]
load --table Logs_20150204
[
{"timestamp": "2015-02-04 00:00:00", "message": "Start"},
{"timestamp": "2015-02-04 00:00:00", "message": "Shutdown"},
{"timestamp": "2015-02-04 00:00:01", "message": "Start"},
{"timestamp": "2015-02-04 00:00:01", "message": "Shutdown"},
{"timestamp": "2015-02-04 23:59:59", "message": "Start"},
{"timestamp": "2015-02-04 23:59:59", "message": "Shutdown"}
]
[[0,0.0,0.0],6]
load --table Logs_20150205
[
{"timestamp": "2015-02-05 00:00:00", "message": "Start"},
{"timestamp": "2015-02-05 00:00:00", "message": "Shutdown"},
{"timestamp": "2015-02-05 00:00:01", "message": "Start"},
{"timestamp": "2015-02-05 00:00:01", "message": "Shutdown"}
]
[[0,0.0,0.0],4]
logical_count Logs timestamp --filter 'message == "Shutdown"' --min "2015-02-04 00:00:01" --min_border "include" --max "2015-02-04 23:59:59" --max_border "include"
[[0,0.0,0.0],2]
@@ -0,0 +1,49 @@
#@on-error omit
plugin_register sharding
#@on-error default

table_create Logs_20150203 TABLE_NO_KEY
column_create Logs_20150203 timestamp COLUMN_SCALAR Time
column_create Logs_20150203 message COLUMN_SCALAR Text

table_create Logs_20150204 TABLE_NO_KEY
column_create Logs_20150204 timestamp COLUMN_SCALAR Time
column_create Logs_20150204 message COLUMN_SCALAR Text

table_create Logs_20150205 TABLE_NO_KEY
column_create Logs_20150205 timestamp COLUMN_SCALAR Time
column_create Logs_20150205 message COLUMN_SCALAR Text

load --table Logs_20150203
[
{"timestamp": "2015-02-03 23:59:58", "message": "Start"},
{"timestamp": "2015-02-03 23:59:58", "message": "Shutdown"},
{"timestamp": "2015-02-03 23:59:59", "message": "Start"},
{"timestamp": "2015-02-03 23:59:59", "message": "Shutdown"}
]

load --table Logs_20150204
[
{"timestamp": "2015-02-04 00:00:00", "message": "Start"},
{"timestamp": "2015-02-04 00:00:00", "message": "Shutdown"},
{"timestamp": "2015-02-04 00:00:01", "message": "Start"},
{"timestamp": "2015-02-04 00:00:01", "message": "Shutdown"},
{"timestamp": "2015-02-04 23:59:59", "message": "Start"},
{"timestamp": "2015-02-04 23:59:59", "message": "Shutdown"}
]

load --table Logs_20150205
[
{"timestamp": "2015-02-05 00:00:00", "message": "Start"},
{"timestamp": "2015-02-05 00:00:00", "message": "Shutdown"},
{"timestamp": "2015-02-05 00:00:01", "message": "Start"},
{"timestamp": "2015-02-05 00:00:01", "message": "Shutdown"}
]

logical_count Logs timestamp \
--filter 'message == "Shutdown"' \
--min "2015-02-04 00:00:01" \
--min_border "include" \
--max "2015-02-04 23:59:59" \
--max_border "include"

0 comments on commit f940037

Please sign in to comment.