Mercurial > repos > rhope
comparison nworker.rhope @ 48:a24eb366195c
Fixed some bugs introduced in previous commit and moved definition of integer methods out of runtime and into the compiler
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Tue, 02 Mar 2010 00:18:49 -0500 |
parents | 6202b866d72c |
children | 3e20ed8959c4 |
comparison
equal
deleted
inserted
replaced
47:6202b866d72c | 48:a24eb366195c |
---|---|
9 Condition Type | 9 Condition Type |
10 } | 10 } |
11 | 11 |
12 AndSet[:out] | 12 AndSet[:out] |
13 { | 13 { |
14 out <- [[[Build["Condition Set"]]Variables <<[New@Dictionary[]]]Subsets <<[New@Dictionary[]]]Condition Type <<["And"] | 14 out <- [[[Build["Condition Set"]]Variables <<[Dictionary[]]]Subsets <<[Dictionary[]]]Condition Type <<["And"] |
15 } | 15 } |
16 | 16 |
17 OrSet[:out] | 17 OrSet[:out] |
18 { | 18 { |
19 out <- [[[Build["Condition Set"]]Variables <<[New@Dictionary[]]]Subsets <<[New@Dictionary[]]]Condition Type <<["Or"] | 19 out <- [[[Build["Condition Set"]]Variables <<[Dictionary[]]]Subsets <<[Dictionary[]]]Condition Type <<["Or"] |
20 } | 20 } |
21 | 21 |
22 To String@Condition Set[set:out] | 22 To String@Condition Set[set:out] |
23 { | 23 { |
24 out <- [[[[[set]Condition Type >> | 24 out <- [[[[[set]Condition Type >> |
343 } | 343 } |
344 }{ | 344 }{ |
345 new type <- Val[type] | 345 new type <- Val[type] |
346 new count <- 1 | 346 new count <- 1 |
347 } | 347 } |
348 new node <- [node]Input Types <<[ | 348 new node <- [node]Input Types <<[ |
349 [[()]Append[ | 349 [ [node]Input Types >> ]Set[ [dest]IO Num >>, [[()]Append[new type]]Append[new count] ] |
350 [ [node]Input Types >> ]Set[ [dest]IO Num >>, new type ] | |
351 ]]Append[new count] | |
352 ] | 350 ] |
353 out <- Infer Types Node[[nodelist]Set[[dest]Index >>, new node], new node, [dest]Index >>, prog, worker] | 351 out <- Infer Types Node[[nodelist]Set[[dest]Index >>, new node], new node, [dest]Index >>, prog, worker] |
354 } | 352 } |
355 | 353 |
356 Propagate Types[nodelist,dests,output num,prog,worker,source node:out] | 354 Propagate Types[nodelist,dests,output num,prog,worker,source node:out] |
453 } | 451 } |
454 } | 452 } |
455 | 453 |
456 Infer Types@NWorker[worker,prog:out] | 454 Infer Types@NWorker[worker,prog:out] |
457 { | 455 { |
456 Print[["Start inference: "]Append[[worker]Name >>]] | |
458 out <- [worker]Nodes <<[Fold[[["Infer Types Node"]Set Input[3, prog]]Set Input[4, worker], [worker]Nodes >>, [worker]Nodes >>]] | 457 out <- [worker]Nodes <<[Fold[[["Infer Types Node"]Set Input[3, prog]]Set Input[4, worker], [worker]Nodes >>, [worker]Nodes >>]] |
458 { Print[["End inference: "]Append[[worker]Name >>]] } | |
459 } | 459 } |
460 | 460 |
461 Add Worker Call@NWorker[worker,tocall:out,node index] | 461 Add Worker Call@NWorker[worker,tocall:out,node index] |
462 { | 462 { |
463 out, node index <- [worker]Add Node["call",tocall,[tocall]Inputs >>,[tocall]Outputs >>] | 463 out, node index <- [worker]Add Node["call",tocall,[tocall]Inputs >>,[tocall]Outputs >>] |
922 Methods | 922 Methods |
923 } | 923 } |
924 | 924 |
925 NBlueprint[:out] | 925 NBlueprint[:out] |
926 { | 926 { |
927 out <- [[Build["NBlueprint"]]Fields <<[()]]Methods <<[New@Dictionary[]] | 927 out <- [[Build["NBlueprint"]]Fields <<[()]]Methods <<[Dictionary[]] |
928 } | 928 } |
929 | 929 |
930 Add Field@NBlueprint[bp,name,type:out] | 930 Add Field@NBlueprint[bp,name,type:out] |
931 { | 931 { |
932 out <- [bp]Fields <<[ [[bp]Fields >>]Append[ [[()]Append[name]]Append[type] ] ] | 932 out <- [bp]Fields <<[ [[bp]Fields >>]Append[ [[()]Append[name]]Append[type] ] ] |
1032 If[[[type]Variant >>] = ["Boxed"]] | 1032 If[[[type]Variant >>] = ["Boxed"]] |
1033 { | 1033 { |
1034 getter <- [[start getter]Do AddRef[getref, "out"]]Release["obj"] | 1034 getter <- [[start getter]Do AddRef[getref, "out"]]Release["obj"] |
1035 }{ | 1035 }{ |
1036 getter <- [[start getter]Box[getref, "out", type]]Release["obj"] | 1036 getter <- [[start getter]Box[getref, "out", type]]Release["obj"] |
1037 { Print["Got getter"] } | |
1037 } | 1038 } |
1038 | 1039 |
1039 begin setter <- [[[[[backend]Create Function[ [[[name]Append[" <<"]]Append["@"]]Append[type name], ("obj","newval"), ("out"), "rhope"] | 1040 begin setter <- [[[[[backend]Create Function[ [[[name]Append[" <<"]]Append["@"]]Append[type name], ("obj","newval"), ("out"), "rhope"] |
1040 ]Set Input Type[mytype, 0] | 1041 ]Set Input Type[mytype, 0] |
1041 ]Set Input Type[[type]Set Variant["Boxed"], 1] | 1042 ]Set Input Type[[type]Set Variant["Boxed"], 1] |
1059 }{ | 1060 }{ |
1060 ,setref <- [begin setter]Write Field["obj", name] | 1061 ,setref <- [begin setter]Write Field["obj", name] |
1061 { | 1062 { |
1062 setter <- [[~]Unbox["newval", setref] | 1063 setter <- [[~]Unbox["newval", setref] |
1063 ]Move["obj", "out"] | 1064 ]Move["obj", "out"] |
1065 { Print ["got setter"] } | |
1064 } | 1066 } |
1065 } | 1067 } |
1066 | 1068 |
1067 out <- [[backend]Store Function[getter]]Store Function[setter] | 1069 out <- [[backend]Store Function[getter]]Store Function[setter] |
1068 | 1070 |
1104 Worker Refs | 1106 Worker Refs |
1105 } | 1107 } |
1106 | 1108 |
1107 NProgram[:out] | 1109 NProgram[:out] |
1108 { | 1110 { |
1109 out <- [[[Build["NProgram"]]Blueprints <<[New@Dictionary[]]]Workers <<[New@Dictionary[]]]Worker Refs <<[New@Dictionary[]] | 1111 out <- [[[Build["NProgram"]]Blueprints <<[Dictionary[]]]Workers <<[Dictionary[]]]Worker Refs <<[Dictionary[]] |
1110 } | 1112 } |
1111 | 1113 |
1112 Bind Worker@NProgram[prog,name,worker:out] | 1114 Bind Worker@NProgram[prog,name,worker:out] |
1113 { | 1115 { |
1114 after bind <- [prog]Workers << [ [[prog]Workers >>]Set[name, [worker]Name <<[name]] ] | 1116 after bind <- [prog]Workers << [ [[prog]Workers >>]Set[name, [worker]Name <<[name]] ] |
1137 out <- [blueprint]Compile Special[backend, name] | 1139 out <- [blueprint]Compile Special[backend, name] |
1138 } | 1140 } |
1139 | 1141 |
1140 _Compile Program[backend, worker, name:out] | 1142 _Compile Program[backend, worker, name:out] |
1141 { | 1143 { |
1144 Print["_Compile Program"] | |
1142 out <- [worker]Compile Worker[backend, name] | 1145 out <- [worker]Compile Worker[backend, name] |
1143 } | 1146 } |
1144 | 1147 |
1145 Compile Program@NProgram[prog, backend:out] | 1148 Compile Program@NProgram[prog, backend:out] |
1146 { | 1149 { |
1147 out <- Fold["_Compile Program", Fold["_Compile Program BP Special", Fold["_Compile Program BP", backend, [prog]Blueprints >>], [prog]Blueprints >>], Map[[prog]Workers >>, ["Infer Types"]Set Input[1, prog]] ] | 1150 backend with bps <- Generate Number Methods[Fold["_Compile Program BP Special", Fold["_Compile Program BP", backend, [prog]Blueprints >>], [prog]Blueprints >>]] |
1151 { Print["All blueprints added"] } | |
1152 workers with infer <- SMap[[prog]Workers >>, ["Infer Types"]Set Input[1, prog]] | |
1153 { Print["Type inference complete"] } | |
1154 out <- Fold["_Compile Program", backend with bps, workers with infer] | |
1148 } | 1155 } |
1149 | 1156 |
1150 Register Method@NProgram[prog, name, convention, inputs, outputs: out] | 1157 Register Method@NProgram[prog, name, convention, inputs, outputs: out] |
1151 { | 1158 { |
1152 out <- [prog]Worker Refs <<[ [[prog]Worker Refs >>]Set[name, Worker Ref[name, convention, inputs, outputs, Yes]]] | 1159 out <- [prog]Worker Refs <<[ [[prog]Worker Refs >>]Set[name, Worker Ref[name, convention, inputs, outputs, Yes]]] |
1169 } | 1176 } |
1170 } | 1177 } |
1171 | 1178 |
1172 Register Builtins@NProgram[prog:out] | 1179 Register Builtins@NProgram[prog:out] |
1173 { | 1180 { |
1174 registered <- [[[[[[[[[[[prog]Register Worker["+@Int32", "rhope", 2, 1] | 1181 registered <- [[[[prog]Register Worker["Print", "rhope", 1, 1] |
1175 ]Register Worker["-@Int32", "rhope", 2, 1] | |
1176 ]Register Worker["*@Int32", "rhope", 2, 1] | |
1177 ]Register Worker["/@Int32", "rhope", 2, 1] | |
1178 ]Register Worker["LShift@Int32", "rhope", 2, 1] | |
1179 ]Register Worker["RShift@Int32", "rhope", 2, 1] | |
1180 ]Register Worker["Print", "rhope", 1, 1] | |
1181 ]Register Worker["If@Boolean", "rhope", 1, 2] | 1182 ]Register Worker["If@Boolean", "rhope", 1, 2] |
1182 ]Register Worker["<@Int32", "rhope", 2, 1] | |
1183 ]Register Worker[">@Int32", "rhope", 2, 1] | |
1184 ]Register Worker["Build", "rhope", 1, 1] | 1183 ]Register Worker["Build", "rhope", 1, 1] |
1184 ]Register Number Methods | |
1185 | 1185 |
1186 out <- [[[[[[[[[[[[[registered]Bind Blueprint["Int32", NBlueprint[]] | 1186 out <- [[[registered]Bind Worker["If@Boolean", |
1187 ]Bind Worker["+@Int32", | |
1188 [[[[[NWorker["rhope"] | |
1189 ]Inputs <<[("left","right")] | |
1190 ]Input Types <<[ [[()]Append[ Type Instance["Int32"]]]Append[Type Instance["Int32"]] ] | |
1191 ]Outputs <<[("out")] | |
1192 ]Output Types <<[ [()]Append[Type Instance["Int32"]] ] | |
1193 ]Builtin? <<[Yes]] | |
1194 ]Bind Worker["-@Int32", | |
1195 [[[[[NWorker["rhope"] | |
1196 ]Inputs <<[("left","right")] | |
1197 ]Input Types <<[ [[()]Append[ Type Instance["Int32"]]]Append[Type Instance["Int32"]] ] | |
1198 ]Outputs <<[("out")] | |
1199 ]Output Types <<[ [()]Append[Type Instance["Int32"]] ] | |
1200 ]Builtin? <<[Yes]] | |
1201 ]Bind Worker["*@Int32", | |
1202 [[[[[NWorker["rhope"] | |
1203 ]Inputs <<[("left","right")] | |
1204 ]Input Types <<[ [[()]Append[ Type Instance["Int32"]]]Append[Type Instance["Int32"]] ] | |
1205 ]Outputs <<[("out")] | |
1206 ]Output Types <<[ [()]Append[Type Instance["Int32"]] ] | |
1207 ]Builtin? <<[Yes]] | |
1208 ]Bind Worker["/@Int32", | |
1209 [[[[[NWorker["rhope"] | |
1210 ]Inputs <<[("left","right")] | |
1211 ]Input Types <<[ [[()]Append[ Type Instance["Int32"]]]Append[Type Instance["Int32"]] ] | |
1212 ]Outputs <<[("out")] | |
1213 ]Output Types <<[ [()]Append[Type Instance["Int32"]] ] | |
1214 ]Builtin? <<[Yes]] | |
1215 ]Bind Worker["LShift@Int32", | |
1216 [[[[[NWorker["rhope"] | |
1217 ]Inputs <<[("left","right")] | |
1218 ]Input Types <<[ [[()]Append[ Type Instance["Int32"]]]Append[Type Instance["Int32"]] ] | |
1219 ]Outputs <<[("out")] | |
1220 ]Output Types <<[ [()]Append[Type Instance["Int32"]] ] | |
1221 ]Builtin? <<[Yes]] | |
1222 ]Bind Worker["RShift@Int32", | |
1223 [[[[[NWorker["rhope"] | |
1224 ]Inputs <<[("left","right")] | |
1225 ]Input Types <<[ [[()]Append[ Type Instance["Int32"]]]Append[Type Instance["Int32"]] ] | |
1226 ]Outputs <<[("out")] | |
1227 ]Output Types <<[ [()]Append[Type Instance["Int32"]] ] | |
1228 ]Builtin? <<[Yes]] | |
1229 ]Bind Worker["<@Int32", | |
1230 [[[[[NWorker["rhope"] | |
1231 ]Inputs <<[("left","right")] | |
1232 ]Input Types <<[ [[()]Append[ Type Instance["Int32"]]]Append[Type Instance["Int32"]] ] | |
1233 ]Outputs <<[("out")] | |
1234 ]Output Types <<[ [()]Append[Type Instance["Int32"]] ] | |
1235 ]Builtin? <<[Yes]] | |
1236 ]Bind Worker[">@Int32", | |
1237 [[[[[NWorker["rhope"] | |
1238 ]Inputs <<[("left","right")] | |
1239 ]Input Types <<[ [[()]Append[ Type Instance["Int32"]]]Append[Type Instance["Int32"]] ] | |
1240 ]Outputs <<[("out")] | |
1241 ]Output Types <<[ [()]Append[Type Instance["Int32"]] ] | |
1242 ]Builtin? <<[Yes]] | |
1243 ]Bind Blueprint["Boolean", NBlueprint[]] | |
1244 ]Bind Worker["If@Boolean", | |
1245 [[[[[NWorker["rhope"] | 1187 [[[[[NWorker["rhope"] |
1246 ]Inputs <<[("condition")] | 1188 ]Inputs <<[("condition")] |
1247 ]Input Types <<[ [()]Append[Type Instance["Boolean"]] ] | 1189 ]Input Types <<[ [()]Append[Type Instance["Boolean"]] ] |
1248 ]Outputs <<[("isyes","isno")] | 1190 ]Outputs <<[("isyes","isno")] |
1249 ]Output Types <<[ [[()]Append[Type Instance["Boolean"]]]Append[Type Instance["Boolean"]] ] | 1191 ]Output Types <<[ [[()]Append[Type Instance["Boolean"]]]Append[Type Instance["Boolean"]] ] |