summaryrefslogtreecommitdiff
path: root/sample/gctest.rb
blob: 6810b95481bec2072492babfe02b296b503f3535 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# GC stress test
def cons(car, cdr)
   [car, cdr]
end

def car(x)
   if x == nil ; nil else x[0] end
end

def cdr(x)
   if x == nil ; nil else x[1] end
end

def reverse1(x, y)
  if x == nil ; y else reverse1(cdr(x), cons(car(x), y)) end
end

def reverse(x)
  reverse1(x, nil)
end

def ints(low, up)
  if low > up
     nil
  else
     cons(low, ints(low+1, up))
  end
end

def print_int_list(x)
  if x == nil
    print("NIL\n")
  else
    print(car(x))
    if nil != cdr(x)
      print(", ")
      print_int_list(cdr(x))
    else
      print("\n")
    end
  end
end

print("start\n")

a = ints(1, 100)
print_int_list(a)
b = ints(1, 50)
print_int_list(b)
print_int_list(reverse(a))
print_int_list(reverse(b))
for i in 1 .. 100
  b = reverse(reverse(b))
#  print(i, ": ")
#  print_int_list(b)
end
print("a: ")
print_int_list(a)
print("b: ")
print_int_list(b)
print("reverse(a): ")
print_int_list(reverse(a))
print("reverse(b): ")
print_int_list(reverse(b))
a = b = nil
print("finish\n")
GC.start()