Skip to content

Commit

Permalink
Generalize type parameterization. T[...] now calls T.^parameterize(..…
Browse files Browse the repository at this point in the history
….), and ParametricRoleGroupHOW gets to decide about CurriedRoleHOW, which is now an implementation details.
  • Loading branch information
jnthn committed Dec 3, 2011
1 parent 2344572 commit 7a8679d
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 19 deletions.
14 changes: 7 additions & 7 deletions src/Perl6/Actions.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2705,18 +2705,18 @@ class Perl6::Actions is HLL::Actions {
}
}
if $all_compile_time {
my $curried := $*ST.curry_role(%*HOW<role-curried>,
$role, $<arglist>, $/);
my $curried := $*ST.parameterize_type($role, $<arglist>, $/);
$past := $*ST.get_object_sc_ref_past($curried);
$past<has_compile_time_value> := 1;
$past<compile_time_value> := $curried;
}
else {
my $rref := $*ST.get_object_sc_ref_past($role);
$past := $<arglist>[0].ast;
$past.pasttype('callmethod');
$past.name('new_type');
$past.unshift($*ST.get_object_sc_ref_past($role));
$past.unshift($*ST.get_object_sc_ref_past(%*HOW<role-curried>));
$past.name('parameterize');
$past.unshift($rref);
$past.unshift(PAST::Op.new( :pirop('get_how PP'), $rref ));
}
}
elsif ~$<longname> eq 'GLOBAL' {
Expand Down Expand Up @@ -3475,10 +3475,10 @@ class Perl6::Actions is HLL::Actions {
my $type := $*ST.find_symbol(Perl6::Grammar::parse_name(
Perl6::Grammar::canonical_type_longname($<longname>)));
if $<arglist> {
$type := $*ST.curry_role(%*HOW<role-curried>, $type, $<arglist>, $/);
$type := $*ST.parameterize_type($type, $<arglist>, $/);
}
if $<typename> {
$type := $*ST.curry_role_with_args(%*HOW<role-curried>, $type,
$type := $*ST.parameterize_type_with_args($type,
[$<typename>[0].ast], hash());
}
make $type;
Expand Down
1 change: 0 additions & 1 deletion src/Perl6/Metamodel/EXPORTHOW.pm
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ my module EXPORTHOW {
($?PACKAGE.WHO)<role> := Perl6::Metamodel::ParametricRoleHOW;
($?PACKAGE.WHO)<role-attr> := Attribute;
($?PACKAGE.WHO)<role-group> := Perl6::Metamodel::ParametricRoleGroupHOW;
($?PACKAGE.WHO)<role-curried> := Perl6::Metamodel::CurriedRoleHOW;
($?PACKAGE.WHO)<grammar> := Perl6::Metamodel::GrammarHOW;
($?PACKAGE.WHO)<grammar-attr> := Attribute;
($?PACKAGE.WHO)<native> := Perl6::Metamodel::NativeHOW;
Expand Down
11 changes: 8 additions & 3 deletions src/Perl6/Metamodel/ParametricRoleGroupHOW.pm
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
# group of those, and know how to specialize to a certain parameter
# list by multi-dispatching over the set of possibilities to pick
# a particular candidate.
my $currier := Perl6::Metamodel::CurriedRoleHOW;
class Perl6::Metamodel::ParametricRoleGroupHOW
does Perl6::Metamodel::Naming
does Perl6::Metamodel::Stashing
Expand All @@ -36,6 +37,10 @@ class Perl6::Metamodel::ParametricRoleGroupHOW
self.add_stash(pir::repr_type_object_for__PPS($meta, 'Uninstantiable'));
}

method parameterize($obj, *@pos_args, *%named_args) {
$currier.new_type($obj, |@pos_args, |%named_args)
}

method add_possibility($obj, $possible) {
@!possibilities[+@!possibilities] := $possible;
@!add_to_selector[+@!add_to_selector] := $possible;
Expand All @@ -46,10 +51,10 @@ class Perl6::Metamodel::ParametricRoleGroupHOW
# Locate correct parametric role and type environment.
my $error;
my @result;
try {
#try {
@result := (self.get_selector($obj))(|@pos_args, |%named_args);
CATCH { $error := $! }
}
# CATCH { $error := $! }
#}
if $error {
pir::die("None of the parametric role variants for '" ~
self.name($obj) ~ "' matched the arguments supplied.\n" ~
Expand Down
15 changes: 8 additions & 7 deletions src/Perl6/SymbolTable.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1357,7 +1357,7 @@ class Perl6::SymbolTable is HLL::Compiler::SerializationContextBuilder {
}

# Builds a curried role based on a parsed argument list.
method curry_role($curryhow, $role, $arglist, $/) {
method parameterize_type($role, $arglist, $/) {
# Build a list of compile time arguments to the role; whine if
# we find something without one.
my @pos_args;
Expand All @@ -1376,21 +1376,22 @@ class Perl6::SymbolTable is HLL::Compiler::SerializationContextBuilder {
}
}

self.curry_role_with_args($curryhow, $role, @pos_args, %named_args);
self.parameterize_type_with_args($role, @pos_args, %named_args);
}

# Curries a role with the specified arguments.
method curry_role_with_args($curryhow, $role, @pos_args, %named_args) {
method parameterize_type_with_args($role, @pos_args, %named_args) {
# Make the curry right away and add it to the SC.
my $curried := $curryhow.new_type($role, |@pos_args, |%named_args);
my $curried := $role.HOW.parameterize($role, |@pos_args, |%named_args);
my $slot := self.add_object($curried);

# Serialize call.
if self.is_precompilation_mode() {
my $rref := self.get_object_sc_ref_past($role);
my $setup_call := PAST::Op.new(
:pasttype('callmethod'), :name('new_type'),
self.get_object_sc_ref_past($curryhow),
self.get_object_sc_ref_past($role)
:pasttype('callmethod'), :name('parameterize'),
PAST::Op.new( :pirop('get_how PP'), $rref ),
$rref
);
for @pos_args {
$setup_call.push(self.get_object_sc_ref_past($_));
Expand Down
1 change: 0 additions & 1 deletion src/core/EXPORTHOW.pm
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ my module EXPORTHOW {
nqp::bindkey($?PACKAGE.WHO, 'role', Perl6::Metamodel::ParametricRoleHOW);
nqp::bindkey($?PACKAGE.WHO, 'role-attr', Attribute);
nqp::bindkey($?PACKAGE.WHO, 'role-group', Perl6::Metamodel::ParametricRoleGroupHOW);
nqp::bindkey($?PACKAGE.WHO, 'role-curried', Perl6::Metamodel::CurriedRoleHOW);
nqp::bindkey($?PACKAGE.WHO, 'grammar', Perl6::Metamodel::GrammarHOW);
nqp::bindkey($?PACKAGE.WHO, 'grammar-attr', Attribute);
nqp::bindkey($?PACKAGE.WHO, 'native', Perl6::Metamodel::NativeHOW);
Expand Down

0 comments on commit 7a8679d

Please sign in to comment.