/
Num.pir
117 lines (80 loc) · 1.72 KB
/
Num.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
113
114
115
116
117
## $Id$
=head1 TITLE
Num - Perl 6 numbers
=head1 SUBROUTINES
=over 4
=item onload()
=cut
.namespace [ 'Num' ]
.sub 'onload' :anon :init :load
.local pmc p6meta, numproto
p6meta = get_hll_global ['Perl6Object'], '$!P6META'
numproto = p6meta.'new_class'('Num', 'parent'=>'parrot;Float Any')
numproto.'!IMMUTABLE'()
p6meta.'register'('Float', 'parent'=>numproto, 'protoobject'=>numproto)
# Override the proto's ACCEPT method so we also accept Ints.
.const 'Sub' $P0 = "Num::ACCEPTS"
$P1 = typeof numproto
$P1.'add_method'('ACCEPTS', $P0)
.end
.sub 'Num::ACCEPTS' :anon :method
.param pmc topic
## first, try our superclass .ACCEPTS
$P0 = get_hll_global 'Any'
$P1 = find_method $P0, 'ACCEPTS'
$I0 = self.$P1(topic)
unless $I0 goto try_int
.return ($I0)
try_int:
$P0 = get_hll_global 'Int'
$I0 = $P0.'ACCEPTS'(topic)
.return ($I0)
.end
=item ACCEPTS()
=cut
.sub 'ACCEPTS' :method
.param num topic
$S0 = self
if $S0 == 'NaN' goto test_nan
.tailcall 'infix:=='(topic, self)
test_nan:
$S0 = topic
$I0 = iseq $S0, 'NaN'
.tailcall 'prefix:?'($I0)
.end
=item succ and pred
Increment and Decrement Methods
=cut
.sub 'pred' :method
$N0 = self
dec $N0
.return ($N0)
.end
.sub 'succ' :method
$N0 = self
inc $N0
.return ($N0)
.end
=item WHICH()
Returns the identify value.
=cut
.sub 'WHICH' :method
$N0 = self
.return ($N0)
.end
=item infix:===
Overridden for Num.
=cut
.namespace []
.sub 'infix:===' :multi(Float,Float)
.param num a
.param num b
.tailcall 'infix:=='(a, b)
.end
=back
=cut
# Local Variables:
# mode: pir
# fill-column: 100
# End:
# vim: expandtab shiftwidth=4 ft=pir: