Mercurial > repos > rhope
comparison cbackend.rhope @ 65:1db811fa4744
Handle native Rhope functions and plain C functions separately as part of move to new C strategy
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Tue, 01 Jun 2010 01:13:54 -0400 |
parents | e1fd6d244f14 |
children | d4b44ae2e34a |
comparison
equal
deleted
inserted
replaced
64:e1fd6d244f14 | 65:1db811fa4744 |
---|---|
869 localtype <- "" | 869 localtype <- "" |
870 } | 870 } |
871 | 871 |
872 If[ [[func]Convention >>] = ["rhope"] ] | 872 If[ [[func]Convention >>] = ["rhope"] ] |
873 { | 873 { |
874 parts <- [[func]Name >>]Split["@"] | 874 /* parts <- [[func]Name >>]Split["@"] |
875 [parts]Index[1] | 875 [parts]Index[1] |
876 { | 876 { |
877 proto <- [[[["MethodDef(" | 877 proto <- [[[["MethodDef(" |
878 ]Append[Escape Rhope Name[[parts]Index[0]]] | 878 ]Append[Escape Rhope Name[[parts]Index[0]]] |
879 ]Append[", "] | 879 ]Append[", "] |
880 ]Append[Escape Rhope Name[~]] | 880 ]Append[Escape Rhope Name[~]] |
881 ]Append[")\n"] | 881 ]Append[")\n"] |
882 }{ | 882 }{ |
883 proto <- [["FuncDef("]Append[Escape Rhope Name[[func]Name >>]]]Append[")\n"] | 883 proto <- [["FuncDef("]Append[Escape Rhope Name[[func]Name >>]]]Append[")\n"] |
884 } | 884 } */ |
885 }{ | 885 out <- Val[localtype] |
886 proto <- [[func]Naked Proto]Append[";\n"] | 886 }{ |
887 } | 887 out <- [[func]Naked Proto]Append[";\n"] |
888 out <- [localtype]Append[proto] | 888 } |
889 } | 889 } |
890 } | 890 } |
891 | 891 |
892 _Proto Input[list,input,index,types:out] | 892 _Proto Input[list,input,index,types:out] |
893 { | 893 { |
940 Text@C Function[func:out] | 940 Text@C Function[func:out] |
941 { | 941 { |
942 Print[["Text@C Function: "]Append[[func]Name >>]] | 942 Print[["Text@C Function: "]Append[[func]Name >>]] |
943 If[ [[func]Convention >>] = ["rhope"] ] | 943 If[ [[func]Convention >>] = ["rhope"] ] |
944 { | 944 { |
945 cname <- Escape Rhope Name[[func]Name >>] | 945 ,before <- [[func]Name >>]Get DString["@"] |
946 { | |
947 type <- "MethodImpl" | |
948 cname <- [[[[Escape Rhope Name[before] | |
949 ]Append[", "] | |
950 ]Append[Escape Rhope Name[~]] | |
951 ]Append[", "] | |
952 ]Append[ [[func]Type Registry >>]Type ID[~] ] | |
953 }{}{}{ | |
954 type <- "Func" | |
955 cname <- Val[fname] | |
956 } | |
957 fname <- Escape Rhope Name[[func]Name >>] | |
946 param check <- Fold[["Check Param Type C"]Set Input[3, func], "", [func]Input Types >>] | 958 param check <- Fold[["Check Param Type C"]Set Input[3, func], "", [func]Input Types >>] |
947 If[ [ [[[func]Variables >>]Length]+[[[func]Outputs >>]Length] ] = [0] ] | 959 If[ [ [[[func]Variables >>]Length]+[[[func]Outputs >>]Length] ] = [0] ] |
948 { | 960 { |
949 out <- [[[[[[["FuncNoLocals(" | 961 out <- [[[[[[[ [type]Append["NoLocals("] |
950 ]Append[cname] | 962 ]Append[cname] |
951 ]Append[",\n\tNumParams "] | 963 ]Append[",\n\tNumParams "] |
952 ]Append[ [[func]Inputs >>]Length ] | 964 ]Append[ [[func]Inputs >>]Length ] |
953 ]Append[",\n\tCallSpace 32)\n\n"]//TODO: Fill in with calculated callspace value | 965 ]Append[")\n\n"] |
954 ]Append[param check] | 966 ]Append[param check] |
955 ]Append[ [[func]Statements >>]Join[""] ] | 967 ]Append[ [[func]Statements >>]Join[""] ] |
956 ]Append["EndFunc"] | 968 ]Append["EndFuncNoLocals"] |
957 }{ | 969 }{ |
958 out <- [[[[[[[[[["Func(" | 970 out <- [[[[[[[[ [type]Append["("] |
959 ]Append[cname] | 971 ]Append[cname] |
960 ]Append[",\n\tNumParams "] | 972 ]Append[",\n\tNumParams "] |
961 ]Append[ [[func]Inputs >>]Length ] | 973 ]Append[ [[func]Inputs >>]Length ] |
962 ]Append[",\n\tCallSpace 32,\n\t"]//TODO: Fill in with calculated callspace value | |
963 ]Append[["l_"]Append[cname]] | |
964 ]Append[")\n\n"] | 974 ]Append[")\n\n"] |
965 ]Append[param check] | 975 ]Append[param check] |
966 ]Append[ [[func]Statements >>]Join[""] ] | 976 ]Append[ [[func]Statements >>]Join[""] ] |
967 ]Append[[func]Set Outputs] | 977 ]Append[[func]Set Outputs] |
968 ]Append["EndFunc"] | 978 ]Append[[["EndFunc("]Append[fname]]Append[")"]] |
969 } | 979 } |
970 }{ | 980 }{ |
971 | 981 |
972 out <- [[[ | 982 out <- [[[ |
973 Fold[["_Output Defs C"]Set Input[3, func], | 983 Fold[["_Output Defs C"]Set Input[3, func], |
1127 ]Append[";\\\n"] | 1137 ]Append[";\\\n"] |
1128 } | 1138 } |
1129 | 1139 |
1130 _Dispatch Switch[text,func,raw name:out] | 1140 _Dispatch Switch[text,func,raw name:out] |
1131 { | 1141 { |
1132 name <- Escape Rhope Name[raw name] | 1142 If[[[func]Convention >>] = ["rhope"]] |
1133 out <- [[text]Append[ [[[["\tcase FUNC_"]Append[name]]Append[": goto f_"]]Append[name]]Append[";\\\n"] ] | 1143 { |
1134 ]Append[Fold[["_Dispatch Switch Sub"]Set Input[2, name], "", Range[1, [func]Resume Index >>]]] | 1144 name <- Escape Rhope Name[raw name] |
1145 out <- [[text]Append[ [[[["\tcase FUNC_"]Append[name]]Append[": goto f_"]]Append[name]]Append[";\\\n"] ] | |
1146 ]Append[Fold[["_Dispatch Switch Sub"]Set Input[2, name], "", Range[1, [func]Resume Index >>]]] | |
1147 }{ | |
1148 out <- text | |
1149 } | |
1135 } | 1150 } |
1136 | 1151 |
1137 _Dispatch Enum Sub[text, num, name:out] | 1152 _Dispatch Enum Sub[text, num, name:out] |
1138 { | 1153 { |
1139 out <- [[[[[text | 1154 out <- [[[[[text |
1144 ]Append[",\n"] | 1159 ]Append[",\n"] |
1145 } | 1160 } |
1146 | 1161 |
1147 _Dispatch Enum[text,func,raw name:out] | 1162 _Dispatch Enum[text,func,raw name:out] |
1148 { | 1163 { |
1149 name <- Escape Rhope Name[raw name] | 1164 If[[[func]Convention >>] = ["rhope"]] |
1150 out <- [[text]Append[ [["\tFUNC_"]Append[name]]Append[",\n"] ] | 1165 { |
1151 ]Append[Fold[["_Dispatch Enum Sub"]Set Input[2, name], "", Range[1, [func]Resume Index >>]]] | 1166 name <- Escape Rhope Name[raw name] |
1167 out <- [[text]Append[ [["\tFUNC_"]Append[name]]Append[",\n"] ] | |
1168 ]Append[Fold[["_Dispatch Enum Sub"]Set Input[2, name], "", Range[1, [func]Resume Index >>]]] | |
1169 }{ | |
1170 out <- text | |
1171 } | |
1152 } | 1172 } |
1153 | 1173 |
1154 Dispatch@C Program[program:out] | 1174 Dispatch@C Program[program:out] |
1155 { | 1175 { |
1156 out <- [[[[["typedef enum {\n" | 1176 out <- [[[[["typedef enum {\n" |
1157 ]Append[Fold["_Dispatch Enum", "", [program]Functions >>]] | 1177 ]Append[Fold["_Dispatch Enum", "", [program]Functions >>]] |
1158 ]Append["\tEND\n} funcids;\n\n"] | 1178 ]Append["\tEND\n} funcids;\n\n"] |
1159 ]Append["#define DISPATCH switch(func) { \\\n"] | 1179 ]Append["#define DISPATCH switch(func) { \\\n"] |
1160 ]Append[Fold["_Dispatch Switch", "", [program]Functions >>]] | 1180 ]Append[Fold["_Dispatch Switch", "", [program]Functions >>]] |
1161 ]Append["\tcase END: goto DO_END;\\\n}\n\n"] | 1181 ]Append["\tcase END: goto DO_END;\\\n}\n\n"] |
1182 } | |
1183 | |
1184 Not Native[func:out] | |
1185 { | |
1186 If[[[func]Convention >>] = ["rhope"]] | |
1187 { out <- No } | |
1188 { out <- Yes } | |
1189 } | |
1190 | |
1191 Native[func:out] | |
1192 { | |
1193 out <- [[func]Convention >>] = ["rhope"] | |
1162 } | 1194 } |
1163 | 1195 |
1164 Text@C Program[program:out] | 1196 Text@C Program[program:out] |
1165 { | 1197 { |
1166 Print["Text@C Program"] | 1198 Print["Text@C Program"] |
1172 #include \"func.h\" | 1204 #include \"func.h\" |
1173 #include \"integer.h\" | 1205 #include \"integer.h\" |
1174 #include \"blueprint.h\" | 1206 #include \"blueprint.h\" |
1175 #include \"array.h\" | 1207 #include \"array.h\" |
1176 #include \"bool.h\"\n\n" | 1208 #include \"bool.h\"\n\n" |
1177 out <- [[[[[[[[headers | 1209 out <- [[[[[[[[[[[headers |
1178 ]Append[[program]Dispatch] | 1210 ]Append[[program]Dispatch] |
1179 ]Append[[[program]Type Registry >>]Type Defs] | 1211 ]Append[[[program]Type Registry >>]Type Defs] |
1180 ]Append[Fold[["_Text C Program"]Set Input[2, [program]Type Registry >>], | 1212 ]Append[Fold["_Consts C Program", |
1181 Fold["_Consts C Program", | |
1182 Fold["_Defs C Program", "", [program]Functions >>], | 1213 Fold["_Defs C Program", "", [program]Functions >>], |
1183 constants | 1214 constants]] |
1184 ], [program]Functions >>]] | 1215 ]Append[Fold[["_Text C Program"]Set Input[2, [program]Type Registry >>], "", Filter[[program]Functions >>, "Not Native"]]] |
1216 ]Append["\n | |
1217 void rhope(uint32_t func) | |
1218 { | |
1219 uint16_t resume,idx; | |
1220 context * ct; | |
1221 calldata * cdata, *temp_cdata;"] | |
1222 ]Append[Fold[["_Text C Program"]Set Input[2, [program]Type Registry >>], "", Filter[[program]Functions >>, "Native"]]] | |
1185 ]Append["\n\nint main(int argc, char **argv) | 1223 ]Append["\n\nint main(int argc, char **argv) |
1186 { | 1224 { |
1187 register_builtin_types();\n\n"] | 1225 register_builtin_types();\n\n"] |
1188 ]Append[ [[program]Type Registry >>]Type Inits[[program]Method Registry >>, [program]Field Registry >>] ] | 1226 ]Append[ [[program]Type Registry >>]Type Inits[[program]Method Registry >>, [program]Field Registry >>] ] |
1189 ]Append[Fold[["_Set Consts C Program"]Set Input[3, [program]Type Registry >>], "", constants]] | 1227 ]Append[Fold[["_Set Consts C Program"]Set Input[3, [program]Type Registry >>], "", constants]] |