comparison cbackend.rhope @ 37:640f541e9116

Added support for type declarations on user defined workers and added a few more methods to Int32 in the runtime for the C backend
author Mike Pavone <pavone@retrodev.com>
date Mon, 05 Oct 2009 23:12:43 -0400
parents 495dddadd058
children 7f05bbe82f24
comparison
equal deleted inserted replaced
36:495dddadd058 37:640f541e9116
126 Register Fields@C Type[ctype,field reg:out] 126 Register Fields@C Type[ctype,field reg:out]
127 { 127 {
128 out <- Fold["_Register Field C", field reg, [ctype]Fields >>] 128 out <- Fold["_Register Field C", field reg, [ctype]Fields >>]
129 } 129 }
130 130
131 Rhope Type to C[typename:out] 131 Rhope Type to C[type:out]
132 { 132 {
133 If[[Type Of[type]]=["Type Instance"]]
134 {
135 typename <- [type]Name >>
136 variant <- [type]Variant >>
137 }{
138 typename <- type
139 variant <- "boxed"
140 }
133 If[[typename] = ["Any Type"]] 141 If[[typename] = ["Any Type"]]
134 { 142 {
135 out <- "struct object *" 143 out <- "struct object *"
136 }{ 144 }{
137 out <- [["t_"]Append[Escape Rhope Name[typename]]]Append[" *"] 145 [("Naked","Raw Pointer")]Find[variant]
146 {
147 prefix <- "nt_"
148 }{
149 prefix <- "t_"
150 }
151
152 If[[variant]=["Naked"]]
153 {
154 postfix <- ""
155 }{
156 postfix <- " *"
157 }
158
159 out <- [[prefix]Append[Escape Rhope Name[typename]]]Append[postfix]
138 } 160 }
139 } 161 }
140 162
141 _Type Def C Type[text,field:out] 163 _Type Def C Type[text,field:out]
142 { 164 {
287 ]Constants <<[New@Dictionary[]] 309 ]Constants <<[New@Dictionary[]]
288 ]Input Types <<[ Fold[["Append"]Set Input[1, "Any Type"], (), inputs] ] 310 ]Input Types <<[ Fold[["Append"]Set Input[1, "Any Type"], (), inputs] ]
289 ]Output Types <<[ Fold[["Append"]Set Input[1, "Any Type"], (), outputs] ] 311 ]Output Types <<[ Fold[["Append"]Set Input[1, "Any Type"], (), outputs] ]
290 } 312 }
291 313
292 Set Input Type@C Function[func,input num,type:out] 314 Set Input Type@C Function[func,type,input num:out]
293 { 315 {
294 out <- [func]Input Types <<[ [[func]Input Types >>]Set[input num, type] ] 316 out <- [func]Input Types <<[ [[func]Input Types >>]Set[input num, type] ]
295 } 317 }
296 318
297 Set Output Type@C Function[func,output num,type:out] 319 Set Output Type@C Function[func,type,output num:out]
298 { 320 {
299 out <- [func]Output Types <<[ [[func]Output Types >>]Set[output num, type] ] 321 out <- [func]Output Types <<[ [[func]Output Types >>]Set[output num, type] ]
300 } 322 }
301 323
302 Register Constant@C Function[func,name,constant:out] 324 Register Constant@C Function[func,name,constant:out]
424 result op <- Field Ref[var,field] 446 result op <- Field Ref[var,field]
425 } 447 }
426 448
427 Set Field Null@C Function[func,var,field:out] 449 Set Field Null@C Function[func,var,field:out]
428 { 450 {
429 out <- [func]Add Statement[ [[[var]Append["->"]]Append[field]]Append[" = NULL"] ] 451 out <- [func]Add Statement[ [[func]Field Result[var,field]]Append[" = NULL"] ]
430 } 452 }
431 453
432 Copy@C Function[func,pdest:out] 454 Copy@C Function[func,pdest:out]
433 { 455 {
434 dest <- [pdest]Make Op[func] 456 dest <- [pdest]Make Op[func]
630 }{ 652 }{
631 out <- [text]Append[ [["\tParam("]Append[input num]]Append[ [[", "]Append[ [[func]Type Registry >>]Type ID[type] ]]Append[")"] ] ] 653 out <- [text]Append[ [["\tParam("]Append[input num]]Append[ [[", "]Append[ [[func]Type Registry >>]Type ID[type] ]]Append[")"] ] ]
632 } 654 }
633 } 655 }
634 656
657 Check Param Type C[text,type,input num,func:out]
658 {
659 If[[Type Of[type]] = ["String"]]
660 {
661 typename <- type
662 }{
663 typename <- [type]Name >>
664 }
665 If[[typename] = ["Any Type"]]
666 {
667 out <- text
668 }{
669 out <- [text]Append[[[["\tParam("]Append[input num]]Append[ [","]Append[ [[func]Type Registry >>]Type ID[typename] ] ]]Append[")\n"]]
670 }
671 }
672
635 Text@C Function[func:out] 673 Text@C Function[func:out]
636 { 674 {
637 If[ [[func]Convention >>] = ["rhope"] ] 675 If[ [[func]Convention >>] = ["rhope"] ]
638 { 676 {
639 cname <- Escape Rhope Name[[func]Name >>] 677 cname <- Escape Rhope Name[[func]Name >>]
678 param check <- Fold[["Check Param Type C"]Set Input[3, func], "", [func]Input Types >>]
640 If[ [ [[[func]Variables >>]Length]+[[[func]Outputs >>]Length] ] = [0] ] 679 If[ [ [[[func]Variables >>]Length]+[[[func]Outputs >>]Length] ] = [0] ]
641 { 680 {
642 out <- [[[[[["FuncNoLocals(" 681 out <- [[[[[[["FuncNoLocals("
643 ]Append[cname] 682 ]Append[cname]
644 ]Append[",\n\tNumParams "] 683 ]Append[",\n\tNumParams "]
645 ]Append[ [[func]Inputs >>]Length ] 684 ]Append[ [[func]Inputs >>]Length ]
646 ]Append[",\n\tCallSpace 32)\n\n"]//TODO: Fill in with calculated callspace value 685 ]Append[",\n\tCallSpace 32)\n\n"]//TODO: Fill in with calculated callspace value
686 ]Append[param check]
647 ]Append[ [[func]Statements >>]Join[""] ] 687 ]Append[ [[func]Statements >>]Join[""] ]
648 ]Append["EndFunc"] 688 ]Append["EndFunc"]
649 }{ 689 }{
650 out <- [[[[[[[[["Func(" 690 out <- [[[[[[[[[["Func("
651 ]Append[cname] 691 ]Append[cname]
652 ]Append[",\n\tNumParams "] 692 ]Append[",\n\tNumParams "]
653 ]Append[ [[func]Inputs >>]Length ] 693 ]Append[ [[func]Inputs >>]Length ]
654 ]Append[",\n\tCallSpace 32,\n\t"]//TODO: Fill in with calculated callspace value 694 ]Append[",\n\tCallSpace 32,\n\t"]//TODO: Fill in with calculated callspace value
655 ]Append[["l_"]Append[cname]] 695 ]Append[["l_"]Append[cname]]
656 ]Append[")\n\n"] 696 ]Append[")\n\n"]
697 ]Append[param check]
657 ]Append[ [[func]Statements >>]Join[""] ] 698 ]Append[ [[func]Statements >>]Join[""] ]
658 ]Append[[func]Set Outputs] 699 ]Append[[func]Set Outputs]
659 ]Append["EndFunc"] 700 ]Append["EndFunc"]
660 } 701 }
661 }{ 702 }{
741 valtype <- Type Of[value] 782 valtype <- Type Of[value]
742 [("Int32","Whole Number")]Find[valtype] 783 [("Int32","Whole Number")]Find[valtype]
743 { 784 {
744 out <- [text]Append[[[[["\t_const_"]Append[Escape Rhope Name[name]]]Append[" = make_Int32("]]Append[value]]Append[");\n"]] 785 out <- [text]Append[[[[["\t_const_"]Append[Escape Rhope Name[name]]]Append[" = make_Int32("]]Append[value]]Append[");\n"]]
745 }{ 786 }{
746 If[[valtype] = ["Type Literal"]] 787 If[[valtype] = ["Type Instance"]]
747 { 788 {
748 //TODO: Support parametric types 789 //TODO: Support parametric types
749 typeid <- [type reg]Type ID[[value]Name >>] 790 typeid <- [type reg]Type ID[[value]Name >>]
750 out <- [text]Append[[[[["\t_const_"]Append[Escape Rhope Name[name]]]Append[" = make_Blueprint("]]Append[typeid]]Append[");\n"]] 791 out <- [text]Append[[[[["\t_const_"]Append[Escape Rhope Name[name]]]Append[" = make_Blueprint("]]Append[typeid]]Append[");\n"]]
792 }{
793 If[[valtype] = ["Yes No"]]
794 {
795 If[value]
796 {
797 out <- [text]Append[[["\t_const_"]Append[Escape Rhope Name[name]]]Append[" = (object *)val_yes;\n"]]
798 }{
799 out <- [text]Append[[["\t_const_"]Append[Escape Rhope Name[name]]]Append[" = (object *)val_no;\n"]]
800 }
801 }
751 } 802 }
752 } 803 }
753 } 804 }
754 805
755 Text@C Program[program:out] 806 Text@C Program[program:out]
760 #include \"builtin.h\" 811 #include \"builtin.h\"
761 #include \"object.h\" 812 #include \"object.h\"
762 #include \"context.h\" 813 #include \"context.h\"
763 #include \"func.h\" 814 #include \"func.h\"
764 #include \"integer.h\" 815 #include \"integer.h\"
765 #include \"blueprint.h\"\n\n" 816 #include \"blueprint.h\"
817 #include \"bool.h\"\n\n"
766 out <- [[[[[[headers 818 out <- [[[[[[headers
767 ]Append[[[program]Type Registry >>]Type Defs] 819 ]Append[[[program]Type Registry >>]Type Defs]
768 ]Append[Fold[["_Text C Program"]Set Input[2, [program]Type Registry >>], 820 ]Append[Fold[["_Text C Program"]Set Input[2, [program]Type Registry >>],
769 Fold["_Consts C Program", 821 Fold["_Consts C Program",
770 Fold["_Defs C Program", "", [program]Functions >>], 822 Fold["_Defs C Program", "", [program]Functions >>],