Mercurial > repos > rhope
comparison parser_old.rhope @ 74:a844c623c7df
Add support for Worker type
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Thu, 01 Jul 2010 21:32:08 -0400 |
parents | 6a1a7d5cc2d9 |
children | 0083b2f7b3c7 |
comparison
equal
deleted
inserted
replaced
73:6a1a7d5cc2d9 | 74:a844c623c7df |
---|---|
243 }{ | 243 }{ |
244 Print[["Error: Could not find a worker named "]Append[[node]Name >>]] | 244 Print[["Error: Could not find a worker named "]Append[[node]Name >>]] |
245 } | 245 } |
246 } | 246 } |
247 | 247 |
248 Check Question Mark[params, index:has mark,no mark] | |
249 { | |
250 param,no mark <-[params]Index[index] | |
251 { | |
252 If[[Type Of[param]]=["Named Pipe Node"]] | |
253 { | |
254 has mark <-If[[[param]Name >>] = ["?"]] {} | |
255 { | |
256 has mark,no mark <- Check Question Mark[params, [index]+[1]] | |
257 } | |
258 }{ | |
259 has mark,no mark <- Check Question Mark[params, [index]+[1]] | |
260 } | |
261 } | |
262 } | |
263 | |
264 Collect Literal Inputs[literal, params, index, complex inputs:literal out,complex out] | |
265 { | |
266 param <- [params]Index[index] | |
267 { | |
268 If[[Type Of[param]]=["Literal Node"]] | |
269 { | |
270 next literal <- [literal]Set Input[index, [param]Value >>] | |
271 next complex <- Val[complex inputs] | |
272 }{ | |
273 ,doset <- If[[Type Of[param]]=["Named Pipe Node"]] | |
274 { | |
275 ,doset <- If[[[param]Name >>] = ["?"]] | |
276 { | |
277 //Question mark indicates unpopulated input | |
278 next complex <- Val[complex inputs] | |
279 next literal <- Val[literal] | |
280 } | |
281 } | |
282 | |
283 Val[doset] | |
284 { | |
285 next complex <- [complex inputs]Set[index, param] | |
286 next literal <- Val[literal] | |
287 } | |
288 } | |
289 literal out, complex out <- Collect Literal Inputs[next literal, params, [index]+[1], next complex] | |
290 }{ | |
291 literal out <- literal | |
292 complex out <- complex inputs | |
293 } | |
294 } | |
295 | |
296 Do Set Input[literal,param,index:out] | |
297 { | |
298 out <- New@Worker Node["Set Input", [[[()]Append[literal]]Append[New@Literal Node[index]]]Append[param]] | |
299 } | |
300 | |
301 Check Worker Literals@Worker Node[node,program:out] | |
302 { | |
303 new params <- Map[[node]Params >>, ["Check Worker Literals"]Set Input[1, program]] | |
304 Check Question Mark[new params, 0] | |
305 { | |
306 base literal, complex inputs <- Collect Literal Inputs[Worker Literal[[node]Name >>], new params, 0, ()] | |
307 new node <- Fold["Do Set Input", New@Literal Node[base literal], complex inputs] | |
308 }{ | |
309 new node <- [node]Params <<[new params] | |
310 } | |
311 out <- [new node]Blocks <<[ Map[[node]Blocks >>, ["Map"]Set Input[1, ["Check Worker Literals"]Set Input[1, program]]] ] | |
312 } | |
313 | |
248 Add Multi Wire[worker,ref,junk,end index,input num:out] | 314 Add Multi Wire[worker,ref,junk,end index,input num:out] |
249 { | 315 { |
250 out <- [worker]Add Wire[[ref]Index >>, [ref]Output Number >>, end index, input num] | 316 out <- [worker]Add Wire[[ref]Index >>, [ref]Output Number >>, end index, input num] |
251 } | 317 } |
252 | 318 |
253 Add Param Wire[worker,param,input num,end index,blocks,parse worker,assignments:out] | 319 Add Param Wire[worker,param,input num,end index,blocks,parse worker,assignments:out] |
254 { | 320 { |
255 param worker, start index, output num <- [param]Add Wires[worker, blocks, parse worker, assignments] {} | 321 Print[["Add Param Wire: "]Append[input num]] |
256 { | 322 { |
323 param worker, start index, output num <- [param]Add Wires[worker, blocks, parse worker, assignments] { Print["got param worker"] } | |
324 { | |
325 Print[["got normal output for param: "]Append[input num]] | |
326 { | |
327 Print[["Start index: "]Append[start index]] | |
328 Print[["Output num: "]Append[output num]] | |
329 | |
257 out <- [param worker]Add Wire[start index, output num, end index, input num] | 330 out <- [param worker]Add Wire[start index, output num, end index, input num] |
331 { Print["Added param wire"] } | |
332 } | |
258 }{}{ | 333 }{}{ |
334 Print["got multi output"] | |
259 out <- Fold[[["Add Multi Wire"]Set Input[3, end index]]Set Input[4, input num], param worker, ~] | 335 out <- Fold[[["Add Multi Wire"]Set Input[3, end index]]Set Input[4, input num], param worker, ~] |
336 { Print["Added multi wire"] } | |
337 } | |
260 } | 338 } |
261 } | 339 } |
262 | 340 |
263 _Add Block Wire[worker,node,junk,blocks,parse worker,assignments:out] | 341 _Add Block Wire[worker,node,junk,blocks,parse worker,assignments:out] |
264 { | 342 { |
324 } | 402 } |
325 } | 403 } |
326 | 404 |
327 Add Wires@Worker Node[node,worker,blocks,parse worker,assignments:worker,index,num,unused] | 405 Add Wires@Worker Node[node,worker,blocks,parse worker,assignments:worker,index,num,unused] |
328 { | 406 { |
407 Print[["Add Wires@Worker Node: "]Append[[node]Name >>]] | |
408 { | |
329 worker,index,num <- Add Wires Worker or Field[node, worker, blocks, parse worker, assignments] | 409 worker,index,num <- Add Wires Worker or Field[node, worker, blocks, parse worker, assignments] |
410 } | |
330 } | 411 } |
331 | 412 |
332 Add Wires Worker or Field[node,worker,blocks,parse worker,assignments:worker,index,num,unused] | 413 Add Wires Worker or Field[node,worker,blocks,parse worker,assignments:worker,index,num,unused] |
333 { | 414 { |
334 Fold[[["Assignments Add Wires"]Set Input[3, parse worker]]Set Input[4, [node]Index >>], worker, [node]Assignments >>] | 415 Fold[[["Assignments Add Wires"]Set Input[3, parse worker]]Set Input[4, [node]Index >>], worker, [node]Assignments >>] |
335 { | 416 { |
417 Print["Assignments Add Wires done"] | |
336 Fold[[[[["Add Block Wire"]Set Input[3, [node]Index >>]]Set Input[4, blocks]]Set Input[5, parse worker]]Set Input[6, assignments], ~, [node]Blocks >>] | 418 Fold[[[[["Add Block Wire"]Set Input[3, [node]Index >>]]Set Input[4, blocks]]Set Input[5, parse worker]]Set Input[6, assignments], ~, [node]Blocks >>] |
337 { | 419 { |
338 params worker <- Fold[[[[["Add Param Wire"]Set Input[3, [node]Index >>]]Set Input[4, blocks]]Set Input[5, parse worker]]Set Input[6, assignments], ~, [node]Params >>] }} | 420 Print["Add Block Wire done"] |
421 params worker <- Fold[[[[["Add Param Wire"]Set Input[3, [node]Index >>]]Set Input[4, blocks]]Set Input[5, parse worker]]Set Input[6, assignments], ~, [node]Params >>] | |
422 { Print["Add Param Wire done"] | |
423 index <- [node]Index >> | |
424 num <- 0 | |
425 } | |
426 } | |
427 } | |
339 If[Has Block Params[[node]Params >>]] | 428 If[Has Block Params[[node]Params >>]] |
340 { | 429 { |
341 worker <- Val[params worker] | 430 worker <- Val[params worker] |
342 }{ | 431 }{ |
343 [blocks]Peek | 432 [blocks]Peek |
345 worker <- [params worker]Add Wire[[~]Index >>, [~]Output Number >>, [node]Index >>, [0]-[1]] | 434 worker <- [params worker]Add Wire[[~]Index >>, [~]Output Number >>, [node]Index >>, [0]-[1]] |
346 }{ | 435 }{ |
347 worker <- Val[params worker] | 436 worker <- Val[params worker] |
348 } | 437 } |
349 } | 438 } |
350 index <- [node]Index >> | |
351 num <- 0 | |
352 } | 439 } |
353 | 440 |
354 Blueprint Field Node | 441 Blueprint Field Node |
355 { | 442 { |
356 Name | 443 Name |
392 } | 479 } |
393 | 480 |
394 Add Wires@Field Node[node,worker,blocks,parse worker,assignments:worker,index,num] | 481 Add Wires@Field Node[node,worker,blocks,parse worker,assignments:worker,index,num] |
395 { | 482 { |
396 worker,index,num <- Add Wires Worker or Field[node, worker, blocks, parse worker, assignments] | 483 worker,index,num <- Add Wires Worker or Field[node, worker, blocks, parse worker, assignments] |
484 } | |
485 | |
486 Check Worker Literals@Field Node[node,program:out] | |
487 { | |
488 new params <- Map[[node]Params >>, ["Check Worker Literals"]Set Input[1, program]] | |
489 out <- [[node]Blocks <<[ Map[[node]Blocks >>, ["Map"]Set Input[1, ["Check Worker Literals"]Set Input[1, program]]] ] | |
490 ]Params <<[new params] | |
397 } | 491 } |
398 | 492 |
399 Blueprint Named Pipe Node | 493 Blueprint Named Pipe Node |
400 { | 494 { |
401 Name | 495 Name |
482 index <- Val[my index] | 576 index <- Val[my index] |
483 | 577 |
484 worker <- Fold[[[[["Add Block Wire"]Set Input[3, my index]]Set Input[4, blocks]]Set Input[5, parse worker]]Set Input[6, assignments], wires worker, [node]Blocks >>] | 578 worker <- Fold[[[[["Add Block Wire"]Set Input[3, my index]]Set Input[4, blocks]]Set Input[5, parse worker]]Set Input[6, assignments], wires worker, [node]Blocks >>] |
485 } | 579 } |
486 | 580 |
581 Check Worker Literals@Named Pipe Node[node,program:out] | |
582 { | |
583 out <- [node]Blocks <<[ Map[[node]Blocks >>, ["Map"]Set Input[1, ["Check Worker Literals"]Set Input[1, program]]] ] | |
584 } | |
585 | |
487 Blueprint Global Node | 586 Blueprint Global Node |
488 { | 587 { |
489 Store | 588 Store |
490 Name | 589 Name |
491 Assignments | 590 Assignments |
516 Has Block@Global Node[junk:out,unused] | 615 Has Block@Global Node[junk:out,unused] |
517 { | 616 { |
518 out <- Yes | 617 out <- Yes |
519 } | 618 } |
520 | 619 |
620 Check Worker Literals@Global Node[node,program:out] | |
621 { | |
622 out <- [node]Blocks <<[ Map[[node]Blocks >>, ["Map"]Set Input[1, ["Check Worker Literals"]Set Input[1, program]]] ] | |
623 } | |
624 | |
521 Blueprint Literal Node | 625 Blueprint Literal Node |
522 { | 626 { |
523 Value | 627 Value |
524 Assignments | 628 Assignments |
525 Blocks | 629 Blocks |
545 } | 649 } |
546 } | 650 } |
547 | 651 |
548 Add Wires@Literal Node[node,worker,blocks,parse worker,assignments:worker,index,num,unused] | 652 Add Wires@Literal Node[node,worker,blocks,parse worker,assignments:worker,index,num,unused] |
549 { | 653 { |
654 Print[["Add Wires@Literal Node, Literal Type: "]Append[Type Of[[node]Value >>]]] | |
550 worker,index,num <- Add Wires Literal or Global[node, worker, blocks, parse worker, assignments] | 655 worker,index,num <- Add Wires Literal or Global[node, worker, blocks, parse worker, assignments] |
656 { Print["Got worker"] } | |
657 { Print["got index"] } | |
658 { Print["got num"] } | |
659 } | |
660 | |
661 Check Worker Literals@Literal Node[node,program:out] | |
662 { | |
663 out <- [node]Blocks <<[ Map[[node]Blocks >>, ["Map"]Set Input[1, ["Check Worker Literals"]Set Input[1, program]]] ] | |
551 } | 664 } |
552 | 665 |
553 Add Wires Literal or Global[node,worker,blocks,parse worker,junk:worker,index,num,unused] | 666 Add Wires Literal or Global[node,worker,blocks,parse worker,junk:worker,index,num,unused] |
554 { | 667 { |
555 assignments worker <- Fold[[["Assignments Add Wires"]Set Input[3, parse worker]]Set Input[4, [node]Index >>], worker, [node]Assignments >>] | 668 assignments worker <- Fold[[["Assignments Add Wires"]Set Input[3, parse worker]]Set Input[4, [node]Index >>], worker, [node]Assignments >>] |
1292 } | 1405 } |
1293 } | 1406 } |
1294 } | 1407 } |
1295 } | 1408 } |
1296 | 1409 |
1410 Check Worker Literals@Parse Worker[worker,program:out] | |
1411 { | |
1412 If[[Type Of[[worker]Trees >>]] = ["List"]] | |
1413 { | |
1414 out <- [worker]Trees <<[ Map[[worker]Trees >>, ["Check Worker Literals"]Set Input[1, program]] ] | |
1415 }{ | |
1416 out <- worker | |
1417 } | |
1418 } | |
1419 | |
1297 Add Workers[workers,name,program:out] | 1420 Add Workers[workers,name,program:out] |
1298 { | 1421 { |
1299 prog,worker <- [program]New Worker[name] | 1422 prog,worker <- [program]New Worker[name] |
1300 [worker]Set IO Counts[ [[[workers]Index[name]]Inputs >>]Length, [[[workers]Index[name]]Outputs >>]Length] | 1423 [worker]Set IO Counts[ [[[workers]Index[name]]Inputs >>]Length, [[[workers]Index[name]]Outputs >>]Length] |
1301 [workers]Next[name] | 1424 [workers]Next[name] |
1328 ]Library <<[ [[worker]Trees >>]Name >> ] | 1451 ]Library <<[ [[worker]Trees >>]Name >> ] |
1329 | 1452 |
1330 }{ | 1453 }{ |
1331 Print[["Transforming "]Append[name]] | 1454 Print[["Transforming "]Append[name]] |
1332 trees, nworker, refs <- Add List to Worker[[worker]Trees >>, [NWorker["rhope"]]Uses[[worker]Uses Stores >>], prog, worker, Dictionary[]] | 1455 trees, nworker, refs <- Add List to Worker[[worker]Trees >>, [NWorker["rhope"]]Uses[[worker]Uses Stores >>], prog, worker, Dictionary[]] |
1333 final nworker <- Fold[[["Add Wires Helper"]Set Input[3, worker]]Set Input[4, refs], nworker, trees] | 1456 { |
1457 ,proceed <- If[[name] = ["Main"]] | |
1458 { Print["Added Trees to worker"] | |
1459 { proceed <- Pretty Print[trees, ""] }} | |
1460 Val[proceed] | |
1461 { | |
1462 final nworker <- Fold[[["Add Wires Helper"]Set Input[3, worker]]Set Input[4, refs], nworker, trees] | |
1463 { | |
1464 If[[name] = ["Main"]] | |
1465 { Print["Added wires to worker"] } | |
1466 } | |
1467 } | |
1468 } | |
1469 | |
1334 } | 1470 } |
1335 out <- [prog]Bind Worker[name, final nworker] | 1471 out <- [prog]Bind Worker[name, final nworker] |
1336 } | 1472 } |
1337 | 1473 |
1338 Add Wires Helper[worker,node,unused,parse worker,assignments:out] | 1474 Add Wires Helper[worker,node,unused,parse worker,assignments:out] |
1554 params <- New@Parser[] | 1690 params <- New@Parser[] |
1555 Print[["Parsing "]Append[fname]] | 1691 Print[["Parsing "]Append[fname]] |
1556 Null[text, params, New@Parse Program[], 0] | 1692 Null[text, params, New@Parse Program[], 0] |
1557 { | 1693 { |
1558 Print["Parsing imports"] | 1694 Print["Parsing imports"] |
1559 tree <- Process Imports[~, params] | 1695 Process Imports[~, params] |
1560 { Print["Compiling"] } | 1696 { |
1697 tree <- [~]Workers << [ Map[[~]Workers >>, ["Check Worker Literals"]Set Input[1, ~]] ] | |
1698 { Print["Compiling"] } | |
1699 } | |
1561 compiled <- [Tree to Program Native[tree]]Compile Program[C Program[]] | 1700 compiled <- [Tree to Program Native[tree]]Compile Program[C Program[]] |
1562 { Print["Compiled program to backend"] } | 1701 { Print["Compiled program to backend"] } |
1563 outfile <- <String@File[ [fname]Append[".c"] ] | 1702 outfile <- <String@File[ [fname]Append[".c"] ] |
1564 [outfile]Put String[ [compiled]Text ] | 1703 [outfile]Put String[ [compiled]Text ] |
1565 { Print[["Wrote output to "]Append[ [fname]Append[".c"] ]] } | 1704 { Print[["Wrote output to "]Append[ [fname]Append[".c"] ]] } |