changeset 106:439db471f595

Merge
author Mike Pavone <pavone@retrodev.com>
date Tue, 24 Aug 2010 23:22:45 -0400
parents 43cc42df26cc (current diff) 2d2da148d844 (diff)
children e5627038b7e7 336da6ce8174 13dfe8214254
files runtime/array.c runtime/array.h string.rhope
diffstat 3 files changed, 69 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/runtime/array.c	Tue Aug 24 23:22:17 2010 -0400
+++ b/runtime/array.c	Tue Aug 24 23:22:45 2010 -0400
@@ -187,4 +187,8 @@
 	release_ref((object *)bp);
 }
 
+int32_t _internal_memcmp_offset(void * left, int32_t loff, void * right, int32_t roff, int32_t len)
+{
+	return memcmp(((char *)left)+loff, ((char *)right)+roff, len);
+}
 
--- a/runtime/array.h	Tue Aug 24 23:22:17 2010 -0400
+++ b/runtime/array.h	Tue Aug 24 23:22:45 2010 -0400
@@ -14,6 +14,7 @@
 object *_internal_array_allocboxedcopy(object * osource, int32_t size);
 object * _internal_array_allocnaked(int32_t size , object * type);
 object * _internal_array_allocnakedcopy(object * osource, int32_t size);
+int32_t _internal_memcmp_offset(void * left, int32_t loff, void * right, int32_t roff, int32_t len);
 void internalarrayboxedcopy(object * obj);
 void internalarraynakedcopy(object * obj);
 void internalarrayboxedcleanup(object * obj);
--- a/string.rhope	Tue Aug 24 23:22:17 2010 -0400
+++ b/string.rhope	Tue Aug 24 23:22:45 2010 -0400
@@ -460,17 +460,7 @@
 {
 	[left]Byte[index]
 	{
-		rbyte <- [right]Byte[index] {}
-		{
-			Print[["Could not fetch byte from right string at offset:"]Append[String[index]]]
-			{ Print[["Right string has type ID: "]Append[ String[ID[Blueprint Of[right]]] ]]
-			{ Print[[right]Byte Length] 
-			{ Print[[right]Length]
-			{ Print[["Left string has type ID: "]Append[ String[ID[Blueprint Of[left]]] ]]
-			{ Print[[left]Byte Length] 
-			{ Print[[left]Length] }}}}}}
-			out <- No
-		}
+		rbyte <- [right]Byte[index]
 		,out <- If[[~]=[rbyte]]
 		{
 			out <- _=String[left,right,[index]+[1]]
@@ -488,9 +478,50 @@
 	}
 }
 
+Foreign C:libc
+{
+	memcmp[a(Array,Raw Pointer),b(Array,Raw Pointer),len(Int64,Naked):out(Int32,Naked)]
+}
+
+Foreign C:runtime
+{
+	_internal_memcmp_offset[left(Array,Raw Pointer),loffset(Int32,Naked),right(Array,Raw Pointer),roffset(Int32,Naked),len(Int32,Naked):out(Int32,Naked)]
+}
+
+_Flat=@String[left,right:out]
+{
+	,out <- If[[[left]Byte Length] = [[right]Byte Length]]
+	{
+		If[memcmp[[left]Buffer >>, [right]Buffer >>, Int64[[left]Byte Length]]]
+		{
+			out <- No
+		}{
+			out <- Yes
+		}
+	}
+}
+
+_Flat=@String Slice[left,right:out]
+{
+	,out <- If[[[left]Byte Length] = [[right]Byte Length]]
+	{
+		If[_internal_memcmp_offset[[[left]Source >>]Buffer >>, [left]Offset >>, [right]Buffer >>, 0i32, [left]Byte Length]]
+		{
+			out <- No
+		}{
+			out <- Yes
+		}
+	}
+}
+
+_Flat=@String Cat[left,right:out]
+{
+	out <- Eq String[left,right]
+}
+
 =@String[left,right:out]
 {
-	out <- Eq String[left,right]	
+	out <- [right]_Flat=[left]
 }
 
 Byte Length@String[string:out]
@@ -534,9 +565,29 @@
 	out <- [string]Length >>
 }
 
+_Slice=@String Slice[left,right:out]
+{
+	,out <- If[[[left]Byte Length]=[[right]Byte Length]]
+	{
+		If[_internal_memcmp_offset[[[left]Source >>]Buffer >>, [left]Offset >>, [[right]Source >>]Buffer >>, [right]Offset >>, [left]Byte Length]]
+		{ out <- No }
+		{ out <- Yes }
+	}
+}
+
+_Slice=@String[left,right:out]
+{
+	out <- [right]_Flat=[left]
+}
+
+_Slice=@String Cat[left,right:out]
+{
+	out <- Eq String[left,right]
+}
+
 =@String Slice[left,right:out]
 {
-	out <- Eq String[left,right]
+	out <- [right]_Slice=[left]
 }
 
 _Flatten@String[string,dest,offset,count:out]