Mercurial > repos > rhope
diff 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 |
line wrap: on
line diff
--- a/parser_old.rhope Sat Jun 19 23:13:41 2010 -0400 +++ b/parser_old.rhope Thu Jul 01 21:32:08 2010 -0400 @@ -245,6 +245,72 @@ } } +Check Question Mark[params, index:has mark,no mark] +{ + param,no mark <-[params]Index[index] + { + If[[Type Of[param]]=["Named Pipe Node"]] + { + has mark <-If[[[param]Name >>] = ["?"]] {} + { + has mark,no mark <- Check Question Mark[params, [index]+[1]] + } + }{ + has mark,no mark <- Check Question Mark[params, [index]+[1]] + } + } +} + +Collect Literal Inputs[literal, params, index, complex inputs:literal out,complex out] +{ + param <- [params]Index[index] + { + If[[Type Of[param]]=["Literal Node"]] + { + next literal <- [literal]Set Input[index, [param]Value >>] + next complex <- Val[complex inputs] + }{ + ,doset <- If[[Type Of[param]]=["Named Pipe Node"]] + { + ,doset <- If[[[param]Name >>] = ["?"]] + { + //Question mark indicates unpopulated input + next complex <- Val[complex inputs] + next literal <- Val[literal] + } + } + + Val[doset] + { + next complex <- [complex inputs]Set[index, param] + next literal <- Val[literal] + } + } + literal out, complex out <- Collect Literal Inputs[next literal, params, [index]+[1], next complex] + }{ + literal out <- literal + complex out <- complex inputs + } +} + +Do Set Input[literal,param,index:out] +{ + out <- New@Worker Node["Set Input", [[[()]Append[literal]]Append[New@Literal Node[index]]]Append[param]] +} + +Check Worker Literals@Worker Node[node,program:out] +{ + new params <- Map[[node]Params >>, ["Check Worker Literals"]Set Input[1, program]] + Check Question Mark[new params, 0] + { + base literal, complex inputs <- Collect Literal Inputs[Worker Literal[[node]Name >>], new params, 0, ()] + new node <- Fold["Do Set Input", New@Literal Node[base literal], complex inputs] + }{ + new node <- [node]Params <<[new params] + } + out <- [new node]Blocks <<[ Map[[node]Blocks >>, ["Map"]Set Input[1, ["Check Worker Literals"]Set Input[1, program]]] ] +} + Add Multi Wire[worker,ref,junk,end index,input num:out] { out <- [worker]Add Wire[[ref]Index >>, [ref]Output Number >>, end index, input num] @@ -252,11 +318,23 @@ Add Param Wire[worker,param,input num,end index,blocks,parse worker,assignments:out] { - param worker, start index, output num <- [param]Add Wires[worker, blocks, parse worker, assignments] {} + Print[["Add Param Wire: "]Append[input num]] + { + param worker, start index, output num <- [param]Add Wires[worker, blocks, parse worker, assignments] { Print["got param worker"] } { + Print[["got normal output for param: "]Append[input num]] + { + Print[["Start index: "]Append[start index]] + Print[["Output num: "]Append[output num]] + out <- [param worker]Add Wire[start index, output num, end index, input num] + { Print["Added param wire"] } + } }{}{ + Print["got multi output"] out <- Fold[[["Add Multi Wire"]Set Input[3, end index]]Set Input[4, input num], param worker, ~] + { Print["Added multi wire"] } + } } } @@ -326,16 +404,27 @@ Add Wires@Worker Node[node,worker,blocks,parse worker,assignments:worker,index,num,unused] { + Print[["Add Wires@Worker Node: "]Append[[node]Name >>]] + { worker,index,num <- Add Wires Worker or Field[node, worker, blocks, parse worker, assignments] + } } Add Wires Worker or Field[node,worker,blocks,parse worker,assignments:worker,index,num,unused] { Fold[[["Assignments Add Wires"]Set Input[3, parse worker]]Set Input[4, [node]Index >>], worker, [node]Assignments >>] - { + { + Print["Assignments Add Wires done"] Fold[[[[["Add Block Wire"]Set Input[3, [node]Index >>]]Set Input[4, blocks]]Set Input[5, parse worker]]Set Input[6, assignments], ~, [node]Blocks >>] { - 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 >>] }} + Print["Add Block Wire done"] + 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 >>] + { Print["Add Param Wire done"] + index <- [node]Index >> + num <- 0 + } + } + } If[Has Block Params[[node]Params >>]] { worker <- Val[params worker] @@ -347,8 +436,6 @@ worker <- Val[params worker] } } - index <- [node]Index >> - num <- 0 } Blueprint Field Node @@ -396,6 +483,13 @@ worker,index,num <- Add Wires Worker or Field[node, worker, blocks, parse worker, assignments] } +Check Worker Literals@Field Node[node,program:out] +{ + new params <- Map[[node]Params >>, ["Check Worker Literals"]Set Input[1, program]] + out <- [[node]Blocks <<[ Map[[node]Blocks >>, ["Map"]Set Input[1, ["Check Worker Literals"]Set Input[1, program]]] ] + ]Params <<[new params] +} + Blueprint Named Pipe Node { Name @@ -484,6 +578,11 @@ 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 >>] } +Check Worker Literals@Named Pipe Node[node,program:out] +{ + out <- [node]Blocks <<[ Map[[node]Blocks >>, ["Map"]Set Input[1, ["Check Worker Literals"]Set Input[1, program]]] ] +} + Blueprint Global Node { Store @@ -518,6 +617,11 @@ out <- Yes } +Check Worker Literals@Global Node[node,program:out] +{ + out <- [node]Blocks <<[ Map[[node]Blocks >>, ["Map"]Set Input[1, ["Check Worker Literals"]Set Input[1, program]]] ] +} + Blueprint Literal Node { Value @@ -547,7 +651,16 @@ Add Wires@Literal Node[node,worker,blocks,parse worker,assignments:worker,index,num,unused] { + Print[["Add Wires@Literal Node, Literal Type: "]Append[Type Of[[node]Value >>]]] worker,index,num <- Add Wires Literal or Global[node, worker, blocks, parse worker, assignments] + { Print["Got worker"] } + { Print["got index"] } + { Print["got num"] } +} + +Check Worker Literals@Literal Node[node,program:out] +{ + out <- [node]Blocks <<[ Map[[node]Blocks >>, ["Map"]Set Input[1, ["Check Worker Literals"]Set Input[1, program]]] ] } Add Wires Literal or Global[node,worker,blocks,parse worker,junk:worker,index,num,unused] @@ -1294,6 +1407,16 @@ } } +Check Worker Literals@Parse Worker[worker,program:out] +{ + If[[Type Of[[worker]Trees >>]] = ["List"]] + { + out <- [worker]Trees <<[ Map[[worker]Trees >>, ["Check Worker Literals"]Set Input[1, program]] ] + }{ + out <- worker + } +} + Add Workers[workers,name,program:out] { prog,worker <- [program]New Worker[name] @@ -1330,7 +1453,20 @@ }{ Print[["Transforming "]Append[name]] trees, nworker, refs <- Add List to Worker[[worker]Trees >>, [NWorker["rhope"]]Uses[[worker]Uses Stores >>], prog, worker, Dictionary[]] - final nworker <- Fold[[["Add Wires Helper"]Set Input[3, worker]]Set Input[4, refs], nworker, trees] + { + ,proceed <- If[[name] = ["Main"]] + { Print["Added Trees to worker"] + { proceed <- Pretty Print[trees, ""] }} + Val[proceed] + { + final nworker <- Fold[[["Add Wires Helper"]Set Input[3, worker]]Set Input[4, refs], nworker, trees] + { + If[[name] = ["Main"]] + { Print["Added wires to worker"] } + } + } + } + } out <- [prog]Bind Worker[name, final nworker] } @@ -1556,8 +1692,11 @@ Null[text, params, New@Parse Program[], 0] { Print["Parsing imports"] - tree <- Process Imports[~, params] - { Print["Compiling"] } + Process Imports[~, params] + { + tree <- [~]Workers << [ Map[[~]Workers >>, ["Check Worker Literals"]Set Input[1, ~]] ] + { Print["Compiling"] } + } compiled <- [Tree to Program Native[tree]]Compile Program[C Program[]] { Print["Compiled program to backend"] } outfile <- <String@File[ [fname]Append[".c"] ]