1
0
mirror of https://github.com/RevCurtisP/C02.git synced 2024-06-08 06:29:32 +00:00

Upgrades to c02 compiler

This commit is contained in:
Curtis F Kaylor 2020-09-24 12:12:39 -04:00
parent 80c75bdb5e
commit 0d45fa4cbd
6 changed files with 48 additions and 32 deletions

View File

@ -79,7 +79,7 @@ void prscmp(int revrse) {
if (cmpenc != 0) cmprtr = cmprtr | cmpenc; //Combine Encoded Comparator if (cmpenc != 0) cmprtr = cmprtr | cmpenc; //Combine Encoded Comparator
} }
skpspc(); skpspc();
if (cmprtr) prstrm(FALSE); if (cmprtr) prstrm(FALSE, TRUE);
//prccmp(); - Do after check for logical operator //prccmp(); - Do after check for logical operator
DEBUG("Parsed comparator %d\n", cmprtr) DEBUG("Parsed comparator %d\n", cmprtr)
} }

View File

@ -21,7 +21,7 @@ void pshtrm(void) {
strcpy(trmstk[trmidx], term); //Put Current Term on Stack strcpy(trmstk[trmidx], term); //Put Current Term on Stack
trmidx++; //Increment Stack Pointer trmidx++; //Increment Stack Pointer
DEBUG("expr.pshtrm: Pushed term %s ", term) DEBUG("expr.pshtrm: Pushed term %s ", term)
DETAIL("and operator '%onto stack'\n", oper) DETAIL("and operator '%c' onto stack\n", oper)
} }
/* Pop Term and Operator off Stack */ /* Pop Term and Operator off Stack */
@ -153,7 +153,7 @@ int prcptr(void) {
} else if (cmos) { } else if (cmos) {
sprintf(word, "(%s)", term); sprintf(word, "(%s)", term);
} else { } else {
asmlin("LDY","0"); asmlin("LDY","#0");
sprintf(word, "(%s),Y", term); sprintf(word, "(%s),Y", term);
} }
strcpy(term, word); strcpy(term, word);
@ -161,12 +161,17 @@ int prcptr(void) {
return FALSE; //Return Value Not an Integer return FALSE; //Return Value Not an Integer
} }
/* Parse Term in Expression * /* Parse Term in Expression *
* Sets: term - the term (as a string) * * Args: alwint: Allow Integer Value *
* Returns: TRUE if term is an integer */ * alwptr: Allow Pointer Dereference *
int prstrm(int alwint) { * Sets: term - the term (as a string) *
* Returns: TRUE if term is an integer */
int prstrm(int alwint, int alwptr) {
DEBUG("expr.prstrm: Parsing term\n", 0) DEBUG("expr.prstrm: Parsing term\n", 0)
if (match('*')) return prcptr(); //Parse and Deference Pointer if (match('*')) {
if (alwptr)return prcptr(); //Parse and Deference Pointer
else ERROR("Pointer dereference not allowed\n", 0, EXIT_FAILURE)
}
prsval(FALSE, TRUE); //Parse Value - Disallow Registers, Allow Constants prsval(FALSE, TRUE); //Parse Value - Disallow Registers, Allow Constants
if (valtyp == FUNCTION) ERROR("Function call only allowed in first term\n", 0, EXIT_FAILURE) if (valtyp == FUNCTION) ERROR("Function call only allowed in first term\n", 0, EXIT_FAILURE)
strcpy(term, value); strcpy(term, value);
@ -263,16 +268,14 @@ void prsfpr(char trmntr) {
if (look('.')) pusha = 255; if (look('.')) pusha = 255;
else {if (prsxpf(0)) goto prsfne;} else {if (prsxpf(0)) goto prsfne;}
if (look(',') && !chkadr(ADLDYX, TRUE)) { if (look(',') && !chkadr(ADLDYX, TRUE)) {
if (look('.')) { if (look('.')) { pushy = -1; }
pushy = -1;
}
else { else {
if (look('(')) { if (look('(')) {
if (pusha==0) {pusha = 1; asmlin("PHA","");} //Save A on Stack if (pusha==0) {pusha = 1; asmlin("PHA","");} //Save A on Stack
prsxpr(')'); asmlin("TAY", ""); //Evaluate Expression, and Copy to Y prsxpr(')'); asmlin("TAY", ""); //Evaluate Expression, and Copy to Y
} }
else { else {
if (prstrm(TRUE)) goto prsfne; if (prstrm(TRUE, FALSE)) goto prsfne;
asmlin("LDY", term); asmlin("LDY", term);
} }
} }
@ -389,7 +392,7 @@ void prsrxp(char trmntr) {
while (isoper()) { while (isoper()) {
trmcnt++; //Increment Expression Depth trmcnt++; //Increment Expression Depth
prsopr(); //Parse Operator prsopr(); //Parse Operator
prstrm(FALSE); //Parse Term prstrm(FALSE, TRUE); //Parse Term
prcopr(); //Process Operator prcopr(); //Process Operator
trmcnt--; //Decrement Expression Depth trmcnt--; //Decrement Expression Depth
} }

View File

@ -25,7 +25,7 @@ void prsfnc(char trmntr); //Parse function call
void prsfpr(char trmntr); //Parse Function Paraeters or Return void prsfpr(char trmntr); //Parse Function Paraeters or Return
void prsidx(); //Parse Array Index void prsidx(); //Parse Array Index
void prsptr(void); //Parse Pointer void prsptr(void); //Parse Pointer
int prstrm(int alwint); //Parse Term in Expression int prstrm(int alwint, int alwptr); //Parse Term in Expression
void prsrxp(char trmntr); //Parse Rest of Expression void prsrxp(char trmntr); //Parse Rest of Expression
int prsxpf(char trmntr); //Parse Expression in Function Call int prsxpf(char trmntr); //Parse Expression in Function Call
void prsxpr(char trmntr); //Parse Expression void prsxpr(char trmntr); //Parse Expression

View File

@ -21,11 +21,13 @@
/* Read next include file name from Source File * /* Read next include file name from Source File *
* Sets: incnam - the include file name */ * Sets: incnam - the include file name */
void pincnm(void) { void pincnm(void) {
DEBUG("Parsing include file name", 0)
char dlmtr; char dlmtr;
int inclen = 0; int inclen = 0;
int sublen[SUBMAX]; int sublen[SUBMAX];
skpspc(); skpspc();
dlmtr = getnxt(); dlmtr = getnxt();
DETAIL(" with delimiter '%c'\n", dlmtr)
if (dlmtr == '<') { if (dlmtr == '<') {
strcpy(incnam, incdir); strcpy(incnam, incdir);
inclen = strlen(incnam); inclen = strlen(incnam);

View File

@ -38,7 +38,7 @@ int isspc(void) {return isspace(nxtchr);}
int isszop(void) {return match('@');} int isszop(void) {return match('@');}
int isvpre(void) {return TF(isalph() || islpre());} int isvpre(void) {return TF(isalph() || islpre());}
int isxfop(void) {return match('?');} int isxfop(void) {return match('?');}
int isxpre(void) {return TF(isvpre() || match('-'));} int isxpre(void) {return TF(isvpre() || match('-') || match('*'));}
/* Process ASCII Character */ /* Process ASCII Character */
char prcchr(char c) { char prcchr(char c) {

View File

@ -198,16 +198,21 @@ void prcavr(char trmntr) {
prsvar(FALSE, FALSE); //get variable name prsvar(FALSE, FALSE); //get variable name
strcpy(ysnvar, word); strcpy(ysnvar, word);
DEBUG("stmnt.prcvar: Set STY variable to %s\n", ysnvar) DEBUG("stmnt.prcvar: Set STY variable to %s\n", ysnvar)
if (valtyp == ARRAY) ysnivt = getidx(ysnidx); //Get Array Index and Type if (vartyp == VTINT) {
else ysnidx[0] = 0; strcpy(xsnvar, ysnvar); //Set Assignment LSB
DEBUG("stmnt.prcvar: Set STY index to '%s'", ysnidx) DETAIL(" and type to %d\n", ysnivt) strcat(ysnvar, "+1"); //Set Assignment MSB
if (look(',')) { } else {
prsvar(FALSE, FALSE); //get variable name if (valtyp == ARRAY) ysnivt = getidx(ysnidx); //Get Array Index and Type
strcpy(xsnvar, word); else ysnidx[0] = 0;
DEBUG("stmnt.prcvar: Set STX variable to %s\n", xsnvar) DEBUG("stmnt.prcvar: Set STY index to '%s'", ysnidx) DETAIL(" and type to %d\n", ysnivt)
//if (valtyp == ARRAY) ERROR("Array element not allowed in third assignment\n", 0, EXIT_FAILURE) if (look(',')) {
if (valtyp == ARRAY) xsnivt = getidx(xsnidx); //Get Array Index and Type prsvar(FALSE, FALSE); //get variable name
else xsnidx[0] = 0; strcpy(xsnvar, word);
DEBUG("stmnt.prcvar: Set STX variable to %s\n", xsnvar)
//if (valtyp == ARRAY) ERROR("Array element not allowed in third assignment\n", 0, EXIT_FAILURE)
if (valtyp == ARRAY) xsnivt = getidx(xsnidx); //Get Array Index and Type
else xsnidx[0] = 0;
}
} }
} }
prcasn(trmntr, FALSE); prcasn(trmntr, FALSE);
@ -348,17 +353,23 @@ void pgoto(void) {
/* parse and compile inline statement */ /* parse and compile inline statement */
void pinlne(void) { void pinlne(void) {
int i; //For Parsing Integers
DEBUG("stmnt.pinlne: Parsing INLINE statement\n", 0) DEBUG("stmnt.pinlne: Parsing INLINE statement\n", 0)
do { do {
DEBUG("stmnt.pinlne: Parsing inline parameter\n", 0) DEBUG("stmnt.pinlne: Parsing inline parameter\n", 0)
if (look('&')) { if (look('&')) {
reqvar(FALSE); //Get Variable Name if (isnpre()) {
strcpy(word, "<"); i = prsnum(0xFFFF);
strcat(word, value); sprintf(word, "$%02x,$%02x", i & 0xFF, i >> 8);
strcat(word, ", >"); } else {
strcat(word, value); reqvar(FALSE); //Get Variable Name
strcpy(word, "<");
strcat(word, value);
strcat(word, ", >");
strcat(word, value);
}
asmlin(BYTEOP, word); asmlin(BYTEOP, word);
} }
else if (look('"')) { else if (look('"')) {
value[0] = 0; value[0] = 0;
while (!match('"')) { while (!match('"')) {
@ -456,7 +467,7 @@ void pcase(void) {
newlbl(cndlbl); //Create Conditional Label newlbl(cndlbl); //Create Conditional Label
pshlbl(LTCASE, cndlbl); //and Push onto Stack pshlbl(LTCASE, cndlbl); //and Push onto Stack
while(TRUE) { while(TRUE) {
prstrm(FALSE); //Parse CASE argument prstrm(FALSE, TRUE); //Parse CASE argument
if (!fcase || valtyp != LITERAL || litval) if (!fcase || valtyp != LITERAL || litval)
asmlin("CMP", term); //Emit Comparison asmlin("CMP", term); //Emit Comparison
if (look(',')) { if (look(',')) {