[svn:parrot] r44588 - in branches/ops_pct/compilers/opsc: src/Ops/Compiler t

bacek at svn.parrot.org bacek at svn.parrot.org
Tue Mar 2 11:12:29 UTC 2010


Author: bacek
Date: Tue Mar  2 11:12:28 2010
New Revision: 44588
URL: https://trac.parrot.org/parrot/changeset/44588

Log:
Assign codes to Ops during parsing.

Modified:
   branches/ops_pct/compilers/opsc/src/Ops/Compiler/Actions.pm
   branches/ops_pct/compilers/opsc/t/05-opsfile.t

Modified: branches/ops_pct/compilers/opsc/src/Ops/Compiler/Actions.pm
==============================================================================
--- branches/ops_pct/compilers/opsc/src/Ops/Compiler/Actions.pm	Tue Mar  2 11:12:01 2010	(r44587)
+++ branches/ops_pct/compilers/opsc/src/Ops/Compiler/Actions.pm	Tue Mar  2 11:12:28 2010	(r44588)
@@ -3,6 +3,12 @@
 
 class Ops::Compiler::Actions is HLL::Actions;
 
+our $CODE;
+
+INIT {
+    $CODE := 0;
+}
+
 method TOP($/) {
     make $<body>.ast;
 }
@@ -26,6 +32,7 @@
     for $<op> {
         my $ops := $_.ast;
         for @($ops) {
+            $_<code> := $CODE++;
             $past<ops>.push($_);
         }
     }

Modified: branches/ops_pct/compilers/opsc/t/05-opsfile.t
==============================================================================
--- branches/ops_pct/compilers/opsc/t/05-opsfile.t	Tue Mar  2 11:12:01 2010	(r44587)
+++ branches/ops_pct/compilers/opsc/t/05-opsfile.t	Tue Mar  2 11:12:28 2010	(r44588)
@@ -3,7 +3,7 @@
 pir::load_bytecode("compilers/opsc/opsc.pbc");
 pir::load_bytecode("nqp-settings.pbc");
 
-plan(2);
+plan(6);
 
 my $f := Ops::File.new();
 ok($f, "Empty Ops::File created");
@@ -15,11 +15,21 @@
 
 $f := Ops::File.new(|@files);
 
+my @ops := $f<parsed_ops>;
 # 84 core
 # 116 math
 # We can generate more than 1 Ops::Op per op due args expansion.
-say( "# Parsed " ~ +$f<parsed_ops>);
-ok( $f<parsed_ops> > 84 + 116, "Ops parsed correctly");
+say( "# Parsed " ~ + at ops);
+ok( @ops > 84 + 116, "Ops parsed correctly");
 
+my $op := @ops[0];
+#_dumper($op);
+# First op should be C<end> and has code 0.
+ok($op.name eq 'end',   "First op is end");
+ok($op<code> == 0,      "... with code 0");
+
+$op := @ops[(+ at ops)-1];
+ok($op.name eq 'fact',  "Last op is fact");
+ok($op<code> == 358,    "... with code 0");
 
 # vim: expandtab shiftwidth=4 ft=perl6:


More information about the parrot-commits mailing list