On Saturday 13 October 2007 17:03:56 Will Coleda wrote: > ENOPATCH
=== lib/Parrot/Op.pm ================================================================== --- lib/Parrot/Op.pm (revision 6305) +++ lib/Parrot/Op.pm (local) @@ -67,6 +67,8 @@ use strict; use warnings; +use Scalar::Util 'blessed'; + =item C<new($code, $type, $name, $args, $argdirs, $labels, $flags)> Allocates a new bodyless op. A body must be provided eventually for the @@ -220,6 +222,36 @@ return @{ $self->{ARGDIRS} }; } +=item C<assertions()> + +Asserts that any in PMCs are not NULL. + +=cut + +sub assertions { + my ($self, $trans) = @_; + my @dirs = $self->arg_dirs(); + my @types = $self->arg_types(); + + my @assertions; + + my $count = 0; + + while (@dirs && @types) { + my $dir = shift @dirs; + my $type = shift @types; + + $count++; + next unless $type eq 'p' && $dir =~ /^i/; + + my $access = $trans->access_arg($type, $count, $self); + + push @assertions, "PARROT_ASSERT(!PMC_IS_NULL($access));"; + } + + return join("\n", @assertions, "\n" ); +} + =item C<labels()> Returns the labels. @@ -375,6 +407,11 @@ $body = $new_body; } + if (blessed( $self )) { + my $assertions = $self->assertions($trans); + $body =~ s/(^.+return)/$assertions\n$1/m if $assertions; + } + return $body; }