Mercurial > repos > rhope
view backendutils_c.rhope @ 117:4d089503fb51
Performance optimization
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Thu, 14 Oct 2010 22:37:20 -0400 |
parents | b7df624895b2 |
children | 18a4403fe576 |
line wrap: on
line source
Escape Rhope Name[name,p:out] { escaped <- [name]Replace[p, ("UN_","AT_","SP_","CN_","QN_","PL_","MN_","TM_","DV_","LT_","GT_","LP_","RP_","NT_","EQ_","PR_", "DP_","TB_","CM_","PD_","NL_","LC_","RC_", "LS_", "RS_", "HS_", "BS_", "CR_", "SC_", "AM_", "PI_", "PC_", "CT_", "BT_", "TD_")] [("char","int","short","long","float","double","void","struct")]Find[=[escaped, ?]] { out <- ["ID_"]Append[escaped] }{ out <- Val[escaped] } } 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@String Cat[string,func:out] { out <- [func]Resolve[string] } Strip Addref@String Cat[op:out] { out <- op } Make Op@String Slice[string,func:out] { out <- [func]Resolve[string] } Strip Addref@String Slice[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[[Blueprint 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[[Blueprint Of[compare]] = [Type Instance()]] { //TODO: Compare parameters ,out <- If[[[type]Name >>] = [[compare]Name >>]] { out <- [[type]Variant >>] = [[compare]Variant >>] } }{ out <- [[type]Name >>] = [compare] } } String@Type Instance[type:out] { typestr <- [[[[type]Name >> ]Append["("] ]Append[ [[type]Params >>]Join[", "] ] ]Append[")"] If[[type]Mutable? >>] { out <- [[ [["("]Append[typestr]]Append[", "] ]Append[[type]Variant >>]]Append[", Mutable)"] }{ If[[[type]Variant >>] = ["Boxed"]] { out <- Val[typestr] }{ out <- [[ [["("]Append[typestr]]Append[", "] ]Append[[type]Variant >>]]Append[", Mutable)"] } } } 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] ] }