Skip to content

Commit

Permalink
Allow for :api<something>
Browse files Browse the repository at this point in the history
In all of the places where :auth was allowed (such as module / class /
role), one can now also specify :api.  Primary use is to allow for
introspection and ability to feed this into the Perl 6 toolchain.
  • Loading branch information
lizmat committed May 30, 2018
1 parent 9472fdf commit affc218
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/Perl6/Metamodel/ClassHOW.nqp
Expand Up @@ -40,13 +40,14 @@ class Perl6::Metamodel::ClassHOW
}

my $anon_id := 1;
method new_type(:$name, :$repr = 'P6opaque', :$ver, :$auth) {
method new_type(:$name, :$repr = 'P6opaque', :$ver, :$auth, :$api) {
my $metaclass := self.new();
my $obj := nqp::settypehll(nqp::newtype($metaclass, $repr), 'perl6');
$metaclass.set_name($obj, $name // "<anon|{$anon_id++}>");
self.add_stash($obj);
$metaclass.set_ver($obj, $ver) if $ver;
$metaclass.set_auth($obj, $auth) if $auth;
$metaclass.set_api($obj, $api) if $api;
$metaclass.setup_mixin_cache($obj);
nqp::setboolspec($obj, 5, nqp::null());
$obj
Expand Down
3 changes: 2 additions & 1 deletion src/Perl6/Metamodel/ConcreteRoleHOW.nqp
Expand Up @@ -42,12 +42,13 @@ class Perl6::Metamodel::ConcreteRoleHOW
method multi() { $!multi }
}

method new_type(:@roles, :$name = '<anon>', :$ver, :$auth, :$repr) {
method new_type(:@roles, :$name = '<anon>', :$ver, :$auth, :$repr, :$api) {
my $metarole := self.new(:roles(@roles));
my $obj := nqp::settypehll(nqp::newtype($metarole, 'Uninstantiable'), 'perl6');
$metarole.set_name($obj, $name);
$metarole.set_ver($obj, $ver) if $ver;
$metarole.set_auth($obj, $auth) if $auth;
$metarole.set_api($obj, $api) if $api;
$obj;
}

Expand Down
3 changes: 2 additions & 1 deletion src/Perl6/Metamodel/ModuleHOW.nqp
Expand Up @@ -17,13 +17,14 @@ class Perl6::Metamodel::ModuleHOW
nqp::findmethod(NQPMu, 'BUILDALL')(nqp::create(self), |%named)
}

method new_type(:$name = '<anon>', :$repr, :$ver, :$auth) {
method new_type(:$name = '<anon>', :$repr, :$ver, :$auth, :$api) {
if $repr { nqp::die("'module' does not support custom representations") }
my $metaclass := self.new();
my $obj := nqp::settypehll(nqp::newtype($metaclass, 'Uninstantiable'), 'perl6');
$metaclass.set_name($obj, $name);
$metaclass.set_ver($obj, $ver) if $ver;
$metaclass.set_auth($obj, $auth) if $auth;
$metaclass.set_api($obj, $api) if $api;
self.add_stash($obj);
}

Expand Down
3 changes: 2 additions & 1 deletion src/Perl6/Metamodel/NativeHOW.nqp
Expand Up @@ -21,12 +21,13 @@ class Perl6::Metamodel::NativeHOW
nqp::findmethod(NQPMu, 'BUILDALL')(nqp::create(self), |%named)
}

method new_type(:$name = '<anon>', :$repr = 'P6opaque', :$ver, :$auth) {
method new_type(:$name = '<anon>', :$repr = 'P6opaque', :$ver, :$auth, :$api) {
my $metaclass := self.new();
my $obj := nqp::settypehll(nqp::newtype($metaclass, $repr), 'perl6');
$metaclass.set_name($obj, $name);
$metaclass.set_ver($obj, $ver) if $ver;
$metaclass.set_auth($obj, $auth) if $auth;
$metaclass.set_api($obj, $api) if $api;
self.add_stash($obj);
}

Expand Down
3 changes: 2 additions & 1 deletion src/Perl6/Metamodel/NativeRefHOW.nqp
Expand Up @@ -22,12 +22,13 @@ class Perl6::Metamodel::NativeRefHOW
nqp::findmethod(NQPMu, 'BUILDALL')(nqp::create(self), |%named)
}

method new_type(:$name = '<anon>', :$ver, :$auth) {
method new_type(:$name = '<anon>', :$ver, :$auth, :$api) {
my $metaclass := self.new();
my $obj := nqp::settypehll(nqp::newtype($metaclass, 'NativeRef'), 'perl6');
$metaclass.set_name($obj, $name);
$metaclass.set_ver($obj, $ver) if $ver;
$metaclass.set_auth($obj, $auth) if $auth;
$metaclass.set_api($obj, $api) if $api;
self.add_stash($obj);
}

Expand Down
3 changes: 2 additions & 1 deletion src/Perl6/Metamodel/ParametricRoleHOW.nqp
Expand Up @@ -33,12 +33,13 @@ class Perl6::Metamodel::ParametricRoleHOW
}

my $anon_id := 1;
method new_type(:$name, :$ver, :$auth, :$repr, :$signatured, *%extra) {
method new_type(:$name, :$ver, :$auth, :$api, :$repr, :$signatured, *%extra) {
my $metarole := self.new(:signatured($signatured), :specialize_lock(NQPLock.new));
my $type := nqp::settypehll(nqp::newtype($metarole, 'Uninstantiable'), 'perl6');
$metarole.set_name($type, $name // "<anon|{$anon_id++}>");
$metarole.set_ver($type, $ver) if $ver;
$metarole.set_auth($type, $auth) if $auth;
$metarole.set_api($type, $api) if $api;
$metarole.set_pun_repr($type, $repr) if $repr;
if nqp::existskey(%extra, 'group') {
$metarole.set_group($type, %extra<group>);
Expand Down
3 changes: 3 additions & 0 deletions src/Perl6/Metamodel/Versioning.nqp
@@ -1,10 +1,13 @@
role Perl6::Metamodel::Versioning {
has $!ver;
has $!auth;
has $!api;

method ver($obj) { $!ver // nqp::null() }
method auth($obj) { $!auth // '' }
method api($obj) { $!api // '' }

method set_ver($obj, $ver) { $!ver := $ver }
method set_auth($obj, $auth) { $!auth := $auth }
method set_api($obj, $api) { $!api := $api }
}

0 comments on commit affc218

Please sign in to comment.