# New Ticket Created by  Steve Fink 
# Please include the string:  [perl #16856]
# in the subject line of all future correspondence about this issue. 
# <URL: http://rt.perl.org/rt2/Ticket/Display.html?id=16856 >


I was once idly toying with imcc while awaiting a phone call. This is
the completely untested result.

 - Adds the CONSERVATIVE_POINTER_CHASING definition to anyop.c, because
   anyop includes the parrot .h files and at one point didn't seem to
   be linking with libparrot, so I couldn't compile it if GC_DEBUG was
   on. However, t/src at one point was behaving the same way and isn't
   anymore, so I don't know if this is needed now.

 - Adds %option nounput to imcc.l. This avoids a warning when
   compiling the output file. This one is correct, at least.

 - An attempt to improve the speed and correctness of set_make_full,
   set_copy, and set_equal in sets.c. A good idea, but wholly
   untested.


-- attachment  1 ------------------------------------------------------
url: http://rt.perl.org/rt2/attach/36046/29169/7ccbfb/imcc-various.patch

? languages/imcc/Makefile.tmp
Index: languages/imcc/anyop.c
===================================================================
RCS file: /cvs/public/parrot/languages/imcc/anyop.c,v
retrieving revision 1.3
diff -p -u -r1.3 anyop.c
--- languages/imcc/anyop.c      27 Aug 2002 06:48:44 -0000      1.3
+++ languages/imcc/anyop.c      29 Aug 2002 20:05:25 -0000
@@ -9,6 +9,10 @@ static int lastdl_handle = 1;
 static struct Oplib oplibs[16];
 static int lastlib = 0;
 
+#if GC_DEBUG
+int CONSERVATIVE_POINTER_CHASING = 0;
+#endif
+
 op_t NULLOP = { -1, -1 };
 
 int
Index: languages/imcc/imcc.l
===================================================================
RCS file: /cvs/public/parrot/languages/imcc/imcc.l,v
retrieving revision 1.10
diff -p -u -r1.10 imcc.l
--- languages/imcc/imcc.l       27 Aug 2002 14:09:00 -0000      1.10
+++ languages/imcc/imcc.l       29 Aug 2002 20:05:25 -0000
@@ -22,6 +22,7 @@ int yyerror(char *);
 %}
 
 %option outfile="imclexer.c"
+%option nounput
 
 LETTER          [a-zA-Z_]
 DIGIT           [0-9]
Index: languages/imcc/sets.c
===================================================================
RCS file: /cvs/public/parrot/languages/imcc/sets.c,v
retrieving revision 1.2
diff -p -u -r1.2 sets.c
--- languages/imcc/sets.c       7 Aug 2002 03:23:42 -0000       1.2
+++ languages/imcc/sets.c       29 Aug 2002 20:05:32 -0000
@@ -12,14 +12,10 @@ Set* set_make (int length) {
 
 Set* set_make_full (int length) {
        Set *s = malloc(sizeof(Set));
-       int i;
 
        s->length = length;
        s->bmp = malloc(sizeof(char) * (length/8 + 1));
-
-       for (i=0; i < (length/8) + 1; i++) {
-               s->bmp[i] = 255;
-       }
+        memset(s->bmp, 0xff, length/8 + 1);
 
        return s;
 }
@@ -30,33 +26,35 @@ void set_free (Set *s) {
 }
 
 Set* set_copy (Set *s1) {
-       int i;
        Set *s = malloc(sizeof(Set));
+
        s->length = s1->length;
        s->bmp = malloc( sizeof(char) * (s->length/8 + 1));
-
-       for (i=0; i < (s->length/8); i++) {
-               s->bmp[i] = s1->bmp[i];
-       }
+        memcpy(s->bmp, s1->bmp, (s->length+1)/8);
 
        return s;
 }
 
 
 int set_equal (Set *s1, Set *s2) {
-       int i;
+    int mask;
        
-       if (s1->length != s2->length) {
-               fprintf(stderr, "INTERNAL ERROR: Sets don't have the same length in 
set_equal!\n");
-       }
-
-       for (i=0; i < (s1->length/8); i++) {
-               if (s1->bmp[i] != s2->bmp[i]) { return 0; };
-       }
-
-       /* bug here: the tail of the bitmap is not compared */
+    if (s1->length != s2->length) {
+        fprintf(stderr, "INTERNAL ERROR: Sets don't have the same length in 
+set_equal!\n");
+    }
+
+    if (memcmp(s1->bmp, s2->bmp, s1->length / 8) != 0)
+        return 0;
+
+    if (s1->length % 8 == 0)
+        return 1;
+
+    /* Have a partial tail. */
+    mask = (1 << (s1->length % 8)) - 1;
+    if ((s1->bmp[s1->length / 8] & mask) != (s2->bmp[s1->length / 8] & mask))
+        return 0;
 
-       return 1;
+    return 1;
 }
 
 void set_add (Set *s, int element) {

Reply via email to