Mercurial > repos > rhope
comparison nworker.rhope @ 21:e9272f7ebd26
Limited compilation from dataflow graph to C backend
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Tue, 23 Jun 2009 01:16:04 -0400 |
parents | b715532225c0 |
children | 914ad38f9b59 |
comparison
equal
deleted
inserted
replaced
20:b715532225c0 | 21:e9272f7ebd26 |
---|---|
187 met? <- [worker]Check Dependency[nodes,wires,~] | 187 met? <- [worker]Check Dependency[nodes,wires,~] |
188 }{ | 188 }{ |
189 met? <- Yes | 189 met? <- Yes |
190 } | 190 } |
191 }{ | 191 }{ |
192 Print[[ref]Index >>] | |
193 met? <- No | 192 met? <- No |
194 } | 193 } |
195 } | 194 } |
196 _Check Dependencies@NWorker[worker,nodes,inputs,input index:met?] | 195 _Check Dependencies@NWorker[worker,nodes,inputs,input index:met?] |
197 { | 196 { |
246 { | 245 { |
247 no deps <- [worker]No Dependencies | 246 no deps <- [worker]No Dependencies |
248 out <- [worker]_Dependency Groups[no deps, no deps, [()]Append[no deps]] | 247 out <- [worker]_Dependency Groups[no deps, no deps, [()]Append[no deps]] |
249 } | 248 } |
250 | 249 |
250 Format Input@NWorker[worker,noderef:out] | |
251 { | |
252 node <- [[worker]Nodes >>]Index[[noderef]Index >>] | |
253 If[[[node]Type >>] = ["call"]] | |
254 { | |
255 out <- AddRef[ [[["__result_"]Append[[noderef]Index >>]]Append["_"]]Append[[noderef]IO Num >>] ] | |
256 }{ | |
257 If[[[node]Type >>] = ["input"]] | |
258 { | |
259 input name <- [[worker]Inputs >>]Index[ [node]Data >> ] | |
260 out <- AddRef[input name] | |
261 } | |
262 } | |
263 } | |
264 | |
265 Collect Input@NWorker[worker,nodeinput:out] | |
266 { | |
267 inputchoices <- Map[nodeinput, ["Format Input"]Set Input[0, worker]] | |
268 [inputchoices]First | |
269 { | |
270 first <- [inputchoices]Index[~] | |
271 [inputchoices]Next[~] | |
272 { | |
273 out <- _Fold[inputchoices, ~, first, "OrValue"] | |
274 }{ | |
275 out <- Val[first] | |
276 } | |
277 }{ | |
278 out <- No | |
279 } | |
280 } | |
281 | |
282 Collect Inputs@NWorker[worker,node:out] | |
283 { | |
284 out <- Map[[node]Wires To>>, ["Collect Input"]Set Input[0, worker]] | |
285 } | |
286 | |
287 Save Result[func,num,node index:out] | |
288 { | |
289 out var <- [[["__result_"]Append[node index]]Append["_"]]Append[num] | |
290 out <- [[func]Allocate Var[out var, "Any Type"] | |
291 ]Move[Result[num], out var] | |
292 } | |
293 | |
251 Compile Node@NWorker[worker,program,func,nodes,current:out] | 294 Compile Node@NWorker[worker,program,func,nodes,current:out] |
252 { | 295 { |
253 Print[[node]Type >>] | 296 Print[[node]Type >>] |
254 node <- [[worker]Nodes >>]Index[[nodes]Index[current]] | 297 node index <- [nodes]Index[current] |
298 node <- [[worker]Nodes >>]Index[node index] | |
255 If[[[node]Type >>] = ["call"]] | 299 If[[[node]Type >>] = ["call"]] |
256 { | 300 { |
301 inputs <- [worker]Collect Inputs[node] | |
257 [program]Method?[[[node]Data >>]Name >>] | 302 [program]Method?[[[node]Data >>]Name >>] |
258 { | 303 { |
259 nfunc <- [func]Method Call[[[node]Data >>]Name >>, ()] | 304 with call <- [func]Method Call[[[node]Data >>]Name >>, inputs] |
260 }{ | 305 }{ |
261 nfunc <- [func]Call[[[node]Data >>]Name >>, ()] | 306 with call <- [func]Call[[[node]Data >>]Name >>, inputs] |
262 } | 307 } |
263 }{ | 308 nfunc <- Fold[["Save Result"]Set Input[2, node index], with call, Range[0, [node]Outputs >>]] |
264 nfunc <- Val[func] | 309 }{ |
310 If[[[node]Type >>] = ["output"]] | |
311 { | |
312 inputs <- [worker]Collect Inputs[node] | |
313 nfunc <- [func]Move[[inputs]Index[0], [[worker]Outputs >>]Index[ [node]Data >> ] ] | |
314 }{ | |
315 nfunc <- Val[func] | |
316 } | |
265 } | 317 } |
266 [nodes]Next[current] | 318 [nodes]Next[current] |
267 { | 319 { |
268 out <- [worker]Compile Node[program,nfunc,nodes,~] | 320 out <- [worker]Compile Node[program,nfunc,nodes,~] |
269 }{ | 321 }{ |
286 }{ | 338 }{ |
287 out <- Val[nfunc] | 339 out <- Val[nfunc] |
288 } | 340 } |
289 } | 341 } |
290 | 342 |
343 Release Var[func,type,name:out] | |
344 { | |
345 out <- [func]Release[name] | |
346 } | |
347 | |
291 Compile Worker@NWorker[worker,program,name:out] | 348 Compile Worker@NWorker[worker,program,name:out] |
292 { | 349 { |
293 func <- [program]Create Function[name,[worker]Inputs >>, [worker]Outputs >>, [worker]Convention >>] | 350 func <- Fold["Null", [program]Create Function[name,[worker]Inputs >>, [worker]Outputs >>, [worker]Convention >>], [worker]Outputs >>] |
294 groups <- [worker]Dependency Groups | 351 groups <- [worker]Dependency Groups |
295 [groups]First | 352 [groups]First |
296 { | 353 { |
297 final func <- [worker]Compile Group[program,func,groups, ~] | 354 final func <- [worker]Compile Group[program,func,groups, ~] |
298 }{ | 355 }{ |
299 final func <- Val[func] | 356 final func <- Val[func] |
300 } | 357 } |
301 out <- [program]Store Function[final func] | 358 out <- [program]Store Function[Fold["Release Var", final func, [final func]Variables >>]] |
302 } | 359 } |
303 | 360 |
304 Test[:out] | 361 Test[:out] |
305 { | 362 { |
306 ref+ <- Worker Ref["+","cdecl",2,1] | 363 ref+ <- Worker Ref["+","cdecl",2,1] |
318 ]Add Wire[c,0,call*,1] | 375 ]Add Wire[c,0,call*,1] |
319 ]Add Wire[call*,0,outref,0] | 376 ]Add Wire[call*,0,outref,0] |
320 }}}}}} | 377 }}}}}} |
321 } | 378 } |
322 | 379 |
323 Test Compile[:out] | 380 Test Graph to Backend[:out] |
324 { | 381 { |
325 out <- [Test[]]Compile Worker[C Program[] "Test"] | 382 out <- [Test[]]Compile Worker[C Program[], "Test"] |
326 } | 383 } |
327 | 384 |
328 Main[] | 385 Main[] |
329 { | 386 { |
330 Pretty Print[Test Compile[], ""] | 387 Pretty Print[Test Graph to Backend[], ""] |
331 } | 388 } |