diff kernel.rhope @ 92:e73a93fb5de1

Beginning of port of compiler to itself, some bugfixes and a refcount optimization
author Mike Pavone <pavone@retrodev.com>
date Mon, 02 Aug 2010 00:58:55 -0400
parents 27bb051d631c
children 5a08705f7610
line wrap: on
line diff
--- a/kernel.rhope	Sat Jul 31 17:17:23 2010 -0400
+++ b/kernel.rhope	Mon Aug 02 00:58:55 2010 -0400
@@ -3,6 +3,7 @@
 Import functional.rhope
 Import file.rhope
 Import dict.rhope
+Import range.rhope
 
 Val[in:out]
 {
@@ -46,31 +47,51 @@
 	read[filedes(Int32,Naked),buf(Array,Raw Pointer,Mutable),nbyte(Int64,Naked):read(Int64,Naked),buf]
 }
 
-_Print Int32[n,buf:out]
+_String 32[n,buf:out]
 {
-	If[[n] < [10i32]]
+	If[[n] < [10u32]]
 	{
-		byte <- [[n]Trunc Int8] + [48i8]
+		byte <- [[n]Trunc UInt8] + [48u8]
 		out <- [buf]Append[byte]
 	}{
-		next <- [n]/[10i32]
+		next <- [n]/[10u32]
 		
-		byte <- [[[n]-[[next]*[10i32]]]Trunc Int8] + [48i8]
-		out <- [_Print Int32[next, buf]]Append[byte]
+		byte <- [[[n]-[[next]*[10u32]]]Trunc UInt8] + [48u8]
+		out <- [_String 32[next, buf]]Append[byte]
 	}
 }
 
+_String Int32[n:out]
+{
+	If[[n] < [0i32]]
+	{
+		buf <- [Array[]]Append[45u8]
+	}{
+		buf <- Array[]
+	}
+	val <- Abs UInt[n]
+	out <- _String 32[val, buf]
+}
+
+String@Int32[n:out]
+{
+	out <- String[_String Int32[n]]
+}
+
 Print@Int32[n:out]
 {
-	If[[n] < [0i32]]
-	{
-		val <- [0i32]-[n]
-		buf <- [Array[]]Append[45i8]
-	}{
-		val <- Val[n]
-		buf <- Array[]
-	}
-	fbuf <- [_Print Int32[val, buf]]Append[10i8]
+	fbuf <- [_String Int32[n]]Append[10u8]
+	out <- write[1i32, fbuf, Int64[[fbuf]Length >>]]
+}
+
+String@UInt32[n:out]
+{
+	out <- String[_String 32[n, Array[]]]
+}
+
+Print@UInt32[n:out]
+{
+	fbuf <- [_String 32[n, Array[]]]Append[10u8]
 	out <- write[1i32, fbuf, Int64[[fbuf]Length >>]]
 }
 
@@ -134,6 +155,39 @@
 	yes,no <- If[[num]!=[0u8]]
 }
 
+Abs@Int64[num:out]
+{
+	If[[num]<[0i64]]
+	{ out <- [0i64]-[num] }
+	{ out <- num }
+}
+
+Abs@Int32[num:out]
+{
+	If[[num]<[0i32]]
+	{ out <- [0i32]-[num] }
+	{ out <- num }
+}
+
+Abs@Int16[num:out]
+{
+	If[[num]<[0i16]]
+	{ out <- [0i16]-[num] }
+	{ out <- num }
+}
+
+Abs@Int8[num:out]
+{
+	If[[num]<[0i8]]
+	{ out <- [0i8]-[num] }
+	{ out <- num }
+}
+
+Mod[a,b:out]
+{
+	out <- [a]-[[[a]/[b]]*[b]]
+}
+
 
 Blueprint Array
 {
@@ -177,7 +231,7 @@
 {
 	If[[cur]<[[source]Size >>]]
 	{
-		[source]Get Input[cur]
+		[source]Get Input[Int32[cur]]
 		{
 			next <- _internal_worker_setinput[dest, cur, ~]
 		}{
@@ -309,10 +363,11 @@
 				out <- _internal_array_copyin[farray, index, val]
 			}{
 				boxed <- _internal_array_allocboxed[[farray]Storage >>]
-				[array]First
+				[farray]First
 				{
-					copied <- _Copy to Boxed[farray, boxed, ~]
+					copied <- [_Copy to Boxed[farray, boxed, ~]]Length <<[ [farray]Length >> ]
 				}{
+					Print["Uh oh, no First on Naked Array!"]
 					//I don't think this case should happen normally
 					copied <- Val[boxed]
 				}