Skip to content
This repository has been archived by the owner on Feb 3, 2021. It is now read-only.

Commit

Permalink
Add NQPNativeHOW meta-object for native types and native package decl…
Browse files Browse the repository at this point in the history
…arator to go with it.
  • Loading branch information
jnthn committed Jan 25, 2011
1 parent 619c67d commit a9206dd
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 1 deletion.
4 changes: 3 additions & 1 deletion build/Makefile.in
Expand Up @@ -163,7 +163,9 @@ METAMODEL_OBJS = ../metamodel/rakudoobject$(O) ../metamodel/repr_registry$(O)
../metamodel/multi_dispatch$(O)

HOW_SOURCES = src/metamodel/how/KnowHOWAttribute.pm src/metamodel/how/NQPClassHOW.pm \
src/metamodel/how/NQPAttribute.pm src/metamodel/how/NQPMu.pm
src/metamodel/how/NQPNativeHOW.pm src/metamodel/how/NQPAttribute.pm \
src/metamodel/how/NQPMu.pm

HOW_COMBINED = src/gen/how.pm


Expand Down
1 change: 1 addition & 0 deletions src/NQP/Actions.pm
Expand Up @@ -374,6 +374,7 @@ method package_declarator:sym<knowhow>($/) { make package($/); }
method package_declarator:sym<class>($/) { make package($/) }
method package_declarator:sym<grammar>($/) { make package($/) }
method package_declarator:sym<role>($/) { make package($/); }
method package_declarator:sym<native>($/) { make package($/); }

sub package($/) {
my @ns := pir::clone__PP($<package_def><name><identifier>);
Expand Down
6 changes: 6 additions & 0 deletions src/NQP/Grammar.pm
Expand Up @@ -14,6 +14,7 @@ method TOP() {
%*HOW<class> := 'NQPClassHOW';
%*HOW<grammar> := 'NQPClassHOW';
%*HOW<role> := 'NQPRoleHOW';
%*HOW<native> := 'NQPNativeHOW';

# What attribute class to use with what HOW, plus a default.
my $*DEFAULT-METAATTR := 'NQPAttribute';
Expand Down Expand Up @@ -298,6 +299,11 @@ token package_declarator:sym<role> {
:my $*PKGDECL := 'role';
<sym> <package_def>
}
token package_declarator:sym<native> {
:my $*PACKAGE-SETUP := PAST::Stmts.new();
:my $*PKGDECL := 'native';
<sym> <package_def>
}

rule package_def {
<name>
Expand Down
38 changes: 38 additions & 0 deletions src/metamodel/how/NQPNativeHOW.pm
@@ -0,0 +1,38 @@
knowhow NQPNativeHOW {
has $!name;
has $!composed;

method new(:$name) {
my $obj := pir::repr_instance_of__PP(self);
$obj.BUILD(:name($name));
$obj
}

method BUILD(:$name) {
$!name := $name;
}

# Create a new meta-class instance, and then a new type object
# to go with it, and return that.
# XXX Should check that this is an inlineable REPR.
method new_type(:$name = '<anon>', :$repr!) {
my $metaclass := self.new(:name($name));
pir::repr_type_object_for__PPS($metaclass, $repr);
}

method add_method($obj, $name, $code_obj) {
pir::die("Native types may not have methods (must be boxed to call method)");
}

method add_multi_method($obj, $name, $code_obj) {
pir::die("Native types may not have methods (must be boxed to call method)");
}

method add_attribute($obj, $meta_attr) {
pir::die("Native types may not have attributes");
}

method compose($obj) {
$!composed := 1;
}
}

0 comments on commit a9206dd

Please sign in to comment.