Implemented minification mode

This commit is contained in:
Luxferre
2022-08-11 19:11:18 +03:00
parent c3faeff722
commit abfc1125c7
3 changed files with 25 additions and 11 deletions
+22 -11
View File
@@ -553,7 +553,9 @@ void equi_main_loop() {
/* Equi VM entry point */
int main(int argc, char* argv[]) {
uchar instr, bc;
uchar instr, bc, mmode = 0;
if(argc > 1 && argv[1][0] == 'm') /* enter minification mode, don't run the programs */
mmode = 1;
/* CC65-specific terminal init */
#ifdef __CC65__
clrscr();
@@ -574,6 +576,7 @@ int main(int argc, char* argv[]) {
/* Start both execution and input buffering from the start of command buffer (-1 because we use prefix increment) */
ram.pc = ram.ibp = 65535U;
if(!mmode) /* skip the greeting if in minification mode */
printf("\nWelcome to Equi v" EQUI_VER " by Luxferre, 2022\nCLT: 0x%04X (%d bytes)\nGPD: 0x%04X (%d bytes)\nCommand buffer: 0x%04X (%d bytes)\nEqui ready\n\n> ",
(unsigned int) ((uchar *)&ram.clt - (uchar *)&ram.main_stack),
(unsigned int) ((uchar *)&ram.gpd - (uchar *)&ram.clt),
@@ -599,16 +602,24 @@ int main(int argc, char* argv[]) {
cputc(instr); /* echo it */
#endif
ram.II = 0;
} else if(!ram.II && (instr == 0xFFU || instr == INS_QUIT)) { /* if not in II mode, process EOF or Q instruction: trigger interpreter loop */
cputc(CR); /* echo CR */
cputc(LF); /* echo LF */
ram.cmdbuf[++ram.ibp] = INS_QUIT; /* end program with INS_QUIT */
ram.IM = 1; /* set the mandatory interpretation mode flag */
equi_main_loop(); /* and run the interpreter loop */
cputc(CR); /* echo CR */
cputc(LF); /* echo LF */
cputc('>');
cputc(' ');
} else if(!ram.II && (instr == 0xFFU || instr == INS_QUIT)) {
if(mmode) { /* output command buffer contents to stdout and exit */
ram.cmdbuf[++ram.ibp] = INS_QUIT; /* end program with INS_QUIT */
ram.cmdbuf[++ram.ibp] = 0; /* and zero terminator */
puts((const char *)&ram.cmdbuf[0]); /* output the command buffer */
break; /* and exit the command mode immediately */
} else {
/* if not in II or minification mode, process EOF or Q instruction: trigger interpreter loop */
cputc(CR); /* echo CR */
cputc(LF); /* echo LF */
ram.cmdbuf[++ram.ibp] = INS_QUIT; /* end program with INS_QUIT */
ram.IM = 1; /* set the mandatory interpretation mode flag */
equi_main_loop(); /* and run the interpreter loop */
cputc(CR); /* echo CR */
cputc(LF); /* echo LF */
cputc('>');
cputc(' ');
}
} else { /* append the instruction/character to the command buffer if and only if it doesn't match the above criteria and we're not in II mode */
if(!ram.II)
ram.cmdbuf[++ram.ibp] = instr;