yarv-diff:63
From: ko1 atdot.net
Date: 31 Jul 2005 05:54:42 -0000
Subject: [yarv-diff:63] r218 - in trunk: . benchmark test
Author: ko1
Date: 2005-07-31 14:54:41 +0900 (Sun, 31 Jul 2005)
New Revision: 218
Modified:
trunk/ChangeLog
trunk/benchmark/bmx_temp.rb
trunk/compile.c
trunk/insns.def
trunk/test.rb
trunk/test/test_method.rb
trunk/vm.h
trunk/vm_macro.def
Log:
* vm_macro.def : fix block parameter
* compile.c : fix to unuse compile_data->in_ensure
* insns.def : add orphan check when return
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2005-07-30 18:27:58 UTC (rev 217)
+++ trunk/ChangeLog 2005-07-31 05:54:41 UTC (rev 218)
@@ -4,6 +4,15 @@
# from Mon, 03 May 2004 01:24:19 +0900
#
+2005-07-31(Sun) 14:52:06 +0900 Koichi Sasada <ko1 atdot.net>
+
+ * vm_macro.def : fix block parameter
+
+ * compile.c : fix to unuse compile_data->in_ensure
+
+ * insns.def : add orphan check when return
+
+
2005-07-31(Sun) 03:25:05 +0900 Koichi Sasada <ko1 atdot.net>
* vm.c, compile.c, yarvcore.h, insns.def :
Modified: trunk/benchmark/bmx_temp.rb
===================================================================
--- trunk/benchmark/bmx_temp.rb 2005-07-30 18:27:58 UTC (rev 217)
+++ trunk/benchmark/bmx_temp.rb 2005-07-31 05:54:41 UTC (rev 218)
@@ -1,4 +1,19 @@
i = 0
-while i<30000000 # benchmark loop 1
+ary = (1..100).to_a
+
+class Array
+ def map
+ i = 0
+ ret = []
+ while i<self.length
+ ret << yield(self[i])
+ i+=1
+ end
+ ret
+ end
+end
+
+while i<30000
i+=1
+ ary.map{|x| x * 1}
end
Modified: trunk/compile.c
===================================================================
--- trunk/compile.c 2005-07-30 18:27:58 UTC (rev 217)
+++ trunk/compile.c 2005-07-31 05:54:41 UTC (rev 218)
@@ -2350,9 +2350,11 @@
iseqobj->compile_data->ensure_node_stack /* prev */
};
+
iseqobj->compile_data->in_ensure = Qtrue;
+ COMPILE_POPED(ensr, "ensure ensr", node->nd_ensr);
- COMPILE_POPED(ensr, "ensure ensr", node->nd_ensr);
+ iseqobj->compile_data->in_ensure = prev_in_ensure;
iseqobj->compile_data->ensure_node_stack = &enl;
ADD_LABEL(ret, lstart);
@@ -2366,7 +2368,6 @@
}
ADD_LABEL(ret, lcont);
- iseqobj->compile_data->in_ensure = prev_in_ensure;
ADD_CATCH_ENTRY(CATCH_TYPE_ENSURE, lstart, lend, ensure, 0, lcont);
iseqobj->compile_data->ensure_node_stack = enl.prev;
break;
@@ -2983,10 +2984,13 @@
else{
COMPILE(ret, "return nd_stts(return val)", node->nd_stts);
- if(is->type == ISEQ_TYPE_METHOD && is->compile_data->in_ensure == Qfalse){
+ /* TODO: compile_data->in_ensure needed? */
+ if(is->type == ISEQ_TYPE_METHOD){// && is->compile_data->in_ensure == Qfalse){
+ add_ensure_iseq(ret, iseqobj, self);
ADD_INSN(ret, nd_line(node), end);
}
- else if(is->type == ISEQ_TYPE_BLOCK || is->compile_data->in_ensure == Qtrue){
+ else if(is->type == ISEQ_TYPE_BLOCK){// || is->compile_data->in_ensure == Qtrue){
+ add_ensure_iseq(ret, iseqobj, self);
ADD_INSN1(ret, nd_line(node), throw, I2F(0x01) /* TAG_RETURN */);
}
else{
Modified: trunk/insns.def
===================================================================
--- trunk/insns.def 2005-07-30 18:27:58 UTC (rev 217)
+++ trunk/insns.def 2005-07-31 05:54:41 UTC (rev 218)
@@ -1237,7 +1237,7 @@
#ifdef YARV_AOT_COMPILED
throwed = val;
#else
- ORPHAN_ENV(GET_DFP());
+ // ORPHAN_ENV(GET_DFP());
POP_CONTROL_STACK_FRAME(th);
RESTORE_REGS();
#endif
@@ -1296,6 +1296,20 @@
}
}
else if(state == TAG_RETURN){
+ yarv_control_frame_t *cfp = GET_CFP();
+ int is_orphan = 1;
+
+ while(cfp < th->stack + th->stack_size){
+ cfp++;
+ if(GET_LFP() == cfp->lfp){
+ is_orphan = 0;
+ break;
+ }
+ }
+ if(is_orphan){
+ localjump_error("unexpected return", throwobj, TAG_RETURN);
+ }
+
/* set current lfp */
pt = GET_LFP();
}
Modified: trunk/test/test_method.rb
===================================================================
--- trunk/test/test_method.rb 2005-07-30 18:27:58 UTC (rev 217)
+++ trunk/test/test_method.rb 2005-07-31 05:54:41 UTC (rev 218)
@@ -305,6 +305,15 @@
[1,2,3].map(&getproc{|block_e| block_e*block_e})
}
+ ae %q{
+ def m a, b, &c
+ c.call(a, b)
+ end
+
+ m(10, 20){|x, y|
+ [x+y, x*y]
+ }
+ }
end
def test_method_missing
Modified: trunk/test.rb
===================================================================
--- trunk/test.rb 2005-07-30 18:27:58 UTC (rev 217)
+++ trunk/test.rb 2005-07-31 05:54:41 UTC (rev 218)
@@ -8,16 +8,156 @@
###########################################################
$prog =<<'__EOP__'
-4.times{|e|
- p e
- class C
- p 1
- next
- p 2
+def m
+ begin
+ 1
+ ensure
+ return
end
- p 3
+end
+
+
+__END__
+ $i = 0
+ def m
+ begin
+ $i += 1
+ begin
+ $i += 2
+ return
+ ensure
+ $i += 3
+ end
+ ensure
+ $i += 4
+ end
+ p :end
+ end
+ m
+ $i
+
+__END__
+def proc &pr
+ pr
+end
+
+def m
+ a = :m
+ pr = proc{
+ return a
+ }
+ m2 pr
+end
+
+def m2 pr
+ pr.call
+end
+
+m
+
+__END__
+def proc &pr
+ pr
+end
+
+def m
+ a = 10
+ proc{
+ p a
+ return
+ }
+end
+
+m.call
+
+__END__
+i = 0
+ary = (1..100).to_a
+
+class Array_
+ def map
+ i = 0
+ ret = []
+ while i<self.length
+ ret << yield(self[i])
+ i+=1
+ end
+ ret
+ end
+end
+
+while i<30000
+ i+=1
+ ary.map{|x| x * 1}
+end
+
+__END__
+class C
+ def self.cons a, b
+ self.new a, b
+ end
+
+ def initialize a, b
+ @car = a
+ @cdr = b
+ end
+
+ def foldl(x, &block)
+ if @cdr
+ @cdr.foldl(block.call(x, @car), &block)
+ else
+ block.call(x, @car)
+ end
+ end
+
+ def foldl_b(x, &block)
+ if @cdr
+ _ = yield(x, @car)
+ @cdr.foldl_b(_, &block)
+ else
+ _ = yield(x, @car)
+ end
+ end
+
+ def foldl_c(x, &block)
+ if @cdr
+ @cdr.foldl_c(yield(x, @car), &block)
+ else
+ _ = yield(x, @car)
+ end
+ end
+end
+
+obj = C.cons(1, C.cons(2, C.cons(3, nil)))
+p obj.foldl([]){|x, e| x << e}
+p obj.foldl_b([]){|x, e| x << e}
+p obj.foldl_c([]){|x, e| x << e}
+
+__END__
+
+def iter x
+ p yield(x)
+end
+
+def m1 a, &b
+ x = yield(a)
+ iter(x, &b)
+end
+
+def m2 a, &b
+ iter(yield(a), &b)
+end
+
+
+m1(10){|x|
+ x * x
}
+m2(10){|x|
+ x * x
+}
+
+
__EOP__
###########################################################
Modified: trunk/vm.h
===================================================================
--- trunk/vm.h 2005-07-30 18:27:58 UTC (rev 217)
+++ trunk/vm.h 2005-07-31 05:54:41 UTC (rev 218)
@@ -33,7 +33,7 @@
#if 0
#undef VMDEBUG
-#define VMDEBUG 5
+#define VMDEBUG 10
#endif
// #define COLLECT_USAGE_ANALYSIS
Modified: trunk/vm_macro.def
===================================================================
--- trunk/vm_macro.def 2005-07-30 18:27:58 UTC (rev 217)
+++ trunk/vm_macro.def 2005-07-31 05:54:41 UTC (rev 218)
@@ -142,7 +142,7 @@
arg_block_val = blockptr->proc;
}
- sp[-niseq->arg_block] = arg_block_val;
+ sp[-num + niseq->arg_block] = arg_block_val;
sp++;
clear_local_size--;
}
--
ML: yarv-diff quickml.atdot.net
Info: http://www.atdot.net/~ko1/quickml