yarv-diff:14
From: ko1 atdot.net
Date: 13 Jun 2005 22:51:04 -0000
Subject: [yarv-diff:14] r169 - in trunk: . test
Author: ko1
Date: 2005-06-14 07:51:03 +0900 (Tue, 14 Jun 2005)
New Revision: 169
Modified:
trunk/ChangeLog
trunk/compile.c
trunk/compile.h
trunk/test.rb
trunk/test/test_block.rb
trunk/yarvcore.c
trunk/yarvcore.h
Log:
* compile.c : support "for" statement
* test/test_block.rb : add test for above
* yarvcore.[ch] : add global id idEach
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2005-06-08 13:33:00 UTC (rev 168)
+++ trunk/ChangeLog 2005-06-13 22:51:03 UTC (rev 169)
@@ -4,6 +4,16 @@
# from Mon, 03 May 2004 01:24:19 +0900
#
+
+2005-06-14(Tue) 07:48:58 +0900 Koichi Sasada <ko1 atdot.net>
+
+ * compile.c : support "for" statement
+
+ * test/test_block.rb : add test for above
+
+ * yarvcore.[ch] : add global id idEach
+
+
2005-06-08(Wed) 22:30:44 +0900 Koichi Sasada <ko1 atdot.net>
* compile.c : add if/unless(L1) jump (L2) :L1 => unless/if(L2)
Modified: trunk/compile.c
===================================================================
--- trunk/compile.c 2005-06-08 13:33:00 UTC (rev 168)
+++ trunk/compile.c 2005-06-13 22:51:03 UTC (rev 169)
@@ -1818,7 +1818,17 @@
self, ISEQ_TYPE_BLOCK);
ret = NEW_SEQ();
ADD_LABEL(ret, retry_label);
- ADD_SEQ (ret, COMPILE_("iter caller", node->nd_iter, poped));
+ if(nd_type(node) == NODE_FOR){
+ ADD_SEQ(ret, COMPILE("iter caller (for)", node->nd_iter));
+ ADD_SEND_R(ret, nd_line(node), ID2SYM(idEach), INT2FIX(0),
+ iseqobj->compile_data->current_block, INT2FIX(0));
+ if(poped){
+ ADD_INSN(ret, nd_line(node), pop);
+ }
+ }
+ else{
+ ADD_SEQ (ret, COMPILE_("iter caller", node->nd_iter, poped));
+ }
ADD_LABEL(ret, retry_end_l);
iseqobj->compile_data->current_block = prevblock;
Modified: trunk/compile.h
===================================================================
--- trunk/compile.h 2005-06-08 13:33:00 UTC (rev 168)
+++ trunk/compile.h 2005-06-13 22:51:03 UTC (rev 169)
@@ -26,7 +26,7 @@
* 10: show every AST array
*/
-// #define CPDEBUG 6
+// #define CPDEBUG 2
#if CPDEBUG > 0
Modified: trunk/test/test_block.rb
===================================================================
--- trunk/test/test_block.rb 2005-06-08 13:33:00 UTC (rev 168)
+++ trunk/test/test_block.rb 2005-06-13 22:51:03 UTC (rev 169)
@@ -250,4 +250,28 @@
}
end
+ def test_for
+ ae %q{
+ sum = 0
+ for x in [1, 2, 3]
+ sum += x
+ end
+ sum
+ }
+ ae %q{
+ sum = 0
+ for x in (1..5)
+ sum += x
+ end
+ sum
+ }
+ ae %q{
+ sum = 0
+ for x in []
+ sum += x
+ end
+ sum
+ }
+ end
+
end
Modified: trunk/test.rb
===================================================================
--- trunk/test.rb 2005-06-08 13:33:00 UTC (rev 168)
+++ trunk/test.rb 2005-06-13 22:51:03 UTC (rev 169)
@@ -9,6 +9,24 @@
###########################################################
$prog =<<'__EOP__'
+ sum = 0
+ for x in [1, 2, 3]
+ sum += x
+ end
+ sum
+__END__
+ary = [ 1,2 ]
+for b in ary
+ p 'hello'
+ p b
+end
+
+__END__
+ary.each{|i|
+ p 'each'
+}
+
+__END__
def f x, y, z
if (x and y) or z
1
Modified: trunk/yarvcore.c
===================================================================
--- trunk/yarvcore.c 2005-06-08 13:33:00 UTC (rev 168)
+++ trunk/yarvcore.c 2005-06-13 22:51:03 UTC (rev 169)
@@ -41,6 +41,7 @@
ID idASET;
ID idIntern;
ID idMethodMissing;
+ID idEach;
#define MARK_UNLESS_NULL(ptr) if(ptr){rb_gc_mark(ptr);}
@@ -885,6 +886,8 @@
idThrowBackDFP = rb_intern("#__ThrowBackDFP__");
idThrowObject = rb_intern("#__ThrowObject__");
+ idEach = rb_intern("each");
+
constant_pool_pool = rb_ary_new();
rb_global_variable(&constant_pool_pool);
Modified: trunk/yarvcore.h
===================================================================
--- trunk/yarvcore.h 2005-06-08 13:33:00 UTC (rev 168)
+++ trunk/yarvcore.h 2005-06-13 22:51:03 UTC (rev 169)
@@ -39,6 +39,7 @@
extern ID idASET;
extern ID idIntern;
extern ID idMethodMissing;
+extern ID idEach;
extern unsigned long yarvGlobalStateVersion;
--
ML: yarv-diff quickml.atdot.net
Info: http://www.atdot.net/~ko1/quickml