Permalink
Browse files

added fib stack frame spec to recur

  • Loading branch information...
1 parent 0c8a4ee commit 33caf67e2772f9d41dd75785834b62f0515f0847 @hosiawak committed Jul 3, 2011
Showing with 16 additions and 0 deletions.
  1. +4 −0 lib/rubinius_macros.rb
  2. +12 −0 spec/recur_spec.rb
View
@@ -1,5 +1,7 @@
require 'lib/gensym'
+require 'lib/swap'
require 'lib/symbol_to_proc'
+require 'lib/string_to_proc'
require 'lib/andand'
require 'lib/goto'
require 'lib/recur'
@@ -8,8 +10,10 @@ module Macros
class Processor < Rubinius::Melbourne
include Gensym
+ include Swap
include Andand
include SymbolToProc
+ include StringToProc
include Goto
include Recur
end
View
@@ -9,6 +9,14 @@ def factorial(n, product)
end
end
+ def fib(n, x, y)
+ if n == 0
+ x
+ else
+ recur(n - 1, y, x + y)
+ end
+ end
+
def default_arg_simple(a = 1)
a == 10 ? :ok : recur(a + 1)
end
@@ -50,6 +58,10 @@ def required_and_splat_factorial(n, *ary)
@t.factorial(4,1).should == 24
end
+ it "doesn't blow the stack with too many call frames" do
+ @t.fib(10_000, 0, 1).to_s[0...10].should == "3364476487"
+ end
+
context "optional args" do
it "works with optional args set to literal values" do
@t.default_arg_simple.should == :ok

0 comments on commit 33caf67

Please sign in to comment.