Browse files

Give signatures a backlink to the code object they are associated with.

  • Loading branch information...
1 parent dca2ab5 commit 61cbec63bcca12df937c59543ba15dd5d02c3787 @jnthn jnthn committed Sep 25, 2012
Showing with 9 additions and 1 deletion.
  1. +2 −0 src/Perl6/Metamodel/BOOTSTRAP.pm
  2. +4 −1 src/Perl6/World.pm
  3. +3 −0 src/binder/bind.h
View
2 src/Perl6/Metamodel/BOOTSTRAP.pm
@@ -326,13 +326,15 @@ BEGIN {
# has $!returns;
# has $!arity;
# has $!count;
+ # has $!code;
# ... # Uncomposed
# }
Signature.HOW.add_parent(Signature, Any);
Signature.HOW.add_attribute(Signature, BOOTSTRAPATTR.new(:name<$!params>, :type(Mu), :package(Signature)));
Signature.HOW.add_attribute(Signature, BOOTSTRAPATTR.new(:name<$!returns>, :type(Mu), :package(Signature)));
Signature.HOW.add_attribute(Signature, BOOTSTRAPATTR.new(:name<$!arity>, :type(Mu), :package(Signature)));
Signature.HOW.add_attribute(Signature, BOOTSTRAPATTR.new(:name<$!count>, :type(Mu), :package(Signature)));
+ Signature.HOW.add_attribute(Signature, BOOTSTRAPATTR.new(:name<$!code>, :type(Mu), :package(Signature)));
Signature.HOW.add_method(Signature, 'is_generic', static(sub ($self) {
# If any parameter is generic, so are we.
my @params := nqp::getattr($self, Signature, '$!params');
View
5 src/Perl6/World.pm
@@ -680,10 +680,13 @@ class Perl6::World is HLL::World {
$code
}
- # Attaches a signature to a code object.
+ # Attaches a signature to a code object, and gives the
+ # signature its backlink to the code object.
method attach_signature($code, $signature) {
my $code_type := self.find_symbol(['Code']);
+ my $sig_type := self.find_symbol(['Signature']);
nqp::bindattr($code, $code_type, '$!signature', $signature);
+ nqp::bindattr($signature, $sig_type, '$!code', $code);
}
# Takes a code object and the QAST::Block for its body.
View
3 src/binder/bind.h
@@ -58,6 +58,9 @@ typedef struct {
PMC *sc; /* Serialization context, though we don't care about that here. */
PMC *params; /* Array of objects that are all parameters. */
PMC *rtype; /* Return type. */
+ PMC *arity; /* Cached arity. */
+ PMC *count; /* Cached count. */
+ PMC *code; /* The code object the signature is for. */
} Rakudo_Signature;
/*

0 comments on commit 61cbec6

Please sign in to comment.