# HG changeset patch # User Mike Pavone # Date 1245734164 14400 # Node ID e9272f7ebd26b14e448c7b8aadf210a24effa519 # Parent b715532225c087e9dfb5ceefbe324ef3980d00c5 Limited compilation from dataflow graph to C backend diff -r b715532225c0 -r e9272f7ebd26 backendutils.rhope --- a/backendutils.rhope Wed May 27 21:42:37 2009 -0400 +++ b/backendutils.rhope Tue Jun 23 01:16:04 2009 -0400 @@ -75,6 +75,22 @@ 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 diff -r b715532225c0 -r e9272f7ebd26 cbackend.rhope --- a/cbackend.rhope Wed May 27 21:42:37 2009 -0400 +++ b/cbackend.rhope Tue Jun 23 01:16:04 2009 -0400 @@ -218,7 +218,6 @@ ]Add Raw Line[ [["if("]Append[cond]]Append[")"] ] ]Add Raw Line["{"], [stream]Statements >>] ]Add Raw Line["}"] - { Print["Do if done"] } } @@ -227,6 +226,17 @@ out <- [["call->params["]Append[output]]Append["]"] } +If Null Else@C Function[func,left,right:out] +{ + out <- [[[[[["(" + ]Append[left] + ]Append[" ? "] + ]Append[left] + ]Append[" : "] + ]Append[right] + ]Append[")"] +} + Init Outputs@C Function[func:out] { If[[[[func]Outputs >>]Length ] > [0]] @@ -281,7 +291,6 @@ Definitions@C Function[func:out] { - Print["Definitions"] out <- [[[Fold["_Output Defs C", Fold["_Var Defs C","typedef struct {\n", [func]Variables >>], [func]Outputs >>]]Append["} l_"]]Append[Escape Rhope Name[[func]Name >>]]]Append[";\n"] } diff -r b715532225c0 -r e9272f7ebd26 nworker.rhope --- a/nworker.rhope Wed May 27 21:42:37 2009 -0400 +++ b/nworker.rhope Tue Jun 23 01:16:04 2009 -0400 @@ -189,7 +189,6 @@ met? <- Yes } }{ - Print[[ref]Index >>] met? <- No } } @@ -248,20 +247,73 @@ out <- [worker]_Dependency Groups[no deps, no deps, [()]Append[no deps]] } +Format Input@NWorker[worker,noderef:out] +{ + node <- [[worker]Nodes >>]Index[[noderef]Index >>] + If[[[node]Type >>] = ["call"]] + { + out <- AddRef[ [[["__result_"]Append[[noderef]Index >>]]Append["_"]]Append[[noderef]IO Num >>] ] + }{ + If[[[node]Type >>] = ["input"]] + { + input name <- [[worker]Inputs >>]Index[ [node]Data >> ] + out <- AddRef[input name] + } + } +} + +Collect Input@NWorker[worker,nodeinput:out] +{ + inputchoices <- Map[nodeinput, ["Format Input"]Set Input[0, worker]] + [inputchoices]First + { + first <- [inputchoices]Index[~] + [inputchoices]Next[~] + { + out <- _Fold[inputchoices, ~, first, "OrValue"] + }{ + out <- Val[first] + } + }{ + out <- No + } +} + +Collect Inputs@NWorker[worker,node:out] +{ + out <- Map[[node]Wires To>>, ["Collect Input"]Set Input[0, worker]] +} + +Save Result[func,num,node index:out] +{ + out var <- [[["__result_"]Append[node index]]Append["_"]]Append[num] + out <- [[func]Allocate Var[out var, "Any Type"] + ]Move[Result[num], out var] +} + Compile Node@NWorker[worker,program,func,nodes,current:out] { Print[[node]Type >>] - node <- [[worker]Nodes >>]Index[[nodes]Index[current]] + node index <- [nodes]Index[current] + node <- [[worker]Nodes >>]Index[node index] If[[[node]Type >>] = ["call"]] { + inputs <- [worker]Collect Inputs[node] [program]Method?[[[node]Data >>]Name >>] { - nfunc <- [func]Method Call[[[node]Data >>]Name >>, ()] + with call <- [func]Method Call[[[node]Data >>]Name >>, inputs] }{ - nfunc <- [func]Call[[[node]Data >>]Name >>, ()] + with call <- [func]Call[[[node]Data >>]Name >>, inputs] } + nfunc <- Fold[["Save Result"]Set Input[2, node index], with call, Range[0, [node]Outputs >>]] }{ - nfunc <- Val[func] + If[[[node]Type >>] = ["output"]] + { + inputs <- [worker]Collect Inputs[node] + nfunc <- [func]Move[[inputs]Index[0], [[worker]Outputs >>]Index[ [node]Data >> ] ] + }{ + nfunc <- Val[func] + } } [nodes]Next[current] { @@ -288,9 +340,14 @@ } } +Release Var[func,type,name:out] +{ + out <- [func]Release[name] +} + Compile Worker@NWorker[worker,program,name:out] { - func <- [program]Create Function[name,[worker]Inputs >>, [worker]Outputs >>, [worker]Convention >>] + func <- Fold["Null", [program]Create Function[name,[worker]Inputs >>, [worker]Outputs >>, [worker]Convention >>], [worker]Outputs >>] groups <- [worker]Dependency Groups [groups]First { @@ -298,7 +355,7 @@ }{ final func <- Val[func] } - out <- [program]Store Function[final func] + out <- [program]Store Function[Fold["Release Var", final func, [final func]Variables >>]] } Test[:out] @@ -320,12 +377,12 @@ }}}}}} } -Test Compile[:out] +Test Graph to Backend[:out] { - out <- [Test[]]Compile Worker[C Program[] "Test"] + out <- [Test[]]Compile Worker[C Program[], "Test"] } Main[] { - Pretty Print[Test Compile[], ""] + Pretty Print[Test Graph to Backend[], ""] }