Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add archetypes to the various NQP meta-objects.
  • Loading branch information
jnthn committed Sep 9, 2011
1 parent 2922924 commit c6f6882
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 5 deletions.
65 changes: 65 additions & 0 deletions src/how/Archetypes.pm
@@ -0,0 +1,65 @@
# Provides various properties of the type of type a given meta-object
# implements. This are used in various ways by the compiler and meta-model
# to do correct code generation or to detect illegal use of types in
# contexts with certain requirements.
my knowhow Archetypes {
# Can this serve as a nominal type? Implies memoizability
# amongst other things.
has $!nominal;

# If it's not nominal, does it know how to provide a nominal
# type part of itself?
has $!nominalizable;

# Can this be inherited from?
has $!inheritable;

# If it's not inheritable, does it know how to produce something
# that is?
has $!inheritalizable;

# Can this be composed (either with flattening composition, or used
# as a mixin)?
has $!composable;

# If it's not composable, does it know how to produce something
# that is?
has $!composalizable;

# Is it generic, in the sense of "we don't know what type this is
# yet"? Note that a parametric type would not be generic - even if
# it has missing parts, it defines a type. A type variable is generic,
# however. This tends to cause various kinds of late (or at least
# delayed) reification. In some contexts, an unresolved generic is
# fatal.
has $!generic;

# Is it a parametric type - that is, it has missing bits that need
# to be filled out before it can be used? Unlike generic, something
# that is parametric does define a type - though we may need the gaps
# filled it before it's useful in some way.
has $!parametric;

method new(:$nominal, :$inheritable, :$composable, :$parametric) {
my $arch := nqp::create(self);
$arch.BUILD(:nominal($nominal), :inheritable($inheritable),
:composable($composable), :parametric($parametric));
$arch
}

method BUILD(:$nominal, :$inheritable, :$composable, :$parametric) {
$!nominal := $nominal;
$!inheritable := $inheritable;
$!composable := $composable;
$!parametric := $parametric;
}

method nominal() { $!nominal }
method nominalizable() { $!nominalizable }
method inheritable() { $!inheritable }
method inheritalizable() { $!inheritalizable }
method composable() { $!composable }
method composalizable() { $!composalizable }
method generic() { $!generic }
method parametric() { $!parametric }
}
5 changes: 5 additions & 0 deletions src/how/NQPClassHOW.pm
Expand Up @@ -34,6 +34,11 @@ knowhow NQPClassHOW {
# Parrot-specific vtable mapping hash. Maps vtable name to method.
has %!parrot_vtable_mapping;
has %!parrot_vtable_handler_mapping;

my $archetypes := Archetypes.new( :nominal(1), :inheritable(1) );
method archetypes() {
$archetypes
}

##
## Declarative.
Expand Down
4 changes: 4 additions & 0 deletions src/how/NQPConcreteRoleHOW.pm
Expand Up @@ -26,6 +26,10 @@ knowhow NQPConcreteRoleHOW {
# Have we been composed?
has $!composed;

my $archetypes := Archetypes.new( :nominal(1), :composable(1) );
method archetypes() {
$archetypes
}

##
## Declarative
Expand Down
5 changes: 5 additions & 0 deletions src/how/NQPModuleHOW.pm
@@ -1,6 +1,11 @@
knowhow NQPModuleHOW {
has $!name;
has $!composed;

my $archetypes := Archetypes.new( );
method archetypes() {
$archetypes
}

method new(:$name) {
my $obj := pir::repr_instance_of__PP(self);
Expand Down
5 changes: 5 additions & 0 deletions src/how/NQPNativeHOW.pm
Expand Up @@ -2,6 +2,11 @@ knowhow NQPNativeHOW {
has $!name;
has $!composed;

my $archetypes := Archetypes.new( :nominal(1) );
method archetypes() {
$archetypes
}

method new(:$name) {
my $obj := pir::repr_instance_of__PP(self);
$obj.BUILD(:name($name));
Expand Down
4 changes: 4 additions & 0 deletions src/how/NQPParametricRoleHOW.pm
Expand Up @@ -26,6 +26,10 @@ knowhow NQPParametricRoleHOW {
# don't do that in NQP.)
has $!body_block;

my $archetypes := Archetypes.new( :nominal(1), :composable(1), :parametric(1) );
method archetypes() {
$archetypes
}

##
## Declarative
Expand Down
10 changes: 5 additions & 5 deletions tools/build/Makefile.in
Expand Up @@ -139,11 +139,11 @@ NQP_COMBINED_PIR = gen/NQP.pir
NQP_PBC = nqp.pbc
NQP_EXE = nqp$(EXE)

NQP_MO_SOURCES = src/how/RoleToRoleApplier.pm src/how/NQPConcreteRoleHOW.pm \
src/how/RoleToClassApplier.pm src/how/NQPParametricRoleHOW.pm \
src/how/NQPClassHOW.pm src/how/NQPNativeHOW.pm \
src/how/NQPAttribute.pm src/how/NQPModuleHOW.pm \
src/how/EXPORTHOW.pm \
NQP_MO_SOURCES = src/how/Archetypes.pm src/how/RoleToRoleApplier.pm \
src/how/NQPConcreteRoleHOW.pm src/how/RoleToClassApplier.pm \
src/how/NQPParametricRoleHOW.pm src/how/NQPClassHOW.pm \
src/how/NQPNativeHOW.pm src/how/NQPAttribute.pm \
src/how/NQPModuleHOW.pm src/how/EXPORTHOW.pm \

NQP_MO_PBC = nqpmo.pbc
NQP_MO_PIR = gen/nqp-mo.pir
Expand Down

0 comments on commit c6f6882

Please sign in to comment.