Mercurial > repos > rhope
comparison parser_old.rhope @ 30:914ad38f9b59
Compiler now works for some simple programs
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Mon, 28 Sep 2009 19:42:33 -0400 |
parents | 8b2b3f4a2a58 |
children | 3498713c3dc9 |
comparison
equal
deleted
inserted
replaced
29:3cc5e4a42344 | 30:914ad38f9b59 |
---|---|
1 Import extendlib.rhope | 1 Import nworker.rhope |
2 | |
3 | |
4 | 2 |
5 Blueprint Parser | 3 Blueprint Parser |
6 { | 4 { |
7 Arg Begin | 5 Arg Begin |
8 Arg End | 6 Arg End |
156 New@Worker Node[name,params:out] | 154 New@Worker Node[name,params:out] |
157 { | 155 { |
158 out <- [[[[Build["Worker Node"]]Name <<[name]]Params <<[params]]Assignments <<[New@List[]]]Blocks <<[New@List[]] | 156 out <- [[[[Build["Worker Node"]]Name <<[name]]Params <<[params]]Assignments <<[New@List[]]]Blocks <<[New@List[]] |
159 } | 157 } |
160 | 158 |
161 Add List Helper[inlist,worker,program,key,parse worker,refs:out,worker,refs] | 159 Add List Helper[inlist,worker,program,key,parse worker,refs:out list,out worker,out refs] |
162 { | 160 { |
163 Print[Type Of[inlist]] | |
164 Print["Add List Helper"] | |
165 ,nextworker,nextrefs <- [[inlist]Index[key]]Add to Worker[worker, program, parse worker, refs] | 161 ,nextworker,nextrefs <- [[inlist]Index[key]]Add to Worker[worker, program, parse worker, refs] |
166 { nextlist <- [inlist]Set[key, ~] } | 162 { nextlist <- [inlist]Set[key, ~] } |
167 [inlist]Next[key] | 163 [inlist]Next[key] |
168 { | 164 { |
169 Print["Next!"] | 165 out list,out worker,out refs <- Add List Helper[nextlist, nextworker, program, ~, parse worker, nextrefs] |
170 list,worker,refs <- Add List Helper[nextlist, nextworker, program, ~, parse worker, nextrefs] | 166 }{ |
171 }{ | 167 out list <- Val[nextlist] |
172 Print["Done!"] | 168 out worker <- Val[nextworker] |
173 list <- Val[nextlist] | 169 out refs <- Val[nextrefs] |
174 worker <- Val[nextworker] | 170 } |
175 refs <- Val[nextrefs] | 171 } |
176 } | 172 |
177 } | 173 Add List to Worker[list,worker,program,parse worker,refs:out list,out worker,out refs] |
178 | 174 { |
179 Add List to Worker[list,worker,program,parse worker,refs:list,worker,refs] | |
180 { | |
181 Print["Add List to Worker"] | |
182 Print[Type Of[list]] | |
183 { | |
184 [list]First | 175 [list]First |
185 { | 176 { |
186 list,worker,refs <- Add List Helper[list, worker, program, ~, parse worker, refs] | 177 out list,out worker,out refs <- Add List Helper[list, worker, program, ~, parse worker, refs] |
187 { Print["Done!!"] } | 178 }{ |
188 }{ | 179 out list <- list |
189 list <- list | 180 out worker <- worker |
190 worker <- worker | 181 out refs <- refs |
191 refs <- refs | 182 } |
192 } | 183 } |
193 } | 184 |
194 } | 185 _Add Blocks to Worker[blocks,worker,program,parse worker,key,refs:out blocks,out worker,out refs] |
195 | |
196 _Add Blocks to Worker[blocks,worker,program,parse worker,key,refs:blocks,worker,refs] | |
197 { | 186 { |
198 block, next worker, nextrefs <- Add List to Worker[[blocks]Index[key], worker, program, parse worker, refs] | 187 block, next worker, nextrefs <- Add List to Worker[[blocks]Index[key], worker, program, parse worker, refs] |
199 next blocks <- [blocks]Set[key, block] | 188 next blocks <- [blocks]Set[key, block] |
200 [blocks]Next[key] | 189 [blocks]Next[key] |
201 { | 190 { |
202 blocks,worker,refs <- _Add Blocks to Worker[next blocks, next worker, program, parse worker, ~, nextrefs] | 191 out blocks,out worker,out refs <- _Add Blocks to Worker[next blocks, next worker, program, parse worker, ~, nextrefs] |
203 }{ | 192 }{ |
204 blocks <- Val[next blocks] | 193 out blocks <- Val[next blocks] |
205 worker <- Val[next worker] | 194 out worker <- Val[next worker] |
206 refs <- Val[nextrefs] | 195 out refs <- Val[nextrefs] |
207 } | 196 } |
208 } | 197 } |
209 | 198 |
210 Add Blocks to Worker[blocks,worker,program,parse worker,refs:blocks,worker,refs] | 199 Add Blocks to Worker[blocks,worker,program,parse worker,refs:out blocks,out worker,out refs] |
211 { | 200 { |
201 Print["Add Blocks to Worker"] | |
202 { | |
212 [blocks]First | 203 [blocks]First |
213 { | 204 { |
214 blocks, worker, refs <- _Add Blocks to Worker[blocks, worker, program, parse worker, ~, refs] | 205 out blocks, out worker, out refs <- _Add Blocks to Worker[blocks, worker, program, parse worker, ~, refs] |
215 }{ | 206 }{ |
216 blocks <- blocks | 207 out blocks <- blocks |
217 worker <- worker | 208 out worker <- worker |
218 refs <- refs | 209 out refs <- refs |
219 } | 210 } |
220 } | 211 } |
221 | 212 } |
222 Add to Worker@Worker Node[node,worker,program,parse worker,refs:node,worker,refs] | 213 |
214 Add to Worker@Worker Node[node,worker,program,parse worker,refs:out node,out worker,out refs] | |
223 { | 215 { |
224 [program]Find Worker[[node]Name >>] | 216 [program]Find Worker[[node]Name >>] |
225 { | 217 { |
226 after worker <- [worker]Add Worker Call[~] {} | 218 after worker <- [worker]Add Worker Call[~] {} |
227 { | 219 { |
220 //Print[[[[node]Name >>]Append[" has index "]]Append[~]] | |
228 assignment refs <- Fold[[["Assignment Save Reference"]Set Input[3, parse worker]]Set Input[4, ~], refs, [node]Assignments >>] | 221 assignment refs <- Fold[[["Assignment Save Reference"]Set Input[3, parse worker]]Set Input[4, ~], refs, [node]Assignments >>] |
229 [node]Index <<[~] | 222 [node]Index <<[~] |
230 { | 223 { |
231 params list, params worker, params refs <- Add List to Worker[[~]Params >>, after worker, program, parse worker, assignment refs] | 224 params list, params worker, params refs <- Add List to Worker[[~]Params >>, after worker, program, parse worker, assignment refs] |
232 block list, worker, refs <- Add Blocks to Worker[[~]Blocks >>, params worker, program, parse worker, params refs] | 225 block list, out worker, out refs <- Add Blocks to Worker[[~]Blocks >>, params worker, program, parse worker, params refs] |
233 node <- [[~]Params <<[params list]]Blocks <<[block list] | 226 out node <- [[~]Params <<[params list]]Blocks <<[block list] |
234 } | 227 } |
235 } | 228 } |
236 }{ | 229 }{ |
237 Print[["Error: Could not find a worker named "]Append[[node]Name >>]] | 230 Print[["Error: Could not find a worker named "]Append[[node]Name >>]] |
238 } | 231 } |
239 } | 232 } |
240 | 233 |
241 Add Multi Wire[worker,ref,junk,end index,input num:out] | 234 Add Multi Wire[worker,ref,junk,end index,input num:out] |
242 { | 235 { |
236 Print[ | |
237 [[[[[[["Wire: " | |
238 ]Append[ [ref]Index >> ] | |
239 ]Append[","] | |
240 ]Append[ [ref]Output Number >>] | |
241 ]Append[" to "] | |
242 ]Append[end index] | |
243 ]Append[","] | |
244 ]Append[input num] | |
245 ] | |
243 out <- [worker]Add Wire[[ref]Index >>, [ref]Output Number >>, end index, input num] | 246 out <- [worker]Add Wire[[ref]Index >>, [ref]Output Number >>, end index, input num] |
247 { Print["Wire added"] } | |
244 } | 248 } |
245 | 249 |
246 Add Param Wire[worker,param,input num,end index,blocks,parse worker,assignments:out] | 250 Add Param Wire[worker,param,input num,end index,blocks,parse worker,assignments:out] |
247 { | 251 { |
252 Print[[[["param type: " | |
253 ]Append[Type Of[param]] | |
254 ]Append[", dest index:"] | |
255 ]Append[end index]] | |
256 { | |
248 param worker, start index, output num <- [param]Add Wires[worker, blocks, parse worker, assignments] {} | 257 param worker, start index, output num <- [param]Add Wires[worker, blocks, parse worker, assignments] {} |
249 { | 258 { |
259 Print[ | |
260 [[[[[[["Wire: " | |
261 ]Append[start index ] | |
262 ]Append[","] | |
263 ]Append[output num] | |
264 ]Append[" to "] | |
265 ]Append[end index] | |
266 ]Append[","] | |
267 ]Append[input num] | |
268 ] { | |
250 out <- [param worker]Add Wire[start index, output num, end index, input num] | 269 out <- [param worker]Add Wire[start index, output num, end index, input num] |
270 { Print["wire done, Add Param Wire"] } | |
271 } | |
251 }{}{ | 272 }{}{ |
252 out <- Fold[[["Add Multi Wire"]Set Input[3, end index]]Set Input[4, input num], param worker, ~] | 273 out <- Fold[[["Add Multi Wire"]Set Input[3, end index]]Set Input[4, input num], param worker, ~] |
253 } | 274 } |
275 } | |
254 } | 276 } |
255 | 277 |
256 _Add Block Wire[worker,node,junk,blocks,parse worker,assignments:out] | 278 _Add Block Wire[worker,node,junk,blocks,parse worker,assignments:out] |
257 { | 279 { |
258 out <- [node]Add Wires[worker, blocks, parse worker, assignments] | 280 Print[["_Add Block Wire "]Append[Type Of[node]]] |
281 { | |
282 out <- [node]Add Wires[worker, blocks, parse worker, assignments] | |
283 { Print[["_Add Block Wire done "]Append[Type Of[node]]] } | |
284 } | |
259 } | 285 } |
260 | 286 |
261 Add Block Wire[worker,block nodes,output num,parent index,existing blocks,parse worker,assignments:out] | 287 Add Block Wire[worker,block nodes,output num,parent index,existing blocks,parse worker,assignments:out] |
262 { | 288 { |
289 Print["Add Block Wire"] | |
290 { | |
263 blocks <- [existing blocks]Append[New@Output Reference[parent index, output num]] | 291 blocks <- [existing blocks]Append[New@Output Reference[parent index, output num]] |
264 out <- Fold[[[["_Add Block Wire"]Set Input[3, blocks]]Set Input[4, parse worker]]Set Input[5, assignments], worker, block nodes] | 292 out <- Fold[[[["_Add Block Wire"]Set Input[3, blocks]]Set Input[4, parse worker]]Set Input[5, assignments], worker, block nodes] |
265 } | 293 { Print["done: Add Block Wire"] } |
266 | 294 } |
267 Assignments Add Wires[worker,assignment,output num,parse worker,start index:worker] | 295 } |
268 { | 296 |
297 Assignments Add Wires[worker,assignment,output num,parse worker,start index:out worker] | |
298 { | |
299 Print[["Assignments Add Wires: "]Append[assignment]] | |
300 { | |
269 [[parse worker]Outputs >>]Find[assignment] | 301 [[parse worker]Outputs >>]Find[assignment] |
270 { | 302 { |
271 ,output index <- [worker]Add Output[assignment, ~] | 303 ,output index <- [worker]Add Output[assignment, ~] |
272 { | 304 { |
273 worker <- [~]Add Wire[start index, output num, output index, 0] | 305 Print[ |
306 [[[[[[["Wire: " | |
307 ]Append[ start index ] | |
308 ]Append[","] | |
309 ]Append[ output num] | |
310 ]Append[" to "] | |
311 ]Append[output index] | |
312 ]Append[","] | |
313 ]Append[ 0 ] | |
314 ] | |
315 out worker <- [~]Add Wire[start index, output num, output index, 0] | |
316 { Print["wire done, Assignments Add Wires 1"] } | |
274 } | 317 } |
275 }{ | 318 }{ |
276 //Ugly hack alert! | 319 //Ugly hack alert! |
277 If[[assignment]Contains["::"]] | 320 If[[assignment]Contains["::"]] |
278 { | 321 { |
279 parts <- [assignment]Split["::"] | 322 parts <- [assignment]Split["::"] |
280 ,global index <- [worker]Add Global Set[[parts]Index[0], [parts]Index[1]] | 323 ,global index <- [worker]Add Global Set[[parts]Index[0], [parts]Index[1]] |
281 { | 324 { |
282 worker <- [~]Add Wire[start index, output num, global index, 0] | 325 out worker <- [~]Add Wire[start index, output num, global index, 0] |
326 { Print["wire done, Assignments Add Wires 2"] } | |
283 } | 327 } |
284 }{ | 328 }{ |
285 worker <- worker | 329 Print["Pipe assignment, do nothing"] |
286 } | 330 { out worker <- worker } |
287 } | 331 } |
332 } | |
333 } | |
288 } | 334 } |
289 | 335 |
290 Has Block@Worker Node[junk:out,unused] | 336 Has Block@Worker Node[junk:out,unused] |
291 { | 337 { |
292 out <- Yes | 338 out <- Yes |
317 } | 363 } |
318 } | 364 } |
319 | 365 |
320 Add Wires@Worker Node[node,worker,blocks,parse worker,assignments:worker,index,num,unused] | 366 Add Wires@Worker Node[node,worker,blocks,parse worker,assignments:worker,index,num,unused] |
321 { | 367 { |
368 Print["Add Wires@Worker Node"] | |
369 { | |
322 worker,index,num <- Add Wires Worker or Field[node, worker, blocks, parse worker, assignments] | 370 worker,index,num <- Add Wires Worker or Field[node, worker, blocks, parse worker, assignments] |
371 } | |
323 } | 372 } |
324 | 373 |
325 Add Wires Worker or Field[node,worker,blocks,parse worker,assignments:worker,index,num,unused] | 374 Add Wires Worker or Field[node,worker,blocks,parse worker,assignments:worker,index,num,unused] |
326 { | 375 { |
376 Print["Add Wires Worker or Field"] | |
377 { | |
327 Fold[[["Assignments Add Wires"]Set Input[3, parse worker]]Set Input[4, [node]Index >>], worker, [node]Assignments >>] | 378 Fold[[["Assignments Add Wires"]Set Input[3, parse worker]]Set Input[4, [node]Index >>], worker, [node]Assignments >>] |
328 { Fold[[[[["Add Block Wire"]Set Input[3, [node]Index >>]]Set Input[4, blocks]]Set Input[5, parse worker]]Set Input[6, assignments], ~, [node]Blocks >>] | 379 { |
329 { params worker <- Fold[[[[["Add Param Wire"]Set Input[3, [node]Index >>]]Set Input[4, blocks]]Set Input[5, parse worker]]Set Input[6, assignments], ~, [node]Params >>] }} | 380 Print["Assignments Add Wires done"] |
381 Fold[[[[["Add Block Wire"]Set Input[3, [node]Index >>]]Set Input[4, blocks]]Set Input[5, parse worker]]Set Input[6, assignments], ~, [node]Blocks >>] | |
382 { | |
383 Print["Add Block Wire fold done"] | |
384 params worker <- Fold[[[[["Add Param Wire"]Set Input[3, [node]Index >>]]Set Input[4, blocks]]Set Input[5, parse worker]]Set Input[6, assignments], ~, [node]Params >>] }} | |
330 If[Has Block Params[[node]Params >>]] | 385 If[Has Block Params[[node]Params >>]] |
331 { | 386 { |
332 worker <- Val[params worker] | 387 worker <- Val[params worker] |
333 }{ | 388 }{ |
334 [blocks]Peek | 389 [blocks]Peek |
338 worker <- Val[params worker] | 393 worker <- Val[params worker] |
339 } | 394 } |
340 } | 395 } |
341 index <- [node]Index >> | 396 index <- [node]Index >> |
342 num <- 0 | 397 num <- 0 |
398 } | |
343 } | 399 } |
344 | 400 |
345 Blueprint Field Node | 401 Blueprint Field Node |
346 { | 402 { |
347 Name | 403 Name |
360 New@Field Node[name,params,set:out] | 416 New@Field Node[name,params,set:out] |
361 { | 417 { |
362 out <- [[[[[Build["Field Node"]]Name <<[name]]Assignments <<[New@List[]]]Blocks <<[New@List[]]]Set? <<[set]]Params <<[params] | 418 out <- [[[[[Build["Field Node"]]Name <<[name]]Assignments <<[New@List[]]]Blocks <<[New@List[]]]Set? <<[set]]Params <<[params] |
363 } | 419 } |
364 | 420 |
365 Add to Worker@Field Node[node,worker,program,parse worker,refs:node,worker,refs,unused] | 421 Add to Worker@Field Node[node,worker,program,parse worker,refs:out node,out worker,out refs] |
366 { | 422 { |
367 If[[node]Set? >>] | 423 If[[node]Set? >>] |
368 { | 424 { |
369 after worker,index <- [worker]Add Object Set[[node]Name >>] | 425 after worker,index <- [worker]Add Object Set[[node]Name >>] |
370 }{ | 426 }{ |
371 after worker,index <- [worker]Add Object Get[[node]Name >>] | 427 after worker,index <- [worker]Add Object Get[[node]Name >>] |
372 } | 428 } |
373 index | 429 Val[index] |
374 { | 430 { |
375 assignment refs <- Fold[[["Assignment Save Reference"]Set Input[3, parse worker]]Set Input[4, ~], refs, [node]Assignments >>] | 431 assignment refs <- Fold[[["Assignment Save Reference"]Set Input[3, parse worker]]Set Input[4, ~], refs, [node]Assignments >>] |
376 [node]Index <<[~] | 432 [node]Index <<[~] |
377 { | 433 { |
378 params list, params worker, params refs <- Add List to Worker[[~]Params >>, after worker, program, parse worker, assignment refs] | 434 params list, params worker, params refs <- Add List to Worker[[~]Params >>, after worker, program, parse worker, assignment refs] |
379 block list, worker, refs <- Add Blocks to Worker[[~]Blocks >>, params worker, program, parse worker, params refs] | 435 block list, out worker, out refs <- Add Blocks to Worker[[~]Blocks >>, params worker, program, parse worker, params refs] |
380 node <- [[~]Params <<[params list]]Blocks <<[block list] | 436 out node <- [[~]Params <<[params list]]Blocks <<[block list] |
381 } | 437 } |
382 } | 438 } |
383 } | 439 } |
384 | 440 |
385 Add Wires@Field Node[node,worker,blocks,parse worker,assignments:worker,index,num] | 441 Add Wires@Field Node[node,worker,blocks,parse worker,assignments:worker,index,num] |
386 { | 442 { |
443 Print["Add Wires@Field Node"] | |
444 { | |
387 worker,index,num <- Add Wires Worker or Field[node, worker, blocks, parse worker, assignments] | 445 worker,index,num <- Add Wires Worker or Field[node, worker, blocks, parse worker, assignments] |
446 } | |
388 } | 447 } |
389 | 448 |
390 Blueprint Named Pipe Node | 449 Blueprint Named Pipe Node |
391 { | 450 { |
392 Name | 451 Name |
414 New@Named Pipe Node[name:out] | 473 New@Named Pipe Node[name:out] |
415 { | 474 { |
416 out <- [[[Build["Named Pipe Node"]]Name <<[name]]Assignments <<[New@List[]]]Blocks <<[New@List[]] | 475 out <- [[[Build["Named Pipe Node"]]Name <<[name]]Assignments <<[New@List[]]]Blocks <<[New@List[]] |
417 } | 476 } |
418 | 477 |
419 Add to Worker@Named Pipe Node[node,worker,program,parse worker,refs:node,worker,refs] | 478 Add to Worker@Named Pipe Node[node,worker,program,parse worker,refs:out node,out worker,out refs] |
420 { | 479 { |
421 [[parse worker]Inputs >>]Find[[node]Name >>] | 480 [[parse worker]Inputs >>]Find[[node]Name >>] |
422 { | 481 { |
423 after add <- [worker]Add Input[[node]Name >>, ~] {} | 482 after add <- [worker]Add Input[[node]Name >>, ~] {} |
424 { | 483 { |
484 Print[["Added input, node:"]Append[~]] | |
425 assign refs <- Fold[[["Assignment Save Reference"]Set Input[3, parse worker]]Set Input[4, ~], refs, [node]Assignments >>] | 485 assign refs <- Fold[[["Assignment Save Reference"]Set Input[3, parse worker]]Set Input[4, ~], refs, [node]Assignments >>] |
426 index node <- [node]Index <<[~] | 486 index node <- [node]Index <<[~] |
427 } | 487 } |
428 }{ | 488 }{ |
429 after add <- worker | 489 after add <- worker |
430 index node <- [node]Index <<[[0]-[1]] | 490 index node <- [node]Index <<[[0]-[1]] |
431 //TODO: Handle assignments from a named pipe that isn't an input | 491 //TODO: Handle assignments from a named pipe that isn't an input |
432 assign refs <- refs | 492 assign refs <- refs |
433 } | 493 } |
434 block list, worker, refs <- Add Blocks to Worker[[node]Blocks >>, after add, program, parse worker, assign refs] | 494 block list, out worker, out refs <- Add Blocks to Worker[[node]Blocks >>, after add, program, parse worker, assign refs] |
435 node <- [index node]Blocks <<[block list] | 495 out node <- [index node]Blocks <<[block list] |
436 } | 496 } |
437 | 497 |
438 Add Wires@Named Pipe Node[node,worker,blocks,parse worker,assignments:worker,index,num,unused] | 498 Add Wires@Named Pipe Node[node,worker,blocks,parse worker,assignments:worker,index,num,reflist] |
439 { | 499 { |
500 Print["Add Wires@Named Pipe Node"] | |
501 { | |
440 reflist <- [assignments]Index[[node]Name >>] | 502 reflist <- [assignments]Index[[node]Name >>] |
441 { | 503 { |
442 //TODO: Fix support for a named pipe with a block | 504 //TODO: Fix support for a named pipe with a block |
443 worker <- worker | 505 worker <- worker |
444 }{ | 506 }{ |
468 wires worker <- Val[assignments worker] | 530 wires worker <- Val[assignments worker] |
469 } | 531 } |
470 } | 532 } |
471 } | 533 } |
472 } | 534 } |
473 index <- my index | 535 } |
536 index <- Val[my index] | |
474 | 537 |
475 worker <- Fold[[[[["Add Block Wire"]Set Input[3, my index]]Set Input[4, blocks]]Set Input[5, parse worker]]Set Input[6, assignments], wires worker, [node]Blocks >>] | 538 worker <- Fold[[[[["Add Block Wire"]Set Input[3, my index]]Set Input[4, blocks]]Set Input[5, parse worker]]Set Input[6, assignments], wires worker, [node]Blocks >>] |
476 } | 539 } |
477 | 540 |
478 Blueprint Global Node | 541 Blueprint Global Node |
525 New@Literal Node[value:out] | 588 New@Literal Node[value:out] |
526 { | 589 { |
527 out <- [[[Build["Literal Node"]]Value <<[value]]Assignments <<[New@List[]]]Blocks <<[New@List[]] | 590 out <- [[[Build["Literal Node"]]Value <<[value]]Assignments <<[New@List[]]]Blocks <<[New@List[]] |
528 } | 591 } |
529 | 592 |
530 Add to Worker@Literal Node[node,worker,unused,parse worker,refs:out node,out worker,refs,unused] | 593 Add to Worker@Literal Node[node,worker,unused,parse worker,refs:out node,out worker,out refs] |
531 { | 594 { |
532 out worker <- [worker]Add Constant[[node]Value >>] {} | 595 out worker <- [worker]Add Constant[[node]Value >>] {} |
533 { | 596 { |
534 refs <- Fold[[["Assignment Save Reference"]Set Input[3, parse worker]]Set Input[4, ~], refs, [node]Assignments >>] | 597 out refs <- Fold[[["Assignment Save Reference"]Set Input[3, parse worker]]Set Input[4, ~], refs, [node]Assignments >>] |
535 out node <- [node]Index <<[~] | 598 out node <- [node]Index <<[~] |
536 } | 599 } |
537 } | 600 } |
538 | 601 |
539 Add Wires@Literal Node[node,worker,blocks,parse worker,assignments:worker,index,num,unused] | 602 Add Wires@Literal Node[node,worker,blocks,parse worker,assignments:worker,index,num,unused] |
540 { | 603 { |
604 Print["Add Wires@Literal Node"] | |
605 { | |
541 worker,index,num <- Add Wires Literal or Global[node, worker, blocks, parse worker, assignments] | 606 worker,index,num <- Add Wires Literal or Global[node, worker, blocks, parse worker, assignments] |
607 } | |
542 } | 608 } |
543 | 609 |
544 Add Wires Literal or Global[node,worker,blocks,parse worker,junk:worker,index,num,unused] | 610 Add Wires Literal or Global[node,worker,blocks,parse worker,junk:worker,index,num,unused] |
545 { | 611 { |
612 Print["Add Wires Literal or Global"] | |
613 { | |
546 assignments worker <- Fold[[["Assignments Add Wires"]Set Input[3, parse worker]]Set Input[4, [node]Index >>], worker, [node]Assignments >>] | 614 assignments worker <- Fold[[["Assignments Add Wires"]Set Input[3, parse worker]]Set Input[4, [node]Index >>], worker, [node]Assignments >>] |
615 { Print["Done fold Assignments Add Wires"] } | |
547 [blocks]Peek | 616 [blocks]Peek |
548 { | 617 { |
618 Print["Add wire"] | |
549 worker <- [assignments worker]Add Wire[[~]Index >>, [~]Output Number>>, [node]Index >>, [0]-[1]] | 619 worker <- [assignments worker]Add Wire[[~]Index >>, [~]Output Number>>, [node]Index >>, [0]-[1]] |
620 { Print["Add wire done"] } | |
550 }{ | 621 }{ |
551 worker <- Val[assignments worker] | 622 worker <- Val[assignments worker] |
552 } | 623 } |
553 index <- [node]Index >> | 624 index <- [node]Index >> |
554 num <- 0 | 625 num <- 0 |
626 } | |
555 } | 627 } |
556 | 628 |
557 Blueprint Block Node | 629 Blueprint Block Node |
558 { | 630 { |
559 Number | 631 Number |
1113 }{ | 1185 }{ |
1114 out <- Val[prog] | 1186 out <- Val[prog] |
1115 } | 1187 } |
1116 } | 1188 } |
1117 | 1189 |
1190 Register Workers Compile[prog, worker, name:out] | |
1191 { | |
1192 Print[["Registering "]Append[name]] | |
1193 out <- [prog]Register Worker[name, "cdecl", [[worker]Inputs >>]Length, [[worker]Outputs >>]Length] | |
1194 } | |
1195 | |
1196 Add Workers Compile[prog, worker, name:out] | |
1197 { | |
1198 Print[["Add Workers Compile: "]Append[name]] | |
1199 { | |
1200 trees, nworker, refs <- Add List to Worker[[worker]Trees >>, [NWorker["cdecl"]]Uses[[worker]Uses Stores >>], prog, worker, New@Dictionary[]] | |
1201 final nworker <- Fold[[["Add Wires Helper"]Set Input[3, worker]]Set Input[4, refs], nworker, trees] | |
1202 out <- [prog]Bind Worker[name, final nworker] | |
1203 } | |
1204 } | |
1205 | |
1118 Add Wires Helper[worker,node,unused,parse worker,assignments:out] | 1206 Add Wires Helper[worker,node,unused,parse worker,assignments:out] |
1119 { | 1207 { |
1208 Print["Add Wires Helper"] | |
1209 { | |
1120 out <- [node]Add Wires[worker, New@List[], parse worker, assignments] | 1210 out <- [node]Add Wires[worker, New@List[], parse worker, assignments] |
1211 { Print["Add Wires Helper Done"] } | |
1212 } | |
1121 } | 1213 } |
1122 | 1214 |
1123 Add Contents[parse worker,name,program:out,key] | 1215 Add Contents[parse worker,name,program:out,key] |
1124 { | 1216 { |
1217 Print[["Add Contents: "]Append[name]] | |
1125 worker <- [[program]Find Worker[name]]Uses[[parse worker]Uses Stores >>] | 1218 worker <- [[program]Find Worker[name]]Uses[[parse worker]Uses Stores >>] |
1126 trees, contents worker, refs <- Add List to Worker[[parse worker]Trees >>, worker, program, parse worker, New@Dictionary[]] | 1219 trees, contents worker, refs <- Add List to Worker[[parse worker]Trees >>, worker, program, parse worker, New@Dictionary[]] |
1127 Fold[[["Add Wires Helper"]Set Input[3, parse worker]]Set Input[4, refs], contents worker, trees] | 1220 Fold[[["Add Wires Helper"]Set Input[3, parse worker]]Set Input[4, refs], contents worker, trees] |
1128 out <- [parse worker]Trees <<[trees] | 1221 out <- [parse worker]Trees <<[trees] |
1129 key <- name | 1222 key <- name |
1161 Tree to Program[parse tree:out] | 1254 Tree to Program[parse tree:out] |
1162 { | 1255 { |
1163 Print["Tree to Program"] | 1256 Print["Tree to Program"] |
1164 out <- _Tree to Program[parse tree, [New@Program[]]Add Builtins] | 1257 out <- _Tree to Program[parse tree, [New@Program[]]Add Builtins] |
1165 { Print["done"] } | 1258 { Print["done"] } |
1259 } | |
1260 | |
1261 Tree to Program Native[parse tree:out] | |
1262 { | |
1263 registered <- Fold["Register Workers Compile", [NProgram[]]Register Builtins, [parse tree]Workers >>] | |
1264 out <- Fold["Add Workers Compile", registered, [parse tree]Workers >>] | |
1166 } | 1265 } |
1167 | 1266 |
1168 Needs Imports[needs import,not imported?,name:out] | 1267 Needs Imports[needs import,not imported?,name:out] |
1169 { | 1268 { |
1170 If[not imported?] | 1269 If[not imported?] |
1329 } | 1428 } |
1330 | 1429 |
1331 | 1430 |
1332 Main[args] | 1431 Main[args] |
1333 { | 1432 { |
1334 [args]Index[1] | 1433 Print["start"] |
1434 fname <- [args]Index[1] | |
1335 { | 1435 { |
1336 file <- <String@File[~] | 1436 file <- <String@File[~] |
1337 ,text <- [file]Get FString[[file]Length] | 1437 ,text <- [file]Get FString[[file]Length] |
1338 params <- New@Parser[] | 1438 params <- New@Parser[] |
1439 Print[["Parsing "]Append[fname]] | |
1339 Null[text, params, New@Parse Program[], 0] | 1440 Null[text, params, New@Parse Program[], 0] |
1340 { | 1441 { |
1442 Print["Parsing imports"] | |
1341 tree <- Process Imports[~, params] | 1443 tree <- Process Imports[~, params] |
1342 Init Used Stores[tree, New@Dictionary[]] | 1444 { Print["Compiling"] } |
1343 { [Tree to Program[tree]]Run[[args]Tail[1]] } | 1445 compiled <- [Tree to Program Native[tree]]Compile Program[C Program[]] |
1446 outfile <- <String@File[ [fname]Append[".c"] ] | |
1447 [outfile]Put String[ [compiled]Text ] | |
1448 { Print[["Wrote output to "]Append[ [fname]Append[".c"] ]] } | |
1344 } | 1449 } |
1345 }{ | 1450 }{ |
1346 REPL[New@Parser[]] | 1451 REPL[New@Parser[]] |
1347 } | 1452 } |
1348 } | 1453 } |