rev 702 - in trunk: include/prothon src

SVN User <[email protected]> Sun, 04 Jul 2004 20:12:06 -0400
Newsgroups gmane.comp.lang.prothon.cvs
Message-ID <[email protected]>
Author: mark
Date: 2004-07-04 20:12:02 -0400 (Sun, 04 Jul 2004)
New Revision: 702

Modified:
   trunk/include/prothon/prothon.h
   trunk/src/builtins-int.c
   trunk/src/builtins-string.c
Log:
added cmp for ints and strings

Modified: trunk/include/prothon/prothon.h
===================================================================
--- trunk/include/prothon/prothon.h	2004-07-04 23:40:27 UTC (rev 701)
+++ trunk/include/prothon/prothon.h	2004-07-05 00:12:02 UTC (rev 702)
@@ -98,9 +98,9 @@
 #endif
 
 //************************* SOME APPLICATION TUNING ***************************
-#define AS_STR_MAX_DEPTH 8
+#define AS_STR_MAX_DEPTH	8
+#define MAX_UNICODE_VALUE	0x10ffff
 
-
 //************************* BASIC TYPE DEFINITIONS ****************************
 
 typedef signed char			i8_t;

Modified: trunk/src/builtins-int.c
===================================================================
--- trunk/src/builtins-int.c	2004-07-04 23:40:27 UTC (rev 701)
+++ trunk/src/builtins-int.c	2004-07-05 00:12:02 UTC (rev 702)
@@ -2054,7 +2054,7 @@
 	ch3_t ch3;
 	i32_t val;
 	val = int2i32t(ist, self);
-	if (val < 0 || val >= 0x10ffff) {
+	if (val < 0 || val >= MAX_UNICODE_VALUE) {
 		raise_exception( ist, OBJ(VALUE_EXC), 
 			             "integer value outside of unicode character range" );
 		return NULL;
@@ -2495,9 +2495,13 @@
 	return new_int_long_obj(ist, long_pow(ist, a, b, NULL));
 }
 
+#define ORD(ch3p) ((((((u32_t)(ch3p)->b2)<<8)|((ch3p)->b1))<<8)|((ch3p)->b0))
+
 DEF(Int, cmp_, FORM_RPARAM){
 	obj_p other = parms[1];
 	BIN_CONTENT_CHK(Int);
+	if (has_proto(ist, other, OBJ(STRING_PROTO)) && pr_strlen(other) == 1)
+		other = NEW_INT(ORD(pr_ch3ptr(other)));
 	if (!is_Int(other)) {
 		if (covers(other, self))
 			return call_func1(ist, other, SYM(RCMP_), self);

Modified: trunk/src/builtins-string.c
===================================================================
--- trunk/src/builtins-string.c	2004-07-04 23:40:27 UTC (rev 701)
+++ trunk/src/builtins-string.c	2004-07-05 00:12:02 UTC (rev 702)
@@ -498,6 +498,18 @@
 	BIN_CONTENT_CHK(String);
 	if (self == other)
 		return NEW_INT(0);
+	if (has_proto(ist, other, OBJ(INT_PROTO)) && pr_strlen(self) == 1) {
+		i32_t ival = int2i32t(ist, other); if_exc_return NULL;
+		if (ival < 0 || ival > MAX_UNICODE_VALUE) {
+			raise_exception( ist, OBJ(VALUE_EXC), 
+			                 "integer value outside of unicode character range" );
+		    return NULL;
+		}
+		sptr = pr_ch3ptr(self);
+		if (ORD(sptr) < (u32_t) ival) return NEW_INT(-1);
+		if (ORD(sptr) > (u32_t) ival) return NEW_INT(+1);
+		return NEW_INT(0);
+	}
 	if (!IS_STRING(other)) {
 		raise_exception(ist, OBJ(TYPE_EXC), "Cannot compare a string and non-string");
 		return NULL;