summaryrefslogtreecommitdiff log msg author committer range
path: root/sample/gctest2.rb
blob: 851d14f217750bcbc575db8953c2c5832d717ac0 (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 68 69 70 71 ``` ``````# GC stress test def cons(car, cdr) car::cdr end def car(x) x.car end def cdr(x) x.cdr end def reverse1(x, y) if x == nil then 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 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() ``````