diff kernel.rhope @ 74:a844c623c7df

Add support for Worker type
author Mike Pavone <pavone@retrodev.com>
date Thu, 01 Jul 2010 21:32:08 -0400
parents c40c3d399133
children 0083b2f7b3c7
line wrap: on
line diff
--- a/kernel.rhope	Sat Jun 19 23:13:41 2010 -0400
+++ b/kernel.rhope	Thu Jul 01 21:32:08 2010 -0400
@@ -146,6 +146,58 @@
 	_internal_array_allocboxed[size(Int32,Naked):out(Array)]
 	_internal_array_allocnaked[size(Int32,Naked),type(Blueprint):out(Array)]
 	_internal_blueprint_eq[left(Blueprint),right(Blueprint):out(Int32,Naked)]
+	_internal_worker_alloc[size(Int16,Naked):out(Worker)]
+	_internal_worker_setinput[worker(Worker,Boxed,Mutable),num(Int16,Naked),val:worker]
+	_internal_worker_getinput[worker(Worker),num(Int16,Naked):out]
+	_internal_worker_hasinput[worker(Worker),num(Int16,Naked):out(Int32,Naked)]
+}
+
+Blueprint Worker
+{
+	Index(Int32,Naked)
+	Size(Int16,Naked)
+	Count(Int16,Naked)
+}
+
+Get Input@Worker[worker(Worker),bindex(Int32):val,not populated]
+{
+	index <- [bindex]Trunc Int16
+	,not populated <- If[_internal_worker_hasinput[worker,index]]
+	{
+		val <- _internal_worker_getinput[worker,index]
+	}
+}
+
+_Copy Params[source(Worker),dest(Worker),cur(Int16):out(Worker)]
+{
+	If[[cur]<[[source]Size >>]]
+	{
+		[source]Get Input[cur]
+		{
+			next <- _internal_worker_setinput[dest, cur, ~]
+		}{
+			next <- Val[dest]
+		}
+		out <- _Copy Params[source, next, [cur]+[1i16]]
+	}{
+		out <- dest
+	}
+}
+
+Set Input@Worker[worker(Worker),bindex(Int32),val:out(Worker)]
+{
+	index <- [bindex]Trunc Int16
+	If[[index] < [[worker]Size >>]]
+	{
+		set <- _internal_worker_setinput[worker, index, val]
+	}{
+		set <- _internal_worker_setinput[
+			_Copy Params[worker, 
+				[ _internal_worker_alloc[[index]+[1i16]] ]Index <<[[worker]Index >>]
+				, 0i16]
+			, index, val]
+	}
+	out <- [set]Count <<[ [[set]Count >>]+[1i16] ]
 }
 
 =@Blueprint[left,right:out]
@@ -293,4 +345,9 @@
 	}
 }
 
+Call@Array[arr(Array),index(Int32):out]
+{
+	out <- [arr]Index[index]
+}
 
+