comparison src/pseudo.c @ 57:035b95a3690f

Added conditional assembly and macros
author lost
date Mon, 05 Jan 2009 00:01:21 +0000
parents 55260a178667
children d85ba47b1e8f
comparison
equal deleted inserted replaced
56:55260a178667 57:035b95a3690f
73 */ 73 */
74 OPFUNC(pseudo_include) 74 OPFUNC(pseudo_include)
75 { 75 {
76 int v1; 76 int v1;
77 char *fn; 77 char *fn;
78 78
79 // only include files on pass 1 79 // only include files on pass 1
80 // but make sure local include context is right 80 // but make sure local include context is right
81 // for the next line... 81 // for the next line...
82 if (as -> passnum != 1) 82 if (as -> passnum != 1)
83 { 83 {
84 as -> context += 1; 84 as -> context = lwasm_next_context(as);
85 return; 85 return;
86 } 86 }
87 87
88 while (**p && isspace(**p)) 88 while (**p && isspace(**p))
89 (*p)++; 89 (*p)++;
116 fn = lwasm_alloc(v1 + 1); 116 fn = lwasm_alloc(v1 + 1);
117 memcpy(fn, *p, v1); 117 memcpy(fn, *p, v1);
118 fn[v1] = '\0'; 118 fn[v1] = '\0';
119 119
120 // end local label context on include 120 // end local label context on include
121 as -> context += 1; 121 as -> context = lwasm_next_context(as);
122 if (lwasm_read_file(as, fn) < 0) 122 if (lwasm_read_file(as, fn) < 0)
123 { 123 {
124 register_error(as, l, 1, "File include error (%s)", fn); 124 register_error(as, l, 1, "File include error (%s)", fn);
125 } 125 }
126 lwasm_free(fn); 126 lwasm_free(fn);
571 (*p)++; 571 (*p)++;
572 goto fqb_again; 572 goto fqb_again;
573 } 573 }
574 } 574 }
575 575
576 /*
577 // don't need to do anything if we are executing one of these 576 // don't need to do anything if we are executing one of these
578 void pseudo_endc(asmstate_t *as, sourceline_t *cl, char **optr) 577 OPFUNC(pseudo_endc)
579 { 578 {
579 if (as -> skipcond && !(as -> skipmacro))
580 {
581 as -> skipcount -= 1;
582 if (as -> skipcount <= 0)
583 {
584 as -> skipcond = 0;
585 }
586 }
580 return; 587 return;
581 } 588 }
582 589
583 // if "else" executes, we must be going into an "ignore" state 590 // if "else" executes, we must be going into an "ignore" state
584 void pseudo_else(asmstate_t *as, sourceline_t *cl, char **optr) 591 OPFUNC(pseudo_else)
585 { 592 {
593 if (as -> skipmacro)
594 return;
595
596 if (as -> skipcond)
597 {
598 if (as -> skipcount == 1)
599 {
600 as -> skipcount = 0;
601 as -> skipcond = 0;
602 }
603 return;
604 }
605
586 as -> skipcond = 1; 606 as -> skipcond = 1;
587 as -> skipcount = 1; 607 as -> skipcount = 1;
588 } 608 }
589 609
590 void pseudo_ifne(asmstate_t *as, sourceline_t *cl, char **optr) 610 OPFUNC(pseudo_ifne)
591 { 611 {
592 int v1; 612 int v1;
593 int rval; 613 int rval;
594 // printf("ifne %s\n", *optr); 614
595 rval = eval_expr(as, cl, optr, &v1); 615 if (as -> skipcond && !(as -> skipmacro))
616 {
617 as -> skipcount++;
618 return;
619 }
620
621 rval = lwasm_expr_result(as, l, p, EXPR_PASS1CONST, &v1);
596 if (rval < 0) 622 if (rval < 0)
597 { 623 return;
598 errorp1(ERR_BADCOND); 624 if (!v1)
599 } 625 {
600 else 626 as -> skipcond = 1;
601 { 627 as -> skipcount = 1;
602 // printf("Condition value: %d\n", v1); 628 }
603 if (!v1) 629 }
604 { 630
605 // printf("condition no match\n"); 631 OPFUNC(pseudo_ifeq)
606 as -> skipcond = 1; 632 {
607 as -> skipcount = 1; 633 int v1;
608 } 634 int rval;
609 } 635
610 } 636 if (as -> skipcond && !(as -> skipmacro))
611 void pseudo_ifeq(asmstate_t *as, sourceline_t *cl, char **optr) 637 {
612 { 638 as -> skipcount++;
613 int v1; 639 return;
614 int rval; 640 }
615 641
616 rval = eval_expr(as, cl, optr, &v1); 642 rval = lwasm_expr_result(as, l, p, EXPR_PASS1CONST, &v1);
617 if (rval < 0) 643 if (rval < 0)
618 { 644 return;
619 errorp1(ERR_BADCOND); 645 if (v1)
620 } 646 {
621 else 647 as -> skipcond = 1;
622 { 648 as -> skipcount = 1;
623 if (v1) 649 }
624 { 650 }
625 as -> skipcond = 1; 651
626 as -> skipcount = 1; 652 OPFUNC(pseudo_iflt)
627 } 653 {
628 } 654 int v1;
629 } 655 int rval;
630 void pseudo_iflt(asmstate_t *as, sourceline_t *cl, char **optr) 656
631 { 657 if (as -> skipcond && !(as -> skipmacro))
632 int v1; 658 {
633 int rval; 659 as -> skipcount++;
634 660 return;
635 rval = eval_expr(as, cl, optr, &v1); 661 }
662
663 rval = lwasm_expr_result(as, l, p, EXPR_PASS1CONST, &v1);
636 if (rval < 0) 664 if (rval < 0)
637 { 665 return;
638 errorp1(ERR_BADCOND); 666 if (v1 >= 0)
639 } 667 {
640 else 668 as -> skipcond = 1;
641 { 669 as -> skipcount = 1;
642 if (v1 >= 0) 670 }
643 { 671 }
644 as -> skipcond = 1; 672
645 as -> skipcount = 1; 673 OPFUNC(pseudo_ifle)
646 } 674 {
647 } 675 int v1;
648 } 676 int rval;
649 void pseudo_ifle(asmstate_t *as, sourceline_t *cl, char **optr) 677
650 { 678 if (as -> skipcond && !(as -> skipmacro))
651 int v1; 679 {
652 int rval; 680 as -> skipcount++;
653 681 return;
654 rval = eval_expr(as, cl, optr, &v1); 682 }
683
684 rval = lwasm_expr_result(as, l, p, EXPR_PASS1CONST, &v1);
655 if (rval < 0) 685 if (rval < 0)
656 { 686 return;
657 errorp1(ERR_BADCOND); 687 if (v1 > 0)
658 } 688 {
659 else 689 as -> skipcond = 1;
660 { 690 as -> skipcount = 1;
661 if (v1 > 0) 691 }
662 { 692 }
663 as -> skipcond = 1; 693
664 as -> skipcount = 1; 694 OPFUNC(pseudo_ifgt)
665 } 695 {
666 } 696 int v1;
667 } 697 int rval;
668 void pseudo_ifgt(asmstate_t *as, sourceline_t *cl, char **optr) 698
669 { 699 if (as -> skipcond && !(as -> skipmacro))
670 int v1; 700 {
671 int rval; 701 as -> skipcount++;
672 702 return;
673 rval = eval_expr(as, cl, optr, &v1); 703 }
704
705 rval = lwasm_expr_result(as, l, p, EXPR_PASS1CONST, &v1);
674 if (rval < 0) 706 if (rval < 0)
675 { 707 return;
676 errorp1(ERR_BADCOND); 708 if (v1 <= 0)
677 } 709 {
678 else 710 as -> skipcond = 1;
679 { 711 as -> skipcount = 1;
680 if (v1 <= 0) 712 }
681 { 713 }
682 as -> skipcond = 1; 714
683 as -> skipcount = 1; 715 OPFUNC(pseudo_ifge)
684 } 716 {
685 } 717 int v1;
686 } 718 int rval;
687 void pseudo_ifge(asmstate_t *as, sourceline_t *cl, char **optr) 719
688 { 720 if (as -> skipcond && !(as -> skipmacro))
689 int v1; 721 {
690 int rval; 722 as -> skipcount++;
691 723 return;
692 rval = eval_expr(as, cl, optr, &v1); 724 }
725
726 rval = lwasm_expr_result(as, l, p, EXPR_PASS1CONST, &v1);
693 if (rval < 0) 727 if (rval < 0)
694 { 728 return;
695 errorp1(ERR_BADCOND); 729 if (v1 < 0)
696 } 730 {
697 else 731 as -> skipcond = 1;
698 { 732 as -> skipcount = 1;
699 if (v1 < 0) 733 }
700 { 734 }
701 as -> skipcond = 1;
702 as -> skipcount = 1;
703 }
704 }
705 }
706 */
707 735
708 OPFUNC(pseudo_error) 736 OPFUNC(pseudo_error)
709 { 737 {
710 register_error(as, l, 1, "User error: %s", *p); 738 register_error(as, l, 1, "User error: %s", *p);
711 } 739 }