view geninterp.rhope @ 175:03e4fa277291

Use worker refs for geninterp
author Mike Pavone <pavone@retrodev.com>
date Wed, 08 Jun 2011 23:24:15 -0700
parents 0c7c5671fcd3
children
line wrap: on
line source


Import parser_old_c.rhope
Import cbackend_c.rhope 

Worker Set[lines,worker:out]
{
	If[[[worker]Name >>]Starts With["_"]]
	{
		out <- lines
	}{
		If[[[worker]Name >>]=["Call@Worker"]]
		{ out <- lines }
		{ out <- [lines]Append[ [[[["\t\t]Set[\""]Append[[worker]Name >>]]Append["\", "]]Append[[worker]Name >>]]Append["[?]]"] ] }
	}
}

Get Constant Type[func,const:out]
{
	out <- func
}

Get Var Type[func,varname:out]
{
	out <- func
}

Main[args]
{

	fname <- [args]Index[1]
	{
		file <- [File[~]]Open["r"]
		text <- String[[file]Read[[file]Length]]
		params <- Parser[]
		Print[["Parsing "]Append[fname]]
		Null[text, params, Parse Program[], 0]
		{
			Print["Parsing imports"]
			Process Imports[~, params]
			{
				tree <- [~]Workers << [ Map[[~]Worker Refs >>, Check Worker Literals[?, ~]] ]
				{ Print["Compiling"] }
			}

		 	program <- Tree to Program Native[tree, [C Program[]]Supported Number Types]
			lines <- Fold[Worker Set[?], (), [program]Workers >>]

			out text <- [[[Fold[Append[?, "["], "Func Lookup[:out]\n{\n\tout <- ", Range[0, Length[lines]]]
				]Append["Dictionary[]\n"]
				]Append[[lines]Join["\n"]]
				]Append["\n}\n"]
				
			
			outname <- [args]Index[2] {}
			{ outname <- "interplookup.rhope" }
			outfile <- [[File[outname]]Open["w"]]Truncate

			[[out text]Write to File[outfile]
			]Close
		}
	}{
		Print["You must provide a file name to compile"]
	}
}