yarv-diff:361
From: ko1 atdot.net
Date: 6 Aug 2006 06:30:12 +0900
Subject: [yarv-diff:361] r528 - in trunk: . yarvtest
Author: ko1
Date: 2006-08-06 06:30:01 +0900 (Sun, 06 Aug 2006)
New Revision: 528
Added:
trunk/yarvtest/test_opts.rb
Modified:
trunk/
trunk/ChangeLog
trunk/blockinlining.c
trunk/common.mk
trunk/compile.c
trunk/compile.h
trunk/eval_method.h
trunk/insnhelper.h
trunk/insns.def
trunk/iseq.c
trunk/numeric.c
trunk/thread.c
trunk/vm.c
trunk/vm.h
trunk/yarvcore.c
trunk/yarvcore.h
Log:
r823@lermite: ko1 | 2006-08-06 06:29:07 +0900
* common.mk : fix build rule (build only ruby binary when benchmark)
* yarvcore.[ch] : fix and add yarv_iseq_new_with_* API
* blockinlining.c : ditto
* compile.c : ditto
* compile.h : ditto
* iseq.c : ditto
* eval_method.h : check redefinition for specialized instruction
* insnhelper.h : ditto
* insns.def : ditto
* vm.c : ditto
* vm.h : ditto
* numeric.c : add Fixnum#succ
* thread.c : remove duplicated method Thread#current
* yarvcore.c : remove duplicated method Proc#clone
* yarvtest/test_opts.rb : added
Property changes on: trunk
___________________________________________________________________
Name: svk:merge
- 81cd9672-7512-7e48-ae48-6936450e977d:/local/yarv/trunk:820
+ 81cd9672-7512-7e48-ae48-6936450e977d:/local/yarv/trunk:823
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2006-07-19 19:22:12 UTC (rev 527)
+++ trunk/ChangeLog 2006-08-05 21:30:01 UTC (rev 528)
@@ -4,6 +4,39 @@
# from Mon, 03 May 2004 01:24:19 +0900
#
+2006-08-06(Sun) 06:24:51 +0900 Koichi Sasada <ko1 atdot.net>
+
+ * common.mk : fix build rule (build only ruby binary when benchmark)
+
+ * yarvcore.[ch] : fix and add yarv_iseq_new_with_* API
+
+ * blockinlining.c : ditto
+
+ * compile.c : ditto
+
+ * compile.h : ditto
+
+ * iseq.c : ditto
+
+ * eval_method.h : check redefinition for specialized instruction
+
+ * insnhelper.h : ditto
+
+ * insns.def : ditto
+
+ * vm.c : ditto
+
+ * vm.h : ditto
+
+ * numeric.c : add Fixnum#succ
+
+ * thread.c : remove duplicated method Thread#current
+
+ * yarvcore.c : remove duplicated method Proc#clone
+
+ * yarvtest/test_opts.rb : added
+
+
2006-07-20(Thu) 04:10:13 +0900 Koichi Sasada <ko1 atdot.net>
* compile.c : fix [yarv-dev:1041] problem (raise TypeError)
Modified: trunk/blockinlining.c
===================================================================
--- trunk/blockinlining.c 2006-07-19 19:22:12 UTC (rev 527)
+++ trunk/blockinlining.c 2006-08-05 21:30:01 UTC (rev 528)
@@ -11,6 +11,7 @@
#if OPT_BLOCKINLINING
VALUE parent = Qfalse;
VALUE iseqval;
+
if (iseq->argc > 1 || iseq->arg_simple == 0) {
/* argument check */
return 0;
@@ -27,12 +28,13 @@
else {
iseq->cached_special_block_builder = (void *)1;
}
+
if (iseq->parent_iseq) {
parent = iseq->parent_iseq->self;
}
- iseqval = yarv_new_iseqval((VALUE)iseq->node, iseq->name,
- iseq->file_name, parent, iseq->type,
- GC_GUARDED_PTR(builder), Qnil);
+ iseqval = yarv_iseq_new_with_bopt(iseq->node, iseq->name, iseq->file_name,
+ parent, iseq->type,
+ GC_GUARDED_PTR(builder));
if (0) {
printf("%s\n", RSTRING(iseq_disasm(iseqval))->ptr);
}
Modified: trunk/common.mk
===================================================================
--- trunk/common.mk 2006-07-19 19:22:12 UTC (rev 527)
+++ trunk/common.mk 2006-08-05 21:30:01 UTC (rev 528)
@@ -439,13 +439,13 @@
parse: miniruby$(EXEEXT)
$(MINIRUBY) $(srcdir)/rb/parse.rb $(srcdir)/test.rb
-benchmark: all
+benchmark: $(RUBY)
$(BASERUBY) -I$(srcdir) -I$(srcdir)/lib $(srcdir)/benchmark/run_rite.rb $(OPT) $(ITEMS) --yarv-program=./$(PROGRAM) --ruby-program=$(BASERUBY) --opts=-I$(srcdir)/lib
tbench: prog
$(BASERUBY) -I$(srcdir) -I$(srcdir)/lib $(srcdir)/benchmark/run_rite.rb bmx $(OPT) --yarv-program=./$(PROGRAM) --ruby-program=$(BASERUBY) --opts=-I$(srcdir)/lib
-bench-each: all
+bench-each: $(RUBY)
$(BASERUBY) -I$(srcdir) $(srcdir)/benchmark/run_rite.rb bm_$(ITEM) $(OPT) --yarv-program=./$(RUBY) --ruby-program=$(BASERUBY) --opts=-I$(srcdir)/lib
aotc:
Modified: trunk/compile.c
===================================================================
--- trunk/compile.c 2006-07-19 19:22:12 UTC (rev 527)
+++ trunk/compile.c 2006-08-05 21:30:01 UTC (rev 528)
@@ -652,14 +652,14 @@
static VALUE
new_child_iseq(yarv_iseq_t *iseq, NODE *node,
- VALUE name, VALUE parent, VALUE type, VALUE block_opt)
+ VALUE name, VALUE parent, VALUE type)
{
VALUE args[6];
VALUE ret;
debugs("[new_child_iseq]> ---------------------------------------\n");
ret = yarv_iseq_new_with_opt(node, name, iseq_filename(iseq->self),
- parent, type, block_opt, iseq->compile_data->option);
+ parent, type, iseq->compile_data->option);
debugs("[new_child_iseq]< ---------------------------------------\n");
iseq_add_mark_object(iseq, ret);
return ret;
@@ -1556,6 +1556,7 @@
return COMPILE_OK;
}
+
static int
iseq_specialized_instruction(yarv_iseq_t *iseq, INSN *iobj)
{
@@ -1565,6 +1566,7 @@
VALUE block = OPERAND_AT(iobj, 2);
VALUE flag = OPERAND_AT(iobj, 3);
+ /* TODO: should be more sophisticated search */
if (block == 0 && flag == INT2FIX(0)) {
if (argc == 0) {
if (mid == idLength) {
Modified: trunk/compile.h
===================================================================
--- trunk/compile.h 2006-07-19 19:22:12 UTC (rev 527)
+++ trunk/compile.h 2006-08-05 21:30:01 UTC (rev 528)
@@ -99,10 +99,10 @@
(((yarv_iseq_t*)DATA_PTR(iseq))->file_name)
#define NEW_ISEQVAL(node, name, type) \
- new_child_iseq(iseq, node, name, 0, type, Qfalse)
+ new_child_iseq(iseq, node, name, 0, type)
#define NEW_CHILD_ISEQVAL(node, name, type) \
- new_child_iseq(iseq, node, name, iseq->self, type, Qfalse)
+ new_child_iseq(iseq, node, name, iseq->self, type)
#define NEW_SPECIAQL_BLOCK_ISEQVAL(iseq, sym) \
new_child_iseq(iseq, iseq->node, iseq->name, iseq->parent_iseq, iseq->type, sym)
Modified: trunk/eval_method.h
===================================================================
--- trunk/eval_method.h 2006-07-19 19:22:12 UTC (rev 527)
+++ trunk/eval_method.h 2006-08-05 21:30:01 UTC (rev 528)
@@ -137,6 +137,15 @@
else {
body = 0;
}
+
+ {
+ NODE *old_node;
+ if (st_lookup(RCLASS(klass)->m_tbl, mid, (st_data_t *)&old_node)) {
+ if (old_node && nd_type(old_node->nd_body->nd_body) == NODE_CFUNC) {
+ yarv_check_redefinition_opt_method(old_node);
+ }
+ }
+ }
st_insert(RCLASS(klass)->m_tbl, mid, (st_data_t) body);
if (node && mid != ID_ALLOCATOR && ruby_running) {
Modified: trunk/insnhelper.h
===================================================================
--- trunk/insnhelper.h 2006-07-19 19:22:12 UTC (rev 527)
+++ trunk/insnhelper.h 2006-08-05 21:30:01 UTC (rev 528)
@@ -139,7 +139,7 @@
/* optimize insn */
#define FIXNUM_2_P(a, b) ((a) & (b) & 1)
-#define BASIC_OP_UNREDEFINED(op) (yarv_unredefined_flag)
+#define BASIC_OP_UNREDEFINED_P(op) ((yarv_redefined_flag & (op)) == 0)
#define HEAP_CLASS_OF(obj) RBASIC(obj)->klass
#endif // _INSNHELPER_H_INCLUDED_
Modified: trunk/insns.def
===================================================================
--- trunk/insns.def 2006-07-19 19:22:12 UTC (rev 527)
+++ trunk/insns.def 2006-08-05 21:30:01 UTC (rev 528)
@@ -1604,7 +1604,8 @@
}
#if 1
- else if (FIXNUM_2_P(recv, obj) && BASIC_OP_UNREDEFINED(FIXNUM_PLUS)) {
+ else if (FIXNUM_2_P(recv, obj) &&
+ BASIC_OP_UNREDEFINED_P(BOP_PLUS)) {
/* fixnum + fixnum */
val = (recv + (obj & (~1)));
if ((~(recv ^ obj) & (recv ^ val)) & 0x80000000) {
@@ -1620,7 +1621,7 @@
#if 1
else if (HEAP_CLASS_OF(recv) == rb_cFloat &&
HEAP_CLASS_OF(obj) == rb_cFloat &&
- BASIC_OP_UNREDEFINED(FLOAT_PLUS)) {
+ BASIC_OP_UNREDEFINED_P(BOP_PLUS)) {
val = rb_float_new(RFLOAT(recv)->value + RFLOAT(obj)->value);
}
#endif
@@ -1628,12 +1629,13 @@
#if 1
else if (HEAP_CLASS_OF(recv) == rb_cString &&
HEAP_CLASS_OF(obj) == rb_cString &&
- BASIC_OP_UNREDEFINED(STRING_PLUS)) {
+ BASIC_OP_UNREDEFINED_P(BOP_PLUS)) {
val = rb_str_plus(recv, obj);
}
#endif
#if 1
- else if (HEAP_CLASS_OF(recv) == rb_cArray) {
+ else if (HEAP_CLASS_OF(recv) == rb_cArray &&
+ BASIC_OP_UNREDEFINED_P(BOP_PLUS)) {
val = rb_ary_plus(recv, obj);
}
#endif
@@ -1666,7 +1668,8 @@
(VALUE recv, VALUE obj)
(VALUE val)
{
- if (FIXNUM_2_P(recv, obj) && BASIC_OP_UNREDEFINED(FIXNUM_MINUS)) {
+ if (FIXNUM_2_P(recv, obj) &&
+ BASIC_OP_UNREDEFINED_P(BOP_MINUS)) {
long a, b, c;
a = FIX2LONG(recv);
@@ -1702,7 +1705,8 @@
(VALUE recv, VALUE obj)
(VALUE val)
{
- if (FIXNUM_2_P(recv, obj) && BASIC_OP_UNREDEFINED(FIXNUM_MULT)) {
+ if (FIXNUM_2_P(recv, obj) &&
+ BASIC_OP_UNREDEFINED_P(BOP_MULT)) {
long a, b, c;
a = FIX2LONG(recv);
@@ -1724,7 +1728,8 @@
}
#if 1
else if (HEAP_CLASS_OF(recv) == rb_cFloat &&
- HEAP_CLASS_OF(obj) == rb_cFloat) {
+ HEAP_CLASS_OF(obj) == rb_cFloat &&
+ BASIC_OP_UNREDEFINED_P(BOP_MULT)) {
val = rb_float_new(RFLOAT(recv)->value * RFLOAT(obj)->value);
}
#endif
@@ -1758,7 +1763,8 @@
(VALUE recv, VALUE obj)
(VALUE val)
{
- if (FIXNUM_2_P(recv, obj) && BASIC_OP_UNREDEFINED(FIXNUM_MULT)) {
+ if (FIXNUM_2_P(recv, obj) &&
+ BASIC_OP_UNREDEFINED_P(BOP_DIV)) {
long x, y, div;
x = FIX2LONG(recv);
@@ -1793,7 +1799,8 @@
}
#if 1
else if (HEAP_CLASS_OF(recv) == rb_cFloat &&
- HEAP_CLASS_OF(obj) == rb_cFloat) {
+ HEAP_CLASS_OF(obj) == rb_cFloat &&
+ BASIC_OP_UNREDEFINED_P(BOP_DIV)) {
val = rb_float_new(RFLOAT(recv)->value / RFLOAT(obj)->value);
}
#endif
@@ -1827,7 +1834,8 @@
(VALUE recv, VALUE obj)
(VALUE val)
{
- if (FIXNUM_2_P(recv, obj) && BASIC_OP_UNREDEFINED(FIXNUM_MULT)) {
+ if (FIXNUM_2_P(recv, obj) &&
+ BASIC_OP_UNREDEFINED_P(BOP_MOD)) {
long x, y, mod;
x = FIX2LONG(recv);
@@ -1862,7 +1870,8 @@
if (0) {
}
else if (HEAP_CLASS_OF(recv) == rb_cFloat &&
- HEAP_CLASS_OF(obj) == rb_cFloat) {
+ HEAP_CLASS_OF(obj) == rb_cFloat &&
+ BASIC_OP_UNREDEFINED_P(BOP_MOD)) {
double x = RFLOAT(recv)->value;
double y = RFLOAT(obj)->value;
double div, mod;
@@ -1916,7 +1925,8 @@
(VALUE recv, VALUE obj)
(VALUE val)
{
- if (FIXNUM_2_P(recv, obj) && BASIC_OP_UNREDEFINED(FIXNUM_LT)) {
+ if (FIXNUM_2_P(recv, obj) &&
+ BASIC_OP_UNREDEFINED_P(BOP_EQ)) {
long a = FIX2LONG(recv), b = FIX2LONG(obj);
if (a == b) {
@@ -1930,7 +1940,8 @@
if (0) {
}
else if (HEAP_CLASS_OF(recv) == rb_cFloat &&
- HEAP_CLASS_OF(recv) == rb_cFloat) {
+ HEAP_CLASS_OF(recv) == rb_cFloat &&
+ BASIC_OP_UNREDEFINED_P(BOP_EQ)) {
double a = RFLOAT(recv)->value;
double b = RFLOAT(obj)->value;
@@ -1945,7 +1956,8 @@
}
}
else if (HEAP_CLASS_OF(recv) == rb_cString &&
- HEAP_CLASS_OF(obj) == rb_cString) {
+ HEAP_CLASS_OF(obj) == rb_cString &&
+ BASIC_OP_UNREDEFINED_P(BOP_EQ)) {
VALUE str1 = recv;
VALUE str2 = obj;
@@ -1991,7 +2003,8 @@
(VALUE recv, VALUE obj)
(VALUE val)
{
- if (FIXNUM_2_P(recv, obj) && BASIC_OP_UNREDEFINED(FIXNUM_LT)) {
+ if (FIXNUM_2_P(recv, obj) &&
+ BASIC_OP_UNREDEFINED_P(BOP_LT)) {
long a = FIX2LONG(recv), b = FIX2LONG(obj);
if (a < b) {
@@ -2025,7 +2038,8 @@
(VALUE recv, VALUE obj)
(VALUE val)
{
- if (FIXNUM_2_P(recv, obj) && BASIC_OP_UNREDEFINED(FIXNUM_LT)) {
+ if (FIXNUM_2_P(recv, obj) &&
+ BASIC_OP_UNREDEFINED_P(BOP_LE)) {
long a = FIX2LONG(recv), b = FIX2LONG(obj);
if (a <= b) {
@@ -2065,11 +2079,11 @@
if (0) {
}
else if (HEAP_CLASS_OF(recv) == rb_cString &&
- BASIC_OP_UNREDEFINED(STRING_LTLT)) {
+ BASIC_OP_UNREDEFINED_P(BOP_LTLT)) {
val = rb_str_concat(recv, obj);
}
else if (HEAP_CLASS_OF(recv) == rb_cArray &&
- BASIC_OP_UNREDEFINED(ARRAY_LTLT)) {
+ BASIC_OP_UNREDEFINED_P(BOP_LTLT)) {
val = rb_ary_push(recv, obj);
}
else {
@@ -2101,7 +2115,7 @@
(VALUE recv, VALUE obj)
(VALUE val)
{
- if (!SPECIAL_CONST_P(recv)) {
+ if (!SPECIAL_CONST_P(recv) && BASIC_OP_UNREDEFINED_P(BOP_AREF)) {
if (HEAP_CLASS_OF(recv) == rb_cArray && FIXNUM_P(obj)) {
val = rb_ary_entry(recv, FIX2LONG(obj));
}
@@ -2137,7 +2151,8 @@
(VALUE recv, VALUE obj, VALUE set)
(VALUE val)
{
- if (!SPECIAL_CONST_P(recv)) {
+ if (!SPECIAL_CONST_P(recv) &&
+ BASIC_OP_UNREDEFINED_P(BOP_ASET)) {
if (HEAP_CLASS_OF(recv) == rb_cArray && FIXNUM_P(obj)) {
rb_ary_store(recv, FIX2LONG(obj), set);
val = set;
@@ -2176,7 +2191,8 @@
(VALUE recv)
(VALUE val)
{
- if (!SPECIAL_CONST_P(recv)) {
+ if (!SPECIAL_CONST_P(recv) &&
+ BASIC_OP_UNREDEFINED_P(BOP_LENGTH)) {
if (HEAP_CLASS_OF(recv) == rb_cArray) {
val = LONG2NUM(RARRAY(recv)->len);
}
@@ -2213,7 +2229,8 @@
(VALUE val)
{
if (SPECIAL_CONST_P(recv)) {
- if (FIXNUM_P(recv) && BASIC_OP_UNREDEFINED(FIXNUM_SUCC)) {
+ if (FIXNUM_P(recv) &&
+ BASIC_OP_UNREDEFINED_P(BOP_SUCC)) {
const VALUE obj = INT2FIX(1);
/* fixnum + INT2FIX(1) */
val = (recv + (obj & (~1)));
@@ -2227,10 +2244,12 @@
}
}
else {
- if (HEAP_CLASS_OF(recv) == rb_cString) {
+ if (HEAP_CLASS_OF(recv) == rb_cString &&
+ BASIC_OP_UNREDEFINED_P(BOP_SUCC)) {
val = rb_str_succ(recv);
}
- else if (HEAP_CLASS_OF(recv) == rb_cTime) {
+ else if (HEAP_CLASS_OF(recv) == rb_cTime &&
+ BASIC_OP_UNREDEFINED_P(BOP_SUCC)) {
val = rb_time_succ(recv);
}
else {
Modified: trunk/iseq.c
===================================================================
--- trunk/iseq.c 2006-07-19 19:22:12 UTC (rev 527)
+++ trunk/iseq.c 2006-08-05 21:30:01 UTC (rev 528)
@@ -246,13 +246,13 @@
VALUE parent, VALUE type)
{
return yarv_iseq_new_with_opt(node, name, file_name, parent, type,
- Qfalse, &COMPILE_OPTION_DEFAULT);
+ &COMPILE_OPTION_DEFAULT);
}
-VALUE
-yarv_iseq_new_with_opt(NODE *node, VALUE name, VALUE file_name,
- VALUE parent, VALUE type,
- VALUE block_opt, const yarv_compile_option_t *option)
+static VALUE
+yarv_iseq_new_with_bopt_and_opt(NODE *node, VALUE name, VALUE file_name,
+ VALUE parent, VALUE type, VALUE bopt,
+ const yarv_compile_option_t *option)
{
yarv_iseq_t *iseq;
VALUE self = iseq_alloc(cYarvISeq);
@@ -260,12 +260,29 @@
GetISeqPtr(self, iseq);
iseq->self = self;
- prepare_iseq_build(iseq, name, file_name, parent, type, block_opt, option);
+ prepare_iseq_build(iseq, name, file_name, parent, type, bopt, option);
iseq_compile(self, node);
cleanup_iseq_build(iseq);
return self;
}
+VALUE
+yarv_iseq_new_with_opt(NODE *node, VALUE name, VALUE file_name,
+ VALUE parent, VALUE type,
+ const yarv_compile_option_t *option)
+{
+ return yarv_iseq_new_with_bopt_and_opt(node, name, file_name, parent, type,
+ Qfalse, option);
+}
+
+VALUE
+yarv_iseq_new_with_bopt(NODE *node, VALUE name, VALUE file_name,
+ VALUE parent, VALUE type, VALUE bopt)
+{
+ return yarv_iseq_new_with_bopt_and_opt(node, name, file_name, parent, type,
+ bopt, &COMPILE_OPTION_DEFAULT);
+}
+
VALUE iseq_build_from_ary(yarv_iseq_t *iseq, VALUE line,
VALUE locals, VALUE args, VALUE exception, VALUE body);
@@ -382,7 +399,7 @@
node = compile_string(str, file, line);
make_compile_option(&option, opt);
return yarv_iseq_new_with_opt(node, rb_str_new2("<main>"), file, Qfalse,
- ISEQ_TYPE_TOP, Qfalse, &option);
+ ISEQ_TYPE_TOP, &option);
}
static VALUE
@@ -404,7 +421,7 @@
node = rb_parser_compile_file(parser, fname, f, NUM2INT(line));
make_compile_option(&option, opt);
return yarv_iseq_new_with_opt(node, rb_str_new2("<main>"), file, Qfalse,
- ISEQ_TYPE_TOP, Qfalse, &option);
+ ISEQ_TYPE_TOP, &option);
}
static VALUE
Modified: trunk/numeric.c
===================================================================
--- trunk/numeric.c 2006-07-19 19:22:12 UTC (rev 527)
+++ trunk/numeric.c 2006-08-05 21:30:01 UTC (rev 528)
@@ -1694,6 +1694,24 @@
/*
* call-seq:
+ * fixnum.next => integer
+ * fixnum.succ => integer
+ *
+ * Returns the <code>Integer</code> equal to <i>int</i> + 1.
+ *
+ * 1.next #=> 2
+ * (-1).next #=> 0
+ */
+
+static VALUE
+fix_succ(VALUE num)
+{
+ long i = FIX2LONG(num) + 1;
+ return LONG2NUM(i);
+}
+
+/*
+ * call-seq:
* int.next => integer
* int.succ => integer
*
@@ -2904,6 +2922,8 @@
rb_define_method(rb_cFixnum, "size", fix_size, 0);
rb_define_method(rb_cFixnum, "zero?", fix_zero_p, 0);
+ rb_define_method(rb_cFixnum, "succ", fix_succ, 0);
+
rb_cFloat = rb_define_class("Float", rb_cNumeric);
rb_undef_alloc_func(rb_cFloat);
Modified: trunk/thread.c
===================================================================
--- trunk/thread.c 2006-07-19 19:22:12 UTC (rev 527)
+++ trunk/thread.c 2006-08-05 21:30:01 UTC (rev 528)
@@ -1948,7 +1948,6 @@
rb_define_singleton_method(cYarvThread, "stop", rb_thread_stop, 0);
rb_define_singleton_method(cYarvThread, "kill", rb_thread_s_kill, 1);
rb_define_singleton_method(cYarvThread, "exit", rb_thread_exit, 0);
- rb_define_singleton_method(cYarvThread, "current", yarv_thread_s_current, 0);
rb_define_singleton_method(cYarvThread, "pass", yarv_thread_s_pass, 0);
rb_define_singleton_method(cYarvThread, "list", rb_thread_list, 0);
rb_define_singleton_method(cYarvThread, "critical", rb_thread_s_critical, 0);
Modified: trunk/vm.c
===================================================================
--- trunk/vm.c 2006-07-19 19:22:12 UTC (rev 527)
+++ trunk/vm.c 2006-08-05 21:30:01 UTC (rev 528)
@@ -1345,8 +1345,65 @@
TH_JUMP_TAG(th, TAG_BREAK);
}
-VALUE yarv_unredefined_flag = 0x01;
+static VALUE yarv_redefined_flag = 0;
+static st_table *yarv_opt_method_table = 0;
+void
+yarv_check_redefinition_opt_method(NODE *node)
+{
+ VALUE bop;
+
+ if (st_lookup(yarv_opt_method_table, (st_data_t)node, &bop)) {
+ yarv_redefined_flag |= bop;
+ }
+}
+
+static void
+add_opt_method(VALUE klass, ID mid, VALUE bop)
+{
+ NODE *node;
+ if (st_lookup(RCLASS(klass)->m_tbl, mid, (void *)&node) &&
+ nd_type(node->nd_body->nd_body) == NODE_CFUNC) {
+ st_insert(yarv_opt_method_table, (st_data_t)node, (st_data_t)bop);
+ }
+ else {
+ rb_bug("undefined optimized method", mid);
+ }
+}
+
+void
+yarv_init_redefined_flag()
+{
+ VALUE register_info[] = {
+ idPLUS, BOP_PLUS, rb_cFixnum, rb_cFloat, rb_cString, rb_cArray, 0,
+ idMINUS, BOP_MINUS, rb_cFixnum, 0,
+ idMULT, BOP_MULT, rb_cFixnum, rb_cFloat, 0,
+ idDIV, BOP_DIV, rb_cFixnum, rb_cFloat, 0,
+ idMOD, BOP_MOD, rb_cFixnum, rb_cFloat, 0,
+ idEq, BOP_EQ, rb_cFixnum, rb_cFloat, rb_cString, 0,
+ idLT, BOP_LT, rb_cFixnum, 0,
+ idLE, BOP_LE, rb_cFixnum, 0,
+ idLTLT, BOP_LTLT, rb_cString, rb_cArray, 0,
+ idAREF, BOP_AREF, rb_cArray, rb_cHash, 0,
+ idASET, BOP_ASET, rb_cArray, rb_cHash, 0,
+ idLength, BOP_LENGTH, rb_cArray, rb_cString, rb_cHash, 0,
+ idSucc, BOP_SUCC, rb_cFixnum, rb_cString, rb_cTime, 0,
+ 0,
+ };
+ VALUE *ptr = register_info;
+ yarv_opt_method_table = st_init_numtable();
+
+ while (*ptr) {
+ ID mid = *ptr++;
+ VALUE bop = *ptr++;
+ while(*ptr) {
+ VALUE klass = *ptr++;
+ add_opt_method(klass, mid, bop);
+ }
+ ptr++;
+ }
+}
+
#include "vm_evalbody.h"
/* finish
Modified: trunk/vm.h
===================================================================
--- trunk/vm.h 2006-07-19 19:22:12 UTC (rev 527)
+++ trunk/vm.h 2006-08-05 21:30:01 UTC (rev 528)
@@ -265,4 +265,18 @@
#define INC_VM_STATE_VERSION() \
(yarvGlobalStateVersion = (yarvGlobalStateVersion+1) & 0x8fffffff)
+#define BOP_PLUS 0x01
+#define BOP_MINUS 0x02
+#define BOP_MULT 0x04
+#define BOP_DIV 0x08
+#define BOP_MOD 0x10
+#define BOP_EQ 0x20
+#define BOP_LT 0x40
+#define BOP_LE 0x80
+#define BOP_LTLT 0x100
+#define BOP_AREF 0x200
+#define BOP_ASET 0x400
+#define BOP_LENGTH 0x800
+#define BOP_SUCC 0x1000
+
#endif // _VM_H_INCLUDED_
Modified: trunk/yarvcore.c
===================================================================
--- trunk/yarvcore.c 2006-07-19 19:22:12 UTC (rev 527)
+++ trunk/yarvcore.c 2006-08-05 21:30:01 UTC (rev 528)
@@ -814,9 +814,7 @@
#elif OPT_CALL_THREADED_CODE
"[call threaded code] "
#endif
-#if FAKE_INLINE_METHOD_CACHE
- "[fake inline method cache] "
-#endif
+
#if OPT_BASIC_OPERATIONS
"[optimize basic operation] "
#endif
@@ -890,7 +888,6 @@
rb_define_method(cYarvProc, "call", proc_call, -1);
rb_define_method(cYarvProc, "[]", proc_call, -1);
rb_define_method(cYarvProc, "to_proc", proc_to_proc, 0);
- rb_define_method(cYarvProc, "clone", proc_clone, 0);
rb_define_method(cYarvProc, "arity", proc_arity, 0);
rb_define_method(cYarvProc, "clone", proc_clone, 0);
rb_define_method(cYarvProc, "dup", proc_dup, 0);
@@ -996,6 +993,7 @@
vm->living_threads = st_init_numtable();
st_insert(vm->living_threads, th->self, (st_data_t) th->thread_id);
}
+ yarv_init_redefined_flag();
}
static void
Modified: trunk/yarvcore.h
===================================================================
--- trunk/yarvcore.h 2006-07-19 19:22:12 UTC (rev 527)
+++ trunk/yarvcore.h 2006-08-05 21:30:01 UTC (rev 528)
@@ -461,8 +461,11 @@
VALUE yarv_iseq_new(NODE *node, VALUE name, VALUE file,
VALUE parent, VALUE type);
+VALUE yarv_iseq_new_with_bopt(NODE *node, VALUE name, VALUE file_name,
+ VALUE parent, VALUE type, VALUE bopt);
+
VALUE yarv_iseq_new_with_opt(NODE *node, VALUE name, VALUE file,
- VALUE parent, VALUE type, VALUE bopt,
+ VALUE parent, VALUE type,
const yarv_compile_option_t *opt);
/** disassemble instruction sequence */
Added: trunk/yarvtest/test_opts.rb
===================================================================
--- trunk/yarvtest/test_opts.rb 2006-07-19 19:22:12 UTC (rev 527)
+++ trunk/yarvtest/test_opts.rb 2006-08-05 21:30:01 UTC (rev 528)
@@ -0,0 +1,86 @@
+require 'yarvtest/yarvtest'
+
+class TestOpt < YarvTestBase
+ def test_plus
+ ae %q{
+ a, b = 1, 2
+ a+b
+ }
+ ae %q{
+ class Fixnum
+ def +(*o)
+ o
+ end
+ def -(*o)
+ o
+ end
+ end
+ [10+11, 100-101]
+ }
+ ae %q{
+ class Float
+ def +(o)
+ self * o
+ end
+ end
+
+ a, b = 1, 2
+ a+b
+ }
+ end
+
+ def test_opt_methdos
+ klasses = [[Fixnum, 2, 3], [Float, 1.1, 2.2],
+ [String, "abc", "def"], [Array, [1,2,3], [4, 5]],
+ [Hash, {:a=>1, :b=>2}, {:x=>"foo", :y=>"bar"}]]
+
+ bin_methods = [:+, :-, :*, :/, :%, ]
+ one_methods = [:length, :succ, ]
+ ary = []
+
+ bin_methods.each{|m|
+ klasses.each{|klass, obj, arg|
+ str = %{
+ ary = []
+ if (#{obj.inspect}).respond_to? #{m.inspect}
+ begin
+ ary << (#{obj.inspect}).#{m.to_s}(#{arg.inspect})
+ rescue Exception => e
+ ary << :error
+ end
+ end
+
+ class #{klass}
+ def #{m}(o)
+ [#{m.inspect}, :bin, #{klass}].inspect
+ end
+ end
+ ary << (#{obj.inspect}).#{m.to_s}(#{arg.inspect})
+ ary
+ }
+ ae str
+ }
+ }
+ one_methods.each{|m|
+ klasses.each{|klass, obj|
+ str = %{
+ ary = []
+ if (#{obj.inspect}).respond_to? #{m.inspect}
+ ary << (#{obj.inspect}).#{m.to_s}()
+ end
+
+ class #{klass}
+ def #{m}()
+ [#{m.inspect}, self, #{klass}].inspect
+ end
+ end
+ ary << (#{obj.inspect}).#{m.to_s}()
+ ary
+ }
+ ae str
+ }
+ }
+ end
+end
+
+
--
ML: yarv-diff quickml.atdot.net
Info: http://www.atdot.net/~ko1/quickml