On Sun, Sep 30, 2001 at 11:31:21AM -0400, Gregor N. Purdy wrote:
 
> And, BTW, the current PackFile_Constant type isn't using a union.
> It has separate members for each type of constant. This could be
> changed once things are working. There's probably a few other
> things that could use some cleanup/refinement too, such as
> documentation.

Here is a patch for macros for accessing constants from ops.  This uses
(INT|STR|NUM)_PCONST(i) for the relevant types. Best to avoid filling opcode
definitions with manual structure dereferences.

/* SET Nx, CONSTANT */
AUTO_OP set_n_nc {
  NUM_REG(P1) = PCONST(P2)->number;
}

is now 

/* SET Nx, CONSTANT */
AUTO_OP set_n_nc {
  NUM_REG(P1) = NUM_PCONST(P2);
}


-- 
Jason
Index: basic_opcodes.ops
===================================================================
RCS file: /home/perlcvs/parrot/basic_opcodes.ops,v
retrieving revision 1.27
diff -u -r1.27 basic_opcodes.ops
--- basic_opcodes.ops   2001/09/30 20:25:22     1.27
+++ basic_opcodes.ops   2001/10/01 03:25:53
@@ -191,7 +191,7 @@
 
 /* SET Nx, CONSTANT */
 AUTO_OP set_n_nc {
-  NUM_REG(P1) = PCONST(P2)->number;
+  NUM_REG(P1) = NUM_PCONST(P2);
 } 
 
 /* SET Nx, Nx */
@@ -232,7 +232,7 @@
 
 /* EQ Nx, CONSTANT, EQ_BRANCH */
 MANUAL_OP eq_nc_ic {
-  if (NUM_REG(P1) == PCONST(P2)->number) {
+  if (NUM_REG(P1) == NUM_PCONST(P2)) {
     RETURN(P3);
   }
 }
@@ -246,7 +246,7 @@
 
 /* NE Nx, CONSTANT, NE_BRANCH */
 MANUAL_OP ne_nc_ic {
-  if (NUM_REG(P1) != PCONST(P2)->number) {
+  if (NUM_REG(P1) != NUM_PCONST(P2)) {
     RETURN(P3);
   }
 }
@@ -260,7 +260,7 @@
 
 /* LT Nx, CONSTANT, LT_BRANCH */
 MANUAL_OP lt_nc_ic {
-  if (NUM_REG(P1) < PCONST(P2)->number) {
+  if (NUM_REG(P1) < NUM_PCONST(P2)) {
     RETURN(P3);
   }
 }
@@ -274,7 +274,7 @@
 
 /* LE Nx, CONSTANT, LE_BRANCH */
 MANUAL_OP le_nc_ic {
-  if (NUM_REG(P1) <= PCONST(P2)->number) {
+  if (NUM_REG(P1) <= NUM_PCONST(P2)) {
     RETURN(P3);
   }
 }
@@ -288,7 +288,7 @@
 
 /* GT Nx, CONSTANT, GT_BRANCH */
 MANUAL_OP gt_nc_ic {
-  if (NUM_REG(P1) > PCONST(P2)->number) {
+  if (NUM_REG(P1) > NUM_PCONST(P2)) {
     RETURN(P3);
   }
 }
@@ -302,7 +302,7 @@
 
 /* GE Nx, CONSTANT, GE_BRANCH */
 MANUAL_OP ge_nc_ic {
-  if (NUM_REG(P1) >= PCONST(P2)->number) {
+  if (NUM_REG(P1) >= NUM_PCONST(P2)) {
     RETURN(P3);
   }
 }
@@ -326,7 +326,7 @@
  
 /* PRINT nc */
 AUTO_OP print_nc {
-  printf("%f", PCONST(P1)->number);
+  printf("%f", NUM_PCONST(P1));
 }
 
 /* INC Nx */
@@ -336,7 +336,7 @@
 
 /* INC Nx, nnn */
 AUTO_OP inc_n_nc {
-  NUM_REG(P1) += PCONST(P2)->number;
+  NUM_REG(P1) += NUM_PCONST(P2);
 }
 
 /* DEC Nx */
@@ -346,7 +346,7 @@
 
 /* DEC Nx, nnn */
 AUTO_OP dec_n_nc {
-  NUM_REG(P1) -= PCONST(P2)->number;
+  NUM_REG(P1) -= NUM_PCONST(P2);
 }
 
 /* ITON Nx, Iy */
@@ -425,7 +425,7 @@
 
 /* SET Sx, CONSTANT */
 AUTO_OP set_s_sc {
-  STR_REG(P1) = PCONST(P2)->string;
+  STR_REG(P1) = STR_PCONST(P2);
 }
 
 /* PRINT Sx */
@@ -436,7 +436,7 @@
 
 /* PRINT sc */
 AUTO_OP print_sc {
-  STRING *s = PCONST(P1)->string;
+  STRING *s = STR_PCONST(P1);
   IV l = string_length(s);
   printf("%.*s",(int)l, (char *)s->bufstart);
 }
Index: interpreter.c
===================================================================
RCS file: /home/perlcvs/parrot/interpreter.c,v
retrieving revision 1.20
diff -u -r1.20 interpreter.c
--- interpreter.c       2001/09/26 18:13:50     1.20
+++ interpreter.c       2001/10/01 03:25:53
@@ -30,8 +30,8 @@
         const char * fp_data;
         IV           fp_len;
 
-        fp_data = PCONST(0)->string->bufstart;
-        fp_len  = PCONST(0)->string->buflen;
+        fp_data = STR_PCONST(0)->bufstart;
+        fp_len  = STR_PCONST(0)->buflen;
         
         if (strncmp(OPCODE_FINGERPRINT, fp_data, fp_len)) {
             fprintf(stderr, "Error: Opcode table fingerprint in bytecode does not 
match interpreter!\n");
Index: include/parrot/interpreter.h
===================================================================
RCS file: /home/perlcvs/parrot/include/parrot/interpreter.h,v
retrieving revision 1.5
diff -u -r1.5 interpreter.h
--- include/parrot/interpreter.h        2001/09/26 18:13:50     1.5
+++ include/parrot/interpreter.h        2001/10/01 03:25:53
@@ -47,6 +47,10 @@
 #define PCONST(i) PF_CONST(interpreter->code, (i))
 #define PNCONST   PF_NCONST(interpreter->code)
 
+#define INT_PCONST(i) PFC_INT(PCONST(i))
+#define NUM_PCONST(i) PFC_NUM(PCONST(i))
+#define STR_PCONST(i) PFC_STR(PCONST(i))
+
 struct Parrot_Interp *
 make_interpreter();
 
Index: include/parrot/packfile.h
===================================================================
RCS file: /home/perlcvs/parrot/include/parrot/packfile.h,v
retrieving revision 1.4
diff -u -r1.4 packfile.h
--- include/parrot/packfile.h   2001/09/30 20:25:24     1.4
+++ include/parrot/packfile.h   2001/10/01 03:25:53
@@ -25,6 +25,10 @@
 #define PFC_NUMBER  'n'
 #define PFC_STRING  's'
 
+#define PFC_INT(pfc) (pfc)->integer
+#define PFC_NUM(pfc) (pfc)->number
+#define PFC_STR(pfc) (pfc)->string
+
 struct PackFile_Constant {
     IV       type;
     IV       integer;

Reply via email to