rev 590 - in trunk: . pr/test src

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

Modified:
   trunk/STATUS.txt
   trunk/pr/test/dbm.pr
   trunk/pr/test/test.pr
   trunk/src/builtins-string.c
Log:
fixed ord()

Modified: trunk/STATUS.txt
===================================================================
--- trunk/STATUS.txt	2004-06-10 03:53:50 UTC (rev 589)
+++ trunk/STATUS.txt	2004-06-10 04:40:50 UTC (rev 590)
@@ -22,7 +22,7 @@
 
 --- import (string variable)
 
---- support long ints in prosist
+--- support long ints & Bytes in dbm & prosist
 
 --- Swig and/or other (what GTK port used?) backend
 

Modified: trunk/pr/test/dbm.pr
===================================================================
--- trunk/pr/test/dbm.pr	2004-06-10 03:53:50 UTC (rev 589)
+++ trunk/pr/test/dbm.pr	2004-06-10 04:40:50 UTC (rev 590)
@@ -10,7 +10,7 @@
 	print 'err1'
 	Sys.exit(1)
 	
-db.store('a', 'abc' + 0.chr() + 'def')
+db.store('a', 'abcdef')
 db.store('c', 'xyz')
 db.store('b', '')
 
@@ -18,7 +18,7 @@
 	print 'err2'
 	Sys.exit(1)
 	
-if db.fetch('a') != 'abc' + 0.chr() + 'def':
+if db.fetch('a') != 'abcdef':
 	print 'err3'
 	Sys.exit(1)
 	

Modified: trunk/pr/test/test.pr
===================================================================
--- trunk/pr/test/test.pr	2004-06-10 03:53:50 UTC (rev 589)
+++ trunk/pr/test/test.pr	2004-06-10 04:40:50 UTC (rev 590)
@@ -1,6 +1,16 @@
 #!/usr/bin/env prothon
 
-def f1(x=''):
-	print 'f1 '+x
-	
-g = Func(f1)
+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
+
+print hex(n & 0x0f0f0f0f0f0f0f0f)

Modified: trunk/src/builtins-string.c
===================================================================
--- trunk/src/builtins-string.c	2004-06-10 03:53:50 UTC (rev 589)
+++ trunk/src/builtins-string.c	2004-06-10 04:40:50 UTC (rev 590)
@@ -134,7 +134,7 @@
 		ch3p      = strp->str;
 	} else {
 		raise_exception(ist, OBJ(VALUE_EXC), "string object uninitialized");
-		return NULL;
+		return "";
 	}
 	len = data_size/3;
 	res = pr_malloc(len+1);
@@ -142,7 +142,7 @@
 		res[i] = (char) ch3p[i].b0;
 		if (!ch3p[i].b0 || ch3p[i].b0 > 127 || ch3p[i].b1 || ch3p[i].b2) {
 			raise_exception(ist, OBJ(VALUE_EXC), "string has non-ascii value");
-			return NULL;
+			return "";
 		}
 	}
 	res[i] = 0;
@@ -387,7 +387,10 @@
 		raise_exception(ist, OBJ(VALUE_EXC), "ord not valid on empty string");
 		return NULL;
 	}
-	ch3p = ((str_p)self->data.ptr)->str;
+	if (self->data_type == DATA_TYPE_IMMDATA)
+		ch3p = self->data.str;
+	else
+		ch3p = ((str_p)self->data.ptr)->str;
 	return NEW_INT(ch3p->b0+((ch3p->b1+(ch3p->b2*256))*256));
 }