mirror of
https://git.code.sf.net/p/newrpl/sources
synced 2024-11-16 19:51:25 +01:00
63 lines
1.2 KiB
C
63 lines
1.2 KiB
C
#include "newrpl.h"
|
|
#include "hal.h"
|
|
|
|
// GROW THE RETURN STACK
|
|
|
|
void growRStk(WORD newtotalsize)
|
|
{
|
|
WORDPTR *newrstk;
|
|
|
|
BINT gc_done=0;
|
|
|
|
do {
|
|
newtotalsize=(newtotalsize+1023)&~1023;
|
|
|
|
newrstk=hal_growmem(RStk,newtotalsize);
|
|
|
|
if(!newrstk) {
|
|
if(!gc_done) { rplGCollect(); ++gc_done; }
|
|
else {
|
|
Exceptions|=EX_OUTOFMEM;
|
|
ExceptionPointer=IPtr;
|
|
return;
|
|
}
|
|
}
|
|
|
|
} while(!newrstk);
|
|
|
|
RSTop+=newrstk-RStk;
|
|
RStk=newrstk;
|
|
RStkSize=newtotalsize;
|
|
}
|
|
|
|
// RETURN STACK ONLY STORES ADDRESS POINTERS
|
|
// NEVER DIRECTLY A WORD OR A COMMAND
|
|
// STACK IS "INCREASE AFTER" FOR STORE, "DECREASE BEFORE" FOR READ
|
|
|
|
|
|
void rplPushRet(WORDPTR p)
|
|
{
|
|
// PUSH FIRST (USE THE GUARANTEED SLACK)
|
|
// SO THAT IF GROWING THE RETURN STACK TRIGGERS A GC, THE POINTER WILL BE AUTOMATICALLY FIXED
|
|
*RSTop++=p;
|
|
|
|
if(RStkSize<=RSTop-RStk+RSTKSLACK) growRStk((WORD)(RSTop-RStk+RSTKSLACK+1024));
|
|
if(Exceptions) return;
|
|
}
|
|
|
|
WORDPTR rplPopRet()
|
|
{
|
|
if(RSTop<=RStk) {
|
|
Exceptions|=EX_EMPTYRSTK;
|
|
ExceptionPointer=IPtr;
|
|
return 0;
|
|
}
|
|
return *(--RSTop);
|
|
}
|
|
|
|
// LOW LEVEL VERSION FOR USE IN LIBRARIES
|
|
inline WORDPTR rplPeekRet(int level)
|
|
{
|
|
return (RSTop-level<RStk)? 0: *(RSTop-level);
|
|
}
|
|
|