comparison parser_old.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 789a146a48e1
comparison
equal deleted inserted replaced
36:495dddadd058 37:640f541e9116
133 Inputs 133 Inputs
134 Outputs 134 Outputs
135 Line Number 135 Line Number
136 Trees 136 Trees
137 Uses Stores 137 Uses Stores
138 } 138 Input Types
139 139 Output Types
140 New@Parse Worker[name,inputs,outputs,line:out] 140 }
141 { 141
142 out <- [[[[[[Build["Parse Worker"]]Name <<[name]]Inputs <<[inputs]]Outputs <<[outputs]]Line Number <<[line]]Trees <<[New@List[]]]Uses Stores <<[New@List[]] 142 New@Parse Worker[name,inputs,outputs,intypes,outtypes,line:out]
143 {
144 out <- [[[[[[[[Build["Parse Worker"]]Name <<[name]]Inputs <<[inputs]]Outputs <<[outputs]]Line Number <<[line]]Trees <<[New@List[]]]Uses Stores <<[New@List[]]]Input Types <<[intypes]]Output Types <<[outtypes]
143 } 145 }
144 146
145 Blueprint Worker Node 147 Blueprint Worker Node
146 { 148 {
147 Name 149 Name
298 { 300 {
299 Print[["Assignments Add Wires: "]Append[assignment]] 301 Print[["Assignments Add Wires: "]Append[assignment]]
300 { 302 {
301 [[parse worker]Outputs >>]Find[assignment] 303 [[parse worker]Outputs >>]Find[assignment]
302 { 304 {
303 ,output index <- [worker]Add Output[assignment, ~] 305 ,output index <- [worker]Add Typed Output[assignment, ~, [[parse worker]Output Types >>]Index[~]]
304 { 306 {
305 Print[ 307 Print[
306 [[[[[[["Wire: " 308 [[[[[[["Wire: "
307 ]Append[ start index ] 309 ]Append[ start index ]
308 ]Append[","] 310 ]Append[","]
477 479
478 Add to Worker@Named Pipe Node[node,worker,program,parse worker,refs:out node,out worker,out refs] 480 Add to Worker@Named Pipe Node[node,worker,program,parse worker,refs:out node,out worker,out refs]
479 { 481 {
480 [[parse worker]Inputs >>]Find[[node]Name >>] 482 [[parse worker]Inputs >>]Find[[node]Name >>]
481 { 483 {
482 after add <- [worker]Add Input[[node]Name >>, ~] {} 484 after add <- [worker]Add Typed Input[[node]Name >>, ~, [[parse worker]Input Types>>]Index[~]] {}
483 { 485 {
484 Print[["Added input, node:"]Append[~]] 486 Print[["Added input, node:"]Append[~]]
485 assign refs <- Fold[[["Assignment Save Reference"]Set Input[3, parse worker]]Set Input[4, ~], refs, [node]Assignments >>] 487 assign refs <- Fold[[["Assignment Save Reference"]Set Input[3, parse worker]]Set Input[4, ~], refs, [node]Assignments >>]
486 index node <- [node]Index <<[~] 488 index node <- [node]Index <<[~]
487 } 489 }
906 value <- <String@Whole Number[valstring] 908 value <- <String@Whole Number[valstring]
907 } 909 }
908 } 910 }
909 } 911 }
910 912
911 Blueprint Type Literal 913 Parse Params@Type Instance[literal,params,string:out,after]
912 { 914 {
913 Name
914 Params
915 }
916
917 Type Literal[name:out]
918 {
919 Print["Type Literal"]
920 out <- [[Build["Type Literal"]]Name <<[name]]Params <<[()]
921 }
922
923 Parse Params@Type Literal[literal,params,string:out,after]
924 {
925 Print[["Parse Params: "]Append[ [string]Slice[10] ]]
926 plist,after <- Parse List[string,params,()] 915 plist,after <- Parse List[string,params,()]
927 out <- [literal]Params <<[plist] 916 out <- [literal]Params <<[plist]
928 } 917 }
929 918
930 Named Pipe or Literal[string,params:out,after] 919 Named Pipe or Literal[string,params:out,after]
948 afterdelim,raw before,delim,nodelim <- [name]Get Comment DString[delims, params] 937 afterdelim,raw before,delim,nodelim <- [name]Get Comment DString[delims, params]
949 938
950 before <- Trim[raw before, "\r\n\t "] 939 before <- Trim[raw before, "\r\n\t "]
951 If[[delim] = [[params]List Begin >>]] 940 If[[delim] = [[params]List Begin >>]]
952 { 941 {
953 value,after <- [Type Literal[before]]Parse Params[params,afterdelim] 942 value,after <- [Type Instance[before]]Parse Params[params,afterdelim]
954 }{ 943 }{
955 Val[afterdelim] 944 Val[afterdelim]
956 { 945 {
957 after <- [delim]Append[~] 946 after <- [delim]Append[~]
958 } 947 }
1142 }{ 1131 }{
1143 out <- worker 1132 out <- worker
1144 } 1133 }
1145 } 1134 }
1146 1135
1136 Remove Named Pipe Node[element:out]
1137 {
1138 If[[Type Of[element]] = ["Named Pipe Node"]]
1139 {
1140 out <- [element]Name >>
1141 }{
1142 If[[Type Of[element]] = ["Type Instance"]]
1143 {
1144 out <- [element]Params <<[ Map[[element]Params >>, "Remove Named Pipe Node"] ]
1145 }{
1146 out <- element
1147 }
1148 }
1149 }
1150
1151 Parse Param List[text,paramlist,typelist,params:out params,out types]
1152 {
1153 delims <- [[()]Append[[params]List Begin >>]]Append[[params]List Delim >>]
1154 after,param name <-[text]Get DString[delims] {}
1155 {
1156 nextlist <- [paramlist]Append[Trim[~, "\r\n\t "]]
1157 next types <- [typelist]Append[paramtype]
1158 }{
1159 If[[~] = [[params]List Begin >>]]
1160 {
1161 type info,after type <- Parse List[after,params,()]
1162 type <- [type info]Index[0]
1163 {
1164 If[[Type Of[~]] = ["Named Pipe Node"]]
1165 {
1166 before variant <- Type Instance[[type]Name >>]
1167 }{
1168 before variant <- <- [type]Params <<[ Map[[type]Params >>, "Remove Named Pipe Node"] ]
1169 }
1170 variant <- [type info]Index[1]
1171 {
1172 ,warn <- If[[Type Of[~]] = ["Named Pipe Node"]]
1173 {
1174 paramtype,warn <- [before variant]Set Variant[[variant]Name >>]
1175 }
1176 Val[warn]
1177 {
1178 Print[[[["Warning: Invalid variant for type "]Append[[before variant]Name >>]]Append[" on input "]]Append[param name]]
1179 paramtype <- Val[before variant]
1180 }
1181 }{
1182 paramtype <- Val[before variant]
1183 }
1184 }{
1185 paramtype <- Type Instance["Any Type"]
1186 }
1187 [after type]Get DString[","]
1188 {
1189 out params,out types <- Parse Param List[~,nextlist,next types,params]
1190 } {} {} {
1191 out params <- Val[nextlist]
1192 out types <- Val[next types]
1193 }
1194 }{
1195 paramtype <- Type Instance["Any Type"]
1196 out params,out types <- Parse Param List[after,nextlist,next types,params]
1197 }
1198
1199 }{
1200 paramtype <- Type Instance["Any Type"]
1201 out params <- Val[nextlist]
1202 out types <- Val[next types]
1203 }
1204 }
1205
1147 Worker Name[string,params,tree,lines:out] 1206 Worker Name[string,params,tree,lines:out]
1148 { 1207 {
1149 ,whitespace name <- [string]Get Comment DString[[params]Arg Begin >>, params] 1208 ,whitespace name <- [string]Get Comment DString[[params]Arg Begin >>, params]
1150 { 1209 {
1151 worker name <- Trim[whitespace name, "\n\r\t "] 1210 worker name <- Trim[whitespace name, "\n\r\t "]
1211 Print[["Parsing worker: "]Append[worker name]]
1152 in out <- [params]In Out Delim >> 1212 in out <- [params]In Out Delim >>
1153 arg end <- [params]Arg End >> 1213 arg end <- [params]Arg End >>
1154 delims <- [[New@List[]]Append[in out]]Append[arg end] 1214 delims <- [[New@List[]]Append[in out]]Append[arg end]
1155 after <- [~]Get Comment DString[delims, params] {} 1215 after <- [~]Get Comment DString[delims, params] {}
1156 { 1216 {
1160 //if it isn't present, everything in the arglist is an input 1220 //if it isn't present, everything in the arglist is an input
1161 If[[~] = [in out]] 1221 If[[~] = [in out]]
1162 { 1222 {
1163 after arglist <- [after]Get Comment DString[arg end, params] {} 1223 after arglist <- [after]Get Comment DString[arg end, params] {}
1164 { 1224 {
1165 output string <- Trim[~,"\n\r\t "] 1225 outputs,output types <- Parse Param List[~, (), (), params]
1226 { Print["got outputs"] }
1227 { Print["got output types"] }
1166 } 1228 }
1167 }{ 1229 }{
1168 after arglist <- Val[after] 1230 after arglist <- Val[after]
1169 output string <- "" 1231 outputs <- ()
1232 output types <- ()
1170 } 1233 }
1171 inputs <- Map[[arglist]Split[[params]List Delim >>], ["Trim"]Set Input[1,"\n\r\t "]] 1234 inputs,input types <- Parse Param List[arglist, (), (), params]
1172 outputs <- Map[[output string]Split[[params]List Delim >>], ["Trim"]Set Input[1,"\n\r\t "]] 1235 { Print["got inputs"] }
1173 1236 { Print["got input types"] }
1174 New@Parse Worker[worker name, inputs, outputs, 0] 1237
1238 //inputs <- Map[[arglist]Split[[params]List Delim >>], ["Trim"]Set Input[1,"\n\r\t "]]
1239 //outputs <- Map[[output string]Split[[params]List Delim >>], ["Trim"]Set Input[1,"\n\r\t "]]
1240
1241 New@Parse Worker[worker name, inputs, outputs, input types, output types, 0]
1175 { 1242 {
1243 Print["Got parse worker"]
1176 body text, modifiers <- [after arglist]Get Comment DString[[params]Block Begin >>, params] 1244 body text, modifiers <- [after arglist]Get Comment DString[[params]Block Begin >>, params]
1177 modified <- Process Modifiers[~, params, modifiers] 1245 modified <- Process Modifiers[~, params, modifiers]
1178 expression trees, after body <- Worker Body[body text, params, New@List[]] 1246 expression trees, after body <- Worker Body[body text, params, New@List[]]
1179 worker <- [modified]Trees <<[expression trees] 1247 worker <- [modified]Trees <<[expression trees]
1180 new worker dict <- [[tree]Workers >>]Set[worker name, worker] 1248 new worker dict <- [[tree]Workers >>]Set[worker name, worker]