Re: [PATCH] - migrate encodings to UINTVAL

2001-12-31 Thread Bryan C. Warnock

On Monday 31 December 2001 11:57 pm, Boris Tschirschwitz wrote:
> I really don't see what UINTVALS are good for.

Here are reflections on my stance
http:[EMAIL PROTECTED]/msg06913.html

> I wonder if making the interpreter so much bigger (with all the
> unsigned counterparts of int arithmetic functions) just for being able to
> use native ints instead of bigints a little longer (*2) wouldn't cost more
> than it gains.

That's not what they are used for.  Ops involving generic numbers (like 
adding two numbers) will always be done with signed values.  Anything larger 
than 31/63 bits will use a BIGINT PMC.  Ops involving fixed, unsigned 
internal entities - like string sizes - will either be coded as such, or be 
cast appropriately.  So we shouldn't have two versions of anything.

> If it is for type checking, I doubt that Parrot is the place to worry
> about types, that ought to be done in the language compiled down to
> parrot.

Internal type checking is one reason, yes.  It's supposed to be an 
extra-level of protection, but I'm sure there are a myriad examples of where 
we'll still go wrong.  The occasional bit-shifting (with masks, etc) also 
need protection from high-bit propogation.

> For optimization issues, an optimizer should either check the high level
> source or, perhaps preferrable, the compiler could write an extra file
> with more language independent optimization hints to be used by an
> optimizer, when optimization is required.

-- 
Bryan C. Warnock
[EMAIL PROTECTED]



Re: [PATCH] - migrate encodings to UINTVAL

2001-12-31 Thread Boris Tschirschwitz

I really don't see what UINTVALS are good for.
I wonder if making the interpreter so much bigger (with all the
unsigned counterparts of int arithmetic functions) just for being able to
use native ints instead of bigints a little longer (*2) wouldn't cost more
than it gains.
If it is for type checking, I doubt that Parrot is the place to worry
about types, that ought to be done in the language compiled down to
parrot.
For optimization issues, an optimizer should either check the high level
source or, perhaps preferrable, the compiler could write an extra file
with more language independent optimization hints to be used by an
optimizer, when optimization is required.

Boris.

--
Boris Tschirschwitz
University of British Columbia
Mathematics Department
email: [EMAIL PROTECTED]


On Mon, 31 Dec 2001, David & Lisa Jacobs wrote:

> I have a LOT of changes I want to make with respect to unsigned ints.  The
> net result will be fewer warnings along with lower chance of errors.  To
> keep from getting out of sync with everyone I'm going to break it into as
> small pieces as I can.  Unfortunately, this made lead to a few extra
> warnings while related pieces are waiting to be checked in.  I will make
> sure that no individual patch fails the test suite.
>
> So here is the first one.  The encodings have been changed the strings file
> will be in a separate patch.
>
> David
>
> Index: encodings/singlebyte.c
> ===
> RCS file: /cvs/public/parrot/encodings/singlebyte.c,v
> retrieving revision 1.6
> diff -c -r1.6 singlebyte.c
> *** encodings/singlebyte.c 30 Dec 2001 12:04:56 - 1.6
> --- encodings/singlebyte.c 1 Jan 2002 04:05:25 -
> ***
> *** 14,25 
>
>   typedef unsigned char byte_t;
>
> ! static INTVAL
> ! singlebyte_characters (const void *ptr, INTVAL bytes) {
>   return bytes;
>   }
>
> ! static INTVAL
>   singlebyte_decode (const void *ptr) {
>   const byte_t *bptr = ptr;
>
> --- 14,25 
>
>   typedef unsigned char byte_t;
>
> ! static UINTVAL
> ! singlebyte_characters (const void *ptr, UINTVAL bytes) {
>   return bytes;
>   }
>
> ! static UINTVAL
>   singlebyte_decode (const void *ptr) {
>   const byte_t *bptr = ptr;
>
> ***
> *** 27,33 
>   }
>
>   static void *
> ! singlebyte_encode (void *ptr, INTVAL c) {
>   byte_t *bptr = ptr;
>
>   if (c < 0 || c > 255) {
> --- 27,33 
>   }
>
>   static void *
> ! singlebyte_encode (void *ptr, UINTVAL c) {
>   byte_t *bptr = ptr;
>
>   if (c < 0 || c > 255) {
> ***
> *** 41,54 
>   }
>
>   static void *
> ! singlebyte_skip_forward (const void *ptr, INTVAL n) {
>   byte_t *bptr = (byte_t*)ptr;
>
>   return bptr + n;
>   }
>
>   static void *
> ! singlebyte_skip_backward (const void *ptr, INTVAL n) {
>   byte_t *bptr = (byte_t*)ptr;
>
>   return bptr - n;
> --- 41,54 
>   }
>
>   static void *
> ! singlebyte_skip_forward (const void *ptr, UINTVAL n) {
>   byte_t *bptr = (byte_t*)ptr;
>
>   return bptr + n;
>   }
>
>   static void *
> ! singlebyte_skip_backward (const void *ptr, UINTVAL n) {
>   byte_t *bptr = (byte_t*)ptr;
>
>   return bptr - n;
> Index: encodings/utf16.c
> ===
> RCS file: /cvs/public/parrot/encodings/utf16.c,v
> retrieving revision 1.5
> diff -c -r1.5 utf16.c
> *** encodings/utf16.c 30 Dec 2001 12:04:56 - 1.5
> --- encodings/utf16.c 1 Jan 2002 04:05:26 -
> ***
> *** 17,27 
>   typedef unsigned short utf16_t;
>   #endif
>
> ! static INTVAL
> ! utf16_characters (const void *ptr, INTVAL bytes) {
>   const utf16_t *u16ptr = ptr;
>   const utf16_t *u16end = u16ptr + bytes / sizeof(utf16_t);
> ! INTVAL characters = 0;
>
>   while (u16ptr < u16end) {
>   u16ptr += UTF16SKIP(u16ptr);
> --- 17,27 
>   typedef unsigned short utf16_t;
>   #endif
>
> ! static UINTVAL
> ! utf16_characters (const void *ptr, UINTVAL bytes) {
>   const utf16_t *u16ptr = ptr;
>   const utf16_t *u16end = u16ptr + bytes / sizeof(utf16_t);
> ! UINTVAL characters = 0;
>
>   while (u16ptr < u16end) {
>   u16ptr += UTF16SKIP(u16ptr);
> ***
> *** 35,44 
>   return characters;
>   }
>
> ! static INTVAL
>   utf16_decode (const void *ptr) {
>   const utf16_t *u16ptr = ptr;
> ! INTVAL c = *u16ptr++;
>
>   if (UNICODE_IS_HIGH_SURROGATE(c)) {
>   utf16_t low = *u16ptr++;
> --- 35,44 
>   return characters;
>   }
>
> ! static UINTVAL
>   utf16_decode (const void *ptr) {
>   const utf16_t *u16ptr = ptr;
> ! UINTVAL c = *u16ptr++;
>
>   if (UNICODE_IS_HIGH_SURROGATE(c)) {
>   utf16_t low = *u16ptr++;
> ***
> *** 57,66 
>   }
>
>   static void *
> ! utf16_encode (void *ptr, INTVAL c) {
>   utf16_t *u16ptr = ptr;
>
> ! if (c < 0 || c > 0x10 || UNICODE_IS_SURROG

Re: [PATCH] - migrate encodings to UINTVAL

2001-12-31 Thread Bryan C. Warnock

On Monday 31 December 2001 11:14 pm, David & Lisa Jacobs wrote:
{patch}

This patch merges changes I made in the same areas.


Index: encodings/singlebyte.c
===
RCS file: /home/perlcvs/parrot/encodings/singlebyte.c,v
retrieving revision 1.6
diff -u -r1.6 singlebyte.c
--- encodings/singlebyte.c  30 Dec 2001 12:04:56 -  1.6
+++ encodings/singlebyte.c  1 Jan 2002 04:40:27 -
@@ -14,12 +14,12 @@
 
 typedef unsigned char byte_t;
 
-static INTVAL
-singlebyte_characters (const void *ptr, INTVAL bytes) {
+static UINTVAL
+singlebyte_characters (const void *ptr, UINTVAL bytes) {
 return bytes;
 }
 
-static INTVAL
+static UINTVAL
 singlebyte_decode (const void *ptr) {
 const byte_t *bptr = ptr;
 
@@ -27,8 +27,8 @@
 }
 
 static void *
-singlebyte_encode (void *ptr, INTVAL c) {
-byte_t *bptr = ptr;
+singlebyte_encode (const void *ptr, UINTVAL c) {
+byte_t *bptr = (byte_t*)ptr;
 
 if (c < 0 || c > 255) {
 INTERNAL_EXCEPTION(INVALID_CHARACTER,
@@ -41,14 +41,14 @@
 }
 
 static void *
-singlebyte_skip_forward (const void *ptr, INTVAL n) {
+singlebyte_skip_forward (const void *ptr, UINTVAL n) {
 byte_t *bptr = (byte_t*)ptr;
 
 return bptr + n;
 }
 
 static void *
-singlebyte_skip_backward (const void *ptr, INTVAL n) {
+singlebyte_skip_backward (const void *ptr, UINTVAL n) {
 byte_t *bptr = (byte_t*)ptr;
 
 return bptr - n;
Index: encodings/utf16.c
===
RCS file: /home/perlcvs/parrot/encodings/utf16.c,v
retrieving revision 1.5
diff -u -r1.5 utf16.c
--- encodings/utf16.c   30 Dec 2001 12:04:56 -  1.5
+++ encodings/utf16.c   1 Jan 2002 04:40:28 -
@@ -17,11 +17,11 @@
 typedef unsigned short utf16_t;
 #endif
 
-static INTVAL
-utf16_characters (const void *ptr, INTVAL bytes) {
+static UINTVAL
+utf16_characters (const void *ptr, UINTVAL bytes) {
 const utf16_t *u16ptr = ptr;
 const utf16_t *u16end = u16ptr + bytes / sizeof(utf16_t);
-INTVAL characters = 0;
+UINTVAL characters = 0;
 
 while (u16ptr < u16end) {
 u16ptr += UTF16SKIP(u16ptr);
@@ -35,10 +35,10 @@
 return characters;
 }
 
-static INTVAL
+static UINTVAL
 utf16_decode (const void *ptr) {
 const utf16_t *u16ptr = ptr;
-INTVAL c = *u16ptr++;
+UINTVAL c = *u16ptr++;
 
 if (UNICODE_IS_HIGH_SURROGATE(c)) {
 utf16_t low = *u16ptr++;
@@ -57,8 +57,8 @@
 }
 
 static void *
-utf16_encode (void *ptr, INTVAL c) {
-utf16_t *u16ptr = ptr;
+utf16_encode (const void *ptr, UINTVAL c) {
+utf16_t *u16ptr = (utf16_t*)ptr;
 
 if (c < 0 || c > 0x10 || UNICODE_IS_SURROGATE(c)) {
 INTERNAL_EXCEPTION(INVALID_CHARACTER,
@@ -77,7 +77,7 @@
 }
 
 static void *
-utf16_skip_forward (const void *ptr, INTVAL n) {
+utf16_skip_forward (const void *ptr, UINTVAL n) {
 utf16_t *u16ptr = (utf16_t*)ptr;
 
 while (n-- > 0) {
@@ -100,7 +100,7 @@
 }
 
 static void *
-utf16_skip_backward (const void *ptr, INTVAL n) {
+utf16_skip_backward (const void *ptr, UINTVAL n) {
 utf16_t *u16ptr = (utf16_t*)ptr;
 
 while (n--> 0) {
Index: encodings/utf32.c
===
RCS file: /home/perlcvs/parrot/encodings/utf32.c,v
retrieving revision 1.2
diff -u -r1.2 utf32.c
--- encodings/utf32.c   30 Dec 2001 12:04:56 -  1.2
+++ encodings/utf32.c   1 Jan 2002 04:40:28 -
@@ -17,12 +17,12 @@
 typedef unsigned long utf32_t;
 #endif
 
-static INTVAL
-utf32_characters (const void *ptr, INTVAL bytes) {
+static UINTVAL
+utf32_characters (const void *ptr, UINTVAL bytes) {
 return bytes / 4;
 }
 
-static INTVAL
+static UINTVAL
 utf32_decode (const void *ptr) {
 const utf32_t *u32ptr = ptr;
 
@@ -30,8 +30,8 @@
 }
 
 static void *
-utf32_encode (void *ptr, INTVAL c) {
-utf32_t *u32ptr = ptr;
+utf32_encode (const void *ptr, UINTVAL c) {
+utf32_t *u32ptr = (utf32_t*)ptr;
 
 if (c < 0 || c > 0x10 || UNICODE_IS_SURROGATE(c)) {
 INTERNAL_EXCEPTION(INVALID_CHARACTER,
@@ -44,14 +44,14 @@
 }
 
 static void *
-utf32_skip_forward (const void *ptr, INTVAL n) {
+utf32_skip_forward (const void *ptr, UINTVAL n) {
 utf32_t *u32ptr = (utf32_t*)ptr;
 
 return u32ptr + n;
 }
 
 static void *
-utf32_skip_backward (const void *ptr, INTVAL n) {
+utf32_skip_backward (const void *ptr, UINTVAL n) {
 utf32_t *u32ptr = (utf32_t*)ptr;
 
 return u32ptr - n;
Index: encodings/utf8.c
===
RCS file: /home/perlcvs/parrot/encodings/utf8.c,v
retrieving revision 1.6
diff -u -r1.6 utf8.c
--- encodings/utf8.c31 Dec 2001 16:00:59 -  1.6
+++ encodings/utf8.c1 Jan 2002 04:40:28 -
@@ -28,11 +28,11 @@
 typedef unsigned char utf8_t;
 #endif
 
-static INTVAL
-utf8_characters (const void *ptr, INTVAL bytes) {
+static UINTVAL
+utf8_characters (const void *ptr, UINTVAL bytes) {
 const utf8_t *u8ptr = p

[PATCH] - migrate encodings to UINTVAL

2001-12-31 Thread David & Lisa Jacobs

I have a LOT of changes I want to make with respect to unsigned ints.  The
net result will be fewer warnings along with lower chance of errors.  To
keep from getting out of sync with everyone I'm going to break it into as
small pieces as I can.  Unfortunately, this made lead to a few extra
warnings while related pieces are waiting to be checked in.  I will make
sure that no individual patch fails the test suite.

So here is the first one.  The encodings have been changed the strings file
will be in a separate patch.

David

Index: encodings/singlebyte.c
===
RCS file: /cvs/public/parrot/encodings/singlebyte.c,v
retrieving revision 1.6
diff -c -r1.6 singlebyte.c
*** encodings/singlebyte.c 30 Dec 2001 12:04:56 - 1.6
--- encodings/singlebyte.c 1 Jan 2002 04:05:25 -
***
*** 14,25 

  typedef unsigned char byte_t;

! static INTVAL
! singlebyte_characters (const void *ptr, INTVAL bytes) {
  return bytes;
  }

! static INTVAL
  singlebyte_decode (const void *ptr) {
  const byte_t *bptr = ptr;

--- 14,25 

  typedef unsigned char byte_t;

! static UINTVAL
! singlebyte_characters (const void *ptr, UINTVAL bytes) {
  return bytes;
  }

! static UINTVAL
  singlebyte_decode (const void *ptr) {
  const byte_t *bptr = ptr;

***
*** 27,33 
  }

  static void *
! singlebyte_encode (void *ptr, INTVAL c) {
  byte_t *bptr = ptr;

  if (c < 0 || c > 255) {
--- 27,33 
  }

  static void *
! singlebyte_encode (void *ptr, UINTVAL c) {
  byte_t *bptr = ptr;

  if (c < 0 || c > 255) {
***
*** 41,54 
  }

  static void *
! singlebyte_skip_forward (const void *ptr, INTVAL n) {
  byte_t *bptr = (byte_t*)ptr;

  return bptr + n;
  }

  static void *
! singlebyte_skip_backward (const void *ptr, INTVAL n) {
  byte_t *bptr = (byte_t*)ptr;

  return bptr - n;
--- 41,54 
  }

  static void *
! singlebyte_skip_forward (const void *ptr, UINTVAL n) {
  byte_t *bptr = (byte_t*)ptr;

  return bptr + n;
  }

  static void *
! singlebyte_skip_backward (const void *ptr, UINTVAL n) {
  byte_t *bptr = (byte_t*)ptr;

  return bptr - n;
Index: encodings/utf16.c
===
RCS file: /cvs/public/parrot/encodings/utf16.c,v
retrieving revision 1.5
diff -c -r1.5 utf16.c
*** encodings/utf16.c 30 Dec 2001 12:04:56 - 1.5
--- encodings/utf16.c 1 Jan 2002 04:05:26 -
***
*** 17,27 
  typedef unsigned short utf16_t;
  #endif

! static INTVAL
! utf16_characters (const void *ptr, INTVAL bytes) {
  const utf16_t *u16ptr = ptr;
  const utf16_t *u16end = u16ptr + bytes / sizeof(utf16_t);
! INTVAL characters = 0;

  while (u16ptr < u16end) {
  u16ptr += UTF16SKIP(u16ptr);
--- 17,27 
  typedef unsigned short utf16_t;
  #endif

! static UINTVAL
! utf16_characters (const void *ptr, UINTVAL bytes) {
  const utf16_t *u16ptr = ptr;
  const utf16_t *u16end = u16ptr + bytes / sizeof(utf16_t);
! UINTVAL characters = 0;

  while (u16ptr < u16end) {
  u16ptr += UTF16SKIP(u16ptr);
***
*** 35,44 
  return characters;
  }

! static INTVAL
  utf16_decode (const void *ptr) {
  const utf16_t *u16ptr = ptr;
! INTVAL c = *u16ptr++;

  if (UNICODE_IS_HIGH_SURROGATE(c)) {
  utf16_t low = *u16ptr++;
--- 35,44 
  return characters;
  }

! static UINTVAL
  utf16_decode (const void *ptr) {
  const utf16_t *u16ptr = ptr;
! UINTVAL c = *u16ptr++;

  if (UNICODE_IS_HIGH_SURROGATE(c)) {
  utf16_t low = *u16ptr++;
***
*** 57,66 
  }

  static void *
! utf16_encode (void *ptr, INTVAL c) {
  utf16_t *u16ptr = ptr;

! if (c < 0 || c > 0x10 || UNICODE_IS_SURROGATE(c)) {
  INTERNAL_EXCEPTION(INVALID_CHARACTER,
 "Invalid character for UTF-16 encoding\n");
  }
--- 57,66 
  }

  static void *
! utf16_encode (void *ptr, UINTVAL c) {
  utf16_t *u16ptr = ptr;

! if (c > 0x10 || UNICODE_IS_SURROGATE(c)) {
  INTERNAL_EXCEPTION(INVALID_CHARACTER,
 "Invalid character for UTF-16 encoding\n");
  }
***
*** 77,83 
  }

  static void *
! utf16_skip_forward (const void *ptr, INTVAL n) {
  utf16_t *u16ptr = (utf16_t*)ptr;

  while (n-- > 0) {
--- 77,83 
  }

  static void *
! utf16_skip_forward (const void *ptr, UINTVAL n) {
  utf16_t *u16ptr = (utf16_t*)ptr;

  while (n-- > 0) {
***
*** 100,106 
  }

  static void *
! utf16_skip_backward (const void *ptr, INTVAL n) {
  utf16_t *u16ptr = (utf16_t*)ptr;

  while (n--> 0) {
--- 100,106 
  }

  static void *
! utf16_skip_backward (const void *ptr, UINTVAL n) {
  utf16_t *u16ptr = (utf16_t*)ptr;

  while (n--> 0) {
Index: encodings/utf32.c
=