comparison nworker.rhope @ 49:3e20ed8959c4

Added initial FFI implementation, Array type and 64-bit integers
author Mike Pavone <pavone@retrodev.com>
date Thu, 08 Apr 2010 01:02:18 -0400
parents a24eb366195c
children 689fb73e7612
comparison
equal deleted inserted replaced
48:a24eb366195c 49:3e20ed8959c4
294 Uses 294 Uses
295 NodeResults 295 NodeResults
296 Free Temps 296 Free Temps
297 Name 297 Name
298 Builtin? 298 Builtin?
299 Library
299 } 300 }
300 301
301 NWorker[convention:out] 302 NWorker[convention:out]
302 { 303 {
303 out <- [[[[[[[[Build["NWorker"]]Convention <<[convention]]Nodes <<[()]]Inputs <<[()]]Outputs <<[()]]Input Types <<[()]]Output Types <<[()]]Name <<["Anonymous"]]Builtin? <<[No] 304 out <- [[[[[[[[[Build["NWorker"]]Convention <<[convention]]Nodes <<[()]]Inputs <<[()]]Outputs <<[()]]Input Types <<[()]]Output Types <<[()]]Name <<["Anonymous"]]Builtin? <<[No]]Library << [""]
304 } 305 }
305 306
306 Add Node@NWorker[worker,type,data,inputs,outputs:out,node index] 307 Add Node@NWorker[worker,type,data,inputs,outputs:out,node index]
307 { 308 {
308 out <- [worker]Nodes <<[[[worker]Nodes >>]Append[NWorker Node[type,data,inputs,outputs]]] 309 out <- [worker]Nodes <<[[[worker]Nodes >>]Append[NWorker Node[type,data,inputs,outputs]]]
730 Print["Method!"] 731 Print["Method!"]
731 with call <- [func]Method Call[[[node]Data >>]Name >>, inputs] 732 with call <- [func]Method Call[[[node]Data >>]Name >>, inputs]
732 { Print["Method Call done"] } 733 { Print["Method Call done"] }
733 }{ 734 }{
734 Print["Function!"] 735 Print["Function!"]
735 with call <- [func]Call[[[node]Data >>]Name >>, inputs] 736 {
737 Pretty Print[inputs, ""]
738 { with call <- [func]Call[[[node]Data >>]Name >>, inputs]}
739 }
740
736 } 741 }
737 } 742 }
738 } 743 }
739 } 744 }
740 out <- Fold[["Save Result"]Set Input[2, node index], with call, Range[0, [node]Outputs >>]] 745 out <- Fold[["Save Result"]Set Input[2, node index], with call, Range[0, [node]Outputs >>]]
761 } 766 }
762 nstream <- Compile Call Node[node, program, stream, inputs, node index] 767 nstream <- Compile Call Node[node, program, stream, inputs, node index]
763 }{ 768 }{
764 If[[[node]Type >>] = ["output"]] 769 If[[[node]Type >>] = ["output"]]
765 { 770 {
771 Print["Compiling output node"]
766 inputs <- [worker]Collect Inputs[node] 772 inputs <- [worker]Collect Inputs[node]
767 [conditions]For Backend 773 [conditions]For Backend
768 { 774 {
775 Print["has conditions"]
769 stream <- [func]Instruction Stream 776 stream <- [func]Instruction Stream
770 nfunc <- [func]Do If[~, nstream] 777 nfunc <- [func]Do If[~, nstream]
771 }{ 778 }{
779 Print["no conditions"]
772 stream <- Val[func] 780 stream <- Val[func]
773 nfunc <- Val[nstream] 781 nfunc <- Val[nstream]
774 } 782 }
775 nstream <- [stream]Move[[inputs]Index[0], [[worker]Outputs >>]Index[ [node]Data >> ] ] 783 nstream <- [stream]Move[[inputs]Index[0], [[worker]Outputs >>]Index[ [node]Data >> ] ]
776 }{ 784 }{
865 Result Vars@NWorker[worker:out] 873 Result Vars@NWorker[worker:out]
866 { 874 {
867 out <- Fold["Node Result Vars", (), [worker]Nodes >>] 875 out <- Fold["Node Result Vars", (), [worker]Nodes >>]
868 } 876 }
869 877
878 Make Basic Type[type:out]
879 {
880 out <- [Type Instance[[type]Name >>]]Params <<[ [type]Params >> ]
881 }
882
883 FInputs[ifunc, input type, index, inputs:out]
884 {
885 func <- [ifunc]Set Input Type[Make Basic Type[input type], index]
886 name <- [inputs]Index[index]
887 Print[["FInputs: "]Append[index]]
888 Pretty Print[input type, ""]
889 {
890 If[[[input type]Variant >>] = ["Naked"]]
891 {
892
893 naked <- [" naked"]Append[name]
894
895 out <- [[[func]Allocate Var[naked, input type]
896 ]Unbox[name, naked]
897 ]Release[name]
898 }{
899 If[[input type]Mutable? >>]
900 {
901 name <- [inputs]Index[index]
902 copied <- [func]Copy[name, name]
903
904 }{
905 copied <- Val[func]
906 }
907 If[[[input type]Variant >>] = ["Raw Pointer"]]
908 {
909 raw <- [" raw"]Append[name]
910 If[[[input type]Name >>]=["Array"]]
911 {
912
913 out <- [[copied]Allocate Var[raw, input type]
914 ]Array Raw Pointer[name, raw]
915 }{
916 out <- [[copied]Allocate Var[raw, input type]
917 ]Get Raw Pointer[name, raw]
918 }
919 }{
920 out <- Val[copied]
921 }
922 }
923 }
924 }
925
926 FParams[input:out]
927 {
928 iname <- [input]Index[0]
929 type <- [input]Index[1]
930 If[[[type]Variant >>] = ["Naked"]]
931 { out <- [" naked"]Append[iname] }
932 {
933 If[[[type]Variant >>] = ["Raw Pointer"]]
934 { out <- [" raw"]Append[iname] }
935 { out <- Val[iname] }
936 }
937 }
938 _Return Param[outputs, inputs, input types, index:out,none]
939 {
940 Print[["_Return Param: "]Append[output]]
941 output <- [outputs]Index[index]
942 [inputs]Find[output]
943 {
944 If[[[input types]Index[~]]Mutable? >>]
945 {
946 ,none <- [outputs]Next[index]
947 {
948 out,none <- _Return Param[outputs, index, input types, ~]
949 }
950 } {
951 out <- index
952 }
953 }{
954 out <- index
955 }
956 }
957
958 Return Param[outputs, inputs, input types:out,none]
959 {
960 Print["Return Param"]
961 ,none <- [outputs]First
962 { out,none <- _Return Param[outputs, inputs, input types, ~] }
963
964 }
965
966 Save Foreign Result[func, output, index, output types, inputs, input types:out]
967 {
968 type <- [output types]Index[index]
969 If[[[type]Variant >>] = ["Naked"]]
970 {
971 out <- [func]Box[[" naked"]Append[output], output, type]
972 }{
973 [inputs]Find[output]
974 {
975 If[[[input types]Index[~]]Mutable? >>]
976 {
977 out <- [func]Move[output, Output[output]]
978 }{
979 out <- func
980 }
981 }{
982 out <- func
983 }
984 }
985 }
986
987 Compile Foreign Stub[worker,program,name:out]
988 {
989 Print[["Compiling FFI stub for "]Append[name]]
990 ifunc <- [[program]Create Function[name, [worker]Inputs >>, [worker]Outputs >>, "rhope"]
991 ]Output Types <<[Map[[worker]Output Types >>, "Make Basic Type"]]
992
993 rp num <- Return Param[[worker]Outputs >>, [worker]Inputs >>, [worker]Input Types >>]
994 {
995 rbase <- [[worker]Outputs >>]Index[rp num]
996 If[[[[[worker]Output Types >>]Index[rp num]]Variant >>] = ["Naked"]]
997 {
998 rparam <- [" naked"]Append[rbase]
999 rfunc <- [ifunc]Allocate Var[rparam, [[worker]Output Types >>]Index[rp num]]
1000 }{
1001 rparam <- Val[rbase]
1002 rfunc <- Val[ifunc]
1003 }
1004 }{
1005 rparam <- ""
1006 rfunc <- Val[ifunc]
1007 }
1008
1009 Fold[["FInputs"]Set Input[3, [worker]Inputs >>], rfunc, [worker]Input Types >>]
1010 { [~]Call Foreign[name, [worker]Convention >>, Map[Zip[[worker]Inputs >>, [worker]Input Types >>], "FParams"], rparam]
1011 { Fold[[[["Save Foreign Result"]Set Input[3, [worker]Output Types >>]]Set Input[4, [worker]Inputs >>]]Set Input[5, [worker]Input Types >>], ~, [worker]Outputs >>]
1012 { out <- [program]Store Function[~] }}}
1013 }
1014
870 Compile Worker@NWorker[worker,program,name:out] 1015 Compile Worker@NWorker[worker,program,name:out]
871 { 1016 {
872 If[[worker]Builtin? >>] 1017 If[[worker]Builtin? >>]
873 { 1018 {
874 out <- program 1019 out <- program
875 }{ 1020 }{
876 Print[["Compiling: "]Append[name]] 1021 If[[[worker]Library >>] = [""]]
877 { 1022 {
878 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 >>] 1023 Print[["Compiling: "]Append[name]]
879 1024 {
880 res vars <- [worker]Result Vars 1025 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 >>]
881 func <- Fold["Set Null", Fold["Set Null", Fold[["Allocate Var"]Set Input[2, "Any Type"], ifunc, res vars], res vars], [worker]Outputs >>] 1026
882 1027 res vars <- [worker]Result Vars
883 groups <- [worker]Dependency Groups 1028 func <- Fold["Set Null", Fold["Set Null", Fold[["Allocate Var"]Set Input[2, "Any Type"], ifunc, res vars], res vars], [worker]Outputs >>]
884 [groups]First 1029
885 { 1030 groups <- [worker]Dependency Groups
886 final func <- [worker]Compile Group[program,func,groups, ~] 1031 [groups]First
887 }{ 1032 {
888 final func <- Val[func] 1033 final func <- [worker]Compile Group[program,func,groups, ~]
889 } 1034 }{
890 out <- [program]Store Function[Fold["Release", Fold[["Release Var"]Set Input[0, worker], final func, res vars], [worker]Inputs >>]] 1035 final func <- Val[func]
1036 }
1037 out <- [program]Store Function[Fold["Release", Fold[["Release Var"]Set Input[0, worker], final func, res vars], [worker]Inputs >>]]
1038 }
1039 }{
1040 out <- Compile Foreign Stub[worker,[program]Link[[worker]Convention >>, [worker]Library >> ],name]
891 } 1041 }
892 } 1042 }
893 } 1043 }
894 1044
895 Test[:out] 1045 Test[:out]
1115 { 1265 {
1116 after bind <- [prog]Workers << [ [[prog]Workers >>]Set[name, [worker]Name <<[name]] ] 1266 after bind <- [prog]Workers << [ [[prog]Workers >>]Set[name, [worker]Name <<[name]] ]
1117 parts <- [name]Split["@"] 1267 parts <- [name]Split["@"]
1118 [parts]Index[1] 1268 [parts]Index[1]
1119 { 1269 {
1120 out <- [after bind]Blueprints <<[ [[after bind]Blueprints >>]Set[~, [[[after bind]Blueprints >>]Index[~]]Add Method[[parts]Index[0]] ] ] 1270 orig bp <- [[after bind]Blueprints >>]Index[~] {}
1271 { orig bp <- NBlueprint[] }
1272 out <- [after bind]Blueprints <<[ [[after bind]Blueprints >>]Set[~, [orig bp]Add Method[[parts]Index[0]] ] ]
1121 }{ 1273 }{
1122 out <- Val[after bind] 1274 out <- Val[after bind]
1123 } 1275 }
1124 } 1276 }
1125 1277
1176 } 1328 }
1177 } 1329 }
1178 1330
1179 Register Builtins@NProgram[prog:out] 1331 Register Builtins@NProgram[prog:out]
1180 { 1332 {
1181 registered <- [[[[prog]Register Worker["Print", "rhope", 1, 1] 1333 registered <- [[[[[prog]Register Worker["Print", "rhope", 1, 1]
1182 ]Register Worker["If@Boolean", "rhope", 1, 2] 1334 ]Register Worker["If@Boolean", "rhope", 1, 2]
1183 ]Register Worker["Build", "rhope", 1, 1] 1335 ]Register Worker["Build", "rhope", 1, 1]
1336 ]Register Worker["Blueprint Of", "rhope", 1, 1]
1184 ]Register Number Methods 1337 ]Register Number Methods
1185 1338
1186 out <- [[[registered]Bind Worker["If@Boolean", 1339 out <- [[[[registered]Bind Worker["If@Boolean",
1187 [[[[[NWorker["rhope"] 1340 [[[[[NWorker["rhope"]
1188 ]Inputs <<[("condition")] 1341 ]Inputs <<[("condition")]
1189 ]Input Types <<[ [()]Append[Type Instance["Boolean"]] ] 1342 ]Input Types <<[ [()]Append[Type Instance["Boolean"]] ]
1190 ]Outputs <<[("isyes","isno")] 1343 ]Outputs <<[("isyes","isno")]
1191 ]Output Types <<[ [[()]Append[Type Instance["Boolean"]]]Append[Type Instance["Boolean"]] ] 1344 ]Output Types <<[ [[()]Append[Type Instance["Boolean"]]]Append[Type Instance["Boolean"]] ]
1202 ]Inputs <<[("type")] 1355 ]Inputs <<[("type")]
1203 ]Input Types <<[ [()]Append[Type Instance["Blueprint"]] ] 1356 ]Input Types <<[ [()]Append[Type Instance["Blueprint"]] ]
1204 ]Outputs <<[("out")] 1357 ]Outputs <<[("out")]
1205 ]Output Types <<[ [()]Append[Type Instance["Any Type"]] ] 1358 ]Output Types <<[ [()]Append[Type Instance["Any Type"]] ]
1206 ]Builtin? <<[Yes]] 1359 ]Builtin? <<[Yes]]
1360 ]Bind Worker["Blueprint Of",
1361 [[[[[NWorker["rhope"]
1362 ]Inputs <<[("object")]
1363 ]Input Types <<[ [()]Append[Type Instance["Any Type"]]]
1364 ]Outputs <<[("type")]
1365 ]Output Types <<[ [()]Append[Type Instance["Blueprint"]]]
1366 ]Builtin? <<[Yes]]
1207 } 1367 }
1208 1368
1209 Find Worker@NProgram[prog, name:out,notfound] 1369 Find Worker@NProgram[prog, name:out,notfound]
1210 { 1370 {
1211 Print[ ["Find Worker@NProgram: "]Append[name] ] 1371 Print[ ["Find Worker@NProgram: "]Append[name] ]