yarv-diff:130
From: ko1 atdot.net
Date: 10 Nov 2005 16:29:25 -0000
Subject: [yarv-diff:130] r287 - in trunk: . benchmark benchmark/other-lang rb yarvtest
Author: ko1
Date: 2005-11-11 01:29:24 +0900 (Fri, 11 Nov 2005)
New Revision: 287
Modified:
trunk/ChangeLog
trunk/benchmark/bmx_temp.rb
trunk/benchmark/other-lang/eval.rb
trunk/common.mk
trunk/compile.c
trunk/disasm.c
trunk/insns.def
trunk/rb/allload.rb
trunk/test.rb
trunk/vm.c
trunk/vm_macro.def
trunk/vm_opts.h.base
trunk/yarvcore.c
trunk/yarvcore.h
trunk/yarvtest/test_block.rb
Log:
* common.mk : add "allload" rule
* compile.c, yarvcore.h, insns.def, vm_macro.def, disasm.c :
change arg_rest, arg_block offset (1)
* insns.def : add postexe instruction
* insns.def, vm.c : support rest block parameter
* yarvtest/test_block.rb : add tests for above
* rb/allload.rb : get path from ARGV
* vm_opts.h.base : set default off
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2005-10-31 23:28:34 UTC (rev 286)
+++ trunk/ChangeLog 2005-11-10 16:29:24 UTC (rev 287)
@@ -4,7 +4,24 @@
# from Mon, 03 May 2004 01:24:19 +0900
#
+2005-11-11(Fri) 01:20:15 +0900 Koichi Sasada <ko1 atdot.net>
+ * common.mk : add "allload" rule
+
+ * compile.c, yarvcore.h, insns.def, vm_macro.def, disasm.c :
+ change arg_rest, arg_block offset (1)
+
+ * insns.def : add postexe instruction
+
+ * insns.def, vm.c : support rest block parameter
+
+ * yarvtest/test_block.rb : add tests for above
+
+ * rb/allload.rb : get path from ARGV
+
+ * vm_opts.h.base : set default off
+
+
2005-11-01(Tue) 08:28:19 +0900 Koichi Sasada <ko1 atdot.net>
* benchmark/other-lang/eval.rb : fix path
Modified: trunk/benchmark/bmx_temp.rb
===================================================================
--- trunk/benchmark/bmx_temp.rb 2005-10-31 23:28:34 UTC (rev 286)
+++ trunk/benchmark/bmx_temp.rb 2005-11-10 16:29:24 UTC (rev 287)
@@ -1 +1 @@
-
+0
Modified: trunk/benchmark/other-lang/eval.rb
===================================================================
--- trunk/benchmark/other-lang/eval.rb 2005-10-31 23:28:34 UTC (rev 286)
+++ trunk/benchmark/other-lang/eval.rb 2005-11-10 16:29:24 UTC (rev 287)
@@ -9,12 +9,15 @@
Lang = <<EOP.map{|l| l.strip}
ruby-cyg
- ../../../build/miniruby
+ ../../../test6/miniruby
perl
python
gosh
EOP
+Bench.replace ['loop2']
+Lang.replace ['ruby-cyg']
+
Ext = %w(
.rb
.rb
Modified: trunk/common.mk
===================================================================
--- trunk/common.mk 2005-10-31 23:28:34 UTC (rev 286)
+++ trunk/common.mk 2005-11-10 16:29:24 UTC (rev 287)
@@ -429,6 +429,9 @@
yarv-test-each: all
$(BASERUBY) -I$(srcdir) $(srcdir)/yarvtest/test_$(ITEM).rb $(OPT) yarv=$(MINIRUBY) ruby=$(BASERUBY)
+allload: all
+ $(MINIRUBY) -I$(srcdir) $(srcdir)/rb/allload.rb `$(BASERUBY) -rrbconfig -e 'print Config::CONFIG["rubylibdir"]'`
+
run2: all
$(BASERUBY) -I$(srcdir)/lib $(srcdir)/test.rb $(MINIRUBY) $(BASERUBY) $(RUNOPT)
@@ -445,14 +448,14 @@
runtest: all
$(MINIRUBY) $(srcdir)/sample/test.rb
-benchmark: all
- $(BASERUBY) -I$(srcdir) -I$(srcdir)/lib $(srcdir)/benchmark/run_rite.rb $(OPT) $(ITEMS) --yarv-program=$(MINIRUBY) --ruby-program=$(BASERUBY) --opts=-I$(srcdir)/lib
+benchmark: all ruby
+ $(BASERUBY) -I$(srcdir) -I$(srcdir)/lib $(srcdir)/benchmark/run_rite.rb $(OPT) $(ITEMS) --yarv-program=./$(RUBY) --ruby-program=$(BASERUBY) --opts=-I$(srcdir)/lib
-tbench: all
- $(BASERUBY) -I$(srcdir) -I$(srcdir)/lib $(srcdir)/benchmark/run_rite.rb bmx $(OPT) --yarv-program=$(MINIRUBY) --ruby-program=$(BASERUBY) --opts=-I$(srcdir)/lib
+tbench: all ruby
+ $(BASERUBY) -I$(srcdir) -I$(srcdir)/lib $(srcdir)/benchmark/run_rite.rb bmx $(OPT) --yarv-program=./$(RUBY) --ruby-program=$(BASERUBY) --opts=-I$(srcdir)/lib
-bench-each: all
- $(BASERUBY) -I$(srcdir) $(srcdir)/benchmark/run_rite.rb bm_$(ITEM) $(OPT) --yarv-program=$(MINIRUBY) --ruby-program=$(BASERUBY) --opts=-I$(srcdir)/lib
+bench-each: all ruby
+ $(BASERUBY) -I$(srcdir) $(srcdir)/benchmark/run_rite.rb bm_$(ITEM) $(OPT) --yarv-program=./$(RUBY) --ruby-program=$(BASERUBY) --opts=-I$(srcdir)/lib
aotc:
$(RUBY) -I$(srcdir) -I. $(srcdir)/rb/aotcompile.rb $(INSNS2VMOPT)
@@ -461,6 +464,8 @@
vmasm:
$(CC) $(CFLAGS) $(CPPFLAGS) -S $(srcdir)/vm.c
+vm.o : CFLAGS += -fno-crossjumping
+
run.gdb:
echo run > run.gdb
Modified: trunk/compile.c
===================================================================
--- trunk/compile.c 2005-10-31 23:28:34 UTC (rev 286)
+++ trunk/compile.c 2005-11-10 16:29:24 UTC (rev 287)
@@ -917,7 +917,6 @@
}
}
iseqobj->local_size = size;
- iseqobj->arg_rest = 0;
}
return node;
}
@@ -962,7 +961,8 @@
if(nd_type(nargs->nd_head) != NODE_DASGN_CURR){
/* idx-th param, current level*/
- ADD_INSN2(anchor, nd_line(node), getdynamic, I2F(iseqobj->local_size - i), I2F(0));
+ ADD_INSN2(anchor, nd_line(node),
+ getdynamic, I2F(iseqobj->local_size - i), I2F(0));
set_block_initializer(self, iseqobj, nargs->nd_head, anchor);
}
i++;
@@ -972,10 +972,11 @@
if((int)node->nd_var->nd_args > 0){
iseqobj->argc++;
- iseqobj->arg_rest = i;
+ iseqobj->arg_rest = i + 1;
if(nd_type(node->nd_var->nd_args) != NODE_DASGN_CURR){
- ADD_INSN2(anchor, nd_line(node), getdynamic, I2F(iseqobj->local_size - i), I2F(0));
+ ADD_INSN2(anchor, nd_line(node), getdynamic,
+ I2F(iseqobj->local_size - i), I2F(0));
set_block_initializer(self, iseqobj, node->nd_var->nd_args, anchor);
}
}
@@ -1056,13 +1057,9 @@
iseqobj->argc = 0;
}
- /* TODO */
if(node->nd_rest){
- iseqobj->arg_rest = node->nd_rest->nd_cnt - 2;
+ iseqobj->arg_rest = node->nd_rest->nd_cnt - 2 + 1;
}
- else{
- iseqobj->arg_rest = -1;
- }
/* optional initializer */
if(node->nd_opt){
@@ -1098,12 +1095,12 @@
}
else{
iseqobj->argc = 0;
- iseqobj->arg_rest = -1;
+ iseqobj->arg_rest = 0;
iseqobj->arg_opts = 0;
}
- if(iseqobj->arg_rest + 1 != 0 ||
- iseqobj->arg_opts != 0){
+ if(iseqobj->arg_rest != 0 ||
+ iseqobj->arg_opts != 0){
iseqobj->arg_simple = 0;
}
else{
@@ -2162,7 +2159,11 @@
case NODE_YIELD:
ADD_INSN3(ret, nd_line(node), defined, I2F(DEFINED_YIELD), 0, needstr);
return 1;
-
+
+ case NODE_NTH_REF:
+ ADD_INSN3(ret, nd_line(node), defined, I2F(DEFINED_REF), 0, needstr);
+ return 1;
+
default:
rb_bug("unimplemented defined: %s", node_name(nd_type(node)));
}
@@ -2538,8 +2539,6 @@
VALUE prevblock = iseqobj->compile_data->current_block;
LABEL * retry_label = NEW_LABEL(nd_line(node));
LABEL * retry_end_l = NEW_LABEL(nd_line(node));
- VALUE name = rb_str_new2("b@");
- rb_str_concat(name, iseqobj->name);
ADD_LABEL(ret, retry_label);
if(nd_type(node) == NODE_FOR){
@@ -2849,10 +2848,9 @@
idx = get_dyna_var_idx(self, node->nd_vid, &lv, &ls);
if(nd_type(node) == NODE_DASGN_CURR &&
lv > 0 &&
- iseqobj->type != ISEQ_TYPE_RESCUE){
- if(iseqobj->compile_data->for_iseq == 1 && lv != 1){
- rb_bug("NODE_DASGN_CURR, but lv == %d (line: %d)", lv, nd_line(node));
- }
+ iseqobj->type != ISEQ_TYPE_RESCUE &&
+ iseqobj->compile_data->for_iseq != 1){
+ rb_bug("NODE_DASGN_CURR, but lv == %d (line: %d)", lv, nd_line(node));
}
if(idx < 0){
@@ -3616,7 +3614,7 @@
break;
}
case NODE_BLOCK_ARG:{
- iseqobj->arg_block = node->nd_cnt - 2;
+ iseqobj->arg_block = node->nd_cnt - 2 + 1;
iseqobj->arg_simple = 0;
break;
@@ -3892,7 +3890,7 @@
break;
}
case NODE_POSTEXE:{
- COMPILE_ERROR(("BUG: unknown node: NODE_POSTEXE"));
+ ADD_INSN1(ret, nd_line(node), postexe, iseqobj->compile_data->current_block);
break;
}
#ifdef C_ALLOCA
Modified: trunk/disasm.c
===================================================================
--- trunk/disasm.c 2005-10-31 23:28:34 UTC (rev 286)
+++ trunk/disasm.c 2005-11-10 16:29:24 UTC (rev 287)
@@ -232,8 +232,8 @@
snprintf(argi, sizeof(argi), "%s%s%s%s", /* arg, opts, rest, block */
iseqdat->argc > i ? "Arg" : "",
opti,
- iseqdat->arg_rest == i ? "Rest" : "",
- iseqdat->arg_block == i ? "Block" : "");
+ iseqdat->arg_rest - 1 == i ? "Rest" : "",
+ iseqdat->arg_block- 1 == i ? "Block" : "");
snprintf(info, sizeof(info), "%s%s%s%s", name ? name : "?",
*argi ? "<" : "", argi, *argi ? ">" : "");
Modified: trunk/insns.def
===================================================================
--- trunk/insns.def 2005-10-31 23:28:34 UTC (rev 286)
+++ trunk/insns.def 2005-11-10 16:29:24 UTC (rev 287)
@@ -1006,7 +1006,32 @@
}
}
+/**
+ @c setting
+ @e END{}
+ @j END{}
+ */
+DEFINE_INSN
+postexe
+(VALUE blockval)
+()
+()
+{
+ yarv_block_t *blockptr;
+ VALUE proc;
+ yarv_iseq_t *blockiseq;
+ /* TODO : eliminate it */
+ GetISeqVal(blockval, blockiseq);
+
+ blockptr = GET_BLOCK_PTR_IN_CFP(GET_CFP());
+ blockptr->iseq = blockiseq;
+ blockptr->proc = 0;
+
+ proc = th_make_proc(th, GET_CFP(), blockptr);
+ rb_set_end_proc(call_yarv_end_proc, proc);
+}
+
/**********************************************************/
/* deal with control flow 1: class/module */
/**********************************************************/
@@ -1350,6 +1375,12 @@
}
}
+ if(0){
+ printf("iseq argc: %d\n", iseq->argc);
+ printf("iseq rest: %d\n", iseq->arg_rest);
+ printf("iseq blck: %d\n", iseq->arg_block);
+ }
+
if(iseq->argc == 1){
if(argc > 1){
/* TODO: for backward compatibility */
@@ -1374,6 +1405,29 @@
}
}
}
+ if(iseq->arg_rest != 0){
+ /*
+ * a1 a2 a3 r1 r2 r3 _
+ * ^r (=3) ^sp, argc = 6
+ */
+ int rest = iseq->arg_rest - 1;
+ int alen;
+ VALUE *rv = GET_SP() - (argc - rest);
+
+ if(argc > rest){
+ alen = argc - rest;
+ }
+ else{
+ VALUE *p = GET_SP();
+ while(p != rv){
+ *p++ = Qnil;
+ }
+ alen = 0;
+ }
+ argc = rest + 1;
+ *rv = rb_ary_new4(alen, rv);
+ SET_SP(rv+1);
+ }
}
if(argc > iseq->argc){
Modified: trunk/rb/allload.rb
===================================================================
--- trunk/rb/allload.rb 2005-10-31 23:28:34 UTC (rev 286)
+++ trunk/rb/allload.rb 2005-11-10 16:29:24 UTC (rev 287)
@@ -1,14 +1,25 @@
+ignores = %w(import.rb)
-require 'yarvutil'
-$LOAD_PATH.shift
-$LOAD_PATH.each{|path|
- Dir.glob("#{path}/**/*.rb"){|file|
- #
- puts "#"
- puts "# #{file}"
- puts "#"
- puts
- puts YARVUtil.parse(File.read(file), file, 1).disasm
+module Enumerable
+ def all?
+ self.each{|e|
+ return false unless yield(e)
+ }
+ true
+ end
+end
+
+ARGV.each{|dir|
+ dir = File.expand_path(dir)
+ Dir.glob(File.join(dir, '**/*.rb')){|file|
+ p file
+ if ignores.all?{|e|
+ r = Regexp.compile(Regexp.escape(e))
+ r !~ file
+ }
+ YARVCore::parse(File.read(file), file, 1)
+ else
+ p 'ignore'
+ end
}
}
-
Modified: trunk/test.rb
===================================================================
--- trunk/test.rb 2005-10-31 23:28:34 UTC (rev 286)
+++ trunk/test.rb 2005-11-10 16:29:24 UTC (rev 287)
@@ -1,25 +1,47 @@
-ary = [1, 2]
-case 1
-when :x, *ary
- :ok
-when :z
- :ng1
-else
- :ng2
+
+def iter
+ yield 1, 2
end
+iter{|a, *|
+ p [a, ]
+}
+iter{|a|
+ p [a, ]
+}
+
+
__END__
-def re
- /#{RE}/o
+ary = [1]
+
+ary.each{|*i|
+ p i
+}
+ary.each{|a, *i|
+ p [a, i]
+}
+ary.each{|a, b, *i|
+ p [a, b, i]
+}
+ary.each{|i|
+ p i
+}
+
+__END__
+def iter
+ yield 1, 2, 3
end
-RE = 'a'
-p [re, re.__id__, re.__id__]
-Object.module_eval %q{
- remove_const :RE
+iter{|a, b, c, d, *y|
+ p [ y]
}
-RE = 'b'
-p [re, re.__id__, re.__id__]
+__END__
+iter{|x, *y| p [x, y]}
+iter{|x, y| p [x, y]}
+iter{|x, | p [x, ]}
+iter{|*x| p [x, ]}
+iter{|*| p []}
+lambda{|*| p :ok}.call(0)
Modified: trunk/vm.c
===================================================================
--- trunk/vm.c 2005-10-31 23:28:34 UTC (rev 286)
+++ trunk/vm.c 2005-11-10 16:29:24 UTC (rev 287)
@@ -490,7 +490,6 @@
yarv_control_frame_t *cfp = th->cfp;
yarv_block_t *block = GC_GUARDED_PTR_REF(cfp->lfp[0]);
VALUE val;
-
if(block == 0){
SDR();
rb_bug("block is not given (th_invoke_yield)");
@@ -511,7 +510,23 @@
argv = RARRAY(argv[0])->ptr;
}
}
-
+
+ if(block->iseq->arg_rest != 0){
+ int rest = block->iseq->arg_rest - 1;
+ int alen;
+
+ if(argc <= rest){
+ VALUE ary = rb_ary_new4(argc, argv);
+ rb_ary_store(ary, rest, rb_ary_new());
+ argc = RARRAY(ary)->len;
+ argv = RARRAY(ary)->ptr;
+ }
+ else{
+ argv[rest] = rb_ary_new4(argc-rest, &argv[rest]);
+ argc = rest + 1;
+ }
+ }
+
th_set_finish_env(th);
th_set_env(th, block->iseq, FRAME_MAGIC_BLOCK,
block->self, GC_GUARDED_PTR(block->dfp),
@@ -886,7 +901,7 @@
#if 0
1 error
-#elif defined(FAKE_INLINE_METHOD_CACHE)
+#elif 0 // defined(FAKE_INLINE_METHOD_CACHE)
{
/* don't support polymorphic method call */
if(LIKELY(ic->ic_method != 0)){
@@ -896,7 +911,7 @@
ic->ic_method = mn = rb_method_node(klass, id);
}
}
-#elif defined(FAKE_INLINE_METHOD_CACHE2)
+#elif 0 //defined(FAKE_INLINE_METHOD_CACHE2)
{
if(LIKELY(klass == ic->ic_klass)){
mn = ic->ic_method;
@@ -907,7 +922,7 @@
ic->ic_method = mn;
}
}
-#elif defined(OPT_INLINE_METHOD_CACHE)
+#elif OPT_INLINE_METHOD_CACHE
{
if(LIKELY(klass == ic->ic_klass) &&
LIKELY(GET_VM_STATE_VERSION() == ic->ic_vmstat)){
@@ -920,8 +935,7 @@
ic->ic_vmstat = GET_VM_STATE_VERSION();
}
}
-
-#elif defined(ONLY_GLOBAL_METHOD_CACHE)
+#elif 0
{
struct cache_entry *ent = cache + EXPR1(klass, id);
int noex;
@@ -947,7 +961,13 @@
return mn;
}
+static void
+call_yarv_end_proc(VALUE data)
+{
+ rb_proc_call(data, rb_ary_new2(0));
+}
+
/*********************************************************/
/*********************************************************/
/* import from ruby1.9/eval.c */
Modified: trunk/vm_macro.def
===================================================================
--- trunk/vm_macro.def 2005-10-31 23:28:34 UTC (rev 286)
+++ trunk/vm_macro.def 2005-11-10 16:29:24 UTC (rev 287)
@@ -98,7 +98,7 @@
int iseq_argc = niseq->argc;
int opts = niseq->arg_opts;
if(num < iseq_argc ||
- (niseq->arg_rest == -1 && num > iseq_argc + opts)){
+ (niseq->arg_rest == 0 && num > iseq_argc + opts)){
rb_raise(rb_eArgError, "wrong number of arguments (%d for %d)",
num, iseq_argc);
}
@@ -116,7 +116,7 @@
}
/* check rest */
- if(niseq->arg_rest == -2){
+ if(niseq->arg_rest == -1){
if(niseq->arg_opts){
num = niseq->argc + niseq->arg_opts;
}
@@ -125,8 +125,8 @@
}
sp = &rsp[1 + num + 1];
}
- else if(niseq->arg_rest != -1){
- int rest = niseq->arg_rest;
+ else if(niseq->arg_rest != 0){
+ int rest = niseq->arg_rest - 1;
int pack_size = num - rest;
if(0){
printf("num: %d, rest: %d, ps: %d\n", num, niseq->arg_rest, pack_size);
@@ -145,8 +145,9 @@
num = rest + 1;
clear_local_size = niseq->local_size - rest - 1;
}
+
/* block argument */
- if(niseq->arg_block != -1){
+ if(niseq->arg_block != 0){
VALUE arg_block_val = Qnil;
if(blockptr){
/* make Proc object */
@@ -162,7 +163,7 @@
}
}
- rsp[1 + niseq->arg_block] = arg_block_val;
+ rsp[1 + niseq->arg_block - 1] = arg_block_val;
sp++;
clear_local_size--;
}
Modified: trunk/vm_opts.h.base
===================================================================
--- trunk/vm_opts.h.base 2005-10-31 23:28:34 UTC (rev 286)
+++ trunk/vm_opts.h.base 2005-11-10 16:29:24 UTC (rev 287)
@@ -12,12 +12,12 @@
#if IGNORE_OPTIMIZE == 0
/* compiler depend */
-#define OPT_DIRECT_THREADED_CODE 1
+#define OPT_DIRECT_THREADED_CODE 0
#define OPT_CALL_THREADED_CODE 0
/* architecture independent */
-#define OPT_BASIC_OPERATIONS 1
-#define OPT_INLINE_METHOD_CACHE 1
+#define OPT_BASIC_OPERATIONS 0
+#define OPT_INLINE_METHOD_CACHE 0
/* architecture independent, affects generated code */
#define OPT_OPERANDS_UNIFICATION 0
Modified: trunk/yarvcore.c
===================================================================
--- trunk/yarvcore.c 2005-10-31 23:28:34 UTC (rev 286)
+++ trunk/yarvcore.c 2005-11-10 16:29:24 UTC (rev 287)
@@ -409,8 +409,8 @@
iseq->iseq_mark_ary = rb_ary_new();
iseq->catch_table_ary = rb_ary_new();
iseq->type = type;
- iseq->arg_rest = -1;
- iseq->arg_block = -1;
+ iseq->arg_rest = 0;
+ iseq->arg_block = 0;
iseq->klass = 0;
/* set class nest stack */
Modified: trunk/yarvcore.h
===================================================================
--- trunk/yarvcore.h 2005-10-31 23:28:34 UTC (rev 286)
+++ trunk/yarvcore.h 2005-11-10 16:29:24 UTC (rev 287)
@@ -223,11 +223,10 @@
* =>
*
* argc = M
- * arg_rest = M+N
+ * arg_rest = M+N + 1 // if no rest arguments, rest is 0
* arg_opts = N
* arg_opts_tbl = [ (N entries) ]
- * arg_initstart = M+N+1
- *
+ * arg_block = M+N + 1 (rest) + 1 (block)
* check:
* M <= num
*/
@@ -476,6 +475,7 @@
#define DEFINED_CONST INT2FIX(4)
#define DEFINED_METHOD INT2FIX(5)
#define DEFINED_YIELD INT2FIX(6)
+#define DEFINED_REF INT2FIX(7)
/* for debug */
extern void vm_stack_dump_raw(yarv_thread_t *, yarv_control_frame_t *);
Modified: trunk/yarvtest/test_block.rb
===================================================================
--- trunk/yarvtest/test_block.rb 2005-10-31 23:28:34 UTC (rev 286)
+++ trunk/yarvtest/test_block.rb 2005-11-10 16:29:24 UTC (rev 287)
@@ -312,4 +312,53 @@
}
}
end
+
+ def test_rest
+ # TODO: known bug
+ #ae %q{
+ # def iter
+ # yield 1, 2
+ # end
+ #
+ # iter{|a, |
+ # [a]
+ # }
+ #}
+ ae %q{
+ def iter
+ yield 1, 2
+ end
+
+ iter{|a, *b|
+ [a, b]
+ }
+ }
+ ae %q{
+ def iter
+ yield 1, 2
+ end
+
+ iter{|*a|
+ [a]
+ }
+ }
+ ae %q{
+ def iter
+ yield 1, 2
+ end
+
+ iter{|a, b, *c|
+ [a, b, c]
+ }
+ }
+ ae %q{
+ def iter
+ yield 1, 2
+ end
+
+ iter{|a, b, c, *d|
+ [a, b, c, d]
+ }
+ }
+ end
end
--
ML: yarv-diff quickml.atdot.net
Info: http://www.atdot.net/~ko1/quickml