tagged release 0.6.4
[parrot.git] / languages / cardinal / src / classes / Integer.pir
blob3212dc5912e895f3cb4f324fdb52e849c3c7d847
1 ## $Id$
3 =head1 TITLE
5 CardinalInteger - Cardinal integers
7 =cut
9 .namespace [ 'CardinalInteger' ]
12 =head1 SUBROUTINES
14 =over 4
16 =item onload
18 =cut
20 .sub 'onload' :anon :init :load
21     .local pmc cardinalmeta, intproto
22     cardinalmeta = get_hll_global ['CardinalObject'], '!CARDINALMETA'
23     intproto = cardinalmeta.'new_class'('CardinalInteger', 'parent'=>'Integer CardinalObject')
24     cardinalmeta.'register'('Float', 'parent'=>'CardinalObject', 'protoobject'=>intproto)
25 .end
28 =item ACCEPTS()
30 =cut
32 .sub 'ACCEPTS' :method
33     .param num topic
34     .return 'infix:=='(topic, self)
35 .end
38 =item perl()
40 Returns a Perl representation of the CardinalInteger.
42 =cut
44 .sub 'perl' :method
45     $S0 = self
46     .return($S0)
47 .end
50 =item to_s()
52 Returns a CardinalString representation of the CardinalInteger.
54 =cut
56 .sub 'to_s' :method
57     $P0 = new 'CardinalString'
58     $P0 = self
59     .return($P0)
60 .end
63 =item downto(n, block)
65 Runs C<block> for each integer from the current value of the Integer down to n.
67 =cut
69 .sub 'downto' :method
70     .param int n
71     .param pmc block
72     $I1 = self
73   downto_loop:
74     $I0 = $I1 < n
75     if $I0, downto_done
76     block($I1)
77     dec $I1
78     goto downto_loop
79   downto_done:
80 .end
83 =item upto(n, block)
85 Runs C<block> for each integer from the current value of the Integer up to n.
87 =cut
89 .sub 'upto' :method
90     .param int n
91     .param pmc block
92     $I1 = self
93   upto_loop:
94     $I0 = $I1 > n
95     if $I0, upto_done
96     block($I1)
97     inc $I1
98     goto upto_loop
99   upto_done:
100 .end
103 =back
105 =cut
107 # Local Variables:
108 #   mode: pir
109 #   fill-column: 100
110 # End:
111 # vim: expandtab shiftwidth=4 ft=pir: