home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / ENTERPRS / CPM / UTILS / S / SMC21SRC.LZH / CC33.C < prev    next >
Text File  |  2000-06-30  |  5KB  |  196 lines

  1.  
  2. /*
  3. ** true if val1 -> int pointer or int array and val2 not ptr or array
  4. */
  5. dbltest(oper, val1,val2) int (*oper)(), val1[], val2[]; {   /*34*/  /*13*/
  6.   if((oper!=ffadd) && (oper!=ffsub)) return 0;              /*34*/
  7.   if(val1[2]!=CINT) return 0;
  8.   if(val2[2]) return 0;
  9.   return 1;
  10.   }
  11.  
  12. /*
  13. ** determine type of binary operation
  14. */
  15. result(lval, lval2) int lval[], lval2[]; {
  16.   if((lval[2]!=0)&(lval2[2]!=0)) {
  17.     lval[2]=0;
  18.     }
  19.   else if(lval2[2]) {
  20.     lval[0]=lval2[0];
  21.     lval[1]=lval2[1];
  22.     lval[2]=lval2[2];
  23.     }
  24.   }
  25. step(oper, lval) int (*oper)(), lval[]; {               /*13*/
  26.   if(lval[1]) {
  27.     if(lval[5]) {
  28.       push();
  29.       rvalue(lval);
  30.       (*oper)(lval[2]>>2);                              /*13*/
  31.       pop();
  32.       store(lval);
  33.       return;
  34.       }
  35.     else {
  36.       move();
  37.       lval[5]=1;
  38.       }
  39.     }
  40.   rvalue(lval);
  41.   (*oper)(lval[2]>>2);                                  /*13*/
  42.   store(lval);
  43.   }
  44.  
  45. store(lval)  int lval[]; {
  46.   if(lval[1]) putstk(lval);
  47.   else        putmem(lval);
  48.   }
  49.  
  50. rvalue(lval) int lval[]; {
  51.   if ((lval[0]!=0)&(lval[1]==0)) getmem(lval);
  52.   else                         indirect(lval);
  53.   }
  54.  
  55. test(label, parens)  int label, parens;  {
  56.   int lval[8];
  57.   char *before, *start;
  58.   if(parens) needtoken("(");
  59.   while(1) {
  60.     setstage(&before, &start);
  61.     if(heir1(lval)) rvalue(lval);
  62.     if(match(",")) clearstage(before, start);
  63.     else break;
  64.     }
  65.   if(parens) needtoken(")");
  66.   if(lval[3]) {  /* constant expression */
  67.     clearstage(before, 0);
  68.     if(lval[4]) return;
  69.     jump(label);
  70.     return;
  71.     }
  72.   if(lval[7]) {  /* stage address of "oper 0" code */
  73.     oper=lval[6];/* operator function address */
  74.          if((oper==ffeq)|
  75.             (oper==ule)) zerojump(eq0, label, lval);
  76.     else if((oper==ffne)|
  77.             (oper==ugt)) zerojump(ne0, label, lval);
  78.     else if (oper==ffgt) zerojump(gt0, label, lval);
  79.     else if (oper==ffge) zerojump(ge0, label, lval);
  80.     else if (oper==uge)  clearstage(lval[7],0);
  81.     else if (oper==fflt) zerojump(lt0, label, lval);
  82.     else if (oper==ult)  zerojump(ult0, label, lval);
  83.     else if (oper==ffle) zerojump(le0, label, lval);
  84.     else                 testjump(label);
  85.     }
  86.   else testjump(label);
  87.   clearstage(before, start);
  88.   }
  89.  
  90. constexpr(val) int *val; {
  91.   int const;
  92.   char *before, *start;
  93.   setstage(&before, &start);
  94.   expression(&const, val);
  95.   clearstage(before, 0);  /* scratch generated code */
  96.   if(const==0) error("must be constant expression");
  97.   return const;
  98.   }
  99.  
  100. const(val) int val; {
  101.   immed();
  102.   outdec(val);
  103.   nl();
  104.   }
  105.  
  106. const2(val) int val; {
  107.   immed2();
  108.   outdec(val);
  109.   nl();
  110.   }
  111.  
  112. constant(lval)  int lval[]; {
  113.   lval=lval+3;
  114.   *lval=1;       /* assume it will be a constant */
  115.   if (number(++lval)) immed();
  116.   else if (pstr(lval)) immed();
  117.   else if (qstr(lval)) {
  118.     *(lval-1)=0; /* nope, it's a string address */
  119.     immed();
  120.     printlabel(litlab);
  121.     outbyte('+');
  122.     }
  123.   else return 0;
  124.   outdec(*lval);
  125.   nl();
  126.   return 1;
  127.   }
  128.  
  129. number(val)  int val[]; {
  130.   int k, minus;
  131.   k=minus=0;
  132.   while(1) {
  133.     if(match("+")) ;
  134.     else if(match("-")) minus=1;
  135.     else break;
  136.     }
  137.   if(isdigit(ch)==0)return 0;
  138.   while (isdigit(ch)) k=k*10+(inbyte()-'0');
  139.   if (minus) k=(-k);
  140.   val[0]=k;
  141.   return 1;
  142.   }
  143.  
  144. address(ptr) char *ptr; {
  145.   immed();
  146.   outstr(ptr+NAME);
  147.   nl();
  148.   }
  149.  
  150. pstr(val)  int val[]; {
  151.   int k;
  152.   k=0;
  153.   if (match("'")==0) return 0;
  154.   while(ch!=39)    k=(k&255)*256 + (litchar()&255);
  155.   gch();                                              /*24*/
  156.   val[0]=k;
  157.   return 1;
  158.   }
  159.  
  160. qstr(val)  int val[]; {
  161.   char c;
  162.   if (match(quote)==0) return 0;
  163.   val[0]=litptr;
  164.   while (ch!='"') {
  165.     if(ch==0) break;
  166.     stowlit(litchar(), 1);
  167.     }
  168.   gch();
  169.   litq[litptr++]=0;
  170.   return 1;
  171.   }
  172.  
  173. stowlit(value, size) int value, size; {
  174.   if((litptr+size) >= LITMAX) {
  175.     error("literal queue overflow"); abort(ERRCODE);
  176.     }
  177.   putint(value, litq+litptr, size);
  178.   litptr=litptr+size;
  179.   }
  180.  
  181. /*
  182. ** return current literal char & bump lptr
  183. */
  184. litchar() {
  185.   int i, oct;
  186.   if((ch!=92)|(nch==0)) return gch();
  187.   gch();
  188.   if(ch=='n') {gch(); return NEWLINE;} /*23*/
  189.   if(ch=='t') {gch(); return  9;} /* HT */
  190.   if(ch=='b') {gch(); return  8;} /* BS */
  191.   if(ch=='f') {gch(); return 12;} /* FF */
  192.   i=3; oct=0;
  193.   while(((i--)>0)&(ch>='0')&(ch<='7')) oct=(oct<<3)+gch()-'0';
  194.   if(i==2) return gch(); else return oct;
  195.   }
  196.