Add support for negative constants in external initialisers.
authorDavid Given <dg@cowlark.com>
Sat, 31 Dec 2016 19:43:03 +0000 (19:43 +0000)
committerDavid Given <dg@cowlark.com>
Sat, 31 Dec 2016 19:43:03 +0000 (19:43 +0000)
lang/b/compiler/b0.c

index 03123ec..e6845be 100644 (file)
@@ -373,7 +373,15 @@ loop:
                return subseq(c,PLUS,INCBEF);
 
        case MINUS:
-               return subseq(c,MINUS,DECBEF);
+               /* avoid peeking a name, which could overwrite
+                * an already set bsym. */
+               if (ctab[peekc = spnextchar()] == DIGIT) {
+                       getnum();
+                       cval = -cval;
+                       return CON;
+               } else {
+                       return subseq(c,MINUS,DECBEF);
+               }
 
        case LESS:
                if (subseq(c,0,1))