home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Interactive Guide / c-cplusplus-interactive-guide.iso / c_ref / csource3 / 156_01 / c80v_2.c < prev    next >
Text File  |  1985-08-21  |  31KB  |  1,383 lines

  1. /*    >>>>>>> start of cc5 <<<<<<<    */
  2. /*
  3.     history...
  4.         14 Jul 84  When profiling, not generating ':'
  5.     after label equated to zero.
  6.         27 Jun 84  No longer generating ENDDATA label
  7.     at end of program (duty taken over by ZLINK).
  8.         25 Jun 84  When profiling, the equate has
  9.     the ZMAC syntax. '\l' added.
  10.         10 Oct 83  Converted DB, DW, and DS to DEFB,
  11.     DEFW, and DEFS.  Added colon after ENDDATA.
  12.         1 Sept 83  calling nl() before outputting
  13.     call to ccalls().
  14.         26 Aug 83  added code to link call counts
  15.     (header, trailer)
  16.         29 Jun 83  addim() now calls outasm
  17.     rather than ot to print the literal.
  18.         7 Mar 83  prefix "&" no longer accepts function
  19.     name.
  20.         1 Feb 83  Declaring "enddata" at the end
  21.     of the allocated memory (=top of heap).
  22.         29 Jan 83  prefix "&" can return address of
  23.     function.
  24.         27 Oct 82  Generating no extra nl() after
  25.     "dstore", updating Zsp in same routines that generate
  26.     calls to floating point routines.
  27.         23 Oct 82  rewrote value-returning expr
  28.     in "fnumber".
  29.         10 Oct 82  Corrected Zsp accounting.
  30.     Moved type coersion to a subroutine. Checking operand
  31.     types for integer operations.
  32.         9 Oct 82  Automatically widening before:
  33.     + - * / < <= == != >= >.  Short-circuit evaluation of
  34.     DOUBLE tests.
  35.         6 Oct 82  Generating calls to "qfloat" rather
  36.     than "qqfloat".
  37.         11 Sept 82  Generating no POP DE instructions
  38.     for most operators.
  39.         5 Sept 82  "constant" doing explicit "dload"
  40.     for floating constants.
  41.         3 Sep 82  Accepting floating constants.
  42.         31 Aug 82  Performing monadic "-" on
  43.     floating point variables.
  44.         30 Aug 82  Automatic conversions to and
  45.     from DOUBLE on assignments. Adjusting stack after
  46.     double precision comparisons. Comparisons now yield
  47.     integers.
  48.         29 Aug 82  monadic "&" now generates
  49.     a correct variable name.
  50.         12 Aug 82 Corrected "number" to return
  51.     type correctly.
  52.         11 Aug 82 Rewrote dbltest.
  53.         9 Aug 82  Started installing floating
  54.     point comparisons.
  55.         7 Aug 82  Modified for floating point
  56.     expressions.
  57.         5 Aug 82  Converted JZ to JP Z,
  58.     Converted several calls to ot() to outasm() to
  59.     eliminate unwanted tabs.  Added some comments.
  60.         3 Aug 82  Corrected immed(), removed two
  61.     unnecessary tests for >0, removed one unnecessary
  62.     8-bit mask.
  63.         1 Aug 82  generating Zilog mnemonic
  64.     output rather than Intel.
  65.         18 Jul 82  Corrected expression analyzer
  66.     per J. E. Hendrix (ddj n62 p41);
  67.         1 Jul 82   Replaced calls to "ccpchar" with
  68.     inline code, per Ron Cain, DDJ n48 p6.
  69.         Implemented backslash escape sequences for
  70.     character and string literals, per J. E. Hendrix,
  71.     DDJ n56 p6.
  72.         18 Apr 81    Preceding names by Q rather
  73.     than QZ, to shorten them.
  74. */
  75.  
  76. /*
  77. ** lval[0] - symbol table address, else 0 for constant
  78. ** lval[1] - type of indirect object to fetch, else 0
  79.         for static object
  80. ** lval[2] - type of pointer or array, else 0
  81. ** lval[3] - type of value calculated  jrvz 8/7/82
  82. */
  83. expression()
  84. {
  85.     int lval[4];    /* jrvz 8/7/82 */
  86.     if(heir1(lval))rvalue(lval);
  87.     return lval[3];  /* return type  jrvz 8/7/82 */
  88. }
  89. heir1(lval)
  90.     int lval[];
  91. {
  92.     int k,lval2[4];
  93.     k=heir2(lval);
  94.     if (match("="))
  95.         {if(k==0){needlval();return 0;
  96.         }
  97.         if (lval[1])zpush();
  98.         if(heir1(lval2))rvalue(lval2);
  99.         force(lval[3],lval2[3]); /* jrvz 10/10/82 */
  100.         store(lval);
  101.         return 0;
  102.         }
  103.     else return k;
  104. }
  105. heir2(lval)
  106.     int lval[];
  107. {    int k,lval2[4];
  108.     k=heir3(lval);
  109.     blanks();
  110.     if(ch()!='|')return k;
  111.     if(k)rvalue(lval);
  112.     while(1)
  113.         {if (match("|"))
  114.             {zpush();
  115.             if(heir3(lval2)) rvalue(lval2);
  116.             intcheck(lval,lval2);
  117.                 /* jrvz 10/10/82 */
  118.             zor();
  119.             }
  120.         else return 0;
  121.         }
  122. }
  123. heir3(lval)
  124.     int lval[];
  125. {    int k,lval2[4];
  126.     k=heir4(lval);
  127.     blanks();
  128.     if(ch()!='^')return k;
  129.     if(k)rvalue(lval);
  130.     while(1)
  131.         {if (match("^"))
  132.             {zpush();
  133.             if(heir4(lval2))rvalue(lval2);
  134.             intcheck(lval,lval2);
  135.                 /* jrvz 10/10/82 */
  136.             zxor();
  137.             }
  138.         else return 0;
  139.         }
  140. }
  141. heir4(lval)
  142.     int lval[];
  143. {    int k,lval2[4];
  144.     k=heir5(lval);
  145.     blanks();
  146.     if(ch()!='&')return k;
  147.     if(k)rvalue(lval);
  148.     while(1)
  149.         {if (match("&"))
  150.             {zpush();
  151.             if(heir5(lval2))rvalue(lval2);
  152.             intcheck(lval,lval2);
  153.                 /* jrvz 10/10/82 */
  154.             zand();
  155.             }
  156.         else return 0;
  157.         }
  158. }
  159. heir5(lval)
  160.     int lval[];
  161. {
  162.     int k,lval2[4];
  163.     k=heir6(lval);
  164.     blanks();
  165.     if((streq(line+lptr,"==")==0)&
  166.         (streq(line+lptr,"!=")==0))return k;
  167.     if(k)rvalue(lval);
  168.     while(1)
  169.         {if (match("=="))
  170.             {if(lval[3]==DOUBLE)dpush();
  171.                     /* jrvz 8/9/82 */
  172.             else zpush();
  173.             if(heir6(lval2))rvalue(lval2);
  174.             if(widen(lval,lval2))
  175.                     /* jrvz 10/9/82 */
  176.                 {deq();
  177.                 lval[3]=cint;
  178.                 }    /* jrvz 8/9/82 */
  179.             else zeq();
  180.             }
  181.         else if (match("!="))
  182.             {if(lval[3]==DOUBLE)dpush();
  183.                     /* jrvz 8/9/82 */
  184.             else zpush();
  185.             if(heir6(lval2))rvalue(lval2);
  186.             if(widen(lval,lval2))
  187.                     /* jrvz 10/9/82 */
  188.                 {dne();
  189.                 lval[3]=cint;
  190.                 }    /* jrvz 8/9/82 */
  191.             else zne();
  192.             }
  193.         else return 0;
  194.         }
  195. }
  196. heir6(lval)
  197.     int lval[];
  198. {
  199.     int k,lval2[4];
  200.     k=heir7(lval);
  201.     blanks();
  202.     if((streq(line+lptr,"<")==0)&
  203.         (streq(line+lptr,">")==0)&
  204.         (streq(line+lptr,"<=")==0)&
  205.         (streq(line+lptr,">=")==0))return k;
  206.         if(streq(line+lptr,">>"))return k;
  207.         if(streq(line+lptr,"<<"))return k;
  208.     if(k)rvalue(lval);
  209.     while(1)
  210.         {if (match("<="))
  211.             {if(lval[3]==DOUBLE)dpush();
  212.             else zpush();    /* jrvz 8/9/82 */
  213.             if(heir7(lval2))rvalue(lval2);
  214.             if(widen(lval,lval2))
  215.                     /* jrvz 10/9/82 */
  216.                 {dle();
  217.                 lval[3]=cint; continue;
  218.                 }
  219.             if(lval[2]|lval2[2])
  220.                 {ule();
  221.                 continue;
  222.                 }
  223.             if(cptr=lval2[0])
  224.                 if(cptr[ident]==pointer)
  225.                 {ule();
  226.                 continue;
  227.                 }
  228.             zle();
  229.             }
  230.         else if (match(">="))
  231.             {if(lval[3]==DOUBLE)dpush();
  232.             else zpush();    /* jrvz 8/9/82 */
  233.             if(heir7(lval2))rvalue(lval2);
  234.             if(widen(lval,lval2))
  235.                     /* jrvz 10/9/82 */
  236.                 {dge();
  237.                 lval[3]=cint; continue;
  238.                 }
  239.             if(lval[2]|lval2[2])
  240.                 {uge();
  241.                 continue;
  242.                 }
  243.             if(cptr=lval2[0])
  244.                 if(cptr[ident]==pointer)
  245.                 {uge();
  246.                 continue;
  247.                 }
  248.             zge();
  249.             }
  250.         else if((streq(line+lptr,"<"))&
  251.             (streq(line+lptr,"<<")==0))
  252.             {inbyte();
  253.             if(lval[3]==DOUBLE)dpush();
  254.             else zpush();  /* jrvz 8/10/82 */
  255.             if(heir7(lval2))rvalue(lval2);
  256.             if(widen(lval,lval2))
  257.                     /* jrvz 10/9/82 */
  258.                 {dlt();
  259.                 lval[3]=cint; continue;
  260.                 }
  261.             if(lval[2]|lval2[2])
  262.                 {ult();
  263.                 continue;
  264.                 }
  265.             if(cptr=lval2[0])
  266.                 if(cptr[ident]==pointer)
  267.                 {ult();
  268.                 continue;
  269.                 }
  270.             zlt();
  271.             }
  272.         else if((streq(line+lptr,">"))&
  273.             (streq(line+lptr,">>")==0))
  274.             {inbyte();
  275.             if(lval[3]==DOUBLE)dpush();
  276.             else zpush();  /* jrvz 8/10/82 */
  277.             if(heir7(lval2))rvalue(lval2);
  278.             if(widen(lval,lval2))
  279.                     /* jrvz 10/9/82 */
  280.                 {dgt();
  281.                 lval[3]=cint; continue;
  282.                 }
  283.             if(lval[2]|lval2[2])
  284.                 {ugt();
  285.                 continue;
  286.                 }
  287.             if(cptr=lval2[0])
  288.                 if(cptr[ident]==pointer)
  289.                 {ugt();
  290.                 continue;
  291.                 }
  292.             zgt();
  293.             }
  294.         else return 0;
  295.         }
  296. }
  297. /*    >>>>>> start of cc6 <<<<<<    */
  298.  
  299. heir7(lval)
  300.     int lval[];
  301. {
  302.     int k,lval2[4];
  303.     k=heir8(lval);
  304.     blanks();
  305.     if((streq(line+lptr,">>")==0)&
  306.         (streq(line+lptr,"<<")==0))return k;
  307.     if(k)rvalue(lval);
  308.     while(1)
  309.         {if (match(">>"))
  310.             {zpush();
  311.             if(heir8(lval2))rvalue(lval2);
  312.             zpop();
  313.             intcheck(lval,lval2);
  314.                 /* jrvz 10/10/82 */
  315.             asr();
  316.             }
  317.         else if (match("<<"))
  318.             {zpush();
  319.             if(heir8(lval2))rvalue(lval2);
  320.             intcheck(lval,lval2);
  321.                 /* jrvz 10/10/82 */
  322.             asl();
  323.             }
  324.         else return 0;
  325.         }
  326. }
  327. heir8(lval)
  328.     int lval[];
  329. {
  330.     int k,lval2[4];
  331.     k=heir9(lval);
  332.     blanks();
  333.     if((ch()!='+')&(ch()!='-'))return k;
  334.     if(k)rvalue(lval);
  335.     while(1)
  336.         {if (match("+"))
  337.             {if(lval[3]==DOUBLE)dpush();
  338.                     /* jrvz 8/7/82 */
  339.             else zpush();
  340.             if(heir9(lval2))rvalue(lval2);
  341.             if(dbltest(lval,lval2))
  342.                 scale(lval[2]);  /* jrvz 8/7/82 */
  343.             if(widen(lval,lval2))
  344.                     /* jrvz 10/9/82 */
  345.                 {dadd();
  346.                 }
  347.             else    /* jrvz 8/8/82 */
  348.                 {zpop();if(dbltest(lval2,lval))
  349.                 {if(lval2[2]!=cchar)
  350.                     {swap();scale(lval2[2]);
  351.                     }
  352.                 }
  353.                 zadd();
  354.                 result(lval,lval2);
  355.                 }
  356.             }
  357.         else if (match("-"))
  358.             {if(lval[3]==DOUB