diff testc_c.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
children 5a08705f7610
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/testc_c.rhope	Mon Aug 02 00:58:55 2010 -0400
@@ -0,0 +1,88 @@
+Import cbackend_c.rhope
+Import number_c.rhope
+Import boolean.rhope
+
+//Dummy versions of nworker methods so the code in number_c.rhope will compile
+Register Worker[prog,name,convention,inputs,outputs:out]
+{
+	out <- prog
+}
+
+Bind Worker[prog,name,worker:out]
+{
+	out <- prog
+}
+
+Blueprint NWorker
+{
+	Inputs
+	Input Types
+	Outputs
+	Output Types
+	Builtin?
+}
+
+NWorker[convention:out]
+{
+	out <- convention
+}
+
+Main[]
+{
+	prog <- [[C Program[]]Generate Number Methods]Generate Boolean Methods
+	base <- [[[[[[[[[prog]Create Function["Fib",("n"),("out"),"rhope"]
+		]Allocate Var["work1", Type Instance["Any Type"]]
+		]Allocate Var["work2", Type Instance["Any Type"]]
+		]Register Constant["const_1", 1]
+		]Register Constant["const_2", 2]
+		]Set Null["out"]
+		]Method Call["<", [[()]Append[AddRef["n"]]]Append[AddRef[Constant["const_2"]]]]
+		]Move[Result[0], "work1"]
+		]Method Call["If", [()]Append["work1"]]
+	{Print["base done"] }
+
+	 stream1 <- [[[base]Instruction Stream
+		]Release[Result[0]]
+		]Move[AddRef[Constant["const_1"]], "out"]
+	{Print["stream1 done"]}
+	
+	
+
+	[[[[[[[[[[base]Instruction Stream
+		]Release[Result[0]]
+		]Method Call["-", [[()]Append[AddRef["n"]]]Append[AddRef[Constant["const_1"]]]]
+		]Move[Result[0], "work1"]
+		]Method Call["-", [[()]Append[AddRef["n"]]]Append[AddRef[Constant["const_2"]]]]
+		]Move[Result[0], "work2"]
+		]Call["Fib", ("work1")]
+		]Move[Result[0], "work1"]
+		]Call["Fib", ("work2")]
+		]Move[Result[0], "work2"]
+	{
+		stream3 <- [[[~]Instruction Stream
+		]Release["n"]
+		]Method Call["+", ("work1","work2")]
+		stream2 <- [~]Do If[NotCond["out"], stream3]
+		{Print["stream2 done"]}
+	}
+	
+
+	func <- [[[base
+		]Do If[Result[0], stream1]
+		]Do If[Result[1], stream2]
+		]Release["n"]
+	{Print["func done"] }
+
+	main <- [[[[prog]Create Function["Main", (), ("out"), "rhope"]
+	]Register Constant["const_30", 30]
+	]Call["Fib", [()]Append[Constant["const_30"]]]
+	]Move[Result[0], "out"]
+
+	Print[
+		[[[prog]Store Function[func]
+		]Store Function[main]
+		]Text
+	]
+		
+}
+