/
Associative.pir
85 lines (63 loc) · 1.7 KB
/
Associative.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
## $Id$
=head1 NAME
src/classes/Associative.pir - Associative Role
=head1 DESCRIPTION
=cut
.namespace ['Associative[::T]']
.sub '' :load :init
# Create a parametric role with 1 possible candidate.
.local pmc role
.const 'Sub' $P0 = '_Associative_role_body'
role = new ['Perl6Role']
role.'!add_variant'($P0)
set_hll_global 'Associative', role
.end
# This defines the body of the role, which is run per type the role is
# parameterized with.
.sub '' :anon :subid('_Associative_role_body')
.param pmc type :optional
# Need to capture the methods that belong in this role.
.const 'Sub' $P1 = 'Associative::of'
capture_lex $P1
# Capture type.
if null type goto no_type
type = type.'WHAT'()
goto type_done
no_type:
type = get_hll_global 'Mu'
type_done:
.lex 'T', type
# Create role.
.tailcall '!create_parametric_role'("Associative[::T]")
.end
.sub '' :load :init
.local pmc block, signature
.const 'Sub' $P0 = '_Associative_role_body'
block = $P0
signature = allocate_signature 1
setprop block, "$!signature", signature
null $P1
set_signature_elem signature, 0, "T", SIG_ELEM_IS_OPTIONAL, $P1, $P1, $P1, $P1, $P1, $P1
.end
=head2 Methods
=over
=item of
Returns the type constraining what may be stored.
=cut
.sub 'of' :method :outer('_Associative_role_body') :subid('Associative::of')
$P0 = find_lex 'T'
.return ($P0)
.end
.sub '' :load :init
.local pmc block, signature
.const 'Sub' block = 'Associative::of'
signature = allocate_signature 0
setprop block, "$!signature", signature
.end
=back
=cut
# Local Variables:
# mode: pir
# fill-column: 100
# End:
# vim: expandtab shiftwidth=4 ft=pir: