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

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

From:
kjs
Date:
December 28, 2008 08:44
Subject:
[svn:parrot] r34498 - trunk/compilers/pirc/new
Message ID:
20081228164425.388FFCB9FA@x12.develooper.com
Author: kjs
Date: Sun Dec 28 08:44:24 2008
New Revision: 34498

Modified:
   trunk/compilers/pirc/new/pircompunit.c
   trunk/compilers/pirc/new/pircompunit.h

Log:
[pirc] calculate flags for arguments.

Modified: trunk/compilers/pirc/new/pircompunit.c
==============================================================================
--- trunk/compilers/pirc/new/pircompunit.c	(original)
+++ trunk/compilers/pirc/new/pircompunit.c	Sun Dec 28 08:44:24 2008
@@ -1725,9 +1725,7 @@
 */
 void
 push_operand(lexer_state * const lexer, NOTNULL(expression * const operand)) {
-    PARROT_ASSERT(lexer->subs->statements);
-
-    fprintf(stderr, "push_operand() current op: %s\n", CURRENT_INSTRUCTION(lexer)->opname);
+    PARROT_ASSERT(CURRENT_INSTRUCTION(lexer));
 
     if (CURRENT_INSTRUCTION(lexer)->operands) {
         operand->next = CURRENT_INSTRUCTION(lexer)->operands->next;
@@ -1927,29 +1925,50 @@
 
 }
 
+
 /*
 
-=item C<static pir_type
-get_expression_pirtype(expression * const expr)>
+=item C<static int
+calculate_argument_flags(argument * const arg)>
 
-Get the PIR type of the expression C<expr>.
+Calculate the Parrot Calling Conventions flags for the
+argument C<arg>. An int encoding the flags is returned.
 
 =cut
 
 */
-static pir_type
-get_expression_pirtype(expression * const expr) {
-    switch (expr->type) {
+static int
+calculate_argument_flags(argument * const arg) {
+    int flag = 0;
+
+    switch (arg->value->type) {
         case EXPR_TARGET:
-            return expr->expr.t->info->type;
+            /* copy the type of the target */
+            SET_FLAG(flag, arg->value->expr.t->info->type);
+            break;
         case EXPR_CONSTANT:
-            return expr->expr.c->type;
+            /* copy the type of the constant */
+            SET_FLAG(flag, arg->value->expr.c->type);
+            /* set the flag indicating the argument is a constant literal, not a register. */
+            SET_FLAG(flag, PARROT_ARG_CONSTANT);
+            break;
         default:
-            PARROT_ASSERT(0); /* should never happen */
-            return UNKNOWN_TYPE;
+            break;
     }
+
+    /* if the argument has a :flat flag, copy that */
+    if (TEST_FLAG(arg->flags, ARG_FLAG_FLAT))
+        SET_FLAG(flag, PARROT_ARG_FLATTEN);
+
+    /* if the argument has a :named flag, copy that */
+    if (TEST_FLAG(arg->flags, ARG_FLAG_NAMED))
+        SET_FLAG(flag, PARROT_ARG_NAME);
+
+    return flag;
 }
 
+
+
 /*
 
 =item C<static void
@@ -1988,9 +2007,7 @@
     argiter = args->next;
 
     for (i = 0; i < num_arguments; ++i) {
-        int flag = 0;
-        /* calculate the right flags for the current argument */
-        SET_FLAG(flag, get_expression_pirtype(argiter->value));
+        int flag = calculate_argument_flags(argiter);
 
         /* set the flags for this argument in the right position in the array */
         VTABLE_set_integer_keyed_int(lexer->interp, signature_array, i, flag);
@@ -2143,7 +2160,9 @@
     if (instr->opinfo)
         lexer->codesize -= instr->opinfo->op_count;
 
+/*
     fprintf(stderr, "updateop(): %s\n", CURRENT_INSTRUCTION(lexer)->opname);
+*/
     /* else the instruction was already set; decrement the codesize, as it was added already */
 
     /* now get the opinfo structure, update the name, and update the opcode. */

Modified: trunk/compilers/pirc/new/pircompunit.h
==============================================================================
--- trunk/compilers/pirc/new/pircompunit.h	(original)
+++ trunk/compilers/pirc/new/pircompunit.h	Sun Dec 28 08:44:24 2008
@@ -112,9 +112,9 @@
 
 /* macros to set the i-th bit */
 #define BIT(i)          (1 << (i))
-#define SET_BIT(M,B)    SET_FLAG(M,B)
-#define TEST_BIT(M,B)   TEST_FLAG(M,B)
-#define CLEAR_BIT(M,B)  CLEAR_FLAG(M,B)
+#define SET_BIT(M,B)    SET_FLAG((M),(B))
+#define TEST_BIT(M,B)   TEST_FLAG((M),(B))
+#define CLEAR_BIT(M,B)  CLEAR_FLAG((M),(B))
 
 #define NOT(X)          !(X)
 
@@ -141,11 +141,6 @@
     char const      *name;     /* name of the constant, if declared as a constant */
     pir_type         type;     /* type of the constant */
     value            val;      /* value of the constant */
-
-    /* XXX this needed? think not. --kjs 12/27/2008.
-    int              const_table_index;
-    */
-
     struct constant *next;
 
 } constant;
@@ -158,10 +153,10 @@
 } label;
 
 
-#define CONST_INTVAL(c) c->val.ival
-#define CONST_NUMVAL(c) c->val.nval
-#define CONST_PMCVAL(c) c->val.pval
-#define CONST_STRVAL(c) c->val.sval
+#define CONST_INTVAL(c) (c)->val.ival
+#define CONST_NUMVAL(c) (c)->val.nval
+#define CONST_PMCVAL(c) (c)->val.pval
+#define CONST_STRVAL(c) (c)->val.sval
 
 /* The expression node is used as a wrapper to represent target nodes (like .param, .local
  * and registers), constant nodes (either named or anonymous), label identifiers,



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