Browse files

* Merge YARV

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11439 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information...
1 parent 3e7566d commit a3e1b1ce7ed7e7ffac23015fc2fde56511b30681 @ko1 ko1 committed Dec 31, 2006
Showing with 27,207 additions and 14,788 deletions.
  1. +4 −0 ChangeLog
  2. +39 −30 array.c
  3. +15 −0 benchmark/bm_app_answer.rb
  4. +11 −0 benchmark/bm_app_factorial.rb
  5. +10 −0 benchmark/bm_app_fib.rb
  6. +23 −0 benchmark/bm_app_mandelbrot.rb
  7. +259 −0 benchmark/bm_app_pentomino.rb
  8. +8 −0 benchmark/bm_app_raise.rb
  9. +5 −0 benchmark/bm_app_strconcat.rb
  10. +13 −0 benchmark/bm_app_tak.rb
  11. +10 −0 benchmark/bm_app_tarai.rb
  12. +1 −0 benchmark/bm_loop_times.rb
  13. +4 −0 benchmark/bm_loop_whileloop.rb
  14. +5 −0 benchmark/bm_loop_whileloop2.rb
  15. +19 −0 benchmark/bm_so_ackermann.rb
  16. +23 −0 benchmark/bm_so_array.rb
  17. +18 −0 benchmark/bm_so_concatenate.rb
  18. +18 −0 benchmark/bm_so_count_words.rb
  19. +61 −0 benchmark/bm_so_exception.rb
  20. +47 −0 benchmark/bm_so_lists.rb
  21. +48 −0 benchmark/bm_so_matrix.rb
  22. +24 −0 benchmark/bm_so_nested_loop.rb
  23. +56 −0 benchmark/bm_so_object.rb
  24. +20 −0 benchmark/bm_so_random.rb
  25. +24 −0 benchmark/bm_so_sieve.rb
  26. +10 −0 benchmark/bm_vm1_block.rb
  27. +8 −0 benchmark/bm_vm1_const.rb
  28. +11 −0 benchmark/bm_vm1_ensure.rb
  29. +9 −0 benchmark/bm_vm1_length.rb
  30. +7 −0 benchmark/bm_vm1_rescue.rb
  31. +9 −0 benchmark/bm_vm1_simplereturn.rb
  32. +8 −0 benchmark/bm_vm1_swap.rb
  33. +5 −0 benchmark/bm_vm2_array.rb
  34. +9 −0 benchmark/bm_vm2_method.rb
  35. +20 −0 benchmark/bm_vm2_poly_method.rb
  36. +20 −0 benchmark/bm_vm2_poly_method_ov.rb
  37. +14 −0 benchmark/bm_vm2_proc.rb
  38. +6 −0 benchmark/bm_vm2_regexp.rb
  39. +12 −0 benchmark/bm_vm2_send.rb
  40. +20 −0 benchmark/bm_vm2_super.rb
  41. +8 −0 benchmark/bm_vm2_unif1.rb
  42. +20 −0 benchmark/bm_vm2_zsuper.rb
  43. +6 −0 benchmark/bm_vm3_thread_create_join.rb
  44. +57 −0 benchmark/bmx_temp.rb
  45. +11 −0 benchmark/other-lang/ack.pl
  46. +16 −0 benchmark/other-lang/ack.py
  47. +12 −0 benchmark/other-lang/ack.rb
  48. +7 −0 benchmark/other-lang/ack.scm
  49. +66 −0 benchmark/other-lang/eval.rb
  50. +13 −0 benchmark/other-lang/fact.pl
  51. +18 −0 benchmark/other-lang/fact.py
  52. +13 −0 benchmark/other-lang/fact.rb
  53. +8 −0 benchmark/other-lang/fact.scm
  54. +11 −0 benchmark/other-lang/fib.pl
  55. +7 −0 benchmark/other-lang/fib.py
  56. +9 −0 benchmark/other-lang/fib.rb
  57. +7 −0 benchmark/other-lang/fib.scm
  58. +3 −0 benchmark/other-lang/loop.pl
  59. +2 −0 benchmark/other-lang/loop.py
  60. +4 −0 benchmark/other-lang/loop.rb
  61. +1 −0 benchmark/other-lang/loop.scm
  62. +1 −0 benchmark/other-lang/loop2.rb
  63. +11 −0 benchmark/other-lang/tak.pl
  64. +8 −0 benchmark/other-lang/tak.py
  65. +13 −0 benchmark/other-lang/tak.rb
  66. +10 −0 benchmark/other-lang/tak.scm
  67. +81 −0 benchmark/report.rb
  68. +137 −0 benchmark/run.rb
  69. +129 −0 benchmark/run_rite.rb
  70. +29 −0 benchmark/runc.rb
  71. +25 −0 benchmark/wc.input.base
  72. +461 −0 blockinlining.c
  73. +94 −0 call_cfunc.ci
  74. +55 −26 class.c
  75. +207 −202 common.mk
  76. +4,914 −0 compile.c
  77. +210 −0 compile.h
  78. +9 −6 configure.in
  79. +71 −0 debug.c
  80. +47 −0 debug.h
  81. +6,917 −0 doc/ChangeLog-YARV
  82. +29 −28 error.c
  83. +2,251 −12,510 eval.c
  84. +250 −0 eval_error.h
  85. +328 −0 eval_intern.h
  86. +411 −0 eval_jump.h
  87. +508 −0 eval_load.c
  88. +612 −0 eval_method.h
  89. +1,195 −0 eval_proc.c
  90. +117 −0 eval_safe.h
  91. +683 −0 eval_thread.c
  92. +12 −12 ext/dl/lib/dl/import.rb
  93. +0 −1 ext/etc/.cvsignore
  94. +4 −2 ext/etc/etc.c
  95. +1 −1 ext/iconv/iconv.c
  96. +0 −1 ext/readline/readline.c
  97. +3 −0 ext/ripper/extconf.rb
  98. +6 −6 ext/win32ole/win32ole.c
  99. +1 −1 ext/zlib/zlib.c
  100. +298 −249 gc.c
  101. +48 −0 gc.h
  102. +40 −35 inits.c
  103. +146 −0 insnhelper.h
  104. +2,390 −0 insns.def
  105. +15 −8 intern.h
  106. +1,345 −0 iseq.c
  107. +2 −1 lib/.document
  108. +6 −4 lib/drb/drb.rb
  109. +12 −8 lib/drb/extservm.rb
  110. +2 −0 lib/generator.rb
  111. +3 −1 lib/getoptlong.rb
  112. +20 −19 lib/mkmf.rb
  113. +57 −79 lib/monitor.rb
  114. +24 −54 lib/mutex_m.rb
  115. +1 −1 lib/rss/0.9.rb
  116. +1 −1 lib/rss/dublincore.rb
  117. +1 −1 lib/rss/parser.rb
  118. +40 −85 lib/singleton.rb
  119. +17 −19 lib/tempfile.rb
  120. +75 −188 lib/thread.rb
  121. +18 −35 lib/timeout.rb
  122. +20 −37 lib/weakref.rb
  123. +1 −1 lib/webrick/utils.rb
  124. +8 −5 main.c
  125. +23 −111 node.h
  126. +47 −21 numeric.c
  127. +8 −8 object.c
  128. +29 −0 opt_insn_unif.def
  129. +59 −0 opt_operand.def
  130. +592 −582 parse.y
  131. +13 −17 process.c
  132. +78 −43 range.c
  133. +59 −31 regenc.h
  134. +179 −118 ruby.c
  135. +21 −19 ruby.h
  136. +5 −26 rubysig.h
  137. +1 −1 rubytest.rb
  138. +4 −1 runruby.rb
  139. +16 −12 sample/test.rb
  140. +105 −132 signal.c
  141. +1 −1 st.c
  142. +11 −8 string.c
  143. +21 −0 template/insns.inc.tmpl
  144. +77 −0 template/insns_info.inc.tmpl
  145. +39 −0 template/insnstbl.html
  146. +14 −0 template/minsns.inc.tmpl
  147. +32 −0 template/opt_sc.inc.tmpl
  148. +30 −0 template/optinsn.inc.tmpl
  149. +35 −0 template/optunifs.inc.tmpl
  150. +28 −0 template/vm.inc.tmpl
  151. +18 −0 template/vmtc.inc.tmpl
Sorry, we could not display the entire diff because it was too big.
View
4 ChangeLog
@@ -1,3 +1,7 @@
+Mon Jan 01 00:00:00 2007 Koichi Sasada <ko1@atdot.net>
+
+ * Merge YARV
+
Sun Dec 31 16:22:48 2006 Eric Hodel <drbrain@segment7.net>
* array.c: Fix Array#reject.
View
69 array.c
@@ -44,7 +44,7 @@ static void
ary_iter_check(VALUE ary)
{
if (FL_TEST(ary, ARY_ITERLOCK)) {
- rb_raise(rb_eRuntimeError, "can't modify array during iteration");
+ rb_raise(rb_eRuntimeError, "can't modify array during iteration");
}
}
#define ARY_SORTLOCK FL_USER3
@@ -143,7 +143,7 @@ ary_new(VALUE klass, long len)
rb_raise(rb_eArgError, "array size too big");
}
ary = ary_alloc(klass);
- if (len == 0) len++;
+ if (len == 0) len++;
RARRAY(ary)->ptr = ALLOC_N(VALUE, len);
RARRAY(ary)->aux.capa = len;
@@ -250,8 +250,6 @@ rb_check_array_type(VALUE ary)
return rb_check_convert_type(ary, T_ARRAY, "Array", "to_ary");
}
-static VALUE rb_ary_replace(VALUE, VALUE);
-
/*
* call-seq:
* Array.new(size=0, obj=nil)
@@ -325,7 +323,7 @@ rb_ary_initialize(int argc, VALUE *argv, VALUE ary)
rb_raise(rb_eArgError, "array size too big");
}
rb_ary_modify(ary);
- RESIZE_CAPA(ary, len);
+ RESIZE_CAPA(ary, len);
if (rb_block_given_p()) {
long i;
@@ -543,10 +541,10 @@ rb_ary_shift(VALUE ary)
top = RARRAY_PTR(ary)[0];
if (!ARY_SHARED_P(ary)) {
if (RARRAY_LEN(ary) < ARY_DEFAULT_SIZE) {
- MEMMOVE(RARRAY_PTR(ary), RARRAY_PTR(ary)+1, VALUE, RARRAY_LEN(ary)-1);
+ MEMMOVE(RARRAY_PTR(ary), RARRAY_PTR(ary)+1, VALUE, RARRAY_LEN(ary)-1);
RARRAY(ary)->len--;
- return top;
- }
+ return top;
+ }
RARRAY_PTR(ary)[0] = Qnil;
ary_make_shared(ary);
}
@@ -590,7 +588,7 @@ rb_ary_shift_m(int argc, VALUE *argv, VALUE ary)
if (ARY_SHARED_P(ary)) {
RARRAY(ary)->ptr += n;
RARRAY(ary)->len -= n;
- }
+ }
else {
MEMMOVE(RARRAY_PTR(ary), RARRAY_PTR(ary)+n, VALUE, RARRAY_LEN(ary)-n);
RARRAY(ary)->len -= n;
@@ -675,7 +673,7 @@ rb_ary_subseq(VALUE ary, long beg, long len)
if (len == 0) return ary_new(klass, 0);
shared = ary_make_shared(ary);
- ptr = RARRAY_PTR(ary);
+ ptr = RARRAY_PTR(ary);
ary2 = ary_alloc(klass);
RARRAY(ary2)->ptr = ptr + beg;
RARRAY(ary2)->len = len;
@@ -775,8 +773,8 @@ rb_ary_at(VALUE ary, VALUE pos)
/*
* call-seq:
* array.first -> obj or nil
- * array.first(n) -> an_array
- *
+ * array.first(n) -> an_array
+ *
* Returns the first element, or the first +n+ elements, of the array.
* If the array is empty, the first form returns <code>nil</code>, and the
* second form returns an empty array.
@@ -931,7 +929,7 @@ rb_ary_rindex(int argc, VALUE *argv, VALUE ary)
long i = RARRAY_LEN(ary);
if (rb_scan_args(argc, argv, "01", &val) == 0) {
- RETURN_ENUMERATOR(ary, 0, 0);
+ RETURN_ENUMERATOR(ary, 0, 0);
while (i--) {
if (RTEST(rb_yield(RARRAY_PTR(ary)[i])))
return LONG2NUM(i);
@@ -1145,11 +1143,23 @@ each_i(VALUE ary)
* a -- b -- c --
*/
+VALUE yarv_invoke_Array_each_special_block(VALUE ary);
+
VALUE
rb_ary_each(VALUE ary)
{
+ long i;
+ VALUE val;
+
RETURN_ENUMERATOR(ary, 0, 0);
+
+ val = yarv_invoke_Array_each_special_block(ary);
+ if(val != Qundef){
+ return val;
+ }
+
ITERATE(each_i, ary);
+ return ary;
}
static VALUE
@@ -1158,7 +1168,7 @@ each_index_i(VALUE ary)
long i;
for (i=0; i<RARRAY_LEN(ary); i++) {
- rb_yield(LONG2NUM(i));
+ rb_yield(LONG2NUM(i));
}
return ary;
}
@@ -1530,7 +1540,7 @@ sort_i(VALUE ary)
data.ary = ary;
data.ptr = RARRAY_PTR(ary); data.len = RARRAY_LEN(ary);
ruby_qsort(RARRAY_PTR(ary), RARRAY_LEN(ary), sizeof(VALUE),
- rb_block_given_p()?sort_1:sort_2, &data);
+ rb_block_given_p()?sort_1:sort_2, &data);
return ary;
}
@@ -1890,7 +1900,6 @@ rb_ary_slice_bang(int argc, VALUE *argv, VALUE ary)
return rb_ary_delete_at(ary, NUM2LONG(arg1));
}
-
static VALUE
reject_bang_i(VALUE ary)
{
@@ -1905,10 +1914,10 @@ reject_bang_i(VALUE ary)
}
i2++;
}
+
if (RARRAY_LEN(ary) == i2) return Qnil;
if (i2 < RARRAY_LEN(ary))
RARRAY(ary)->len = i2;
-
return ary;
}
@@ -2075,7 +2084,7 @@ rb_ary_transpose(VALUE ary)
* a #=> ["x", "y", "z"]
*/
-static VALUE
+VALUE
rb_ary_replace(VALUE copy, VALUE orig)
{
VALUE shared;
@@ -2087,7 +2096,7 @@ rb_ary_replace(VALUE copy, VALUE orig)
if (copy == orig) return copy;
shared = ary_make_shared(orig);
ptr = RARRAY(copy)->ptr;
- xfree(ptr);
+ xfree(ptr);
RARRAY(copy)->ptr = RARRAY(shared)->ptr;
RARRAY(copy)->len = RARRAY(shared)->len;
RARRAY(copy)->aux.shared = shared;
@@ -2804,16 +2813,16 @@ flatten(VALUE ary, long idx, VALUE ary2, VALUE memo, int level)
rb_ary_push(memo, id);
rb_ary_splice(ary, idx, 1, ary2);
if (level != 0) {
- while (i < lim) {
- VALUE tmp;
+ while (i < lim) {
+ VALUE tmp;
- tmp = rb_check_array_type(rb_ary_elt(ary, i));
- if (!NIL_P(tmp)) {
+ tmp = rb_check_array_type(rb_ary_elt(ary, i));
+ if (!NIL_P(tmp)) {
n = flatten(ary, i, tmp, memo, level);
- i += n; lim += n;
- }
- i++;
+ i += n; lim += n;
}
+ i++;
+ }
}
rb_ary_pop(memo);
@@ -2822,7 +2831,7 @@ flatten(VALUE ary, long idx, VALUE ary2, VALUE memo, int level)
/*
* call-seq:
- * array.flatten! -> array or nil
+ * array.flatten! -> array or nil
* array.flatten!(level) -> array or nil
*
* Flattens _self_ in place.
@@ -2831,9 +2840,9 @@ flatten(VALUE ary, long idx, VALUE ary2, VALUE memo, int level)
* argument determins the level of recursion to flatten.
*
* a = [ 1, 2, [3, [4, 5] ] ]
- * a.flatten! #=> [1, 2, 3, 4, 5]
- * a.flatten! #=> nil
- * a #=> [1, 2, 3, 4, 5]
+ * a.flatten! #=> [1, 2, 3, 4, 5]
+ * a.flatten! #=> nil
+ * a #=> [1, 2, 3, 4, 5]
* a = [ 1, 2, [3, [4, 5] ] ]
* a.flatten!(1) #=> [1, 2, 3, [4, 5]]
*/
View
15 benchmark/bm_app_answer.rb
@@ -0,0 +1,15 @@
+def ack(m, n)
+ if m == 0 then
+ n + 1
+ elsif n == 0 then
+ ack(m - 1, 1)
+ else
+ ack(m - 1, ack(m, n - 1))
+ end
+end
+
+def the_answer_to_life_the_universe_and_everything
+ (ack(3,7).to_s.split(//).inject(0){|s,x| s+x.to_i}.to_s + "2" ).to_i
+end
+
+answer = the_answer_to_life_the_universe_and_everything
View
11 benchmark/bm_app_factorial.rb
@@ -0,0 +1,11 @@
+def fact(n)
+ if(n > 1)
+ n * fact(n-1)
+ else
+ 1
+ end
+end
+
+8.times{
+ fact(5000)
+}
View
10 benchmark/bm_app_fib.rb
@@ -0,0 +1,10 @@
+def fib n
+ if n < 3
+ 1
+ else
+ fib(n-1) + fib(n-2)
+ end
+end
+
+fib(34)
+
View
23 benchmark/bm_app_mandelbrot.rb
@@ -0,0 +1,23 @@
+require 'complex'
+
+def mandelbrot? z
+ i = 0
+ while i<100
+ i+=1
+ z = z * z
+ return false if z.abs > 2
+ end
+ true
+end
+
+ary = []
+
+(0..100).each{|dx|
+ (0..100).each{|dy|
+ x = dx / 50.0
+ y = dy / 50.0
+ c = Complex(x, y)
+ ary << c if mandelbrot?(c)
+ }
+}
+
View
259 benchmark/bm_app_pentomino.rb
@@ -0,0 +1,259 @@
+#!/usr/local/bin/ruby
+# This program is contributed by Shin Nishiyama
+
+
+# modified by K.Sasada
+
+NP = 5
+ROW = 8 + NP
+COL = 8
+
+$p = []
+$b = []
+$no = 0
+
+def piece(n, a, nb)
+ nb.each{|x|
+ a[n] = x
+ if n == NP-1
+ $p << [a.sort]
+ else
+ nbc=nb.clone
+ [-ROW, -1, 1, ROW].each{|d|
+ if x+d > 0 and not a.include?(x+d) and not nbc.include?(x+d)
+ nbc << x+d
+ end
+ }
+ nbc.delete x
+ piece(n+1,a[0..n],nbc)
+ end
+ }
+end
+
+def kikaku(a)
+ a.collect {|x| x - a[0]}
+end
+def ud(a)
+ kikaku(a.collect {|x| ((x+NP)%ROW)-ROW*((x+NP)/ROW) }.sort)
+end
+def rl(a)
+ kikaku(a.collect {|x| ROW*((x+NP)/ROW)+ROW-((x+NP)%ROW)}.sort)
+end
+def xy(a)
+ kikaku(a.collect {|x| ROW*((x+NP)%ROW) + (x+NP)/ROW }.sort)
+end
+
+def mkpieces
+ piece(0,[],[0])
+ $p.each do |a|
+ a0 = a[0]
+ a[1] = ud(a0)
+ a[2] = rl(a0)
+ a[3] = ud(rl(a0))
+ a[4] = xy(a0)
+ a[5] = ud(xy(a0))
+ a[6] = rl(xy(a0))
+ a[7] = ud(rl(xy(a0)))
+ a.sort!
+ a.uniq!
+ end
+ $p.uniq!.sort! {|x,y| x[0] <=> y[0] }
+end
+
+def mkboard
+ (0...ROW*COL).each{|i|
+ if i % ROW >= ROW-NP
+ $b[i] = -2
+ else
+ $b[i] = -1
+ end
+ $b[3*ROW+3]=$b[3*ROW+4]=$b[4*ROW+3]=$b[4*ROW+4]=-2
+ }
+end
+
+def pboard
+ return # skip print
+ print "No. #$no\n"
+ (0...COL).each{|i|
+ print "|"
+ (0...ROW-NP).each{|j|
+ x = $b[i*ROW+j]
+ if x < 0
+ print "..|"
+ else
+ printf "%2d|",x+1
+ end
+ }
+ print "\n"
+ }
+ print "\n"
+end
+
+$pnum=[]
+def setpiece(a,pos)
+ if a.length == $p.length then
+ $no += 1
+ pboard
+ return
+ end
+ while $b[pos] != -1
+ pos += 1
+ end
+ ($pnum - a).each do |i|
+ $p[i].each do |x|
+ f = 0
+ x.each{|s|
+ if $b[pos+s] != -1
+ f=1
+ break
+ end
+ }
+ if f == 0 then
+ x.each{|s|
+ $b[pos+s] = i
+ }
+ a << i
+ setpiece(a.clone, pos)
+ a.pop
+ x.each{|s|
+ $b[pos+s] = -1
+ }
+ end
+ end
+ end
+end
+
+mkpieces
+mkboard
+$p[4] = [$p[4][0]]
+$pnum = (0...$p.length).to_a
+setpiece([],0)
+
+
+__END__
+
+# original
+
+NP = 5
+ROW = 8 + NP
+COL = 8
+
+$p = []
+$b = []
+$no = 0
+
+def piece(n,a,nb)
+ for x in nb
+ a[n] = x
+ if n == NP-1
+ $p << [a.sort]
+ else
+ nbc=nb.clone
+ for d in [-ROW, -1, 1, ROW]
+ if x+d > 0 and not a.include?(x+d) and not nbc.include?(x+d)
+ nbc << x+d
+ end
+ end
+ nbc.delete x
+ piece(n+1,a[0..n],nbc)
+ end
+ end
+end
+
+def kikaku(a)
+ a.collect {|x| x - a[0]}
+end
+def ud(a)
+ kikaku(a.collect {|x| ((x+NP)%ROW)-ROW*((x+NP)/ROW) }.sort)
+end
+def rl(a)
+ kikaku(a.collect {|x| ROW*((x+NP)/ROW)+ROW-((x+NP)%ROW)}.sort)
+end
+def xy(a)
+ kikaku(a.collect {|x| ROW*((x+NP)%ROW) + (x+NP)/ROW }.sort)
+end
+
+def mkpieces
+ piece(0,[],[0])
+ $p.each do |a|
+ a0 = a[0]
+ a[1] = ud(a0)
+ a[2] = rl(a0)
+ a[3] = ud(rl(a0))
+ a[4] = xy(a0)
+ a[5] = ud(xy(a0))
+ a[6] = rl(xy(a0))
+ a[7] = ud(rl(xy(a0)))
+ a.sort!
+ a.uniq!
+ end
+ $p.uniq!.sort! {|x,y| x[0] <=> y[0] }
+end
+
+def mkboard
+ for i in 0...ROW*COL
+ if i % ROW >= ROW-NP
+ $b[i] = -2
+ else
+ $b[i] = -1
+ end
+ $b[3*ROW+3]=$b[3*ROW+4]=$b[4*ROW+3]=$b[4*ROW+4]=-2
+ end
+end
+
+def pboard
+ print "No. #$no\n"
+ for i in 0...COL
+ print "|"
+ for j in 0...ROW-NP
+ x = $b[i*ROW+j]
+ if x < 0
+ print "..|"
+ else
+ printf "%2d|",x+1
+ end
+ end
+ print "\n"
+ end
+ print "\n"
+end
+
+$pnum=[]
+def setpiece(a,pos)
+ if a.length == $p.length then
+ $no += 1
+ pboard
+ return
+ end
+ while $b[pos] != -1
+ pos += 1
+ end
+ ($pnum - a).each do |i|
+ $p[i].each do |x|
+ f = 0
+ for s in x do
+ if $b[pos+s] != -1
+ f=1
+ break
+ end
+ end
+ if f == 0 then
+ for s in x do
+ $b[pos+s] = i
+ end
+ a << i
+ setpiece(a.clone, pos)
+ a.pop
+ for s in x do
+ $b[pos+s] = -1
+ end
+ end
+ end
+ end
+end
+
+mkpieces
+mkboard
+$p[4] = [$p[4][0]]
+$pnum = (0...$p.length).to_a
+setpiece([],0)
View
8 benchmark/bm_app_raise.rb
@@ -0,0 +1,8 @@
+i=0
+while i<300000
+ i+=1
+ begin
+ raise
+ rescue
+ end
+end
View
5 benchmark/bm_app_strconcat.rb
@@ -0,0 +1,5 @@
+i=0
+while i<500000
+ "#{1+1} #{1+1} #{1+1}"
+ i+=1
+end
View
13 benchmark/bm_app_tak.rb
@@ -0,0 +1,13 @@
+
+def tak x, y, z
+ unless y < x
+ z
+ else
+ tak( tak(x-1, y, z),
+ tak(y-1, z, x),
+ tak(z-1, x, y))
+ end
+end
+
+tak(18, 9, 0)
+
View
10 benchmark/bm_app_tarai.rb
@@ -0,0 +1,10 @@
+def tarai( x, y, z )
+ if x <= y
+ then y
+ else tarai(tarai(x-1, y, z),
+ tarai(y-1, z, x),
+ tarai(z-1, x, y))
+ end
+end
+
+tarai(12, 6, 0)
View
1 benchmark/bm_loop_times.rb
@@ -0,0 +1 @@
+30000000.times{|e|}
View
4 benchmark/bm_loop_whileloop.rb
@@ -0,0 +1,4 @@
+i = 0
+while i<30000000 # benchmark loop 1
+ i+=1
+end
View
5 benchmark/bm_loop_whileloop2.rb
@@ -0,0 +1,5 @@
+i=0
+while i<6000000 # benchmark loop 2
+ i+=1
+end
+
View
19 benchmark/bm_so_ackermann.rb
@@ -0,0 +1,19 @@
+#!/usr/bin/ruby
+# -*- mode: ruby -*-
+# $Id: ackermann-ruby.code,v 1.4 2004/11/13 07:40:41 bfulgham Exp $
+# http://www.bagley.org/~doug/shootout/
+
+def ack(m, n)
+ if m == 0 then
+ n + 1
+ elsif n == 0 then
+ ack(m - 1, 1)
+ else
+ ack(m - 1, ack(m, n - 1))
+ end
+end
+
+NUM = 9
+ack(3, NUM)
+
+
View
23 benchmark/bm_so_array.rb
@@ -0,0 +1,23 @@
+#!/usr/bin/ruby
+# -*- mode: ruby -*-
+# $Id: ary-ruby.code,v 1.4 2004/11/13 07:41:27 bfulgham Exp $
+# http://www.bagley.org/~doug/shootout/
+# with help from Paul Brannan and Mark Hubbart
+
+n = 9000 # Integer(ARGV.shift || 1)
+
+x = Array.new(n)
+y = Array.new(n, 0)
+
+n.times{|bi|
+ x[bi] = bi + 1
+}
+
+(0 .. 999).each do |e|
+ (n-1).step(0,-1) do |bi|
+ y[bi] += x.at(bi)
+ end
+end
+# puts "#{y.first} #{y.last}"
+
+
View
18 benchmark/bm_so_concatenate.rb
@@ -0,0 +1,18 @@
+#!/usr/bin/ruby
+# -*- mode: ruby -*-
+# $Id: strcat-ruby.code,v 1.4 2004/11/13 07:43:28 bfulgham Exp $
+# http://www.bagley.org/~doug/shootout/
+# based on code from Aristarkh A Zagorodnikov and Dat Nguyen
+
+STUFF = "hello\n"
+i=0
+while i<10
+ i+=1
+ hello = ''
+ 400000.times do |e|
+ hello << STUFF
+ end
+end
+# puts hello.length
+
+
View
18 benchmark/bm_so_count_words.rb
@@ -0,0 +1,18 @@
+#!/usr/bin/ruby
+# -*- mode: ruby -*-
+# $Id: wc-ruby.code,v 1.4 2004/11/13 07:43:32 bfulgham Exp $
+# http://www.bagley.org/~doug/shootout/
+# with help from Paul Brannan
+
+input = open(File.join(File.dirname($0), 'wc.input'), 'rb')
+
+nl = nw = nc = 0
+while true
+ data = (input.read(4096) or break) << (input.gets || "")
+ nc += data.length
+ nl += data.count("\n")
+ ((data.strip! || data).tr!("\n", " ") || data).squeeze!
+ #nw += data.count(" ") + 1
+end
+# STDERR.puts "#{nl} #{nw} #{nc}"
+
View
61 benchmark/bm_so_exception.rb
@@ -0,0 +1,61 @@
+#!/usr/bin/ruby
+# -*- mode: ruby -*-
+# $Id: except-ruby.code,v 1.4 2004/11/13 07:41:33 bfulgham Exp $
+# http://www.bagley.org/~doug/shootout/
+
+$HI = 0
+$LO = 0
+NUM = 250000 # Integer(ARGV[0] || 1)
+
+
+class Lo_Exception < Exception
+ def initialize(num)
+ @value = num
+ end
+end
+
+class Hi_Exception < Exception
+ def initialize(num)
+ @value = num
+ end
+end
+
+def some_function(num)
+ begin
+ hi_function(num)
+ rescue
+ print "We shouldn't get here, exception is: #{$!.type}\n"
+ end
+end
+
+def hi_function(num)
+ begin
+ lo_function(num)
+ rescue Hi_Exception
+ $HI = $HI + 1
+ end
+end
+
+def lo_function(num)
+ begin
+ blowup(num)
+ rescue Lo_Exception
+ $LO = $LO + 1
+ end
+end
+
+def blowup(num)
+ if num % 2 == 0
+ raise Lo_Exception.new(num)
+ else
+ raise Hi_Exception.new(num)
+ end
+end
+
+
+i = 1
+max = NUM+1
+while i < max
+ i+=1
+ some_function(i+1)
+end
View
47 benchmark/bm_so_lists.rb
@@ -0,0 +1,47 @@
+#from http://www.bagley.org/~doug/shootout/bench/lists/lists.ruby
+
+NUM = 100
+SIZE = 10000
+
+def test_lists()
+ # create a list of integers (Li1) from 1 to SIZE
+ li1 = (1..SIZE).to_a
+ # copy the list to li2 (not by individual items)
+ li2 = li1.dup
+ # remove each individual item from left side of li2 and
+ # append to right side of li3 (preserving order)
+ li3 = Array.new
+ while (not li2.empty?)
+ li3.push(li2.shift)
+ end
+ # li2 must now be empty
+ # remove each individual item from right side of li3 and
+ # append to right side of li2 (reversing list)
+ while (not li3.empty?)
+ li2.push(li3.pop)
+ end
+ # li3 must now be empty
+ # reverse li1 in place
+ li1.reverse!
+ # check that first item is now SIZE
+ if li1[0] != SIZE then
+ p "not SIZE"
+ 0
+ else
+ # compare li1 and li2 for equality
+ if li1 != li2 then
+ return(0)
+ else
+ # return the length of the list
+ li1.length
+ end
+ end
+end
+
+i = 0
+while i<NUM
+ i+=1
+ result = test_lists()
+end
+
+result
View
48 benchmark/bm_so_matrix.rb
@@ -0,0 +1,48 @@
+#!/usr/bin/ruby
+# -*- mode: ruby -*-
+# $Id: matrix-ruby.code,v 1.4 2004/11/13 07:42:14 bfulgham Exp $
+# http://www.bagley.org/~doug/shootout/
+
+n = 60 #Integer(ARGV.shift || 1)
+
+size = 30
+
+def mkmatrix(rows, cols)
+ count = 1
+ mx = Array.new(rows)
+ (0 .. (rows - 1)).each do |bi|
+ row = Array.new(cols, 0)
+ (0 .. (cols - 1)).each do |j|
+ row[j] = count
+ count += 1
+ end
+ mx[bi] = row
+ end
+ mx
+end
+
+def mmult(rows, cols, m1, m2)
+ m3 = Array.new(rows)
+ (0 .. (rows - 1)).each do |bi|
+ row = Array.new(cols, 0)
+ (0 .. (cols - 1)).each do |j|
+ val = 0
+ (0 .. (cols - 1)).each do |k|
+ val += m1.at(bi).at(k) * m2.at(k).at(j)
+ end
+ row[j] = val
+ end
+ m3[bi] = row
+ end
+ m3
+end
+
+m1 = mkmatrix(size, size)
+m2 = mkmatrix(size, size)
+mm = Array.new
+n.times do
+ mm = mmult(size, size, m1, m2)
+end
+# puts "#{mm[0][0]} #{mm[2][3]} #{mm[3][2]} #{mm[4][4]}"
+
+
View
24 benchmark/bm_so_nested_loop.rb
@@ -0,0 +1,24 @@
+#!/usr/bin/ruby
+# -*- mode: ruby -*-
+# $Id: nestedloop-ruby.code,v 1.4 2004/11/13 07:42:22 bfulgham Exp $
+# http://www.bagley.org/~doug/shootout/
+# from Avi Bryant
+
+n = 16 # Integer(ARGV.shift || 1)
+x = 0
+n.times do
+ n.times do
+ n.times do
+ n.times do
+ n.times do
+ n.times do
+ x += 1
+ end
+ end
+ end
+ end
+ end
+end
+# puts x
+
+
View
56 benchmark/bm_so_object.rb
@@ -0,0 +1,56 @@
+#!/usr/bin/ruby
+# -*- mode: ruby -*-
+# $Id: objinst-ruby.code,v 1.4 2004/11/13 07:42:25 bfulgham Exp $
+# http://www.bagley.org/~doug/shootout/
+# with help from Aristarkh Zagorodnikov
+
+class Toggle
+ def initialize(start_state)
+ @bool = start_state
+ end
+
+ def value
+ @bool
+ end
+
+ def activate
+ @bool = !@bool
+ self
+ end
+end
+
+class NthToggle < Toggle
+ def initialize(start_state, max_counter)
+ super start_state
+ @count_max = max_counter
+ @counter = 0
+ end
+
+ def activate
+ @counter += 1
+ if @counter >= @count_max
+ @bool = !@bool
+ @counter = 0
+ end
+ self
+ end
+end
+
+n = 1500000 # (ARGV.shift || 1).to_i
+
+toggle = Toggle.new 1
+5.times do
+ toggle.activate.value ? 'true' : 'false'
+end
+n.times do
+ toggle = Toggle.new 1
+end
+
+ntoggle = NthToggle.new 1, 3
+8.times do
+ ntoggle.activate.value ? 'true' : 'false'
+end
+n.times do
+ ntoggle = NthToggle.new 1, 3
+end
+
View
20 benchmark/bm_so_random.rb
@@ -0,0 +1,20 @@
+# from http://www.bagley.org/~doug/shootout/bench/random/random.ruby
+
+IM = 139968.0
+IA = 3877.0
+IC = 29573.0
+
+$last = 42.0
+
+def gen_random(max)
+ (max * ($last = ($last * IA + IC) % IM)) / IM
+end
+
+N = 1000000
+
+i=0
+while i<N
+ i+=1
+ gen_random(100.0)
+end
+# "%.9f" % gen_random(100.0)
View
24 benchmark/bm_so_sieve.rb
@@ -0,0 +1,24 @@
+# from http://www.bagley.org/~doug/shootout/bench/sieve/sieve.ruby
+num = 40
+count = i = j = 0
+flags0 = Array.new(8192,1)
+k = 0
+while k < num
+ k+=1
+ count = 0
+ flags = flags0.dup
+ i = 2
+ while i<8192
+ i+=1
+ if flags[i]
+ # remove all multiples of prime: i
+ j = i*i
+ while j < 8192
+ j += i
+ flags[j] = nil
+ end
+ count += 1
+ end
+ end
+end
+count
View
10 benchmark/bm_vm1_block.rb
@@ -0,0 +1,10 @@
+def m
+ yield
+end
+
+i=0
+while i<30000000 # while loop 1
+ i+=1
+ m{
+ }
+end
View
8 benchmark/bm_vm1_const.rb
@@ -0,0 +1,8 @@
+Const = 1
+
+i = 0
+while i<30000000 # while loop 1
+ i+= 1
+ j = Const
+ k = Const
+end
View
11 benchmark/bm_vm1_ensure.rb
@@ -0,0 +1,11 @@
+i=0
+while i<30000000 # benchmark loop 1
+ i+=1
+ begin
+ begin
+ ensure
+ end
+ ensure
+ end
+end
+
View
9 benchmark/bm_vm1_length.rb
@@ -0,0 +1,9 @@
+a = 'abc'
+b = [1, 2, 3]
+i=0
+while i<30000000 # while loop 1
+ i+=1
+ a.length
+ b.length
+end
+
View
7 benchmark/bm_vm1_rescue.rb
@@ -0,0 +1,7 @@
+i=0
+while i<30000000 # while loop 1
+ i+=1
+ begin
+ rescue
+ end
+end
View
9 benchmark/bm_vm1_simplereturn.rb
@@ -0,0 +1,9 @@
+def m
+ return 1
+end
+i=0
+while i<30000000 # while loop 1
+ i+=1
+ m
+end
+
View
8 benchmark/bm_vm1_swap.rb
@@ -0,0 +1,8 @@
+a = 1
+b = 2
+i=0
+while i<30000000 # while loop 1
+ i+=1
+ a, b = b, a
+end
+
View
5 benchmark/bm_vm2_array.rb
@@ -0,0 +1,5 @@
+i=0
+while i<6000000 # benchmark loop 2
+ i+=1
+ a = [1,2,3,4,5,6,7,8,9,10]
+end
View
9 benchmark/bm_vm2_method.rb
@@ -0,0 +1,9 @@
+def m
+ nil
+end
+
+i=0
+while i<6000000 # benchmark loop 2
+ i+=1
+ m; m; m; m; m; m; m; m;
+end
View
20 benchmark/bm_vm2_poly_method.rb
@@ -0,0 +1,20 @@
+class C1
+ def m
+ 1
+ end
+end
+class C2
+ def m
+ 2
+ end
+end
+
+o1 = C1.new
+o2 = C2.new
+
+i=0
+while i<6000000 # benchmark loop 2
+ o = (i % 2 == 0) ? o1 : o2
+ o.m; o.m; o.m; o.m; o.m; o.m; o.m; o.m
+ i+=1
+end
View
20 benchmark/bm_vm2_poly_method_ov.rb
@@ -0,0 +1,20 @@
+class C1
+ def m
+ 1
+ end
+end
+class C2
+ def m
+ 2
+ end
+end
+
+o1 = C1.new
+o2 = C2.new
+
+i=0
+while i<6000000 # benchmark loop 2
+ o = (i % 2 == 0) ? o1 : o2
+# o.m; o.m; o.m; o.m; o.m; o.m; o.m; o.m
+ i+=1
+end
View
14 benchmark/bm_vm2_proc.rb
@@ -0,0 +1,14 @@
+def m &b
+ b
+end
+
+pr = m{
+ a = 1
+}
+
+i=0
+while i<6000000 # benchmark loop 2
+ i+=1
+ pr.call
+end
+
View
6 benchmark/bm_vm2_regexp.rb
@@ -0,0 +1,6 @@
+i=0
+str = 'xxxhogexxx'
+while i<6000000 # benchmark loop 2
+ /hoge/ =~ str
+ i+=1
+end
View
12 benchmark/bm_vm2_send.rb
@@ -0,0 +1,12 @@
+class C
+ def m
+ end
+end
+
+o = C.new
+
+i=0
+while i<6000000 # benchmark loop 2
+ i+=1
+ o.__send__ :m
+end
View
20 benchmark/bm_vm2_super.rb
@@ -0,0 +1,20 @@
+
+class C
+ def m
+ 1
+ end
+end
+
+class CC < C
+ def m
+ super()
+ end
+end
+
+obj = CC.new
+
+i = 0
+while i<6000000 # benchmark loop 2
+ obj.m
+ i+=1
+end
View
8 benchmark/bm_vm2_unif1.rb
@@ -0,0 +1,8 @@
+i = 0
+def m a, b
+end
+
+while i<6000000 # benchmark loop 2
+ i+=1
+ m 100, 200
+end
View
20 benchmark/bm_vm2_zsuper.rb
@@ -0,0 +1,20 @@
+i = 0
+
+class C
+ def m a
+ 1
+ end
+end
+
+class CC < C
+ def m a
+ super
+ end
+end
+
+obj = CC.new
+
+while i<6000000 # benchmark loop 2
+ obj.m 10
+ i+=1
+end
View
6 benchmark/bm_vm3_thread_create_join.rb
@@ -0,0 +1,6 @@
+i=0
+while i<1000 # benchmark loop 3
+ i+=1
+ Thread.new{
+ }.join
+end
View
57 benchmark/bmx_temp.rb
@@ -0,0 +1,57 @@
+
+i=0
+while i<20000000
+ x = 1 # "foo"
+ i+=1
+end
+
+__END__
+
+class Range
+ def each
+ f = self.first
+ l = self.last
+ while f < l
+ yield
+ f = f.succ
+ end
+ end
+end
+
+(0..10000000).each{
+}
+
+__END__
+class Fixnum_
+ def times
+ i = 0
+ while i<self
+ yield(i)
+ i+=1
+ end
+ end
+end
+
+10000000.times{
+}
+__END__
+
+ths = (1..10).map{
+ Thread.new{
+ 1000000.times{
+ }
+ }
+}
+ths.each{|e|
+ e.join
+}
+
+__END__
+$pr = proc{}
+def m
+ $pr.call
+end
+
+1000000.times{|e|
+ m
+}
View
11 benchmark/other-lang/ack.pl
@@ -0,0 +1,11 @@
+use integer;
+
+sub Ack {
+ return $_[0] ? ($_[1] ? Ack($_[0]-1, Ack($_[0], $_[1]-1))
+ : Ack($_[0]-1, 1))
+ : $_[1]+1;
+}
+
+my $NUM = 9;
+$NUM = 1 if ($NUM < 1);
+my $ack = Ack(3, $NUM);
View
16 benchmark/other-lang/ack.py
@@ -0,0 +1,16 @@
+import sys
+sys.setrecursionlimit(5000000)
+
+def Ack(M, N):
+ if (not M):
+ return( N + 1 )
+ if (not N):
+ return( Ack(M-1, 1) )
+ return( Ack(M-1, Ack(M, N-1)) )
+
+def main():
+ NUM = 9
+ sys.setrecursionlimit(10000)
+ Ack(3, NUM)
+
+main()
View
12 benchmark/other-lang/ack.rb
@@ -0,0 +1,12 @@
+def ack(m, n)
+ if m == 0 then
+ n + 1
+ elsif n == 0 then
+ ack(m - 1, 1)
+ else
+ ack(m - 1, ack(m, n - 1))
+ end
+end
+
+NUM = 9
+ack(3, NUM)
View
7 benchmark/other-lang/ack.scm
@@ -0,0 +1,7 @@
+(define (ack m n)
+ (cond ((zero? m) (+ n 1))
+ ((zero? n) (ack (- m 1) 1))
+ (else (ack (- m 1) (ack m (- n 1))))))
+
+(ack 3 9)
+
View
66 benchmark/other-lang/eval.rb
@@ -0,0 +1,66 @@
+
+Bench = %w(
+ loop
+ ack
+ fib
+ tak
+ fact
+)
+
+Lang = <<EOP.map{|l| l.strip}
+ ruby-cyg
+ ../../../test6/miniruby
+ perl
+ python
+ gosh
+EOP
+
+Bench.replace ['loop2']
+Lang.replace ['ruby-cyg']
+
+Ext = %w(
+ .rb
+ .rb
+ .pl
+ .py
+ .scm
+)
+
+p Bench
+p Lang
+
+require 'benchmark'
+
+def bench cmd
+ m = Benchmark.measure{
+ #p cmd
+ system(cmd)
+ }
+ [m.utime, m.real]
+end
+
+Result = []
+Bench.each{|b|
+ r = []
+ Lang.each_with_index{|l, idx|
+ cmd = "#{l} #{b}#{Ext[idx]}"
+ r << bench(cmd)
+ }
+ Result << r
+}
+
+require 'pp'
+# utime
+puts Lang.join("\t")
+Bench.each_with_index{|b, bi|
+ print b, "\t"
+ puts Result[bi].map{|e| e[0]}.join("\t")
+}
+
+# rtime
+puts Lang.join("\t")
+Bench.each_with_index{|b, bi|
+ print b, "\t"
+ puts Result[bi].map{|e| e[1]}.join("\t")
+}
+
View
13 benchmark/other-lang/fact.pl
@@ -0,0 +1,13 @@
+sub fact{
+ my $n = @_[0];
+ if($n < 2){
+ return 1;
+ }
+ else{
+ return $n * fact($n-1);
+ }
+}
+
+for($i=0; $i<10000; $i++){
+ &fact(100);
+}
View
18 benchmark/other-lang/fact.py
@@ -0,0 +1,18 @@
+#import sys
+#sys.setrecursionlimit(1000)
+
+def factL(n):
+ r = 1
+ for x in range(2, n):
+ r *= x
+ return r
+
+def factR(n):
+ if n < 2:
+ return 1
+ else:
+ return n * factR(n-1)
+
+for i in range(10000):
+ factR(100)
+
View
13 benchmark/other-lang/fact.rb
@@ -0,0 +1,13 @@
+def fact(n)
+ if n < 2
+ 1
+ else
+ n * fact(n-1)
+ end
+end
+
+i=0
+while i<10000
+ i+=1
+ fact(100)
+end
View
8 benchmark/other-lang/fact.scm
@@ -0,0 +1,8 @@
+(define (fact n)
+ (if (< n 2)
+ 1
+ (* n (fact (- n 1)))))
+
+(dotimes (i 10000)
+ (fact 100))
+
View
11 benchmark/other-lang/fib.pl
@@ -0,0 +1,11 @@
+sub fib{
+ my $n = $_[0];
+ if($n < 3){
+ return 1;
+ }
+ else{
+ return fib($n-1) + fib($n-2);
+ }
+};
+
+&fib(34);
View
7 benchmark/other-lang/fib.py
@@ -0,0 +1,7 @@
+def fib(n):
+ if n < 3:
+ return 1
+ else:
+ return fib(n-1) + fib(n-2)
+
+fib(34)
View
9 benchmark/other-lang/fib.rb
@@ -0,0 +1,9 @@
+def fib n
+ if n < 3
+ 1
+ else
+ fib(n-1) + fib(n-2)
+ end
+end
+
+fib(34)
View
7 benchmark/other-lang/fib.scm
@@ -0,0 +1,7 @@
+(define (fib n)
+ (if (< n 3)
+ 1
+ (+ (fib (- n 1)) (fib (- n 2)))))
+
+(fib 34)
+
View
3 benchmark/other-lang/loop.pl
@@ -0,0 +1,3 @@
+for($i=0; $i<30000000; $i++){
+}
+
View
2 benchmark/other-lang/loop.py
@@ -0,0 +1,2 @@
+for i in xrange(30000000):
+ pass
View
4 benchmark/other-lang/loop.rb
@@ -0,0 +1,4 @@
+i=0
+while i<30000000
+ i+=1
+end
View
1 benchmark/other-lang/loop.scm
@@ -0,0 +1 @@
+(dotimes (x 30000000))
View
1 benchmark/other-lang/loop2.rb
@@ -0,0 +1 @@
+30000000.times{}
View
11 benchmark/other-lang/tak.pl
@@ -0,0 +1,11 @@
+sub tak {
+ local($x, $y, $z) = @_;
+ if (!($y < $x)) {
+ return $z;
+ } else {
+ return &tak(&tak($x - 1, $y, $z),
+ &tak($y - 1, $z, $x),
+ &tak($z - 1, $x, $y));
+ }
+}
+&tak(18, 9, 0);
View
8 benchmark/other-lang/tak.py
@@ -0,0 +1,8 @@
+def tak(x, y, z):
+ if not(y<x):
+ return z
+ else:
+ return tak(tak(x-1, y, z),
+ tak(y-1, z, x),
+ tak(z-1, x, y))
+tak(18, 9, 0)
View
13 benchmark/other-lang/tak.rb
@@ -0,0 +1,13 @@
+
+def tak x, y, z
+ unless y < x
+ z
+ else
+ tak( tak(x-1, y, z),
+ tak(y-1, z, x),
+ tak(z-1, x, y))
+ end
+end
+
+tak(18, 9, 0)
+
View
10 benchmark/other-lang/tak.scm
@@ -0,0 +1,10 @@
+(define (tak x y z)
+ (if (not (< y x))
+ z
+ (tak (tak (- x 1) y z)
+ (tak (- y 1) z x)
+ (tak (- z 1) x y))))
+
+(tak 18 9 0)
+
+
View
81 benchmark/report.rb
@@ -0,0 +1,81 @@
+#
+# YARV benchmark driver
+#
+
+require 'yarvutil'
+require 'benchmark'
+require 'rbconfig'
+
+def exec_command type, file, w
+ <<-EOP
+ $DRIVER_PATH = '#{File.dirname($0)}'
+ $LOAD_PATH.replace $LOAD_PATH | #{$LOAD_PATH.inspect}
+ require 'benchmark'
+ require 'yarvutil'
+# print '#{type}'
+ begin
+ puts Benchmark.measure{
+ #{w}('#{file}')
+ }.utime
+ rescue Exception => exec_command_error_variable
+ puts "\t" + exec_command_error_variable.message
+ end
+ EOP
+end
+
+def benchmark cmd
+ rubybin = ENV['RUBY'] || File.join(
+ Config::CONFIG["bindir"],
+ Config::CONFIG["ruby_install_name"] + Config::CONFIG["EXEEXT"])
+
+ IO.popen(rubybin, 'r+'){|io|
+ io.write cmd
+ io.close_write
+ return io.gets
+ }
+end
+
+def ruby_exec file
+ prog = exec_command 'ruby', file, 'load'
+ benchmark prog
+end
+
+def yarv_exec file
+ prog = exec_command 'yarv', file, 'YARVUtil.load_bm'
+ benchmark prog
+end
+
+$wr = $wy = nil
+
+def measure bench
+ file = File.dirname($0) + "/bm_#{bench}.rb"
+ r = ruby_exec(file).to_f
+ y = yarv_exec(file).to_f
+ puts "#{bench}\t#{r}\t#{y}"
+end
+
+def measure2
+ r = ruby_exec.to_f
+ y = yarv_exec.to_f
+ puts r/y
+end
+
+if $0 == __FILE__
+ %w{
+ whileloop
+ whileloop2
+ times
+ const
+ method
+ poly_method
+ block
+ rescue
+ rescue2
+ }.each{|bench|
+ measure bench
+ }
+end
+
+
+
+
View
137 benchmark/run.rb
@@ -0,0 +1,137 @@
+#
+# YARV benchmark driver
+#
+
+require 'yarvutil'
+require 'benchmark'
+require 'rbconfig'
+
+$yarvonly = false
+$rubyonly = false
+
+$results = []
+
+puts "ruby #{RUBY_VERSION} #{RUBY_PLATFORM}(#{RUBY_RELEASE_DATE})"
+puts YARVCore::VERSION + " rev: #{YARVCore::REV} (#{YARVCore::DATE})"
+puts YARVCore::OPTS
+puts
+
+def bm file
+ prog = File.read(file).map{|e| e.rstrip}.join("\n")
+ return if prog.empty?
+
+ /[a-z]+_(.+)\.rb/ =~ file
+ bm_name = $1
+ puts '-----------------------------------------------------------' unless $yarvonly || $rubyonly
+ puts "#{bm_name}: "
+
+
+puts <<EOS unless $yarvonly || $rubyonly
+#{prog}
+--
+EOS
+ #iseq = YARVUtil.parse(File.read(file))
+ #vm = YARVCore::VM.new
+ begin
+ Benchmark.bm{|x|
+ # x.report("yarv"){ YARVUtil.load_bm(file) }
+ } unless $yarvonly || $rubyonly
+
+ result = [bm_name]
+ result << ruby_exec(file) unless $yarvonly
+ result << yarv_exec(file) unless $rubyonly
+ $results << result
+
+ # puts YARVUtil.parse(File.read(file), file, 1).disasm
+
+ # x.report("ruby"){ load(file, false) }
+ # x.report("yarv"){ vm.eval iseq }
+ rescue Exception => e
+ puts
+ puts "** benchmark failure: #{e}"
+ puts e.backtrace
+ end
+end
+
+def exec_command type, file, w
+ <<-EOP
+ $DRIVER_PATH = '#{File.dirname($0)}'
+ $LOAD_PATH.replace $LOAD_PATH | #{$LOAD_PATH.inspect}
+ require 'benchmark'
+ require 'yarvutil'
+ print '#{type}'
+ begin
+ puts Benchmark.measure{
+ #{w}('#{file}')
+ }
+ rescue Exception => exec_command_error_variable
+ puts "\t" + exec_command_error_variable.message
+ end
+ EOP
+end
+
+def benchmark prog
+ rubybin = ENV['RUBY'] || File.join(
+ Config::CONFIG["bindir"],
+ Config::CONFIG["ruby_install_name"] + Config::CONFIG["EXEEXT"])
+
+ #
+ tmpfile = Tempfile.new('yarvbench')
+ tmpfile.write(prog)
+ tmpfile.close
+
+ cmd = "#{rubybin} #{tmpfile.path}"
+ result = `#{cmd}`
+ puts result
+ tmpfile.close(true)
+ result
+end
+
+def ruby_exec file
+ prog = exec_command 'ruby', file, 'load'
+ benchmark prog
+end
+
+def yarv_exec file
+ prog = exec_command 'yarv', file, 'YARVUtil.load_bm'
+ benchmark prog
+end
+
+if $0 == __FILE__
+ ARGV.each{|arg|
+ if /\A(--yarv)|(-y)/ =~ arg
+ $yarvonly = true
+ elsif /\A(--ruby)|(-r)/ =~ arg
+ $rubyonly = true
+ end
+ }
+ ARGV.delete_if{|arg|
+ /\A-/ =~ arg
+ }
+
+ if ARGV.empty?
+ Dir.glob(File.dirname(__FILE__) + '/bm_*.rb').sort.each{|file|
+ bm file
+ }
+ else
+ ARGV.each{|file|
+ Dir.glob(File.join(File.dirname(__FILE__), file + '*')){|ef|
+ # file = "#{File.dirname(__FILE__)}/#{file}.rb"
+ bm ef
+ }
+ }
+ end
+
+ puts
+ puts "-- benchmark summary ---------------------------"
+ $results.each{|res|
+ print res.shift, "\t"
+ (res||[]).each{|result|
+ /([\d\.]+)/ =~ result
+ print $1 + "\t" if $1
+ }
+ puts
+ }
+end
+
+
View
129 benchmark/run_rite.rb
@@ -0,0 +1,129 @@
+#
+# YARV benchmark driver
+#
+
+require 'benchmark'
+require 'rbconfig'
+
+$yarvonly = false
+$rubyonly = false
+
+$results = []
+
+# prepare 'wc.input'
+def prepare_wc_input
+ wcinput = File.join(File.dirname($0), 'wc.input')
+ wcbase = File.join(File.dirname($0), 'wc.input.base')
+ unless FileTest.exist?(wcinput)
+ data = File.read(wcbase)
+ 13.times{
+ data << data
+ }
+ open(wcinput, 'w'){|f| f.write data}
+ end
+end
+
+prepare_wc_input
+
+def bm file
+ prog = File.read(file).map{|e| e.rstrip}.join("\n")
+ return if prog.empty?
+
+ /[a-z]+_(.+)\.rb/ =~ file
+ bm_name = $1
+ puts '-----------------------------------------------------------' unless $yarvonly || $rubyonly
+ puts "#{bm_name}: "
+
+
+puts <<EOS unless $yarvonly || $rubyonly
+#{prog}
+--
+EOS
+ #iseq = YARVUtil.parse(File.read(file))
+ #vm = YARVCore::VM.new
+ begin
+ result = [bm_name]
+ result << ruby_exec(file) unless $yarvonly
+ result << yarv_exec(file) unless $rubyonly
+ $results << result
+
+ # puts YARVUtil.parse(File.read(file), file, 1).disasm
+
+ # x.report("ruby"){ load(file, false) }
+ # x.report("yarv"){ vm.eval iseq }
+ rescue Exception => e
+ puts
+ puts "** benchmark failure: #{e}"
+ puts e.backtrace
+ end
+end
+
+def benchmark file, bin
+ m = Benchmark.measure{
+ `#{bin} #{$opts} #{file}`
+ }
+ sec = '%.3f' % m.real
+ puts " #{sec}"
+ sec
+end
+
+def ruby_exec file
+ print 'ruby'
+ benchmark file, $ruby_program
+end
+
+def yarv_exec file
+ print 'yarv'
+ benchmark file, $yarv_program
+end
+
+if $0 == __FILE__
+ ARGV.each{|arg|
+ case arg
+ when /\A--yarv-program=(.+)/
+ $yarv_program = $1
+ when /\A--ruby-program=(.+)/
+ $ruby_program = $1
+ when /\A--opts=(.+)/
+ $opts = $1
+ when /\A(--yarv)|(-y)/
+ $yarvonly = true
+ when /\A(--ruby)|(-r)/
+ $rubyonly = true
+ end
+ }
+ ARGV.delete_if{|arg|
+ /\A-/ =~ arg
+ }
+
+ puts "Ruby:"
+ system("#{$ruby_program} -v")
+ puts
+ puts "YARV:"
+ system("#{$yarv_program} -v")
+
+ if ARGV.empty?
+ Dir.glob(File.dirname(__FILE__) + '/bm_*.rb').sort.each{|file|
+ bm file
+ }
+ else
+ ARGV.each{|file|
+ Dir.glob(File.join(File.dirname(__FILE__), file + '*')){|ef|
+ # file = "#{File.dirname(__FILE__)}/#{file}.rb"
+ bm ef
+ }
+ }
+ end
+
+ puts
+ puts "-- benchmark summary ---------------------------"
+ $results.each{|res|
+ print res.shift, "\t"
+ (res||[]).each{|result|
+ /([\d\.]+)/ =~ result
+ print $1 + "\t" if $1
+ }
+ puts
+ }
+end
+
View
29 benchmark/runc.rb
@@ -0,0 +1,29 @@
+#
+#
+#
+
+require 'benchmark'
+require 'rbconfig'
+
+$rubybin = ENV['RUBY'] || File.join(
+ Config::CONFIG["bindir"],
+ Config::CONFIG["ruby_install_name"] + Config::CONFIG["EXEEXT"])
+
+def runfile file
+ puts file
+ file = File.join(File.dirname($0), 'contrib', file)
+ Benchmark.bm{|x|
+ x.report('ruby'){
+ system("#{$rubybin} #{file}")
+ }
+ x.report('yarv'){
+ system("#{$rubybin} -rite -I.. #{file}")
+ }
+ }
+end
+
+ARGV.each{|file|
+ runfile file
+}
+
+
View
25 benchmark/wc.input.base
@@ -0,0 +1,25 @@
+Subject: Re: Who was Izchak Miller?
+From: "Jane D. Anonymous" <nobody@yale.edu>
+Date: 1996/04/28
+Message-Id: <4lv7bc$oh@news.ycc.yale.edu>
+References: <317C405E.5DFA@panix.com> <4lk6vl$gde@ns.oar.net>
+To: 75176.2330@compuserve.com
+Content-Type: text/plain; charset=us-ascii
+Organization: Yale University
+X-Url: news:4lk6vl$gde@ns.oar.net
+Mime-Version: 1.0
+Newsgroups: rec.games.roguelike.nethack
+X-Mailer: Mozilla 1.1N (Macintosh; I; 68K)
+
+Hello there, Izchak Miller was my father. When I was younger I spent
+many a night, hunched over the keyboard with a cup of tea, playing
+nethack with him and my brother. my dad was a philosopher with a strong
+weakness for fantasy/sci fi. I remember when he started to get involved
+with the Nethack team- my brother's Dungeons and Dragons monster book
+found a regular place beside my dad's desk. it's nice to see him living
+on in the game he loved so much :-).
+ Tamar Miller
+
+The following is a really long word of 5000 characters:
+
+wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww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wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww
View
461 blockinlining.c
@@ -0,0 +1,461 @@
+/**********************************************************************
+
+ blockinlining.c -
+
+ $Author$
+ $Date$
+
+ Copyright (C) 2004-2006 Koichi Sasada
+
+**********************************************************************/
+
+#include "ruby.h"
+#include "node.h"
+#include "yarvcore.h"
+
+VALUE yarv_new_iseqval(VALUE node, VALUE name, VALUE file,
+ VALUE parent, VALUE type, VALUE block_opt, VALUE opt);
+
+static VALUE
+yarv_iseq_special_block(yarv_iseq_t *iseq, void *builder)
+{
+#if OPT_BLOCKINLINING
+ VALUE parent = Qfalse;
+ VALUE iseqval;
+
+ if (iseq->argc > 1 || iseq->arg_simple == 0) {
+ /* argument check */
+ return 0;
+ }
+
+ if (iseq->cached_special_block_builder) {
+ if (iseq->cached_special_block_builder == builder) {