# HG changeset patch # User Mike Pavone # Date 1243459755 0 # Node ID 90c20dc3f4e58d9c216ea53ce88edb3034154ebe # Parent ea991f95ae1fa8f91c6d344730eef075d9ca5b6a Initial work on compiling dataflow graphs to a backend diff -r ea991f95ae1f -r 90c20dc3f4e5 cbackend.rhope --- a/cbackend.rhope Wed May 27 04:49:32 2009 -0400 +++ b/cbackend.rhope Wed May 27 21:29:15 2009 +0000 @@ -301,3 +301,44 @@ } +Blueprint C Program +{ + Functions + Method Registry +} + +C Program[:out] +{ + out <- [[Build["C Program"]]Functions <<[New@Dictionary[]]]Method Registry <<[C Method Registry[]] +} + +Create Function@C Program[program,name,inputs,outputs,convention:out] +{ + out <- C Function With Registry[name,inputs,outputs,convention, [program]Method Registry >>] +} + +Store Function@C Program[program,func:out] +{ + out <- [program]Functions <<[ [[program]Functions >>]Set[ [func]Name >>, func] ] +} + +_Defs C Program[text,func:out] +{ + Print["start _Defs"] + out <- [text]Append[[func]Definitions] + { Print["_Defs done"] } +} + +_Text C Program[text,func:out] +{ + Print["start _Text"] + out <- [text]Append[[func]Text] + { Print["_Text done"] } +} + +Text@C Program[program:out] +{ + out <- Fold["_Text C Program", Fold["_Defs C Program", "", [program]Functions >>], [program]Functions >>] +} + + diff -r ea991f95ae1f -r 90c20dc3f4e5 extendlib.rhope --- a/extendlib.rhope Wed May 27 04:49:32 2009 -0400 +++ b/extendlib.rhope Wed May 27 21:29:15 2009 +0000 @@ -594,7 +594,7 @@ not found <- text } } - + Blueprint Range { Start @@ -606,9 +606,14 @@ out <- [[Build["Range"]]Start <<[start]]End <<[end] } -First@Range[range:out] +First@Range[range:out,none] { - out <- [range]Start >> + If[[[range]Start >>] < [[range]End >>]] + { + out <- [range]Start >> + }{ + none <- range + } } Next@Range[range,val:out,done] @@ -637,3 +642,5 @@ } } + + diff -r ea991f95ae1f -r 90c20dc3f4e5 nworker.rhope --- a/nworker.rhope Wed May 27 04:49:32 2009 -0400 +++ b/nworker.rhope Wed May 27 21:29:15 2009 +0000 @@ -1,42 +1,5 @@ Import extendlib.rhope -Blueprint Range -{ - Start - Stop -} - -Range[start,stop:out] -{ - out <- [[Build["Range"]]Start <<[start]]Stop <<[stop] -} - -First@Range[range:first,none] -{ - If[[[range]Start >>] < [[range]Stop >>]] - { - first <- [range]Start >> - }{ - none <- range - } -} - -Next@Range[range,current:next,none] -{ - pnext <- [current]+[1] - If[[pnext] < [[range]Stop >>]] - { - next <- Val[pnext] - }{ - none <- range - } -} - -Index@Range[range,index:val,none] -{ - val <- index -} - Set@Range[range,index,val:out] { out <- [[()]Concatenate[range] @@ -143,6 +106,8 @@ Nodes Inputs Outputs + NodeResults + Free Temps } NWorker[convention:out] @@ -282,6 +247,53 @@ out <- [worker]_Dependency Groups[no deps, no deps, [()]Append[no deps]] } +Compile Node@NWorker[worker,program,func,nodes,current:out] +{ + node <- [[worker]Nodes >>]Index[[nodes]Index[current]] + If[[[node]Type >>] = [""]] + { + nfunc <- [func]Call[[[node]Data >>]Name >>, ()] + }{ + nfunc <- Val[func] + } + [nodes]Next[current] + { + out <- [worker]Compile Node[program,func,nodes,~] + }{ + out <- Val[nfunc] + } +} + +Compile Group@NWorker[worker,program,func,groups,current:out] +{ + nodes <- [groups]Index[current] + [nodes]First + { + nfunc <- [worker]Compile Node[program,func,nodes,~] + }{ + nfunc <- Val[func] + } + [groups]Next[current] + { + out <- [worker]Compile Group[program,func,groups,~] + }{ + out <- Val[nfunc] + } +} + +Compile Worker@NWorker[worker,program,name:out] +{ + func <- [program]Create Function[name,[worker]Inputs >>, [worker]Outputs >>, [worker]Convention >>] + groups <- [worker]Dependency Groups + [groups]First + { + final func <- [worker]Compile Group[program,func,groups, ~] + }{ + final func <- Val[func] + } + out <- [program]Store Function[func] +} + Test[:out] { ref+ <- Worker Ref["+","cdecl",2,1] @@ -299,4 +311,4 @@ ]Add Wire[c,0,call*,1] ]Add Wire[call*,0,outref,0] }}}}}} -} \ No newline at end of file +} diff -r ea991f95ae1f -r 90c20dc3f4e5 testc.rhope --- a/testc.rhope Wed May 27 04:49:32 2009 -0400 +++ b/testc.rhope Wed May 27 21:29:15 2009 +0000 @@ -2,7 +2,8 @@ Main[] { - base <- [[[[[[C Function["Fib",("n"),("out"),""] + prog <- C Program[] + base <- [[[[[[[prog]Create Function["Fib",("n"),("out"),""] ]Allocate Var["work1", "Any Type"] ]Allocate Var["work2", "Any Type"] ]Null["out"] @@ -38,13 +39,8 @@ ]Do If[Result[1], stream2] ]Release["n"] {Print["func done"] } + + Print[[[prog]Store Function[func]]Text] - Print[[func]Definitions] - { - Print[[func]Text] } } -Foo[] -{ -} -