From 818174a15a3904c8fd7790d5da1d7119ff8cc702 Mon Sep 17 00:00:00 2001 From: Curtis F Kaylor Date: Wed, 18 Jul 2018 23:49:39 -0400 Subject: [PATCH] Fixed break/continue bug in DO/WHILE loop --- py65/loops.c02 | 13 +++++++++++++ src/dclrtn.c | 1 + src/label.c | 3 ++- src/stmnt.c | 2 +- src/vars.c | 15 ++++++++++++--- src/vars.h | 2 +- 6 files changed, 30 insertions(+), 6 deletions(-) diff --git a/py65/loops.c02 b/py65/loops.c02 index af60dc0..de62c1d 100644 --- a/py65/loops.c02 +++ b/py65/loops.c02 @@ -69,6 +69,19 @@ for (i=0;i<10;i++) { } newlin(); +/* Test Do with Break and Continue*/ +i = 0; +puts("DO BC "); +do { + i++; + if (!i&1) continue; + if (i>15) break; + prbyte(i); + putc(' '); +} while ($FF); +newlin(); + + newlin(); /* Test Block If */ diff --git a/src/dclrtn.c b/src/dclrtn.c index 8957511..73a4644 100644 --- a/src/dclrtn.c +++ b/src/dclrtn.c @@ -136,6 +136,7 @@ int pmodfr(void) { int result = TRUE; if (wordis("ALIGNED")) { getwrd(); ptype(MTALGN); } else if (wordis("ZEROPAGE")) { getwrd(); ptype(MTZP); } + else if (wordis("ALIAS")) { getwrd(); ptype(MTALS); } else result = FALSE; return result; } diff --git a/src/label.c b/src/label.c index 4f4c3f6..5625bf2 100644 --- a/src/label.c +++ b/src/label.c @@ -13,7 +13,8 @@ #include "parse.h" #include "label.h" -const char lblflg[] = {LFNONE, LFNONE, LFBGN, LFEND, LFBGN, LFEND, LFEND, LFNONE, LFNONE}; //Label Type Flags +const char lblflg[] = {LFNONE, LFNONE, LFNONE, LFBGN, LFEND, LFBGN, LFEND, LFEND, LFNONE, LFNONE}; //Label Type Flags +// enum ltypes {LTNONE, LTIF, LTELSE, LTLOOP, LTEND, LTDO, LTDWHL, LTSLCT, LTCASE, LTFUNC}; //Label Types /* Find Last Label of Specified Types * * Args: lbtyp1: First label type * diff --git a/src/stmnt.c b/src/stmnt.c index dd76999..7a8102b 100644 --- a/src/stmnt.c +++ b/src/stmnt.c @@ -381,7 +381,7 @@ void pwhile(void) { expect('('); newlbl(endlbl); //Create End Label pshlbl(LTEND, endlbl); //and Push onto Stack - reqlbl(loplbl); //Get or Create/Set Loop Label + reqlbl(loplbl); //Get or Create/Set Loop Label pshlbl(LTLOOP, loplbl); //Push onto Stack if (!look(')')) { newlbl(cndlbl); //Create Conditional Skip Label diff --git a/src/vars.c b/src/vars.c index cbb4a44..eb485ea 100644 --- a/src/vars.c +++ b/src/vars.c @@ -209,7 +209,16 @@ void addvar(int m, int t) { setlbl(vrname); sprintf(word, "$%hhX", zpaddr++); asmlin(EQUOP, word); - strcpy(value, "*"); //Set Variable Type to Zero Page + strcpy(value, "*"); //Set Variable to Non Allocated + } + else if (m == MTALS) { + setlbl(vrname); + skpspc(); + expect('='); + skpspc(); + if (isnpre()) prsnum(0xFFFF); else prsvar(FALSE); + asmlin(EQUOP, word); + strcpy(value, "*"); //Set Variable to Non Allocated } else { if (t == VTSTRUCT) { @@ -226,9 +235,9 @@ void addvar(int m, int t) { } else value[0] = 0; if (!alcvar) strcpy(value, "*"); - setvar(m, t); //Add to Variable Table } - if (m != MTZP && t != VTSTRUCT ) prsdat(); //Parse Variable Data + setvar(m, t); //Add to Variable Table + if (m < MTZP && t != VTSTRUCT ) prsdat(); //Parse Variable Data varcnt++; //Increment Variable Counter } diff --git a/src/vars.h b/src/vars.h index 3f22da2..10e01de 100644 --- a/src/vars.h +++ b/src/vars.h @@ -48,7 +48,7 @@ int dsize; //Total Data Length enum dtypes {DTBYTE, DTSTR, DTARRY}; //Variable Data Types -enum mtypes {MTNONE, MTALGN, MTZP}; //Variable Modifier Types +enum mtypes {MTNONE, MTALGN, MTZP, MTALS}; //Variable Modifier Types int symdef(char *name); //Is Variable defined (TRUE or FALSE) int zpaddr; //Current Zero-Page Address