yarv-diff:65
From: ko1 atdot.net
Date: 31 Jul 2005 15:40:43 -0000
Subject: [yarv-diff:65] r220 - in trunk: . test
Author: ko1
Date: 2005-08-01 00:40:42 +0900 (Mon, 01 Aug 2005)
New Revision: 220
Modified:
trunk/ChangeLog
trunk/compile.c
trunk/insns.def
trunk/test.rb
trunk/test/test_class.rb
trunk/test/test_method.rb
trunk/vm.c
trunk/vm_dump.c
trunk/vm_macro.def
trunk/yarvcore.c
Log:
* yarvcore.c, vm.c, insns.def : fix search object path
* compile.c : fix "for" statement
* vm_macro.def : fix rest, opt arguments
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2005-07-31 05:57:19 UTC (rev 219)
+++ trunk/ChangeLog 2005-07-31 15:40:42 UTC (rev 220)
@@ -4,6 +4,15 @@
# from Mon, 03 May 2004 01:24:19 +0900
#
+2005-07-31(Sun) 23:27:24 +0900 Koichi Sasada <ko1 atdot.net>
+
+ * yarvcore.c, vm.c, insns.def : fix search object path
+
+ * compile.c : fix "for" statement
+
+ * vm_macro.def : fix rest, opt arguments
+
+
2005-07-31(Sun) 14:52:06 +0900 Koichi Sasada <ko1 atdot.net>
* vm_macro.def : fix block parameter
Modified: trunk/compile.c
===================================================================
--- trunk/compile.c 2005-07-31 05:57:19 UTC (rev 219)
+++ trunk/compile.c 2005-07-31 15:40:42 UTC (rev 220)
@@ -2137,12 +2137,15 @@
LABEL * retry_end_l = NEW_LABEL(nd_line(node));
VALUE name = rb_str_new2("b@");
rb_str_concat(name, iseqobj->name);
- iseqobj->compile_data->current_block =
- NEW_CHILD_ISEQOBJ(node, make_name_for_block(iseqobj),
- self, ISEQ_TYPE_BLOCK);
+
ADD_LABEL(ret, retry_label);
if(nd_type(node) == NODE_FOR){
COMPILE(ret, "iter caller (for)", node->nd_iter);
+
+ iseqobj->compile_data->current_block =
+ NEW_CHILD_ISEQOBJ(node, make_name_for_block(iseqobj),
+ self, ISEQ_TYPE_BLOCK);
+
ADD_SEND_R(ret, nd_line(node), ID2SYM(idEach), INT2FIX(0),
iseqobj->compile_data->current_block, INT2FIX(0));
if(poped){
@@ -2150,6 +2153,9 @@
}
}
else{
+ iseqobj->compile_data->current_block =
+ NEW_CHILD_ISEQOBJ(node, make_name_for_block(iseqobj),
+ self, ISEQ_TYPE_BLOCK);
COMPILE_(ret, "iter caller", node->nd_iter, poped);
}
ADD_LABEL(ret, retry_end_l);
Modified: trunk/insns.def
===================================================================
--- trunk/insns.def 2005-07-31 05:57:19 UTC (rev 219)
+++ trunk/insns.def 2005-07-31 15:40:42 UTC (rev 220)
@@ -730,7 +730,8 @@
/* dup */
GetISeqVal(body, iseqobj);
- iseqobj->klass_nest_stack = rb_ary_dup(th->klass_nest_stack);
+ rb_funcall2(iseqobj->klass_nest_stack, rb_intern("replace"),
+ 1, &th->klass_nest_stack);
/* make new node */
newbody = NEW_NODE(YARV_METHOD_NODE, NOEX_PUBLIC, body, 0);
Modified: trunk/test/test_class.rb
===================================================================
--- trunk/test/test_class.rb 2005-07-31 05:57:19 UTC (rev 219)
+++ trunk/test/test_class.rb 2005-07-31 15:40:42 UTC (rev 220)
@@ -244,6 +244,38 @@
remove_const(:C3)
end
end
+
+ def test_const_in_other_scope
+ ae %q{
+ class C
+ Const = :ok
+ def m
+ 1.times{
+ Const
+ }
+ end
+ end
+ C.new.m
+ } do
+ remove_const(:C)
+ end
+
+ ae %q{
+ class C
+ Const = 1
+ def m
+ begin
+ raise
+ rescue
+ Const
+ end
+ end
+ end
+ C.new.m
+ } do
+ remove_const(:C)
+ end
+ end
end
Modified: trunk/test/test_method.rb
===================================================================
--- trunk/test/test_method.rb 2005-07-31 05:57:19 UTC (rev 219)
+++ trunk/test/test_method.rb 2005-07-31 15:40:42 UTC (rev 220)
@@ -182,11 +182,48 @@
end
m 10, 20, 30
}
+ end
+ def test_opt_rest
+ ae %q{
+ def m a, b = 0, c = 1, *d
+ [a, b, c, d]
+ end
+
+ m(:a) +
+ m(:a, :b) +
+ m(:a, :b, :c) +
+ m(:a, :b, :c, :d) +
+ m(:a, :b, :c, :d, :e)
+ }
end
-
+ def test_opt_rest_block
+ ae %q{
+ def m a, b = 0, c = 1, *d, &pr
+ [a, b, c, d, pr]
+ end
+
+ m(:a) +
+ m(:a, :b) +
+ m(:a, :b, :c) +
+ m(:a, :b, :c, :d) +
+ m(:a, :b, :c, :d, :e)
+ }
+ ae %q{
+ def m a, b = 0, c = 1, *d, &pr
+ [a, b, c, d, pr.call]
+ end
+
+ m(:a){1} +
+ m(:a, :b){2} +
+ m(:a, :b, :c){3} +
+ m(:a, :b, :c, :d){4} +
+ m(:a, :b, :c, :d, :e){5}
+ }
+ end
+
def test_singletonmethod
ae %q{
lobj = Object.new
Modified: trunk/test.rb
===================================================================
--- trunk/test.rb 2005-07-31 05:57:19 UTC (rev 219)
+++ trunk/test.rb 2005-07-31 15:40:42 UTC (rev 220)
@@ -8,6 +8,36 @@
###########################################################
$prog =<<'__EOP__'
+
+class C
+ Const = 1
+ def m
+ 1.times{
+ p Const
+ }
+ end
+end
+
+C.new.m
+
+
+__END__
+
+class C
+ def m1
+ raise
+ end
+
+ alias m2 m1
+end
+
+begin
+ C.new.m2
+rescue => e
+ puts e.backtrace
+end
+
+__END__
def m
begin
1
Modified: trunk/vm.c
===================================================================
--- trunk/vm.c 2005-07-31 05:57:19 UTC (rev 219)
+++ trunk/vm.c 2005-07-31 15:40:42 UTC (rev 220)
@@ -83,7 +83,6 @@
if(lfp == 0){
lfp = sp;
}
-
PUSH_CONTROL_STACK_FRAME(th,
pc, // pc
sp+1, // sp
@@ -234,6 +233,9 @@
NODE *body, int nosuper){
VALUE val;
yarv_block_t *blockptr = 0;
+
+ //printf("id: %s\n", rb_id2name(id));
+ //SDR2(th->cfp);
if(th->ifuncnode){
blockptr = GET_BLOCK_PTR_IN_CFP(th->cfp);
@@ -249,12 +251,13 @@
const int flag = 0;
th_set_finish_env(th);
+
reg_cfp = th->cfp;
for(i=0; i<argc; i++){
*reg_cfp->sp++ = argv[i];
}
-
+
macro_eval_invoke_func(body->nd_body, recv, klass, blockptr, argc);
val = th_eval_body(th);
break;
@@ -266,7 +269,6 @@
FRAME_MAGIC_CFUNC, recv, (VALUE)blockptr,
0, reg_cfp->sp, 0,
0, 0, 0);
-
val = call_cfunc(body->nd_cfnc, recv, body->nd_argc, argc, argv);
th->cfp = reg_cfp; /* pop control stack frame */
break;
@@ -611,8 +613,9 @@
/* in current lexical scope */
VALUE cref; /* Array */
int i, last_pos;
-
- if((cref = iseq->klass_nest_stack) == 0){
+
+ cref = iseq->klass_nest_stack;
+ if(cref == 0){
/* in module or class scope */
cref = th->klass_nest_stack;
}
@@ -1011,8 +1014,7 @@
exception_handler:
cont_pc = cont_sp = catch_iseqval = 0;
-
- while(th->cfp->pc == 0){
+ while(th->cfp->pc == 0 || th->cfp->iseq == 0){
th->cfp++;
}
cfp = th->cfp;
Modified: trunk/vm_dump.c
===================================================================
--- trunk/vm_dump.c 2005-07-31 05:57:19 UTC (rev 219)
+++ trunk/vm_dump.c 2005-07-31 15:40:42 UTC (rev 220)
@@ -13,18 +13,6 @@
char *magic, *iseq_name = "-", *selfstr = "-", *biseq_name = "-";
VALUE tmp;
- if(cfp->iseq != 0){
- struct cmethod_info *cmi = (void *)cfp->iseq;
-
- if(CMETHOD_INFO_P(cfp->iseq)){
- iseq_name = rb_id2name(cmi->id);
- }
- else{
- pc = cfp->pc - cfp->iseq->ISEQ_MEMBER;
- iseq_name = RSTRING(cfp->iseq->name)->ptr;
- }
- }
-
if(cfp->block_iseq != 0 && BUILTIN_TYPE(cfp->block_iseq) != T_NODE){
biseq_name = RSTRING(cfp->block_iseq->name)->ptr;
}
@@ -47,9 +35,26 @@
case 0: magic = "------"; break;
default: magic = "(none)"; break;
}
- tmp = rb_inspect(cfp->self);
- selfstr = StringValueCStr(tmp);
+ if(1){
+ tmp = rb_inspect(cfp->self);
+ selfstr = StringValueCStr(tmp);
+ }
+ else{
+ selfstr = "";
+ }
+
+ if(cfp->iseq != 0){
+ struct cmethod_info *cmi = (void *)cfp->iseq;
+ if(CMETHOD_INFO_P(cfp->iseq)){
+ iseq_name = rb_id2name(cmi->id);
+ }
+ else{
+ pc = cfp->pc - cfp->iseq->ISEQ_MEMBER;
+ iseq_name = "";//RSTRING(cfp->iseq->name)->ptr;
+ }
+ }
+
printf("c:%04d ", (yarv_control_frame_t *)(th->stack + th->stack_size) - cfp);
printf("p:%04d s:%04d b:%04d ", pc,
cfp->sp - th->stack, bp);
Modified: trunk/vm_macro.def
===================================================================
--- trunk/vm_macro.def 2005-07-31 05:57:19 UTC (rev 219)
+++ trunk/vm_macro.def 2005-07-31 15:40:42 UTC (rev 220)
@@ -70,6 +70,7 @@
MACRO macro_eval_invoke_func(niseqval, recv, klass, blockptr, num){
yarv_iseq_t *niseq;
VALUE *sp = GET_SP();
+ VALUE *rsp = sp - num - 1;
int opt_pc = 0, clear_local_size, i;
/* TODO: eliminate it */
@@ -85,69 +86,83 @@
}
}
else{
- /* rest argument */
+ /* check optional arguments */
+ if(niseq->arg_opts){
+ int iseq_argc = niseq->argc;
+ int opts = niseq->arg_opts;
+
+ if(num < iseq_argc ||
+ (niseq->arg_rest == -1 && num > iseq_argc + opts)){
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for %d)",
+ num, iseq_argc);
+ }
+
+
+ if(num < opts){
+ opt_pc = niseq->arg_opt_tbl[num - iseq_argc];
+ sp += opts - num;
+ num+= opts - num;
+ clear_local_size = niseq->local_size - opts;
+ }
+ else{
+ opt_pc = niseq->arg_opt_tbl[opts-1];
+ }
+ }
+
+ /* check rest */
if(niseq->arg_rest == -2){
- sp += niseq->argc - num + 1;
- num = niseq->argc;
+ if(niseq->arg_opts){
+ num = niseq->argc + niseq->arg_opts;
+ }
+ else{
+ num = niseq->argc;
+ }
+ sp = &rsp[1 + num + 1];
}
else if(niseq->arg_rest != -1){
- int pack_size = num - niseq->arg_rest + niseq->arg_opts;
+ int rest = niseq->arg_rest;
+ int pack_size = num - rest;
+
+ if(0){
+ printf("num: %d, rest: %d, ps: %d\n", num, niseq->arg_rest, pack_size);
+ }
if(pack_size < 0){
rb_raise(rb_eArgError, "wrong number of arguments (%d for %d)",
- num, niseq->arg_rest - niseq->arg_opts);
+ num, rest - niseq->arg_opts);
}
/*
* def m(x,y,z,*a) =>
* x, y, z, a, b, c <SP> => x, y, z, [a,b,c], <SP>
*/
- sp -= pack_size - 1;
- sp[-1] = rb_ary_new4(pack_size, &sp[-1]);
- num -= pack_size;
- clear_local_size += pack_size - 1;
+ rsp[1 + rest] = rb_ary_new4(pack_size, &rsp[1 + rest]);
+ sp = &rsp[2 + rest];
+ num = rest + 1;
+ clear_local_size = niseq->local_size - rest - 1;
}
-
- /* check arguments size */
- if(niseq->arg_opts){
- int argc = niseq->argc;
- int opts = niseq->arg_opts;
- int idx = 0;
-
- if(num < argc || num > argc + opts){
- rb_raise(rb_eArgError, "wrong number of arguments (%d for %d)",
- num, argc);
- }
- idx = num - argc;
- opt_pc = niseq->arg_opt_tbl[idx];
- }
- else{
- if(niseq->argc != num){
- rb_raise(rb_eArgError, "wrong number of arguments (%d for %d)",
- num, niseq->argc);
- }
- }
-
/* block argument */
if(niseq->arg_block != -1){
VALUE arg_block_val = Qnil;
- /* make Proc object */
- if(blockptr->proc == 0){
- yarv_proc_t *proc;
- arg_block_val = th_make_proc(th, GET_CFP(), blockptr);
- GetProcVal(arg_block_val, proc);
- blockptr = &proc->block;
+ if(blockptr){
+ /* make Proc object */
+ if(blockptr->proc == 0){
+ yarv_proc_t *proc;
+ reg_cfp->sp = sp;
+ arg_block_val = th_make_proc(th, GET_CFP(), blockptr);
+ GetProcVal(arg_block_val, proc);
+ blockptr = &proc->block;
+ }
+ else{
+ arg_block_val = blockptr->proc;
+ }
}
- else{
- arg_block_val = blockptr->proc;
- }
-
- sp[-num + niseq->arg_block] = arg_block_val;
+
+ rsp[1 + niseq->arg_block] = arg_block_val;
sp++;
clear_local_size--;
}
}
-
/* stack overflow check */
if(CHECK_STACK_OVERFLOW(th, GET_CFP(), niseq->stack_max)){
rb_bug("stack overflow");
@@ -158,8 +173,6 @@
}
{
- VALUE *rsp = reg_cfp->sp - num - 1;
-
if(0 &&
(flag & VM_CALL_TAILCALL_BIT)){
th->cfp++;
Modified: trunk/yarvcore.c
===================================================================
--- trunk/yarvcore.c 2005-07-31 05:57:19 UTC (rev 219)
+++ trunk/yarvcore.c 2005-07-31 15:40:42 UTC (rev 220)
@@ -350,6 +350,7 @@
static VALUE prepare_iseq_build(yarv_iseq_t *iseqobj,
VALUE name, VALUE file_name,
VALUE parent, VALUE type){
+
iseqobj->name = name;
iseqobj->file_name = file_name;
iseqobj->iseq_mark_ary = rb_ary_new();
@@ -358,20 +359,35 @@
iseqobj->arg_rest = -1;
iseqobj->arg_block = -1;
+ if(parent){
+ if(type != ISEQ_TYPE_CLASS){
+ yarv_iseq_t *piseq;
+ GetISeqVal(parent, piseq);
+ iseqobj->klass_nest_stack = piseq->klass_nest_stack;
+ }
+ }
+ else if(type == ISEQ_TYPE_TOP){
+ iseqobj->klass_nest_stack = rb_ary_new();
+ rb_ary_push(iseqobj->klass_nest_stack, rb_cObject);
+ }
+ else if(type == ISEQ_TYPE_METHOD){
+ iseqobj->klass_nest_stack = rb_ary_new();
+ }
+
iseqobj->compile_data = ALLOC_N(struct iseq_compile_data, 1);
MEMZERO(iseqobj->compile_data, struct iseq_compile_data, 1);
iseqobj->compile_data->mark_ary = rb_ary_new();
-
+
iseqobj->compile_data->storage_head = iseqobj->compile_data->storage_current =
(struct iseq_compile_data_storage *)
ALLOC_N(char, INITIAL_ISEQ_COMPILE_DATA_STORAGE_BUFF_SIZE +
sizeof(struct iseq_compile_data_storage));
-
+
iseqobj->compile_data->storage_head->pos = 0;
iseqobj->compile_data->storage_head->next = 0;
iseqobj->compile_data->storage_head->size = INITIAL_ISEQ_COMPILE_DATA_STORAGE_BUFF_SIZE;
iseqobj->compile_data->storage_head->buff = (char *)(&iseqobj->compile_data->storage_head->buff + 1);
-
+
if(parent && CLASS_OF(parent) == cYarvISeq){
yarv_iseq_t *piseqobj;
GetISeqVal(parent, piseqobj);
--
ML: yarv-diff quickml.atdot.net
Info: http://www.atdot.net/~ko1/quickml