comparison nworker.rhope @ 82:2e2e55fc12f9

Fix bug with conditionally assigning a literal or input to a named pipe
author Mike Pavone <pavone@retrodev.com>
date Tue, 27 Jul 2010 15:23:32 -0400
parents 0083b2f7b3c7
children 27bb051d631c
comparison
equal deleted inserted replaced
81:dbe95bfec970 82:2e2e55fc12f9
633 } 633 }
634 634
635 Format Input@NWorker[worker,noderef:out] 635 Format Input@NWorker[worker,noderef:out]
636 { 636 {
637 node <- [[worker]Nodes >>]Index[[noderef]Index >>] 637 node <- [[worker]Nodes >>]Index[[noderef]Index >>]
638
638 [("call","getfield","setfield")]Find[[node]Type >>] 639 [("call","getfield","setfield")]Find[[node]Type >>]
639 { 640 {
640 out <- AddRef[ [[["__result_"]Append[[noderef]Index >>]]Append["_"]]Append[[noderef]IO Num >>] ] 641 out <- AddRef[ [[["__result_"]Append[[noderef]Index >>]]Append["_"]]Append[[noderef]IO Num >>] ]
641 }{ 642 }{
643 conditions <- [node]Conditions >>
644
642 If[[[node]Type >>] = ["input"]] 645 If[[[node]Type >>] = ["input"]]
643 { 646 {
644 input name <- [[worker]Inputs >>]Index[ [node]Data >> ] 647 input name <- [[worker]Inputs >>]Index[ [node]Data >> ]
645 out <- AddRef[input name] 648 [conditions]For Backend
649 {
650 out <- AddRef[ [[["__result_"]Append[[noderef]Index >>]]Append["_"]]Append[[noderef]IO Num >>] ]
651 }{
652 out <- AddRef[input name]
653 }
646 }{ 654 }{
647 If[[[node]Type >>] = ["const"]] 655 If[[[node]Type >>] = ["const"]]
648 { 656 {
649 If[[Type Of[[node]Data >>]] = ["Type Instance"]] 657 [conditions]For Backend
650 { 658 {
651 //TODO: Support parametric types 659 out <- AddRef[ [[["__result_"]Append[[noderef]Index >>]]Append["_"]]Append[[noderef]IO Num >>] ]
652 datstring <- [[node]Data >>]Name >>
653 }{ 660 }{
654 If[[Type Of[[node]Data >>]] = ["Machine Integer"]] 661 If[[Type Of[[node]Data >>]] = ["Type Instance"]]
655 { 662 {
656 If[[[node]Data >>]Signed? >>] 663 //TODO: Support parametric types
657 { s <- "i" } 664 datstring <- [[node]Data >>]Name >>
658 { s <- "u" }
659 datstring <- [[[[node]Data >>]Value >>]Append[s]]Append[[[node]Data >>]Size >>]
660 }{ 665 }{
661 If[[Type Of[[node]Data >>]] = ["Worker Literal"]] 666 If[[Type Of[[node]Data >>]] = ["Machine Integer"]]
662 { 667 {
663 If[[[[[node]Data >>]Args >>]Length] > [0]] 668 If[[[node]Data >>]Signed? >>]
669 { s <- "i" }
670 { s <- "u" }
671 datstring <- [[[[node]Data >>]Value >>]Append[s]]Append[[[node]Data >>]Size >>]
672 }{
673 If[[Type Of[[node]Data >>]] = ["Worker Literal"]]
664 { 674 {
665 datstring <- [[["Arg "]Append[[noderef]Index >>]]Append[" "]]Append[[worker]Name >>] 675 If[[[[[node]Data >>]Args >>]Length] > [0]]
676 {
677 datstring <- [[["Arg "]Append[[noderef]Index >>]]Append[" "]]Append[[worker]Name >>]
678 }{
679 datstring <- [[node]Data >>]Name >>
680 }
666 }{ 681 }{
667 datstring <- [[node]Data >>]Name >> 682 datstring <- [node]Data >>
668 } 683 }
669 }{
670 datstring <- [node]Data >>
671 } 684 }
672 } 685 }
686 out <- Constant[[[Type Of[[node]Data >>]]Append["_"]]Append[datstring]]
673 } 687 }
674 out <- Constant[[[Type Of[[node]Data >>]]Append["_"]]Append[datstring]]
675
676 } 688 }
677 } 689 }
678 } 690 }
679 } 691 }
680 692
792 after save <- Fold[["Save Result"]Set Input[2, node index], with call, Range[0, save outs]] 804 after save <- Fold[["Save Result"]Set Input[2, node index], with call, Range[0, save outs]]
793 } 805 }
794 806
795 Compile Node@NWorker[worker,program,func,nodes,current:out,out worker] 807 Compile Node@NWorker[worker,program,func,nodes,current:out,out worker]
796 { 808 {
809 Print[[[["Compile node: "]Append[[node]Type >>]]Append[", "]]Append[node index]]
797 node index <- [nodes]Index[current] 810 node index <- [nodes]Index[current]
798 node <- [[worker]Nodes >>]Index[node index] 811 node <- [[worker]Nodes >>]Index[node index]
799 conditions <- [worker]Collect Conditions[node] 812 conditions <- [node]Conditions >>
800 [("call","getfield","setfield")]Find[[node]Type >>] 813 [("call","getfield","setfield")]Find[[node]Type >>]
801 { 814 {
802 inputs <- [worker]Collect Inputs[node] 815 inputs <- [worker]Collect Inputs[node]
803 [conditions]For Backend 816 [conditions]For Backend
804 { 817 {
849 }{ 862 }{
850 datstring <- [node]Data >> 863 datstring <- [node]Data >>
851 } 864 }
852 } 865 }
853 } 866 }
854 nfunc <- [func]Register Constant[[[Type Of[[node]Data >>]]Append["_"]]Append[datstring], [node]Data >>] 867 constname <- [[Type Of[[node]Data >>]]Append["_"]]Append[datstring]
868 withconst <- [func]Register Constant[constname, [node]Data >>]
869 [conditions]For Backend
870 {
871 stream <- [[withconst]Instruction Stream
872 ]Move[Constant[constname], [[["__result_"]Append[node index]]Append["_"]]Append[0]]
873 nfunc <- [withconst]Do If[~, stream]
874 }{
875 nfunc <- Val[withconst]
876 }
855 }{ 877 }{
856 nfunc <- Val[func] 878 [conditions]For Backend
879 {
880 input name <- [[worker]Inputs >>]Index[ [node]Data >> ]
881 stream <- [[func]Instruction Stream
882 ]Move[input name, [[["__result_"]Append[node index]]Append["_"]]Append[0]]
883 nfunc <- [func]Do If[~, stream]
884 }{
885 nfunc <- Val[func]
886 }
857 } 887 }
858 888
859 } 889 }
860 } 890 }
861 If[[[node]Outputs >>] = [0]]
862 {
863 nworker <- Val[worker]
864 }{
865 nworker <- [worker]Nodes <<[ [[worker]Nodes >>]Set[node index, [node]Conditions <<[conditions]] ]
866 }
867 [nodes]Next[current] 891 [nodes]Next[current]
868 { 892 {
869 out,out worker <- [nworker]Compile Node[program,nfunc,nodes,~] 893 out,out worker <- [worker]Compile Node[program,nfunc,nodes,~]
870 }{ 894 }{
871 out <- Val[nfunc] 895 out <- Val[nfunc]
872 out worker <- Val[nworker] 896 out worker <- Val[worker]
897 }
898 }
899
900 Save Node Conditions@NWorker[worker,node index:out]
901 {
902 node <- [[worker]Nodes >>]Index[node index]
903 conditions <- [worker]Collect Conditions[node]
904 out <- [worker]Nodes <<[ [[worker]Nodes >>]Set[node index, [node]Conditions <<[conditions]] ]
905
906 }
907
908 Save Group Conditions@NWorker[worker, groups,current:out]
909 {
910 nodes <- [groups]Index[current]
911 nworker <- Fold["Save Node Conditions", worker, nodes]
912
913 [groups]Next[current]
914 {
915 out <- [nworker]Save Group Conditions[groups,~]
916 }{
917 out <- Val[nworker]
873 } 918 }
874 } 919 }
875 920
876 Compile Group@NWorker[worker,program,func,groups,current:out,out worker] 921 Compile Group@NWorker[worker,program,func,groups,current:out,out worker]
877 { 922 {
936 } 981 }
937 982
938 Result Vars@NWorker[worker:out] 983 Result Vars@NWorker[worker:out]
939 { 984 {
940 out <- Fold["Node Result Vars", (), [worker]Nodes >>] 985 out <- Fold["Node Result Vars", (), [worker]Nodes >>]
986 }
987
988 _No Release[vars,node,index,worker:out]
989 {
990 Print[["_No Release"]Append[[node]Type >>]]
991 [("const","input")]Find[[node]Type >>]
992 {
993 [[node]Conditions >>]For Backend
994 {
995 Print[["Const or input with conditions: "]Append[index]]
996 out <- Result Var[vars, 0, index]
997 }{
998 Print[["Const or input with no conditions: "]Append[index]]
999 out <- vars
1000 }
1001 }{
1002 Print[["Other node type: "]Append[index]]
1003 out <- vars
1004 }
1005 }
1006
1007 No Release Results@NWorker[worker:out]
1008 {
1009 out <- Fold[["_No Release"]Set Input[3, worker], (), [worker]Nodes >>]
941 } 1010 }
942 1011
943 Make Basic Type[type:out] 1012 Make Basic Type[type:out]
944 { 1013 {
945 out <- [Type Instance[[type]Name >>]]Params <<[ [type]Params >> ] 1014 out <- [Type Instance[[type]Name >>]]Params <<[ [type]Params >> ]
1069 { Fold[[[["Save Foreign Result"]Set Input[3, [worker]Output Types >>]]Set Input[4, [worker]Inputs >>]]Set Input[5, [worker]Input Types >>], ~, [worker]Outputs >>] 1138 { Fold[[[["Save Foreign Result"]Set Input[3, [worker]Output Types >>]]Set Input[4, [worker]Inputs >>]]Set Input[5, [worker]Input Types >>], ~, [worker]Outputs >>]
1070 { out <- [program]Store Function[~] }}} 1139 { out <- [program]Store Function[~] }}}
1071 } 1140 }
1072 1141
1073 Compile Worker@NWorker[worker,program,name:out] 1142 Compile Worker@NWorker[worker,program,name:out]
1074 { 1143 {
1144 Print[["Compile Worker: "]Append[[worker]Name >>]]
1075 If[[worker]Builtin? >>] 1145 If[[worker]Builtin? >>]
1076 { 1146 {
1077 out <- program 1147 out <- program
1078 }{ 1148 }{
1079 If[[[worker]Library >>] = [""]] 1149 If[[[worker]Library >>] = [""]]
1080 { 1150 {
1081 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 >>] 1151 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 >>]
1082 1152
1083 res vars <- [worker]Result Vars 1153
1084 func <- Fold["Set Null", Fold["Set Null", Fold[["Allocate Var"]Set Input[2, "Any Type"], ifunc, res vars], res vars], [worker]Outputs >>]
1085 1154
1086 groups <- [worker]Dependency Groups 1155 groups <- [worker]Dependency Groups
1087 [groups]First 1156 [groups]First
1088 { 1157 {
1089 final func <- [worker]Compile Group[program,func,groups, ~] 1158 with conds <- [worker]Save Group Conditions[groups, ~]
1159 final func <- [with conds]Compile Group[program,func,groups, ~]
1090 }{ 1160 }{
1091 final func <- Val[func] 1161 final func <- Val[func]
1092 } 1162 }
1163 res vars <- [worker]Result Vars
1164 init vars <- Concatenate[res vars, [with conds]No Release Results]
1165
1166 func <- Fold["Set Null", Fold["Set Null", Fold[["Allocate Var"]Set Input[2, "Any Type"], ifunc, init vars], init vars], [worker]Outputs >>]
1093 out <- [program]Store Function[Fold["Release", Fold[["Release Var"]Set Input[0, worker], final func, res vars], [worker]Inputs >>]] 1167 out <- [program]Store Function[Fold["Release", Fold[["Release Var"]Set Input[0, worker], final func, res vars], [worker]Inputs >>]]
1094 }{ 1168 }{
1095 out <- Compile Foreign Stub[worker,[program]Link[[worker]Convention >>, [worker]Library >> ],name] 1169 out <- Compile Foreign Stub[worker,[program]Link[[worker]Convention >>, [worker]Library >> ],name]
1096 } 1170 }
1097 } 1171 }