Skip to content

Commit

Permalink
Get signature building a little further along, plus assorted fixes to…
Browse files Browse the repository at this point in the history
… trait application time.
  • Loading branch information
jnthn committed May 22, 2011
1 parent c50c120 commit 56a776f
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 8 deletions.
15 changes: 13 additions & 2 deletions src/Perl6/Actions.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1549,6 +1549,9 @@ class Perl6::Actions is HLL::Actions {

method signature($/) {
my @parameters;
for $<parameter> {
@parameters.push($_.ast);
}
make $*ST.create_signature(@parameters);
}

Expand Down Expand Up @@ -1680,6 +1683,10 @@ class Perl6::Actions is HLL::Actions {
$/.CURSOR.panic('post_constraints not yet implemented');
}
}

method trait($/) {
make $<trait_mod> ?? $<trait_mod>.ast !! $<colonpair>.ast;
}

method trait_mod:sym<is>($/) {
# Handle is repr specially.
Expand All @@ -1701,12 +1708,16 @@ class Perl6::Actions is HLL::Actions {
my @name := Perl6::Grammar::parse_name(~$<longname>);
if $*ST.is_type(@name) {
my $trait := $*ST.find_symbol(@name);
$tmi($*DECLARAND, $trait);
make -> $declarand {
$tmi($declarand, $trait);
};
}
else {
my %arg;
%arg{~$<longname>} := 1;
$tmi($*DECLARAND, |%arg);
make -> $declarand {
$tmi($declarand, |%arg);
};
}
}
}
Expand Down
8 changes: 8 additions & 0 deletions src/Perl6/Grammar.pm
Original file line number Diff line number Diff line change
Expand Up @@ -920,6 +920,14 @@ grammar Perl6::Grammar is HLL::Grammar {

# Set declarand as the package.
$*DECLARAND := $*PACKAGE;

# Apply any traits.
for $<trait> {
my $applier := $_.ast;
if $applier {
$applier($*DECLARAND);
}
}
}

[
Expand Down
2 changes: 1 addition & 1 deletion src/Perl6/Metamodel/BOOTSTRAP.pm
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ Signature.HOW.add_attribute(Signature, BOOTSTRAPATTR.new(:name<$!named_to_pos_ca
# }
my stub Parameter metaclass Perl6::Metamodel::ClassHOW { ... };
Parameter.HOW.add_parent(Parameter, Cool);
Parameter.HOW.add_attribute(Parameter, BOOTSTRAPATTR.new(:name<$!name>, :type(str)));
Parameter.HOW.add_attribute(Parameter, BOOTSTRAPATTR.new(:name<$!variable_name>, :type(str)));
Parameter.HOW.add_attribute(Parameter, BOOTSTRAPATTR.new(:name<$!named_names>, :type(Mu)));
Parameter.HOW.add_attribute(Parameter, BOOTSTRAPATTR.new(:name<$!type_captures>, :type(Mu)));
Parameter.HOW.add_attribute(Parameter, BOOTSTRAPATTR.new(:name<$!flags>, :type(int)));
Expand Down
41 changes: 36 additions & 5 deletions src/Perl6/SymbolTable.pm
Original file line number Diff line number Diff line change
Expand Up @@ -163,17 +163,30 @@ class Perl6::SymbolTable is HLL::Compiler::SerializationContextBuilder {
my $slot := self.add_object($parameter);
say("# ... slot $slot");

# XXX Set up values.

# Create PAST to make it when deserializing.
# XXX TODO: Finish it.
my $set_attrs := PAST::Stmts.new();
self.add_event(:deserialize_past(PAST::Stmts.new(
self.set_slot_past($slot, self.set_cur_sc(PAST::Op.new(
:pirop('repr_instance_of PP'),
self.get_object_sc_ref_past($par_type)
)))
))),
$set_attrs
)));

# Set name if there is one.
if pir::exists(%param_info, 'variable_name') {
pir::repr_bind_attr_str__vPPsS($parameter, $par_type, '$!variable_name', %param_info<variable_name>);
$set_attrs.push(self.set_attribute_typed($parameter, $par_type,
'$!variable_name', %param_info<variable_name>, str));
}

# Set nominal type.
pir::setattribute__vPPsP($parameter, $par_type, '$!nominal_type', %param_info<nominal_type>);
$set_attrs.push(self.set_attribute($parameter, $par_type, '$!nominal_type',
self.get_object_sc_ref_past(%param_info<nominal_type>)));

# XXX Set up other various attribute values.

# Return created parameter.
$parameter
}
Expand Down Expand Up @@ -263,17 +276,35 @@ class Perl6::SymbolTable is HLL::Compiler::SerializationContextBuilder {
)
}

# Helper to make PAST for setting a typed attribute to a value. Value should
# be a PAST tree.
method set_attribute_typed($obj, $class, $name, $value_past, $type) {
PAST::Op.new(
:pasttype('bind'),
PAST::Var.new(
:name($name), :scope('attribute_6model'), :type($type),
self.get_object_sc_ref_past($obj),
self.get_object_sc_ref_past($class)
),
$value_past
)
}

# Takes a PAST::Block and compiles it for running during "compile time".
# We need to do this for BEGIN but also for things that get called in
# the compilation process, like user defined traits.
method compile_in_context($past) {
# Ensure that we have the appropriate op libs loaded.
# Ensure that we have the appropriate op libs loaded and correct
# HLL.
$past.loadlibs('perl6_group', 'perl6_ops');
$past.hll('perl6');

# Create outer lexical contexts with all symbols visible.
# XXX TODO

# Compile and return.
my $pir := PAST::Compiler.compile($past, :target('pir'));
say($pir);
PAST::Compiler.compile($past)
}

Expand Down

0 comments on commit 56a776f

Please sign in to comment.