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

Defined functions

gotoop defined in line 71; used 1 times
label defined in line 21; used 1 times
labeled defined in line 101; used 1 times
Last modified: 1981-07-10
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 2241
Valid CSS Valid XHTML 1.0 Strict