Whitespace logic revamped, now Q at the end is mandatory but one can use any whitespace in the programs

This commit is contained in:
Luxferre
2022-08-11 11:43:05 +03:00
parent c0ee893f25
commit f68975f5c8
2 changed files with 22 additions and 26 deletions
+17 -21
View File
@@ -337,9 +337,6 @@ void equi_main_loop() {
if(ram.lsp > 0 && instr != INS_LITSTR && instr != INS_LITCALL && instr != INS_LITINT && instr != INS_CMSTART)
pushLitVal();
switch(instr) { /* then perform all main interpretation logic */
case INS_IISTART: /* instruction ignore start */
ram.II = 1; /* raise II flag */
break;
case INS_CMSTART: /* compilation start */
ram.cbp = ram.pc + 1U; /* save CBP */
ram.CM = 1U; /* raise CM flag */
@@ -540,49 +537,48 @@ 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;
printf("Welcome to Equi v" EQUI_VER " by Luxferre, 2022\n\nCLT: 0x%04X (%d bytes)\nGPD: 0x%04X (%d bytes)\nCommand buffer: 0x%04X (%d bytes)\nEqui ready\n\n",
printf("Welcome to Equi v" EQUI_VER " by Luxferre, 2022\n\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),
ram.gpd_start,
ram.cmd_start - ram.gpd_start,
ram.cmd_start, ram.cmd_size);
cputc('>');
cputc(' ');
while(1) { /* Now, we're in the command mode loop */
instr = ram.cmdbuf[++ram.ibp] = cgetc(); /* Fetch the next instruction from the keyboard */
if(instr == 0xFFU || instr == 0U) /* exit */
instr = cgetc(); /* Fetch the next instruction from the keyboard/stdin */
if(instr == 0xFFU || instr == 0U) /* exit on zero byte */
break;
else if(instr == BS && ram.ibp > ram.cmd_start) { /* process the backspace */
else if(instr == BS || instr == CR || instr == LF || instr == ' ' || instr == '\t') { /* ignore the backspace or whitespaces */
#ifdef __CC65__
cputc(instr); /* echo it */
#endif
--ram.ibp;
} else if(instr == INS_IISTART) { /* process II just to avoid quitting in command mode */
} else if(instr == INS_IISTART) { /* process II start */
#ifdef __CC65__
cputc(instr); /* echo it */
#endif
ram.II = 1;
} else if(instr == INS_IIEND) { /* process II just to avoid quitting in command mode */
} else if(instr == INS_IIEND) { /* process II end */
#ifdef __CC65__
cputc(instr); /* echo it */
#endif
ram.II = 0;
} else if(instr == CR || instr == LF) { /* process carriage return or linefeed */
cputc(CR); /* echo it */
cputc(LF); /* echo it */
ram.cmdbuf[ram.ibp] = 0; /* replace itself with 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] = 0; /* end program with 0 */
ram.IM = 1; /* set the mandatory interpretation mode flag */
equi_main_loop(); /* and run the interpreter loop */
cputc(CR); /* echo it */
cputc(LF); /* echo it */
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;
#ifdef __CC65__
else cputc(instr); /* echo it */
cputc(instr); /* echo it */
#endif
}
} /* command mode loop end */
return 0;
}