comparison nworker.rhope @ 37:640f541e9116

Added support for type declarations on user defined workers and added a few more methods to Int32 in the runtime for the C backend
author Mike Pavone <pavone@retrodev.com>
date Mon, 05 Oct 2009 23:12:43 -0400
parents 495dddadd058
children 789a146a48e1
comparison
equal deleted inserted replaced
36:495dddadd058 37:640f541e9116
256 Blueprint NWorker 256 Blueprint NWorker
257 { 257 {
258 Convention 258 Convention
259 Nodes 259 Nodes
260 Inputs 260 Inputs
261 Input Types
261 Outputs 262 Outputs
263 Output Types
262 Uses 264 Uses
263 NodeResults 265 NodeResults
264 Free Temps 266 Free Temps
265 } 267 }
266 268
267 NWorker[convention:out] 269 NWorker[convention:out]
268 { 270 {
269 out <- [[[[Build["NWorker"]]Convention <<[convention]]Nodes <<[()]]Inputs <<[()]]Outputs <<[()] 271 out <- [[[[[[Build["NWorker"]]Convention <<[convention]]Nodes <<[()]]Inputs <<[()]]Outputs <<[()]]Input Types <<[()]]Output Types <<[()]
270 } 272 }
271 273
272 Add Node@NWorker[worker,type,data,inputs,outputs:out,node index] 274 Add Node@NWorker[worker,type,data,inputs,outputs:out,node index]
273 { 275 {
274 out <- [worker]Nodes <<[[[worker]Nodes >>]Append[NWorker Node[type,data,inputs,outputs]]] 276 out <- [worker]Nodes <<[[[worker]Nodes >>]Append[NWorker Node[type,data,inputs,outputs]]]
285 out, node index <- [worker]Add Node["const",constant,0,1] 287 out, node index <- [worker]Add Node["const",constant,0,1]
286 } 288 }
287 289
288 Add Input@NWorker[worker,name,number:out,node index] 290 Add Input@NWorker[worker,name,number:out,node index]
289 { 291 {
292 out,node index <- [worker]Add Typed Input[name,number,Type Instance["Any Type"]]
293 }
294
295 Add Typed Input@NWorker[worker,name,number,type:out,node index]
296 {
290 ,node index <- [worker]Add Node["input",number,0,1] 297 ,node index <- [worker]Add Node["input",number,0,1]
291 { out <- [~]Inputs <<[[[~]Inputs >>]Set[number,name]] } 298 {
299 out <- [[~]Inputs <<[[[~]Inputs >>]Set[number,name]]
300 ]Input Types <<[[[~]Input Types >>]Set[number,type]]
301 }
292 } 302 }
293 303
294 Add Output@NWorker[worker,name,number:out,node index] 304 Add Output@NWorker[worker,name,number:out,node index]
295 { 305 {
306 out,node index <- [worker]Add Typed Output[name,number,Type Instance["Any Type"]]
307 }
308
309 Add Typed Output@NWorker[worker,name,number,type:out,node index]
310 {
296 ,node index <- [worker]Add Node["output",number,1,0] 311 ,node index <- [worker]Add Node["output",number,1,0]
297 { out <- [~]Outputs <<[[[~]Outputs >>]Set[number,name]] } 312 {
313 out <- [[~]Outputs <<[[[~]Outputs >>]Set[number,name]]
314 ]Output Types <<[[[~]Output Types >>]Set[number,type]]
315 }
298 } 316 }
299 317
300 Add Object Get@NWorker[worker,fieldname:out,node index] 318 Add Object Get@NWorker[worker,fieldname:out,node index]
301 { 319 {
302 out, node index <- [worker]Add Node["getfield",fieldname,1,1] 320 out, node index <- [worker]Add Node["getfield",fieldname,1,1]
439 input name <- [[worker]Inputs >>]Index[ [node]Data >> ] 457 input name <- [[worker]Inputs >>]Index[ [node]Data >> ]
440 out <- AddRef[input name] 458 out <- AddRef[input name]
441 }{ 459 }{
442 If[[[node]Type >>] = ["const"]] 460 If[[[node]Type >>] = ["const"]]
443 { 461 {
444 If[[Type Of[[node]Data >>]] = ["Type Literal"]] 462 If[[Type Of[[node]Data >>]] = ["Type Instance"]]
445 { 463 {
446 //TODO: Support parametric types 464 //TODO: Support parametric types
447 datstring <- [[node]Data >>]Name >> 465 datstring <- [[node]Data >>]Name >>
448 }{ 466 }{
449 datstring <- [node]Data >> 467 datstring <- [node]Data >>
576 nstream <- [stream]Move[[inputs]Index[0], [[worker]Outputs >>]Index[ [node]Data >> ] ] 594 nstream <- [stream]Move[[inputs]Index[0], [[worker]Outputs >>]Index[ [node]Data >> ] ]
577 }{ 595 }{
578 If[[[node]Type >>] = ["const"]] 596 If[[[node]Type >>] = ["const"]]
579 { 597 {
580 //TODO: Handle list constants 598 //TODO: Handle list constants
581 If[[Type Of[[node]Data >>]] = ["Type Literal"]] 599 If[[Type Of[[node]Data >>]] = ["Type Instance"]]
582 { 600 {
583 //TODO: Support parametric types 601 //TODO: Support parametric types
584 datstring <- [[node]Data >>]Name >> 602 datstring <- [[node]Data >>]Name >>
585 }{ 603 }{
586 datstring <- [node]Data >> 604 datstring <- [node]Data >>
670 688
671 Compile Worker@NWorker[worker,program,name:out] 689 Compile Worker@NWorker[worker,program,name:out]
672 { 690 {
673 Print[["Compiling: "]Append[name]] 691 Print[["Compiling: "]Append[name]]
674 { 692 {
675 ifunc <- [program]Create Function[name,[worker]Inputs >>, [worker]Outputs >>, [worker]Convention >>] 693 ifunc <- Fold["Set Output Type", Fold["Set Input Type", [program]Create Function[name,[worker]Inputs >>, [worker]Outputs >>, [worker]Convention >>], [worker]Input Types >>], [worker]Output Types >>]
676 694
677 res vars <- [worker]Result Vars 695 res vars <- [worker]Result Vars
678 func <- Fold["Set Null", Fold["Set Null", Fold[["Allocate Var"]Set Input[2, "Any Type"], ifunc, res vars], res vars], [worker]Outputs >>] 696 func <- Fold["Set Null", Fold["Set Null", Fold[["Allocate Var"]Set Input[2, "Any Type"], ifunc, res vars], res vars], [worker]Outputs >>]
679 697
680 groups <- [worker]Dependency Groups 698 groups <- [worker]Dependency Groups
682 { 700 {
683 final func <- [worker]Compile Group[program,func,groups, ~] 701 final func <- [worker]Compile Group[program,func,groups, ~]
684 }{ 702 }{
685 final func <- Val[func] 703 final func <- Val[func]
686 } 704 }
687 out <- [program]Store Function[Fold[["Release Var"]Set Input[0, worker], final func, res vars]] 705 out <- [program]Store Function[Fold["Release", Fold[["Release Var"]Set Input[0, worker], final func, res vars], [worker]Inputs >>]]
688 } 706 }
689 } 707 }
690 708
691 Test[:out] 709 Test[:out]
692 { 710 {
774 } 792 }
775 793
776 Make Special@NBlueprint[bp,backend,func name,bp name,pop worker:out] 794 Make Special@NBlueprint[bp,backend,func name,bp name,pop worker:out]
777 { 795 {
778 func <- [[backend]Create Function[func name,("obj"),(),"cdecl"] 796 func <- [[backend]Create Function[func name,("obj"),(),"cdecl"]
779 ]Set Input Type[0, bp name] 797 ]Set Input Type[bp name, 0]
780 out <- [backend]Store Function[Fold[pop worker, func, [bp]Fields >>]] 798 out <- [backend]Store Function[Fold[pop worker, func, [bp]Fields >>]]
781 } 799 }
782 800
783 Getters Setters[backend,field,type name:out] 801 Getters Setters[backend,field,type name:out]
784 { 802 {
785 //TODO: Throw an exception or something if we read a field that is empty 803 //TODO: Throw an exception or something if we read a field that is empty
786 Print[["Getters Setters: "]Append[name]] 804 Print[["Getters Setters: "]Append[name]]
787 name <- [field]Index[0] 805 name <- [field]Index[0]
788 type <- [field]Index[1] 806 type <- [field]Index[1]
789 ,getref <- [[[[backend]Create Function[ [[[name]Append[" >>"]]Append["@"]]Append[type name], ("obj"), ("out"), "rhope"] 807 ,getref <- [[[[backend]Create Function[ [[[name]Append[" >>"]]Append["@"]]Append[type name], ("obj"), ("out"), "rhope"]
790 ]Set Input Type[0, type name] 808 ]Set Input Type[type name, 0]
791 ]Set Output Type[0, type] 809 ]Set Output Type[type, 0]
792 ]Read Field["obj", name] 810 ]Read Field["obj", name]
793 { getter <- [~]Do AddRef[getref, "out"] 811 { getter <- [[~]Do AddRef[getref, "out"]]Release["obj"]
794 { Print["Got getter"] } } 812 { Print["Got getter"] } }
795 813
796 ,origref <- [[[[[[backend]Create Function[ [[[name]Append[" <<"]]Append["@"]]Append[type name], ("obj","newval"), ("out"), "rhope"] 814 ,origref <- [[[[[[backend]Create Function[ [[[name]Append[" <<"]]Append["@"]]Append[type name], ("obj","newval"), ("out"), "rhope"]
797 ]Set Input Type[0, type name] 815 ]Set Input Type[type name, 0]
798 ]Set Input Type[1, type] 816 ]Set Input Type[type, 1]
799 ]Set Output Type[0, type name] 817 ]Set Output Type[type name, 0]
800 ]Copy["obj"] 818 ]Copy["obj"]
801 ]Read Field["obj", name] 819 ]Read Field["obj", name]
802 { 820 {
803 stream <- [[~]Instruction Stream 821 stream <- [[~]Instruction Stream
804 ]Release[origref] 822 ]Release[origref]
893 } 911 }
894 } 912 }
895 913
896 Register Builtins@NProgram[prog:out] 914 Register Builtins@NProgram[prog:out]
897 { 915 {
898 out <- [[[[[[[[[prog]Register Worker["+@Int32", "rhope", 2, 1] 916 out <- [[[[[[[[[[[prog]Register Worker["+@Int32", "rhope", 2, 1]
899 ]Register Worker["-@Int32", "rhope", 2, 1] 917 ]Register Worker["-@Int32", "rhope", 2, 1]
900 ]Register Worker["*@Int32", "rhope", 2, 1] 918 ]Register Worker["*@Int32", "rhope", 2, 1]
901 ]Register Worker["/@Int32", "rhope", 2, 1] 919 ]Register Worker["/@Int32", "rhope", 2, 1]
920 ]Register Worker["LShift@Int32", "rhope", 2, 1]
921 ]Register Worker["RShift@Int32", "rhope", 2, 1]
902 ]Register Worker["Print", "rhope", 1, 1] 922 ]Register Worker["Print", "rhope", 1, 1]
903 ]Register Worker["If@Yes No", "rhope", 1, 2] 923 ]Register Worker["If@Yes No", "rhope", 1, 2]
904 ]Register Worker["<@Int32", "rhope", 2, 1] 924 ]Register Worker["<@Int32", "rhope", 2, 1]
905 ]Register Worker[">@Int32", "rhope", 1, 1] 925 ]Register Worker[">@Int32", "rhope", 2, 1]
906 ]Register Worker["Build", "rhope", 1, 1] 926 ]Register Worker["Build", "rhope", 1, 1]
907 } 927 }
908 928
909 Find Worker@NProgram[prog, name:out,notfound] 929 Find Worker@NProgram[prog, name:out,notfound]
910 { 930 {