summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-01-01 03:24:29 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-01-01 03:24:29 +0000
commit0082edfd3d4c0288cf8464fac54d7655db5a29ca (patch)
tree34a346b3f856bb042d524cc0e8b943f87d55f105
parent2a54402839534bff1bebbf0feb2e53298819aee9 (diff)
* 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
-rw-r--r--ChangeLog11
-rw-r--r--eval.c159
-rw-r--r--node.h6
-rw-r--r--parse.y57
-rw-r--r--sample/test.rb165
5 files changed, 185 insertions, 213 deletions
diff --git a/ChangeLog b/ChangeLog
index 735895e14e..516aef14ec 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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.
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>
* Makefile.in, {win32,bcc32}/Makefile.sub: add new target:
diff --git a/eval.c b/eval.c
index 1c32855f8f..b451a91251 100644
--- a/eval.c
+++ b/eval.c
@@ -905,7 +905,7 @@ static VALUE rb_eval _((VALUE,NODE*));
static VALUE eval _((VALUE,VALUE,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 module_setup _((VALUE,NODE*));
@@ -2157,82 +2157,61 @@ call_trace_func(event, node, self, id, klass)
}
static VALUE
-svalue_to_avalue(v)
+mrhs_to_svalue(v)
VALUE v;
{
- if (NIL_P(v)) return rb_ary_new2(0);
- 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
-avalue_to_svalue(v)
- VALUE v;
-{
- 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;
-}
+ VALUE tmp;
-static VALUE
-avalue_to_yvalue(v)
- VALUE v;
-{
- if (TYPE(v) != T_ARRAY) {
- 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 Qundef;
}
- if (RARRAY(v)->len == 1) {
- return RARRAY(v)->ptr[0];
+ if (RARRAY(tmp)->len == 1) {
+ return RARRAY(tmp)->ptr[0];
}
- return v;
+ return tmp;
}
static VALUE
-svalue_to_mvalue(v)
+mrhs_to_avalue(v)
VALUE v;
{
- if (v == Qnil || v == Qundef)
- return rb_ary_new2(0);
- if (TYPE(v) == T_ARRAY) {
- return v;
- }
- else {
- v = rb_ary_to_ary(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;
}
static VALUE
-mvalue_to_svalue(v)
+args_to_svalue(v)
VALUE v;
{
- if (TYPE(v) != T_ARRAY) {
- v = rb_ary_to_ary(v);
+ VALUE tmp;
+
+ if (v == Qundef) return v;
+ tmp = rb_check_array_type(v);
+ if (NIL_P(tmp)) {
+ return v;
}
- if (RARRAY(v)->len == 0) {
- return Qnil;
+ if (RARRAY(tmp)->len == 0) {
+ return Qundef;
}
- if (RARRAY(v)->len == 1 && TYPE(RARRAY(v)->ptr[0]) != T_ARRAY) {
- return RARRAY(v)->ptr[0];
+ if (RARRAY(tmp)->len == 1) {
+ v = rb_check_array_type(tmp);
+ if (NIL_P(v)) {
+ return RARRAY(tmp)->ptr[0];
+ }
}
- return v;
+ return tmp;
}
static void return_check _((void));
@@ -2557,23 +2536,13 @@ rb_eval(self, n)
break;
case NODE_BREAK:
- if (node->nd_stts) {
- return_value(avalue_to_svalue(rb_eval(self, node->nd_stts)));
- }
- else {
- return_value(Qnil);
- }
+ return_value(rb_eval(self, node->nd_stts));
JUMP_TAG(TAG_BREAK);
break;
case NODE_NEXT:
CHECK_INTS;
- if (node->nd_stts) {
- return_value(avalue_to_svalue(rb_eval(self, node->nd_stts)));
- }
- else {
- return_value(Qnil);
- }
+ return_value(rb_eval(self, node->nd_stts));
JUMP_TAG(TAG_NEXT);
break;
@@ -2587,24 +2556,29 @@ rb_eval(self, n)
JUMP_TAG(TAG_RETRY);
break;
- case NODE_RESTARGS:
case NODE_RESTARY:
+ case NODE_RESTARY2:
result = rb_ary_to_ary(rb_eval(self, node->nd_head));
break;
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;
case NODE_YIELD:
if (node->nd_stts) {
- result = avalue_to_yvalue(rb_eval(self, node->nd_stts));
+ result = rb_eval(self, node->nd_head);
}
else {
result = Qundef; /* no arg */
}
SET_CURRENT_SOURCE();
- result = rb_yield_0(result, 0, 0, 0);
+ result = rb_yield_0(result, 0, 0, 0, 0);
break;
case NODE_RESCUE:
@@ -2742,12 +2716,7 @@ rb_eval(self, n)
break;
case NODE_RETURN:
- if (node->nd_stts) {
- return_value(avalue_to_svalue(rb_eval(self, node->nd_stts)));
- }
- else {
- return_value(Qnil);
- }
+ return_value(rb_eval(self, node->nd_stts));
return_check();
JUMP_TAG(TAG_RETURN);
break;
@@ -2958,7 +2927,7 @@ rb_eval(self, n)
break;
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;
case NODE_LASGN:
@@ -3826,9 +3795,9 @@ rb_f_block_given_p()
}
static VALUE
-rb_yield_0(val, self, klass, pcall)
+rb_yield_0(val, self, klass, pcall, avalue)
VALUE val, self, klass; /* OK */
- int pcall;
+ int pcall, avalue;
{
NODE *node;
volatile VALUE result = Qnil;
@@ -3889,18 +3858,14 @@ rb_yield_0(val, self, klass, pcall)
massign(self, block->var, val, pcall);
}
else {
- if (pcall) {
- val = avalue_to_yvalue(val);
- }
+ if (avalue) val = mrhs_to_svalue(val);
+ if (val == Qundef) val = Qnil;
assign(self, block->var, val, pcall);
}
}
POP_TAG();
if (state) goto pop_state;
}
- else if (pcall) {
- val = avalue_to_yvalue(val);
- }
PUSH_ITER(block->iter);
PUSH_TAG(PROT_NONE);
@@ -3981,14 +3946,14 @@ VALUE
rb_yield(val)
VALUE val;
{
- return rb_yield_0(val, 0, 0, 0);
+ return rb_yield_0(val, 0, 0, 0, 0);
}
static VALUE
rb_f_loop()
{
for (;;) {
- rb_yield_0(Qundef, 0, 0, 0);
+ rb_yield_0(Qundef, 0, 0, 0, 0);
CHECK_INTS;
}
return Qnil; /* dummy */
@@ -4004,9 +3969,7 @@ massign(self, node, val, pcall)
NODE *list;
long i = 0, len;
- if (!pcall) {
- val = svalue_to_mvalue(val);
- }
+ val = mrhs_to_avalue(val);
len = RARRAY(val)->len;
list = node->nd_head;
for (i=0; list && i<len; i++) {
@@ -4095,7 +4058,7 @@ assign(self, lhs, val, pcall)
break;
case NODE_MASGN:
- massign(self, lhs, svalue_to_mvalue(val), pcall);
+ massign(self, lhs, val, pcall);
break;
case NODE_CALL:
@@ -5329,7 +5292,7 @@ static VALUE
yield_under_i(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 */
@@ -6620,14 +6583,11 @@ proc_invoke(proc, args, pcall, self)
PUSH_ITER(ITER_CUR);
ruby_frame->iter = ITER_CUR;
- if (!pcall) {
- args = avalue_to_yvalue(args);
- }
PUSH_TAG(PROT_NONE);
state = EXEC_TAG();
if (state == 0) {
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();
@@ -7167,7 +7127,6 @@ static VALUE
bmcall(args, method)
VALUE args, method;
{
- args = svalue_to_avalue(args);
return method_call(RARRAY(args)->len, RARRAY(args)->ptr, method);
}
@@ -8951,7 +8910,7 @@ rb_thread_yield(arg, th)
rb_dvar_push('~', Qnil);
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
@@ -9546,7 +9505,7 @@ rb_f_catch(dmy, tag)
t = rb_to_id(tag);
PUSH_TAG(t);
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) {
val = prot_tag->retval;
diff --git a/node.h b/node.h
index 74a462a98a..24964c3a1e 100644
--- a/node.h
+++ b/node.h
@@ -87,9 +87,10 @@ enum node_type {
NODE_ARGS,
NODE_ARGSCAT,
NODE_ARGSPUSH,
- NODE_RESTARGS,
NODE_RESTARY,
+ NODE_RESTARY2,
NODE_REXPAND,
+ NODE_SVALUE,
NODE_BLOCK_ARG,
NODE_BLOCK_PASS,
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_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_RESTARGS(a) rb_node_newnode(NODE_RESTARGS,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_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_PASS(b) rb_node_newnode(NODE_BLOCK_PASS,0,b,0)
#define NEW_ALIAS(n,o) rb_node_newnode(NODE_ALIAS,o,n,0)
diff --git a/parse.y b/parse.y
index 664914552c..b2a835e4b7 100644
--- a/parse.y
+++ b/parse.y
@@ -137,6 +137,7 @@ static NODE *new_evstr();
static NODE *call_op();
static int in_defined = 0;
+static NODE *yield_args();
static NODE *ret_args();
static NODE *arg_blk_pass();
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> 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> 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> 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
@@ -460,7 +461,7 @@ stmt : kALIAS fitem {lex_state = EXPR_FNAME;} fitem
| mlhs '=' command_call
{
value_expr($3);
- $1->nd_value = $3;
+ $1->nd_value = NEW_RESTARY($3);
$$ = $1;
}
| var_lhs tOP_ASGN command_call
@@ -546,9 +547,14 @@ stmt : kALIAS fitem {lex_state = EXPR_FNAME;} fitem
rb_backref_error($1);
$$ = 0;
}
- | lhs '=' mrhs_basic
+ | lhs '=' mrhs
+ {
+ $$ = node_assign($1, NEW_SVALUE($3));
+ }
+ | mlhs '=' arg_value
{
- $$ = node_assign($1, NEW_REXPAND($3));
+ $1->nd_value = NEW_RESTARY($3);
+ $$ = $1;
}
| mlhs '=' mrhs
{
@@ -689,7 +695,7 @@ command : operation command_args %prec tLOWEST
}
| kYIELD command_args
{
- $$ = NEW_YIELD(ret_args($2));
+ $$ = NEW_YIELD(yield_args($2));
fixpos($$, $2);
}
;
@@ -1147,7 +1153,7 @@ aref_args : none
| tSTAR arg opt_nl
{
value_expr($2);
- $$ = NEW_RESTARY($2);
+ $$ = NEW_RESTARY2($2);
}
;
@@ -1212,7 +1218,7 @@ call_args : command
}
| tSTAR arg_value opt_block_arg
{
- $$ = arg_blk_pass(NEW_RESTARGS($2), $3);
+ $$ = arg_blk_pass(NEW_RESTARY($2), $3);
}
| block_arg
;
@@ -1267,7 +1273,7 @@ call_args2 : arg_value ',' args 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
;
@@ -1322,17 +1328,7 @@ args : arg_value
}
;
-mrhs : arg_value
- {
- $$ = $1;
- }
- | mrhs_basic
- {
- $$ = NEW_REXPAND($1);
- }
- ;
-
-mrhs_basic : args ',' arg_value
+mrhs : args ',' arg_value
{
$$ = list_append($1, $3);
}
@@ -1342,7 +1338,7 @@ mrhs_basic : args ',' arg_value
}
| tSTAR arg_value
{
- $$ = $2;
+ $$ = NEW_REXPAND($2);
}
;
@@ -1408,7 +1404,7 @@ primary : literal
}
| kYIELD '(' call_args ')'
{
- $$ = NEW_YIELD(ret_args($3));
+ $$ = NEW_YIELD(yield_args($3));
}
| kYIELD '(' ')'
{
@@ -4765,7 +4761,7 @@ rb_backref_error(node)
rb_compile_error("Can't set variable $%d", node->nd_nth);
break;
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;
}
}
@@ -5198,6 +5194,20 @@ ret_args(node)
if (nd_type(node) == NODE_BLOCK_PASS) {
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;
}
@@ -5222,7 +5232,8 @@ arg_prepend(node1, node2)
case NODE_ARRAY:
return list_concat(NEW_LIST(node1), node2);
- case NODE_RESTARGS:
+ case NODE_RESTARY:
+ case NODE_RESTARY2:
return arg_concat(node1, node2->nd_head);
case NODE_BLOCK_PASS:
diff --git a/sample/test.rb b/sample/test.rb
index b16d7779c1..f8a3eb447e 100644
--- a/sample/test.rb
+++ b/sample/test.rb
@@ -48,6 +48,7 @@ a = []; test_ok(a == [])
a = [1]; test_ok(a == [1])
a = [nil]; test_ok(a == [nil])
a = [[]]; test_ok(a == [[]])
+a = [1,2]; test_ok(a == [1,2])
a = [*[]]; test_ok(a == [])
a = [*[1]]; test_ok(a == [1])
a = [*[1,2]]; test_ok(a == [1,2])
@@ -58,50 +59,56 @@ a = *[]; test_ok(a == nil)
a = *[1]; test_ok(a == 1)
a = *[nil]; test_ok(a == nil)
a = *[[]]; test_ok(a == [])
+a = *[1,2]; test_ok(a == [1,2])
a = *[*[]]; test_ok(a == nil)
a = *[*[1]]; test_ok(a == 1)
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 = []; test_ok(a == [])
*a = [1]; test_ok(a == [1])
*a = [nil]; test_ok(a == [nil])
*a = [[]]; test_ok(a == [[]])
+*a = [1,2]; test_ok(a == [1,2])
*a = [*[]]; test_ok(a == [])
*a = [*[1]]; test_ok(a == [1])
*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 = *[]; test_ok(a == [])
*a = *[1]; test_ok(a == [1])
-*a = *[nil]; test_ok(a == [])
+*a = *[nil]; test_ok(a == [nil])
*a = *[[]]; test_ok(a == [])
+*a = *[1,2]; test_ok(a == [1,2])
*a = *[*[]]; test_ok(a == [])
*a = *[*[1]]; test_ok(a == [1])
*a = *[*[1,2]]; test_ok(a == [1,2])
-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 = []; test_ok([a,b,c] == [nil, 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 = [[]]; test_ok([a,b,c] == [[], 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,2]]; test_ok([a,b,c] == [1, 2, []])
-
-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 = *[]; test_ok([a,b,c] == [nil, 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 = *[[]]; 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,2]]; test_ok([a,b,c] == [1, 2, []])
-
+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 = []; test_ok([a,b,c] == [nil,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 = [[]]; test_ok([a,b,c] == [[],nil,[]])
+a,b,*c = [1,2]; test_ok([a,b,c] == [1,2,[]])
+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,2]]; test_ok([a,b,c] == [1,2,[]])
+
+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 = *[]; test_ok([a,b,c] == [nil,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 = *[[]]; test_ok([a,b,c] == [nil,nil,[]])
+a,b,*c = *[1,2]; test_ok([a,b,c] == [1,2,[]])
+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,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 1; end; f {|a| test_ok(a == 1)}
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,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 []; end; f {|*a| test_ok(a == [])}
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,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 *[]; end; f {|*a| test_ok(a == [])}
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 *[*[1]]; end; f {|*a| test_ok(a == [1])}
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 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]; 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, []])}
-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,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 *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]; 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 *[*[]]; 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,2]]; end; f {|a,b,*c| test_ok([a,b,c] == [1, 2, []])}
+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,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,[]])}
+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,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 *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]; 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 *[*[]]; 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,2]]; end; f {|a,b,*c| test_ok([a,b,c] == [1,2,[]])}
test_check "condition"
@@ -679,48 +688,28 @@ class IterTest
end
IterTest.new(nil).method(:f).to_proc.call([1])
-IterTest.new([0]).each0 { |x| $x = x }
-test_ok($x == 0)
-IterTest.new([1]).each1 { |x| $x = x }
-test_ok($x == 1)
-IterTest.new([2]).each2 { |x| $x = x }
-test_ok($x == [2])
-IterTest.new([3]).each3 { |x| $x = x }
-test_ok($x == 3)
-IterTest.new([4]).each4 { |x| $x = x }
-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 }
-test_ok($x == [0])
-IterTest.new([[1]]).each1 { |x| $x = x }
-test_ok($x == 1)
-IterTest.new([[2]]).each2 { |x| $x = x }
-test_ok($x == [2])
-IterTest.new([[3]]).each3 { |x| $x = x }
-test_ok($x == 3)
-IterTest.new([[4]]).each4 { |x| $x = x }
-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 }
-test_ok($x == [0,0])
-IterTest.new([[8,8]]).each8 { |x| $x = x }
-test_ok($x == [8,8])
+IterTest.new([0]).each0 { |x| test_ok(x == 0)}
+IterTest.new([1]).each1 { |x| test_ok(x == 1)}
+IterTest.new([2]).each2 { |x| test_ok(x == [2])}
+IterTest.new([3]).each3 { |x| test_ok(x == 3)}
+IterTest.new([4]).each4 { |x| test_ok(x == 4)}
+IterTest.new([5]).each5 { |x| test_ok(x == 5)}
+IterTest.new([6]).each6 { |x| test_ok(x == [6])}
+IterTest.new([7]).each7 { |x| test_ok(x == 7)}
+IterTest.new([8]).each8 { |x| test_ok(x == 8)}
+
+IterTest.new([[0]]).each0 { |x| test_ok(x == [0])}
+IterTest.new([[1]]).each1 { |x| test_ok(x == 1)}
+IterTest.new([[2]]).each2 { |x| test_ok(x == [2])}
+IterTest.new([[3]]).each3 { |x| test_ok(x == 3)}
+IterTest.new([[4]]).each4 { |x| test_ok(x == [4])}
+IterTest.new([[5]]).each5 { |x| test_ok(x == 5)}
+IterTest.new([[6]]).each6 { |x| test_ok(x == [6])}
+IterTest.new([[7]]).each7 { |x| test_ok(x == 7)}
+IterTest.new([[8]]).each8 { |x| test_ok(x == [8])}
+
+IterTest.new([[0,0]]).each0 { |x| test_ok(x == [0,0])}
+IterTest.new([[8,8]]).each8 { |x| test_ok(x == [8,8])}
test_check "float"
test_ok(2.6.floor == 2)
@@ -948,7 +937,7 @@ test_ok(a == [1, 2, 3])
test_ok(a == [4])
*a = nil
-test_ok(a == [])
+test_ok(a == [nil])
test_check "call"
def aaa(a, b=100, *rest)