Mercurial > repos > rhope
diff backendutils.rhope @ 184:c6ba9fe45910
Strip _c from filenames of current compiler
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Wed, 27 Jul 2011 21:28:43 -0700 |
parents | backendutils_c.rhope@ed322ae64738 |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/backendutils.rhope Wed Jul 27 21:28:43 2011 -0700 @@ -0,0 +1,526 @@ + +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 Make Op Res +{ + Func + Val +} + +Make Op Res[func,val:out] +{ + out <- [[Build[Make Op Res()]]Func <<[func]]Val <<[val] +} + +Make Op Mod[func,val:out func,out val] +{ + nval <- [val]Make Op[func] + If[[Blueprint Of[nval]]=[Make Op Res()]] + { + out func <- Func >>[nval] + out val <- Val >>[nval] + }{ + out func <- func + out val <- Val[nval] + } +} + +Blueprint AddRef +{ + Value +} + +AddRef[value:out] +{ + out <- [Build[AddRef()]]Value <<[value] +} + +Make Op@AddRef[addref,func:out] +{ + out <- [func]Make AddRef Op[[addref]Value >>] +} + +Strip Addref@AddRef[op:out] +{ + out <- [[op]Value >>]Strip Addref +} + +=@AddRef[a,b(AddRef):out] +{ + out <- [[a]Value >>]==[[b]Value >>] +} + +Make Op@String[string,func:out] +{ + out <- [func]Resolve[string] +} + +Strip Addref@String[op:out] +{ + out <- op +} + +Get Type@String[op,func:out] +{ + out <- [func]Get Var Type[op] +} + +Make Op@String Cat[string,func:out] +{ + out <- [func]Resolve[string] +} + +Strip Addref@String Cat[op:out] +{ + out <- op +} + +Get Type@String Cat[op,func:out] +{ + out <- [func]Get Var Type[op] +} + +Make Op@String Slice[string,func:out] +{ + out <- [func]Resolve[string] +} + +Strip Addref@String Slice[op:out] +{ + out <- op +} + +Get Type@String Slice[op,func:out] +{ + out <- [func]Get Var Type[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 +} + +=@Output[a,b(Output):out] +{ + out <- [[a]Name >>]=[[b]Name >>] +} + + +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 >>] +} + +Get Type@Constant[const,func:out] +{ + out <- [func]Get Constant Type[const] +} + +Strip Addref@Constant[op:out] +{ + out <- [op]Need Addref <<[No] +} + +=@Constant[a,b(Constant):out] +{ + out <- [[a]Value >>]=[[b]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>>] +} + +Strip Addref@Result[op:out] +{ + out <- op +} + +=@Result[a,b(Result):out] +{ + out <- [[a]Output Num >>]=[[b]Output Num >>] +} + +Blueprint Global Get +{ + Store + Var +} + +Global Get[store,var:out] +{ + out <- [[Build[Global Get()]]Store <<[store]]Var <<[var] +} + +Make Op@Global Get[get,func:out] +{ + out <- [func]Global Reference[[get]Store >>, [get]Var >>] +} + +Strip Addref@Global Get[get:out] +{ + out <- get +} + +=@Global Get[a,b(Global Get):out] +{ + ,out <- If[[[a]Store >>]=[[b]Store >>]] + { + out <- [[a]Var >>]=[[b]Var >>] + } +} + +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 + } +} + +=@Check Result[a,b(Check Result):out] +{ + out <- [[a]Output Num >>]=[[b]Output Num >>] +} + +Blueprint OrValue +{ + Left + Right +} + +OrValue[left,right:out] +{ + If[[left]==[right]] + { + out <- left + }{ + 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 ] +} + +=@OrValue[a,b(OrValue):out] +{ + ,out <- If[[[a]Left >>]==[[b]Left >>]] + { + out <- [[a]Right >>]==[[b]Right >>] + } +} + +Blueprint Cast +{ + Value + Type +} + +Cast[val,type:out] +{ + out <- [[Build[Cast()]]Value <<[val]]Type <<[type] +} + +Make Op@Cast[cast,func:out] +{ + out <- [func]Cast Value[[cast]Value >>, [cast]Type >>] +} + +Strip Addref@Cast[op:out] +{ + out <- [op]Value <<[[[op]Value >>]Strip Addref] +} + +=@Cast[a,b(Cast):out] +{ + ,out <- If[[[a]Value >>] == [[b]Value >>]] + { + out <- [[a]Type >>]=[[b]Type >>] + } +} + +Blueprint NotCond +{ + Condition +} + +NotCond[cond:out] +{ + If[[Blueprint Of[cond]]=[NotCond()]] + { + out <- [cond]Condition >> + }{ + 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 +} + +=@NotCond[a,b(NotCond):out] +{ + out <- [[a]Condition >>]==[[b]Condition >>] +} + +Blueprint OrCond +{ + Condition1 + Condition2 +} + +OrCond[cond1,cond2:out] +{ + If[[cond1]==[cond2]] + { + out <- cond1 + }{ + 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 +} + +=@OrCond[a,b(OrCond):out] +{ + ,out <- If[[[a]Condition1 >>] == [[b]Condition1 >>]] + { + out <- [[a]Condition2 >>] == [[b]Condition2 >>] + } +} + +Blueprint AndCond +{ + Condition1 + Condition2 +} + +AndCond[cond1,cond2:out] +{ + If[[cond1]==[cond2]] + { + out <- cond1 + }{ + 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 +} + +=@AndCond[a,b(AndCond):out] +{ + ,out <- If[[[a]Condition1 >>] == [[b]Condition1 >>]] + { + out <- [[a]Condition2 >>] == [[b]Condition2 >>] + } +} + +Blueprint Field Ref +{ + Variable + Field +} + +Field Ref[var,field:out] +{ + out <- [[Build[Field Ref()]]Variable <<[var]]Field <<[field] +} + +Get Type@Field Ref[ref,func:out] +{ + out <- [func]Get Field Type[[[ref]Variable >>]Get Type[func], [ref]Field >>] +} + +Make Op@Field Ref[ref,func:out] +{ + out <- [func]Field Result[[ref]Variable >>,[ref]Field >>] +} + +Strip Addref@Field Ref[op:out] +{ + out <- op +} + +=@Field Ref[a,b(Field Ref):out] +{ + ,out <- If[[[a]Variable >>]==[[b]Variable >>]] + { + out <- [[a]Field >>]=[[b]Field >>] + } +} + +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] ] +} +