view testc.rhope @ 75:0083b2f7b3c7

Partially working implementation of List. Modified build scripts to allow use of other compilers. Fixed some bugs involving method implementations on different types returning different numbers of outputs. Added Fold to the 'builtins' in the comipler.
author Mike Pavone <pavone@retrodev.com>
date Tue, 06 Jul 2010 07:52:59 -0400
parents 90c20dc3f4e5
children
line wrap: on
line source

Import cbackend.rhope

Main[]
{
	prog <- C Program[]
	base <- [[[[[[[prog]Create Function["Fib",("n"),("out"),""]
		]Allocate Var["work1", "Any Type"]
		]Allocate Var["work2", "Any Type"]
		]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"]}
	
	stream3 <- [[[base]Instruction Stream
		]Release["n"]
		]Tail Method Call["+", ("work1","work2")]

	stream2 <- [[[[[[[[[[[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"]
		]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"] }

	Print[[[prog]Store Function[func]]Text]
		
}