comparison nworker_c.rhope @ 139:a68e6828d896

Global stores and transactions are working. Definately leaks memory on retries. Probably a fair number of bugs to work out. However, a basic test program works.
author Mike Pavone <pavone@retrodev.com>
date Fri, 19 Nov 2010 04:04:14 -0500
parents fc3815b7462f
children c14698c512f1
comparison
equal deleted inserted replaced
138:1411de6050e1 139:a68e6828d896
294 Library 294 Library
295 } 295 }
296 296
297 NWorker[convention:out] 297 NWorker[convention:out]
298 { 298 {
299 out <- [[[[[[[[[Build[NWorker()]]Convention <<[convention]]Nodes <<[()]]Inputs <<[()]]Outputs <<[()]]Input Types <<[()]]Output Types <<[()]]Name <<["Anonymous"]]Builtin? <<[No]]Library << [""] 299 out <- [[[[[[[[[[Build[NWorker()]]Convention <<[convention]]Nodes <<[()]]Inputs <<[()]]Outputs <<[()]]Input Types <<[()]]Output Types <<[()]]Name <<["Anonymous"]]Builtin? <<[No]]Library << [""]]Uses <<[()]
300 } 300 }
301 301
302 String@NWorker[worker:out] 302 String@NWorker[worker:out]
303 { 303 {
304 out <- ["NWorker"]Append[[worker]Name >>] 304 out <- ["NWorker"]Append[[worker]Name >>]
391 If[[[node]Type >>] = ["output"]] 391 If[[[node]Type >>] = ["output"]]
392 { 392 {
393 out <- nodelist 393 out <- nodelist
394 394
395 }{ 395 }{
396 [node]Has Input Types? 396 If[[[node]Type >>] = ["getglobal"]]
397 { 397 {
398 If[[[node]Type >>] = ["setfield"]] 398 nextnode <- [node]Output Types <<[ [()]Append[Type Instance["Any Type"]] ]
399 }{
400 [node]Has Input Types?
399 { 401 {
400 nextnode <- [node]Output Types <<[ [()]Append[ [[[node]Input Types >>]Index[0]]Index[0] ] ] 402 If[[[node]Type >>] = ["setfield"]]
401 }{
402 If[[[node]Type >>] = ["getfield"]]
403 { 403 {
404 type <- [[[node]Input Types >>]Index[0]]Index[0] 404 nextnode <- [node]Output Types <<[ [()]Append[ [[[node]Input Types >>]Index[0]]Index[0] ] ]
405 If[[[type]Name >>] = ["Any Type"]] 405 }{
406 If[[[node]Type >>] = ["getfield"]]
406 { 407 {
407 outtype <- Val[type] 408 type <- [[[node]Input Types >>]Index[0]]Index[0]
408 }{ 409 If[[[type]Name >>] = ["Any Type"]]
409 outtype <- [prog]Find Field[[node]Data >>, type] {}
410 { 410 {
411 //TODO: Return errors rather than printing them 411 outtype <- Val[type]
412 Print[
413 [[[[["Type "
414 ]Append[[type]Name >>]
415 ]Append[" does not have a field named "]
416 ]Append[[node]Data >>]
417 ]Append[" in worker "]
418 ]Append[worker name]]
419 }
420 }
421 nextnode <- [node]Output Types <<[ [()]Append[outtype] ]
422 }{
423 worker name <- [[node]Data >>]Name >>
424 [prog]Is Method?[worker name]
425 {
426 first arg type <- [[[node]Input Types >>]Index[0]]Index[0]
427 If[[[first arg type]Name >>] = ["Any Type"]]
428 {
429 outtypes <- Fold[Append[?, Type Instance["Any Type"]], (), Range[0, [node]Inputs >>]]
430 }{ 412 }{
431 worker def <- [prog]Find Method[worker name, first arg type] {} 413 outtype <- [prog]Find Field[[node]Data >>, type] {}
432 { 414 {
433 //TODO: Return errors instead of printing them 415 //TODO: Return errors rather than printing them
434 Print[ 416 Print[
435 [[[[["Type " 417 [[[[["Type "
436 ]Append[[first arg type]Name >>] 418 ]Append[[type]Name >>]
437 ]Append[" does not support method "] 419 ]Append[" does not have a field named "]
438 ]Append[worker name] 420 ]Append[[node]Data >>]
439 ]Append[" in worker "] 421 ]Append[" in worker "]
440 ]Append[ [worker]Name >> ]] 422 ]Append[worker name]]
441 } 423 }
442 } 424 }
425 nextnode <- [node]Output Types <<[ [()]Append[outtype] ]
443 }{ 426 }{
444 worker def <- [prog]Find Worker Def[worker name] 427
428 worker name <- [[node]Data >>]Name >>
429 [prog]Is Method?[worker name]
430 {
431 first arg type <- [[[node]Input Types >>]Index[0]]Index[0]
432 If[[[first arg type]Name >>] = ["Any Type"]]
433 {
434 outtypes <- Fold[Append[?, Type Instance["Any Type"]], (), Range[0, [node]Inputs >>]]
435 }{
436 worker def <- [prog]Find Method[worker name, first arg type] {}
437 {
438 //TODO: Return errors instead of printing them
439 Print[
440 [[[[["Type "
441 ]Append[[first arg type]Name >>]
442 ]Append[" does not support method "]
443 ]Append[worker name]
444 ]Append[" in worker "]
445 ]Append[ [worker]Name >> ]]
446 }
447 }
448 }{
449 worker def <- [prog]Find Worker Def[worker name]
450 }
451 outtypes <- [worker def]Output Types >>
452 nextnode <- [node]Output Types <<[ outtypes ]
445 } 453 }
446 outtypes <- [worker def]Output Types >>
447 nextnode <- [node]Output Types <<[ outtypes ]
448 } 454 }
455 }{
456 out <- nodelist
449 } 457 }
450 }{
451 out <- nodelist
452 } 458 }
453 } 459 }
454 } 460 }
455 } 461 }
456 462
735 { 741 {
736 out <- AddRef[Result Var Name[[noderef]IO Num >>, [noderef]Index >>]] 742 out <- AddRef[Result Var Name[[noderef]IO Num >>, [noderef]Index >>]]
737 }{ 743 }{
738 out <- Constant[Const Name[[node]Data >>, [noderef]Index >>, [worker]Name >>]] 744 out <- Constant[Const Name[[node]Data >>, [noderef]Index >>, [worker]Name >>]]
739 } 745 }
746 }{
747 If[[[node]Type >>]=["getglobal"]]
748 {
749 [conditions]Empty?
750 {
751 out <- AddRef[Result Var Name[[noderef]IO Num >>, [noderef]Index >>]]
752 }{
753 out <- AddRef[Global Get[[[node]Data >>]Index[0], [[node]Data >>]Index[1]]]
754 }
755 }
740 } 756 }
741 } 757 }
742 } 758 }
743 759
744 Val[maybe addref] 760 Val[maybe addref]
903 nfunc <- [withconst]Do If[~, stream] 919 nfunc <- [withconst]Do If[~, stream]
904 }{ 920 }{
905 nfunc <- Val[withconst] 921 nfunc <- Val[withconst]
906 } 922 }
907 }{ 923 }{
908 [conditions]For Backend 924 If[[[node]Type >>]=["getglobal"]]
909 { 925 {
910 input name <- [[worker]Inputs >>]Index[ [node]Data >> ] 926 [conditions]For Backend
911 stream <- [[func]Instruction Stream 927 {
912 ]Move[input name, Result Var Name[0, node index]] 928 stream <- [[func]Instruction Stream
913 nfunc <- [func]Do If[~, stream] 929 ]Move[Global Get[[[node]Data >>]Index[0], [[node]Data >>]Index[1]], Result Var Name[0, node index]]
930 nfunc <- [func]Do If[~, stream]
931 }{
932 nfunc <- Val[func]
933 }
914 }{ 934 }{
915 nfunc <- Val[func] 935 If[[[node]Type >>]=["setglobal"]]
936 {
937 inputs <- [worker]Collect Inputs[node]
938 [conditions]For Backend
939 {
940 stream <- [func]Instruction Stream
941 nfunc <- [func]Do If[~, nstream]
942 }{
943 stream <- Val[func]
944 nfunc <- Val[nstream]
945 }
946 nstream <- [stream]Set Global[[[node]Data >>]Index[0], [[node]Data >>]Index[1], [inputs]Index[0]]
947 }{
948 [conditions]For Backend
949 {
950 input name <- [[worker]Inputs >>]Index[ [node]Data >> ]
951 stream <- [[func]Instruction Stream
952 ]Move[input name, Result Var Name[0, node index]]
953 nfunc <- [func]Do If[~, stream]
954 }{
955 nfunc <- Val[func]
956 }
957 }
916 } 958 }
917 } 959 }
918 960
919 } 961 }
920 } 962 }
1223 { 1265 {
1224 out <- program 1266 out <- program
1225 }{ 1267 }{
1226 If[[[worker]Library >>] = [""]] 1268 If[[[worker]Library >>] = [""]]
1227 { 1269 {
1228 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 >>] 1270 ifunc <- Fold[Set Output Type[?], Fold[Set Input Type[?], [[program]Create Function[name,[worker]Inputs >>, [worker]Outputs >>, [worker]Convention >>]]Uses <<[[worker]Uses >>], [worker]Input Types >>], [worker]Output Types >>]
1229 1271
1230 groups <- [worker]Dependency Groups 1272 groups <- [worker]Dependency Groups
1231 1273
1232 fgroup <- [groups]First 1274 fgroup <- [groups]First
1233 { 1275 {
1448 { 1490 {
1449 Blueprints 1491 Blueprints
1450 Workers 1492 Workers
1451 Worker Refs 1493 Worker Refs
1452 Numtypes 1494 Numtypes
1495 Global Stores
1453 } 1496 }
1454 1497
1455 NProgram[:out] 1498 NProgram[:out]
1456 { 1499 {
1457 out <- [[[[Build[NProgram()] 1500 out <- [[[[[Build[NProgram()]
1458 ]Blueprints <<[Dictionary[]] 1501 ]Blueprints <<[Dictionary[]]
1459 ]Workers <<[Dictionary[]] 1502 ]Workers <<[Dictionary[]]
1460 ]Worker Refs <<[Dictionary[]] 1503 ]Worker Refs <<[Dictionary[]]
1461 ]Numtypes << [("Int8","Int16","Int32","Int64","UInt8","UInt16","UInt32","UInt64")] 1504 ]Numtypes << [("Int8","Int16","Int32","Int64","UInt8","UInt16","UInt32","UInt64")]
1505 ]Global Stores <<[Dictionary[]]
1462 } 1506 }
1463 1507
1464 Supported Number Types@NProgram[program:out] 1508 Supported Number Types@NProgram[program:out]
1465 { 1509 {
1466 out <- [program]Numtypes >> 1510 out <- [program]Numtypes >>
1505 out <- [worker]Compile Worker[backend, name] 1549 out <- [worker]Compile Worker[backend, name]
1506 } 1550 }
1507 1551
1508 Compile Program@NProgram[prog, backend:out] 1552 Compile Program@NProgram[prog, backend:out]
1509 { 1553 {
1510 backend with bps <- Generate Boolean Methods[Generate Number Methods[Fold[_Compile Program BP Special[?], Fold[_Compile Program BP[?], backend, [prog]Blueprints >>], [prog]Blueprints >>]]] 1554 backend with bps <- Generate Boolean Methods[Generate Number Methods[Fold[_Compile Program BP Special[?], Fold[_Compile Program BP[?], [backend]Global Stores <<[[prog]Global Stores >>], [prog]Blueprints >>], [prog]Blueprints >>]]]
1511 workers with infer <- Map[[prog]Workers >>, Infer Types[?, prog]] 1555 workers with infer <- Map[[prog]Workers >>, Infer Types[?, prog]]
1512 out <- Fold[_Compile Program[?], backend with bps, workers with infer] 1556 out <- Fold[_Compile Program[?], backend with bps, workers with infer]
1513 } 1557 }
1514 1558
1515 Register Method@NProgram[prog, name, convention, inputs, outputs: out] 1559 Register Method@NProgram[prog, name, convention, inputs, outputs: out]