G'day all.

This patch allows op-writers to store optional metadata to be
associated along with an op.  Very simple key-value stuff at the
moment; may get fancier later.

Once again, this is mostly for the optimizer's benefit, so you
can note things like if an op affects the state of the world, or
if it may throw an exception, or where it may branch to if it
may branch.  However, you could potentially use it for anything
(e.g. you could mark an op as DEPRECATED, so the assembler can
issue a warning if you use it).

Cheers,
Andrew Bromage

Index: lib/Parrot/Op.pm
===================================================================
RCS file: /cvs/public/parrot/lib/Parrot/Op.pm,v
retrieving revision 1.7
diff -u -r1.7 Op.pm
--- lib/Parrot/Op.pm    15 Feb 2002 03:24:57 -0000      1.7
+++ lib/Parrot/Op.pm    19 Apr 2002 02:55:50 -0000
@@ -147,6 +147,20 @@
 }
 
 #
+# metadata()
+#
+
+sub metadata
+{
+  my $self = shift;
+  if (@_) {
+    $self->{METADATA} = shift;
+  }
+
+  return $self->{METADATA};
+}
+
+#
 # full_body()
 #
 
Index: lib/Parrot/OpsFile.pm
===================================================================
RCS file: /cvs/public/parrot/lib/Parrot/OpsFile.pm,v
retrieving revision 1.18
diff -u -r1.18 OpsFile.pm
--- lib/Parrot/OpsFile.pm       19 Apr 2002 01:32:43 -0000      1.18
+++ lib/Parrot/OpsFile.pm       19 Apr 2002 02:55:50 -0000
@@ -93,8 +93,10 @@
   my $short_name;
   my $args;
   my @args;
+  my $metadata;
   my $seen_pod;
   my $seen_op;
+  my $seen_meta;
   my $line;
 
   while (<OPS>) {
@@ -164,6 +166,7 @@
       $short_name = lc $2;
       $args       = trim(lc $3);
       @args       = split(/\s*,\s*/, $args);
+      $metadata   = {};
       $body       = '';
       $seen_op    = 1;
       $line          = $.+1;
@@ -206,9 +209,15 @@
     # one.
     #
 
-    if (/^}\s*$/) {
-      $count += $self->make_op($count, $type, $short_name, $body, \@args, $line, 
$orig);
+    if (/^}\s*meta\s*{\s*$/i) {
+      $seen_meta = 1;
+      next;
+    }
+    elsif (/^}\s*$/) {
+      $count += $self->make_op($count, $type, $short_name, $body, \@args,
+               $metadata, $line, $orig);
 
+      $seen_meta = 0;
       $seen_op = 0;
 
       next;
@@ -218,7 +227,18 @@
     # Accummulate the code into the op's body:
     #
 
-    if ($seen_op) {
+    if ($seen_meta) {
+      if (/^\s*(\w+)\s*=>\s*(\w+)\s*$/) {
+        if (defined $metadata->{$1}) {
+          die "Parrot::OpsFile: Metadata '$1' already set!\n";
+        }
+        $metadata->{$1} = $2;
+      }
+      else {
+        die "Parrot::OpsFile: Badly formed metadata line: '$_'!\n";
+      }
+    }
+    elsif ($seen_op) {
       $body .= $_;
     } else {
       die "Parrot::OpsFile: Unrecognized line: '$_'!\n";
@@ -241,7 +261,7 @@
 
 sub make_op
 {
-  my ($self, $code, $type, $short_name, $body, $args, $line, $file) = @_;
+  my ($self, $code, $type, $short_name, $body, $args, $meta, $line, $file) = @_;
   my $counter = 0;
   my $jumps = 0;
 
@@ -310,6 +330,7 @@
       $op->body(qq{#line $line "$file"\n}.$body);
 
       $op->may_jump($jumps);
+      $op->metadata($meta);
 
       $self->push_op($op);
       $counter++;

Reply via email to