mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-01-31 11:37:35 +00:00
fa20edc44d
- Remove most __ASSEMBLER__ __LINKER__ ifdefs - Rename libc/intrin/bits.h to libc/serialize.h - Block pthread cancelation in fchmodat() polyfill - Remove `clang-format off` statements in third_party
47 lines
1 KiB
C
47 lines
1 KiB
C
#ifndef COSMOPOLITAN_TOOL_PLINKO_LIB_STACK_H_
|
|
#define COSMOPOLITAN_TOOL_PLINKO_LIB_STACK_H_
|
|
#include "libc/log/check.h"
|
|
#include "libc/stdckdint.h"
|
|
#include "tool/plinko/lib/error.h"
|
|
#include "tool/plinko/lib/plinko.h"
|
|
COSMOPOLITAN_C_START_
|
|
|
|
#define SetFrame(r, x) \
|
|
do { \
|
|
if (r & NEED_POP) { \
|
|
Repush(x); \
|
|
} else { \
|
|
r |= NEED_POP; \
|
|
Push(x); \
|
|
} \
|
|
} while (0)
|
|
|
|
forceinline dword GetCurrentFrame(void) {
|
|
DCHECK_GT(sp, 0);
|
|
return g_stack[(sp - 1) & 0xffffffff];
|
|
}
|
|
|
|
forceinline void Push(int x) {
|
|
unsigned short s = sp;
|
|
g_stack[s] = MAKE(x, ~cx);
|
|
if (!ckd_add(&s, s, 1)) {
|
|
sp = s;
|
|
} else {
|
|
StackOverflow();
|
|
}
|
|
}
|
|
|
|
forceinline dword Pop(void) {
|
|
DCHECK_GT(sp, 0);
|
|
return g_stack[--sp & 0xffffffff];
|
|
}
|
|
|
|
forceinline void Repush(int x) {
|
|
int i;
|
|
DCHECK_GT(sp, 0);
|
|
i = (sp - 1) & MASK(STACK);
|
|
g_stack[i & 0xffffffff] = MAKE(x, HI(g_stack[i & 0xffffffff]));
|
|
}
|
|
|
|
COSMOPOLITAN_C_END_
|
|
#endif /* COSMOPOLITAN_TOOL_PLINKO_LIB_STACK_H_ */
|