On Tue, 1 Oct 2002, Brent Dax wrote:

> Andy Dougherty:
> # > *elbows him in the side and points at 
> # /Parrot_v?sn?printf(_[sc])?/ in
> # > misc.c*
> # 
> # Interesting, yes, that's mostly what I had in mind, but I'm 
> # unsure just how it's intended to be used.[*] That is, if I have
> # 
> #     INTVAL iv = 7;
> # 
> # what format do I use to print it?  Is it the intent that 
> 
> %vd, I believe.
> 
> # As a side note, I see that misc.c currently seems to assume that
> # sizeof(long) >= sizeof(INTVAL), so I'll need to patch that up 
> # anyway, but at the moment, I'm unclear even as to intention.
> 
> It was my intent that HUGEINTVAL be the largest integer the machine
> supports, detected by Configure.  However, I never got around to adding
> that in.

Here's a patch that makes misc.c work that way. (This does not fix the
original trace.c problem at the beginning of this thread.  trace.c still
needs to be patched.  My original patch is fine for now.)

Also, would it be ok to add some more wrapper functions to
misc.c?  In particular, is it ok to use stdio-isms (mindful that they
will later be replaced with ParrotIO-isms)?  I'm looking to replace 
existing print statements like (from trace.c)

    fprintf(stderr, "PC=%ld; OP=%ld (%s)", 
                    (long)(pc - code_start), (long) *pc,
                    interpreter->op_info_table[*pc].full_name)));

with something much less verbose than

    fprintf(stderr, 
            string_to_cstring(interpreter,
                Parrot_sprintf_c(interpreter,
                "PC=%vd; OP=%vd (%s)", 
                    (INTVAL)(pc - code_start), (INTVAL) *pc,
                    interpreter->op_info_table[*pc].full_name)));


--- parrot-orig/misc.c  Thu Sep 26 08:35:09 2002
+++ parrot-andy/misc.c  Mon Oct  7 11:30:59 2002
@@ -14,8 +14,16 @@
 
 #include <stdarg.h>
 
+/* HUGEINTVAL is an integral type long enough to hold anything that
+   might get handed to our printf routine.
+*/
+#if INTVAL_SIZE > LONG_SIZE /* INTVAL might be long long */
+typedef INTVAL HUGEINTVAL;
+typedef UINTVAL UHUGEINTVAL;
+#else
 typedef long HUGEINTVAL;
 typedef unsigned long UHUGEINTVAL;
+#endif
 
 typedef struct spfinfo_t {
     UINTVAL flags;
@@ -41,11 +49,10 @@
 #define FLAG_SPACE  8
 #define FLAG_SHARP  16
 
-#define SIZE_REG    0
+#define SIZE_REG    0  /* Regular integer */
 #define SIZE_SHORT  1
 #define SIZE_LONG   2
-#define SIZE_HUGE   3
-#define SIZE_XVAL   4
+#define SIZE_XVAL   3  /* a Parrot INTVAL or UINTVAL */
 
 #define GetInt(targ, whichone)                                               \
     switch(whichone) {                                                       \
@@ -58,9 +65,6 @@
         case SIZE_LONG:                                                      \
             targ=(HUGEINTVAL)(long)va_arg(*args, long);                      \
             break;                                                           \
-        case SIZE_HUGE:                                                      \
-            targ=(HUGEINTVAL)(long /*long*/)va_arg(*args, long /*long*/);    \
-            break;                                                           \
         case SIZE_XVAL:                                                      \
             targ=(HUGEINTVAL)(INTVAL)va_arg(*args, INTVAL);                  \
             break;                                                           \
@@ -77,9 +81,6 @@
         case SIZE_LONG:                                                      \
             targ=(UHUGEINTVAL)(unsigned long)va_arg(*args, unsigned long);   \
             break;                                                           \
-        case SIZE_HUGE:                                                      \
-            targ=(UHUGEINTVAL)(unsigned long /*long*/)va_arg(*args, unsigned long 
/*long*/); \
-            break;                                                           \
         case SIZE_XVAL:                                                      \
             targ=(UHUGEINTVAL)(UINTVAL)va_arg(*args, UINTVAL);               \
             break;                                                           \
@@ -92,7 +93,7 @@
 void gen_sprintf_call(char *, char *, SpfInfo, char);
 
 static void
-uint_to_str(char *buf1, char *buf2, UHUGEINTVAL num, char base)
+uint_to_str(char *buf1, char *buf2, UHUGEINTVAL num, int base)
 {
     int i = 0, cur2;
     char cur;
@@ -118,7 +119,7 @@
 }
 
 static void
-int_to_str(char *buf1, char *buf2, HUGEINTVAL num, char base)
+int_to_str(char *buf1, char *buf2, HUGEINTVAL num, int base)
 {
     INTVAL neg;
     int i = 0, cur2;
@@ -335,10 +336,6 @@
                             info.type = SIZE_LONG;
                             continue;
 
-                        case 'H':
-                            info.type = SIZE_HUGE;
-                            continue;
-
                         case 'v':
                             info.type = SIZE_XVAL;
                             continue;
@@ -387,7 +384,7 @@
 
                         case 'p':
                             chptr = va_arg(*args, void *);
-                            int_to_str(t1, t2, (HUGEINTVAL)chptr, 16);
+                            int_to_str(t1, t2, PTR2UINTVAL(chptr), 16);
                             targ = string_concat(interpreter, targ,
                                                  cstr2pstr(t1), 0);
                             break;

Reply via email to