1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* eval.c (massign): removed awkward conversion between yvalue,

mvalue, etc.

* eval.c (rb_yield_0): new parameter added to tell whether val is
  an array value or not.

* parse.y (yield_args): restructuring: new nodes: NODE_RESTARY2,
  NODE_SVALUE; removed node: NODE_RESTARGS.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3269 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 2003-01-01 03:24:29 +00:00
parent 2a54402839
commit 0082edfd3d
5 changed files with 187 additions and 215 deletions

View file

@ -5,6 +5,17 @@ Wed Jan 1 04:16:18 2003 Akinori MUSHA <knu@iDaemons.org>
sizeof(int) != sizeof(long) and the byte order is big-endian. sizeof(int) != sizeof(long) and the byte order is big-endian.
This fixes breakage on FreeBSD/sparc64. This fixes breakage on FreeBSD/sparc64.
Tue Dec 31 23:22:50 2002 Yukihiro Matsumoto <matz@ruby-lang.org>
* eval.c (massign): removed awkward conversion between yvalue,
mvalue, etc.
* eval.c (rb_yield_0): new parameter added to tell whether val is
an array value or not.
* parse.y (yield_args): restructuring: new nodes: NODE_RESTARY2,
NODE_SVALUE; removed node: NODE_RESTARGS.
Tue Dec 31 21:13:51 2002 WATANABE Hirofumi <eban@ruby-lang.org> Tue Dec 31 21:13:51 2002 WATANABE Hirofumi <eban@ruby-lang.org>
* Makefile.in, {win32,bcc32}/Makefile.sub: add new target: * Makefile.in, {win32,bcc32}/Makefile.sub: add new target:

173
eval.c
View file

@ -905,7 +905,7 @@ static VALUE rb_eval _((VALUE,NODE*));
static VALUE eval _((VALUE,VALUE,VALUE,char*,int)); static VALUE eval _((VALUE,VALUE,VALUE,char*,int));
static NODE *compile _((VALUE, char*, int)); static NODE *compile _((VALUE, char*, int));
static VALUE rb_yield_0 _((VALUE, VALUE, VALUE, int)); static VALUE rb_yield_0 _((VALUE, VALUE, VALUE, int, int));
static VALUE rb_call _((VALUE,VALUE,ID,int,const VALUE*,int)); static VALUE rb_call _((VALUE,VALUE,ID,int,const VALUE*,int));
static VALUE module_setup _((VALUE,NODE*)); static VALUE module_setup _((VALUE,NODE*));
@ -2157,82 +2157,61 @@ call_trace_func(event, node, self, id, klass)
} }
static VALUE static VALUE
svalue_to_avalue(v) mrhs_to_svalue(v)
VALUE v; VALUE v;
{ {
if (NIL_P(v)) return rb_ary_new2(0); VALUE tmp;
if (v == Qundef) return rb_ary_new2(0);
if (TYPE(v) == T_ARRAY) {
if (RARRAY(v)->len > 1) return v;
return rb_ary_new3(1, v);
}
else {
v = rb_ary_to_ary(v);
}
return v;
}
static VALUE if (v == Qundef) return v;
avalue_to_svalue(v) tmp = rb_check_array_type(v);
VALUE v; if (NIL_P(tmp)) {
{
if (TYPE(v) != T_ARRAY) {
v = rb_ary_to_ary(v);
}
if (RARRAY(v)->len == 0) {
return Qnil;
}
if (RARRAY(v)->len == 1) {
return RARRAY(v)->ptr[0];
}
return v;
}
static VALUE
avalue_to_yvalue(v)
VALUE v;
{
if (TYPE(v) != T_ARRAY) {
v = rb_ary_to_ary(v);
}
if (RARRAY(v)->len == 0) {
return Qundef;
}
if (RARRAY(v)->len == 1) {
return RARRAY(v)->ptr[0];
}
return v;
}
static VALUE
svalue_to_mvalue(v)
VALUE v;
{
if (v == Qnil || v == Qundef)
return rb_ary_new2(0);
if (TYPE(v) == T_ARRAY) {
return v; return v;
} }
else { if (RARRAY(tmp)->len == 0) {
v = rb_ary_to_ary(v); return Qundef;
}
if (RARRAY(tmp)->len == 1) {
return RARRAY(tmp)->ptr[0];
}
return tmp;
}
static VALUE
mrhs_to_avalue(v)
VALUE v;
{
VALUE tmp;
if (v == Qundef) return rb_ary_new2(0);
tmp = rb_check_array_type(v);
if (NIL_P(tmp)) {
return rb_ary_new3(1, v);
} }
return v; return v;
} }
static VALUE static VALUE
mvalue_to_svalue(v) args_to_svalue(v)
VALUE v; VALUE v;
{ {
if (TYPE(v) != T_ARRAY) { VALUE tmp;
v = rb_ary_to_ary(v);
if (v == Qundef) return v;
tmp = rb_check_array_type(v);
if (NIL_P(tmp)) {
return v;
} }
if (RARRAY(v)->len == 0) { if (RARRAY(tmp)->len == 0) {
return Qnil; return Qundef;
} }
if (RARRAY(v)->len == 1 && TYPE(RARRAY(v)->ptr[0]) != T_ARRAY) { if (RARRAY(tmp)->len == 1) {
return RARRAY(v)->ptr[0]; v = rb_check_array_type(tmp);
if (NIL_P(v)) {
return RARRAY(tmp)->ptr[0];
}
} }
return v; return tmp;
} }
static void return_check _((void)); static void return_check _((void));
@ -2557,23 +2536,13 @@ rb_eval(self, n)
break; break;
case NODE_BREAK: case NODE_BREAK:
if (node->nd_stts) { return_value(rb_eval(self, node->nd_stts));
return_value(avalue_to_svalue(rb_eval(self, node->nd_stts)));
}
else {
return_value(Qnil);
}
JUMP_TAG(TAG_BREAK); JUMP_TAG(TAG_BREAK);
break; break;
case NODE_NEXT: case NODE_NEXT:
CHECK_INTS; CHECK_INTS;
if (node->nd_stts) { return_value(rb_eval(self, node->nd_stts));
return_value(avalue_to_svalue(rb_eval(self, node->nd_stts)));
}
else {
return_value(Qnil);
}
JUMP_TAG(TAG_NEXT); JUMP_TAG(TAG_NEXT);
break; break;
@ -2587,24 +2556,29 @@ rb_eval(self, n)
JUMP_TAG(TAG_RETRY); JUMP_TAG(TAG_RETRY);
break; break;
case NODE_RESTARGS:
case NODE_RESTARY: case NODE_RESTARY:
case NODE_RESTARY2:
result = rb_ary_to_ary(rb_eval(self, node->nd_head)); result = rb_ary_to_ary(rb_eval(self, node->nd_head));
break; break;
case NODE_REXPAND: case NODE_REXPAND:
result = avalue_to_svalue(rb_eval(self, node->nd_head)); result = mrhs_to_svalue(rb_eval(self, node->nd_head));
break;
case NODE_SVALUE:
result = rb_eval(self, node->nd_head);
if (result == Qundef) result = Qnil;
break; break;
case NODE_YIELD: case NODE_YIELD:
if (node->nd_stts) { if (node->nd_stts) {
result = avalue_to_yvalue(rb_eval(self, node->nd_stts)); result = rb_eval(self, node->nd_head);
} }
else { else {
result = Qundef; /* no arg */ result = Qundef; /* no arg */
} }
SET_CURRENT_SOURCE(); SET_CURRENT_SOURCE();
result = rb_yield_0(result, 0, 0, 0); result = rb_yield_0(result, 0, 0, 0, 0);
break; break;
case NODE_RESCUE: case NODE_RESCUE:
@ -2742,12 +2716,7 @@ rb_eval(self, n)
break; break;
case NODE_RETURN: case NODE_RETURN:
if (node->nd_stts) { return_value(rb_eval(self, node->nd_stts));
return_value(avalue_to_svalue(rb_eval(self, node->nd_stts)));
}
else {
return_value(Qnil);
}
return_check(); return_check();
JUMP_TAG(TAG_RETURN); JUMP_TAG(TAG_RETURN);
break; break;
@ -2958,7 +2927,7 @@ rb_eval(self, n)
break; break;
case NODE_MASGN: case NODE_MASGN:
result = massign(self, node, rb_eval(self, node->nd_value),0); result = massign(self, node, rb_eval(self, node->nd_value), 0);
break; break;
case NODE_LASGN: case NODE_LASGN:
@ -3826,9 +3795,9 @@ rb_f_block_given_p()
} }
static VALUE static VALUE
rb_yield_0(val, self, klass, pcall) rb_yield_0(val, self, klass, pcall, avalue)
VALUE val, self, klass; /* OK */ VALUE val, self, klass; /* OK */
int pcall; int pcall, avalue;
{ {
NODE *node; NODE *node;
volatile VALUE result = Qnil; volatile VALUE result = Qnil;
@ -3889,18 +3858,14 @@ rb_yield_0(val, self, klass, pcall)
massign(self, block->var, val, pcall); massign(self, block->var, val, pcall);
} }
else { else {
if (pcall) { if (avalue) val = mrhs_to_svalue(val);
val = avalue_to_yvalue(val); if (val == Qundef) val = Qnil;
}
assign(self, block->var, val, pcall); assign(self, block->var, val, pcall);
} }
} }
POP_TAG(); POP_TAG();
if (state) goto pop_state; if (state) goto pop_state;
} }
else if (pcall) {
val = avalue_to_yvalue(val);
}
PUSH_ITER(block->iter); PUSH_ITER(block->iter);
PUSH_TAG(PROT_NONE); PUSH_TAG(PROT_NONE);
@ -3981,14 +3946,14 @@ VALUE
rb_yield(val) rb_yield(val)
VALUE val; VALUE val;
{ {
return rb_yield_0(val, 0, 0, 0); return rb_yield_0(val, 0, 0, 0, 0);
} }
static VALUE static VALUE
rb_f_loop() rb_f_loop()
{ {
for (;;) { for (;;) {
rb_yield_0(Qundef, 0, 0, 0); rb_yield_0(Qundef, 0, 0, 0, 0);
CHECK_INTS; CHECK_INTS;
} }
return Qnil; /* dummy */ return Qnil; /* dummy */
@ -4004,9 +3969,7 @@ massign(self, node, val, pcall)
NODE *list; NODE *list;
long i = 0, len; long i = 0, len;
if (!pcall) { val = mrhs_to_avalue(val);
val = svalue_to_mvalue(val);
}
len = RARRAY(val)->len; len = RARRAY(val)->len;
list = node->nd_head; list = node->nd_head;
for (i=0; list && i<len; i++) { for (i=0; list && i<len; i++) {
@ -4095,7 +4058,7 @@ assign(self, lhs, val, pcall)
break; break;
case NODE_MASGN: case NODE_MASGN:
massign(self, lhs, svalue_to_mvalue(val), pcall); massign(self, lhs, val, pcall);
break; break;
case NODE_CALL: case NODE_CALL:
@ -5329,7 +5292,7 @@ static VALUE
yield_under_i(self) yield_under_i(self)
VALUE self; VALUE self;
{ {
return rb_yield_0(self, self, ruby_class, 0); return rb_yield_0(self, self, ruby_class, 0, 0);
} }
/* block eval under the class/module context */ /* block eval under the class/module context */
@ -6620,14 +6583,11 @@ proc_invoke(proc, args, pcall, self)
PUSH_ITER(ITER_CUR); PUSH_ITER(ITER_CUR);
ruby_frame->iter = ITER_CUR; ruby_frame->iter = ITER_CUR;
if (!pcall) {
args = avalue_to_yvalue(args);
}
PUSH_TAG(PROT_NONE); PUSH_TAG(PROT_NONE);
state = EXEC_TAG(); state = EXEC_TAG();
if (state == 0) { if (state == 0) {
proc_set_safe_level(proc); proc_set_safe_level(proc);
result = rb_yield_0(args, self, self!=Qundef?CLASS_OF(self):0, pcall); result = rb_yield_0(args, self, self!=Qundef?CLASS_OF(self):0, pcall, Qtrue);
} }
POP_TAG(); POP_TAG();
@ -7167,7 +7127,6 @@ static VALUE
bmcall(args, method) bmcall(args, method)
VALUE args, method; VALUE args, method;
{ {
args = svalue_to_avalue(args);
return method_call(RARRAY(args)->len, RARRAY(args)->ptr, method); return method_call(RARRAY(args)->len, RARRAY(args)->ptr, method);
} }
@ -8951,7 +8910,7 @@ rb_thread_yield(arg, th)
rb_dvar_push('~', Qnil); rb_dvar_push('~', Qnil);
ruby_block->dyna_vars = ruby_dyna_vars; ruby_block->dyna_vars = ruby_dyna_vars;
return rb_yield_0(mvalue_to_svalue(arg), 0, 0, Qtrue); return rb_yield_0(arg, 0, 0, Qtrue, Qtrue);
} }
static VALUE static VALUE
@ -9546,7 +9505,7 @@ rb_f_catch(dmy, tag)
t = rb_to_id(tag); t = rb_to_id(tag);
PUSH_TAG(t); PUSH_TAG(t);
if ((state = EXEC_TAG()) == 0) { if ((state = EXEC_TAG()) == 0) {
val = rb_yield_0(tag, 0, 0, 0); val = rb_yield_0(tag, 0, 0, 0, Qfalse);
} }
else if (state == TAG_THROW && t == prot_tag->dst) { else if (state == TAG_THROW && t == prot_tag->dst) {
val = prot_tag->retval; val = prot_tag->retval;

6
node.h
View file

@ -87,9 +87,10 @@ enum node_type {
NODE_ARGS, NODE_ARGS,
NODE_ARGSCAT, NODE_ARGSCAT,
NODE_ARGSPUSH, NODE_ARGSPUSH,
NODE_RESTARGS,
NODE_RESTARY, NODE_RESTARY,
NODE_RESTARY2,
NODE_REXPAND, NODE_REXPAND,
NODE_SVALUE,
NODE_BLOCK_ARG, NODE_BLOCK_ARG,
NODE_BLOCK_PASS, NODE_BLOCK_PASS,
NODE_DEFN, NODE_DEFN,
@ -306,9 +307,10 @@ typedef struct RNode {
#define NEW_ARGS(f,o,r) rb_node_newnode(NODE_ARGS,o,r,f) #define NEW_ARGS(f,o,r) rb_node_newnode(NODE_ARGS,o,r,f)
#define NEW_ARGSCAT(a,b) rb_node_newnode(NODE_ARGSCAT,a,b,0) #define NEW_ARGSCAT(a,b) rb_node_newnode(NODE_ARGSCAT,a,b,0)
#define NEW_ARGSPUSH(a,b) rb_node_newnode(NODE_ARGSPUSH,a,b,0) #define NEW_ARGSPUSH(a,b) rb_node_newnode(NODE_ARGSPUSH,a,b,0)
#define NEW_RESTARGS(a) rb_node_newnode(NODE_RESTARGS,a,0,0)
#define NEW_RESTARY(a) rb_node_newnode(NODE_RESTARY,a,0,0) #define NEW_RESTARY(a) rb_node_newnode(NODE_RESTARY,a,0,0)
#define NEW_RESTARY2(a) rb_node_newnode(NODE_RESTARY2,a,0,0)
#define NEW_REXPAND(a) rb_node_newnode(NODE_REXPAND,a,0,0) #define NEW_REXPAND(a) rb_node_newnode(NODE_REXPAND,a,0,0)
#define NEW_SVALUE(a) rb_node_newnode(NODE_SVALUE,a,0,0)
#define NEW_BLOCK_ARG(v) rb_node_newnode(NODE_BLOCK_ARG,v,0,local_cnt(v)) #define NEW_BLOCK_ARG(v) rb_node_newnode(NODE_BLOCK_ARG,v,0,local_cnt(v))
#define NEW_BLOCK_PASS(b) rb_node_newnode(NODE_BLOCK_PASS,0,b,0) #define NEW_BLOCK_PASS(b) rb_node_newnode(NODE_BLOCK_PASS,0,b,0)
#define NEW_ALIAS(n,o) rb_node_newnode(NODE_ALIAS,o,n,0) #define NEW_ALIAS(n,o) rb_node_newnode(NODE_ALIAS,o,n,0)

57
parse.y
View file

@ -137,6 +137,7 @@ static NODE *new_evstr();
static NODE *call_op(); static NODE *call_op();
static int in_defined = 0; static int in_defined = 0;
static NODE *yield_args();
static NODE *ret_args(); static NODE *ret_args();
static NODE *arg_blk_pass(); static NODE *arg_blk_pass();
static NODE *new_call(); static NODE *new_call();
@ -245,7 +246,7 @@ static void top_local_setup();
%type <node> if_tail opt_else case_body cases opt_rescue exc_list exc_var opt_ensure %type <node> if_tail opt_else case_body cases opt_rescue exc_list exc_var opt_ensure
%type <node> args when_args call_args call_args2 open_args paren_args opt_paren_args %type <node> args when_args call_args call_args2 open_args paren_args opt_paren_args
%type <node> command_args aref_args opt_block_arg block_arg var_ref var_lhs %type <node> command_args aref_args opt_block_arg block_arg var_ref var_lhs
%type <node> mrhs mrhs_basic superclass block_call block_command %type <node> mrhs superclass block_call block_command
%type <node> f_arglist f_args f_optarg f_opt f_block_arg opt_f_block_arg %type <node> f_arglist f_args f_optarg f_opt f_block_arg opt_f_block_arg
%type <node> assoc_list assocs assoc undef_list backref string_dvar %type <node> assoc_list assocs assoc undef_list backref string_dvar
%type <node> block_var opt_block_var brace_block cmd_brace_block do_block lhs none %type <node> block_var opt_block_var brace_block cmd_brace_block do_block lhs none
@ -460,7 +461,7 @@ stmt : kALIAS fitem {lex_state = EXPR_FNAME;} fitem
| mlhs '=' command_call | mlhs '=' command_call
{ {
value_expr($3); value_expr($3);
$1->nd_value = $3; $1->nd_value = NEW_RESTARY($3);
$$ = $1; $$ = $1;
} }
| var_lhs tOP_ASGN command_call | var_lhs tOP_ASGN command_call
@ -546,9 +547,14 @@ stmt : kALIAS fitem {lex_state = EXPR_FNAME;} fitem
rb_backref_error($1); rb_backref_error($1);
$$ = 0; $$ = 0;
} }
| lhs '=' mrhs_basic | lhs '=' mrhs
{ {
$$ = node_assign($1, NEW_REXPAND($3)); $$ = node_assign($1, NEW_SVALUE($3));
}
| mlhs '=' arg_value
{
$1->nd_value = NEW_RESTARY($3);
$$ = $1;
} }
| mlhs '=' mrhs | mlhs '=' mrhs
{ {
@ -689,7 +695,7 @@ command : operation command_args %prec tLOWEST
} }
| kYIELD command_args | kYIELD command_args
{ {
$$ = NEW_YIELD(ret_args($2)); $$ = NEW_YIELD(yield_args($2));
fixpos($$, $2); fixpos($$, $2);
} }
; ;
@ -1147,7 +1153,7 @@ aref_args : none
| tSTAR arg opt_nl | tSTAR arg opt_nl
{ {
value_expr($2); value_expr($2);
$$ = NEW_RESTARY($2); $$ = NEW_RESTARY2($2);
} }
; ;
@ -1212,7 +1218,7 @@ call_args : command
} }
| tSTAR arg_value opt_block_arg | tSTAR arg_value opt_block_arg
{ {
$$ = arg_blk_pass(NEW_RESTARGS($2), $3); $$ = arg_blk_pass(NEW_RESTARY($2), $3);
} }
| block_arg | block_arg
; ;
@ -1267,7 +1273,7 @@ call_args2 : arg_value ',' args opt_block_arg
} }
| tSTAR arg_value opt_block_arg | tSTAR arg_value opt_block_arg
{ {
$$ = arg_blk_pass(NEW_RESTARGS($2), $3); $$ = arg_blk_pass(NEW_RESTARY($2), $3);
} }
| block_arg | block_arg
; ;
@ -1322,17 +1328,7 @@ args : arg_value
} }
; ;
mrhs : arg_value mrhs : args ',' arg_value
{
$$ = $1;
}
| mrhs_basic
{
$$ = NEW_REXPAND($1);
}
;
mrhs_basic : args ',' arg_value
{ {
$$ = list_append($1, $3); $$ = list_append($1, $3);
} }
@ -1342,7 +1338,7 @@ mrhs_basic : args ',' arg_value
} }
| tSTAR arg_value | tSTAR arg_value
{ {
$$ = $2; $$ = NEW_REXPAND($2);
} }
; ;
@ -1408,7 +1404,7 @@ primary : literal
} }
| kYIELD '(' call_args ')' | kYIELD '(' call_args ')'
{ {
$$ = NEW_YIELD(ret_args($3)); $$ = NEW_YIELD(yield_args($3));
} }
| kYIELD '(' ')' | kYIELD '(' ')'
{ {
@ -4765,7 +4761,7 @@ rb_backref_error(node)
rb_compile_error("Can't set variable $%d", node->nd_nth); rb_compile_error("Can't set variable $%d", node->nd_nth);
break; break;
case NODE_BACK_REF: case NODE_BACK_REF:
rb_compile_error("Can't set variable $%c", node->nd_nth); rb_compile_error("Can't set variable $%c", (int)node->nd_nth);
break; break;
} }
} }
@ -5198,6 +5194,20 @@ ret_args(node)
if (nd_type(node) == NODE_BLOCK_PASS) { if (nd_type(node) == NODE_BLOCK_PASS) {
rb_compile_error("block argument should not be given"); rb_compile_error("block argument should not be given");
} }
if (nd_type(node) == NODE_ARRAY && node->nd_next == 0) {
node = node->nd_head;
}
}
return node;
}
static NODE *
yield_args(node)
NODE *node;
{
node = ret_args(node);
if (node && nd_type(node) == NODE_RESTARY) {
nd_set_type(node, NODE_REXPAND);
} }
return node; return node;
} }
@ -5222,7 +5232,8 @@ arg_prepend(node1, node2)
case NODE_ARRAY: case NODE_ARRAY:
return list_concat(NEW_LIST(node1), node2); return list_concat(NEW_LIST(node1), node2);
case NODE_RESTARGS: case NODE_RESTARY:
case NODE_RESTARY2:
return arg_concat(node1, node2->nd_head); return arg_concat(node1, node2->nd_head);
case NODE_BLOCK_PASS: case NODE_BLOCK_PASS:

View file

@ -48,6 +48,7 @@ a = []; test_ok(a == [])
a = [1]; test_ok(a == [1]) a = [1]; test_ok(a == [1])
a = [nil]; test_ok(a == [nil]) a = [nil]; test_ok(a == [nil])
a = [[]]; test_ok(a == [[]]) a = [[]]; test_ok(a == [[]])
a = [1,2]; test_ok(a == [1,2])
a = [*[]]; test_ok(a == []) a = [*[]]; test_ok(a == [])
a = [*[1]]; test_ok(a == [1]) a = [*[1]]; test_ok(a == [1])
a = [*[1,2]]; test_ok(a == [1,2]) a = [*[1,2]]; test_ok(a == [1,2])
@ -58,50 +59,56 @@ a = *[]; test_ok(a == nil)
a = *[1]; test_ok(a == 1) a = *[1]; test_ok(a == 1)
a = *[nil]; test_ok(a == nil) a = *[nil]; test_ok(a == nil)
a = *[[]]; test_ok(a == []) a = *[[]]; test_ok(a == [])
a = *[1,2]; test_ok(a == [1,2])
a = *[*[]]; test_ok(a == nil) a = *[*[]]; test_ok(a == nil)
a = *[*[1]]; test_ok(a == 1) a = *[*[1]]; test_ok(a == 1)
a = *[*[1,2]]; test_ok(a == [1,2]) a = *[*[1,2]]; test_ok(a == [1,2])
*a = nil; test_ok(a == []) *a = nil; test_ok(a == [nil])
*a = 1; test_ok(a == [1]) *a = 1; test_ok(a == [1])
*a = []; test_ok(a == []) *a = []; test_ok(a == [])
*a = [1]; test_ok(a == [1]) *a = [1]; test_ok(a == [1])
*a = [nil]; test_ok(a == [nil]) *a = [nil]; test_ok(a == [nil])
*a = [[]]; test_ok(a == [[]]) *a = [[]]; test_ok(a == [[]])
*a = [1,2]; test_ok(a == [1,2])
*a = [*[]]; test_ok(a == []) *a = [*[]]; test_ok(a == [])
*a = [*[1]]; test_ok(a == [1]) *a = [*[1]]; test_ok(a == [1])
*a = [*[1,2]]; test_ok(a == [1,2]) *a = [*[1,2]]; test_ok(a == [1,2])
*a = *nil; test_ok(a == []) *a = *nil; test_ok(a == [nil])
*a = *1; test_ok(a == [1]) *a = *1; test_ok(a == [1])
*a = *[]; test_ok(a == []) *a = *[]; test_ok(a == [])
*a = *[1]; test_ok(a == [1]) *a = *[1]; test_ok(a == [1])
*a = *[nil]; test_ok(a == []) *a = *[nil]; test_ok(a == [nil])
*a = *[[]]; test_ok(a == []) *a = *[[]]; test_ok(a == [])
*a = *[1,2]; test_ok(a == [1,2])
*a = *[*[]]; test_ok(a == []) *a = *[*[]]; test_ok(a == [])
*a = *[*[1]]; test_ok(a == [1]) *a = *[*[1]]; test_ok(a == [1])
*a = *[*[1,2]]; test_ok(a == [1,2]) *a = *[*[1,2]]; test_ok(a == [1,2])
a,b,*c = nil; test_ok([a,b,c] == [nil, nil, []]) a,b,*c = nil; test_ok([a,b,c] == [nil,nil,[]])
a,b,*c = 1; test_ok([a,b,c] == [1, nil, []]) a,b,*c = 1; test_ok([a,b,c] == [1,nil,[]])
a,b,*c = []; test_ok([a,b,c] == [nil, nil, []]) a,b,*c = []; test_ok([a,b,c] == [nil,nil,[]])
a,b,*c = [1]; test_ok([a,b,c] == [1, nil, []]) a,b,*c = [1]; test_ok([a,b,c] == [1,nil,[]])
a,b,*c = [nil]; test_ok([a,b,c] == [nil, nil, []]) a,b,*c = [nil]; test_ok([a,b,c] == [nil,nil,[]])
a,b,*c = [[]]; test_ok([a,b,c] == [[], nil, []]) a,b,*c = [[]]; test_ok([a,b,c] == [[],nil,[]])
a,b,*c = [*[]]; test_ok([a,b,c] == [nil, nil, []]) a,b,*c = [1,2]; test_ok([a,b,c] == [1,2,[]])
a,b,*c = [*[1]]; test_ok([a,b,c] == [1, nil, []]) a,b,*c = [*[]]; test_ok([a,b,c] == [nil,nil,[]])
a,b,*c = [*[1,2]]; test_ok([a,b,c] == [1, 2, []]) a,b,*c = [*[1]]; test_ok([a,b,c] == [1,nil,[]])
a,b,*c = [*[1,2]]; test_ok([a,b,c] == [1,2,[]])
a,b,*c = *nil; test_ok([a,b,c] == [nil, nil, []]) a,b,*c = *nil; test_ok([a,b,c] == [nil,nil,[]])
a,b,*c = *1; test_ok([a,b,c] == [1, nil, []]) a,b,*c = *1; test_ok([a,b,c] == [1,nil,[]])
a,b,*c = *[]; test_ok([a,b,c] == [nil, nil, []]) a,b,*c = *[]; test_ok([a,b,c] == [nil,nil,[]])
a,b,*c = *[1]; test_ok([a,b,c] == [1, nil, []]) a,b,*c = *[1]; test_ok([a,b,c] == [1,nil,[]])
a,b,*c = *[nil]; test_ok([a,b,c] == [nil, nil, []]) a,b,*c = *[nil]; test_ok([a,b,c] == [nil,nil,[]])
a,b,*c = *[[]]; test_ok([a,b,c] == [nil, nil, []]) a,b,*c = *[[]]; test_ok([a,b,c] == [nil,nil,[]])
a,b,*c = *[*[]]; test_ok([a,b,c] == [nil, nil, []]) a,b,*c = *[1,2]; test_ok([a,b,c] == [1,2,[]])
a,b,*c = *[*[1]]; test_ok([a,b,c] == [1, nil, []]) a,b,*c = *[*[]]; test_ok([a,b,c] == [nil,nil,[]])
a,b,*c = *[*[1,2]]; test_ok([a,b,c] == [1, 2, []]) a,b,*c = *[*[1]]; test_ok([a,b,c] == [1,nil,[]])
a,b,*c = *[*[1,2]]; test_ok([a,b,c] == [1,2,[]])
def f; yield; end; f {|a| test_ok(a == nil)}
def f; yield nil; end; f {|a| test_ok(a == nil)} def f; yield nil; end; f {|a| test_ok(a == nil)}
def f; yield 1; end; f {|a| test_ok(a == 1)} def f; yield 1; end; f {|a| test_ok(a == 1)}
def f; yield []; end; f {|a| test_ok(a == [])} def f; yield []; end; f {|a| test_ok(a == [])}
@ -122,7 +129,8 @@ def f; yield *[*[]]; end; f {|a| test_ok(a == nil)}
def f; yield *[*[1]]; end; f {|a| test_ok(a == 1)} def f; yield *[*[1]]; end; f {|a| test_ok(a == 1)}
def f; yield *[*[1,2]]; end; f {|a| test_ok(a == [1,2])} def f; yield *[*[1,2]]; end; f {|a| test_ok(a == [1,2])}
def f; yield nil; end; f {|*a| test_ok(a == [])} def f; yield; end; f {|*a| test_ok(a == [])}
def f; yield nil; end; f {|*a| test_ok(a == [nil])}
def f; yield 1; end; f {|*a| test_ok(a == [1])} def f; yield 1; end; f {|*a| test_ok(a == [1])}
def f; yield []; end; f {|*a| test_ok(a == [])} def f; yield []; end; f {|*a| test_ok(a == [])}
def f; yield [1]; end; f {|*a| test_ok(a == [1])} def f; yield [1]; end; f {|*a| test_ok(a == [1])}
@ -132,35 +140,36 @@ def f; yield [*[]]; end; f {|*a| test_ok(a == [])}
def f; yield [*[1]]; end; f {|*a| test_ok(a == [1])} def f; yield [*[1]]; end; f {|*a| test_ok(a == [1])}
def f; yield [*[1,2]]; end; f {|*a| test_ok(a == [1,2])} def f; yield [*[1,2]]; end; f {|*a| test_ok(a == [1,2])}
def f; yield *nil; end; f {|*a| test_ok(a == [])} def f; yield *nil; end; f {|*a| test_ok(a == [nil])}
def f; yield *1; end; f {|*a| test_ok(a == [1])} def f; yield *1; end; f {|*a| test_ok(a == [1])}
def f; yield *[]; end; f {|*a| test_ok(a == [])} def f; yield *[]; end; f {|*a| test_ok(a == [])}
def f; yield *[1]; end; f {|*a| test_ok(a == [1])} def f; yield *[1]; end; f {|*a| test_ok(a == [1])}
def f; yield *[nil]; end; f {|*a| test_ok(a == [])} def f; yield *[nil]; end; f {|*a| test_ok(a == [nil])}
def f; yield *[[]]; end; f {|*a| test_ok(a == [])} def f; yield *[[]]; end; f {|*a| test_ok(a == [])}
def f; yield *[*[]]; end; f {|*a| test_ok(a == [])} def f; yield *[*[]]; end; f {|*a| test_ok(a == [])}
def f; yield *[*[1]]; end; f {|*a| test_ok(a == [1])} def f; yield *[*[1]]; end; f {|*a| test_ok(a == [1])}
def f; yield *[*[1,2]]; end; f {|*a| test_ok(a == [1,2])} def f; yield *[*[1,2]]; end; f {|*a| test_ok(a == [1,2])}
def f; yield nil; end; f {|a,b,*c| test_ok([a,b,c] == [nil, nil, []])} def f; yield; end; f {|a,b,*c| test_ok([a,b,c] == [nil,nil,[]])}
def f; yield 1; end; f {|a,b,*c| test_ok([a,b,c] == [1, nil, []])} def f; yield nil; end; f {|a,b,*c| test_ok([a,b,c] == [nil,nil,[]])}
def f; yield []; end; f {|a,b,*c| test_ok([a,b,c] == [nil, nil, []])} def f; yield 1; end; f {|a,b,*c| test_ok([a,b,c] == [1,nil,[]])}
def f; yield [1]; end; f {|a,b,*c| test_ok([a,b,c] == [1, nil, []])} def f; yield []; end; f {|a,b,*c| test_ok([a,b,c] == [nil,nil,[]])}
def f; yield [nil]; end; f {|a,b,*c| test_ok([a,b,c] == [nil, nil, []])} def f; yield [1]; end; f {|a,b,*c| test_ok([a,b,c] == [1,nil,[]])}
def f; yield [[]]; end; f {|a,b,*c| test_ok([a,b,c] == [[], nil, []])} def f; yield [nil]; end; f {|a,b,*c| test_ok([a,b,c] == [nil,nil,[]])}
def f; yield [*[]]; end; f {|a,b,*c| test_ok([a,b,c] == [nil, nil, []])} def f; yield [[]]; end; f {|a,b,*c| test_ok([a,b,c] == [[],nil,[]])}
def f; yield [*[1]]; end; f {|a,b,*c| test_ok([a,b,c] == [1, nil, []])} def f; yield [*[]]; end; f {|a,b,*c| test_ok([a,b,c] == [nil,nil,[]])}
def f; yield [*[1,2]]; end; f {|a,b,*c| test_ok([a,b,c] == [1, 2, []])} def f; yield [*[1]]; end; f {|a,b,*c| test_ok([a,b,c] == [1,nil,[]])}
def f; yield [*[1,2]]; end; f {|a,b,*c| test_ok([a,b,c] == [1,2,[]])}
def f; yield *nil; end; f {|a,b,*c| test_ok([a,b,c] == [nil, nil, []])} def f; yield *nil; end; f {|a,b,*c| test_ok([a,b,c] == [nil,nil,[]])}
def f; yield *1; end; f {|a,b,*c| test_ok([a,b,c] == [1, nil, []])} def f; yield *1; end; f {|a,b,*c| test_ok([a,b,c] == [1,nil,[]])}
def f; yield *[]; end; f {|a,b,*c| test_ok([a,b,c] == [nil, nil, []])} def f; yield *[]; end; f {|a,b,*c| test_ok([a,b,c] == [nil,nil,[]])}
def f; yield *[1]; end; f {|a,b,*c| test_ok([a,b,c] == [1, nil, []])} def f; yield *[1]; end; f {|a,b,*c| test_ok([a,b,c] == [1,nil,[]])}
def f; yield *[nil]; end; f {|a,b,*c| test_ok([a,b,c] == [nil, nil, []])} def f; yield *[nil]; end; f {|a,b,*c| test_ok([a,b,c] == [nil,nil,[]])}
def f; yield *[[]]; end; f {|a,b,*c| test_ok([a,b,c] == [nil, nil, []])} def f; yield *[[]]; end; f {|a,b,*c| test_ok([a,b,c] == [nil,nil,[]])}
def f; yield *[*[]]; end; f {|a,b,*c| test_ok([a,b,c] == [nil, nil, []])} def f; yield *[*[]]; end; f {|a,b,*c| test_ok([a,b,c] == [nil,nil,[]])}
def f; yield *[*[1]]; end; f {|a,b,*c| test_ok([a,b,c] == [1, nil, []])} def f; yield *[*[1]]; end; f {|a,b,*c| test_ok([a,b,c] == [1,nil,[]])}
def f; yield *[*[1,2]]; end; f {|a,b,*c| test_ok([a,b,c] == [1, 2, []])} def f; yield *[*[1,2]]; end; f {|a,b,*c| test_ok([a,b,c] == [1,2,[]])}
test_check "condition" test_check "condition"
@ -679,48 +688,28 @@ class IterTest
end end
IterTest.new(nil).method(:f).to_proc.call([1]) IterTest.new(nil).method(:f).to_proc.call([1])
IterTest.new([0]).each0 { |x| $x = x } IterTest.new([0]).each0 { |x| test_ok(x == 0)}
test_ok($x == 0) IterTest.new([1]).each1 { |x| test_ok(x == 1)}
IterTest.new([1]).each1 { |x| $x = x } IterTest.new([2]).each2 { |x| test_ok(x == [2])}
test_ok($x == 1) IterTest.new([3]).each3 { |x| test_ok(x == 3)}
IterTest.new([2]).each2 { |x| $x = x } IterTest.new([4]).each4 { |x| test_ok(x == 4)}
test_ok($x == [2]) IterTest.new([5]).each5 { |x| test_ok(x == 5)}
IterTest.new([3]).each3 { |x| $x = x } IterTest.new([6]).each6 { |x| test_ok(x == [6])}
test_ok($x == 3) IterTest.new([7]).each7 { |x| test_ok(x == 7)}
IterTest.new([4]).each4 { |x| $x = x } IterTest.new([8]).each8 { |x| test_ok(x == 8)}
test_ok($x == 4)
IterTest.new([5]).each5 { |x| $x = x }
test_ok($x == 5)
IterTest.new([6]).each6 { |x| $x = x }
test_ok($x == [6])
IterTest.new([7]).each7 { |x| $x = x }
test_ok($x == 7)
IterTest.new([8]).each8 { |x| $x = x }
test_ok($x == 8)
IterTest.new([[0]]).each0 { |x| $x = x } IterTest.new([[0]]).each0 { |x| test_ok(x == [0])}
test_ok($x == [0]) IterTest.new([[1]]).each1 { |x| test_ok(x == 1)}
IterTest.new([[1]]).each1 { |x| $x = x } IterTest.new([[2]]).each2 { |x| test_ok(x == [2])}
test_ok($x == 1) IterTest.new([[3]]).each3 { |x| test_ok(x == 3)}
IterTest.new([[2]]).each2 { |x| $x = x } IterTest.new([[4]]).each4 { |x| test_ok(x == [4])}
test_ok($x == [2]) IterTest.new([[5]]).each5 { |x| test_ok(x == 5)}
IterTest.new([[3]]).each3 { |x| $x = x } IterTest.new([[6]]).each6 { |x| test_ok(x == [6])}
test_ok($x == 3) IterTest.new([[7]]).each7 { |x| test_ok(x == 7)}
IterTest.new([[4]]).each4 { |x| $x = x } IterTest.new([[8]]).each8 { |x| test_ok(x == [8])}
test_ok($x == [4])
IterTest.new([[5]]).each5 { |x| $x = x }
test_ok($x == 5)
IterTest.new([[6]]).each6 { |x| $x = x }
test_ok($x == [6])
IterTest.new([[7]]).each7 { |x| $x = x }
test_ok($x == 7)
IterTest.new([[8]]).each8 { |x| $x = x }
test_ok($x == [8])
IterTest.new([[0,0]]).each0 { |x| $x = x } IterTest.new([[0,0]]).each0 { |x| test_ok(x == [0,0])}
test_ok($x == [0,0]) IterTest.new([[8,8]]).each8 { |x| test_ok(x == [8,8])}
IterTest.new([[8,8]]).each8 { |x| $x = x }
test_ok($x == [8,8])
test_check "float" test_check "float"
test_ok(2.6.floor == 2) test_ok(2.6.floor == 2)
@ -948,7 +937,7 @@ test_ok(a == [1, 2, 3])
test_ok(a == [4]) test_ok(a == [4])
*a = nil *a = nil
test_ok(a == []) test_ok(a == [nil])
test_check "call" test_check "call"
def aaa(a, b=100, *rest) def aaa(a, b=100, *rest)