comparison nworker.rhope @ 74:a844c623c7df

Add support for Worker type
author Mike Pavone <pavone@retrodev.com>
date Thu, 01 Jul 2010 21:32:08 -0400
parents 6a1a7d5cc2d9
children 0083b2f7b3c7
comparison
equal deleted inserted replaced
73:6a1a7d5cc2d9 74:a844c623c7df
191 Conditions 191 Conditions
192 } 192 }
193 193
194 Wire To@NWorker Node[node,from,output,pre input:out] 194 Wire To@NWorker Node[node,from,output,pre input:out]
195 { 195 {
196 existing cons <- [[node]Wires To >>]Index[input] {}
197 { existing cons <- () }
196 input <- [pre input]+[1] 198 input <- [pre input]+[1]
197 out <- [node]Wires To <<[ 199 out <- [node]Wires To <<[
198 [[node]Wires To >>]Set[input, 200 [[node]Wires To >>]Set[input,
199 [[[node]Wires To >>]Index[input] 201 [existing cons]Append[Node Ref[from,output]]
200 ]Append[Node Ref[from,output]]
201 ] 202 ]
202 ] 203 ]
203 } 204 }
204 205
205 Wire From@NWorker Node[node,to,input,output:out] 206 Wire From@NWorker Node[node,to,input,output:out]
206 { 207 {
208 existing cons <- [[node]Wires From >>]Index[output] {}
209 { exist cons <- () }
207 out <- [node]Wires From <<[ 210 out <- [node]Wires From <<[
208 [[node]Wires From >>]Set[output, 211 [[node]Wires From >>]Set[output,
209 [[[node]Wires From >>]Index[output] 212 [existing cons]Append[Node Ref[to,input]]
210 ]Append[Node Ref[to,input]]
211 ] 213 ]
212 ] 214 ]
213 } 215 }
214 216
215 _Has Input Types@NWorker Node[node,input num:does,does not] 217 _Has Input Types@NWorker Node[node,input num:does,does not]
343 345
344 Infer Types Node[nodelist,node,index,prog,worker:out] 346 Infer Types Node[nodelist,node,index,prog,worker:out]
345 { 347 {
346 If[[[node]Type >>] = ["const"]] 348 If[[[node]Type >>] = ["const"]]
347 { 349 {
350 const type <- Type Of[[node]Data >>]
348 //Temporary hack 351 //Temporary hack
349 If[[Type Of[[node]Data >>]] = ["Whole Number"]] 352 If[[const type] = ["Whole Number"]]
350 { 353 {
351 outtype <- Type Instance["Int32"] 354 outtype <- Type Instance["Int32"]
352 }{ 355 }{
353 If[[Type Of[[node]Data >>]] = ["Type Instance"]] 356 If[[const type] = ["Type Instance"]]
354 { 357 {
355 outtype <- Type Instance["Blueprint"] 358 outtype <- Type Instance["Blueprint"]
356 }{ 359 }{
357 If[[Type Of[[node]Data >>]] = ["Machine Integer"]] 360 If[[const type] = ["Machine Integer"]]
358 { 361 {
359 If[[[node]Data >>]Signed? >>] 362 If[[[node]Data >>]Signed? >>]
360 { base <- "Int" } 363 { base <- "Int" }
361 { base <- "UInt" } 364 { base <- "UInt" }
362 365
363 outtype <- Type Instance[[base]Append[ [[node]Data >>]Size >> ]] 366 outtype <- Type Instance[[base]Append[ [[node]Data >>]Size >> ]]
364 }{ 367 }{
365 outtype <- Type Instance[Type Of[[node]Data >>]] 368 If[[const type] = ["Worker Literal"]]
369 {
370 outtype <- Type Instance["Worker"]
371 }{
372 outtype <- Type Instance[const type]
373 }
366 } 374 }
367 } 375 }
368 } 376 }
369 nextnode <- [node]Output Types <<[ [()]Append[outtype] ] 377 nextnode <- [node]Output Types <<[ [()]Append[outtype] ]
370 378
636 If[[[node]Data >>]Signed? >>] 644 If[[[node]Data >>]Signed? >>]
637 { s <- "i" } 645 { s <- "i" }
638 { s <- "u" } 646 { s <- "u" }
639 datstring <- [[[[node]Data >>]Value >>]Append[s]]Append[[[node]Data >>]Size >>] 647 datstring <- [[[[node]Data >>]Value >>]Append[s]]Append[[[node]Data >>]Size >>]
640 }{ 648 }{
641 datstring <- [node]Data >> 649 If[[Type Of[[node]Data >>]] = ["Worker Literal"]]
650 {
651 If[[[[[node]Data >>]Args >>]Length] > [0]]
652 {
653 datstring <- [[["Arg "]Append[[noderef]Index >>]]Append[" "]]Append[[worker]Name >>]
654 }{
655 datstring <- [[node]Data >>]Name >>
656 }
657 }{
658 datstring <- [node]Data >>
659 }
642 } 660 }
643 } 661 }
644 out <- Constant[[[Type Of[[node]Data >>]]Append["_"]]Append[datstring]] 662 out <- Constant[[[Type Of[[node]Data >>]]Append["_"]]Append[datstring]]
645 663
646 } 664 }
766 If[[[node]Data >>]Signed? >>] 784 If[[[node]Data >>]Signed? >>]
767 { s <- "i" } 785 { s <- "i" }
768 { s <- "u" } 786 { s <- "u" }
769 datstring <- [[[[node]Data >>]Value >>]Append[s]]Append[[[node]Data >>]Size >>] 787 datstring <- [[[[node]Data >>]Value >>]Append[s]]Append[[[node]Data >>]Size >>]
770 }{ 788 }{
771 datstring <- [node]Data >> 789 If[[Type Of[[node]Data >>]] = ["Worker Literal"]]
790 {
791 If[[[[[node]Data >>]Args >>]Length] > [0]]
792 {
793 datstring <- [[["Arg "]Append[node index]]Append[" "]]Append[[worker]Name >>]
794 }{
795 datstring <- [[node]Data >>]Name >>
796 }
797 }{
798 datstring <- [node]Data >>
799 }
772 } 800 }
773 } 801 }
774 nfunc <- [func]Register Constant[[[Type Of[[node]Data >>]]Append["_"]]Append[datstring], [node]Data >>] 802 nfunc <- [func]Register Constant[[[Type Of[[node]Data >>]]Append["_"]]Append[datstring], [node]Data >>]
775 }{ 803 }{
776 nfunc <- Val[func] 804 nfunc <- Val[func]
1075 out <- [type]Add Field[name,ftype] 1103 out <- [type]Add Field[name,ftype]
1076 } 1104 }
1077 1105
1078 _Compile Blueprint Methods[type,junk,name:out] 1106 _Compile Blueprint Methods[type,junk,name:out]
1079 { 1107 {
1080 out <- [type]Add Method[name] 1108 If[[[name]=["Call"]] And [[[type]Name >>] = ["Worker"]]]
1109 {
1110 out <- type
1111 }{
1112 out <- [type]Add Method[name]
1113 }
1081 } 1114 }
1082 1115
1083 Make Init[func,field:out] 1116 Make Init[func,field:out]
1084 { 1117 {
1085 name <- [field]Index[0] 1118 name <- [field]Index[0]
1282 } 1315 }
1283 } 1316 }
1284 1317
1285 Register Builtins@NProgram[prog:out] 1318 Register Builtins@NProgram[prog:out]
1286 { 1319 {
1287 registered <- [[[[[prog]Register Worker["Print", "rhope", 1, 1] 1320 registered <- [[[[[[prog]Register Worker["Print", "rhope", 1, 1]
1288 ]Register Worker["If@Boolean", "rhope", 1, 2] 1321 ]Register Worker["If@Boolean", "rhope", 1, 2]
1289 ]Register Worker["Build", "rhope", 1, 1] 1322 ]Register Worker["Build", "rhope", 1, 1]
1290 ]Register Worker["Blueprint Of", "rhope", 1, 1] 1323 ]Register Worker["Blueprint Of", "rhope", 1, 1]
1324 ]Register Worker["Call@Worker", "rhope", 1, 2] //We're using 2 because we need to assume that the outputs are conditional
1291 ]Register Number Methods 1325 ]Register Number Methods
1292 1326
1293 out <- [[[[registered]Bind Worker["If@Boolean", 1327 out <- [[[[[registered]Bind Worker["If@Boolean",
1294 [[[[[NWorker["rhope"] 1328 [[[[[NWorker["rhope"]
1295 ]Inputs <<[("condition")] 1329 ]Inputs <<[("condition")]
1296 ]Input Types <<[ [()]Append[Type Instance["Boolean"]] ] 1330 ]Input Types <<[ [()]Append[Type Instance["Boolean"]] ]
1297 ]Outputs <<[("isyes","isno")] 1331 ]Outputs <<[("isyes","isno")]
1298 ]Output Types <<[ [[()]Append[Type Instance["Boolean"]]]Append[Type Instance["Boolean"]] ] 1332 ]Output Types <<[ [[()]Append[Type Instance["Boolean"]]]Append[Type Instance["Boolean"]] ]
1316 ]Inputs <<[("object")] 1350 ]Inputs <<[("object")]
1317 ]Input Types <<[ [()]Append[Type Instance["Any Type"]]] 1351 ]Input Types <<[ [()]Append[Type Instance["Any Type"]]]
1318 ]Outputs <<[("type")] 1352 ]Outputs <<[("type")]
1319 ]Output Types <<[ [()]Append[Type Instance["Blueprint"]]] 1353 ]Output Types <<[ [()]Append[Type Instance["Blueprint"]]]
1320 ]Builtin? <<[Yes]] 1354 ]Builtin? <<[Yes]]
1355 ]Bind Worker["Call@Worker",
1356 [[[[[NWorker["rhope"]
1357 ]Inputs <<[("worker")]
1358 ]Input Types <<[ [()]Append[Type Instance["Worker"]] ]
1359 ]Outputs <<[("ret1","ret2")]
1360 ]Output Types <<[ [[()]Append[Type Instance["Any Type"]]]Append[Type Instance["Any Type"]] ]
1361 ]Builtin? << [Yes]]
1321 } 1362 }
1322 1363
1323 Find Worker@NProgram[prog, name:out,notfound] 1364 Find Worker@NProgram[prog, name:out,notfound]
1324 { 1365 {
1325 out,notfound <- [[prog]Worker Refs >>]Index[name] 1366 out,notfound <- [[prog]Worker Refs >>]Index[name]