view backendutils.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 a844c623c7df
children c25d75c2440b
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_"]
		]Replace["'","PR_"]
		]Replace["\"","DP_"]
		]Replace["\t","TB_"]
		]Replace[",", "CM_"]
		]Replace[".", "PD_"]
}

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
	Need Addref
}

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

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

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

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
}

Blueprint Check Result
{
	Output Num
}

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

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

Strip Addref@Check 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 >>] }
	}
}

Blueprint Worker Literal
{
	Name
	Args
}

Worker Literal[name:out]
{
	out <- [[Build["Worker Literal"]]Name <<[name]]Args <<[()]
}

Set Input@Worker Literal[worker,argnum,val:out]
{
	out <- [worker]Args <<[ [[worker]Args >>]Set[argnum, val] ]
}