1
1
use Perl6::BOOTSTRAP;
3
# Stub a few things the compiler wants to have really early on.
5
my class Whatever { ... }
6
my class WhateverCode { ... }
3
8
# Stub these or we can't use any sigil other than $.
4
9
my role Positional { ... }
5
10
my role Associative { ... }
6
11
my role Callable { ... }
8
proto trait_mod:<is>(|$) { * }
14
my class X::Inheritance::Unsupported { ... }
15
my class X::Export::NameClash { ... }
16
my class X::Composition::NotComposable { ... }
17
my class X::Import::MissingSymbols { ... }
18
my class X::Redeclaration { ... }
20
proto trait_mod:<is>(|) { * }
9
21
multi trait_mod:<is>(Mu:U $child, Mu:U $parent) {
10
22
if $parent.HOW.archetypes.inheritable() {
11
23
$child.HOW.add_parent($child, $parent);
14
26
$child.HOW.add_parent($child, $parent.HOW.inheritalize($parent))
17
die $child.HOW.name($child) ~ " cannot inherit from " ~
18
$parent.HOW.name($parent) ~ " because it is not inheritable"
29
X::Inheritance::Unsupported.new(
30
:child-typename($child.HOW.name($child)),
21
35
multi trait_mod:<is>(Mu:U $type, :$rw!) {
22
36
$type.HOW.set_rw($type);
24
multi trait_mod:<is>(Mu:U $type, $size, :$nativesize!) {
25
$type.HOW.set_nativesize($type, $size);
38
multi trait_mod:<is>(Mu:U $type, :$nativesize!) {
39
$type.HOW.set_nativesize($type, $nativesize);
41
multi trait_mod:<is>(Mu:U $type, :$hidden!) {
42
$type.HOW.set_hidden($type);
28
45
multi trait_mod:<is>(Attribute:D $attr, :$rw!) {
41
58
multi trait_mod:<is>(Routine:D $r, :$default!) {
42
59
$r does role { method default() { True } }
44
multi trait_mod:<is>(Routine:D $r, $info, :$inlinable!) {
45
$r.set_inline_info($info);
61
multi trait_mod:<is>(Routine:D $r, :$DEPRECATED!) {
62
# we'll add logic here later
64
multi trait_mod:<is>(Routine:D $r, Mu :$inlinable!) {
65
$r.set_inline_info(nqp::p6decont($inlinable));
67
multi trait_mod:<is>(Routine:D $r, :$onlystar!) {
71
# Since trait_mod:<is> to set onlystar isn't there at the
72
# point we wrote its proto, we do it manually here.
73
BEGIN &trait_mod:<is>.set_onlystar();
48
75
multi trait_mod:<is>(Parameter:D $param, :$readonly!) {
49
76
# This is the default.
64
91
# TODO: Make this much less cheaty. That'll probably need the
65
92
# full-blown serialization, though.
66
sub EXPORT_SYMBOL(\$exp_name, @tags, Mu \$sym) {
69
if $*EXPORT.WHO.exists($tag) {
70
$install_in := $*EXPORT.WHO.{$tag};
73
$install_in := $*W.pkg_create_mo($/, (package { }).HOW, :name($tag));
74
$*W.pkg_compose($install_in);
75
$*W.install_package_symbol($*EXPORT, $tag, $install_in);
77
if $install_in.WHO.exists($exp_name) {
78
unless ($install_in.WHO){$exp_name} =:= $sym {
79
die "A symbol $exp_name has already been exported";
82
$*W.install_package_symbol($install_in, $exp_name, $sym);
93
sub EXPORT_SYMBOL(\exp_name, @tags, Mu \sym) {
94
my @export_packages = $*EXPORT;
95
for nqp::p6type(@*PACKAGES) {
96
unless .WHO.exists('EXPORT') {
97
.WHO<EXPORT> := Metamodel::PackageHOW.new_type(:name('EXPORT'));
98
.WHO<EXPORT>.^compose;
100
@export_packages.push: .WHO<EXPORT>;
102
for @export_packages -> $p {
105
if $p.WHO.exists($tag) {
106
$install_in := $p.WHO.{$tag};
109
$install_in := $*W.pkg_create_mo($/, (package { }).HOW, :name($tag));
110
$*W.pkg_compose($install_in);
111
$*W.install_package_symbol($p, $tag, $install_in);
113
if $install_in.WHO.exists(exp_name) {
114
unless ($install_in.WHO){exp_name} =:= sym {
115
X::Export::NameClash.new(symbol => exp_name).throw;
118
$*W.install_package_symbol($install_in, exp_name, sym);
85
multi trait_mod:<is>(Routine:D \$r, :$export!) {
86
my $to_export := $r.multi ?? $r.dispatcher !! $r;
87
my $exp_name := '&' ~ $r.name;
88
my @tags = 'ALL', 'DEFAULT';
122
multi trait_mod:<is>(Routine:D \r, :$export!) {
123
my $to_export := r.multi ?? r.dispatcher !! r;
124
my $exp_name := '&' ~ r.name;
125
my @tags = 'ALL', ($export ~~ Pair ?? $export.key() !!
126
$export ~~ Positional ?? @($export)>>.key !!
89
128
EXPORT_SYMBOL($exp_name, @tags, $to_export);
91
multi trait_mod:<is>(Mu:U \$type, :$export!) {
92
my $exp_name := $type.HOW.name($type);
93
my @tags = 'ALL', 'DEFAULT';
94
EXPORT_SYMBOL($exp_name, @tags, $type);
130
multi trait_mod:<is>(Mu:U \type, :$export!) {
131
my $exp_name := type.HOW.name(type);
132
my @tags = 'ALL', ($export ~~ Pair ?? $export.key !!
133
$export ~~ Positional ?? @($export)>>.key !!
135
EXPORT_SYMBOL($exp_name, @tags, type);
138
multi trait_mod:<is>(Mu \sym, :$export!, :$SYMBOL!) {
139
my @tags = 'ALL', ($export ~~ Pair ?? $export.key !!
140
$export ~~ Positional ?? @($export)>>.key !!
142
EXPORT_SYMBOL($SYMBOL, @tags, sym);
97
multi trait_mod:<is>(Mu:D $docee, $doc, :$docs!) {
145
multi trait_mod:<is>(Mu:D $docee, :$docs!) {
98
146
$docee does role {
100
148
method WHY { $!WHY }
101
149
method set_docs($d) { $!WHY = $d }
103
$docee.set_docs($doc);
104
$doc.set_docee($docee);
107
multi trait_mod:<is>(Mu:U $docee, $doc, :$docs!) {
108
$docee.HOW.set_docs($doc);
109
$doc.set_docee($docee);
113
proto trait_mod:<does>(|$) { * }
151
$docee.set_docs($docs);
152
$docs.set_docee($docee);
155
multi trait_mod:<is>(Mu:U $docee, :$docs!) {
156
$docee.HOW.set_docs($docs);
157
$docs.set_docee($docee);
161
proto trait_mod:<does>(|) { * }
114
162
multi trait_mod:<does>(Mu:U $doee, Mu:U $role) {
115
163
if $role.HOW.archetypes.composable() {
116
164
$doee.HOW.add_role($doee, $role)
119
167
$doee.HOW.add_role($doee, $role.HOW.composalize($role))
122
die $doee.HOW.name($doee) ~ " cannot compose " ~
123
$role.HOW.name($role) ~ " because it is not composable"
170
X::Composition::NotComposable.new(
171
target-name => $doee.HOW.name($doee),
127
proto trait_mod:<of>(|$) { * }
177
proto trait_mod:<of>(|) { * }
128
178
multi trait_mod:<of>(Mu:U $target, Mu:U $type) {
129
179
# XXX Ensure we can do this, die if not.
130
180
$target.HOW.set_of($target, $type);
132
182
multi trait_mod:<of>(Routine:D $target, Mu:U $type) {
133
$target.signature.set_returns($type)
183
my $sig := $target.signature;
184
X::Redeclaration.new(what => 'return type for', symbol => $target,
185
postfix => " (previous return type was {$sig.returns.^name})").throw
187
$sig.set_returns($type)
136
190
multi trait_mod:<is>(Routine:D $r, :$hidden_from_backtrace!) {
143
proto trait_mod:<returns>(|$) { * }
197
proto trait_mod:<returns>(|) { * }
144
198
multi trait_mod:<returns>(Routine:D $target, Mu:U $type) {
145
$target.signature.set_returns($type)
199
my $sig := $target.signature;
200
X::Redeclaration.new(what => 'return type for', symbol => $target,
201
postfix => " (previous return type was {$sig.returns.^name})").throw
203
$sig.set_returns($type)
148
proto trait_mod:<as>(|$) { * }
206
proto trait_mod:<as>(|) { * }
149
207
multi trait_mod:<as>(Parameter:D $param, $type) {
150
208
$param.set_coercion($type);
153
211
my class Pair { ... }
154
proto trait_mod:<handles>(|$) { * }
212
proto trait_mod:<handles>(|) { * }
155
213
multi trait_mod:<handles>(Attribute:D $target, $thunk) {
156
214
$target does role {
212
270
$target.set_handles($thunk());
215
proto trait_mod:<will>(|$) { * }
216
multi trait_mod:<will>(Attribute $attr, Block $closure, :$build!) {
217
$attr.set_build($closure)
220
proto trait_mod:<trusts>(|$) { * }
273
multi sub trait_mod:<handles>(Method:D $m, &thunk) {
274
my $pkg := $m.signature.params[0].type;
275
my $call_name := $m.name;
276
for thunk() -> $meth_name {
277
my $meth := method (|c) is rw {
278
self."$call_name"()."$meth_name"(|c);
280
$meth.set_name($meth_name);
281
$pkg.HOW.add_method($pkg, $meth_name, $meth);
285
proto trait_mod:<will>(|) { * }
286
multi trait_mod:<will>(Attribute $attr, Block :$build!) {
287
$attr.set_build($build)
290
proto trait_mod:<trusts>(|) { * }
221
291
multi trait_mod:<trusts>(Mu:U $truster, Mu:U $trustee) {
222
292
$truster.HOW.add_trustee($truster, $trustee);
295
proto trait_mod:<hides>(|) { * }
296
multi trait_mod:<hides>(Mu:U $child, Mu:U $parent) {
297
if $parent.HOW.archetypes.inheritable() {
298
$child.HOW.add_parent($child, $parent, :hides);
300
elsif $parent.HOW.archetypes.inheritalizable() {
301
$child.HOW.add_parent($child, $parent.HOW.inheritalize($parent), :hides)
304
X::Inheritance::Unsupported.new(
305
:child-typename($child.HOW.name($child)),