comparison nworker.rhope @ 42:aabda74c7a88

Fields can now be defined to have naked primitive types
author Mike Pavone <pavone@retrodev.com>
date Tue, 13 Oct 2009 00:07:34 -0400
parents 789a146a48e1
children 709df3e82bb4
comparison
equal deleted inserted replaced
41:1b86a1ee500a 42:aabda74c7a88
764 } 764 }
765 765
766 Make Init[func,field:out] 766 Make Init[func,field:out]
767 { 767 {
768 name <- [field]Index[0] 768 name <- [field]Index[0]
769 Print[["Field: "]Append[name]]
770 { Print[[" Variant: "]Append[variant]] }
769 variant <- [[field]Index[1]]Variant >> 771 variant <- [[field]Index[1]]Variant >>
770 If[[variant] = ["Boxed"]] 772 If[[variant] = ["Boxed"]]
771 { 773 {
772 out <- [func]Set Field Null["obj", name] 774 out <- [func]Set Field Null["obj", name]
775 { Print["done"] }
773 }{ 776 }{
774 out <- func 777 out <- func
775 } 778 }
776 } 779 }
777 780
809 } 812 }
810 } 813 }
811 814
812 Make Special@NBlueprint[bp,backend,func name,bp name,pop worker:out] 815 Make Special@NBlueprint[bp,backend,func name,bp name,pop worker:out]
813 { 816 {
817 Print[[["Make Special: "]Append[func name]]Append[bp name]]
814 func <- [[backend]Create Function[func name,("obj"),(),"cdecl"] 818 func <- [[backend]Create Function[func name,("obj"),(),"cdecl"]
815 ]Set Input Type[bp name, 0] 819 ]Set Input Type[Type Instance[bp name], 0]
816 out <- [backend]Store Function[Fold[pop worker, func, [bp]Fields >>]] 820 out <- [backend]Store Function[Fold[pop worker, func, [bp]Fields >>]]
817 } 821 }
818 822
819 Getters Setters[backend,field,type name:out] 823 Getters Setters[backend,field,type name:out]
820 { 824 {
821 //TODO: Throw an exception or something if we read a field that is empty 825 //TODO: Throw an exception or something if we read a field that is empty
822 Print[["Getters Setters: "]Append[name]] 826 Print[["Getters Setters: "]Append[name]]
823 name <- [field]Index[0] 827 name <- [field]Index[0]
824 type <- [field]Index[1] 828 type <- [field]Index[1]
825 ,getref <- [[[[backend]Create Function[ [[[name]Append[" >>"]]Append["@"]]Append[type name], ("obj"), ("out"), "rhope"] 829 mytype <- Type Instance[type name]
826 ]Set Input Type[type name, 0] 830 start getter,getref <- [[[[backend]Create Function[ [[[name]Append[" >>"]]Append["@"]]Append[type name], ("obj"), ("out"), "rhope"]
827 ]Set Output Type[type, 0] 831 ]Set Input Type[mytype, 0]
832 ]Set Output Type[[type]Set Variant["Boxed"], 0]
828 ]Read Field["obj", name] 833 ]Read Field["obj", name]
829 { getter <- [[~]Do AddRef[getref, "out"]]Release["obj"] 834 If[[[type]Variant >>] = ["Boxed"]]
830 { Print["Got getter"] } } 835 {
836 getter <- [[start getter]Do AddRef[getref, "out"]]Release["obj"]
837 }{
838 getter <- [[start getter]Box[getref, "out", type]]Release["obj"]
839 }
831 840
832 ,origref <- [[[[[[backend]Create Function[ [[[name]Append[" <<"]]Append["@"]]Append[type name], ("obj","newval"), ("out"), "rhope"] 841 begin setter <- [[[[[backend]Create Function[ [[[name]Append[" <<"]]Append["@"]]Append[type name], ("obj","newval"), ("out"), "rhope"]
833 ]Set Input Type[type name, 0] 842 ]Set Input Type[mytype, 0]
834 ]Set Input Type[type, 1] 843 ]Set Input Type[[type]Set Variant["Boxed"], 1]
835 ]Set Output Type[type name, 0] 844 ]Set Output Type[mytype, 0]
836 ]Copy["obj"] 845 ]Copy["obj"]
837 ]Read Field["obj", name] 846
838 { 847 If[[[type]Variant >>] = ["Boxed"]]
839 stream <- [[~]Instruction Stream 848 {
840 ]Release[origref] 849 ,origref <- [begin setter]Read Field["obj", name]
841 ,setref <- [[~]Do If[origref, stream] 850 {
842 ]Write Field["obj", name] 851 stream <- [[~]Instruction Stream
843 { 852 ]Release[origref]
844 setter <- [[~]Move["newval", setref] 853 ,setref <- [[~]Do If[origref, stream]
854 ]Write Field["obj", name]
855 {
856 setter <- [[~]Move["newval", setref]
857 ]Move["obj", "out"]
858 { Print["got setter"] }
859 }
860 }
861 }{
862 ,setref <- [begin setter]Write Field["obj", name]
863 {
864 setter <- [[~]Unbox["newval", setref]
845 ]Move["obj", "out"] 865 ]Move["obj", "out"]
846 { Print["got setter"] }
847 } 866 }
848 } 867 }
849 868
850 out <- [[backend]Store Function[getter]]Store Function[setter] 869 out <- [[backend]Store Function[getter]]Store Function[setter]
851 870
852 } 871 }
853 872
854 Compile Blueprint@NBlueprint[bp,backend,name:out] 873 Compile Blueprint@NBlueprint[bp,backend,name:out]
855 { 874 {
856 875 Print[["Compiling blueprint: "]Append[name]]
857 //Rhope identifiers can't start with spaces, so we can use identifiers that start with spaces for special functions 876 //Rhope identifiers can't start with spaces, so we can use identifiers that start with spaces for special functions
858 init name <- [" init "]Append[name] 877 init name <- [" init "]Append[name]
859 copy name <- [" copy "]Append[name] 878 copy name <- [" copy "]Append[name]
860 cleanup name <- [" cleanup "]Append[name] 879 cleanup name <- [" cleanup "]Append[name]
861 type <- [[[Fold["_Compile Blueprint Methods", Fold["_Compile Blueprint Fields", [backend]Create Type[name], [bp]Fields >>], [bp]Methods >>] 880 type <- [[[Fold["_Compile Blueprint Methods", Fold["_Compile Blueprint Fields", [backend]Create Type[name], [bp]Fields >>], [bp]Methods >>]
862 ]Init <<[init name] 881 ]Init <<[init name]
863 ]Copy <<[copy name] 882 ]Copy <<[copy name]
864 ]Cleanup <<[cleanup name] 883 ]Cleanup <<[cleanup name]
884 { Print["Created type on backend"] }
865 885
886 out <- [backend]Register Type[type]
887 }
888
889 Compile Special@NBlueprint[bp,backend,name:out]
890 {
891 init name <- [" init "]Append[name]
892 copy name <- [" copy "]Append[name]
893 cleanup name <- [" cleanup "]Append[name]
866 got specials <- [bp]Make Special[ 894 got specials <- [bp]Make Special[
867 [bp]Make Special[ 895 [bp]Make Special[
868 [bp]Make Special[[backend]Register Type[type], init name, name, "Make Init"], 896 [bp]Make Special[backend, init name, name, "Make Init"],
869 copy name, name, "Make Copy"], 897 copy name, name, "Make Copy"],
870 cleanup name, name, "Make Cleanup"] 898 cleanup name, name, "Make Cleanup"]
871 out <- Fold[["Getters Setters"]Set Input[2, name], got specials, [bp]Fields >>] 899 out <- Fold[["Getters Setters"]Set Input[2, name], got specials, [bp]Fields >>]
872 } 900 }
873 901
904 _Compile Program BP[backend, blueprint, name:out] 932 _Compile Program BP[backend, blueprint, name:out]
905 { 933 {
906 out <- [blueprint]Compile Blueprint[backend, name] 934 out <- [blueprint]Compile Blueprint[backend, name]
907 } 935 }
908 936
937 _Compile Program BP Special[backend, blueprint, name:out]
938 {
939 out <- [blueprint]Compile Special[backend, name]
940 }
941
909 _Compile Program[backend, worker, name:out] 942 _Compile Program[backend, worker, name:out]
910 { 943 {
911 out <- [worker]Compile Worker[backend, name] 944 out <- [worker]Compile Worker[backend, name]
912 } 945 }
913 946
914 Compile Program@NProgram[prog, backend:out] 947 Compile Program@NProgram[prog, backend:out]
915 { 948 {
916 out <- Fold["_Compile Program", Fold["_Compile Program BP", backend, [prog]Blueprints >>], [prog]Workers >>] 949 out <- Fold["_Compile Program", Fold["_Compile Program BP Special", Fold["_Compile Program BP", backend, [prog]Blueprints >>], [prog]Blueprints >>], [prog]Workers >>]
917 } 950 }
918 951
919 Register Worker@NProgram[prog, name, convention, inputs, outputs: out] 952 Register Worker@NProgram[prog, name, convention, inputs, outputs: out]
920 { 953 {
921 Print[["Register Worker "]Append[name]] 954 Print[["Register Worker "]Append[name]]