changeset 40:b8fa36c04ff7

fix multiple label on empty line prevlp now follows symrecord movements
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Tue, 17 Jul 2018 10:55:16 +0900
parents 1d3057b6b786
children 0d570c55ebd4
files a09.c
diffstat 1 files changed, 21 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/a09.c	Tue Jul 17 07:07:59 2018 +0900
+++ b/a09.c	Tue Jul 17 10:55:16 2018 +0900
@@ -264,10 +264,9 @@
  return optable+i;
 }
 
-struct symrecord * findsym(char * nm)
+struct symrecord * findsym(char * nm) {
 /* finds symbol table record; inserts if not found
    uses binary search, maintains sorted table */
-{
  int lo,hi,i,j,s;
  lo=0;hi=symcounter-1;
  s=1;i=0;
@@ -284,7 +283,12 @@
    fprintf(stderr,"Sorry, no storage for symbols!!!");
    exit(4);
   }
-  for(j=symcounter;j>i;j--) symtable[j]=symtable[j-1];
+  for(j=symcounter;j>i;j--) {
+      struct symrecord *from = &symtable[j-1];
+      if (prevlp == from)  prevlp++; 
+      if (from->next && from->next - symtable > i) from->next ++;
+      symtable[j]=symtable[j-1];
+  }
   symcounter++;
   strcpy(symtable[i].name,nm);
   symtable[i].cat=13;
@@ -933,6 +937,7 @@
  while (prevlp) {
      struct symrecord *l = prevlp;
      prevlp = prevlp->next;
+     l->next = 0;
      setlabel(l);
  }
  if(lp) {
@@ -1226,6 +1231,7 @@
             rmbmode = 1;
         }
         setlabel(lp);
+        oldlc = loccounter;
         operand=scanexpr(0);
         if(unknown)error|=4;
         loccounter+=operand;
@@ -1245,9 +1251,9 @@
             (lp->value==(unsigned short)operand&&pass==2)) {
           if(exprcat==2)lp->cat=2;
           else lp->cat=0;
-          lp->value=operand;
+          lp->value=oldlc=operand;
          } else // else error|=8;
-          lp->value=operand;
+          lp->value=oldlc=operand;
         }
         break;
  case 7:/* FCB */
@@ -1352,16 +1358,15 @@
          if(lp->cat&1||lp->cat==6) {
           if(exprcat==2)lp->cat=3;
           else lp->cat=1;
-          lp->value=operand;
+          lp->value=oldlc=operand;
          } else // else error|=8;
-          lp->value=operand;
+          lp->value=oldlc=operand;
         }
         break;
    case 2: /* END */
         terminate=1;
         break;     
    case 27: /* USE */     
-        // locsave = loccounter ;
    case 16: /* INCLUDE */     
         skipspace();
         if(*srcptr=='"')srcptr++;
@@ -1377,7 +1382,6 @@
         processfile(fname);
         codeptr=0;
         srcline[0]=0;
-        // if (co==27) loccounter = locsave;
         break; 
    case 24: /* MOD */     
         oldlc = loccounter = 0;
@@ -1476,13 +1480,15 @@
  struct oprecord * op;
  srcptr=srcline;
  oldlc=loccounter;
+ struct symrecord * lp = 0;
  codeptr=0;
  if(isalnum(*srcptr)) {
-  scanname();
+  scanname();lp=findsym(namebuf);
+  if (lp) oldlc = lp->value;
   if(*srcptr==':')srcptr++;
  }
  skipspace();
- scanname();op=findop(namebuf);
+ scanname();op=findop(namebuf); 
  if(op && op->cat==13) {
   if(op->code==10||op->code==13||op->code==29||op->code==28||op->code==21||op->code==30||op->code==31||op->code==33) ifcount++;
   else if(op->code==3) {
@@ -1617,7 +1623,10 @@
    expandline();
    lineno++; glineno++;
    srcptr=srcline;
-   if(suppress)suppressline(); else processline();
+   if(suppress)
+       suppressline(); 
+   else 
+       processline();
  }
  setlabel(0);   // process prevlp
  fclose(srcfile);