ensure desired updating order between envCurr and its pointed-to data

This commit is contained in:
dzaima 2024-03-25 15:32:33 +02:00
parent b089337ee8
commit 79ea9ec02c

View File

@ -223,16 +223,19 @@ extern GLOBAL Env* envCurr;
extern GLOBAL Env* envStart; extern GLOBAL Env* envStart;
extern GLOBAL Env* envEnd; extern GLOBAL Env* envEnd;
extern GLOBAL u64 envPrevHeight; // envStart+prevEnvHeight gives envCurr+1 from before the error extern GLOBAL u64 envPrevHeight; // envStart+prevEnvHeight gives envCurr+1 from before the error
#define PROFILER_FENCE __asm__ volatile("" ::: "memory")
static inline void pushEnv(Scope* sc, u32* bc) { static inline void pushEnv(Scope* sc, u32* bc) {
if (envCurr+1==envEnd) thrM("Stack overflow"); if (envCurr+1==envEnd) thrM("Stack overflow");
Env* e = envCurr+1; Env* e = envCurr+1;
e->sc = sc; e->sc = sc;
e->pos = ptr2u64(bc); e->pos = ptr2u64(bc);
PROFILER_FENCE;
envCurr = e; envCurr = e;
} }
static inline void popEnv() { static inline void popEnv() {
assert(envCurr>=envStart); assert(envCurr>=envStart);
envCurr--; envCurr--;
PROFILER_FENCE;
} }
FORCE_INLINE i32 argCount(u8 ty, bool imm) { return (imm?0:3) + ty + (ty>0); } FORCE_INLINE i32 argCount(u8 ty, bool imm) { return (imm?0:3) + ty + (ty>0); }
FORCE_INLINE i32 blockGivenVars(Block* bl) { return argCount(bl->ty, bl->imm); } FORCE_INLINE i32 blockGivenVars(Block* bl) { return argCount(bl->ty, bl->imm); }