develooper Front page | perl.cvs.parrot | Postings from December 2008

[svn:parrot] r34420 - trunk/compilers/pirc/new

From:
kjs
Date:
December 27, 2008 03:37
Subject:
[svn:parrot] r34420 - trunk/compilers/pirc/new
Message ID:
20081227113714.6F69BCBA12@x12.develooper.com
Author: kjs
Date: Sat Dec 27 03:37:13 2008
New Revision: 34420

Modified:
   trunk/compilers/pirc/new/pir.y
   trunk/compilers/pirc/new/pirparser.c

Log:
[pirc] rewrite some complex code into switch format.

Modified: trunk/compilers/pirc/new/pir.y
==============================================================================
--- trunk/compilers/pirc/new/pir.y	(original)
+++ trunk/compilers/pirc/new/pir.y	Sat Dec 27 03:37:13 2008
@@ -3294,11 +3294,37 @@
                 *instr_writer++ = '_';
                 *instr_writer++ = 'k';
 
+                /* XXX this switch replaces the messy code below. double-check before delete. */
+                switch (iter->expr.t->key->expr->type) {
+                    case EXPR_TARGET:
+                        switch (iter->expr.t->key->expr->expr.t->info->type) {
+                            case PMC_TYPE:
+                                /* the key is a target, and its type is a PMC. In that
+                                 * case, do not print the signature; 'kp' is not valid.
+                                 */
+                                break;
+                            case INT_TYPE:
+                                *instr_writer++ = 'i';
+                                break;
+                            default:
+                                break;
+                        }
+                        break;
+                    case EXPR_CONSTANT:
+                        *instr_writer++ = 'c';
+                        break;
+                    default:
+                        /* XXX does this ever happen? */
+                        fprintf(stderr, "write_signature: non-constant key\n");
+                        instr_writer = write_signature(iter->expr.t->key->expr, instr_writer);
+                        break;
+                }
+
+
+                /*
                 if ((iter->expr.t->key->expr->type == EXPR_TARGET)
                 &&  (iter->expr.t->key->expr->expr.t->info->type == PMC_TYPE)) {
-                    /* the key is a target, and its type is a PMC. In that case, do not
-                     * print the signature; 'kp' is not valid.
-                     */
+
                 }
                 else {
                     if ((iter->expr.t->key->expr->type == EXPR_TARGET)
@@ -3307,9 +3333,7 @@
                        *instr_writer++ = 'i';
                     }
                     else
-                    /*
-                    instr_writer = write_signature(iter->expr.t->key->expr, instr_writer);
-                    */
+
                     switch (iter->expr.t->key->expr->type) {
                         case EXPR_CONSTANT:
                             *instr_writer++ = 'c';
@@ -3319,7 +3343,8 @@
                             instr_writer = write_signature(iter->expr.t->key->expr, instr_writer);
                             break;
                     }
-                }
+                }*/
+
             }
             break;
         case EXPR_CONSTANT:
@@ -3535,7 +3560,6 @@
         expression *iter = CURRENT_INSTRUCTION(lexer)->operands;
         opinfo           = CURRENT_INSTRUCTION(lexer)->opinfo;
 
-
         PARROT_ASSERT(opinfo);
 
         opcount = opinfo->op_count - 1; /* according to op.h, opcount also counts the op itself. */
@@ -3569,13 +3593,10 @@
                  * which one to fix.
                  */
 
-                /*
-                fprintf(stderr, "setting %dth label flag on instruction %s\n", BIT(i),
-                        CURRENT_INSTRUCTION(lexer)->opname);
-                 */
+                /* fprintf(stderr, "setting %dth label flag on instruction %s\n", BIT(i),
+                        CURRENT_INSTRUCTION(lexer)->opname); */
 
                 SET_FLAG(CURRENT_INSTRUCTION(lexer)->oplabelbits, BIT(i));
-
             }
 
             ++i;

Modified: trunk/compilers/pirc/new/pirparser.c
==============================================================================
--- trunk/compilers/pirc/new/pirparser.c	(original)
+++ trunk/compilers/pirc/new/pirparser.c	Sat Dec 27 03:37:13 2008
@@ -5987,11 +5987,37 @@
                 *instr_writer++ = '_';
                 *instr_writer++ = 'k';
 
+                /* XXX this switch replaces the messy code below. double-check before delete. */
+                switch (iter->expr.t->key->expr->type) {
+                    case EXPR_TARGET:
+                        switch (iter->expr.t->key->expr->expr.t->info->type) {
+                            case PMC_TYPE:
+                                /* the key is a target, and its type is a PMC. In that
+                                 * case, do not print the signature; 'kp' is not valid.
+                                 */
+                                break;
+                            case INT_TYPE:
+                                *instr_writer++ = 'i';
+                                break;
+                            default:
+                                break;
+                        }
+                        break;
+                    case EXPR_CONSTANT:
+                        *instr_writer++ = 'c';
+                        break;
+                    default:
+                        /* XXX does this ever happen? */
+                        fprintf(stderr, "write_signature: non-constant key\n");
+                        instr_writer = write_signature(iter->expr.t->key->expr, instr_writer);
+                        break;
+                }
+
+
+                /*
                 if ((iter->expr.t->key->expr->type == EXPR_TARGET)
                 &&  (iter->expr.t->key->expr->expr.t->info->type == PMC_TYPE)) {
-                    /* the key is a target, and its type is a PMC. In that case, do not
-                     * print the signature; 'kp' is not valid.
-                     */
+
                 }
                 else {
                     if ((iter->expr.t->key->expr->type == EXPR_TARGET)
@@ -6000,9 +6026,7 @@
                        *instr_writer++ = 'i';
                     }
                     else
-                    /*
-                    instr_writer = write_signature(iter->expr.t->key->expr, instr_writer);
-                    */
+
                     switch (iter->expr.t->key->expr->type) {
                         case EXPR_CONSTANT:
                             *instr_writer++ = 'c';
@@ -6012,7 +6036,8 @@
                             instr_writer = write_signature(iter->expr.t->key->expr, instr_writer);
                             break;
                     }
-                }
+                }*/
+
             }
             break;
         case EXPR_CONSTANT:
@@ -6228,7 +6253,6 @@
         expression *iter = CURRENT_INSTRUCTION(lexer)->operands;
         opinfo           = CURRENT_INSTRUCTION(lexer)->opinfo;
 
-
         PARROT_ASSERT(opinfo);
 
         opcount = opinfo->op_count - 1; /* according to op.h, opcount also counts the op itself. */
@@ -6262,13 +6286,10 @@
                  * which one to fix.
                  */
 
-                /*
-                fprintf(stderr, "setting %dth label flag on instruction %s\n", BIT(i),
-                        CURRENT_INSTRUCTION(lexer)->opname);
-                 */
+                /* fprintf(stderr, "setting %dth label flag on instruction %s\n", BIT(i),
+                        CURRENT_INSTRUCTION(lexer)->opname); */
 
                 SET_FLAG(CURRENT_INSTRUCTION(lexer)->oplabelbits, BIT(i));
-
             }
 
             ++i;



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About