[svn:parrot] r47524 - trunk/compilers/opsc/src/Ops

cotto at svn.parrot.org cotto at svn.parrot.org
Thu Jun 10 08:12:39 UTC 2010


Author: cotto
Date: Thu Jun 10 08:12:39 2010
New Revision: 47524
URL: https://trac.parrot.org/parrot/changeset/47524

Log:
[opsc] use proper multis in Ops::Op.process_body_chunk

Modified:
   trunk/compilers/opsc/src/Ops/Op.pm

Modified: trunk/compilers/opsc/src/Ops/Op.pm
==============================================================================
--- trunk/compilers/opsc/src/Ops/Op.pm	Thu Jun 10 03:03:14 2010	(r47523)
+++ trunk/compilers/opsc/src/Ops/Op.pm	Thu Jun 10 08:12:39 2010	(r47524)
@@ -284,61 +284,55 @@
 }
 
 # Recursively process body chunks returning string.
-# Ideally bunch of multisubs, but...
-method process_body_chunk($trans, $chunk) {
-    my $what := $chunk.WHAT;
-    # Poor man multis...
-    if $what eq 'PAST::Var()' {
-        my $n := +$chunk.name;
-        return $trans.access_arg( self.arg_type($n - 1), $n);
+
+our multi method process_body_chunk($trans, PAST::Var $chunk) {
+    my $n := +$chunk.name;
+    return $trans.access_arg( self.arg_type($n - 1), $n);
+}
+
+our multi method process_body_chunk($trans, PAST::Op $chunk) {
+    my $type := $chunk.pasttype;
+    #say('OP ' ~ $type);
+    if $type eq 'inline' {
+        #_dumper($chunk);
+        #pir::say('RET ' ~ $chunk<inline>);
+        return $chunk.inline;
     }
-    elsif $what eq 'PAST::Op()' {
-        my $type := $chunk.pasttype;
-        #say('OP ' ~ $type);
-        if $type eq 'inline' {
-            #_dumper($chunk);
-            #pir::say('RET ' ~ $chunk<inline>);
-            return $chunk.inline;
+    elsif $type eq 'call' {
+        my $name     := $chunk.name;
+        #say('NAME '~$name ~ ' ' ~ $is_next);
+        if $name eq 'OPSIZE' {
+            #say('is_next');
+            return ~self.size;
         }
-        elsif $type eq 'call' {
-            my $name     := $chunk.name;
-            #say('NAME '~$name ~ ' ' ~ $is_next);
-            if $name eq 'OPSIZE' {
-                #say('is_next');
-                return ~self.size;
-            }
-
-            my @children := list();
-            for @($chunk) {
-                @children.push(self.process_body_chunk($trans, $_));
-            }
-            my $children := join('', |@children);
-
-            #pir::say('children ' ~ $children);
-            my $ret := Q:PIR<
-                $P0 = find_lex '$trans'
-                $P1 = find_lex '$name'
-                $S0 = $P1
-                $P1 = find_lex '$children'
-                %r  = $P0.$S0($P1)
-            >;
-            #pir::say('RET ' ~ $ret);
-            return $ret;
-        }
-    }
-    elsif $what eq 'PAST::Stmts()' {
+
         my @children := list();
         for @($chunk) {
             @children.push(self.process_body_chunk($trans, $_));
         }
         my $children := join('', |@children);
-        return $children;
-    }
-    else {
-        pir::die('HOLEY');
+
+        #pir::say('children ' ~ $children);
+        my $ret := Q:PIR<
+            $P0 = find_lex '$trans'
+            $P1 = find_lex '$name'
+            $S0 = $P1
+            $P1 = find_lex '$children'
+            %r  = $P0.$S0($P1)
+        >;
+        #pir::say('RET ' ~ $ret);
+        return $ret;
     }
 }
 
+our multi method process_body_chunk($trans, PAST::Stmts $chunk) {
+    my @children := list();
+    for @($chunk) {
+        @children.push(self.process_body_chunk($trans, $_));
+    }
+    my $children := join('', |@children);
+    return $children;
+}
 
 =begin
 


More information about the parrot-commits mailing list