[svn:parrot] r42263 - trunk/lib/Parrot

chromatic at svn.parrot.org chromatic at svn.parrot.org
Thu Nov 5 08:43:28 UTC 2009


Author: chromatic
Date: Thu Nov  5 08:43:28 2009
New Revision: 42263
URL: https://trac.parrot.org/parrot/changeset/42263

Log:
[lib] Added an exception to ops processor when it (presumably accidentally)
performs op argument substitution in .ops file preamble sections (RT #43721).

Modified:
   trunk/lib/Parrot/Op.pm
   trunk/lib/Parrot/OpsFile.pm

Modified: trunk/lib/Parrot/Op.pm
==============================================================================
--- trunk/lib/Parrot/Op.pm	Thu Nov  5 07:56:03 2009	(r42262)
+++ trunk/lib/Parrot/Op.pm	Thu Nov  5 08:43:28 2009	(r42263)
@@ -1,5 +1,5 @@
 #! perl
-# Copyright (C) 2001-2008, Parrot Foundation.
+# Copyright (C) 2001-2009, Parrot Foundation.
 # $Id$
 
 =head1 NAME
@@ -319,11 +319,16 @@
 
 # Called from rewrite_body() to perform the actual substitutions.
 sub _substitute {
-    my $self = shift;
-    local $_ = shift;
-    my $trans = shift;
+    my $self           = shift;
+    local $_           = shift;
+    my $trans          = shift;
+    my $preamble_only  = shift;
+
+    my $rewrote_access =
+        s/{{\@([^{]*?)}}/   $trans->access_arg($self->arg_type($1 - 1), $1, $self); /me;
 
-    s/{{\@([^{]*?)}}/   $trans->access_arg($self->arg_type($1 - 1), $1, $self); /me;
+    die "Argument access not allowed in preamble\n"
+        if $preamble_only && $rewrote_access;
 
     s/{{=0,=([^{]*?)}}/   $trans->restart_address($1) . "; {{=0}}"; /me;
     s/{{=0,\+=([^{]*?)}}/ $trans->restart_offset($1)  . "; {{=0}}"; /me;
@@ -341,7 +346,7 @@
     return $_;
 }
 
-=item C<rewrite_body($body, $trans)>
+=item C<rewrite_body($body, $trans, [$preamble])>
 
 Performs the various macro substitutions using the specified transform,
 correctly handling nested substitions, and repeating over the whole string
@@ -353,7 +358,7 @@
 =cut
 
 sub rewrite_body {
-    my ( $self, $body, $trans ) = @_;
+    my ( $self, $body, $trans, $preamble_only ) = @_;
 
     # use vtable macros
     $body =~ s!
@@ -365,7 +370,7 @@
         !VTABLE_$1(!sgx;
 
     while (1) {
-        my $new_body = $self->_substitute( $body, $trans );
+        my $new_body = $self->_substitute( $body, $trans, !!$preamble_only );
 
         last if $body eq $new_body;
 

Modified: trunk/lib/Parrot/OpsFile.pm
==============================================================================
--- trunk/lib/Parrot/OpsFile.pm	Thu Nov  5 07:56:03 2009	(r42262)
+++ trunk/lib/Parrot/OpsFile.pm	Thu Nov  5 08:43:28 2009	(r42263)
@@ -1,5 +1,5 @@
 #! perl
-# Copyright (C) 2001-2008, Parrot Foundation.
+# Copyright (C) 2001-2009, Parrot Foundation.
 # $Id$
 
 =head1 NAME
@@ -668,7 +668,7 @@
         # RT#43721: This ought to throw errors when attempting to rewrite $n
         # argument accesses and other things that make no sense in the
         # preamble.
-        $_ = Parrot::Op->rewrite_body( $_, $trans );
+        $_ = Parrot::Op->rewrite_body( $_, $trans, 'preamble' );
     }
 
     return $_;


More information about the parrot-commits mailing list