-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfib.pir
65 lines (45 loc) · 871 Bytes
/
fib.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
# Copyright (C) 2001-2008, Parrot Foundation.
=head1 NAME
examples/benchmarks/fib.pir - Fibonacci Benchmark
=head1 SYNOPSIS
% time ./parrot examples/benchmarks/fib.pir n
=head1 DESCRIPTION
Calculates the Fibonacci Number for C<n> (defaults to 28 if
unspecified).
=cut
.sub main :main
.param pmc argv
.local int argc
argc = argv
.local int N
N = 28
if argc <= 1 goto noarg
N = argv[1]
noarg:
.local int r
r = fib(N)
print "fib("
print N
print ") = "
say r
.end
.sub fib
.param int n
if n < 2 goto ret
.local int n1, n2, r1, r2
n1 = n - 1
n2 = n - 2
r1 = fib(n1)
r2 = fib(n2)
n = r1 + r2
ret:
.return (n)
.end
=head1 SEE ALSO
F<examples/benchmarks/fib.pl>.
=cut
# Local Variables:
# mode: pir
# fill-column: 100
# End:
# vim: expandtab shiftwidth=4 ft=pir: