all repos — xyw @ 4546ecda19fa588cd56b5e7d3a084876d6619d96

A minimal virtual machine and assembler for terminals.

Improved error management.
h3rald h3rald@h3rald.com
Fri, 24 Jul 2026 14:42:02 +0200
commit

4546ecda19fa588cd56b5e7d3a084876d6619d96

parent

56e2988e6a6ef18d17c848016e3d4bde93434a0e

2 files changed, 28 insertions(+), 5 deletions(-)

jump to
M examples/lib/macros.xywexamples/lib/macros.xyw

@@ -55,10 +55,25 @@ .macro arg.sep $1E

.macro arg.end $1D ;;; Errors -.macro error.file.not_found $31 -.macro error.file.access_denied $32 -.macro error.file.invalid_op $33 -.macro error.file.io_error $34 + +;system +.macro error.system.division_by_zero $01 +.macro error.system.stack_underflow $02 +.macro error.system.stack_overflow $03 +.macro error.system.exec_depth $04 +.macro error.system.image_not_found $05 +.macro error.system.image_read_error $06 + +;file +.macro error.file.not_found $31 +.macro error.file.access_denied $32 +.macro error.file.invalid_op $33 +.macro error.file.io_error $34 + +;beeper +.macro error.beeper.device $41 +.macro error.beeper.memory $42 +.macro error.beeper.playback $43 ;;; File operations .macro file.op.read $01
M xywrun.cxywrun.c

@@ -58,6 +58,8 @@ XYW_ERROR_DIVISION_BY_ZERO,

XYW_ERROR_STACK_UNDERFLOW, XYW_ERROR_STACK_OVERFLOW, XYW_ERROR_EXEC_DEPTH_EXCEEDED, + XYW_ERROR_IMAGE_NOT_FOUND, + XYW_ERROR_IMAGE_READ_ERROR, } xyw_error; #define SYSTEM_STATE_RUNNING 0x01

@@ -475,6 +477,7 @@ FILE *fp = fopen(path, "rb");

if (!fp) { fprintf(stderr, "Error - Could not open file [%s]\n", path); + xyw_memory[SYSTEM_ERROR] = XYW_ERROR_IMAGE_NOT_FOUND; xyw_memory[SYSTEM_STATE] &= ~SYSTEM_STATE_RUNNING; return -1; }

@@ -483,6 +486,7 @@ fclose(fp);

if (bytes_read == 0) { fprintf(stderr, "Error - Could not read file contents [%s]\n", path); + xyw_memory[SYSTEM_ERROR] = XYW_ERROR_IMAGE_READ_ERROR; xyw_memory[SYSTEM_STATE] &= ~SYSTEM_STATE_RUNNING; return -1; }

@@ -580,7 +584,11 @@ char *path, *argstart;

split_exec_string(path_copy, &path, &argstart); reset_vm_state(); - load_and_launch(path, argstart); + if (load_and_launch(path, argstart) != 0) + { + // Restore parent state so error handler can run in the caller's context + restore_snapshot(&exec_stack[--exec_stack_depth]); + } } //// Event dispatch (WAITING state)