all repos — xyw @ 9b133410ee47c39b928890d0bc3bdaf9cc033049

A minimal virtual machine and assembler for terminals.

Fixes.
h3rald h3rald@h3rald.com
Sat, 29 Nov 2025 17:22:19 +0100
commit

9b133410ee47c39b928890d0bc3bdaf9cc033049

parent

6d6ab0c1da21f115338db95e98bb4661acd3af0d

2 files changed, 26 insertions(+), 3 deletions(-)

jump to
M xywxyw

          
M xywvm.cxywvm.c

@@ -147,6 +147,29 @@ (*ssp) += 2;

} */ +//// User stack management + +static void us_push(xyw_byte val) +{ + if (*usp > STACK_SIZE - 1) + { + xyw_memory[SYSTEM_ERROR] = XYW_ERROR_STACK_OVERFLOW; + return; + } + user_stack[(*usp)++] = val; +} + +static void us_pushw(xyw_word val) +{ + if (*usp > STACK_SIZE - 2) + { + xyw_memory[SYSTEM_ERROR] = XYW_ERROR_STACK_OVERFLOW; + return; + } + mset(USER_STACK_START + *usp, val); + (*usp) += 2; +} + //// Instructions static void PSH()

@@ -303,11 +326,11 @@

//// Macro helpers // Infix operation -#define IOP(op) is_w() ? PSHw((POPw(1) op POPw(0))) : PSH((POP(1) op POP(0))) +#define IOP(op) is_w() ? us_pushw((POPw(1) op POPw(0))) : us_push((POP(1) op POP(0))) // Binary operation -#define BOP(op) is_w() ? PSHw(op(POPw(1), POPw(0))) : PSH(op(POP(1), POP(0))) +#define BOP(op) is_w() ? us_pushw(op(POPw(1), POPw(0))) : us_push(op(POP(1), POP(0))) // Unary operation -#define UOP(op) is_w() ? PSHw(op(POPw(1))) : PSH(op(POP(1))) +#define UOP(op) is_w() ? us_pushw(op(POPw(1))) : us_push(op(POP(1))) int run() {