home *** CD-ROM | disk | FTP | other *** search
/ minnie.tuhs.org / unixen.tar / unixen / PDP-11 / Distributions / ucb / spencer_2bsd.tar.gz / 2bsd.tar / src / pi0 / lab.c < prev    next >
C/C++ Source or Header  |  1980-02-17  |  2KB  |  125 lines

  1. /* Copyright (c) 1979 Regents of the University of California */
  2. #
  3. /*
  4.  * pi - Pascal interpreter code translator
  5.  *
  6.  * Charles Haley, Bill Joy UCB
  7.  * Version 1.2 January 1979
  8.  */
  9.  
  10. #include "0.h"
  11. #include "tree.h"
  12. #include "opcode.h"
  13.  
  14. /*
  15.  * Label enters the definitions
  16.  * of the label declaration part
  17.  * into the namelist.
  18.  */
  19. label(r, l)
  20.     int *r, l;
  21. {
  22. #ifndef PI0
  23.     register *ll;
  24.     register struct nl *p, *lp;
  25.  
  26.     lp = NIL;
  27. #else
  28.     send(REVLAB, r);
  29. #endif
  30.     line = l;
  31. #ifndef PI1
  32.     if (parts & (CPRT|TPRT|VPRT))
  33.         error("Label declarations must precede const, type and var declarations");
  34.     if (parts & LPRT)
  35.         error("All labels must be declared in one label part");
  36.     parts =| LPRT;
  37. #endif
  38. #ifndef PI0
  39.     for (ll = r; ll != NIL; ll = ll[2]) {
  40.         l = getlab();
  41.         p = enter(defnl(ll[1], LABEL, 0, l));
  42.         /*
  43.          * Get the label for the eventual target
  44.          */
  45.         p->value[1] = getlab();
  46.         p->chain = lp;
  47.         p->nl_flags =| (NFORWD|NMOD);
  48.         p->value[NL_GOLEV] = NOTYET;
  49.         lp = p;
  50.         /*
  51.          * This operator is between
  52.          * the bodies of two procedures
  53.          * and provides a target for
  54.          * gotos for this label via TRA.
  55.          */
  56.         putlab(l);
  57.         put2(O_GOTO | cbn<<9, p->value[1]);
  58.     }
  59.     gotos[cbn] = lp;
  60. #endif
  61. }
  62.  
  63. #ifndef PI0
  64. /*
  65.  * Gotoop is called when
  66.  * we get a statement "goto label"
  67.  * and generates the needed tra.
  68.  */
  69. gotoop(s)
  70.     char *s;
  71. {
  72.     register struct nl *p;
  73.  
  74.     gocnt++;
  75.     p = lookup(s);
  76.     if (p == NIL)
  77.         return (NIL);
  78.     put2(O_TRA, p->value[0]);
  79.     if (bn == cbn)
  80.         if (p->nl_flags & NFORWD) {
  81.             if (p->value[NL_GOLEV] == NOTYET) {
  82.                 p->value[NL_GOLEV] = level;
  83.                 p->value[NL_GOLINE] = line;
  84.             }
  85.         } else
  86.             if (p->value[NL_GOLEV] == DEAD) {
  87.                 recovered();
  88.                 error("Goto %s is into a structured statement", p->symbol);
  89.             }
  90. }
  91.  
  92. /*
  93.  * Labeled is called when a label
  94.  * definition is encountered, and
  95.  * marks that it has been found and
  96.  * patches the associated GOTO generated
  97.  * by gotoop.
  98.  */
  99. labeled(s)
  100.     char *s;
  101. {
  102.     register struct nl *p;
  103.  
  104.     p = lookup(s);
  105.     if (p == NIL)
  106.         return (NIL);
  107.     if (bn != cbn) {
  108.         error("Label %s not defined in correct block", s);
  109.         return;
  110.     }
  111.     if ((p->nl_flags & NFORWD) == 0) {
  112.         error("Label %s redefined", s);
  113.         return;
  114.     }
  115.     p->nl_flags =& ~NFORWD;
  116.     patch(p->value[1]);
  117.     if (p->value[NL_GOLEV] != NOTYET)
  118.         if (p->value[NL_GOLEV] < level) {
  119.             recovered();
  120.             error("Goto %s from line %d is into a structured statement", s, p->value[NL_GOLINE]);
  121.         }
  122.     p->value[NL_GOLEV] = level;
  123. }
  124. #endif
  125.