commit 080078cce5798640d8947fe1644083a69d9f6c91
parent b16e692e898d416f27880d4900b57690435182c2
Author: Luxferre <lux@ferre>
Date: Sat, 13 Aug 2022 19:05:25 +0300
Yet another RAM structure revamp for memory protection and future multitasking - to be reflected in README
Diffstat:
M | equi.c | | | 23 | ++++++++++++----------- |
1 file changed, 12 insertions(+), 11 deletions(-)
diff --git a/equi.c b/equi.c
@@ -101,6 +101,9 @@ struct EquiCtx { /* one Equi program context */
ushort rsp; /* return stack pointer */
ushort lsp; /* literal stack pointer */
ushort cltp; /* compilation lookup table pointer */
+ ushort cbp; /* compilation buffer pointer */
+ uchar CM; /* compilation mode flag */
+ uchar IM; /* interpretation mode flag */
ushort gpd_start; /* GPD area start for this task */
ushort cmd_start; /* command buffer start for this task */
ushort cmd_size; /* size of loaded code in bytes for this task */
@@ -117,11 +120,8 @@ struct EquiRAM {
uchar literal_stack_size; /* literal stack size in bytes */
ushort cmd_start; /* (global) command buffer start */
ushort cmd_size; /* (global) command buffer size in bytes */
- ushort cbp; /* compilation buffer pointer */
ushort ibp; /* input buffer pointer */
uchar II; /* instruction ignore mode flag */
- uchar CM; /* compilation mode flag */
- uchar IM; /* interpretation mode flag */
uchar MM; /* minification bypass mode flag */
ushort taskcount; /* count of active tasks */
ushort taskid; /* currently running task ID - necessary? */
@@ -400,6 +400,8 @@ struct EquiCtx* equi_load_task(ushort progStart, ushort len) {
taskptr->cmd_size = len; /* actual command buffer size */
taskptr->id = ram.taskcount; /* assign task ID */
taskptr->gpd_start = (ushort) (taskptr->gpd - flatram); /* assign GPD area start */
+ taskptr->IM = 1; /* set interpretation mode flag */
+ taskptr->CM = 0; /* unset compilation mode flag */
++ram.taskcount; /* increase task count */
return taskptr;
}
@@ -421,7 +423,7 @@ void equi_main_loop() {
continue;
}
/* then, check for compilation mode */
- if(ram.CM) {
+ if(curtask->CM) {
if(instr == INS_CMEND) { /* trigger word compilation logic as per the spec */
if(curtask->lsp < 1)
trapout(STACK_UNDERFLOW);
@@ -429,11 +431,11 @@ void equi_main_loop() {
/* hash and save compiled word */
curtask->clt[curtask->cltp].nhash = crc16(&(curtask->literal_stack[0]), curtask->lsp);
curtask->lsp = 0; /* clear the literal stack */
- curtask->clt[curtask->cltp].loc = ram.cbp; /* stored the compiled code location from the most recent CBP value */
+ curtask->clt[curtask->cltp].loc = curtask->cbp; /* stored the compiled code location from the most recent CBP value */
++curtask->cltp; /* increase the word */
if(curtask->cltp == CLT_ENTRIES_MAX)
trapout(CLT_OVERFLOW);
- ram.CM = 0; /* unset compilation mode flag */
+ curtask->CM = 0; /* unset compilation mode flag */
}
continue;
}
@@ -448,8 +450,8 @@ void equi_main_loop() {
pushLitVal();
switch(instr) { /* then perform all main interpretation logic */
case INS_CMSTART: /* compilation start */
- ram.cbp = curtask->pc + 1U; /* save CBP */
- ram.CM = 1U; /* raise CM flag */
+ curtask->cbp = curtask->pc + 1U; /* save CBP */
+ curtask->CM = 1U; /* raise CM flag */
break;
case CR:
case LF:
@@ -630,7 +632,7 @@ void equi_main_loop() {
/* close the persistent sandbox file if open */
if(pfd) fclose(pfd);
/* unset interpretation mode flag and exit */
- ram.IM = 0;
+ curtask->IM = 0;
curtask->pc = ram.ibp = 65535U;
/* clear all stacks and CLT */
curtask->msp = curtask->rsp = curtask->lsp = curtask->cltp = 0;
@@ -654,7 +656,7 @@ int main(int argc, char* argv[]) {
ram.literal_stack_size = LIT_STACK_SIZE;
ram.cmd_start = (uchar *)&ram.cmdbuf - (uchar *)&ram;
ram.cmd_size = CMD_BUF_SIZE;
- ram.II = ram.CM = ram.IM = ram.MM = 0; /* reset all flags */
+ ram.II = ram.MM = 0; /* reset all flags */
ram.taskcount = 0;
/* process command line params */
if(argc > 1 && argv[1][0] == 'm') /* enter minification mode, don't run the programs */
@@ -706,7 +708,6 @@ int main(int argc, char* argv[]) {
cputc(LF); /* echo LF */
}
ram.cmdbuf[++ram.ibp] = INS_QUIT; /* end program with INS_QUIT */
- ram.IM = 1; /* set the mandatory interpretation mode flag */
curtask = equi_load_task((ushort)ram.cmd_start, ram.ibp + 1); /* load the code as task 0 */
equi_main_loop(); /* and run the interpreter loop */
if(!smode) {