[svn:parrot] r46886 - in branches/ops_pct/compilers/opsc/src/Ops: . Compiler

cotto at svn.parrot.org cotto at svn.parrot.org
Sat May 22 17:06:42 UTC 2010


Author: cotto
Date: Sat May 22 17:06:41 2010
New Revision: 46886
URL: https://trac.parrot.org/parrot/changeset/46886

Log:
[opsc] move op num and experimental calculations out of the parser

Modified:
   branches/ops_pct/compilers/opsc/src/Ops/Compiler.pm
   branches/ops_pct/compilers/opsc/src/Ops/Compiler/Actions.pm
   branches/ops_pct/compilers/opsc/src/Ops/File.pm

Modified: branches/ops_pct/compilers/opsc/src/Ops/Compiler.pm
==============================================================================
--- branches/ops_pct/compilers/opsc/src/Ops/Compiler.pm	Sat May 22 11:47:32 2010	(r46885)
+++ branches/ops_pct/compilers/opsc/src/Ops/Compiler.pm	Sat May 22 17:06:41 2010	(r46886)
@@ -12,7 +12,6 @@
 
 method set_oplib($oplib) {
     $Ops::Compiler::Actions::OPLIB := $oplib;
-    $Ops::Compiler::Actions::CODE  := $oplib.max_op_num + 1;
 }
 
 # vim: ft=perl6 expandtab shiftwidth=4:

Modified: branches/ops_pct/compilers/opsc/src/Ops/Compiler/Actions.pm
==============================================================================
--- branches/ops_pct/compilers/opsc/src/Ops/Compiler/Actions.pm	Sat May 22 11:47:32 2010	(r46885)
+++ branches/ops_pct/compilers/opsc/src/Ops/Compiler/Actions.pm	Sat May 22 17:06:41 2010	(r46886)
@@ -4,12 +4,10 @@
 
 class Ops::Compiler::Actions is HLL::Actions;
 
-our $CODE;
 our $OPLIB;
 
 INIT {
     pir::load_bytecode("nqp-setting.pbc");
-    $CODE  := 0;
     $OPLIB := 0;
 }
 
@@ -36,34 +34,13 @@
     for $<op> {
         my $ops := $_.ast;
         my $op_skip_table;
-        my $op_num_table;
         if $OPLIB {
             $op_skip_table := $OPLIB.op_skip_table;
-            $op_num_table  := $OPLIB.op_num_table;
         }
         for @($ops) -> $op {
-            my $full_name := $op.full_name;
-            if $OPLIB && !$op_skip_table.exists($full_name) {
-
-                #ops listed in ops.num are non-experimental
-                if $op_num_table.exists($full_name) {
-                    $op<code> := $op_num_table{$full_name};
-                    $op<experimental> := 0;
-                }
-                #ops not explicitly listed but not skipped are experimental
-                else {
-                    $op<code> := $CODE++;
-                    $op<experimental> := 1;
-                }
+            if $OPLIB && !$op_skip_table.exists($op.full_name) || !$OPLIB {
                 $past<ops>.push($op);
             }
-            #if there's no oplib, we're compiling dynops and ops aren't experimental
-            elsif !$OPLIB {
-                $op<code> := $CODE++;
-                $op<experimental> := 0;
-                $past<ops>.push($op);
-            }
-
         }
     }
 

Modified: branches/ops_pct/compilers/opsc/src/Ops/File.pm
==============================================================================
--- branches/ops_pct/compilers/opsc/src/Ops/File.pm	Sat May 22 11:47:32 2010	(r46885)
+++ branches/ops_pct/compilers/opsc/src/Ops/File.pm	Sat May 22 17:06:41 2010	(r46886)
@@ -192,7 +192,7 @@
     self<op_order>:= 0;
 
     if $core {
-        self<oplib>   := $oplib;
+        self<oplib> := $oplib;
         self<compiler>.set_oplib($oplib);
     }
     else {
@@ -203,6 +203,8 @@
 
     for @files { self.read_ops( $_, $nolines ) }
 
+    self._calculate_op_codes();
+                                
     self;
 }
 
@@ -282,6 +284,34 @@
 method version_minor() { self<version_minor> }
 method version_patch() { self<version_patch> }
 
+method _calculate_op_codes() {
+
+    my $code := self<oplib> ?? 
+        self<oplib>.max_op_num + 1 !!
+        0;
+
+    for self<ops> -> $op {
+        #ops listed in ops.num are non-experimental
+        if self<oplib> {
+            my $full_name := $op.full_name;
+            if self<oplib>.op_num_table.exists($full_name) {
+                $op<code> := self<oplib>.op_num_table{$full_name};
+                $op<experimental> := 0;
+            }
+            #ops not explicitly listed but not skipped are experimental
+            else {
+                $op<code> := $code++;
+                $op<experimental> := 1;
+            }
+        }
+        #if there's no oplib, we're compiling dynops and ops aren't experimental
+        else {
+            $op<code> := $code++;
+            $op<experimental> := 0;
+        }
+    }
+}
+
 method _set_version() {
     my $config := _config();
     my $version := $config<VERSION>;


More information about the parrot-commits mailing list