rev 591 - in trunk: pr/test src

SVN User <[email protected]> Thu, 10 Jun 2004 01:03:06 -0400
Newsgroups gmane.comp.lang.prothon.cvs
Message-ID <[email protected]>
Author: mark
Date: 2004-06-10 01:03:03 -0400 (Thu, 10 Jun 2004)
New Revision: 591

Modified:
   trunk/pr/test/test.pr
   trunk/src/builtins-int.c
Log:
fixed bug in long format

Modified: trunk/pr/test/test.pr
===================================================================
--- trunk/pr/test/test.pr	2004-06-10 04:40:50 UTC (rev 590)
+++ trunk/pr/test/test.pr	2004-06-10 05:03:03 UTC (rev 591)
@@ -1,16 +1,43 @@
 #!/usr/bin/env prothon
 
-def hex(n):
-    s = ""
-    while n:
-        d = n & 0xf
-        n = n >> 4
-        if d < 10: s = ('0'.ord()+d).chr()    + s
-        else:      s = ('a'.ord()+d-10).chr() + s
-    return s
-   
-print hex(0x100)
-   
-n=0x0123456789abcdef
+def err(n):
+	print 'error', n
+	Sys.exit(1)
 
-print hex(n & 0x0f0f0f0f0f0f0f0f)
+x = 1
+if x != 1: err(0)
+	
+for i in 200:
+	x *= 2
+
+y = 2**200
+
+if x != y: 
+	print 'x:',x
+	print 'y:',y
+	err(1)
+if x != 1606938044258990275541962092341162602522202993782792835301376:
+	err(2)
+
+for i in 200:
+	x //=2
+
+if x != 1: err(3)
+
+x = 254373265453637
+if -(823 * 2134 + 3184536 - 42312 % 311) | 19234567 & 149578376456 != -4915202:
+	err(4)
+
+if -(8211442569234385238487474353 * 212847346352034947352764 + 31842289378376456945234123236
+        - 44872283873746635434256223262312 % 3387611
+        ) | 192328437462345263464564567 & 1495728438374645645346368376456 != 
+				-1747783760583674902504339775785929746473575241492788:
+	err(5)
+
+y = 1002003004005006007008009000100200300400500600700800900
+print """
+--- All tests passed ---
+
+The following should match:
+1002003004005006007008009000100200300400500600700800900"""
+print y
\ No newline at end of file

Modified: trunk/src/builtins-int.c
===================================================================
--- trunk/src/builtins-int.c	2004-06-10 04:40:50 UTC (rev 590)
+++ trunk/src/builtins-int.c	2004-06-10 05:03:03 UTC (rev 591)
@@ -545,7 +545,7 @@
 	obj_p str;
 	int i;
 	const int size_a = abs(a->dsize);
-	char *p;
+	char *p, *strp;
 	int bits;
 	char sign = '\0';
 
@@ -559,10 +559,9 @@
 		i >>= 1;
 	}
 	i = 5 + (addL ? 1 : 0) + (size_a*SHIFT + bits-1) / bits;
-	str = new_string_n_obj(ist, "", i);
-	if (str == NULL)
-		return NULL;
-	p = pr2c_strptr(ist, str) + i;
+	strp = pr_malloc(i+1);
+	strp[i] = 0;
+	p = strp + i;
     if (addL)
         *--p = 'L';
 	if (a->dsize < 0)
@@ -587,7 +586,7 @@
 			do {
 				char cdigit = (char)(accum & (base - 1));
 				cdigit += (cdigit < 10) ? '0' : 'A'-10;
-				pr_assert(p > pr2c_strptr(ist, str));
+				pr_assert(p > strp);
 				*--p = cdigit;
 				accumbits -= basebits;
 				accum >>= basebits;
@@ -616,7 +615,7 @@
 		/* Get a scratch area for repeated division. */
 		scratch = new_longp_non_init(dsize);
 		if (scratch == NULL) {
-			pr_free(str);
+			pr_free(strp);
 			return NULL;
 		}
 
@@ -630,7 +629,7 @@
 				--dsize;
 			SIGCHECK({
 				pr_free(scratch);
-				pr_free(str);
+				pr_free(strp);
 				return NULL;
 			})
 
@@ -639,7 +638,7 @@
 			do {
 				digit nextrem = (digit)(rem / base);
 				char c = (char)(rem - nextrem * base);
-				pr_assert(p > pr2c_strptr(ist, str));
+				pr_assert(p > strp);
 				c += (c < 10) ? '0' : 'A'-10;
 				*--p = c;
 				rem = nextrem;
@@ -668,13 +667,15 @@
 	}
 	if (sign)
 		*--p = sign;
-	if (p != pr2c_strptr(ist, str)) {
-		char *q = pr2c_strptr(ist, str);
+	if (p != strp) {
+		char *q = strp;
 		pr_assert(p > q);
 		do {
 		} while ((*q++ = *p++) != '\0');
 	}
-	return NEW_STRING(pr2c_strptr(ist, str));
+	str = NEW_STRING(strp);
+	pr_free(strp);
+	return str;
 }
 
 /* *str points to the first digit in a string of base base digits. base