-
Notifications
You must be signed in to change notification settings - Fork 2
/
oofib.pir
112 lines (91 loc) · 1.52 KB
/
oofib.pir
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# Copyright (C) 2004-2009, Parrot Foundation.
.sub bench :main
.param pmc argv
.local int argc
argc = argv
.local pmc N
N = new 'Integer'
if argc <= 1 goto noarg
$S0 = argv[1]
N = $S0
goto begin
noarg:
N = 24
begin:
.local num start
time start
.local pmc A
.local pmc B
.local pmc b
A = newclass "A"
B = subclass A, "B"
b = new "B"
.local pmc r
r = b."fib"(N)
.local num fin
time fin
print "fib("
print N
print ") = "
print r
print " "
sub fin, start
print fin
print "s\n"
end
.end
.namespace ["A"]
.sub fib :method
.param int n
if n >= 2 goto rec
.return (n)
rec:
.local int prev
.local int r1
prev = n
dec prev
r1 = self."fibA"(prev)
dec prev
.local int r2
r2 = self."fibB"(prev)
n = r1 + r2
.return (n)
.end
.sub fibA :method
.param int n
if n >= 2 goto rec
.return (n)
rec:
.local int prev
prev = n
dec prev
.local int r1
r1 = self."fib"(prev)
dec prev
.local int r2
r2 = self."fibB"(prev)
n = r1 + r2
.return (n)
.end
.namespace ["B"]
.sub fibB :method
.param int n
if n >= 2 goto rec
.return (n)
rec:
.local int prev
prev = n
dec prev
.local int r1
r1 = self."fib"(prev)
dec prev
.local int r2
r2 = self."fibA"(prev)
n = r1 + r2
.return (n)
.end
# Local Variables:
# mode: pir
# fill-column: 100
# End:
# vim: expandtab shiftwidth=4 ft=pir: