view backendutils.rhope @ 69:d0ce696786cc

Clean up debug print statements a bit. Fix bug that prevented workers that took no inputs from working. Remove workaround in Array for said bug.
author Mike Pavone <pavone@retrodev.com>
date Wed, 16 Jun 2010 04:36:08 +0000
parents 3e20ed8959c4
children a844c623c7df
line wrap: on
line source


Escape Rhope Name NU[name:escaped]
{
	escaped <- [[[[[[[[[[[[[[[name]Replace["_","UN_"]
		]Replace["@","AT_"]
		]Replace[" ","SP_"]
		]Replace[":","CN_"]
		]Replace["?","QN_"]
		]Replace["+","PL_"]
		]Replace["-","MN_"]
		]Replace["*","TM_"]
		]Replace["/","DV_"]
		]Replace["<","LT_"]
		]Replace[">","GT_"]
		]Replace["(","LP_"]
		]Replace[")","RP_"]
		]Replace["!","NT_"]
		]Replace["=","EQ_"]
}

Escape Rhope Name[name:escaped]
{
	escaped <- Escape Rhope Name NU[[name]Replace["_","__"]]
}

Blueprint AddRef
{
	Value
}

AddRef[value:out]
{
	out <- [Build["AddRef"]]Value <<[value]
}

Make Op@AddRef[addref,func:out]
{
	//TODO: Make me work with other backends
	out <- [["add_ref((object *)"]Append[ [[addref]Value >>]Make Op[func] ]]Append[")"]
}

Strip Addref@AddRef[op:out]
{
	out <- [[op]Value >>]Strip Addref
}

Make Op@String[string,func:out]
{
	out <- [func]Resolve[string]
}

Strip Addref@String[op:out]
{
	out <- op
}

Make Op@Whole Number[num,func:out]
{
	out <- num
}

Strip Addref@Whole Number[op:out]
{
	out <- op
}

Make Op@Real Number[num,func:out]
{
	out <- num
}

Strip Addref@Real Number[op:out]
{
	out <- op
}

Blueprint Output
{
	Name
}

Output[name:out]
{
	out <- [Build["Output"]]Name <<[name]
}

Make Op@Output[op,func:out]
{
	out <- [func]Resolve Output[[op]Name >>]
}

Strip Addref@Output[op:out]
{
	out <- op
}

Blueprint Constant
{
	Value
}

Constant[var:out]
{
	out <- [Build["Constant"]]Value <<[var]
}

Make Op@Constant[const,func:out]
{
	out <- [func]Lookup Constant[[const]Value >>]
}

Strip Addref@Constant[op:out]
{
	out <- op
}

Blueprint Result
{
	Output Num
}

Result[num:out]
{
	out <- [Build["Result"]]Output Num <<[num]
}

Make Op@Result[result,func:out]
{
	out <- [func]Result Reference[[result]Output Num>>]
}

Strip Addref@Result[op:out]
{
	out <- op
}

Make Condition[op:out]
{
	If[[Type Of[op]]=["OrValue"]]
	{
		out <- OrCond[Make Condition[[op]Left >>], Make Condition[[op]Right >>]]
	}{
		out <- op
	}
}

Blueprint OrValue
{
	Left
	Right
}

OrValue[left,right:out]
{
	out <- [[Build["OrValue"]]Left <<[left]]Right <<[right]
}

Make Op@OrValue[orval,func:out]
{
	out <- [func]If Null Else[[orval]Left >>, [orval]Right >>]
}

Strip Addref@OrValue[op:out]
{
	out <- [[op]Left <<[ [[op]Left >>]Strip Addref ]]Right <<[ [[op]Right >>]Strip Addref ]
}

Blueprint NotCond
{
	Condition
}

NotCond[cond:out]
{
	out <- [Build["NotCond"]]Condition <<[[cond]Strip Addref]
}

Make Op@NotCond[cond,func:out]
{
	out <- ["!"]Append[[[cond]Condition >>]Make Op[func]]
}

Strip Addref@NotCond[op:out]
{
	out <- op
}

Blueprint OrCond
{
	Condition1
	Condition2
}

OrCond[cond1,cond2:out]
{
	out <- [[Build["OrCond"]]Condition1 <<[[cond1]Strip Addref]]Condition2 <<[[cond2]Strip Addref]
}

Make Op@OrCond[cond,func:out]
{
	out <- ["("]Append[[[ [[cond]Condition1 >>]Make Op[func] ]Append[" || "]]Append[[ [[cond]Condition2 >>]Make Op[func] ]Append[")"]]]
}

Strip Addref@OrCond[op:out]
{
	out <- op
}

Blueprint AndCond
{
	Condition1
	Condition2
}

AndCond[cond1,cond2:out]
{
	out <- [[Build["AndCond"]]Condition1 <<[[cond1]Strip Addref]]Condition2 <<[[cond2]Strip Addref]
}

Make Op@AndCond[cond,func:out]
{
	out <- ["("]Append[[[ [[cond]Condition1 >>]Make Op[func] ]Append[" && "]]Append[[ [[cond]Condition2 >>]Make Op[func] ]Append[")"]]]
}

Strip Addref@AndCond[op:out]
{
	out <- op
}

Blueprint Field Ref
{
	Variable
	Field
}

Field Ref[var,field:out]
{
	out <- [[Build["Field Ref"]]Variable <<[var]]Field <<[field]
}

Make Op@Field Ref[ref,func:out]
{
	out <- [func]Field Result[[ref]Variable >>,[ref]Field >>]
}

Strip Addref@Field Ref[op:out]
{
	out <- op
}

Blueprint Type Instance
{
	Name
	Params
	Variant
	Mutable?
}

Type Instance[raw name:out]
{
	If[[raw name]=[""]]
	{
		name <- "Any Type"
	}{
		name <- raw name
	}
	out <- [[[[Build["Type Instance"]]Name <<[name]]Params <<[()]]Variant <<["Boxed"]]Mutable? <<[No]
}

Set Variant@Type Instance[type,variant:out,invalid]
{
	[("Boxed","Naked","Pointer","Raw Pointer")]Find[variant]
	{
		out <- [type]Variant <<[variant]
	}{
		invalid <- type
	}
}

=@Type Instance[type,compare:out]
{
	If[[Type Of[compare]] = ["String"]]
	{
		out <- [[type]Name >>] = [compare]
	}{
		//TODO: Compare parameters
		,out <- If[[[type]Name >>] = [[compare]Name >>]]
		{ out <- [[type]Variant >>] = [[compare]Variant >>] }
	}
}