comparison nworker.rhope @ 75:0083b2f7b3c7

Partially working implementation of List. Modified build scripts to allow use of other compilers. Fixed some bugs involving method implementations on different types returning different numbers of outputs. Added Fold to the 'builtins' in the comipler.
author Mike Pavone <pavone@retrodev.com>
date Tue, 06 Jul 2010 07:52:59 -0400
parents a844c623c7df
children 2e2e55fc12f9
comparison
equal deleted inserted replaced
74:a844c623c7df 75:0083b2f7b3c7
148 Blueprint Worker Ref 148 Blueprint Worker Ref
149 { 149 {
150 Name 150 Name
151 Convention 151 Convention
152 Inputs 152 Inputs
153 Min Inputs
153 Outputs 154 Outputs
155 Min Outputs
154 Is Method? 156 Is Method?
155 } 157 }
156 158
157 Worker Ref[name,convention,inputs,outputs,ismethod?:out] 159 Worker Ref[name,convention,inputs,outputs,ismethod?:out]
158 { 160 {
159 out <- [[[[[Build["Worker Ref"]]Name <<[name]]Convention <<[convention]]Inputs <<[inputs]]Outputs <<[outputs]]Is Method? <<[ismethod?] 161 out <- [[[[[[[Build["Worker Ref"]]Name <<[name]]Convention <<[convention]]Inputs <<[inputs]]Outputs <<[outputs]]Is Method? <<[ismethod?]]Min Inputs <<[inputs]]Min Outputs <<[outputs]
160 } 162 }
161 163
162 Blueprint Node Ref 164 Blueprint Node Ref
163 { 165 {
164 Index 166 Index
181 Blueprint NWorker Node 183 Blueprint NWorker Node
182 { 184 {
183 Type 185 Type
184 Data 186 Data
185 Inputs 187 Inputs
188 Min Inputs
186 Input Types 189 Input Types
187 Outputs 190 Outputs
191 Min Outputs
188 Output Types 192 Output Types
189 Wires From 193 Wires From
190 Wires To 194 Wires To
191 Conditions 195 Conditions
192 } 196 }
255 } 259 }
256 260
257 261
258 NWorker Node[type,data,inputs,outputs:out] 262 NWorker Node[type,data,inputs,outputs:out]
259 { 263 {
260 out <- [[[[[[[[[Build["NWorker Node"] 264 out <- [[[[[[[[[[[Build["NWorker Node"]
261 ]Type <<[type] 265 ]Type <<[type]
262 ]Data <<[data] 266 ]Data <<[data]
263 ]Inputs <<[inputs] 267 ]Inputs <<[inputs]
268 ]Min Inputs <<[inputs]
264 ]Outputs <<[outputs] 269 ]Outputs <<[outputs]
270 ]Min Outputs <<[outputs]
265 ]Wires From <<[List of Lists[outputs]] 271 ]Wires From <<[List of Lists[outputs]]
266 ]Wires To <<[List of Lists[[inputs]+[1]]] 272 ]Wires To <<[List of Lists[[inputs]+[1]]]
267 ]Conditions <<[AndSet[]] 273 ]Conditions <<[AndSet[]]
268 ]Input Types <<[()] 274 ]Input Types <<[()]
269 ]Output Types <<[()] 275 ]Output Types <<[()]
291 } 297 }
292 298
293 Add Node@NWorker[worker,type,data,inputs,outputs:out,node index] 299 Add Node@NWorker[worker,type,data,inputs,outputs:out,node index]
294 { 300 {
295 out <- [worker]Nodes <<[[[worker]Nodes >>]Append[NWorker Node[type,data,inputs,outputs]]] 301 out <- [worker]Nodes <<[[[worker]Nodes >>]Append[NWorker Node[type,data,inputs,outputs]]]
302 node index <- [[worker]Nodes >>]Length
303 }
304
305 Add Full Node@NWorker[worker,type,data,inputs,min inputs,outputs,min outputs:out,node index]
306 {
307 out <- [worker]Nodes <<[[[worker]Nodes >>]Append[ [[NWorker Node[type,data,inputs,outputs]]Min Inputs <<[min inputs]]Min Outputs <<[min outputs] ]]
296 node index <- [[worker]Nodes >>]Length 308 node index <- [[worker]Nodes >>]Length
297 } 309 }
298 310
299 Propagate Type[nodelist,dest,prog,worker,type:out] 311 Propagate Type[nodelist,dest,prog,worker,type:out]
300 { 312 {
459 out <- [worker]Nodes <<[Fold[[["Infer Types Node"]Set Input[3, prog]]Set Input[4, worker], [worker]Nodes >>, [worker]Nodes >>]] 471 out <- [worker]Nodes <<[Fold[[["Infer Types Node"]Set Input[3, prog]]Set Input[4, worker], [worker]Nodes >>, [worker]Nodes >>]]
460 } 472 }
461 473
462 Add Worker Call@NWorker[worker,tocall:out,node index] 474 Add Worker Call@NWorker[worker,tocall:out,node index]
463 { 475 {
464 out, node index <- [worker]Add Node["call",tocall,[tocall]Inputs >>,[tocall]Outputs >>] 476 out, node index <- [worker]Add Full Node["call",tocall,[tocall]Inputs >>, [tocall]Min Inputs >>,[tocall]Outputs >>, [tocall]Min Outputs >>]
465 } 477 }
466 478
467 Add Constant@NWorker[worker,constant:out,node index] 479 Add Constant@NWorker[worker,constant:out,node index]
468 { 480 {
469 out, node index <- [worker]Add Node["const",constant,0,1] 481 out, node index <- [worker]Add Node["const",constant,0,1]
717 ]Move[Result[num], out var] 729 ]Move[Result[num], out var]
718 */ 730 */
719 out <- [func]Move[Result[num], out var] 731 out <- [func]Move[Result[num], out var]
720 } 732 }
721 733
734 Save Maybe Result[func,num,node index:out]
735 {
736 out var <- [[["__result_"]Append[node index]]Append["_"]]Append[num]
737 out <- [func]Move[Check Result[num], out var]
738 }
739
740 Max Used Output[node,cur:out]
741 {
742 If[[cur] < [0]]
743 {
744 out <- cur
745 }{
746 [[[node]Wires From >>]Index[cur]]Index[0]
747 {
748 out <- cur
749 }{
750 out <- Max Used Output[node, [cur]-[1]]
751 }
752 }
753 }
754
722 Compile Call Node[node,program,func,inputs,node index:out] 755 Compile Call Node[node,program,func,inputs,node index:out]
723 { 756 {
724 If[[[node]Type >>] = ["getfield"]] 757 If[[[node]Type >>] = ["getfield"]]
725 { 758 {
726 with call <- [func]Get Field Call[[node]Data >>, [inputs]Index[0]] 759 with call <- [func]Get Field Call[[node]Data >>, [inputs]Index[0]]
760 save outs <- [node]Outputs >>
761 out <- Val[after save]
727 }{ 762 }{
728 If[[[node]Type >>] = ["setfield"]] 763 If[[[node]Type >>] = ["setfield"]]
729 { 764 {
730 with call <- [func]Set Field Call[[node]Data >>, [inputs]Index[0], [inputs]Index[1]] 765 with call <- [func]Set Field Call[[node]Data >>, [inputs]Index[0], [inputs]Index[1]]
766 save outs <- [node]Outputs >>
767 out <- Val[after save]
731 }{ 768 }{
732 [program]Method?[[[node]Data >>]Name >>] 769 [program]Method?[[[node]Data >>]Name >>]
733 { 770 {
734 with call <- [func]Method Call[[[node]Data >>]Name >>, inputs] 771 with call <- [func]Method Call[[[node]Data >>]Name >>, inputs]
735 }{ 772 }{
736 with call <- [func]Call[[[node]Data >>]Name >>, inputs] 773 with call <- [func]Call[[[node]Data >>]Name >>, inputs]
737 } 774 }
738 } 775 first unused <- [Max Used Output[node, [[node]Outputs >>]-[1]]]+[1]
739 } 776 If[[first unused] > [[node]Min Outputs >>]]
740 out <- Fold[["Save Result"]Set Input[2, node index], with call, Range[0, [node]Outputs >>]] 777 {
778 save outs <- [node]Min Outputs >>
779 after maybe <- Fold[["Save Maybe Result"]Set Input[2, node index], after save, Range[save outs, first unused]]
780 }{
781 save outs <- Val[first unused]
782 after maybe <- Val[after save]
783 }
784 If[[first unused] < [[node]Outputs >>]]
785 {
786 out <- [after maybe]Discard Outputs[first unused]
787 }{
788 out <- Val[after maybe]
789 }
790 }
791 }
792 after save <- Fold[["Save Result"]Set Input[2, node index], with call, Range[0, save outs]]
741 } 793 }
742 794
743 Compile Node@NWorker[worker,program,func,nodes,current:out,out worker] 795 Compile Node@NWorker[worker,program,func,nodes,current:out,out worker]
744 { 796 {
745 node index <- [nodes]Index[current] 797 node index <- [nodes]Index[current]
869 921
870 Node Result Vars[vars,node,index:out] 922 Node Result Vars[vars,node,index:out]
871 { 923 {
872 [("call","getfield","setfield")]Find[[node]Type >>] 924 [("call","getfield","setfield")]Find[[node]Type >>]
873 { 925 {
874 out <- Fold[["Result Var"]Set Input[2, index], vars, Range[0, [node]Outputs >>]] 926 If[[[node]Type >>]=["call"]]
927 {
928 save outs <- [Max Used Output[node, [[node]Outputs >>]-[1]]]+[1]
929 }{
930 save outs <- [node]Outputs >>
931 }
932 out <- Fold[["Result Var"]Set Input[2, index], vars, Range[0, save outs]]
875 }{ 933 }{
876 out <- vars 934 out <- vars
877 } 935 }
878 } 936 }
879 937
1299 out <- [prog]Worker Refs <<[ [[prog]Worker Refs >>]Set[name, Worker Ref[name, convention, inputs, outputs, Yes]]] 1357 out <- [prog]Worker Refs <<[ [[prog]Worker Refs >>]Set[name, Worker Ref[name, convention, inputs, outputs, Yes]]]
1300 } 1358 }
1301 1359
1302 Register Worker@NProgram[prog, name, convention, inputs, outputs: out] 1360 Register Worker@NProgram[prog, name, convention, inputs, outputs: out]
1303 { 1361 {
1362 [[prog]Worker Refs >>]Index[name]
1363 {
1364 ref <- [[[[~]Inputs <<[ Max[[~]Inputs >>, inputs] ]
1365 ]Min Inputs <<[ Min[[~]Min Inputs >>, inputs] ]
1366 ]Outputs <<[ Max[[~]Outputs >>, outputs] ]
1367 ]Min Outputs <<[ Min[[~]Min Outputs >>, outputs] ]
1368 }{
1369 ref <- Worker Ref[name, convention, inputs, outputs, No]
1370 }
1304 after reg <- [prog]Worker Refs <<[ 1371 after reg <- [prog]Worker Refs <<[
1305 [ [prog]Worker Refs >> ]Set[name, 1372 [ [prog]Worker Refs >> ]Set[name, ref]
1306 Worker Ref[name, convention, inputs, outputs, No]
1307 ]
1308 ] 1373 ]
1309 parts <- [name]Split["@"] 1374
1310 [parts]Index[1] 1375 parts <- [name]Split["@"]
1311 { 1376 [parts]Index[1]
1312 out <- [after reg]Register Method@NProgram[[parts]Index[0], convention, inputs, outputs] 1377 {
1313 }{ 1378 out <- [after reg]Register Method@NProgram[[parts]Index[0], convention, inputs, outputs]
1314 out <- Val[after reg] 1379 }{
1315 } 1380 out <- Val[after reg]
1381 }
1316 } 1382 }
1317 1383
1318 Register Builtins@NProgram[prog:out] 1384 Register Builtins@NProgram[prog:out]
1319 { 1385 {
1320 registered <- [[[[[[prog]Register Worker["Print", "rhope", 1, 1] 1386 registered <- [[[[[[prog]Register Worker["Print", "rhope", 1, 1]