view backendutils.rhope @ 37:640f541e9116

Added support for type declarations on user defined workers and added a few more methods to Int32 in the runtime for the C backend
author Mike Pavone <pavone@retrodev.com>
date Mon, 05 Oct 2009 23:12:43 -0400
parents 495dddadd058
children 7f05bbe82f24
line wrap: on
line source


Escape Rhope Name NU[name:escaped]
{
	escaped <- [[[[[[[[[[name]Replace["@","_AT_"]
		]Replace[" ","_SP_"]
		]Replace[":","_CN_"]
		]Replace["?","_QN_"]
		]Replace["+","_PL_"]
		]Replace["-","_MN_"]
		]Replace["*","_TM_"]
		]Replace["/","_DV_"]
		]Replace["<","_LT_"]
		]Replace[">","_GT_"]
}

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("]Append[ [[addref]Value >>]Make Op[func] ]]Append[")"]
}

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

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

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

Blueprint Constant
{
	Value
}

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

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

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>>]
}

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[[[func]Left >>]Make Op[func], [[func]Right >>]Make Op[func]]
}

Blueprint NotCond
{
	Condition
}

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

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

Blueprint OrCond
{
	Condition1
	Condition2
}

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

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

Blueprint AndCond
{
	Condition1
	Condition2
}

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

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

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 >>]
}

Blueprint Type Instance
{
	Name
	Params
	Variant
}

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

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