Mercurial > repos > rhope
comparison cbackend.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 | a24eb366195c |
comparison
equal
deleted
inserted
replaced
41:1b86a1ee500a | 42:aabda74c7a88 |
---|---|
228 out <- [[[[text]Append[type]]Append[" "]]Append[[Escape Rhope Name[name]]Append[postfix]]]Append[";"] | 228 out <- [[[[text]Append[type]]Append[" "]]Append[[Escape Rhope Name[name]]Append[postfix]]]Append[";"] |
229 } | 229 } |
230 | 230 |
231 Type Def@C Type[ctype:out] | 231 Type Def@C Type[ctype:out] |
232 { | 232 { |
233 out <- [Fold["_Type Def C Type", "OBegin", [ctype]Fields >>]]Append[ [["\nObject("]Append[Escape Rhope Name[[ctype]Name >>]]]Append[")"] ] | 233 If[[[[ctype]Fields >>]Length] = [1]] |
234 { | |
235 out <- [[[_Type Def C Type["typedef struct {\n\tobject _SP_header;\n\t", [[ctype]Fields >>]Index[0]]]Append["\n} t_"]]Append[[ctype]Name >>]]Append[";"] | |
236 }{ | |
237 out <- [Fold["_Type Def C Type", "OBegin", [ctype]Fields >>]]Append[ [["\nObject("]Append[Escape Rhope Name[[ctype]Name >>]]]Append[")"] ] | |
238 } | |
234 } | 239 } |
235 | 240 |
236 _Type Init C[type name,method reg,text,method:out] | 241 _Type Init C[type name,method reg,text,method:out] |
237 { | 242 { |
238 out <- [[text]Append[[["\n\tadd_method(bp, "]Append[ [method reg]Method ID[method] ]]Append[ [[", MethodName("]Append[Escape Rhope Name[method]]]Append[[","]Append[Escape Rhope Name[type name]]]]]]Append["));"] | 243 out <- [[text]Append[[["\n\tadd_method(bp, "]Append[ [method reg]Method ID[method] ]]Append[ [[", MethodName("]Append[Escape Rhope Name[method]]]Append[[","]Append[Escape Rhope Name[type name]]]]]]Append["));"] |
332 Type ID@C Type Registry[reg,name:out,notfound] | 337 Type ID@C Type Registry[reg,name:out,notfound] |
333 { | 338 { |
334 out,notfound <- [[reg]Lookup >>]Index[name] | 339 out,notfound <- [[reg]Lookup >>]Index[name] |
335 } | 340 } |
336 | 341 |
342 Simple Type?@C Type Registry[reg,name:yep,nope,notfound] | |
343 { | |
344 Print[["Symple Type?: "]Append[name]] | |
345 ,notfound <- [[reg]Definitions >>]Index[name] | |
346 { | |
347 Print["found type"] | |
348 yep,nope <- If[[[[~]Fields >>]Length] = [1]] | |
349 } | |
350 } | |
351 | |
337 Blueprint C Function | 352 Blueprint C Function |
338 { | 353 { |
339 Name | 354 Name |
340 Inputs | 355 Inputs |
341 Outputs | 356 Outputs |
350 Output Types | 365 Output Types |
351 } | 366 } |
352 | 367 |
353 C Function[name,inputs,outputs,convention:out] | 368 C Function[name,inputs,outputs,convention:out] |
354 { | 369 { |
355 out <- C Function With Registry[name,inputs,outputs,convention, C Method Registry[], C Field Registry[]] | 370 out <- C Function With Registry[name,inputs,outputs,convention, C Method Registry[], C Field Registry[], C Type Registry[]] |
356 } | 371 } |
357 | 372 |
358 C Function With Registry[name,inputs,outputs,convention,registry,field reg:out] | 373 C Function With Registry[name,inputs,outputs,convention,registry,field reg,type reg:out] |
359 { | 374 { |
360 out <- [[[[[[[[[[[[Build["C Function"] | 375 out <- [[[[[[[[[[[[Build["C Function"] |
361 ]Name <<[name] | 376 ]Name <<[name] |
362 ]Inputs <<[inputs] | 377 ]Inputs <<[inputs] |
363 ]Outputs <<[outputs] | 378 ]Outputs <<[outputs] |
364 ]Convention <<[convention] | 379 ]Convention <<[convention] |
365 ]Variables <<[New@Dictionary[]] | 380 ]Variables <<[New@Dictionary[]] |
366 ]Statements <<[()] | 381 ]Statements <<[()] |
367 ]Method Registry <<[registry] | 382 ]Method Registry <<[registry] |
368 ]Field Registry <<[field reg] | 383 ]Field Registry <<[field reg] |
369 ]Type Registry <<[C Type Registry[]] | 384 ]Type Registry <<[type reg] |
370 ]Constants <<[New@Dictionary[]] | 385 ]Constants <<[New@Dictionary[]] |
371 ]Input Types <<[ Fold[["Append"]Set Input[1, "Any Type"], (), inputs] ] | 386 ]Input Types <<[ Fold[["Append"]Set Input[1, "Any Type"], (), inputs] ] |
372 ]Output Types <<[ Fold[["Append"]Set Input[1, "Any Type"], (), outputs] ] | 387 ]Output Types <<[ Fold[["Append"]Set Input[1, "Any Type"], (), outputs] ] |
373 } | 388 } |
374 | 389 |
473 } | 488 } |
474 | 489 |
475 Field Result@C Function[func,var,field:out] | 490 Field Result@C Function[func,var,field:out] |
476 { | 491 { |
477 as op <- [var]Make Op[func] | 492 as op <- [var]Make Op[func] |
478 If[[[Type Of[var]] = ["String"]] And[ [[func]Convention >>] = ["rhope"]] ] | 493 If[[Type Of[var]] = ["String"]] |
479 { | 494 { |
480 [[func]Inputs >>]Find[var] | 495 [[func]Inputs >>]Find[var] |
481 { | 496 { |
482 type <- [[func]Input Types >>]Index[~] | 497 type <- [[func]Input Types >>]Index[~] |
483 If[[type] = ["Any Type"]] | 498 }{ |
484 { | 499 type <- [[func]Variables >>]Index[var] {} |
485 rvar <- Val[as op] | 500 { |
486 }{ | 501 //Does it make sense for us to do this? |
487 rvar <- [[[["(("]Append[ Rhope Type to C[type] ]]Append[")("]]Append[as op]]Append["))"] | 502 type <- Type Instance["Any Type"] |
488 } | 503 } |
504 } | |
505 }{ | |
506 type <- Type Instance["Any Type"] | |
507 } | |
508 If[[[func]Convention >>] = ["rhope"]] | |
509 { | |
510 If[[type] = ["Any Type"]] | |
511 { | |
512 rvar <- Val[as op] | |
489 }{ | 513 }{ |
490 rvar <- Val[as op] | 514 rvar <- [[[["(("]Append[ Rhope Type to C[type] ]]Append[")("]]Append[as op]]Append["))"] |
491 } | 515 } |
492 }{ | 516 }{ |
493 rvar <- Val[as op] | 517 rvar <- Val[as op] |
494 } | 518 } |
495 out <- [[rvar]Append["->"]]Append[Escape Rhope Name[field]] | 519 |
520 [[func]Type Registry >>]Simple Type?[[type]Name >>] | |
521 { access <- "->" } | |
522 { access <- "->payload." } | |
523 out <- [[rvar]Append[access]]Append[Escape Rhope Name[field]] | |
496 } | 524 } |
497 | 525 |
498 Read Field@C Function[func,var,field:out,result op] | 526 Read Field@C Function[func,var,field:out,result op] |
499 { | 527 { |
500 out <- func | 528 out <- func |
507 result op <- Field Ref[var,field] | 535 result op <- Field Ref[var,field] |
508 } | 536 } |
509 | 537 |
510 Set Field Null@C Function[func,var,field:out] | 538 Set Field Null@C Function[func,var,field:out] |
511 { | 539 { |
540 Print["Set Field Null"] | |
512 out <- [func]Add Statement[ [[func]Field Result[var,field]]Append[" = NULL"] ] | 541 out <- [func]Add Statement[ [[func]Field Result[var,field]]Append[" = NULL"] ] |
513 } | 542 } |
514 | 543 |
515 Copy@C Function[func,pdest:out] | 544 Copy@C Function[func,pdest:out] |
516 { | 545 { |
517 dest <- [pdest]Make Op[func] | 546 dest <- [pdest]Make Op[func] |
518 out <- [func]Add Statement[ [dest]Append[[[" = copy_object("]Append[dest]]Append[")"]] ] | 547 out <- [func]Add Statement[ [dest]Append[[[" = copy_object("]Append[dest]]Append[")"]] ] |
519 } | 548 } |
520 | 549 |
521 Box@C Function[func,pdest,psource,type:out] | 550 Box@C Function[func,psource,pdest,type:out] |
522 { | 551 { |
523 dest <- [pdest]Make Op[func] | 552 dest <- [pdest]Make Op[func] |
524 source <- [psource]Make Op[func] | 553 source <- [psource]Make Op[func] |
525 out <- [func]Add Statement[ | 554 out <- [func]Add Statement[ |
526 [[[[[dest | 555 [[[[[dest |
529 ]Append[", &"] | 558 ]Append[", &"] |
530 ]Append[source] | 559 ]Append[source] |
531 ]Append[")"] ] | 560 ]Append[")"] ] |
532 } | 561 } |
533 | 562 |
534 Unbox@C Function[func,pdest,psource:out] | 563 Unbox@C Function[func,psource,pdest:out] |
535 { | 564 { |
536 dest <- [pdest]Make Op[func] | 565 dest <- [pdest]Make Op[func] |
537 source <- [psource]Make Op[func] | 566 source <- [psource]Make Op[func] |
538 out <- [func]Add Statement[ | 567 out <- [func]Add Statement[ |
539 [[[["boxed_to_naked(" | 568 [[[["boxed_to_naked(" |
667 } | 696 } |
668 } | 697 } |
669 } | 698 } |
670 _Output Defs C[string,varname,index,func:out] | 699 _Output Defs C[string,varname,index,func:out] |
671 { | 700 { |
672 out <- [[[string]Append[ ["\t"]Append[Rhope Type to C[[[func]Output Types >>]Index[index]]] ]]Append[Escape Rhope Name[varname]]]Append[";\n"] | 701 out <- [[[string]Append[ ["\t"]Append[Rhope Type to C[[[func]Output Types >>]Index[index]]] ]]Append[[" "]Append[Escape Rhope Name[varname]]]]Append[";\n"] |
673 } | 702 } |
674 _Var Defs C[string,type,varname:out] | 703 _Var Defs C[string,type,varname:out] |
675 { | 704 { |
676 out <- [[[string]Append[ ["\t"]Append[Rhope Type to C[type]] ]]Append[Escape Rhope Name[varname]]]Append[";\n"] | 705 out <- [[[string]Append[ ["\t"]Append[Rhope Type to C[type]] ]]Append[[" "]Append[Escape Rhope Name[varname]]]]Append[";\n"] |
677 } | 706 } |
678 | 707 |
679 | 708 |
680 Definitions@C Function[func:out] | 709 Definitions@C Function[func:out] |
681 { | 710 { |
705 out <- [localtype]Append[proto] | 734 out <- [localtype]Append[proto] |
706 } | 735 } |
707 | 736 |
708 _Proto Input[list,input,index,types:out] | 737 _Proto Input[list,input,index,types:out] |
709 { | 738 { |
710 Print[["_Proto Input: "]Append[input]] | |
711 { Print[[types]Index[index]] } | |
712 out <- [list]Append[ [[Rhope Type to C[[types]Index[index]]]Append[" "]]Append[Escape Rhope Name[input]] ] | 739 out <- [list]Append[ [[Rhope Type to C[[types]Index[index]]]Append[" "]]Append[Escape Rhope Name[input]] ] |
713 { Pretty Print[~, ""] } | |
714 } | 740 } |
715 | 741 |
716 Naked Proto@C Function[func:out] | 742 Naked Proto@C Function[func:out] |
717 { | 743 { |
718 Print[["Naked Proto: "]Append[ [func]Name >>] ] | 744 Print[["Naked Proto: "]Append[ [func]Name >>] ] |
821 out <- C Type[name] | 847 out <- C Type[name] |
822 } | 848 } |
823 | 849 |
824 Create Function@C Program[program,name,inputs,outputs,convention:out] | 850 Create Function@C Program[program,name,inputs,outputs,convention:out] |
825 { | 851 { |
826 out <- C Function With Registry[name,inputs,outputs,convention, [program]Method Registry >>, [program]Field Registry >>] | 852 out <- C Function With Registry[name,inputs,outputs,convention, [program]Method Registry >>, [program]Field Registry >>, [program]Type Registry >>] |
827 } | 853 } |
828 | 854 |
829 Store Function@C Program[program,func:out] | 855 Store Function@C Program[program,func:out] |
830 { | 856 { |
831 out <- [program]Functions <<[ [[program]Functions >>]Set[ [func]Name >>, func] ] | 857 out <- [program]Functions <<[ [[program]Functions >>]Set[ [func]Name >>, func] ] |