diff options
author | ko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-03-21 11:15:15 +0000 |
---|---|---|
committer | ko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-03-21 11:15:15 +0000 |
commit | bb7a2d40ff6190f819feb3d9eef0caaffec1a3f9 (patch) | |
tree | e50ce2d744f47f485bc2d1a4bb7eae57f5a9ed87 /vm.c | |
parent | df896a05608e4041c36488c60218f06ca74830b9 (diff) | |
download | ruby-bb7a2d40ff6190f819feb3d9eef0caaffec1a3f9.tar.gz |
* compile.c, parse.y, eval.c, intern.h, iseq.c, lex.c, node.h,
proc.c, vm.c, vm_macro.def, vm_macro.def, yarvcore.c, yarvcore.h,
debug.c, debug.h: merge half-baked-1.9 changes. The biggest change
is to change node structure around NODE_SCOPE, NODE_ARGS. Every
scope (method/class/block) has own NODE_SCOPE node and NODE_ARGS
represents more details of arguments information. I'll write a
document about detail of node structure.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12117 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'vm.c')
-rw-r--r-- | vm.c | 83 |
1 files changed, 36 insertions, 47 deletions
@@ -678,7 +678,7 @@ th_yield_with_cfunc(rb_thread_t *th, rb_block_t *block, static inline int th_yield_setup_args(rb_iseq_t *iseq, int argc, VALUE *argv) { - int i; + int i, arg_n = iseq->argc + (iseq->arg_rest == -1 ? 0 : 1); if (0) { /* for debug */ int i; @@ -686,6 +686,7 @@ th_yield_setup_args(rb_iseq_t *iseq, int argc, VALUE *argv) for(i=0; i<argc; i++){ dp(argv[i]); } + printf(" argc: %d\n", argc); printf("iseq argc: %d\n", iseq->argc); printf("iseq rest: %d\n", iseq->arg_rest); @@ -693,61 +694,49 @@ th_yield_setup_args(rb_iseq_t *iseq, int argc, VALUE *argv) GET_THREAD()->cfp->sp -= argc; } - if (iseq->argc == 1 && iseq->arg_rest != -1) { - if (argc > 1) { - argv[0] = rb_ary_new4(argc, argv); - argc = 1; - } - else if (iseq->arg_rest > 0) { - argv[0] = rb_ary_new4(argc, argv); - argc = 1; + if (argc == 1 && TYPE(argv[0]) == T_ARRAY && arg_n != 1) { + VALUE ary = argv[0]; + argc = RARRAY_LEN(ary); + + /* TODO: check overflow */ + + for (i=0; i<argc; i++) { + argv[i] = RARRAY_PTR(ary)[i]; } } - else { - if (argc == 1 && TYPE(argv[0]) == T_ARRAY /* && iseq->arg_rest == 0 */) { - VALUE ary = argv[0]; - argc = RARRAY_LEN(ary); - /* TODO: check overflow */ - for (i=0; i<argc; i++) { - argv[i] = RARRAY_PTR(ary)[i]; + if (iseq->arg_rest == -1) { + if (iseq->argc == 1) { + if (argc != 1) { + /* yield 1, 2, 3 for iter{|a| ...} + * + * ruby 1.8 warns on this timing. + * rb_warn("multiple values for a block parameter (%d for %d)", argc, iseq->argc); + */ + argv[0] = rb_ary_new4(argc, argv); + argc = 1; } } - if (iseq->arg_rest != 0) { - if (iseq->arg_rest == -1) { - /* */ - } - else { - int rest = iseq->arg_rest - 1; - if (argc <= rest) { - /* param: a, b, c, *r - * args : x, y - * => - * : x, y, nil, [] - */ - for (i=argc; i<rest; i++) { - argv[i] = Qnil; /* initialize */ - } - argv[rest] = rb_ary_new(); - argc = rest + 1; - } - else { - /* param: a, *r - * args : x, y, z - * => - * : x, [y, z] - */ - /* TODO: check overflow */ - argv[rest] = rb_ary_new4(argc - rest, &argv[rest]); - argc = rest + 1; - } - } + if (iseq->argc < argc) { + /* simple truncate */ + argc = iseq->argc; } } + else { + int r = iseq->arg_rest; - if (argc > iseq->argc) { - argc = iseq->argc; + if (argc < r) { + /* TODO: check overflow */ + for (i=argc; i<r; i++) { + argv[i] = Qnil; + } + argv[r] = rb_ary_new(); + } + else { + argv[r] = rb_ary_new4(argc-r, &argv[r]); + } + argc = iseq->arg_rest + 1; } return argc; |